Subversion Repositories Kolibri OS

Rev

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

Rev 6469 Rev 7698
Line 20... Line 20...
20
; To compute HMAC over the data `text' we perform
20
; To compute HMAC over the data `text' we perform
21
; H(K XOR opad, H(K XOR ipad, text))
21
; H(K XOR opad, H(K XOR ipad, text))
Line 22... Line 22...
22
 
22
 
23
struct hmac_sha256_context
23
struct hmac_sha256_context
24
        hash            rb SHA256_HASH_SIZE
24
        hash            rb SHA256_HASH_SIZE
25
        ipad_ctx        ctx_sha224256
25
        ipad_ctx        crash_ctx
26
        opad_ctx        ctx_sha224256
26
        opad_ctx        crash_ctx
Line 27... Line 27...
27
ends
27
ends
28
 
28
 
Line 29... Line 29...
29
; We will precompute partial hashes of K XOR ipad and K XOR opad,
29
; We will precompute partial hashes of K XOR ipad and K XOR opad,
Line 30... Line 30...
30
; and store them in the context structure.
30
; and store them in the context structure.
31
 
31
 
32
proc hmac_sha256_setkey ctx, key, key_length
32
proc hmac_sha256_setkey ctx, key, key_length
Line 33... Line 33...
33
 
33
 
Line 34... Line 34...
34
locals
34
locals
35
        k_temp  rb SHA224256_BLOCK_SIZE
35
        k_temp  rb SHA256_BLOCK_SIZE
36
endl
36
endl
37
 
37
 
38
        pusha
38
        pusha
39
 
39
 
40
; input esi = key, ecx=key_length
40
; input esi = key, ecx=key_length
41
        mov     ecx, [key_length]
41
        mov     ecx, [key_length]
42
        cmp     ecx, SHA224256_BLOCK_SIZE
42
        cmp     ecx, SHA256_BLOCK_SIZE
43
        ja      .hash_it
43
        ja      .hash_it
44
; Key is smaller then or equal to blocksize,
44
; Key is smaller then or equal to blocksize,
45
; copy key to ipad
45
; copy key to ipad
46
        mov     esi, [key]
46
        mov     esi, [key]
47
        lea     edi, [k_temp]
47
        lea     edi, [k_temp]
48
        rep movsb
48
        rep movsb
Line 62... Line 62...
62
        mov     esi, [ctx]
62
        mov     esi, [ctx]
63
        lea     edi, [k_temp]
63
        lea     edi, [k_temp]
64
        mov     ecx, SHA256_HASH_SIZE/4
64
        mov     ecx, SHA256_HASH_SIZE/4
65
        rep movsd
65
        rep movsd
66
        xor     eax, eax
66
        xor     eax, eax
67
        mov     ecx, (SHA224256_BLOCK_SIZE-SHA256_HASH_SIZE)/4
67
        mov     ecx, (SHA256_BLOCK_SIZE-SHA256_HASH_SIZE)/4
68
        rep stosd
68
        rep stosd
Line 69... Line 69...
69
 
69
 
70
  .finish:
70
  .finish:
71
; xor ipad buffer with 0x36363...
71
; xor ipad buffer with 0x36363...
72
        lea     esi, [k_temp]
72
        lea     esi, [k_temp]
73
        mov     ecx, SHA224256_BLOCK_SIZE/4
73
        mov     ecx, SHA256_BLOCK_SIZE/4
74
  @@:
74
  @@:
75
        xor     dword[esi], 0x36363636          ; ipad constant
75
        xor     dword[esi], 0x36363636          ; ipad constant
76
        add     esi, 4
76
        add     esi, 4
77
        dec     ecx
77
        dec     ecx
Line 82... Line 82...
82
        lea     edi, [ebx+hmac_sha256_context.ipad_ctx]
82
        lea     edi, [ebx+hmac_sha256_context.ipad_ctx]
83
        invoke  sha256_init, edi
83
        invoke  sha256_init, edi
Line 84... Line 84...
84
 
84
 
