#include "../lib/lib.h" #include "../lib/lib2.h" #include "../lib/lib3.h" #include "../lib/lib4.h" #include "../lib/lib5.h" #include "../lib/lib7.h" void generate_random_printable_bytes(char *s, unsigned int length) { int i; for(i=0;i TAB \t) for(i=0;i<16;i++) { value = 16 - ((strlen(__expand)+i) % 16); // add character until value == 9 to expand if(value != 16) expand[strlen(__expand)+i] = '/'; else expand[strlen(__expand)+i] = '\0'; } int expand_len = strlen(expand); // now we have a full with 7 bytes we can change + 9 bytes padding (TAB) // we want to change the 7 bytes so that the result is printable char *concat = malloc(strlen(msg)+expand_len+9); int pad_len; while(1) { // construct a first block of msg so that mac[i] ^ msg[i] generate_random_printable_bytes(&expand[expand_len], 7); memset(iv, 0 ,16); cbc_mac(expand, expand_len+7, iv, key, mac); char *expand_padded = __pkcs7_padding(expand, expand_len+7, 16, &pad_len); if (pad_len != 9) printf("ERROR: padding length is nor 9: %i\n", pad_len); memcpy(concat, expand_padded, expand_len+7+pad_len); memcpy(&concat[expand_len+pad_len+7], msg, strlen(msg)); for(i=0;i<16;i++) concat[i+pad_len+7+expand_len] = mac[i] ^ msg[i]; if(isprintable(&concat[pad_len+6+expand_len], 17) == 1) break; } //printf("printable string is:\n"); printf("%s", concat); memset(iv, 0, 16); cbc_mac(concat, strlen(msg)+expand_len+pad_len+7, iv, key, mac); hex_binary_to_string(mac, hex_mac, 16); //printf("mac is: %s\n", hex_mac); }