add main header file

This commit is contained in:
GRISHNOV
2020-11-17 19:32:34 +03:00
commit 7ecd396449

49
include/PKCS7.h Normal file
View File

@@ -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