]> code.ossystems Code Review - meta-freescale.git/blob
1043fbd49716940264214051803e3994cd48a7f3
[meta-freescale.git] /
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
5
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
8
9 Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
10 ---
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(-)
17
18 diff --git a/crypto/crypto.h b/crypto/crypto.h
19 index 2b4ec59..ddb9b69 100644
20 --- a/crypto/crypto.h
21 +++ b/crypto/crypto.h
22 @@ -668,7 +668,7 @@ struct pkc_cookie_s {
23            *            -EINVAL: Parameters Invalid
24            */
25         void (*pkc_callback)(struct pkc_cookie_s *cookie, int status);
26 -       void *eng_handle;
27 +       int eng_handle;
28  };
29  
30  #ifdef  __cplusplus
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)
36  
37  static int put_dev_crypto(int fd)
38  {
39 -#ifdef CRIOGET_NOT_NEEDED
40 -       return 0;
41 -#else
42 -       return close(fd);
43 +# ifdef CRIOGET_NOT_NEEDED
44 +    return 0;
45 +# else
46 +    return close(fd);
47  # endif
48  }
49  
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;
53  
54 -    fd = *(int *)cookie->eng_handle;
55 +    fd = cookie->eng_handle;
56  
57      eng_cookie = malloc(sizeof(struct cryptodev_cookie_s));
58      if (!eng_cookie)
59 @@ -1926,38 +1926,11 @@ cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen,
60      return (ret);
61  }
62  
63 -/* Close an opened instance of cryptodev engine */
64 -void cryptodev_close_instance(void *handle)
65 -{
66 -    int fd;
67 -
68 -    if (handle) {
69 -        fd = *(int *)handle;
70 -        close(fd);
71 -        free(handle);
72 -    }
73 -}
74 -
75 -/* Create an instance of cryptodev for asynchronous interface */
76 -void *cryptodev_init_instance(void)
77 -{
78 -    int *fd = malloc(sizeof(int));
79 -
80 -    if (fd) {
81 -        if ((*fd = open("/dev/crypto", O_RDWR, 0)) == -1) {
82 -            free(fd);
83 -            return NULL;
84 -        }
85 -    }
86 -    return fd;
87 -}
88 -
89  # include <poll.h>
90  
91  /* Return 0 on success and 1 on failure */
92 -int cryptodev_check_availability(void *eng_handle)
93 +int cryptodev_check_availability(int fd)
94  {
95 -    int fd = *(int *)eng_handle;
96      struct pkc_cookie_list_s cookie_list;
97      struct pkc_cookie_s *cookie;
98      int i;
99 @@ -4706,8 +4679,8 @@ void ENGINE_load_cryptodev(void)
100      }
101  
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);
108  
109      ENGINE_add(engine);
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;
118 -       /*
119 -        * Instantiate Engine handle to be passed in check_pkc_availability
120 -        * Ensure that Engine is instantiated before any pkc asynchronous call.
121 -        */
122 -       void *(*engine_init_instance)(void);
123 -       /*
124 -        * Instantiated Engine handle will be closed with this call.
125 -        * Ensure that no pkc asynchronous call is made after this call
126 -        */
127 -       void (*engine_close_instance)(void *handle);
128 +       int (*engine_open_instance)(void);
129 +       int (*engine_close_instance)(int fd);
130         /*
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
135          */
136 -       int (*check_pkc_availability)(void *eng_handle);
137 +       int (*check_pkc_availability)(int fd);
138         /*
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;
152      e->cmd_defns = NULL;
153         e->async_map = 0;
154 @@ -252,46 +252,45 @@ int ENGINE_set_id(ENGINE *e, const char *id)
155      return 1;
156         }
157  
158 -void ENGINE_set_init_instance(ENGINE *e, void *(*engine_init_instance)(void))
159 -       {
160 -               e->engine_init_instance = engine_init_instance;
161 -       }
162 +void ENGINE_set_open_instance(ENGINE *e, int (*engine_open_instance)(void))
163 +{
164 +       e->engine_open_instance = engine_open_instance;
165 +}
166  
167 -void ENGINE_set_close_instance(ENGINE *e,
168 -       void (*engine_close_instance)(void *))
169 -       {
170 -               e->engine_close_instance = engine_close_instance;
171 -       }
172 +void ENGINE_set_close_instance(ENGINE *e, int (*engine_close_instance)(int))
173 +{
174 +       e->engine_close_instance = engine_close_instance;
175 +}
176  
177  void ENGINE_set_async_map(ENGINE *e, int async_map)
178         {
179                 e->async_map = async_map;
180         }
181  
182 -void *ENGINE_init_instance(ENGINE *e)
183 -       {
184 -               return e->engine_init_instance();
185 -       }
186 -
187 -void ENGINE_close_instance(ENGINE *e, void *eng_handle)
188 -       {
189 -               e->engine_close_instance(eng_handle);
190 -       }
191 -
192  int ENGINE_get_async_map(ENGINE *e)
193         {
194                 return e->async_map;
195         }
196  
197 +int ENGINE_open_instance(ENGINE *e)
198 +{
199 +       return e->engine_open_instance();
200 +}
201 +
202 +int ENGINE_close_instance(ENGINE *e, int fd)
203 +{
204 +       return e->engine_close_instance(fd);
205 +}
206 +
207  void ENGINE_set_check_pkc_availability(ENGINE *e,
208 -       int (*check_pkc_availability)(void *eng_handle))
209 -       {
210 -               e->check_pkc_availability = check_pkc_availability;
211 -       }
212 +       int (*check_pkc_availability)(int fd))
213 +{
214 +       e->check_pkc_availability = check_pkc_availability;
215 +}
216  
217 -int ENGINE_check_pkc_availability(ENGINE *e, void *eng_handle)
218 -       {
219 -               return e->check_pkc_availability(eng_handle);
220 +int ENGINE_check_pkc_availability(ENGINE *e, int fd)
221 +{
222 +       return e->check_pkc_availability(fd);
223  }
224  
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 *));
237  /*
238   * Following FLAGS are bitmap store in async_map to set asynchronous interface capability
239   *of the engine
240 @@ -570,11 +567,13 @@ void ENGINE_set_async_map(ENGINE *e, int async_map);
241    * to confirm asynchronous methods supported
242    */
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);
258 -- 
259 2.7.0
260