Skip to content

Commit a80abb1

Browse files
committed
put dh_set_pg_dhparam() in own c file
1 parent 5640f8a commit a80abb1

2 files changed

Lines changed: 54 additions & 36 deletions

File tree

src/pk/dh/dh_set.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,6 @@ int dh_set_pg(const unsigned char *p, unsigned long plen,
4646
return err;
4747
}
4848

49-
/**
50-
Import DH key parts p and g from dhparam
51-
52-
dhparam data: openssl dhparam -outform DER -out dhparam.der 2048
53-
54-
@param dhparam The DH param DER encoded data
55-
@param dhparamlen The length of dhparam data
56-
@param key [out] Where the newly created DH key will be stored
57-
@return CRYPT_OK if successful, note: on error all allocated memory will be freed automatically.
58-
*/
59-
int dh_set_pg_dhparam(const unsigned char *dhparam, unsigned long dhparamlen, dh_key *key)
60-
{
61-
int err;
62-
63-
LTC_ARGCHK(key != NULL);
64-
LTC_ARGCHK(ltc_mp.name != NULL);
65-
LTC_ARGCHK(dhparam != NULL);
66-
LTC_ARGCHK(dhparamlen > 0);
67-
68-
if ((err = mp_init_multi(&key->x, &key->y, &key->base, &key->prime, NULL)) != CRYPT_OK) {
69-
return err;
70-
}
71-
if ((err = der_decode_sequence_multi(dhparam, dhparamlen,
72-
LTC_ASN1_INTEGER, 1UL, key->prime,
73-
LTC_ASN1_INTEGER, 1UL, key->base,
74-
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
75-
goto LBL_ERR;
76-
}
77-
78-
return CRYPT_OK;
79-
80-
LBL_ERR:
81-
dh_free(key);
82-
return err;
83-
}
84-
8549
/**
8650
Import DH key parts p and g from built-in DH groups
8751

src/pk/dh/dh_set_pg_dhparam.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
10+
#include "tomcrypt.h"
11+
12+
#ifdef LTC_MDH
13+
14+
/**
15+
Import DH key parts p and g from dhparam
16+
17+
dhparam data: openssl dhparam -outform DER -out dhparam.der 2048
18+
19+
@param dhparam The DH param DER encoded data
20+
@param dhparamlen The length of dhparam data
21+
@param key [out] Where the newly created DH key will be stored
22+
@return CRYPT_OK if successful, note: on error all allocated memory will be freed automatically.
23+
*/
24+
int dh_set_pg_dhparam(const unsigned char *dhparam, unsigned long dhparamlen, dh_key *key)
25+
{
26+
int err;
27+
28+
LTC_ARGCHK(key != NULL);
29+
LTC_ARGCHK(ltc_mp.name != NULL);
30+
LTC_ARGCHK(dhparam != NULL);
31+
LTC_ARGCHK(dhparamlen > 0);
32+
33+
if ((err = mp_init_multi(&key->x, &key->y, &key->base, &key->prime, NULL)) != CRYPT_OK) {
34+
return err;
35+
}
36+
if ((err = der_decode_sequence_multi(dhparam, dhparamlen,
37+
LTC_ASN1_INTEGER, 1UL, key->prime,
38+
LTC_ASN1_INTEGER, 1UL, key->base,
39+
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
40+
goto LBL_ERR;
41+
}
42+
43+
return CRYPT_OK;
44+
45+
LBL_ERR:
46+
dh_free(key);
47+
return err;
48+
}
49+
50+
#endif /* LTC_MDH */
51+
52+
/* ref: $Format:%D$ */
53+
/* git commit: $Format:%H$ */
54+
/* commit time: $Format:%ai$ */

0 commit comments

Comments
 (0)