Вы находитесь на странице: 1из 35

ERROR: REFERENCE SOURCE NOT FOUND

Error: Reference source not found

.
28147-89
X
:
07.19.00 -

Error: Reference source not found 2002

2
774:002:006.354
: .., ..
: . .-. ..

28147-89: / ..,
... : -, 2002. 32 .
. 1 . . 4. . 1.

(). .
(
).
,
Delphi..

http://www.mp.dpt.ustu.ru/InformationSystemsTheory.

.
.

................................................................................................3
.....................................................................................................5
1. 00000...........................................................6
1.1. ...................................................................6
1.2.
.................................................................................................7
1.3. ............................................8
1.4. ...................9
1.5. ...................................................11
2. ..............................13
2.1. .........................................13
2.2. ................................................15
2.3.
..............................................................................................16
3.
- 28147-89.................................18
3.1. ............................................................................18
3.2. GOST........................................................19
3.3. GOST
..........................................................................................................19
3.3.1 .................................................................19
3.3.2 ....................................................21
3.4. ..................................21
3.5.
BaseEncryptionStep..........................................................................21
3.5.1 .................................................................21
3.5.2
BaseEncryptionStep........................22
3.6. ..................................................................25
4. ................26
4.1. ............................................26
4.1.1.
....................................................................................................26

: .., 2002
, : ..,2002

4
4.1.2.
................................................................26
4.2. ..........................................................................27
1.3. ...........................................29
..............................................................................................30
.....................................30

........................31
.1 .........................................31
.1.1 ......................................................................31
.1.2 ............................................................................32
.2. .........................................................33
.2.1 .............................................33
.2.2 ...........................................34


.
,
, . ,

.

.
.
,

,
,
. .
,
, , ,
.
.
.
28147-89, , ,
1989 .

1. 0000 0
1.1.

,
28147-89.

.

(, X). |X|
X . ,
,
: 0<<2|X|.

, : X = (X0, X1, , Xn-1) = X0||
X1||||Xn-1.
||. ,
: |X|
= |X0| + |X1| + +|Xn-1|.
,
. ,
,
:
( X 0, X1,...,X n1) = X 0 ||X1 ||...||X n1 = X 0 + 2

X0

( X1 + 2

X1

(...(X n2 + 2

X n2

X n1)...)).


, ,
, , :
X = (x0, x1,...,xn1) = x0 + 21 x1 + ...+ 2n1 xn1.

,
, ,
. AB =
(a0b0, a1b1, , an-1bn-1), n = |A| = |B| , "."
; ,
, - 2:
ab = (a+b) mod 2.

7
1.2.

28147-89, ,
.
,
,
. ,
.
, .
,
:
(32-3);
(32-);
(16-3). *
,
,

.
, ,
:
) ;
) ,
)
.
,
, .
,
,
.
. ,
, .
.
1) 32- ,
K: K = {Ki}0 i 7.
32- :


. ,
, , ,
, .
, .

8
0 K i < 232.

, 328=256 32

.
2) 816, 4- ,
0 15.
,
, 16
0 15 .
H: H ={H i , j }00ij715,0 H i, j 15. ,
: 8 16 / 4
/ = 512 64 .
1.3.

,
64- .
32- ,
- .
1. :

0.

N 64- ,
(N1) (N2) 32 . , N=(N1,N2).

X 32- ;
1. .
232 ,
;
2. , 32- ,
, 4- :
S = (S0 , S1, S2, S3, S4, S5, S6 , S7 )

,
: Si
Si - ( ) i-
(.. i- , ).
,
, ,
, 4-
.
: 4- 32 , ,

9
4- , 2 4,
.
3. 11 .
11
.
11

28147-89

11
.
4. :
,
3,

.
5. :

,

.
6.
. 1.1.


.
1.4.
,
.
, , .
,
.

, .
,
. ,
,
.
,

10
,
.



. .
1) 32-3:

K 0, K1, K 2, K 3, K 4, K 5, K 6, K 7 , K 0, K1, K 2, K 3, K 4, K 5, K 6, K 7 , K 0, K1, K 2, K 3, K 4, K 5, K 6, K 7 , K 7

2) 32-:

K 0 , K 1, K 2 , K 3, K 4 , K 5, K 6, K 7 , K 7 , K 6 , K 5, K 4 , K 3, K 2 , K 1, K 0 , K 7 , K 6, K 5, K 4 , K 3, K 2 , K 1, K 0 , K 7

a)

1.4
, -,
(), ,
(X), , (3)
() .
:
,

, :

11
32 ( 32 ( )) =

, - 64- , x() .
,
.
,
, 32-
32-. :
, 32-3
32-. ,

,
.
,
, 28147-89

.
1.4 1.4.
64 , N. (N,X)
N
X.
,
.
1.5.
28147-89
:
,
, **
, **
64 ,
,
, .

8 ,
, 8 .
**


, 64
, .
.

12

, ,

()

a)

)
1.5.

:
0,
;
0

i ,Ti
i- 64-
: T0 = (T10,T20,...,Tn0 ), T = (T1,T2,...,Tn ), 1 i n;
n
64- ;
x 64-
X;
:
.
32-3
, - 32-
. , 64-
.

1.5 ,
.
,
, 64
: T = T =64n
.
:
0

13
1.


.

,
, .
2. 8 64 ,
,
64 . ,
,
, ,


,
. ,
, ,
64 , ,
(
).
,
,
64
, 64- . ,

. , : ,
32 , - 64 .
, 8-
,
. ,
,
, ,
.

2.
2.1.

14
,
.
: ; ,
;
, ,
.
,
,
. ,
,
. ,
, ,
,
.
,

.

, ,
, ,
,
,


.

,

.
,
, ,
,
,

2.2.
,

15
DES , ,
,
, ..
. ,
. 256-
2256 (1.1581077).

DES 56
2 56.
.
DES ,
.
2.2.
28147-89
, .
, DES.
, ,
, ,
. ,

, .
.
,
, .
2.2. ,
.
,
,
, .
,
(X),
.
,
: N1 = N2 = X , DESe 32 .
(.
. 1.1), , 1,2,3
, 4 5

.

16
DES
. 32 ,
DESa 16.
DESa,

. , DESa
.

.
,
. ,
,
DESa,
.
2.3.


. , DES
,
,
.
.
, ,
, ,
.
. ,
,
, , ,
,
.
,
, :
1. ,
0 1.
,

. , ,
. ,
,

17
,
.
,
, ,
; , ,
. ,

, . ,

.
, -
0 1
( ), .
.
2. ,
, .
,
.

.

.
, .
, .
,
,
, (..
)
, .
.
,
.

0 15, , ,
,
.
,
. 32-3 32- ,
0 15.

18
, , ,
, ,
. , ,
. ,
, ,
,
, .

, ,
,
()
.
,
. (
) .

3.
- 28147-89
3.1.

,
.
,
.
, ,
() . ,
, -, :
1) (BaseEncodeSet).
2) (BaseDecodeSet).

,
.
,
,
(
BaseEncryptionStep).

19
3.2. GOST
3 :
, : ,
( ,
),
;
,
(GostBase);
,
(Indication).
,
GostBase.

. Indication
.
.

3.3.
GOST
3.3.1
(.. ,
)
, .

, .
GOST.
8
64 ,
/ (
).
, 64 ,

,

4 ,
TDATAUNIT

tDataUnit
(16 ),
W3 W2 W1 W0
tDataUnit***.
Words:
0
1
2
3
***


GostBase
3.1.

20
(Words),
(Wx) (. 3.1).
Wx,
:
Words[0]=W3 4863;
Words[1]=W2 3247;
Words[2]=W1 1631;
Words[3]=W0 015;
32-
, tKey,
(Wds) (Dws) (. .
2). Dws tDword
(. 3.3).
TKEY
tKey
Wds:
Dws:

1
0

3
1

5
2

7
3

9
4

10

11

12

13
6

14

15
7

3.2.
TDWORD
tDword
W0

W1

3.3.
, 2
tKey,
tDword:
W1 ;
W0 ;
,
16 4- 0 15,
.
1 ( = 4 ),
1816=128 .
, ""
4 "" , 256
0 255. " " 14*256=1024 .
""
"" . ,
GOST, ,

21
, tSubstitutionTable
byte.
, ,
.
,

,
(.
2.3).
3.3.2

MEx, (
) . (
, ), ,
.
3.4.

,
BaseEncryptionStep ,

.
, ( BaseEncodeSet) :
1) 4 ;
2)
,
xKey tDword BaseEncryptionStep.
3) .
.
3.5.
BASEENCRYPTIONSTEP
3.5.1
8
4- . Pascal
4- , ,
,

22
( 3.2).
(

)
:
;

, 4-
.
, :
, 11 ,

Pascal.
:
Shl, Shr ;
Hi, Lo
;
Or :
:
-
0101
-
0011

0111
Xor :
:
-
0101
-
0011

0110
And :
:
-
0101
-
0011

0001

MEx,
.
3.5.2
BaseEncryptionStep
Pascal.

3.5.1. 3.6.

23
1.3. 1.1.
GOST:
1
OR;
2

11 , .
,
8 (. 3.4.);

24

8 .
8 :

1 :

2 :

3 :

4 :

B3

B2

B1

B0

B3

B2

B1

B0

B3

B2

B0

B1

B3

B2

B0

B1

B3

B1

B0

B2

B3

B1

B0

B2

B2

B1

B0

B3

B2

B1

B0

B3

8 :
: Bx ,
Bx ( ).

