-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgost.asm
236 lines (218 loc) · 7.57 KB
/
gost.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
10 ORG 100H
20 JP MAIN
30PUTSTR EQU 0BFF1H
40INKEY EQU 0BE53H
50PUTCHR EQU 0BE62H
60WAITK EQU 0BFCDH
70RPTCHR EQU 0BFEEH
80ENCRYP EQU 1
90DECRYP EQU 0
100N1: DB 0,0,0,0
110N2: DB 0,0,0,0
120TMP1: DB 0,0,0,0
130TMP2: DB 0,0,0,0
140ROUND: DB 0
150BLOCK: DEFS 8
160OPE: DB 0
170MAIN: LD A,23
180 CALL MOD8
190 LD (N1),A
200 RET
210RawCrp: ; RawCrypt
220 ; N1 = uchar2ulong(block + 0);
230 LD DE,N1
240 LD HL,BLOCK
250 LD A,(HL)
260 LD (DE),A
270 INC HL
280 INC DE
290 LD A,(HL)
300 LD (DE),A
310 INC HL
320 INC DE
330 LD A,(HL)
340 LD (DE),A
350 INC HL
360 INC DE
370 LD A,(HL)
380 LD (DE),A
390 INC HL
400 ; N2 = uchar2ulong(block + 4);
410 LD DE,N2
420 LD A,(HL)
430 LD (DE),A
440 INC HL
450 INC DE
460 LD A,(HL)
470 LD (DE),A
480 INC HL
490 INC DE
500 LD A,(HL)
510 LD (DE),A
520 INC HL
530 INC DE
540 LD A,(HL)
550 LD (DE),A
560 ; round = (operation == OPERATION_ENCRYPT) ? 0 : 31;
570 LD A,(OPE)
580 CP DECRYP
590 JP Z,MAIN00
600 LD A,31
610MAIN00: LD (ROUND),A
620MAIN01: ;do {
630 ; if (round < 24) TMP1 = N1 + X[round % 8];
640 CP 25
650 JP P,MAIN02
660 CALL MOD8 ; round % 8
670 ADD A,A
680 ADD A,A ; (round % 8) * 4
?LD A,(N1+3)
690MAIN02:
3999 RET
4000MOD8: ; modulo 8
4010 ; In A, out A
4020 CP 8
4030 RET M
4040 PUSH AF
4050 RRA
4060 RRA
4070 RRA
4080 AND 1FH ; / 8
4100 ADD A,A
4110 ADD A,A
4120 ADD A,A ; * 8
4140 LD B,A
4150 POP AF
4160 SUB B
4170 RET
5000X: DEFS 32 ; the key (KMU)
5010LBlock: DEFS 8 ; for CBC chaining
5020K12: DB 0D0H, 0CFH, 0CEH, 0CDH, 0CCH, 0CBH, 0CAH, 0C9H
5030 DB 0C8H, 0C7H, 0C6H, 0C5H, 0C4H, 0C3H, 0C2H, 0C1H
5040 DB 0C0H, 0BFH, 0BEH, 0BDH, 0BCH, 0BBH, 0BAH, 0B9H
5050 DB 0B8H, 0B7H, 0B6H, 0B5H, 0B4H, 0B3H, 0B2H, 0B1H
5060 DB 0B0H, 0AFH, 0AEH, 0ADH, 0ACH, 0ABH, 0AAH, 0A9H
5070 DB 0A8H, 0A7H, 0A6H, 0A5H, 0A4H, 0A3H, 0A2H, 0A1H
5080 DB 0A0H, 9FH, 9EH, 9DH, 9CH, 9BH, 9AH, 99H
5090 DB 98H, 97H, 96H, 95H, 94H, 93H, 92H, 91H
5100 DB 90H, 8FH, 8EH, 8DH, 8CH, 8BH, 8AH, 89H
5110 DB 88H, 87H, 86H, 85H, 84H, 83H, 82H, 81H
5120 DB 80H, 7FH, 7EH, 7DH, 7CH, 7BH, 7AH, 79H
5130 DB 78H, 77H, 76H, 75H, 74H, 73H, 72H, 71H
5140 DB 70H, 6FH, 6EH, 6DH, 6CH, 6BH, 6AH, 69H
5150 DB 68H, 67H, 66H, 65H, 64H, 63H, 62H, 61H
5160 DB 60H, 5FH, 5EH, 5DH, 5CH, 5BH, 46H, 47H
5170 DB 48H, 49H, 4AH, 4BH, 4CH, 4DH, 4EH, 4FH
5180 DB 50H, 51H, 52H, 53H, 54H, 55H, 56H, 57H
5190 DB 58H, 59H, 00H, 00H, 00H, 00H, 00H, 00H
5200 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5210 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5220 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5230 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5240 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5250 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5260 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5270 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5280 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5290 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5300 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5310 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5320 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5330 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5340K34: DB 8CH, 8BH, 8AH, 89H, 88H, 87H, 86H, 85H
5350 DB 84H, 83H, 82H, 81H, 80H, 7FH, 7EH, 7DH
5360 DB 7CH, 7BH, 7AH, 79H, 78H, 77H, 76H, 75H
5370 DB 74H, 73H, 72H, 71H, 70H, 6FH, 6EH, 6DH
5380 DB 6CH, 6BH, 6AH, 69H, 68H, 67H, 66H, 65H
5390 DB 64H, 63H, 62H, 61H, 60H, 5FH, 5EH, 5DH
5400 DB 5CH, 5BH, 5AH, 59H, 58H, 57H, 56H, 55H
5410 DB 54H, 53H, 52H, 51H, 50H, 4FH, 4EH, 4DH
5420 DB 4CH, 4BH, 4AH, 49H, 48H, 47H, 46H, 45H
5430 DB 44H, 43H, 42H, 41H, 40H, 3FH, 3EH, 3DH
5440 DB 3CH, 3BH, 3AH, 39H, 38H, 37H, 36H, 35H
5450 DB 34H, 33H, 32H, 31H, 30H, 2FH, 2EH, 2DH
5460 DB 2CH, 2BH, 2AH, 29H, 28H, 27H, 26H, 25H
5470 DB 24H, 23H, 22H, 21H, 20H, 1FH, 1EH, 1DH
5480 DB 1CH, 1BH, 1AH, 19H, 18H, 17H, 16H, 15H
5490 DB 14H, 13H, 12H, 11H, 10H, 0FH, 0EH, 0DH
5500 DB 0CH, 0BH, 0AH, 09H, 08H, 07H, 06H, 05H
5510 DB 04H, 03H, 02H, 01H, 00H, 0FFH, 0FEH, 0FDH
5520 DB 0FCH, 0FBH, 0FAH, 0F9H, 0F8H, 0F7H, 0F6H, 0F5H
5530 DB 0F4H, 0F3H, 0F2H, 0F1H, 0F0H, 0EFH, 0EEH, 0EDH
5540 DB 0ECH, 0EBH, 0EAH, 0E9H, 0E8H, 0E7H, 0E6H, 0E5H
5550 DB 0E4H, 0E3H, 0E2H, 0E1H, 0E0H, 0DFH, 0DEH, 0DDH
5560 DB 0DCH, 0DBH, 0DAH, 0D9H, 0D8H, 0D7H, 0D6H, 0D5H
5570 DB 0D4H, 0D3H, 0D2H, 0D1H, 0D0H, 0CFH, 0CEH, 0CDH
5580 DB 0CCH, 0CBH, 0CAH, 0C9H, 0C8H, 0C7H, 0C6H, 0C5H
5590 DB 0C4H, 0C3H, 0C2H, 0C1H, 0C0H, 0BFH, 0BEH, 0BDH
5600 DB 0BCH, 0BBH, 0BAH, 0B9H, 0B8H, 0B7H, 0B6H, 0B5H
5610 DB 0B4H, 0B3H, 0B2H, 0B1H, 0B0H, 0AFH, 0AEH, 0ADH
5620 DB 0ACH, 0ABH, 0AAH, 0A9H, 0A8H, 0A7H, 0A6H, 0A5H
5630 DB 0A4H, 0A3H, 00H, 00H, 00H, 00H, 00H, 00H
5640 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5650 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5660K56: DB 78H, 77H, 76H, 75H, 74H, 73H, 72H, 71H
5670 DB 70H, 6FH, 6EH, 6DH, 6CH, 6BH, 6AH, 69H
5680 DB 68H, 67H, 66H, 65H, 64H, 63H, 62H, 61H
5690 DB 60H, 5FH, 5EH, 5DH, 5CH, 5BH, 5AH, 59H
5700 DB 58H, 57H, 56H, 55H, 54H, 53H, 52H, 51H
5710 DB 50H, 4FH, 4EH, 4DH, 4CH, 4BH, 4AH, 49H
5720 DB 48H, 47H, 46H, 45H, 44H, 43H, 42H, 41H
5730 DB 40H, 3FH, 3EH, 3DH, 3CH, 3BH, 3AH, 39H
5740 DB 38H, 37H, 36H, 35H, 34H, 33H, 32H, 31H
5750 DB 30H, 2FH, 2EH, 2DH, 2CH, 2BH, 2AH, 29H
5760 DB 28H, 27H, 26H, 25H, 24H, 23H, 22H, 21H
5770 DB 20H, 1FH, 1EH, 1DH, 1CH, 1BH, 1AH, 19H
5780 DB 18H, 17H, 16H, 15H, 14H, 13H, 12H, 11H
5790 DB 10H, 0FH, 0EH, 0DH, 0CH, 0BH, 0AH, 09H
5800 DB 08H, 07H, 06H, 05H, 04H, 03H, 02H, 01H
5810 DB 00H, 0FFH, 0FEH, 0FDH, 0FCH, 0FBH, 0FAH, 0F9H
5820 DB 0F8H, 0F7H, 0F6H, 0F5H, 0F4H, 0F3H, 0F2H, 0F1H
5830 DB 0F0H, 0EFH, 0EEH, 0EDH, 0ECH, 0EBH, 0EAH, 0E9H
5840 DB 0E8H, 0E7H, 0E6H, 0E5H, 0E4H, 0E3H, 0E2H, 0E1H
5850 DB 0E0H, 0DFH, 0DEH, 0DDH, 0DCH, 0DBH, 0DAH, 0D9H
5860 DB 0D8H, 0D7H, 0D6H, 0D5H, 0D4H, 0D3H, 0D2H, 0D1H
5870 DB 0D0H, 0CFH, 0CEH, 0CDH, 00H, 00H, 00H, 00H
5880 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5890 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5900 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5910 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5920 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5930 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5940 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5950 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5960 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5970 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
5980K78: DB 9EH, 9DH, 9CH, 9BH, 9AH, 99H, 98H, 97H
5990 DB 96H, 95H, 94H, 93H, 92H, 91H, 90H, 8FH
6000 DB 8EH, 8DH, 8CH, 8BH, 8AH, 89H, 88H, 87H
6010 DB 86H, 85H, 84H, 83H, 82H, 81H, 80H, 7FH
6020 DB 7EH, 7DH, 7CH, 7BH, 7AH, 79H, 78H, 77H
6030 DB 76H, 75H, 74H, 73H, 72H, 71H, 70H, 6FH
6040 DB 6EH, 6DH, 6CH, 6BH, 6AH, 69H, 68H, 67H
6050 DB 66H, 65H, 64H, 63H, 62H, 61H, 60H, 5FH
6060 DB 5EH, 5DH, 5CH, 5BH, 5AH, 59H, 58H, 57H
6070 DB 56H, 55H, 54H, 53H, 52H, 51H, 50H, 4FH
6080 DB 4EH, 4DH, 4CH, 4BH, 4AH, 49H, 48H, 47H
6090 DB 46H, 45H, 44H, 43H, 42H, 41H, 40H, 3FH
6100 DB 3EH, 3DH, 3CH, 3BH, 3AH, 39H, 38H, 37H
6110 DB 36H, 35H, 34H, 33H, 32H, 31H, 30H, 2FH
6120 DB 2EH, 2DH, 2CH, 2BH, 2AH, 29H, 28H, 27H
6130 DB 26H, 25H, 24H, 23H, 22H, 21H, 20H, 1FH
6140 DB 1EH, 1DH, 1CH, 1BH, 1AH, 19H, 18H, 17H
6150 DB 16H, 15H, 14H, 13H, 12H, 11H, 10H, 0FH
6160 DB 0EH, 0DH, 0CH, 0BH, 0AH, 09H, 08H, 07H
6170 DB 06H, 05H, 04H, 03H, 02H, 01H, 00H, 0FFH
6180 DB 0FEH, 0FDH, 0FCH, 0FBH, 0FAH, 0F9H, 0F8H, 0F7H
6190 DB 0F6H, 0F5H, 0F4H, 0F3H, 0F2H, 0F1H, 0F0H, 0EFH
6200 DB 0EEH, 0EDH, 0ECH, 0EBH, 0EAH, 0E9H, 0E8H, 0E7H
6210 DB 0E6H, 0E5H, 0E4H, 0E3H, 0E2H, 0E1H, 0E0H, 0DFH
6220 DB 0DEH, 0DDH, 0DCH, 0DBH, 0DAH, 0D9H, 0D8H, 0D7H
6230 DB 0D6H, 0D5H, 0D4H, 0D3H, 0D2H, 0D1H, 0D0H, 0CFH
6240 DB 0CEH, 0CDH, 0CCH, 0CBH, 0CAH, 0C9H, 0C8H, 0C7H
6250 DB 0C6H, 0C5H, 0C4H, 0C3H, 0C2H, 0C1H, 0C0H, 0BFH
6260 DB 0BEH, 0BDH, 0BCH, 0BBH, 0BAH, 0B9H, 0B8H, 0B7H
6270 DB 0B6H, 0B5H, 00H, 00H, 00H, 00H, 00H, 00H
6280 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
6290 DB 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H