1
10
13
14
20
21
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
124
125
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
173
174
175
176
177
181
182
183
184
185
187
191
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
216
217
218
222
223
224
225
226
227
228
232
233
234
235
...
...
...
#include "nx_crypto_phash.h"
...
...
NX_CRYPTO_KEEP UINT _nx_crypto_phash(NX_CRYPTO_PHASH *phash, UCHAR *output, UINT desired_length)
{
UINT offset;
UINT hash_size;
UINT output_len;
UINT status;
UCHAR *temp_A;
UINT temp_A_size;
UCHAR *secret;
UINT secret_len;
UCHAR *seed;
UINT seed_len;
UCHAR *metadata;
UINT metadata_size;
UCHAR *hmac_output;
UINT hmac_output_size;
UINT A_len;
UINT remaining_len, i;
VOID *handler = NX_CRYPTO_NULL;
NX_CRYPTO_METHOD *hash_method = phash -> nx_crypto_hmac_method;
NX_CRYPTO_STATE_CHECK
if (hash_method == NX_CRYPTO_NULL
|| hash_method -> nx_crypto_operation == NX_CRYPTO_NULL
|| hash_method -> nx_crypto_cleanup == NX_CRYPTO_NULL
|| output == NX_CRYPTO_NULL)
{
return(NX_CRYPTO_INVALID_PARAMETER);
}if (hash_method == NX_CRYPTO_NULL || hash_method -> nx_crypto_operation == NX_CRYPTO_NULL || hash_method -> nx_crypto_cleanup == NX_CRYPTO_NULL || output == NX_CRYPTO_NULL) { ... }
secret = phash -> nx_crypto_phash_secret;
secret_len = phash -> nx_crypto_phash_secret_length;
seed = phash -> nx_crypto_phash_seed;
seed_len = phash -> nx_crypto_phash_seed_length;
temp_A = phash -> nx_crypto_phash_temp_A;
temp_A_size = phash -> nx_crypto_phash_temp_A_size;
hash_size = hash_method -> nx_crypto_ICV_size_in_bits >> 3;
metadata = phash -> nx_crypto_hmac_metadata;
metadata_size = phash -> nx_crypto_hmac_metadata_size;
hmac_output = phash -> nx_crypto_hmac_output;
hmac_output_size = phash -> nx_crypto_hmac_output_size;
if (hash_size > hmac_output_size)
{
return(NX_CRYPTO_INVALID_PARAMETER);
}if (hash_size > hmac_output_size) { ... }
if (seed_len > temp_A_size)
{
return(NX_CRYPTO_SIZE_ERROR);
}if (seed_len > temp_A_size) { ... }
NX_CRYPTO_MEMSET(temp_A, 0, temp_A_size);
NX_CRYPTO_MEMCPY(temp_A, seed, seed_len);
A_len = phash -> nx_crypto_phash_seed_length;
remaining_len = desired_length;
for (offset = 0; offset < desired_length; offset += hash_size)
{
if (hash_method -> nx_crypto_init)
{
status = hash_method -> nx_crypto_init(hash_method,
secret,
(NX_CRYPTO_KEY_SIZE)(secret_len << 3),
&handler,
metadata,
metadata_size);
if(status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}if (hash_method -> nx_crypto_init) { ... }
status = hash_method -> nx_crypto_operation(NX_CRYPTO_AUTHENTICATE,
handler,
hash_method,
secret,
(NX_CRYPTO_KEY_SIZE)(secret_len << 3),
temp_A,
A_len,
NX_CRYPTO_NULL,
temp_A,
temp_A_size,
metadata,
metadata_size,
NX_CRYPTO_NULL,
NX_CRYPTO_NULL);
if(status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
A_len = hash_size;
if ((A_len + seed_len) > temp_A_size)
{
return(NX_CRYPTO_SIZE_ERROR);
}if ((A_len + seed_len) > temp_A_size) { ... }
NX_CRYPTO_MEMCPY(&temp_A[A_len], seed, seed_len);
/* ... */
if (remaining_len < hash_size)
{
output_len = remaining_len;
}if (remaining_len < hash_size) { ... }
else
{
output_len = hash_size;
}else { ... }
status = hash_method -> nx_crypto_operation(NX_CRYPTO_AUTHENTICATE,
handler,
hash_method,
secret,
(NX_CRYPTO_KEY_SIZE)(secret_len << 3),
temp_A,
A_len + seed_len,
NX_CRYPTO_NULL,
hmac_output,
output_len,
metadata,
metadata_size,
NX_CRYPTO_NULL,
NX_CRYPTO_NULL);
if(status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
for (i = 0; i < output_len; i++)
{
output[offset + i] ^= hmac_output[i];
}for (i = 0; i < output_len; i++) { ... }
remaining_len -= hash_size;
status = hash_method -> nx_crypto_cleanup(metadata);
if(status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}for (offset = 0; offset < desired_length; offset += hash_size) { ... }
return(NX_CRYPTO_SUCCESS);
}{ ... }