X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=lib%2Finteg.c;h=b51d27e333892c5f9080bc7fb0b80ad881ad0216;hb=2ac486ab18adbbb84563eafc0d67fa8da6ca7822;hp=81667eae77cee6ebd721fabd5d93b1d555a6217a;hpb=383712eefa950c5dc619f8cd5fb60be8e8041502;p=zpackage diff --git a/lib/integ.c b/lib/integ.c index 81667ea..b51d27e 100644 --- a/lib/integ.c +++ b/lib/integ.c @@ -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: @@ -127,15 +127,19 @@ static void hash_query(struct zpm *zpm, const char *zSql, struct sha256_state *h hash_byte(h, 'B'); hash_int(h, bytes); break; + default: + hash_byte(h, 'U'); + 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]; @@ -144,9 +148,10 @@ int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash) { return 0; } - sha256_init(&d); /* find package */ + 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); hash_query(zpm, sql, &d); @@ -161,14 +166,21 @@ int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash) { hash_query(zpm, sql, &d); sqlite3_free(sql); - sha256_done(&d, tmp); + /* package dependencies */ + sql = sqlite3_mprintf("dselect requires from packagedeps" + " where printf('%%q-%%q-%%d',package,version,release) = %Q" + "order by requires", + pkgid); + hash_query(zpm, sql, &d); + sqlite3_free(sql); + + blake2b_final(&d, tmp, sizeof tmp); for (i=0; i<32; i++) { sprintf(hash+i*2, "%02x", (unsigned)tmp[i]); } hash[64] = 0; return 1; - } int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash) {