xref: /dflybsd-src/crypto/libressl/include/openssl/curve25519.h (revision cca6fc5243d2098262ea81f83ad5b28d3b800f4a)
1*cca6fc52SDaniel Fojt /*	$OpenBSD: curve25519.h,v 1.3 2019/05/11 15:55:52 tb Exp $ */
272c33676SMaxim Ag /*
372c33676SMaxim Ag  * Copyright (c) 2015, Google Inc.
472c33676SMaxim Ag  *
572c33676SMaxim Ag  * Permission to use, copy, modify, and/or distribute this software for any
672c33676SMaxim Ag  * purpose with or without fee is hereby granted, provided that the above
772c33676SMaxim Ag  * copyright notice and this permission notice appear in all copies.
872c33676SMaxim Ag  *
972c33676SMaxim Ag  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1072c33676SMaxim Ag  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1172c33676SMaxim Ag  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
1272c33676SMaxim Ag  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1372c33676SMaxim Ag  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
1472c33676SMaxim Ag  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1572c33676SMaxim Ag  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1672c33676SMaxim Ag  */
1772c33676SMaxim Ag 
1872c33676SMaxim Ag #ifndef HEADER_CURVE25519_H
1972c33676SMaxim Ag #define HEADER_CURVE25519_H
2072c33676SMaxim Ag 
2172c33676SMaxim Ag #include <stdint.h>
2272c33676SMaxim Ag 
2372c33676SMaxim Ag #include <openssl/opensslconf.h>
2472c33676SMaxim Ag 
2572c33676SMaxim Ag #if defined(__cplusplus)
2672c33676SMaxim Ag extern "C" {
2772c33676SMaxim Ag #endif
2872c33676SMaxim Ag 
2972c33676SMaxim Ag /*
3072c33676SMaxim Ag  * Curve25519.
3172c33676SMaxim Ag  *
3272c33676SMaxim Ag  * Curve25519 is an elliptic curve. See https://tools.ietf.org/html/rfc7748.
3372c33676SMaxim Ag  */
3472c33676SMaxim Ag 
3572c33676SMaxim Ag /*
3672c33676SMaxim Ag  * X25519.
3772c33676SMaxim Ag  *
3872c33676SMaxim Ag  * X25519 is the Diffie-Hellman primitive built from curve25519. It is
3972c33676SMaxim Ag  * sometimes referred to as curve25519, but X25519 is a more precise name.
4072c33676SMaxim Ag  * See http://cr.yp.to/ecdh.html and https://tools.ietf.org/html/rfc7748.
4172c33676SMaxim Ag  */
4272c33676SMaxim Ag 
4372c33676SMaxim Ag #define X25519_KEY_LENGTH 32
4472c33676SMaxim Ag 
4572c33676SMaxim Ag /*
4672c33676SMaxim Ag  * X25519_keypair sets |out_public_value| and |out_private_key| to a freshly
4772c33676SMaxim Ag  * generated, public/private key pair.
4872c33676SMaxim Ag  */
4972c33676SMaxim Ag void X25519_keypair(uint8_t out_public_value[X25519_KEY_LENGTH],
5072c33676SMaxim Ag     uint8_t out_private_key[X25519_KEY_LENGTH]);
5172c33676SMaxim Ag 
5272c33676SMaxim Ag /*
5372c33676SMaxim Ag  * X25519 writes a shared key to |out_shared_key| that is calculated from the
5472c33676SMaxim Ag  * given private key and the peer's public value. It returns one on success and
5572c33676SMaxim Ag  * zero on error.
5672c33676SMaxim Ag  *
5772c33676SMaxim Ag  * Don't use the shared key directly, rather use a KDF and also include the two
5872c33676SMaxim Ag  * public values as inputs.
5972c33676SMaxim Ag  */
6072c33676SMaxim Ag int X25519(uint8_t out_shared_key[X25519_KEY_LENGTH],
6172c33676SMaxim Ag     const uint8_t private_key[X25519_KEY_LENGTH],
6272c33676SMaxim Ag     const uint8_t peers_public_value[X25519_KEY_LENGTH]);
6372c33676SMaxim Ag 
6472c33676SMaxim Ag #if defined(__cplusplus)
6572c33676SMaxim Ag }  /* extern C */
6672c33676SMaxim Ag #endif
6772c33676SMaxim Ag 
6872c33676SMaxim Ag #endif  /* HEADER_CURVE25519_H */
69