Code Monkey home page Code Monkey logo

Comments (3)

prochat avatar prochat commented on June 9, 2024

from arduinolibs.

fralomb avatar fralomb commented on June 9, 2024

@prochat probably i did not explain my doubt very well.. i cannot find a mechanism in the library which add a specified padding to a block of data that isn't a multiple of the block size of a specified algorithm. Is there a way in the library to accomplish this or i have to specify this by myself? In the first case, can explain me how i can do it? Thanks.

from arduinolibs.

rweather avatar rweather commented on June 9, 2024

Hi there. The hash algorithms have in-built padding support compatible with their respective standards. Nothing special needs to be done for them.

I assume that you are referring to padding for block ciphers in CBC mode. There is no explicit support for padding in the Crypto library because there are many different padding schemes - pad with zeroes, pad with a byte set to N if there are N padding bytes, pad with a 1 bit followed by a zero bit and finally a 1 bit. Which one?

Also, dealing with the last block in CBC mode is a pain in the neck for both encryption and decryption, as an extra block needs to be added if the plaintext was block-aligned to begin with. So it was easier to say "the application pads the data itself and then passes the block-aligned data into the CBC mode".

In any case, CBC mode is not recommended for new designs as it is difficult to make the padding have constant-time behaviour. It is better to use CTR mode which doesn't require padding. Or better yet, EAX mode for encryption and authentication (AEAD).

If you do still want to use CBC mode, then you'll have to pad the block yourself before passing it to the library for encryption, and remove the padding yourself after decryption.

from arduinolibs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.