summaryrefslogtreecommitdiff
path: root/app/openssl/crypto/bn/exptest.c
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-15 16:22:58 +0100
committerParménides GV <parmegv@sdf.org>2014-12-15 16:22:58 +0100
commit18fef7c99aa36b3e5622b3865f36d78d0879e92d (patch)
tree7a04fc87318d5008bbc1f1ac145ebb505bb5238c /app/openssl/crypto/bn/exptest.c
parent56fe0400b8983ce57112ed5a0f993985a87741c0 (diff)
parent33c5958a18599267820f73b151d8161d83f93d88 (diff)
Merge branch 'research/Test-on-Android-5-#6543' into develop
Diffstat (limited to 'app/openssl/crypto/bn/exptest.c')
-rw-r--r--app/openssl/crypto/bn/exptest.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/app/openssl/crypto/bn/exptest.c b/app/openssl/crypto/bn/exptest.c
index 074a8e88..5fa02a12 100644
--- a/app/openssl/crypto/bn/exptest.c
+++ b/app/openssl/crypto/bn/exptest.c
@@ -71,6 +71,43 @@
static const char rnd_seed[] = "string to make the random number generator think it has entropy";
+/* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success. */
+static int test_exp_mod_zero() {
+ BIGNUM a, p, m;
+ BIGNUM r;
+ BN_CTX *ctx = BN_CTX_new();
+ int ret = 1;
+
+ BN_init(&m);
+ BN_one(&m);
+
+ BN_init(&a);
+ BN_one(&a);
+
+ BN_init(&p);
+ BN_zero(&p);
+
+ BN_init(&r);
+ BN_mod_exp(&r, &a, &p, &m, ctx);
+ BN_CTX_free(ctx);
+
+ if (BN_is_zero(&r))
+ ret = 0;
+ else
+ {
+ printf("1**0 mod 1 = ");
+ BN_print_fp(stdout, &r);
+ printf(", should be 0\n");
+ }
+
+ BN_free(&r);
+ BN_free(&a);
+ BN_free(&p);
+ BN_free(&m);
+
+ return ret;
+}
+
int main(int argc, char *argv[])
{
BN_CTX *ctx;
@@ -190,7 +227,13 @@ int main(int argc, char *argv[])
ERR_remove_thread_state(NULL);
CRYPTO_mem_leaks(out);
BIO_free(out);
- printf(" done\n");
+ printf("\n");
+
+ if (test_exp_mod_zero() != 0)
+ goto err;
+
+ printf("done\n");
+
EXIT(0);
err:
ERR_load_crypto_strings();