Commit graph

7090 commits

Author SHA1 Message Date
Frank Denis
ab37ab33ce
poly1305: properly cast the mask from u1 to u64 (#15869)
Fixes #15855
2023-05-27 08:50:57 +00:00
Veikka Tuominen
ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
Veikka Tuominen
8f5f8090c5
Merge pull request #15803 from linusg/std-snek-case-enums
std: Snake-case some public facing enums
2023-05-27 02:40:38 +03:00
David CARLIER
41502c6aa5
std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791) 2023-05-25 14:32:17 -05:00
Linus Groh
ba35eeb417 std.fs.file: Rename File.Lock enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
e96de1b636 std.event.loop: Rename Loop.Request.Finish enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
1f57043a21 std.event.loop: Rename Loop.ResumeNode.Id enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
9123377cdb std.fmt: Rename parseWithSign() sign parameter enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
7860cd734c std.fmt: Rename Alignment enum values to snake case 2023-05-25 20:17:07 +01:00
Mason Remaley
5744ceedb8
Fixes WriteFile.getFileSource failure on Windows (#15730) 2023-05-24 14:26:07 -07:00
Linus Groh
93d9c9bf31 std.io.tty: Remove unused Config.writeDEC() function
For reference:
https://github.com/ziglang/zig/pull/15806#discussion_r1203377118
2023-05-24 10:15:47 +01:00
Linus Groh
5d3f3cae64 std.io.tty: Add missing colors to Color enum
Also make colors not bold by default, that's what .bold is for.
2023-05-24 10:15:02 +01:00
Linus Groh
0f6fa3f20b std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.tty
Also get rid of the TTY wrapper struct, which was exlusively used as a
namespace - this is done by the tty.zig root struct now.

detectTTYConfig has been renamed to just detectConfig, which is enough
given the new namespace. Additionally, a doc comment had been added.
2023-05-24 10:15:02 +01:00
Linus Groh
39c2eee285 std.debug: Rename TTY.Color enum values to snake case 2023-05-24 10:15:02 +01:00
Frank Denis
16dbb960fc
std.crypto: 2.5 times faster ghash and polyval on WebAssembly (#15835)
* std.crypto: faster ghash and polyval on WebAssembly

Before:  91 MiB/s
After : 243 MiB/s

Some other platforms might benefit from this, but WebAssembly is
the obvious one (simd128 doesn't make a difference).
2023-05-24 08:38:28 +02:00
Ali Chraghi
3db3cf7790 std.sort: add pdqsort and heapsort 2023-05-23 17:55:59 -07:00
tison
bfe02ff61a
make @boolToInt always return a u1
Signed-off-by: tison <wander4096@gmail.com>
2023-05-24 00:01:48 +00:00
Frank Denis
0000b34a2d
crypto.aes: define optimal_parallel_blocks for more CPUs (#15829) 2023-05-23 19:47:11 +00:00
Frank Denis
057d30bacc
std.crypto.chacha: remove the hack for ChaCha with a 64-bit counter (#15818)
Support for 64-bit counters was a hack built upon the version with
a 32-bit counter, that emulated a larger counter by splitting the
input into large blocks.

This is fragile, particularily if the initial counter is set to
a non-default value and if we have parallelism.

Simply add a comptime parameter to check if we have a 32 bit or a
64 bit counter instead.

Also convert a couple while() loops to for(), and change @panic()
to @compileError().
2023-05-23 14:36:44 +00:00
Bas Westerbaan
7cb3a67507
crypto/tls: switch X25519Kyber768Draft00 to new codepoint (#15821)
The tls wg preferred a codepoint outside of the reserved range. This new
codepoint has been assigned by IANA.

See

 - https://datatracker.ietf.org/doc/draft-tls-westerbaan-xyber768d00-02/
 - https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#table-tls-parameters-8
2023-05-23 11:07:07 +00:00
Veikka Tuominen
4ce1ae71a5
Merge pull request #15235 from Vexu/safety
add runtime safety for noreturn function returning
2023-05-23 13:34:52 +03:00
Frank Denis
9d179a98f6
Make Poly1305 faster by leveraging @addWithOverflow/@subWithOverflow (#15815)
These operations are constant-time on most, if not all currently
supported architectures. However, even if they are not, this is not
a big deal in the case on Poly1305, as the key is added at the end.

The final addition remains protected.

SalsaPoly and ChaChaPoly do encrypt-then-mac, so side channels would
not leak anything about the plaintext anyway.

* Apple Silicon (M1)

Before: 2048 MiB/s
After : 2823 MiB/s

* AMD Ryzen 7

Before: 3165 MiB/s
After : 4774 MiB/s
2023-05-23 09:55:45 +02:00
Frank Denis
5af89b3dcc
std.crypto.chacha: support larger vectors on AVX2 and AVX512 targets (#15809)
* std.crypto.chacha: support larger vectors on AVX2 and AVX512 targets

Ryzen 7 7700, ChaCha20/8 stream, long outputs:

Generic: 3268 MiB/s
AVX2   : 6023 MiB/s
AVX512 : 8086 MiB/s

Bump the rand.chacha buffer a tiny bit to take advantage of this.
More than 8 blocks doesn't seem to make any measurable difference.

ChaChaPoly also gets a small performance boost from this, albeit
Poly1305 remains the bottleneck.

Generic:  707 MiB/s
AVX2   :  981 MiB/s
AVX512 : 1202 MiB/s

aarch64 appears to generally benefit from 4-way vectorization.

Verified on Apple Silicon, but also on a Cortex A72.
2023-05-22 20:33:35 +02:00
DraagrenKirneh
957f269a42
Ignore certificates with unknown OID (#15539)
* Ignore certificates with unknown OID

* switch directly after catch
2023-05-22 16:13:34 +02:00
Frank Denis
89f622fc68
std.crypto.ff - Alloc-free, constant-time field arithmetic for crypto (#15795)
A minimal set of simple, safe functions for Montgomery arithmetic,
designed for cryptographic primitives.

Also update the current RSA cert validation to use it, getting rid
of the FixedBuffer hack and the previous limitations.

Make the check of the RSA public key a little bit more strict by
the way.
2023-05-22 16:11:06 +02:00
yujiri8
a1bb9e94d4
fix type errors in os.linux (#15801)
* fix NUMA-related functions in os.linux

* fix os.linux.CPU_ISSET
2023-05-22 13:34:39 +03:00
David CARLIER
768965788e std.c: fix freebsd's CPU_ISSET call 2023-05-22 13:13:57 +03:00
David CARLIER
f8991ba3d4 std.os: gethostname non libc linking using uname like linux 2023-05-22 12:45:18 +03:00
Michael Dusan
19c96c09f3 std.c: openbsd sigcontext/ucontext fix enum 2023-05-22 11:31:57 +03:00
Chris Heyes
df909da5d8
std.crypto: expose Fe isOdd & add basic parity tests for each pcurve (#15734)
* std Secp256k1 Scalar: expose Fe isOdd & add basic parity test

* std.crypto: also add Scalar.isOdd convenience fn for p256 and p384 curves
2023-05-21 13:00:48 +02:00
Andrew Kelley
b7cb88384c
Merge pull request #15407 from mlugg/feat/pkg-dedup
Deduplicate uses of the same package across dependencies

closes #15755
2023-05-20 22:58:20 -07:00
mlugg
38b83d9d93 Zir: eliminate field_call_bind and field_call_bind_named
This commit removes the `field_call_bind` and `field_call_bind_named` ZIR
instructions, replacing them with a `field_call` instruction which does the bind
and call in one.

`field_call_bind` is an unfortunate instruction. It's tied into one very
specific usage pattern - its result can only be used as a callee. This means
that it creates a value of a "pseudo-type" of sorts, `bound_fn` - this type used
to exist in Zig, but now we just hide it from the user and have AstGen ensure
it's only used in one way. This is quite silly - `Type` and `Value` should, as
much as possible, reflect real Zig types and values.

It makes sense to instead encode the `a.b()` syntax as its own ZIR instruction,
so that's what we do here. This commit introduces a new instruction,
`field_call`. It's like `call`, but rather than a callee ref, it contains a ref
to the object pointer (`&a` in `a.b()`) and the string field name (`b`). This
eliminates `bound_fn` from the language, and slightly decreases the size of
generated ZIR - stats below.

This commit does remove a few usages which used to be allowed:
- `@field(a, "b")()`
- `@call(.auto, a.b, .{})`
- `@call(.auto, @field(a, "b"), .{})`

These forms used to work just like `a.b()`, but are no longer allowed. I believe
this is the correct choice for a few reasons:
- `a.b()` is a purely *syntactic* form; for instance, `(a.b)()` is not valid.
  This means it is *not* inconsistent to not allow it in these cases; the
  special case here isn't "a field access as a callee", but rather this exact
  syntactic form.
- The second argument to `@call` looks much more visually distinct from the
  callee in standard call syntax. To me, this makes it seem strange for that
  argument to not work like a normal expression in this context.
- A more practical argument: it's confusing! `@field` and `@call` are used in
  very different contexts to standard function calls: the former normally hints
  at some comptime machinery, and the latter that you want more precise control
  over parts of a function call. In these contexts, you don't want implicit
  arguments adding extra confusion: you want to be very explicit about what
  you're doing.

Lastly, some stats. I mentioned before that this change slightly reduces the
size of ZIR - this is due to two instructions (`field_call_bind` then `call`)
being replaced with one (`field_call`). Here are some numbers:

+--------------+----------+----------+--------+
| File         | Before   | After    | Change |
+--------------+----------+----------+--------+
| Sema.zig     | 4.72M    | 4.53M    | -4%    |
| AstGen.zig   | 1.52M    | 1.48M    | -3%    |
| hash_map.zig | 283.9K   | 276.2K   | -3%    |
| math.zig     | 312.6K   | 305.3K   | -2%    |
+--------------+----------+----------+--------+
2023-05-20 12:27:48 -07:00
Meghan
7077e90b3f std.meta: allow ArgsTuple to be used on functions with comptime parameters
any comptime parameter sets `.is_generic` to be true but in many cases these will still be discrete types available in `.params`
2023-05-20 11:21:06 +03:00
David CARLIER
ccfb0d408d std.c: adding ptrace for netbsd. 2023-05-20 11:06:11 +03:00
Motiejus Jakštys
b61d0debd6 multi-writer: test with a non-comptime stream
Since #14819 this test failed with:

    $ ../../../build/stage3/bin/zig test multi_writer.zig
    multi_writer.zig:26:57: error: unable to evaluate comptime expression
                var batch = std.event.Batch(Error!void, self.streams.len, .auto_async).init();
                                                        ~~~~^~~~~~~~
    referenced by:
        Writer: multi_writer.zig:19:52
        writer: multi_writer.zig:21:36
        remaining reference traces hidden; use '-freference-trace' to see all reference traces

Thanks @jacobly for hints how to fix this on IRC.
2023-05-19 09:13:49 -07:00
David CARLIER
b9d2e0e308 std.os: add linux timer api 2023-05-19 03:41:10 +03:00
Andrew Kelley
7cf2cbb33e std.crypto.tls.Client.readvAdvanced: fix bugs
* When there is buffered cleartext, return it without calling the
   underlying read function. This prevents buffer overflow due to space
   used up by cleartext.
 * Avoid clearing the buffer when the buffered cleartext could not be
   completely given to the result read buffer, and there is some
   buffered ciphertext left.
 * Instead of rounding up the amount of bytes to ask for to the nearest
   TLS record size, round down, with a minimum of 1. This prevents the
   code path from being taken which requires extra memory copies.
 * Avoid calling `@memcpy` with overlapping arguments.

closes #15590
2023-05-18 03:26:16 -07:00
mlugg
f65e8c7862 Deduplicate uses of the same package across dependencies 2023-05-18 00:27:21 -07:00
IntegratedQuantum
6e05620117 Document the sorting order in std.sort. 2023-05-17 18:26:49 -07:00
Andrew Kelley
c1add1e19e
Merge pull request #15459 from motiejus/build-id-full
stage2: implement `--build-id` styles
2023-05-17 07:19:15 -07:00
Andrew Kelley
728ce2d7c1 tweaks to --build-id
* build.zig: the result of b.option() can be assigned directly in many
   cases thanks to the return type being an optional
 * std.Build: make the build system aware of the
   std.Build.Step.Compile.BuildId type when used as an option.
   - remove extraneous newlines in error logs
 * simplify caching logic
 * simplify hexstring parsing tests and use a doc test
 * simplify hashing logic. don't use an optional when the `none` tag
   already provides this meaning.
 * CLI: fix incorrect linker arg parsing
2023-05-16 20:39:01 -07:00
Motiejus Jakštys
df5085bde0 stage2: implement --build-id styles 2023-05-16 20:38:39 -07:00
David CARLIER
40e8c2243c std.c: darwin's *copyfile api update. 2023-05-17 06:06:41 +03:00
Frank Denis
c6966486e3
crypto.AegisMac: fix a regression from s/mem.copy/@memcpy/ (#15733)
In an update whose size is not a multiple of the block size,
we would end up calling @memcpy() with arguments of different sizes.
2023-05-16 23:51:47 +00:00
Cortex
c269e16c3b
std.mem.byteSwapAllFields: add suppport for nested structs (#15696) 2023-05-16 19:10:44 -04:00
David CARLIER
b754068fbc std.c: add ptrace for freebsd support. 2023-05-16 22:47:51 +03:00
Veikka Tuominen
ebbc521a87 workaround AstGen's love for copying arrays 2023-05-16 11:37:25 +03:00
Veikka Tuominen
b91d6ff9e8 add runtime safety for noreturn function returning
Closes #15221
2023-05-16 11:33:38 +03:00
Tw
e584dd8062 std.mem.zeroInit: zero hidden padding for extern struct
Signed-off-by: Tw <tw19881113@gmail.com>
2023-05-16 10:33:04 +03:00