raw.c
1 // run with gcc -Wall -g -o raw ../sbt.c raw.c && ./raw 2 #include <stdint.h> 3 #include <string.h> 4 #include <stdio.h> 5 #include <stdarg.h> 6 #include <sys/random.h> 7 #include "../sbt.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 uint8_t __attribute__((nonstring)) key[15]="\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"; 23 24 for(int n = 0; n<99999000;n++) { 25 uint8_t nonce[5]={2, 1, 13, 12, 11}; 26 //uint16_t dptr = 0; 27 //for(int i = 5; i>0; i--, dptr++) { 28 // getrandom(&tmp,1,0); 29 // tmp = (nonce[dptr] ^ tmp) & 0xf; 30 // tmp = tmp + 1; 31 // nonce[dptr] = tmp; 32 // //printf("%c", 0x40|tmp); 33 //} 34 //printf(" "); 35 sbt_set_key(&ctx, nonce,key); 36 37 //copy result of parametric_entry to nonce 38 memcpy(nonce, ctx.cipherblock, 5); 39 40 int i; 41 //const uint8_t tv[8]={ //0x32, 0x17, 0x27, 0x2a, 0x1d, 0x17, 0x1d, 0x0a }; 42 // 0x3f, 0x3f, 0x29, 0x00, 0x11, 0x2b, 0x3d, 0x00 }; 43 //// 0x3b, 0x0b, 0x15, 0x10, 0x37, 0x1a, 0x19, 0x19 }; 44 //for(i=0;i<8 && (tv[i]==(crypt_byte(0)&0x3f));i++); 45 //if(i==8) dump(key,15,"k"); 46 47 for(i=0;i<8;i++) { 48 fprintf(stderr, "%02x", sbt_crypt_byte(&ctx, 0)&0x3f); 49 } 50 fprintf(stderr,"\n"); 51 //dump(key,15," key"); 52 for(int i=0;i<15;i++){ 53 key[i]++; 54 if(key[i] == 27) { 55 key[i]=44; 56 break; 57 } 58 if(key[i] == 47) { 59 key[i]=48; 60 break; 61 } 62 if(key[i]==58) { 63 key[i]=1; 64 } else { 65 break; 66 } 67 } 68 } 69 70 return 0; 71 }