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
This commit is contained in:
Enji Cooper 2014-11-01 22:00:46 +00:00
parent 6a4bfd1397
commit 4c8d4de868
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273952
2 changed files with 34 additions and 0 deletions

View File

@ -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);

View File

@ -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);