| 1 |
// Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 2 |
// |
| 3 |
// The Elliptic Curve Public-Key Crypto Library (ECC Code) included |
| 4 |
// herein is developed by SUN MICROSYSTEMS, INC., and is contributed |
| 5 |
// to the OpenSSL project. |
| 6 |
// |
| 7 |
// The ECDH software is originally written by Douglas Stebila of |
| 8 |
// Sun Microsystems Laboratories. |
| 9 |
// |
| 10 |
// Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. |
| 11 |
// SPDX-License-Identifier: Apache-2.0 |
| 12 |
|
| 13 |
#ifndef OPENSSL_HEADER_ECDH_H |
| 14 |
#define OPENSSL_HEADER_ECDH_H |
| 15 |
|
| 16 |
#include <openssl/base.h> |
| 17 |
|
| 18 |
#include <openssl/ec_key.h> |
| 19 |
|
| 20 |
#if defined(__cplusplus) |
| 21 |
extern "C" { |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
// Elliptic curve Diffie-Hellman. |
| 26 |
|
| 27 |
|
| 28 |
// ECDH_compute_key calculates the shared key between |pub_key| and |priv_key|. |
| 29 |
// If |kdf| is not NULL, then it is called with the bytes of the shared key and |
| 30 |
// the parameter |out|. When |kdf| returns, the value of |*outlen| becomes the |
| 31 |
// return value. Otherwise, as many bytes of the shared key as will fit are |
| 32 |
// copied directly to, at most, |outlen| bytes at |out|. It returns the number |
| 33 |
// of bytes written to |out|, or -1 on error. |
| 34 |
OPENSSL_EXPORT int ECDH_compute_key( |
| 35 |
void *out, size_t outlen, const EC_POINT *pub_key, const EC_KEY *priv_key, |
| 36 |
void *(*kdf)(const void *in, size_t inlen, void *out, size_t *outlen)); |
| 37 |
|
| 38 |
// ECDH_compute_key_fips calculates the shared key between |pub_key| and |
| 39 |
// |priv_key| and hashes it with the appropriate SHA function for |out_len|. The |
| 40 |
// only value values for |out_len| are thus 24 (SHA-224), 32 (SHA-256), 48 |
| 41 |
// (SHA-384), and 64 (SHA-512). It returns one on success and zero on error. |
| 42 |
// |
| 43 |
// Note that the return value is different to |ECDH_compute_key|: it returns an |
| 44 |
// error flag (as is common for BoringSSL) rather than the number of bytes |
| 45 |
// written. |
| 46 |
// |
| 47 |
// This function allows the FIPS module to compute an ECDH and KDF within the |
| 48 |
// module boundary without taking an arbitrary function pointer for the KDF, |
| 49 |
// which isn't very FIPSy. |
| 50 |
OPENSSL_EXPORT int ECDH_compute_key_fips(uint8_t *out, size_t out_len, |
| 51 |
const EC_POINT *pub_key, |
| 52 |
const EC_KEY *priv_key); |
| 53 |
|
| 54 |
|
| 55 |
#if defined(__cplusplus) |
| 56 |
} // extern C |
| 57 |
#endif |
| 58 |
|
| 59 |
#define ECDH_R_KDF_FAILED 100 |
| 60 |
#define ECDH_R_NO_PRIVATE_VALUE 101 |
| 61 |
#define ECDH_R_POINT_ARITHMETIC_FAILURE 102 |
| 62 |
#define ECDH_R_UNKNOWN_DIGEST_LENGTH 103 |
| 63 |
|
| 64 |
#endif // OPENSSL_HEADER_ECDH_H |