Include SKIP DH parameters with OpenSSL.
[oweals/openssl.git] / crypto / dh / dh_key.c
index 4e6a0fc0ef35a6ac6ee4c5797181b4b05a3f753e..6f9426dd6fc276129100eba63f9d1abdcadb322d 100644 (file)
@@ -161,7 +161,8 @@ static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
        int ret= -1;
 
        BN_CTX_init(&ctx);
-       tmp= &(ctx.bn[ctx.tos++]);
+       BN_CTX_start(&ctx);
+       tmp = BN_CTX_get(&ctx);
        
        if (dh->priv_key == NULL)
                {
@@ -184,6 +185,7 @@ static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
 
        ret=BN_bn2bin(tmp,key);
 err:
+       BN_CTX_end(&ctx);
        BN_CTX_free(&ctx);
        return(ret);
        }
@@ -191,19 +193,26 @@ err:
 static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
                        const BIGNUM *m, BN_CTX *ctx,
                        BN_MONT_CTX *m_ctx)
-{
-       return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
-}
+       {
+       if (a->top == 1)
+               {
+               BN_ULONG A = a->d[0];
+               return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx);
+               }
+       else
+               return BN_mod_exp_mont(r,a,p,m,ctx,m_ctx);
+       }
+
 
 static int dh_init(DH *dh)
-{
+       {
        dh->flags |= DH_FLAG_CACHE_MONT_P;
        return(1);
-}
+       }
 
 static int dh_finish(DH *dh)
-{
+       {
        if(dh->method_mont_p)
                BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
        return(1);
-}
+       }