Main step of GOST 28147-89: Difference between revisions

Updated D entry
(Updated D entry)
Line 124:
{{trans|C}}
{{trans|Go}}
<lang d>alias SBox = immutable ubyte[16][8] SBox; // A matrix2D array of nibbles.
 
private bool _validateSBox(in SBox data) @safe pure nothrow {
foreach (const ref row; data)
foreach (immutable ub; row)
if (ub >= 16) // Verify it's a nibble.
return false;
Line 139:
private uint[2] buffer;
 
@safe nothrow static this() {
alias s = sBoxes[0] s;
 
foreach (immutable i; 0 .. k87.length) {
// Given validateSBox, the & 0xFF aren't necessary.
k87[i] = ((s[7][i >> 4] << 4) & 0xFF) | s[6][i & 0xF];
Line 185 ⟶ 186:
[13, 11, 4, 1, 3, 15, 5, 9, 0, 10, 14, 7, 6, 8, 2, 12],
[ 1, 15, 13, 0, 5, 7, 10, 4, 9, 2, 3, 14, 6, 11, 8, 12]];
 
GOST!cbrf g;
 
// Example from the talk page (bytes swapped for endianess):
Line 190 ⟶ 193:
immutable uint key = 0x_E2_C1_04_F9;
 
GOST!cbrf g;
g.mainStep(input, key);
writefln("%(%08X %)", g.buffer);