New function DSA_dup_DH, and fixes for bugs that were found
[openssl.git] / crypto / dsa / dsa_lib.c
index 8923fb45f4340e0d6ea10b238ff3124fd916aa93..a5f0182101273429e8ce2019b0c9b22ec67e6cde 100644 (file)
@@ -145,3 +145,40 @@ int DSA_size(DSA *r)
        return(ret);
        }
 
+#ifndef NO_DH
+DH *DSA_dup_DH(DSA *r)
+       {
+       /* DSA has p, q, g, optional pub_key, optional priv_key.
+        * DH has p, optional length, g, optional pub_key, optional priv_key.
+        */ 
+
+       DH *ret;
+
+       if (r == NULL)
+               goto err;
+       ret = DH_new();
+       if (ret == NULL)
+               goto err;
+       if (r->p != NULL) 
+               if ((ret->p = BN_dup(r->p)) == NULL)
+                       goto err;
+       if (r->q != NULL)
+               ret->length = BN_num_bits(r->q);
+       if (r->g != NULL)
+               if ((ret->g = BN_dup(r->g)) == NULL)
+                       goto err;
+       if (r->pub_key != NULL)
+               if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
+                       goto err;
+       if (r->priv_key != NULL)
+               if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
+                       goto err;
+
+       return ret;
+
+ err:
+       if (ret != NULL)
+               DH_free(ret);
+       return NULL;
+       }
+#endif