Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Nov 2014 22:00:46 +0000 (UTC)
From:      Garrett Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273952 - head/contrib/netbsd-tests/lib/libc/hash
Message-ID:  <201411012200.sA1M0kMc072172@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Sat Nov  1 22:00:46 2014
New Revision: 273952
URL: https://svnweb.freebsd.org/changeset/base/273952

Log:
  Port h_hash and t_sha2 to FreeBSD
  
  t_sha2 contains dirty copy-paste hacks that need to be fixed with the openssh
  OpenBSD compat layer
  
  Submitted by: pho

Modified:
  head/contrib/netbsd-tests/lib/libc/hash/h_hash.c
  head/contrib/netbsd-tests/lib/libc/hash/t_sha2.c

Modified: head/contrib/netbsd-tests/lib/libc/hash/h_hash.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/hash/h_hash.c	Sat Nov  1 21:30:18 2014	(r273951)
+++ head/contrib/netbsd-tests/lib/libc/hash/h_hash.c	Sat Nov  1 22:00:46 2014	(r273952)
@@ -35,8 +35,13 @@
 #include <unistd.h>
 #include <string.h>
 #include <md5.h>
+#ifdef __NetBSD__
 #include <sha1.h>
+#endif
 
+#ifdef __FreeBSD__
+#include <sha.h>
+#endif
 
 int mflag, rflag, sflag, tflag;
 
@@ -102,17 +107,32 @@ regress(void)
 			MD5Final(out, &ctx);
 			outlen = 16;
 		} else {
+#ifdef __FreeBSD__
+			SHA_CTX ctx;
+
+			SHA1_Init(&ctx);
+			SHA1_Update(&ctx, buf, len);
+#else
 			SHA1_CTX ctx;
 
 			SHA1Init(&ctx);
 			SHA1Update(&ctx, buf, len);
+#endif
 			while (!last &&
 			    fgets((char *)buf, sizeof(buf), stdin) != NULL) {
 				len = strlen((char *)buf);
 				CHOMP(buf, len, last);				
+#ifdef __FreeBSD__
+				SHA1_Update(&ctx, buf, len);
+#else
 				SHA1Update(&ctx, buf, len);
+#endif
 			}
+#ifdef __FreeBSD__
+			SHA1_Final(out, &ctx);
+#else
 			SHA1Final(out, &ctx);
+#endif
 			outlen = 20;
 		}
 		hexdump(out, outlen);

Modified: head/contrib/netbsd-tests/lib/libc/hash/t_sha2.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/hash/t_sha2.c	Sat Nov  1 21:30:18 2014	(r273951)
+++ head/contrib/netbsd-tests/lib/libc/hash/t_sha2.c	Sat Nov  1 22:00:46 2014	(r273952)
@@ -36,9 +36,23 @@ __RCSID("$NetBSD: t_sha2.c,v 1.3 2012/09
 
 #include <atf-c.h>
 #include <sys/types.h>
+#ifdef __NetBSD__
 #include <sha2.h>
+#endif
 #include <string.h>
 
+#ifdef __FreeBSD__
+#include <openssl/sha.h>
+typedef SHA512_CTX SHA384_CTX;
+/* From /usr/src/crypto/openssh/openbsd-compat/sha2.h */
+#define SHA256_DIGEST_LENGTH		32
+#define SHA256_DIGEST_STRING_LENGTH	(SHA256_DIGEST_LENGTH * 2 + 1)
+#define SHA384_DIGEST_LENGTH		48
+#define SHA384_DIGEST_STRING_LENGTH	(SHA384_DIGEST_LENGTH * 2 + 1)
+#define SHA512_DIGEST_LENGTH		64
+#define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
+#endif
+
 ATF_TC(t_sha256);
 ATF_TC(t_sha384);
 ATF_TC(t_sha512);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411012200.sA1M0kMc072172>