Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp620083ybh; Wed, 22 Jul 2020 08:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzknHCiz651RQ8hw9hFJUX7+DbUWwdeqObopGVc5d9jWRn1YeQpf8zBvAlT2vCMzas7Oo35 X-Received: by 2002:aa7:c808:: with SMTP id a8mr94388edt.259.1595433581069; Wed, 22 Jul 2020 08:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595433581; cv=none; d=google.com; s=arc-20160816; b=jQY1ejO999EhFxgaeeAZmrSlr0XmP6PFNViO1yW+wyzARB2TnNRmQg6mjoc46mDwLS z9n2YX/HF2AocM68ucjBMEWf1QGW4cHVH5kMxLJM6rnxK4w/IEG0oq1xH8QtGBm5FTkG Mm2Ytf3148Rczo6f8vnLgM8ZbZDCjLg9Z/XwgPCirFleV9ApW3+N523lPlgdkZ7Ysnr+ DN2P6TbGdpPlqz0Z/hPoO6GUWixOZZGyRzVqzS58gg4J55nxWHFwoF6McIXVxvr4xIZy DPS7B97XpggulhuWPJGeInLVNiZh5sdnMnJSCf+4534il9m3mWi2kgSZSqQX2U7Y9C0K zrwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=cOEr+LyMVs7W4AcjUOz/Et/5aT0i/ml/NtqBg3uElyY=; b=ggzIJwmjtX1O8tUC8YMJP0G58gHF7fZ5Bh2IH2nDXt7OquxsOkyLdPSfnVSn4PVOT5 S01EA9y+P79dMIF9ERoi95R8w+yYL+LIR7l8aLczhB4UF7D9isgp7aDbM6Hsv7b6Il4h ggxrhlURBkj9bQAjC7FUSUqcbRa6LDIQavv8B1qAx7fZ+uoRx3FiKHmbReQDQhhrmzud MeKwxA1ZHE77+s/lTjaUMZn1DaXVlL/3sAxHl4K6aJR4coAXkF+bHJcqI5lcah/Y948m jLKSf5KBH2/gTrlqS8bFMX+uyBwYFyO/tRoA6MxwGljO28owQQ4Wen8MHqGImfKtPF/j sIew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mMUZf1IT; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si245317ejw.204.2020.07.22.08.59.09; Wed, 22 Jul 2020 08:59:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mMUZf1IT; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726711AbgGVP7I (ORCPT + 99 others); Wed, 22 Jul 2020 11:59:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:39092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726427AbgGVP7H (ORCPT ); Wed, 22 Jul 2020 11:59:07 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D38722BEF; Wed, 22 Jul 2020 15:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595433547; bh=Sik9EDg9/EYvGlKmpDWAs+el6Z98mlU2O09h3CSpS38=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mMUZf1ITzrNrKb+ap2VL57h582o5mbchmG9R/ouX1yJK9qt+k6a1QDUWRDsJdSUZl i/5JnTvC//qKR+rh0CMsUsRik53V1RHBlVErjuezOf/b7iLzZv24GKJO31z8SEIl/l 8f8p5o6YnaRhgOvZAcpYul2GyRlETp4Re0/w+Xtk= Date: Wed, 22 Jul 2020 08:59:05 -0700 From: Eric Biggers To: Elena Petrova Cc: linux-crypto@vger.kernel.org, Stephan =?iso-8859-1?Q?M=FCller?= , Ard Biesheuvel Subject: Re: [PATCH v2] crypto: af_alg - add extra parameters for DRBG interface Message-ID: <20200722155905.GA789@sol.localdomain> References: <20200716164028.1805047-1-lenaptr@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200716164028.1805047-1-lenaptr@google.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, Jul 16, 2020 at 05:40:28PM +0100, Elena Petrova wrote: > Extending the userspace RNG interface: > 1. adding ALG_SET_DRBG_ENTROPY setsockopt option for entropy input; > 2. using sendmsg syscall for specifying the additional data. > > Signed-off-by: Elena Petrova Can you add more details to the commit message? E.g. why this is needed. Also please use imperative tense, e.g. "Extend the userspace RNG interface". > static int rng_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > int flags) > { > @@ -65,6 +80,7 @@ static int rng_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > int genlen = 0; > u8 result[MAXSIZE]; > > + lock_sock(sock->sk); > if (len == 0) > return 0; This returns without unlocking the socket. > if (len > MAXSIZE) > @@ -82,16 +98,45 @@ static int rng_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > * seeding as they automatically seed. The X9.31 DRNG will return > * an error if it was not seeded properly. > */ > - genlen = crypto_rng_get_bytes(ctx->drng, result, len); > + genlen = crypto_rng_generate(ctx->drng, ctx->addtl, ctx->addtl_len, > + result, len); > if (genlen < 0) > return genlen; Likewise. > > err = memcpy_to_msg(msg, result, len); > memzero_explicit(result, len); > + rng_reset_addtl(ctx); > + release_sock(sock->sk); > > return err ? err : len; > } > > +static int rng_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) > +{ > + int err; > + struct alg_sock *ask = alg_sk(sock->sk); > + struct rng_ctx *ctx = ask->private; > + > + lock_sock(sock->sk); > + if (len > MAXSIZE) > + len = MAXSIZE; > + > + rng_reset_addtl(ctx); > + ctx->addtl = kmalloc(len, GFP_KERNEL); > + if (!ctx->addtl) > + return -ENOMEM; Likewise. > + > + err = memcpy_from_msg(ctx->addtl, msg, len); > + if (err) { > + rng_reset_addtl(ctx); > + return err; Likewise.