From patchwork Sun Dec 7 12:26:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Spelvin X-Patchwork-Id: 5451591 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 D9595BEEA8 for ; Sun, 7 Dec 2014 12:27:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D6F620154 for ; Sun, 7 Dec 2014 12:27:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 095E12015E for ; Sun, 7 Dec 2014 12:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753219AbaLGM1Q (ORCPT ); Sun, 7 Dec 2014 07:27:16 -0500 Received: from ns.horizon.com ([71.41.210.147]:35811 "HELO ns.horizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753216AbaLGM1H (ORCPT ); Sun, 7 Dec 2014 07:27:07 -0500 Received: (qmail 20903 invoked by uid 1000); 7 Dec 2014 07:26:57 -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 25/25] crypto: ansi_cprng - If non-deterministic, don't buffer old output Date: Sun, 7 Dec 2014 07:26:33 -0500 Message-Id: <6f29805d8bbde1af112d48201d5fde9a7776027f.1417951990.git.linux@horizon.com> 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 standards documents are silent on how to handle multi-part output, so this is an RFC for something in the spirit of the source specifications, but not actually required by them. Signed-off-by: George Spelvin --- crypto/ansi_cprng.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c index d39ce301..b88d3446 100644 --- a/crypto/ansi_cprng.c +++ b/crypto/ansi_cprng.c @@ -198,12 +198,14 @@ static int get_prng_bytes(u8 *buf, unsigned int nbytes, read_pos = ctx->rand_read_pos; if (byte_count > DEFAULT_BLK_SZ - read_pos) { - /* Leading partial block */ - unsigned int avail = DEFAULT_BLK_SZ - read_pos; + if (ctx->flags & PRNG_DETERMINISTIC) { + /* Return leftover data from previous call */ + unsigned int avail = DEFAULT_BLK_SZ - read_pos; - memcpy(ptr, ctx->rand_data.b + read_pos, avail); - ptr += avail; - byte_count -= avail; + memcpy(ptr, ctx->rand_data.b + read_pos, avail); + ptr += avail; + byte_count -= avail; + } read_pos = 0; /* Intermediate full blocks */