summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiod <>2014-07-11 20:52:59 +0000
committermiod <>2014-07-11 20:52:59 +0000
commitb09046247c3d356bf05192288c21568ec9b85567 (patch)
tree37e24197f94e9abf5d030efac40304f43b5255aa
parent31c7d116821af2f9c20ba5afd68a12129a3435fc (diff)
downloadopenbsd-b09046247c3d356bf05192288c21568ec9b85567.tar.gz
openbsd-b09046247c3d356bf05192288c21568ec9b85567.tar.bz2
openbsd-b09046247c3d356bf05192288c21568ec9b85567.zip
Another regress test for OpenSSL PR #3397 (Joyent 7704), from agl via OpenSSL
RT.
-rw-r--r--src/regress/lib/libcrypto/bn/general/bntest.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/regress/lib/libcrypto/bn/general/bntest.c b/src/regress/lib/libcrypto/bn/general/bntest.c
index 74a97e9c8a..7a902b823f 100644
--- a/src/regress/lib/libcrypto/bn/general/bntest.c
+++ b/src/regress/lib/libcrypto/bn/general/bntest.c
@@ -117,6 +117,7 @@ int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx);
117int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx); 117int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx);
118int test_kron(BIO *bp,BN_CTX *ctx); 118int test_kron(BIO *bp,BN_CTX *ctx);
119int test_sqrt(BIO *bp,BN_CTX *ctx); 119int test_sqrt(BIO *bp,BN_CTX *ctx);
120int test_mod_exp_sizes(BIO *bp, BN_CTX *ctx);
120int rand_neg(void); 121int rand_neg(void);
121static int results=0; 122static int results=0;
122 123
@@ -256,6 +257,12 @@ int main(int argc, char *argv[])
256 message(out,"BN_mod_sqrt"); 257 message(out,"BN_mod_sqrt");
257 if (!test_sqrt(out,ctx)) goto err; 258 if (!test_sqrt(out,ctx)) goto err;
258 (void)BIO_flush(out); 259 (void)BIO_flush(out);
260
261 message(out, "Modexp with different sizes");
262 if (!test_mod_exp_sizes(out, ctx))
263 goto err;
264 (void)BIO_flush(out);
265
259#ifndef OPENSSL_NO_EC2M 266#ifndef OPENSSL_NO_EC2M
260 message(out,"BN_GF2m_add"); 267 message(out,"BN_GF2m_add");
261 if (!test_gf2m_add(out)) goto err; 268 if (!test_gf2m_add(out)) goto err;
@@ -1998,3 +2005,53 @@ int rand_neg(void)
1998 2005
1999 return(sign[(neg++)%8]); 2006 return(sign[(neg++)%8]);
2000 } 2007 }
2008
2009int
2010test_mod_exp_sizes(BIO *bp, BN_CTX *ctx)
2011{
2012 BN_MONT_CTX *mont_ctx;
2013 BIGNUM *p, *x, *y, *r, *r2;
2014 int size;
2015 int ok = 0;
2016
2017 BN_CTX_start(ctx);
2018 p = BN_CTX_get(ctx);
2019 x = BN_CTX_get(ctx);
2020 y = BN_CTX_get(ctx);
2021 r = BN_CTX_get(ctx);
2022 r2 = BN_CTX_get(ctx);
2023 mont_ctx = BN_MONT_CTX_new();
2024
2025 if (r2 == NULL || mont_ctx == NULL)
2026 goto err;
2027
2028 if (!BN_generate_prime_ex(p, 32, 0, NULL, NULL, NULL) ||
2029 !BN_MONT_CTX_set(mont_ctx, p, ctx))
2030 goto err;
2031
2032 for (size = 32; size < 1024; size += 8) {
2033 if (!BN_rand(x, size, -1, 0) ||
2034 !BN_rand(y, size, -1, 0) ||
2035 !BN_mod_exp_mont_consttime(r, x, y, p, ctx, mont_ctx) ||
2036 !BN_mod_exp(r2, x, y, p, ctx))
2037 goto err;
2038
2039 if (BN_cmp(r, r2) != 0) {
2040 char *r_str = BN_bn2hex(r);
2041 char *r2_str = BN_bn2hex(r2);
2042
2043 printf("Incorrect answer at size %d: %s vs %s\n",
2044 size, r_str, r2_str);
2045 free(r_str);
2046 free(r2_str);
2047 goto err;
2048 }
2049 }
2050
2051 ok = 1;
2052
2053err:
2054 BN_MONT_CTX_free(mont_ctx);
2055 BN_CTX_end(ctx);
2056 return ok;
2057}