Lines Matching refs:ctx

100 int aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)  in aes_encrypt()  argument
102 symmetric_key *skey = ctx; in aes_encrypt()
107 void aes_encrypt_deinit(void *ctx) in aes_encrypt_deinit() argument
109 symmetric_key *skey = ctx; in aes_encrypt_deinit()
129 int aes_decrypt(void *ctx, const u8 *crypt, u8 *plain) in aes_decrypt() argument
131 symmetric_key *skey = ctx; in aes_decrypt()
136 void aes_decrypt_deinit(void *ctx) in aes_decrypt_deinit() argument
138 symmetric_key *skey = ctx; in aes_decrypt_deinit()
157 struct crypto_hash *ctx; in crypto_hash_init() local
159 ctx = os_zalloc(sizeof(*ctx)); in crypto_hash_init()
160 if (ctx == NULL) in crypto_hash_init()
163 ctx->alg = alg; in crypto_hash_init()
167 if (md5_init(&ctx->u.md) != CRYPT_OK) in crypto_hash_init()
171 if (sha1_init(&ctx->u.md) != CRYPT_OK) in crypto_hash_init()
175 if (hmac_init(&ctx->u.hmac, find_hash("md5"), key, key_len) != in crypto_hash_init()
180 if (hmac_init(&ctx->u.hmac, find_hash("sha1"), key, key_len) != in crypto_hash_init()
188 return ctx; in crypto_hash_init()
191 os_free(ctx); in crypto_hash_init()
195 void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len) in crypto_hash_update() argument
197 if (ctx == NULL || ctx->error) in crypto_hash_update()
200 switch (ctx->alg) { in crypto_hash_update()
202 ctx->error = md5_process(&ctx->u.md, data, len) != CRYPT_OK; in crypto_hash_update()
205 ctx->error = sha1_process(&ctx->u.md, data, len) != CRYPT_OK; in crypto_hash_update()
209 ctx->error = hmac_process(&ctx->u.hmac, data, len) != CRYPT_OK; in crypto_hash_update()
215 int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len) in crypto_hash_finish() argument
220 if (ctx == NULL) in crypto_hash_finish()
224 os_free(ctx); in crypto_hash_finish()
228 if (ctx->error) { in crypto_hash_finish()
229 os_free(ctx); in crypto_hash_finish()
233 switch (ctx->alg) { in crypto_hash_finish()
237 os_free(ctx); in crypto_hash_finish()
241 if (md5_done(&ctx->u.md, mac) != CRYPT_OK) in crypto_hash_finish()
247 os_free(ctx); in crypto_hash_finish()
251 if (sha1_done(&ctx->u.md, mac) != CRYPT_OK) in crypto_hash_finish()
257 os_free(ctx); in crypto_hash_finish()
264 os_free(ctx); in crypto_hash_finish()
268 if (hmac_done(&ctx->u.hmac, mac, &clen) != CRYPT_OK) { in crypto_hash_finish()
269 os_free(ctx); in crypto_hash_finish()
279 os_free(ctx); in crypto_hash_finish()
305 struct crypto_cipher *ctx; in crypto_cipher_init() local
329 ctx = os_zalloc(sizeof(*ctx)); in crypto_cipher_init()
330 if (ctx == NULL) in crypto_cipher_init()
334 ctx->rc4 = 1; in crypto_cipher_init()
335 if (key_len > sizeof(ctx->u.rc4.key)) { in crypto_cipher_init()
336 os_free(ctx); in crypto_cipher_init()
339 ctx->u.rc4.keylen = key_len; in crypto_cipher_init()
340 os_memcpy(ctx->u.rc4.key, key, key_len); in crypto_cipher_init()
342 res = cbc_start(idx, iv, key, key_len, 0, &ctx->u.cbc); in crypto_cipher_init()
346 os_free(ctx); in crypto_cipher_init()
351 return ctx; in crypto_cipher_init()
354 int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain, in crypto_cipher_encrypt() argument
359 if (ctx->rc4) { in crypto_cipher_encrypt()
362 rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen, in crypto_cipher_encrypt()
363 ctx->u.rc4.used_bytes, crypt, len); in crypto_cipher_encrypt()
364 ctx->u.rc4.used_bytes += len; in crypto_cipher_encrypt()
368 res = cbc_encrypt(plain, crypt, len, &ctx->u.cbc); in crypto_cipher_encrypt()
378 int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt, in crypto_cipher_decrypt() argument
383 if (ctx->rc4) { in crypto_cipher_decrypt()
386 rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen, in crypto_cipher_decrypt()
387 ctx->u.rc4.used_bytes, plain, len); in crypto_cipher_decrypt()
388 ctx->u.rc4.used_bytes += len; in crypto_cipher_decrypt()
392 res = cbc_decrypt(crypt, plain, len, &ctx->u.cbc); in crypto_cipher_decrypt()
403 void crypto_cipher_deinit(struct crypto_cipher *ctx) in crypto_cipher_deinit() argument
405 if (!ctx->rc4) in crypto_cipher_deinit()
406 cbc_done(&ctx->u.cbc); in crypto_cipher_deinit()
407 os_free(ctx); in crypto_cipher_deinit()