aboutsummaryrefslogtreecommitdiffstats
path: root/meta-fsl-ppc/recipes-connectivity/openssl/openssl-fsl/0026-cryptodev-simplify-cryptodev-pkc-support-code.patch
blob: 6527ac8f32e20debbf9944eb4b75dc330d244f9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
From 787539e7720c99785f6c664a7484842bba08f6ed Mon Sep 17 00:00:00 2001
From: Cristian Stoica <cristian.stoica@freescale.com>
Date: Thu, 19 Feb 2015 13:39:52 +0200
Subject: [PATCH 26/26] cryptodev: simplify cryptodev pkc support code

- Engine init returns directly a file descriptor instead of a pointer to one
- Similarly, the Engine close will now just close the file

Change-Id: Ief736d0776c7009dee002204fb1d4ce9d31c8787
Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
Reviewed-on: http://git.am.freescale.net:8181/34221
---
 crypto/crypto.h               |  2 +-
 crypto/engine/eng_cryptodev.c | 35 +++-----------------------
 crypto/engine/eng_int.h       | 14 +++--------
 crypto/engine/eng_lib.c       | 57 +++++++++++++++++++++----------------------
 crypto/engine/engine.h        | 13 +++++-----
 5 files changed, 42 insertions(+), 79 deletions(-)

diff --git a/crypto/crypto.h b/crypto/crypto.h
index ce12731..292427e 100644
--- a/crypto/crypto.h
+++ b/crypto/crypto.h
@@ -618,7 +618,7 @@ struct pkc_cookie_s {
 	   *		-EINVAL: Parameters Invalid
 	   */
 	void (*pkc_callback)(struct pkc_cookie_s *cookie, int status);
-	void *eng_handle;
+	int eng_handle;
 };
 
 #ifdef  __cplusplus
diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
index c9db27d..f173bde 100644
--- a/crypto/engine/eng_cryptodev.c
+++ b/crypto/engine/eng_cryptodev.c
@@ -1742,7 +1742,7 @@ cryptodev_asym_async(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen,
 	struct pkc_cookie_s *cookie = kop->cookie;
 	struct cryptodev_cookie_s *eng_cookie;
 
-	fd = *(int *)cookie->eng_handle;
+	fd = cookie->eng_handle;
 
 	eng_cookie = malloc(sizeof(struct cryptodev_cookie_s));
 	if (!eng_cookie)
@@ -1802,38 +1802,11 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s)
 	return (ret);
 }
 
-/* Close an opened instance of cryptodev engine */
-void cryptodev_close_instance(void *handle)
-{
-	int fd;
-
-	if (handle) {
-		fd = *(int *)handle;
-		close(fd);
-		free(handle);
-	}
-}
-
-/* Create an instance of cryptodev for asynchronous interface */
-void *cryptodev_init_instance(void)
-{
-	int *fd = malloc(sizeof(int));
-
-	if (fd) {
-		if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) {
-			free(fd);
-			return NULL;
-		}
-	}
-	return fd;
-}
-
 #include <poll.h>
 
 /* Return 0 on success and 1 on failure */
-int cryptodev_check_availability(void *eng_handle)
+int cryptodev_check_availability(int fd)
 {
-	int fd = *(int *)eng_handle;
 	struct pkc_cookie_list_s cookie_list;
 	struct pkc_cookie_s *cookie;
 	int i;
@@ -4540,8 +4513,8 @@ ENGINE_load_cryptodev(void)
 	}
 
 	ENGINE_set_check_pkc_availability(engine, cryptodev_check_availability);
-	ENGINE_set_close_instance(engine, cryptodev_close_instance);
-	ENGINE_set_init_instance(engine, cryptodev_init_instance);
+	ENGINE_set_close_instance(engine, put_dev_crypto);
+	ENGINE_set_open_instance(engine, open_dev_crypto);
 	ENGINE_set_async_map(engine, ENGINE_ALLPKC_ASYNC);
 
 	ENGINE_add(engine);
diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h
index 8fc3077..8fb79c0 100644
--- a/crypto/engine/eng_int.h
+++ b/crypto/engine/eng_int.h
@@ -181,23 +181,15 @@ struct engine_st
 	ENGINE_LOAD_KEY_PTR load_pubkey;
 
 	ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
-	/*
-	 * Instantiate Engine handle to be passed in check_pkc_availability
-	 * Ensure that Engine is instantiated before any pkc asynchronous call.
-	 */
-	void *(*engine_init_instance)(void);
-	/*
-	 * Instantiated Engine handle will be closed with this call.
-	 * Ensure that no pkc asynchronous call is made after this call
-	 */
-	void (*engine_close_instance)(void *handle);
+	int (*engine_open_instance)(void);
+	int (*engine_close_instance)(int fd);
 	/*
 	 * Check availability will extract the data from kernel.
 	 * eng_handle: This is the Engine handle corresponds to which
 	 * the cookies needs to be polled.
 	 * return 0 if cookie available else 1
 	 */
