Skip to main content
Folmer Brem N�hr
Associate
December 7, 2016
Solved

How to handle padding with STM32 Cryptographic Library

  • December 7, 2016
  • 5 replies
  • 1875 views
Posted on December 07, 2016 at 15:40

I am writing an application in C# that AES-encrypts some data that is then decrypted inside an STM32 using STM32 Cryptographic Library. My C#-class (

https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndael(v=vs.110).aspx

) can encrypt using different types of padding (ANSIX923, ISO10126, PKCS7 and with zeros). I have not found a way to specify the padding for the function in the 

STM32 Cryptographic Library.

Right now, my decryption fails because of padding-issues.

I use AES 128-bit, CBC-mode.

What padding is used in STM32 Cryptographic Library?

How to I change the padding mode?

Thanks

    This topic has been closed for replies.
    Best answer by Imen.D
    Posted on December 09, 2016 at 16:34

    Hello

    Brem_N_hr.Folmer

    ,

    In fact the following note on the

    http://www.st.com/content/ccc/resource/technical/document/user_manual/group0/f9/6e/f2/a2/b4/ec/49/c0/DM00215061/files/DM00215pdf/jcr:content/translations/en.DM00215pdf

    specify this:

    * In case of a call where P_inputSize is greater than 16 and not multiple of 16,

    Cipher-text

    Stealing will be activated.

    Accordingly, we don't use padding, we use ciphertext stealing as the mode 'CBC-CS2' specified in NIST SP 800-38A.

    This mode doesn't modify the plaintext if it's already a multiple of 16 bytes.

    So, if the customer needs to implement its own padding, this can be done, provided the output of the customer's padding function gives an output multiple of 16 bytes.

    Best Regards

    -Imen-

    If the response is useful, please mark it as correct. Thank you for yourcontribution

    5 replies

    ST Technical Moderator
    December 7, 2016
    Posted on December 07, 2016 at 16:55

    Dear

    folmerbrem

    ‌,

    Why do you need use the padding ?Would you please specify the message size that you want to encrypt ?

    Best Regards

    -Imen-

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Folmer Brem N�hr
    Associate
    December 7, 2016
    Posted on December 07, 2016 at 17:00

    I need it as the data from the C# application is padded. It can choose between 

    ANSIX923, ISO10126, PKCS7 and with zeros.

    Is this something that I need to implement myself or is there some way to use padding inside the library?

    The message size is anywhere from 16bytes to many megabytes

    Tesla DeLorean
    Guru
    December 7, 2016
    Posted on December 07, 2016 at 18:40

    Are you using an STM32 with CRYPT hardware? A review of the hardware implementation should provide some insight.

    Beyond simplistic implementation, you'd do a lot better compiling your own library from source you can understand and inspect.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..