mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Add fences
This commit is contained in:
@@ -241,8 +241,12 @@ decrypt_detached(uint8_t *m, const uint8_t *c, size_t clen, const uint8_t *mac,
|
||||
} else if (maclen == 32) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -224,8 +224,12 @@ decrypt_detached(uint8_t *m, const uint8_t *c, size_t clen, const uint8_t *mac,
|
||||
} else if (maclen == 32) {
|
||||
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;
|
||||
|
||||
@@ -101,6 +101,7 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c,
|
||||
if (m == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ACQUIRE_FENCE;
|
||||
if (((uintptr_t) c > (uintptr_t) m &&
|
||||
(uintptr_t) c - (uintptr_t) m < clen) ||
|
||||
((uintptr_t) m > (uintptr_t) c &&
|
||||
|
||||
@@ -108,6 +108,7 @@ crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m,
|
||||
if (m == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ACQUIRE_FENCE;
|
||||
if (((uintptr_t) c > (uintptr_t) m &&
|
||||
(uintptr_t) c - (uintptr_t) m < clen) ||
|
||||
((uintptr_t) m > (uintptr_t) c &&
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -239,6 +239,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);
|
||||
|
||||
Reference in New Issue
Block a user