From aa83760418f5ed5ce35a9add6517b2ca98ccb5bd Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Wed, 22 Mar 2023 16:44:03 +0100 Subject: Add crypto sources for future use. * the goal is to support AES-CBC-HMAC-SHA as AEAD cipher Signed-off-by: Toni Uhlig --- crypto/pkcs7_padding.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 crypto/pkcs7_padding.h (limited to 'crypto/pkcs7_padding.h') diff --git a/crypto/pkcs7_padding.h b/crypto/pkcs7_padding.h new file mode 100644 index 0000000..bdd6c21 --- /dev/null +++ b/crypto/pkcs7_padding.h @@ -0,0 +1,24 @@ +#ifndef _PKCS7_PADDING_H_ +#define _PKCS7_PADDING_H_ + +#include +#include + +/* Pad a buffer with bytes as defined in PKCS#7 + * Returns the number of pad bytes added, or zero if + * the buffer size is not large enough to hold the correctly padded data + */ +int pkcs7_padding_pad_buffer( uint8_t *buffer, size_t data_length, size_t buffer_size, uint8_t modulus ); + +int pkcs7_padding_valid( uint8_t *buffer, size_t data_length, size_t buffer_size, uint8_t modulus ); + +/* Given a block of pkcs7 padded data, return the actual data length in the block based on the padding applied. + * buffer_size must be a multiple of modulus + * last byte 'x' in buffer must be between 1 and modulus + * buffer_size must be at least x + 1 in size + * last 'x' bytes in buffer must be same as 'x' + * returned size will be buffer_size - 'x' + */ +size_t pkcs7_padding_data_length( uint8_t * buffer, size_t buffer_size, uint8_t modulus ); + +#endif \ No newline at end of file -- cgit v1.2.3