traces-tbc.c (1591B)
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 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 36 }, 37 .message = { 38 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 39 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f 40 } 41 } 42 }; 43 44 45 int main(int argc, char **argv) 46 { 47 if (argc < 3) 48 { 49 fprintf(stderr, "usage: %s OUTPUT-FOLDER PREFIX\n", argv[0]); 50 return 1; 51 } 52 53 for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++) 54 { 55 debug_open_dump(argv[1], argv[2], v->name); 56 debug_dump_buffer("message", BLOCK_BYTES, v->message, 0); 57 debug_dump_buffer("key", KEY_BYTES, v->key, 0); 58 debug_dump_buffer("tweak", TWEAK_BYTES, v->tweak, 0); 59 60 uint8_t ciphertext[BLOCK_BYTES]; 61 62 lilliput_tbc_encrypt(v->key, v->tweak, v->message, ciphertext); 63 64 debug_dump_buffer("ciphertext", BLOCK_BYTES, ciphertext, 0); 65 66 fclose(DUMP); 67 } 68 }