Lines Matching refs:cc
65 struct crypt_config *cc; member
90 int (*ctr)(struct crypt_config *cc, struct dm_target *ti,
92 void (*dtr)(struct crypt_config *cc);
93 int (*init)(struct crypt_config *cc);
94 int (*wipe)(struct crypt_config *cc);
95 int (*generator)(struct crypt_config *cc, u8 *iv,
97 int (*post)(struct crypt_config *cc, u8 *iv,
223 static struct scatterlist *crypt_get_sg_data(struct crypt_config *cc,
229 static struct crypto_skcipher *any_tfm(struct crypt_config *cc) in any_tfm() argument
231 return cc->cipher_tfm.tfms[0]; in any_tfm()
234 static struct crypto_aead *any_tfm_aead(struct crypt_config *cc) in any_tfm_aead() argument
236 return cc->cipher_tfm.tfms_aead[0]; in any_tfm_aead()
290 static int crypt_iv_plain_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_plain_gen() argument
293 memset(iv, 0, cc->iv_size); in crypt_iv_plain_gen()
299 static int crypt_iv_plain64_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_plain64_gen() argument
302 memset(iv, 0, cc->iv_size); in crypt_iv_plain64_gen()
308 static int crypt_iv_plain64be_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_plain64be_gen() argument
311 memset(iv, 0, cc->iv_size); in crypt_iv_plain64be_gen()
313 *(__be64 *)&iv[cc->iv_size - sizeof(u64)] = cpu_to_be64(dmreq->iv_sector); in crypt_iv_plain64be_gen()
318 static int crypt_iv_essiv_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_essiv_gen() argument
325 memset(iv, 0, cc->iv_size); in crypt_iv_essiv_gen()
331 static int crypt_iv_benbi_ctr(struct crypt_config *cc, struct dm_target *ti, in crypt_iv_benbi_ctr() argument
334 unsigned bs = crypto_skcipher_blocksize(any_tfm(cc)); in crypt_iv_benbi_ctr()
350 cc->iv_gen_private.benbi.shift = 9 - log; in crypt_iv_benbi_ctr()
355 static void crypt_iv_benbi_dtr(struct crypt_config *cc) in crypt_iv_benbi_dtr() argument
359 static int crypt_iv_benbi_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_benbi_gen() argument
364 memset(iv, 0, cc->iv_size - sizeof(u64)); /* rest is cleared below */ in crypt_iv_benbi_gen()
366 val = cpu_to_be64(((u64)dmreq->iv_sector << cc->iv_gen_private.benbi.shift) + 1); in crypt_iv_benbi_gen()
367 put_unaligned(val, (__be64 *)(iv + cc->iv_size - sizeof(u64))); in crypt_iv_benbi_gen()
372 static int crypt_iv_null_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_null_gen() argument
375 memset(iv, 0, cc->iv_size); in crypt_iv_null_gen()
380 static void crypt_iv_lmk_dtr(struct crypt_config *cc) in crypt_iv_lmk_dtr() argument
382 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk; in crypt_iv_lmk_dtr()
392 static int crypt_iv_lmk_ctr(struct crypt_config *cc, struct dm_target *ti, in crypt_iv_lmk_ctr() argument
395 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk; in crypt_iv_lmk_ctr()
397 if (cc->sector_size != (1 << SECTOR_SHIFT)) { in crypt_iv_lmk_ctr()
409 if (cc->key_parts == cc->tfms_count) { in crypt_iv_lmk_ctr()
416 crypt_iv_lmk_dtr(cc); in crypt_iv_lmk_ctr()
424 static int crypt_iv_lmk_init(struct crypt_config *cc) in crypt_iv_lmk_init() argument
426 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk; in crypt_iv_lmk_init()
427 int subkey_size = cc->key_size / cc->key_parts; in crypt_iv_lmk_init()
431 memcpy(lmk->seed, cc->key + (cc->tfms_count * subkey_size), in crypt_iv_lmk_init()
437 static int crypt_iv_lmk_wipe(struct crypt_config *cc) in crypt_iv_lmk_wipe() argument
439 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk; in crypt_iv_lmk_wipe()
447 static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv, in crypt_iv_lmk_one() argument
451 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk; in crypt_iv_lmk_one()
490 memcpy(iv, &md5state.hash, cc->iv_size); in crypt_iv_lmk_one()
495 static int crypt_iv_lmk_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_lmk_gen() argument
503 sg = crypt_get_sg_data(cc, dmreq->sg_in); in crypt_iv_lmk_gen()
505 r = crypt_iv_lmk_one(cc, iv, dmreq, src + sg->offset); in crypt_iv_lmk_gen()
508 memset(iv, 0, cc->iv_size); in crypt_iv_lmk_gen()
513 static int crypt_iv_lmk_post(struct crypt_config *cc, u8 *iv, in crypt_iv_lmk_post() argument
523 sg = crypt_get_sg_data(cc, dmreq->sg_out); in crypt_iv_lmk_post()
525 r = crypt_iv_lmk_one(cc, iv, dmreq, dst + sg->offset); in crypt_iv_lmk_post()
529 crypto_xor(dst + sg->offset, iv, cc->iv_size); in crypt_iv_lmk_post()
535 static void crypt_iv_tcw_dtr(struct crypt_config *cc) in crypt_iv_tcw_dtr() argument
537 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; in crypt_iv_tcw_dtr()
549 static int crypt_iv_tcw_ctr(struct crypt_config *cc, struct dm_target *ti, in crypt_iv_tcw_ctr() argument
552 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; in crypt_iv_tcw_ctr()
554 if (cc->sector_size != (1 << SECTOR_SHIFT)) { in crypt_iv_tcw_ctr()
559 if (cc->key_size <= (cc->iv_size + TCW_WHITENING_SIZE)) { in crypt_iv_tcw_ctr()
570 tcw->iv_seed = kzalloc(cc->iv_size, GFP_KERNEL); in crypt_iv_tcw_ctr()
573 crypt_iv_tcw_dtr(cc); in crypt_iv_tcw_ctr()
581 static int crypt_iv_tcw_init(struct crypt_config *cc) in crypt_iv_tcw_init() argument
583 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; in crypt_iv_tcw_init()
584 int key_offset = cc->key_size - cc->iv_size - TCW_WHITENING_SIZE; in crypt_iv_tcw_init()
586 memcpy(tcw->iv_seed, &cc->key[key_offset], cc->iv_size); in crypt_iv_tcw_init()
587 memcpy(tcw->whitening, &cc->key[key_offset + cc->iv_size], in crypt_iv_tcw_init()
593 static int crypt_iv_tcw_wipe(struct crypt_config *cc) in crypt_iv_tcw_wipe() argument
595 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; in crypt_iv_tcw_wipe()
597 memset(tcw->iv_seed, 0, cc->iv_size); in crypt_iv_tcw_wipe()
603 static int crypt_iv_tcw_whitening(struct crypt_config *cc, in crypt_iv_tcw_whitening() argument
607 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; in crypt_iv_tcw_whitening()
641 static int crypt_iv_tcw_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_tcw_gen() argument
645 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; in crypt_iv_tcw_gen()
652 sg = crypt_get_sg_data(cc, dmreq->sg_in); in crypt_iv_tcw_gen()
654 r = crypt_iv_tcw_whitening(cc, dmreq, src + sg->offset); in crypt_iv_tcw_gen()
660 if (cc->iv_size > 8) in crypt_iv_tcw_gen()
662 cc->iv_size - 8); in crypt_iv_tcw_gen()
667 static int crypt_iv_tcw_post(struct crypt_config *cc, u8 *iv, in crypt_iv_tcw_post() argument
678 sg = crypt_get_sg_data(cc, dmreq->sg_out); in crypt_iv_tcw_post()
680 r = crypt_iv_tcw_whitening(cc, dmreq, dst + sg->offset); in crypt_iv_tcw_post()
686 static int crypt_iv_random_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_random_gen() argument
690 get_random_bytes(iv, cc->iv_size); in crypt_iv_random_gen()
694 static int crypt_iv_eboiv_ctr(struct crypt_config *cc, struct dm_target *ti, in crypt_iv_eboiv_ctr() argument
697 if (test_bit(CRYPT_MODE_INTEGRITY_AEAD, &cc->cipher_flags)) { in crypt_iv_eboiv_ctr()
702 if (crypto_skcipher_blocksize(any_tfm(cc)) != cc->iv_size) { in crypt_iv_eboiv_ctr()
711 static int crypt_iv_eboiv_gen(struct crypt_config *cc, u8 *iv, in crypt_iv_eboiv_gen() argument
720 req = skcipher_request_alloc(any_tfm(cc), GFP_KERNEL | GFP_NOFS); in crypt_iv_eboiv_gen()
724 memset(buf, 0, cc->iv_size); in crypt_iv_eboiv_gen()
725 *(__le64 *)buf = cpu_to_le64(dmreq->iv_sector * cc->sector_size); in crypt_iv_eboiv_gen()
727 sg_init_one(&src, page_address(ZERO_PAGE(0)), cc->iv_size); in crypt_iv_eboiv_gen()
728 sg_init_one(&dst, iv, cc->iv_size); in crypt_iv_eboiv_gen()
729 skcipher_request_set_crypt(req, &src, &dst, cc->iv_size, buf); in crypt_iv_eboiv_gen()
793 static bool crypt_integrity_aead(struct crypt_config *cc) in crypt_integrity_aead() argument
795 return test_bit(CRYPT_MODE_INTEGRITY_AEAD, &cc->cipher_flags); in crypt_integrity_aead()
798 static bool crypt_integrity_hmac(struct crypt_config *cc) in crypt_integrity_hmac() argument
800 return crypt_integrity_aead(cc) && cc->key_mac_size; in crypt_integrity_hmac()
804 static struct scatterlist *crypt_get_sg_data(struct crypt_config *cc, in crypt_get_sg_data() argument
807 if (unlikely(crypt_integrity_aead(cc))) in crypt_get_sg_data()
819 if (!bio_sectors(bio) || !io->cc->on_disk_tag_size) in dm_crypt_integrity_io_alloc()
826 tag_len = io->cc->on_disk_tag_size * (bio_sectors(bio) >> io->cc->sector_shift); in dm_crypt_integrity_io_alloc()
829 bip->bip_iter.bi_sector = io->cc->start + io->sector; in dm_crypt_integrity_io_alloc()
839 static int crypt_integrity_ctr(struct crypt_config *cc, struct dm_target *ti) in crypt_integrity_ctr() argument
842 struct blk_integrity *bi = blk_get_integrity(cc->dev->bdev->bd_disk); in crypt_integrity_ctr()
851 if (bi->tag_size != cc->on_disk_tag_size || in crypt_integrity_ctr()
852 bi->tuple_size != cc->on_disk_tag_size) { in crypt_integrity_ctr()
856 if (1 << bi->interval_exp != cc->sector_size) { in crypt_integrity_ctr()
861 if (crypt_integrity_aead(cc)) { in crypt_integrity_ctr()
862 cc->integrity_tag_size = cc->on_disk_tag_size - cc->integrity_iv_size; in crypt_integrity_ctr()
864 cc->integrity_tag_size, cc->integrity_iv_size); in crypt_integrity_ctr()
866 if (crypto_aead_setauthsize(any_tfm_aead(cc), cc->integrity_tag_size)) { in crypt_integrity_ctr()
870 } else if (cc->integrity_iv_size) in crypt_integrity_ctr()
872 cc->integrity_iv_size); in crypt_integrity_ctr()
874 if ((cc->integrity_tag_size + cc->integrity_iv_size) != bi->tag_size) { in crypt_integrity_ctr()
886 static void crypt_convert_init(struct crypt_config *cc, in crypt_convert_init() argument
897 ctx->cc_sector = sector + cc->iv_offset; in crypt_convert_init()
901 static struct dm_crypt_request *dmreq_of_req(struct crypt_config *cc, in dmreq_of_req() argument
904 return (struct dm_crypt_request *)((char *)req + cc->dmreq_start); in dmreq_of_req()
907 static void *req_of_dmreq(struct crypt_config *cc, struct dm_crypt_request *dmreq) in req_of_dmreq() argument
909 return (void *)((char *)dmreq - cc->dmreq_start); in req_of_dmreq()
912 static u8 *iv_of_dmreq(struct crypt_config *cc, in iv_of_dmreq() argument
915 if (crypt_integrity_aead(cc)) in iv_of_dmreq()
917 crypto_aead_alignmask(any_tfm_aead(cc)) + 1); in iv_of_dmreq()
920 crypto_skcipher_alignmask(any_tfm(cc)) + 1); in iv_of_dmreq()
923 static u8 *org_iv_of_dmreq(struct crypt_config *cc, in org_iv_of_dmreq() argument
926 return iv_of_dmreq(cc, dmreq) + cc->iv_size; in org_iv_of_dmreq()
929 static __le64 *org_sector_of_dmreq(struct crypt_config *cc, in org_sector_of_dmreq() argument
932 u8 *ptr = iv_of_dmreq(cc, dmreq) + cc->iv_size + cc->iv_size; in org_sector_of_dmreq()
936 static unsigned int *org_tag_of_dmreq(struct crypt_config *cc, in org_tag_of_dmreq() argument
939 u8 *ptr = iv_of_dmreq(cc, dmreq) + cc->iv_size + in org_tag_of_dmreq()
940 cc->iv_size + sizeof(uint64_t); in org_tag_of_dmreq()
944 static void *tag_from_dmreq(struct crypt_config *cc, in tag_from_dmreq() argument
950 return &io->integrity_metadata[*org_tag_of_dmreq(cc, dmreq) * in tag_from_dmreq()
951 cc->on_disk_tag_size]; in tag_from_dmreq()
954 static void *iv_tag_from_dmreq(struct crypt_config *cc, in iv_tag_from_dmreq() argument
957 return tag_from_dmreq(cc, dmreq) + cc->integrity_tag_size; in iv_tag_from_dmreq()
960 static int crypt_convert_block_aead(struct crypt_config *cc, in crypt_convert_block_aead() argument
972 BUG_ON(cc->integrity_iv_size && cc->integrity_iv_size != cc->iv_size); in crypt_convert_block_aead()
975 if (unlikely(bv_in.bv_len & (cc->sector_size - 1))) in crypt_convert_block_aead()
978 dmreq = dmreq_of_req(cc, req); in crypt_convert_block_aead()
980 if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags)) in crypt_convert_block_aead()
981 dmreq->iv_sector >>= cc->sector_shift; in crypt_convert_block_aead()
984 *org_tag_of_dmreq(cc, dmreq) = tag_offset; in crypt_convert_block_aead()
986 sector = org_sector_of_dmreq(cc, dmreq); in crypt_convert_block_aead()
987 *sector = cpu_to_le64(ctx->cc_sector - cc->iv_offset); in crypt_convert_block_aead()
989 iv = iv_of_dmreq(cc, dmreq); in crypt_convert_block_aead()
990 org_iv = org_iv_of_dmreq(cc, dmreq); in crypt_convert_block_aead()
991 tag = tag_from_dmreq(cc, dmreq); in crypt_convert_block_aead()
992 tag_iv = iv_tag_from_dmreq(cc, dmreq); in crypt_convert_block_aead()
1001 sg_set_buf(&dmreq->sg_in[1], org_iv, cc->iv_size); in crypt_convert_block_aead()
1002 sg_set_page(&dmreq->sg_in[2], bv_in.bv_page, cc->sector_size, bv_in.bv_offset); in crypt_convert_block_aead()
1003 sg_set_buf(&dmreq->sg_in[3], tag, cc->integrity_tag_size); in crypt_convert_block_aead()
1007 sg_set_buf(&dmreq->sg_out[1], org_iv, cc->iv_size); in crypt_convert_block_aead()
1008 sg_set_page(&dmreq->sg_out[2], bv_out.bv_page, cc->sector_size, bv_out.bv_offset); in crypt_convert_block_aead()
1009 sg_set_buf(&dmreq->sg_out[3], tag, cc->integrity_tag_size); in crypt_convert_block_aead()
1011 if (cc->iv_gen_ops) { in crypt_convert_block_aead()
1013 if (cc->integrity_iv_size && bio_data_dir(ctx->bio_in) != WRITE) { in crypt_convert_block_aead()
1014 memcpy(org_iv, tag_iv, cc->iv_size); in crypt_convert_block_aead()
1016 r = cc->iv_gen_ops->generator(cc, org_iv, dmreq); in crypt_convert_block_aead()
1020 if (cc->integrity_iv_size) in crypt_convert_block_aead()
1021 memcpy(tag_iv, org_iv, cc->iv_size); in crypt_convert_block_aead()
1024 memcpy(iv, org_iv, cc->iv_size); in crypt_convert_block_aead()
1027 aead_request_set_ad(req, sizeof(uint64_t) + cc->iv_size); in crypt_convert_block_aead()
1030 cc->sector_size, iv); in crypt_convert_block_aead()
1032 if (cc->integrity_tag_size + cc->integrity_iv_size != cc->on_disk_tag_size) in crypt_convert_block_aead()
1033 memset(tag + cc->integrity_tag_size + cc->integrity_iv_size, 0, in crypt_convert_block_aead()
1034 cc->on_disk_tag_size - (cc->integrity_tag_size + cc->integrity_iv_size)); in crypt_convert_block_aead()
1037 cc->sector_size + cc->integrity_tag_size, iv); in crypt_convert_block_aead()
1047 if (!r && cc->iv_gen_ops && cc->iv_gen_ops->post) in crypt_convert_block_aead()
1048 r = cc->iv_gen_ops->post(cc, org_iv, dmreq); in crypt_convert_block_aead()
1050 bio_advance_iter(ctx->bio_in, &ctx->iter_in, cc->sector_size); in crypt_convert_block_aead()
1051 bio_advance_iter(ctx->bio_out, &ctx->iter_out, cc->sector_size); in crypt_convert_block_aead()
1056 static int crypt_convert_block_skcipher(struct crypt_config *cc, in crypt_convert_block_skcipher() argument
1070 if (unlikely(bv_in.bv_len & (cc->sector_size - 1))) in crypt_convert_block_skcipher()
1073 dmreq = dmreq_of_req(cc, req); in crypt_convert_block_skcipher()
1075 if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags)) in crypt_convert_block_skcipher()
1076 dmreq->iv_sector >>= cc->sector_shift; in crypt_convert_block_skcipher()
1079 *org_tag_of_dmreq(cc, dmreq) = tag_offset; in crypt_convert_block_skcipher()
1081 iv = iv_of_dmreq(cc, dmreq); in crypt_convert_block_skcipher()
1082 org_iv = org_iv_of_dmreq(cc, dmreq); in crypt_convert_block_skcipher()
1083 tag_iv = iv_tag_from_dmreq(cc, dmreq); in crypt_convert_block_skcipher()
1085 sector = org_sector_of_dmreq(cc, dmreq); in crypt_convert_block_skcipher()
1086 *sector = cpu_to_le64(ctx->cc_sector - cc->iv_offset); in crypt_convert_block_skcipher()
1093 sg_set_page(sg_in, bv_in.bv_page, cc->sector_size, bv_in.bv_offset); in crypt_convert_block_skcipher()
1096 sg_set_page(sg_out, bv_out.bv_page, cc->sector_size, bv_out.bv_offset); in crypt_convert_block_skcipher()
1098 if (cc->iv_gen_ops) { in crypt_convert_block_skcipher()
1100 if (cc->integrity_iv_size && bio_data_dir(ctx->bio_in) != WRITE) { in crypt_convert_block_skcipher()
1101 memcpy(org_iv, tag_iv, cc->integrity_iv_size); in crypt_convert_block_skcipher()
1103 r = cc->iv_gen_ops->generator(cc, org_iv, dmreq); in crypt_convert_block_skcipher()
1107 if (cc->integrity_iv_size) in crypt_convert_block_skcipher()
1108 memcpy(tag_iv, org_iv, cc->integrity_iv_size); in crypt_convert_block_skcipher()
1111 memcpy(iv, org_iv, cc->iv_size); in crypt_convert_block_skcipher()
1114 skcipher_request_set_crypt(req, sg_in, sg_out, cc->sector_size, iv); in crypt_convert_block_skcipher()
1121 if (!r && cc->iv_gen_ops && cc->iv_gen_ops->post) in crypt_convert_block_skcipher()
1122 r = cc->iv_gen_ops->post(cc, org_iv, dmreq); in crypt_convert_block_skcipher()
1124 bio_advance_iter(ctx->bio_in, &ctx->iter_in, cc->sector_size); in crypt_convert_block_skcipher()
1125 bio_advance_iter(ctx->bio_out, &ctx->iter_out, cc->sector_size); in crypt_convert_block_skcipher()
1133 static void crypt_alloc_req_skcipher(struct crypt_config *cc, in crypt_alloc_req_skcipher() argument
1136 unsigned key_index = ctx->cc_sector & (cc->tfms_count - 1); in crypt_alloc_req_skcipher()
1139 ctx->r.req = mempool_alloc(&cc->req_pool, GFP_NOIO); in crypt_alloc_req_skcipher()
1141 skcipher_request_set_tfm(ctx->r.req, cc->cipher_tfm.tfms[key_index]); in crypt_alloc_req_skcipher()
1149 kcryptd_async_done, dmreq_of_req(cc, ctx->r.req)); in crypt_alloc_req_skcipher()
1152 static void crypt_alloc_req_aead(struct crypt_config *cc, in crypt_alloc_req_aead() argument
1156 ctx->r.req_aead = mempool_alloc(&cc->req_pool, GFP_NOIO); in crypt_alloc_req_aead()
1158 aead_request_set_tfm(ctx->r.req_aead, cc->cipher_tfm.tfms_aead[0]); in crypt_alloc_req_aead()
1166 kcryptd_async_done, dmreq_of_req(cc, ctx->r.req_aead)); in crypt_alloc_req_aead()
1169 static void crypt_alloc_req(struct crypt_config *cc, in crypt_alloc_req() argument
1172 if (crypt_integrity_aead(cc)) in crypt_alloc_req()
1173 crypt_alloc_req_aead(cc, ctx); in crypt_alloc_req()
1175 crypt_alloc_req_skcipher(cc, ctx); in crypt_alloc_req()
1178 static void crypt_free_req_skcipher(struct crypt_config *cc, in crypt_free_req_skcipher() argument
1181 struct dm_crypt_io *io = dm_per_bio_data(base_bio, cc->per_bio_data_size); in crypt_free_req_skcipher()
1184 mempool_free(req, &cc->req_pool); in crypt_free_req_skcipher()
1187 static void crypt_free_req_aead(struct crypt_config *cc, in crypt_free_req_aead() argument
1190 struct dm_crypt_io *io = dm_per_bio_data(base_bio, cc->per_bio_data_size); in crypt_free_req_aead()
1193 mempool_free(req, &cc->req_pool); in crypt_free_req_aead()
1196 static void crypt_free_req(struct crypt_config *cc, void *req, struct bio *base_bio) in crypt_free_req() argument
1198 if (crypt_integrity_aead(cc)) in crypt_free_req()
1199 crypt_free_req_aead(cc, req, base_bio); in crypt_free_req()
1201 crypt_free_req_skcipher(cc, req, base_bio); in crypt_free_req()
1207 static blk_status_t crypt_convert(struct crypt_config *cc, in crypt_convert() argument
1211 unsigned int sector_step = cc->sector_size >> SECTOR_SHIFT; in crypt_convert()
1218 crypt_alloc_req(cc, ctx); in crypt_convert()
1221 if (crypt_integrity_aead(cc)) in crypt_convert()
1222 r = crypt_convert_block_aead(cc, ctx, ctx->r.req_aead, tag_offset); in crypt_convert()
1224 r = crypt_convert_block_skcipher(cc, ctx, ctx->r.req, tag_offset); in crypt_convert()
1271 static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone);
1292 struct crypt_config *cc = io->cc; in crypt_alloc_buffer() local
1301 mutex_lock(&cc->bio_alloc_lock); in crypt_alloc_buffer()
1303 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, &cc->bs); in crypt_alloc_buffer()
1312 page = mempool_alloc(&cc->page_pool, gfp_mask); in crypt_alloc_buffer()
1314 crypt_free_buffer_pages(cc, clone); in crypt_alloc_buffer()
1329 crypt_free_buffer_pages(cc, clone); in crypt_alloc_buffer()
1335 mutex_unlock(&cc->bio_alloc_lock); in crypt_alloc_buffer()
1340 static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone) in crypt_free_buffer_pages() argument
1347 mempool_free(bv->bv_page, &cc->page_pool); in crypt_free_buffer_pages()
1351 static void crypt_io_init(struct dm_crypt_io *io, struct crypt_config *cc, in crypt_io_init() argument
1354 io->cc = cc; in crypt_io_init()
1375 struct crypt_config *cc = io->cc; in crypt_dec_pending() local
1383 crypt_free_req(cc, io->ctx.r.req, base_bio); in crypt_dec_pending()
1386 mempool_free(io->integrity_metadata, &io->cc->tag_pool); in crypt_dec_pending()
1414 struct crypt_config *cc = io->cc; in crypt_endio() local
1422 crypt_free_buffer_pages(cc, clone); in crypt_endio()
1440 struct crypt_config *cc = io->cc; in clone_init() local
1444 bio_set_dev(clone, cc->dev->bdev); in clone_init()
1450 struct crypt_config *cc = io->cc; in kcryptd_io_read() local
1459 clone = bio_clone_fast(io->base_bio, gfp, &cc->bs); in kcryptd_io_read()
1466 clone->bi_iter.bi_sector = cc->start + io->sector; in kcryptd_io_read()
1490 struct crypt_config *cc = io->cc; in kcryptd_queue_read() local
1493 queue_work(cc->io_queue, &io->work); in kcryptd_queue_read()
1507 struct crypt_config *cc = data; in dmcrypt_write() local
1514 spin_lock_irq(&cc->write_thread_lock); in dmcrypt_write()
1517 if (!RB_EMPTY_ROOT(&cc->write_tree)) in dmcrypt_write()
1522 spin_unlock_irq(&cc->write_thread_lock); in dmcrypt_write()
1532 spin_lock_irq(&cc->write_thread_lock); in dmcrypt_write()
1536 write_tree = cc->write_tree; in dmcrypt_write()
1537 cc->write_tree = RB_ROOT; in dmcrypt_write()
1538 spin_unlock_irq(&cc->write_thread_lock); in dmcrypt_write()
1560 struct crypt_config *cc = io->cc; in kcryptd_crypt_write_io_submit() local
1566 crypt_free_buffer_pages(cc, clone); in kcryptd_crypt_write_io_submit()
1575 clone->bi_iter.bi_sector = cc->start + io->sector; in kcryptd_crypt_write_io_submit()
1577 if (likely(!async) && test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) { in kcryptd_crypt_write_io_submit()
1582 spin_lock_irqsave(&cc->write_thread_lock, flags); in kcryptd_crypt_write_io_submit()
1583 if (RB_EMPTY_ROOT(&cc->write_tree)) in kcryptd_crypt_write_io_submit()
1584 wake_up_process(cc->write_thread); in kcryptd_crypt_write_io_submit()
1585 rbp = &cc->write_tree.rb_node; in kcryptd_crypt_write_io_submit()
1596 rb_insert_color(&io->rb_node, &cc->write_tree); in kcryptd_crypt_write_io_submit()
1597 spin_unlock_irqrestore(&cc->write_thread_lock, flags); in kcryptd_crypt_write_io_submit()
1602 struct crypt_config *cc = io->cc; in kcryptd_crypt_write_convert() local
1612 crypt_convert_init(cc, &io->ctx, NULL, io->base_bio, sector); in kcryptd_crypt_write_convert()
1626 r = crypt_convert(cc, &io->ctx); in kcryptd_crypt_write_convert()
1648 struct crypt_config *cc = io->cc; in kcryptd_crypt_read_convert() local
1653 crypt_convert_init(cc, &io->ctx, io->base_bio, io->base_bio, in kcryptd_crypt_read_convert()
1656 r = crypt_convert(cc, &io->ctx); in kcryptd_crypt_read_convert()
1672 struct crypt_config *cc = io->cc; in kcryptd_async_done() local
1684 if (!error && cc->iv_gen_ops && cc->iv_gen_ops->post) in kcryptd_async_done()
1685 error = cc->iv_gen_ops->post(cc, org_iv_of_dmreq(cc, dmreq), dmreq); in kcryptd_async_done()
1690 (unsigned long long)le64_to_cpu(*org_sector_of_dmreq(cc, dmreq))); in kcryptd_async_done()
1695 crypt_free_req(cc, req_of_dmreq(cc, dmreq), io->base_bio); in kcryptd_async_done()
1718 struct crypt_config *cc = io->cc; in kcryptd_queue_crypt() local
1721 queue_work(cc->crypt_queue, &io->work); in kcryptd_queue_crypt()
1724 static void crypt_free_tfms_aead(struct crypt_config *cc) in crypt_free_tfms_aead() argument
1726 if (!cc->cipher_tfm.tfms_aead) in crypt_free_tfms_aead()
1729 if (cc->cipher_tfm.tfms_aead[0] && !IS_ERR(cc->cipher_tfm.tfms_aead[0])) { in crypt_free_tfms_aead()
1730 crypto_free_aead(cc->cipher_tfm.tfms_aead[0]); in crypt_free_tfms_aead()
1731 cc->cipher_tfm.tfms_aead[0] = NULL; in crypt_free_tfms_aead()
1734 kfree(cc->cipher_tfm.tfms_aead); in crypt_free_tfms_aead()
1735 cc->cipher_tfm.tfms_aead = NULL; in crypt_free_tfms_aead()
1738 static void crypt_free_tfms_skcipher(struct crypt_config *cc) in crypt_free_tfms_skcipher() argument
1742 if (!cc->cipher_tfm.tfms) in crypt_free_tfms_skcipher()
1745 for (i = 0; i < cc->tfms_count; i++) in crypt_free_tfms_skcipher()
1746 if (cc->cipher_tfm.tfms[i] && !IS_ERR(cc->cipher_tfm.tfms[i])) { in crypt_free_tfms_skcipher()
1747 crypto_free_skcipher(cc->cipher_tfm.tfms[i]); in crypt_free_tfms_skcipher()
1748 cc->cipher_tfm.tfms[i] = NULL; in crypt_free_tfms_skcipher()
1751 kfree(cc->cipher_tfm.tfms); in crypt_free_tfms_skcipher()
1752 cc->cipher_tfm.tfms = NULL; in crypt_free_tfms_skcipher()
1755 static void crypt_free_tfms(struct crypt_config *cc) in crypt_free_tfms() argument
1757 if (crypt_integrity_aead(cc)) in crypt_free_tfms()
1758 crypt_free_tfms_aead(cc); in crypt_free_tfms()
1760 crypt_free_tfms_skcipher(cc); in crypt_free_tfms()
1763 static int crypt_alloc_tfms_skcipher(struct crypt_config *cc, char *ciphermode) in crypt_alloc_tfms_skcipher() argument
1768 cc->cipher_tfm.tfms = kcalloc(cc->tfms_count, in crypt_alloc_tfms_skcipher()
1771 if (!cc->cipher_tfm.tfms) in crypt_alloc_tfms_skcipher()
1774 for (i = 0; i < cc->tfms_count; i++) { in crypt_alloc_tfms_skcipher()
1775 cc->cipher_tfm.tfms[i] = crypto_alloc_skcipher(ciphermode, 0, 0); in crypt_alloc_tfms_skcipher()
1776 if (IS_ERR(cc->cipher_tfm.tfms[i])) { in crypt_alloc_tfms_skcipher()
1777 err = PTR_ERR(cc->cipher_tfm.tfms[i]); in crypt_alloc_tfms_skcipher()
1778 crypt_free_tfms(cc); in crypt_alloc_tfms_skcipher()
1789 crypto_skcipher_alg(any_tfm(cc))->base.cra_driver_name); in crypt_alloc_tfms_skcipher()
1793 static int crypt_alloc_tfms_aead(struct crypt_config *cc, char *ciphermode) in crypt_alloc_tfms_aead() argument
1797 cc->cipher_tfm.tfms = kmalloc(sizeof(struct crypto_aead *), GFP_KERNEL); in crypt_alloc_tfms_aead()
1798 if (!cc->cipher_tfm.tfms) in crypt_alloc_tfms_aead()
1801 cc->cipher_tfm.tfms_aead[0] = crypto_alloc_aead(ciphermode, 0, 0); in crypt_alloc_tfms_aead()
1802 if (IS_ERR(cc->cipher_tfm.tfms_aead[0])) { in crypt_alloc_tfms_aead()
1803 err = PTR_ERR(cc->cipher_tfm.tfms_aead[0]); in crypt_alloc_tfms_aead()
1804 crypt_free_tfms(cc); in crypt_alloc_tfms_aead()
1809 crypto_aead_alg(any_tfm_aead(cc))->base.cra_driver_name); in crypt_alloc_tfms_aead()
1813 static int crypt_alloc_tfms(struct crypt_config *cc, char *ciphermode) in crypt_alloc_tfms() argument
1815 if (crypt_integrity_aead(cc)) in crypt_alloc_tfms()
1816 return crypt_alloc_tfms_aead(cc, ciphermode); in crypt_alloc_tfms()
1818 return crypt_alloc_tfms_skcipher(cc, ciphermode); in crypt_alloc_tfms()
1821 static unsigned crypt_subkey_size(struct crypt_config *cc) in crypt_subkey_size() argument
1823 return (cc->key_size - cc->key_extra_size) >> ilog2(cc->tfms_count); in crypt_subkey_size()
1826 static unsigned crypt_authenckey_size(struct crypt_config *cc) in crypt_authenckey_size() argument
1828 return crypt_subkey_size(cc) + RTA_SPACE(sizeof(struct crypto_authenc_key_param)); in crypt_authenckey_size()
1853 static int crypt_setkey(struct crypt_config *cc) in crypt_setkey() argument
1859 subkey_size = crypt_subkey_size(cc); in crypt_setkey()
1861 if (crypt_integrity_hmac(cc)) { in crypt_setkey()
1862 if (subkey_size < cc->key_mac_size) in crypt_setkey()
1865 crypt_copy_authenckey(cc->authenc_key, cc->key, in crypt_setkey()
1866 subkey_size - cc->key_mac_size, in crypt_setkey()
1867 cc->key_mac_size); in crypt_setkey()
1870 for (i = 0; i < cc->tfms_count; i++) { in crypt_setkey()
1871 if (crypt_integrity_hmac(cc)) in crypt_setkey()
1872 r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], in crypt_setkey()
1873 cc->authenc_key, crypt_authenckey_size(cc)); in crypt_setkey()
1874 else if (crypt_integrity_aead(cc)) in crypt_setkey()
1875 r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], in crypt_setkey()
1876 cc->key + (i * subkey_size), in crypt_setkey()
1879 r = crypto_skcipher_setkey(cc->cipher_tfm.tfms[i], in crypt_setkey()
1880 cc->key + (i * subkey_size), in crypt_setkey()
1886 if (crypt_integrity_hmac(cc)) in crypt_setkey()
1887 memzero_explicit(cc->authenc_key, crypt_authenckey_size(cc)); in crypt_setkey()
1902 static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string) in crypt_set_keyring_key() argument
1948 if (cc->key_size != ukp->datalen) { in crypt_set_keyring_key()
1955 memcpy(cc->key, ukp->data, cc->key_size); in crypt_set_keyring_key()
1961 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); in crypt_set_keyring_key()
1963 ret = crypt_setkey(cc); in crypt_set_keyring_key()
1966 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); in crypt_set_keyring_key()
1967 kzfree(cc->key_string); in crypt_set_keyring_key()
1968 cc->key_string = new_key_string; in crypt_set_keyring_key()
2000 static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string) in crypt_set_keyring_key() argument
2012 static int crypt_set_key(struct crypt_config *cc, char *key) in crypt_set_key() argument
2018 if (!cc->key_size && strcmp(key, "-")) in crypt_set_key()
2023 r = crypt_set_keyring_key(cc, key + 1); in crypt_set_key()
2028 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); in crypt_set_key()
2031 kzfree(cc->key_string); in crypt_set_key()
2032 cc->key_string = NULL; in crypt_set_key()
2035 if (cc->key_size && hex2bin(cc->key, key, cc->key_size) < 0) in crypt_set_key()
2038 r = crypt_setkey(cc); in crypt_set_key()
2040 set_bit(DM_CRYPT_KEY_VALID, &cc->flags); in crypt_set_key()
2049 static int crypt_wipe_key(struct crypt_config *cc) in crypt_wipe_key() argument
2053 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); in crypt_wipe_key()
2054 get_random_bytes(&cc->key, cc->key_size); in crypt_wipe_key()
2057 if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) { in crypt_wipe_key()
2058 r = cc->iv_gen_ops->wipe(cc); in crypt_wipe_key()
2063 kzfree(cc->key_string); in crypt_wipe_key()
2064 cc->key_string = NULL; in crypt_wipe_key()
2065 r = crypt_setkey(cc); in crypt_wipe_key()
2066 memset(&cc->key, 0, cc->key_size * sizeof(u8)); in crypt_wipe_key()
2086 struct crypt_config *cc = pool_data; in crypt_page_alloc() local
2089 if (unlikely(percpu_counter_compare(&cc->n_allocated_pages, dm_crypt_pages_per_client) >= 0) && in crypt_page_alloc()
2095 percpu_counter_add(&cc->n_allocated_pages, 1); in crypt_page_alloc()
2102 struct crypt_config *cc = pool_data; in crypt_page_free() local
2105 percpu_counter_sub(&cc->n_allocated_pages, 1); in crypt_page_free()
2110 struct crypt_config *cc = ti->private; in crypt_dtr() local
2114 if (!cc) in crypt_dtr()
2117 if (cc->write_thread) in crypt_dtr()
2118 kthread_stop(cc->write_thread); in crypt_dtr()
2120 if (cc->io_queue) in crypt_dtr()
2121 destroy_workqueue(cc->io_queue); in crypt_dtr()
2122 if (cc->crypt_queue) in crypt_dtr()
2123 destroy_workqueue(cc->crypt_queue); in crypt_dtr()
2125 crypt_free_tfms(cc); in crypt_dtr()
2127 bioset_exit(&cc->bs); in crypt_dtr()
2129 mempool_exit(&cc->page_pool); in crypt_dtr()
2130 mempool_exit(&cc->req_pool); in crypt_dtr()
2131 mempool_exit(&cc->tag_pool); in crypt_dtr()
2133 WARN_ON(percpu_counter_sum(&cc->n_allocated_pages) != 0); in crypt_dtr()
2134 percpu_counter_destroy(&cc->n_allocated_pages); in crypt_dtr()
2136 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr) in crypt_dtr()
2137 cc->iv_gen_ops->dtr(cc); in crypt_dtr()
2139 if (cc->dev) in crypt_dtr()
2140 dm_put_device(ti, cc->dev); in crypt_dtr()
2142 kzfree(cc->cipher_string); in crypt_dtr()
2143 kzfree(cc->key_string); in crypt_dtr()
2144 kzfree(cc->cipher_auth); in crypt_dtr()
2145 kzfree(cc->authenc_key); in crypt_dtr()
2147 mutex_destroy(&cc->bio_alloc_lock); in crypt_dtr()
2150 kzfree(cc); in crypt_dtr()
2161 struct crypt_config *cc = ti->private; in crypt_ctr_ivmode() local
2163 if (crypt_integrity_aead(cc)) in crypt_ctr_ivmode()
2164 cc->iv_size = crypto_aead_ivsize(any_tfm_aead(cc)); in crypt_ctr_ivmode()
2166 cc->iv_size = crypto_skcipher_ivsize(any_tfm(cc)); in crypt_ctr_ivmode()
2168 if (cc->iv_size) in crypt_ctr_ivmode()
2170 cc->iv_size = max(cc->iv_size, in crypt_ctr_ivmode()
2179 cc->iv_gen_ops = NULL; in crypt_ctr_ivmode()
2181 cc->iv_gen_ops = &crypt_iv_plain_ops; in crypt_ctr_ivmode()
2183 cc->iv_gen_ops = &crypt_iv_plain64_ops; in crypt_ctr_ivmode()
2185 cc->iv_gen_ops = &crypt_iv_plain64be_ops; in crypt_ctr_ivmode()
2187 cc->iv_gen_ops = &crypt_iv_essiv_ops; in crypt_ctr_ivmode()
2189 cc->iv_gen_ops = &crypt_iv_benbi_ops; in crypt_ctr_ivmode()
2191 cc->iv_gen_ops = &crypt_iv_null_ops; in crypt_ctr_ivmode()
2193 cc->iv_gen_ops = &crypt_iv_eboiv_ops; in crypt_ctr_ivmode()
2195 cc->iv_gen_ops = &crypt_iv_lmk_ops; in crypt_ctr_ivmode()
2202 if (cc->key_size % cc->key_parts) { in crypt_ctr_ivmode()
2203 cc->key_parts++; in crypt_ctr_ivmode()
2204 cc->key_extra_size = cc->key_size / cc->key_parts; in crypt_ctr_ivmode()
2207 cc->iv_gen_ops = &crypt_iv_tcw_ops; in crypt_ctr_ivmode()
2208 cc->key_parts += 2; /* IV + whitening */ in crypt_ctr_ivmode()
2209 cc->key_extra_size = cc->iv_size + TCW_WHITENING_SIZE; in crypt_ctr_ivmode()
2211 cc->iv_gen_ops = &crypt_iv_random_ops; in crypt_ctr_ivmode()
2213 cc->integrity_iv_size = cc->iv_size; in crypt_ctr_ivmode()
2227 static int crypt_ctr_auth_cipher(struct crypt_config *cc, char *cipher_api) in crypt_ctr_auth_cipher() argument
2251 cc->key_mac_size = crypto_ahash_digestsize(mac); in crypt_ctr_auth_cipher()
2254 cc->authenc_key = kmalloc(crypt_authenckey_size(cc), GFP_KERNEL); in crypt_ctr_auth_cipher()
2255 if (!cc->authenc_key) in crypt_ctr_auth_cipher()
2264 struct crypt_config *cc = ti->private; in crypt_ctr_cipher_new() local
2268 cc->tfms_count = 1; in crypt_ctr_cipher_new()
2292 if (crypt_integrity_aead(cc)) { in crypt_ctr_cipher_new()
2293 ret = crypt_ctr_auth_cipher(cc, cipher_api); in crypt_ctr_cipher_new()
2301 cc->tfms_count = 64; in crypt_ctr_cipher_new()
2317 cc->key_parts = cc->tfms_count; in crypt_ctr_cipher_new()
2320 ret = crypt_alloc_tfms(cc, cipher_api); in crypt_ctr_cipher_new()
2326 if (crypt_integrity_aead(cc)) in crypt_ctr_cipher_new()
2327 cc->iv_size = crypto_aead_ivsize(any_tfm_aead(cc)); in crypt_ctr_cipher_new()
2329 cc->iv_size = crypto_skcipher_ivsize(any_tfm(cc)); in crypt_ctr_cipher_new()
2337 struct crypt_config *cc = ti->private; in crypt_ctr_cipher_old() local
2343 if (strchr(cipher_in, '(') || crypt_integrity_aead(cc)) { in crypt_ctr_cipher_old()
2357 cc->tfms_count = 1; in crypt_ctr_cipher_old()
2358 else if (sscanf(keycount, "%u%c", &cc->tfms_count, &dummy) != 1 || in crypt_ctr_cipher_old()
2359 !is_power_of_2(cc->tfms_count)) { in crypt_ctr_cipher_old()
2363 cc->key_parts = cc->tfms_count; in crypt_ctr_cipher_old()
2405 ret = crypt_alloc_tfms(cc, cipher_api); in crypt_ctr_cipher_old()
2421 struct crypt_config *cc = ti->private; in crypt_ctr_cipher() local
2425 cc->cipher_string = kstrdup(cipher_in, GFP_KERNEL); in crypt_ctr_cipher()
2426 if (!cc->cipher_string) { in crypt_ctr_cipher()
2444 ret = crypt_set_key(cc, key); in crypt_ctr_cipher()
2451 if (cc->iv_gen_ops && cc->iv_gen_ops->ctr) { in crypt_ctr_cipher()
2452 ret = cc->iv_gen_ops->ctr(cc, ti, ivopts); in crypt_ctr_cipher()
2460 if (cc->iv_gen_ops && cc->iv_gen_ops->init) { in crypt_ctr_cipher()
2461 ret = cc->iv_gen_ops->init(cc); in crypt_ctr_cipher()
2469 if (cc->key_string) in crypt_ctr_cipher()
2470 memset(cc->key, 0, cc->key_size * sizeof(u8)); in crypt_ctr_cipher()
2477 struct crypt_config *cc = ti->private; in crypt_ctr_optional() local
2506 set_bit(DM_CRYPT_SAME_CPU, &cc->flags); in crypt_ctr_optional()
2509 set_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags); in crypt_ctr_optional()
2515 cc->on_disk_tag_size = val; in crypt_ctr_optional()
2518 set_bit(CRYPT_MODE_INTEGRITY_AEAD, &cc->cipher_flags); in crypt_ctr_optional()
2524 cc->cipher_auth = kstrdup(sval, GFP_KERNEL); in crypt_ctr_optional()
2525 if (!cc->cipher_auth) in crypt_ctr_optional()
2527 } else if (sscanf(opt_string, "sector_size:%hu%c", &cc->sector_size, &dummy) == 1) { in crypt_ctr_optional()
2528 if (cc->sector_size < (1 << SECTOR_SHIFT) || in crypt_ctr_optional()
2529 cc->sector_size > 4096 || in crypt_ctr_optional()
2530 (cc->sector_size & (cc->sector_size - 1))) { in crypt_ctr_optional()
2534 if (ti->len & ((cc->sector_size >> SECTOR_SHIFT) - 1)) { in crypt_ctr_optional()
2538 cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT; in crypt_ctr_optional()
2540 set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); in crypt_ctr_optional()
2556 struct crypt_config *cc; in crypt_ctr() local
2576 cc = kzalloc(struct_size(cc, key, key_size), GFP_KERNEL); in crypt_ctr()
2577 if (!cc) { in crypt_ctr()
2581 cc->key_size = key_size; in crypt_ctr()
2582 cc->sector_size = (1 << SECTOR_SHIFT); in crypt_ctr()
2583 cc->sector_shift = 0; in crypt_ctr()
2585 ti->private = cc; in crypt_ctr()
2592 ret = percpu_counter_init(&cc->n_allocated_pages, 0, GFP_KERNEL); in crypt_ctr()
2607 if (crypt_integrity_aead(cc)) { in crypt_ctr()
2608 cc->dmreq_start = sizeof(struct aead_request); in crypt_ctr()
2609 cc->dmreq_start += crypto_aead_reqsize(any_tfm_aead(cc)); in crypt_ctr()
2610 align_mask = crypto_aead_alignmask(any_tfm_aead(cc)); in crypt_ctr()
2612 cc->dmreq_start = sizeof(struct skcipher_request); in crypt_ctr()
2613 cc->dmreq_start += crypto_skcipher_reqsize(any_tfm(cc)); in crypt_ctr()
2614 align_mask = crypto_skcipher_alignmask(any_tfm(cc)); in crypt_ctr()
2616 cc->dmreq_start = ALIGN(cc->dmreq_start, __alignof__(struct dm_crypt_request)); in crypt_ctr()
2620 iv_size_padding = -(cc->dmreq_start + sizeof(struct dm_crypt_request)) in crypt_ctr()
2633 iv_size_padding + cc->iv_size + in crypt_ctr()
2634 cc->iv_size + in crypt_ctr()
2638 ret = mempool_init_kmalloc_pool(&cc->req_pool, MIN_IOS, cc->dmreq_start + additional_req_size); in crypt_ctr()
2644 cc->per_bio_data_size = ti->per_io_data_size = in crypt_ctr()
2645 ALIGN(sizeof(struct dm_crypt_io) + cc->dmreq_start + additional_req_size, in crypt_ctr()
2648 ret = mempool_init(&cc->page_pool, BIO_MAX_PAGES, crypt_page_alloc, crypt_page_free, cc); in crypt_ctr()
2654 ret = bioset_init(&cc->bs, MIN_IOS, 0, BIOSET_NEED_BVECS); in crypt_ctr()
2660 mutex_init(&cc->bio_alloc_lock); in crypt_ctr()
2664 (tmpll & ((cc->sector_size >> SECTOR_SHIFT) - 1))) { in crypt_ctr()
2668 cc->iv_offset = tmpll; in crypt_ctr()
2670 ret = dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev); in crypt_ctr()
2681 cc->start = tmpll; in crypt_ctr()
2683 if (crypt_integrity_aead(cc) || cc->integrity_iv_size) { in crypt_ctr()
2684 ret = crypt_integrity_ctr(cc, ti); in crypt_ctr()
2688 cc->tag_pool_max_sectors = POOL_ENTRY_SIZE / cc->on_disk_tag_size; in crypt_ctr()
2689 if (!cc->tag_pool_max_sectors) in crypt_ctr()
2690 cc->tag_pool_max_sectors = 1; in crypt_ctr()
2692 ret = mempool_init_kmalloc_pool(&cc->tag_pool, MIN_IOS, in crypt_ctr()
2693 cc->tag_pool_max_sectors * cc->on_disk_tag_size); in crypt_ctr()
2699 cc->tag_pool_max_sectors <<= cc->sector_shift; in crypt_ctr()
2703 cc->io_queue = alloc_workqueue("kcryptd_io/%s", WQ_MEM_RECLAIM, 1, devname); in crypt_ctr()
2704 if (!cc->io_queue) { in crypt_ctr()
2709 if (test_bit(DM_CRYPT_SAME_CPU, &cc->flags)) in crypt_ctr()
2710 cc->crypt_queue = alloc_workqueue("kcryptd/%s", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM, in crypt_ctr()
2713 cc->crypt_queue = alloc_workqueue("kcryptd/%s", in crypt_ctr()
2716 if (!cc->crypt_queue) { in crypt_ctr()
2721 spin_lock_init(&cc->write_thread_lock); in crypt_ctr()
2722 cc->write_tree = RB_ROOT; in crypt_ctr()
2724 cc->write_thread = kthread_create(dmcrypt_write, cc, "dmcrypt_write/%s", devname); in crypt_ctr()
2725 if (IS_ERR(cc->write_thread)) { in crypt_ctr()
2726 ret = PTR_ERR(cc->write_thread); in crypt_ctr()
2727 cc->write_thread = NULL; in crypt_ctr()
2731 wake_up_process(cc->write_thread); in crypt_ctr()
2745 struct crypt_config *cc = ti->private; in crypt_map() local
2754 bio_set_dev(bio, cc->dev->bdev); in crypt_map()
2756 bio->bi_iter.bi_sector = cc->start + in crypt_map()
2765 (bio_data_dir(bio) == WRITE || cc->on_disk_tag_size)) in crypt_map()
2772 if (unlikely((bio->bi_iter.bi_sector & ((cc->sector_size >> SECTOR_SHIFT) - 1)) != 0)) in crypt_map()
2775 if (unlikely(bio->bi_iter.bi_size & (cc->sector_size - 1))) in crypt_map()
2778 io = dm_per_bio_data(bio, cc->per_bio_data_size); in crypt_map()
2779 crypt_io_init(io, cc, bio, dm_target_offset(ti, bio->bi_iter.bi_sector)); in crypt_map()
2781 if (cc->on_disk_tag_size) { in crypt_map()
2782 unsigned tag_len = cc->on_disk_tag_size * (bio_sectors(bio) >> cc->sector_shift); in crypt_map()
2787 if (bio_sectors(bio) > cc->tag_pool_max_sectors) in crypt_map()
2788 dm_accept_partial_bio(bio, cc->tag_pool_max_sectors); in crypt_map()
2789 io->integrity_metadata = mempool_alloc(&cc->tag_pool, GFP_NOIO); in crypt_map()
2794 if (crypt_integrity_aead(cc)) in crypt_map()
2811 struct crypt_config *cc = ti->private; in crypt_status() local
2821 DMEMIT("%s ", cc->cipher_string); in crypt_status()
2823 if (cc->key_size > 0) { in crypt_status()
2824 if (cc->key_string) in crypt_status()
2825 DMEMIT(":%u:%s", cc->key_size, cc->key_string); in crypt_status()
2827 for (i = 0; i < cc->key_size; i++) in crypt_status()
2828 DMEMIT("%02x", cc->key[i]); in crypt_status()
2832 DMEMIT(" %llu %s %llu", (unsigned long long)cc->iv_offset, in crypt_status()
2833 cc->dev->name, (unsigned long long)cc->start); in crypt_status()
2836 num_feature_args += test_bit(DM_CRYPT_SAME_CPU, &cc->flags); in crypt_status()
2837 num_feature_args += test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags); in crypt_status()
2838 num_feature_args += cc->sector_size != (1 << SECTOR_SHIFT); in crypt_status()
2839 num_feature_args += test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); in crypt_status()
2840 if (cc->on_disk_tag_size) in crypt_status()
2846 if (test_bit(DM_CRYPT_SAME_CPU, &cc->flags)) in crypt_status()
2848 if (test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) in crypt_status()
2850 if (cc->on_disk_tag_size) in crypt_status()
2851 DMEMIT(" integrity:%u:%s", cc->on_disk_tag_size, cc->cipher_auth); in crypt_status()
2852 if (cc->sector_size != (1 << SECTOR_SHIFT)) in crypt_status()
2853 DMEMIT(" sector_size:%d", cc->sector_size); in crypt_status()
2854 if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags)) in crypt_status()
2864 struct crypt_config *cc = ti->private; in crypt_postsuspend() local
2866 set_bit(DM_CRYPT_SUSPENDED, &cc->flags); in crypt_postsuspend()
2871 struct crypt_config *cc = ti->private; in crypt_preresume() local
2873 if (!test_bit(DM_CRYPT_KEY_VALID, &cc->flags)) { in crypt_preresume()
2883 struct crypt_config *cc = ti->private; in crypt_resume() local
2885 clear_bit(DM_CRYPT_SUSPENDED, &cc->flags); in crypt_resume()
2895 struct crypt_config *cc = ti->private; in crypt_message() local
2902 if (!test_bit(DM_CRYPT_SUSPENDED, &cc->flags)) { in crypt_message()
2909 if (key_size < 0 || cc->key_size != key_size) { in crypt_message()
2914 ret = crypt_set_key(cc, argv[2]); in crypt_message()
2917 if (cc->iv_gen_ops && cc->iv_gen_ops->init) in crypt_message()
2918 ret = cc->iv_gen_ops->init(cc); in crypt_message()
2920 if (cc->key_string) in crypt_message()
2921 memset(cc->key, 0, cc->key_size * sizeof(u8)); in crypt_message()
2925 return crypt_wipe_key(cc); in crypt_message()
2936 struct crypt_config *cc = ti->private; in crypt_iterate_devices() local
2938 return fn(ti, cc->dev, cc->start, ti->len, data); in crypt_iterate_devices()
2943 struct crypt_config *cc = ti->private; in crypt_io_hints() local
2954 max_t(unsigned short, limits->logical_block_size, cc->sector_size); in crypt_io_hints()
2956 max_t(unsigned, limits->physical_block_size, cc->sector_size); in crypt_io_hints()
2957 limits->io_min = max_t(unsigned, limits->io_min, cc->sector_size); in crypt_io_hints()