From 76e9ede9225dd75cc74b2e32306a17c4530cb200 Mon Sep 17 00:00:00 2001 From: Stephan Mueller Date: Sun, 7 Jan 2018 11:57:54 +0100 Subject: [PATCH v3 2/8] icrypto: AF_ALG -- add DH param / ECDH curve setsockopt call For supporting DH ciphers, user space must be able to set the DH parameters. The patch adds a new setsockopt call for setting these parameters. Similarly, the ECDH curve information can be set by user space via the newly added setsockopt call. Signed-off-by: Stephan Mueller --- crypto/af_alg.c | 12 ++++++++++++ include/crypto/if_alg.h | 2 ++ include/uapi/linux/if_alg.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index f2df3dc5210a..e3f7c5932f04 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -261,6 +261,18 @@ static int alg_setsockopt(struct socket *sock, int level, int optname, err = alg_setkey(sk, optval, optlen, type->setpubkey); break; + case ALG_SET_DH_PARAMETERS: + if (sock->state == SS_CONNECTED) + goto unlock; + + err = alg_setkey(sk, optval, optlen, type->dhparams); + break; + case ALG_SET_ECDH_CURVE: + if (sock->state == SS_CONNECTED) + goto unlock; + + err = alg_setkey(sk, optval, optlen, type->ecdhcurve); + break; case ALG_SET_AEAD_AUTHSIZE: if (sock->state == SS_CONNECTED) goto unlock; diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 79c5010a713b..641315e3051a 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -53,6 +53,8 @@ struct af_alg_type { void (*release)(void *private); int (*setkey)(void *private, const u8 *key, unsigned int keylen); int (*setpubkey)(void *private, const u8 *key, unsigned int keylen); + int (*dhparams)(void *private, const u8 *param, unsigned int paramlen); + int (*ecdhcurve)(void *private, const u8 *param, unsigned int paramlen); int (*accept)(void *private, struct sock *sk); int (*accept_nokey)(void *private, struct sock *sk); int (*setauthsize)(void *private, unsigned int authsize); diff --git a/include/uapi/linux/if_alg.h b/include/uapi/linux/if_alg.h index a53275c85612..e19a5addbb54 100644 --- a/include/uapi/linux/if_alg.h +++ b/include/uapi/linux/if_alg.h @@ -36,6 +36,8 @@ struct af_alg_iv { #define ALG_SET_AEAD_ASSOCLEN 4 #define ALG_SET_AEAD_AUTHSIZE 5 #define ALG_SET_PUBKEY 6 +#define ALG_SET_DH_PARAMETERS 7 +#define ALG_SET_ECDH_CURVE 8 /* Operations */ #define ALG_OP_DECRYPT 0 -- 2.14.3