comparison libtomcrypt/src/pk/dh/dh_export_key.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
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 Binary export a DH key to a buffer
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
21 */
22 int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key)
23 {
24 unsigned long len;
25 void *k;
26
27 LTC_ARGCHK(out != NULL);
28 LTC_ARGCHK(outlen != NULL);
29 LTC_ARGCHK(key != NULL);
30
31 k = (type == PK_PRIVATE) ? key->x : key->y;
32 len = mp_unsigned_bin_size(k);
33
34 if (*outlen < len) {
35 *outlen = len;
36 return CRYPT_BUFFER_OVERFLOW;
37 }
38 *outlen = len;
39
40 return mp_to_unsigned_bin(k, out);
41 }
42
43 #endif /* LTC_MDH */
44
45 /* ref: $Format:%D$ */
46 /* git commit: $Format:%H$ */
47 /* commit time: $Format:%ai$ */