#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/string.h>
#define ECDH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + 2 * sizeof(short))
static inline u8 *ecdh_pack_data(void *dst, const void *src, size_t sz)
static inline const u8 *ecdh_unpack_data(void *dst, const void *src, size_t sz)
unsigned int crypto_ecdh_key_len(const struct ecdh *params)
return ECDH_KPP_SECRET_MIN_SIZE + params->key_size;
EXPORT_SYMBOL_GPL(crypto_ecdh_key_len);
int crypto_ecdh_encode_key(char *buf, unsigned int len,
const struct ecdh *params)
struct kpp_secret secret = {
.type = CRYPTO_KPP_SECRET_TYPE_ECDH,
if (len != crypto_ecdh_key_len(params))
ptr = ecdh_pack_data(ptr, &secret, sizeof(secret));
ptr = ecdh_pack_data(ptr, ¶ms->curve_id, sizeof(params->curve_id));
ptr = ecdh_pack_data(ptr, ¶ms->key_size, sizeof(params->key_size));
ecdh_pack_data(ptr, params->key, params->key_size);
EXPORT_SYMBOL_GPL(crypto_ecdh_encode_key);
int crypto_ecdh_decode_key(const char *buf, unsigned int len,