Function fill [src]
Fills the buffer with random bytes.
Prototype
pub fn fill(self: *Self, buf_: []u8) void
Parameters
self: *Self
buf_: []u8
Source
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;
}
}