tiny.reticulum.hash
Defined in tiny.reticulum.
API (12)
Actions
Public operations.
Hasher.finalFullHasher.finalNameHasher.finalTruncatedHasher.initHasher.updatefull: Returns the complete 32-byte SHA-256 digest of some bytes, following Reticulum@1.5.0 RNS/Identity.py:352.name: Returns the first 10 bytes of the SHA-256 digest of some bytes, following Reticulum@1.5.0 RNS/Identity.py:83 and Reticulum@1.5.0 RNS/Destination.py:120.truncated: Returns the first 16 bytes of the SHA-256 digest of some bytes, following Reticulum@1.5.0 RNS/Identity.py:362 and Reticulum@1.5.0 RNS/Reticulum.py:148.
Types and contracts
Public types and contracts.
Hasher: A SHA-256 state that takes its input in pieces and then gives any of the three widths.
Values and defaults
Public values and defaults.
full_bytes: 32 bytes, the width of a complete SHA-256 digest, following Reticulum@1.5.0 RNS/Identity.py:352.name_bytes: 10 bytes, the width a destination's announced name hash and a rotating key's identifier take, following Reticulum@1.5.0 RNS/Identity.py:83.truncated_bytes: 16 bytes, the width a destination hash and an identity hash take on the wire, following Reticulum@1.5.0 RNS/Identity.py:362 and Reticulum@1.5.0 RNS/Reticulum.py:148.
Source
Source: lib/reticulum/src/hash.zig
zig
const std = @import("std");const Sha256 = std.crypto.hash.sha2.Sha256;/// 32 bytes, the width of a complete SHA-256 digest, following Reticulum@1.5.0/// RNS/Identity.py:352.pub const full_bytes: usize = 32;/// 16 bytes, the width a destination hash and an identity hash take on the/// wire, following Reticulum@1.5.0 RNS/Identity.py:362 and Reticulum@1.5.0/// RNS/Reticulum.py:148.pub const truncated_bytes: usize = 16;/// 10 bytes, the width a destination's announced name hash and a rotating key's/// identifier take, following Reticulum@1.5.0 RNS/Identity.py:83.pub const name_bytes: usize = 10;/// Returns the complete 32-byte SHA-256 digest of some bytes, following/// Reticulum@1.5.0 RNS/Identity.py:352.pub fn full(bytes: []const u8) [full_bytes]u8 { var hasher = Hasher.init(); hasher.update(bytes); return hasher.finalFull();}/// Returns the first 16 bytes of the SHA-256 digest of some bytes, following/// Reticulum@1.5.0 RNS/Identity.py:362 and Reticulum@1.5.0/// RNS/Reticulum.py:148.pub fn truncated(bytes: []const u8) [truncated_bytes]u8 { var hasher = Hasher.init(); hasher.update(bytes); return hasher.finalTruncated();}/// Returns the first 10 bytes of the SHA-256 digest of some bytes, following/// Reticulum@1.5.0 RNS/Identity.py:83 and Reticulum@1.5.0/// RNS/Destination.py:120.pub fn name(bytes: []const u8) [name_bytes]u8 { var hasher = Hasher.init(); hasher.update(bytes); return hasher.finalName();}/// A SHA-256 state that takes its input in pieces and then gives any of the/// three widths. Reticulum hashes joined transcripts, so a caller feeds the/// pieces in turn and needs no buffer holding them all at once. Taking a digest/// works on a copy of the state, so one hasher gives more than one width.pub const Hasher = struct { state: Sha256, pub fn init() Hasher { return .{ .state = Sha256.init(.{}) }; } pub fn update(self: *Hasher, bytes: []const u8) void { self.state.update(bytes); } pub fn finalFull(self: Hasher) [full_bytes]u8 { var state = self.state; var result: [full_bytes]u8 = undefined; state.final(&result); return result; } pub fn finalTruncated(self: Hasher) [truncated_bytes]u8 { const result = self.finalFull(); return result[0..truncated_bytes].*; } pub fn finalName(self: Hasher) [name_bytes]u8 { const result = self.finalFull(); return result[0..name_bytes].*; }};Source: lib/reticulum/src/root.zig:62
zig
pub const hash = @import("hash.zig");Audit
| Definitions | 13 |
|---|---|
| Public names | 13 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |