summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2022-09-03 20:06:43 +0000
committerjsing <>2022-09-03 20:06:43 +0000
commite6ddefe813ee122cf52b085578a0a3649bd9f2cd (patch)
treeb8a40b1b0ca804120f179c51f4d4ed19972d9954
parent5f08472f8305c7336ca9acc5587cebd87a292439 (diff)
downloadopenbsd-e6ddefe813ee122cf52b085578a0a3649bd9f2cd.tar.gz
openbsd-e6ddefe813ee122cf52b085578a0a3649bd9f2cd.tar.bz2
openbsd-e6ddefe813ee122cf52b085578a0a3649bd9f2cd.zip
Mechanically expand IMPLEMENT_BLOCK_CIPHER macro.
Only change to generated assembly is due to EVPerror()'s use of line numbers.
-rw-r--r--src/lib/libcrypto/evp/e_camellia.c507
1 files changed, 486 insertions, 21 deletions
diff --git a/src/lib/libcrypto/evp/e_camellia.c b/src/lib/libcrypto/evp/e_camellia.c
index 70dad7ead6..46b918c163 100644
--- a/src/lib/libcrypto/evp/e_camellia.c
+++ b/src/lib/libcrypto/evp/e_camellia.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_camellia.c,v 1.9 2021/12/12 21:30:13 tb Exp $ */ 1/* $OpenBSD: e_camellia.c,v 1.10 2022/09/03 20:06:43 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -73,26 +73,491 @@ typedef struct {
73} EVP_CAMELLIA_KEY; 73} EVP_CAMELLIA_KEY;
74 74
75/* Attribute operation for Camellia */ 75/* Attribute operation for Camellia */
76#define data(ctx) EVP_C_DATA(EVP_CAMELLIA_KEY,ctx) 76#define data(ctx) ((EVP_CAMELLIA_KEY *)(ctx)->cipher_data)
77 77
78IMPLEMENT_BLOCK_CIPHER(camellia_128, ks, Camellia, EVP_CAMELLIA_KEY, 78static int
79 NID_camellia_128, 16, 16, 16, 128, 79camellia_128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
80 0, camellia_init_key, NULL, 80{
81 EVP_CIPHER_set_asn1_iv, 81 while (inl >= EVP_MAXCHUNK) {
82 EVP_CIPHER_get_asn1_iv, 82 Camellia_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
83 NULL) 83 inl -= EVP_MAXCHUNK;
84IMPLEMENT_BLOCK_CIPHER(camellia_192, ks, Camellia, EVP_CAMELLIA_KEY, 84 in += EVP_MAXCHUNK;
85 NID_camellia_192, 16, 24, 16, 128, 85 out += EVP_MAXCHUNK;
86 0, camellia_init_key, NULL, 86 }
87 EVP_CIPHER_set_asn1_iv, 87
88 EVP_CIPHER_get_asn1_iv, 88 if (inl)
89 NULL) 89 Camellia_cbc_encrypt(in, out, (long)inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
90IMPLEMENT_BLOCK_CIPHER(camellia_256, ks, Camellia, EVP_CAMELLIA_KEY, 90
91 NID_camellia_256, 16, 32, 16, 128, 91 return 1;
92 0, camellia_init_key, NULL, 92}
93 EVP_CIPHER_set_asn1_iv, 93
94 EVP_CIPHER_get_asn1_iv, 94static int
95 NULL) 95camellia_128_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
96{
97 size_t chunk = EVP_MAXCHUNK;
98
99 if (128 == 1)
100 chunk >>= 3;
101
102 if (inl < chunk)
103 chunk = inl;
104
105 while (inl && inl >= chunk) {
106 Camellia_cfb128_encrypt(in, out, (long)((128 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
107 inl -= chunk;
108 in += chunk;
109 out += chunk;
110 if (inl < chunk)
111 chunk = inl;
112 }
113
114 return 1;
115}
116
117static int
118camellia_128_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
119{
120 size_t i, bl;
121
122 bl = ctx->cipher->block_size;
123
124 if (inl < bl)
125 return 1;
126
127 inl -= bl;
128
129 for (i = 0; i <= inl; i += bl)
130 Camellia_ecb_encrypt(in + i, out + i, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->encrypt);
131
132 return 1;
133}
134
135static int
136camellia_128_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
137{
138 while (inl >= EVP_MAXCHUNK) {
139 Camellia_ofb128_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num);
140 inl -= EVP_MAXCHUNK;
141 in += EVP_MAXCHUNK;
142 out += EVP_MAXCHUNK;
143 }
144
145 if (inl)
146 Camellia_ofb128_encrypt(in, out, (long)inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num);
147
148 return 1;
149}
150
151static const EVP_CIPHER camellia_128_cbc = {
152 .nid = NID_camellia_128_cbc,
153 .block_size = 16,
154 .key_len = 16,
155 .iv_len = 16,
156 .flags = 0 | EVP_CIPH_CBC_MODE,
157 .init = camellia_init_key,
158 .do_cipher = camellia_128_cbc_cipher,
159 .cleanup = NULL,
160 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
161 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
162 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
163 .ctrl = NULL,
164 .app_data = NULL,
165};
166
167const EVP_CIPHER *
168EVP_camellia_128_cbc(void)
169{
170 return &camellia_128_cbc;
171}
172
173static const EVP_CIPHER camellia_128_cfb128 = {
174 .nid = NID_camellia_128_cfb128,
175 .block_size = 1,
176 .key_len = 16,
177 .iv_len = 16,
178 .flags = 0 | EVP_CIPH_CFB_MODE,
179 .init = camellia_init_key,
180 .do_cipher = camellia_128_cfb128_cipher,
181 .cleanup = NULL,
182 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
183 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
184 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
185 .ctrl = NULL,
186 .app_data = NULL,
187};
188
189const EVP_CIPHER *
190EVP_camellia_128_cfb128(void)
191{
192 return &camellia_128_cfb128;
193}
194
195static const EVP_CIPHER camellia_128_ofb = {
196 .nid = NID_camellia_128_ofb128,
197 .block_size = 1,
198 .key_len = 16,
199 .iv_len = 16,
200 .flags = 0 | EVP_CIPH_OFB_MODE,
201 .init = camellia_init_key,
202 .do_cipher = camellia_128_ofb_cipher,
203 .cleanup = NULL,
204 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
205 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
206 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
207 .ctrl = NULL,
208 .app_data = NULL,
209};
210
211const EVP_CIPHER *
212EVP_camellia_128_ofb(void)
213{
214 return &camellia_128_ofb;
215}
216
217static const EVP_CIPHER camellia_128_ecb = {
218 .nid = NID_camellia_128_ecb,
219 .block_size = 16,
220 .key_len = 16,
221 .iv_len = 0,
222 .flags = 0 | EVP_CIPH_ECB_MODE,
223 .init = camellia_init_key,
224 .do_cipher = camellia_128_ecb_cipher,
225 .cleanup = NULL,
226 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
227 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
228 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
229 .ctrl = NULL,
230 .app_data = NULL,
231};
232
233const EVP_CIPHER *
234EVP_camellia_128_ecb(void)
235{
236 return &camellia_128_ecb;
237}
238
239static int
240camellia_192_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
241{
242 while (inl >= EVP_MAXCHUNK) {
243 Camellia_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
244 inl -= EVP_MAXCHUNK;
245 in += EVP_MAXCHUNK;
246 out += EVP_MAXCHUNK;
247 }
248
249 if (inl)
250 Camellia_cbc_encrypt(in, out, (long)inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
251
252 return 1;
253}
254
255static int
256camellia_192_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
257{
258 size_t chunk = EVP_MAXCHUNK;
259
260 if (128 == 1)
261 chunk >>= 3;
262
263 if (inl < chunk)
264 chunk = inl;
265
266 while (inl && inl >= chunk) {
267 Camellia_cfb128_encrypt(in, out, (long)((128 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
268 inl -= chunk;
269 in += chunk;
270 out += chunk;
271 if (inl < chunk)
272 chunk = inl;
273 }
274
275 return 1;
276}
277
278static int
279camellia_192_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
280{
281 size_t i, bl;
282
283 bl = ctx->cipher->block_size;
284
285 if (inl < bl)
286 return 1;
287
288 inl -= bl;
289
290 for (i = 0; i <= inl; i += bl)
291 Camellia_ecb_encrypt(in + i, out + i, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->encrypt);
292
293 return 1;
294}
295
296static int
297camellia_192_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
298{
299 while (inl >= EVP_MAXCHUNK) {
300 Camellia_ofb128_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num);
301 inl -= EVP_MAXCHUNK;
302 in += EVP_MAXCHUNK;
303 out += EVP_MAXCHUNK;
304 }
305
306 if (inl)
307 Camellia_ofb128_encrypt(in, out, (long)inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num);
308
309 return 1;
310}
311
312static const EVP_CIPHER camellia_192_cbc = {
313 .nid = NID_camellia_192_cbc,
314 .block_size = 16,
315 .key_len = 24,
316 .iv_len = 16,
317 .flags = 0 | EVP_CIPH_CBC_MODE,
318 .init = camellia_init_key,
319 .do_cipher = camellia_192_cbc_cipher,
320 .cleanup = NULL,
321 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
322 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
323 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
324 .ctrl = NULL,
325 .app_data = NULL,
326};
327
328const EVP_CIPHER *
329EVP_camellia_192_cbc(void)
330{
331 return &camellia_192_cbc;
332}
333
334static const EVP_CIPHER camellia_192_cfb128 = {
335 .nid = NID_camellia_192_cfb128,
336 .block_size = 1,
337 .key_len = 24,
338 .iv_len = 16,
339 .flags = 0 | EVP_CIPH_CFB_MODE,
340 .init = camellia_init_key,
341 .do_cipher = camellia_192_cfb128_cipher,
342 .cleanup = NULL,
343 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
344 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
345 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
346 .ctrl = NULL,
347 .app_data = NULL,
348};
349
350const EVP_CIPHER *
351EVP_camellia_192_cfb128(void)
352{
353 return &camellia_192_cfb128;
354}
355
356static const EVP_CIPHER camellia_192_ofb = {
357 .nid = NID_camellia_192_ofb128,
358 .block_size = 1,
359 .key_len = 24,
360 .iv_len = 16,
361 .flags = 0 | EVP_CIPH_OFB_MODE,
362 .init = camellia_init_key,
363 .do_cipher = camellia_192_ofb_cipher,
364 .cleanup = NULL,
365 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
366 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
367 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
368 .ctrl = NULL,
369 .app_data = NULL,
370};
371
372const EVP_CIPHER *
373EVP_camellia_192_ofb(void)
374{
375 return &camellia_192_ofb;
376}
377
378static const EVP_CIPHER camellia_192_ecb = {
379 .nid = NID_camellia_192_ecb,
380 .block_size = 16,
381 .key_len = 24,
382 .iv_len = 0,
383 .flags = 0 | EVP_CIPH_ECB_MODE,
384 .init = camellia_init_key,
385 .do_cipher = camellia_192_ecb_cipher,
386 .cleanup = NULL,
387 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
388 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
389 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
390 .ctrl = NULL,
391 .app_data = NULL,
392};
393
394const EVP_CIPHER *
395EVP_camellia_192_ecb(void)
396{
397 return &camellia_192_ecb;
398}
399
400static int
401camellia_256_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
402{
403 while (inl >= EVP_MAXCHUNK) {
404 Camellia_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
405 inl -= EVP_MAXCHUNK;
406 in += EVP_MAXCHUNK;
407 out += EVP_MAXCHUNK;
408 }
409
410 if (inl)
411 Camellia_cbc_encrypt(in, out, (long)inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
412
413 return 1;
414}
415
416static int
417camellia_256_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
418{
419 size_t chunk = EVP_MAXCHUNK;
420
421 if (128 == 1)
422 chunk >>= 3;
423
424 if (inl < chunk)
425 chunk = inl;
426
427 while (inl && inl >= chunk) {
428 Camellia_cfb128_encrypt(in, out, (long)((128 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
429 inl -= chunk;
430 in += chunk;
431 out += chunk;
432 if (inl < chunk)
433 chunk = inl;
434 }
435
436 return 1;
437}
438
439static int
440camellia_256_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
441{
442 size_t i, bl;
443
444 bl = ctx->cipher->block_size;
445
446 if (inl < bl)
447 return 1;
448
449 inl -= bl;
450
451 for (i = 0; i <= inl; i += bl)
452 Camellia_ecb_encrypt(in + i, out + i, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->encrypt);
453
454 return 1;
455}
456
457static int
458camellia_256_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
459{
460 while (inl >= EVP_MAXCHUNK) {
461 Camellia_ofb128_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num);
462 inl -= EVP_MAXCHUNK;
463 in += EVP_MAXCHUNK;
464 out += EVP_MAXCHUNK;
465 }
466
467 if (inl)
468 Camellia_ofb128_encrypt(in, out, (long)inl, &((EVP_CAMELLIA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num);
469
470 return 1;
471}
472
473static const EVP_CIPHER camellia_256_cbc = {
474 .nid = NID_camellia_256_cbc,
475 .block_size = 16,
476 .key_len = 32,
477 .iv_len = 16,
478 .flags = 0 | EVP_CIPH_CBC_MODE,
479 .init = camellia_init_key,
480 .do_cipher = camellia_256_cbc_cipher,
481 .cleanup = NULL,
482 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
483 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
484 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
485 .ctrl = NULL,
486 .app_data = NULL,
487};
488
489const EVP_CIPHER *
490EVP_camellia_256_cbc(void)
491{
492 return &camellia_256_cbc;
493}
494
495static const EVP_CIPHER camellia_256_cfb128 = {
496 .nid = NID_camellia_256_cfb128,
497 .block_size = 1,
498 .key_len = 32,
499 .iv_len = 16,
500 .flags = 0 | EVP_CIPH_CFB_MODE,
501 .init = camellia_init_key,
502 .do_cipher = camellia_256_cfb128_cipher,
503 .cleanup = NULL,
504 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
505 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
506 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
507 .ctrl = NULL,
508 .app_data = NULL,
509};
510
511const EVP_CIPHER *
512EVP_camellia_256_cfb128(void)
513{
514 return &camellia_256_cfb128;
515}
516
517static const EVP_CIPHER camellia_256_ofb = {
518 .nid = NID_camellia_256_ofb128,
519 .block_size = 1,
520 .key_len = 32,
521 .iv_len = 16,
522 .flags = 0 | EVP_CIPH_OFB_MODE,
523 .init = camellia_init_key,
524 .do_cipher = camellia_256_ofb_cipher,
525 .cleanup = NULL,
526 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
527 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
528 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
529 .ctrl = NULL,
530 .app_data = NULL,
531};
532
533const EVP_CIPHER *
534EVP_camellia_256_ofb(void)
535{
536 return &camellia_256_ofb;
537}
538
539static const EVP_CIPHER camellia_256_ecb = {
540 .nid = NID_camellia_256_ecb,
541 .block_size = 16,
542 .key_len = 32,
543 .iv_len = 0,
544 .flags = 0 | EVP_CIPH_ECB_MODE,
545 .init = camellia_init_key,
546 .do_cipher = camellia_256_ecb_cipher,
547 .cleanup = NULL,
548 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
549 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv,
550 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv,
551 .ctrl = NULL,
552 .app_data = NULL,
553};
554
555const EVP_CIPHER *
556EVP_camellia_256_ecb(void)
557{
558 return &camellia_256_ecb;
559}
560
96 561
97#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits) IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16) 562#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits) IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16)
98 563