@ -163,20 +163,24 @@ OPENSSL_EXPORT int DH_generate_parameters_ex(DH *dh, int prime_bits,
// |dh|. It returns one on success and zero on error.
// |dh|. It returns one on success and zero on error.
OPENSSL_EXPORT int DH_generate_key ( DH * dh ) ;
OPENSSL_EXPORT int DH_generate_key ( DH * dh ) ;
// DH_compute_key calculates the shared key between |dh| and |peers_key| and
// DH_compute_key_padded calculates the shared key between |dh| and |peers_key|
// writes it as a big-endian integer into |out|, which must have |DH_size|
// and writes it as a big-endian integer into |out|, padded up to |DH_size|
// bytes of space. It returns the number of bytes written, or a negative numbe r
// bytes. It returns the number of bytes written, which is always |DH_size|, o r
// on error.
// a negative number on error. |out| must have |DH_size| bytes of space .
//
//
// Note the output may be shorter than |DH_size| bytes. Contrary to PKCS #3,
// WARNING: this differs from the usual BoringSSL return-value convention.
// this function returns a variable-length shared key with leading zeros
// removed. This may result in sporadic key mismatch and, if |dh| is reused,
// side channel attacks such as https://raccoon-attack.com/.
//
//
// This is a legacy algorithm, so we do not provide a fixed-width variant. Use
// Note this function differs from |DH_compute_key| in that it preserves leading
// X25519 or ECDH with P-256 instead.
// zeros in the secret. This function is the preferred variant. It matches PKCS
OPENSSL_EXPORT int DH_compute_key ( uint8_t * out , const BIGNUM * peers_key ,
// #3 and avoids some side channel attacks. However, the two functions are not
DH * dh ) ;
// drop-in replacements for each other. Using a different variant than the
// application expects will result in sporadic key mismatches.
//
// Callers that expect a fixed-width secret should use this function over
// |DH_compute_key|. Callers that use either function should migrate to a modern
// primitive such as X25519 or ECDH with P-256 instead.
OPENSSL_EXPORT int DH_compute_key_padded ( uint8_t * out , const BIGNUM * peers_key ,
DH * dh ) ;
// DH_compute_key_hashed calculates the shared key between |dh| and |peers_key|
// DH_compute_key_hashed calculates the shared key between |dh| and |peers_key|
// and hashes it with the given |digest|. If the hash output is less than
// and hashes it with the given |digest|. If the hash output is less than
@ -185,7 +189,7 @@ OPENSSL_EXPORT int DH_compute_key(uint8_t *out, const BIGNUM *peers_key,
// returns one on success or zero on error.
// returns one on success or zero on error.
//
//
// NOTE: this follows the usual BoringSSL return-value convention, but that's
// NOTE: this follows the usual BoringSSL return-value convention, but that's
// different from |DH_compute_key|, above .
// different from |DH_compute_key| and |DH_compute_key_padded| .
OPENSSL_EXPORT int DH_compute_key_hashed ( DH * dh , uint8_t * out , size_t * out_len ,
OPENSSL_EXPORT int DH_compute_key_hashed ( DH * dh , uint8_t * out , size_t * out_len ,
size_t max_out_len ,
size_t max_out_len ,
const BIGNUM * peers_key ,
const BIGNUM * peers_key ,
@ -278,6 +282,28 @@ OPENSSL_EXPORT DH *d2i_DHparams(DH **ret, const unsigned char **inp, long len);
// Use |DH_marshal_parameters| instead.
// Use |DH_marshal_parameters| instead.
OPENSSL_EXPORT int i2d_DHparams ( const DH * in , unsigned char * * outp ) ;
OPENSSL_EXPORT int i2d_DHparams ( const DH * in , unsigned char * * outp ) ;
// DH_compute_key behaves like |DH_compute_key_padded| but, contrary to PKCS #3,
// returns a variable-length shared key with leading zeros. It returns the
// number of bytes written, or a negative number on error. |out| must have
// |DH_size| bytes of space.
//
// WARNING: this differs from the usual BoringSSL return-value convention.
//
// Note this function's running time and memory access pattern leaks information
// about the shared secret. Particularly if |dh| is reused, this may result in
// side channel attacks such as https://raccoon-attack.com/.
//
// |DH_compute_key_padded| is the preferred variant and avoids the above
// attacks. However, the two functions are not drop-in replacements for each
// other. Using a different variant than the application expects will result in
// sporadic key mismatches.
//
// Callers that expect a fixed-width secret should use |DH_compute_key_padded|
// instead. Callers that use either function should migrate to a modern
// primitive such as X25519 or ECDH with P-256 instead.
OPENSSL_EXPORT int DH_compute_key ( uint8_t * out , const BIGNUM * peers_key ,
DH * dh ) ;
struct dh_st {
struct dh_st {
BIGNUM * p ;
BIGNUM * p ;