pq_crypto-seal 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +66 -0
- data/CHANGELOG.md +44 -0
- data/FORMAT.md +139 -0
- data/GET_STARTED.md +30 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +215 -0
- data/RELEASING.md +34 -0
- data/Rakefile +19 -0
- data/SECURITY.md +85 -0
- data/VENDORING.md +14 -0
- data/ext/pq_crypto_seal/aegis_unused_stubs.c +20 -0
- data/ext/pq_crypto_seal/extconf.rb +296 -0
- data/ext/pq_crypto_seal/pq_crypto_seal.c +390 -0
- data/ext/pq_crypto_seal/vendor/libaegis/LICENSE +21 -0
- data/ext/pq_crypto_seal/vendor/libaegis/TREE_SHA256 +1 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l.c +246 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_aesni.c +73 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_aesni.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_altivec.c +70 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_altivec.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_common.h +691 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_neon_aes.c +77 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_neon_aes.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_neon_sha3.c +86 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_neon_sha3.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_soft.c +63 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/aegis128l_soft.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128l/implementations.h +40 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2.c +247 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_aesni.c +108 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_aesni.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_altivec.c +103 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_altivec.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_avx2.c +79 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_avx2.h +11 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_common.h +795 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_neon_aes.c +111 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_neon_aes.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_soft.c +96 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/aegis128x2_soft.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x2/implementations.h +40 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4.c +252 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_aesni.c +117 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_aesni.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_altivec.c +111 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_altivec.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_avx2.c +112 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_avx2.h +11 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_avx512.c +85 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_avx512.h +11 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_common.h +808 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_neon_aes.c +119 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_neon_aes.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_soft.c +104 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/aegis128x4_soft.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis128x4/implementations.h +41 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256.c +240 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_aesni.c +68 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_aesni.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_altivec.c +68 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_altivec.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_common.h +673 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_neon_aes.c +75 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_neon_aes.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_soft.c +58 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/aegis256_soft.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256/implementations.h +39 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2.c +247 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_aesni.c +103 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_aesni.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_altivec.c +101 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_altivec.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_avx2.c +74 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_avx2.h +11 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_common.h +790 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_neon_aes.c +109 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_neon_aes.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_soft.c +91 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/aegis256x2_soft.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x2/implementations.h +41 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4.c +252 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_aesni.c +112 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_aesni.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_altivec.c +109 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_altivec.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_avx2.c +107 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_avx2.h +11 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_avx512.c +79 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_avx512.h +11 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_common.h +805 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_neon_aes.c +117 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_neon_aes.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_soft.c +99 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/aegis256x4_soft.h +9 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/aegis256x4/implementations.h +42 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/common.c +81 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/common.h +144 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/cpu.c +378 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/cpu.h +34 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/keccak.c +187 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/keccak.h +13 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/softaes.c +338 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/common/softaes.h +69 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis.h +77 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis128l.h +311 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis128x2.h +313 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis128x4.h +313 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis256.h +311 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis256x2.h +313 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis256x4.h +313 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/include/aegis_raf.h +580 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf.c +87 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_aegis128l.c +20 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_aegis128x2.c +20 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_aegis128x4.c +20 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_aegis256.c +20 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_aegis256x2.c +20 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_aegis256x4.c +20 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_internal.h +152 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_merkle.c +268 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_merkle.h +165 -0
- data/ext/pq_crypto_seal/vendor/libaegis/src/raf/raf_variant.h +1119 -0
- data/fuzz/decrypt_fuzz.rb +119 -0
- data/lib/pq_crypto/seal/binary.rb +62 -0
- data/lib/pq_crypto/seal/core.rb +398 -0
- data/lib/pq_crypto/seal/errors.rb +15 -0
- data/lib/pq_crypto/seal/format.rb +275 -0
- data/lib/pq_crypto/seal/io.rb +336 -0
- data/lib/pq_crypto/seal/native.rb +13 -0
- data/lib/pq_crypto/seal/padding.rb +47 -0
- data/lib/pq_crypto/seal/version.rb +6 -0
- data/lib/pq_crypto/seal.rb +32 -0
- data/pq_crypto-seal.gemspec +37 -0
- data/script/vendor_libs.rb +79 -0
- data/test/aegis_vectors_test.rb +54 -0
- data/test/golden_vectors_test.rb +183 -0
- data/test/io_test.rb +125 -0
- data/test/native_test.rb +36 -0
- data/test/seal_test.rb +238 -0
- data/test/test_helper.rb +6 -0
- metadata +244 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#if defined(__ALTIVEC__) && defined(__CRYPTO__)
|
|
2
|
+
|
|
3
|
+
# include <stddef.h>
|
|
4
|
+
# include <stdint.h>
|
|
5
|
+
|
|
6
|
+
# include "../common/common.h"
|
|
7
|
+
# include "aegis128x4.h"
|
|
8
|
+
# include "aegis128x4_altivec.h"
|
|
9
|
+
|
|
10
|
+
# include <altivec.h>
|
|
11
|
+
|
|
12
|
+
# ifdef __clang__
|
|
13
|
+
# pragma clang attribute push(__attribute__((target("altivec,crypto"))), apply_to = function)
|
|
14
|
+
# elif defined(__GNUC__)
|
|
15
|
+
# pragma GCC target("altivec,crypto")
|
|
16
|
+
# endif
|
|
17
|
+
|
|
18
|
+
# define AES_BLOCK_LENGTH 64
|
|
19
|
+
|
|
20
|
+
typedef struct {
|
|
21
|
+
vector unsigned char b0;
|
|
22
|
+
vector unsigned char b1;
|
|
23
|
+
vector unsigned char b2;
|
|
24
|
+
vector unsigned char b3;
|
|
25
|
+
} aes_block_t;
|
|
26
|
+
|
|
27
|
+
static inline aes_block_t
|
|
28
|
+
AES_BLOCK_XOR(const aes_block_t a, const aes_block_t b)
|
|
29
|
+
{
|
|
30
|
+
return (aes_block_t) { vec_xor(a.b0, b.b0), vec_xor(a.b1, b.b1), vec_xor(a.b2, b.b2),
|
|
31
|
+
vec_xor(a.b3, b.b3) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static inline aes_block_t
|
|
35
|
+
AES_BLOCK_AND(const aes_block_t a, const aes_block_t b)
|
|
36
|
+
{
|
|
37
|
+
return (aes_block_t) { vec_and(a.b0, b.b0), vec_and(a.b1, b.b1), vec_and(a.b2, b.b2),
|
|
38
|
+
vec_and(a.b3, b.b3) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static inline aes_block_t
|
|
42
|
+
AES_BLOCK_LOAD(const uint8_t *a)
|
|
43
|
+
{
|
|
44
|
+
return (aes_block_t) { vec_xl_be(0, a), vec_xl_be(0, a + 16), vec_xl_be(0, a + 32),
|
|
45
|
+
vec_xl_be(0, a + 48) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static inline aes_block_t
|
|
49
|
+
AES_BLOCK_LOAD_64x2(uint64_t a, uint64_t b)
|
|
50
|
+
{
|
|
51
|
+
const vector unsigned char t = ((vector unsigned char) vec_revb(
|
|
52
|
+
vec_insert(a, vec_promote((unsigned long long) (b), 1), 0)));
|
|
53
|
+
return (aes_block_t) { t, t, t, t };
|
|
54
|
+
}
|
|
55
|
+
static inline void
|
|
56
|
+
AES_BLOCK_STORE(uint8_t *a, const aes_block_t b)
|
|
57
|
+
{
|
|
58
|
+
vec_xst_be(b.b0, 0, a);
|
|
59
|
+
vec_xst_be(b.b1, 0, a + 16);
|
|
60
|
+
vec_xst_be(b.b2, 0, a + 32);
|
|
61
|
+
vec_xst_be(b.b3, 0, a + 48);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static inline aes_block_t
|
|
65
|
+
AES_ENC(const aes_block_t a, const aes_block_t b)
|
|
66
|
+
{
|
|
67
|
+
return (aes_block_t) { vec_cipher_be(a.b0, b.b0), vec_cipher_be(a.b1, b.b1),
|
|
68
|
+
vec_cipher_be(a.b2, b.b2), vec_cipher_be(a.b3, b.b3) };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static inline void
|
|
72
|
+
aegis128x4_update(aes_block_t *const state, const aes_block_t d1, const aes_block_t d2)
|
|
73
|
+
{
|
|
74
|
+
aes_block_t tmp;
|
|
75
|
+
|
|
76
|
+
tmp = state[7];
|
|
77
|
+
state[7] = AES_ENC(state[6], state[7]);
|
|
78
|
+
state[6] = AES_ENC(state[5], state[6]);
|
|
79
|
+
state[5] = AES_ENC(state[4], state[5]);
|
|
80
|
+
state[4] = AES_BLOCK_XOR(AES_ENC(state[3], state[4]), d2);
|
|
81
|
+
state[3] = AES_ENC(state[2], state[3]);
|
|
82
|
+
state[2] = AES_ENC(state[1], state[2]);
|
|
83
|
+
state[1] = AES_ENC(state[0], state[1]);
|
|
84
|
+
state[0] = AES_BLOCK_XOR(AES_ENC(tmp, state[0]), d1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# include "aegis128x4_common.h"
|
|
88
|
+
|
|
89
|
+
struct aegis128x4_implementation aegis128x4_altivec_implementation = {
|
|
90
|
+
.encrypt_detached = encrypt_detached,
|
|
91
|
+
.decrypt_detached = decrypt_detached,
|
|
92
|
+
.encrypt_unauthenticated = encrypt_unauthenticated,
|
|
93
|
+
.decrypt_unauthenticated = decrypt_unauthenticated,
|
|
94
|
+
.stream = stream,
|
|
95
|
+
.state_init = state_init,
|
|
96
|
+
.state_encrypt_update = state_encrypt_update,
|
|
97
|
+
.state_encrypt_final = state_encrypt_final,
|
|
98
|
+
.state_decrypt_update = state_decrypt_update,
|
|
99
|
+
.state_decrypt_final = state_decrypt_final,
|
|
100
|
+
.state_mac_init = state_mac_init,
|
|
101
|
+
.state_mac_update = state_mac_update,
|
|
102
|
+
.state_mac_final = state_mac_final,
|
|
103
|
+
.state_mac_reset = state_mac_reset,
|
|
104
|
+
.state_mac_clone = state_mac_clone,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
# ifdef __clang__
|
|
108
|
+
# pragma clang attribute pop
|
|
109
|
+
# endif
|
|
110
|
+
|
|
111
|
+
#endif
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64)
|
|
2
|
+
|
|
3
|
+
# include <stddef.h>
|
|
4
|
+
# include <stdint.h>
|
|
5
|
+
|
|
6
|
+
# include "../common/common.h"
|
|
7
|
+
# include "aegis128x4.h"
|
|
8
|
+
# include "aegis128x4_avx2.h"
|
|
9
|
+
|
|
10
|
+
# ifdef HAVE_VAESINTRIN_H
|
|
11
|
+
|
|
12
|
+
# ifdef __clang__
|
|
13
|
+
# pragma clang attribute push(__attribute__((target("aes,vaes,avx2"))), \
|
|
14
|
+
apply_to = function)
|
|
15
|
+
# elif defined(__GNUC__)
|
|
16
|
+
# pragma GCC target("aes,vaes,avx2")
|
|
17
|
+
# endif
|
|
18
|
+
|
|
19
|
+
# include <immintrin.h>
|
|
20
|
+
|
|
21
|
+
# define AES_BLOCK_LENGTH 64
|
|
22
|
+
|
|
23
|
+
typedef struct {
|
|
24
|
+
__m256i b0;
|
|
25
|
+
__m256i b1;
|
|
26
|
+
} aes_block_t;
|
|
27
|
+
|
|
28
|
+
static inline aes_block_t
|
|
29
|
+
AES_BLOCK_XOR(const aes_block_t a, const aes_block_t b)
|
|
30
|
+
{
|
|
31
|
+
return (aes_block_t) { _mm256_xor_si256(a.b0, b.b0), _mm256_xor_si256(a.b1, b.b1) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static inline aes_block_t
|
|
35
|
+
AES_BLOCK_AND(const aes_block_t a, const aes_block_t b)
|
|
36
|
+
{
|
|
37
|
+
return (aes_block_t) { _mm256_and_si256(a.b0, b.b0), _mm256_and_si256(a.b1, b.b1) };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static inline aes_block_t
|
|
41
|
+
AES_BLOCK_LOAD(const uint8_t *a)
|
|
42
|
+
{
|
|
43
|
+
return (aes_block_t) { _mm256_loadu_si256((const __m256i *) (const void *) a),
|
|
44
|
+
_mm256_loadu_si256((const __m256i *) (const void *) (a + 32)) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static inline aes_block_t
|
|
48
|
+
AES_BLOCK_LOAD_64x2(uint64_t a, uint64_t b)
|
|
49
|
+
{
|
|
50
|
+
const __m256i t = _mm256_broadcastsi128_si256(_mm_set_epi64x((long long) a, (long long) b));
|
|
51
|
+
return (aes_block_t) { t, t };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static inline void
|
|
55
|
+
AES_BLOCK_STORE(uint8_t *a, const aes_block_t b)
|
|
56
|
+
{
|
|
57
|
+
_mm256_storeu_si256((__m256i *) (void *) a, b.b0);
|
|
58
|
+
_mm256_storeu_si256((__m256i *) (void *) (a + 32), b.b1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static inline aes_block_t
|
|
62
|
+
AES_ENC(const aes_block_t a, const aes_block_t b)
|
|
63
|
+
{
|
|
64
|
+
return (aes_block_t) { _mm256_aesenc_epi128(a.b0, b.b0), _mm256_aesenc_epi128(a.b1, b.b1) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static inline void
|
|
68
|
+
aegis128x4_update(aes_block_t *const state, const aes_block_t d1, const aes_block_t d2)
|
|
69
|
+
{
|
|
70
|
+
aes_block_t tmp;
|
|
71
|
+
|
|
72
|
+
tmp = state[7];
|
|
73
|
+
state[7] = AES_ENC(state[6], state[7]);
|
|
74
|
+
state[6] = AES_ENC(state[5], state[6]);
|
|
75
|
+
state[5] = AES_ENC(state[4], state[5]);
|
|
76
|
+
state[4] = AES_ENC(state[3], state[4]);
|
|
77
|
+
state[3] = AES_ENC(state[2], state[3]);
|
|
78
|
+
state[2] = AES_ENC(state[1], state[2]);
|
|
79
|
+
state[1] = AES_ENC(state[0], state[1]);
|
|
80
|
+
state[0] = AES_ENC(tmp, state[0]);
|
|
81
|
+
|
|
82
|
+
state[0] = AES_BLOCK_XOR(state[0], d1);
|
|
83
|
+
state[4] = AES_BLOCK_XOR(state[4], d2);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# include "aegis128x4_common.h"
|
|
87
|
+
|
|
88
|
+
struct aegis128x4_implementation aegis128x4_avx2_implementation = {
|
|
89
|
+
.encrypt_detached = encrypt_detached,
|
|
90
|
+
.decrypt_detached = decrypt_detached,
|
|
91
|
+
.encrypt_unauthenticated = encrypt_unauthenticated,
|
|
92
|
+
.decrypt_unauthenticated = decrypt_unauthenticated,
|
|
93
|
+
.stream = stream,
|
|
94
|
+
.state_init = state_init,
|
|
95
|
+
.state_encrypt_update = state_encrypt_update,
|
|
96
|
+
.state_encrypt_final = state_encrypt_final,
|
|
97
|
+
.state_decrypt_update = state_decrypt_update,
|
|
98
|
+
.state_decrypt_final = state_decrypt_final,
|
|
99
|
+
.state_mac_init = state_mac_init,
|
|
100
|
+
.state_mac_update = state_mac_update,
|
|
101
|
+
.state_mac_final = state_mac_final,
|
|
102
|
+
.state_mac_reset = state_mac_reset,
|
|
103
|
+
.state_mac_clone = state_mac_clone,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
# ifdef __clang__
|
|
107
|
+
# pragma clang attribute pop
|
|
108
|
+
# endif
|
|
109
|
+
|
|
110
|
+
# endif
|
|
111
|
+
|
|
112
|
+
#endif
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64)
|
|
2
|
+
|
|
3
|
+
# include <stddef.h>
|
|
4
|
+
# include <stdint.h>
|
|
5
|
+
|
|
6
|
+
# include "../common/common.h"
|
|
7
|
+
# include "aegis128x4.h"
|
|
8
|
+
# include "aegis128x4_avx512.h"
|
|
9
|
+
|
|
10
|
+
# ifdef HAVE_VAESINTRIN_H
|
|
11
|
+
|
|
12
|
+
# ifdef __clang__
|
|
13
|
+
# if __clang_major__ >= 18 && __clang_major__ < 22
|
|
14
|
+
# pragma clang attribute push(__attribute__((target("aes,vaes,avx512f,evex512"))), \
|
|
15
|
+
apply_to = function)
|
|
16
|
+
# else
|
|
17
|
+
# pragma clang attribute push(__attribute__((target("aes,vaes,avx512f"))), \
|
|
18
|
+
apply_to = function)
|
|
19
|
+
# endif
|
|
20
|
+
# elif defined(__GNUC__)
|
|
21
|
+
# pragma GCC target("aes,vaes,avx512f")
|
|
22
|
+
# endif
|
|
23
|
+
|
|
24
|
+
# include <immintrin.h>
|
|
25
|
+
|
|
26
|
+
# define AES_BLOCK_LENGTH 64
|
|
27
|
+
|
|
28
|
+
typedef __m512i aes_block_t;
|
|
29
|
+
|
|
30
|
+
# define AES_BLOCK_XOR(A, B) _mm512_xor_si512((A), (B))
|
|
31
|
+
# define AES_BLOCK_XOR3(A, B, C) _mm512_ternarylogic_epi64((A), (B), (C), 0x96)
|
|
32
|
+
# define AES_BLOCK_AND(A, B) _mm512_and_si512((A), (B))
|
|
33
|
+
# define AES_BLOCK_LOAD128_BROADCAST(A) \
|
|
34
|
+
_mm512_broadcast_i32x4(_mm_loadu_si128((const void *) (A)))
|
|
35
|
+
# define AES_BLOCK_LOAD(A) _mm512_loadu_si512((const aes_block_t *) (const void *) (A))
|
|
36
|
+
# define AES_BLOCK_LOAD_64x2(A, B) _mm512_broadcast_i32x4(_mm_set_epi64x((A), (B)))
|
|
37
|
+
# define AES_BLOCK_STORE(A, B) _mm512_storeu_si512((aes_block_t *) (void *) (A), (B))
|
|
38
|
+
# define AES_ENC(A, B) _mm512_aesenc_epi128((A), (B))
|
|
39
|
+
|
|
40
|
+
static inline void
|
|
41
|
+
aegis128x4_update(aes_block_t *const state, const aes_block_t d1, const aes_block_t d2)
|
|
42
|
+
{
|
|
43
|
+
aes_block_t tmp;
|
|
44
|
+
|
|
45
|
+
tmp = state[7];
|
|
46
|
+
state[7] = AES_ENC(state[6], state[7]);
|
|
47
|
+
state[6] = AES_ENC(state[5], state[6]);
|
|
48
|
+
state[5] = AES_ENC(state[4], state[5]);
|
|
49
|
+
state[4] = AES_ENC(state[3], state[4]);
|
|
50
|
+
state[3] = AES_ENC(state[2], state[3]);
|
|
51
|
+
state[2] = AES_ENC(state[1], state[2]);
|
|
52
|
+
state[1] = AES_ENC(state[0], state[1]);
|
|
53
|
+
state[0] = AES_ENC(tmp, state[0]);
|
|
54
|
+
|
|
55
|
+
state[0] = AES_BLOCK_XOR(state[0], d1);
|
|
56
|
+
state[4] = AES_BLOCK_XOR(state[4], d2);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# include "aegis128x4_common.h"
|
|
60
|
+
|
|
61
|
+
struct aegis128x4_implementation aegis128x4_avx512_implementation = {
|
|
62
|
+
.encrypt_detached = encrypt_detached,
|
|
63
|
+
.decrypt_detached = decrypt_detached,
|
|
64
|
+
.encrypt_unauthenticated = encrypt_unauthenticated,
|
|
65
|
+
.decrypt_unauthenticated = decrypt_unauthenticated,
|
|
66
|
+
.stream = stream,
|
|
67
|
+
.state_init = state_init,
|
|
68
|
+
.state_encrypt_update = state_encrypt_update,
|
|
69
|
+
.state_encrypt_final = state_encrypt_final,
|
|
70
|
+
.state_decrypt_update = state_decrypt_update,
|
|
71
|
+
.state_decrypt_final = state_decrypt_final,
|
|
72
|
+
.state_mac_init = state_mac_init,
|
|
73
|
+
.state_mac_update = state_mac_update,
|
|
74
|
+
.state_mac_final = state_mac_final,
|
|
75
|
+
.state_mac_reset = state_mac_reset,
|
|
76
|
+
.state_mac_clone = state_mac_clone,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
# ifdef __clang__
|
|
80
|
+
# pragma clang attribute pop
|
|
81
|
+
# endif
|
|
82
|
+
|
|
83
|
+
# endif
|
|
84
|
+
|
|
85
|
+
#endif
|