#include <linux/module.h>
#include <crypto/internal/kpp.h>
#include <linux/scatterlist.h>
u64 private_key[ECC_MAX_DIGITS];
static inline struct ecdh_ctx *ecdh_get_ctx(struct crypto_kpp *tfm)
static unsigned int ecdh_supported_curve(unsigned int curve_id)
case ECC_CURVE_NIST_P192: return ECC_CURVE_NIST_P192_DIGITS;
case ECC_CURVE_NIST_P256: return ECC_CURVE_NIST_P256_DIGITS;
static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
struct ecdh_ctx *ctx = ecdh_get_ctx(tfm);
if (crypto_ecdh_decode_key(buf, len, ¶ms) < 0)
ndigits = ecdh_supported_curve(params.curve_id);
ctx->curve_id = params.curve_id;
if (!params.key || !params.key_size)
return ecc_gen_privkey(ctx->curve_id, ctx->ndigits,
if (ecc_is_key_valid(ctx->curve_id, ctx->ndigits,
(const u64 *)params.key, params.key_size) < 0)
memcpy(ctx->private_key, params.key, params.key_size);