Mercurial > dropbear
annotate libtomcrypt/src/pk/dh/dh_export_key.c @ 1938:77bc00dcc19f default tip main master
Bump version to 2022.82
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 01 Apr 2022 14:43:27 +0800 |
parents | 6dba84798cd5 |
children |
rev | line source |
---|---|
1471
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * LibTomCrypt is a library that provides various cryptographic |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * algorithms in a highly modular and flexible manner. |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * The library is free for all purposes without any express |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * guarantee it works. |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 #include "tomcrypt.h" |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 #ifdef LTC_MDH |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 /** |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 Binary export a DH key to a buffer |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 @param out [out] The destination for the key |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 @param outlen [in/out] The max size and resulting size of the DH key |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 @param type Which type of key (PK_PRIVATE or PK_PUBLIC) |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 @param key The key you wish to export |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 @return CRYPT_OK if successful |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key) |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 unsigned long len; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 void *k; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 LTC_ARGCHK(out != NULL); |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 LTC_ARGCHK(outlen != NULL); |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 LTC_ARGCHK(key != NULL); |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 k = (type == PK_PRIVATE) ? key->x : key->y; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 len = mp_unsigned_bin_size(k); |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 if (*outlen < len) { |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 *outlen = len; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 return CRYPT_BUFFER_OVERFLOW; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 *outlen = len; |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 return mp_to_unsigned_bin(k, out); |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 } |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 #endif /* LTC_MDH */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 /* ref: $Format:%D$ */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 /* git commit: $Format:%H$ */ |
6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 /* commit time: $Format:%ai$ */ |