Lines Matching refs:ctx

58 static int ext4_fname_encrypt(struct ext4_fname_crypto_ctx *ctx,  in ext4_fname_encrypt()  argument
65 struct crypto_ablkcipher *tfm = ctx->ctfm; in ext4_fname_encrypt()
69 int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK); in ext4_fname_encrypt()
72 if (iname->len <= 0 || iname->len > ctx->lim) in ext4_fname_encrypt()
78 ciphertext_len = (ciphertext_len > ctx->lim) in ext4_fname_encrypt()
79 ? ctx->lim : ciphertext_len; in ext4_fname_encrypt()
93 workbuf = kmap(ctx->workpage); in ext4_fname_encrypt()
105 sg_set_page(sg, ctx->workpage, PAGE_SIZE, 0); in ext4_fname_encrypt()
118 kunmap(ctx->workpage); in ext4_fname_encrypt()
135 static int ext4_fname_decrypt(struct ext4_fname_crypto_ctx *ctx, in ext4_fname_decrypt() argument
143 struct crypto_ablkcipher *tfm = ctx->ctfm; in ext4_fname_decrypt()
148 if (iname->len <= 0 || iname->len > ctx->lim) in ext4_fname_decrypt()
167 workbuf = kmap(ctx->workpage); in ext4_fname_decrypt()
177 sg_set_page(sg, ctx->workpage, PAGE_SIZE, 0); in ext4_fname_decrypt()
190 kunmap(ctx->workpage); in ext4_fname_decrypt()
261 void ext4_free_fname_crypto_ctx(struct ext4_fname_crypto_ctx *ctx) in ext4_free_fname_crypto_ctx() argument
263 if (ctx == NULL || IS_ERR(ctx)) in ext4_free_fname_crypto_ctx()
266 if (ctx->ctfm && !IS_ERR(ctx->ctfm)) in ext4_free_fname_crypto_ctx()
267 crypto_free_ablkcipher(ctx->ctfm); in ext4_free_fname_crypto_ctx()
268 if (ctx->htfm && !IS_ERR(ctx->htfm)) in ext4_free_fname_crypto_ctx()
269 crypto_free_hash(ctx->htfm); in ext4_free_fname_crypto_ctx()
270 if (ctx->workpage && !IS_ERR(ctx->workpage)) in ext4_free_fname_crypto_ctx()
271 __free_page(ctx->workpage); in ext4_free_fname_crypto_ctx()
272 kfree(ctx); in ext4_free_fname_crypto_ctx()
285 void ext4_put_fname_crypto_ctx(struct ext4_fname_crypto_ctx **ctx) in ext4_put_fname_crypto_ctx() argument
287 if (*ctx == NULL || IS_ERR(*ctx)) in ext4_put_fname_crypto_ctx()
289 ext4_free_fname_crypto_ctx(*ctx); in ext4_put_fname_crypto_ctx()
290 *ctx = NULL; in ext4_put_fname_crypto_ctx()
308 struct ext4_fname_crypto_ctx *ctx; in ext4_alloc_fname_crypto_ctx() local
310 ctx = kmalloc(sizeof(struct ext4_fname_crypto_ctx), GFP_NOFS); in ext4_alloc_fname_crypto_ctx()
311 if (ctx == NULL) in ext4_alloc_fname_crypto_ctx()
316 memset(&ctx->key, 0, sizeof(ctx->key)); in ext4_alloc_fname_crypto_ctx()
318 memcpy(&ctx->key, key, sizeof(struct ext4_encryption_key)); in ext4_alloc_fname_crypto_ctx()
320 ctx->has_valid_key = (EXT4_ENCRYPTION_MODE_INVALID == key->mode) in ext4_alloc_fname_crypto_ctx()
322 ctx->ctfm_key_is_ready = 0; in ext4_alloc_fname_crypto_ctx()
323 ctx->ctfm = NULL; in ext4_alloc_fname_crypto_ctx()
324 ctx->htfm = NULL; in ext4_alloc_fname_crypto_ctx()
325 ctx->workpage = NULL; in ext4_alloc_fname_crypto_ctx()
326 return ctx; in ext4_alloc_fname_crypto_ctx()
340 struct ext4_fname_crypto_ctx *ctx; in ext4_get_fname_crypto_ctx() local
355 ctx = ext4_search_fname_crypto_ctx(&(ei->i_encryption_key)); in ext4_get_fname_crypto_ctx()
356 if (ctx == NULL) in ext4_get_fname_crypto_ctx()
357 ctx = ext4_alloc_fname_crypto_ctx(&(ei->i_encryption_key)); in ext4_get_fname_crypto_ctx()
358 if (IS_ERR(ctx)) in ext4_get_fname_crypto_ctx()
359 return ctx; in ext4_get_fname_crypto_ctx()
361 ctx->flags = ei->i_crypt_policy_flags; in ext4_get_fname_crypto_ctx()
362 if (ctx->has_valid_key) { in ext4_get_fname_crypto_ctx()
363 if (ctx->key.mode != EXT4_ENCRYPTION_MODE_AES_256_CTS) { in ext4_get_fname_crypto_ctx()
366 ctx->key.mode); in ext4_get_fname_crypto_ctx()
373 if (ctx->ctfm == NULL) { in ext4_get_fname_crypto_ctx()
374 ctx->ctfm = crypto_alloc_ablkcipher("cts(cbc(aes))", in ext4_get_fname_crypto_ctx()
377 if (IS_ERR(ctx->ctfm)) { in ext4_get_fname_crypto_ctx()
378 res = PTR_ERR(ctx->ctfm); in ext4_get_fname_crypto_ctx()
382 ctx->ctfm = NULL; in ext4_get_fname_crypto_ctx()
383 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
386 if (ctx->ctfm == NULL) { in ext4_get_fname_crypto_ctx()
390 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
393 if (ctx->workpage == NULL) in ext4_get_fname_crypto_ctx()
394 ctx->workpage = alloc_page(GFP_NOFS); in ext4_get_fname_crypto_ctx()
395 if (IS_ERR(ctx->workpage)) { in ext4_get_fname_crypto_ctx()
396 res = PTR_ERR(ctx->workpage); in ext4_get_fname_crypto_ctx()
400 ctx->workpage = NULL; in ext4_get_fname_crypto_ctx()
401 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
404 if (ctx->workpage == NULL) { in ext4_get_fname_crypto_ctx()
408 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
411 ctx->lim = max_ciphertext_len; in ext4_get_fname_crypto_ctx()
412 crypto_ablkcipher_clear_flags(ctx->ctfm, ~0); in ext4_get_fname_crypto_ctx()
413 crypto_tfm_set_flags(crypto_ablkcipher_tfm(ctx->ctfm), in ext4_get_fname_crypto_ctx()
419 if (!ctx->ctfm_key_is_ready) { in ext4_get_fname_crypto_ctx()
423 res = crypto_ablkcipher_setkey(ctx->ctfm, in ext4_get_fname_crypto_ctx()
424 ctx->key.raw, ctx->key.size); in ext4_get_fname_crypto_ctx()
426 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
429 ctx->ctfm_key_is_ready = 1; in ext4_get_fname_crypto_ctx()
437 if (ctx->htfm == NULL) in ext4_get_fname_crypto_ctx()
438 ctx->htfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC); in ext4_get_fname_crypto_ctx()
439 if (IS_ERR(ctx->htfm)) { in ext4_get_fname_crypto_ctx()
440 res = PTR_ERR(ctx->htfm); in ext4_get_fname_crypto_ctx()
443 ctx->htfm = NULL; in ext4_get_fname_crypto_ctx()
444 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
447 if (ctx->htfm == NULL) { in ext4_get_fname_crypto_ctx()
450 ext4_put_fname_crypto_ctx(&ctx); in ext4_get_fname_crypto_ctx()
454 return ctx; in ext4_get_fname_crypto_ctx()
470 int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx, in ext4_fname_crypto_namelen_on_disk() argument
474 int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK); in ext4_fname_crypto_namelen_on_disk()
476 if (ctx == NULL) in ext4_fname_crypto_namelen_on_disk()
478 if (!(ctx->has_valid_key)) in ext4_fname_crypto_namelen_on_disk()
483 ciphertext_len = (ciphertext_len > ctx->lim) in ext4_fname_crypto_namelen_on_disk()
484 ? ctx->lim : ciphertext_len; in ext4_fname_crypto_namelen_on_disk()
494 int ext4_fname_crypto_alloc_buffer(struct ext4_fname_crypto_ctx *ctx, in ext4_fname_crypto_alloc_buffer() argument
498 int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK); in ext4_fname_crypto_alloc_buffer()
500 if (!ctx) in ext4_fname_crypto_alloc_buffer()
532 int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, in _ext4_fname_disk_to_usr() argument
540 if (ctx == NULL) in _ext4_fname_disk_to_usr()
551 if (ctx->has_valid_key) in _ext4_fname_disk_to_usr()
552 return ext4_fname_decrypt(ctx, iname, oname); in _ext4_fname_disk_to_usr()
571 int ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, in ext4_fname_disk_to_usr() argument
579 return _ext4_fname_disk_to_usr(ctx, hinfo, &iname, oname); in ext4_fname_disk_to_usr()
586 int ext4_fname_usr_to_disk(struct ext4_fname_crypto_ctx *ctx, in ext4_fname_usr_to_disk() argument
592 if (ctx == NULL) in ext4_fname_usr_to_disk()
604 if (ctx->has_valid_key) { in ext4_fname_usr_to_disk()
605 res = ext4_fname_encrypt(ctx, iname, oname); in ext4_fname_usr_to_disk()
617 int ext4_fname_usr_to_hash(struct ext4_fname_crypto_ctx *ctx, in ext4_fname_usr_to_hash() argument
625 if (!ctx || in ext4_fname_usr_to_hash()
633 if (!ctx->has_valid_key && iname->name[0] == '_') { in ext4_fname_usr_to_hash()
644 if (!ctx->has_valid_key && iname->name[0] != '_') { in ext4_fname_usr_to_hash()
653 ret = ext4_fname_crypto_alloc_buffer(ctx, iname->len, &tmp); in ext4_fname_usr_to_hash()
657 ret = ext4_fname_encrypt(ctx, iname, &tmp); in ext4_fname_usr_to_hash()
667 int ext4_fname_match(struct ext4_fname_crypto_ctx *ctx, struct ext4_str *cstr, in ext4_fname_match() argument
674 if (ctx->has_valid_key) { in ext4_fname_match()
678 ret = ext4_fname_crypto_alloc_buffer(ctx, len, cstr); in ext4_fname_match()
683 ret = ext4_fname_encrypt(ctx, &istr, cstr); in ext4_fname_match()