Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6419 hidnplayr 1
;    aestest.inc - AES test suite
2
;
3
;    Copyright (C) 2016 Ivan Baravy (dunkaist)
4
;    Copyright (C) 2016 Jeffrey Amelynck
5
;
6
;    This program is free software: you can redistribute it and/or modify
7
;    it under the terms of the GNU General Public License as published by
8
;    the Free Software Foundation, either version 3 of the License, or
9
;    (at your option) any later version.
10
;
11
;    This program is distributed in the hope that it will be useful,
12
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
;    GNU General Public License for more details.
15
;
16
;    You should have received a copy of the GNU General Public License
17
;    along with this program.  If not, see .
18
 
19
format binary as ""
20
 
21
use32
22
    org 0x0
23
    db  'MENUET01'
24
    dd  0x01,start,i_end,e_end,e_end,0,0
25
 
26
__DEBUG__       = 1
27
__DEBUG_LEVEL__ = 1
28
 
29
include '../../../proc32.inc'
30
include '../../../macros.inc'
31
include '../../../dll.inc'
32
include '../../../debug-fdo.inc'
33
;include 'libcrash.inc'
34
include '../aes256.inc'
35
include '../aes256-ctr.inc'
36
include '../aes256-cbc.inc'
37
 
38
; Test vectors are taken from the very end of sp800-38a.pdf
39
 
40
 
41
start:
42
        mcall   68, 11
43
 
44
DEBUGF 1,'===========================================\n'
45
DEBUGF 1,'AES256_CTR_CRYPT\n'
46
        DEBUGF  1,'\n'
47
        DEBUGF  1,'key    : '
48
        stdcall dump_128bit_hex, key
49
        DEBUGF  1,'\n'
50
        DEBUGF  1,'         '
51
        stdcall dump_128bit_hex, key+16
52
        DEBUGF  1,'\n'
53
        DEBUGF  1,'\n'
54
        DEBUGF  1,'counter: '
55
        stdcall dump_128bit_hex, counter
56
        DEBUGF  1,'\n'
57
        DEBUGF  1,'\n'
58
 
59
        stdcall aes256_ctr_init, counter
60
        ; returns context, save it to ebx
61
        mov     ebx, eax
62
        stdcall aes256_set_encrypt_key, ebx, key
63
 
64
        mov     esi, plain
65
        mov     edi, cipher
66
        mov     ecx, 4
67
  @@:
68
        push    ecx
69
        stdcall aes256_ctr_crypt, ebx, esi, edi
70
        pop     ecx
71
        add     esi, 16
72
        add     edi, 16
73
        loop    @r
74
 
75
DEBUGF 1,'===========================================\n'
76
DEBUGF 1,'AES256_CBC_ENCRYPT\n'
77
        DEBUGF  1,'\n'
78
        DEBUGF  1,'key    : '
79
        stdcall dump_128bit_hex, key
80
        DEBUGF  1,'\n'
81
        DEBUGF  1,'         '
82
        stdcall dump_128bit_hex, key+16
83
        DEBUGF  1,'\n'
84
        DEBUGF  1,'\n'
85
        DEBUGF  1,'IV     : '
86
        stdcall dump_128bit_hex, iv
87
        DEBUGF  1,'\n'
88
        DEBUGF  1,'\n'
89
 
90
        stdcall aes256_cbc_init, iv
91
        ; returns context, save it to ebx
92
        mov     ebx, eax
93
        stdcall aes256_set_encrypt_key, ebx, key
94
 
95
        mov     esi, plain
96
        mov     edi, cipher
97
        mov     ecx, 4
98
  @@:
99
        push    ecx
100
        stdcall aes256_cbc_encrypt, ebx, esi, edi
101
        pop     ecx
102
        add     esi, 16
103
        add     edi, 16
104
        loop    @r
105
 
106
DEBUGF 1,'===========================================\n'
107
DEBUGF 1,'AES256_CBC_DECRYPT\n'
108
        DEBUGF  1,'\n'
109
        DEBUGF  1,'key    : '
110
        stdcall dump_128bit_hex, key
111
        DEBUGF  1,'\n'
112
        DEBUGF  1,'         '
113
        stdcall dump_128bit_hex, key+16
114
        DEBUGF  1,'\n'
115
        DEBUGF  1,'\n'
116
        DEBUGF  1,'IV     : '
117
        stdcall dump_128bit_hex, iv
118
        DEBUGF  1,'\n'
119
        DEBUGF  1,'\n'
120
 
121
        stdcall aes256_cbc_init, iv
122
        ; returns context, save it to ebx
123
        mov     ebx, eax
124
        stdcall aes256_set_decrypt_key, ebx, key
125
 
126
        mov     esi, cipher
127
        mov     edi, plain
128
        mov     ecx, 4
129
  @@:
130
        push    ecx
131
        stdcall aes256_cbc_decrypt, ebx, esi, edi
132
        pop     ecx
133
        add     esi, 16
134
        add     edi, 16
135
        loop    @r
136
 
137
quit:
138
DEBUGF 1,'===========================================\n'
139
        mcall   -1
140
 
141
 
142
key     db      0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,\
143
                0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,\
144
                0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
145
 
146
iv      db      0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,\
147
                0x0c,0x0d,0x0e,0x0f
148
 
149
counter db      0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,\
150
                0xfc,0xfd,0xfe,0xff
151
 
152
plain   db      0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,\
153
                0x73,0x93,0x17,0x2a,0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,\
154
                0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,0x30,0xc8,0x1c,0x46,\
