summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa/dsa_key.c
diff options
context:
space:
mode:
authormarkus <>2002-09-05 12:51:50 +0000
committermarkus <>2002-09-05 12:51:50 +0000
commit15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch)
treebf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/dsa/dsa_key.c
parent027351f729b9e837200dae6e1520cda6577ab930 (diff)
downloadopenbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_key.c')
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
index d51ed9395f..ef87c3e637 100644
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ b/src/lib/libcrypto/dsa/dsa_key.c
@@ -56,19 +56,17 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include <time.h> 61#include <time.h>
61#include "cryptlib.h" 62#include "cryptlib.h"
62#include "sha.h" 63#include <openssl/bn.h>
63#include "bn.h" 64#include <openssl/dsa.h>
64#include "dsa.h" 65#include <openssl/rand.h>
65#include "rand.h"
66 66
67int DSA_generate_key(dsa) 67int DSA_generate_key(DSA *dsa)
68DSA *dsa;
69 { 68 {
70 int ok=0; 69 int ok=0;
71 unsigned int i;
72 BN_CTX *ctx=NULL; 70 BN_CTX *ctx=NULL;
73 BIGNUM *pub_key=NULL,*priv_key=NULL; 71 BIGNUM *pub_key=NULL,*priv_key=NULL;
74 72
@@ -81,14 +79,9 @@ DSA *dsa;
81 else 79 else
82 priv_key=dsa->priv_key; 80 priv_key=dsa->priv_key;
83 81
84 i=BN_num_bits(dsa->q); 82 do
85 for (;;) 83 if (!BN_rand_range(priv_key,dsa->q)) goto err;
86 { 84 while (BN_is_zero(priv_key));
87 BN_rand(priv_key,i,1,0);
88 if (BN_cmp(priv_key,dsa->q) >= 0)
89 BN_sub(priv_key,priv_key,dsa->q);
90 if (!BN_is_zero(priv_key)) break;
91 }
92 85
93 if (dsa->pub_key == NULL) 86 if (dsa->pub_key == NULL)
94 { 87 {
@@ -109,4 +102,4 @@ err:
109 if (ctx != NULL) BN_CTX_free(ctx); 102 if (ctx != NULL) BN_CTX_free(ctx);
110 return(ok); 103 return(ok);
111 } 104 }
112 105#endif