1
/* This file was automatically imported with
2
import_gcry.py. Please don't modify it */
3
/* camellia-glue.c - Glue for the Camellia cipher
4
* Copyright (C) 2007 Free Software Foundation, Inc.
6
* This file is part of Libgcrypt.
8
* Libgcrypt is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as
10
* published by the Free Software Foundation; either version 2.1 of
11
* the License, or (at your option) any later version.
13
* Libgcrypt is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
/* I put all the libgcrypt-specific stuff in this file to keep the
25
camellia.c/camellia.h files exactly as provided by NTT. If they
26
update their code, this should make it easier to bring the changes
29
There is one small change which needs to be done: Include the
30
following code at the top of camellia.h: */
33
/* To use Camellia with libraries it is often useful to keep the name
34
* space of the library clean. The following macro is thus useful:
36
* #define CAMELLIA_EXT_SYM_PREFIX foo_
38
* This prefixes all external symbols with "foo_".
42
#ifdef CAMELLIA_EXT_SYM_PREFIX
43
#define CAMELLIA_PREFIX1(x,y) x ## y
44
#define CAMELLIA_PREFIX2(x,y) CAMELLIA_PREFIX1(x,y)
45
#define CAMELLIA_PREFIX(x) CAMELLIA_PREFIX2(CAMELLIA_EXT_SYM_PREFIX,x)
46
#define Camellia_Ekeygen CAMELLIA_PREFIX(Camellia_Ekeygen)
47
#define Camellia_EncryptBlock CAMELLIA_PREFIX(Camellia_EncryptBlock)
48
#define Camellia_DecryptBlock CAMELLIA_PREFIX(Camellia_DecryptBlock)
49
#define camellia_decrypt128 CAMELLIA_PREFIX(camellia_decrypt128)
50
#define camellia_decrypt256 CAMELLIA_PREFIX(camellia_decrypt256)
51
#define camellia_encrypt128 CAMELLIA_PREFIX(camellia_encrypt128)
52
#define camellia_encrypt256 CAMELLIA_PREFIX(camellia_encrypt256)
53
#define camellia_setup128 CAMELLIA_PREFIX(camellia_setup128)
54
#define camellia_setup192 CAMELLIA_PREFIX(camellia_setup192)
55
#define camellia_setup256 CAMELLIA_PREFIX(camellia_setup256)
56
#endif /*CAMELLIA_EXT_SYM_PREFIX*/
58
#endif /* Code sample. */
69
KEY_TABLE_TYPE keytable;
73
static gcry_err_code_t
74
camellia_setkey(void *c, const byte *key, unsigned keylen)
76
CAMELLIA_context *ctx=c;
77
static int initialized=0;
78
static const char *selftest_failed=NULL;
80
if(keylen!=16 && keylen!=24 && keylen!=32)
81
return GPG_ERR_INV_KEYLEN;
86
selftest_failed=selftest();
88
log_error("%s\n",selftest_failed);
92
return GPG_ERR_SELFTEST_FAILED;
94
ctx->keybitlength=keylen*8;
95
Camellia_Ekeygen(ctx->keybitlength,key,ctx->keytable);
97
((19+34+34)*sizeof(u32)+2*sizeof(void*) /* camellia_setup256 */
98
+(4+32)*sizeof(u32)+2*sizeof(void*) /* camellia_setup192 */
99
+0+sizeof(int)+2*sizeof(void*) /* Camellia_Ekeygen */
100
+3*2*sizeof(void*) /* Function calls. */
107
camellia_encrypt(void *c, byte *outbuf, const byte *inbuf)
109
CAMELLIA_context *ctx=c;
111
Camellia_EncryptBlock(ctx->keybitlength,inbuf,ctx->keytable,outbuf);
113
(sizeof(int)+2*sizeof(unsigned char *)+sizeof(KEY_TABLE_TYPE)
115
+2*sizeof(u32*)+4*sizeof(u32)
116
+2*2*sizeof(void*) /* Function calls. */
121
camellia_decrypt(void *c, byte *outbuf, const byte *inbuf)
123
CAMELLIA_context *ctx=c;
125
Camellia_DecryptBlock(ctx->keybitlength,inbuf,ctx->keytable,outbuf);
127
(sizeof(int)+2*sizeof(unsigned char *)+sizeof(KEY_TABLE_TYPE)
129
+2*sizeof(u32*)+4*sizeof(u32)
130
+2*2*sizeof(void*) /* Function calls. */
135
/* These oids are from
136
<http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications_oid.html>,
137
retrieved May 1, 2007. */
139
static gcry_cipher_oid_spec_t camellia128_oids[] =
141
{"1.2.392.200011.61.1.1.1.2", GCRY_CIPHER_MODE_CBC},
142
{"0.3.4401.5.3.1.9.1", GCRY_CIPHER_MODE_ECB},
143
{"0.3.4401.5.3.1.9.3", GCRY_CIPHER_MODE_OFB},
144
{"0.3.4401.5.3.1.9.4", GCRY_CIPHER_MODE_CFB},
148
static gcry_cipher_oid_spec_t camellia192_oids[] =
150
{"1.2.392.200011.61.1.1.1.3", GCRY_CIPHER_MODE_CBC},
151
{"0.3.4401.5.3.1.9.21", GCRY_CIPHER_MODE_ECB},
152
{"0.3.4401.5.3.1.9.23", GCRY_CIPHER_MODE_OFB},
153
{"0.3.4401.5.3.1.9.24", GCRY_CIPHER_MODE_CFB},
157
static gcry_cipher_oid_spec_t camellia256_oids[] =
159
{"1.2.392.200011.61.1.1.1.4", GCRY_CIPHER_MODE_CBC},
160
{"0.3.4401.5.3.1.9.41", GCRY_CIPHER_MODE_ECB},
161
{"0.3.4401.5.3.1.9.43", GCRY_CIPHER_MODE_OFB},
162
{"0.3.4401.5.3.1.9.44", GCRY_CIPHER_MODE_CFB},
166
gcry_cipher_spec_t _gcry_cipher_spec_camellia128 =
168
"CAMELLIA128",NULL,camellia128_oids,CAMELLIA_BLOCK_SIZE,128,
169
sizeof(CAMELLIA_context),camellia_setkey,camellia_encrypt,camellia_decrypt
172
gcry_cipher_spec_t _gcry_cipher_spec_camellia192 =
174
"CAMELLIA192",NULL,camellia192_oids,CAMELLIA_BLOCK_SIZE,192,
175
sizeof(CAMELLIA_context),camellia_setkey,camellia_encrypt,camellia_decrypt
178
gcry_cipher_spec_t _gcry_cipher_spec_camellia256 =
180
"CAMELLIA256",NULL,camellia256_oids,CAMELLIA_BLOCK_SIZE,256,
181
sizeof(CAMELLIA_context),camellia_setkey,camellia_encrypt,camellia_decrypt
185
GRUB_MOD_INIT(gcry_camellia)
187
grub_cipher_register (&_gcry_cipher_spec_camellia128);
188
grub_cipher_register (&_gcry_cipher_spec_camellia192);
189
grub_cipher_register (&_gcry_cipher_spec_camellia256);
192
GRUB_MOD_FINI(gcry_camellia)
194
grub_cipher_unregister (&_gcry_cipher_spec_camellia128);
195
grub_cipher_unregister (&_gcry_cipher_spec_camellia192);
196
grub_cipher_unregister (&_gcry_cipher_spec_camellia256);