Skip to content

Commit 243a1dc

Browse files
committed
drop _dh_make_key_ex
1 parent cba1569 commit 243a1dc

1 file changed

Lines changed: 10 additions & 42 deletions

File tree

src/pk/dh/dh_make_key.c

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -106,43 +106,6 @@ static int _dh_make_key(prng_state *prng, int wprng, void *prime, void *base, dh
106106
return err;
107107
}
108108

109-
/**
110-
Make a DH key (custom DH group) [private key pair]
111-
@param prng An active PRNG state
112-
@param wprng The index for the PRNG you desire to use
113-
@param prime_hex The prime p (hexadecimal string)
114-
@param base_hex The base g (hexadecimal string)
115-
@param key [out] Where the newly created DH key will be stored
116-
@return CRYPT_OK if successful, note: on error all allocated memory will be freed automatically.
117-
*/
118-
static int _dh_make_key_ex(prng_state *prng, int wprng, int radix,
119-
void *prime, unsigned long primelen,
120-
void *base, unsigned long baselen,
121-
dh_key *key)
122-
{
123-
void *p, *b;
124-
int err;
125-
126-
LTC_ARGCHK(prime != NULL);
127-
LTC_ARGCHK(base != NULL);
128-
LTC_ARGCHK((radix >= 2 && radix <= 64) || radix == 256);
129-
130-
if ((err = mp_init_multi(&p, &b, NULL)) != CRYPT_OK) { return err; }
131-
if (radix == 256) {
132-
if ((err = mp_read_unsigned_bin(b, base, baselen)) != CRYPT_OK) { goto error; }
133-
if ((err = mp_read_unsigned_bin(p, prime, primelen)) != CRYPT_OK) { goto error; }
134-
}
135-
else {
136-
if ((err = mp_read_radix(b, base, radix)) != CRYPT_OK) { goto error; }
137-
if ((err = mp_read_radix(p, prime, radix)) != CRYPT_OK) { goto error; }
138-
}
139-
err = _dh_make_key(prng, wprng, p, b, key);
140-
141-
error:
142-
mp_clear_multi(p, b, NULL);
143-
return err;
144-
}
145-
146109
/**
147110
Make a DH key (use built-in DH groups) [private key pair]
148111
@param prng An active PRNG state
@@ -153,17 +116,22 @@ static int _dh_make_key_ex(prng_state *prng, int wprng, int radix,
153116
*/
154117
int dh_make_key(prng_state *prng, int wprng, int groupsize, dh_key *key)
155118
{
156-
int i;
119+
void *p, *b;
120+
int i, err;
157121

158122
LTC_ARGCHK(groupsize > 0);
159123

160124
for (i = 0; (groupsize > ltc_dh_sets[i].size) && (ltc_dh_sets[i].size != 0); i++);
161125
if (ltc_dh_sets[i].size == 0) return CRYPT_INVALID_KEYSIZE;
162126

163-
return _dh_make_key_ex(prng, wprng, 16,
164-
ltc_dh_sets[i].prime, strlen(ltc_dh_sets[i].prime) + 1,
165-
ltc_dh_sets[i].base, strlen(ltc_dh_sets[i].base) + 1,
166-
key);
127+
if ((err = mp_init_multi(&p, &b, NULL)) != CRYPT_OK) { return err; }
128+
if ((err = mp_read_radix(b, ltc_dh_sets[i].base, 16)) != CRYPT_OK) { goto error; }
129+
if ((err = mp_read_radix(p, ltc_dh_sets[i].prime, 16)) != CRYPT_OK) { goto error; }
130+
err = _dh_make_key(prng, wprng, p, b, key);
131+
132+
error:
133+
mp_clear_multi(p, b, NULL);
134+
return err;
167135
}
168136

169137
/**

0 commit comments

Comments
 (0)