#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;
* 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 */
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:
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];
/* 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);
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]);
}