2617 Commits

Author SHA1 Message Date
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
Andrew Kelley
f701459f04
Merge pull request #6685 from ifreund/bufprint0
std/fmt: rename allocPrint0() to allocPrintZ(), add bufPrintZ()
2020-10-15 20:51:25 -04:00
Frank Denis
cb44f27104 std/crypto/hmac: remove HmacBlake2s256 definition
HMAC is a generic construction, so we allow it to be instantiated
with any hash function.

In practice, HMAC is almost exclusively used with MD5, SHA1 and SHA2,
so it makes sense to define some shortcuts for them.

However, defining `HmacBlake2s256` is a bit weird (and why
specifically that one, and not other hash functions we also support?).
There would be nothing wrong with that construction, but it's not
used in any standard protocol and would be a curious choice.

BLAKE2 being a keyed hash function, it doesn't need HMAC to be used as
a MAC, so that also doesn't make it a good example of a possible hash
function for HMAC.

This commit doesn't remove the ability to use a Hmac(Blake2s256) type
if, for some reason, applications really need this, but it removes
HmacBlake2s256 as a constant.
2020-10-15 20:50:34 -04:00
Andrew Kelley
a66449c1ed
Merge pull request #6616 from fengb/darwin-rusage
Darwin rusage
2020-10-15 20:49:54 -04:00
Tadeo Kondrak
e892ee17e6 std: move std.meta.refAllDecls to std.testing 2020-10-15 20:34:22 -04:00
Andrew Kelley
e17297102a Merge branch 'kubkon-enable-stage2-macos-tests'
closes #6661
2020-10-15 16:48:44 -07:00
Andrew Kelley
d91e75f5ca getExternalExecutor fixups regarding dynamic linker
* std.Target.standardDynamicLinkerPath: macOS has a dynamic linker
 * no need to override the default dynamic linker in the macos
   CrossTarget initialization in the tests
 * in getExternalExecutor, when validating the dynamic linker path, take
   into account the standard dynamic linker path.
2020-10-15 16:44:16 -07:00
Clayton Voges
8c4031fd87 replaced inStream() with reader()
`inStream()` is now deprecated and deserves replacing.
2020-10-15 19:30:21 -04:00
Jakub Konka
0e1afee732 Enable stage2 end-to-end tests on macOS run natively
This commit enables stage2 end-to-end tests to run natively on macOS
(where and when applicable). Since QEMU on macOS doesn't support
the same type of architecture emulation as it does on linux (i.e.,
there is no `qemu-x86_64` for instance), this commit ensures that we
specify a path to dynamic linker on macOS (`/usr/lib/dyld`) which
is then checked for existence in `std.CrossTarget.getExternalExecutor()`
function, and if exists, we can run the test natively.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-15 15:59:16 -07:00
Frank Denis
f3667e8a80 std/crypto/25519: do cofactored ed25519 verification
This is slightly slower but makes our verification function compatible
with batch signatures. Which, in turn, makes blockchain people happy.
And we want to make our users happy.

