@@ -7807,13 +7807,13 @@ int AllocKey(WOLFSSL* ssl, int type, void** pKey)
78077807 #if defined(HAVE_PQC)
78087808 #if defined(HAVE_FALCON)
78097809 case DYNAMIC_TYPE_FALCON:
7810- wc_falcon_init ((falcon_key*)*pKey);
7810+ wc_falcon_init_ex ((falcon_key*)*pKey, ssl->heap, ssl->devId );
78117811 ret = 0;
78127812 break;
78137813 #endif /* HAVE_FALCON */
78147814 #if defined(HAVE_DILITHIUM)
78157815 case DYNAMIC_TYPE_DILITHIUM:
7816- wc_dilithium_init ((dilithium_key*)*pKey);
7816+ wc_dilithium_init_ex ((dilithium_key*)*pKey, ssl->heap, ssl->devId );
78177817 ret = 0;
78187818 break;
78197819 #endif /* HAVE_DILITHIUM */
@@ -27534,6 +27534,55 @@ int CreateDevPrivateKey(void** pkey, byte* data, word32 length, int hsType,
2753427534 }
2753527535#endif
2753627536 }
27537+ else if (hsType == DYNAMIC_TYPE_DILITHIUM) {
27538+ #if defined(HAVE_PQC) && defined(HAVE_DILITHIUM)
27539+ dilithium_key* dilithiumKey;
27540+
27541+ dilithiumKey = (dilithium_key*)XMALLOC(sizeof(dilithium_key), heap,
27542+ DYNAMIC_TYPE_DILITHIUM);
27543+ if (dilithiumKey == NULL) {
27544+ return MEMORY_E;
27545+ }
27546+
27547+ if (label) {
27548+ ret = wc_dilithium_init_label(dilithiumKey, (char*)data,
27549+ heap, devId);
27550+ }
27551+ else if (id) {
27552+ ret = wc_dilithium_init_id(dilithiumKey, data, length, heap, devId);
27553+ }
27554+ if (ret == 0) {
27555+ *pkey = (void*)dilithiumKey;
27556+ }
27557+ else {
27558+ XFREE(dilithiumKey, heap, DYNAMIC_TYPE_DILITHIUM);
27559+ }
27560+ #endif
27561+ }
27562+ else if (hsType == DYNAMIC_TYPE_FALCON) {
27563+ #if defined(HAVE_PQC) && defined(HAVE_FALCON)
27564+ falcon_key* falconKey;
27565+
27566+ falconKey = (falcon_key*)XMALLOC(sizeof(falcon_key), heap,
27567+ DYNAMIC_TYPE_FALCON);
27568+ if (falconKey == NULL) {
27569+ return MEMORY_E;
27570+ }
27571+
27572+ if (label) {
27573+ ret = wc_falcon_init_label(falconKey, (char*)data, heap, devId);
27574+ }
27575+ else if (id) {
27576+ ret = wc_falcon_init_id(falconKey, data, length, heap, devId);
27577+ }
27578+ if (ret == 0) {
27579+ *pkey = (void*)falconKey;
27580+ }
27581+ else {
27582+ XFREE(falconKey, heap, DYNAMIC_TYPE_FALCON);
27583+ }
27584+ #endif
27585+ }
2753727586
2753827587 return ret;
2753927588}
@@ -27582,6 +27631,10 @@ int DecodePrivateKey(WOLFSSL *ssl, word16* length)
2758227631 ssl->hsType = DYNAMIC_TYPE_RSA;
2758327632 else if (ssl->buffers.keyType == ecc_dsa_sa_algo)
2758427633 ssl->hsType = DYNAMIC_TYPE_ECC;
27634+ else if (ssl->buffers.keyType == falcon_level5_sa_algo)
27635+ ssl->hsType = DYNAMIC_TYPE_FALCON;
27636+ else if (ssl->buffers.keyType == dilithium_level5_sa_algo)
27637+ ssl->hsType = DYNAMIC_TYPE_DILITHIUM;
2758527638 ret = AllocKey(ssl, ssl->hsType, &ssl->hsKey);
2758627639 if (ret != 0) {
2758727640 goto exit_dpk;
@@ -27637,6 +27690,59 @@ int DecodePrivateKey(WOLFSSL *ssl, word16* length)
2763727690 }
2763827691 #else
2763927692 ret = NOT_COMPILED_IN;
27693+ #endif
27694+ }
27695+ else if (ssl->buffers.keyType == falcon_level5_sa_algo) {
27696+ #if defined(HAVE_PQC) && defined(HAVE_FALCON)
27697+ if (ssl->buffers.keyLabel) {
27698+ ret = wc_falcon_init_label((falcon_key*)ssl->hsKey,
27699+ (char*)ssl->buffers.key->buffer,
27700+ ssl->heap, ssl->buffers.keyDevId);
27701+ }
27702+ else if (ssl->buffers.keyId) {
27703+ ret = wc_falcon_init_id((falcon_key*)ssl->hsKey,
27704+ ssl->buffers.key->buffer,
27705+ ssl->buffers.key->length, ssl->heap,
27706+ ssl->buffers.keyDevId);
27707+ }
27708+ if (ret == 0) {
27709+ if (ssl->buffers.keySz < ssl->options.minFalconKeySz) {
27710+ WOLFSSL_MSG("Falcon key size too small");
27711+ ERROR_OUT(FALCON_KEY_SIZE_E, exit_dpk);
27712+ }
27713+
27714+ /* Return the maximum signature length. */
27715+ *length = (word16)wc_falcon_sig_size((falcon_key*)ssl->hsKey);
27716+ }
27717+ #else
27718+ ret = NOT_COMPILED_IN;
27719+ #endif
27720+ }
27721+ else if (ssl->buffers.keyType == dilithium_level5_sa_algo) {
27722+ #if defined(HAVE_PQC) && defined(HAVE_DILITHIUM)
27723+ if (ssl->buffers.keyLabel) {
27724+ ret = wc_dilithium_init_label((dilithium_key*)ssl->hsKey,
27725+ (char*)ssl->buffers.key->buffer,
27726+ ssl->heap, ssl->buffers.keyDevId);
27727+ }
27728+ else if (ssl->buffers.keyId) {
27729+ ret = wc_dilithium_init_id((dilithium_key*)ssl->hsKey,
27730+ ssl->buffers.key->buffer,
27731+ ssl->buffers.key->length, ssl->heap,
27732+ ssl->buffers.keyDevId);
27733+ }
27734+ if (ret == 0) {
27735+ if (ssl->buffers.keySz < ssl->options.minDilithiumKeySz) {
27736+ WOLFSSL_MSG("Dilithium key size too small");
27737+ ERROR_OUT(DILITHIUM_KEY_SIZE_E, exit_dpk);
27738+ }
27739+
27740+ /* Return the maximum signature length. */
27741+ *length = (word16)wc_dilithium_sig_size(
27742+ (dilithium_key*)ssl->hsKey);
27743+ }
27744+ #else
27745+ ret = NOT_COMPILED_IN;
2764027746 #endif
2764127747 }
2764227748 goto exit_dpk;
0 commit comments