cryptopals_c

cryptopals crypto challenges solutions in pure c
git clone git://git.superpozycja.net/cryptopals_c
Log | Files | Refs | README

c7.c (1208B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 #include <ba.h>
      5 #include <util.h>
      6 
      7 /*
      8 int decrypt(unsigned char *ct, int ct_len, unsigned char *key,
      9 	    unsigned char *pt)
     10 {
     11 	EVP_CIPHER_CTX *ctx;
     12 	int pt_len;
     13 	int len;
     14 
     15 	if (!(ctx = EVP_CIPHER_CTX_new()))
     16 		return -1;
     17 
     18 	if(EVP_DecryptInit_ex(ctx, EVP_aes_128_ecb(), NULL, key, NULL) != 1)
     19 		return -1;
     20 
     21 	if(EVP_DecryptUpdate(ctx, pt, &len, ct, ct_len) != 1)
     22 		return -1;
     23 
     24 	pt_len = len;
     25 
     26 	if(EVP_DecryptFinal_ex(ctx, pt + len, &len) != 1)
     27 		return -1;
     28 	pt_len += len;
     29 
     30 	EVP_CIPHER_CTX_free(ctx);
     31 	return pt_len;
     32 }
     33 */
     34 
     35 int main(int argc, char *argv[])
     36 {
     37 	unsigned char *key = (unsigned char*) "YELLOW SUBMARINE";
     38 	char line[256];
     39 	int pt_len;
     40 	char *b64;
     41 	char *hex;
     42 	char *pt;
     43 	FILE *f;
     44 	ba *ct;
     45 	int sz;
     46 
     47 	b64 = (char *) malloc(sizeof(char));
     48 
     49 	f = fopen(argv[1], "r");
     50 	sz = 0;
     51 	while (fgets(line, sizeof(line), f)) {
     52 		sz += strlen(line) - 1;
     53 		b64 = (char *) realloc(b64, sz);
     54 		strncat(b64, line, strlen(line) - 1);
     55 	}
     56 
     57 	base64_to_hex(&hex, b64);
     58 	
     59 	pt = (char *) malloc(sizeof(char) * strlen(hex) + 1);
     60 
     61 	//pt_len = decrypt(hex, strlen(hex), key, pt);
     62 
     63 	/* Add a NULL terminator. We are expecting printable text */
     64 	//pt[pt_len] = '\0';
     65 }