[Botan-devel] Dubious MinGW error messages

Hans Mull hans72mull at aol.com
Tue Apr 22 12:42:04 EDT 2008


Jack Lloyd schrieb:
> On Mon, Apr 21, 2008 at 06:54:35PM +0200, Hans Mull wrote:
>   
>> Hi!
>> I've just startet using botan and want to encrypt a string with a string
>> password so I've modified the code from the tutorial slightly (removed
>> the DataSink stuff etc.). When using Botan 1.6.4 on
>> Win32/Code::Blocks/MinGW 5.1.3 the comppiler complains about many
>> things. This is my code:
>>     
> [...]
>   
>> Which function should I use instead the one from the tutorial? I think
>> these error messages appear because the tutorial is a bit outdated.
>> It would be kind if you help me!
>>     
>
> Hi,
>
> Yes the tutorial needs to be updated a bit for the latest
> releases. Two changes to your code are needed for Botan 1.6:
>
> When calling derive_key() you need to pass a MemoryRegion<byte> rather
> than a SymmetricKey. You can perform this conversion using bits_of:
>
>     SymmetricKey key = kdf->derive_key(20, master_key.bits_of(), "cipher key");
>     SymmetricKey mac_key = kdf->derive_key(20, master_key.bits_of(), "hmac key");
>     InitializationVector iv = kdf->derive_key(8, master_key.bits_of(), "cipher iv");
>
> Also the ptr() function of SecureVector<byte> has been renamed begin():
>
>     ctss << (const char*)the_salt.begin();
>     [...]
>     ctss << (const char*)hmac.begin();
>
> Initializing the library each time you call the function may be a bit
> expensive, BTW. It should work, but it will cause new allocations,
> entropy polls, etc to run each time you call botanEncrypt()
>
> Regards,
>   Jack
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://www.randombit.net/mailman/listinfo/botan-devel
>   
Hi,
Thanks, it works fine now. But one question:
I saw I have to Base64-encode the output (cipher and hmac output) and
for now
I've solved this by declaring a new function:

string Base64_Encode(string input)
{
    stringstream iss(input); //Input stringstream
    stringstream rss; //Return stringstream
    Pipe B64Encoder(new Base64_Encoder());
    B64Encoder.start_msg();
    iss >> B64Encoder;
    B64Encoder.end_msg();
    SecureVector<byte> b64b = B64Encoder.read_all(); //Base64 bytes
    return (const char*)b64b.begin();
}

Can I do that more efficiently in the botanEncrypt(...) pipe declaration?
Like:
Pipe pipe
    (
        new Chain(
        new Fork
        (
                get_cipher(cipher, key, iv, ENCRYPTION), new
Base64_Encoder(),
                new MAC_Filter("HMAC(SHA-1)", mac_key)
        ),new Base64_Encoder())
    );

BTW: If I'm familiar with Botan's API I will write a very-high-level C++
API for Crypto-beginners. That will make it easier hust ti encrypt a
string or so.

Best regards, Hans



More information about the botan-devel mailing list