@@ -1017,6 +1017,154 @@ int wc_CryptoCb_Ed25519Verify(const byte* sig, word32 sigLen,
10171017}
10181018#endif /* HAVE_ED25519 */
10191019
1020+ #if defined(WOLFSSL_HAVE_LMS ) || defined(WOLFSSL_HAVE_XMSS )
1021+ int wc_CryptoCb_PqcStatefulSigGetDevId (int type , void * key )
1022+ {
1023+ int devId = INVALID_DEVID ;
1024+
1025+ if (key == NULL )
1026+ return devId ;
1027+
1028+ #if defined(WOLFSSL_HAVE_LMS )
1029+ if (type == WC_PQC_STATEFUL_SIG_TYPE_LMS ) {
1030+ devId = ((LmsKey * )key )-> devId ;
1031+ }
1032+ #endif
1033+ #if defined(WOLFSSL_HAVE_XMSS )
1034+ if (type == WC_PQC_STATEFUL_SIG_TYPE_XMSS ) {
1035+ devId = ((XmssKey * )key )-> devId ;
1036+ }
1037+ #endif
1038+
1039+ return devId ;
1040+ }
1041+
1042+ int wc_CryptoCb_PqcStatefulSigKeyGen (int type , void * key , WC_RNG * rng )
1043+ {
1044+ int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
1045+ int devId = INVALID_DEVID ;
1046+ CryptoCb * dev ;
1047+
1048+ if (key == NULL )
1049+ return ret ;
1050+
1051+ devId = wc_CryptoCb_PqcStatefulSigGetDevId (type , key );
1052+ if (devId == INVALID_DEVID )
1053+ return ret ;
1054+
1055+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
1056+ if (dev && dev -> cb ) {
1057+ wc_CryptoInfo cryptoInfo ;
1058+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
1059+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
1060+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_STATEFUL_SIG_KEYGEN ;
1061+ cryptoInfo .pk .pqc_stateful_sig_kg .rng = rng ;
1062+ cryptoInfo .pk .pqc_stateful_sig_kg .key = key ;
1063+ cryptoInfo .pk .pqc_stateful_sig_kg .type = type ;
1064+
1065+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1066+ }
1067+
1068+ return wc_CryptoCb_TranslateErrorCode (ret );
1069+ }
1070+
1071+ int wc_CryptoCb_PqcStatefulSigSign (const byte * msg , word32 msgSz , byte * out ,
1072+ word32 * outSz , int type , void * key )
1073+ {
1074+ int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
1075+ int devId = INVALID_DEVID ;
1076+ CryptoCb * dev ;
1077+
1078+ if (key == NULL )
1079+ return ret ;
1080+
1081+ devId = wc_CryptoCb_PqcStatefulSigGetDevId (type , key );
1082+ if (devId == INVALID_DEVID )
1083+ return ret ;
1084+
1085+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
1086+ if (dev && dev -> cb ) {
1087+ wc_CryptoInfo cryptoInfo ;
1088+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
1089+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
1090+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_STATEFUL_SIG_SIGN ;
1091+ cryptoInfo .pk .pqc_stateful_sig_sign .msg = msg ;
1092+ cryptoInfo .pk .pqc_stateful_sig_sign .msgSz = msgSz ;
1093+ cryptoInfo .pk .pqc_stateful_sig_sign .out = out ;
1094+ cryptoInfo .pk .pqc_stateful_sig_sign .outSz = outSz ;
1095+ cryptoInfo .pk .pqc_stateful_sig_sign .key = key ;
1096+ cryptoInfo .pk .pqc_stateful_sig_sign .type = type ;
1097+
1098+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1099+ }
1100+
1101+ return wc_CryptoCb_TranslateErrorCode (ret );
1102+ }
1103+
1104+ int wc_CryptoCb_PqcStatefulSigVerify (const byte * sig , word32 sigSz ,
1105+ const byte * msg , word32 msgSz , int * res , int type , void * key )
1106+ {
1107+ int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
1108+ int devId = INVALID_DEVID ;
1109+ CryptoCb * dev ;
1110+
1111+ if (key == NULL )
1112+ return ret ;
1113+
1114+ devId = wc_CryptoCb_PqcStatefulSigGetDevId (type , key );
1115+ if (devId == INVALID_DEVID )
1116+ return ret ;
1117+
1118+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
1119+ if (dev && dev -> cb ) {
1120+ wc_CryptoInfo cryptoInfo ;
1121+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
1122+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
1123+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_STATEFUL_SIG_VERIFY ;
1124+ cryptoInfo .pk .pqc_stateful_sig_verify .sig = sig ;
1125+ cryptoInfo .pk .pqc_stateful_sig_verify .sigSz = sigSz ;
1126+ cryptoInfo .pk .pqc_stateful_sig_verify .msg = msg ;
1127+ cryptoInfo .pk .pqc_stateful_sig_verify .msgSz = msgSz ;
1128+ cryptoInfo .pk .pqc_stateful_sig_verify .res = res ;
1129+ cryptoInfo .pk .pqc_stateful_sig_verify .key = key ;
1130+ cryptoInfo .pk .pqc_stateful_sig_verify .type = type ;
1131+
1132+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1133+ }
1134+
1135+ return wc_CryptoCb_TranslateErrorCode (ret );
1136+ }
1137+
1138+ int wc_CryptoCb_PqcStatefulSigSigsLeft (int type , void * key , word32 * sigsLeft )
1139+ {
1140+ int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
1141+ int devId = INVALID_DEVID ;
1142+ CryptoCb * dev ;
1143+
1144+ if (key == NULL )
1145+ return ret ;
1146+
1147+ devId = wc_CryptoCb_PqcStatefulSigGetDevId (type , key );
1148+ if (devId == INVALID_DEVID )
1149+ return ret ;
1150+
1151+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
1152+ if (dev && dev -> cb ) {
1153+ wc_CryptoInfo cryptoInfo ;
1154+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
1155+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
1156+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_STATEFUL_SIG_SIGS_LEFT ;
1157+ cryptoInfo .pk .pqc_stateful_sig_sigs_left .key = key ;
1158+ cryptoInfo .pk .pqc_stateful_sig_sigs_left .sigsLeft = sigsLeft ;
1159+ cryptoInfo .pk .pqc_stateful_sig_sigs_left .type = type ;
1160+
1161+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
1162+ }
1163+
1164+ return wc_CryptoCb_TranslateErrorCode (ret );
1165+ }
1166+ #endif /* WOLFSSL_HAVE_LMS || WOLFSSL_HAVE_XMSS */
1167+
10201168#if defined(WOLFSSL_HAVE_MLKEM )
10211169int wc_CryptoCb_PqcKemGetDevId (int type , void * key )
10221170{
0 commit comments