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,580 @@
|
|
|
1
|
+
#ifndef aegis_raf_H
|
|
2
|
+
#define aegis_raf_H
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
#ifndef CRYPTO_ALIGN
|
|
8
|
+
# if defined(__INTEL_COMPILER) || defined(_MSC_VER)
|
|
9
|
+
# define CRYPTO_ALIGN(x) __declspec(align(x))
|
|
10
|
+
# else
|
|
11
|
+
# define CRYPTO_ALIGN(x) __attribute__((aligned(x)))
|
|
12
|
+
# endif
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#ifndef AEGIS_WARN_UNUSED_RESULT
|
|
16
|
+
# if defined(__GNUC__) || defined(__clang__)
|
|
17
|
+
# define AEGIS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
|
18
|
+
# elif defined(_MSC_VER)
|
|
19
|
+
# define AEGIS_WARN_UNUSED_RESULT _Check_return_
|
|
20
|
+
# else
|
|
21
|
+
# define AEGIS_WARN_UNUSED_RESULT
|
|
22
|
+
# endif
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#define AEGIS_RAF_ALG_128L 1
|
|
30
|
+
#define AEGIS_RAF_ALG_128X2 2
|
|
31
|
+
#define AEGIS_RAF_ALG_128X4 3
|
|
32
|
+
#define AEGIS_RAF_ALG_256 4
|
|
33
|
+
#define AEGIS_RAF_ALG_256X2 5
|
|
34
|
+
#define AEGIS_RAF_ALG_256X4 6
|
|
35
|
+
|
|
36
|
+
#define AEGIS_RAF_CREATE 0x01
|
|
37
|
+
#define AEGIS_RAF_TRUNCATE 0x02
|
|
38
|
+
|
|
39
|
+
#define AEGIS_RAF_CHUNK_MIN 1024
|
|
40
|
+
#define AEGIS_RAF_CHUNK_MAX (1 << 20)
|
|
41
|
+
|
|
42
|
+
#define AEGIS_RAF_HEADER_SIZE 64
|
|
43
|
+
#define AEGIS_RAF_FILE_ID_BYTES 24
|
|
44
|
+
#define AEGIS_RAF_TAG_BYTES 16
|
|
45
|
+
|
|
46
|
+
#define AEGIS_RAF_SCRATCH_ALIGN 64
|
|
47
|
+
#define AEGIS_RAF_ALIGN_UP(x, a) (((x) + ((a) - 1)) & ~((size_t) (a) - 1))
|
|
48
|
+
#define AEGIS_RAF_MERKLE_HASH_MIN 8
|
|
49
|
+
#define AEGIS_RAF_MERKLE_HASH_MAX 64
|
|
50
|
+
#define AEGIS_RAF_COMMITMENT_CONTEXT_BYTES 32
|
|
51
|
+
|
|
52
|
+
#define AEGIS128L_RAF_NPUBBYTES 16
|
|
53
|
+
#define AEGIS128X2_RAF_NPUBBYTES 16
|
|
54
|
+
#define AEGIS128X4_RAF_NPUBBYTES 16
|
|
55
|
+
#define AEGIS256_RAF_NPUBBYTES 32
|
|
56
|
+
#define AEGIS256X2_RAF_NPUBBYTES 32
|
|
57
|
+
#define AEGIS256X4_RAF_NPUBBYTES 32
|
|
58
|
+
|
|
59
|
+
#define AEGIS128L_RAF_RECORD_SIZE(chunk_size) \
|
|
60
|
+
((size_t) (AEGIS128L_RAF_NPUBBYTES) + (size_t) (chunk_size) + (size_t) (AEGIS_RAF_TAG_BYTES))
|
|
61
|
+
|
|
62
|
+
#define AEGIS128X2_RAF_RECORD_SIZE(chunk_size) \
|
|
63
|
+
((size_t) (AEGIS128X2_RAF_NPUBBYTES) + (size_t) (chunk_size) + (size_t) (AEGIS_RAF_TAG_BYTES))
|
|
64
|
+
|
|
65
|
+
#define AEGIS128X4_RAF_RECORD_SIZE(chunk_size) \
|
|
66
|
+
((size_t) (AEGIS128X4_RAF_NPUBBYTES) + (size_t) (chunk_size) + (size_t) (AEGIS_RAF_TAG_BYTES))
|
|
67
|
+
|
|
68
|
+
#define AEGIS256_RAF_RECORD_SIZE(chunk_size) \
|
|
69
|
+
((size_t) (AEGIS256_RAF_NPUBBYTES) + (size_t) (chunk_size) + (size_t) (AEGIS_RAF_TAG_BYTES))
|
|
70
|
+
|
|
71
|
+
#define AEGIS256X2_RAF_RECORD_SIZE(chunk_size) \
|
|
72
|
+
((size_t) (AEGIS256X2_RAF_NPUBBYTES) + (size_t) (chunk_size) + (size_t) (AEGIS_RAF_TAG_BYTES))
|
|
73
|
+
|
|
74
|
+
#define AEGIS256X4_RAF_RECORD_SIZE(chunk_size) \
|
|
75
|
+
((size_t) (AEGIS256X4_RAF_NPUBBYTES) + (size_t) (chunk_size) + (size_t) (AEGIS_RAF_TAG_BYTES))
|
|
76
|
+
|
|
77
|
+
#define AEGIS128L_RAF_SCRATCH_SIZE(chunk_size) \
|
|
78
|
+
(AEGIS_RAF_ALIGN_UP(AEGIS128L_RAF_RECORD_SIZE(chunk_size), AEGIS_RAF_SCRATCH_ALIGN) + \
|
|
79
|
+
AEGIS_RAF_ALIGN_UP((size_t) (chunk_size), AEGIS_RAF_SCRATCH_ALIGN))
|
|
80
|
+
|
|
81
|
+
#define AEGIS128X2_RAF_SCRATCH_SIZE(chunk_size) \
|
|
82
|
+
(AEGIS_RAF_ALIGN_UP(AEGIS128X2_RAF_RECORD_SIZE(chunk_size), AEGIS_RAF_SCRATCH_ALIGN) + \
|
|
83
|
+
AEGIS_RAF_ALIGN_UP((size_t) (chunk_size), AEGIS_RAF_SCRATCH_ALIGN))
|
|
84
|
+
|
|
85
|
+
#define AEGIS128X4_RAF_SCRATCH_SIZE(chunk_size) \
|
|
86
|
+
(AEGIS_RAF_ALIGN_UP(AEGIS128X4_RAF_RECORD_SIZE(chunk_size), AEGIS_RAF_SCRATCH_ALIGN) + \
|
|
87
|
+
AEGIS_RAF_ALIGN_UP((size_t) (chunk_size), AEGIS_RAF_SCRATCH_ALIGN))
|
|
88
|
+
|
|
89
|
+
#define AEGIS256_RAF_SCRATCH_SIZE(chunk_size) \
|
|
90
|
+
(AEGIS_RAF_ALIGN_UP(AEGIS256_RAF_RECORD_SIZE(chunk_size), AEGIS_RAF_SCRATCH_ALIGN) + \
|
|
91
|
+
AEGIS_RAF_ALIGN_UP((size_t) (chunk_size), AEGIS_RAF_SCRATCH_ALIGN))
|
|
92
|
+
|
|
93
|
+
#define AEGIS256X2_RAF_SCRATCH_SIZE(chunk_size) \
|
|
94
|
+
(AEGIS_RAF_ALIGN_UP(AEGIS256X2_RAF_RECORD_SIZE(chunk_size), AEGIS_RAF_SCRATCH_ALIGN) + \
|
|
95
|
+
AEGIS_RAF_ALIGN_UP((size_t) (chunk_size), AEGIS_RAF_SCRATCH_ALIGN))
|
|
96
|
+
|
|
97
|
+
#define AEGIS256X4_RAF_SCRATCH_SIZE(chunk_size) \
|
|
98
|
+
(AEGIS_RAF_ALIGN_UP(AEGIS256X4_RAF_RECORD_SIZE(chunk_size), AEGIS_RAF_SCRATCH_ALIGN) + \
|
|
99
|
+
AEGIS_RAF_ALIGN_UP((size_t) (chunk_size), AEGIS_RAF_SCRATCH_ALIGN))
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* Scratch buffer for RAF operations. Must be allocated by the caller and
|
|
103
|
+
* passed to create/open. Use the *_raf_scratch_size() macros or functions
|
|
104
|
+
* to determine the required size for a given chunk_size.
|
|
105
|
+
*/
|
|
106
|
+
typedef struct aegis_raf_scratch {
|
|
107
|
+
uint8_t *buf;
|
|
108
|
+
size_t len;
|
|
109
|
+
} aegis_raf_scratch;
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
* I/O callbacks for backing store operations. All callbacks receive the
|
|
113
|
+
* user pointer and return 0 on success, -1 on error (with errno set).
|
|
114
|
+
*
|
|
115
|
+
* read_at: Read exactly len bytes at offset. Returns -1 if fewer available.
|
|
116
|
+
* write_at: Write exactly len bytes at offset.
|
|
117
|
+
* get_size: Get current backing store size in bytes.
|
|
118
|
+
* set_size: Resize backing store (truncate or extend).
|
|
119
|
+
* sync: Flush writes to durable storage (may be NULL).
|
|
120
|
+
*/
|
|
121
|
+
typedef struct aegis_raf_io {
|
|
122
|
+
void *user;
|
|
123
|
+
int (*read_at)(void *user, uint8_t *buf, size_t len, uint64_t off);
|
|
124
|
+
int (*write_at)(void *user, const uint8_t *buf, size_t len, uint64_t off);
|
|
125
|
+
int (*get_size)(void *user, uint64_t *size);
|
|
126
|
+
int (*set_size)(void *user, uint64_t size);
|
|
127
|
+
int (*sync)(void *user);
|
|
128
|
+
} aegis_raf_io;
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* Random number generator callback for nonce generation.
|
|
132
|
+
* Must provide cryptographically secure random bytes.
|
|
133
|
+
* Returns 0 on success, -1 on error.
|
|
134
|
+
*/
|
|
135
|
+
typedef struct aegis_raf_rng {
|
|
136
|
+
void *user;
|
|
137
|
+
int (*random)(void *user, uint8_t *out, size_t len);
|
|
138
|
+
} aegis_raf_rng;
|
|
139
|
+
|
|
140
|
+
/*
|
|
141
|
+
* Optional Merkle tree configuration for whole-file commitment tracking.
|
|
142
|
+
*
|
|
143
|
+
* Individual chunks are already authenticated by their AEAD tags. When
|
|
144
|
+
* provided, the RAF context will automatically update a Merkle tree
|
|
145
|
+
* buffer on chunk writes, maintaining a single root hash that represents
|
|
146
|
+
* the current plaintext content of the entire file.
|
|
147
|
+
*
|
|
148
|
+
* user: User-defined pointer passed to hash callbacks.
|
|
149
|
+
* buf: Caller-allocated buffer for the Merkle tree. Use
|
|
150
|
+
* aegis_raf_merkle_buffer_size() to determine required size.
|
|
151
|
+
* len: Size of the buffer in bytes.
|
|
152
|
+
* hash_len: Size of each hash in bytes (e.g., 32 for SHA-256).
|
|
153
|
+
* Must be between AEGIS_RAF_MERKLE_HASH_MIN and
|
|
154
|
+
* AEGIS_RAF_MERKLE_HASH_MAX.
|
|
155
|
+
* max_chunks: Maximum number of chunks (leaves) the tree can hold.
|
|
156
|
+
* Writes exceeding this limit will fail with EOVERFLOW.
|
|
157
|
+
* Merkle initialization work is O(max_chunks), so choose a
|
|
158
|
+
* realistic upper bound instead of an excessively large ceiling.
|
|
159
|
+
*
|
|
160
|
+
* Hash callbacks must return 0 on success, -1 on error.
|
|
161
|
+
*
|
|
162
|
+
* hash_leaf: Hash a chunk. Called with the plaintext chunk data, its length
|
|
163
|
+
* (may be less than chunk_size for the final chunk), and the
|
|
164
|
+
* chunk index. The hash must depend only on these three inputs.
|
|
165
|
+
*
|
|
166
|
+
* hash_parent: Hash two child nodes to produce a parent. Called with left and
|
|
167
|
+
* right child hashes, the tree level (0 = leaves), and the node
|
|
168
|
+
* index within that level.
|
|
169
|
+
*
|
|
170
|
+
* hash_empty: Produce a hash for an empty/missing node. Called for leaves
|
|
171
|
+
* beyond EOF and for missing siblings when a level has an odd
|
|
172
|
+
* number of nodes. Level and node index are provided for domain
|
|
173
|
+
* separation.
|
|
174
|
+
*
|
|
175
|
+
* hash_commitment: Produce the root commitment by hashing the structural tree
|
|
176
|
+
* root together with the file context and file size. ctx/ctx_len
|
|
177
|
+
* provide file context for domain separation. The per-variant
|
|
178
|
+
* *_raf_merkle_commitment() API passes ctx pointing to
|
|
179
|
+
* AEGIS_RAF_COMMITMENT_CONTEXT_BYTES bytes encoding version,
|
|
180
|
+
* alg_id, chunk_size, and file_id. The callback should include
|
|
181
|
+
* all of ctx, file_size, and structural_root in its hash for
|
|
182
|
+
* full domain separation. The structural_root pointer is exactly
|
|
183
|
+
* hash_len bytes. The callback must write exactly hash_len bytes
|
|
184
|
+
* to out.
|
|
185
|
+
*
|
|
186
|
+
* Thread Safety: Merkle buffers are not internally synchronized. Callers must
|
|
187
|
+
* serialize writes that share a Merkle buffer, or provide external locking.
|
|
188
|
+
*/
|
|
189
|
+
typedef struct aegis_raf_merkle_config {
|
|
190
|
+
int (*hash_leaf)(void *user, uint8_t *out, size_t out_len, const uint8_t *chunk,
|
|
191
|
+
size_t chunk_len, uint64_t chunk_idx);
|
|
192
|
+
|
|
193
|
+
int (*hash_parent)(void *user, uint8_t *out, size_t out_len, const uint8_t *left,
|
|
194
|
+
const uint8_t *right, uint32_t level, uint64_t node_idx);
|
|
195
|
+
|
|
196
|
+
int (*hash_empty)(void *user, uint8_t *out, size_t out_len, uint32_t level, uint64_t node_idx);
|
|
197
|
+
|
|
198
|
+
int (*hash_commitment)(void *user, uint8_t *out, size_t out_len, const uint8_t *structural_root,
|
|
199
|
+
const uint8_t *ctx, size_t ctx_len, uint64_t file_size);
|
|
200
|
+
|
|
201
|
+
void *user;
|
|
202
|
+
uint8_t *buf;
|
|
203
|
+
size_t len;
|
|
204
|
+
uint64_t max_chunks;
|
|
205
|
+
uint32_t hash_len;
|
|
206
|
+
} aegis_raf_merkle_config;
|
|
207
|
+
|
|
208
|
+
/*
|
|
209
|
+
* Configuration for RAF create/open operations.
|
|
210
|
+
*
|
|
211
|
+
* scratch: Caller-allocated scratch buffer (required).
|
|
212
|
+
* chunk_size: Plaintext bytes per chunk (AEGIS_RAF_CHUNK_MIN to AEGIS_RAF_CHUNK_MAX).
|
|
213
|
+
* Ignored when opening existing files.
|
|
214
|
+
* flags: AEGIS_RAF_CREATE to create new files, AEGIS_RAF_TRUNCATE to
|
|
215
|
+
* overwrite existing files.
|
|
216
|
+
* merkle: Optional Merkle tree configuration. Set to NULL to disable.
|
|
217
|
+
*/
|
|
218
|
+
typedef struct aegis_raf_config {
|
|
219
|
+
const aegis_raf_scratch *scratch;
|
|
220
|
+
const aegis_raf_merkle_config *merkle;
|
|
221
|
+
uint32_t chunk_size;
|
|
222
|
+
uint8_t flags;
|
|
223
|
+
} aegis_raf_config;
|
|
224
|
+
|
|
225
|
+
/*
|
|
226
|
+
* File metadata returned by aegis_raf_probe().
|
|
227
|
+
*
|
|
228
|
+
* alg_id: Algorithm identifier (AEGIS_RAF_ALG_*).
|
|
229
|
+
* chunk_size: Plaintext bytes per chunk.
|
|
230
|
+
* file_size: Logical plaintext file size.
|
|
231
|
+
*/
|
|
232
|
+
typedef struct aegis_raf_info {
|
|
233
|
+
uint64_t file_size;
|
|
234
|
+
uint32_t chunk_size;
|
|
235
|
+
uint8_t alg_id;
|
|
236
|
+
} aegis_raf_info;
|
|
237
|
+
|
|
238
|
+
/* Returns minimum allowed chunk size (AEGIS_RAF_CHUNK_MIN). */
|
|
239
|
+
size_t aegis_raf_chunk_min(void);
|
|
240
|
+
|
|
241
|
+
/* Returns maximum allowed chunk size (AEGIS_RAF_CHUNK_MAX). */
|
|
242
|
+
size_t aegis_raf_chunk_max(void);
|
|
243
|
+
|
|
244
|
+
/* Returns RAF header size in bytes (AEGIS_RAF_HEADER_SIZE). */
|
|
245
|
+
size_t aegis_raf_header_size(void);
|
|
246
|
+
|
|
247
|
+
/* Returns required alignment for scratch buffers (AEGIS_RAF_SCRATCH_ALIGN). */
|
|
248
|
+
size_t aegis_raf_scratch_align(void);
|
|
249
|
+
|
|
250
|
+
/*
|
|
251
|
+
* Probe an encrypted file to determine its algorithm and parameters.
|
|
252
|
+
* Reads and parses the header without validating the MAC.
|
|
253
|
+
* Returns 0 on success, -1 on error (invalid header or I/O failure).
|
|
254
|
+
*/
|
|
255
|
+
int aegis_raf_probe(const aegis_raf_io *io, aegis_raf_info *info);
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Scratch buffer helpers.
|
|
259
|
+
*
|
|
260
|
+
* *_raf_scratch_size(): Returns required scratch buffer size for a given
|
|
261
|
+
* chunk_size. Use this to allocate the buffer.
|
|
262
|
+
*
|
|
263
|
+
* *_raf_scratch_validate(): Validates that a scratch buffer is large enough
|
|
264
|
+
* and properly aligned. Returns 0 if valid, -1 if not.
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
size_t aegis128l_raf_scratch_size(uint32_t chunk_size);
|
|
268
|
+
int aegis128l_raf_scratch_validate(const aegis_raf_scratch *scratch, uint32_t chunk_size);
|
|
269
|
+
|
|
270
|
+
size_t aegis128x2_raf_scratch_size(uint32_t chunk_size);
|
|
271
|
+
int aegis128x2_raf_scratch_validate(const aegis_raf_scratch *scratch, uint32_t chunk_size);
|
|
272
|
+
|
|
273
|
+
size_t aegis128x4_raf_scratch_size(uint32_t chunk_size);
|
|
274
|
+
int aegis128x4_raf_scratch_validate(const aegis_raf_scratch *scratch, uint32_t chunk_size);
|
|
275
|
+
|
|
276
|
+
size_t aegis256_raf_scratch_size(uint32_t chunk_size);
|
|
277
|
+
int aegis256_raf_scratch_validate(const aegis_raf_scratch *scratch, uint32_t chunk_size);
|
|
278
|
+
|
|
279
|
+
size_t aegis256x2_raf_scratch_size(uint32_t chunk_size);
|
|
280
|
+
int aegis256x2_raf_scratch_validate(const aegis_raf_scratch *scratch, uint32_t chunk_size);
|
|
281
|
+
|
|
282
|
+
size_t aegis256x4_raf_scratch_size(uint32_t chunk_size);
|
|
283
|
+
int aegis256x4_raf_scratch_validate(const aegis_raf_scratch *scratch, uint32_t chunk_size);
|
|
284
|
+
|
|
285
|
+
/*
|
|
286
|
+
* Merkle tree helpers.
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
/*
|
|
290
|
+
* Returns the required buffer size in bytes for a Merkle tree based on the
|
|
291
|
+
* max_chunks and hash_len fields in the config. The buf field may be NULL
|
|
292
|
+
* when calling this function (it's used to determine how much to allocate).
|
|
293
|
+
* Returns 0 if cfg is NULL, max_chunks is 0, or hash_len is 0.
|
|
294
|
+
*/
|
|
295
|
+
size_t aegis_raf_merkle_buffer_size(const aegis_raf_merkle_config *cfg);
|
|
296
|
+
|
|
297
|
+
/*
|
|
298
|
+
* Random-Access Encrypted File API
|
|
299
|
+
*
|
|
300
|
+
* Provides pread/pwrite-style access to encrypted files. Files are divided
|
|
301
|
+
* into fixed-size chunks, each independently encrypted with a fresh nonce.
|
|
302
|
+
* The API supports multiple AEGIS variants with identical calling conventions.
|
|
303
|
+
*
|
|
304
|
+
* The master_key size depends on the variant:
|
|
305
|
+
* - AEGIS-128L, AEGIS-128X2, AEGIS-128X4: 16 bytes
|
|
306
|
+
* - AEGIS-256, AEGIS-256X2, AEGIS-256X4: 32 bytes
|
|
307
|
+
*
|
|
308
|
+
* All functions return 0 on success and -1 on error with errno set.
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
/* Opaque context for AEGIS-128L RAF operations. */
|
|
312
|
+
typedef struct aegis128l_raf_ctx {
|
|
313
|
+
CRYPTO_ALIGN(32) uint8_t opaque[512];
|
|
314
|
+
} aegis128l_raf_ctx;
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
* Create a new encrypted file.
|
|
318
|
+
*
|
|
319
|
+
* Writes the header and initializes the context for subsequent I/O.
|
|
320
|
+
* Requires AEGIS_RAF_CREATE flag. Use AEGIS_RAF_TRUNCATE to overwrite
|
|
321
|
+
* existing files, otherwise returns -1 with errno=EEXIST.
|
|
322
|
+
*
|
|
323
|
+
* The master_key must be 16 bytes for AEGIS-128L.
|
|
324
|
+
*/
|
|
325
|
+
int aegis128l_raf_create(aegis128l_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
326
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
327
|
+
|
|
328
|
+
/*
|
|
329
|
+
* Open an existing encrypted file.
|
|
330
|
+
*
|
|
331
|
+
* Reads and validates the header, verifying the MAC with the provided key.
|
|
332
|
+
* Returns -1 with errno=ENOENT if the file doesn't exist or errno=EINVAL
|
|
333
|
+
* if the header is invalid or the MAC verification fails.
|
|
334
|
+
*
|
|
335
|
+
* The scratch buffer must be sized for the file's chunk_size (from probe).
|
|
336
|
+
*/
|
|
337
|
+
int aegis128l_raf_open(aegis128l_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
338
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
339
|
+
|
|
340
|
+
/*
|
|
341
|
+
* Read and decrypt bytes at the given offset.
|
|
342
|
+
*
|
|
343
|
+
* On success, returns 0 and sets *bytes_read to the number of bytes read.
|
|
344
|
+
* Returns 0 with *bytes_read=0 at EOF. Returns -1 on I/O error or if
|
|
345
|
+
* authentication fails (indicating corruption or tampering).
|
|
346
|
+
*/
|
|
347
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
348
|
+
int aegis128l_raf_read(aegis128l_raf_ctx *ctx, uint8_t *out, size_t *bytes_read, size_t len,
|
|
349
|
+
uint64_t offset);
|
|
350
|
+
|
|
351
|
+
/*
|
|
352
|
+
* Encrypt and write bytes at the given offset.
|
|
353
|
+
*
|
|
354
|
+
* Performs read-modify-write for partial chunks. Automatically extends
|
|
355
|
+
* the file when writing past the current end. On success, returns 0 and
|
|
356
|
+
* sets *bytes_written to len.
|
|
357
|
+
*/
|
|
358
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
359
|
+
int aegis128l_raf_write(aegis128l_raf_ctx *ctx, size_t *bytes_written, const uint8_t *in,
|
|
360
|
+
size_t len, uint64_t offset);
|
|
361
|
+
|
|
362
|
+
/*
|
|
363
|
+
* Resize the file to the given size.
|
|
364
|
+
*
|
|
365
|
+
* Shrinking discards data beyond the new size. Growing fills the new
|
|
366
|
+
* range with zeros (sparse if the backing store supports it).
|
|
367
|
+
*/
|
|
368
|
+
int aegis128l_raf_truncate(aegis128l_raf_ctx *ctx, uint64_t size);
|
|
369
|
+
|
|
370
|
+
/* Get the logical plaintext file size. */
|
|
371
|
+
int aegis128l_raf_get_size(const aegis128l_raf_ctx *ctx, uint64_t *size);
|
|
372
|
+
|
|
373
|
+
/* Flush writes to backing store. Calls io->sync if provided. */
|
|
374
|
+
int aegis128l_raf_sync(aegis128l_raf_ctx *ctx);
|
|
375
|
+
|
|
376
|
+
/*
|
|
377
|
+
* Close the context and zeroize all key material.
|
|
378
|
+
* Automatically calls sync before cleanup.
|
|
379
|
+
*/
|
|
380
|
+
void aegis128l_raf_close(aegis128l_raf_ctx *ctx);
|
|
381
|
+
|
|
382
|
+
/*
|
|
383
|
+
* Rebuild the Merkle tree from file contents.
|
|
384
|
+
*
|
|
385
|
+
* Reads each chunk from the file and recomputes all leaf and parent hashes.
|
|
386
|
+
* Useful after opening an existing file to restore the Merkle tree state.
|
|
387
|
+
* Returns -1 if Merkle is not enabled or on I/O/hash error.
|
|
388
|
+
*/
|
|
389
|
+
int aegis128l_raf_merkle_rebuild(aegis128l_raf_ctx *ctx);
|
|
390
|
+
|
|
391
|
+
/*
|
|
392
|
+
* Verify file integrity against the Merkle tree.
|
|
393
|
+
*
|
|
394
|
+
* Reads each chunk, computes its hash, and compares against the stored tree.
|
|
395
|
+
* On success, returns 0. On corruption, returns -1 and sets *corrupted_chunk
|
|
396
|
+
* to the index of the first corrupted chunk (if corrupted_chunk is not NULL).
|
|
397
|
+
* Returns -1 with errno=ENOTSUP if Merkle is not enabled.
|
|
398
|
+
*/
|
|
399
|
+
int aegis128l_raf_merkle_verify(aegis128l_raf_ctx *ctx, uint64_t *corrupted_chunk);
|
|
400
|
+
|
|
401
|
+
/*
|
|
402
|
+
* Compute the root commitment with canonical context binding.
|
|
403
|
+
*
|
|
404
|
+
* Builds a context blob from the file's version, alg_id, chunk_size, and
|
|
405
|
+
* file_id, then combines it with the structural tree root and file_size via
|
|
406
|
+
* hash_commitment. This is the recommended API for RAF files.
|
|
407
|
+
* Returns -1 with errno=ENOTSUP if Merkle is not enabled.
|
|
408
|
+
*/
|
|
409
|
+
int aegis128l_raf_merkle_commitment(const aegis128l_raf_ctx *ctx, uint8_t *out, size_t out_len);
|
|
410
|
+
|
|
411
|
+
/* Opaque context for AEGIS-128X2 RAF operations. See aegis128l_raf_* for API docs. */
|
|
412
|
+
typedef struct aegis128x2_raf_ctx {
|
|
413
|
+
CRYPTO_ALIGN(32) uint8_t opaque[512];
|
|
414
|
+
} aegis128x2_raf_ctx;
|
|
415
|
+
|
|
416
|
+
int aegis128x2_raf_create(aegis128x2_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
417
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
418
|
+
|
|
419
|
+
int aegis128x2_raf_open(aegis128x2_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
420
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
421
|
+
|
|
422
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
423
|
+
int aegis128x2_raf_read(aegis128x2_raf_ctx *ctx, uint8_t *out, size_t *bytes_read, size_t len,
|
|
424
|
+
uint64_t offset);
|
|
425
|
+
|
|
426
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
427
|
+
int aegis128x2_raf_write(aegis128x2_raf_ctx *ctx, size_t *bytes_written, const uint8_t *in,
|
|
428
|
+
size_t len, uint64_t offset);
|
|
429
|
+
|
|
430
|
+
int aegis128x2_raf_truncate(aegis128x2_raf_ctx *ctx, uint64_t size);
|
|
431
|
+
|
|
432
|
+
int aegis128x2_raf_get_size(const aegis128x2_raf_ctx *ctx, uint64_t *size);
|
|
433
|
+
|
|
434
|
+
int aegis128x2_raf_sync(aegis128x2_raf_ctx *ctx);
|
|
435
|
+
|
|
436
|
+
void aegis128x2_raf_close(aegis128x2_raf_ctx *ctx);
|
|
437
|
+
|
|
438
|
+
int aegis128x2_raf_merkle_rebuild(aegis128x2_raf_ctx *ctx);
|
|
439
|
+
|
|
440
|
+
int aegis128x2_raf_merkle_verify(aegis128x2_raf_ctx *ctx, uint64_t *corrupted_chunk);
|
|
441
|
+
|
|
442
|
+
int aegis128x2_raf_merkle_commitment(const aegis128x2_raf_ctx *ctx, uint8_t *out, size_t out_len);
|
|
443
|
+
|
|
444
|
+
/* Opaque context for AEGIS-128X4 RAF operations. See aegis128l_raf_* for API docs. */
|
|
445
|
+
typedef struct aegis128x4_raf_ctx {
|
|
446
|
+
CRYPTO_ALIGN(64) uint8_t opaque[512];
|
|
447
|
+
} aegis128x4_raf_ctx;
|
|
448
|
+
|
|
449
|
+
int aegis128x4_raf_create(aegis128x4_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
450
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
451
|
+
|
|
452
|
+
int aegis128x4_raf_open(aegis128x4_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
453
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
454
|
+
|
|
455
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
456
|
+
int aegis128x4_raf_read(aegis128x4_raf_ctx *ctx, uint8_t *out, size_t *bytes_read, size_t len,
|
|
457
|
+
uint64_t offset);
|
|
458
|
+
|
|
459
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
460
|
+
int aegis128x4_raf_write(aegis128x4_raf_ctx *ctx, size_t *bytes_written, const uint8_t *in,
|
|
461
|
+
size_t len, uint64_t offset);
|
|
462
|
+
|
|
463
|
+
int aegis128x4_raf_truncate(aegis128x4_raf_ctx *ctx, uint64_t size);
|
|
464
|
+
|
|
465
|
+
int aegis128x4_raf_get_size(const aegis128x4_raf_ctx *ctx, uint64_t *size);
|
|
466
|
+
|
|
467
|
+
int aegis128x4_raf_sync(aegis128x4_raf_ctx *ctx);
|
|
468
|
+
|
|
469
|
+
void aegis128x4_raf_close(aegis128x4_raf_ctx *ctx);
|
|
470
|
+
|
|
471
|
+
int aegis128x4_raf_merkle_rebuild(aegis128x4_raf_ctx *ctx);
|
|
472
|
+
|
|
473
|
+
int aegis128x4_raf_merkle_verify(aegis128x4_raf_ctx *ctx, uint64_t *corrupted_chunk);
|
|
474
|
+
|
|
475
|
+
int aegis128x4_raf_merkle_commitment(const aegis128x4_raf_ctx *ctx, uint8_t *out, size_t out_len);
|
|
476
|
+
|
|
477
|
+
/* Opaque context for AEGIS-256 RAF operations. Master key is 32 bytes. */
|
|
478
|
+
typedef struct aegis256_raf_ctx {
|
|
479
|
+
CRYPTO_ALIGN(16) uint8_t opaque[512];
|
|
480
|
+
} aegis256_raf_ctx;
|
|
481
|
+
|
|
482
|
+
int aegis256_raf_create(aegis256_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
483
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
484
|
+
|
|
485
|
+
int aegis256_raf_open(aegis256_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
486
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
487
|
+
|
|
488
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
489
|
+
int aegis256_raf_read(aegis256_raf_ctx *ctx, uint8_t *out, size_t *bytes_read, size_t len,
|
|
490
|
+
uint64_t offset);
|
|
491
|
+
|
|
492
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
493
|
+
int aegis256_raf_write(aegis256_raf_ctx *ctx, size_t *bytes_written, const uint8_t *in, size_t len,
|
|
494
|
+
uint64_t offset);
|
|
495
|
+
|
|
496
|
+
int aegis256_raf_truncate(aegis256_raf_ctx *ctx, uint64_t size);
|
|
497
|
+
|
|
498
|
+
int aegis256_raf_get_size(const aegis256_raf_ctx *ctx, uint64_t *size);
|
|
499
|
+
|
|
500
|
+
int aegis256_raf_sync(aegis256_raf_ctx *ctx);
|
|
501
|
+
|
|
502
|
+
void aegis256_raf_close(aegis256_raf_ctx *ctx);
|
|
503
|
+
|
|
504
|
+
int aegis256_raf_merkle_rebuild(aegis256_raf_ctx *ctx);
|
|
505
|
+
|
|
506
|
+
int aegis256_raf_merkle_verify(aegis256_raf_ctx *ctx, uint64_t *corrupted_chunk);
|
|
507
|
+
|
|
508
|
+
int aegis256_raf_merkle_commitment(const aegis256_raf_ctx *ctx, uint8_t *out, size_t out_len);
|
|
509
|
+
|
|
510
|
+
/* Opaque context for AEGIS-256X2 RAF operations. Master key is 32 bytes. */
|
|
511
|
+
typedef struct aegis256x2_raf_ctx {
|
|
512
|
+
CRYPTO_ALIGN(32) uint8_t opaque[512];
|
|
513
|
+
} aegis256x2_raf_ctx;
|
|
514
|
+
|
|
515
|
+
int aegis256x2_raf_create(aegis256x2_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
516
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
517
|
+
|
|
518
|
+
int aegis256x2_raf_open(aegis256x2_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
519
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
520
|
+
|
|
521
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
522
|
+
int aegis256x2_raf_read(aegis256x2_raf_ctx *ctx, uint8_t *out, size_t *bytes_read, size_t len,
|
|
523
|
+
uint64_t offset);
|
|
524
|
+
|
|
525
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
526
|
+
int aegis256x2_raf_write(aegis256x2_raf_ctx *ctx, size_t *bytes_written, const uint8_t *in,
|
|
527
|
+
size_t len, uint64_t offset);
|
|
528
|
+
|
|
529
|
+
int aegis256x2_raf_truncate(aegis256x2_raf_ctx *ctx, uint64_t size);
|
|
530
|
+
|
|
531
|
+
int aegis256x2_raf_get_size(const aegis256x2_raf_ctx *ctx, uint64_t *size);
|
|
532
|
+
|
|
533
|
+
int aegis256x2_raf_sync(aegis256x2_raf_ctx *ctx);
|
|
534
|
+
|
|
535
|
+
void aegis256x2_raf_close(aegis256x2_raf_ctx *ctx);
|
|
536
|
+
|
|
537
|
+
int aegis256x2_raf_merkle_rebuild(aegis256x2_raf_ctx *ctx);
|
|
538
|
+
|
|
539
|
+
int aegis256x2_raf_merkle_verify(aegis256x2_raf_ctx *ctx, uint64_t *corrupted_chunk);
|
|
540
|
+
|
|
541
|
+
int aegis256x2_raf_merkle_commitment(const aegis256x2_raf_ctx *ctx, uint8_t *out, size_t out_len);
|
|
542
|
+
|
|
543
|
+
/* Opaque context for AEGIS-256X4 RAF operations. Master key is 32 bytes. */
|
|
544
|
+
typedef struct aegis256x4_raf_ctx {
|
|
545
|
+
CRYPTO_ALIGN(64) uint8_t opaque[512];
|
|
546
|
+
} aegis256x4_raf_ctx;
|
|
547
|
+
|
|
548
|
+
int aegis256x4_raf_create(aegis256x4_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
549
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
550
|
+
|
|
551
|
+
int aegis256x4_raf_open(aegis256x4_raf_ctx *ctx, const aegis_raf_io *io, const aegis_raf_rng *rng,
|
|
552
|
+
const aegis_raf_config *cfg, const uint8_t *master_key);
|
|
553
|
+
|
|
554
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
555
|
+
int aegis256x4_raf_read(aegis256x4_raf_ctx *ctx, uint8_t *out, size_t *bytes_read, size_t len,
|
|
556
|
+
uint64_t offset);
|
|
557
|
+
|
|
558
|
+
AEGIS_WARN_UNUSED_RESULT
|
|
559
|
+
int aegis256x4_raf_write(aegis256x4_raf_ctx *ctx, size_t *bytes_written, const uint8_t *in,
|
|
560
|
+
size_t len, uint64_t offset);
|
|
561
|
+
|
|
562
|
+
int aegis256x4_raf_truncate(aegis256x4_raf_ctx *ctx, uint64_t size);
|
|
563
|
+
|
|
564
|
+
int aegis256x4_raf_get_size(const aegis256x4_raf_ctx *ctx, uint64_t *size);
|
|
565
|
+
|
|
566
|
+
int aegis256x4_raf_sync(aegis256x4_raf_ctx *ctx);
|
|
567
|
+
|
|
568
|
+
void aegis256x4_raf_close(aegis256x4_raf_ctx *ctx);
|
|
569
|
+
|
|
570
|
+
int aegis256x4_raf_merkle_rebuild(aegis256x4_raf_ctx *ctx);
|
|
571
|
+
|
|
572
|
+
int aegis256x4_raf_merkle_verify(aegis256x4_raf_ctx *ctx, uint64_t *corrupted_chunk);
|
|
573
|
+
|
|
574
|
+
int aegis256x4_raf_merkle_commitment(const aegis256x4_raf_ctx *ctx, uint8_t *out, size_t out_len);
|
|
575
|
+
|
|
576
|
+
#ifdef __cplusplus
|
|
577
|
+
}
|
|
578
|
+
#endif
|
|
579
|
+
|
|
580
|
+
#endif
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#include <stddef.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
|
|
4
|
+
#include "raf_internal.h"
|
|
5
|
+
|
|
6
|
+
size_t
|
|
7
|
+
aegis_raf_chunk_min(void)
|
|
8
|
+
{
|
|
9
|
+
return AEGIS_RAF_CHUNK_MIN;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
size_t
|
|
13
|
+
aegis_raf_chunk_max(void)
|
|
14
|
+
{
|
|
15
|
+
return AEGIS_RAF_CHUNK_MAX;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
size_t
|
|
19
|
+
aegis_raf_header_size(void)
|
|
20
|
+
{
|
|
21
|
+
return AEGIS_RAF_HEADER_SIZE;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
size_t
|
|
25
|
+
aegis_raf_scratch_align(void)
|
|
26
|
+
{
|
|
27
|
+
return AEGIS_RAF_SCRATCH_ALIGN;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
int
|
|
31
|
+
aegis_raf_probe(const aegis_raf_io *io, aegis_raf_info *info)
|
|
32
|
+
{
|
|
33
|
+
uint8_t hdr[AEGIS_RAF_HEADER_SIZE];
|
|
34
|
+
uint16_t header_size;
|
|
35
|
+
uint8_t version;
|
|
36
|
+
uint32_t chunk_size;
|
|
37
|
+
uint8_t alg_id;
|
|
38
|
+
|
|
39
|
+
if (io == NULL || info == NULL) {
|
|
40
|
+
errno = EINVAL;
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
43
|
+
if (io->read_at == NULL) {
|
|
44
|
+
errno = EINVAL;
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (io->read_at(io->user, hdr, AEGIS_RAF_HEADER_SIZE, 0) != 0) {
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (memcmp(hdr, AEGIS_RAF_MAGIC, 8) != 0) {
|
|
53
|
+
errno = EINVAL;
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
header_size = LOAD16_LE(hdr + 8);
|
|
58
|
+
if (header_size != AEGIS_RAF_HEADER_SIZE) {
|
|
59
|
+
errno = EINVAL;
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
version = hdr[10];
|
|
64
|
+
if (version != AEGIS_RAF_VERSION) {
|
|
65
|
+
errno = EINVAL;
|
|
66
|
+
return -1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
chunk_size = LOAD32_LE(hdr + 12);
|
|
70
|
+
if (chunk_size < AEGIS_RAF_CHUNK_MIN || chunk_size > AEGIS_RAF_CHUNK_MAX ||
|
|
71
|
+
(chunk_size % 16) != 0) {
|
|
72
|
+
errno = EINVAL;
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
alg_id = hdr[11];
|
|
77
|
+
if (alg_id < AEGIS_RAF_ALG_128L || alg_id > AEGIS_RAF_ALG_256X4) {
|
|
78
|
+
errno = EINVAL;
|
|
79
|
+
return -1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
info->alg_id = alg_id;
|
|
83
|
+
info->chunk_size = chunk_size;
|
|
84
|
+
info->file_size = LOAD64_LE(hdr + 16);
|
|
85
|
+
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#include <stddef.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
|
|
4
|
+
#include "raf_internal.h"
|
|
5
|
+
|
|
6
|
+
#include "../include/aegis128l.h"
|
|
7
|
+
|
|
8
|
+
#define VARIANT aegis128l
|
|
9
|
+
#define KEYBYTES aegis128l_KEYBYTES
|
|
10
|
+
#define NPUBBYTES aegis128l_NPUBBYTES
|
|
11
|
+
#define ALG_ID AEGIS_RAF_ALG_128L
|
|
12
|
+
|
|
13
|
+
#define VARIANT_encrypt_detached aegis128l_encrypt_detached
|
|
14
|
+
#define VARIANT_decrypt_detached aegis128l_decrypt_detached
|
|
15
|
+
#define VARIANT_mac_init aegis128l_mac_init
|
|
16
|
+
#define VARIANT_mac_update aegis128l_mac_update
|
|
17
|
+
#define VARIANT_mac_final aegis128l_mac_final
|
|
18
|
+
#define VARIANT_mac_verify aegis128l_mac_verify
|
|
19
|
+
|
|
20
|
+
#include "raf_variant.h"
|