Commit Graph

5581 Commits

Author SHA1 Message Date
Andrew Kelley
25671f5a97 compiler-rt: move SPARC functions into appropriate compilation units 2022-06-17 16:38:59 -07:00
Andrew Kelley
c99c085d70 compiler-rt: break up functions even more
The purpose of this branch is to switch to using an object file for each
independent function, in order to make linking simpler - instead of
relying on `-ffunction-sections` and `--gc-sections`, which involves the
linker doing the work of linking everything and then undoing work via
garbage collection, this will allow the linker to only include the
compilation units that are depended on in the first place.

This commit makes progress towards that goal.
2022-06-17 16:38:59 -07:00
Jakub Konka
f572e5a0c4 compiler_rt: shuffle order of imports to mark relevant symbols for export 2022-06-17 16:38:59 -07:00
Jakub Konka
57c530155f compiler_rt: correctly export allrem and aullrem for i386-windows-msvc 2022-06-17 16:38:59 -07:00
Jakub Konka
2259d629d3 compiler_rt: use single cache for libcompiler_rt.a static lib 2022-06-17 16:38:59 -07:00
Jakub Konka
80790be309 compiler_rt: compile each unit separately for improved archiving 2022-06-17 16:38:59 -07:00
Veikka Tuominen
28986a0590 stage2: check that struct is a tuple when value tags differ in eql 2022-06-17 21:04:21 +03:00
Veikka Tuominen
a224dfceee std.tz: fix function returning pointer to local variable 2022-06-17 21:04:21 +03:00
Jakub Konka
d3caacfab7
Merge pull request #11864 from jedisct1/wasi-libc-update
Update the WASI libc to 30094b6ed05f19cee102115215863d185f2db4f0
2022-06-15 12:33:17 +02:00
Frank Denis
27610b0a0f
std/crypto: add support for ECDSA signatures (#11855)
ECDSA is the most commonly used signature scheme today, mainly for
historical and conformance reasons. It is a necessary evil for
many standard protocols such as TLS and JWT.

It is tricky to implement securely and has been the root cause of
multiple security disasters, from the Playstation 3 hack to multiple
critical issues in OpenSSL and Java.

This implementation combines lessons learned from the past with
recent recommendations.

In Zig, the NIST curves that ECDSA is almost always instantied with
use formally verified field arithmetic, giving us peace of mind
even on edge cases. And the API rejects neutral elements where it
matters, and unconditionally checks for non-canonical encoding for
scalars and group elements. This automatically eliminates common
vulnerabilities such as https://sk.tl/2LpS695v .

ECDSA's security heavily relies on the security of the random number
generator, which is a concern in some environments.

This implementation mitigates this by computing deterministic
nonces using the conservative scheme from Pornin et al. with the
optional addition of randomness as proposed in Ericsson's
"Deterministic ECDSA and EdDSA Signatures with Additional Randomness"
document. This approach mitigates both the implications of a weak RNG
and the practical implications of fault attacks.

Project Wycheproof is a Google project to test crypto libraries against
known attacks by triggering edge cases. It discovered vulnerabilities
in virtually all major ECDSA implementations.

The entire set of ECDSA-P256-SHA256 test vectors from Project Wycheproof
is included here. Zero defects were found in this implementation.

The public API differs from the Ed25519 one. Instead of raw byte strings
for keys and signatures, we introduce Signature, PublicKey and SecretKey
structures.

The reason is that a raw byte representation would not be optimal.
There are multiple standard representations for keys and signatures,
and decoding/encoding them may not be cheap (field elements have to be
converted from/to the montgomery domain).

So, the intent is to eventually move ed25519 to the same API, which
is not going to introduce any performance regression, but will bring
us a consistent API, that we can also reuse for RSA.
2022-06-15 08:55:39 +02:00
Frank Denis
8c63037695 Update the WASI libc
Update our copy of wasi-libc up to the commit
30094b6ed05f19cee102115215863d185f2db4f0 from the upstream repository.
2022-06-14 23:20:39 +02:00
Mikael Berthe
47c4d44502
std.math.big.int: update Managed.toString() to use provided allocator (#11839) 2022-06-13 17:19:37 +02:00
Frank Denis
7c660d17cd
crypto/pcurves: compute constants for inversion at comptime (#11780) 2022-06-13 08:13:52 +02:00
Andrew Kelley
ffa700ee58
Merge pull request #11837 from Vexu/stage2
Fix (nearly) all stage2 crashes when testing stdlib
2022-06-12 17:45:57 -04:00
Veikka Tuominen
0a9d6956e7 Sema: add missing set_union_tag 2022-06-12 19:17:41 +03:00
Andrew Kelley
c29746aa55 add std.debug.Trace.format
This makes it show up in some useful places; for example in the
self-hosted compiler we already print it now with
--debug-compile-errors.
2022-06-12 00:57:59 -07:00
Andrew Kelley
85492f2b91 std.mem.zeroes: remove call to std.meta
everybody is so horny for std.meta
2022-06-12 00:56:59 -07:00
Veikka Tuominen
6b36774adc std: disable failing tests, add zig2 build test-std to CI 2022-06-12 10:43:28 +03:00
Veikka Tuominen
35c7e376b8 stage2: improve anon name strategy for local variables 2022-06-11 23:49:33 +03:00
Veikka Tuominen
0333ff4476 stage2: make error{} the same size as anyerror
Having `error{}` be a zero bit type causes issues when it interracts
with empty inferred error sets which are the same size as `anyerror`.
2022-06-11 23:49:33 +03:00
Veikka Tuominen
488e1e5f51 stage2: small fixes + adjustments to std tests 2022-06-11 23:49:33 +03:00
Veikka Tuominen
002df65b6e Sema: handle tuple and anon_struct in resolveTypeFully 2022-06-11 11:02:56 +03:00
Andrew Kelley
af909f6c93 std.debug.Trace: improve API
Now `std.debug.Trace` is a concrete type with pre-chosen defaults.
`std.debug.ConfigurableTrace` can be used for more advanced cases.
2022-06-09 15:37:16 -07:00
Andrew Kelley
bac132bc8f introduce std.debug.Trace
And use it to debug a LazySrcLoc in stage2 that is set to a bogus value.

The actual fix in this commit is:

```diff
-        try sema.emitBackwardBranch(&child_block, call_src);
+        try sema.emitBackwardBranch(block, call_src);
```
2022-06-09 15:37:16 -07:00
Isaac Freund
29dd9a5880 parser: sync comments with formal grammar 2022-06-08 21:53:06 +02:00
Isaac Freund
d8cae4d197
std.build: Expose -z norelro and -z lazy 2022-06-08 15:13:04 +02:00
Cody Tapscott
70dc910086 std.math: Add O(log N) implementation of log2(x) for comptime_int
Since Zig provides @clz and not @ffs (find-first-set), log2 for comptime
integers needs to be computed algorithmically. To avoid hitting the
backward branch quota, this updates log2(x) to use a simple O(log N)
algorithm.
2022-06-07 20:07:40 -04:00
Andrew Kelley
6ff7b437ff
Merge pull request #11813 from Vexu/stage2
`zig2 build test-std` finale
2022-06-07 20:07:28 -04:00
Jonathan Marler
523fae420b add const to msghdr_const iov and control pointers
alongside the typical msghdr struct, Zig has added a msghdr_const
type that can be used with sendmsg which allows const data to
be provided.  I believe that data pointed to by the iov and control
fields in msghdr are also left unmodified, in which case they can
be marked const as well.
2022-06-07 15:23:44 -04:00
Veikka Tuominen
413577c881 std: adjust for stage2 semantics 2022-06-07 21:27:07 +03:00
Andrew Kelley
073762395e std.os.abort patch cleanups
* move global into function scope
 * clarify comments
 * avoid unnecessary usage of std.atomic API
 * switch on error instead of `catch unreachable`
 * call linux.gettid() instead of going through higher level API and
   doing unnecessary casting
2022-06-06 15:34:20 -07:00
Jan Philipp Hafer
d1e8b73939 std.os.abort: ported signal handling from musl
* Document deviation from Linux man page, which is identical to musl.
  Man page wants always enabled user-provided abort handlers.
  Worst case logic bug, which this can introduce:
    + user disables SIGABRT handler to prevent tear down to last safe
      state
    + abort() gets called and enables user-provided SIGABRT handler
    + SIGABRT tears down to supposed last safe state instead of crash
    + Application, instead of crashing, continues
* Pid 1 within containers needs special handling.
  - fatal signals are not transmitted without privileges,
    so use exit as fallback
* Fix some signaling bits
* Add checks in Debug and ReleaseSafe for wrong sigprocmask
2022-06-06 15:32:39 -07:00
Veikka Tuominen
32568dba74 std: handle stage2 function pointer semantics in test 2022-06-06 13:11:50 -07:00
Veikka Tuominen
61c5d8f8f1 std.fs: fix incorrect passing of pointer to temporary 2022-06-06 13:11:50 -07:00
Veikka Tuominen
bb84c87a47 std: add necessary @alignCasts 2022-06-06 13:11:50 -07:00
Veikka Tuominen
15ec55406d std: fix ambiguous references 2022-06-06 13:11:50 -07:00
Veikka Tuominen
6d44c0a16c std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
Veikka Tuominen
1a7b4ddeae std: disable tests that crash stage2 2022-06-03 20:21:20 +03:00
Veikka Tuominen
9aae4d57cb compiler_rt: fix infinite loop 2022-06-03 14:27:45 +03:00
Andrew Kelley
a4cdb49a58
Merge pull request #11763 from Vexu/stage2-alloc-const
Stage2: detect when initializer of const variable is comptime known
2022-06-01 18:59:13 -04:00
Veikka Tuominen
9431100736 Sema: apply previous changes to validateUnionInit 2022-06-01 13:01:39 +03:00
Andrew Kelley
59219e7e91 stage2: add support for -fbuild-id,-fno-build-id
closes #3047
2022-05-31 13:36:33 -07:00
Frank Denis
26aea8cfa1
crypto: add support for the NIST P-384 curve (#11735)
After P-256, here comes P-384, also known as secp384r1.

Like P-256, it is required for TLS, and is the current NIST recommendation for key exchange and signatures, for better or for worse.

Like P-256, all the finite field arithmetic has been computed and verified to be correct by fiat-crypto.
2022-05-31 17:29:38 +02:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Andrew Kelley
f2e8c79763 std.Progress.log: adjust API
Now it will fall back to std.debug.print if there is no tty.
2022-05-26 21:58:19 -07:00
Andreas Reischuck
5a8b6149fb
add more corner case tests to float_parse (#11727)
also drop some unused constants

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2022-05-26 22:05:53 -04:00
Yuto Oguchi
43373e61fa
std.c: Fix incorrect dirent structure (#11602)
d_name is a null-terminated string, but it is not guaranteed that the
last byte of the array is null.
2022-05-26 20:15:51 -04:00
Andrew Kelley
e0a0df5a8a
Merge pull request #11598 from aiotter/master
Add functions from `dirent.h` to std.c
2022-05-26 20:11:54 -04:00
Jonathan Marler
ee1a95b555 fix semantic error with std.os.linux.all_mask
all_mask is a value of type sigset_t, which is defined as an array type
[N]u32.  However, all_mask references sigset_t.len, but, the array type
does not have a len field.  Fix is to use @typeInfo(sigset_t).Array.len
instead.
2022-05-26 19:50:10 -04:00
Hanna
4e918873e7
Rename std.build.Pkg.path to std.build.Pkg.source (#11557) 2022-05-26 19:32:28 -04:00