Skip to content

Commit fe5ae0c

Browse files
Restore 128-byte SRP test using safe prime N for the case where 192 bytes is too large for the fast/SP math config.
1 parent a035b04 commit fe5ae0c

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

wolfcrypt/test/test.c

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,8 +2217,7 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
22172217
TEST_PASS("DSA test passed!\n");
22182218
#endif
22192219

2220-
#if defined(WOLFCRYPT_HAVE_SRP) && ((defined(FP_MAX_BITS) && (FP_MAX_BITS >= 3072)) \
2221-
|| (defined(SP_INT_BITS) && (SP_INT_BITS >= 3072)))
2220+
#ifdef WOLFCRYPT_HAVE_SRP
22222221
if ( (ret = srp_test()) != 0)
22232222
TEST_FAIL("SRP test failed!\n", ret);
22242223
else
@@ -24152,8 +24151,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
2415224151

2415324152
#endif /* !NO_DSA */
2415424153

24155-
#if defined(WOLFCRYPT_HAVE_SRP) && ((defined(FP_MAX_BITS) && (FP_MAX_BITS >= 3072)) \
24156-
|| (defined(SP_INT_BITS) && (SP_INT_BITS >= 3072)))
24154+
#ifdef WOLFCRYPT_HAVE_SRP
2415724155
static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
2415824156
{
2415924157
wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
@@ -24171,21 +24169,48 @@ static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
2417124169
return ret;
2417224170
}
2417324171

24172+
#if ((defined(FP_MAX_BITS) && (FP_MAX_BITS >= 3072)) \
24173+
|| (defined(SP_INT_BITS) && (SP_INT_BITS >= 3072)))
24174+
#define SRP_TEST_BUFFER_SIZE 192
24175+
#else
24176+
#define SRP_TEST_BUFFER_SIZE 128
24177+
#endif
24178+
2417424179
static wc_test_ret_t srp_test_digest(SrpType dgstType)
2417524180
{
2417624181
wc_test_ret_t r;
2417724182

24178-
byte clientPubKey[192]; /* A */
24179-
byte serverPubKey[192]; /* B */
24180-
word32 clientPubKeySz = 192;
24181-
word32 serverPubKeySz = 192;
24183+
byte clientPubKey[SRP_TEST_BUFFER_SIZE]; /* A */
24184+
byte serverPubKey[SRP_TEST_BUFFER_SIZE]; /* B */
24185+
word32 clientPubKeySz = SRP_TEST_BUFFER_SIZE;
24186+
word32 serverPubKeySz = SRP_TEST_BUFFER_SIZE;
2418224187

2418324188
byte username[] = "user";
2418424189
word32 usernameSz = 4;
2418524190

2418624191
byte password[] = "password";
2418724192
word32 passwordSz = 8;
2418824193

24194+
#if SRP_TEST_BUFFER_SIZE == 128
24195+
WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
24196+
0xEE, 0xAF, 0x0A, 0xB9, 0xAD, 0xB3, 0x8D, 0xD6,
24197+
0x9C, 0x33, 0xF8, 0x0A, 0xFA, 0x8F, 0xC5, 0xE8,
24198+
0x60, 0x72, 0x61, 0x87, 0x75, 0xFF, 0x3C, 0x0B,
24199+
0x9E, 0xA2, 0x31, 0x4C, 0x9C, 0x25, 0x65, 0x76,
24200+
0xD6, 0x74, 0xDF, 0x74, 0x96, 0xEA, 0x81, 0xD3,
24201+
0x38, 0x3B, 0x48, 0x13, 0xD6, 0x92, 0xC6, 0xE0,
24202+
0xE0, 0xD5, 0xD8, 0xE2, 0x50, 0xB9, 0x8B, 0xE4,
24203+
0x8E, 0x49, 0x5C, 0x1D, 0x60, 0x89, 0xDA, 0xD1,
24204+
0x5D, 0xC7, 0xD7, 0xB4, 0x61, 0x54, 0xD6, 0xB6,
24205+
0xCE, 0x8E, 0xF4, 0xAD, 0x69, 0xB1, 0x5D, 0x49,
24206+
0x82, 0x55, 0x9B, 0x29, 0x7B, 0xCF, 0x18, 0x85,
24207+
0xC5, 0x29, 0xF5, 0x66, 0x66, 0x0E, 0x57, 0xEC,
24208+
0x68, 0xED, 0xBC, 0x3C, 0x05, 0x72, 0x6C, 0xC0,
24209+
0x2F, 0xD4, 0xCB, 0xF4, 0x97, 0x6E, 0xAA, 0x9A,
24210+
0xFD, 0x51, 0x38, 0xFE, 0x83, 0x76, 0x43, 0x5B,
24211+
0x9F, 0xC6, 0x1D, 0x2F, 0xC0, 0xEB, 0x06, 0xE3
24212+
};
24213+
#else
2418924214
WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
2419024215
0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
2419124216
0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
@@ -24212,14 +24237,16 @@ static wc_test_ret_t srp_test_digest(SrpType dgstType)
2421224237
0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
2421324238
0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
2421424239
};
24240+
#endif
2421524241

24242+
/* Generator is 2 for both cases. */
2421624243
WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
2421724244
0x02
2421824245
};
2421924246

2422024247
byte salt[10];
2422124248

24222-
byte verifier[192];
24249+
byte verifier[SRP_TEST_BUFFER_SIZE];
2422324250
word32 v_size = (word32)sizeof(verifier);
2422424251

2422524252
word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
@@ -24341,9 +24368,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
2434124368
return ret;
2434224369
}
2434324370

24344-
#endif
24345-
/* WOLFCRYPT_HAVE_SRP && ((FP_MAX_BITS && (FP_MAX_BITS >= 3072))
24346-
|| (SP_INT_BITS && (SP_INT_BITS >= 3072))) */
24371+
#endif /* WOLFCRYPT_HAVE_SRP */
2434724372

2434824373
#if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
2434924374

0 commit comments

Comments
 (0)