|
26 | 26 | #include <wolfssl/wolfcrypt/ed25519.h> |
27 | 27 | #include <wolfssl/wolfcrypt/ed448.h> |
28 | 28 |
|
29 | | -#if defined(WP_HAVE_ED25519) || defined(WP_HAVE_ECD448) |
30 | | - |
31 | 29 | #ifndef ARRAY_SIZE |
32 | 30 | #define ARRAY_SIZE(a) ((sizeof(a)/sizeof(a[0]))) |
33 | 31 | #endif |
34 | 32 |
|
| 33 | +#if defined(WP_HAVE_ED25519) || defined(WP_HAVE_ED448) |
| 34 | + |
35 | 35 | #ifndef MAX |
36 | 36 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
37 | 37 | #endif |
@@ -656,7 +656,6 @@ static int test_ecx_null_sign_init_ex(OSSL_LIB_CTX *libCtx) |
656 | 656 |
|
657 | 657 | #ifndef WP_HAVE_ED25519 |
658 | 658 | (void)libCtx; |
659 | | - (void)provider_name; |
660 | 659 | PRINT_MSG("Skipping test - WP_HAVE_ED25519 not defined"); |
661 | 660 | return 0; |
662 | 661 | #endif |
@@ -895,5 +894,89 @@ int test_ecx_dup(void *data) |
895 | 894 | return err; |
896 | 895 | } |
897 | 896 |
|
898 | | -#endif /* defined(WP_HAVE_ED25519) || defined(WP_HAVE_ECD444) */ |
| 897 | +#endif /* defined(WP_HAVE_ED25519) || defined(WP_HAVE_ED448) */ |
| 898 | + |
| 899 | +#if defined(WP_HAVE_X25519) || defined(WP_HAVE_X448) |
| 900 | + |
| 901 | +/* |
| 902 | + * Check that the correct security bits are provided for x25519 and x448 |
| 903 | + */ |
| 904 | +int test_ecx_x_security_bits(void *data) |
| 905 | +{ |
| 906 | + int err = 0; |
| 907 | + (void)data; |
| 908 | + |
| 909 | + EVP_PKEY *pkey_ossl = NULL; |
| 910 | + EVP_PKEY *pkey_wolf = NULL; |
| 911 | + EVP_PKEY_CTX *ctx_ossl = NULL; |
| 912 | + EVP_PKEY_CTX *ctx_wolf = NULL; |
| 913 | + |
| 914 | + struct { |
| 915 | + const char *name; |
| 916 | + int expectedBits; |
| 917 | + } types[] = { |
| 918 | +#ifdef WP_HAVE_X25519 |
| 919 | + { "X25519", 128 }, |
| 920 | +#endif |
| 921 | +#ifdef WP_HAVE_X448 |
| 922 | + { "X448", 224 }, |
| 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 mismatch for %s:" |
| 956 | + " OpenSSL %d, wolfProvider %d", types[i].name, sec_ossl, |
| 957 | + sec_wolf); |
| 958 | + err = 1; |
| 959 | + } |
| 960 | + else if (sec_wolf != types[i].expectedBits) { |
| 961 | + PRINT_MSG("EVP_PKEY_get_security_bits failed for %s:" |
| 962 | + " expected %d, got %d", types[i].name, |
| 963 | + types[i].expectedBits, sec_wolf); |
| 964 | + err = 1; |
| 965 | + } |
| 966 | + } |
| 967 | + |
| 968 | + EVP_PKEY_free(pkey_ossl); |
| 969 | + EVP_PKEY_free(pkey_wolf); |
| 970 | + EVP_PKEY_CTX_free(ctx_ossl); |
| 971 | + EVP_PKEY_CTX_free(ctx_wolf); |
| 972 | + pkey_ossl = NULL; |
| 973 | + pkey_wolf = NULL; |
| 974 | + ctx_ossl = NULL; |
| 975 | + ctx_wolf = NULL; |
| 976 | + } |
| 977 | + |
| 978 | + return err; |
| 979 | +} |
| 980 | + |
| 981 | +#endif /* defined(WP_HAVE_X25519) || defined(WP_HAVE_X448) */ |
899 | 982 |
|
0 commit comments