diff options
author | djm <> | 2006-06-27 05:05:40 +0000 |
---|---|---|
committer | djm <> | 2006-06-27 05:05:40 +0000 |
commit | 4f828b924f54507141fb95ebe49dfcd261945e85 (patch) | |
tree | f6b05913ca6b34db73a343a7bb36d57ff4105356 /src/lib/libcrypto/bn | |
parent | 588543a0946f1dbf0f1dd5135f8f6447486dc183 (diff) | |
download | openbsd-4f828b924f54507141fb95ebe49dfcd261945e85.tar.gz openbsd-4f828b924f54507141fb95ebe49dfcd261945e85.tar.bz2 openbsd-4f828b924f54507141fb95ebe49dfcd261945e85.zip |
import of openssl-0.9.7j
Diffstat (limited to 'src/lib/libcrypto/bn')
-rw-r--r-- | src/lib/libcrypto/bn/Makefile | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bntest.c | 56 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/expspeed.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/exptest.c | 18 |
4 files changed, 78 insertions, 6 deletions
diff --git a/src/lib/libcrypto/bn/Makefile b/src/lib/libcrypto/bn/Makefile index f693d35d87..9969d242cc 100644 --- a/src/lib/libcrypto/bn/Makefile +++ b/src/lib/libcrypto/bn/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | # | 1 | # |
2 | # SSLeay/crypto/bn/Makefile | 2 | # OpenSSL/crypto/bn/Makefile |
3 | # | 3 | # |
4 | 4 | ||
5 | DIR= bn | 5 | DIR= bn |
@@ -31,12 +31,12 @@ LIB=$(TOP)/libcrypto.a | |||
31 | LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \ | 31 | LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \ |
32 | bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \ | 32 | bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \ |
33 | bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \ | 33 | bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \ |
34 | bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c | 34 | bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_x931p.c |
35 | 35 | ||
36 | LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \ | 36 | LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \ |
37 | bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \ | 37 | bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \ |
38 | bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \ | 38 | bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \ |
39 | bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o | 39 | bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_x931p.o |
40 | 40 | ||
41 | SRC= $(LIBSRC) | 41 | SRC= $(LIBSRC) |
42 | 42 | ||
@@ -329,3 +329,5 @@ bn_word.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | |||
329 | bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | 329 | bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
330 | bn_word.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | 330 | bn_word.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h |
331 | bn_word.o: ../cryptlib.h bn_lcl.h bn_word.c | 331 | bn_word.o: ../cryptlib.h bn_lcl.h bn_word.c |
332 | bn_x931p.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h | ||
333 | bn_x931p.o: ../../include/openssl/opensslconf.h bn_x931p.c | ||
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c index 28cd3339da..685007d330 100644 --- a/src/lib/libcrypto/bn/bntest.c +++ b/src/lib/libcrypto/bn/bntest.c | |||
@@ -86,6 +86,7 @@ int test_mont(BIO *bp,BN_CTX *ctx); | |||
86 | int test_mod(BIO *bp,BN_CTX *ctx); | 86 | int test_mod(BIO *bp,BN_CTX *ctx); |
87 | int test_mod_mul(BIO *bp,BN_CTX *ctx); | 87 | int test_mod_mul(BIO *bp,BN_CTX *ctx); |
88 | int test_mod_exp(BIO *bp,BN_CTX *ctx); | 88 | int test_mod_exp(BIO *bp,BN_CTX *ctx); |
89 | int test_mod_exp_mont_consttime(BIO *bp,BN_CTX *ctx); | ||
89 | int test_exp(BIO *bp,BN_CTX *ctx); | 90 | int test_exp(BIO *bp,BN_CTX *ctx); |
90 | int test_kron(BIO *bp,BN_CTX *ctx); | 91 | int test_kron(BIO *bp,BN_CTX *ctx); |
91 | int test_sqrt(BIO *bp,BN_CTX *ctx); | 92 | int test_sqrt(BIO *bp,BN_CTX *ctx); |
@@ -213,6 +214,10 @@ int main(int argc, char *argv[]) | |||
213 | if (!test_mod_exp(out,ctx)) goto err; | 214 | if (!test_mod_exp(out,ctx)) goto err; |
214 | BIO_flush(out); | 215 | BIO_flush(out); |
215 | 216 | ||
217 | message(out,"BN_mod_exp_mont_consttime"); | ||
218 | if (!test_mod_exp_mont_consttime(out,ctx)) goto err; | ||
219 | BIO_flush(out); | ||
220 | |||
216 | message(out,"BN_exp"); | 221 | message(out,"BN_exp"); |
217 | if (!test_exp(out,ctx)) goto err; | 222 | if (!test_exp(out,ctx)) goto err; |
218 | BIO_flush(out); | 223 | BIO_flush(out); |
@@ -813,6 +818,57 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx) | |||
813 | return(1); | 818 | return(1); |
814 | } | 819 | } |
815 | 820 | ||
821 | int test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx) | ||
822 | { | ||
823 | BIGNUM *a,*b,*c,*d,*e; | ||
824 | int i; | ||
825 | |||
826 | a=BN_new(); | ||
827 | b=BN_new(); | ||
828 | c=BN_new(); | ||
829 | d=BN_new(); | ||
830 | e=BN_new(); | ||
831 | |||
832 | BN_bntest_rand(c,30,0,1); /* must be odd for montgomery */ | ||
833 | for (i=0; i<num2; i++) | ||
834 | { | ||
835 | BN_bntest_rand(a,20+i*5,0,0); /**/ | ||
836 | BN_bntest_rand(b,2+i,0,0); /**/ | ||
837 | |||
838 | if (!BN_mod_exp_mont_consttime(d,a,b,c,ctx,NULL)) | ||
839 | return(00); | ||
840 | |||
841 | if (bp != NULL) | ||
842 | { | ||
843 | if (!results) | ||
844 | { | ||
845 | BN_print(bp,a); | ||
846 | BIO_puts(bp," ^ "); | ||
847 | BN_print(bp,b); | ||
848 | BIO_puts(bp," % "); | ||
849 | BN_print(bp,c); | ||
850 | BIO_puts(bp," - "); | ||
851 | } | ||
852 | BN_print(bp,d); | ||
853 | BIO_puts(bp,"\n"); | ||
854 | } | ||
855 | BN_exp(e,a,b,ctx); | ||
856 | BN_sub(e,e,d); | ||
857 | BN_div(a,b,e,c,ctx); | ||
858 | if(!BN_is_zero(b)) | ||
859 | { | ||
860 | fprintf(stderr,"Modulo exponentiation test failed!\n"); | ||
861 | return 0; | ||
862 | } | ||
863 | } | ||
864 | BN_free(a); | ||
865 | BN_free(b); | ||
866 | BN_free(c); | ||
867 | BN_free(d); | ||
868 | BN_free(e); | ||
869 | return(1); | ||
870 | } | ||
871 | |||
816 | int test_exp(BIO *bp, BN_CTX *ctx) | 872 | int test_exp(BIO *bp, BN_CTX *ctx) |
817 | { | 873 | { |
818 | BIGNUM *a,*b,*d,*e,*one; | 874 | BIGNUM *a,*b,*d,*e,*one; |
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c index 07a1bcf51c..4d5f221f33 100644 --- a/src/lib/libcrypto/bn/expspeed.c +++ b/src/lib/libcrypto/bn/expspeed.c | |||
@@ -321,7 +321,7 @@ void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx) | |||
321 | #else /* TEST_SQRT */ | 321 | #else /* TEST_SQRT */ |
322 | "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d" | 322 | "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d" |
323 | #endif | 323 | #endif |
324 | " -> %8.3fms %5.1f (%ld)\n", | 324 | " -> %8.6fms %5.1f (%ld)\n", |
325 | #ifdef TEST_SQRT | 325 | #ifdef TEST_SQRT |
326 | P_MOD_64, | 326 | P_MOD_64, |
327 | #endif | 327 | #endif |
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c index b09cf88705..28aaac2ac1 100644 --- a/src/lib/libcrypto/bn/exptest.c +++ b/src/lib/libcrypto/bn/exptest.c | |||
@@ -77,7 +77,7 @@ int main(int argc, char *argv[]) | |||
77 | BIO *out=NULL; | 77 | BIO *out=NULL; |
78 | int i,ret; | 78 | int i,ret; |
79 | unsigned char c; | 79 | unsigned char c; |
80 | BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m; | 80 | BIGNUM *r_mont,*r_mont_const,*r_recp,*r_simple,*a,*b,*m; |
81 | 81 | ||
82 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't | 82 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't |
83 | * even check its return value | 83 | * even check its return value |
@@ -88,6 +88,7 @@ int main(int argc, char *argv[]) | |||
88 | ctx=BN_CTX_new(); | 88 | ctx=BN_CTX_new(); |
89 | if (ctx == NULL) EXIT(1); | 89 | if (ctx == NULL) EXIT(1); |
90 | r_mont=BN_new(); | 90 | r_mont=BN_new(); |
91 | r_mont_const=BN_new(); | ||
91 | r_recp=BN_new(); | 92 | r_recp=BN_new(); |
92 | r_simple=BN_new(); | 93 | r_simple=BN_new(); |
93 | a=BN_new(); | 94 | a=BN_new(); |
@@ -143,8 +144,17 @@ int main(int argc, char *argv[]) | |||
143 | EXIT(1); | 144 | EXIT(1); |
144 | } | 145 | } |
145 | 146 | ||
147 | ret=BN_mod_exp_mont_consttime(r_mont_const,a,b,m,ctx,NULL); | ||
148 | if (ret <= 0) | ||
149 | { | ||
150 | printf("BN_mod_exp_mont_consttime() problems\n"); | ||
151 | ERR_print_errors(out); | ||
152 | EXIT(1); | ||
153 | } | ||
154 | |||
146 | if (BN_cmp(r_simple, r_mont) == 0 | 155 | if (BN_cmp(r_simple, r_mont) == 0 |
147 | && BN_cmp(r_simple,r_recp) == 0) | 156 | && BN_cmp(r_simple,r_recp) == 0 |
157 | && BN_cmp(r_simple,r_mont_const) == 0) | ||
148 | { | 158 | { |
149 | printf("."); | 159 | printf("."); |
150 | fflush(stdout); | 160 | fflush(stdout); |
@@ -153,6 +163,8 @@ int main(int argc, char *argv[]) | |||
153 | { | 163 | { |
154 | if (BN_cmp(r_simple,r_mont) != 0) | 164 | if (BN_cmp(r_simple,r_mont) != 0) |
155 | printf("\nsimple and mont results differ\n"); | 165 | printf("\nsimple and mont results differ\n"); |
166 | if (BN_cmp(r_simple,r_mont) != 0) | ||
167 | printf("\nsimple and mont const time results differ\n"); | ||
156 | if (BN_cmp(r_simple,r_recp) != 0) | 168 | if (BN_cmp(r_simple,r_recp) != 0) |
157 | printf("\nsimple and recp results differ\n"); | 169 | printf("\nsimple and recp results differ\n"); |
158 | 170 | ||
@@ -162,11 +174,13 @@ int main(int argc, char *argv[]) | |||
162 | printf("\nsimple ="); BN_print(out,r_simple); | 174 | printf("\nsimple ="); BN_print(out,r_simple); |
163 | printf("\nrecp ="); BN_print(out,r_recp); | 175 | printf("\nrecp ="); BN_print(out,r_recp); |
164 | printf("\nmont ="); BN_print(out,r_mont); | 176 | printf("\nmont ="); BN_print(out,r_mont); |
177 | printf("\nmont_ct ="); BN_print(out,r_mont_const); | ||
165 | printf("\n"); | 178 | printf("\n"); |
166 | EXIT(1); | 179 | EXIT(1); |
167 | } | 180 | } |
168 | } | 181 | } |
169 | BN_free(r_mont); | 182 | BN_free(r_mont); |
183 | BN_free(r_mont_const); | ||
170 | BN_free(r_recp); | 184 | BN_free(r_recp); |
171 | BN_free(r_simple); | 185 | BN_free(r_simple); |
172 | BN_free(a); | 186 | BN_free(a); |