[Botan-devel] Re: Stream cipher operations

Carlton Davis carlton at cs.mcgill.ca
Thu Oct 13 17:35:21 EDT 2005


Thanks again Jack for your prompt response. What you
suggested did fix the problem as usual. I am curious
to know though, the reason why
SecureVector<byte> ciphertext = enc->encrypt(bits,sizeof(bits));
where bits is a SecureVector<byte>
works, whereas for the decryption process
SecureVector<byte> size() function needs to be used instead of
sizeof(SecureVector<byte>).

Best regards,

-Carlton


On Thu, 13 Oct 2005, Jack wrote:

This should be ciphertext.size(), not sizeof(ciphertext). In the call, the
ciphertext is truncated so you get a basically random number as the
output. Since you're using Raw encoding here, this wasn't detected as an
encoding error as it would if you were using OAEP or PKCS #1 v1.5. So the
value
of plaintext iends up being a random integer less than n, which will
usually
end up being around the modulus size (in this case, 1024 bits, or 128
bytes),
and WiderWAKE only supports 128-bit keys so it blows up when you try to
pass
this to set_key.

On Thu, 13 Oct 2005, Carlton Davis wrote:

> I ran into another issue during some additional test
> involving some stream cipher operations. Essentially,
> I want to generate a symmetric key or octet string
> on a network node, encrypts the symmetric key with
> nodeB public key, and sends the encrypted key to nodeB.
> I use the code below to test the above operation
> and I got the following:
> ---
>
> "terminate called after throwing an instance of
> 'Botan::Invalid_Key_Length'
>   what():  Botan: WiderWake4+1-BE cannot accept a key of length 128
> Abort trap"
>
> --
>
> Here is the code:
>
>   std::string passphrase = "testing";
>   //Just testing here: a quick insecure way of getting a 128-bit key
>   HashFunction* hash = get_hash("MD5");
>   SymmetricKey skey = hash->process(passphrase);
>
>   unsigned short flag = 4;
>   for (i = 0; i != sizeof(flag); i++)
>     buf[i] = get_byte(i, flag);
>   fprintf(stderr, "\nThe number is: %i\n", make_u16bit(buf[0], buf[1]));
>
>   StreamCipher* cipher = get_stream_cipher("WiderWake4+1-BE");
>   cipher->set_key(skey);  //This is fine
>   cipher->encrypt(buf, 2);
>
>   SecureVector<byte> bits = skey.bits_of();
>   PK_Encryptor* enc = get_pk_encryptor(*pubkey, "Raw");
>   SecureVector<byte> ciphertext = enc->encrypt(bits,sizeof(bits));
>
>   PK_Decryptor* dec = get_pk_decryptor(*privkey, "Raw");
>   SecureVector<byte> plaintext = dec->decrypt(ciphertext, sizeof(ciphertext));
>
>   StreamCipher* cipher2 = get_stream_cipher("WiderWake4+1-BE");
>   //The prblem is this set_key operation
>   cipher2->set_key(SymmetricKey(plaintext));
>   cipher2->decrypt(buf, 2);
>
>   fprintf(stderr, "\nAfter decryption, the byte values are %x and %x\n",
> 	  buf[0], buf[1]);
>   unsigned short decryptflag = make_u16bit(buf[0], buf[1]);
>   fprintf(stderr, "\nThe decrypted number is: %i\n", decryptflag);
> ---
>
> Any idea why WiderWake4+1 is not accepting the SymmetricKey object
> I created?
>
> Thanks and best regards,
>
> -Carlton
>
>
>
>



More information about the botan-devel mailing list