@@ -897,3 +897,79 @@ int test_ecx_dup(void *data)
897897
898898#endif /* defined(WP_HAVE_ED25519) || defined(WP_HAVE_ECD444) */
899899
900+ #if defined(WP_HAVE_X25519 ) || defined(WP_HAVE_X448 )
901+
902+ /*
903+ * Check that the correct security bits are provided for x25519 and x448
904+ */
905+ int test_ecx_x_security_bits (void * data )
906+ {
907+ int err = 0 ;
908+ (void )data ;
909+
910+ EVP_PKEY * pkey_ossl = NULL ;
911+ EVP_PKEY * pkey_wolf = NULL ;
912+ EVP_PKEY_CTX * ctx_ossl = NULL ;
913+ EVP_PKEY_CTX * ctx_wolf = NULL ;
914+
915+ struct {
916+ const char * name ;
917+ } types [] = {
918+ #ifdef WP_HAVE_X25519
919+ { "X25519" },
920+ #endif
921+ #ifdef WP_HAVE_X448
922+ { "X448" },
923+ #endif
924+ };
925+
926+ for (unsigned i = 0 ; i < ARRAY_SIZE (types ) && err == 0 ; i ++ ) {
927+ if (err == 0 ) {
928+ ctx_ossl = EVP_PKEY_CTX_new_from_name (osslLibCtx , types [i ].name ,
929+ NULL );
930+ err = ctx_ossl == NULL ;
931+ }
932+ if (err == 0 ) {
933+ ctx_wolf = EVP_PKEY_CTX_new_from_name (wpLibCtx , types [i ].name ,
934+ NULL );
935+ err = ctx_wolf == NULL ;
936+ }
937+ if (err == 0 ) {
938+ err = EVP_PKEY_keygen_init (ctx_ossl ) != 1 ;
939+ }
940+ if (err == 0 ) {
941+ err = EVP_PKEY_keygen_init (ctx_wolf ) != 1 ;
942+ }
943+ if (err == 0 ) {
944+ pkey_ossl = NULL ;
945+ err = EVP_PKEY_generate (ctx_ossl , & pkey_ossl ) != 1 ;
946+ }
947+ if (err == 0 ) {
948+ pkey_wolf = NULL ;
949+ err = EVP_PKEY_generate (ctx_wolf , & pkey_wolf ) != 1 ;
950+ }
951+ if (err == 0 ) {
952+ int sec_ossl = EVP_PKEY_get_security_bits (pkey_ossl );
953+ int sec_wolf = EVP_PKEY_get_security_bits (pkey_wolf );
954+ if (sec_ossl != sec_wolf ) {
955+ PRINT_MSG ("EVP_PKEY_get_security_bits failed for %s:"
956+ " expected %d, got %d" , types [i ].name , sec_ossl , sec_wolf );
957+ err = 1 ;
958+ }
959+ }
960+
961+ EVP_PKEY_free (pkey_ossl );
962+ EVP_PKEY_free (pkey_wolf );
963+ EVP_PKEY_CTX_free (ctx_ossl );
964+ EVP_PKEY_CTX_free (ctx_wolf );
965+ pkey_ossl = NULL ;
966+ pkey_wolf = NULL ;
967+ ctx_ossl = NULL ;
968+ ctx_wolf = NULL ;
969+ }
970+
971+ return err ;
972+ }
973+
974+ #endif /* defined(WP_HAVE_X25519) || defined(WP_HAVE_X448) */
975+
0 commit comments