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 */ dh_export_key(void * out,unsigned long * outlen,int type,dh_key * key)22int 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: HEAD -> master, tag: v1.18.2 */ 46 /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */ 47 /* commit time: 2018-07-01 22:49:01 +0200 */ 48