From 7035cb0e273361b21af78961ebfa56693c0d75b3 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 8 Mar 2026 15:26:40 +0100 Subject: [PATCH] Remove useless sodium_memzero, add one that makes sense --- src/libsodium/crypto_box/crypto_box_seal.c | 2 -- .../box_curve25519xchacha20poly1305.c | 5 ++++- .../box_seal_curve25519xchacha20poly1305.c | 2 -- .../box_curve25519xsalsa20poly1305.c | 5 ++++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libsodium/crypto_box/crypto_box_seal.c b/src/libsodium/crypto_box/crypto_box_seal.c index e01d6498..9a677d00 100644 --- a/src/libsodium/crypto_box/crypto_box_seal.c +++ b/src/libsodium/crypto_box/crypto_box_seal.c @@ -37,8 +37,6 @@ crypto_box_seal(unsigned char *c, const unsigned char *m, nonce, pk, esk); memcpy(c, epk, crypto_box_PUBLICKEYBYTES); sodium_memzero(esk, sizeof esk); - sodium_memzero(epk, sizeof epk); - sodium_memzero(nonce, sizeof nonce); return ret; } diff --git a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c index 5e2532ea..789286e0 100644 --- a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +++ b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c @@ -48,7 +48,10 @@ crypto_box_curve25519xchacha20poly1305_beforenm(unsigned char *k, if (crypto_scalarmult_curve25519(s, sk, pk) != 0) { return -1; } - return crypto_core_hchacha20(k, zero, s, NULL); + crypto_core_hchacha20(k, zero, s, NULL); + sodium_memzero(s, sizeof s); + + return 0; } int diff --git a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c index 0240f036..0b63431b 100644 --- a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c +++ b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c @@ -44,8 +44,6 @@ crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c, const unsigned cha nonce, pk, esk); memcpy(c, epk, crypto_box_curve25519xchacha20poly1305_PUBLICKEYBYTES); sodium_memzero(esk, sizeof esk); - sodium_memzero(epk, sizeof epk); - sodium_memzero(nonce, sizeof nonce); return ret; } diff --git a/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c b/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c index 4c1d62ed..c8d7fe01 100644 --- a/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c +++ b/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c @@ -42,7 +42,10 @@ crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k, if (crypto_scalarmult_curve25519(s, sk, pk) != 0) { return -1; } - return crypto_core_hsalsa20(k, zero, s, NULL); + crypto_core_hsalsa20(k, zero, s, NULL); + sodium_memzero(s, sizeof s); + + return 0; } int