diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/bn/exptest.c | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c index 67dc95d726..5ca570d1a8 100644 --- a/src/lib/libcrypto/bn/exptest.c +++ b/src/lib/libcrypto/bn/exptest.c | |||
| @@ -59,30 +59,37 @@ | |||
| 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 OPENSSL_SYS_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 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; |
| 73 | int argc; | 73 | |
| 74 | char *argv[]; | 74 | int main(int argc, char *argv[]) |
| 75 | { | 75 | { |
| 76 | BN_CTX *ctx; | 76 | BN_CTX *ctx; |
| 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,*a,*b,*m; | 80 | BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m; |
| 81 | |||
| 82 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't | ||
| 83 | * even check its return value | ||
| 84 | * (which we should) */ | ||
| 85 | |||
| 86 | ERR_load_BN_strings(); | ||
| 81 | 87 | ||
| 82 | ctx=BN_CTX_new(); | 88 | ctx=BN_CTX_new(); |
| 83 | if (ctx == NULL) exit(1); | 89 | if (ctx == NULL) exit(1); |
| 84 | r_mont=BN_new(); | 90 | r_mont=BN_new(); |
| 85 | r_recp=BN_new(); | 91 | r_recp=BN_new(); |
| 92 | r_simple=BN_new(); | ||
| 86 | a=BN_new(); | 93 | a=BN_new(); |
| 87 | b=BN_new(); | 94 | b=BN_new(); |
| 88 | m=BN_new(); | 95 | m=BN_new(); |
| @@ -114,29 +121,61 @@ char *argv[]; | |||
| 114 | 121 | ||
| 115 | ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); | 122 | ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); |
| 116 | if (ret <= 0) | 123 | if (ret <= 0) |
| 117 | { printf("BN_mod_exp_mont() problems\n"); exit(1); } | 124 | { |
| 125 | printf("BN_mod_exp_mont() problems\n"); | ||
| 126 | ERR_print_errors(out); | ||
| 127 | exit(1); | ||
| 128 | } | ||
| 118 | 129 | ||
| 119 | ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); | 130 | ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); |
| 120 | if (ret <= 0) | 131 | if (ret <= 0) |
| 121 | { printf("BN_mod_exp_recp() problems\n"); exit(1); } | ||
| 122 | |||
| 123 | if (BN_cmp(r_mont,r_recp) != 0) | ||
| 124 | { | 132 | { |
| 125 | printf("\nmont and recp results differ\n"); | 133 | printf("BN_mod_exp_recp() problems\n"); |
| 134 | ERR_print_errors(out); | ||
| 135 | exit(1); | ||
| 136 | } | ||
| 137 | |||
| 138 | ret=BN_mod_exp_simple(r_simple,a,b,m,ctx); | ||
| 139 | if (ret <= 0) | ||
| 140 | { | ||
| 141 | printf("BN_mod_exp_simple() problems\n"); | ||
| 142 | ERR_print_errors(out); | ||
| 143 | exit(1); | ||
| 144 | } | ||
| 145 | |||
| 146 | if (BN_cmp(r_simple, r_mont) == 0 | ||
| 147 | && BN_cmp(r_simple,r_recp) == 0) | ||
| 148 | { | ||
| 149 | printf("."); | ||
| 150 | fflush(stdout); | ||
| 151 | } | ||
| 152 | else | ||
| 153 | { | ||
| 154 | if (BN_cmp(r_simple,r_mont) != 0) | ||
| 155 | printf("\nsimple and mont results differ\n"); | ||
| 156 | if (BN_cmp(r_simple,r_recp) != 0) | ||
| 157 | printf("\nsimple and recp results differ\n"); | ||
| 158 | |||
| 126 | printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); | 159 | printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); |
| 127 | printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); | 160 | printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); |
| 128 | printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); | 161 | printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); |
| 162 | printf("\nsimple ="); BN_print(out,r_simple); | ||
| 129 | printf("\nrecp ="); BN_print(out,r_recp); | 163 | printf("\nrecp ="); BN_print(out,r_recp); |
| 130 | printf("\nmont ="); BN_print(out,r_mont); | 164 | printf("\nmont ="); BN_print(out,r_mont); |
| 131 | printf("\n"); | 165 | printf("\n"); |
| 132 | exit(1); | 166 | exit(1); |
| 133 | } | 167 | } |
| 134 | else | ||
| 135 | { | ||
| 136 | printf("."); | ||
| 137 | fflush(stdout); | ||
| 138 | } | ||
| 139 | } | 168 | } |
| 169 | BN_free(r_mont); | ||
| 170 | BN_free(r_recp); | ||
| 171 | BN_free(r_simple); | ||
| 172 | BN_free(a); | ||
| 173 | BN_free(b); | ||
| 174 | BN_free(m); | ||
| 175 | BN_CTX_free(ctx); | ||
| 176 | ERR_remove_state(0); | ||
| 177 | CRYPTO_mem_leaks(out); | ||
| 178 | BIO_free(out); | ||
| 140 | printf(" done\n"); | 179 | printf(" done\n"); |
| 141 | exit(0); | 180 | exit(0); |
| 142 | err: | 181 | err: |
