From patchwork Sun Dec 7 12:26:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Spelvin X-Patchwork-Id: 5451431 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 64E95BEEA8 for ; Sun, 7 Dec 2014 12:27:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7197620154 for ; Sun, 7 Dec 2014 12:27:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8571D20155 for ; Sun, 7 Dec 2014 12:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753158AbaLGM07 (ORCPT ); Sun, 7 Dec 2014 07:26:59 -0500 Received: from ns.horizon.com ([71.41.210.147]:39555 "HELO ns.horizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753147AbaLGM07 (ORCPT ); Sun, 7 Dec 2014 07:26:59 -0500 Received: (qmail 20818 invoked by uid 1000); 7 Dec 2014 07:26:52 -0500 From: George Spelvin To: nhorman@tuxdriver.com, linux-crypto@vger.kernel.org Cc: smueller@chronox.de, herbert@gondor.apana.org.au, linux@horizon.com Subject: [PATCH v2 08/25] crypto: ansi_cprng - Don't call reset_prng_context from cprng_init Date: Sun, 7 Dec 2014 07:26:16 -0500 Message-Id: X-Mailer: git-send-email 2.1.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The PRNG_NEEDS_RESET flag ensures that it will be called, so reset_prng_context() no longer needs to support NULL key and V pointers. Signed-off-by: George Spelvin --- crypto/ansi_cprng.c | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c index 022662d7..62b8f958 100644 --- a/crypto/ansi_cprng.c +++ b/crypto/ansi_cprng.c @@ -23,10 +23,8 @@ #include "internal.h" -#define DEFAULT_PRNG_KEY "0123456789abcdef" #define DEFAULT_PRNG_KSZ 16 #define DEFAULT_BLK_SZ 16 -#define DEFAULT_V_SEED "zaybxcwdveuftgsh" /* * Flags for the prng_context flags field @@ -250,41 +248,28 @@ static int reset_prng_context(struct prng_context *ctx, unsigned char *V, unsigned char *DT) { int ret; - unsigned char *prng_key; spin_lock_bh(&ctx->prng_lock); ctx->flags |= PRNG_NEED_RESET; - - prng_key = (key != NULL) ? key : (unsigned char *)DEFAULT_PRNG_KEY; - - if (!key) - klen = DEFAULT_PRNG_KSZ; - - if (V) - memcpy(ctx->V, V, DEFAULT_BLK_SZ); - else - memcpy(ctx->V, DEFAULT_V_SEED, DEFAULT_BLK_SZ); - - if (DT) - memcpy(ctx->DT, DT, DEFAULT_BLK_SZ); - else - memset(ctx->DT, 0, DEFAULT_BLK_SZ); - - memset(ctx->rand_data, 0, DEFAULT_BLK_SZ); - ctx->rand_data_valid = DEFAULT_BLK_SZ; - ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen); + memset(ctx->rand_data, 0, DEFAULT_BLK_SZ); + + if (!DT) + DT = ctx->rand_data; /* Use all-zeros if NULL */ + + memcpy(ctx->DT, DT, DEFAULT_BLK_SZ); + memcpy(ctx->V, V, DEFAULT_BLK_SZ); + + ret = crypto_cipher_setkey(ctx->tfm, key, klen); if (ret) { dbgprint(KERN_CRIT "PRNG: setkey() failed flags=%x\n", crypto_cipher_get_flags(ctx->tfm)); - goto out; + } else { + ctx->flags &= ~PRNG_NEED_RESET; } - - ret = 0; - ctx->flags &= ~PRNG_NEED_RESET; -out: spin_unlock_bh(&ctx->prng_lock); + return ret; } @@ -300,13 +285,9 @@ static int cprng_init(struct crypto_tfm *tfm) return PTR_ERR(ctx->tfm); } - if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0) - return -EINVAL; - /* - * after allocation, we should always force the user to reset - * so they don't inadvertently use the insecure default values - * without specifying them intentially + * After allocation, we always force the user to reset, which + * completes initialization of the context. */ ctx->flags |= PRNG_NEED_RESET; return 0;