/ analysis / nonces.c
nonces.c
 1  // run with gcc -Wall -g -o nonces ../sbt.c nonces.c && ./nonces
 2  #include <stdint.h>
 3  #include <string.h>
 4  #include <stdio.h>
 5  #include <stdarg.h>
 6  #include "../sbt.h"
 7  #include <sys/random.h>
 8  
 9  void dump(const uint8_t *p, const size_t len, const char* msg, ...) {
10    va_list args;
11    va_start(args, msg);
12    vfprintf(stderr,msg, args);
13    va_end(args);
14    fprintf(stderr," ");
15    for(size_t i=0;i<len;i++)
16      fprintf(stderr,"%02x", p[i]);
17    fprintf(stderr,"\n");
18  }
19  
20  int main(void) {
21    sbt_ctx ctx;
22  
23    uint8_t __attribute__((nonstring)) key[15]="\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01";
24  
25    uint8_t nonce[5][5]={{2, 1, 13, 12, 11},  // BAMLK
26                         {8, 3, 1, 13, 13},   // HCAMM
27                         {5, 7, 12, 12, 1},   // EGLLA
28                         {12, 5, 5, 9, 3},    // LEEIC
29                         {10, 4, 13, 14, 10}};// JDMNJ
30    for(int n = 0; n<4;n++) {
31  
32      //uint16_t dptr = 0;
33      //for(int i = 5; i>0; i--, dptr++) {
34      //    getrandom(&tmp,1,0);
35      //    tmp = (nonce[dptr] ^ tmp) & 0xf;
36      //    tmp = tmp + 1;
37      //    nonce[dptr] = tmp;
38      //    //printf("%c", 0x40|tmp);
39      //}
40      //printf(" ");
41      sbt_set_key(&ctx, nonce[n],key);
42  
43      //for(int i=0;i<5;i++) {
44      //  fprintf(stderr, "%02x ", crypt_byte(nonce[n+1][i] -1) & 0xf);
45      //}
46      //for(int i=0;i<5;i++) {
47      //  fprintf(stderr, "%02x ", ((nonce[n+1][i]-1) ^ crypt_byte(0)) & 0xf);
48      //}
49      fprintf(stderr, "cb ");
50      for(int i=0;i<5;i++) {
51        fprintf(stderr, "%02x ", sbt_crypt_byte(&ctx, 0) & 0xf);
52      }
53      fprintf(stderr,"\n");
54      for(uint8_t x=16;x>0;x--) {
55        fprintf(stderr, "%02x ", x);
56        for(int i=0;i<5;i++) {
57          fprintf(stderr, "%02x ",(uint8_t) ((nonce[n+1][i]-1) ^ (x-i))  & 0xf);
58        }
59        fprintf(stderr,"\n");
60      }
61      //for(int i=0;i<5;i++) {
62      //  for(uint8_t x=16;x>0;x--) {
63      //  fprintf(stderr, "%02x=%02x ", (uint8_t) (nonce[n+1][i]-1), crypt_byte(0) & 0xf);
64      //}
65      fprintf(stderr,"\n");
66    }
67  
68    return 0;
69  }