Switch hastctl and hastd to libmd instead of openssl for sha256
Reviewed by: bapt, brnrd, pjd Approved by: pjd (maintainer) Sponsored by: ScaleEngine Inc., FOSDEM DevSummit Differential Revision: https://reviews.freebsd.org/D9423
This commit is contained in:
parent
52972faf3b
commit
95b08b8b4a
@ -33,11 +33,7 @@ CFLAGS+=-DINET6
|
|||||||
CFLAGS+=-DYY_NO_UNPUT
|
CFLAGS+=-DYY_NO_UNPUT
|
||||||
CFLAGS+=-DYY_NO_INPUT
|
CFLAGS+=-DYY_NO_INPUT
|
||||||
|
|
||||||
LIBADD= util
|
LIBADD= md util
|
||||||
.if ${MK_OPENSSL} != "no"
|
|
||||||
LIBADD+= crypto
|
|
||||||
CFLAGS+=-DHAVE_CRYPTO
|
|
||||||
.endif
|
|
||||||
|
|
||||||
YFLAGS+=-v
|
YFLAGS+=-v
|
||||||
|
|
||||||
|
@ -31,11 +31,7 @@ CFLAGS+=-DINET
|
|||||||
CFLAGS+=-DINET6
|
CFLAGS+=-DINET6
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
LIBADD= geom pthread util
|
LIBADD= geom md pthread util
|
||||||
.if ${MK_OPENSSL} != "no"
|
|
||||||
LIBADD+= crypto
|
|
||||||
CFLAGS+=-DHAVE_CRYPTO
|
|
||||||
.endif
|
|
||||||
|
|
||||||
YFLAGS+=-v
|
YFLAGS+=-v
|
||||||
|
|
||||||
|
@ -31,22 +31,15 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
#include <openssl/sha.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <crc32.h>
|
#include <crc32.h>
|
||||||
#include <hast.h>
|
#include <hast.h>
|
||||||
#include <nv.h>
|
#include <nv.h>
|
||||||
|
#include <sha256.h>
|
||||||
#include <pjdlog.h>
|
#include <pjdlog.h>
|
||||||
|
|
||||||
#include "hast_checksum.h"
|
#include "hast_checksum.h"
|
||||||
|
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
#define MAX_HASH_SIZE SHA256_DIGEST_LENGTH
|
#define MAX_HASH_SIZE SHA256_DIGEST_LENGTH
|
||||||
#else
|
|
||||||
#define MAX_HASH_SIZE 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hast_crc32_checksum(const unsigned char *data, size_t size,
|
hast_crc32_checksum(const unsigned char *data, size_t size,
|
||||||
@ -60,7 +53,6 @@ hast_crc32_checksum(const unsigned char *data, size_t size,
|
|||||||
*hsizep = sizeof(crc);
|
*hsizep = sizeof(crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
static void
|
static void
|
||||||
hast_sha256_checksum(const unsigned char *data, size_t size,
|
hast_sha256_checksum(const unsigned char *data, size_t size,
|
||||||
unsigned char *hash, size_t *hsizep)
|
unsigned char *hash, size_t *hsizep)
|
||||||
@ -72,7 +64,6 @@ hast_sha256_checksum(const unsigned char *data, size_t size,
|
|||||||
SHA256_Final(hash, &ctx);
|
SHA256_Final(hash, &ctx);
|
||||||
*hsizep = SHA256_DIGEST_LENGTH;
|
*hsizep = SHA256_DIGEST_LENGTH;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_CRYPTO */
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
checksum_name(int num)
|
checksum_name(int num)
|
||||||
@ -102,11 +93,9 @@ checksum_send(const struct hast_resource *res, struct nv *nv, void **datap,
|
|||||||
case HAST_CHECKSUM_CRC32:
|
case HAST_CHECKSUM_CRC32:
|
||||||
hast_crc32_checksum(*datap, *sizep, hash, &hsize);
|
hast_crc32_checksum(*datap, *sizep, hash, &hsize);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
case HAST_CHECKSUM_SHA256:
|
case HAST_CHECKSUM_SHA256:
|
||||||
hast_sha256_checksum(*datap, *sizep, hash, &hsize);
|
hast_sha256_checksum(*datap, *sizep, hash, &hsize);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
PJDLOG_ABORT("Invalid checksum: %d.", res->hr_checksum);
|
PJDLOG_ABORT("Invalid checksum: %d.", res->hr_checksum);
|
||||||
}
|
}
|
||||||
@ -138,10 +127,8 @@ checksum_recv(const struct hast_resource *res __unused, struct nv *nv,
|
|||||||
}
|
}
|
||||||
if (strcmp(algo, "crc32") == 0)
|
if (strcmp(algo, "crc32") == 0)
|
||||||
hast_crc32_checksum(*datap, *sizep, chash, &chsize);
|
hast_crc32_checksum(*datap, *sizep, chash, &chsize);
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
else if (strcmp(algo, "sha256") == 0)
|
else if (strcmp(algo, "sha256") == 0)
|
||||||
hast_sha256_checksum(*datap, *sizep, chash, &chsize);
|
hast_sha256_checksum(*datap, *sizep, chash, &chsize);
|
||||||
#endif
|
|
||||||
else {
|
else {
|
||||||
pjdlog_error("Unknown checksum algorithm '%s'.", algo);
|
pjdlog_error("Unknown checksum algorithm '%s'.", algo);
|
||||||
return (-1); /* Unknown checksum algorithm. */
|
return (-1); /* Unknown checksum algorithm. */
|
||||||
|
@ -42,9 +42,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <pjdlog.h>
|
#include <pjdlog.h>
|
||||||
#include <proto.h>
|
#include <proto.h>
|
||||||
|
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
#include "hast_checksum.h"
|
#include "hast_checksum.h"
|
||||||
#endif
|
|
||||||
#include "hast_compression.h"
|
#include "hast_compression.h"
|
||||||
#include "hast_proto.h"
|
#include "hast_proto.h"
|
||||||
|
|
||||||
@ -68,9 +66,7 @@ struct hast_pipe_stage {
|
|||||||
|
|
||||||
static struct hast_pipe_stage pipeline[] = {
|
static struct hast_pipe_stage pipeline[] = {
|
||||||
{ "compression", compression_send, compression_recv },
|
{ "compression", compression_send, compression_recv },
|
||||||
#ifdef HAVE_CRYPTO
|
|
||||||
{ "checksum", checksum_send, checksum_recv }
|
{ "checksum", checksum_send, checksum_recv }
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user