fill
Fills the buffer with random bytes.
Function parameters
Parameters
- self:*Self
- buf_:[]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 fill(self: *Self, buf_: []u8) void {
const bytes = self.state[Cipher.key_length..];
var buf = buf_;
const avail = bytes.len - self.offset;
if (avail > 0) {
// Bytes from the current block
const n = @min(avail, buf.len);
@memcpy(buf[0..n], bytes[self.offset..][0..n]);
@memset(bytes[self.offset..][0..n], 0);
buf = buf[n..];
self.offset += n;
}
if (buf.len == 0) return;
self.refill();
// Full blocks
while (buf.len >= bytes.len) {
@memcpy(buf[0..bytes.len], bytes);
buf = buf[bytes.len..];
self.refill();
}
// Remaining bytes
if (buf.len > 0) {
@memcpy(buf, bytes[0..buf.len]);
@memset(bytes[0..buf.len], 0);
self.offset = buf.len;
}
}