lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

test-tweakey.c (2913B)


      1 #include <inttypes.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 #include "tweakey.h"
      6 
      7 #include "test-helpers.h"
      8 
      9 
     10 struct vector
     11 {
     12     char *name;
     13     uint8_t key[KEY_BYTES];
     14     uint8_t tweak[TWEAK_BYTES];
     15     uint8_t last_rtk[TWEAKEY_BYTES];
     16 };
     17 
     18 typedef struct vector vector;
     19 
     20 
     21 /* [0]: LSB */
     22 const vector VECTORS[] = {
     23     {
     24         .name = "full",
     25         .tweak = {
     26             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
     27             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
     28             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
     29         },
     30         .key = {
     31             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
     32             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
     33         },
     34         .last_rtk = {
     35             0x53, 0x40, 0x95, 0x96, 0xea, 0x82, 0x2b, 0x28
     36         }
     37     },
     38     {
     39         .name = "null",
     40         .tweak = {
     41             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     42             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     43             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     44         },
     45         .key = {
     46             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     47             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     48         },
     49         .last_rtk = {
     50             0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     51         }
     52 
     53     },
     54     {
     55         .name = "order",
     56         .tweak = {
     57             0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
     58             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
     59             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
     60         },
     61         .key = {
     62             0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
     63             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
     64         },
     65         .last_rtk = {
     66             0xfa, 0xd6, 0x9e, 0x4d, 0x08, 0x9a, 0x46, 0x5b
     67         }
     68     },
     69     {
     70         .name = "random",
     71         .tweak = {
     72             0xa8, 0x43, 0xf3, 0x10, 0x81, 0x11, 0x1c, 0x84,
     73             0xdf, 0xf8, 0x2e, 0xfa, 0x90, 0x90, 0x26, 0x21,
     74             0x7d, 0x8d, 0x43, 0x12, 0x2a, 0xb3, 0xd2, 0x4d
     75         },
     76         .key = {
     77             0xc1, 0x96, 0xc6, 0x0a, 0x02, 0x73, 0x91, 0x68,
     78             0x7f, 0xf4, 0x23, 0x4d, 0x3d, 0xd5, 0xf9, 0x9b
     79         },
     80         .last_rtk = {
     81             0xc2, 0xd1, 0xb0, 0x98, 0xf3, 0x74, 0x8a, 0xc0
     82         }
     83     }
     84 };
     85 
     86 
     87 int main()
     88 {
     89     int diff = 0;
     90 
     91     for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++)
     92     {
     93         uint8_t tk[TWEAKEY_BYTES];
     94         tweakey_state_init(tk, v->key, v->tweak);
     95 
     96         uint8_t rtk[ROUND_TWEAKEY_BYTES];
     97         tweakey_state_extract(tk, 0, rtk);
     98 
     99         for (uint8_t i=1; i<ROUNDS; i++)
    100         {
    101             tweakey_state_update(tk);
    102             tweakey_state_extract(tk, i, rtk);
    103         }
    104 
    105         if (memcmp(rtk, v->last_rtk, sizeof(rtk)) != 0)
    106         {
    107             REPORT_DIFFERENCE(v->name, "last RTK");
    108             dump_c_initializer(ROUND_TWEAKEY_BYTES, rtk);
    109             diff++;
    110         }
    111     }
    112 
    113     return diff;
    114 }