From ff480f17f01954fee38f88f4b9030b3fced867f3 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 11 Dec 2022 23:15:06 +0100 Subject: [PATCH] Nits --- .../aegis128l/aesni/aead_aegis128l_aesni.c | 42 +++++++++---------- .../armcrypto/aead_aegis128l_armcrypto.c | 15 +++---- .../aegis128l/soft/aead_aegis128l_soft.c | 6 +-- .../aegis256/aesni/aead_aegis256_aesni.c | 27 ++++++------ .../armcrypto/aead_aegis256_armcrypto.c | 6 +-- 5 files changed, 42 insertions(+), 54 deletions(-) diff --git a/src/libsodium/crypto_aead/aegis128l/aesni/aead_aegis128l_aesni.c b/src/libsodium/crypto_aead/aegis128l/aesni/aead_aegis128l_aesni.c index 48b7586f..800517a9 100644 --- a/src/libsodium/crypto_aead/aegis128l/aesni/aead_aegis128l_aesni.c +++ b/src/libsodium/crypto_aead/aegis128l/aesni/aead_aegis128l_aesni.c @@ -67,8 +67,8 @@ aegis128l_init(const unsigned char *key, const unsigned char *nonce, aes_block_t aes_block_t n; int i; - k = AES_BLOCK_LOAD((const aes_block_t *) (const void *) key); - n = AES_BLOCK_LOAD((const aes_block_t *) (const void *) nonce); + k = AES_BLOCK_LOAD(key); + n = AES_BLOCK_LOAD(nonce); state[0] = AES_BLOCK_XOR(k, n); state[1] = c0; @@ -97,14 +97,11 @@ aegis128l_mac(unsigned char *mac, unsigned long long adlen, unsigned long long m aegis128l_update(state, tmp, tmp); } - tmp = AES_BLOCK_XOR(state[6], state[5]); - tmp = AES_BLOCK_XOR(tmp, state[4]); - tmp = AES_BLOCK_XOR(tmp, state[3]); - tmp = AES_BLOCK_XOR(tmp, state[2]); - tmp = AES_BLOCK_XOR(tmp, state[1]); - tmp = AES_BLOCK_XOR(tmp, state[0]); + tmp = AES_BLOCK_XOR(state[6], AES_BLOCK_XOR(state[5], state[4])); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[3], state[2])); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[1], state[0])); - AES_BLOCK_STORE((aes_block_t *) (void *) mac, tmp); + AES_BLOCK_STORE(mac, tmp); } static inline void @@ -123,16 +120,16 @@ aegis128l_enc(unsigned char *const dst, const unsigned char *const src, aes_bloc aes_block_t msg0, msg1; aes_block_t tmp0, tmp1; - msg0 = AES_BLOCK_LOAD((const aes_block_t *) (const void *) src); - msg1 = AES_BLOCK_LOAD((const aes_block_t *) (const void *) (src + 16)); + msg0 = AES_BLOCK_LOAD(src); + msg1 = AES_BLOCK_LOAD(src + 16); tmp0 = AES_BLOCK_XOR(msg0, state[6]); tmp0 = AES_BLOCK_XOR(tmp0, state[1]); - tmp1 = AES_BLOCK_XOR(msg1, state[2]); - tmp1 = AES_BLOCK_XOR(tmp1, state[5]); + tmp1 = AES_BLOCK_XOR(msg1, state[5]); + tmp1 = AES_BLOCK_XOR(tmp1, state[2]); tmp0 = AES_BLOCK_XOR(tmp0, AES_BLOCK_AND(state[2], state[3])); tmp1 = AES_BLOCK_XOR(tmp1, AES_BLOCK_AND(state[6], state[7])); - AES_BLOCK_STORE((aes_block_t *) (void *) dst, tmp0); - AES_BLOCK_STORE((aes_block_t *) (void *) (dst + 16), tmp1); + AES_BLOCK_STORE(dst, tmp0); + AES_BLOCK_STORE(dst + 16, tmp1); aegis128l_update(state, msg0, msg1); } @@ -142,16 +139,16 @@ aegis128l_dec(unsigned char *const dst, const unsigned char *const src, aes_bloc { aes_block_t msg0, msg1; - msg0 = AES_BLOCK_LOAD((const aes_block_t *) (const void *) src); - msg1 = AES_BLOCK_LOAD((const aes_block_t *) (const void *) (src + 16)); + msg0 = AES_BLOCK_LOAD(src); + msg1 = AES_BLOCK_LOAD(src + 16); msg0 = AES_BLOCK_XOR(msg0, state[6]); msg0 = AES_BLOCK_XOR(msg0, state[1]); - msg1 = AES_BLOCK_XOR(msg1, state[2]); msg1 = AES_BLOCK_XOR(msg1, state[5]); + msg1 = AES_BLOCK_XOR(msg1, state[2]); msg0 = AES_BLOCK_XOR(msg0, AES_BLOCK_AND(state[2], state[3])); msg1 = AES_BLOCK_XOR(msg1, AES_BLOCK_AND(state[6], state[7])); - AES_BLOCK_STORE((aes_block_t *) (void *) dst, msg0); - AES_BLOCK_STORE((aes_block_t *) (void *) (dst + 16), msg1); + AES_BLOCK_STORE(dst, msg0); + AES_BLOCK_STORE(dst + 16, msg1); aegis128l_update(state, msg0, msg1); } @@ -243,9 +240,8 @@ aegis128l_decrypt_detached(unsigned char *m, unsigned char *nsec, const unsigned } memset(dst, 0, mlen & 0x1f); state[0] = - AES_BLOCK_XOR(state[0], AES_BLOCK_LOAD((const aes_block_t *) (const void *) dst)); - state[4] = AES_BLOCK_XOR(state[4], - AES_BLOCK_LOAD((const aes_block_t *) (const void *) (dst + 16))); + AES_BLOCK_XOR(state[0], AES_BLOCK_LOAD(dst)); + state[4] = AES_BLOCK_XOR(state[4], AES_BLOCK_LOAD(dst + 16)); } aegis128l_mac(computed_mac, adlen, mlen, state); diff --git a/src/libsodium/crypto_aead/aegis128l/armcrypto/aead_aegis128l_armcrypto.c b/src/libsodium/crypto_aead/aegis128l/armcrypto/aead_aegis128l_armcrypto.c index 22577da6..feea33ae 100644 --- a/src/libsodium/crypto_aead/aegis128l/armcrypto/aead_aegis128l_armcrypto.c +++ b/src/libsodium/crypto_aead/aegis128l/armcrypto/aead_aegis128l_armcrypto.c @@ -90,12 +90,9 @@ aegis128l_mac(unsigned char *mac, unsigned long long adlen, unsigned long long m aegis128l_update(state, tmp, tmp); } - tmp = AES_BLOCK_XOR(state[6], state[5]); - tmp = AES_BLOCK_XOR(tmp, state[4]); - tmp = AES_BLOCK_XOR(tmp, state[3]); - tmp = AES_BLOCK_XOR(tmp, state[2]); - tmp = AES_BLOCK_XOR(tmp, state[1]); - tmp = AES_BLOCK_XOR(tmp, state[0]); + tmp = AES_BLOCK_XOR(state[6], AES_BLOCK_XOR(state[5], state[4])); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[3], state[2])); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[1], state[0])); AES_BLOCK_STORE(mac, tmp); } @@ -120,8 +117,8 @@ aegis128l_enc(unsigned char *const dst, const unsigned char *const src, aes_bloc msg1 = AES_BLOCK_LOAD(src + 16); tmp0 = AES_BLOCK_XOR(msg0, state[6]); tmp0 = AES_BLOCK_XOR(tmp0, state[1]); - tmp1 = AES_BLOCK_XOR(msg1, state[2]); - tmp1 = AES_BLOCK_XOR(tmp1, state[5]); + tmp1 = AES_BLOCK_XOR(msg1, state[5]); + tmp1 = AES_BLOCK_XOR(tmp1, state[2]); tmp0 = AES_BLOCK_XOR(tmp0, AES_BLOCK_AND(state[2], state[3])); tmp1 = AES_BLOCK_XOR(tmp1, AES_BLOCK_AND(state[6], state[7])); AES_BLOCK_STORE(dst, tmp0); @@ -139,8 +136,8 @@ aegis128l_dec(unsigned char *const dst, const unsigned char *const src, aes_bloc msg1 = AES_BLOCK_LOAD(src + 16); msg0 = AES_BLOCK_XOR(msg0, state[6]); msg0 = AES_BLOCK_XOR(msg0, state[1]); - msg1 = AES_BLOCK_XOR(msg1, state[2]); msg1 = AES_BLOCK_XOR(msg1, state[5]); + msg1 = AES_BLOCK_XOR(msg1, state[2]); msg0 = AES_BLOCK_XOR(msg0, AES_BLOCK_AND(state[2], state[3])); msg1 = AES_BLOCK_XOR(msg1, AES_BLOCK_AND(state[6], state[7])); AES_BLOCK_STORE(dst, msg0); diff --git a/src/libsodium/crypto_aead/aegis128l/soft/aead_aegis128l_soft.c b/src/libsodium/crypto_aead/aegis128l/soft/aead_aegis128l_soft.c index 31f57aef..d537a855 100644 --- a/src/libsodium/crypto_aead/aegis128l/soft/aead_aegis128l_soft.c +++ b/src/libsodium/crypto_aead/aegis128l/soft/aead_aegis128l_soft.c @@ -117,8 +117,8 @@ aegis128l_enc(unsigned char *const dst, const unsigned char *const src, aes_bloc msg1 = AES_BLOCK_LOAD(src + 16); tmp0 = AES_BLOCK_XOR(msg0, state[6]); tmp0 = AES_BLOCK_XOR(tmp0, state[1]); - tmp1 = AES_BLOCK_XOR(msg1, state[2]); - tmp1 = AES_BLOCK_XOR(tmp1, state[5]); + tmp1 = AES_BLOCK_XOR(msg1, state[5]); + tmp1 = AES_BLOCK_XOR(tmp1, state[2]); tmp0 = AES_BLOCK_XOR(tmp0, AES_BLOCK_AND(state[2], state[3])); tmp1 = AES_BLOCK_XOR(tmp1, AES_BLOCK_AND(state[6], state[7])); AES_BLOCK_STORE(dst, tmp0); @@ -136,8 +136,8 @@ aegis128l_dec(unsigned char *const dst, const unsigned char *const src, aes_bloc msg1 = AES_BLOCK_LOAD(src + 16); msg0 = AES_BLOCK_XOR(msg0, state[6]); msg0 = AES_BLOCK_XOR(msg0, state[1]); - msg1 = AES_BLOCK_XOR(msg1, state[2]); msg1 = AES_BLOCK_XOR(msg1, state[5]); + msg1 = AES_BLOCK_XOR(msg1, state[2]); msg0 = AES_BLOCK_XOR(msg0, AES_BLOCK_AND(state[2], state[3])); msg1 = AES_BLOCK_XOR(msg1, AES_BLOCK_AND(state[6], state[7])); AES_BLOCK_STORE(dst, msg0); diff --git a/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c b/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c index f8dfe46e..45fa7d42 100644 --- a/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c +++ b/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c @@ -62,10 +62,10 @@ aegis256_init(const unsigned char *key, const unsigned char *nonce, aes_block_t aes_block_t kxn1, kxn2; int i; - k1 = AES_BLOCK_LOAD((const aes_block_t *) (const void *) &key[0]); - k2 = AES_BLOCK_LOAD((const aes_block_t *) (const void *) &key[16]); - kxn1 = AES_BLOCK_XOR(k1, AES_BLOCK_LOAD((aes_block_t *) (void *) &nonce[0])); - kxn2 = AES_BLOCK_XOR(k2, AES_BLOCK_LOAD((aes_block_t *) (void *) &nonce[16])); + k1 = AES_BLOCK_LOAD(&key[0]); + k2 = AES_BLOCK_LOAD(&key[16]); + kxn1 = AES_BLOCK_XOR(k1, AES_BLOCK_LOAD(&nonce[0])); + kxn2 = AES_BLOCK_XOR(k2, AES_BLOCK_LOAD(&nonce[16])); state[0] = kxn1; state[1] = kxn2; @@ -97,12 +97,10 @@ aegis256_mac(unsigned char *mac, unsigned long long adlen, unsigned long long ml } tmp = AES_BLOCK_XOR(state[5], state[4]); - tmp = AES_BLOCK_XOR(tmp, state[3]); - tmp = AES_BLOCK_XOR(tmp, state[2]); - tmp = AES_BLOCK_XOR(tmp, state[1]); - tmp = AES_BLOCK_XOR(tmp, state[0]); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[3], state[2])); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[1], state[0])); - AES_BLOCK_STORE((aes_block_t *) (void *) mac, tmp); + AES_BLOCK_STORE(mac, tmp); } static inline void @@ -120,12 +118,12 @@ aegis256_enc(unsigned char *const dst, const unsigned char *const src, aes_block aes_block_t msg; aes_block_t tmp; - msg = AES_BLOCK_LOAD((const aes_block_t *) (const void *) src); + msg = AES_BLOCK_LOAD(src); tmp = AES_BLOCK_XOR(msg, state[5]); tmp = AES_BLOCK_XOR(tmp, state[4]); tmp = AES_BLOCK_XOR(tmp, state[1]); tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_AND(state[2], state[3])); - AES_BLOCK_STORE((aes_block_t *) (void *) dst, tmp); + AES_BLOCK_STORE(dst, tmp); aegis256_update(state, msg); } @@ -135,12 +133,12 @@ aegis256_dec(unsigned char *const dst, const unsigned char *const src, aes_block { aes_block_t msg; - msg = AES_BLOCK_LOAD((const aes_block_t *) (const void *) src); + msg = AES_BLOCK_LOAD(src); msg = AES_BLOCK_XOR(msg, state[5]); msg = AES_BLOCK_XOR(msg, state[4]); msg = AES_BLOCK_XOR(msg, state[1]); msg = AES_BLOCK_XOR(msg, AES_BLOCK_AND(state[2], state[3])); - AES_BLOCK_STORE((aes_block_t *) (void *) dst, msg); + AES_BLOCK_STORE(dst, msg); aegis256_update(state, msg); } @@ -231,8 +229,7 @@ aegis256_decrypt_detached(unsigned char *m, unsigned char *nsec, const unsigned memcpy(m + i, dst, mlen & 0xf); } memset(dst, 0, mlen & 0xf); - state[0] = - AES_BLOCK_XOR(state[0], AES_BLOCK_LOAD((const aes_block_t *) (const void *) dst)); + state[0] = AES_BLOCK_XOR(state[0], AES_BLOCK_LOAD(dst)); } aegis256_mac(computed_mac, adlen, mlen, state); diff --git a/src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c b/src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c index 15cdb992..84e5a992 100644 --- a/src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c +++ b/src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c @@ -92,10 +92,8 @@ aegis256_mac(unsigned char *mac, unsigned long long adlen, unsigned long long ml } tmp = AES_BLOCK_XOR(state[5], state[4]); - tmp = AES_BLOCK_XOR(tmp, state[3]); - tmp = AES_BLOCK_XOR(tmp, state[2]); - tmp = AES_BLOCK_XOR(tmp, state[1]); - tmp = AES_BLOCK_XOR(tmp, state[0]); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[3], state[2])); + tmp = AES_BLOCK_XOR(tmp, AES_BLOCK_XOR(state[1], state[0])); AES_BLOCK_STORE(mac, tmp); }