summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn')
-rw-r--r--src/lib/libcrypto/bn/Makefile79
-rw-r--r--src/lib/libcrypto/bn/bntest.c38
-rw-r--r--src/lib/libcrypto/bn/exptest.c4
3 files changed, 54 insertions, 67 deletions
diff --git a/src/lib/libcrypto/bn/Makefile b/src/lib/libcrypto/bn/Makefile
index f5e8f65a46..aabc4f56b8 100644
--- a/src/lib/libcrypto/bn/Makefile
+++ b/src/lib/libcrypto/bn/Makefile
@@ -12,8 +12,6 @@ MAKEFILE= Makefile
12AR= ar r 12AR= ar r
13 13
14BN_ASM= bn_asm.o 14BN_ASM= bn_asm.o
15# or use
16#BN_ASM= bn86-elf.o
17 15
18CFLAGS= $(INCLUDES) $(CFLAG) 16CFLAGS= $(INCLUDES) $(CFLAG)
19ASFLAGS= $(INCLUDES) $(ASFLAG) 17ASFLAGS= $(INCLUDES) $(ASFLAG)
@@ -28,13 +26,13 @@ LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
28 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \ 26 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
29 bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \ 27 bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \
30 bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \ 28 bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \
31 bn_depr.c bn_x931p.c bn_const.c bn_opt.c 29 bn_depr.c bn_const.c
32 30
33LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \ 31LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \
34 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \ 32 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
35 bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \ 33 bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \
36 bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_gf2m.o bn_nist.o \ 34 bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_gf2m.o bn_nist.o \
37 bn_depr.o bn_x931p.o bn_const.o bn_opt.o 35 bn_depr.o bn_const.o
38 36
39SRC= $(LIBSRC) 37SRC= $(LIBSRC)
40 38
@@ -58,36 +56,25 @@ bnbug: bnbug.c ../../libcrypto.a top
58 cc -g -I../../include bnbug.c -o bnbug ../../libcrypto.a 56 cc -g -I../../include bnbug.c -o bnbug ../../libcrypto.a
59 57
60lib: $(LIBOBJ) 58lib: $(LIBOBJ)
61 $(ARX) $(LIB) $(LIBOBJ) 59 $(AR) $(LIB) $(LIBOBJ)
62 $(RANLIB) $(LIB) || echo Never mind. 60 $(RANLIB) $(LIB) || echo Never mind.
63 @touch lib 61 @touch lib
64 62
65# ELF 63bn-586.s: asm/bn-586.pl ../perlasm/x86asm.pl
66bn86-elf.s: asm/bn-586.pl ../perlasm/x86asm.pl 64 $(PERL) asm/bn-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
67 (cd asm; $(PERL) bn-586.pl elf $(CFLAGS) > ../$@) 65co-586.s: asm/co-586.pl ../perlasm/x86asm.pl
68co86-elf.s: asm/co-586.pl ../perlasm/x86asm.pl 66 $(PERL) asm/co-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
69 (cd asm; $(PERL) co-586.pl elf $(CFLAGS) > ../$@) 67x86-mont.s: asm/x86-mont.pl ../perlasm/x86asm.pl
70mo86-elf.s: asm/mo-586.pl ../perlasm/x86asm.pl 68 $(PERL) asm/x86-mont.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
71 (cd asm; $(PERL) mo-586.pl elf $(CFLAGS) > ../$@)
72# COFF
73bn86-cof.s: asm/bn-586.pl ../perlasm/x86asm.pl
74 (cd asm; $(PERL) bn-586.pl coff $(CFLAGS) > ../$@)
75co86-cof.s: asm/co-586.pl ../perlasm/x86asm.pl
76 (cd asm; $(PERL) co-586.pl coff $(CFLAGS) > ../$@)
77mo86-cof.s: asm/mo-586.pl ../perlasm/x86asm.pl
78 (cd asm; $(PERL) mo-586.pl coff $(CFLAGS) > ../$@)
79# a.out
80bn86-out.s: asm/bn-586.pl ../perlasm/x86asm.pl
81 (cd asm; $(PERL) bn-586.pl a.out $(CFLAGS) > ../$@)
82co86-out.s: asm/co-586.pl ../perlasm/x86asm.pl
83 (cd asm; $(PERL) co-586.pl a.out $(CFLAGS) > ../$@)
84mo86-out.s: asm/mo-586.pl ../perlasm/x86asm.pl
85 (cd asm; $(PERL) mo-586.pl a.out $(CFLAGS) > ../$@)
86 69
87sparcv8.o: asm/sparcv8.S 70sparcv8.o: asm/sparcv8.S
88 $(CC) $(CFLAGS) -c asm/sparcv8.S 71 $(CC) $(CFLAGS) -c asm/sparcv8.S
89sparcv8plus.o: asm/sparcv8plus.S 72bn-sparcv9.o: asm/sparcv8plus.S
90 $(CC) $(CFLAGS) -c asm/sparcv8plus.S 73 $(CC) $(CFLAGS) -c -o $@ asm/sparcv8plus.S
74sparcv9a-mont.s: asm/sparcv9a-mont.pl
75 $(PERL) asm/sparcv9a-mont.pl $(CFLAGS) > $@
76sparcv9-mont.s: asm/sparcv9-mont.pl
77 $(PERL) asm/sparcv9-mont.pl $(CFLAGS) > $@
91 78
92bn-mips3.o: asm/mips3.s 79bn-mips3.o: asm/mips3.s
93 @if [ "$(CC)" = "gcc" ]; then \ 80 @if [ "$(CC)" = "gcc" ]; then \
@@ -95,10 +82,13 @@ bn-mips3.o: asm/mips3.s
95 as -$$ABI -O -o $@ asm/mips3.s; \ 82 as -$$ABI -O -o $@ asm/mips3.s; \
96 else $(CC) -c $(CFLAGS) -o $@ asm/mips3.s; fi 83 else $(CC) -c $(CFLAGS) -o $@ asm/mips3.s; fi
97 84
85bn-s390x.o: asm/s390x.S
86 $(CC) $(CFLAGS) -c -o $@ asm/s390x.S
87
98x86_64-gcc.o: asm/x86_64-gcc.c 88x86_64-gcc.o: asm/x86_64-gcc.c
99 $(CC) $(CFLAGS) -c -o $@ asm/x86_64-gcc.c 89 $(CC) $(CFLAGS) -c -o $@ asm/x86_64-gcc.c
100x86_64-mont.s: asm/x86_64-mont.pl 90x86_64-mont.s: asm/x86_64-mont.pl
101 $(PERL) asm/x86_64-mont.pl $@ 91 $(PERL) asm/x86_64-mont.pl $(PERLASM_SCHEME) > $@
102 92
103bn-ia64.s: asm/ia64.S 93bn-ia64.s: asm/ia64.S
104 $(CC) $(CFLAGS) -E asm/ia64.S > $@ 94 $(CC) $(CFLAGS) -E asm/ia64.S > $@
@@ -111,12 +101,14 @@ pa-risc2.o: asm/pa-risc2.s
111 /usr/ccs/bin/as -o pa-risc2.o asm/pa-risc2.s 101 /usr/ccs/bin/as -o pa-risc2.o asm/pa-risc2.s
112 102
113# ppc - AIX, Linux, MacOS X... 103# ppc - AIX, Linux, MacOS X...
114linux_ppc32.s: asm/ppc.pl; $(PERL) $< $@ 104bn-ppc.s: asm/ppc.pl; $(PERL) asm/ppc.pl $(PERLASM_SCHEME) $@
115linux_ppc64.s: asm/ppc.pl; $(PERL) $< $@ 105ppc-mont.s: asm/ppc-mont.pl;$(PERL) asm/ppc-mont.pl $(PERLASM_SCHEME) $@
116aix_ppc32.s: asm/ppc.pl; $(PERL) asm/ppc.pl $@ 106
117aix_ppc64.s: asm/ppc.pl; $(PERL) asm/ppc.pl $@ 107alpha-mont.s: asm/alpha-mont.pl
118osx_ppc32.s: asm/ppc.pl; $(PERL) $< $@ 108 $(PERL) $< | $(CC) -E - | tee $@ > /dev/null
119osx_ppc64.s: asm/ppc.pl; $(PERL) $< $@ 109
110# GNU make "catch all"
111%-mont.s: asm/%-mont.pl; $(PERL) $< $(CFLAGS) > $@
120 112
121files: 113files:
122 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO 114 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
@@ -184,8 +176,11 @@ bn_blind.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
184bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 176bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
185bn_blind.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 177bn_blind.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
186bn_blind.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_blind.c bn_lcl.h 178bn_blind.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_blind.c bn_lcl.h
187bn_const.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h 179bn_const.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
188bn_const.o: ../../include/openssl/ossl_typ.h bn.h bn_const.c 180bn_const.o: ../../include/openssl/opensslconf.h
181bn_const.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
182bn_const.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
183bn_const.o: ../../include/openssl/symhacks.h bn.h bn_const.c
189bn_ctx.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h 184bn_ctx.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
190bn_ctx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 185bn_ctx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
191bn_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 186bn_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
@@ -292,13 +287,6 @@ bn_nist.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
292bn_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 287bn_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
293bn_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 288bn_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
294bn_nist.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_nist.c 289bn_nist.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_nist.c
295bn_opt.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
296bn_opt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
297bn_opt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
298bn_opt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
299bn_opt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
300bn_opt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
301bn_opt.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_opt.c
302bn_prime.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h 290bn_prime.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
303bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 291bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
304bn_prime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 292bn_prime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
@@ -357,6 +345,3 @@ bn_word.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
357bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 345bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
358bn_word.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 346bn_word.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
359bn_word.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_word.c 347bn_word.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_word.c
360bn_x931p.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
361bn_x931p.o: ../../include/openssl/opensslconf.h
362bn_x931p.o: ../../include/openssl/ossl_typ.h bn_x931p.c
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c
index cf190380f5..0cd99c5b4b 100644
--- a/src/lib/libcrypto/bn/bntest.c
+++ b/src/lib/libcrypto/bn/bntest.c
@@ -486,7 +486,7 @@ static void print_word(BIO *bp,BN_ULONG w)
486 return; 486 return;
487 } 487 }
488#endif 488#endif
489 BIO_printf(bp,"%lX",w); 489 BIO_printf(bp,BN_HEX_FMT1,w);
490 } 490 }
491 491
492int test_div_word(BIO *bp) 492int test_div_word(BIO *bp)
@@ -732,6 +732,8 @@ int test_mont(BIO *bp, BN_CTX *ctx)
732 BN_init(&n); 732 BN_init(&n);
733 733
734 mont=BN_MONT_CTX_new(); 734 mont=BN_MONT_CTX_new();
735 if (mont == NULL)
736 return 0;
735 737
736 BN_bntest_rand(&a,100,0,0); /**/ 738 BN_bntest_rand(&a,100,0,0); /**/
737 BN_bntest_rand(&b,100,0,0); /**/ 739 BN_bntest_rand(&b,100,0,0); /**/
@@ -1027,7 +1029,7 @@ int test_exp(BIO *bp, BN_CTX *ctx)
1027 BN_bntest_rand(a,20+i*5,0,0); /**/ 1029 BN_bntest_rand(a,20+i*5,0,0); /**/
1028 BN_bntest_rand(b,2+i,0,0); /**/ 1030 BN_bntest_rand(b,2+i,0,0); /**/
1029 1031
1030 if (!BN_exp(d,a,b,ctx)) 1032 if (BN_exp(d,a,b,ctx) <= 0)
1031 return(0); 1033 return(0);
1032 1034
1033 if (bp != NULL) 1035 if (bp != NULL)
@@ -1116,8 +1118,8 @@ int test_gf2m_mod(BIO *bp)
1116 { 1118 {
1117 BIGNUM *a,*b[2],*c,*d,*e; 1119 BIGNUM *a,*b[2],*c,*d,*e;
1118 int i, j, ret = 0; 1120 int i, j, ret = 0;
1119 unsigned int p0[] = {163,7,6,3,0}; 1121 int p0[] = {163,7,6,3,0,-1};
1120 unsigned int p1[] = {193,15,0}; 1122 int p1[] = {193,15,0,-1};
1121 1123
1122 a=BN_new(); 1124 a=BN_new();
1123 b[0]=BN_new(); 1125 b[0]=BN_new();
@@ -1174,8 +1176,8 @@ int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx)
1174 { 1176 {
1175 BIGNUM *a,*b[2],*c,*d,*e,*f,*g,*h; 1177 BIGNUM *a,*b[2],*c,*d,*e,*f,*g,*h;
1176 int i, j, ret = 0; 1178 int i, j, ret = 0;
1177 unsigned int p0[] = {163,7,6,3,0}; 1179 int p0[] = {163,7,6,3,0,-1};
1178 unsigned int p1[] = {193,15,0}; 1180 int p1[] = {193,15,0,-1};
1179 1181
1180 a=BN_new(); 1182 a=BN_new();
1181 b[0]=BN_new(); 1183 b[0]=BN_new();
@@ -1245,8 +1247,8 @@ int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx)
1245 { 1247 {
1246 BIGNUM *a,*b[2],*c,*d; 1248 BIGNUM *a,*b[2],*c,*d;
1247 int i, j, ret = 0; 1249 int i, j, ret = 0;
1248 unsigned int p0[] = {163,7,6,3,0}; 1250 int p0[] = {163,7,6,3,0,-1};
1249 unsigned int p1[] = {193,15,0}; 1251 int p1[] = {193,15,0,-1};
1250 1252
1251 a=BN_new(); 1253 a=BN_new();
1252 b[0]=BN_new(); 1254 b[0]=BN_new();
@@ -1304,8 +1306,8 @@ int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx)
1304 { 1306 {
1305 BIGNUM *a,*b[2],*c,*d; 1307 BIGNUM *a,*b[2],*c,*d;
1306 int i, j, ret = 0; 1308 int i, j, ret = 0;
1307 unsigned int p0[] = {163,7,6,3,0}; 1309 int p0[] = {163,7,6,3,0,-1};
1308 unsigned int p1[] = {193,15,0}; 1310 int p1[] = {193,15,0,-1};
1309 1311
1310 a=BN_new(); 1312 a=BN_new();
1311 b[0]=BN_new(); 1313 b[0]=BN_new();
@@ -1359,8 +1361,8 @@ int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx)
1359 { 1361 {
1360 BIGNUM *a,*b[2],*c,*d,*e,*f; 1362 BIGNUM *a,*b[2],*c,*d,*e,*f;
1361 int i, j, ret = 0; 1363 int i, j, ret = 0;
1362 unsigned int p0[] = {163,7,6,3,0}; 1364 int p0[] = {163,7,6,3,0,-1};
1363 unsigned int p1[] = {193,15,0}; 1365 int p1[] = {193,15,0,-1};
1364 1366
1365 a=BN_new(); 1367 a=BN_new();
1366 b[0]=BN_new(); 1368 b[0]=BN_new();
@@ -1422,8 +1424,8 @@ int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx)
1422 { 1424 {
1423 BIGNUM *a,*b[2],*c,*d,*e,*f; 1425 BIGNUM *a,*b[2],*c,*d,*e,*f;
1424 int i, j, ret = 0; 1426 int i, j, ret = 0;
1425 unsigned int p0[] = {163,7,6,3,0}; 1427 int p0[] = {163,7,6,3,0,-1};
1426 unsigned int p1[] = {193,15,0}; 1428 int p1[] = {193,15,0,-1};
1427 1429
1428 a=BN_new(); 1430 a=BN_new();
1429 b[0]=BN_new(); 1431 b[0]=BN_new();
@@ -1493,8 +1495,8 @@ int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx)
1493 { 1495 {
1494 BIGNUM *a,*b[2],*c,*d,*e,*f; 1496 BIGNUM *a,*b[2],*c,*d,*e,*f;
1495 int i, j, ret = 0; 1497 int i, j, ret = 0;
1496 unsigned int p0[] = {163,7,6,3,0}; 1498 int p0[] = {163,7,6,3,0,-1};
1497 unsigned int p1[] = {193,15,0}; 1499 int p1[] = {193,15,0,-1};
1498 1500
1499 a=BN_new(); 1501 a=BN_new();
1500 b[0]=BN_new(); 1502 b[0]=BN_new();
@@ -1552,8 +1554,8 @@ int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx)
1552 { 1554 {
1553 BIGNUM *a,*b[2],*c,*d,*e; 1555 BIGNUM *a,*b[2],*c,*d,*e;
1554 int i, j, s = 0, t, ret = 0; 1556 int i, j, s = 0, t, ret = 0;
1555 unsigned int p0[] = {163,7,6,3,0}; 1557 int p0[] = {163,7,6,3,0,-1};
1556 unsigned int p1[] = {193,15,0}; 1558 int p1[] = {193,15,0,-1};
1557 1559
1558 a=BN_new(); 1560 a=BN_new();
1559 b[0]=BN_new(); 1561 b[0]=BN_new();
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c
index f598a07cf5..074a8e882a 100644
--- a/src/lib/libcrypto/bn/exptest.c
+++ b/src/lib/libcrypto/bn/exptest.c
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
163 { 163 {
164 if (BN_cmp(r_simple,r_mont) != 0) 164 if (BN_cmp(r_simple,r_mont) != 0)
165 printf("\nsimple and mont results differ\n"); 165 printf("\nsimple and mont results differ\n");
166 if (BN_cmp(r_simple,r_mont) != 0) 166 if (BN_cmp(r_simple,r_mont_const) != 0)
167 printf("\nsimple and mont const time results differ\n"); 167 printf("\nsimple and mont const time results differ\n");
168 if (BN_cmp(r_simple,r_recp) != 0) 168 if (BN_cmp(r_simple,r_recp) != 0)
169 printf("\nsimple and recp results differ\n"); 169 printf("\nsimple and recp results differ\n");
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
187 BN_free(b); 187 BN_free(b);
188 BN_free(m); 188 BN_free(m);
189 BN_CTX_free(ctx); 189 BN_CTX_free(ctx);
190 ERR_remove_state(0); 190 ERR_remove_thread_state(NULL);
191 CRYPTO_mem_leaks(out); 191 CRYPTO_mem_leaks(out);
192 BIO_free(out); 192 BIO_free(out);
193 printf(" done\n"); 193 printf(" done\n");