1 From f99682e0ccaeadb7446d211dfad6dbf8fcd5675f Mon Sep 17 00:00:00 2001
2 From: Cristian Stoica <cristian.stoica@freescale.com>
3 Date: Thu, 19 Feb 2015 13:39:52 +0200
4 Subject: [PATCH 23/48] cryptodev: simplify cryptodev pkc support code
6 - Engine init returns directly a file descriptor instead of a pointer to one
7 - Similarly, the Engine close will now just close the file
9 Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
11 crypto/crypto.h | 2 +-
12 crypto/engine/eng_cryptodev.c | 43 +++++++----------------------------
13 crypto/engine/eng_int.h | 14 +++---------
14 crypto/engine/eng_lib.c | 53 +++++++++++++++++++++----------------------
15 crypto/engine/engine.h | 13 +++++------
16 5 files changed, 44 insertions(+), 81 deletions(-)
18 diff --git a/crypto/crypto.h b/crypto/crypto.h
19 index 2b4ec59..ddb9b69 100644
22 @@ -668,7 +668,7 @@ struct pkc_cookie_s {
23 * -EINVAL: Parameters Invalid
25 void (*pkc_callback)(struct pkc_cookie_s *cookie, int status);
31 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
32 index b162646..1910c89 100644
33 --- a/crypto/engine/eng_cryptodev.c
34 +++ b/crypto/engine/eng_cryptodev.c
35 @@ -433,10 +433,10 @@ static int get_dev_crypto(void)
37 static int put_dev_crypto(int fd)
39 -#ifdef CRIOGET_NOT_NEEDED
43 +# ifdef CRIOGET_NOT_NEEDED
50 @@ -1863,7 +1863,7 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen,
51 struct pkc_cookie_s *cookie = kop->cookie;
52 struct cryptodev_cookie_s *eng_cookie;
54 - fd = *(int *)cookie->eng_handle;
55 + fd = cookie->eng_handle;
57 eng_cookie = malloc(sizeof(struct cryptodev_cookie_s));
59 @@ -1926,38 +1926,11 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen,
63 -/* Close an opened instance of cryptodev engine */
64 -void cryptodev_close_instance(void *handle)
69 - fd = *(int *)handle;
75 -/* Create an instance of cryptodev for asynchronous interface */
76 -void *cryptodev_init_instance(void)
78 - int *fd = malloc(sizeof(int));
81 - if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) {
91 /* Return 0 on success and 1 on failure */
92 -int cryptodev_check_availability(void *eng_handle)
93 +int cryptodev_check_availability(int fd)
95 - int fd = *(int *)eng_handle;
96 struct pkc_cookie_list_s cookie_list;
97 struct pkc_cookie_s *cookie;
99 @@ -4706,8 +4679,8 @@ void ENGINE_load_cryptodev(void)
102 ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability);
103 - ENGINE_set_close_instance(engine, cryptodev_close_instance);
104 - ENGINE_set_init_instance(engine, cryptodev_init_instance);
105 + ENGINE_set_close_instance(engine, put_dev_crypto);
106 + ENGINE_set_open_instance(engine, open_dev_crypto);
107 ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC);
110 diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h
111 index b698a0c..7541beb 100644
112 --- a/crypto/engine/eng_int.h
113 +++ b/crypto/engine/eng_int.h
114 @@ -198,23 +198,15 @@ struct engine_st {
115 ENGINE_LOAD_KEY_PTR load_privkey;
116 ENGINE_LOAD_KEY_PTR load_pubkey;
117 ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
119 - * Instantiate Engine handle to be passed in check_pkc_availability
120 - * Ensure that Engine is instantiated before any pkc asynchronous call.
122 - void *(*engine_init_instance)(void);
124 - * Instantiated Engine handle will be closed with this call.
125 - * Ensure that no pkc asynchronous call is made after this call
127 - void (*engine_close_instance)(void *handle);
128 + int (*engine_open_instance)(void);
129 + int (*engine_close_instance)(int fd);
131 * Check availability will extract the data from kernel.
132 * eng_handle: This is the Engine handle corresponds to which
133 * the cookies needs to be polled.
134 * return 0 if cookie available else 1
136 - int (*check_pkc_availability)(void *eng_handle);
137 + int (*check_pkc_availability)(int fd);
139 * The following map is used to check if the engine supports asynchronous implementation
140 * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous
141 diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
142 index 0c57e12..4fdcfd6 100644
143 --- a/crypto/engine/eng_lib.c
144 +++ b/crypto/engine/eng_lib.c
145 @@ -101,7 +101,7 @@ void engine_set_all_null(ENGINE *e)
146 e->load_privkey = NULL;
147 e->load_pubkey = NULL;
148 e->check_pkc_availability = NULL;
149 - e->engine_init_instance = NULL;
150 + e->engine_open_instance = NULL;
151 e->engine_close_instance = NULL;
154 @@ -252,46 +252,45 @@ int ENGINE_set_id(ENGINE *e, const char *id)
158 -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void))
160 - e->engine_init_instance = engine_init_instance;
162 +void ENGINE_set_open_instance(ENGINE *e, int (*engine_open_instance)(void))
164 + e->engine_open_instance = engine_open_instance;
167 -void ENGINE_set_close_instance(ENGINE *e,
168 - void (*engine_close_instance)(void *))
170 - e->engine_close_instance = engine_close_instance;
172 +void ENGINE_set_close_instance(ENGINE *e, int (*engine_close_instance)(int))
174 + e->engine_close_instance = engine_close_instance;
177 void ENGINE_set_async_map(ENGINE *e, int async_map)
179 e->async_map = async_map;
182 -void *ENGINE_init_instance(ENGINE *e)
184 - return e->engine_init_instance();
187 -void ENGINE_close_instance(ENGINE *e, void *eng_handle)
189 - e->engine_close_instance(eng_handle);
192 int ENGINE_get_async_map(ENGINE *e)
197 +int ENGINE_open_instance(ENGINE *e)
199 + return e->engine_open_instance();
202 +int ENGINE_close_instance(ENGINE *e, int fd)
204 + return e->engine_close_instance(fd);
207 void ENGINE_set_check_pkc_availability(ENGINE *e,
208 - int (*check_pkc_availability)(void *eng_handle))
210 - e->check_pkc_availability = check_pkc_availability;
212 + int (*check_pkc_availability)(int fd))
214 + e->check_pkc_availability = check_pkc_availability;
217 -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle)
219 - return e->check_pkc_availability(eng_handle);
220 +int ENGINE_check_pkc_availability(ENGINE *e, int fd)
222 + return e->check_pkc_availability(fd);
225 int ENGINE_set_name(ENGINE *e, const char *name)
226 diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h
227 index 4527aa1..f83ee73 100644
228 --- a/crypto/engine/engine.h
229 +++ b/crypto/engine/engine.h
230 @@ -551,9 +551,6 @@ ENGINE *ENGINE_new(void);
231 int ENGINE_free(ENGINE *e);
232 int ENGINE_up_ref(ENGINE *e);
233 int ENGINE_set_id(ENGINE *e, const char *id);
234 -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void));
235 -void ENGINE_set_close_instance(ENGINE *e,
236 - void (*engine_free_instance)(void *));
238 * Following FLAGS are bitmap store in async_map to set asynchronous interface capability
240 @@ -570,11 +567,13 @@ void ENGINE_set_async_map(ENGINE *e, int async_map);
241 * to confirm asynchronous methods supported
243 int ENGINE_get_async_map(ENGINE *e);
244 -void *ENGINE_init_instance(ENGINE *e);
245 -void ENGINE_close_instance(ENGINE *e, void *eng_handle);
246 +int ENGINE_open_instance(ENGINE *e);
247 +int ENGINE_close_instance(ENGINE *e, int fd);
248 +void ENGINE_set_init_instance(ENGINE *e, int(*engine_init_instance)(void));
249 +void ENGINE_set_close_instance(ENGINE *e, int(*engine_close_instance)(int));
250 void ENGINE_set_check_pkc_availability(ENGINE *e,
251 - int (*check_pkc_availability)(void *eng_handle));
252 -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle);
253 + int (*check_pkc_availability)(int fd));
254 +int ENGINE_check_pkc_availability(ENGINE *e, int fd);
255 int ENGINE_set_name(ENGINE *e, const char *name);
256 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
257 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);