summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2008-04-18 11:20:25 +0200
committerWerner Koch <wk@gnupg.org>2008-04-18 11:20:25 +0200
commit4896f5f47c1a58a4ee81c1ce1ef879fd3156bbe7 (patch)
treefb2741341342ef10c52ef1f345eef45eda8defe0 /g10
parentTest commit (diff)
downloadgnupg2-4896f5f47c1a58a4ee81c1ce1ef879fd3156bbe7.tar.xz
gnupg2-4896f5f47c1a58a4ee81c1ce1ef879fd3156bbe7.zip
Adjust for the changed Camellia draft.
W32 gettext changes. Comment and typo fixes.
Diffstat (limited to 'g10')
-rw-r--r--g10/ChangeLog7
-rw-r--r--g10/main.h1
-rw-r--r--g10/misc.c35
-rw-r--r--g10/parse-packet.c14
4 files changed, 42 insertions, 15 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 0edfb7a28..b7c3d1d50 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-18 Werner Koch <wk@g10code.com>
+
+ * misc.c (map_cipher_openpgp_to_gcry, map_cipher_gcry_to_openpgp)
+ (openpgp_cipher_test_algo): Add camellia-192.
+ (openpgp_cipher_blocklen): New.
+ * parse-packet.c (parse_key): Use new function here.
+
2008-04-15 David Shaw <dshaw@jabberwocky.com>
* getkey.c (merge_selfsigs_subkey): If there are multiple 0x19
diff --git a/g10/main.h b/g10/main.h
index bf3df6417..179c06757 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -82,6 +82,7 @@ u16 checksum( byte *p, unsigned n );
u16 checksum_mpi( gcry_mpi_t a );
u32 buffer_to_u32( const byte *buffer );
const byte *get_session_marker( size_t *rlen );
+int openpgp_cipher_blocklen (int algo);
int openpgp_cipher_test_algo( int algo );
const char *openpgp_cipher_algo_name (int algo);
int openpgp_pk_test_algo( int algo );
diff --git a/g10/misc.c b/g10/misc.c
index 233c40264..2e2c70722 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -1,6 +1,6 @@
/* misc.c - miscellaneous functions
- * 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.
*
@@ -338,6 +338,7 @@ map_cipher_openpgp_to_gcry (int algo)
switch (algo)
{
case CIPHER_ALGO_CAMELLIA128: return 310;
+ case CIPHER_ALGO_CAMELLIA192: return 311;
case CIPHER_ALGO_CAMELLIA256: return 312;
default: return algo;
}
@@ -350,11 +351,36 @@ map_cipher_gcry_to_openpgp (int algo)
switch (algo)
{
case 310: return CIPHER_ALGO_CAMELLIA128;
+ case 311: return CIPHER_ALGO_CAMELLIA192;
case 312: return CIPHER_ALGO_CAMELLIA256;
default: return algo;
}
}
+
+/* Return the block length of an OpenPGP cipher algorithm. */
+int
+openpgp_cipher_blocklen (int algo)
+{
+ /* We use the numbers from OpenPGP to be sure that we get the right
+ block length. This is so that the packet parsing code works even
+ for unknown algorithms (for which we assume 8 due to tradition).
+
+ NOTE: If you change the the returned blocklen above 16, check
+ the callers because they may use a fixed size buffer of that
+ size. */
+ switch (algo)
+ {
+ case 7: case 8: case 9: /* AES */
+ case 10: /* Twofish */
+ case 11: case 12: case 13: /* Camellia */
+ return 16;
+
+ default:
+ return 8;
+ }
+}
+
/****************
* Wrapper around the libgcrypt function with additonal checks on
* the OpenPGP contraints for the algo ID.
@@ -370,7 +396,8 @@ openpgp_cipher_test_algo( int algo )
requested. */
#ifndef USE_CAMELLIA
if (algo == CIPHER_ALGO_CAMELLIA128
- || algo == CIPHER_ALGO_CAMELLIA256)
+ || algo == CIPHER_ALGO_CAMELLIA192
+ || algo == CIPHER_ALGO_CAMELLIA256)
return gpg_error (GPG_ERR_CIPHER_ALGO);
#endif
@@ -386,8 +413,6 @@ openpgp_cipher_algo_name (int algo)
return gcry_cipher_algo_name (map_cipher_openpgp_to_gcry (algo));
}
-
-
int
openpgp_pk_test_algo( int algo )
{
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index 409daab09..dbaa27886 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -1901,19 +1901,13 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen,
* of the IV here in cases we are not aware of the algorithm.
* so a
* sk->protect.ivlen = cipher_get_blocksize(sk->protect.algo);
- * won't work. The only solution I see is to hardwire it here.
+ * won't work. The only solution I see is to hardwire it.
* NOTE: if you change the ivlen above 16, don't forget to
* enlarge temp.
*/
- switch( sk->protect.algo ) {
- case 7: case 8: case 9: /* AES */
- case 10: /* Twofish */
- case 11: case 12: /* Camellia */
- sk->protect.ivlen = 16;
- break;
- default:
- sk->protect.ivlen = 8;
- }
+ sk->protect.ivlen = openpgp_cipher_blocklen (sk->protect.algo);
+ assert (sk->protect.ivlen <= sizeof (temp));
+
if( sk->protect.s2k.mode == 1001 )
sk->protect.ivlen = 0;
else if( sk->protect.s2k.mode == 1002 )