Lines Matching refs:alg

31 static int crypto_check_alg(struct crypto_alg *alg)  in crypto_check_alg()  argument
33 crypto_check_module_sig(alg->cra_module); in crypto_check_alg()
35 if (!alg->cra_name[0] || !alg->cra_driver_name[0]) in crypto_check_alg()
38 if (alg->cra_alignmask & (alg->cra_alignmask + 1)) in crypto_check_alg()
42 if (alg->cra_alignmask > MAX_ALGAPI_ALIGNMASK) in crypto_check_alg()
45 if (alg->cra_blocksize > MAX_ALGAPI_BLOCKSIZE) in crypto_check_alg()
49 if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == in crypto_check_alg()
51 if (alg->cra_alignmask > MAX_CIPHER_ALIGNMASK) in crypto_check_alg()
54 if (alg->cra_blocksize > MAX_CIPHER_BLOCKSIZE) in crypto_check_alg()
58 if (alg->cra_priority < 0) in crypto_check_alg()
61 refcount_set(&alg->cra_refcnt, 1); in crypto_check_alg()
68 inst->alg.cra_type->free(inst); in crypto_free_instance()
71 static void crypto_destroy_instance(struct crypto_alg *alg) in crypto_destroy_instance() argument
73 struct crypto_instance *inst = (void *)alg; in crypto_destroy_instance()
89 static struct list_head *crypto_more_spawns(struct crypto_alg *alg, in crypto_more_spawns() argument
110 return &n->inst->alg.cra_users; in crypto_more_spawns()
118 if (crypto_is_dead(&inst->alg)) in crypto_remove_instance()
121 inst->alg.cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_instance()
126 list_move(&inst->alg.cra_list, list); in crypto_remove_instance()
128 inst->alg.cra_destroy = crypto_destroy_instance; in crypto_remove_instance()
130 BUG_ON(!list_empty(&inst->alg.cra_users)); in crypto_remove_instance()
139 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, in crypto_remove_spawns() argument
142 u32 new_type = (nalg ?: alg)->cra_flags; in crypto_remove_spawns()
149 spawns = &alg->cra_users; in crypto_remove_spawns()
151 if ((spawn->alg->cra_flags ^ new_type) & spawn->mask) in crypto_remove_spawns()
172 spawn->dead = !spawn->registered || &inst->alg != nalg; in crypto_remove_spawns()
177 BUG_ON(&inst->alg == alg); in crypto_remove_spawns()
179 if (&inst->alg == nalg) in crypto_remove_spawns()
182 spawns = &inst->alg.cra_users; in crypto_remove_spawns()
202 } while ((spawns = crypto_more_spawns(alg, &stack, &top, in crypto_remove_spawns()
212 list_move(&spawn->list, &spawn->alg->cra_users); in crypto_remove_spawns()
219 static struct crypto_larval *crypto_alloc_test_larval(struct crypto_alg *alg) in crypto_alloc_test_larval() argument
226 larval = crypto_larval_alloc(alg->cra_name, in crypto_alloc_test_larval()
227 alg->cra_flags | CRYPTO_ALG_TESTED, 0); in crypto_alloc_test_larval()
231 larval->adult = crypto_mod_get(alg); in crypto_alloc_test_larval()
237 refcount_set(&larval->alg.cra_refcnt, 1); in crypto_alloc_test_larval()
238 memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, in crypto_alloc_test_larval()
240 larval->alg.cra_priority = alg->cra_priority; in crypto_alloc_test_larval()
245 static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) in __crypto_register_alg() argument
251 if (crypto_is_dead(alg)) in __crypto_register_alg()
254 INIT_LIST_HEAD(&alg->cra_users); in __crypto_register_alg()
257 alg->cra_flags &= ~CRYPTO_ALG_TESTED; in __crypto_register_alg()
262 if (q == alg) in __crypto_register_alg()
269 if (!strcmp(alg->cra_driver_name, q->cra_driver_name)) in __crypto_register_alg()
274 if (!strcmp(q->cra_driver_name, alg->cra_name) || in __crypto_register_alg()
275 !strcmp(q->cra_name, alg->cra_driver_name)) in __crypto_register_alg()
279 larval = crypto_alloc_test_larval(alg); in __crypto_register_alg()
283 list_add(&alg->cra_list, &crypto_alg_list); in __crypto_register_alg()
286 list_add(&larval->alg.cra_list, &crypto_alg_list); in __crypto_register_alg()
288 alg->cra_flags |= CRYPTO_ALG_TESTED; in __crypto_register_alg()
290 crypto_stats_init(alg); in __crypto_register_alg()
303 struct crypto_alg *alg; in crypto_alg_tested() local
324 alg = test->adult; in crypto_alg_tested()
325 if (err || list_empty(&alg->cra_list)) in crypto_alg_tested()
328 alg->cra_flags |= CRYPTO_ALG_TESTED; in crypto_alg_tested()
336 if (strcmp(alg->cra_name, q->cra_name)) in crypto_alg_tested()
339 if (q->cra_priority > alg->cra_priority) { in crypto_alg_tested()
346 if (q == alg) in crypto_alg_tested()
360 if (strcmp(alg->cra_name, q->cra_name) && in crypto_alg_tested()
361 strcmp(alg->cra_driver_name, q->cra_name)) in crypto_alg_tested()
366 if ((q->cra_flags ^ alg->cra_flags) & larval->mask) in crypto_alg_tested()
369 if (best && crypto_mod_get(alg)) in crypto_alg_tested()
370 larval->adult = alg; in crypto_alg_tested()
377 if (strcmp(alg->cra_name, q->cra_name)) in crypto_alg_tested()
380 if (strcmp(alg->cra_driver_name, q->cra_driver_name) && in crypto_alg_tested()
381 q->cra_priority > alg->cra_priority) in crypto_alg_tested()
384 crypto_remove_spawns(q, &list, alg); in crypto_alg_tested()
399 struct crypto_alg *alg; in crypto_remove_final() local
402 list_for_each_entry_safe(alg, n, list, cra_list) { in crypto_remove_final()
403 list_del_init(&alg->cra_list); in crypto_remove_final()
404 crypto_alg_put(alg); in crypto_remove_final()
409 int crypto_register_alg(struct crypto_alg *alg) in crypto_register_alg() argument
415 alg->cra_flags &= ~CRYPTO_ALG_DEAD; in crypto_register_alg()
416 err = crypto_check_alg(alg); in crypto_register_alg()
421 larval = __crypto_register_alg(alg); in crypto_register_alg()
436 static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list) in crypto_remove_alg() argument
438 if (unlikely(list_empty(&alg->cra_list))) in crypto_remove_alg()
441 alg->cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_alg()
443 list_del_init(&alg->cra_list); in crypto_remove_alg()
444 crypto_remove_spawns(alg, list, NULL); in crypto_remove_alg()
449 void crypto_unregister_alg(struct crypto_alg *alg) in crypto_unregister_alg() argument
455 ret = crypto_remove_alg(alg, &list); in crypto_unregister_alg()
458 if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) in crypto_unregister_alg()
461 BUG_ON(refcount_read(&alg->cra_refcnt) != 1); in crypto_unregister_alg()
462 if (alg->cra_destroy) in crypto_unregister_alg()
463 alg->cra_destroy(alg); in crypto_unregister_alg()
552 int err = crypto_remove_alg(&inst->alg, &users); in crypto_unregister_template()
560 BUG_ON(refcount_read(&inst->alg.cra_refcnt) != 1); in crypto_unregister_template()
609 err = crypto_check_alg(&inst->alg); in crypto_register_instance()
613 inst->alg.cra_module = tmpl->module; in crypto_register_instance()
614 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; in crypto_register_instance()
629 crypto_mod_put(spawn->alg); in crypto_register_instance()
634 larval = __crypto_register_alg(&inst->alg); in crypto_register_instance()
664 crypto_remove_spawns(&inst->alg, &list, NULL); in crypto_unregister_instance()
676 struct crypto_alg *alg; in crypto_grab_spawn() local
686 alg = crypto_find_alg(name, spawn->frontend, type, mask); in crypto_grab_spawn()
687 if (IS_ERR(alg)) in crypto_grab_spawn()
688 return PTR_ERR(alg); in crypto_grab_spawn()
691 if (!crypto_is_moribund(alg)) { in crypto_grab_spawn()
692 list_add(&spawn->list, &alg->cra_users); in crypto_grab_spawn()
693 spawn->alg = alg; in crypto_grab_spawn()
697 inst->alg.cra_flags |= in crypto_grab_spawn()
698 (alg->cra_flags & CRYPTO_ALG_INHERITED_FLAGS); in crypto_grab_spawn()
703 crypto_mod_put(alg); in crypto_grab_spawn()
710 if (!spawn->alg) /* not yet initialized? */ in crypto_drop_spawn()
719 crypto_mod_put(spawn->alg); in crypto_drop_spawn()
725 struct crypto_alg *alg = ERR_PTR(-EAGAIN); in crypto_spawn_alg() local
731 alg = spawn->alg; in crypto_spawn_alg()
732 if (!crypto_mod_get(alg)) { in crypto_spawn_alg()
733 target = crypto_alg_get(alg); in crypto_spawn_alg()
735 alg = ERR_PTR(-EAGAIN); in crypto_spawn_alg()
745 return alg; in crypto_spawn_alg()
751 struct crypto_alg *alg; in crypto_spawn_tfm() local
754 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm()
755 if (IS_ERR(alg)) in crypto_spawn_tfm()
756 return ERR_CAST(alg); in crypto_spawn_tfm()
759 if (unlikely((alg->cra_flags ^ type) & mask)) in crypto_spawn_tfm()
762 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_spawn_tfm()
769 crypto_mod_put(alg); in crypto_spawn_tfm()
776 struct crypto_alg *alg; in crypto_spawn_tfm2() local
779 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm2()
780 if (IS_ERR(alg)) in crypto_spawn_tfm2()
781 return ERR_CAST(alg); in crypto_spawn_tfm2()
783 tfm = crypto_create_tfm(alg, spawn->frontend); in crypto_spawn_tfm2()
790 crypto_mod_put(alg); in crypto_spawn_tfm2()
876 struct crypto_alg *alg) in crypto_inst_setname() argument
878 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, in crypto_inst_setname()
879 alg->cra_name) >= CRYPTO_MAX_ALG_NAME) in crypto_inst_setname()
882 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", in crypto_inst_setname()
883 name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) in crypto_inst_setname()
1033 unsigned int crypto_alg_extsize(struct crypto_alg *alg) in crypto_alg_extsize() argument
1035 return alg->cra_ctxsize + in crypto_alg_extsize()
1036 (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1)); in crypto_alg_extsize()
1044 struct crypto_alg *alg = crypto_find_alg(name, frontend, type, mask); in crypto_type_has_alg() local
1046 if (!IS_ERR(alg)) { in crypto_type_has_alg()
1047 crypto_mod_put(alg); in crypto_type_has_alg()
1056 void crypto_stats_init(struct crypto_alg *alg) in crypto_stats_init() argument
1058 memset(&alg->stats, 0, sizeof(alg->stats)); in crypto_stats_init()
1062 void crypto_stats_get(struct crypto_alg *alg) in crypto_stats_get() argument
1064 crypto_alg_get(alg); in crypto_stats_get()
1068 void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, in crypto_stats_aead_encrypt() argument
1072 atomic64_inc(&alg->stats.aead.err_cnt); in crypto_stats_aead_encrypt()
1074 atomic64_inc(&alg->stats.aead.encrypt_cnt); in crypto_stats_aead_encrypt()
1075 atomic64_add(cryptlen, &alg->stats.aead.encrypt_tlen); in crypto_stats_aead_encrypt()
1077 crypto_alg_put(alg); in crypto_stats_aead_encrypt()
1081 void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, in crypto_stats_aead_decrypt() argument
1085 atomic64_inc(&alg->stats.aead.err_cnt); in crypto_stats_aead_decrypt()
1087 atomic64_inc(&alg->stats.aead.decrypt_cnt); in crypto_stats_aead_decrypt()
1088 atomic64_add(cryptlen, &alg->stats.aead.decrypt_tlen); in crypto_stats_aead_decrypt()
1090 crypto_alg_put(alg); in crypto_stats_aead_decrypt()
1095 struct crypto_alg *alg) in crypto_stats_akcipher_encrypt() argument
1098 atomic64_inc(&alg->stats.akcipher.err_cnt); in crypto_stats_akcipher_encrypt()
1100 atomic64_inc(&alg->stats.akcipher.encrypt_cnt); in crypto_stats_akcipher_encrypt()
1101 atomic64_add(src_len, &alg->stats.akcipher.encrypt_tlen); in crypto_stats_akcipher_encrypt()
1103 crypto_alg_put(alg); in crypto_stats_akcipher_encrypt()
1108 struct crypto_alg *alg) in crypto_stats_akcipher_decrypt() argument
1111 atomic64_inc(&alg->stats.akcipher.err_cnt); in crypto_stats_akcipher_decrypt()
1113 atomic64_inc(&alg->stats.akcipher.decrypt_cnt); in crypto_stats_akcipher_decrypt()
1114 atomic64_add(src_len, &alg->stats.akcipher.decrypt_tlen); in crypto_stats_akcipher_decrypt()
1116 crypto_alg_put(alg); in crypto_stats_akcipher_decrypt()
1120 void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg) in crypto_stats_akcipher_sign() argument
1123 atomic64_inc(&alg->stats.akcipher.err_cnt); in crypto_stats_akcipher_sign()
1125 atomic64_inc(&alg->stats.akcipher.sign_cnt); in crypto_stats_akcipher_sign()
1126 crypto_alg_put(alg); in crypto_stats_akcipher_sign()
1130 void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg) in crypto_stats_akcipher_verify() argument
1133 atomic64_inc(&alg->stats.akcipher.err_cnt); in crypto_stats_akcipher_verify()
1135 atomic64_inc(&alg->stats.akcipher.verify_cnt); in crypto_stats_akcipher_verify()
1136 crypto_alg_put(alg); in crypto_stats_akcipher_verify()
1140 void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg) in crypto_stats_compress() argument
1143 atomic64_inc(&alg->stats.compress.err_cnt); in crypto_stats_compress()
1145 atomic64_inc(&alg->stats.compress.compress_cnt); in crypto_stats_compress()
1146 atomic64_add(slen, &alg->stats.compress.compress_tlen); in crypto_stats_compress()
1148 crypto_alg_put(alg); in crypto_stats_compress()
1152 void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg) in crypto_stats_decompress() argument
1155 atomic64_inc(&alg->stats.compress.err_cnt); in crypto_stats_decompress()
1157 atomic64_inc(&alg->stats.compress.decompress_cnt); in crypto_stats_decompress()
1158 atomic64_add(slen, &alg->stats.compress.decompress_tlen); in crypto_stats_decompress()
1160 crypto_alg_put(alg); in crypto_stats_decompress()
1165 struct crypto_alg *alg) in crypto_stats_ahash_update() argument
1168 atomic64_inc(&alg->stats.hash.err_cnt); in crypto_stats_ahash_update()
1170 atomic64_add(nbytes, &alg->stats.hash.hash_tlen); in crypto_stats_ahash_update()
1171 crypto_alg_put(alg); in crypto_stats_ahash_update()
1176 struct crypto_alg *alg) in crypto_stats_ahash_final() argument
1179 atomic64_inc(&alg->stats.hash.err_cnt); in crypto_stats_ahash_final()
1181 atomic64_inc(&alg->stats.hash.hash_cnt); in crypto_stats_ahash_final()
1182 atomic64_add(nbytes, &alg->stats.hash.hash_tlen); in crypto_stats_ahash_final()
1184 crypto_alg_put(alg); in crypto_stats_ahash_final()
1188 void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret) in crypto_stats_kpp_set_secret() argument
1191 atomic64_inc(&alg->stats.kpp.err_cnt); in crypto_stats_kpp_set_secret()
1193 atomic64_inc(&alg->stats.kpp.setsecret_cnt); in crypto_stats_kpp_set_secret()
1194 crypto_alg_put(alg); in crypto_stats_kpp_set_secret()
1198 void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret) in crypto_stats_kpp_generate_public_key() argument
1201 atomic64_inc(&alg->stats.kpp.err_cnt); in crypto_stats_kpp_generate_public_key()
1203 atomic64_inc(&alg->stats.kpp.generate_public_key_cnt); in crypto_stats_kpp_generate_public_key()
1204 crypto_alg_put(alg); in crypto_stats_kpp_generate_public_key()
1208 void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret) in crypto_stats_kpp_compute_shared_secret() argument
1211 atomic64_inc(&alg->stats.kpp.err_cnt); in crypto_stats_kpp_compute_shared_secret()
1213 atomic64_inc(&alg->stats.kpp.compute_shared_secret_cnt); in crypto_stats_kpp_compute_shared_secret()
1214 crypto_alg_put(alg); in crypto_stats_kpp_compute_shared_secret()
1218 void crypto_stats_rng_seed(struct crypto_alg *alg, int ret) in crypto_stats_rng_seed() argument
1221 atomic64_inc(&alg->stats.rng.err_cnt); in crypto_stats_rng_seed()
1223 atomic64_inc(&alg->stats.rng.seed_cnt); in crypto_stats_rng_seed()
1224 crypto_alg_put(alg); in crypto_stats_rng_seed()
1228 void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, in crypto_stats_rng_generate() argument
1232 atomic64_inc(&alg->stats.rng.err_cnt); in crypto_stats_rng_generate()
1234 atomic64_inc(&alg->stats.rng.generate_cnt); in crypto_stats_rng_generate()
1235 atomic64_add(dlen, &alg->stats.rng.generate_tlen); in crypto_stats_rng_generate()
1237 crypto_alg_put(alg); in crypto_stats_rng_generate()
1242 struct crypto_alg *alg) in crypto_stats_skcipher_encrypt() argument
1245 atomic64_inc(&alg->stats.cipher.err_cnt); in crypto_stats_skcipher_encrypt()
1247 atomic64_inc(&alg->stats.cipher.encrypt_cnt); in crypto_stats_skcipher_encrypt()
1248 atomic64_add(cryptlen, &alg->stats.cipher.encrypt_tlen); in crypto_stats_skcipher_encrypt()
1250 crypto_alg_put(alg); in crypto_stats_skcipher_encrypt()
1255 struct crypto_alg *alg) in crypto_stats_skcipher_decrypt() argument
1258 atomic64_inc(&alg->stats.cipher.err_cnt); in crypto_stats_skcipher_decrypt()
1260 atomic64_inc(&alg->stats.cipher.decrypt_cnt); in crypto_stats_skcipher_decrypt()
1261 atomic64_add(cryptlen, &alg->stats.cipher.decrypt_tlen); in crypto_stats_skcipher_decrypt()
1263 crypto_alg_put(alg); in crypto_stats_skcipher_decrypt()