From owner-svn-src-all@FreeBSD.ORG Sat Jan 11 20:49:23 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2CD35309; Sat, 11 Jan 2014 20:49:23 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id F3BA81353; Sat, 11 Jan 2014 20:49:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s0BKnM7s039748; Sat, 11 Jan 2014 20:49:22 GMT (envelope-from jmg@svn.freebsd.org) Received: (from jmg@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s0BKnMIe039746; Sat, 11 Jan 2014 20:49:22 GMT (envelope-from jmg@svn.freebsd.org) Message-Id: <201401112049.s0BKnMIe039746@svn.freebsd.org> From: John-Mark Gurney Date: Sat, 11 Jan 2014 20:49:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260554 - head/lib/libmd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jan 2014 20:49:23 -0000 Author: jmg Date: Sat Jan 11 20:49:22 2014 New Revision: 260554 URL: http://svnweb.freebsd.org/changeset/base/260554 Log: use a real uint64_t instead of writing code to emulate one.. I verified w/ a: dd if=/dev/zero bs=1m count=5000 | sha256 a33351fafd00e4c4bcdee2a1c5d019026500f8cdfeaf91a9b8dbbb2619429659 Reviewed by: cperciva MFC after: 1 week Modified: head/lib/libmd/sha256.h head/lib/libmd/sha256c.c Modified: head/lib/libmd/sha256.h ============================================================================== --- head/lib/libmd/sha256.h Sat Jan 11 19:02:17 2014 (r260553) +++ head/lib/libmd/sha256.h Sat Jan 11 20:49:22 2014 (r260554) @@ -33,7 +33,7 @@ typedef struct SHA256Context { uint32_t state[8]; - uint32_t count[2]; + uint64_t count; unsigned char buf[64]; } SHA256_CTX; Modified: head/lib/libmd/sha256c.c ============================================================================== --- head/lib/libmd/sha256c.c Sat Jan 11 19:02:17 2014 (r260553) +++ head/lib/libmd/sha256c.c Sat Jan 11 20:49:22 2014 (r260554) @@ -208,10 +208,10 @@ SHA256_Pad(SHA256_CTX * ctx) * Convert length to a vector of bytes -- we do this now rather * than later because the length will change after we pad. */ - be32enc_vect(len, ctx->count, 8); + be64enc(len, ctx->count); /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ - r = (ctx->count[1] >> 3) & 0x3f; + r = (ctx->count >> 3) & 0x3f; plen = (r < 56) ? (56 - r) : (120 - r); SHA256_Update(ctx, PAD, (size_t)plen); @@ -225,7 +225,7 @@ SHA256_Init(SHA256_CTX * ctx) { /* Zero bits processed so far */ - ctx->count[0] = ctx->count[1] = 0; + ctx->count = 0; /* Magic initialization constants */ ctx->state[0] = 0x6A09E667; @@ -242,21 +242,18 @@ SHA256_Init(SHA256_CTX * ctx) void SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) { - uint32_t bitlen[2]; + uint64_t bitlen; uint32_t r; const unsigned char *src = in; /* Number of bytes left in the buffer from previous updates */ - r = (ctx->count[1] >> 3) & 0x3f; + r = (ctx->count >> 3) & 0x3f; /* Convert the length into a number of bits */ - bitlen[1] = ((uint32_t)len) << 3; - bitlen[0] = (uint32_t)(len >> 29); + bitlen = len << 3; /* Update number of bits */ - if ((ctx->count[1] += bitlen[1]) < bitlen[1]) - ctx->count[0]++; - ctx->count[0] += bitlen[0]; + ctx->count += bitlen; /* Handle the case where we don't need to perform any transforms */ if (len < 64 - r) {