Doing AES OFB with ECB ??

9 views
Skip to first unread message

Robert Bielik

unread,
Apr 7, 2011, 4:22:47 AM4/7/11
to Crypto++ Users
A little off-topic, although I don't know where else to ask ;)

To my great dismay, .NET does not have OFB cipher mode available in
the Rinjdael implementation, however looking at Wikipedia (OFB), I
should be able to use ECB with the following scheme:

Rijndael alg = new Rinjdael();
alg.KeySize=16;
alg.Mode = CipherMode.ECB;
byte[] block = new byte[16];
ICryptoTransform t = alg.CreateEncryptor(key, block);
Buffer.BlockCopy(iv, 0, block, 0, 16); // copy iv to block to start
up
len = inputStream.Length;
while (len > 0)
{
byte[] inputBlock = new byte[16];
int n = inputStream.Read(inputBlock, 0, 16);
for (int i = 0; i < n; ++i)
{
// Do the XOR
block[i] ^= inputBlock[i];
}
outputStream.Write(block, 0, block.Length);
len -= n;
}

???

TIA
/Rob

Robert Bielik

unread,
Apr 7, 2011, 4:28:59 AM4/7/11
to Crypto++ Users
Ah, spotted a mistake. I put back the XORed block into next
encryption, whereas I should put back the non-XORed block...

/Rob

Vishal Rao

unread,
Apr 7, 2011, 4:45:54 AM4/7/11
to Robert Bielik, Crypto++ Users
> --
> You received this message because you are subscribed to the "Crypto++ Users" Google Group.
> To unsubscribe, send an email to cryptopp-user...@googlegroups.com.
> More information about Crypto++ and this group is available at http://www.cryptopp.com.

Isn't ECB unsafe? [1] Or does XOR-ing work around the leak problem?

See the image of Tux in the ECB section of [1]
http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation

- Vishal

--
"The World is a book, and those who do not travel read only a page." -
St. Augustine.

Robert Bielik

unread,
Apr 7, 2011, 4:55:20 AM4/7/11
to Vishal Rao, Crypto++ Users
Vishal Rao skrev 2011-04-07 10:45:
>> More information about Crypto++ and this group is available at http://www.cryptopp.com.
>
> Isn't ECB unsafe? [1] Or does XOR-ing work around the leak problem?

Yes, using plain ECB I think would be unsafe. But in all modes, whether ECB, CBC, CFG etc... the actual block cipher is the
same is it not ? And the block cipher pretty much _is_ ECB. So I guess the XOR + propagation of encryption block is what
"does it" :)

/Rob


Robert Bielik

unread,
Apr 7, 2011, 5:44:59 AM4/7/11
to Crypto++ Users
Oki, it works! :)
Reply all
Reply to author
Forward
0 new messages