Skip to documentation
SLOP

tiny.reticulum.crypto.hmac

Reference tiny.reticulum crypto hmac

Defined in crypto.

API (7)

Actions

Public operations.

Types and contracts

Public types and contracts.

Values and defaults

Public values and defaults.

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

Source

Called byCallsNo direct callsprivate sourcelib.reticulum.src.crypto.hkdfexpandcrypto.hmacsigncrypto.hmac.Signerfinal
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.reticulum.src.crypto.hkdfexpandcrypto.hmacsigncrypto.hmac.Signerinit
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.reticulum.src.crypto.hkdfexpandcrypto.hmacsigncrypto.hmac.Signerupdate
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallscrypto.hkdfderivecrypto.hmacverifytest sourcelib.reticulum.src.crypto.testtest: RFC 4231 test cases 1 and 2 HMA...test sourcelib.reticulum.src.crypto.test.test_Reticulum@...py:77-114 authenticated short tokencrypto.token.Tokenencryptcrypto.hmac.Signerfinalcrypto.hmac.Signerinitcrypto.hmac.Signerupdatecrypto.hmacsign
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.reticulum.src.crypto.testtest: RFC 4231 test cases 1 and 2 HMA...crypto.token.Tokenverifycrypto.hmacsigncrypto.hmacverify
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/reticulum/src/crypto/hmac.zig

zig
const std = @import("std");const HmacSha256 = std.crypto.auth.hmac.sha2.HmacSha256;pub const tag_length: u8 = HmacSha256.mac_length;/// An HMAC-SHA256 state that takes its input in pieces and then gives the/// 32-byte tag. The key derivation feeds three pieces into one of these for/// every output block, so it needs no buffer holding them together.pub const Signer = struct {    state: HmacSha256,    pub fn init(key: []const u8) Signer {        return .{ .state = HmacSha256.init(key) };    }    pub fn update(self: *Signer, data: []const u8) void {        self.state.update(data);    }    pub fn final(self: *Signer) [tag_length]u8 {        var tag: [tag_length]u8 = undefined;        self.state.final(&tag);        return tag;    }};/// Returns the 32-byte HMAC-SHA256 tag of some data under a key, following/// Reticulum@1.5.0 RNS/Cryptography/HMAC.py:27-45.pub fn sign(key: []const u8, data: []const u8) [tag_length]u8 {    var signer = Signer.init(key);    signer.update(data);    return signer.final();}/// Returns whether a tag matches the one the key and data give, following/// Reticulum@1.5.0 RNS/Cryptography/HMAC.py:185-188. The comparison takes the/// same time whatever the bytes are, so a failure says nothing about how far/// the tag matched.pub fn verify(key: []const u8, data: []const u8, tag: [tag_length]u8) bool {    const expected = sign(key, data);    return std.crypto.timing_safe.eql([tag_length]u8, expected, tag);}

Source: lib/reticulum/src/crypto/root.zig:47

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

Audit

Definitions8
Public names8
Members1
Version26.7.0
Revisiondaab053ee433