blob: 86dd823343c00ed75a61c5e99df52de8793fbb95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "lib2.h"
/**
* appends PKCS#7 padding to string. devide string in blocks of size blocksize
* and append to last block so that it is also of blocksize length
*/
char *pkcs7_padding(char *string, int length_string, int blocksize)
{
char *result = NULL;
int i;
int value = blocksize - (length_string % blocksize);
result = malloc(length_string+value+1);
memcpy(result, string, length_string);
for(i=0;i<value;i++) {
result[length_string+i] = (char) value;
}
result[length_string+i] = '\0';
return result;
}
|