summaryrefslogtreecommitdiff
path: root/src/apk_csum.h
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-08 09:50:21 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-08 10:45:49 +0300
commitbf094dc5ea30be1defb5c9f0d2064c6b2fc96272 (patch)
tree34be7a9326397d6b408a8f59dd61f8e6ea4bc238 /src/apk_csum.h
parentc84196e0d367d8e82e5a3161394741f86bc32750 (diff)
downloadapk-tools-bf094dc5ea30be1defb5c9f0d2064c6b2fc96272.tar.gz
apk-tools-bf094dc5ea30be1defb5c9f0d2064c6b2fc96272.tar.bz2
apk-tools-bf094dc5ea30be1defb5c9f0d2064c6b2fc96272.tar.xz
apk-tools-bf094dc5ea30be1defb5c9f0d2064c6b2fc96272.zip
csum: use openssl instead
instead of having static md5 implemenation, use the openssl library for digest functions.
Diffstat (limited to 'src/apk_csum.h')
-rw-r--r--src/apk_csum.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/apk_csum.h b/src/apk_csum.h
new file mode 100644
index 0000000..564339b
--- /dev/null
+++ b/src/apk_csum.h
@@ -0,0 +1,53 @@
+/* apk_csum.c - Alpine Package Keeper (APK)
+ *
+ * Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi>
+ * 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 http://www.gnu.org/ 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_init(&ctx);
+ csum_process(&ctx, (csum_p) blob.ptr, blob.len);
+ csum_finish(&ctx, csum);
+}
+
+#endif