diff options
author | Bodo Möller <bodo@openssl.org> | 2000-11-30 00:43:41 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2000-11-30 00:43:41 +0000 |
commit | ac445acf6959ec21b19d3670369e107db2627213 (patch) | |
tree | 311f4d487d03099661652b5f0e2069038451f989 /crypto/bn | |
parent | 77ac92d00a795ef34ff0a169a87718780250ca54 (diff) |
bn_modfs.c is no longer needed, a BN_sqrt implementation
exists in bn_sqrt.c now
Diffstat (limited to 'crypto/bn')
-rw-r--r-- | crypto/bn/bn_modfs.c | 131 | ||||
-rw-r--r-- | crypto/bn/bn_modfs.h | 20 |
2 files changed, 0 insertions, 151 deletions
diff --git a/crypto/bn/bn_modfs.c b/crypto/bn/bn_modfs.c deleted file mode 100644 index b4c245cc49..0000000000 --- a/crypto/bn/bn_modfs.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * - * bn_modfs.c - * - * Some Modular Arithmetic Functions. - * - * Copyright (C) Lenka Fibikova 2000 - * - * - */ - - -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#include "bn_modfs.h" - -#define MAX_ROUNDS 10 - - -int BN_mod_sqrt(BIGNUM *x, BIGNUM *a, BIGNUM *p, BN_CTX *ctx) -/* x^2 = a (mod p) */ - { - int ret; - BIGNUM *n0, *n1, *r, *b, *m; - int max; - - assert(x != NULL && a != NULL && p != NULL && ctx != NULL); - assert(BN_cmp(a, p) < 0); - - ret = BN_kronecker(a, p, ctx); - if (ret < 0 || ret > 1) return 0; - if (ret == 0) - { - if (!BN_zero(x)) return 0; - return 1; - } - - BN_CTX_start(ctx); - n0 = BN_CTX_get(ctx); - n1 = BN_CTX_get(ctx); - if (n1 == NULL) goto err; - - if ((r = BN_new()) == NULL) goto err; - if ((b = BN_new()) == NULL) goto err; - if ((m = BN_new()) == NULL) goto err; - - - if (!BN_zero(n0)) goto err; - if (!BN_zero(n1)) goto err; - if (!BN_zero(r)) goto err; - if (!BN_zero(b)) goto err; - if (!BN_zero(m)) goto err; - - max = 0; - - do - { - if (max++ > MAX_ROUNDS) goto err; /* if p is not prime could never stop*/ - if (!BN_add_word(m, 1)) goto err; - ret = BN_kronecker(m, p, ctx); - if (ret < -1 || ret > 1) goto err; - } - while (ret != -1); - - if (BN_copy(n1, p) == NULL) goto err; - if (!BN_sub_word(n1, 1)) goto err; - - while (!BN_is_odd(n1)) - { - if (!BN_add_word(r, 1)) goto err; - if (!BN_rshift1(n1, n1)) goto err; - } - - if (!BN_mod_exp_simple(n0, m, n1, p, ctx)) goto err; - - if (!BN_sub_word(n1, 1)) goto err; - if (!BN_rshift1(n1, n1)) goto err; - if (!BN_mod_exp_simple(x, a, n1, p, ctx)) goto err; - - if (!BN_mod_sqr(b, x, p, ctx)) goto err; - if (!BN_mod_mul(b, b, a, p, ctx)) goto err; - - if (!BN_mod_mul(x, x, a, p, ctx)) goto err; - - while (!BN_is_one(b)) - { - if (!BN_one(m)) goto err; - if (!BN_mod_sqr(n1, b, p, ctx)) goto err; - while(!BN_is_one(n1)) - { - if (!BN_mod_mul(n1, n1, n1, p, ctx)) goto err; - if (!BN_add_word(m, 1)) goto err; - } - - if (!BN_sub(r, r, m)) goto err; - if (!BN_sub_word(r, 1)) goto err; - if (r->neg) goto err; - - if (BN_copy(n1, n0) == NULL) goto err; - while(!BN_is_zero(r)) - { - if (!BN_mod_mul(n1, n1, n1, p, ctx)) goto err; - if (!BN_sub_word(r, 1)) goto err; - } - - if (!BN_mod_mul(n0, n1, n1, p, ctx)) goto err; - if (BN_copy(r, m) == NULL) goto err; - if (!BN_mod_mul(x, x, n1, p, ctx)) goto err; - if (!BN_mod_mul(b, b, n0, p, ctx)) goto err; - } - - -#ifdef TEST - BN_mod_sqr(n0, x, p, ctx); - if (BN_cmp(n0, a)) goto err; -#endif - - if (r != NULL) BN_clear_free(r); - if (b != NULL) BN_clear_free(b); - if (m != NULL) BN_clear_free(m); - BN_CTX_end(ctx); - return 1; -err: - if (r != NULL) BN_clear_free(r); - if (b != NULL) BN_clear_free(b); - if (m != NULL) BN_clear_free(m); - BN_CTX_end(ctx); - return 0; - } diff --git a/crypto/bn/bn_modfs.h b/crypto/bn/bn_modfs.h deleted file mode 100644 index 8233a801df..0000000000 --- a/crypto/bn/bn_modfs.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * - * bn_modfs.h - * - * Some Modular Arithmetic Functions. - * - * Copyright (C) Lenka Fibikova 2000 - * - * - */ - -#ifndef HEADER_BN_MODFS_H -#define HEADER_BN_MODFS_H - - -#include <openssl/bn.h> - -int BN_mod_sqrt(BIGNUM *x, BIGNUM *a, BIGNUM *p, BN_CTX *ctx); - -#endif |