Lines Matching full:ctx
99 void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
101 symmetric_key *skey = ctx;
106 void aes_encrypt_deinit(void *ctx)
108 symmetric_key *skey = ctx;
128 void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
130 symmetric_key *skey = ctx;
135 void aes_decrypt_deinit(void *ctx)
137 symmetric_key *skey = ctx;
156 struct crypto_hash *ctx;
158 ctx = os_zalloc(sizeof(*ctx));
159 if (ctx == NULL)
162 ctx->alg = alg;
166 if (md5_init(&ctx->u.md) != CRYPT_OK)
170 if (sha1_init(&ctx->u.md) != CRYPT_OK)
174 if (hmac_init(&ctx->u.hmac, find_hash("md5"), key, key_len) !=
179 if (hmac_init(&ctx->u.hmac, find_hash("sha1"), key, key_len) !=
187 return ctx;
190 os_free(ctx);
194 void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len)
196 if (ctx == NULL || ctx->error)
199 switch (ctx->alg) {
201 ctx->error = md5_process(&ctx->u.md, data, len) != CRYPT_OK;
204 ctx->error = sha1_process(&ctx->u.md, data, len) != CRYPT_OK;
208 ctx->error = hmac_process(&ctx->u.hmac, data, len) != CRYPT_OK;
214 int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
219 if (ctx == NULL)
223 os_free(ctx);
227 if (ctx->error) {
228 os_free(ctx);
232 switch (ctx->alg) {
236 os_free(ctx);
240 if (md5_done(&ctx->u.md, mac) != CRYPT_OK)
246 os_free(ctx);
250 if (sha1_done(&ctx->u.md, mac) != CRYPT_OK)
256 os_free(ctx);
263 os_free(ctx);
267 if (hmac_done(&ctx->u.hmac, mac, &clen) != CRYPT_OK) {
268 os_free(ctx);
278 os_free(ctx);
301 struct crypto_cipher *ctx;
325 ctx = os_zalloc(sizeof(*ctx));
326 if (ctx == NULL)
330 ctx->rc4 = 1;
331 if (key_len > sizeof(ctx->u.rc4.key)) {
332 os_free(ctx);
335 ctx->u.rc4.keylen = key_len;
336 os_memcpy(ctx->u.rc4.key, key, key_len);
338 res = cbc_start(idx, iv, key, key_len, 0, &ctx->u.cbc);
342 os_free(ctx);
347 return ctx;
350 int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
355 if (ctx->rc4) {
358 rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
359 ctx->u.rc4.used_bytes, crypt, len);
360 ctx->u.rc4.used_bytes += len;
364 res = cbc_encrypt(plain, crypt, len, &ctx->u.cbc);
374 int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
379 if (ctx->rc4) {
382 rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
383 ctx->u.rc4.used_bytes, plain, len);
384 ctx->u.rc4.used_bytes += len;
388 res = cbc_decrypt(crypt, plain, len, &ctx->u.cbc);
399 void crypto_cipher_deinit(struct crypto_cipher *ctx)
401 if (!ctx->rc4)
402 cbc_done(&ctx->u.cbc);
403 os_free(ctx);