wrap vendored blake3 in own file, #2

laumann
May 13, 2023, 10:52 AM
YM2LC6QP2D7TK3JUKOXWUWTQEGMCEGQDGPTOZPWC3BRDFNRKSZWQC

Dependencies

  • [2] L3HKOF4W wrap vendored zstd seekable in own file, #2
  • [3] XTKRT6OQ format the codebase
  • [4] Q7TKZCJP Add initial support for reading the offsets from a (fixed) change
  • [5] CYS4NENL move zstdseek files to vendor/zstdseek
  • [6] 2U7P5SFQ Change struct names "struct foo -> typedef struct Foo"
  • [7] VKLGQREY change: add base32 decode, initial deconstruction of hashed
  • [8] QYRJIOYP change: separate decoding and printing of hashed struct
  • [9] OBKF6SII change: decompress the hashed section too
  • [10] YG4DZB3A add representation of hash, decode dependencies
  • [11] 2C2EF2GK move blake3 files to vendor/blake3
  • [12] RIWSVVAS change: decompress the 'contents' with zstd_seekable
  • [13] 3FT3XTJM change: support -v/-h flags
  • [14] WMFNGOYT change: reduce printed noise, rework some code
  • [15] Y26WT3ZF change: decode message, description and timestamp
  • [*] XJ2PEH74 add meson.build
  • [*] PEUS54XQ

Change contents

  • edit in meson.build at line 31
    [2.1427]
    [17.357]
    'blake3.c',
  • replacement in change.c at line 12
    [3.269][3.285666:285700](),[2.1450][3.285666:285700](),[3.66][3.285666:285700]()
    #include "vendor/blake3/blake3.h"
    [2.1450]
    [3.818]
    #include "blake3.h"
  • edit in change.c at line 37
    [3.3][3.3:146](),[3.146][3.238:241](),[3.238][3.238:241]()
    static int
    cmp_hash(uint8_t *h1, uint8_t *h2)
    {
    size_t i;
    for (i = 0; i < BLAKE3_OUT_LEN; i++)
    if (h1[i] != h2[i])
    return 1;
    return 0;
    }
  • replacement in change.c at line 340
    [3.895][3.895:917](),[3.917][3.307:347]()
    blake3_hasher b3sum;
    uint8_t computed_hash[BLAKE3_OUT_LEN];
    [3.1172]
    [3.950]
    uint8_t computed_hash[BLAKE3_LEN];
  • edit in change.c at line 353
    [3.1055]
    [3.1055]
    blake3_hash(computed_hash, buf, hashed_len);
  • edit in change.c at line 355
    [3.1056][3.1056:1133](),[3.1133][3.363:427](),[3.427][3.1190:1191](),[3.1190][3.1190:1191]()
    blake3_hasher_init(&b3sum);
    blake3_hasher_update(&b3sum, buf, hashed_len);
    blake3_hasher_finalize(&b3sum, computed_hash, BLAKE3_OUT_LEN);
  • replacement in change.c at line 356
    [3.1304][3.428:476]()
    err = cmp_hash(computed_hash, expected_hash);
    [3.1304]
    [3.476]
    err = blake3_cmp(computed_hash, expected_hash);
  • replacement in change.c at line 360
    [3.1153][3.552:592](),[3.552][3.552:592]()
    for (i = 0; i < BLAKE3_OUT_LEN; i++)
    [3.1153]
    [3.592]
    for (i = 0; i < BLAKE3_LEN; i++)
  • replacement in change.c at line 363
    [3.674][3.674:714]()
    for (i = 0; i < BLAKE3_OUT_LEN; i++)
    [3.674]
    [3.714]
    for (i = 0; i < BLAKE3_LEN; i++)
  • file addition: blake3.h (----------)
    [18.1]
    #ifndef ANI_BLAKE3_H
    #define ANI_BLAKE3_H
    /* Wrapper for the vendored blake3 hash algorithm (the C implementation) */
    #define BLAKE3_LEN 32
    /* Hash the given input of the indicated length and put the result in out */
    void blake3_hash(uint8_t *out, uint8_t *in, size_t len);
    /* Compare two hashes */
    int blake3_cmp(uint8_t *h1, uint8_t *h2);
    #endif
  • file addition: blake3.c (----------)
    [18.1]
    #include <stdint.h>
    #include "vendor/blake3/blake3.h"
    #include "blake3.h"
    void
    blake3_hash(uint8_t *out, uint8_t *in, size_t len)
    {
    blake3_hasher b3sum;
    blake3_hasher_init(&b3sum);
    blake3_hasher_update(&b3sum, in, len);
    blake3_hasher_finalize(&b3sum, out, BLAKE3_OUT_LEN);
    }
    int
    blake3_cmp(uint8_t *h1, uint8_t *h2)
    {
    size_t i;
    for (i = 0; i < BLAKE3_OUT_LEN; i++)
    if (h1[i] != h2[i])
    return 1;
    return 0;
    }