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
15 Export a DH key to a binary packet
16 @param out [out] The destination for the key
17 @param outlen [in/out] The max size and resulting size of the DH key
18 @param type Which type of key (PK_PRIVATE or PK_PUBLIC)
19 @param key The key you wish to export
20 @return CRYPT_OK if successful
22 int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key)
24 unsigned char flags[1];
26 unsigned long version = 0;
28 LTC_ARGCHK(out != NULL);
29 LTC_ARGCHK(outlen != NULL);
30 LTC_ARGCHK(key != NULL);
32 if (type == PK_PRIVATE) {
33 /* export x - private key */
35 err = der_encode_sequence_multi(out, outlen,
36 LTC_ASN1_SHORT_INTEGER, 1UL, &version,
37 LTC_ASN1_BIT_STRING, 1UL, flags,
38 LTC_ASN1_INTEGER, 1UL, key->prime,
39 LTC_ASN1_INTEGER, 1UL, key->base,
40 LTC_ASN1_INTEGER, 1UL, key->x,
41 LTC_ASN1_EOL, 0UL, NULL);
44 /* export y - public key */
46 err = der_encode_sequence_multi(out, outlen,
47 LTC_ASN1_SHORT_INTEGER, 1UL, &version,
48 LTC_ASN1_BIT_STRING, 1UL, flags,
49 LTC_ASN1_INTEGER, 1UL, key->prime,
50 LTC_ASN1_INTEGER, 1UL, key->base,
51 LTC_ASN1_INTEGER, 1UL, key->y,
52 LTC_ASN1_EOL, 0UL, NULL);
60 /* ref: $Format:%D$ */
61 /* git commit: $Format:%H$ */
62 /* commit time: $Format:%ai$ */