From 32a517ba39d5f346c79ed582a5220a21ccdd5b37 Mon Sep 17 00:00:00 2001 From: Samuele Andreoli Date: Thu, 5 Mar 2020 14:16:50 +0000 Subject: [PATCH 1/2] Fix tests when using DEBUG_NORM --- test/CMakeLists.txt | 6 ++++-- test/test_big_consistency_XXX.c.in | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5c13d80..2cf47b4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -160,8 +160,10 @@ foreach(curve ${AMCL_CURVE}) endif(CS STREQUAL "128") amcl_curve_test(${curve} test_pair_${TC} test_pair_ZZZ.c.in amcl_pairing_${TC} "SUCCESS") - if(CMAKE_SYSTEM_NAME MATCHES "Linux") - # Test arithmetics debug output functions - Linux specific code + # Test arithmetics debug output functions - Linux specific code + # Skip the tests when using DEBUG_NORM, since it changes the raw + # output + if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT DEBUG_NORM) amcl_curve_test(${curve} test_output_functions_${TC} test_output_functions_ZZZ.c.in amcl_pairing_${TC} "SUCCESS" "output/test_vector_${TC}_${WORD_SIZE}.txt" "stdout.out") endif(CMAKE_SYSTEM_NAME MATCHES "Linux") diff --git a/test/test_big_consistency_XXX.c.in b/test/test_big_consistency_XXX.c.in index dbdfca8..3cb69af 100644 --- a/test/test_big_consistency_XXX.c.in +++ b/test/test_big_consistency_XXX.c.in @@ -112,7 +112,7 @@ int main() /* Testing small multiplication and addition */ BIG_XXX_random(F,&rng); - for (j = 1; j <= 20; ++j) + for (j = 1; j <= NEXCESS_XXX; ++j) { BIG_XXX_imul(H,F,j); BIG_XXX_copy(G,F); From 0fac9ed257f3c6b2747d4e4b09d79a2d4865759e Mon Sep 17 00:00:00 2001 From: Samuele Andreoli Date: Thu, 5 Mar 2020 14:17:07 +0000 Subject: [PATCH 2/2] Add missing norms --- src/ecp2.c.in | 1 + src/ecp4.c.in | 1 + src/ecp8.c.in | 1 + src/fp.c.in | 1 + src/fp4.c.in | 1 + src/fp8.c.in | 4 ++-- 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ecp2.c.in b/src/ecp2.c.in index 4a6f937..6061d98 100644 --- a/src/ecp2.c.in +++ b/src/ecp2.c.in @@ -641,6 +641,7 @@ void ECP2_ZZZ_mapit(ECP2_ZZZ *Q,octet *W) FP2_YYY_from_BIGs(&X,one,hv); if (ECP2_ZZZ_setx(Q,&X)) break; BIG_XXX_inc(hv,1); + BIG_XXX_norm(hv); } BIG_XXX_rcopy(Fx,Fra_YYY); diff --git a/src/ecp4.c.in b/src/ecp4.c.in index 3f95f7a..3a35199 100644 --- a/src/ecp4.c.in +++ b/src/ecp4.c.in @@ -744,6 +744,7 @@ void ECP4_ZZZ_mapit(ECP4_ZZZ *Q,octet *W) FP4_YYY_from_FP2(&X4,&T); if (ECP4_ZZZ_setx(Q,&X4)) break; BIG_XXX_inc(hv,1); + BIG_XXX_norm(hv); } ECP4_ZZZ_frob_constants(X); diff --git a/src/ecp8.c.in b/src/ecp8.c.in index f807da2..2cca877 100644 --- a/src/ecp8.c.in +++ b/src/ecp8.c.in @@ -893,6 +893,7 @@ void ECP8_ZZZ_mapit(ECP8_ZZZ *Q,octet *W) FP8_YYY_from_FP4(&X8,&X4); if (ECP8_ZZZ_setx(Q,&X8)) break; BIG_XXX_inc(hv,1); + BIG_XXX_norm(hv); } ECP8_ZZZ_frob_constants(X); diff --git a/src/fp.c.in b/src/fp.c.in index ec1ab9a..7a98312 100644 --- a/src/fp.c.in +++ b/src/fp.c.in @@ -767,6 +767,7 @@ void FP_YYY_sqrt(FP_YYY *r,FP_YYY *a) FP_YYY_mul(&i,&i,&v); // i=(2x)^(p+3)/8 FP_YYY_mul(&i,&i,&v); // i=(2x)^(p-1)/4 BIG_XXX_dec(i.g,1); // i=(2x)^(p-1)/4 - 1 + BIG_XXX_norm(i.g); FP_YYY_mul(r,a,&v); FP_YYY_mul(r,r,&i); FP_YYY_reduce(r); diff --git a/src/fp4.c.in b/src/fp4.c.in index c1c54f0..3e3b64b 100644 --- a/src/fp4.c.in +++ b/src/fp4.c.in @@ -624,6 +624,7 @@ int FP4_YYY_sqrt(FP4_YYY *r,FP4_YYY* x) FP2_YYY_mul_ip(&s); FP2_YYY_norm(&s); FP2_YYY_sub(&a,&a,&s); // a-=txx(s) + FP2_YYY_norm(&a); if (!FP2_YYY_sqrt(&s,&a)) return 0; diff --git a/src/fp8.c.in b/src/fp8.c.in index 9fe0452..e4557df 100644 --- a/src/fp8.c.in +++ b/src/fp8.c.in @@ -614,12 +614,12 @@ int FP8_YYY_sqrt(FP8_YYY *r,FP8_YYY* x) FP4_YYY_times_i(&s); FP4_YYY_norm(&s); FP4_YYY_sub(&a,&a,&s); // a-=txx(s) + FP4_YYY_norm(&a); if (!FP4_YYY_sqrt(&s,&a)) return 0; FP4_YYY_sqr(&t,&s); - FP4_YYY_copy(&t,&(x->a)); FP4_YYY_add(&a,&t,&s); FP4_YYY_norm(&a); @@ -635,13 +635,13 @@ int FP8_YYY_sqrt(FP8_YYY *r,FP8_YYY* x) FP4_YYY_copy(&t,&(x->b)); FP4_YYY_add(&s,&a,&a); + FP4_YYY_norm(&s); FP4_YYY_inv(&s,&s); FP4_YYY_mul(&t,&t,&s); FP8_YYY_from_FP4s(r,&a,&t); return 1; - }