[svn] GnuPG - r4633 - in branches/STABLE-BRANCH-1-4: cipher include
svn author dshaw
cvs at cvs.gnupg.org
Thu Nov 29 15:51:10 CET 2007
Author: dshaw
Date: 2007-11-29 15:51:08 +0100 (Thu, 29 Nov 2007)
New Revision: 4633
Modified:
branches/STABLE-BRANCH-1-4/cipher/ChangeLog
branches/STABLE-BRANCH-1-4/cipher/camellia-glue.c
branches/STABLE-BRANCH-1-4/cipher/cipher.c
branches/STABLE-BRANCH-1-4/include/ChangeLog
branches/STABLE-BRANCH-1-4/include/cipher.h
Log:
Add 128-bit variant of Camellia.
Modified: branches/STABLE-BRANCH-1-4/cipher/ChangeLog
===================================================================
--- branches/STABLE-BRANCH-1-4/cipher/ChangeLog 2007-11-28 23:08:35 UTC (rev 4632)
+++ branches/STABLE-BRANCH-1-4/cipher/ChangeLog 2007-11-29 14:51:08 UTC (rev 4633)
@@ -1,3 +1,8 @@
+2007-11-29 David Shaw <dshaw at 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 at jabberwocky.com>
* sha256.c (sha224_get_info): 4880 has an error in the SHA-224 OID
Modified: branches/STABLE-BRANCH-1-4/cipher/camellia-glue.c
===================================================================
--- branches/STABLE-BRANCH-1-4/cipher/camellia-glue.c 2007-11-28 23:08:35 UTC (rev 4632)
+++ branches/STABLE-BRANCH-1-4/cipher/camellia-glue.c 2007-11-29 14:51:08 UTC (rev 4633)
@@ -58,7 +58,7 @@
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 @@
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 @@
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 @@
void (**r_decrypt)(void *c, byte *outbuf, const byte *inbuf)
)
{
- *keylen = 256;
*blocksize = CAMELLIA_BLOCK_SIZE;
*contextsize = sizeof (CAMELLIA_context);
@@ -164,8 +180,16 @@
*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;
}
Modified: branches/STABLE-BRANCH-1-4/cipher/cipher.c
===================================================================
--- branches/STABLE-BRANCH-1-4/cipher/cipher.c 2007-11-28 23:08:35 UTC (rev 4632)
+++ branches/STABLE-BRANCH-1-4/cipher/cipher.c 2007-11-29 14:51:08 UTC (rev 4633)
@@ -178,7 +178,7 @@
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,
@@ -189,6 +189,17 @@
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,
+ &cipher_table[i].contextsize,
+ &cipher_table[i].setkey,
+ &cipher_table[i].encrypt,
+ &cipher_table[i].decrypt );
+ if( !cipher_table[i].name )
+ BUG();
+ i++;
#endif
#ifdef USE_IDEA
Modified: branches/STABLE-BRANCH-1-4/include/ChangeLog
===================================================================
--- branches/STABLE-BRANCH-1-4/include/ChangeLog 2007-11-28 23:08:35 UTC (rev 4632)
+++ branches/STABLE-BRANCH-1-4/include/ChangeLog 2007-11-29 14:51:08 UTC (rev 4633)
@@ -1,3 +1,7 @@
+2007-11-29 David Shaw <dshaw at jabberwocky.com>
+
+ * cipher.h: Add the 128-bit variant of Camellia.
+
2007-10-23 Werner Koch <wk at g10code.com>
Switched entire package to GPLv3+.
Modified: branches/STABLE-BRANCH-1-4/include/cipher.h
===================================================================
--- branches/STABLE-BRANCH-1-4/include/cipher.h 2007-11-28 23:08:35 UTC (rev 4632)
+++ branches/STABLE-BRANCH-1-4/include/cipher.h 2007-11-29 14:51:08 UTC (rev 4633)
@@ -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 */
More information about the Gnupg-commits
mailing list