[Botan-devel] Re: Stream cipher operations

Carlton Davis carlton at cs.mcgill.ca
Wed Oct 12 17:50:03 EDT 2005


Jack

Thanks for your prompt response. What you indicated below makes
perfect sense. I was trying to mimic two network nodes: one
encrypts a 16-bit flag and the other decrypts it. Yes, they
will indeed use two different cipher objects; so, it retrospect,
my code didn't really reflect what I was trying to do.

Thanks again and best regards,

-Carlton

-----------------------------------------------------------------
On Wed, 12 Oct 2005 Jack wrote:

Stream ciphers are stateful, and for most stream ciphers, encryption and
decryption are the same operation. So you actually didn't encrypt and
decrypt
the message in the code below, you encrypted it twice.

While those semantics are somewhat confusing, the alternative would be
that
each stream cipher object has two full states, one for encryption and one
for
decryption, and the object uses different states depending on if it is
encrypting or decrypting. And in fact in this case that's how you would do
it;
create two stream cipher objects, key them both, and use one to encrypt
and one
to decrypt. As far as I can tell, the case where a single process needs to
both
encrypt and decrypt with a stream cipher using the same key in each
direction
is pretty rare, which is why it is not supported directly.



On Wed, 12 Oct 2005, Carlton Davis wrote:

> Thanks for your feedback on my previous messages.
> I did some testing on stream cipher operations, but
> it seems as if I am doing something wrong. Here is the code:
>
>   std::string passphrase = "testing"
>   LibraryInitializer init;
>   //Just testing here: a quick insecure way of getting a 128-bit key
>   HashFunction* hash = get_hash("MD5");
>   SymmetricKey skey = hash->process(passphrase)
>   StreamCipher* cipher = get_stream_cipher("WiderWake4+1-BE");
>   cipher->set_key(skey);
>
>   unsigned short flag = 4;
>   for (i = 0; i != sizeof(flag); i++)
>     buf[i] = get_byte(i, flag);
>
>   fprintf(stderr, "\nThe byte values are %x and %x\n",
>           buf[0], buf[1]);
>   cipher->encrypt(buf, 2);
>   cipher->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);
> --
>
> I was expecting to get the same byte values after the
> encryption/decryption operations, but here is the output:
> -----
> The byte values are 0 and 4
>
> After decryption, the byte values are 6a and 46
>
> The decrypted number is: 27206
> -----
>
> What am I doing wrong?
>
> Thanks and best regards,
>
> -Carlton
>
>



More information about the botan-devel mailing list