diff options
Diffstat (limited to 'regress/lib/libcrypto/exp')
-rw-r--r-- | regress/lib/libcrypto/exp/Makefile | 6 | ||||
-rw-r--r-- | regress/lib/libcrypto/exp/exptest.c | 56 |
2 files changed, 58 insertions, 4 deletions
diff --git a/regress/lib/libcrypto/exp/Makefile b/regress/lib/libcrypto/exp/Makefile index 39142014315..890b38e9fe9 100644 --- a/regress/lib/libcrypto/exp/Makefile +++ b/regress/lib/libcrypto/exp/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ +# $OpenBSD: Makefile,v 1.4 2017/01/21 09:38:58 beck Exp $ PROG= exptest -LDADD= -lcrypto +LDADD= ${CRYPTO_INT} DPADD= ${LIBCRYPTO} WARNINGS= Yes -CFLAGS+= -DLIBRESSL_INTERNAL -Werror +CFLAGS+= -Werror .include <bsd.regress.mk> diff --git a/regress/lib/libcrypto/exp/exptest.c b/regress/lib/libcrypto/exp/exptest.c index 45ca5ac5f57..375628cb251 100644 --- a/regress/lib/libcrypto/exp/exptest.c +++ b/regress/lib/libcrypto/exp/exptest.c @@ -64,6 +64,15 @@ #include <openssl/bn.h> #include <openssl/err.h> +int BN_mod_exp_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_mod_exp_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_mod_exp_mont_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp_mont_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); + #define NUM_BITS (BN_BITS*2) /* @@ -116,6 +125,18 @@ static int test_exp_mod_zero(void) if (!a_is_zero_mod_one("BN_mod_exp", &r, &a)) failed = 1; + if (!BN_mod_exp_ct(&r, &a, &p, &m, ctx)) + goto err; + + if (!a_is_zero_mod_one("BN_mod_exp_ct", &r, &a)) + failed = 1; + + if (!BN_mod_exp_nonct(&r, &a, &p, &m, ctx)) + goto err; + + if (!a_is_zero_mod_one("BN_mod_exp_nonct", &r, &a)) + failed = 1; + if (!BN_mod_exp_recp(&r, &a, &p, &m, ctx)) goto err; @@ -134,6 +155,18 @@ static int test_exp_mod_zero(void) if (!a_is_zero_mod_one("BN_mod_exp_mont", &r, &a)) failed = 1; + if (!BN_mod_exp_mont_ct(&r, &a, &p, &m, ctx, NULL)) + goto err; + + if (!a_is_zero_mod_one("BN_mod_exp_mont_ct", &r, &a)) + failed = 1; + + if (!BN_mod_exp_mont_nonct(&r, &a, &p, &m, ctx, NULL)) + goto err; + + if (!a_is_zero_mod_one("BN_mod_exp_mont_nonct", &r, &a)) + failed = 1; + if (!BN_mod_exp_mont_consttime(&r, &a, &p, &m, ctx, NULL)) { goto err; } @@ -175,7 +208,8 @@ int main(int argc, char *argv[]) BIO *out = NULL; int i, ret; unsigned char c; - BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple, *a, *b, *m; + BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple, + *r_mont_ct, *r_mont_nonct, *a, *b, *m; ERR_load_BN_strings(); @@ -184,6 +218,8 @@ int main(int argc, char *argv[]) exit(1); r_mont = BN_new(); r_mont_const = BN_new(); + r_mont_ct = BN_new(); + r_mont_nonct = BN_new(); r_recp = BN_new(); r_simple = BN_new(); a = BN_new(); @@ -221,6 +257,20 @@ int main(int argc, char *argv[]) exit(1); } + ret = BN_mod_exp_mont_ct(r_mont_ct, a, b, m, ctx, NULL); + if (ret <= 0) { + printf("BN_mod_exp_mont_ct() problems\n"); + ERR_print_errors(out); + exit(1); + } + + ret = BN_mod_exp_mont_nonct(r_mont_nonct, a, b, m, ctx, NULL); + if (ret <= 0) { + printf("BN_mod_exp_mont_nonct() problems\n"); + ERR_print_errors(out); + exit(1); + } + ret = BN_mod_exp_recp(r_recp, a, b, m, ctx); if (ret <= 0) { printf("BN_mod_exp_recp() problems\n"); @@ -254,6 +304,10 @@ int main(int argc, char *argv[]) printf("\nsimple and mont const time results differ\n"); if (BN_cmp(r_simple, r_recp) != 0) printf("\nsimple and recp results differ\n"); + if (BN_cmp(r_mont, r_mont_ct) != 0) + printf("\nmont_ct and mont results differ\n"); + if (BN_cmp(r_mont_ct, r_mont_nonct) != 0) + printf("\nmont_ct and mont_nonct results differ\n"); printf("a (%3d) = ", BN_num_bits(a)); BN_print(out, a); |