structstd.crypto.stream.salsa[src]

Types

Type FunctionSalsa[src]

The Salsa stream cipher.

Parameters

rounds: comptime_int

Values

Constantnonce_length[src]

Nonce length in bytes.

Source Code

Source code
pub const nonce_length = 8

Constantkey_length[src]

Key length in bytes.

Source Code

Source code
pub const key_length = 32

Functions

Functionxor[src]

pub fn xor(out: []u8, in: []const u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void

Add the output of the Salsa stream cipher to in and stores the result into out. WARNING: This function doesn't provide authenticated encryption. Using the AEAD or one of the box versions is usually preferred.

Parameters

out: []u8
in: []const u8
counter: u64
key: [key_length]u8
nonce: [nonce_length]u8

Source Code

Source code
pub fn xor(out: []u8, in: []const u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void {
    debug.assert(in.len == out.len);

    var d: [4]u32 = undefined;
    d[0] = mem.readInt(u32, nonce[0..4], .little);
    d[1] = mem.readInt(u32, nonce[4..8], .little);
    d[2] = @as(u32, @truncate(counter));
    d[3] = @as(u32, @truncate(counter >> 32));
    SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d);
}

Source Code

Source code
pub fn Salsa(comptime rounds: comptime_int) type {
    return struct {
        /// Nonce length in bytes.
        pub const nonce_length = 8;
        /// Key length in bytes.
        pub const key_length = 32;

        /// Add the output of the Salsa stream cipher to `in` and stores the result into `out`.
        /// WARNING: This function doesn't provide authenticated encryption.
        /// Using the AEAD or one of the `box` versions is usually preferred.
        pub fn xor(out: []u8, in: []const u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void {
            debug.assert(in.len == out.len);

            var d: [4]u32 = undefined;
            d[0] = mem.readInt(u32, nonce[0..4], .little);
            d[1] = mem.readInt(u32, nonce[4..8], .little);
            d[2] = @as(u32, @truncate(counter));
            d[3] = @as(u32, @truncate(counter >> 32));
            SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d);
        }
    };
}

Type FunctionXSalsa[src]

The XSalsa stream cipher.

Parameters

rounds: comptime_int

Values

Constantnonce_length[src]

Nonce length in bytes.

Source Code

Source code
pub const nonce_length = 24

Constantkey_length[src]

Key length in bytes.

Source Code

Source code
pub const key_length = 32

Functions

Functionxor[src]

pub fn xor(out: []u8, in: []const u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void

Add the output of the XSalsa stream cipher to in and stores the result into out. WARNING: This function doesn't provide authenticated encryption. Using the AEAD or one of the box versions is usually preferred.

Parameters

out: []u8
in: []const u8
counter: u64
key: [key_length]u8
nonce: [nonce_length]u8

Source Code

Source code
pub fn xor(out: []u8, in: []const u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void {
    const extended = extend(rounds, key, nonce);
    Salsa(rounds).xor(out, in, counter, extended.key, extended.nonce);
}

Source Code

Source code
pub fn XSalsa(comptime rounds: comptime_int) type {
    return struct {
        /// Nonce length in bytes.
        pub const nonce_length = 24;
        /// Key length in bytes.
        pub const key_length = 32;

        /// Add the output of the XSalsa stream cipher to `in` and stores the result into `out`.
        /// WARNING: This function doesn't provide authenticated encryption.
        /// Using the AEAD or one of the `box` versions is usually preferred.
        pub fn xor(out: []u8, in: []const u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void {
            const extended = extend(rounds, key, nonce);
            Salsa(rounds).xor(out, in, counter, extended.key, extended.nonce);
        }
    };
}

TypeSalsa20[src]

The Salsa cipher with 20 rounds.

Source Code

Source code
pub const Salsa20 = Salsa(20)

TypeXSalsa20[src]

The XSalsa cipher with 20 rounds.

Source Code

Source code
pub const XSalsa20 = XSalsa(20)

Source Code

Source code
pub const salsa = struct {
    pub const Salsa = @import("crypto/salsa20.zig").Salsa;
    pub const XSalsa = @import("crypto/salsa20.zig").XSalsa;
    pub const Salsa20 = @import("crypto/salsa20.zig").Salsa20;
    pub const XSalsa20 = @import("crypto/salsa20.zig").XSalsa20;
}