commit 7ecd39644988c390f44d0c92d700b285d27d46fb Author: GRISHNOV Date: Tue Nov 17 19:32:34 2020 +0300 add main header file diff --git a/include/PKCS7.h b/include/PKCS7.h new file mode 100644 index 0000000..d5b74dd --- /dev/null +++ b/include/PKCS7.h @@ -0,0 +1,49 @@ +#ifndef PKCS7_H +#define PKCS7_H + +/* + Examples of commonly used block sizes for data padding. + WARNING: block size for PKCS7 padding can be 0 < BLOCK_SIZE < 256 bytes. +*/ +typedef enum { + BLOCK_SIZE_128_BIT = 128 / 8, /* 16 bytes block */ + BLOCK_SIZE_256_BIT = 256 / 8, /* 32 bytes block */ + BLOCK_SIZE_CUSTOM_VALUE = 0 /* you can set your own constant to use */ +} paddingBlockSize; /* can be used as third argument to the function addPadding() */ + + +/* + A pointer to this structure is returned from the function addPadding(). + The structure contains result of adding PKCS7 padding. +*/ +typedef struct { + void* dataWithPadding; /* result of adding padding to the data */ + unsigned char dataLengthWithPadding; /* length of the result */ + unsigned char valueOfByteForPadding; /* used for padding byte value */ +} PKCS7_Padding; + +/* + Applies PKCS7 padding to data. + Your data at the provided address does not change. A copy is created, to which the adding padding is applied. + WARNING: use only 0 < BLOCK_SIZE < 256 +*/ +PKCS7_Padding* addPadding(const void* const data, const unsigned int dataLength, const unsigned char BLOCK_SIZE); + + +/* + A pointer to this structure is returned from the function removePadding(). + The structure contains result of removing PKCS7 padding. +*/ +typedef struct { + void* dataWithoutPadding; /* result of remove padding from data */ + unsigned char dataLengthWithoutPadding; /* length of the result */ + unsigned char valueOfRemovedByteFromData; /* value of byte that was used for padding */ +} PKCS7_unPadding; + +/* + Remove PKCS7 padding from data. + Your data at the provided address does not change. A copy is created, to which the removing padding is applied. +*/ +PKCS7_unPadding* removePadding(const void* const data, const unsigned int dataLength); + +#endif // PKCS7_H \ No newline at end of file