Add convenience functions to substract edwards25519 points and to
clear the cofactor.
2020-10-15 18:49:10 -04:00
Isaac Freund
d52035f401
std/fmt: add bufPrintZ() 2020-10-15 12:21:19 +02:00
Isaac Freund
b259696cfb
std/fmt: rename allocPrint0() to allocPrintZ()
This is consistent with other standard library functions working with
null terminated pointers/slices.
2020-10-15 12:21:14 +02:00
Andrew Kelley
3b4432d9a6
Merge pull request #6655 from kprotty/timers
Integrate std.time.sleep with the event loop
2020-10-14 21:49:45 -04:00
Andrew Kelley
2f52f95b92
Merge pull request #6669 from ifreund/color-fixes
std/build: support --color
2020-10-14 21:35:43 -04:00
Matthew Knight
352976ed23
Event Channel: updated linked list node initialization (#6652)
fixed node init method
2020-10-14 21:33:53 -04:00
Rocknest
548fd6e87b force comptime on comptimePrint 2020-10-14 01:03:01 -04:00
Andrew Kelley
3811602ad7
Merge pull request #6643 from jedisct1/chacha-vec
std/crypto: add a vectorized ChaCha20 implementation
2020-10-14 00:52:36 -04:00
Isaac Freund
f01c3150c1
std/build: support --color 2020-10-13 20:06:03 +02:00
Andrew Kelley
27b04d5905 disable the failing std lib freebsd tests
enable std lib freebsd tests on the CI

See #1759
2020-10-12 20:08:23 -07:00
Andrew Kelley
c19dcafa17 Merge remote-tracking branch 'origin/master' into llvm11 2020-10-12 17:57:35 -07:00
Vignesh Rajagopalan
2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
kprotty
12508025a4 Add more comments & cleanup AutoResetEvent 2020-10-11 19:16:07 -05:00
kprotty
e9a4c3dd82 fix DelayQueue typos 2020-10-11 14:21:36 -05:00
kprotty
aa53f6d0b5 integrate std.time.sleep with the event loop 2020-10-11 14:18:19 -05:00
kprotty
a42c0f88e0 AutoResetEvent 2020-10-11 14:17:51 -05:00
Frank Denis
9f109ba0eb Simpler ChaCha20 vector code 2020-10-10 22:45:41 +02:00
Frank Denis
459128e059 Use an array of comptime_int for shuffle masks
Suggested by @LemonBoy - Thanks!
2020-10-10 22:45:41 +02:00
Frank Denis
9b386bda33 std/crypto: add a vectorized ChaCha20 implementation
Brings a 30% speed boost on x86_64 even though we still process only
one block at a time for now.

Only enabled on x86_64 since the non-vectorized implementation seems
to currently perform better on some architectures (at least on aarch64).

But the non-vectorized implementation still gets a little speed boost
as well (~17%) with these changes.
2020-10-10 22:45:41 +02:00
LemonBoy
a31b70c4b8 std: Add/Fix/Change parts of big.int
* Add an optimized squaring routine under the `sqr` name.
  Algorithms for squaring bigger numbers efficiently will come in a
  PR later.
* Fix a bug where a multiplication was done twice if the threshold for
  the use of Karatsuba algorithm was crossed. Add a test to make sure
  this won't happen again.
* Streamline `pow` method, take a `Const` parameter.
* Minor tweaks to `pow`, avoid bit-reversing the exponent.
2020-10-09 22:16:48 -04:00
Andrew Kelley
9f8f446435 fixups to previous commit
* std.fs.Dir.readFile: add doc comments to explain what it means when
   the returned slice has the same length as the supplied buffer.
 * introduce readSmallFile / writeSmallFile to abstract over the
   decision to use symlink or file contents to store data.
2020-10-09 16:45:39 -07:00
mlarouche
57912964af Use regular file for caching stage 1 hash digest instead of symlink, fix zig build caching on Windows
Fix #6500
2020-10-09 16:50:43 -04:00
Andrew Kelley
a4828f6d0f std.c (darwin) update to new opaque syntax
This was an undetected conflict between

76a195473dac059a842fed2a6ba581ca99947d2b and
95a37373e9f576854956c2909cc128b5b6388ec6
2020-10-08 22:45:39 -07:00
Andrew Kelley
76a195473d
Merge pull request #6516 from LemonBoy/fastfilecopy
std: Make file copy ops use zero-copy mechanisms
2020-10-08 20:14:47 -04:00
Andrew Kelley
8b7539bd95 Merge remote-tracking branch 'origin/master' into llvm11
Conflicts:
  src/clang.zig

Master branch renamed an enum; this branch gave it an explicit tag type
and explicitly initialized values. This commit combines the changes
together.
2020-10-08 15:47:45 -07:00
Andrew Kelley
b02341d6f5
Merge pull request #6614 from jedisct1/aes-arm
std/crypto/aes: add AES hardware acceleration on aarch64
2020-10-08 18:09:40 -04:00
Frank Denis
1bc2b68916 ghash: add pmull support on aarch64 2020-10-08 18:09:23 -04:00
Benjamin Feng
9de0f15b8e Rename ix_rss -> ixrss 2020-10-08 15:31:36 -05:00
Benjamin Feng
fd3f676cdb Pull in Darwin definitions for rusage 2020-10-08 15:19:52 -05:00
Frank Denis
60d1e675d2 aes/aesni is not based on a Go implementation, only aes/soft is
Don't blame them for our bugs :)
2020-10-08 14:55:11 +02:00
Frank Denis
f39dc00ed4 std/crypto/aes: add AES hardware acceleration on aarch64 2020-10-08 14:55:08 +02:00
xavier
a0a834a2f2 restore ability to do comptime math
until https://github.com/ziglang/zig/issues/6168 is implemented,
partially revert 0bd53dd2033c60d3446abfb83209237c6eb6c9e2
in order to restore the ability to use std.math in comptime functions.
2020-10-07 17:04:48 -04:00
Andrew Kelley
95a37373e9
Merge pull request #6421 from tadeokondrak/opaque-syntax
Add opaque syntax that allows declarations
2020-10-07 16:58:50 -04:00
Andrew Kelley
3c43eeceab
Merge pull request #6595 from tadeokondrak/comptime-print-0
std.fmt.comptimePrint: Return null terminated string
2020-10-07 16:55:03 -04:00
Tadeo Kondrak
e9bca9de3c
std.fmt.comptimePrint: Properly null-terminate result and add test 2020-10-07 11:43:23 -06:00
LemonBoy
03762da2af New review round 2020-10-07 11:13:26 +02:00
Loris Cro
53dee08af9 add WaitGroup to std.event
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-07 04:34:09 -04:00
Tadeo Kondrak
0a6863a267 Remove .Cold calling convention.
This isn't a stable, defined calling convention, so it shouldn't be
grouped in with the others.

Closes https://github.com/ziglang/zig/issues/6556
2020-10-07 04:31:20 -04:00
Andrew Kelley
b5a36f676b Merge remote-tracking branch 'origin/master' into llvm11
Conflicts:
  cmake/Findllvm.cmake

The llvm11 branch changed 10's to 11's and master branch added the
"using LLVM_CONFIG_EXE" help message, so the resolution was to merge
these changes together.

I also added a check to make sure LLVM is built with AVR enabled, which
is no longer an experimental target.
2020-10-07 00:46:05 -07:00
Andrew Kelley
b2b0bf0506 fixups for the previous commit
* std.fs.File.copyRange and copyRangeAll return u64 instead of usize -
   the returned value is how much of the `len` is transferred, so the
   types should match. This removes the need for an `@intCast`.
 * fix typo that removed a subtraction
 * Fix the size of codegen.AnyMCValue which gave me a compile error when
   I tried to build self-hosted for i386-linux.
 * restore the coercion to u64 of syms_sect.sh_info. We want to make
   sure the multiplication happens with 64 bits and not the smaller type
   used by the ELF format.
 * fix another offset parameter in link/Elf.zig to be u64 instead of usize
 * add a nice little TODO note to help out Jakub
 * FmtError already has FileTooBig in it; we just need to return it.
2020-10-07 00:39:13 -07:00
Timon Kruiper
bd7eab573a Fix building the zig compiler for 32-bit targets 2020-10-06 23:39:58 -07:00