1 From 787539e7720c99785f6c664a7484842bba08f6ed 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 26/26] 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 Change-Id: Ief736d0776c7009dee002204fb1d4ce9d31c8787
10 Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
11 Reviewed-on: http://git.am.freescale.net:8181/34221
13 crypto/crypto.h | 2 +-
14 crypto/engine/eng_cryptodev.c | 35 +++-----------------------
15 crypto/engine/eng_int.h | 14 +++--------
16 crypto/engine/eng_lib.c | 57 +++++++++++++++++++++----------------------
17 crypto/engine/engine.h | 13 +++++-----
18 5 files changed, 42 insertions(+), 79 deletions(-)
20 diff --git a/crypto/crypto.h b/crypto/crypto.h
21 index ce12731..292427e 100644
24 @@ -618,7 +618,7 @@ struct pkc_cookie_s {
25 * -EINVAL: Parameters Invalid
27 void (*pkc_callback)(struct pkc_cookie_s *cookie, int status);
33 diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
34 index c9db27d..f173bde 100644
35 --- a/crypto/engine/eng_cryptodev.c
36 +++ b/crypto/engine/eng_cryptodev.c
37 @@ -1742,7 +1742,7 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen,
38 struct pkc_cookie_s *cookie = kop->cookie;
39 struct cryptodev_cookie_s *eng_cookie;
41 - fd = *(int *)cookie->eng_handle;
42 + fd = cookie->eng_handle;
44 eng_cookie = malloc(sizeof(struct cryptodev_cookie_s));
46 @@ -1802,38 +1802,11 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s)
50 -/* Close an opened instance of cryptodev engine */
51 -void cryptodev_close_instance(void *handle)
56 - fd = *(int *)handle;
62 -/* Create an instance of cryptodev for asynchronous interface */
63 -void *cryptodev_init_instance(void)
65 - int *fd = malloc(sizeof(int));
68 - if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) {
78 /* Return 0 on success and 1 on failure */
79 -int cryptodev_check_availability(void *eng_handle)
80 +int cryptodev_check_availability(int fd)
82 - int fd = *(int *)eng_handle;
83 struct pkc_cookie_list_s cookie_list;
84 struct pkc_cookie_s *cookie;
86 @@ -4540,8 +4513,8 @@ ENGINE_load_cryptodev(void)
89 ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability);
90 - ENGINE_set_close_instance(engine, cryptodev_close_instance);
91 - ENGINE_set_init_instance(engine, cryptodev_init_instance);
92 + ENGINE_set_close_instance(engine, put_dev_crypto);
93 + ENGINE_set_open_instance(engine, open_dev_crypto);
94 ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC);
97 diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h
98 index 8fc3077..8fb79c0 100644
99 --- a/crypto/engine/eng_int.h
100 +++ b/crypto/engine/eng_int.h
101 @@ -181,23 +181,15 @@ struct engine_st
102 ENGINE_LOAD_KEY_PTR load_pubkey;
104 ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
106 - * Instantiate Engine handle to be passed in check_pkc_availability
107 - * Ensure that Engine is instantiated before any pkc asynchronous call.
109 - void *(*engine_init_instance)(void);
111 - * Instantiated Engine handle will be closed with this call.
112 - * Ensure that no pkc asynchronous call is made after this call
114 - void (*engine_close_instance)(void *handle);
115 + int (*engine_open_instance)(void);
116 + int (*engine_close_instance)(int fd);
118 * Check availability will extract the data from kernel.
119 * eng_handle: This is the Engine handle corresponds to which
120 * the cookies needs to be polled.
121 * return 0 if cookie available else 1
123 - int (*check_pkc_availability)(void *eng_handle);
124 + int (*check_pkc_availability)(int fd);
126 * The following map is used to check if the engine supports asynchronous implementation
127 * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous
128 diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
129 index 6fa621c..6c9471b 100644
130 --- a/crypto/engine/eng_lib.c
131 +++ b/crypto/engine/eng_lib.c
132 @@ -99,7 +99,7 @@ void engine_set_all_null(ENGINE *e)
133 e->load_privkey = NULL;
134 e->load_pubkey = NULL;
135 e->check_pkc_availability = NULL;
136 - e->engine_init_instance = NULL;
137 + e->engine_open_instance = NULL;
138 e->engine_close_instance = NULL;
141 @@ -237,47 +237,46 @@ int ENGINE_set_id(ENGINE *e, const char *id)
145 -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void))
147 - e->engine_init_instance = engine_init_instance;
149 +void ENGINE_set_open_instance(ENGINE *e, int (*engine_open_instance)(void))
151 + e->engine_open_instance = engine_open_instance;
154 -void ENGINE_set_close_instance(ENGINE *e,
155 - void (*engine_close_instance)(void *))
157 - e->engine_close_instance = engine_close_instance;
159 +void ENGINE_set_close_instance(ENGINE *e, int (*engine_close_instance)(int))
161 + e->engine_close_instance = engine_close_instance;
164 void ENGINE_set_async_map(ENGINE *e, int async_map)
166 e->async_map = async_map;
169 -void *ENGINE_init_instance(ENGINE *e)
171 - return e->engine_init_instance();
174 -void ENGINE_close_instance(ENGINE *e, void *eng_handle)
176 - e->engine_close_instance(eng_handle);
179 int ENGINE_get_async_map(ENGINE *e)
184 -void ENGINE_set_check_pkc_availability(ENGINE *e,
185 - int (*check_pkc_availability)(void *eng_handle))
187 - e->check_pkc_availability = check_pkc_availability;
189 +int ENGINE_open_instance(ENGINE *e)
191 + return e->engine_open_instance();
194 -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle)
196 - return e->check_pkc_availability(eng_handle);
198 +int ENGINE_close_instance(ENGINE *e, int fd)
200 + return e->engine_close_instance(fd);
203 +void ENGINE_set_check_pkc_availability(ENGINE *e,
204 + int (*check_pkc_availability)(int fd))
206 + e->check_pkc_availability = check_pkc_availability;
209 +int ENGINE_check_pkc_availability(ENGINE *e, int fd)
211 + return e->check_pkc_availability(fd);
214 int ENGINE_set_name(ENGINE *e, const char *name)
216 diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h
217 index ccff86a..3ba3e97 100644
218 --- a/crypto/engine/engine.h
219 +++ b/crypto/engine/engine.h
220 @@ -473,9 +473,6 @@ ENGINE *ENGINE_new(void);
221 int ENGINE_free(ENGINE *e);
222 int ENGINE_up_ref(ENGINE *e);
223 int ENGINE_set_id(ENGINE *e, const char *id);
224 -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void));
225 -void ENGINE_set_close_instance(ENGINE *e,
226 - void (*engine_free_instance)(void *));
228 * Following FLAGS are bitmap store in async_map to set asynchronous interface capability
230 @@ -492,11 +489,13 @@ void ENGINE_set_async_map(ENGINE *e, int async_map);
231 * to confirm asynchronous methods supported
233 int ENGINE_get_async_map(ENGINE *e);
234 -void *ENGINE_init_instance(ENGINE *e);
235 -void ENGINE_close_instance(ENGINE *e, void *eng_handle);
236 +int ENGINE_open_instance(ENGINE *e);
237 +int ENGINE_close_instance(ENGINE *e, int fd);
238 +void ENGINE_set_init_instance(ENGINE *e, int(*engine_init_instance)(void));
239 +void ENGINE_set_close_instance(ENGINE *e, int(*engine_close_instance)(int));
240 void ENGINE_set_check_pkc_availability(ENGINE *e,
241 - int (*check_pkc_availability)(void *eng_handle));
242 -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle);
243 + int (*check_pkc_availability)(int fd));
244 +int ENGINE_check_pkc_availability(ENGINE *e, int fd);
245 int ENGINE_set_name(ENGINE *e, const char *name);
246 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
247 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);