tiny.reticulum.wire.hash
Defined in wire.
API (4)
Actions
Public operations.
full: 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.hashableLength: 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.truncated: 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.
Types and contracts
Public types and contracts.
Source
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.
tiny.reticulum.node.announce.run[function] atlib/reticulum/src/node/announce.zig:96lib.reticulum.src.node.fixture.test.relayHolds[function] — private source atlib/reticulum/src/node/fixture/test.zig:571in nearest public ownerlib.reticulum.src.node.fixture.testtiny.reticulum.node.inbound.run[function] atlib/reticulum/src/node/inbound.zig:362tiny.reticulum.node.link.open[function] atlib/reticulum/src/node/link.zig:470tiny.reticulum.node.link.send[function] atlib/reticulum/src/node/link.zig:522lib.reticulum.src.node.link.sendOnLink[function] — private source atlib/reticulum/src/node/link.zig:294in nearest public ownertiny.reticulum.node.linktiny.reticulum.node.outbound.run[function] atlib/reticulum/src/node/outbound.zig:291tiny.reticulum.node.transport.requests.answerWaiting[function] atlib/reticulum/src/node/transport/requests.zig:395lib.reticulum.src.node.transport.requests.discover[function] — private source atlib/reticulum/src/node/transport/requests.zig:259in nearest public ownertiny.reticulum.node.transport.requeststiny.reticulum.node.transport.requests.rediscover[function] atlib/reticulum/src/node/transport/requests.zig:321tiny.reticulum.node.transport.requests.send[function] atlib/reticulum/src/node/transport/requests.zig:281lib.reticulum.src.node.transport.retransmit.visit[function] — private source atlib/reticulum/src/node/transport/retransmit.zig:172in nearest public ownertiny.reticulum.node.transport.retransmitlib.reticulum.src.node.transport.rewrite.test_Reticulum@1.5.0_RNS/Transport.py:1345-1354_insertion_keeps_the_packet_hash[function] — test source atlib/reticulum/src/node/transport/rewrite.zig:94in nearest public ownertiny.reticulum.node.transport.rewritelib.reticulum.src.node.transport.rewrite.test_Reticulum@1.5.0_RNS/Transport.py:1935-1946_forwarding_and_stripping_keep_the_packet_hash[function] — test source atlib/reticulum/src/node/transport/rewrite.zig:140in nearest public ownertiny.reticulum.node.transport.rewritelib.reticulum.src.node.transport.test.expectFrameFacts[function] — private source atlib/reticulum/src/node/transport/test.zig:827in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.firstReceiptOnEveryCarrier[function] — private source atlib/reticulum/src/node/transport/test.zig:1438in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.relayData[function] — private source atlib/reticulum/src/node/transport/test.zig:181in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:1345-1356_inserts_SINGLE_data_by_a_learned_path[function] — test source atlib/reticulum/src/node/transport/test.zig:236in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:1381-1386_sends_one-hop_data_on_the_path_carrier[function] — test source atlib/reticulum/src/node/transport/test.zig:263in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:1738-1750_drops_short_and_tagless_requests_unstored[function] — test source atlib/reticulum/src/node/transport/test.zig:1107in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:1935-1940_forwards_at_two_remaining_hops[function] — test source atlib/reticulum/src/node/transport/test.zig:582in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:1941-1946_strips_at_one_remaining_hop[function] — test source atlib/reticulum/src/node/transport/test.zig:614in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:3219-3250_sends_a_tagged_request_on_one_or_every_carrier[function] — test source atlib/reticulum/src/node/transport/test.zig:1487in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.node.transport.test.test_Reticulum@1.5.0_RNS/Transport.py:737-799_rebroadcasts_twice_and_then_completes[function] — test source atlib/reticulum/src/node/transport/test.zig:381in nearest public ownerlib.reticulum.src.node.transport.testlib.reticulum.src.properties.transport.RewritesKeepHash.property[function] — private source atlib/reticulum/src/properties/transport.zig:189in nearest public ownerlib.reticulum.src.properties.transportlib.reticulum.src.properties.wire.DecoderTotal.property[function] — private source atlib/reticulum/src/properties/wire.zig:77in nearest public ownerlib.reticulum.src.properties.wiretiny.reticulum.wire.hash.truncated[function] atlib/reticulum/src/wire/hash.zig:56lib.reticulum.src.wire.test.checkAnnounceVector[function] — private source atlib/reticulum/src/wire/test.zig:190in nearest public ownerlib.reticulum.src.wire.testlib.reticulum.src.wire.test.checkHashVector[function] — private source atlib/reticulum/src/wire/test.zig:166in nearest public ownerlib.reticulum.src.wire.testlib.reticulum.src.wire.test.test_Reticulum@1.5.0_RNS/Link.py:378-389_link_data_proof_corpus_proves_the_data_hash[function] — test source atlib/reticulum/src/wire/test.zig:400in nearest public ownerlib.reticulum.src.wire.testlib.reticulum.src.wire.test.test_Reticulum@1.5.0_RNS/Packet.py:349-358_link_corpus_packet_hashes[function] — test source atlib/reticulum/src/wire/test.zig:431in nearest public ownerlib.reticulum.src.wire.test
Audit
| Definitions | 5 |
|---|---|
| Public names | 5 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |