Subversion Repositories Kolibri OS

Rev

Rev 6465 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6465 Rev 7698
Line 1... Line 1...
1
;    libcrash -- cryptographic hash functions
1
;    libcrash -- cryptographic hash functions
2
;
2
;
3
;    Copyright (C) 2013,2016 Ivan Baravy (dunkaist)
3
;    Copyright (C) 2013,2016,2019 Ivan Baravy (dunkaist)
4
;
4
;
5
;    This program is free software: you can redistribute it and/or modify
5
;    This program is free software: you can redistribute it and/or modify
6
;    it under the terms of the GNU General Public License as published by
6
;    it under the terms of the GNU General Public License as published by
7
;    the Free Software Foundation, either version 3 of the License, or
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
8
;    (at your option) any later version.
Line 14... Line 14...
14
;
14
;
15
;    You should have received a copy of the GNU General Public License
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
16
;    along with this program.  If not, see .
Line -... Line 17...
-
 
17
 
-
 
18
 
-
 
19
SHA3_224_HASH_SIZE       = 28
-
 
20
SHA3_256_HASH_SIZE       = 32
-
 
21
SHA3_384_HASH_SIZE       = 48
-
 
22
SHA3_512_HASH_SIZE       = 64
-
 
23
 
-
 
24
SHA3_224_BLOCK_SIZE      = 144
-
 
25
SHA3_256_BLOCK_SIZE      = 136
-
 
26
SHA3_384_BLOCK_SIZE      = 104
-
 
27
SHA3_512_BLOCK_SIZE      = 72
-
 
28
SHA3MAX_BLOCK_SIZE      = SHA3_224_BLOCK_SIZE
-
 
29
 
-
 
30
SHA3_INIT_SIZE          = 200
-
 
31
SHA3_ALIGN              = 16
-
 
32
SHA3_ALIGN_MASK         = SHA3_ALIGN-1
-
 
33
 
-
 
34
struct ctx_sha3
-
 
35
        hash            rb SHA3_INIT_SIZE
-
 
36
                        rb SHA3_ALIGN - (SHA3_INIT_SIZE mod SHA3_ALIGN)
-
 
37
        block           rb SHA3MAX_BLOCK_SIZE
-
 
38
                        rb SHA3_ALIGN - (SHA3MAX_BLOCK_SIZE mod SHA3_ALIGN)
-
 
39
        index           rd 1
-
 
40
        block_size      rd 1
-
 
41
        rounds_cnt      rd 1
-
 
42
                        rd 1    ; align
-
 
43
        ; tmp vars
-
 
44
        C               rq 5
-
 
45
        D               rq 5
-
 
46
ends
-
 
47
 
-
 
48
if defined sizeof.crash_ctx
-
 
49
  assert sizeof.crash_ctx >= sizeof.ctx_sha3
17
 
50
end if
18
 
51
 
19
macro sha3._.rol_xor nd, ncl, ncr
52
macro sha3._.rol_xor nd, ncl, ncr
20
{
53
{
21
        movq    mm0, [C + 8*(ncl)]
54
        movq    mm0, [C + 8*(ncl)]
Line 242... Line 275...
242
        mov     [ebx + ctx_sha3.index], eax
275
        mov     [ebx + ctx_sha3.index], eax
243
        ret
276
        ret
244
endp
277
endp
Line 245... Line 278...
245
 
278
 
246
 
279
 
247
proc sha3224.init _ctx
280
proc sha3_224.init _ctx
248
        mov     ebx, [_ctx]
281
        mov     ebx, [_ctx]
249
        mov     eax, SHA3224_BLOCK_SIZE
282
        mov     eax, SHA3_224_BLOCK_SIZE
250
        stdcall sha3._.init
283
        stdcall sha3._.init
Line 251... Line 284...
251
        ret
284
        ret
252
endp
285
endp
253
 
286
 
254
 
287
 
255
proc sha3256.init _ctx
288
proc sha3_256.init _ctx
256
        mov     ebx, [_ctx]
289
        mov     ebx, [_ctx]
Line 257... Line 290...
257
        mov     eax, SHA3256_BLOCK_SIZE
290
        mov     eax, SHA3_256_BLOCK_SIZE
258
        stdcall sha3._.init
291
        stdcall sha3._.init
259
        ret
292
        ret
260
endp
293
endp
261
 
294
 
262
 
295
 
Line 263... Line 296...
263
proc sha3384.init _ctx
296
proc sha3_384.init _ctx
264
        mov     ebx, [_ctx]
297
        mov     ebx, [_ctx]
265
        mov     eax, SHA3384_BLOCK_SIZE
298
        mov     eax, SHA3_384_BLOCK_SIZE
266
        stdcall sha3._.init
299
        stdcall sha3._.init
267
        ret
300
        ret
268
endp
301
endp
Line 291... Line 324...
291
 
324
 
292
        ret
325
        ret
Line 293... Line 326...
293
endp
326
endp
294
 
327
 
295
 
328
 
296
sha3224.update = sha3.update
329
sha3_224.update = sha3.update
297
sha3256.update = sha3.update
330
sha3_256.update = sha3.update
298
sha3384.update = sha3.update
331
sha3_384.update = sha3.update
299
sha3512.update = sha3.update
332
sha3_512.update = sha3.update
300
proc sha3.update _ctx, _msg, _size
333
proc sha3.update _ctx, _msg, _size
301
  .next_block:
334
  .next_block:
Line 353... Line 386...
353
  .quit:
386
  .quit:
354
        ret
387
        ret
355
endp
388
endp
Line 356... Line 389...
356
 
389
 
357
 
390
 
358
sha3224.final = sha3.final
391
sha3_224.final = sha3.final
359
sha3256.final = sha3.final
392
sha3_256.final = sha3.final
360
sha3384.final = sha3.final
393
sha3_384.final = sha3.final
361
sha3512.final = sha3.final
394
sha3_512.final = sha3.final
362
proc sha3.final _ctx
395
proc sha3.final _ctx
363
        pushad
396
        pushad
364
        mov     ebx, [_ctx]
397
        mov     ebx, [_ctx]
Line 402... Line 435...
402
        emms
435
        emms
403
        ret
436
        ret
404
endp
437
endp
Line -... Line 438...
-
 
438
 
-
 
439
 
-
 
440
proc sha3_224.oneshot _ctx, _data, _len
405
 
441
	stdcall	sha3_224.init, [_ctx]
-
 
442
	stdcall	sha3.update, [_ctx], [_data], [_len]
-
 
443
	stdcall	sha3.final, [_ctx]
-
 
444
	ret
Line -... Line 445...
-
 
445
endp
-
 
446
 
-
 
447
 
-
 
448
proc sha3_256.oneshot _ctx, _data, _len
-
 
449
	stdcall	sha3_256.init, [_ctx]
-
 
450
	stdcall	sha3.update, [_ctx], [_data], [_len]
-
 
451
	stdcall	sha3.final, [_ctx]
-
 
452
	ret
-
 
453
endp
-
 
454
 
-
 
455
 
-
 
456
proc sha3_384.oneshot _ctx, _data, _len
-
 
457
	stdcall	sha3_384.init, [_ctx]
-
 
458
	stdcall	sha3.update, [_ctx], [_data], [_len]
-
 
459
	stdcall	sha3.final, [_ctx]
-
 
460
	ret
-
 
461
endp
-
 
462
 
-
 
463
 
-
 
464
proc sha3_512.oneshot _ctx, _data, _len
-
 
465
	stdcall	sha3_512.init, [_ctx]
-
 
466
	stdcall	sha3.update, [_ctx], [_data], [_len]
-
 
467
	stdcall	sha3.final, [_ctx]
-
 
468
	ret
-
 
469
endp
-
 
470
 
406
 
471
 
407
align SHA3_ALIGN
472
iglobal
408
 
473
align SHA3_ALIGN
409
sha3._.round    dq 0x0000000000000001, 0x0000000000008082, 0x800000000000808A,\
474
sha3._.round    dq 0x0000000000000001, 0x0000000000008082, 0x800000000000808A,\
410
                   0x8000000080008000, 0x000000000000808B, 0x0000000080000001,\
475
                   0x8000000080008000, 0x000000000000808B, 0x0000000080000001,\
411
                   0x8000000080008081, 0x8000000000008009, 0x000000000000008A,\
476
                   0x8000000080008081, 0x8000000000008009, 0x000000000000008A,\
412
                   0x0000000000000088, 0x0000000080008009, 0x000000008000000A,\
477
                   0x0000000000000088, 0x0000000080008009, 0x000000008000000A,\
413
                   0x000000008000808B, 0x800000000000008B, 0x8000000000008089,\
478
                   0x000000008000808B, 0x800000000000008B, 0x8000000000008089,\
414
                   0x8000000000008003, 0x8000000000008002, 0x8000000000000080,\
479
                   0x8000000000008003, 0x8000000000008002, 0x8000000000000080,\