11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Cryptographic API. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 55cb1454bSHerbert Xu * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 81da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the Free 91da177e4SLinus Torvalds * Software Foundation; either version 2 of the License, or (at your option) 101da177e4SLinus Torvalds * any later version. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds #ifndef _CRYPTO_INTERNAL_H 141da177e4SLinus Torvalds #define _CRYPTO_INTERNAL_H 15cce9e06dSHerbert Xu 16cce9e06dSHerbert Xu #include <crypto/algapi.h> 172825982dSHerbert Xu #include <linux/completion.h> 181da177e4SLinus Torvalds #include <linux/mm.h> 191da177e4SLinus Torvalds #include <linux/highmem.h> 201da177e4SLinus Torvalds #include <linux/interrupt.h> 211da177e4SLinus Torvalds #include <linux/init.h> 225cb1454bSHerbert Xu #include <linux/list.h> 234cc7720cSHerbert Xu #include <linux/module.h> 24fbdae9f3SHerbert Xu #include <linux/kernel.h> 252825982dSHerbert Xu #include <linux/notifier.h> 265cb1454bSHerbert Xu #include <linux/rwsem.h> 2764baf3cfSHerbert Xu #include <linux/slab.h> 281da177e4SLinus Torvalds 292825982dSHerbert Xu /* Crypto notification events. */ 302825982dSHerbert Xu enum { 312825982dSHerbert Xu CRYPTO_MSG_ALG_REQUEST, 322825982dSHerbert Xu CRYPTO_MSG_ALG_REGISTER, 332825982dSHerbert Xu CRYPTO_MSG_ALG_UNREGISTER, 342825982dSHerbert Xu CRYPTO_MSG_TMPL_REGISTER, 352825982dSHerbert Xu CRYPTO_MSG_TMPL_UNREGISTER, 362825982dSHerbert Xu }; 372825982dSHerbert Xu 384cc7720cSHerbert Xu struct crypto_instance; 394cc7720cSHerbert Xu struct crypto_template; 404cc7720cSHerbert Xu 412825982dSHerbert Xu struct crypto_larval { 422825982dSHerbert Xu struct crypto_alg alg; 432825982dSHerbert Xu struct crypto_alg *adult; 442825982dSHerbert Xu struct completion completion; 45492e2b63SHerbert Xu u32 mask; 462825982dSHerbert Xu }; 472825982dSHerbert Xu 485cb1454bSHerbert Xu extern struct list_head crypto_alg_list; 495cb1454bSHerbert Xu extern struct rw_semaphore crypto_alg_sem; 502825982dSHerbert Xu extern struct blocking_notifier_head crypto_chain; 515cb1454bSHerbert Xu 521da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 531da177e4SLinus Torvalds void __init crypto_init_proc(void); 54cce9e06dSHerbert Xu void __exit crypto_exit_proc(void); 551da177e4SLinus Torvalds #else 561da177e4SLinus Torvalds static inline void crypto_init_proc(void) 571da177e4SLinus Torvalds { } 58cce9e06dSHerbert Xu static inline void crypto_exit_proc(void) 59cce9e06dSHerbert Xu { } 601da177e4SLinus Torvalds #endif 611da177e4SLinus Torvalds 62f1ddcaf3SHerbert Xu static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg) 63fbdae9f3SHerbert Xu { 64ee756416SHerbert Xu unsigned int len = alg->cra_ctxsize; 65ee756416SHerbert Xu 66ee756416SHerbert Xu if (alg->cra_alignmask) { 67ee756416SHerbert Xu len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1); 68ee756416SHerbert Xu len += alg->cra_digest.dia_digestsize; 69ee756416SHerbert Xu } 70ee756416SHerbert Xu 71ee756416SHerbert Xu return len; 72fbdae9f3SHerbert Xu } 73fbdae9f3SHerbert Xu 74f1ddcaf3SHerbert Xu static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg) 75fbdae9f3SHerbert Xu { 76f1ddcaf3SHerbert Xu return alg->cra_ctxsize; 77fbdae9f3SHerbert Xu } 78fbdae9f3SHerbert Xu 79f1ddcaf3SHerbert Xu static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg) 80fbdae9f3SHerbert Xu { 81fbdae9f3SHerbert Xu return alg->cra_ctxsize; 82fbdae9f3SHerbert Xu } 83fbdae9f3SHerbert Xu 842825982dSHerbert Xu struct crypto_alg *crypto_mod_get(struct crypto_alg *alg); 85492e2b63SHerbert Xu struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask); 86492e2b63SHerbert Xu struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask); 872825982dSHerbert Xu 881da177e4SLinus Torvalds int crypto_init_digest_ops(struct crypto_tfm *tfm); 891da177e4SLinus Torvalds int crypto_init_cipher_ops(struct crypto_tfm *tfm); 901da177e4SLinus Torvalds int crypto_init_compress_ops(struct crypto_tfm *tfm); 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds void crypto_exit_digest_ops(struct crypto_tfm *tfm); 931da177e4SLinus Torvalds void crypto_exit_cipher_ops(struct crypto_tfm *tfm); 941da177e4SLinus Torvalds void crypto_exit_compress_ops(struct crypto_tfm *tfm); 951da177e4SLinus Torvalds 96*b9c55aa4SHerbert Xu void crypto_larval_kill(struct crypto_alg *alg); 97*b9c55aa4SHerbert Xu struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask); 98492e2b63SHerbert Xu void crypto_larval_error(const char *name, u32 type, u32 mask); 992825982dSHerbert Xu 1006bfd4809SHerbert Xu void crypto_shoot_alg(struct crypto_alg *alg); 10127d2a330SHerbert Xu struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, 10227d2a330SHerbert Xu u32 mask); 1036bfd4809SHerbert Xu 1044cc7720cSHerbert Xu int crypto_register_instance(struct crypto_template *tmpl, 1054cc7720cSHerbert Xu struct crypto_instance *inst); 1064cc7720cSHerbert Xu 1072825982dSHerbert Xu int crypto_register_notifier(struct notifier_block *nb); 1082825982dSHerbert Xu int crypto_unregister_notifier(struct notifier_block *nb); 1092825982dSHerbert Xu 1106bfd4809SHerbert Xu static inline void crypto_alg_put(struct crypto_alg *alg) 1116bfd4809SHerbert Xu { 1126bfd4809SHerbert Xu if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy) 1136bfd4809SHerbert Xu alg->cra_destroy(alg); 1146bfd4809SHerbert Xu } 1156bfd4809SHerbert Xu 1164cc7720cSHerbert Xu static inline int crypto_tmpl_get(struct crypto_template *tmpl) 1174cc7720cSHerbert Xu { 1184cc7720cSHerbert Xu return try_module_get(tmpl->module); 1194cc7720cSHerbert Xu } 1204cc7720cSHerbert Xu 1214cc7720cSHerbert Xu static inline void crypto_tmpl_put(struct crypto_template *tmpl) 1224cc7720cSHerbert Xu { 1234cc7720cSHerbert Xu module_put(tmpl->module); 1244cc7720cSHerbert Xu } 1254cc7720cSHerbert Xu 1262825982dSHerbert Xu static inline int crypto_is_larval(struct crypto_alg *alg) 1272825982dSHerbert Xu { 1282825982dSHerbert Xu return alg->cra_flags & CRYPTO_ALG_LARVAL; 1292825982dSHerbert Xu } 1302825982dSHerbert Xu 1316bfd4809SHerbert Xu static inline int crypto_is_dead(struct crypto_alg *alg) 1326bfd4809SHerbert Xu { 1336bfd4809SHerbert Xu return alg->cra_flags & CRYPTO_ALG_DEAD; 1346bfd4809SHerbert Xu } 1356bfd4809SHerbert Xu 1366bfd4809SHerbert Xu static inline int crypto_is_moribund(struct crypto_alg *alg) 1376bfd4809SHerbert Xu { 1386bfd4809SHerbert Xu return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING); 1396bfd4809SHerbert Xu } 1406bfd4809SHerbert Xu 1412825982dSHerbert Xu static inline int crypto_notify(unsigned long val, void *v) 1422825982dSHerbert Xu { 1432825982dSHerbert Xu return blocking_notifier_call_chain(&crypto_chain, val, v); 1442825982dSHerbert Xu } 1452825982dSHerbert Xu 1461da177e4SLinus Torvalds #endif /* _CRYPTO_INTERNAL_H */ 1471da177e4SLinus Torvalds 148