Add fences

This commit is contained in:
Frank Denis
2026-01-06 23:09:21 +01:00
parent f6c5b9f0e4
commit c89ee84172
10 changed files with 24 additions and 6 deletions
@@ -242,8 +242,12 @@ decrypt_detached(uint8_t *m, const uint8_t *c, size_t clen, const uint8_t *mac,
ret = crypto_verify_32(computed_mac, mac);
}
}
if (ret != 0 && m != NULL) {
memset(m, 0, mlen);
if (ret != 0) {
if (m != NULL) {
memset(m, 0, mlen);
}
return ret;
}
return ret;
ACQUIRE_FENCE;
return 0;
}
@@ -225,8 +225,12 @@ decrypt_detached(uint8_t *m, const uint8_t *c, size_t clen, const uint8_t *mac,
ret = crypto_verify_32(computed_mac, mac);
}
}
if (ret != 0 && m != NULL) {
memset(m, 0, mlen);
if (ret != 0) {
if (m != NULL) {
memset(m, 0, mlen);
}
return ret;
}
return ret;
ACQUIRE_FENCE;
return 0;
}
@@ -935,6 +935,7 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char *
memset(m, 0xd0, m_len);
return -1;
}
ACQUIRE_FENCE;
return 0;
}
@@ -953,6 +953,7 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char *
memset(m, 0xd0, m_len);
return -1;
}
ACQUIRE_FENCE;
return 0;
}
@@ -208,6 +208,7 @@ crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,
memset(m, 0, mlen);
return -1;
}
ACQUIRE_FENCE;
crypto_stream_chacha20_xor_ic(m, c, mlen, npub, 1U, k);
return 0;
@@ -292,6 +293,7 @@ crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,
memset(m, 0, mlen);
return -1;
}
ACQUIRE_FENCE;
crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, npub, 1U, k);
return 0;
@@ -112,6 +112,7 @@ _decrypt_detached(unsigned char *m,
memset(m, 0, mlen);
return -1;
}
ACQUIRE_FENCE;
crypto_stream_chacha20_ietf_ext_xor_ic(m, c, mlen, npub, 1U, k);
return 0;
@@ -115,6 +115,7 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c,
if (m == NULL) {
return 0;
}
ACQUIRE_FENCE;
/*
* Allow the m and c buffers to partially overlap, by calling
@@ -124,6 +124,7 @@ crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m,
if (m == NULL) {
return 0;
}
ACQUIRE_FENCE;
/*
* Allow the m and c buffers to partially overlap, by calling
@@ -2,6 +2,7 @@
#include "crypto_secretbox_xsalsa20poly1305.h"
#include "crypto_stream_xsalsa20.h"
#include "randombytes.h"
#include "private/common.h"
int
crypto_secretbox_xsalsa20poly1305(unsigned char *c, const unsigned char *m,
@@ -39,6 +40,7 @@ crypto_secretbox_xsalsa20poly1305_open(unsigned char *m, const unsigned char *c,
clen - 32, subkey) != 0) {
return -1;
}
ACQUIRE_FENCE;
crypto_stream_xsalsa20_xor(m, c, clen, n, k);
for (i = 0; i < 32; ++i) {
m[i] = 0;
@@ -241,6 +241,7 @@ crypto_secretstream_xchacha20poly1305_pull
return -1;
}
ACQUIRE_FENCE;
crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, state->nonce, 2U, state->k);
XOR_BUF(STATE_INONCE(state), mac,
crypto_secretstream_xchacha20poly1305_INONCEBYTES);