Ulf M�ller wrote:
>
> >Here is a test data that does not work with rsa_oaep_test.c
> >Can someone tell me what could be wrong?
>
> You've got an invalid value for iqmp. You can set it like this:
>
> BN_mod_inverse(key->iqmp, key->q, key->p, ctx);
>
> int RSA_check(RSA *key)
> {
> BIGNUM *i, *j, *k;
> BN_CTX *ctx;
> int ret=0;
>
> i = BN_new();
> j = BN_new();
> k = BN_new();
> ctx = BN_CTX_new();
> if (i == NULL || j == NULL || k == NULL || ctx == NULL)
> return (-2);
>
> /* p prime? */
> if (BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL) != 1)
> ret = -1;
>
> /* q prime? */
> if (BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL) != 1)
> ret = -1;
>
> /* n = p*q? */
> BN_mul(i, key->p, key->q, ctx);
> if (BN_cmp(i, key->n) != 0)
> ret = -1;
>
> /* dmp1 = d mod (p-1)? */
> BN_sub(i, key->p, BN_value_one());
> BN_mod(j, key->d, i, ctx);
> if (BN_cmp(j, key->dmp1) != 0)
> ret = -1;
>
> /* dmq1 = d mod (q-1)? */
> BN_sub(i, key->q, BN_value_one());
> BN_mod(j, key->d, i, ctx);
> if (BN_cmp(j, key->dmq1) != 0)
> ret = -1;
>
> /* iqmp = q^-1 mod p? */
> BN_mod_inverse(i, key->q, key->p, ctx);
> if (BN_cmp(i, key->iqmp) != 0)
> ret = -1;
>
> /* d*e = 1 mod (p-1)(q-1)? */
> BN_sub(i, key->p, BN_value_one());
> BN_sub(j, key->q, BN_value_one());
> BN_mul(k, i, j, ctx);
> BN_mod_mul(i, key->d, key->e, k, ctx);
> if (!BN_is_one(i))
> ret = -1;
>
> BN_free(i);
> BN_free(j);
> BN_free(k);
> BN_CTX_free(ctx);
> return (ret);
> }
Hmmm... very nice! I've been meaning to write something like that. IMHO
it should be included in crypto/rsa, possibly with more meaningful
return codes to say why it doesn't like the key and with a -check option
added to the rsa utility to call it.
Steve.
--
Dr Stephen N. Henson. http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED]
Senior crypto engineer, Celo Communications: http://www.celocom.com/
Core developer of the OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]