Skip to content

Commit 771d67e

Browse files
committed
DH facelift part1
1 parent 5e71ac2 commit 771d67e

15 files changed

Lines changed: 1171 additions & 1379 deletions

demos/timing.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,7 @@ static void time_dh(void)
891891
{
892892
dh_key key;
893893
ulong64 t1, t2;
894-
unsigned char buf[2][4096];
895-
unsigned long i, x, y, z;
894+
unsigned long i, x, y;
896895
int err;
897896
static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8, 3072/8, 4096/8, 6144/8, 8192/8, 100000};
898897

@@ -908,29 +907,10 @@ static void time_dh(void)
908907
t1 = t_read() - t1;
909908
t2 += t1;
910909

911-
if (y < 15) {
912-
dh_free(&key);
913-
}
910+
dh_free(&key);
914911
}
915912
t2 >>= 4;
916913
fprintf(stderr, "DH-%4lu make_key took %15llu cycles\n", x*8, t2);
917-
918-
t2 = 0;
919-
for (y = 0; y < 16; y++) {
920-
t_start();
921-
t1 = t_read();
922-
z = sizeof(buf[1]);
923-
if ((err = dh_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),
924-
&key)) != CRYPT_OK) {
925-
fprintf(stderr, "\n\ndh_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
926-
exit(EXIT_FAILURE);
927-
}
928-
t1 = t_read() - t1;
929-
t2 += t1;
930-
}
931-
t2 >>= 4;
932-
fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
933-
dh_free(&key);
934914
}
935915
}
936916
#else

src/headers/tomcrypt_pk.h

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,45 +183,57 @@ int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key);
183183
/* ---- DH Routines ---- */
184184
#ifdef LTC_MDH
185185

186-
typedef struct Dh_key {
187-
int idx, type;
186+
#ifndef DH_BUF_SIZE
187+
#define DH_BUF_SIZE 2100
188+
#endif
189+
190+
typedef struct {
191+
int size;
192+
char *name, *base, *prime;
193+
} ltc_dh_set_type;
194+
195+
extern const ltc_dh_set_type ltc_dh_sets[];
196+
197+
typedef struct {
198+
int type;
188199
void *x;
189200
void *y;
201+
void *base;
202+
void *prime;
190203
} dh_key;
191204

192-
int dh_compat_test(void);
193-
void dh_sizes(int *low, int *high);
194-
int dh_get_size(dh_key *key);
205+
int dh_get_groupsize(dh_key *key);
195206

196-
int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key);
207+
int dh_make_key(prng_state *prng, int wprng, int groupsize, dh_key *key);
208+
int dh_make_key_ex(prng_state *prng, int wprng, int radix,
209+
void *prime, unsigned long primelen,
210+
void *base, unsigned long baselen,
211+
dh_key *key);
212+
int dh_make_key_dhparam(prng_state *prng, int wprng, unsigned char *dhparam, unsigned long dhparamlen, dh_key *key);
197213
void dh_free(dh_key *key);
198214

199215
int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
200216
int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
201217

218+
int dh_export_radix(int radix,
219+
void *out, unsigned long *outlen,
220+
int type, dh_key *key);
221+
int dh_import_radix(int radix,
222+
void *in, unsigned long inlen,
223+
void *prime, unsigned long primelen,
224+
void *base, unsigned long baselen,
225+
int type, dh_key *key);
226+
202227
int dh_shared_secret(dh_key *private_key, dh_key *public_key,
203228
unsigned char *out, unsigned long *outlen);
204229

205-
int dh_encrypt_key(const unsigned char *in, unsigned long keylen,
206-
unsigned char *out, unsigned long *outlen,
207-
prng_state *prng, int wprng, int hash,
208-
dh_key *key);
209-
210-
int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
211-
unsigned char *out, unsigned long *outlen,
212-
dh_key *key);
213-
214-
int dh_sign_hash(const unsigned char *in, unsigned long inlen,
215-
unsigned char *out, unsigned long *outlen,
216-
prng_state *prng, int wprng, dh_key *key);
217-
218-
int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
219-
const unsigned char *hash, unsigned long hashlen,
220-
int *stat, dh_key *key);
221-
222-
230+
#ifdef LTC_SOURCE
231+
/* INTERNAL ONLY - it should be later moved to src/headers/tomcrypt_internal.h */
232+
int dh_check_pubkey(dh_key *key);
223233
#endif
224234

235+
#endif /* LTC_MDH */
236+
225237

226238
/* ---- ECC Routines ---- */
227239
#ifdef LTC_MECC

0 commit comments

Comments
 (0)