STAILQ_ENTRY(pakfire_archive_chksum) nodes;
char path[PATH_MAX];
- archive_checksum_algo_t algo;
- unsigned char digest[EVP_MAX_MD_SIZE];
+
+ unsigned char digest_sha512[64];
+ unsigned char digest_sha256[32];
};
struct pakfire_archive {
// Checksum Stuff
-static const char* checksum_algo_string(archive_checksum_algo_t algo) {
- switch (algo) {
- case PAKFIRE_CHECKSUM_SHA512:
- return "SHA512";
-
- case PAKFIRE_CHECKSUM_UNKNOWN:
- return "UNKNOWN";
- }
-
- return NULL;
-}
-
static int read_hexdigest(unsigned char* dst, size_t l, const char* src) {
const char* p = src;
}
static int pakfire_archive_add_chksum(struct pakfire_archive* archive, const char* path,
- archive_checksum_algo_t algo, const char* hexdigest) {
+ const char* digest_sha512, const char* digest_sha256) {
int r = 1;
+ // Path must be set
+ if (!path) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ // At least one of the digests must be set
+ if (!digest_sha512 && !digest_sha256) {
+ errno = EINVAL;
+ return 1;
+ }
+
// Allocate a new chksum object
struct pakfire_archive_chksum* chksum = calloc(1, sizeof(*chksum));
if (!chksum)
if (r < 0)
goto ERROR;
- // Store algo
- chksum->algo = algo;
+ // SHA512
+ if (digest_sha512)
+ memcpy(chksum->digest_sha512, digest_sha512, sizeof(chksum->digest_sha512));
- // Store hexdigest as digest
- r = read_hexdigest(chksum->digest, sizeof(chksum->digest), hexdigest);
- if (r)
- goto ERROR;
+ // SHA256
+ if (digest_sha256)
+ memcpy(chksum->digest_sha256, digest_sha256, sizeof(chksum->digest_sha256));
// Append it
STAILQ_INSERT_TAIL(&archive->chksums, chksum, nodes);
- DEBUG(archive->pakfire, "Read checksum for %s - %s:%s\n",
- path, checksum_algo_string(algo), hexdigest);
+ DEBUG(archive->pakfire, "Added checksum for %s\n", path);
return 0;
const char* filename = NULL;
const char* checksum = NULL;
- archive_checksum_algo_t algo = PAKFIRE_CHECKSUM_SHA512;
char* p = data;
while (*p) {
// Add new checksum object
if (filename && checksum) {
- r = pakfire_archive_add_chksum(archive, filename, algo, checksum);
+ r = pakfire_archive_add_chksum(archive, filename, checksum, NULL);
if (r)
goto ERROR;
}
EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
// Select algorithm
- switch (chksum->algo) {
- case PAKFIRE_CHECKSUM_SHA512:
- md = EVP_sha512();
- break;
-
- default:
- ERROR(pakfire, "Unknown algorithm chosen\n");
- goto ERROR;
- }
+ md = EVP_sha512();
// Initialise the hash algorithm
r = EVP_DigestInit_ex(mdctx, md, NULL);
}
// Compare digests
- if (CRYPTO_memcmp(digest, chksum->digest, EVP_MD_CTX_size(mdctx)) == 0) {
+ if (CRYPTO_memcmp(digest, chksum->digest_sha512, EVP_MD_CTX_size(mdctx)) == 0) {
DEBUG(pakfire, "Checksum of %s is OK\n", chksum->path);
status = PAKFIRE_ARCHIVE_VERIFY_OK;
} else {