tiny.reticulum.crypto.hmac
Defined in crypto.
API (7)
Actions
Public operations.
Signer.finalSigner.initSigner.updatesign: Returns the 32-byte HMAC-SHA256 tag of some data under a key, following Reticulum@1.5.0 RNS/Cryptography/HMAC.py:27-45.verify: Returns whether a tag matches the one the key and data give, following Reticulum@1.5.0 RNS/Cryptography/HMAC.py:185-188.
Types and contracts
Public types and contracts.
Signer: An HMAC-SHA256 state that takes its input in pieces and then gives the 32-byte tag.
Values and defaults
Public values and defaults.
Source
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
| Definitions | 8 |
|---|---|
| Public names | 8 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |