Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e2f68c1a0 |
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
|||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -c -Wall -Wextra -Wpedantic
|
CFLAGS = -c -I include -Wall -Wextra -Wpedantic
|
||||||
|
|
||||||
all: buildProject
|
all: buildProject
|
||||||
|
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -57,7 +57,8 @@ typedef struct {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Applies PKCS7 padding to data.
|
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.
|
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
|
WARNING: use only 0 < BLOCK_SIZE < 256
|
||||||
*/
|
*/
|
||||||
PKCS7_Padding* addPadding(const void* const data, const uint64_t dataLength, const uint8_t BLOCK_SIZE);
|
PKCS7_Padding* addPadding(const void* const data, const uint64_t dataLength, const uint8_t BLOCK_SIZE);
|
||||||
@@ -78,7 +79,8 @@ typedef struct {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Remove PKCS7 padding from data.
|
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.
|
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 uint64_t dataLength);
|
PKCS7_unPadding* removePadding(const void* const data, const uint64_t dataLength);
|
||||||
```
|
```
|
||||||
@@ -96,6 +98,19 @@ typedef enum {
|
|||||||
BLOCK_SIZE_CUSTOM_VALUE = 0 /* you can set your own constant to use */
|
BLOCK_SIZE_CUSTOM_VALUE = 0 /* you can set your own constant to use */
|
||||||
} paddingBlockSize; /* can be used as third argument to the function addPadding() */
|
} paddingBlockSize; /* can be used as third argument to the function addPadding() */
|
||||||
```
|
```
|
||||||
|
When finished, use the following functions to free memory.
|
||||||
|
|
||||||
|
```C
|
||||||
|
/*
|
||||||
|
Frees the memory that was allocated for padding structure.
|
||||||
|
*/
|
||||||
|
void freePaddingResult(PKCS7_Padding* puddingResult);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Frees the memory that was allocated for unpadding structure.
|
||||||
|
*/
|
||||||
|
void freeUnPaddingResult(PKCS7_unPadding* unPuddingResult);
|
||||||
|
```
|
||||||
|
|
||||||
# Demonstration
|
# Demonstration
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef PKCS7_H
|
#ifndef PKCS7_H
|
||||||
#define PKCS7_H
|
#define PKCS7_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Examples of commonly used block sizes for data padding.
|
Examples of commonly used block sizes for data padding.
|
||||||
WARNING: block size for PKCS7 padding can be 0 < BLOCK_SIZE < 256 bytes.
|
WARNING: block size for PKCS7 padding can be 0 < BLOCK_SIZE < 256 bytes.
|
||||||
@@ -46,4 +48,15 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
PKCS7_unPadding* removePadding(const void* const data, const uint64_t dataLength);
|
PKCS7_unPadding* removePadding(const void* const data, const uint64_t dataLength);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Frees the memory that was allocated for padding structure.
|
||||||
|
*/
|
||||||
|
void freePaddingResult(PKCS7_Padding* puddingResult);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Frees the memory that was allocated for unpadding structure.
|
||||||
|
*/
|
||||||
|
void freeUnPaddingResult(PKCS7_unPadding* unPuddingResult);
|
||||||
|
|
||||||
#endif // PKCS7_H
|
#endif // PKCS7_H
|
||||||
14
src/PKCS7.c
14
src/PKCS7.c
@@ -2,7 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "./../include/PKCS7.h"
|
#include "PKCS7.h"
|
||||||
|
|
||||||
PKCS7_Padding* addPadding(const void* const data, const uint64_t dataLength, const uint8_t BLOCK_SIZE)
|
PKCS7_Padding* addPadding(const void* const data, const uint64_t dataLength, const uint8_t BLOCK_SIZE)
|
||||||
{
|
{
|
||||||
@@ -64,4 +64,16 @@ PKCS7_unPadding* removePadding(const void* const data, const uint64_t dataLength
|
|||||||
unpaddingResult->dataWithoutPadding = dataWithoutPadding;
|
unpaddingResult->dataWithoutPadding = dataWithoutPadding;
|
||||||
|
|
||||||
return unpaddingResult;
|
return unpaddingResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
void freePaddingResult(PKCS7_Padding* puddingResult)
|
||||||
|
{
|
||||||
|
free(puddingResult->dataWithPadding);
|
||||||
|
free(puddingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
void freeUnPaddingResult(PKCS7_unPadding* unPuddingResult)
|
||||||
|
{
|
||||||
|
free(unPuddingResult->dataWithoutPadding);
|
||||||
|
free(unPuddingResult);
|
||||||
}
|
}
|
||||||
@@ -123,6 +123,10 @@ void demonstrationPaddingOnTestInput(const uint8_t* const testDataExample, const
|
|||||||
ptrToUnpaddingDataResult++;
|
ptrToUnpaddingDataResult++;
|
||||||
}
|
}
|
||||||
printf("\n\n************************************\n\n");
|
printf("\n\n************************************\n\n");
|
||||||
|
|
||||||
|
freePaddingResult(structWithPaddingResult);
|
||||||
|
freeUnPaddingResult(structWithUnpaddingResult);
|
||||||
|
free(testData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printDescription(void)
|
void printDescription(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user