Add Camellia-192.

This commit is contained in:
David Shaw 2008-04-17 17:40:30 +00:00
parent 06278768b4
commit 18f6e7e5d8
7 changed files with 58 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2008-04-17 David Shaw <dshaw@jabberwocky.com>
* camellia-glue.c (selftest, camellia_get_info), cipher.c
(setup_cipher_table): Add Camellia-192.
2008-03-22 Werner Koch <wk@g10code.com>
* cipher.c (struct cipher_handle_s): Make sure IV is u32

View File

@ -1,5 +1,5 @@
/* camellia-glue.c - Glue for the Camellia cipher
* Copyright (C) 2007 Free Software Foundation, Inc.
* Copyright (C) 2007, 2008 Free Software Foundation, Inc.
*
* This file is part of GNUPG.
*
@ -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!=16 && keylen!=32)
if(keylen!=16 && keylen!=24 && keylen!=32)
return G10ERR_WRONG_KEYLEN;
if(!initialized)
@ -133,6 +133,16 @@ selftest(void)
0x67,0x67,0x31,0x38,0x54,0x96,0x69,0x73,
0x08,0x57,0x06,0x56,0x48,0xea,0xbe,0x43
};
const byte key_192[]=
{
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,0x98,
0x76,0x54,0x32,0x10,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77
};
const byte ciphertext_192[]=
{
0xb4,0x99,0x34,0x01,0xb3,0xe9,0x96,0xf8,
0x4e,0xe5,0xce,0xe7,0xd7,0x9b,0x09,0xb9
};
const byte key_256[]=
{
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xfe,0xdc,0xba,
@ -154,6 +164,14 @@ selftest(void)
if(memcmp(scratch,plaintext,sizeof(scratch))!=0)
return "CAMELLIA128 test decryption failed.";
camellia_setkey(&ctx,key_192,sizeof(key_192));
camellia_encrypt(&ctx,scratch,plaintext);
if(memcmp(scratch,ciphertext_192,sizeof(scratch))!=0)
return "CAMELLIA192 test encryption failed.";
camellia_decrypt(&ctx,scratch,scratch);
if(memcmp(scratch,plaintext,sizeof(scratch))!=0)
return "CAMELLIA192 test decryption failed.";
camellia_setkey(&ctx,key_256,sizeof(key_256));
camellia_encrypt(&ctx,scratch,plaintext);
if(memcmp(scratch,ciphertext_256,sizeof(scratch))!=0)
@ -185,6 +203,11 @@ camellia_get_info(int algo, size_t *keylen,
*keylen = 128;
return "CAMELLIA128";
}
else if(algo==CIPHER_ALGO_CAMELLIA192)
{
*keylen = 192;
return "CAMELLIA192";
}
else if(algo==CIPHER_ALGO_CAMELLIA256)
{
*keylen = 256;

View File

@ -1,6 +1,6 @@
/* cipher.c - cipher dispatcher
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
* 2007, 2008 Free Software Foundation, Inc.
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
* 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -198,6 +198,17 @@ setup_cipher_table(void)
if( !cipher_table[i].name )
BUG();
i++;
cipher_table[i].algo = CIPHER_ALGO_CAMELLIA192;
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,

View File

@ -1,3 +1,7 @@
2008-04-17 David Shaw <dshaw@jabberwocky.com>
* parse-packet.c (parse_key): Add constant for Camellia-192.
2008-04-12 David Shaw <dshaw@jabberwocky.com>
* getkey.c (merge_selfsigs_subkey): If there are multiple 0x19

View File

@ -1,6 +1,6 @@
/* parse-packet.c - read packets
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
* 2007 Free Software Foundation, Inc.
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
* 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -1856,7 +1856,7 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen,
switch( sk->protect.algo ) {
case 7: case 8: case 9: /* AES */
case 10: /* Twofish */
case 11: case 12: /* Camellia */
case 11: case 12: case 13: /* Camellia */
sk->protect.ivlen = 16;
break;
default:

View File

@ -1,3 +1,7 @@
2008-04-17 David Shaw <dshaw@jabberwocky.com>
* cipher.h: Add the 192-bit variant of Camellia.
2007-11-29 David Shaw <dshaw@jabberwocky.com>
* cipher.h: Add the 128-bit variant of Camellia.

View File

@ -1,6 +1,6 @@
/* cipher.h
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
* 2007 Free Software Foundation, Inc.
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007,
* 2008 Free Software Foundation, Inc.
*
* This file is part of GNUPG.
*
@ -37,7 +37,8 @@
#define CIPHER_ALGO_AES256 9
#define CIPHER_ALGO_TWOFISH 10 /* twofish 256 bit */
#define CIPHER_ALGO_CAMELLIA128 11
#define CIPHER_ALGO_CAMELLIA256 12
#define CIPHER_ALGO_CAMELLIA192 12
#define CIPHER_ALGO_CAMELLIA256 13
#define CIPHER_ALGO_DUMMY 110 /* no encryption at all */