[botan-devel] Porting from 1.8 to 1.10: What happened to min_keylength_of etc.?

Jack Lloyd lloyd at randombit.net
Mon Mar 21 12:03:23 EDT 2011


Hi Bernhard,

Having gone back and looked at my reasoning for removing them, I'm not
sure it make sense to break working code for this.

I've reverted that change and added these functions back for 1.9.16.

Attached is a patch you can use for your 1.9.15 build.

-Jack

On Mon, Mar 21, 2011 at 04:38:13PM +0100, Bernhard Rosenkraenzer wrote:
> Hi,
> now that 1.10 is approaching, I've started to port everything we're shipping in Ark Linux to it.
> Most of the time, it's pretty painless - I've just run into one piece of code I don't know how to port - it uses
> 
> Botan::min_keylength_of("algorithm name")
> Botan::max_keylength_of("algorithm name")
> Botan::keylength_multiple_of("algorithm name")
> 
> This probably has to use a Key_Length_Specification these days, but how do I get the Key_Length_Specification from just knowing the algorithm type?
> 
> ttyl
> bero
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://lists.randombit.net/mailman/listinfo/botan-devel
-------------- next part --------------
#
# old_revision [0d669db52a92e4cc12c22572e77bd4baac7edfe0]
#
# patch "src/libstate/lookup.cpp"
#  from [fbe4aabccadd948b173244921cd75c0d89837ee1]
#    to [b10e0aba5d6223828eed7a586d45d1e59cce9e2c]
# 
# patch "src/libstate/lookup.h"
#  from [bae0fef8bd0b1a8f80db54988c1e73cfb92a8d3c]
#    to [e8b4d039f5142c91c97621aee8ae6c68b5c14c0d]
#
============================================================
--- src/libstate/lookup.h	bae0fef8bd0b1a8f80db54988c1e73cfb92a8d3c
+++ src/libstate/lookup.h	e8b4d039f5142c91c97621aee8ae6c68b5c14c0d
@@ -299,6 +299,36 @@ BOTAN_DLL size_t output_length_of(const 
 */
 BOTAN_DLL size_t output_length_of(const std::string& algo_spec);
 
+/**
+* Find out the minimum key size of a certain symmetric algorithm.
+* @deprecated Call algorithm_factory() directly
+*
+* @param algo_spec the name of the algorithm
+* @return minimum key length of the specified algorithm
+*/
+BOTAN_DEPRECATED("Retrieve object you want and then call key_spec")
+BOTAN_DLL size_t min_keylength_of(const std::string& algo_spec);
+
+/**
+* Find out the maximum key size of a certain symmetric algorithm.
+* @deprecated Call algorithm_factory() directly
+*
+* @param algo_spec the name of the algorithm
+* @return maximum key length of the specified algorithm
+*/
+BOTAN_DEPRECATED("Retrieve object you want and then call key_spec")
+BOTAN_DLL size_t max_keylength_of(const std::string& algo_spec);
+
+/**
+* Find out the size any valid key is a multiple of for a certain algorithm.
+* @deprecated Call algorithm_factory() directly
+*
+* @param algo_spec the name of the algorithm
+* @return size any valid key is a multiple of
+*/
+BOTAN_DEPRECATED("Retrieve object you want and then call key_spec")
+BOTAN_DLL size_t keylength_multiple_of(const std::string& algo_spec);
+
 }
 
 #endif
============================================================
--- src/libstate/lookup.cpp	fbe4aabccadd948b173244921cd75c0d89837ee1
+++ src/libstate/lookup.cpp	b10e0aba5d6223828eed7a586d45d1e59cce9e2c
@@ -62,6 +62,63 @@ size_t output_length_of(const std::strin
    }
 
 /*
+* Query the minimum allowed key length of an algorithm implementation
+*/
+size_t min_keylength_of(const std::string& name)
+   {
+   Algorithm_Factory& af = global_state().algorithm_factory();
+
+   if(const BlockCipher* bc = af.prototype_block_cipher(name))
+      return bc->key_spec().minimum_keylength();
+
+   if(const StreamCipher* sc = af.prototype_stream_cipher(name))
+      return sc->key_spec().minimum_keylength();
+
+   if(const MessageAuthenticationCode* mac = af.prototype_mac(name))
+      return mac->key_spec().minimum_keylength();
+
+   throw Algorithm_Not_Found(name);
+   }
+
+/*
+* Query the maximum allowed keylength of an algorithm implementation
+*/
+size_t max_keylength_of(const std::string& name)
+   {
+   Algorithm_Factory& af = global_state().algorithm_factory();
+
+   if(const BlockCipher* bc = af.prototype_block_cipher(name))
+      return bc->key_spec().maximum_keylength();
+
+   if(const StreamCipher* sc = af.prototype_stream_cipher(name))
+      return sc->key_spec().maximum_keylength();
+
+   if(const MessageAuthenticationCode* mac = af.prototype_mac(name))
+      return mac->key_spec().maximum_keylength();
+
+   throw Algorithm_Not_Found(name);
+   }
+
+/*
+* Query the number of byte a valid key must be a multiple of
+*/
+size_t keylength_multiple_of(const std::string& name)
+   {
+   Algorithm_Factory& af = global_state().algorithm_factory();
+
+   if(const BlockCipher* bc = af.prototype_block_cipher(name))
+      return bc->key_spec().keylength_multiple();
+
+   if(const StreamCipher* sc = af.prototype_stream_cipher(name))
+      return sc->key_spec().keylength_multiple();
+
+   if(const MessageAuthenticationCode* mac = af.prototype_mac(name))
+      return mac->key_spec().keylength_multiple();
+
+   throw Algorithm_Not_Found(name);
+   }
+
+/*
 * Get a cipher object
 */
 Keyed_Filter* get_cipher(const std::string& algo_spec,


More information about the botan-devel mailing list