VSF Documented
kpp.h
Go to the documentation of this file.
1#ifndef __VSF_LINUX_CRYPTO_KPP_H__
2#define __VSF_LINUX_CRYPTO_KPP_H__
3
4#include <linux/crypto.h>
5
6struct kpp_request {
8 struct scatterlist *src;
9 struct scatterlist *dst;
10 unsigned int src_len;
11 unsigned int dst_len;
12};
13
14struct crypto_kpp {
15 unsigned int reqsize;
17};
18
19struct kpp_alg {
20 int (*set_secret)(struct crypto_kpp *tfm, const void *buffer, unsigned int len);
21 int (*generate_public_key)(struct kpp_request *req);
23
25};
26
27enum {
31};
32
33struct kpp_secret {
34 unsigned short type;
35 unsigned short len;
36};
37
38static inline struct crypto_tfm *crypto_kpp_tfm(struct crypto_kpp *tfm)
39{
40 return &tfm->base;
41}
42
43static inline struct kpp_alg *crypto_kpp_alg(struct crypto_kpp *tfm)
44{
45 struct crypto_alg *alg = crypto_kpp_tfm(tfm)->__crt_alg;
46 return vsf_container_of(alg, struct kpp_alg, base);
47}
48
49static inline unsigned int crypto_kpp_reqsize(struct crypto_kpp *tfm)
50{
51 return tfm->reqsize;
52}
53
54static inline void kpp_request_set_tfm(struct kpp_request *req, struct crypto_kpp *tfm)
55{
56 req->base.tfm = crypto_kpp_tfm(tfm);
57}
58
59static inline struct crypto_kpp *crypto_kpp_reqtfm(struct kpp_request *req)
60{
61 return vsf_container_of(req->base.tfm, struct crypto_kpp, base);
62}
63
64static inline struct kpp_request *kpp_request_alloc(struct crypto_kpp *tfm, gfp_t gfp)
65{
66 struct kpp_request *req = kmalloc(sizeof(*req) + crypto_kpp_reqsize(tfm), gfp);
67 if (req) { kpp_request_set_tfm(req, tfm); }
68 return req;
69}
70
71static inline void kpp_request_free(struct kpp_request *req)
72{
73 kfree(req);
74}
75
76static inline void kpp_request_set_callback(struct kpp_request *req, u32 flgs, crypto_completion_t cmpl, void *data)
77{
78 req->base.complete = cmpl;
79 req->base.data = data;
80 req->base.flags = flgs;
81}
82
83static inline void kpp_request_set_input(struct kpp_request *req, struct scatterlist *input, unsigned int input_len)
84{
85 req->src = input;
86 req->src_len = input_len;
87}
88
89static inline void kpp_request_set_output(struct kpp_request *req, struct scatterlist *output, unsigned int output_len)
90{
91 req->dst = output;
92 req->dst_len = output_len;
93}
94
95static inline int crypto_kpp_generate_public_key(struct kpp_request *req)
96{
97 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
98 return crypto_kpp_alg(tfm)->generate_public_key(req);
99}
100
101static inline int crypto_kpp_compute_shared_secret(struct kpp_request *req)
102{
103 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
104 return crypto_kpp_alg(tfm)->compute_shared_secret(req);
105}
106
107static inline struct crypto_kpp *crypto_alloc_kpp(const char *alg_name, u32 type, u32 mask)
108{
109 extern const struct crypto_type crypto_kpp_type;
110 struct crypto_kpp *tfm = crypto_alloc_tfm(alg_name, &crypto_kpp_type, type, mask);
111 if (!IS_ERR(tfm)) {
112 tfm->reqsize = sizeof(struct kpp_request);
113 }
114 return tfm;
115}
116
117static inline void crypto_free_kpp(struct crypto_kpp *tfm)
118{
119 crypto_destroy_tfm(tfm, crypto_kpp_tfm(tfm));
120}
121
122static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm, const void *buffer, unsigned int len)
123{
124 return crypto_kpp_alg(tfm)->set_secret(tfm, buffer, len);
125}
126
127#endif
#define vsf_container_of(__ptr, __type, __member)
Definition __type.h:164
void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
Definition vsf_linux_core_crypto.c:348
void(* crypto_completion_t)(void *req, int err)
Definition crypto.h:27
unsigned int gfp_t
Definition gfp.h:10
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
void * crypto_alloc_tfm(const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask)
Definition vsf_linux_core_crypto.c:327
@ CRYPTO_KPP_SECRET_TYPE_UNKNOWN
Definition kpp.h:28
@ CRYPTO_KPP_SECRET_TYPE_ECDH
Definition kpp.h:30
@ CRYPTO_KPP_SECRET_TYPE_DH
Definition kpp.h:29
uint32_t u32
Definition lvgl.h:43
Definition crypto.h:37
psa_algorithm_t alg
Definition crypto.h:47
Definition crypto.h:30
crypto_completion_t complete
Definition crypto.h:31
u32 flags
Definition crypto.h:34
void * data
Definition crypto.h:32
struct crypto_tfm * tfm
Definition crypto.h:33
Definition kpp.h:14
struct crypto_tfm base
Definition kpp.h:16
unsigned int reqsize
Definition kpp.h:15
Definition crypto.h:62
struct crypto_alg * __crt_alg
Definition crypto.h:63
Definition internal.h:6
Definition kpp.h:19
int(* generate_public_key)(struct kpp_request *req)
Definition kpp.h:21
int(* compute_shared_secret)(struct kpp_request *req)
Definition kpp.h:22
int(* set_secret)(struct crypto_kpp *tfm, const void *buffer, unsigned int len)
Definition kpp.h:20
struct crypto_alg base
Definition kpp.h:24
Definition kpp.h:6
unsigned int dst_len
Definition kpp.h:11
struct scatterlist * src
Definition kpp.h:8
struct scatterlist * dst
Definition kpp.h:9
struct crypto_async_request base
Definition kpp.h:7
unsigned int src_len
Definition kpp.h:10
Definition kpp.h:33
unsigned short len
Definition kpp.h:35
unsigned short type
Definition kpp.h:34
Definition scatterlist.h:4
vk_av_control_type_t type
Definition vsf_audio.h:170
const struct crypto_type crypto_kpp_type
Definition vsf_linux_core_crypto.c:76
Generated from commit: vsfteam/vsf@f33b89f