Lines Matching refs:ctx

38 lws_genaes_create(struct lws_genaes_ctx *ctx, enum enum_aes_operation op,
44 ctx->ctx = EVP_CIPHER_CTX_new();
45 if (!ctx->ctx)
48 ctx->mode = mode;
49 ctx->k = el;
50 ctx->engine = engine;
51 ctx->init = 0;
52 ctx->op = op;
53 ctx->padding = padding;
55 switch (ctx->k->len) {
60 EVP_CIPHER_CTX_set_flags(ctx->ctx,
62 ctx->cipher = EVP_aes_128_wrap();
70 ctx->cipher = EVP_aes_128_cbc();
74 ctx->cipher = EVP_aes_128_cfb128();
79 ctx->cipher = EVP_aes_128_cfb8();
84 ctx->cipher = EVP_aes_128_ctr();
89 ctx->cipher = EVP_aes_128_ecb();
94 ctx->cipher = EVP_aes_128_ofb();
104 ctx->cipher = EVP_aes_128_gcm();
115 EVP_CIPHER_CTX_set_flags(ctx->ctx,
117 ctx->cipher = EVP_aes_192_wrap();
125 ctx->cipher = EVP_aes_192_cbc();
129 ctx->cipher = EVP_aes_192_cfb128();
134 ctx->cipher = EVP_aes_192_cfb8();
139 ctx->cipher = EVP_aes_192_ctr();
144 ctx->cipher = EVP_aes_192_ecb();
149 ctx->cipher = EVP_aes_192_ofb();
158 ctx->cipher = EVP_aes_192_gcm();
169 EVP_CIPHER_CTX_set_flags(ctx->ctx,
171 ctx->cipher = EVP_aes_256_wrap();
179 ctx->cipher = EVP_aes_256_cbc();
183 ctx->cipher = EVP_aes_256_cfb128();
188 ctx->cipher = EVP_aes_256_cfb8();
193 ctx->cipher = EVP_aes_256_ctr();
198 ctx->cipher = EVP_aes_256_ecb();
203 ctx->cipher = EVP_aes_256_ofb();
208 ctx->cipher = EVP_aes_128_xts();
212 ctx->cipher = EVP_aes_256_gcm();
223 ctx->cipher = EVP_aes_256_xts();
233 ctx->k->len * 8);
237 switch (ctx->op) {
239 n = EVP_EncryptInit_ex(ctx->ctx, ctx->cipher, ctx->engine,
241 EVP_CIPHER_CTX_set_padding(ctx->ctx, (int)padding);
244 n = EVP_DecryptInit_ex(ctx->ctx, ctx->cipher, ctx->engine,
246 EVP_CIPHER_CTX_set_padding(ctx->ctx, (int)padding);
251 ctx->cipher);
258 EVP_CIPHER_CTX_free(ctx->ctx);
259 ctx->ctx = NULL;
264 lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen)
269 if (!ctx->ctx)
272 if (ctx->init) {
273 switch (ctx->op) {
276 if (EVP_EncryptFinal_ex(ctx->ctx, buf, &outl) != 1) {
281 if (ctx->mode == LWS_GAESM_GCM) {
282 if (EVP_CIPHER_CTX_ctrl(ctx->ctx,
284 ctx->taglen, tag) != 1) {
290 if (ctx->mode == LWS_GAESM_CBC)
296 if (EVP_DecryptFinal_ex(ctx->ctx, buf, &outl) != 1) {
308 ctx->k = NULL;
309 EVP_CIPHER_CTX_free(ctx->ctx);
310 ctx->ctx = NULL;
316 lws_genaes_crypt(struct lws_genaes_ctx *ctx,
323 if (!ctx->init) {
325 EVP_CIPHER_CTX_set_key_length(ctx->ctx, (int)ctx->k->len);
327 if (ctx->mode == LWS_GAESM_GCM) {
328 n = EVP_CIPHER_CTX_ctrl(ctx->ctx, EVP_CTRL_GCM_SET_IVLEN,
334 memcpy(ctx->tag, stream_block_16, (unsigned int)taglen);
335 ctx->taglen = taglen;
338 switch (ctx->op) {
340 n = EVP_EncryptInit_ex(ctx->ctx, NULL, NULL,
341 ctx->k->buf,
345 if (ctx->mode == LWS_GAESM_GCM)
346 EVP_CIPHER_CTX_ctrl(ctx->ctx,
348 ctx->taglen, ctx->tag);
349 n = EVP_DecryptInit_ex(ctx->ctx, NULL, NULL,
350 ctx->k->buf,
358 __func__, ctx->cipher);
362 ctx->init = 1;
365 if (ctx->mode == LWS_GAESM_GCM && !out) {
371 switch (ctx->op) {
373 n = EVP_EncryptUpdate(ctx->ctx, NULL, &olen, in, (int)len);
376 n = EVP_DecryptUpdate(ctx->ctx, NULL, &olen, in, (int)len);
391 switch (ctx->op) {
393 n = EVP_EncryptUpdate(ctx->ctx, out, &outl, in, (int)len);
396 n = EVP_DecryptUpdate(ctx->ctx, out, &outl, in, (int)len);