3.4.
3
11 ,
3 . ,
, Pascal
, Shl
, . ,
3.6.
,
-
.
1, SumBit
;
4


, ;
5
tDataUnit .

25
3.6.
-
.

1 8 . ,
n-
n- . .
,
.
N- B
( ):
1) : Nb := N div 8.
div N 8.
2) b : b := B[Nb].
3) : nb := N mod 8. mod
N 8.
4) bit : bit := (b shr nb) and 1. shl
, shr
.
5) bit=1, N- B 1 bit=0,
N- B 0.
6) bit N- B
( ):
7) : Nb := N div 8.
div N 8.
8) b : b := B[Nb].
9) : nb := N mod 8. mod
N 8.
10) b ,
. bit =1, b := b or (1 shl nb), b := b and (not (1 shl
nb)). or , and
, not .
11) b : B[Nb] := b.
Borland
Pascal.

26
4.
4.1.
4.1.1.
DELPHI,
8
:
Prg_gost: *.pas, *.dfm, *.dcu ;
Keys: *.pas, *.dfm, *.dcu
;
Tabl: *.pas, *.dfm, *.dcu ;
gost.dpr ;
GostBase.pas ,
, ;
Indication.pas , .
GOST,
.
,
.
4.1.2.

, ,

. ( Delphi)
7) \ - Delphi 5\ 23147-89\

1) 2) Win - Delphi5 :
GOST89.dpr ;
Fcmdline.pas ;
ReadKey.pas ;
CompareFile.pas .
2) Common :
Umiscfun.pas xStrings.pas .
3) 89 :
GOSTBASE.PAS
23147-89.

27
4) GOST89.exe
GOST89.dpr ,
.
5) gostkey.txt, substable.txt sync.txt
, , .
.
GOST89.exe /?.
GOST89.exe ( ) ,
,
.
:
64 16 .
64 (8-)
. ( )
8 .
:
64 (8-) 89#0
() . .
64 4- ,
4-
.
.
GOST89.exe ,
GOST89.exe .
gostkey.txt, substable.txt sync.txt.
4.2.
0 .
, /
.
1, 2 ,
.

. .. ,
.

,
. .

28
MathCAD.
, ,
.
0 ()
.
:
.

1 ()

/ . ,

/.

1) GOST GOST89.
2) : 1) ? 2)
? 3) ? 4)
( )
? 5) ? 6)
? 7)
? 8)
?
( )
3) /
23147-89 MathCAD-. AES.
4) Gost89.exe
.
5) Gost89.exe
, . :
1%
Gost89.exe,
. ,
.
1

23147-89 MathCAD.
[2]. :
.

29
2

(
) .
Gost89.exe
AES.
3
23147-89
, ,
Gost89.exe 10% .
4

( ,
)
Gost89.exe.
5

.
6

. ( )
.
.
1.3.

, .
:
1) :

, ,
, 28147-89 .
2) /
.
3) .

30
4)
() .
5)
.


.

.
,
x
,
.
4.1
. 4 6
. 1 2 ,
.


1.
2.

, ..

AES

: /
.. , . . . :
-, 2007. 25 .

31


.1
.1.1

procedure TForm1.BaseEncriptionStep;
begin
asm
{ }
pushad;
pushfd;
{ 32- }
xor
EAX,EAX;
xor
EBX,EBX;
xor
ECX,ECX;
xor
EDX,EDX;
xor
EDI,EDI;
xor
EBP,EBP;
{ }
mov
EBX,P1;
{ 8 }
mov
AX,N1_l;
mov
DX,N1_h;
mov
DI,N2_l;
mov
BP,N2_h;
{ 1. N1}
push
DX;
push
AX;
{ 2. S 2^32}
add
AX,key_l;
adc
DX,key_h;
{ 3. S 8 }
mov
CL,AL;
mov
AL,[EBX+ECX];
xchg
AH,AL;
mov
CL,AL;
mov
AL,[EBX+ECX+$100];
xchg
DL,AL;
mov
CL,AL;
mov
AL,[EBX+ECX+$200];
xchg
DH,AL;
mov
CL,AL;
mov
AL,[EBX+ECX+$300];
{ 4. S 3 }
shl AX,1;
rcl DX,1;
adc AX,0;
shl AX,1;
rcl DX,1;
adc AX,0;
shl AX,1;
rcl DX,1;
adc AX,0;
{ 5. N1,N2}

32
xor
DX,BP;
xor
AX,DI;
{ DI BP }
pop
DI;
pop
BP;
{ }
mov
N1_l,AX;
mov
N1_h,DX;
mov
N2_l,DI;
mov
N2_h,BP;
{ }
popfd;
popad;
end;
end;

.1.2

