37
37
/* first make sure key->q and key->p are prime */
38
if ((err = is_prime(&key->q, &res)) != CRYPT_OK) {
38
if ((err = mp_prime_is_prime(key->q, 8, &res)) != CRYPT_OK) {
46
if ((err = is_prime(&key->p, &res)) != CRYPT_OK) {
45
if ((err = mp_prime_is_prime(key->p, 8, &res)) != CRYPT_OK) {
53
52
/* now make sure that g is not -1, 0 or 1 and <p */
54
if (mp_cmp_d(&key->g, 0) == MP_EQ || mp_cmp_d(&key->g, 1) == MP_EQ) {
53
if (mp_cmp_d(key->g, 0) == LTC_MP_EQ || mp_cmp_d(key->g, 1) == LTC_MP_EQ) {
57
if ((err = mp_init_multi(&tmp, &tmp2, NULL)) != MP_OKAY) { goto error; }
58
if ((err = mp_sub_d(&key->p, 1, &tmp)) != MP_OKAY) { goto error; }
59
if (mp_cmp(&tmp, &key->g) == MP_EQ || mp_cmp(&key->g, &key->p) != MP_LT) {
56
if ((err = mp_init_multi(&tmp, &tmp2, NULL)) != CRYPT_OK) { return err; }
57
if ((err = mp_sub_d(key->p, 1, tmp)) != CRYPT_OK) { goto error; }
58
if (mp_cmp(tmp, key->g) == LTC_MP_EQ || mp_cmp(key->g, key->p) != LTC_MP_LT) {
65
if (!(mp_cmp_d(&key->y, 1) == MP_GT && mp_cmp(&key->y, &tmp) == MP_LT)) {
64
if (!(mp_cmp_d(key->y, 1) == LTC_MP_GT && mp_cmp(key->y, tmp) == LTC_MP_LT)) {
70
69
/* now we have to make sure that g^q = 1, and that p-1/q gives 0 remainder */
71
if ((err = mp_div(&tmp, &key->q, &tmp, &tmp2)) != MP_OKAY) { goto error; }
72
if (mp_iszero(&tmp2) != MP_YES) {
70
if ((err = mp_div(tmp, key->q, tmp, tmp2)) != CRYPT_OK) { goto error; }
71
if (mp_iszero(tmp2) != LTC_MP_YES) {
77
if ((err = mp_exptmod(&key->g, &key->q, &key->p, &tmp)) != MP_OKAY) { goto error; }
78
if (mp_cmp_d(&tmp, 1) != MP_EQ) {
76
if ((err = mp_exptmod(key->g, key->q, key->p, tmp)) != CRYPT_OK) { goto error; }
77
if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
83
82
/* now we have to make sure that y^q = 1, this makes sure y \in g^x mod p */
84
if ((err = mp_exptmod(&key->y, &key->q, &key->p, &tmp)) != MP_OKAY) { goto error; }
85
if (mp_cmp_d(&tmp, 1) != MP_EQ) {
83
if ((err = mp_exptmod(key->y, key->q, key->p, tmp)) != CRYPT_OK) { goto error; }
84
if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
90
89
/* at this point we are out of tests ;-( */
94
error: err = mpi_to_ltc_error(err);
95
done : mp_clear_multi(&tmp, &tmp2, NULL);
93
mp_clear_multi(tmp, tmp2, NULL);
100
98
/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_verify_key.c,v $ */
101
/* $Revision: 1.3 $ */
102
/* $Date: 2005/05/05 14:35:59 $ */
99
/* $Revision: 1.6 $ */
100
/* $Date: 2006/12/04 03:18:43 $ */