1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 DSA implementation, generate 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.
25 int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key)
29 LTC_ARGCHK(key != NULL);
30 LTC_ARGCHK(ltc_mp.name != NULL);
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
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;
45 /* ref: $Format:%D$ */
46 /* git commit: $Format:%H$ */
47 /* commit time: $Format:%ai$ */