Commit graph

558 commits

Author SHA1 Message Date
Jacob Young
fe93332ba2 x86_64: implement enough to pass unicode tests
* implement vector comparison
 * implement reduce for bool vectors
 * fix `@memcpy` bug
 * enable passing std tests
2023-10-23 22:42:18 -04:00
Andrew Kelley
b82459fa43
Merge pull request #17407 from truemedian/http-ng
std.http: more proxy support, buffer writes, tls toggle
2023-10-22 17:48:03 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadb.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab, reversing
changes made to 5f92b070bf.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Nameless
e1c37f70d4
std.http.Client: store *Connection instead of a pool node, buffer writes 2023-10-21 20:52:58 -05:00
Jacob Young
32e85d44eb x86_64: disable failing tests, enable test-std testing 2023-10-21 10:55:41 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
Jacob Young
c880644d92 x86_64: disable difficult std tests and hack around more zero-bit types 2023-10-21 10:55:41 -04:00
Frank Denis
a5c79c7998
crypto.ff: faster exponentiation with short/public exponents (#17617)
RSA exponents are typically 3 or 65537, and public.

For those, we don't need to use conditional moves on the exponent,
and precomputing a lookup table is not worth it. So, save a few
cpu cycles and some memory for that common case.

For safety, make `powWithEncodedExponent()` constant-time by default,
and introduce a `powWithEncodedPublicExponent()` function for exponents
that are assumed to be public.

With `powWithEncodedPublicExponent()`, short (<= 36 bits) exponents
will take the fast path.
2023-10-21 02:09:43 -07:00
Andrew Kelley
8804d72684 std certs: solaris can use the BSD path 2023-10-18 12:51:45 -04:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Ryan Zezeski
68bcd7ddd4 solaris: load CA certs file 2023-09-30 11:38:56 -06:00
e4m2
9135115573
std.crypto.aead: Consistent decryption tail and doc fixes (#16781)
* Consistent decryption tail for all AEADs

* Remove outdated note

This was previously copied here from another function. There used
to be another comment on the tag verification linking to issue #1776,
but that one was not copied over. As it stands, this note seems fairly
misleading/irrelevant.

* Prettier docs

* Add note about plaintext contents to docs

* Capitalization

* Fixup missing XChaChaPoly docs
2023-08-14 21:39:51 +02:00
Andrew Kelley
f8666d748d
Merge pull request #16516 from lacc97/std-crypto-certificate-parse-datetime
std.crypto.Certificate: fix timedate parsing
2023-07-24 10:56:38 -07:00
Zachary Raineri
d82b359010 Use builtin inference over @as where possible 2023-07-24 10:23:51 -07:00
Luis Cáceres
df5f6836c4 std.crypto.Certificate: consistent param types for parseTimeDigits
This commit changes the type of the first parameter of parseTimeDigits
to *const [2]u8 for consistency with parseYear4 which uses *const [4]u8
as its first parameter. This is also more ergonomic for the caller since
they don't need to dereference the array.
2023-07-23 21:02:59 +00:00
Luis Cáceres
05bad1f42d std.crypto.Certificate: fix timedate parsing
This commit fixes parsing in parseYear4 and parseTimeDigits by using a
wider vector data type such that the intermediate result cannot overflow
and the error check remains correct.
2023-07-23 20:48:45 +00:00
Frank Denis
32aeb2c2ec
Be more conservative in the description of Aegis256Mac (#16452)
It is assumed that generating a collision requires more than 2^156
ciphertext modifications. This is plenty enough for any practical
purposes, but it hasn't been proven to be >= 2^256.

Be consistent and conservative here; just claim the same security
as the other variants.
2023-07-19 23:59:24 +00:00
Frank Denis
a0b35249a2
Replace hand-written endian-specific loads with std.mem.readInt*() (#16431)
And when we have the choice, favor little-endian because it's 2023.

Gives a slight performance improvement:

   md5: 552 -> 555 MiB/s
  sha1: 768 -> 786 MiB/s
sha512: 211 -> 217 MiB/s
2023-07-18 00:40:31 +02:00
Luiz Berti
a86f589a9f
Small documentation fixes on std.crypto (#16427)
* Small documentation fix of ChaCha variants

Previous documentation was seemingly copy-pasted and left
behind some errors where the number of rounds was not
properly updated.

* Suggest `std.crypto.utils.secureZero` on `@memset` docs

* Revert previous change
2023-07-17 21:16:41 +00:00
George Zhao
9abe392647
std.crypto: add finalResult and peek api for Sha1 (#16426)
close #16250
2023-07-17 10:02:57 +00:00
e4m2
3022c525ec
std.crypto.sha3: Minor TurboSHAKE/Keccak fixes (#16408) 2023-07-14 14:02:01 +00:00
dec05eba
2e424e019f Client.zig: support rsa_pss_rsae_sha384 and rsa_pss_rsae_sha512
This fixes HTTP GET to https://www.iana.org/domains/reserved
for example
2023-07-06 18:36:15 -07:00
Michael Dusan
fc9ab5f0e8 tls certificates: support more BSDs
- add support for freebsd, netbsd, dragonfly
- refactor rescanOpenBSD -> rescanBSD
- make os-specific rescan*() non-public

closes #16279
2023-07-02 19:24:37 -07:00
Michael Dusan
614bc6755e openbsd: add root certificate scanning
patch by @bilaliscarioth, thank you!

closes #16168
2023-06-29 10:29:28 -07:00
Lauri Tirkkonen
82520a214c std.crypto.hash.sha2: require avx2 on x86_64
according to
https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=vpalignr&ig_expand=283,283,284,283,283&techs=AVX_ALL
the vpalignr instruction requires AVX2 support
2023-06-28 17:33:02 -07:00
Jacob Young
8239d3b358 crypto: recoup storage in tls.Client.partially_read_buffer 2023-06-26 21:05:08 -04:00
Jacob Young
eb8881a538 crypto: cleanup unneeded uses of @as in tls.Client 2023-06-26 21:05:08 -04:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
r00ster91
6e84f46990 std: replace builtin.Version with SemanticVersion 2023-06-17 13:17:34 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Andrew Kelley
38fc826a5a
Merge pull request #15957 from BratishkaErik/deprecated-
std.*: remove stuff that was deprecated in older versions
2023-06-13 14:53:41 -07:00
Frank Denis
cc708b4a88
crypto.pcurves: don't assume that points with X=0 are at infinity (#16017)
There's also a valid point with X=0 on each curves.

Fixes #16015
2023-06-13 18:20:24 +00:00
Eric Joldasov
4d5fb62a82
std.crypto.sign.Ed25519: remove sign, verify, key_blinding.sign, and
`key_blinding.unblindPublicKey` (deprecated in 0.10)

Followup to 9c0d975a09.
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:46:58 +06:00
mlugg
9e61ba19e9 std.crypto.tls.Client: fix @memcpy crash in limitedOverlapCopy
Resolves: #15928
2023-06-12 14:22:09 -07:00
Frank Denis
9ee0a706da
crypto.bcrypt: allow very large passwords to be pre-hashed (#15955)
crypto.bcrypt: allow very large passwords to be pre-hashed

bcrypt has a slightly annoying limitation: passwords are limited
to 72 characters. In the original implementation, additional characters
are silently ignored.

When they care, applications adopt different strategies to work around
this, in incompatible ways.

Ideally, large passwords should be pre-hashed using a hash function that
hinders GPU attackers, and the hashed function should not be deterministic
in order to defeat shucking attacks.

This change improves the developer experience by adding a very explicit
`silently_truncate_password` option, that can be set to `false` in
order to do that automatically, and consistently across Zig applications.

By default, passwords are still truncated, so this is not a breaking
change.

Add some inline documentation for our beloved autodoc by the way.
2023-06-06 09:08:57 +02:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
Andrew Kelley
77b40d6ecb
Merge pull request #15927 from truemedian/http-bugs
std.http: fix infinite read loop, deduplicate connection code, add TlsAlert errors
2023-06-03 13:36:07 -07:00
Frank Denis
879f0b9cee
Fix std.hash benchmarks (#15917) 2023-06-02 20:08:28 +02:00
Nameless
0e5e6cb10c
std.http: add TlsAlert descriptions so that they can at least be viewed in err return traces 2023-06-01 13:43:55 -05:00
Frank Denis
1ab008d89d
RSA: remove usage of allocators (#15901)
Individual max buffer sizes are well known, now that arithmetic doesn't
require allocations any more.

Also bump `main_cert_pub_key_buf`, so that e.g. `nodejs.org` public
keys can fit.
2023-05-30 10:06:44 +00:00
Frank Denis
ab37ab33ce
poly1305: properly cast the mask from u1 to u64 (#15869)
Fixes #15855
2023-05-27 08:50:57 +00:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +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
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