--- embedaddon/strongswan/src/libstrongswan/plugins/openssl/openssl_util.h 2020/06/03 09:46:44 1.1.1.1 +++ embedaddon/strongswan/src/libstrongswan/plugins/openssl/openssl_util.h 2021/03/17 00:20:08 1.1.1.2 @@ -37,6 +37,16 @@ #define EC_FIELD_ELEMENT_LEN(group) ((EC_GROUP_get_degree(group) + 7) / 8) /** + * Derives a shared DH secret from the given keys. + * + * @param priv private key + * @param pub public key + * @param shared shared secret + * @return TRUE on success, FALSE otherwise + */ +bool openssl_compute_shared_key(EVP_PKEY *priv, EVP_PKEY *pub, chunk_t *shared); + +/** * Creates a hash of a given type of a chunk of data. * * Note: this function allocates memory for the hash @@ -91,9 +101,14 @@ bool openssl_bn2chunk(const BIGNUM *bn, chunk_t *chunk * @returns allocated chunk of the object, or chunk_empty */ #define openssl_i2chunk(type, obj) ({ \ - unsigned char *ptr = NULL; \ - int len = i2d_##type(obj, &ptr); \ - len < 0 ? chunk_empty : chunk_create(ptr, len);}) + chunk_t chunk = chunk_empty; \ + int len = i2d_##type(obj, NULL); \ + if (len >= 0) { \ + chunk = chunk_alloc(len); \ + u_char *p = chunk.ptr; \ + i2d_##type(obj, &p); \ + } \ + chunk; }) /** * Convert an OpenSSL ASN1_OBJECT to a chunk.