summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2011-06-29 13:26:22 (GMT)
committerWerner Koch <wk@gnupg.org>2011-06-29 13:26:22 (GMT)
commit7cae9fdfc9e322941545a3a2128a5ead1010a6cf (patch)
tree81ffb01412c1ca2516444725336f0ad69f4a75cd
parentea2b4d6653b7e3f483582ee5bf1dc7de2cb0a3f9 (diff)
downloadlibgcrypt-7cae9fdfc9e322941545a3a2128a5ead1010a6cf.tar.gz
libgcrypt-7cae9fdfc9e322941545a3a2128a5ead1010a6cf.tar.xz
Fixed a bug in the gcry_cipher_get_algo_keylen and gcry_cipher_get_algo_blklen
Contrary to the documentation those functions aborted if an invalid algorithm was passed. The same happened for the corresponding subcommands of gcry_cipher_algo_info.
-rw-r--r--cipher/ChangeLog5
-rw-r--r--cipher/cipher.c19
-rw-r--r--doc/gcrypt.texi33
-rw-r--r--src/gcrypt.h.in2
4 files changed, 42 insertions, 17 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 16632f0..f061d01 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,8 @@
+2011-06-29 Werner Koch <wk@g10code.com>
+
+ * cipher.c (cipher_get_keylen): Return zero for an invalid algorithm.
+ (cipher_get_blocksize): Ditto.
+
2011-06-13 Werner Koch <wk@g10code.com>
* dsa.c (selftest_sign_1024): Use the raw and not the pkcs1 flag.
diff --git a/cipher/cipher.c b/cipher/cipher.c
index b0a532a..b99ab41 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -1,6 +1,6 @@
/* cipher.c - cipher dispatcher
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
- * 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+ * 2005, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -610,10 +610,8 @@ check_cipher_algo (int algorithm)
}
-/* Return the standard length of the key for the cipher algorithm with
- the identifier ALGORITHM. This function expects a valid algorithm
- and will abort if the algorithm is not available or the length of
- the key is not known. */
+/* Return the standard length in bits of the key for the cipher
+ algorithm with the identifier ALGORITHM. */
static unsigned int
cipher_get_keylen (int algorithm)
{
@@ -631,17 +629,13 @@ cipher_get_keylen (int algorithm)
log_bug ("cipher %d w/o key length\n", algorithm);
_gcry_module_release (cipher);
}
- else
- log_bug ("cipher %d not found\n", algorithm);
ath_mutex_unlock (&ciphers_registered_lock);
return len;
}
/* Return the block length of the cipher algorithm with the identifier
- ALGORITHM. This function expects a valid algorithm and will abort
- if the algorithm is not available or the length of the key is not
- known. */
+ ALGORITHM. This function return 0 for an invalid algorithm. */
static unsigned int
cipher_get_blocksize (int algorithm)
{
@@ -659,8 +653,6 @@ cipher_get_blocksize (int algorithm)
log_bug ("cipher %d w/o blocksize\n", algorithm);
_gcry_module_release (cipher);
}
- else
- log_bug ("cipher %d not found\n", algorithm);
ath_mutex_unlock (&ciphers_registered_lock);
return len;
@@ -2084,8 +2076,7 @@ gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes)
if ((ui > 0) && (ui <= 512))
*nbytes = (size_t) ui / 8;
else
- /* The only reason is an invalid algo or a strange
- blocksize. */
+ /* The only reason for an error is an invalid algo. */
err = GPG_ERR_CIPHER_ALGO;
}
break;
diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi
index e172ca8..1f5e6e1 100644
--- a/doc/gcrypt.texi
+++ b/doc/gcrypt.texi
@@ -1891,11 +1891,15 @@ Here is a list of supported codes for @var{what}:
Return the length of the key. If the algorithm supports multiple key
lengths, the maximum supported value is returned. The length is
returned as number of octets (bytes) and not as number of bits in
-@var{nbytes}; @var{buffer} must be zero.
+@var{nbytes}; @var{buffer} must be zero. Note that it is usually
+better to use the convenience function
+@code{gcry_cipher_get_algo_keylen}.
@item GCRYCTL_GET_BLKLEN:
Return the block length of the algorithm. The length is returned as a
-number of octets in @var{nbytes}; @var{buffer} must be zero.
+number of octets in @var{nbytes}; @var{buffer} must be zero. Note
+that it is usually better to use the convenience function
+@code{gcry_cipher_get_algo_blklen}.
@item GCRYCTL_TEST_ALGO:
Returns @code{0} when the specified algorithm is available for use.
@@ -1907,6 +1911,31 @@ Returns @code{0} when the specified algorithm is available for use.
@end deftypefun
@c end gcry_cipher_algo_info
+@deftypefun size_t gcry_cipher_get_algo_keylen (@var{algo})
+
+This function returns length of the key for algorithm @var{algo}. If
+the algorithm supports multiple key lengths, the maximum supported key
+length is returned. On error @code{0} is returned. The key length is
+returned as number of octets.
+
+This is a convenience functions which should be preferred over
+@code{gcry_cipher_algo_info} because it allows for proper type
+checking.
+@end deftypefun
+@c end gcry_cipher_get_algo_keylen
+
+@deftypefun size_t gcry_cipher_get_algo_blklen (int @var{algo})
+
+This functions returns the blocklength of the algorithm @var{algo}
+counted in octets. On error @code{0} is returned.
+
+This is a convenience functions which should be preferred over
+@code{gcry_cipher_algo_info} because it allows for proper type
+checking.
+@end deftypefun
+@c end gcry_cipher_get_algo_blklen
+
+
@deftypefun {const char *} gcry_cipher_algo_name (int @var{algo})
@code{gcry_cipher_algo_name} returns a string with the name of the
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index f67c19a..63f71c0 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -941,7 +941,7 @@ gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t hd,
gpg_error_t gcry_cipher_setctr (gcry_cipher_hd_t hd,
const void *ctr, size_t ctrlen);
-/* Retrieved the key length in bytes used with algorithm A. */
+/* Retrieve the key length in bytes used with algorithm A. */
size_t gcry_cipher_get_algo_keylen (int algo);
/* Retrieve the block length in bytes used with algorithm A. */