gingerBill
703eab2f15
Merge pull request #3229 from Yawning/feature/moar-crypto
...
core/crypto: More improvements/additions
2024-03-06 14:49:15 +00:00
Yawning Angel
fa8dd5a13b
core/crypto: Misc cleanups and documentation improvements
2024-03-04 17:50:45 +09:00
Yawning Angel
b818ebc02f
core/crypto/kmac: Initial import
2024-03-04 17:50:45 +09:00
Yawning Angel
c04a53e453
core/crypto/tuplehash: Initial import
2024-03-04 17:50:43 +09:00
Yawning Angel
15287a771f
core/crypto/shake: Support cSHAKE
2024-03-04 17:50:24 +09:00
Yawning Angel
2db31cf0d5
core/crypto/_sha3: Cleanups, prepare for cSHAKE
2024-03-04 14:51:38 +09:00
Yawning Angel
550e798c1b
core/crypto/hkdf: Initial import
2024-03-04 14:51:38 +09:00
Yawning Angel
290168f862
core/crypto/pbkdf2: Initial import
2024-03-04 14:51:38 +09:00
Yawning Angel
2f2a92866b
core/crypto/hmac: Add a clone method
2024-03-04 14:51:38 +09:00
Laytan Laats
88e6980b13
fix build tags
2024-02-13 17:34:40 +01:00
Laytan Laats
0d413b8136
implement part of core foundation framework bindings for err message
2024-02-13 17:34:40 +01:00
Laytan Laats
32a4a5e601
remove darwin from bsd filename
2024-02-13 17:34:40 +01:00
Laytan Laats
91cf0826c1
use Security.framework with SecRandomCopyBytes for rand_bytes on darwin
2024-02-13 17:34:40 +01:00
Laytan Laats
3bc172c70b
add crypto.rand_bytes for Darwin and FreeBSD
2024-02-13 17:34:00 +01:00
Yawning Angel
44758f2a60
core/crypto: Stop using context.temp_allocator
...
The max digest size for the foreseeable future will be 512 bits, and the
max block size is currently 1152 bits (SHA3-224). If people add more
exotic hash algorithms without bumping the constants when required,
tests will fail.
The stream buffer will currently be 576 bytes, which is "fine" to just
stick on the stack, and is a sensible multiple of the more common block
size of 64 bytes.
2024-02-07 02:33:53 +09:00
Yawning Angel
56516ee8b2
core/crypto/poly1305: Relax the tag length check on the verify helper
2024-02-07 00:42:01 +09:00
Yawning Angel
1cc639bc93
core/crypto/hmac: Initial import
2024-02-07 00:42:01 +09:00
Yawning Angel
2357293e05
core/crypto/hash: Make the low level interface allocator-less
...
Just (ab)using reflect to victory is probably fine.
2024-02-07 00:37:18 +09:00
Yawning Angel
7a8b1669b0
core/crypto: Expose the block sizes for every hash algorithm
...
While I just went and made this private, this information is required
for keying HMAC.
2024-02-07 00:37:18 +09:00
Yawning Angel
b02b85d242
core/crypto/shake: SHAKE is an XOF, not a hash
2024-02-07 00:37:18 +09:00
Yawning Angel
899fab64d9
core/crypto: Documentation cleanups
2024-02-07 00:37:18 +09:00
Yawning Angel
00ab3beed9
core:crypto/hash: Add a generic higher level hash interface
...
There is a lot of code duplicated in convenience methods in each hash
implementation, and having a generic hash type makes implementing
higher-level constructs such as HMAC significantly easier down the road.
2024-02-07 00:37:18 +09:00
Yawning Angel
9cc5cd9d40
core/crypto: Update the documentation (NFC)
2023-11-17 19:54:06 +09:00
Yawning Angel
59950bcad6
core/crypto: Exile keccak, md5 and sha1 to legacy
...
In an perfect world these would just be removed, but the world is
imperfect, and people are forced to interact/interface with things
that are broken.
2023-11-17 19:32:11 +09:00
Yawning Angel
4587a55486
core/crypto/sm3: API cleanup
...
- sm3.Sm3_Context -> sm3.Context
2023-11-17 19:32:09 +09:00
Yawning Angel
7640fb0483
core/crypto/shake: API cleanup
...
- shake.Shake_Context -> shake.Context
2023-11-17 19:31:51 +09:00
Yawning Angel
b8f9deb3d8
core/crypto/sha3: API cleanup
...
- sha3.Sha3_Context -> sha3.Context
2023-11-17 19:31:51 +09:00
Yawning Angel
92aad90c6b
core/crypto/sha2: API cleanup
...
- sha2.Sha256_Context -> sha2.Context_256
- sha2.Sha512_Context -> sha2.Context_512
2023-11-17 19:31:51 +09:00
Yawning Angel
506adfb105
core/crypto/sha1: API cleanup
...
-sha1.Sha1_Context -> Context
2023-11-17 19:31:51 +09:00
Yawning Angel
e819eebc63
core/crypto/md5: API cleanup
...
- md5.Md5_Context -> md5.Context
2023-11-17 19:31:51 +09:00
Yawning Angel
841e73fcd5
core/crypto/keccak: API cleanup
...
- keccak.Keccak_Context -> keccak.Context
2023-11-17 19:31:51 +09:00
Yawning Angel
aa821991b8
core/crypto/blake2: API cleanup and bug fixes
...
- blake2s.Blake2s_Context -> blake2s.Context
- blake2b.Blake2b_Context -> blake2b.Context
- Fix the BLAKE2s low level API (context type was incorrect)
- Support the configurable output size
2023-11-17 19:31:51 +09:00
Yawning Angel
b71afdc3ee
core/crypto/sha2: Refactor update/final
...
This is largely modeled off the SM3 versions of these routines, since
the relevant parts of the code are the same between SHA-256 and SM3,
and the alterations required to support SHA-512 are relatively simple.
The prior versions of update and the transform would leak memory, and
doing things this way also reduces the context buffer sizes by 1 block.
2023-11-17 19:31:51 +09:00
Yawning Angel
bc139ba6c6
core/crypto/util: Remove, no longer needed
2023-11-17 19:31:51 +09:00
Yawning Angel
8af6da5de1
core/crypto/whirlpool: Remove, historical/exotic
2023-11-17 19:31:51 +09:00
Yawning Angel
0b86038482
core/crypto/tiger: Remove, historical/exotic
2023-11-17 19:31:51 +09:00
Yawning Angel
8d943f5902
core/crypto/streebog: Remove, exotic
2023-11-17 19:31:51 +09:00
Yawning Angel
3494a6dcd8
core/crypto/ripemd: Remove, historical/exotic
2023-11-17 19:31:51 +09:00
Yawning Angel
235fec23af
core/crypto/md4: Remove, badly broken
2023-11-17 19:31:51 +09:00
Yawning Angel
97b066f112
core/crypto/md2: Remove, badly broken
2023-11-17 19:31:51 +09:00
Yawning Angel
a99c0b3e4a
core/crypto/jh: Remove, use SHA-3
2023-11-17 19:31:51 +09:00
Yawning Angel
2a6fb3a387
core/crypto/haval: Remove, badly broken
2023-11-17 19:31:51 +09:00
Yawning Angel
65204f13a8
core/crypto/groestl: Remove, use SHA-3
2023-11-17 19:31:51 +09:00
Yawning Angel
8438d66e6b
core/crypto/gost: Remove, exotic
2023-11-17 19:31:51 +09:00
Yawning Angel
44c8da7bf2
core/crypto/blake: Remove, use BLAKE2b/BLAKE2s
2023-11-17 19:31:51 +09:00
Yawning Angel
41fdcfeecf
core/crypto/sha2: Add SHA-512/256
2023-11-17 19:31:51 +09:00
Yawning Angel
70ba4b5321
core/crypto: Add more assertions to the low level API
...
Assertions here are "fine" and it matches what the code that has the
checks in init/update/final already does.
2023-11-17 19:31:51 +09:00
Yawning Angel
71da3ef925
core/crypto/sha2: Fix overflow for large amounts of hashed data
2023-11-17 19:31:51 +09:00
Yawning Angel
582bd760b7
core/crypto/shake: Add a TODO comment (NFC)
2023-11-17 19:31:51 +09:00
Yawning Angel
e86bb3a795
core/crypto: Change hash asserts to panics
...
Assertions can be disabled, but at the point where cryptographic
anything is involved, a single branch has an infinitesimally small
performance impact.
The correct thing to do is to punch the caller in the face if they do
something that is blatantly incorrect, especially in a security critical
setting.
2023-11-17 19:31:51 +09:00