-	int (*check_pkc_availability)(void *eng_handle);
+	int (*check_pkc_availability)(int fd);
 	/*
 	 * The following map is used to check if the engine supports asynchronous implementation
 	 * ENGINE_ASYNC_FLAG* for available bitmap. Any application checking for asynchronous
diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
index 6fa621c..6c9471b 100644
--- a/crypto/engine/eng_lib.c
+++ b/crypto/engine/eng_lib.c
@@ -99,7 +99,7 @@ void engine_set_all_null(ENGINE *e)
 	e->load_privkey = NULL;
 	e->load_pubkey = NULL;
 	e->check_pkc_availability = NULL;
-	e->engine_init_instance = NULL;
+	e->engine_open_instance = NULL;
 	e->engine_close_instance = NULL;
 	e->cmd_defns = NULL;
 	e->async_map = 0;
@@ -237,47 +237,46 @@ int ENGINE_set_id(ENGINE *e, const char *id)
 	return 1;
 	}
 
-void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void))
-	{
-		e->engine_init_instance = engine_init_instance;
-	}
+void ENGINE_set_open_instance(ENGINE *e, int (*engine_open_instance)(void))
+{
+	e->engine_open_instance = engine_open_instance;
+}
 
-void ENGINE_set_close_instance(ENGINE *e,
-	void (*engine_close_instance)(void *))
-	{
-		e->engine_close_instance = engine_close_instance;
-	}
+void ENGINE_set_close_instance(ENGINE *e, int (*engine_close_instance)(int))
+{
+	e->engine_close_instance = engine_close_instance;
+}
 
 void ENGINE_set_async_map(ENGINE *e, int async_map)
 	{
 		e->async_map = async_map;
 	}
 
-void *ENGINE_init_instance(ENGINE *e)
-	{
-		return e->engine_init_instance();
-	}
-
-void ENGINE_close_instance(ENGINE *e, void *eng_handle)
-	{
-		e->engine_close_instance(eng_handle);
-	}
-
 int ENGINE_get_async_map(ENGINE *e)
 	{
 		return e->async_map;
 	}
 
-void ENGINE_set_check_pkc_availability(ENGINE *e,
-	int (*check_pkc_availability)(void *eng_handle))
-	{
-		e->check_pkc_availability = check_pkc_availability;
-	}
+int ENGINE_open_instance(ENGINE *e)
+{
+	return e->engine_open_instance();
+}
 
-int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle)
-	{
-		return e->check_pkc_availability(eng_handle);
-	}
+int ENGINE_close_instance(ENGINE *e, int fd)
+{
+	return e->engine_close_instance(fd);
+}
+
+void ENGINE_set_check_pkc_availability(ENGINE *e,
+	int (*check_pkc_availability)(int fd))
+{
+	e->check_pkc_availability = check_pkc_availability;
+}
+
+int ENGINE_check_pkc_availability(ENGINE *e, int fd)
+{
+	return e->check_pkc_availability(fd);
+}
 
 int ENGINE_set_name(ENGINE *e, const char *name)
 	{
diff --git a/crypto/engine/engine.h b/crypto/engine/engine.h
index ccff86a..3ba3e97 100644
--- a/crypto/engine/engine.h
+++ b/crypto/engine/engine.h
@@ -473,9 +473,6 @@ ENGINE *ENGINE_new(void);
 int ENGINE_free(ENGINE *e);
 int ENGINE_up_ref(ENGINE *e);
 int ENGINE_set_id(ENGINE *e, const char *id);
-void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void));
-void ENGINE_set_close_instance(ENGINE *e,
-	void (*engine_free_instance)(void *));
 /*
  * Following FLAGS are bitmap store in async_map to set asynchronous interface capability
  *of the engine
@@ -492,11 +489,13 @@ void ENGINE_set_async_map(ENGINE *e, int async_map);
   * to confirm asynchronous methods supported
   */
 int ENGINE_get_async_map(ENGINE *e);
-void *ENGINE_init_instance(ENGINE *e);
-void ENGINE_close_instance(ENGINE *e, void *eng_handle);
+int ENGINE_open_instance(ENGINE *e);
+int ENGINE_close_instance(ENGINE *e, int fd);
+void ENGINE_set_init_instance(ENGINE *e, int(*engine_init_instance)(void));
+void ENGINE_set_close_instance(ENGINE *e, int(*engine_close_instance)(int));
 void ENGINE_set_check_pkc_availability(ENGINE *e,
-	int (*check_pkc_availability)(void *eng_handle));
-int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle);
+	int (*check_pkc_availability)(int fd));
+int ENGINE_check_pkc_availability(ENGINE *e, int fd);
 int ENGINE_set_name(ENGINE *e, const char *name);
 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
-- 
2.3.5