| ... | ... | @@ -219,17 +219,7 @@ fn posixCallMainAndExit() noreturn { |
| 219 | 219 | if (!@hasDecl(root, "use_AT_RANDOM_auxval") or root.use_AT_RANDOM_auxval) { |
| 220 | 220 | // Initialize the per-thread CSPRNG since Linux gave us the handy-dandy |
| 221 | 221 | // AT_RANDOM. This depends on the TLS initialization above. |
| 222 | | var i: usize = 0; |
| 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 | | } |
| 222 | initCryptoSeedFromAuxVal(std.os.linux.getauxval(std.elf.AT_RANDOM)); |
| 233 | 223 | } |
| 234 | 224 | |
| 235 | 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 | 274 | |
| 285 | 275 | fn initCryptoSeedFromAuxVal(addr: usize) void { |
| 286 | 276 | if (addr == 0) return; |
| 277 | // "The address of sixteen bytes containing a random value." |
| 287 | 278 | const ptr = @intToPtr(*[16]u8, addr); |
| 288 | 279 | tlcsprng.init(ptr.*); |
| 289 | 280 | // Clear AT_RANDOM after we use it, otherwise our secure |