提交 adf65243 编写于 作者: M Matt Caswell

Test that a ^ 0 mod -1 is always 0

Check all functions that do this.
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6355)
上级 4aa5b725
...@@ -2063,6 +2063,53 @@ err: ...@@ -2063,6 +2063,53 @@ err:
return st; return st;
} }
static int test_expmodone(void)
{
int ret = 0, i;
BIGNUM *r = BN_new();
BIGNUM *a = BN_new();
BIGNUM *p = BN_new();
BIGNUM *m = BN_new();
if (!TEST_ptr(r)
|| !TEST_ptr(a)
|| !TEST_ptr(p)
|| !TEST_ptr(p)
|| !TEST_ptr(m)
|| !TEST_true(BN_set_word(a, 1))
|| !TEST_true(BN_set_word(p, 0))
|| !TEST_true(BN_set_word(m, 1)))
goto err;
/* Calculate r = 1 ^ 0 mod 1, and check the result is always 0 */
for (i = 0; i < 2; i++) {
if (!TEST_true(BN_mod_exp(r, a, p, m, NULL))
|| !TEST_BN_eq_zero(r)
|| !TEST_true(BN_mod_exp_mont(r, a, p, m, NULL, NULL))
|| !TEST_BN_eq_zero(r)
|| !TEST_true(BN_mod_exp_mont_consttime(r, a, p, m, NULL, NULL))
|| !TEST_BN_eq_zero(r)
|| !TEST_true(BN_mod_exp_mont_word(r, 1, p, m, NULL, NULL))
|| !TEST_BN_eq_zero(r)
|| !TEST_true(BN_mod_exp_simple(r, a, p, m, NULL))
|| !TEST_BN_eq_zero(r)
|| !TEST_true(BN_mod_exp_recp(r, a, p, m, NULL))
|| !TEST_BN_eq_zero(r))
goto err;
/* Repeat for r = 1 ^ 0 mod -1 */
if (i == 0)
BN_set_negative(m, 1);
}
ret = 1;
err:
BN_free(r);
BN_free(a);
BN_free(p);
BN_free(m);
return ret;
}
static int test_smallprime(void) static int test_smallprime(void)
{ {
static const int kBits = 10; static const int kBits = 10;
...@@ -2189,6 +2236,7 @@ int setup_tests(void) ...@@ -2189,6 +2236,7 @@ int setup_tests(void)
ADD_TEST(test_negzero); ADD_TEST(test_negzero);
ADD_TEST(test_badmod); ADD_TEST(test_badmod);
ADD_TEST(test_expmodzero); ADD_TEST(test_expmodzero);
ADD_TEST(test_expmodone);
ADD_TEST(test_smallprime); ADD_TEST(test_smallprime);
ADD_TEST(test_swap); ADD_TEST(test_swap);
#ifndef OPENSSL_NO_EC2M #ifndef OPENSSL_NO_EC2M
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册