added patch to make openssl digests operational.
[cryptodev-linux.git] / extras / openssl-digests.patch
blobc81bf7f63a62f8961e1ded3762d3a5485947c4b3
1 Index: ./crypto/engine/eng_cryptodev.c
2 ===================================================================
3 RCS file: /v/openssl/cvs/openssl/crypto/engine/eng_cryptodev.c,v
4 retrieving revision 1.23
5 diff -u -r1.23 eng_cryptodev.c
6 --- ./crypto/engine/eng_cryptodev.c 3 Mar 2010 15:30:42 -0000 1.23
7 +++ ./crypto/engine/eng_cryptodev.c 24 Feb 2012 23:41:51 -0000
8 @@ -79,8 +79,6 @@
9 unsigned char digest_res[HASH_MAX_LEN];
10 char *mac_data;
11 int mac_len;
13 - int copy;
14 #endif
17 @@ -200,6 +198,7 @@
19 if ((fd = open_dev_crypto()) == -1)
20 return (-1);
21 +#ifndef CRIOGET_NOT_NEEDED
22 if (ioctl(fd, CRIOGET, &retfd) == -1)
23 return (-1);
25 @@ -208,9 +207,19 @@
26 close(retfd);
27 return (-1);
29 +#else
30 + retfd = fd;
31 +#endif
32 return (retfd);
35 +static void put_dev_crypto(int fd)
37 +#ifndef CRIOGET_NOT_NEEDED
38 + close(fd);
39 +#endif
42 /* Caching version for asym operations */
43 static int
44 get_asym_dev_crypto(void)
45 @@ -252,7 +261,7 @@
46 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
47 nids[count++] = ciphers[i].nid;
49 - close(fd);
50 + put_dev_crypto(fd);
52 if (count > 0)
53 *cnids = nids;
54 @@ -291,7 +300,7 @@
55 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
56 nids[count++] = digests[i].nid;
58 - close(fd);
59 + put_dev_crypto(fd);
61 if (count > 0)
62 *cnids = nids;
63 @@ -436,7 +445,7 @@
64 sess->cipher = cipher;
66 if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) {
67 - close(state->d_fd);
68 + put_dev_crypto(state->d_fd);
69 state->d_fd = -1;
70 return (0);
72 @@ -473,7 +482,7 @@
73 } else {
74 ret = 1;
76 - close(state->d_fd);
77 + put_dev_crypto(state->d_fd);
78 state->d_fd = -1;
80 return (ret);
81 @@ -686,7 +695,7 @@
82 sess->mac = digest;
84 if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) {
85 - close(state->d_fd);
86 + put_dev_crypto(state->d_fd);
87 state->d_fd = -1;
88 printf("cryptodev_digest_init: Open session failed\n");
89 return (0);
90 @@ -758,14 +767,12 @@
91 if (! (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) ) {
92 /* if application doesn't support one buffer */
93 memset(&cryp, 0, sizeof(cryp));
95 cryp.ses = sess->ses;
96 cryp.flags = 0;
97 cryp.len = state->mac_len;
98 cryp.src = state->mac_data;
99 cryp.dst = NULL;
100 cryp.mac = (caddr_t)md;
102 if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
103 printf("cryptodev_digest_final: digest failed\n");
104 return (0);
105 @@ -786,6 +793,9 @@
106 struct dev_crypto_state *state = ctx->md_data;
107 struct session_op *sess = &state->d_sess;
109 + if (state == NULL)
110 + return 0;
112 if (state->d_fd < 0) {
113 printf("cryptodev_digest_cleanup: illegal input\n");
114 return (0);
115 @@ -797,16 +807,13 @@
116 state->mac_len = 0;
119 - if (state->copy)
120 - return 1;
122 if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) {
123 printf("cryptodev_digest_cleanup: failed to close session\n");
124 ret = 0;
125 } else {
126 ret = 1;
128 - close(state->d_fd);
129 + put_dev_crypto(state->d_fd);
130 state->d_fd = -1;
132 return (ret);
133 @@ -816,15 +823,39 @@
135 struct dev_crypto_state *fstate = from->md_data;
136 struct dev_crypto_state *dstate = to->md_data;
137 + struct session_op *sess;
138 + int digest;
140 - memcpy(dstate, fstate, sizeof(struct dev_crypto_state));
141 + if (dstate == NULL || fstate == NULL)
142 + return 1;
144 - if (fstate->mac_len != 0) {
145 - dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
146 - memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
147 + memcpy(dstate, fstate, sizeof(struct dev_crypto_state));
149 + sess = &dstate->d_sess;
151 + digest = digest_nid_to_cryptodev(to->digest->type);
153 + sess->mackey = dstate->dummy_mac_key;
154 + sess->mackeylen = digest_key_length(to->digest->type);
155 + sess->mac = digest;
157 + dstate->d_fd = get_dev_crypto();
159 + if (ioctl(dstate->d_fd, CIOCGSESSION, sess) < 0) {
160 + put_dev_crypto(dstate->d_fd);
161 + dstate->d_fd = -1;
162 + printf("cryptodev_digest_init: Open session failed\n");
163 + return (0);
166 - dstate->copy = 1;
167 + if (fstate->mac_len != 0) {
168 + if (fstate->mac_data != NULL)
170 + dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
171 + memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
172 + dstate->mac_len = fstate->mac_len;
176 return 1;
178 @@ -1347,11 +1378,11 @@
179 * find out what asymmetric crypto algorithms we support
181 if (ioctl(fd, CIOCASYMFEAT, &cryptodev_asymfeat) == -1) {
182 - close(fd);
183 + put_dev_crypto(fd);
184 ENGINE_free(engine);
185 return;
187 - close(fd);
188 + put_dev_crypto(fd);
190 if (!ENGINE_set_id(engine, "cryptodev") ||
191 !ENGINE_set_name(engine, "BSD cryptodev engine") ||