1 XGen
= function(permutation
, okeys
, rc
, rounds
, name
)
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"};
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)");
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
17 -- print("fprintf(stderr, \"%016llX \", out["..(i-1).."]);");
19 -- print("fprintf(stderr, \"\\n\");");
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]..";");
30 print("\tout["..i
.."]+="..keys
[(subkey
+i
)%#keys
+1].."+"..subkey
..";");
34 -- print("fprintf(stderr, \"%016llX \", out["..(i-1).."]);");
36 -- print("fprintf(stderr, \"\\n\");");
39 if r
== rounds
then break; end
41 print("\tout["..current_permute
[i
].."]=out["..current_permute
[i
].."]+out["..current_permute
[i
+1]..
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]..
50 current_permute
[i
]=permutation
[current_permute
[i
]+1];
53 for i
=0,okeys
-1 do print("\tout["..i
.."]=in["..i
.."]^out["..i
.."];"); end
56 print("\tasm volatile(\"\" : : \"r\"(&k) : \"memory\");");
57 print("\tasm volatile(\"\" : : \"r\"(&t) : \"memory\");");
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");