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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/*
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <asn1/oid.h>
#include "crypter.h"
ENUM_BEGIN(encryption_algorithm_names, ENCR_DES_IV64, ENCR_DES_IV32,
"DES_IV64",
"DES_CBC",
"3DES_CBC",
"RC5_CBC",
"IDEA_CBC",
"CAST_CBC",
"BLOWFISH_CBC",
"3IDEA",
"DES_IV32");
ENUM_NEXT(encryption_algorithm_names, ENCR_NULL, ENCR_AES_CCM_ICV16, ENCR_DES_IV32,
"NULL",
"AES_CBC",
"AES_CTR",
"AES_CCM_8",
"AES_CCM_12",
"AES_CCM_16");
ENUM_NEXT(encryption_algorithm_names, ENCR_AES_GCM_ICV8, ENCR_NULL_AUTH_AES_GMAC, ENCR_AES_CCM_ICV16,
"AES_GCM_8",
"AES_GCM_12",
"AES_GCM_16",
"NULL_AES_GMAC");
ENUM_NEXT(encryption_algorithm_names, ENCR_CAMELLIA_CBC, ENCR_CAMELLIA_CCM_ICV16, ENCR_NULL_AUTH_AES_GMAC,
"CAMELLIA_CBC",
"CAMELLIA_CTR",
"CAMELLIA_CCM_8",
"CAMELLIA_CCM_12",
"CAMELLIA_CCM_16");
ENUM_NEXT(encryption_algorithm_names, ENCR_UNDEFINED, ENCR_RC2_CBC, ENCR_CAMELLIA_CCM_ICV16,
"UNDEFINED",
"DES_ECB",
"SERPENT_CBC",
"TWOFISH_CBC",
"RC2_CBC");
ENUM_END(encryption_algorithm_names, ENCR_RC2_CBC);
/*
* Described in header.
*/
encryption_algorithm_t encryption_algorithm_from_oid(int oid, size_t *key_size)
{
encryption_algorithm_t alg;
size_t alg_key_size;
switch (oid)
{
case OID_DES_CBC:
alg = ENCR_DES;
alg_key_size = 0;
break;
case OID_3DES_EDE_CBC:
alg = ENCR_3DES;
alg_key_size = 0;
break;
case OID_AES128_CBC:
alg = ENCR_AES_CBC;
alg_key_size = 128;
break;
case OID_AES192_CBC:
alg = ENCR_AES_CBC;
alg_key_size = 192;
break;
case OID_AES256_CBC:
alg = ENCR_AES_CBC;
alg_key_size = 256;
break;
case OID_CAMELLIA128_CBC:
alg = ENCR_CAMELLIA_CBC;
alg_key_size = 128;
break;
case OID_CAMELLIA192_CBC:
alg = ENCR_CAMELLIA_CBC;
alg_key_size = 192;
break;
case OID_CAMELLIA256_CBC:
alg = ENCR_CAMELLIA_CBC;
alg_key_size = 256;
break;
case OID_BLOWFISH_CBC:
alg = ENCR_BLOWFISH;
alg_key_size = 0;
break;
default:
alg = ENCR_UNDEFINED;
alg_key_size = 0;
}
if (key_size)
{
*key_size = alg_key_size;
}
return alg;
}
/*
* Described in header.
*/
int encryption_algorithm_to_oid(encryption_algorithm_t alg, size_t key_size)
{
int oid;
switch(alg)
{
case ENCR_DES:
oid = OID_DES_CBC;
break;
case ENCR_3DES:
oid = OID_3DES_EDE_CBC;
break;
case ENCR_AES_CBC:
switch (key_size)
{
case 128:
oid = OID_AES128_CBC;
break;
case 192:
oid = OID_AES192_CBC;
break;
case 256:
oid = OID_AES256_CBC;
break;
default:
oid = OID_UNKNOWN;
}
break;
case ENCR_CAMELLIA_CBC:
switch (key_size)
{
case 128:
oid = OID_CAMELLIA128_CBC;
break;
case 192:
oid = OID_CAMELLIA192_CBC;
break;
case 256:
oid = OID_CAMELLIA256_CBC;
break;
default:
oid = OID_UNKNOWN;
}
break;
case ENCR_BLOWFISH:
oid = OID_BLOWFISH_CBC;
break;
default:
oid = OID_UNKNOWN;
}
return oid;
}
/*
* Described in header.
*/
bool encryption_algorithm_is_aead(encryption_algorithm_t alg)
{
switch (alg)
{
case ENCR_AES_CCM_ICV8:
case ENCR_AES_CCM_ICV12:
case ENCR_AES_CCM_ICV16:
case ENCR_AES_GCM_ICV8:
case ENCR_AES_GCM_ICV12:
case ENCR_AES_GCM_ICV16:
case ENCR_NULL_AUTH_AES_GMAC:
case ENCR_CAMELLIA_CCM_ICV8:
case ENCR_CAMELLIA_CCM_ICV12:
case ENCR_CAMELLIA_CCM_ICV16:
return TRUE;
default:
return FALSE;
}
}
|