Lines Matching refs:ctx

47 	struct crypto_cipher *ctx;  in crypto_cipher_init()  local
49 ctx = os_zalloc(sizeof(*ctx)); in crypto_cipher_init()
50 if (ctx == NULL) in crypto_cipher_init()
53 ctx->alg = alg; in crypto_cipher_init()
57 if (key_len > sizeof(ctx->u.rc4.key)) { in crypto_cipher_init()
58 os_free(ctx); in crypto_cipher_init()
61 ctx->u.rc4.keylen = key_len; in crypto_cipher_init()
62 os_memcpy(ctx->u.rc4.key, key, key_len); in crypto_cipher_init()
65 ctx->u.aes.ctx_enc = aes_encrypt_init(key, key_len); in crypto_cipher_init()
66 if (ctx->u.aes.ctx_enc == NULL) { in crypto_cipher_init()
67 os_free(ctx); in crypto_cipher_init()
70 ctx->u.aes.ctx_dec = aes_decrypt_init(key, key_len); in crypto_cipher_init()
71 if (ctx->u.aes.ctx_dec == NULL) { in crypto_cipher_init()
72 aes_encrypt_deinit(ctx->u.aes.ctx_enc); in crypto_cipher_init()
73 os_free(ctx); in crypto_cipher_init()
76 os_memcpy(ctx->u.aes.cbc, iv, AES_BLOCK_SIZE); in crypto_cipher_init()
80 os_free(ctx); in crypto_cipher_init()
83 des3_key_setup(key, &ctx->u.des3.key); in crypto_cipher_init()
84 os_memcpy(ctx->u.des3.cbc, iv, 8); in crypto_cipher_init()
88 os_free(ctx); in crypto_cipher_init()
91 des_key_setup(key, ctx->u.des.ek, ctx->u.des.dk); in crypto_cipher_init()
92 os_memcpy(ctx->u.des.cbc, iv, 8); in crypto_cipher_init()
95 os_free(ctx); in crypto_cipher_init()
99 return ctx; in crypto_cipher_init()
103 int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain, in crypto_cipher_encrypt() argument
108 switch (ctx->alg) { in crypto_cipher_encrypt()
112 rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen, in crypto_cipher_encrypt()
113 ctx->u.rc4.used_bytes, crypt, len); in crypto_cipher_encrypt()
114 ctx->u.rc4.used_bytes += len; in crypto_cipher_encrypt()
122 ctx->u.aes.cbc[j] ^= plain[j]; in crypto_cipher_encrypt()
123 aes_encrypt(ctx->u.aes.ctx_enc, ctx->u.aes.cbc, in crypto_cipher_encrypt()
124 ctx->u.aes.cbc); in crypto_cipher_encrypt()
125 os_memcpy(crypt, ctx->u.aes.cbc, AES_BLOCK_SIZE); in crypto_cipher_encrypt()
136 ctx->u.des3.cbc[j] ^= plain[j]; in crypto_cipher_encrypt()
137 des3_encrypt(ctx->u.des3.cbc, &ctx->u.des3.key, in crypto_cipher_encrypt()
138 ctx->u.des3.cbc); in crypto_cipher_encrypt()
139 os_memcpy(crypt, ctx->u.des3.cbc, 8); in crypto_cipher_encrypt()
150 ctx->u.des3.cbc[j] ^= plain[j]; in crypto_cipher_encrypt()
151 des_block_encrypt(ctx->u.des.cbc, ctx->u.des.ek, in crypto_cipher_encrypt()
152 ctx->u.des.cbc); in crypto_cipher_encrypt()
153 os_memcpy(crypt, ctx->u.des.cbc, 8); in crypto_cipher_encrypt()
166 int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt, in crypto_cipher_decrypt() argument
172 switch (ctx->alg) { in crypto_cipher_decrypt()
176 rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen, in crypto_cipher_decrypt()
177 ctx->u.rc4.used_bytes, plain, len); in crypto_cipher_decrypt()
178 ctx->u.rc4.used_bytes += len; in crypto_cipher_decrypt()
186 aes_decrypt(ctx->u.aes.ctx_dec, crypt, plain); in crypto_cipher_decrypt()
188 plain[j] ^= ctx->u.aes.cbc[j]; in crypto_cipher_decrypt()
189 os_memcpy(ctx->u.aes.cbc, tmp, AES_BLOCK_SIZE); in crypto_cipher_decrypt()
200 des3_decrypt(crypt, &ctx->u.des3.key, plain); in crypto_cipher_decrypt()
202 plain[j] ^= ctx->u.des3.cbc[j]; in crypto_cipher_decrypt()
203 os_memcpy(ctx->u.des3.cbc, tmp, 8); in crypto_cipher_decrypt()
214 des_block_decrypt(crypt, ctx->u.des.dk, plain); in crypto_cipher_decrypt()
216 plain[j] ^= ctx->u.des.cbc[j]; in crypto_cipher_decrypt()
217 os_memcpy(ctx->u.des.cbc, tmp, 8); in crypto_cipher_decrypt()
230 void crypto_cipher_deinit(struct crypto_cipher *ctx) in crypto_cipher_deinit() argument
232 switch (ctx->alg) { in crypto_cipher_deinit()
234 aes_encrypt_deinit(ctx->u.aes.ctx_enc); in crypto_cipher_deinit()
235 aes_decrypt_deinit(ctx->u.aes.ctx_dec); in crypto_cipher_deinit()
242 os_free(ctx); in crypto_cipher_deinit()