Function encrypt [src]

c: ciphertext: output buffer should be of size m.len tag: authentication tag: output MAC m: message ad: Associated Data npub: public nonce k: private key

Prototype

pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void

Parameters

c: []u8tag: *[tag_length]u8m: []const u8ad: []const u8npub: [nonce_length]u8k: [key_length]u8

Source

pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void { debug.assert(c.len == m.len); const extended = extend(rounds, k, npub); var block0 = [_]u8{0} ** 64; const mlen0 = @min(32, m.len); @memcpy(block0[32..][0..mlen0], m[0..mlen0]); Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); @memcpy(c[0..mlen0], block0[32..][0..mlen0]); Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce); var mac = Poly1305.init(block0[0..32]); mac.update(ad); mac.update(c); mac.final(tag); }