1 #include <openssl/bn.h>
2 #include <openssl/rand.h>
7 RAND_pseudo_bytes(x, 2);
8 return (x[0] + 2 * x[1]);
11 static void bug(char *m, BIGNUM *a, BIGNUM *b)
14 BN_print_fp(stdout, a);
16 BN_print_fp(stdout, b);
23 BIGNUM *a = BN_new(), *b = BN_new(), *c = BN_new(), *d = BN_new(),
24 *C = BN_new(), *D = BN_new();
25 BN_RECP_CTX *recp = BN_RECP_CTX_new();
26 BN_CTX *ctx = BN_CTX_new();
29 BN_pseudo_rand(a, Rand(), 0, 0);
30 BN_pseudo_rand(b, Rand(), 0, 0);
34 BN_RECP_CTX_set(recp, b, ctx);
35 if (BN_div(C, D, a, b, ctx) != 1)
36 bug("BN_div failed", a, b);
37 if (BN_div_recp(c, d, a, recp, ctx) != 1)
38 bug("BN_div_recp failed", a, b);
39 else if (BN_cmp(c, C) != 0 || BN_cmp(c, C) != 0)
40 bug("mismatch", a, b);