From owner-freebsd-bugs@FreeBSD.ORG Sat Sep 2 17:00:37 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4B61916A4E2 for ; Sat, 2 Sep 2006 17:00:37 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2CBF243D46 for ; Sat, 2 Sep 2006 17:00:36 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k82H0aug062230 for ; Sat, 2 Sep 2006 17:00:36 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k82H0ZtH062226; Sat, 2 Sep 2006 17:00:35 GMT (envelope-from gnats) Resent-Date: Sat, 2 Sep 2006 17:00:35 GMT Resent-Message-Id: <200609021700.k82H0ZtH062226@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Pavel Gorshkov Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 379FA16A4DD for ; Sat, 2 Sep 2006 16:57:38 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id DFDA643D45 for ; Sat, 2 Sep 2006 16:57:37 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k82GvbND043776 for ; Sat, 2 Sep 2006 16:57:37 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k82Gvbjk043775; Sat, 2 Sep 2006 16:57:37 GMT (envelope-from nobody) Message-Id: <200609021657.k82Gvbjk043775@www.freebsd.org> Date: Sat, 2 Sep 2006 16:57:37 GMT From: Pavel Gorshkov To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: kern/102795: {SHA1, RIPEMD160}_Update() produce wrong results for large buffers X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Sep 2006 17:00:37 -0000 >Number: 102795 >Category: kern >Synopsis: {SHA1,RIPEMD160}_Update() produce wrong results for large buffers >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Sep 02 17:00:35 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Pavel Gorshkov >Release: 6.1-STABLE >Organization: >Environment: FreeBSD localhost 6.1-STABLE FreeBSD 6.1-STABLE #8: Tue May 16 14:22:42 MSD 2006 root@localhost:/usr/obj/usr/src/sys/DESKTOP i386 >Description: asm-optimized SHA1_Update() and RIPEMD160_Update() as provided by libmd.a handle buffers larger than approx. 930M incorrectly (this is known to happen on 7.0-CURRENT/i386 as well) >How-To-Repeat: compile the test program (included at the bottom): gcc mdtest.c -o sha1test.shared -lmd gcc mdtest.c -o sha1test.static -lmd -static gcc -DDO_RMD mdtest.c -o rmd160test.shared -lmd gcc -DDO_RMD mdtest.c -o rmd160test.static -lmd -static create a large test file: dd if=/dev/zero bs=32m count=32 of=testfile run the test program, then verify the results with either openssl or gpg: $ ./sha1test.shared testfile 2a492f15396a6768bcbca016993f4b4c8b0b5307 $ ./sha1test.static testfile 0d6ee6083bf8b6368cb80d323e82164e5540e296 <======= WRONG!!! $ openssl dgst -sha1 #include #include #include #include #include #ifdef DO_RMD #include RIPEMD160_CTX ctx; #define MD_INIT RIPEMD160_Init #define MD_UPDATE RIPEMD160_Update #define MD_FINAL RIPEMD160_Final #else #include SHA_CTX ctx; #define MD_INIT SHA1_Init #define MD_UPDATE SHA1_Update #define MD_FINAL SHA1_Final #endif int main(int argc, char **argv) { int fd, i; struct stat st; unsigned char *buf, digest[20]; char hexdigest[41]; if (argc < 2 || stat(argv[1], &st) == -1 || (fd=open(argv[1], O_RDONLY)) == -1 || (buf=mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) return 1; MD_INIT(&ctx); MD_UPDATE(&ctx, buf, st.st_size); MD_FINAL(digest, &ctx); for (i = 0; i < 20; ++i) sprintf(hexdigest + 2*i, "%02x", digest[i]); puts(hexdigest); if (st.st_size) munmap(buf, st.st_size); close(fd); return 0; } /*** end of mdtest.c ***/ >Fix: >Release-Note: >Audit-Trail: >Unformatted: