Elektronicke autorizace zarizeni - algoritmy
Ales Prochaska, Divesoft
prochaska na divesoft.cz
Čtvrtek Září 28 14:36:12 CEST 2017
> From: Jaroslav Lukesh <lukesh na seznam.cz>
> To: "HW-news" <hw-list na list.hw.cz>
> Date: Wednesday, September 27, 2017, 5:56:29 PM
> Subject: Elektronicke autorizace zarizeni - algoritmy
>
> https://dxdt.ru/arduino/MagmaCipher_v1.ino
Ok, zde je zase moje pradavna verze (snad to funguje...):
Ales Prochaska
//----------------------------------------------------------------------------
// Symetricka blokova podle GOST 28147-89.
//----------------------------------------------------------------------------
// Ales Prochaska 1996
//----------------------------------------------------------------------------
type
gost_key = array [0..7] of unsigned32;
const
// Tabulky permutaci ("s-boxy").
// S-boxy nema smysl utajovat, protoze je lze odhalit utokem
// se zvolenym klicem pomoci nejvyse 2^32 sifrovani.
// Protoze sifra je (na rozdil od DES) odolna proti linearni
// kryptoanalyze, lze pravdepodobne pouzit jakekoliv jine,
// nahodne vygenerovane s-boxy.
sbox : array [0..7,0..15] of byte = (
( 4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3 ),
( 14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9 ),
( 5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11 ),
( 7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3 ),
( 6, 12, 7, 1, 5, 15, 13, 8, 4, 10, 9, 14, 0, 3, 11, 2 ),
( 4, 11, 10, 0, 7, 2, 1, 13, 3, 6, 8, 5, 9, 12, 15, 14 ),
( 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 ));
//----------------------------------------------------------------------------
procedure gostencrypt (var _blok; // blok dat (8 byte)
const klic : gost_key; // sifrovaci klic
sifruj : boolean); // T=sifrovat, F=desifrovat
// Sifrovani nebo desifrovani osmibytoveho bloku
//----------------------------------------------------------------------------
var
l,r,x : unsigned32;
p : unsigned32;
blok : array [0..1] of unsigned32 absolute _blok;
i,n : integer;
begin
// rozdelit blok na slova (l,r)
l:=blok[0];
r:=blok[1];
// de/sifrovat
for i:=0 to 31 do begin
n:=i mod 8;
if sifruj
then begin if i>=24 then n:=7-n; end
else begin if i>=8 then n:=7-n; end;
p:=r+klic[n]; // aritmeticky soucet, preteceni se ignoruje
p:=sbox[7,(p shr 28) and 15] shl 28 or sbox[6,(p shr 24) and 15] shl 24 or
sbox[5,(p shr 20) and 15] shl 20 or sbox[4,(p shr 16) and 15] shl 16 or
sbox[3,(p shr 12) and 15] shl 12 or sbox[2,(p shr 8) and 15] shl 8 or
sbox[1,(p shr 4) and 15] shl 4 or sbox[0,(p ) and 15];
p:=(p shl 11) or (p shr 21);
x:=l;
l:=r;
r:=x xor p;
end {for};
// spojit slova (r,l) do bloku
blok[0]:=r;
blok[1]:=l;
end {gostencrypt};
Další informace o konferenci Hw-list