xref: /freebsd/crypto/libecc/include/libecc/ecdh/ecccdh.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1 /*
2  *  Copyright (C) 2021 - This file is part of libecc project
3  *
4  *  Authors:
5  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7  *
8  *  This software is licensed under a dual BSD and GPL v2 license.
9  *  See LICENSE file at the root folder of the project.
10  */
11 #include <libecc/lib_ecc_config.h>
12 #include <libecc/lib_ecc_types.h>
13 #if defined(WITH_ECCCDH)
14 
15 
16 #ifndef __ECCCDH_H__
17 #define __ECCCDH_H__
18 
19 #include <libecc/curves/curves.h>
20 #include <libecc/sig/ec_key.h>
21 #include <libecc/utils/utils.h>
22 
23 /* Get the size of the shared secret associated to the curve parameters.
24  *
25  */
26 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_shared_secret_size(const ec_params *params, u8 *size);
27 
28 /* Get the size of the serialized public key associated to the curve parameters.
29  *
30  */
31 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_serialized_pub_key_size(const ec_params *params, u8 *size);
32 
33 /* Initialize ECCCDH public key from an initialized private key.
34  *
35  */
36 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv);
37 
38 /* Generate a key pair for ECCCDH given curve parameters as input.
39  *
40  */
41 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_gen_key_pair(ec_key_pair *kp, const ec_params *params);
42 
43 /* Create a key pair from a serialized private key.
44  *
45  */
46 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_import_key_pair_from_priv_key_buf(ec_key_pair *kp, const ec_params *params, const u8 *priv_key_buf, u8 priv_key_buf_len);
47 
48 /* Serialize our public key in a buffer.
49  *
50  */
51 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_serialize_pub_key(const ec_pub_key *our_pub_key, u8 *buff, u8 buff_len);
52 
53 /* Derive the ECCCDH shared secret and store it in a buffer given the peer
54  * public key and our private key.
55  *
56  * The shared_secret_len length MUST be exactly equal to the expected shared secret size:
57  * the function fails otherwise.
58  */
59 ATTRIBUTE_WARN_UNUSED_RET int ecccdh_derive_secret(const ec_priv_key *our_priv_key, const u8 *peer_pub_key, u8 peer_pub_key_len, u8 *shared_secret, u8 shared_secret_len);
60 
61 #endif /* __ECCCDH_H__ */
62 
63 #endif /* WITH_ECCCDH */
64