1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

Add 128-bit variant of Camellia.

This commit is contained in:
David Shaw 2007-11-29 14:51:08 +00:00
parent a92fa61c48
commit bc15e25d7a
5 changed files with 59 additions and 14 deletions

View File

@ -1,3 +1,8 @@
2007-11-29 David Shaw <dshaw@jabberwocky.com>
* camellia-glue.c (camellia_get_info), cipher.c
(setup_cipher_table): Add 128-bit variant of Camellia.
2007-11-28 David Shaw <dshaw@jabberwocky.com>
* sha256.c (sha224_get_info): 4880 has an error in the SHA-224 OID

View File

@ -58,7 +58,7 @@ camellia_setkey(void *c, const byte *key, unsigned keylen)
static int initialized=0;
static const char *selftest_failed=NULL;
if(keylen!=32)
if(keylen!=16 && keylen!=32)
return G10ERR_WRONG_KEYLEN;
if(!initialized)
@ -117,14 +117,22 @@ static const char *
selftest(void)
{
CAMELLIA_context ctx;
byte scratch[16];
/* These test vectors are from RFC-3713 */
const byte plaintext[]=
{
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10
};
const byte key_128[]=
{
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10
};
const byte ciphertext_128[]=
{
0x67,0x67,0x31,0x38,0x54,0x96,0x69,0x73,
0x08,0x57,0x06,0x56,0x48,0xea,0xbe,0x43
};
const byte key_256[]=
{
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,
@ -136,14 +144,23 @@ selftest(void)
0x9a,0xcc,0x23,0x7d,0xff,0x16,0xd7,0x6c,
0x20,0xef,0x7c,0x91,0x9e,0x3a,0x75,0x09
};
byte scratch[sizeof(plaintext)];
camellia_setkey(&ctx,key_128,sizeof(key_128));
camellia_encrypt(&ctx,scratch,plaintext);
if(memcmp(scratch,ciphertext_128,sizeof(scratch))!=0)
return "CAMELLIA128 test encryption failed.";
camellia_decrypt(&ctx,scratch,scratch);
if(memcmp(scratch,plaintext,sizeof(scratch))!=0)
return "CAMELLIA128 test decryption failed.";
camellia_setkey(&ctx,key_256,sizeof(key_256));
camellia_encrypt(&ctx,scratch,plaintext);
if(memcmp(scratch,ciphertext_256,sizeof(ciphertext_256))!=0)
return "CAMELLIA-256 test encryption failed.";
if(memcmp(scratch,ciphertext_256,sizeof(scratch))!=0)
return "CAMELLIA256 test encryption failed.";
camellia_decrypt(&ctx,scratch,scratch);
if(memcmp(scratch,plaintext,sizeof(plaintext))!=0)
return "CAMELLIA-256 test decryption failed.";
if(memcmp(scratch,plaintext,sizeof(scratch))!=0)
return "CAMELLIA256 test decryption failed.";
return NULL;
}
@ -156,7 +173,6 @@ camellia_get_info(int algo, size_t *keylen,
void (**r_decrypt)(void *c, byte *outbuf, const byte *inbuf)
)
{
*keylen = 256;
*blocksize = CAMELLIA_BLOCK_SIZE;
*contextsize = sizeof (CAMELLIA_context);
@ -164,8 +180,16 @@ camellia_get_info(int algo, size_t *keylen,
*r_encrypt = camellia_encrypt;
*r_decrypt = camellia_decrypt;
if(algo==CIPHER_ALGO_CAMELLIA)
return "CAMELLIA";
return NULL;
if(algo==CIPHER_ALGO_CAMELLIA128)
{
*keylen = 128;
return "CAMELLIA128";
}
else if(algo==CIPHER_ALGO_CAMELLIA256)
{
*keylen = 256;
return "CAMELLIA256";
}
else
return NULL;
}

View File

@ -178,7 +178,18 @@ setup_cipher_table(void)
i++;
#ifdef USE_CAMELLIA
cipher_table[i].algo = CIPHER_ALGO_CAMELLIA;
cipher_table[i].algo = CIPHER_ALGO_CAMELLIA128;
cipher_table[i].name = camellia_get_info( cipher_table[i].algo,
&cipher_table[i].keylen,
&cipher_table[i].blocksize,
&cipher_table[i].contextsize,
&cipher_table[i].setkey,
&cipher_table[i].encrypt,
&cipher_table[i].decrypt );
if( !cipher_table[i].name )
BUG();
i++;
cipher_table[i].algo = CIPHER_ALGO_CAMELLIA256;
cipher_table[i].name = camellia_get_info( cipher_table[i].algo,
&cipher_table[i].keylen,
&cipher_table[i].blocksize,

View File

@ -1,3 +1,7 @@
2007-11-29 David Shaw <dshaw@jabberwocky.com>
* cipher.h: Add the 128-bit variant of Camellia.
2007-10-23 Werner Koch <wk@g10code.com>
Switched entire package to GPLv3+.

View File

@ -36,7 +36,8 @@
#define CIPHER_ALGO_AES192 8
#define CIPHER_ALGO_AES256 9
#define CIPHER_ALGO_TWOFISH 10 /* twofish 256 bit */
#define CIPHER_ALGO_CAMELLIA 11 /* camellia 256 bit */
#define CIPHER_ALGO_CAMELLIA128 11
#define CIPHER_ALGO_CAMELLIA256 12
#define CIPHER_ALGO_DUMMY 110 /* no encryption at all */