[Botan-devel] trivial hash example ?

Jack Lloyd lloyd at randombit.net
Mon Jul 2 15:47:58 EDT 2007


On Mon, Jul 02, 2007 at 09:43:39PM +0200, Christophe Meessen wrote:
> Hello,
> 
> I need to use a hash function but with pipes. I couldn't find info or
> examples on how to do this.
> 
> Looking into the source I found what I need in lookup.h. I guess I
> should use
> HashFunction* myHash = get_hash( "SHA-1");
> What is the purpose of retrieve_hash() ?

It returns the prototype object, which is why it is const. It is
useful if you want to look up fixed data (eg a cipher's block size),
or you can call clone() on it to get a new object (that's how
get_hash, etc, work).

If you are using filters you can also say

 Pipe pipe(...,
           new Hash_Filter("SHA-1"),
           ...);

> I also need the same for a cipher but want to use "AES-128/CFB" for
> instance.
> How do I instantiate such a cipher. Do I need to instantiate it as a
> filter ?

Two methods:
  get_cipher("AES-128/CFB", key, iv, ENCRYPTION)
or
  new CFB_Encryption("AES-128", key, iv);

both of which are Filters (and the return value of get_cipher is
actually a CFB_Encryption object, in this particular case).

> I tried have_algorithm( "AES-128/CFB(128)" ) but it returned false.

have_algorithm() only works for basic types (eg, "AES-128").

-Jack


More information about the botan-devel mailing list