Attempt to account for differences in libmd on different platforms
This commit is contained in:
parent
632f93e084
commit
a762f3555e
1 changed files with 39 additions and 2 deletions
41
src/haggis.c
41
src/haggis.c
|
@ -30,9 +30,20 @@
|
||||||
* other than his own.
|
* other than his own.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <md5.h>
|
#if defined (__FreeBSD__) || defined (__DragonFly__)
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sha.h>
|
||||||
|
#include <sha256.h>
|
||||||
|
#elif defined (__NetBSD__) || defined (__OpenBSD__)
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sha1.h>
|
#include <sha1.h>
|
||||||
#include <sha2.h>
|
#include <sha2.h>
|
||||||
|
#elif defined (__linux__)
|
||||||
|
#include <sha1.h>
|
||||||
|
#include <sha2.h>
|
||||||
|
#endif /* if defined (__FreeBSD__) */
|
||||||
|
|
||||||
|
#include <md5.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -144,9 +155,21 @@ int validate_md5(struct haggis_file *file) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined (__FreeBSD__) || defined (__DragonFly__)
|
||||||
int validate_sha1(struct haggis_file *file) {
|
int validate_sha1(struct haggis_file *file) {
|
||||||
SHA1_CTX ctx;
|
SHA1_CTX ctx;
|
||||||
u8 digest[SHA1_DIGEST_LENGTH];
|
u8 digest[20];
|
||||||
|
SHA1_Init(&ctx);
|
||||||
|
SHA1_Update(&ctx, *file->data, (size_t)file->len.val);
|
||||||
|
SHA1_Final(digest, &ctx);
|
||||||
|
if (memcmp(file->cksum->sum->sha1, digest, sizeof(digest)))
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__)
|
||||||
|
int validate_sha1(struct haggis_file *file) {
|
||||||
|
SHA1_CTX ctx;
|
||||||
|
u8 digest[20];
|
||||||
SHA1Init(&ctx);
|
SHA1Init(&ctx);
|
||||||
SHA1Update(&ctx, *file->data, (size_t)file->len.val);
|
SHA1Update(&ctx, *file->data, (size_t)file->len.val);
|
||||||
SHA1Final(digest, &ctx);
|
SHA1Final(digest, &ctx);
|
||||||
|
@ -154,7 +177,20 @@ int validate_sha1(struct haggis_file *file) {
|
||||||
return 2;
|
return 2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* if defined (__FreeBSD__) */
|
||||||
|
|
||||||
|
#if defined (__FreeBSD__) || defined (__DragonFly) || defined (__NetBSD__)
|
||||||
|
int validate_sha256(struct haggis_file *file) {
|
||||||
|
SHA256_CTX ctx;
|
||||||
|
u8 digest[SHA256_DIGEST_LENGTH];
|
||||||
|
SHA256_Init(&ctx);
|
||||||
|
SHA256_Update(&ctx, *file->data, (size_t)file->len.val);
|
||||||
|
SHA256_Final(digest, &ctx);
|
||||||
|
if (memcmp(file->cksum->sum->sha256, digest, sizeof(digest)))
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined (__linux__) || defined (__OpenBSD__)
|
||||||
int validate_sha256(struct haggis_file *file) {
|
int validate_sha256(struct haggis_file *file) {
|
||||||
SHA2_CTX ctx;
|
SHA2_CTX ctx;
|
||||||
u8 digest[SHA256_DIGEST_LENGTH];
|
u8 digest[SHA256_DIGEST_LENGTH];
|
||||||
|
@ -165,6 +201,7 @@ int validate_sha256(struct haggis_file *file) {
|
||||||
return 2;
|
return 2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* if defined (__FreeBSD__) */
|
||||||
|
|
||||||
int haggis_validate_cksum(struct haggis_file *file) {
|
int haggis_validate_cksum(struct haggis_file *file) {
|
||||||
switch (file->cksum->tag) {
|
switch (file->cksum->tag) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue