Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/prefix:master commit in: scripts/rsync-generation/
Date: Mon, 27 Nov 2017 13:07:09
Message-Id: 1511786120.2ced4dd4b98a186dbcef48501bdcbde57ecb40c1.grobian@gentoo
1 commit: 2ced4dd4b98a186dbcef48501bdcbde57ecb40c1
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Mon Nov 27 12:35:20 2017 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Mon Nov 27 12:35:20 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=2ced4dd4
7
8 hashgen: phase 1, add BLAKE2B hashing
9
10 scripts/rsync-generation/hashgen.c | 30 +++++++++++++++++++++++++-----
11 1 file changed, 25 insertions(+), 5 deletions(-)
12
13 diff --git a/scripts/rsync-generation/hashgen.c b/scripts/rsync-generation/hashgen.c
14 index 6fc8e150d3..fed99a3132 100644
15 --- a/scripts/rsync-generation/hashgen.c
16 +++ b/scripts/rsync-generation/hashgen.c
17 @@ -1,4 +1,4 @@
18 -/* Copyright 2006-2015 Gentoo Foundation; Distributed under the GPL v2 */
19 +/* Copyright 2006-2017 Gentoo Foundation; Distributed under the GPL v2 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <strings.h>
23 @@ -9,9 +9,16 @@
24 #include <sys/time.h>
25 #include <openssl/sha.h>
26 #include <openssl/whrlpool.h>
27 +#include <blake2.h>
28
29 /* Generate thick Manifests based on thin Manifests */
30 -/* gcc -o hashgen -fopenmp -Wall -Werror -O3 -pipe -lssl -lcrypto hashgen.c */
31 +
32 +/* In order to build this program, the following packages are required:
33 + * - app-crypt/libb2 (for BLAKE2, for as long as openssl doesn't include it)
34 + * - dev-libs/openssl (for SHA, WHIRLPOOL)
35 + * compile like this
36 + * ${CC} -o hashgen -fopenmp ${CFLAGS} -lssl -lcrypto -lb2 hashgen.c
37 + */
38
39 static inline void
40 hex_hash(char *out, const unsigned char *buf, const int length)
41 @@ -31,11 +38,13 @@ write_hashes(const char *root, const char *name, const char *type, FILE *m)
42 char sha256[(SHA256_DIGEST_LENGTH * 2) + 1];
43 char sha512[(SHA512_DIGEST_LENGTH * 2) + 1];
44 char whrlpl[(WHIRLPOOL_DIGEST_LENGTH * 2) + 1];
45 + char blak2b[(BLAKE2B_OUTBYTES * 2) + 1];
46 char data[8096];
47 size_t len;
48 SHA256_CTX s256;
49 SHA512_CTX s512;
50 WHIRLPOOL_CTX whrl;
51 + blake2b_state bl2b;
52
53 snprintf(fname, sizeof(fname), "%s/%s", root, name);
54 if ((f = fopen(fname, "r")) == NULL)
55 @@ -44,6 +53,7 @@ write_hashes(const char *root, const char *name, const char *type, FILE *m)
56 SHA256_Init(&s256);
57 SHA512_Init(&s512);
58 WHIRLPOOL_Init(&whrl);
59 + blake2b_init(&bl2b, BLAKE2B_OUTBYTES);
60
61 while ((len = fread(data, 1, sizeof(data), f)) > 0) {
62 flen += len;
63 @@ -61,6 +71,10 @@ write_hashes(const char *root, const char *name, const char *type, FILE *m)
64 {
65 WHIRLPOOL_Update(&whrl, data, len);
66 }
67 +#pragma omp section
68 + {
69 + blake2b_update(&bl2b, data, len);
70 + }
71 }
72 }
73
74 @@ -83,11 +97,17 @@ write_hashes(const char *root, const char *name, const char *type, FILE *m)
75 WHIRLPOOL_Final(whrlplbuf, &whrl);
76 hex_hash(whrlpl, whrlplbuf, WHIRLPOOL_DIGEST_LENGTH);
77 }
78 +#pragma omp section
79 + {
80 + unsigned char blak2bbuf[BLAKE2B_OUTBYTES];
81 + blake2b_final(&bl2b, blak2bbuf, BLAKE2B_OUTBYTES);
82 + hex_hash(blak2b, blak2bbuf, WHIRLPOOL_DIGEST_LENGTH);
83 + }
84 }
85 fclose(f);
86
87 - fprintf(m, "%s %s %zd SHA256 %s SHA512 %s WHIRLPOOL %s\n",
88 - type, name, flen, sha256, sha512, whrlpl);
89 + fprintf(m, "%s %s %zd SHA256 %s SHA512 %s WHIRLPOOL %s BLAKE2B %s\n",
90 + type, name, flen, sha256, sha512, whrlpl, blak2b);
91 }
92
93 static char
94 @@ -149,7 +169,7 @@ process_dir(const char *dir)
95 struct timeval tv[2];
96
97 /* set mtime of Manifest to the one of the parent dir, this way
98 - * we enure the Manifest gets mtime bumped upon any change made
99 + * we ensure the Manifest gets mtime bumped upon any change made
100 * to the directory, that is, a DIST change (Manifest itself) or
101 * any other change (ebuild, files, metadata) */
102 if (stat(dir, &s)) {