Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Public Key Encryption
0004  *
0005  * Copyright (c) 2015, Intel Corporation
0006  * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
0007  */
0008 #ifndef _CRYPTO_AKCIPHER_INT_H
0009 #define _CRYPTO_AKCIPHER_INT_H
0010 #include <crypto/akcipher.h>
0011 #include <crypto/algapi.h>
0012 
0013 struct akcipher_instance {
0014     void (*free)(struct akcipher_instance *inst);
0015     union {
0016         struct {
0017             char head[offsetof(struct akcipher_alg, base)];
0018             struct crypto_instance base;
0019         } s;
0020         struct akcipher_alg alg;
0021     };
0022 };
0023 
0024 struct crypto_akcipher_spawn {
0025     struct crypto_spawn base;
0026 };
0027 
0028 /*
0029  * Transform internal helpers.
0030  */
0031 static inline void *akcipher_request_ctx(struct akcipher_request *req)
0032 {
0033     return req->__ctx;
0034 }
0035 
0036 static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher,
0037                     unsigned int reqsize)
0038 {
0039     crypto_akcipher_alg(akcipher)->reqsize = reqsize;
0040 }
0041 
0042 static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm)
0043 {
0044     return tfm->base.__crt_ctx;
0045 }
0046 
0047 static inline void akcipher_request_complete(struct akcipher_request *req,
0048                          int err)
0049 {
0050     req->base.complete(&req->base, err);
0051 }
0052 
0053 static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm)
0054 {
0055     return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name;
0056 }
0057 
0058 static inline struct crypto_instance *akcipher_crypto_instance(
0059         struct akcipher_instance *inst)
0060 {
0061     return container_of(&inst->alg.base, struct crypto_instance, alg);
0062 }
0063 
0064 static inline struct akcipher_instance *akcipher_instance(
0065         struct crypto_instance *inst)
0066 {
0067     return container_of(&inst->alg, struct akcipher_instance, alg.base);
0068 }
0069 
0070 static inline struct akcipher_instance *akcipher_alg_instance(
0071         struct crypto_akcipher *akcipher)
0072 {
0073     return akcipher_instance(crypto_tfm_alg_instance(&akcipher->base));
0074 }
0075 
0076 static inline void *akcipher_instance_ctx(struct akcipher_instance *inst)
0077 {
0078     return crypto_instance_ctx(akcipher_crypto_instance(inst));
0079 }
0080 
0081 int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn,
0082              struct crypto_instance *inst,
0083              const char *name, u32 type, u32 mask);
0084 
0085 static inline struct crypto_akcipher *crypto_spawn_akcipher(
0086         struct crypto_akcipher_spawn *spawn)
0087 {
0088     return crypto_spawn_tfm2(&spawn->base);
0089 }
0090 
0091 static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn *spawn)
0092 {
0093     crypto_drop_spawn(&spawn->base);
0094 }
0095 
0096 static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
0097         struct crypto_akcipher_spawn *spawn)
0098 {
0099     return container_of(spawn->base.alg, struct akcipher_alg, base);
0100 }
0101 
0102 /**
0103  * crypto_register_akcipher() -- Register public key algorithm
0104  *
0105  * Function registers an implementation of a public key verify algorithm
0106  *
0107  * @alg:    algorithm definition
0108  *
0109  * Return: zero on success; error code in case of error
0110  */
0111 int crypto_register_akcipher(struct akcipher_alg *alg);
0112 
0113 /**
0114  * crypto_unregister_akcipher() -- Unregister public key algorithm
0115  *
0116  * Function unregisters an implementation of a public key verify algorithm
0117  *
0118  * @alg:    algorithm definition
0119  */
0120 void crypto_unregister_akcipher(struct akcipher_alg *alg);
0121 
0122 /**
0123  * akcipher_register_instance() -- Unregister public key template instance
0124  *
0125  * Function registers an implementation of an asymmetric key algorithm
0126  * created from a template
0127  *
0128  * @tmpl:   the template from which the algorithm was created
0129  * @inst:   the template instance
0130  */
0131 int akcipher_register_instance(struct crypto_template *tmpl,
0132         struct akcipher_instance *inst);
0133 #endif