85
        lea     esi, [k_temp]
85
        lea     esi, [k_temp]
86
        DEBUGF  1, "HASH: "
86
        DEBUGF  1, "HASH: "
Line 87... Line 87...
87
        stdcall dump_hex, esi, SHA224256_BLOCK_SIZE/4
87
        stdcall dump_hex, esi, SHA256_BLOCK_SIZE/4
88
 
88
 
89
        mov     ebx, [ctx]
89
        mov     ebx, [ctx]
Line 90... Line 90...
90
        lea     edi, [ebx+hmac_sha256_context.ipad_ctx]
90
        lea     edi, [ebx+hmac_sha256_context.ipad_ctx]
91
        invoke  sha256_update, edi, esi, SHA224256_BLOCK_SIZE
91
        invoke  sha256_update, edi, esi, SHA256_BLOCK_SIZE
92
 
92
 
93
; xor opad buffer with 0x5c5c5...
93
; xor opad buffer with 0x5c5c5...
94
        lea     esi, [k_temp]
94
        lea     esi, [k_temp]
95
        mov     ecx, SHA224256_BLOCK_SIZE/4
95
        mov     ecx, SHA256_BLOCK_SIZE/4
96
  @@:
96
  @@:
97
        xor     dword[esi], 0x36363636 xor 0x5c5c5c5c   ; opad constant
97
        xor     dword[esi], 0x36363636 xor 0x5c5c5c5c   ; opad constant
Line 104... Line 104...
104
        lea     edi, [ebx+hmac_sha256_context.opad_ctx]
104
        lea     edi, [ebx+hmac_sha256_context.opad_ctx]
105
        invoke  sha256_init, edi
105
        invoke  sha256_init, edi
Line 106... Line 106...
106
 
106
 
107
        lea     esi, [k_temp]
107
        lea     esi, [k_temp]
108
        DEBUGF  1, "HASH: "
108
        DEBUGF  1, "HASH: "
Line 109... Line 109...
109
        stdcall dump_hex, esi, SHA224256_BLOCK_SIZE/4
109
        stdcall dump_hex, esi, SHA256_BLOCK_SIZE/4
110
 
110
 
111
        mov     ebx, [ctx]
111
        mov     ebx, [ctx]
Line 112... Line 112...
112
        lea     edi, [ebx+hmac_sha256_context.opad_ctx]
112
        lea     edi, [ebx+hmac_sha256_context.opad_ctx]
113
        invoke  sha256_update, edi, esi, SHA224256_BLOCK_SIZE
113
        invoke  sha256_update, edi, esi, SHA256_BLOCK_SIZE
Line 114... Line 114...
114
 
114
 
Line 122... Line 122...
122
; TODO: remove unnescessary pushing/popping
122
; TODO: remove unnescessary pushing/popping
Line 123... Line 123...
123
 
123
 
Line 124... Line 124...
124
proc hmac_sha256 ctx, _data, _length
124
proc hmac_sha256 ctx, _data, _length
125
 
125
 
126
locals
126
locals
127
        inner_ctx        ctx_sha224256
127
        inner_ctx        crash_ctx
Line 128... Line 128...
128
        outer_ctx        ctx_sha224256
128
        outer_ctx        crash_ctx
129
endl
129
endl
130
 
130
 
Line 136... Line 136...
136
 
136
 
137
; Copy partial hashes of ipad and opad to our temporary buffers
137
; Copy partial hashes of ipad and opad to our temporary buffers
138
        mov     esi, [ctx]
138
        mov     esi, [ctx]
139
        lea     esi, [esi+hmac_sha256_context.ipad_ctx]
139
        lea     esi, [esi+hmac_sha256_context.ipad_ctx]
140
        lea     edi, [inner_ctx]
140
        lea     edi, [inner_ctx]
141
repeat (sizeof.ctx_sha224256)/4*2
141
repeat (sizeof.crash_ctx)/4*2
142
        movsd
142
        movsd
Line 143... Line 143...
143
end repeat
143
end repeat
144
 
144