blob: 304725b96ac86bc5108ed31c7db881e4325a869e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// https://cryptopals.com/sets/2/challenges/9
#include "util/pkcs7_padding.h"
#include <stdio.h>
#include <string.h>
/*
* a block cipher transforms fixed-size block (8/16 bytes) of plaintext into
* ciphertext. but we rarely want to transform a single block; we encrypt
* irregularly-sized messages. the odd size of these messages can be accounted
* for using padding, specifically PKCS#7 scheme. eg. "YELLOW SUBMARINE" padded
* to 20 bytes would be "YELLOW SUBMARINE\x04\x04\x04\x04" (0x04 indicates EOT
* or end-of-transmission)
*/
int main() {
uint8_t *str = (uint8_t *)"YELLOW SUBMARINE", *res;
size_t curr_len = strlen((char *)str);
ssize_t new_len = add_padding(str, curr_len, 20, &res);
if (new_len == -1) {
fprintf(stderr, "add_padding() failed\n");
exit(1);
}
fwrite(res, 1, new_len, stdout);
free(res);
printf("curr len: %zu\nnew_len: %zd\n", curr_len, new_len);
}
|