Lines Matching refs:ctx
34 struct crypto_hash *ctx; in crypto_hash_init() local
39 ctx = os_zalloc(sizeof(*ctx)); in crypto_hash_init()
40 if (ctx == NULL) in crypto_hash_init()
43 ctx->alg = alg; in crypto_hash_init()
47 MD5Init(&ctx->u.md5); in crypto_hash_init()
50 SHA1Init(&ctx->u.sha1); in crypto_hash_init()
54 sha256_init(&ctx->u.sha256); in crypto_hash_init()
59 MD5Init(&ctx->u.md5); in crypto_hash_init()
60 MD5Update(&ctx->u.md5, key, key_len); in crypto_hash_init()
61 MD5Final(tk, &ctx->u.md5); in crypto_hash_init()
65 os_memcpy(ctx->key, key, key_len); in crypto_hash_init()
66 ctx->key_len = key_len; in crypto_hash_init()
73 MD5Init(&ctx->u.md5); in crypto_hash_init()
74 MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad)); in crypto_hash_init()
78 SHA1Init(&ctx->u.sha1); in crypto_hash_init()
79 SHA1Update(&ctx->u.sha1, key, key_len); in crypto_hash_init()
80 SHA1Final(tk, &ctx->u.sha1); in crypto_hash_init()
84 os_memcpy(ctx->key, key, key_len); in crypto_hash_init()
85 ctx->key_len = key_len; in crypto_hash_init()
92 SHA1Init(&ctx->u.sha1); in crypto_hash_init()
93 SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad)); in crypto_hash_init()
98 sha256_init(&ctx->u.sha256); in crypto_hash_init()
99 sha256_process(&ctx->u.sha256, key, key_len); in crypto_hash_init()
100 sha256_done(&ctx->u.sha256, tk); in crypto_hash_init()
104 os_memcpy(ctx->key, key, key_len); in crypto_hash_init()
105 ctx->key_len = key_len; in crypto_hash_init()
112 sha256_init(&ctx->u.sha256); in crypto_hash_init()
113 sha256_process(&ctx->u.sha256, k_pad, sizeof(k_pad)); in crypto_hash_init()
117 os_free(ctx); in crypto_hash_init()
121 return ctx; in crypto_hash_init()
125 void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len) in crypto_hash_update() argument
127 if (ctx == NULL) in crypto_hash_update()
130 switch (ctx->alg) { in crypto_hash_update()
133 MD5Update(&ctx->u.md5, data, len); in crypto_hash_update()
137 SHA1Update(&ctx->u.sha1, data, len); in crypto_hash_update()
142 sha256_process(&ctx->u.sha256, data, len); in crypto_hash_update()
151 int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len) in crypto_hash_finish() argument
156 if (ctx == NULL) in crypto_hash_finish()
160 os_free(ctx); in crypto_hash_finish()
164 switch (ctx->alg) { in crypto_hash_finish()
168 os_free(ctx); in crypto_hash_finish()
172 MD5Final(mac, &ctx->u.md5); in crypto_hash_finish()
177 os_free(ctx); in crypto_hash_finish()
181 SHA1Final(mac, &ctx->u.sha1); in crypto_hash_finish()
187 os_free(ctx); in crypto_hash_finish()
191 sha256_done(&ctx->u.sha256, mac); in crypto_hash_finish()
197 os_free(ctx); in crypto_hash_finish()
202 MD5Final(mac, &ctx->u.md5); in crypto_hash_finish()
204 os_memcpy(k_pad, ctx->key, ctx->key_len); in crypto_hash_finish()
205 os_memset(k_pad + ctx->key_len, 0, in crypto_hash_finish()
206 sizeof(k_pad) - ctx->key_len); in crypto_hash_finish()
209 MD5Init(&ctx->u.md5); in crypto_hash_finish()
210 MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad)); in crypto_hash_finish()
211 MD5Update(&ctx->u.md5, mac, 16); in crypto_hash_finish()
212 MD5Final(mac, &ctx->u.md5); in crypto_hash_finish()
217 os_free(ctx); in crypto_hash_finish()
222 SHA1Final(mac, &ctx->u.sha1); in crypto_hash_finish()
224 os_memcpy(k_pad, ctx->key, ctx->key_len); in crypto_hash_finish()
225 os_memset(k_pad + ctx->key_len, 0, in crypto_hash_finish()
226 sizeof(k_pad) - ctx->key_len); in crypto_hash_finish()
229 SHA1Init(&ctx->u.sha1); in crypto_hash_finish()
230 SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad)); in crypto_hash_finish()
231 SHA1Update(&ctx->u.sha1, mac, 20); in crypto_hash_finish()
232 SHA1Final(mac, &ctx->u.sha1); in crypto_hash_finish()
238 os_free(ctx); in crypto_hash_finish()
243 sha256_done(&ctx->u.sha256, mac); in crypto_hash_finish()
245 os_memcpy(k_pad, ctx->key, ctx->key_len); in crypto_hash_finish()
246 os_memset(k_pad + ctx->key_len, 0, in crypto_hash_finish()
247 sizeof(k_pad) - ctx->key_len); in crypto_hash_finish()
250 sha256_init(&ctx->u.sha256); in crypto_hash_finish()
251 sha256_process(&ctx->u.sha256, k_pad, sizeof(k_pad)); in crypto_hash_finish()
252 sha256_process(&ctx->u.sha256, mac, 32); in crypto_hash_finish()
253 sha256_done(&ctx->u.sha256, mac); in crypto_hash_finish()
257 os_free(ctx); in crypto_hash_finish()
261 os_free(ctx); in crypto_hash_finish()