Subversion Repositories Kolibri OS

Rev

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

Rev 6419 Rev 6469
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 17... Line 17...
17
 
17
 
18
struct aes256_cbc_context aes256_context
18
struct aes256_cbc_context aes256_context
19
        vector  rb 16
19
        vector  rb AES256_BLOCKSIZE
Line 20... Line 20...
20
ends
20
ends
21
 
21
 
Line 22... Line 22...
22
 
22
 
23
proc aes256_cbc_init _vector
23
proc aes256_cbc_init _vector
24
        push    ebx esi edi
24
        push    ebx esi edi
25
 
25
 
26
        mcall   68, 12, sizeof.aes256_cbc_context
26
        mcall   68, 12, sizeof.aes256_cbc_context
27
        ; handle errors
27
        ; handle errors
28
        mov     ecx, 16/4
28
        mov     ecx, AES256_BLOCKSIZE/4
Line 37... Line 37...
37
 
37
 
38
proc aes256_cbc_encrypt _ctx, _in, _out
38
proc aes256_cbc_encrypt _ctx, _in, _out
Line 39... Line 39...
39
        push    ebx esi edi
39
        push    ebx esi edi
40
 
40
 
41
        DEBUGF  1,'plain  : '
-
 
Line 42... Line 41...
42
        stdcall dump_128bit_hex, [_in]
41
        DEBUGF  1,'plain  : '
43
        DEBUGF  1,'\n'
42
        stdcall dump_hex, [_in], 4
44
 
43
 
-
 
44
        mov     edi, [_ctx]
45
        mov     edi, [_ctx]
45
        lea     edi, [edi + aes256_cbc_context.vector]
46
        lea     edi, [edi + aes256_cbc_context.vector]
46
        mov     esi, [_in]
47
        mov     esi, [_in]
47
repeat AES256_BLOCKSIZE/4
48
        lodsd
-
 
49
        xor     eax, [edi]
-
 
50
        stosd
-
 
51
        lodsd
-
 
52
        xor     eax, [edi]
-
 
53
        stosd
48
        lodsd
54
        lodsd
-
 
55
        xor     eax, [edi]
-
 
56
        stosd
-
 
Line 57... Line 49...
57
        lodsd
49
        xor     eax, [edi]
58
        xor     eax, [edi]
50
        stosd
59
        stosd
51
end repeat
60
 
52
 
Line 61... Line 53...
61
        mov     esi, [_ctx]
53
        mov     esi, [_ctx]
62
        lea     eax, [esi + aes256_cbc_context.key]
54
        lea     eax, [esi + aes256_cbc_context.key]
63
        lea     ebx, [esi + aes256_cbc_context.vector]
55
        lea     ebx, [esi + aes256_cbc_context.vector]
-
 
56
        stdcall aes256_encrypt, eax, ebx, [_out]   ; Key, in, out
64
        stdcall aes256_encrypt, eax, ebx, [_out]   ; Key, in, out
57
 
65
 
-
 
66
        mov     esi, [_out]
-
 
67
        mov     eax, [_ctx]
58
        mov     esi, [_out]
Line 68... Line 59...
68
        lea     edi, [eax + aes256_cbc_context.vector]
59
        mov     eax, [_ctx]
69
        movsd
60
        lea     edi, [eax + aes256_cbc_context.vector]
70
        movsd
-
 
Line 71... Line 61...
71
        movsd
61
repeat AES256_BLOCKSIZE/4
72
        movsd
62
        movsd
73
 
63
end repeat
Line 74... Line 64...
74
        DEBUGF  1,'cipher : '
64
 
-
 
65
        DEBUGF  1,'cipher : '
-
 
66
        stdcall dump_hex, [_out], 4
-
 
67
 
-
 
68
        pop     edi esi ebx
-
 
69
        ret
75
        stdcall dump_128bit_hex, [_out]
70
endp
Line 76... Line 71...
76
        DEBUGF  1,'\n\n'
71
 
77
 
72
proc aes256_cbc_decrypt _ctx, _in, _out
-
 
73
 
78
        pop     edi esi ebx
74
locals
-
 
75
        temp_iv rb AES256_BLOCKSIZE
-
 
76
endl
-
 
77
 
-
 
78
        push    ebx esi edi
Line 79... Line 79...
79
        ret
79
 
80
endp
80
        DEBUGF  1,'cipher : '
81
 
81
        stdcall dump_hex, [_in], 4
Line 82... Line 82...
82
proc aes256_cbc_decrypt _ctx, _in, _out
82
 
83
        push    ebx esi edi
83
        mov     esi, [_in]
84
 
84
        lea     edi, [temp_iv]
-
 
85
repeat AES256_BLOCKSIZE/4
85
        DEBUGF  1,'cipher : '
86
        movsd
86
        stdcall dump_128bit_hex, [_in]
87
end repeat
87
        DEBUGF  1,'\n'
88
 
88
 
-
 
89
        mov     esi, [_ctx]
-
 
90
        lea     eax, [esi + aes256_cbc_context.key]
-
 
91
        stdcall aes256_decrypt, eax, [_in], [_out]   ; Key, in, out
-
 
92
 
-
 
93
        mov     esi, [_ctx]
89
        mov     esi, [_ctx]
94
        lea     esi, [esi + aes256_cbc_context.vector]
-
 
95
        mov     edi, [_out]
-
 
96
        lodsd
-
 
Line 97... Line 90...
97
        xor     eax, [edi]
90
        lea     eax, [esi + aes256_cbc_context.key]
98
        stosd
91
        stdcall aes256_decrypt, eax, [_in], [_out]   ; Key, in, out
99
        lodsd
92
 
-
 
93
        mov     esi, [_ctx]
100
        xor     eax, [edi]
94
        lea     esi, [esi + aes256_cbc_context.vector]
101
        stosd
-
 
102
        lodsd
-
 
103
        xor     eax, [edi]
95
        mov     edi, [_out]
Line 104... Line 96...
104
        stosd
96
repeat AES256_BLOCKSIZE/4
105
        lodsd
97
        lodsd
106
        xor     eax, [edi]
-
 
Line 107... Line 98...
107
        stosd
98
        xor     eax, [edi]
108
 
99
        stosd
109
        mov     esi, [_in]
100
end repeat
110
        mov     edi, [_ctx]
101