71 |
|
|
72 |
|
static const char rnd_seed[] = "string to make the random number generator think it has entropy"; |
73 |
|
|
74 |
+ |
/* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success. */ |
75 |
+ |
static int test_exp_mod_zero() { |
76 |
+ |
BIGNUM a, p, m; |
77 |
+ |
BIGNUM r; |
78 |
+ |
BN_CTX *ctx = BN_CTX_new(); |
79 |
+ |
int ret = 1; |
80 |
+ |
|
81 |
+ |
BN_init(&m); |
82 |
+ |
BN_one(&m); |
83 |
+ |
|
84 |
+ |
BN_init(&a); |
85 |
+ |
BN_one(&a); |
86 |
+ |
|
87 |
+ |
BN_init(&p); |
88 |
+ |
BN_zero(&p); |
89 |
+ |
|
90 |
+ |
BN_init(&r); |
91 |
+ |
BN_mod_exp(&r, &a, &p, &m, ctx); |
92 |
+ |
BN_CTX_free(ctx); |
93 |
+ |
|
94 |
+ |
if (BN_is_zero(&r)) |
95 |
+ |
ret = 0; |
96 |
+ |
else |
97 |
+ |
{ |
98 |
+ |
printf("1**0 mod 1 = "); |
99 |
+ |
BN_print_fp(stdout, &r); |
100 |
+ |
printf(", should be 0\n"); |
101 |
+ |
} |
102 |
+ |
|
103 |
+ |
BN_free(&r); |
104 |
+ |
BN_free(&a); |
105 |
+ |
BN_free(&p); |
106 |
+ |
BN_free(&m); |
107 |
+ |
|
108 |
+ |
return ret; |
109 |
+ |
} |
110 |
+ |
|
111 |
|
int main(int argc, char *argv[]) |
112 |
|
{ |
113 |
|
BN_CTX *ctx; |
227 |
|
ERR_remove_state(0); |
228 |
|
CRYPTO_mem_leaks(out); |
229 |
|
BIO_free(out); |
230 |
< |
printf(" done\n"); |
230 |
> |
printf("\n"); |
231 |
> |
|
232 |
> |
if (test_exp_mod_zero() != 0) |
233 |
> |
goto err; |
234 |
> |
|
235 |
> |
printf("done\n"); |
236 |
> |
|
237 |
|
EXIT(0); |
238 |
|
err: |
239 |
|
ERR_load_crypto_strings(); |