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