Commit Graph

2235 Commits

Author SHA1 Message Date
Frank Denis eef111fe78 Fix missing init() update in std/build/write_file.zig 2020-08-20 19:21:10 -04:00
Andrew Kelley 21106b9c9f Merge pull request #6095 from jedisct1/crypto-reorg
Breaking: sort std/crypto functions into categories
2020-08-20 19:01:22 -04:00
Frank Denis fc55cd458a Hash functions now accept an option set
- This avoids having multiple `init()` functions for every combination
of optional parameters
- The API is consistent across all hash functions
- New options can be added later without breaking existing applications.
  For example, this is going to come in handy if we implement parallelization
  for BLAKE2 and BLAKE3.
- We don't have a mix of snake_case and camelCase functions any more, at
least in the public crypto API

Support for BLAKE2 salt and personalization (more commonly called context)
parameters have been implemented by the way to illustrate this.
2020-08-21 00:51:14 +02:00
Andrew Kelley 9cfcd0c296 Merge pull request #6103 from Vexu/extern
Disallow extern variables with initializers.
2020-08-20 18:35:31 -04:00
heidezomp 1ca49b92c6 add UTIME_NOW and UTIME_OMIT constants for use in utimensat/futimens
copied from lib/libc/include/generic-musl/sys/stat.h
2020-08-20 17:02:58 -04:00
Frank Denis adf3d00e87 Remove explicit comptime 2020-08-20 23:02:10 +02:00
Frank Denis 446597bd3c Remove the reset() function from hash functions
Justification:
- reset() is unnecessary; states that have to be reused can be copied
- reset() is error-prone. Copying a previous state prevents forgetting
  struct members.
- reset() forces implementation to store sensitive data (key, initial state)
  in memory even when they are not needed.
