From patchwork Tue Apr 18 23:05:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 9686603 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 862D96037E for ; Tue, 18 Apr 2017 23:10:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7882527D4D for ; Tue, 18 Apr 2017 23:10:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D4AE283A6; Tue, 18 Apr 2017 23:10:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 202CD27D4D for ; Tue, 18 Apr 2017 23:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758168AbdDRXJ6 (ORCPT ); Tue, 18 Apr 2017 19:09:58 -0400 Received: from mail.eperm.de ([89.247.134.16]:59004 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757695AbdDRXJy (ORCPT ); Tue, 18 Apr 2017 19:09:54 -0400 Received: from positron.chronox.de (mail.eperm.de [89.247.134.16]) by mail.eperm.de (Postfix) with ESMTPA id 9F50A181444A; Wed, 19 Apr 2017 01:09:43 +0200 (CEST) From: Stephan =?ISO-8859-1?Q?M=FCller?= To: linux-crypto@vger.kernel.org Cc: keyrings@vger.kernel.org Subject: [PATCH 2/8] crypto: AF_ALG -- add DH param / ECDH curve setsockopt call Date: Wed, 19 Apr 2017 01:05:12 +0200 Message-ID: <4340841.16OFkZJjv3@positron.chronox.de> In-Reply-To: <2715753.J0rCo2lbig@positron.chronox.de> References: <2715753.J0rCo2lbig@positron.chronox.de> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 0a91404..a3210bf 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -260,6 +260,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 3c3ebe3..52dcefe 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 c48eeb6..fc9ed9f 100644 --- a/include/uapi/linux/if_alg.h +++ b/include/uapi/linux/if_alg.h @@ -35,6 +35,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