diff options
Diffstat (limited to 'src/lib/libcrypto/bn/exptest.c')
-rw-r--r-- | src/lib/libcrypto/bn/exptest.c | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c index 67dc95d726..9e4ae91d20 100644 --- a/src/lib/libcrypto/bn/exptest.c +++ b/src/lib/libcrypto/bn/exptest.c | |||
@@ -59,30 +59,31 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <string.h> | 61 | #include <string.h> |
62 | #include "bio.h" | 62 | #include <openssl/bio.h> |
63 | #include "bn.h" | 63 | #include <openssl/bn.h> |
64 | #include "rand.h" | 64 | #include <openssl/rand.h> |
65 | #include "err.h" | 65 | #include <openssl/err.h> |
66 | #ifdef WINDOWS | 66 | #ifdef WINDOWS |
67 | #include "../bio/bss_file.c" | 67 | #include "../bio/bss_file.c" |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | #define NUM_BITS (BN_BITS*2) | 70 | #define NUM_BITS (BN_BITS*2) |
71 | 71 | ||
72 | int main(argc,argv) | 72 | int main(int argc, char *argv[]) |
73 | int argc; | ||
74 | char *argv[]; | ||
75 | { | 73 | { |
76 | BN_CTX *ctx; | 74 | BN_CTX *ctx; |
77 | BIO *out=NULL; | 75 | BIO *out=NULL; |
78 | int i,ret; | 76 | int i,ret; |
79 | unsigned char c; | 77 | unsigned char c; |
80 | BIGNUM *r_mont,*r_recp,*a,*b,*m; | 78 | BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m; |
79 | |||
80 | ERR_load_BN_strings(); | ||
81 | 81 | ||
82 | ctx=BN_CTX_new(); | 82 | ctx=BN_CTX_new(); |
83 | if (ctx == NULL) exit(1); | 83 | if (ctx == NULL) exit(1); |
84 | r_mont=BN_new(); | 84 | r_mont=BN_new(); |
85 | r_recp=BN_new(); | 85 | r_recp=BN_new(); |
86 | r_simple=BN_new(); | ||
86 | a=BN_new(); | 87 | a=BN_new(); |
87 | b=BN_new(); | 88 | b=BN_new(); |
88 | m=BN_new(); | 89 | m=BN_new(); |
@@ -114,29 +115,52 @@ char *argv[]; | |||
114 | 115 | ||
115 | ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); | 116 | ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); |
116 | if (ret <= 0) | 117 | if (ret <= 0) |
117 | { printf("BN_mod_exp_mont() problems\n"); exit(1); } | 118 | { |
119 | printf("BN_mod_exp_mont() problems\n"); | ||
120 | ERR_print_errors(out); | ||
121 | exit(1); | ||
122 | } | ||
118 | 123 | ||
119 | ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); | 124 | ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); |
120 | if (ret <= 0) | 125 | if (ret <= 0) |
121 | { printf("BN_mod_exp_recp() problems\n"); exit(1); } | ||
122 | |||
123 | if (BN_cmp(r_mont,r_recp) != 0) | ||
124 | { | 126 | { |
125 | printf("\nmont and recp results differ\n"); | 127 | printf("BN_mod_exp_recp() problems\n"); |
128 | ERR_print_errors(out); | ||
129 | exit(1); | ||
130 | } | ||
131 | |||
132 | ret=BN_mod_exp_simple(r_simple,a,b,m,ctx); | ||
133 | if (ret <= 0) | ||
134 | { | ||
135 | printf("BN_mod_exp_simple() problems\n"); | ||
136 | ERR_print_errors(out); | ||
137 | exit(1); | ||
138 | } | ||
139 | |||
140 | if (BN_cmp(r_simple, r_mont) == 0 | ||
141 | && BN_cmp(r_simple,r_recp) == 0) | ||
142 | { | ||
143 | printf("."); | ||
144 | fflush(stdout); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | if (BN_cmp(r_simple,r_mont) != 0) | ||
149 | printf("\nsimple and mont results differ\n"); | ||
150 | if (BN_cmp(r_simple,r_recp) != 0) | ||
151 | printf("\nsimple and recp results differ\n"); | ||
152 | |||
126 | printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); | 153 | printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); |
127 | printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); | 154 | printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); |
128 | printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); | 155 | printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); |
156 | printf("\nsimple ="); BN_print(out,r_simple); | ||
129 | printf("\nrecp ="); BN_print(out,r_recp); | 157 | printf("\nrecp ="); BN_print(out,r_recp); |
130 | printf("\nmont ="); BN_print(out,r_mont); | 158 | printf("\nmont ="); BN_print(out,r_mont); |
131 | printf("\n"); | 159 | printf("\n"); |
132 | exit(1); | 160 | exit(1); |
133 | } | 161 | } |
134 | else | ||
135 | { | ||
136 | printf("."); | ||
137 | fflush(stdout); | ||
138 | } | ||
139 | } | 162 | } |
163 | CRYPTO_mem_leaks(out); | ||
140 | printf(" done\n"); | 164 | printf(" done\n"); |
141 | exit(0); | 165 | exit(0); |
142 | err: | 166 | err: |