Skip to content

Commit 5fa65c3

Browse files
Debug riscv64 SM2 regression
1 parent 2ade36d commit 5fa65c3

File tree

7 files changed

+104
-17
lines changed

7 files changed

+104
-17
lines changed

.github/workflows/cross-compiles.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ jobs:
210210
if: github.event_name == 'push' && matrix.platform.tests == ''
211211
run: |
212212
.github/workflows/make-test \
213-
TESTS="-test_afalg" \
213+
TESTS="test_internal_ec" V=1 \
214214
QEMU_LD_PREFIX=/usr/${{ matrix.platform.arch }}
215215
- name: make some tests
216216
if: github.event_name == 'push' && matrix.platform.tests != 'none' && matrix.platform.tests != ''

crypto/bn/bn_exp.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
309309
return ret;
310310
}
311311

312+
#ifndef OPENSSL_NO_STDIO
313+
extern int debug;
314+
int debug = 0;
315+
#ifdef FIPS_MODULE
316+
int BN_print_fp(FILE *fp, const BIGNUM *a)
317+
{
318+
char *hex = BN_bn2hex(a);
319+
fprintf(fp, "%s", hex);
320+
OPENSSL_free(hex);
321+
return 0;
322+
}
323+
#endif
324+
#endif
325+
312326
int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
313327
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
314328
{
@@ -337,6 +351,10 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
337351
}
338352

339353
bits = BN_num_bits(p);
354+
#ifndef OPENSSL_NO_STDIO
355+
if (debug > 0)
356+
printf("bits=%d\n", bits);
357+
#endif
340358
if (bits == 0) {
341359
/* x**0 mod 1, or x**0 mod -1 is still zero. */
342360
if (BN_abs_is_word(m, 1)) {
@@ -374,6 +392,13 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
374392
aa = val[0];
375393
} else
376394
aa = a;
395+
#ifndef OPENSSL_NO_STDIO
396+
if (debug > 0) {
397+
printf("aa=");
398+
BN_print_fp(stdout, aa);
399+
printf("\n");
400+
}
401+
#endif
377402
if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))
378403
goto err; /* 1 */
379404

crypto/ec/ecp_mont.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ int ossl_ec_GFp_mont_field_inv(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a
227227
BN_CTX *new_ctx = NULL;
228228
int ret = 0;
229229

230+
#ifndef OPENSSL_NO_STDIO
231+
extern int debug;
232+
if (group->meth->field_type == NID_X9_62_prime_field && debug == 0)
233+
debug = 1;
234+
else if (debug > 0)
235+
debug = -1;
236+
if (debug > 0)
237+
printf("in ossl_ec_GFp_mont_field_inv\n");
238+
#endif
230239
if (group->field_data1 == NULL)
231240
return 0;
232241

@@ -243,13 +252,30 @@ int ossl_ec_GFp_mont_field_inv(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a
243252
goto err;
244253
if (!BN_sub(e, group->field, e))
245254
goto err;
255+
#ifndef OPENSSL_NO_STDIO
256+
if (debug > 0) {
257+
printf("a=");
258+
BN_print_fp(stdout, a);
259+
printf("\ne=");
260+
BN_print_fp(stdout, e);
261+
printf("\n");
262+
}
263+
#endif
246264
/*-
247265
* Exponent e is public.
248266
* No need for scatter-gather or BN_FLG_CONSTTIME.
249267
*/
250268
if (!BN_mod_exp_mont(r, a, e, group->field, ctx, group->field_data1))
251269
goto err;
252270

271+
#ifndef OPENSSL_NO_STDIO
272+
if (debug > 0) {
273+
printf("r=");
274+
BN_print_fp(stdout, r);
275+
printf("\n");
276+
debug = -1;
277+
}
278+
#endif
253279
/* throw an error on zero */
254280
if (BN_is_zero(r)) {
255281
ERR_raise(ERR_LIB_EC, EC_R_CANNOT_INVERT);

crypto/ec/ecp_smpl.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,15 @@ int ossl_ec_GFp_simple_field_inv(const EC_GROUP *group, BIGNUM *r,
13871387
BN_CTX *new_ctx = NULL;
13881388
int ret = 0;
13891389

1390+
#ifndef OPENSSL_NO_STDIO
1391+
extern int debug;
1392+
if (group->meth->field_type == NID_X9_62_prime_field && debug == 0)
1393+
debug = 1;
1394+
else if (debug > 0)
1395+
debug = -1;
1396+
if (debug > 0)
1397+
printf("in ossl_ec_GFp_simple_field_inv\n");
1398+
#endif
13901399
if (ctx == NULL
13911400
&& (ctx = new_ctx = BN_CTX_secure_new_ex(group->libctx)) == NULL)
13921401
return 0;
@@ -1400,17 +1409,48 @@ int ossl_ec_GFp_simple_field_inv(const EC_GROUP *group, BIGNUM *r,
14001409
goto err;
14011410
} while (BN_is_zero(e));
14021411

1412+
#ifndef OPENSSL_NO_STDIO
1413+
if (debug > 0) {
1414+
printf("a=");
1415+
BN_print_fp(stdout, a);
1416+
printf("\ne=");
1417+
BN_print_fp(stdout, e);
1418+
printf("\n");
1419+
}
1420+
#endif
14031421
/* r := a * e */
14041422
if (!group->meth->field_mul(group, r, a, e, ctx))
14051423
goto err;
1424+
#ifndef OPENSSL_NO_STDIO
1425+
if (debug > 0) {
1426+
printf("a*e=");
1427+
BN_print_fp(stdout, r);
1428+
printf("\n");
1429+
}
1430+
#endif
14061431
/* r := 1/(a * e) */
14071432
if (!BN_mod_inverse(r, r, group->field, ctx)) {
14081433
ERR_raise(ERR_LIB_EC, EC_R_CANNOT_INVERT);
14091434
goto err;
14101435
}
1436+
#ifndef OPENSSL_NO_STDIO
1437+
if (debug > 0) {
1438+
printf("1/(a*e)=");
1439+
BN_print_fp(stdout, r);
1440+
printf("\n");
1441+
}
1442+
#endif
14111443
/* r := e/(a * e) = 1/a */
14121444
if (!group->meth->field_mul(group, r, r, e, ctx))
14131445
goto err;
1446+
#ifndef OPENSSL_NO_STDIO
1447+
if (debug > 0) {
1448+
printf("r=");
1449+
BN_print_fp(stdout, r);
1450+
printf("\n");
1451+
debug = -1;
1452+
}
1453+
#endif
14141454

14151455
ret = 1;
14161456

test/ec_internal_test.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static int group_field_tests(const EC_GROUP *group, BN_CTX *ctx)
7272
return ret;
7373
}
7474

75+
#if 0
7576
/* wrapper for group_field_tests for explicit curve params and EC_METHOD */
7677
static int field_tests(const EC_METHOD *meth, const unsigned char *params,
7778
int len)
@@ -214,6 +215,7 @@ static int field_tests_ec2_simple(void)
214215
sizeof(params_b283) / 3);
215216
}
216217
#endif
218+
#endif
217219

218220
/* test default method for a named curve */
219221
static int field_tests_default(int n)
@@ -239,6 +241,7 @@ static int field_tests_default(int n)
239241
return ret;
240242
}
241243

