Exemple #1
0
static int ibmca_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
        {
        BN_CTX *ctx;
        int to_return = 0;

        if((ctx = BN_CTX_new()) == NULL)
                goto err;
        if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
                {
                if(!rsa->d || !rsa->n)
                        {
                        IBMCAerr(IBMCA_F_IBMCA_RSA_MOD_EXP,
                                IBMCA_R_MISSING_KEY_COMPONENTS);
                        goto err;
                        }
                to_return = ibmca_mod_exp(r0, I, rsa->d, rsa->n, ctx);
                }
        else
                {
                to_return = ibmca_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
                        rsa->dmq1, rsa->iqmp, ctx);
                }
 err:
        if(ctx)
                BN_CTX_free(ctx);
        return to_return;
        }
Exemple #2
0
static int ibmca_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,

        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)

        {

        return ibmca_mod_exp(r, a, p, m, ctx);

        }
Exemple #3
0
/* This code was liberated and adapted from the commented-out code in
 * dsa_ossl.c. Because of the unoptimised form of the Ibmca acceleration
 * (it doesn't have a CRT form for RSA), this function means that an
 * Ibmca system running with a DSA server certificate can handshake
 * around 5 or 6 times faster/more than an equivalent system running with
 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
 * of "openssl speed -engine ibmca dsa1024 rsa1024". */
static int ibmca_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
        BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
        BN_CTX *ctx, BN_MONT_CTX *in_mont)
        {
        BIGNUM t;
        int to_return = 0;

        BN_init(&t);
        /* let rr = a1 ^ p1 mod m */
        if (!ibmca_mod_exp(rr,a1,p1,m,ctx)) goto end;
        /* let t = a2 ^ p2 mod m */
        if (!ibmca_mod_exp(&t,a2,p2,m,ctx)) goto end;
        /* let rr = rr * t mod m */
        if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
        to_return = 1;
 end:
        BN_free(&t);
        return to_return;
        }