Commit bf094dc5 authored by Timo Teräs's avatar Timo Teräs

csum: use openssl instead

instead of having static md5 implemenation, use the openssl
library for digest functions.
parent c84196e0
PKGDEPS := openssl
ifeq ($(shell pkg-config --print-errors --exists $(PKGDEPS) || echo fail),fail)
$(error Build dependencies are not met)
progs-y += apk
apk-objs := state.o database.o package.o archive.o \
version.o io.o url.o gunzip.o blob.o \
hash.o md5.o apk.o \
version.o io.o url.o gunzip.o blob.o hash.o apk.o \
add.o del.o update.o info.o search.o upgrade.o \
cache.o ver.o index.o fetch.o audit.o
......@@ -11,7 +16,8 @@ apk.static-objs := $(apk-objs)
LDFLAGS_apk.static := -static
LDFLAGS_apk += -nopie
LIBS := /usr/lib/libz.a
LIBS += $(shell pkg-config --libs $(PKGDEPS))
LIBS += /usr/lib/libz.a
......@@ -103,7 +103,7 @@ static int add_main(void *ctx, int argc, char **argv)
goto err;
virtpkg->name = apk_db_get_name(&db, APK_BLOB_STR(actx->virtpkg));
apk_blob_csum(APK_BLOB_STR(virtpkg->name->name), virtpkg->csum);
csum_blob(APK_BLOB_STR(virtpkg->name->name), virtpkg->csum);
virtpkg->version = strdup("0");
virtpkg->description = strdup("virtual meta package");
virtdep = apk_dep_from_pkg(&db, virtpkg);
......@@ -21,7 +21,9 @@
#include "apk_defines.h"
#include "apk_applet.h"
#include "apk_blob.h"
#include "apk_csum.h"
csum_t bad_checksum = {0};
const char *apk_root;
struct apk_repository_url apk_repository_list;
int apk_verbosity = 1, apk_cwd_fd, apk_wait;
......@@ -44,7 +44,6 @@ int apk_blob_rsplit(apk_blob_t blob, char split, apk_blob_t *l, apk_blob_t *r);
unsigned apk_blob_uint(apk_blob_t blob, int base);
unsigned long apk_blob_hash(apk_blob_t str);
int apk_blob_compare(apk_blob_t a, apk_blob_t b);
void apk_blob_csum(apk_blob_t blob, csum_t csum);
int apk_blob_for_each_segment(apk_blob_t blob, const char *split,
apk_blob_cb cb, void *ctx);
/* apk_csum.c - Alpine Package Keeper (APK)
* Copyright (C) 2009 Timo Teräs <>
* All rights reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See for details.
#ifndef APK_CSUM_H
#define APK_CSUM_H
#include <openssl/evp.h>
#define MAX_CSUM_SIZE 16 /* MD5 */
typedef unsigned char *csum_p;
typedef unsigned char csum_t[MAX_CSUM_SIZE];
typedef EVP_MD_CTX csum_ctx_t;
extern csum_t bad_checksum;
static inline void csum_init(csum_ctx_t *ctx)
EVP_DigestInit(ctx, EVP_md5());
static inline void csum_process(csum_ctx_t *ctx, unsigned char *buf, size_t len)
EVP_DigestUpdate(ctx, buf, len);
static inline void csum_finish(csum_ctx_t *ctx, csum_p csum)
EVP_DigestFinal(ctx, csum, NULL);
static inline int csum_valid(csum_p csum)
return memcmp(csum, bad_checksum, MAX_CSUM_SIZE);
static inline void csum_blob(apk_blob_t blob, csum_p csum)
csum_ctx_t ctx;
csum_process(&ctx, (csum_p) blob.ptr, blob.len);
csum_finish(&ctx, csum);
......@@ -36,20 +36,6 @@
(type *)( (char *)__mptr - offsetof(type,member) );})
#if 1
#include "md5.h"
typedef unsigned char *csum_p;
typedef md5sum_t csum_t;
typedef struct md5_ctx csum_ctx_t;
extern csum_t bad_checksum;
#define csum_init(ctx) md5_init(ctx)
#define csum_process(ctx, buf, len) md5_process(ctx, buf, len)
#define csum_finish(ctx, buf) md5_finish(ctx, buf)
#define csum_valid(buf) memcmp(buf, bad_checksum, sizeof(csum_t))
extern int apk_cwd_fd, apk_verbosity, apk_wait;
extern unsigned int apk_flags;
......@@ -13,6 +13,7 @@
#include "apk_defines.h"
#include "apk_blob.h"
#include "apk_csum.h"
struct apk_file_info {
char *name;
......@@ -165,15 +165,6 @@ unsigned apk_blob_uint(apk_blob_t blob, int base)
return val;
void apk_blob_csum(apk_blob_t blob, csum_t csum)
csum_ctx_t ctx;
csum_process(&ctx, blob.ptr, blob.len);
csum_finish(&ctx, csum);
int apk_hexdump_parse(apk_blob_t to, apk_blob_t from)
int i;
......@@ -1043,7 +1043,7 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
if (apk_url_local_file(repo->url) == NULL) {
apk_blob_csum(repository, repo->url_csum);
csum_blob(repository, repo->url_csum);
bs = apk_db_cache_open(db, repo->url_csum, apk_index_gz);
if (bs == NULL) {
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment