1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
// This file is part of the "AES tools" project.
// For details, see https://github.com/egor-tensin/aes-tools.
// Distributed under the MIT License.
#pragma once
#include "aes.h"
#include "error.h"
#include "mode.h"
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef union
{
AES_AES128_Key aes128_key;
AES_AES192_Key aes192_key;
AES_AES256_Key aes256_key;
}
AES_BoxKey;
typedef union
{
AES_AES128_RoundKeys aes128_encryption_keys;
AES_AES192_RoundKeys aes192_encryption_keys;
AES_AES256_RoundKeys aes256_encryption_keys;
}
AES_BoxEncryptionRoundKeys;
typedef union
{
AES_AES128_RoundKeys aes128_decryption_keys;
AES_AES192_RoundKeys aes192_decryption_keys;
AES_AES256_RoundKeys aes256_decryption_keys;
}
AES_BoxDecryptionRoundKeys;
typedef union
{
AES_AES128_KeyString aes128;
AES_AES192_KeyString aes192;
AES_AES256_KeyString aes256;
}
AES_BoxKeyString;
typedef union
{
AES_AES_Block aes_block;
}
AES_BoxBlock;
typedef union
{
AES_AES_BlockString aes;
}
AES_BoxBlockString;
typedef AES_StatusCode (*AES_BoxCalculateRoundKeys)(
const AES_BoxKey* params,
AES_BoxEncryptionRoundKeys*,
AES_BoxDecryptionRoundKeys*,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxParseBlock)(
AES_BoxBlock* dest,
const char* src,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxParseKey)(
AES_BoxKey* dest,
const char* src,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxFormatBlock)(
AES_BoxBlockString* dest,
const AES_BoxBlock* src,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxFormatKey)(
AES_BoxKeyString* dest,
const AES_BoxKey* src,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxEncryptBlock)(
const AES_BoxBlock* plaintext,
const AES_BoxEncryptionRoundKeys* params,
AES_BoxBlock* ciphertext,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxDecryptBlock)(
const AES_BoxBlock* ciphertext,
const AES_BoxDecryptionRoundKeys* params,
AES_BoxBlock* plaintext,
AES_ErrorDetails* err_details);
typedef AES_StatusCode (*AES_BoxXorBlock)(
AES_BoxBlock*,
const AES_BoxBlock*,
AES_ErrorDetails*);
typedef AES_StatusCode (*AES_BoxIncBlock)(
AES_BoxBlock*,
AES_ErrorDetails*);
typedef AES_StatusCode (*AES_BoxGetBlockSize)(
size_t*,
AES_ErrorDetails*);
typedef AES_StatusCode (*AES_BoxStoreBlock)(
void*,
const AES_BoxBlock*,
AES_ErrorDetails*);
typedef AES_StatusCode (*AES_BoxLoadBlock)(
AES_BoxBlock*,
const void*,
AES_ErrorDetails*);
typedef struct
{
AES_BoxCalculateRoundKeys calc_round_keys;
AES_BoxParseBlock parse_block;
AES_BoxParseKey parse_key;
AES_BoxFormatBlock format_block;
AES_BoxFormatKey format_key;
AES_BoxEncryptBlock encrypt_block;
AES_BoxDecryptBlock decrypt_block;
AES_BoxXorBlock xor_block;
AES_BoxIncBlock inc_block;
AES_BoxGetBlockSize get_block_size;
AES_BoxStoreBlock store_block;
AES_BoxLoadBlock load_block;
}
AES_BoxAlgorithmInterface;
typedef struct
{
const AES_BoxAlgorithmInterface* algorithm;
AES_BoxEncryptionRoundKeys encryption_keys;
AES_BoxDecryptionRoundKeys decryption_keys;
AES_Mode mode;
AES_BoxBlock iv;
}
AES_Box;
#ifdef __cplusplus
}
#endif
|