1995 Commits
Author SHA1 Message Date
Frank Denis 2c61b499e7 sodium_bin2ip: no need to copy an extra byte 2026-08-13 07:30:50 +02:00
Frank Denis 2ce4d906a6 Always use STORE32_LE for unaligned stores, even when it's a noop 2026-07-12 14:37:05 +02:00
Frank Denis b934a541f7 Replace softaes with a bitsliced implementation 2026-06-11 15:28:22 +02:00
Frank Denis 7c1ea609f4 SipHash: help the compiler a little bit 2026-06-11 15:27:51 +02:00
Frank Denis 6871630041 Improve Keccak performance 2026-06-11 15:27:39 +02:00
Frank Denis 33cc75ab15 Fix: sodium_misuse() callback runs under global lock and can deadlock
SUMMARY
`src/libsodium/sodium/core.c` invokes the process-global misuse callback from `sodium_misuse()` while still holding the library-wide critical section. If the application-installed callback re-enters any API path that acquires the same lock, including `sodium_set_misuse_handler()`, execution deadlocks before `abort()` is reached. This breaks the intended fail-stop behavior of misuse handling.

PROVENANCE
Verified from the provided finding, reproduced locally from the committed control flow, and documented for Swival Security Scanner (https://swival.dev).

PRECONDITIONS
- A caller installs a misuse handler via `sodium_set_misuse_handler()`.
- The handler re-enters an API path that takes the same global critical section, including `sodium_set_misuse_handler()`.

PROOF
1. `sodium_set_misuse_handler()` writes the global `_misuse_handler` under `sodium_crit_enter()` / `sodium_crit_leave()` in `src/libsodium/sodium/core.c:170` and `src/libsodium/sodium/core.c:174`.
2. `sodium_misuse()` acquires that same critical section, copies `_misuse_handler`, and invokes `handler()` before releasing the lock in `src/libsodium/sodium/core.c:155` and `src/libsodium/sodium/core.c:160`.
3. The pthread-backed critical section in this file is non-recursive (`src/libsodium/sodium/core.c:89`), so a callback that calls `sodium_set_misuse_handler()` blocks in `sodium_crit_enter()` waiting on the lock already held by `sodium_misuse()`.
4. Because `sodium_misuse()` is waiting for the callback to return, it never reaches `abort()`, converting a fail-stop misuse path into a hang.
5. Reproduction confirmed this with a minimal pthread harness: the handler printed `handler: before reentry` and then hung until terminated by `timeout`.

WHY THIS IS A REAL BUG
The callback target is application-controlled through an exported setter, and `sodium_misuse()` calls it on a misuse path without enforcing any non-reentrancy contract. On pthread targets, a handler that performs a supported API call can permanently block process termination. That is a reachable behavioral failure, not a theoretical lock-order concern.

FIX REQUIREMENT
Load `_misuse_handler` while holding the lock, release the critical section, and only then invoke the callback. This removes lock-dependent behavior from arbitrary user code while preserving synchronized access to the global handler pointer.
2026-04-16 16:51:18 +02:00
Frank Denis 77e1ce5d6d Add code comments about why variable-time is fine for public inputs 2026-04-09 23:00:06 +02:00
Frank Denis d022f2d637 State wipe 2026-04-09 23:00:05 +02:00
Frank Denis 758bb4a4de ML-KEM: wipe ephemeral seeds and harden invalid-pk test 2026-04-09 23:00:05 +02:00
Frank Denis bf8cf449ea sha3: make post-final misuse safe and deterministic 2026-04-09 23:00:05 +02:00
Frank Denis 57c6200865 Regen 2026-04-09 23:00:05 +02:00
Frank Denis 30a18ae407 Add a high-level crypto_kem API mapping to xwing 2026-04-09 23:00:05 +02:00
Frank Denis 3fa3eac209 Add X-Wing 2026-04-09 23:00:05 +02:00
Frank Denis bca64e0982 Add ML-KEM768 2026-04-09 23:00:05 +02:00
Frank Denis 350313ec20 Add support for SHA3 2026-04-09 23:00:05 +02:00
Frank Denis a09f7ed21a Add some coverage exclusions 2026-04-09 23:00:05 +02:00
Frank Denis 98e1f0dba7 SHAKE: in case update is called right after squeezing, permute
Calling update after squeezing is undocumented and non standard,
but if an application still decides to do it, permute the state
before absorbing so that it's still safe to do so.

We can easily do it since we keep track of the state.

Still return an error as this is not the expected usage of SHAKE,
and zeroing the state is another thing we could do.
2026-04-09 23:00:04 +02:00
Frank Denis db920a146c Add NEON optimizations for Argon2 2026-04-09 23:00:04 +02:00
Frank Denis 4defa543c4 Relax crypto_auth_hmacsha{256,512}_init to accept NULL pointers 2026-04-09 22:20:32 +02:00
Frank Denis 45b5cae00a Include <core.h> to get sodium_misuse 2026-04-09 22:18:52 +02:00
Frank Denis d6820320e8 Allow NULL pointers (with length=0) with shorthash 2026-04-09 22:18:47 +02:00
Frank Denis c1fe2af601 Reject impossible lengths in crypto_box 2026-04-09 22:18:41 +02:00
Frank Denis c7fb97c2bf Add some zeroing 2026-04-09 22:18:35 +02:00
Frank Denis 874c12a3ae Add some message size guards in AEGIS, for consistency 2026-04-09 22:18:29 +02:00
Frank Denis a77b7e7bbf Add Visual Studio quirks back 2026-04-09 00:42:34 +02:00
Frank Denis 4fe02571dd Fix compilation on ARM with very old gcc versions 2026-04-09 00:28:22 +02:00
Frank Denis d4bc6fb5fe Unify AES key expansion code on ARM 2026-04-09 00:28:18 +02:00
Frank Denis 829426cd1d More fixes for MSVC/aarch64 2026-04-09 00:28:13 +02:00
Frank Denis 2d949f8330 Add support for MSVC to aes256gcm 2026-04-09 00:28:09 +02:00
Frank Denis 168e60a217 Add casts for aarch64+gcc 2026-04-09 00:28:06 +02:00
Frank Denis 00ff370f84 Try to enable aes256-gcm even on non-clang compilers 2026-04-09 00:28:03 +02:00
Frank Denis 5160d47a9d Remove trailing comma 2026-04-09 00:15:51 +02:00
Frank Denis 098c5d46d3 Call sodium_misuse on ridiculously high base64 input lengths 2026-04-08 21:41:43 +02:00
Frank Denis 1518607867 C++ compat 2026-04-05 21:58:17 +02:00
Frank Denis 175d573e29 Remove ctype usage 2026-04-04 22:41:59 +02:00
Frank Denis 7a69ca5bc9 Refactor IPv6 zone ID parsing and reject malformed zone identifiers 2026-04-04 22:35:40 +02:00
Frank Denis 97a6e1d2d8 gcc on FreeBSD can produce bogus code for isspace 2026-04-04 22:24:16 +02:00
Frank Denis d44576d85a defined _AIX -> defined(_AIX) 2026-04-04 22:05:00 +02:00
Frank Denis bd6402c5db Define TLS as _Thread_local only if not properly autoconfigured 2026-04-04 11:12:55 +02:00
Frank Denis 8565c4a159 Some AIX versions define a macro named ip_len
So, workaround that by using ip_len_ :/
2026-04-04 11:05:04 +02:00
Frank Denis d23bbc58c3 base64: reject signed chars 2026-03-29 09:22:30 +02:00
Frank Denis c8dbc9c926 No need to include the hkdf headers twice 2026-03-26 23:53:05 +08:00
Frank Denis cdd5dea03d Avoid an MSVC warning in sodium_base64_ENCODED_LEN macro
Reported by @valveri , thanks!

Fixes #1526
Fixes #1527
2026-03-24 19:39:47 +08:00
Frank Denis 79a59b7a0a Restrict evex512 to clang 18-21 only 2026-03-16 20:52:58 +01:00
Frank Denis b55d75015b Add LCOV markers 2026-03-15 12:40:05 +01:00
Frank Denis 4286cef393 Add inlilne hints for aegis hot paths 2026-03-15 10:42:01 +01:00
Frank Denis 13d2c97a72 Remove useless sodium_memzero, add one that makes sense 2026-03-08 15:26:40 +01:00
Frank Denis c4e3b4028f Zero the state afetr AES decryption 2026-02-10 09:01:00 +01:00
Frank Denis 8a8d8a62fa secretbox: zero the state after checking only the tag 2026-02-10 09:00:59 +01:00
Frank Denis f6c18801a8 Add WASM SIMD implementations of Argon2 2026-01-22 10:42:14 +01:00