]> pd.if.org Git - zpackage/blobdiff - lib/integ.c
switch to blake2
[zpackage] / lib / integ.c
index 13a2505bf53b7bf5b1454392c0885a8c279777d7..b51d27e333892c5f9080bc7fb0b80ad881ad0216 100644 (file)
@@ -3,17 +3,17 @@
 
 #include "zpm.h"
 #include "sqlite3.h"
-#include "sha256.h"
+#include "lib/blake2/ref/blake2.h"
 
-static void hash_byte(struct sha256_state *h, int ch) {
+static void hash_byte(struct blake2b_state__ *h, int ch) {
        unsigned char buf[1];
 
        buf[0] = ch & 0xff;
-       sha256_process(h, buf, 1);
+       blake2b_update(h, buf, 1);
 }
 
 /* i will be positive, we are hashing column sizes */
-static void hash_int(struct sha256_state *h, int i) {
+static void hash_int(struct blake2b_state__ *h, int i) {
        int n;
        uint64_t z;
 
@@ -56,7 +56,7 @@ static void hash_int(struct sha256_state *h, int i) {
  * with no delimiters of any kind.
  */
 
-static void hash_query(struct zpm *zpm, const char *zSql, struct sha256_state *h) {
+static void hash_query(struct zpm *zpm, const char *zSql, struct blake2b_state__ *h) {
        sqlite3 *db;
        sqlite3_stmt *pStmt = 0;
        int nCol; /* Number of columns in the result set */
@@ -86,7 +86,7 @@ static void hash_query(struct zpm *zpm, const char *zSql, struct sha256_state *h
        nCol = sqlite3_column_count(pStmt);
 
        while (sqlite3_step(pStmt) == SQLITE_ROW) {
-               sha256_process(h, (const unsigned char *)"R", 1);
+               blake2b_update(h, "R", 1);
                for (i = 0; i < nCol; i++) {
                        switch (sqlite3_column_type(pStmt, i)) {
                                case SQLITE_NULL:
@@ -132,14 +132,14 @@ static void hash_query(struct zpm *zpm, const char *zSql, struct sha256_state *h
                                        continue;
                                        break;
                        }
-                       sha256_process(h, data, bytes);
+                       blake2b_update(h, data, bytes);
                }
        }
        sqlite3_finalize(pStmt);
 }
 
 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash) {
-       struct sha256_state d;
+       struct blake2b_state__ d;
        char *sql;
        int i;
        unsigned char tmp[32];
@@ -150,7 +150,7 @@ int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash) {
 
        /* find package */
 
-       sha256_init(&d);
+       blake2b_init(&d, 32);
 
        sql = sqlite3_mprintf("select package,version,release,description,architecture,url,licenses,packager,build_time from packages_pkgid where pkgid = %Q", pkgid);
 
@@ -174,7 +174,7 @@ int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash) {
        hash_query(zpm, sql, &d);
        sqlite3_free(sql);
 
-       sha256_done(&d, tmp);
+       blake2b_final(&d, tmp, sizeof tmp);
        for (i=0; i<32; i++) {
                sprintf(hash+i*2, "%02x", (unsigned)tmp[i]);
        }