24 Commits

Author SHA1 Message Date
Frank Denis
4417206230 Now that they support vectors, use math.rot{l,r} 2020-11-05 17:19:48 -05:00
Frank Denis
ea45897fcc PascalCase *box names, remove unneeded comptime & parenthesis
Also rename (salsa20|chacha20)Internal() to a better name.

And sort reexported crypto.* names
2020-10-28 21:43:15 +02:00
Frank Denis
fa17447090 std/crypto: make the whole APIs more consistent
- use `PascalCase` for all types. So, AES256GCM is now Aes256Gcm.
- consistently use `_length` instead of mixing `_size` and `_length` for the
constants we expose
- Use `minimum_key_length` when it represents an actual minimum length.
Otherwise, use `key_length`.
- Require output buffers (for ciphertexts, macs, hashes) to be of the right
size, not at least of that size in some functions, and the exact size elsewhere.
- Use a `_bits` suffix instead of `_length` when a size is represented as a
number of bits to avoid confusion.
- Functions returning a constant-sized slice are now defined as a slice instead
of a pointer + a runtime assertion. This is the case for most hash functions.
- Use `camelCase` for all functions instead of `snake_case`.

No functional changes, but these are breaking API changes.
2020-10-17 18:53:08 -04: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
xackus
b8b68cb279 std: clean up bitrotten imports in crypto 2020-09-08 12:54:28 -04:00
Frank Denis
ff2e82f382 Rename at to tag in AEADs 2020-08-26 10:50:34 +02:00
Frank Denis
b8729ca1a0 Improve crypto benchmarks
- 1MiB objects on the stack doesn't play well with wasmtime.
Reduce these to 512KiB so that the webassembly benchmarks can run.
- Pass expected results to a blackBox() function. Without this, in
release-fast mode, the compiler could detected unused return values,
and would produce results that didn't make sense for siphash.
- Add AEAD constructions to the benchmarks.
- Inline chacha20Core() makes it 4 times faster.
- benchmarkSignatures() -> benchmarkSignature() for consistency.
2020-08-26 10:50:34 +02: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
Frank Denis
cd591a9b25 No need for an explicit deref 2020-08-17 13:54:01 -07:00
Frank Denis
795033c35f std/crypto: XChaCha20, detached modes and standard AEAD API
* Factor redundant code in std/crypto/chacha20

* Add support for XChaCha20, and the XChaCha20-Poly1305 construction.

XChaCha20 is a 24-byte version of ChaCha20, is widely implemented
and is on the standards track:
https://tools.ietf.org/html/draft-irtf-cfrg-xchacha-03

* Add support for encryption/decryption with the authentication tag
detached from the ciphertext

* Add wrappers with an API similar to the Gimli AEAD type, so that
we can use and benchmark AEADs with a common API.
2020-08-17 13:54:01 -07:00
Andrew Kelley
f614d94faa
update std lib to take advantage of slicing with comptime indexes 2020-03-19 14:48:47 -04:00
Andrew Kelley
5575e2a168
std.mem.compare: breaking API changes
* `std.mem.Compare` is now `std.math.Order` and the enum tags
   renamed to follow new style convention.
 * `std.mem.compare` is renamed to `std.mem.order`.
 * new function `std.math.order`
2020-01-01 18:08:40 -05:00
lukechampine
ab093228f9
Fix segfault by not reassigning to function parameter 2019-12-30 13:53:09 -05:00
lukechampine
d1a570a4b8
chacha: Fix open docstring 2019-12-30 13:35:16 -05:00
lukechampine
d6ca2323cf
chacha: Use error set instead of bool 2019-12-30 13:35:13 -05:00
lukechampine
1953b60599
chacha20poly1305: Return false on short ciphertext 2019-12-30 13:35:05 -05:00
lukechampine
ae7bb4ecc0
chacha20poly1305: verify tag in constant time 2019-12-30 13:34:57 -05:00
lukechampine
fbe7d8c1cb
crypto: Add chacha20poly1305 2019-12-30 13:34:53 -05: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
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