2016-12-07 06:40 AM
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 theSTM32 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
Solved! Go to Solution.
2016-12-09 08:34 AM
Hello
Brem_N_hr.Folmer
, In fact the following note on the 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
2016-12-07 07:55 AM
Dear
folmerbrem
,Why do you need use the padding ?Would you please specify the message size that you want to encrypt ?
Best Regards
-Imen-
2016-12-07 08:00 AM
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
2016-12-07 10:40 AM
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.
2016-12-09 08:34 AM
Hello
Brem_N_hr.Folmer
, In fact the following note on the 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
2016-12-09 09:12 AM
So realistically, you need to packetize/decompose larger transfers into manageable lengths divisible by 16, and special case the last 0..15 bytes of such a transfer.
:)
If a response is useful/helpful mark it as such, mark it as correct if it answers the original question accurately, correctly, satisfactorily and completely.