-
Notifications
You must be signed in to change notification settings - Fork 1
/
gostbox.asm
65 lines (48 loc) · 1.85 KB
/
gostbox.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
; gostbox.asm
; 2021-02-07 Markku-Juhani O. Saarinen <mjos@mjos.fi>
; Small DOS .COM assembler program that generates and outputs the
; "Nonlinear bijection" S-Box defined for GOST R 34.11-2012 "Streebog"
; and GOST R 34.12-2015 "Kuznyechik."
; Syntax may be a bit odd (historic);
; Assemble with "nasm -f bin -o gostbox.com gostbox.asm"
; Run with dosbox or similar.
org 0x100 ; .com file relocation start point
pi equ 0x200 ; Pi table will go here
; ---- generate the table pi[1..255]
start: mov bx, pi ; address
mov ax, 0xFCEE ; pi[0] and pi[1] values
mov [bx], ah
inc bl ; bl = 0x01
mov di, tab_s ; sigma table
.for_i: mov si, tab_k ; kappa table
mov ah, [di] ; y = sy[i]
.for_j: mov [bx], al
mov al, [si]
xor al, ah
add bl, bl ; left shift, high bit into carry
jnc .lfsr
xor bl, 0x1D ; reduce by base polynomial
.lfsr:
inc si
cmp si, tab_k + 17
jnz .for_j
mov al, 15[di] ; tab_k is at offset 15 from tab_s
inc di
cmp di, tab_s + 15
jnz .for_i
; ----- print pi
dec bl ; set bx = pi again
.sout:
mov dl, [bx]
mov ah, 0x02 ; DOS: "print character"
int 0x21
inc bl
jnz .sout
mov ah, 0x4C ; DOS: "terminate program"
int 0x21
; ----- tables
tab_s: db 0x01, 0xDD, 0x92, 0x4F, 0x93,
db 0x99, 0x0B, 0x44, 0xD6, 0xD7,
db 0x4E, 0xDC, 0x98, 0x0A, 0x45
tab_k: db 0xDC, 0xCE, 0xFA, 0xE8, 0xF8, 0xEA, 0xDE, 0xCC,
db 0xEC, 0xFE, 0xCA, 0xD8, 0xC8, 0xDA, 0xEE, 0xFC