procedure BaseEncryptionStep(
var
ADataUnit:tDataUnit;
const ASubstitutionTable: tSubstitutionTable;
Key:tDword
);
var
xN1_h, xN1_l, tmp: Word;
HiByte2, HiByte1: Byte;
SumBit_l, SumBit_h, i: Integer;
begin
{ }
{1. S 2^32}
xN1_l := ADataUnit.W0 or key.W0;
xN1_h := ADataUnit.W1 or key.W1;
{ 3. S 8 }
HiByte1 := ASubstitutionTable[0, Lo(xN1_l)];
xN1_l := ASubstitutionTable[1, Hi(xN1_l)];
HiByte2 := ASubstitutionTable[2, Lo(xN1_h)];
xN1_h := ASubstitutionTable[3, Hi(xN1_h)];
tmp := xN1_l + HiByte2*256;
xN1_l := xN1_h + HiByte1*256;
xN1_h := tmp;
{ 4. S 3 }
i := 0;
repeat
if ((xN1_l shr 15) and 1) = 1 then begin
xN1_l := xN1_l shl 1; SumBit_l := 1;
end
else begin
xN1_l := xN1_l shl 1; SumBit_l := 0;
end;
if ((xN1_h shr 15) and 1) = 1 then begin
xN1_h := xN1_h shl 1; SumBit_h := 1;
end
else begin
xN1_h := xN1_h shl 1; SumBit_h := 0;

33
end;
xN1_l := xN1_l or SumBit_h;
xN1_h := xN1_h or SumBit_l;
i := i+1;
until i = 3;
{ 5. N1,N2}
xN1_l := xN1_l xor ADataUnit.W2;
xN1_h := xN1_h xor ADataUnit.W3;
{ }
ADataUnit.W3 := ADataUnit.W1;
ADataUnit.W2 := ADataUnit.W0;
ADataUnit.W1 := xN1_h;
ADataUnit.W0 := xN1_l;
{ }
end;

.2.
.2.1

procedure BaseEncodeSet(var
AData:tDataUnit;
const ASubstititionTable:tSubstitutionTable;
Key:tKey);
var
i,j: Integer;
N_tmp: word;
xKey: tDWord;
begin
{------- --------}
for i:=1 to 3 do
for j:=0 to 7 do begin;
xKey.W1:=Key.Dws[j].W0;
xKey.W0:=Key.Dws[j].W1;
BaseEncryptionStep(AData,
ASubstititionTable,
xKey);
temp_indication(AData,
xKey,
ME5,ME6,ME7,ME8,ME21,ME22,ME23,ME24,
ME9,ME10,ME11,ME12,ME13,ME14,ME19,ME20);
end;
for j:=7 downto 0 do begin
xKey.W1:=Key.Dws[j].W0;
xKey.W0:=Key.Dws[j].W1;
BaseEncryptionStep(AData,
ASubstititionTable,
xKey);
temp_indication(AData,
xKey,
ME5,ME6,ME7,ME8,ME21,ME22,ME23,ME24,
ME9,ME10,ME11,ME12,ME13,ME14,ME19,ME20);
end;

34
{ }
N_tmp:=AData.W0;
AData.W0:=AData.W2;
AData.W2:=N_tmp;
N_tmp:=AData.W1;
AData.W1:=AData.W3;
AData.W3:=N_tmp;
{------- -------}
end;

.2.2

procedure BaseDecodeSet(var
AData:tDataUnit;
const ASubstititionTable:tSubstitutionTable;
Key:tKey);
var
i,j: Integer;
N_tmp: word;
xKey: tDWord;
begin
{------- --------}
for j:=0 to 7 do begin
xKey.W1:=Key.Dws[j].W0;
xKey.W0:=Key.Dws[j].W1;
BaseEncryptionStep(AData,
ASubstititionTable,
xKey);
temp_indication(AData,
xKey,
ME5,ME6,ME7,ME8,ME21,ME22,ME23,ME24,
ME9,ME10,ME11,ME12,ME13,ME14,ME19,ME20);
end;
for i:=1 to 3 do
for j:=7 downto 0 do begin
xKey.W1:=Key.Dws[j].W0;
xKey.W0:=Key.Dws[j].W1;
BaseEncryptionStep(AData,
ASubstititionTable,
xKey);
temp_indication(AData,
xKey,
ME5,ME6,ME7,ME8,ME21,ME22,ME23,ME24,
ME9,ME10,ME11,ME12,ME13,ME14,ME19,ME20);
end;
{ }
N_tmp:=AData.W0;
AData.W0:=AData.W2;
AData.W2:=N_tmp;
N_tmp:=AData.W1;
AData.W1:=AData.W3;
AData.W3:=N_tmp;
temp_indication(AData,

35
xKey,
ME5,ME6,ME7,ME8,ME21,ME22,ME23,ME24,
ME9,ME10,ME11,ME12,ME13,ME14,ME19,ME20);
{------- -------}
end;