@@ -785,6 +785,129 @@ int wc_CryptoCb_Ed25519Verify(const byte* sig, word32 sigLen,
785785}
786786#endif /* HAVE_ED25519 */
787787
788+ #if defined(HAVE_PQC ) && defined(WOLFSSL_HAVE_KYBER )
789+ int wc_CryptoCb_PqcKemGetDevId (int type , void * key )
790+ {
791+ int devId = INVALID_DEVID ;
792+
793+ if (key == NULL )
794+ return devId ;
795+
796+ /* get devId */
797+ #if defined(WOLFSSL_HAVE_KYBER )
798+ if (type == WC_PQC_KEM_TYPE_KYBER ) {
799+ devId = ((KyberKey * ) key )-> devId ;
800+ }
801+ #endif
802+
803+ return devId ;
804+ }
805+
806+ int wc_CryptoCb_MakePqcKemKey (WC_RNG * rng , int type , int keySize , void * key )
807+ {
808+ int ret = CRYPTOCB_UNAVAILABLE ;
809+ int devId = INVALID_DEVID ;
810+ CryptoCb * dev ;
811+
812+ if (key == NULL )
813+ return ret ;
814+
815+ /* get devId */
816+ devId = wc_CryptoCb_PqcKemGetDevId (type , key );
817+ if (devId == INVALID_DEVID )
818+ return ret ;
819+
820+ /* locate registered callback */
821+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
822+ if (dev && dev -> cb ) {
823+ wc_CryptoInfo cryptoInfo ;
824+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
825+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
826+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_KEM_KEYGEN ;
827+ cryptoInfo .pk .pqc_kem_kg .rng = rng ;
828+ cryptoInfo .pk .pqc_kem_kg .size = keySize ;
829+ cryptoInfo .pk .pqc_kem_kg .key = key ;
830+ cryptoInfo .pk .pqc_kem_kg .type = type ;
831+
832+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
833+ }
834+
835+ return wc_CryptoCb_TranslateErrorCode (ret );
836+ }
837+
838+ int wc_CryptoCb_PqcEncapsulate (byte * ciphertext , word32 ciphertextLen ,
839+ byte * sharedSecret , word32 sharedSecretLen , WC_RNG * rng , int type ,
840+ void * key )
841+ {
842+ int ret = CRYPTOCB_UNAVAILABLE ;
843+ int devId = INVALID_DEVID ;
844+ CryptoCb * dev ;
845+
846+ if (key == NULL )
847+ return ret ;
848+
849+ /* get devId */
850+ devId = wc_CryptoCb_PqcKemGetDevId (type , key );
851+ if (devId == INVALID_DEVID )
852+ return ret ;
853+
854+ /* locate registered callback */
855+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
856+ if (dev && dev -> cb ) {
857+ wc_CryptoInfo cryptoInfo ;
858+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
859+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
860+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_KEM_ENCAPS ;
861+ cryptoInfo .pk .pqc_encaps .ciphertext = ciphertext ;
862+ cryptoInfo .pk .pqc_encaps .ciphertextLen = ciphertextLen ;
863+ cryptoInfo .pk .pqc_encaps .sharedSecret = sharedSecret ;
864+ cryptoInfo .pk .pqc_encaps .sharedSecretLen = sharedSecretLen ;
865+ cryptoInfo .pk .pqc_encaps .rng = rng ;
866+ cryptoInfo .pk .pqc_encaps .key = key ;
867+ cryptoInfo .pk .pqc_encaps .type = type ;
868+
869+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
870+ }
871+
872+ return wc_CryptoCb_TranslateErrorCode (ret );
873+ }
874+
875+ int wc_CryptoCb_PqcDecapsulate (const byte * ciphertext , word32 ciphertextLen ,
876+ byte * sharedSecret , word32 sharedSecretLen , int type , void * key )
877+ {
878+ int ret = CRYPTOCB_UNAVAILABLE ;
879+ int devId = INVALID_DEVID ;
880+ CryptoCb * dev ;
881+
882+ if (key == NULL )
883+ return ret ;
884+
885+ /* get devId */
886+ devId = wc_CryptoCb_PqcKemGetDevId (type , key );
887+ if (devId == INVALID_DEVID )
888+ return ret ;
889+
890+ /* locate registered callback */
891+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_PK );
892+ if (dev && dev -> cb ) {
893+ wc_CryptoInfo cryptoInfo ;
894+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
895+ cryptoInfo .algo_type = WC_ALGO_TYPE_PK ;
896+ cryptoInfo .pk .type = WC_PK_TYPE_PQC_KEM_DECAPS ;
897+ cryptoInfo .pk .pqc_decaps .ciphertext = ciphertext ;
898+ cryptoInfo .pk .pqc_decaps .ciphertextLen = ciphertextLen ;
899+ cryptoInfo .pk .pqc_decaps .sharedSecret = sharedSecret ;
900+ cryptoInfo .pk .pqc_decaps .sharedSecretLen = sharedSecretLen ;
901+ cryptoInfo .pk .pqc_decaps .key = key ;
902+ cryptoInfo .pk .pqc_decaps .type = type ;
903+
904+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
905+ }
906+
907+ return wc_CryptoCb_TranslateErrorCode (ret );
908+ }
909+ #endif /* HAVE_PQC && WOLFSSL_HAVE_KYBER */
910+
788911#if defined(HAVE_PQC ) && (defined(HAVE_FALCON ) || defined(HAVE_DILITHIUM ))
789912int wc_CryptoCb_PqcSigGetDevId (int type , void * key )
790913{
0 commit comments