244+
#if 0
242245
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
243246
/*
244247
* Tests a point known to cause an incorrect underflow in an old version of
@@ -545,6 +548,7 @@ static int named_group_creation_test(void)
545548
EC_GROUP_free(group);
546549
return ret;
547550
}
551+
#endif
548552

549553
int setup_tests(void)
550554
{
@@ -553,25 +557,14 @@ int setup_tests(void)
553557
|| !TEST_true(EC_get_builtin_curves(curves, crv_len)))
554558
return 0;
555559

556-
ADD_TEST(field_tests_ecp_simple);
557-
ADD_TEST(field_tests_ecp_mont);
558-
#ifndef OPENSSL_NO_EC2M
559-
ADD_TEST(ec2m_field_sanity);
560-
ADD_TEST(field_tests_ec2_simple);
561-
#endif
562-
ADD_ALL_TESTS(field_tests_default, (int)crv_len);
563-
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
564-
ADD_TEST(underflow_test);
565-
#endif
566-
ADD_TEST(set_private_key);
567-
ADD_TEST(decoded_flag_test);
568-
ADD_ALL_TESTS(ecpkparams_i2d2i_test, (int)crv_len);
569-
ADD_TEST(named_group_creation_test);
560+
curves += crv_len - 1;
561+
ADD_ALL_TESTS(field_tests_default, 1);
570562

571563
return 1;
572564
}
573565

574566
void cleanup_tests(void)
575567
{
568+
curves -= crv_len - 1;
576569
OPENSSL_free(curves);
577570
}

test/recipes/80-test_ssl_old.t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ my $client_sess="client.ss";
7979
# If you're adding tests here, you probably want to convert them to the
8080
# new format in ssl_test.c and add recipes to 80-test_ssl_new.t instead.
8181
plan tests =>
82-
($no_fips ? 0 : 7) # testssl with fips provider
82+
($no_fips ? 0 : 6) # testssl with fips provider
8383
+ 1 # For testss
84-
+ 5 # For the testssl with default provider
84+
+ 4 # For the testssl with default provider
8585
+ 1 # For security level 0 failure tests
8686
;
8787

@@ -499,6 +499,7 @@ sub testssl {
499499
}
500500
};
501501

502+
if (0) {
502503
subtest "Testing ciphersuites" => sub {
503504

504505
my @exkeys = ();
@@ -598,6 +599,7 @@ sub testssl {
598599
}
599600
}
600601
};
602+
}
601603

602604
subtest 'SSL security level failure tests' => sub {
603605
######################################################################

util/checkplatformsyms.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
my $OBJFH;
2222
my $cmd;
2323

24+
exit 0;
2425
if ($Config{osname} eq "MSWin32") {
2526
my $currentdll = "";
2627
$cmd = "dumpbin /imports " . $objfilelist;

0 commit comments

Comments
 (0)