tiny.reticulum.wire.proof
Defined in wire.
API (13)
Actions
Public operations.
decode: Splits a proof payload into its pieces, and its length decides the form: 96 bytes give a hash and a signature, and 64 give a signature, following Reticulum@1.5.0 RNS/Packet.py:403-404.destinationHash: Returns the first 16 bytes of a proved packet's hash as the destination for addressing the proof packet sent back, following Reticulum@1.5.0 RNS/Packet.py:381-384.encode: Writes a built proof payload intooutfor sending and returns the bytes written, following Reticulum@1.5.0 RNS/Packet.py:403-404.encodedLength
Types and contracts
Public types and contracts.
Values and defaults
Public values and defaults.
explicit_bytes: 96 bytes, a proof payload that carries the proved packet's hash ahead of the signature, for sizing or recognizing the longer of the two proof payloads, following Reticulum@1.5.0 RNS/Packet.py:403.implicit_bytes: 64 bytes, a proof payload that carries the signature alone, which the receiver matches against a packet it is already waiting on, for sizing or recognizing the shorter of the two proof payloads, following Reticulum@1.5.0 RNS/Packet.py:404.packet_hash_bytes: 32 bytes, the width of the packet hash a proof (the signed reply that tells a sender its packet arrived) signs, for sizing the hash, following Reticulum@1.5.0 RNS/Packet.py:403.signature_bytes: 64 bytes, the width of the Ed25519 signature a proof carries, for sizing the signature, following Reticulum@1.5.0 RNS/Packet.py:403-404.
Source
Source: lib/reticulum/src/wire/proof.zig
zig
const std = @import("std");/// 32 bytes, the width of the packet hash a proof (the signed reply that tells/// a sender its packet arrived) signs, for sizing the hash, following/// Reticulum@1.5.0 RNS/Packet.py:403.pub const packet_hash_bytes: u16 = 32;/// 64 bytes, the width of the Ed25519 signature a proof carries, for sizing the/// signature, following Reticulum@1.5.0 RNS/Packet.py:403-404.pub const signature_bytes: u16 = 64;/// 96 bytes, a proof payload that carries the proved packet's hash ahead of the/// signature, for sizing or recognizing the longer of the two proof payloads,/// following Reticulum@1.5.0 RNS/Packet.py:403.pub const explicit_bytes: u16 = packet_hash_bytes + signature_bytes;/// 64 bytes, a proof payload that carries the signature alone, which the/// receiver matches against a packet it is already waiting on, for sizing or/// recognizing the shorter of the two proof payloads, following Reticulum@1.5.0/// RNS/Packet.py:404.pub const implicit_bytes: u16 = signature_bytes;pub const Explicit = struct { packet_hash: [packet_hash_bytes]u8, signature: [signature_bytes]u8,};pub const Implicit = struct { signature: [signature_bytes]u8,};pub const Proof = union(enum) { explicit: Explicit, implicit: Implicit,};pub const DecodeError = error{InvalidLength};pub const EncodeError = error{OutputTooSmall};/// Splits a proof payload into its pieces, and its length decides the form: 96/// bytes give a hash and a signature, and 64 give a signature, following/// Reticulum@1.5.0 RNS/Packet.py:403-404. The call returns/// `error.InvalidLength` for every other length.pub fn decode(bytes: []const u8) DecodeError!Proof { return switch (bytes.len) { explicit_bytes => .{ .explicit = .{ .packet_hash = bytes[0..packet_hash_bytes].*, .signature = bytes[packet_hash_bytes..explicit_bytes].*, } }, implicit_bytes => .{ .implicit = .{ .signature = bytes[0..implicit_bytes].*, } }, else => error.InvalidLength, };}pub fn encodedLength(value: Proof) u16 { return switch (value) { .explicit => explicit_bytes, .implicit => implicit_bytes, };}/// Writes a built proof payload into `out` for sending and returns the bytes/// written, following Reticulum@1.5.0 RNS/Packet.py:403-404. The call returns/// `error.OutputTooSmall` when `out` is shorter than the payload.pub fn encode(value: Proof, out: []u8) EncodeError![]u8 { const length: usize = encodedLength(value); if (out.len < length) return error.OutputTooSmall; switch (value) { .explicit => |explicit| { std.mem.copyForwards(u8, out[0..packet_hash_bytes], &explicit.packet_hash); std.mem.copyForwards( u8, out[packet_hash_bytes..explicit_bytes], &explicit.signature, ); }, .implicit => |implicit| { std.mem.copyForwards(u8, out[0..implicit_bytes], &implicit.signature); }, } return out[0..length];}/// Returns the first 16 bytes of a proved packet's hash as the destination for/// addressing the proof packet sent back, following Reticulum@1.5.0/// RNS/Packet.py:381-384.pub fn destinationHash(packet_hash: [packet_hash_bytes]u8) [16]u8 { return packet_hash[0..16].*;}test "Reticulum@1.5.0 RNS/Packet.py:403-404 splits and joins both proof forms" { var explicit_raw: [explicit_bytes]u8 = undefined; for (&explicit_raw, 0..) |*byte, index| byte.* = @intCast(index); const explicit = try decode(&explicit_raw); var explicit_out: [explicit_bytes]u8 = undefined; try std.testing.expectEqualSlices(u8, &explicit_raw, try encode(explicit, &explicit_out)); var implicit_raw: [implicit_bytes]u8 = undefined; for (&implicit_raw, 0..) |*byte, index| byte.* = @intCast(index); const implicit = try decode(&implicit_raw); var implicit_out: [implicit_bytes]u8 = undefined; try std.testing.expectEqualSlices(u8, &implicit_raw, try encode(implicit, &implicit_out));}test "Reticulum@1.5.0 RNS/Packet.py:381-384 truncates proof destinations" { var packet_hash: [packet_hash_bytes]u8 = undefined; for (&packet_hash, 0..) |*byte, index| byte.* = @intCast(index); try std.testing.expectEqualSlices(u8, packet_hash[0..16], &destinationHash(packet_hash));}test "Reticulum@1.5.0 RNS/Packet.py:403-404 rejects other proof lengths" { var bytes: [explicit_bytes + 1]u8 = @splat(0); try std.testing.expectError(error.InvalidLength, decode(bytes[0 .. implicit_bytes - 1])); try std.testing.expectError(error.InvalidLength, decode(bytes[0 .. implicit_bytes + 1])); try std.testing.expectError(error.InvalidLength, decode(bytes[0 .. explicit_bytes - 1])); try std.testing.expectError(error.InvalidLength, decode(&bytes));}Source: lib/reticulum/src/wire/root.zig:53
zig
pub const proof = @import("proof.zig");Complete caller list for wire.proof.decode
7 direct callers.
lib.reticulum.src.node.inbound.acceptProof[function] — private source atlib/reticulum/src/node/inbound.zig:294in nearest public ownertiny.reticulum.node.inboundlib.reticulum.src.packet.proof.test_Reticulum@1.5.0_RNS/Identity.py:943-953_builds_both_proof_lengths[function] — test source atlib/reticulum/src/packet/proof.zig:56in nearest public ownertiny.reticulum.packet.prooflib.reticulum.src.packet.proof.test_Reticulum@1.5.0_RNS/Packet.py:485-520_validates_built_proof_payloads[function] — test source atlib/reticulum/src/packet/proof.zig:71in nearest public ownertiny.reticulum.packet.prooflib.reticulum.src.properties.wire.DecoderTotal.property[function] — private source atlib/reticulum/src/properties/wire.zig:77in nearest public ownerlib.reticulum.src.properties.wirelib.reticulum.src.wire.proof.test_Reticulum@1.5.0_RNS/Packet.py:403-404_rejects_other_proof_lengths[function] — test source atlib/reticulum/src/wire/proof.zig:110in nearest public ownertiny.reticulum.wire.prooflib.reticulum.src.wire.proof.test_Reticulum@1.5.0_RNS/Packet.py:403-404_splits_and_joins_both_proof_forms[function] — test source atlib/reticulum/src/wire/proof.zig:90in nearest public ownertiny.reticulum.wire.prooflib.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.test
Audit
| Definitions | 13 |
|---|---|
| Public names | 14 |
| Members | 7 |
| Version | 26.7.0 |
| Revision | daab053ee433 |