- reset() is confusing as it has a different meaning elsewhere in Zig.
2020-08-20 23:02:10 +02:00
Frank Denis f92a5d7944 Repair crypto/benchmark; add BLAKE2b256
Some MACs have a 64-bit output
2020-08-20 23:02:10 +02:00
Frank Denis 3bed749b1c Add truncated SHA512 variants 2020-08-20 23:02:10 +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 776bfb0ee6 Merge pull request #6099 from tadeokondrak/@Type(.Struct)
Implement @Type for structs
2020-08-20 16:57:10 -04: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
Vexu 717e2a365d correct llvm linkage conversion
when weakly exporting external declaration we need to pass LLVMExternalWeakLinkage
2020-08-20 17:12:26 +03:00
Vexu d25674a51e disallow extern variables with initializers 2020-08-20 11:35:33 +03:00
Vexu adc5bce5e8 translate-c: correct translation of global variables
* externs with intializers are translated as exports
* non extern without explicit initialization are zero initalized
2020-08-20 10:08:27 +03:00
Andrew Kelley 23c427b5fb windows: match the same error code for EBADF 2020-08-19 20:51:06 -07:00
StrangeBug 59711becc7 Add handler for INVALID_HANDLE to prevent infinite loop when stderr is not available. 2020-08-19 20:49:25 -07:00
Andrew Kelley b1c7334355 Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
2020-08-19 23:46:22 -04:00
Vincent Rischmann b0846b6ecb builder: implement integer options 2020-08-19 17:41:43 -04:00
Tadeo Kondrak 0f677810ea Remove offset field from TypeInfo.StructField
This isn't needed with @bitOffsetOf/@byteoffsetOf and complicates
@Type handling.
2020-08-19 14:55:40 -06:00
dbandstra a237283d90 fixes and improvements for parseCharLiteral 2020-08-19 16:30:42 -04:00
Jakub Konka 5fe878cd42 Merge pull request #6085 from kubkon/macho-header
Write out Mach-O header
2020-08-19 07:50:11 +02:00
Nathan Michaels 4237f1afc7 Change std.debug.warn to std.log.info in init-exe template. (#5941) 2020-08-18 22:47:38 -04:00
Andrew Kelley 771f40204e Merge pull request #6086 from Vexu/stage2
Stage2: more astgen stuff
2020-08-18 22:02:55 -04:00
Andrew Kelley f950f5452b test_runner: don't assume the GeneralPurposeAllocator config
This allows changing the config in only 1 location (std.testing)
2020-08-18 15:10:31 -07:00
Andrew Kelley 583b843803 std.heap.GeneralPurposeAllocator: add never_unmap config option
This is a temporary debugging trick you can use to turn segfaults into more helpful
logged error messages with stack trace details. The downside is that every allocation
will be leaked!
2020-08-18 15:09:48 -07:00
Jakub Konka e4b3da2720 Write out Mach-O header
This commit write out Mach-O header in the linker's `flush`
method. The header currently only populates the magic number,
filetype, and cpu info.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Andrew Kelley e2c741f1e7 std.cache_hash: additionally use file size to detect modifications
I have observed on Linux writing and reading the same file many times
without the mtime changing, despite the file system having nanosecond
granularity (and about 1 millisecond worth of nanoseconds passing between
modifications). I am calling this a Linux Kernel Bug and adding file
size to the cache hash manifest as a mitigation. As evidence, macOS does
not exhibit this behavior.

This means it is possible, on Linux, for a file to be added to the cache
hash, and, if it is updated with the same file size, same inode, within
about 1 millisecond, the cache system will give us a false positive,
saying it is unmodified. I don't see any way to improve this situation
without fixing the bug in the Linux kernel.

closes #6082
2020-08-18 12:44:00 -07:00
Vexu 2b45e23477 stage2: character literals and multiline strings 2020-08-18 20:10:18 +03:00
Andrew Kelley c0517bf1f6 std.cache_hash: temporary workaround for mtime precision on linux
See #6082
2020-08-18 01:30:57 -07:00
Frank Denis 8d60047697 ristretto255: add uniform string->element map & fast equivalence check 2020-08-18 00:31:02 -04:00
Andrew Kelley ce8b9c0c5c std.cache_hash: don't trust mtime granularity to be better than 1ms
I empirically observed mtime not changing when rapidly writing the same
file name within the same millisecond of wall clock time, despite the
mtime field having nanosecond precision.

I believe this fixes the CI test failures.
2020-08-17 21:26:33 -07:00
Matthew Knight d605af511a added bpf() syscall and some supporting structs (#6061)
* added bpf syscall and some supporting structs

* moved bpf to bits and added flags
2020-08-17 22:17:04 -04:00
Andrew Kelley a916f63940 std.cache_hash: fix bug parsing inode
This resulted in false negatives cache misses.
2020-08-17 18:49:33 -07:00
Andrew Kelley ae2c88754d std: signalfd: fix the types of things; add test 2020-08-17 16:19:57 -07:00
Luna 293b07df12 add signalfd to std.c.linux 2020-08-17 16:05:35 -07:00
Luna 2deb07a001 rename signalfd4 to signalfd 2020-08-17 16:05:35 -07:00
Andrew Kelley 624e643872 Merge pull request #6046 from heidezomp/std-log-scoped-part2
std.log: (breaking) remove scope parameter from logging functions
2020-08-17 16:59:27 -04:00
Frank Denis 5fabb44aeb Export crypto.aead 2020-08-17 13:55:40 -07: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
Frank Denis 7f9a227abf deinline edwards25519.{add,dbl} 2020-08-16 22:35:28 -07:00
Frank Denis 37ae246405 Inline Fe.{sub,mul,sq} for a performance boost in release-safe mode 2020-08-16 22:35:28 -07:00
Frank Denis ab6ffa8a3c Work around sqrtRatioM1() issue in release-safe mode 2020-08-16 22:35:28 -07:00
Frank Denis 08dfbee961 Benchmark signatures 2020-08-16 22:35:27 -07:00
Frank Denis 5ab69633b7 Constify the ladder 2020-08-16 22:35:27 -07:00
Frank Denis d86cde5752 Add comment, use @truncate 2020-08-16 22:35:27 -07:00
Frank Denis bcef123d90 Address more review issues 2020-08-16 22:35:27 -07:00
Frank Denis 263c444738 Move loop decrements into continuations
Suggested by @daurnimator
2020-08-16 22:35:27 -07:00
Frank Denis ed558bfbaa Address @daurnimator feedback 2020-08-16 22:35:27 -07:00