summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2014-11-01 22:00:46 +0000
committerngie <ngie@FreeBSD.org>2014-11-01 22:00:46 +0000
commit6d8b7cad33b6077912a4191e4ce4e55672d329fa (patch)
treef394b56ab91aa1235d41dd43d7eac06a6ce1564f /contrib/netbsd-tests
parent204692190e5a42f3c8a4165ad387c5bb4b6a2cf7 (diff)
downloadFreeBSD-src-6d8b7cad33b6077912a4191e4ce4e55672d329fa.zip
FreeBSD-src-6d8b7cad33b6077912a4191e4ce4e55672d329fa.tar.gz
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
Diffstat (limited to 'contrib/netbsd-tests')
-rw-r--r--contrib/netbsd-tests/lib/libc/hash/h_hash.c20
-rw-r--r--contrib/netbsd-tests/lib/libc/hash/t_sha2.c14
2 files changed, 34 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libc/hash/h_hash.c b/contrib/netbsd-tests/lib/libc/hash/h_hash.c
index 33b9f9a..6e20a48 100644
--- a/contrib/netbsd-tests/lib/libc/hash/h_hash.c
+++ b/contrib/netbsd-tests/lib/libc/hash/h_hash.c
@@ -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);
diff --git a/contrib/netbsd-tests/lib/libc/hash/t_sha2.c b/contrib/netbsd-tests/lib/libc/hash/t_sha2.c
index a45e82a..ce2c80d 100644
--- a/contrib/netbsd-tests/lib/libc/hash/t_sha2.c
+++ b/contrib/netbsd-tests/lib/libc/hash/t_sha2.c
@@ -36,9 +36,23 @@ __RCSID("$NetBSD: t_sha2.c,v 1.3 2012/09/26 22:23:30 joerg Exp $");
#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);
OpenPOWER on IntegriCloud