Trending

World technology news

→
RFC 7693 and BLAKE2: Verifying build artifacts with a fixed digest profile
Software Engineering · 2015
Software Engineering2015

RFC 7693 and BLAKE2: Verifying build artifacts with a fixed digest profile

A local experiment based on the 2015 BLAKE2 specification compares incremental hashing and the effect of the digest length parameter.

Archive retrospective · Topic year 2015

Developer's JournalPublished: Dec 6, 20266 min read
Reading progress0%
In this article
  1. Identify the bytes that belong to an artifact
  2. The algorithm and output length in the 2015 document
  3. A known vector and four local checks
  4. A stream preserves the order even when chunks change
  5. A shorter profile differs from a shortened output
  6. What a matching digest tells a release pipeline

Identify the bytes that belong to an artifact

A build can deliver the same report through several mirrors. A digest lets an application check that the download matches the recorded artifact. The first decision is which bytes participate in that comparison. A text editor may change line endings, and an archive builder may write different entry timestamps even when the unpacked files look identical. This experiment hashes the bytes belonging to the delivered artifact directly. It keeps the report shown in a reader and any later serialization outside that calculation. If a separate workflow needs to compare records semantically, it can specify a normalization method and version for that purpose. Distinguishing those requirements makes it easier to diagnose a changed download or an artifact that was rebuilt from the same input. The manifest should identify the exact output that was released.

The algorithm and output length in the 2015 document

RFC 7693 is an informational publication from November 2015 that describes BLAKE2b and BLAKE2s. BLAKE2b uses 64-bit words and accepts an output length from one to 64 bytes. BLAKE2s uses 32-bit words and outputs from one to 32 bytes. A hexadecimal string can hide that distinction. A 32-byte BLAKE2b output and a 32-byte BLAKE2s output are both written as 64 hexadecimal characters. An artifact record can identify the algorithm and digest length explicitly. Two parties can also agree on how the digest is encoded and whether a keyed mode applies. Recording those choices with the artifact is more reliable than inferring them from its filename or from a library's default arguments. Migration also becomes easier when an older manifest continues to identify the profile it originally used.

Application flowConceptual sketch · summary of the article's technical flow
Illustrative diagram. Verification uses the same bytes and digest profile.

A known vector and four local checks

The Python example begins with the three-byte test input from the RFC. It compares the output to a known digest before processing a synthetic report that contains a period and a quantity. The report travels through the hash in increments of five bytes. Those increments have no connection to the locations of the line breaks. The test compares the result with a one-shot 32-byte digest and checks that the first 32 bytes of the default 64-byte result differ. Finally it changes one ASCII byte in the report and compares the new digest. Each named check printed True in Python 3.12.10. The test uses a current implementation and a controlled fixture. It offers no historical runtime benchmark and measures no real download service.

from hashlib import blake2b

known = (
    "ba80a53f981c4d0d6a2797b69f12f6e9"
    "4c212f14685ac4b74b12bb6fdbffa2d1"
    "7d87c5392aab792dc252d5de4533cc9"
    "518d38aa8dbf1925ab92386edd4009923"
)
fixture = b"period=2015-11\nunits=4\n"
streamed = blake2b(digest_size=32)
for start in range(0, len(fixture), 5):
    streamed.update(fixture[start:start + 5])

checks = {
    "rfc7693_abc": blake2b(b"abc").hexdigest() == known,
    "stream_matches": streamed.digest() == blake2b(fixture, digest_size=32).digest(),
    "truncation_differs": streamed.digest() != blake2b(fixture).digest()[:32],
    "changed_byte_differs": streamed.digest() != blake2b(fixture.replace(b"4", b"5"), digest_size=32).digest(),
}
for label, value in checks.items():
    print(f"{label}={value}")
assert all(checks.values())

A stream preserves the order even when chunks change

Streaming lets an application process a file without reading the full contents into memory. A disk read can use regular blocks while a network stream supplies irregular pieces. Both must deliver the bytes in order under the same hash profile. Changing the order of consecutive pieces changes the input. The example keeps its source in memory to isolate that behavior. In a file pipeline, the implementation should also notice an interrupted read and keep an expected length when that information is available. When a writer can replace a file at the same path, the published artifact should be identified after the write has finished. An incomplete download can have a perfectly valid digest for its partial contents. That digest must never be recorded as confirmation that the complete artifact arrived.

A shorter profile differs from a shortened output

In BLAKE2b, the output length participates in initialization. Requesting 32 bytes and producing 64 bytes before dropping half of them are distinct operations. The example compares those two outputs on the same input and makes the distinction observable. On either side of an integration, the application may return 64 hexadecimal characters for the result it decided to keep. A length check on that string alone cannot detect a disagreement about the profile. A shared fixture and an explicit profile name help resolve it. The example writes the digest as lowercase hexadecimal. An importer that converts hexadecimal into raw bytes can validate the representation and the expected size before comparing the actual digests. None of those formatting choices need to alter the bytes that belong to the artifact itself.

What a matching digest tells a release pipeline

A match means the received bytes agree with the digest provided for comparison. If a third party can replace both the artifact and its manifest, that match does not identify the origin of the artifact. The manifest can come from an authenticated release channel or be covered by a signed record. The RFC also describes a keyed mode, which this example does not exercise. When introducing a digest profile to an existing pipeline, producers and consumers can run the same fixture and retain the original profile for older records. Together these checks help diagnose an unexpected transformation separately from a hash configuration error. The release process still needs its own evidence about the origin of the manifest, the expected length, and whether the bytes were transferred in full.

347 reads ✎ Write a comment

Reader discussion

Discussion prompt

Which data would you verify before applying this development in your field?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.