traces-tbc.c (1531B)
1 #include <stdio.h> 2 #include <stdint.h> 3 4 #include "cipher.h" 5 6 #include "debug.h" 7 #include "test-helpers.h" 8 9 10 FILE *DUMP; 11 12 13 struct vector 14 { 15 char *name; 16 uint8_t key[KEY_BYTES]; 17 uint8_t tweak[TWEAK_BYTES]; 18 uint8_t message[BLOCK_BYTES]; 19 }; 20 21 typedef struct vector vector; 22 23 24 const vector VECTORS[] = { 25 { 26 .name = "order", 27 .key = { 28 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 29 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 30 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 31 }, 32 .tweak = { 33 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 34 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f 35 }, 36 .message = { 37 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 38 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f 39 } 40 } 41 }; 42 43 44 int main(int argc, char **argv) 45 { 46 if (argc < 3) 47 { 48 fprintf(stderr, "usage: %s OUTPUT-FOLDER PREFIX\n", argv[0]); 49 return 1; 50 } 51 52 for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++) 53 { 54 debug_open_dump(argv[1], argv[2], v->name); 55 debug_dump_buffer("message", BLOCK_BYTES, v->message, 0); 56 debug_dump_buffer("key", KEY_BYTES, v->key, 0); 57 debug_dump_buffer("tweak", TWEAK_BYTES, v->tweak, 0); 58 59 uint8_t ciphertext[BLOCK_BYTES]; 60 61 lilliput_tbc_encrypt(v->key, v->tweak, v->message, ciphertext); 62 63 debug_dump_buffer("ciphertext", BLOCK_BYTES, ciphertext, 0); 64 65 fclose(DUMP); 66 } 67 }