1/* Copyright (c) 2015, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#ifndef OPENSSL_HEADER_CURVE25519_H
16#define OPENSSL_HEADER_CURVE25519_H
17
18#include <openssl/base.h>
19
20#if defined(__cplusplus)
21extern "C" {
22#endif
23
24
25/* Curve25519.
26 *
27 * Curve25519 is an elliptic curve. See
28 * https://tools.ietf.org/html/draft-irtf-cfrg-curves-11. */
29
30
31/* X25519.
32 *
33 * Curve25519 is an elliptic curve. The same name is also sometimes used for
34 * the Diffie-Hellman primitive built from it but “X25519” is a more precise
35 * name for that, which is the one used here. See http://cr.yp.to/ecdh.html and
36 * https://tools.ietf.org/html/draft-irtf-cfrg-curves-11. */
37
38/* X25519_keypair sets |out_public_value| and |out_private_key| to a freshly
39 * generated, public–private key pair. */
40OPENSSL_EXPORT void X25519_keypair(uint8_t out_public_value[32],
41                                   uint8_t out_private_key[32]);
42
43/* X25519 writes a shared key to |out_shared_key| that is calculated from the
44 * given private key and the peer's public value. It returns one on success and
45 * zero on error.
46 *
47 * Don't use the shared key directly, rather use a KDF and also include the two
48 * public values as inputs. */
49OPENSSL_EXPORT int X25519(uint8_t out_shared_key[32],
50                          const uint8_t private_key[32],
51                          const uint8_t peers_public_value[32]);
52
53/* X25519_public_from_private calculates a Diffie-Hellman public value from the
54 * given private key and writes it to |out_public_value|. */
55OPENSSL_EXPORT void X25519_public_from_private(uint8_t out_public_value[32],
56                                               const uint8_t private_key[32]);
57
58
59/* Ed25519.
60 *
61 * Ed25519 is a signature scheme using a twisted-Edwards curve that is
62 * birationally equivalent to curve25519. */
63
64#define ED25519_PRIVATE_KEY_LEN 64
65#define ED25519_PUBLIC_KEY_LEN 32
66#define ED25519_SIGNATURE_LEN 64
67
68/* ED25519_keypair sets |out_public_key| and |out_private_key| to a freshly
69 * generated, public–private key pair. */
70OPENSSL_EXPORT void ED25519_keypair(uint8_t out_public_key[32],
71                                    uint8_t out_private_key[64]);
72
73/* ED25519_sign sets |out_sig| to be a signature of |message_len| bytes from
74 * |message| using |private_key|. It returns one on success or zero on
75 * error. */
76OPENSSL_EXPORT int ED25519_sign(uint8_t out_sig[64], const uint8_t *message,
77                                size_t message_len,
78                                const uint8_t private_key[64]);
79
80/* ED25519_verify returns one iff |signature| is a valid signature, by
81 * |public_key| of |message_len| bytes from |message|. It returns zero
82 * otherwise. */
83OPENSSL_EXPORT int ED25519_verify(const uint8_t *message, size_t message_len,
84                                  const uint8_t signature[64],
85                                  const uint8_t public_key[32]);
86
87
88#if defined(__cplusplus)
89}  /* extern C */
90#endif
91
92#endif  /* OPENSSL_HEADER_CURVE25519_H */
93