diff options
author | Cristian Stoica <cristian.stoica@nxp.com> | 2016-01-25 13:33:46 +0200 |
---|---|---|
committer | Zhenhua Luo <zhenhua.luo@nxp.com> | 2016-06-23 10:58:51 +0800 |
commit | 84cb2cc407cf85459fb463be2aabedd4f12ade77 (patch) | |
tree | 5bcdd8c2673052d6c3670b7ef9a48767a8f685b6 /recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch | |
parent | 4cc0cf8255a3726fe3f6cbbe1a877fe2fab7edc6 (diff) | |
download | meta-fsl-ppc-84cb2cc407cf85459fb463be2aabedd4f12ade77.tar.gz |
openssl-qoriq: upgrade to 1.0.2h plus fsl patches
upstream recipe extended with patches from fsl and CIOCHASH feature.
Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
Diffstat (limited to 'recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch')
-rw-r--r-- | recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch | 508 |
1 files changed, 267 insertions, 241 deletions
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch index ab2b7ea..d590789 100644 --- a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch +++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0002-eng_cryptodev-add-support-for-TLS-algorithms-offload.patch | |||
@@ -1,7 +1,7 @@ | |||
1 | From dfd6ba263dc25ea2a4bbc32448b24ca2b1fc40e8 Mon Sep 17 00:00:00 2001 | 1 | From e7c630f8417b6f4e1bf2466e545ffe04af2eff00 Mon Sep 17 00:00:00 2001 |
2 | From: Cristian Stoica <cristian.stoica@freescale.com> | 2 | From: Cristian Stoica <cristian.stoica@freescale.com> |
3 | Date: Thu, 29 Aug 2013 16:51:18 +0300 | 3 | Date: Thu, 29 Aug 2013 16:51:18 +0300 |
4 | Subject: [PATCH 02/26] eng_cryptodev: add support for TLS algorithms offload | 4 | Subject: [PATCH 02/48] eng_cryptodev: add support for TLS algorithms offload |
5 | 5 | ||
6 | - aes-128-cbc-hmac-sha1 | 6 | - aes-128-cbc-hmac-sha1 |
7 | - aes-256-cbc-hmac-sha1 | 7 | - aes-256-cbc-hmac-sha1 |
@@ -9,309 +9,335 @@ Subject: [PATCH 02/26] eng_cryptodev: add support for TLS algorithms offload | |||
9 | Requires TLS patches on cryptodev and TLS algorithm support in Linux | 9 | Requires TLS patches on cryptodev and TLS algorithm support in Linux |
10 | kernel driver. | 10 | kernel driver. |
11 | 11 | ||
12 | Change-Id: I43048caa348414daddd6c1a5cdc55e769ac1945f | ||
13 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> | 12 | Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> |
14 | Reviewed-on: http://git.am.freescale.net:8181/17223 | ||
15 | --- | 13 | --- |
16 | crypto/engine/eng_cryptodev.c | 222 +++++++++++++++++++++++++++++++++++++++--- | 14 | crypto/engine/eng_cryptodev.c | 226 ++++++++++++++++++++++++++++++++++++++++-- |
17 | 1 file changed, 211 insertions(+), 11 deletions(-) | 15 | 1 file changed, 215 insertions(+), 11 deletions(-) |
18 | 16 | ||
19 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c | 17 | diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c |
20 | index 5a715ac..7588a28 100644 | 18 | index 8fb9c33..4d783d4 100644 |
21 | --- a/crypto/engine/eng_cryptodev.c | 19 | --- a/crypto/engine/eng_cryptodev.c |
22 | +++ b/crypto/engine/eng_cryptodev.c | 20 | +++ b/crypto/engine/eng_cryptodev.c |
23 | @@ -72,6 +72,9 @@ ENGINE_load_cryptodev(void) | 21 | @@ -71,6 +71,9 @@ void ENGINE_load_cryptodev(void) |
24 | struct dev_crypto_state { | 22 | struct dev_crypto_state { |
25 | struct session_op d_sess; | 23 | struct session_op d_sess; |
26 | int d_fd; | 24 | int d_fd; |
27 | + unsigned char *aad; | 25 | + unsigned char *aad; |
28 | + unsigned int aad_len; | 26 | + unsigned int aad_len; |
29 | + unsigned int len; | 27 | + unsigned int len; |
30 | 28 | # ifdef USE_CRYPTODEV_DIGESTS | |
31 | #ifdef USE_CRYPTODEV_DIGESTS | 29 | char dummy_mac_key[HASH_MAX_LEN]; |
32 | char dummy_mac_key[HASH_MAX_LEN]; | 30 | unsigned char digest_res[HASH_MAX_LEN]; |
33 | @@ -140,17 +143,20 @@ static struct { | 31 | @@ -141,24 +144,25 @@ static struct { |
34 | int nid; | 32 | int nid; |
35 | int ivmax; | 33 | int ivmax; |
36 | int keylen; | 34 | int keylen; |
37 | + int mackeylen; | 35 | + int mackeylen; |
38 | } ciphers[] = { | 36 | } ciphers[] = { |
39 | - { CRYPTO_ARC4, NID_rc4, 0, 16, }, | 37 | { |
40 | - { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, }, | 38 | - CRYPTO_ARC4, NID_rc4, 0, 16, |
41 | - { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, }, | 39 | + CRYPTO_ARC4, NID_rc4, 0, 16, 0 |
42 | - { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, }, | 40 | }, |
43 | - { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, }, | 41 | { |
44 | - { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, }, | 42 | - CRYPTO_DES_CBC, NID_des_cbc, 8, 8, |
45 | - { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, }, | 43 | + CRYPTO_DES_CBC, NID_des_cbc, 8, 8, 0 |
46 | - { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, }, | 44 | }, |
47 | - { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, }, | 45 | { |
48 | - { 0, NID_undef, 0, 0, }, | 46 | - CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, |
49 | + { CRYPTO_ARC4, NID_rc4, 0, 16, 0}, | 47 | + CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, 0 |
50 | + { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, 0}, | 48 | }, |
51 | + { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, 0}, | 49 | { |
52 | + { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, 0}, | 50 | - CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, |
53 | + { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, 0}, | 51 | + CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, 0 |
54 | + { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, 0}, | 52 | }, |
55 | + { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, 0}, | 53 | { |
56 | + { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, 0}, | 54 | - CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, |
57 | + { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0}, | 55 | + CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, 0 |
58 | + { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20}, | 56 | }, |
59 | + { CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20}, | 57 | { |
60 | + { 0, NID_undef, 0, 0, 0}, | 58 | - CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, |
59 | + CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, 0 | ||
60 | }, | ||
61 | # ifdef CRYPTO_AES_CTR | ||
62 | { | ||
63 | @@ -172,16 +176,22 @@ static struct { | ||
64 | }, | ||
65 | # endif | ||
66 | { | ||
67 | - CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, | ||
68 | + CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, 0 | ||
69 | }, | ||
70 | { | ||
71 | - CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, | ||
72 | + CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, 0 | ||
73 | }, | ||
74 | { | ||
75 | - CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, | ||
76 | + CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, 0 | ||
77 | }, | ||
78 | { | ||
79 | - 0, NID_undef, 0, 0, | ||
80 | + CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_128_cbc_hmac_sha1, 16, 16, 20 | ||
81 | + }, | ||
82 | + { | ||
83 | + CRYPTO_TLS10_AES_CBC_HMAC_SHA1, NID_aes_256_cbc_hmac_sha1, 16, 32, 20 | ||
84 | + }, | ||
85 | + { | ||
86 | + 0, NID_undef, 0, 0, 0 | ||
87 | }, | ||
61 | }; | 88 | }; |
62 | 89 | ||
63 | #ifdef USE_CRYPTODEV_DIGESTS | 90 | @@ -295,13 +305,15 @@ static int get_cryptodev_ciphers(const int **cnids) |
64 | @@ -250,13 +256,15 @@ get_cryptodev_ciphers(const int **cnids) | 91 | } |
65 | } | 92 | memset(&sess, 0, sizeof(sess)); |
66 | memset(&sess, 0, sizeof(sess)); | 93 | sess.key = (caddr_t) "123456789abcdefghijklmno"; |
67 | sess.key = (caddr_t)"123456789abcdefghijklmno"; | 94 | + sess.mackey = (caddr_t) "123456789ABCDEFGHIJKLMNO"; |
68 | + sess.mackey = (caddr_t)"123456789ABCDEFGHIJKLMNO"; | ||
69 | 95 | ||
70 | for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | 96 | for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { |
71 | if (ciphers[i].nid == NID_undef) | 97 | if (ciphers[i].nid == NID_undef) |
72 | continue; | 98 | continue; |
73 | sess.cipher = ciphers[i].id; | 99 | sess.cipher = ciphers[i].id; |
74 | sess.keylen = ciphers[i].keylen; | 100 | sess.keylen = ciphers[i].keylen; |
75 | - sess.mac = 0; | 101 | - sess.mac = 0; |
76 | + sess.mackeylen = ciphers[i].mackeylen; | 102 | + sess.mackeylen = ciphers[i].mackeylen; |
77 | + | 103 | + |
78 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && | 104 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && |
79 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) | 105 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) |
80 | nids[count++] = ciphers[i].nid; | 106 | nids[count++] = ciphers[i].nid; |
81 | @@ -414,6 +422,67 @@ cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 107 | @@ -457,6 +469,66 @@ cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
82 | return (1); | 108 | return (1); |
83 | } | 109 | } |
84 | 110 | ||
85 | + | ||
86 | +static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 111 | +static int cryptodev_aead_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
87 | + const unsigned char *in, size_t len) | 112 | + const unsigned char *in, size_t len) |
88 | +{ | 113 | +{ |
89 | + struct crypt_auth_op cryp; | 114 | + struct crypt_auth_op cryp; |
90 | + struct dev_crypto_state *state = ctx->cipher_data; | 115 | + struct dev_crypto_state *state = ctx->cipher_data; |
91 | + struct session_op *sess = &state->d_sess; | 116 | + struct session_op *sess = &state->d_sess; |
92 | + const void *iiv; | 117 | + const void *iiv; |
93 | + unsigned char save_iv[EVP_MAX_IV_LENGTH]; | 118 | + unsigned char save_iv[EVP_MAX_IV_LENGTH]; |
94 | + | 119 | + |
95 | + if (state->d_fd < 0) | 120 | + if (state->d_fd < 0) |
96 | + return (0); | 121 | + return (0); |
97 | + if (!len) | 122 | + if (!len) |
98 | + return (1); | 123 | + return (1); |
99 | + if ((len % ctx->cipher->block_size) != 0) | 124 | + if ((len % ctx->cipher->block_size) != 0) |
100 | + return (0); | 125 | + return (0); |
101 | + | 126 | + |
102 | + memset(&cryp, 0, sizeof(cryp)); | 127 | + memset(&cryp, 0, sizeof(cryp)); |
103 | + | 128 | + |
104 | + /* TODO: make a seamless integration with cryptodev flags */ | 129 | + /* TODO: make a seamless integration with cryptodev flags */ |
105 | + switch (ctx->cipher->nid) { | 130 | + switch (ctx->cipher->nid) { |
106 | + case NID_aes_128_cbc_hmac_sha1: | 131 | + case NID_aes_128_cbc_hmac_sha1: |
107 | + case NID_aes_256_cbc_hmac_sha1: | 132 | + case NID_aes_256_cbc_hmac_sha1: |
108 | + cryp.flags = COP_FLAG_AEAD_TLS_TYPE; | 133 | + cryp.flags = COP_FLAG_AEAD_TLS_TYPE; |
109 | + } | 134 | + } |
110 | + cryp.ses = sess->ses; | 135 | + cryp.ses = sess->ses; |
111 | + cryp.len = state->len; | 136 | + cryp.len = state->len; |
112 | + cryp.src = (caddr_t) in; | 137 | + cryp.src = (caddr_t) in; |
113 | + cryp.dst = (caddr_t) out; | 138 | + cryp.dst = (caddr_t) out; |
114 | + cryp.auth_src = state->aad; | 139 | + cryp.auth_src = state->aad; |
115 | + cryp.auth_len = state->aad_len; | 140 | + cryp.auth_len = state->aad_len; |
116 | + | 141 | + |
117 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | 142 | + cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; |
118 | + | 143 | + |
119 | + if (ctx->cipher->iv_len) { | 144 | + if (ctx->cipher->iv_len) { |
120 | + cryp.iv = (caddr_t) ctx->iv; | 145 | + cryp.iv = (caddr_t) ctx->iv; |
121 | + if (!ctx->encrypt) { | 146 | + if (!ctx->encrypt) { |
122 | + iiv = in + len - ctx->cipher->iv_len; | 147 | + iiv = in + len - ctx->cipher->iv_len; |
123 | + memcpy(save_iv, iiv, ctx->cipher->iv_len); | 148 | + memcpy(save_iv, iiv, ctx->cipher->iv_len); |
124 | + } | 149 | + } |
125 | + } else | 150 | + } else |
126 | + cryp.iv = NULL; | 151 | + cryp.iv = NULL; |
127 | + | 152 | + |
128 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { | 153 | + if (ioctl(state->d_fd, CIOCAUTHCRYPT, &cryp) == -1) { |
129 | + /* XXX need better errror handling | 154 | + /* |
130 | + * this can fail for a number of different reasons. | 155 | + * XXX need better errror handling this can fail for a number of |
131 | + */ | 156 | + * different reasons. |
132 | + return (0); | 157 | + */ |
133 | + } | 158 | + return (0); |
159 | + } | ||
134 | + | 160 | + |
135 | + if (ctx->cipher->iv_len) { | 161 | + if (ctx->cipher->iv_len) { |
136 | + if (ctx->encrypt) | 162 | + if (ctx->encrypt) |
137 | + iiv = out + len - ctx->cipher->iv_len; | 163 | + iiv = out + len - ctx->cipher->iv_len; |
138 | + else | 164 | + else |
139 | + iiv = save_iv; | 165 | + iiv = save_iv; |
140 | + memcpy(ctx->iv, iiv, ctx->cipher->iv_len); | 166 | + memcpy(ctx->iv, iiv, ctx->cipher->iv_len); |
141 | + } | 167 | + } |
142 | + return (1); | 168 | + return (1); |
143 | +} | 169 | +} |
144 | + | 170 | + |
145 | + | ||
146 | static int | 171 | static int |
147 | cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 172 | cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
148 | const unsigned char *iv, int enc) | 173 | const unsigned char *iv, int enc) |
149 | @@ -452,6 +521,45 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 174 | @@ -496,6 +568,45 @@ cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
150 | return (1); | ||
151 | } | 175 | } |
152 | 176 | ||
153 | +/* Save the encryption key provided by upper layers. | 177 | /* |
154 | + * | 178 | + * Save the encryption key provided by upper layers. This function is called |
155 | + * This function is called by EVP_CipherInit_ex to initialize the algorithm's | 179 | + * by EVP_CipherInit_ex to initialize the algorithm's extra data. We can't do |
156 | + * extra data. We can't do much here because the mac key is not available. | 180 | + * much here because the mac key is not available. The next call should/will |
157 | + * The next call should/will be to cryptodev_cbc_hmac_sha1_ctrl with parameter | 181 | + * be to cryptodev_cbc_hmac_sha1_ctrl with parameter |
158 | + * EVP_CTRL_AEAD_SET_MAC_KEY, to set the hmac key. There we call CIOCGSESSION | 182 | + * EVP_CTRL_AEAD_SET_MAC_KEY, to set the hmac key. There we call CIOCGSESSION |
159 | + * with both the crypto and hmac keys. | 183 | + * with both the crypto and hmac keys. |
160 | + */ | 184 | + */ |
161 | +static int cryptodev_init_aead_key(EVP_CIPHER_CTX *ctx, | 185 | +static int cryptodev_init_aead_key(EVP_CIPHER_CTX *ctx, |
162 | + const unsigned char *key, const unsigned char *iv, int enc) | 186 | + const unsigned char *key, |
187 | + const unsigned char *iv, int enc) | ||
163 | +{ | 188 | +{ |
164 | + struct dev_crypto_state *state = ctx->cipher_data; | 189 | + struct dev_crypto_state *state = ctx->cipher_data; |
165 | + struct session_op *sess = &state->d_sess; | 190 | + struct session_op *sess = &state->d_sess; |
166 | + int cipher = -1, i; | 191 | + int cipher = -1, i; |
167 | + | 192 | + |
168 | + for (i = 0; ciphers[i].id; i++) | 193 | + for (i = 0; ciphers[i].id; i++) |
169 | + if (ctx->cipher->nid == ciphers[i].nid && | 194 | + if (ctx->cipher->nid == ciphers[i].nid && |
170 | + ctx->cipher->iv_len <= ciphers[i].ivmax && | 195 | + ctx->cipher->iv_len <= ciphers[i].ivmax && |
171 | + ctx->key_len == ciphers[i].keylen) { | 196 | + ctx->key_len == ciphers[i].keylen) { |
172 | + cipher = ciphers[i].id; | 197 | + cipher = ciphers[i].id; |
173 | + break; | 198 | + break; |
174 | + } | 199 | + } |
175 | + | 200 | + |
176 | + if (!ciphers[i].id) { | 201 | + if (!ciphers[i].id) { |
177 | + state->d_fd = -1; | 202 | + state->d_fd = -1; |
178 | + return (0); | 203 | + return (0); |
179 | + } | 204 | + } |
180 | + | 205 | + |
181 | + memset(sess, 0, sizeof(struct session_op)); | 206 | + memset(sess, 0, sizeof(struct session_op)); |
182 | + | 207 | + |
183 | + sess->key = (caddr_t)key; | 208 | + sess->key = (caddr_t) key; |
184 | + sess->keylen = ctx->key_len; | 209 | + sess->keylen = ctx->key_len; |
185 | + sess->cipher = cipher; | 210 | + sess->cipher = cipher; |
186 | + | 211 | + |
187 | + /* for whatever reason, (1) means success */ | 212 | + /* for whatever reason, (1) means success */ |
188 | + return (1); | 213 | + return (1); |
189 | +} | 214 | +} |
190 | + | 215 | + |
191 | + | 216 | +/* |
192 | /* | ||
193 | * free anything we allocated earlier when initting a | 217 | * free anything we allocated earlier when initting a |
194 | * session, and close the session. | 218 | * session, and close the session. |
195 | @@ -488,6 +596,63 @@ cryptodev_cleanup(EVP_CIPHER_CTX *ctx) | 219 | */ |
196 | return (ret); | 220 | @@ -529,6 +640,63 @@ static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx) |
221 | return (ret); | ||
197 | } | 222 | } |
198 | 223 | ||
199 | +static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, | 224 | +static int cryptodev_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, |
200 | + void *ptr) | 225 | + int arg, void *ptr) |
201 | +{ | 226 | +{ |
202 | + switch (type) { | 227 | + switch (type) { |
203 | + case EVP_CTRL_AEAD_SET_MAC_KEY: | 228 | + case EVP_CTRL_AEAD_SET_MAC_KEY: |
204 | + { | 229 | + { |
205 | + /* TODO: what happens with hmac keys larger than 64 bytes? */ | 230 | + /* TODO: what happens with hmac keys larger than 64 bytes? */ |
206 | + struct dev_crypto_state *state = ctx->cipher_data; | 231 | + struct dev_crypto_state *state = ctx->cipher_data; |
207 | + struct session_op *sess = &state->d_sess; | 232 | + struct session_op *sess = &state->d_sess; |
208 | + | 233 | + |
209 | + if ((state->d_fd = get_dev_crypto()) < 0) | 234 | + if ((state->d_fd = get_dev_crypto()) < 0) |
210 | + return (0); | 235 | + return (0); |
211 | + | 236 | + |
212 | + /* the rest should have been set in cryptodev_init_aead_key */ | 237 | + /* the rest should have been set in cryptodev_init_aead_key */ |
213 | + sess->mackey = ptr; | 238 | + sess->mackey = ptr; |
214 | + sess->mackeylen = arg; | 239 | + sess->mackeylen = arg; |
215 | + | 240 | + |
216 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { | 241 | + if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { |
217 | + put_dev_crypto(state->d_fd); | 242 | + put_dev_crypto(state->d_fd); |
218 | + state->d_fd = -1; | 243 | + state->d_fd = -1; |
219 | + return (0); | 244 | + return (0); |
220 | + } | 245 | + } |
221 | + return (1); | 246 | + return (1); |
222 | + } | 247 | + } |
223 | + case EVP_CTRL_AEAD_TLS1_AAD: | 248 | + case EVP_CTRL_AEAD_TLS1_AAD: |
224 | + { | 249 | + { |
225 | + /* ptr points to the associated data buffer of 13 bytes */ | 250 | + /* ptr points to the associated data buffer of 13 bytes */ |
226 | + struct dev_crypto_state *state = ctx->cipher_data; | 251 | + struct dev_crypto_state *state = ctx->cipher_data; |
227 | + unsigned char *p = ptr; | 252 | + unsigned char *p = ptr; |
228 | + unsigned int cryptlen = p[arg - 2] << 8 | p[arg - 1]; | 253 | + unsigned int cryptlen = p[arg - 2] << 8 | p[arg - 1]; |
229 | + unsigned int maclen, padlen; | 254 | + unsigned int maclen, padlen; |
230 | + unsigned int bs = ctx->cipher->block_size; | 255 | + unsigned int bs = ctx->cipher->block_size; |
231 | + | 256 | + |
232 | + state->aad = ptr; | 257 | + state->aad = ptr; |
233 | + state->aad_len = arg; | 258 | + state->aad_len = arg; |
234 | + state->len = cryptlen; | 259 | + state->len = cryptlen; |
235 | + | 260 | + |
236 | + /* TODO: this should be an extension of EVP_CIPHER struct */ | 261 | + /* TODO: this should be an extension of EVP_CIPHER struct */ |
237 | + switch (ctx->cipher->nid) { | 262 | + switch (ctx->cipher->nid) { |
238 | + case NID_aes_128_cbc_hmac_sha1: | 263 | + case NID_aes_128_cbc_hmac_sha1: |
239 | + case NID_aes_256_cbc_hmac_sha1: | 264 | + case NID_aes_256_cbc_hmac_sha1: |
240 | + maclen = SHA_DIGEST_LENGTH; | 265 | + maclen = SHA_DIGEST_LENGTH; |
241 | + } | 266 | + } |
242 | + | 267 | + |
243 | + /* space required for encryption (not only TLS padding) */ | 268 | + /* space required for encryption (not only TLS padding) */ |
244 | + padlen = maclen; | 269 | + padlen = maclen; |
245 | + if (ctx->encrypt) { | 270 | + if (ctx->encrypt) { |
246 | + cryptlen += maclen; | 271 | + cryptlen += maclen; |
247 | + padlen += bs - (cryptlen % bs); | 272 | + padlen += bs - (cryptlen % bs); |
248 | + } | 273 | + } |
249 | + return padlen; | 274 | + return padlen; |
250 | + } | 275 | + } |
251 | + default: | 276 | + default: |
252 | + return -1; | 277 | + return -1; |
253 | + } | 278 | + } |
254 | +} | 279 | +} |
255 | + | 280 | + |
256 | /* | 281 | /* |
257 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine | 282 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine |
258 | * gets called when libcrypto requests a cipher NID. | 283 | * gets called when libcrypto requests a cipher NID. |
259 | @@ -600,6 +765,33 @@ const EVP_CIPHER cryptodev_aes_256_cbc = { | 284 | @@ -641,6 +809,34 @@ const EVP_CIPHER cryptodev_aes_256_cbc = { |
260 | NULL | 285 | NULL |
261 | }; | 286 | }; |
262 | 287 | ||
263 | +const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1 = { | 288 | +const EVP_CIPHER cryptodev_aes_128_cbc_hmac_sha1 = { |
264 | + NID_aes_128_cbc_hmac_sha1, | 289 | + NID_aes_128_cbc_hmac_sha1, |
265 | + 16, 16, 16, | 290 | + 16, 16, 16, |
266 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | 291 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, |
267 | + cryptodev_init_aead_key, | 292 | + cryptodev_init_aead_key, |
268 | + cryptodev_aead_cipher, | 293 | + cryptodev_aead_cipher, |
269 | + cryptodev_cleanup, | 294 | + cryptodev_cleanup, |
270 | + sizeof(struct dev_crypto_state), | 295 | + sizeof(struct dev_crypto_state), |
271 | + EVP_CIPHER_set_asn1_iv, | 296 | + EVP_CIPHER_set_asn1_iv, |
272 | + EVP_CIPHER_get_asn1_iv, | 297 | + EVP_CIPHER_get_asn1_iv, |
273 | + cryptodev_cbc_hmac_sha1_ctrl, | 298 | + cryptodev_cbc_hmac_sha1_ctrl, |
274 | + NULL | 299 | + NULL |
275 | +}; | 300 | +}; |
276 | + | 301 | + |
277 | +const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { | 302 | +const EVP_CIPHER cryptodev_aes_256_cbc_hmac_sha1 = { |
278 | + NID_aes_256_cbc_hmac_sha1, | 303 | + NID_aes_256_cbc_hmac_sha1, |
279 | + 16, 32, 16, | 304 | + 16, 32, 16, |
280 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, | 305 | + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_AEAD_CIPHER, |
281 | + cryptodev_init_aead_key, | 306 | + cryptodev_init_aead_key, |
282 | + cryptodev_aead_cipher, | 307 | + cryptodev_aead_cipher, |
283 | + cryptodev_cleanup, | 308 | + cryptodev_cleanup, |
284 | + sizeof(struct dev_crypto_state), | 309 | + sizeof(struct dev_crypto_state), |
285 | + EVP_CIPHER_set_asn1_iv, | 310 | + EVP_CIPHER_set_asn1_iv, |
286 | + EVP_CIPHER_get_asn1_iv, | 311 | + EVP_CIPHER_get_asn1_iv, |
287 | + cryptodev_cbc_hmac_sha1_ctrl, | 312 | + cryptodev_cbc_hmac_sha1_ctrl, |
288 | + NULL | 313 | + NULL |
289 | +}; | 314 | +}; |
290 | /* | 315 | + |
291 | * Registered by the ENGINE when used to find out how to deal with | 316 | # ifdef CRYPTO_AES_CTR |
292 | * a particular NID in the ENGINE. this says what we'll do at the | 317 | const EVP_CIPHER cryptodev_aes_ctr = { |
293 | @@ -637,6 +829,12 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | 318 | NID_aes_128_ctr, |
294 | case NID_aes_256_cbc: | 319 | @@ -729,6 +925,12 @@ cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, |
295 | *cipher = &cryptodev_aes_256_cbc; | 320 | *cipher = &cryptodev_aes_ctr_256; |
296 | break; | 321 | break; |
297 | + case NID_aes_128_cbc_hmac_sha1: | 322 | # endif |
298 | + *cipher = &cryptodev_aes_128_cbc_hmac_sha1; | 323 | + case NID_aes_128_cbc_hmac_sha1: |
299 | + break; | 324 | + *cipher = &cryptodev_aes_128_cbc_hmac_sha1; |
300 | + case NID_aes_256_cbc_hmac_sha1: | 325 | + break; |
301 | + *cipher = &cryptodev_aes_256_cbc_hmac_sha1; | 326 | + case NID_aes_256_cbc_hmac_sha1: |
302 | + break; | 327 | + *cipher = &cryptodev_aes_256_cbc_hmac_sha1; |
303 | default: | 328 | + break; |
304 | *cipher = NULL; | 329 | default: |
305 | break; | 330 | *cipher = NULL; |
306 | @@ -1384,6 +1582,8 @@ ENGINE_load_cryptodev(void) | 331 | break; |
307 | } | 332 | @@ -1472,6 +1674,8 @@ void ENGINE_load_cryptodev(void) |
308 | put_dev_crypto(fd); | 333 | } |
334 | put_dev_crypto(fd); | ||
309 | 335 | ||
310 | + EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); | 336 | + EVP_add_cipher(&cryptodev_aes_128_cbc_hmac_sha1); |
311 | + EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); | 337 | + EVP_add_cipher(&cryptodev_aes_256_cbc_hmac_sha1); |
312 | if (!ENGINE_set_id(engine, "cryptodev") || | 338 | if (!ENGINE_set_id(engine, "cryptodev") || |
313 | !ENGINE_set_name(engine, "BSD cryptodev engine") || | 339 | !ENGINE_set_name(engine, "BSD cryptodev engine") || |
314 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || | 340 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || |
315 | -- | 341 | -- |
316 | 2.3.5 | 342 | 2.7.0 |
317 | 343 | ||