Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/pk/dsa/dsa_generate_key.c
4396 views
1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2
*
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
5
*
6
* The library is free for all purposes without any express
7
* guarantee it works.
8
*/
9
#include "tomcrypt.h"
10
11
/**
12
@file dsa_make_key.c
13
DSA implementation, generate a DSA key
14
*/
15
16
#ifdef LTC_MDSA
17
18
/**
19
Create a DSA key
20
@param prng An active PRNG state
21
@param wprng The index of the PRNG desired
22
@param key [in/out] Where to store the created key
23
@return CRYPT_OK if successful.
24
*/
25
int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key)
26
{
27
int err;
28
29
LTC_ARGCHK(key != NULL);
30
LTC_ARGCHK(ltc_mp.name != NULL);
31
32
/* so now we have our DH structure, generator g, order q, modulus p
33
Now we need a random exponent [mod q] and it's power g^x mod p
34
*/
35
/* private key x should be from range: 1 <= x <= q-1 (see FIPS 186-4 B.1.2) */
36
if ((err = rand_bn_upto(key->x, key->q, prng, wprng)) != CRYPT_OK) { return err; }
37
if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) { return err; }
38
key->type = PK_PRIVATE;
39
40
return CRYPT_OK;
41
}
42
43
#endif
44
45