aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2007-11-29 14:51:08 +0000
committerDavid Shaw <[email protected]>2007-11-29 14:51:08 +0000
commitbc15e25d7abc9c22053ee2cdb732ad74905e414f (patch)
tree53d7cb256677036f2c8dbb81b66c5d09f7666383
parent* sig-check.c (do_check): Code to try both the incorrect and correct (diff)
downloadgnupg-bc15e25d7abc9c22053ee2cdb732ad74905e414f.tar.gz
gnupg-bc15e25d7abc9c22053ee2cdb732ad74905e414f.zip
Add 128-bit variant of Camellia.
-rw-r--r--cipher/ChangeLog5
-rw-r--r--cipher/camellia-glue.c48
-rw-r--r--cipher/cipher.c13
-rw-r--r--include/ChangeLog4
-rw-r--r--include/cipher.h3
5 files changed, 59 insertions, 14 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 0895cc81a..07ab5bdcf 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-29 David Shaw <[email protected]>
+
+ * camellia-glue.c (camellia_get_info), cipher.c
+ (setup_cipher_table): Add 128-bit variant of Camellia.
+
2007-11-28 David Shaw <[email protected]>
* sha256.c (sha224_get_info): 4880 has an error in the SHA-224 OID
diff --git a/cipher/camellia-glue.c b/cipher/camellia-glue.c
index 2a6f553c1..aeaa722a5 100644
--- a/cipher/camellia-glue.c
+++ b/cipher/camellia-glue.c
@@ -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;
}
diff --git a/cipher/cipher.c b/cipher/cipher.c
index c8ebb7574..a6489d9f5 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -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,
diff --git a/include/ChangeLog b/include/ChangeLog
index 1ef67dbdd..4cfd4b8bf 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,7 @@
+2007-11-29 David Shaw <[email protected]>
+
+ * cipher.h: Add the 128-bit variant of Camellia.
+
2007-10-23 Werner Koch <[email protected]>
Switched entire package to GPLv3+.
diff --git a/include/cipher.h b/include/cipher.h
index 543f1665a..73db8fde4 100644
--- a/include/cipher.h
+++ b/include/cipher.h
@@ -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 */