| ... | @@ -219,17 +219,7 @@ fn posixCallMainAndExit() noreturn { | ... | @@ -219,17 +219,7 @@ fn posixCallMainAndExit() noreturn { |
| 219 | if (!@hasDecl(root, "use_AT_RANDOM_auxval") or root.use_AT_RANDOM_auxval) { | 219 | if (!@hasDecl(root, "use_AT_RANDOM_auxval") or root.use_AT_RANDOM_auxval) { |
| 220 | // Initialize the per-thread CSPRNG since Linux gave us the handy-dandy | 220 | // Initialize the per-thread CSPRNG since Linux gave us the handy-dandy |
| 221 | // AT_RANDOM. This depends on the TLS initialization above. | 221 | // AT_RANDOM. This depends on the TLS initialization above. |
| 222 | var i: usize = 0; | 222 | initCryptoSeedFromAuxVal(std.os.linux.getauxval(std.elf.AT_RANDOM)); |
| 223 | while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { | | |
| 224 | switch (auxv[i].a_type) { | | |
| 225 | std.elf.AT_RANDOM => { | | |
| 226 | // "The address of sixteen bytes containing a random value." | | |
| 227 | initCryptoSeedFromAuxVal(auxv[i].a_un.a_val); | | |
| 228 | break; | | |
| 229 | }, | | |
| 230 | else => continue, | | |
| 231 | } | | |
| 232 | } | | |
| 233 | } | 223 | } |
| 234 | | 224 | |
| 235 | // TODO This is disabled because what should we do when linking libc and this code | 225 | // TODO This is disabled because what should we do when linking libc and this code |
| ... | @@ -284,6 +274,7 @@ fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.C) | ... | @@ -284,6 +274,7 @@ fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.C) |
| 284 | | 274 | |
| 285 | fn initCryptoSeedFromAuxVal(addr: usize) void { | 275 | fn initCryptoSeedFromAuxVal(addr: usize) void { |
| 286 | if (addr == 0) return; | 276 | if (addr == 0) return; |
| | 277 | // "The address of sixteen bytes containing a random value." |
| 287 | const ptr = @intToPtr(*[16]u8, addr); | 278 | const ptr = @intToPtr(*[16]u8, addr); |
| 288 | tlcsprng.init(ptr.*); | 279 | tlcsprng.init(ptr.*); |
| 289 | // Clear AT_RANDOM after we use it, otherwise our secure | 280 | // Clear AT_RANDOM after we use it, otherwise our secure |