DoxigAlpha

addEntropy

Inserts entropy to refresh the internal state.

Function parameters

Parameters

#
self:*Self
bytes:[]const u8

The seed must be uniform, secret and `secret_seed_length` bytes long.

Functions

#
init
The seed must be uniform, secret and `secret_seed_length` bytes long.
addEntropy
Inserts entropy to refresh the internal state.
random
Returns a `std.Random` structure backed by the current RNG.
fill
Fills the buffer with random bytes.

= Cipher.key_length

Values

#
secret_seed_length
= Cipher.key_length

Source

Implementation

#
pub fn addEntropy(self: *Self, bytes: []const u8) void {
    var i: usize = 0;
    while (i + Cipher.key_length <= bytes.len) : (i += Cipher.key_length) {
        Cipher.xor(
            self.state[0..Cipher.key_length],
            self.state[0..Cipher.key_length],
            0,
            bytes[i..][0..Cipher.key_length].*,
            nonce,
        );
    }
    if (i < bytes.len) {
        var k = [_]u8{0} ** Cipher.key_length;
        const src = bytes[i..];
        @memcpy(k[0..src.len], src);
        Cipher.xor(
            self.state[0..Cipher.key_length],
            self.state[0..Cipher.key_length],
            0,
            k,
            nonce,
        );
    }
    self.refill();
}