aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-03-30 15:33:07 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-03-30 18:14:39 +0200
commit8c124ca0b9ffc961a6140f3b2e90830d9adbb291 (patch)
tree32edfe342c99122cd464777ee9ee3a291a2e5f53 /src/crypto
parentcurve25519: protect against potential invalid point attacks (diff)
downloadwireguard-monolithic-historical-8c124ca0b9ffc961a6140f3b2e90830d9adbb291.tar.xz
wireguard-monolithic-historical-8c124ca0b9ffc961a6140f3b2e90830d9adbb291.zip
chacha20poly1305: enforce authtag checking with compiler
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/chacha20poly1305.c13
-rw-r--r--src/crypto/chacha20poly1305.h12
2 files changed, 10 insertions, 15 deletions
diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c
index b7b7bef..9cc1305 100644
--- a/src/crypto/chacha20poly1305.c
+++ b/src/crypto/chacha20poly1305.c
@@ -568,7 +568,7 @@ static struct blkcipher_desc chacha20_desc = {
.tfm = &chacha20_cipher
};
-bool chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
+void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN])
{
@@ -605,11 +605,9 @@ bool chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
memzero_explicit(&chacha20_state, sizeof(chacha20_state));
chacha20poly1305_deinit_simd(have_simd);
-
- return true;
}
-bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
+void chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN],
bool have_simd)
@@ -660,7 +658,6 @@ bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *sr
memzero_explicit(&poly1305_state, sizeof(poly1305_state));
memzero_explicit(&chacha20_state, sizeof(chacha20_state));
memzero_explicit(mac, sizeof(mac));
- return true;
}
bool chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
@@ -782,17 +779,15 @@ bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *sr
}
-bool xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
+void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u8 nonce[XCHACHA20POLY1305_NONCELEN],
const u8 key[CHACHA20POLY1305_KEYLEN])
{
u8 derived_key[CHACHA20POLY1305_KEYLEN];
- bool ret;
hchacha20(derived_key, nonce, key);
- ret = chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, le64_to_cpuvp(nonce + 16), derived_key);
+ chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len, le64_to_cpuvp(nonce + 16), derived_key);
memzero_explicit(derived_key, CHACHA20POLY1305_KEYLEN);
- return ret;
}
bool xchacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
diff --git a/src/crypto/chacha20poly1305.h b/src/crypto/chacha20poly1305.h
index 560ba84..76b76d2 100644
--- a/src/crypto/chacha20poly1305.h
+++ b/src/crypto/chacha20poly1305.h
@@ -15,29 +15,29 @@ enum chacha20poly1305_lengths {
void chacha20poly1305_fpu_init(void);
-bool chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
+void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN]);
-bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
+void chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN],
bool have_simd);
-bool chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
+bool __must_check chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN]);
-bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
+bool __must_check chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN]);
-bool xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
+void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u8 nonce[XCHACHA20POLY1305_NONCELEN],
const u8 key[CHACHA20POLY1305_KEYLEN]);
-bool xchacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
+bool __must_check xchacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u8 nonce[XCHACHA20POLY1305_NONCELEN],
const u8 key[CHACHA20POLY1305_KEYLEN]);