Topic: Is it possible to use cbc block by block?

Hi,

I am looking for library which allows to do des encryption in cbc mode block by block. Is it possible to do this using wolfCrypt? I have been trying to find anything about this, but without any success.

Share

Re: Is it possible to use cbc block by block?

Hi Devyr,

The very definition of CBC (Cipher Block Chaining) mode is to use the previous encrypted block as input to the the current plain-text block + encryption and the first block uses an IV instead of the previous block as input. This is block by block in CBC mode.

Is it possible you are looking for DES ECB (Electronic Code Book) mode instead? This is encrypting just a single block at a time where the previous block is NOT used as input for the current plain-text encryption.

See:

https://en.wikipedia.org/wiki/Block_cip … _.28ECB.29

vs

https://en.wikipedia.org/wiki/Block_cip … _.28CBC.29

Let me know if you are looking for ECB mode or please describe in more detail exactly what it is you are looking to achieve.

For our curiousity could you tell us a little about what it is you are working on?


Warm Regards,

Kaleb

Re: Is it possible to use cbc block by block?

I must admit that my question was quite imprecise.

What I wanted to ask is if it is possible to encrypt large file reading it by parts and using Cbc functions like this:

wc_Des3_SetKey(&enc, key, iv, DES_ENCRYPTION);
wc_Des3_CbcEncrypt(&enc, cipher, plain, sizeof(plain));
//read another part of plaintext and write cipher to file
wc_Des3_CbcEncrypt(&enc, cipher, plain, sizeof(plain));

And if it is about ECB - does wolfSSL support this mode?

Share

4 (edited by Kaleb J. Himes 2017-12-01 10:09:19)

Re: Is it possible to use cbc block by block?

Hi Devyr,

Yes this is entirely possible. In fact we have an example of doing this in our wolfCLU (Command Line Utility). In that solution we encrypt 1K at a time with CBC and output the result to a file.

The relevant while loop can be seen at this link: https://github.com/wolfSSL/wolfssl-exam … ypt.c#L155

An example of using the command line tool once built and installed based off the README would be:

wolfssl -encrypt 3des-cbc-168 -pwd ThisIsMyPassword -in somefile.txt -out encryptedfile.txt

That would encrypt your file, 1 Kilobyte at a time using CBC mode.
You may also use that code as a reference if you are looking to develop your own solution.

If you are looking for ECB mode then yes wolfSSL does support ECB as well.


Warm Regards,

Kaleb