Skip to documentation
SLOP

tiny.reticulum.wire.hash

Reference tiny.reticulum wire hash

Defined in wire.

API (4)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callswirehash
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsnode.announcerunprivate sourcelib.reticulum.src.node.fixture.testrelayHoldsnode.inboundrunnode.linkopennode.linksend+26 moreprivate sourcelib.reticulum.src.wire.hashsuffixOffsetwire.hashfull
Static calls · unresolved targets: 3 · external targets: 0.
Called byCallsprivate sourcelib.reticulum.src.wire.testcheckHashVectorprivate sourcelib.reticulum.src.wire.hashsuffixOffsetwire.hashhashableLength
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.reticulum.src.properties.link.LinkIdspropertyprivate sourcelib.reticulum.src.wire.testcheckHashVectorwire.hashfullwire.hashtruncated
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/reticulum/src/wire/hash.zig

zig
const std = @import("std");const flags = @import("flags.zig");const header = @import("header.zig");const Sha256 = std.crypto.hash.sha2.Sha256;const assert = std.debug.assert;pub const HashError = error{PacketTooShort};fn suffixOffset(bytes: []const u8) HashError!usize {    if (bytes.len < 1) return error.PacketTooShort;    const header_type = flags.Flags.decode(bytes[0]).header;    if (bytes.len < header.headerLength(header_type)) return error.PacketTooShort;    return switch (header_type) {        .one => 2,        .two => 18,    };}/// Returns how many bytes a packet hash covers: one for the masked flags byte/// plus everything from the destination hash onward, so a caller can size a/// buffer or check a bound before it hashes a packet, following Reticulum@1.5.0/// RNS/Packet.py:353-357. The call returns `error.PacketTooShort` for an empty/// input, and for bytes shorter than the header their flags byte claims.pub fn hashableLength(bytes: []const u8) HashError!usize {    const offset = try suffixOffset(bytes);    assert(offset <= bytes.len);    return 1 + bytes.len - offset;}/// Returns the 32-byte SHA-256 digest that names one Reticulum datagram/// (*packet*), so a caller can match the proof sent back for a packet to the/// packet it answers or recognize one it has already handled. The digest covers/// the low four bits of the packet's first byte followed by the destination/// hash onward, which leaves out the hop count and the 16 bytes a carrying node/// inserts, so the name holds still at every node the packet crosses. The two/// pieces stream into the hash state where they lie, so the call copies the/// hashable part nowhere. The call returns `error.PacketTooShort` for an empty/// input, and for bytes shorter than the header their flags byte claims.pub fn full(bytes: []const u8) HashError![32]u8 {    const offset = try suffixOffset(bytes);    assert(offset <= bytes.len);    const first = [1]u8{bytes[0] & 0x0f};    var state = Sha256.init(.{});    state.update(&first);    state.update(bytes[offset..]);    var result: [32]u8 = undefined;    state.final(&result);    return result;}/// Returns the first 16 bytes of the full hash of one Reticulum datagram/// (*packet*), the width carried as the destination so a caller can address the/// proof sent back for a packet, following Reticulum@1.5.0/// RNS/Packet.py:349-351.pub fn truncated(bytes: []const u8) HashError![16]u8 {    const result = try full(bytes);    return result[0..16].*;}

Source: lib/reticulum/src/wire/root.zig:50

zig
pub const hash = @import("hash.zig");

Complete caller list for wire.hash.full

31 direct callers.

Audit

Definitions5
Public names5
Members1
Version26.7.0
Revisiondaab053ee433