155
                0xa3,0x5c,0xe4,0x11,0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,\
156
                0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,0xad,0x2b,0x41,0x7b,\
157
                0xe6,0x6c,0x37,0x10
158
 
159
cipher  rd      16
160
 
161
; CTR-AES256.Encrypt
162
;
163
; Key           603deb1015ca71be2b73aef0857d7781
164
;               1f352c073b6108d72d9810a30914dff4
165
; Init. Counter f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
166
;
167
;
168
; Block #1
169
;
170
; Input Block   f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
171
; Output Block  0bdf7df1591716335e9a8b15c860c502
172
; Plaintext     6bc1bee22e409f96e93d7e117393172a
173
; Ciphertext    601ec313775789a5b7a7f504bbf3d228
174
;
175
;
176
; Block #2
177
;
178
; Input Block   f0f1f2f3f4f5f6f7f8f9fafbfcfdff00
179
; Output Block  5a6e699d536119065433863c8f657b94
180
; Plaintext     ae2d8a571e03ac9c9eb76fac45af8e51
181
; Ciphertext    f443e3ca4d62b59aca84e990cacaf5c5
182
;
183
;
184
; Block #3
185
;
186
; Input Block   f0f1f2f3f4f5f6f7f8f9fafbfcfdff01
187
; Output Block  1bc12c9c01610d5d0d8bd6a3378eca62
188
; Plaintext     30c81c46a35ce411e5fbc1191a0a52ef
189
; Ciphertext    2b0930daa23de94ce87017ba2d84988d
190
;
191
;
192
; Block #4
193
;
194
; Input Block   f0f1f2f3f4f5f6f7f8f9fafbfcfdff02
195
; Output Block  2956e1c8693536b1bee99c73a31576b6
196
; Plaintext     f69f2445df4f9b17ad2b417be66c3710
197
; Ciphertext    dfc9c58db67aada613c2dd08457941a6
198
 
199
 
200
; CBC-AES256.Encrypt
201
; Key           603deb1015ca71be2b73aef0857d7781
202
;               1f352c073b6108d72d9810a30914dff4
203
; IV            000102030405060708090a0b0c0d0e0f
204
;
205
; Block #1
206
;
207
; Plaintext     6bc1bee22e409f96e93d7e117393172a
208
; Input Block   6bc0bce12a459991e134741a7f9e1925
209
; Output Block  f58c4c04d6e5f1ba779eabfb5f7bfbd6
210
; Ciphertext    f58c4c04d6e5f1ba779eabfb5f7bfbd6
211
;
212
; Block #2
213
;
214
; Plaintext     ae2d8a571e03ac9c9eb76fac45af8e51
215
; Input Block   5ba1c653c8e65d26e929c4571ad47587
216
; Output Block  9cfc4e967edb808d679f777bc6702c7d
217
; Ciphertext    9cfc4e967edb808d679f777bc6702c7d
218
;
219
; Block #3
220
;
221
; Plaintext     30c81c46a35ce411e5fbc1191a0a52ef
222
; Input Block   ac3452d0dd87649c8264b662dc7a7e92
223
; Output Block  39f23369a9d9bacfa530e26304231461
224
; Ciphertext    39f23369a9d9bacfa530e26304231461
225
;
226
; Block #4
227
;
228
; Plaintext     f69f2445df4f9b17ad2b417be66c3710
229
; Input Block   cf6d172c769621d8081ba318e24f2371
230
; Output Block  b2eb05e2c39be9fcda6c19078c6a9d1b
231
; Ciphertext    b2eb05e2c39be9fcda6c19078c6a9d1b
232
 
233
 
234
; CBC-AES256.Decrypt
235
; Key           603deb1015ca71be2b73aef0857d7781
236
;               1f352c073b6108d72d9810a30914dff4
237
; IV            000102030405060708090a0b0c0d0e0f
238
;
239
; Block #1
240
;
241
; Ciphertext    f58c4c04d6e5f1ba779eabfb5f7bfbd6
242
; Input Block   f58c4c04d6e5f1ba779eabfb5f7bfbd6
243
; Output Block  6bc0bce12a459991e134741a7f9e1925
244
; Plaintext     6bc1bee22e409f96e93d7e117393172a
245
;
246
; Block #2
247
;
248
; Ciphertext    9cfc4e967edb808d679f777bc6702c7d
249
; Input Block   9cfc4e967edb808d679f777bc6702c7d
250
; Output Block  5ba1c653c8e65d26e929c4571ad47587
251
; Plaintext     ae2d8a571e03ac9c9eb76fac45af8e51
252
;
253
; Block #3
254
;
255
; Ciphertext    39f23369a9d9bacfa530e26304231461
256
; Input Block   39f23369a9d9bacfa530e26304231461
257
; Output Block  ac3452d0dd87649c8264b662dc7a7e92
258
; Plaintext     30c81c46a35ce411e5fbc1191a0a52ef
259
;
260
; Block #4
261
;
262
; Ciphertext    b2eb05e2c39be9fcda6c19078c6a9d1b
263
; Input Block   b2eb05e2c39be9fcda6c19078c6a9d1b
264
; Output Block  cf6d172c769621d8081ba318e24f2371
265
; Plaintext     f69f2445df4f9b17ad2b417be66c3710
266
 
267
 
268
 
269
include_debug_strings
270
 
271
IncludeIGlobals
272
 
273
i_end:
274
 
275
IncludeUGlobals
276
 
277
rb 0x1000       ;stack
278
e_end:
279