Commit Graph

24 Commits

Author SHA1 Message Date
Andrew Kelley 429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
LemonBoy 134f5fd3d6 std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
Frank Denis 6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley 013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
Tadeo Kondrak 25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
xackus 5c8f7f81cd change debug.assert to testing.expect in tests 2020-11-06 22:48:54 +01:00
Jan Prudil aadccc4206 Make std.meta.Int accept a signedness parameter 2020-10-17 14:09:59 +02:00
Frank Denis 51a3d0603c std.rand: set DefaultCsprng to Gimli, and require a larger seed
`DefaultCsprng` is documented as a cryptographically secure RNG.

While `ISAAC` is a CSPRNG, the variant we have, `ISAAC64` is not.
A 64 bit seed is a bit small to satisfy that claim.

We also saw it being used with the current date as a seed, that
also defeats the point of a CSPRNG.

Set `DefaultCsprng` to `Gimli` instead of `ISAAC64`, rename
the parameter from `init_s` to `secret_seed` + add a comment to
clarify what kind of seed is expected here.

Instead of directly touching the internals of the Gimli implementation
(which can change/be architecture-specific), add an `init()` function
to the state.

Our Gimli-based CSPRNG was also not backtracking resistant. Gimli
is a permutation; it can be reverted. So, if the state was ever leaked,
future secrets, but also all the previously generated ones could be
recovered. Clear the rate after a squeeze in order to prevent this.

Finally, a dumb test was added just to exercise `DefaultCsprng` since
we don't use it anywhere.
2020-10-15 20:57:16 -04:00
Tadeo Kondrak e892ee17e6 std: move std.meta.refAllDecls to std.testing 2020-10-15 20:34:22 -04:00
Vexu 1df0f3ac24 update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
Andrew Kelley 3e24e95892 std.rand: promote normal comments to doc comments 2020-08-25 19:51:40 -07:00
Frank Denis 6f9ea9eaef Breaking: sort std/crypto functions into categories
Instead of having all primitives and constructions share the same namespace,
they are now organized by category and function family.

Types within the same category are expected to share the exact same API.
2020-08-20 23:02:05 +02:00
Andrew Kelley 4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley 44aeb38328 make rand function public, fixes crypto benchmark 2020-05-20 21:27:08 -04:00
Tadeo Kondrak 350b2adacd std.meta.IntType -> std.meta.Int 2020-04-28 19:11:31 -06:00
Andrew Kelley ca38b18879 rand: ref the decls so they get tested 2020-04-18 14:41:25 -04:00
Andrew Kelley 9e7ae06249 std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Andrew Kelley f614d94faa update std lib to take advantage of slicing with comptime indexes 2020-03-19 14:48:47 -04:00
Vexu 538d9a5dd8 remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
daurnimator 5a095a3f08 std: add Gimli based PRNG to std.rand 2020-02-06 00:16:00 +11:00
Andrew Kelley bf3ac66150 remove type coercion from array values to references
* Implements #3768. This is a sweeping breaking change that requires
   many (trivial) edits to Zig source code. Array values no longer
   coerced to slices; however one may use `&` to obtain a reference to
   an array value, which may then be coerced to a slice.

 * Adds `IrInstruction::dump`, for debugging purposes. It's useful to
   call to inspect the instruction when debugging Zig IR.

 * Fixes bugs with result location semantics. See the new behavior test
   cases, and compile error test cases.

 * Fixes bugs with `@typeInfo` not properly resolving const values.

 * Behavior tests are passing but std lib tests are not yet. There
   is more work to do before merging this branch.
2019-11-27 03:37:50 -05:00
Andrew Kelley aa0daea541 update more of the std lib to use @as 2019-11-08 15:57:25 -05:00
Andrew Kelley e0db54e89d update the codebase to use @as 2019-11-08 15:57:24 -05:00
Andrew Kelley ed36dbbd9c mv std/ lib/
that's all this commit does. further commits will fix cli flags and
such.

see #2221
2019-09-25 23:35:41 -04:00