1 /*
2  * Copyright (c) 2015, Google Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef HEADER_CURVE25519_H
18 #define HEADER_CURVE25519_H
19 
20 #include <stdint.h>
21 
22 #include <openssl/opensslconf.h>
23 
24 #if defined(__cplusplus)
25 extern "C" {
26 #endif
27 
28 /*
29  * Curve25519.
30  *
31  * Curve25519 is an elliptic curve. See https://tools.ietf.org/html/rfc7748.
32  */
33 
34 /*
35  * X25519.
36  *
37  * X25519 is the Diffie-Hellman primitive built from curve25519. It is
38  * sometimes referred to as curve25519, but X25519 is a more precise name.
39  * See http://cr.yp.to/ecdh.html and https://tools.ietf.org/html/rfc7748.
40  */
41 
42 /*
43  * X25519_keypair sets |out_public_value| and |out_private_key| to a freshly
44  * generated, public/private key pair.
45  */
46 void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]);
47 
48 /*
49  * X25519 writes a shared key to |out_shared_key| that is calculated from the
50  * given private key and the peer's public value. It returns one on success and
51  * zero on error.
52  *
53  * Don't use the shared key directly, rather use a KDF and also include the two
54  * public values as inputs.
55  */
56 int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
57     const uint8_t peers_public_value[32]);
58 
59 #if defined(__cplusplus)
60 }  /* extern C */
61 #endif
62 
63 #endif  /* HEADER_CURVE25519_H */
64