From ec17df90f18c0e98c46986b8b0dfb6854cfc8a42 Mon Sep 17 00:00:00 2001 From: n0p <0x90@n0p.cc> Date: Tue, 17 Oct 2017 20:31:59 +0200 Subject: Init. --- encrypt_decoy.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 encrypt_decoy.c (limited to 'encrypt_decoy.c') diff --git a/encrypt_decoy.c b/encrypt_decoy.c new file mode 100644 index 0000000..3cde750 --- /dev/null +++ b/encrypt_decoy.c @@ -0,0 +1,80 @@ +/* + * gcc encrypt_decoy.c -lcrypto + */ + +#include +#include +#include +#include + +#include "openssl/aes.h" + +int main() { + AES_KEY enc_key; + + unsigned char plain[80] = + "Oh my, there's nothing here... Move along, but don't fall off the " + "edge!\0", + keys[4][16], cipher[4][80]; + + // Getting 4 random 128 bit keys. + int fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + exit(-1); + } + + for (int i = 0; i < 4; i++) { + if (read(fd, keys[i], 16) != 16) { + exit(-1); + } + } + + close(fd); + + // Encrypting the plain text with the 4 keys to 4 cipher texts. + for (int i = 0; i < 4; i++) { + AES_set_encrypt_key(keys[i], 128, &enc_key); + + for (int j = 0; j < 5; j++) { + AES_encrypt(plain + 16 * j, cipher[i] + 16 * j, &enc_key); + } + } + + // PP the key for copy & paste to the challenge source. + for (int i = 0; i < 4; i++) { + if (i == 0) { + printf("static unsigned char decoy_keys[4][16] = {{"); + } else { + printf(" {"); + } + + for (int j = 0; j < 16; j++) { + if (j == 15) { + printf("'\\x%02X'", keys[i][j]); + } else { + printf("'\\x%02X', ", keys[i][j]); + } + } + + if (i == 3) { + printf("}};\n"); + } else { + printf("},\n"); + } + } + + // PP the cipher texts. + for (int i = 0; i < 4; i++) { + printf("static const unsigned char cipher[80] = {"); + + for (int j = 0; j < 80; j++) { + if (j == 79) { + printf("'\\x%02X'};\n", cipher[i][j]); + } else { + printf("'\\x%02X', ", cipher[i][j]); + } + } + } + + return 0; +} \ No newline at end of file -- cgit v1.2.3