dsa_make_key_ex() is now dsa_generate_key()
This commit is contained in:
parent
dbeaefd65b
commit
3c2e0d6686
@ -669,7 +669,7 @@ static const struct {
|
||||
fprintf(stderr, "\n\ndsa_generate_pqg says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ((err = dsa_make_key_ex(&yarrow_prng, find_prng("yarrow"), &key)) != CRYPT_OK) {
|
||||
if ((err = dsa_generate_key(&yarrow_prng, find_prng("yarrow"), &key)) != CRYPT_OK) {
|
||||
fprintf(stderr, "\n\ndsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ int dsa_generate_pqg(prng_state *prng, int wprng, int group_size, int modulus_si
|
||||
int dsa_set_key(const unsigned char *pub, unsigned long publen,
|
||||
const unsigned char *priv, unsigned long privlen,
|
||||
dsa_key *key);
|
||||
int dsa_make_key_ex(prng_state *prng, int wprng, dsa_key *key);
|
||||
int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key);
|
||||
|
||||
void dsa_free(dsa_key *key);
|
||||
|
||||
|
47
src/pk/dsa/dsa_generate_key.c
Normal file
47
src/pk/dsa/dsa_generate_key.c
Normal file
@ -0,0 +1,47 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file dsa_make_key.c
|
||||
DSA implementation, generate a DSA key
|
||||
*/
|
||||
|
||||
#ifdef LTC_MDSA
|
||||
|
||||
/**
|
||||
Create a DSA key
|
||||
@param prng An active PRNG state
|
||||
@param wprng The index of the PRNG desired
|
||||
@param key [in/out] Where to store the created key
|
||||
@return CRYPT_OK if successful.
|
||||
*/
|
||||
int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(ltc_mp.name != NULL);
|
||||
|
||||
/* so now we have our DH structure, generator g, order q, modulus p
|
||||
Now we need a random exponent [mod q] and it's power g^x mod p
|
||||
*/
|
||||
/* private key x should be from range: 1 <= x <= q-1 (see FIPS 186-4 B.1.2) */
|
||||
if ((err = rand_bn_range(key->x, key->q, prng, wprng)) != CRYPT_OK) { return err; }
|
||||
if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) { return err; }
|
||||
key->type = PK_PRIVATE;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
@ -15,31 +15,6 @@
|
||||
|
||||
#ifdef LTC_MDSA
|
||||
|
||||
/**
|
||||
Create a DSA key
|
||||
@param prng An active PRNG state
|
||||
@param wprng The index of the PRNG desired
|
||||
@param key [in/out] Where to store the created key
|
||||
@return CRYPT_OK if successful.
|
||||
*/
|
||||
int dsa_make_key_ex(prng_state *prng, int wprng, dsa_key *key)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(ltc_mp.name != NULL);
|
||||
|
||||
/* so now we have our DH structure, generator g, order q, modulus p
|
||||
Now we need a random exponent [mod q] and it's power g^x mod p
|
||||
*/
|
||||
/* private key x should be from range: 1 <= x <= q-1 (see FIPS 186-4 B.1.2) */
|
||||
if ((err = rand_bn_range(key->x, key->q, prng, wprng)) != CRYPT_OK) { return err; }
|
||||
if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) { return err; }
|
||||
key->type = PK_PRIVATE;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Old-style creation of a DSA key
|
||||
@param prng An active PRNG state
|
||||
@ -54,7 +29,7 @@ int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size,
|
||||
int err;
|
||||
|
||||
if ((err = dsa_generate_pqg(prng, wprng, group_size, modulus_size, key)) != CRYPT_OK) { return err; }
|
||||
if ((err = dsa_make_key_ex(prng, wprng, key)) != CRYPT_OK) { return err; }
|
||||
if ((err = dsa_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; }
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
@ -118,6 +118,11 @@ int dsa_set_key(const unsigned char *pub, unsigned long publen,
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(key->x != NULL);
|
||||
LTC_ARGCHK(key->y != NULL);
|
||||
LTC_ARGCHK(key->p != NULL);
|
||||
LTC_ARGCHK(key->g != NULL);
|
||||
LTC_ARGCHK(key->q != NULL);
|
||||
LTC_ARGCHK(ltc_mp.name != NULL);
|
||||
|
||||
if ((err = mp_read_unsigned_bin(key->y, (unsigned char *)pub , publen)) != CRYPT_OK) { goto LBL_ERR; }
|
||||
|
@ -208,7 +208,7 @@ static int _dsa_compat_test(void)
|
||||
|
||||
/* try import dsaparam */
|
||||
DO(dsa_set_pqg_dsaparam(dsaparam_der, sizeof(dsaparam_der), &key));
|
||||
DO(dsa_make_key_ex(&yarrow_prng, find_prng("yarrow"), &key));
|
||||
DO(dsa_generate_key(&yarrow_prng, find_prng("yarrow"), &key));
|
||||
/* verify it */
|
||||
DO(dsa_verify_key(&key, &stat));
|
||||
if (stat == 0) {
|
||||
@ -257,7 +257,7 @@ int dsa_test(void)
|
||||
|
||||
/* make a random key */
|
||||
DO(dsa_generate_pqg(&yarrow_prng, find_prng("yarrow"), 20, 128, &key));
|
||||
DO(dsa_make_key_ex(&yarrow_prng, find_prng("yarrow"), &key));
|
||||
DO(dsa_generate_key(&yarrow_prng, find_prng("yarrow"), &key));
|
||||
|
||||
/* verify it */
|
||||
DO(dsa_verify_key(&key, &stat1));
|
||||
|
Loading…
Reference in New Issue
Block a user