diff options
| author | miod <> | 2014-07-11 20:52:59 +0000 |
|---|---|---|
| committer | miod <> | 2014-07-11 20:52:59 +0000 |
| commit | c345ce5786a065d1f4eca21eadea4e5aa3f0a65e (patch) | |
| tree | 37e24197f94e9abf5d030efac40304f43b5255aa | |
| parent | d5aeb551a86a3aebf5e6501c43fc4086263d364c (diff) | |
| download | openbsd-c345ce5786a065d1f4eca21eadea4e5aa3f0a65e.tar.gz openbsd-c345ce5786a065d1f4eca21eadea4e5aa3f0a65e.tar.bz2 openbsd-c345ce5786a065d1f4eca21eadea4e5aa3f0a65e.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.c | 57 |
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); | |||
| 117 | int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx); | 117 | int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx); |
| 118 | int test_kron(BIO *bp,BN_CTX *ctx); | 118 | int test_kron(BIO *bp,BN_CTX *ctx); |
| 119 | int test_sqrt(BIO *bp,BN_CTX *ctx); | 119 | int test_sqrt(BIO *bp,BN_CTX *ctx); |
| 120 | int test_mod_exp_sizes(BIO *bp, BN_CTX *ctx); | ||
| 120 | int rand_neg(void); | 121 | int rand_neg(void); |
| 121 | static int results=0; | 122 | static 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 | |||
| 2009 | int | ||
| 2010 | test_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 | |||
| 2053 | err: | ||
| 2054 | BN_MONT_CTX_free(mont_ctx); | ||
| 2055 | BN_CTX_end(ctx); | ||
| 2056 | return ok; | ||
| 2057 | } | ||
