Skip to content

Commit

Permalink
take advantage of std.os.linux.getauxval
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Dec 18, 2020
1 parent cbd81e6 commit 9aa77b5
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/std/start.zig
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,7 @@ fn posixCallMainAndExit() noreturn {
if (!@hasDecl(root, "use_AT_RANDOM_auxval") or root.use_AT_RANDOM_auxval) {
// Initialize the per-thread CSPRNG since Linux gave us the handy-dandy
// AT_RANDOM. This depends on the TLS initialization above.
var i: usize = 0;
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
switch (auxv[i].a_type) {
std.elf.AT_RANDOM => {
// "The address of sixteen bytes containing a random value."
initCryptoSeedFromAuxVal(auxv[i].a_un.a_val);
break;
},
else => continue,
}
}
initCryptoSeedFromAuxVal(std.os.linux.getauxval(std.elf.AT_RANDOM));
}

// TODO This is disabled because what should we do when linking libc and this code
Expand Down Expand Up @@ -284,6 +274,7 @@ fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.C)

fn initCryptoSeedFromAuxVal(addr: usize) void {
if (addr == 0) return;
// "The address of sixteen bytes containing a random value."
const ptr = @intToPtr(*[16]u8, addr);
tlcsprng.init(ptr.*);
// Clear AT_RANDOM after we use it, otherwise our secure
Expand Down

0 comments on commit 9aa77b5

Please sign in to comment.