Implicitly redirect cmdhelp includes to corresponding JSON files
[lsnes.git] / src / library / skeincgen.lua
blobdaf481672a7be6dbddbeacac1f9bc08f50ce0b16
1 XGen = function(permutation, okeys, rc, rounds, name)
2 local keys = {};
3 for i=1,okeys,1 do keys[i] = "key["..(i-1).."]"; end
4 table.insert(keys, "k");
5 local tweaks={"tweak[0]","tweak[1]","t"};
6 local subkey = 0;
7 local current_permute = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
9 print("static void "..name.."(uint64_t* out, const uint64_t* in, const uint64_t* key, const uint64_t* tweak)");
10 print("{");
11 local s="";
12 for i=0,okeys-1 do s=s.."key["..i.."]^"; end
13 print("\tuint64_t k="..s.."0x1BD11BDAA9FC1A22ULL;");
14 print("\tuint64_t t=tweak[0]^tweak[1];");
15 for i=0,okeys-1 do print("\tout["..i.."]=in["..i.."];"); end
16 -- for i=1,okeys do
17 -- print("fprintf(stderr, \"%016llX \", out["..(i-1).."]);");
18 -- end
19 -- print("fprintf(stderr, \"\\n\");");
20 for r=0,rounds do
21 if r % 4 == 0 then
22 --Add subkey.
23 for i=0,okeys-1 do
24 if i < okeys - 3 then
25 print("\tout["..i.."]+="..keys[(subkey+i)%#keys+1]..";");
26 elseif i < okeys - 1 then
27 print("\tout["..i.."]+="..keys[(subkey+i)%#keys+1].."+"..
28 tweaks[(subkey+i-(okeys - 3))%3+1]..";");
29 else
30 print("\tout["..i.."]+="..keys[(subkey+i)%#keys+1].."+"..subkey..";");
31 end
32 end
33 -- for i=1,okeys do
34 -- print("fprintf(stderr, \"%016llX \", out["..(i-1).."]);");
35 -- end
36 -- print("fprintf(stderr, \"\\n\");");
37 subkey = subkey + 1;
38 end
39 if r == rounds then break; end
40 for i=1,okeys-1,2 do
41 print("\tout["..current_permute[i].."]=out["..current_permute[i].."]+out["..current_permute[i+1]..
42 "];");
43 print("\tout["..current_permute[i+1].."]=(out["..current_permute[i+1].."] << "..
44 rc[(r%8)*(okeys/2)+(i+1)/2]..
45 ")|(out["..current_permute[i+1].."] >> "..(64-rc[(r%8)*(okeys/2)+(i+1)/2]..");"));
46 print("\tout["..current_permute[i+1].."]=out["..current_permute[i].."]^out["..current_permute[i+1]..
47 "];");
48 end
49 for i = 1,okeys do
50 current_permute[i]=permutation[current_permute[i]+1];
51 end
52 end
53 for i=0,okeys-1 do print("\tout["..i.."]=in["..i.."]^out["..i.."];"); end
54 print("\tk = 0;");
55 print("\tt = 0;");
56 print("\tasm volatile(\"\" : : \"r\"(&k) : \"memory\");");
57 print("\tasm volatile(\"\" : : \"r\"(&t) : \"memory\");");
58 print("}");
59 end
61 XGen({0,3,2,1},4,{14,16,52,57,23,40,5,37,25,33,46,12,58,22,32,32},72,"skein256_compress");
62 XGen({2,1,4,7,6,5,0,3},8,{46,36,19,37,33,27,14,42,17,49,36,39,44,9,54,56,39,30,34,24,13,50,10,17,25,29,39,43,8,35,
63 56,22},72,"skein512_compress");
64 XGen({0,9,2,13,6,11,4,15,10,7,12,3,14,5,8,1},16,{24,13,8,47,8,17,22,37,38,19,10,55,49,18,23,52,33,4,51,13,34,41,59,
65 17,5,20,48,41,47,28,16,25,41,9,37,31,12,47,44,30,16,34,56,51,4,53,42,41,31,44,47,46,19,42,44,25,9,48,35,52,
66 23,31,37,20},80,"skein1024_compress");