1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Public Key Signature Algorithm 4 * 5 * Copyright (c) 2023 Herbert Xu <herbert@gondor.apana.org.au> 6 */ 7 #ifndef _CRYPTO_INTERNAL_SIG_H 8 #define _CRYPTO_INTERNAL_SIG_H 9 10 #include <crypto/algapi.h> 11 #include <crypto/sig.h> 12 13 struct sig_instance { 14 void (*free)(struct sig_instance *inst); 15 union { 16 struct { 17 char head[offsetof(struct sig_alg, base)]; 18 struct crypto_instance base; 19 }; 20 struct sig_alg alg; 21 }; 22 }; 23 24 struct crypto_sig_spawn { 25 struct crypto_spawn base; 26 }; 27 28 static inline void *crypto_sig_ctx(struct crypto_sig *tfm) 29 { 30 return crypto_tfm_ctx(&tfm->base); 31 } 32 33 /** 34 * crypto_register_sig() -- Register public key signature algorithm 35 * 36 * Function registers an implementation of a public key signature algorithm 37 * 38 * @alg: algorithm definition 39 * 40 * Return: zero on success; error code in case of error 41 */ 42 int crypto_register_sig(struct sig_alg *alg); 43 44 /** 45 * crypto_unregister_sig() -- Unregister public key signature algorithm 46 * 47 * Function unregisters an implementation of a public key signature algorithm 48 * 49 * @alg: algorithm definition 50 */ 51 void crypto_unregister_sig(struct sig_alg *alg); 52 53 int sig_register_instance(struct crypto_template *tmpl, 54 struct sig_instance *inst); 55 56 static inline struct sig_instance *sig_instance(struct crypto_instance *inst) 57 { 58 return container_of(&inst->alg, struct sig_instance, alg.base); 59 } 60 61 static inline struct sig_instance *sig_alg_instance(struct crypto_sig *tfm) 62 { 63 return sig_instance(crypto_tfm_alg_instance(&tfm->base)); 64 } 65 66 static inline struct crypto_instance *sig_crypto_instance(struct sig_instance 67 *inst) 68 { 69 return container_of(&inst->alg.base, struct crypto_instance, alg); 70 } 71 72 static inline void *sig_instance_ctx(struct sig_instance *inst) 73 { 74 return crypto_instance_ctx(sig_crypto_instance(inst)); 75 } 76 77 int crypto_grab_sig(struct crypto_sig_spawn *spawn, 78 struct crypto_instance *inst, 79 const char *name, u32 type, u32 mask); 80 81 static inline struct crypto_sig *crypto_spawn_sig(struct crypto_sig_spawn 82 *spawn) 83 { 84 return crypto_spawn_tfm2(&spawn->base); 85 } 86 87 static inline void crypto_drop_sig(struct crypto_sig_spawn *spawn) 88 { 89 crypto_drop_spawn(&spawn->base); 90 } 91 92 static inline struct sig_alg *crypto_spawn_sig_alg(struct crypto_sig_spawn 93 *spawn) 94 { 95 return container_of(spawn->base.alg, struct sig_alg, base); 96 } 97 #endif 98