diff options
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0092-Support-skcipher-in-addition-to-ablkcipher-API.patch')
| -rw-r--r-- | recipes-kernel/cryptodev/sdk_patches/0092-Support-skcipher-in-addition-to-ablkcipher-API.patch | 281 |
1 files changed, 281 insertions, 0 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0092-Support-skcipher-in-addition-to-ablkcipher-API.patch b/recipes-kernel/cryptodev/sdk_patches/0092-Support-skcipher-in-addition-to-ablkcipher-API.patch new file mode 100644 index 000000000..4a82955e5 --- /dev/null +++ b/recipes-kernel/cryptodev/sdk_patches/0092-Support-skcipher-in-addition-to-ablkcipher-API.patch | |||
| @@ -0,0 +1,281 @@ | |||
| 1 | From e41e73551c886366d741b5e401a3c4c661aa3020 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Michael Weiser <michael.weiser@gmx.de> | ||
| 3 | Date: Fri, 5 Aug 2016 17:26:27 +0200 | ||
| 4 | Subject: [PATCH 092/104] Support skcipher in addition to ablkcipher API | ||
| 5 | |||
| 6 | The ablkcipher API is being phased out[1]. The unified skcipher API | ||
| 7 | seems to have made its entry with 4.3.[3, 4] By what can be seen from | ||
| 8 | migration patches[1.ff.], it's a drop-in replacement. | ||
| 9 | |||
| 10 | Also, deallocators such as crypto_free_skcipher() are NULL-safe now[2]. | ||
| 11 | |||
| 12 | Add a new header cipherapi.h to aid migration from ablkcipher to skcipher and | ||
| 13 | retain support for old kernels. Make it decide which API to use and provide | ||
| 14 | appropriate function calls and type definitions. Since the ablkcipher and | ||
| 15 | skcipher APIs are so similar, those are mainly defines for corresponding | ||
| 16 | pseudo-functions in namespace cryptodev_ derived directly from their API | ||
| 17 | counterparts. | ||
| 18 | |||
| 19 | Compiles and works (i.e. checks pass) with Debian testing 4.6.4 kernel | ||
| 20 | as well as 4.8-rc2+ Linus git tree as of today. (Both require a fix for | ||
| 21 | changed page access API[5].) | ||
| 22 | |||
| 23 | [1] https://www.spinics.net/lists/linux-crypto/msg18133.html | ||
| 24 | [2] https://www.spinics.net/lists/linux-crypto/msg18154.html, line 120 | ||
| 25 | [3] https://www.spinics.net/lists/linux-crypto/msg16373.html | ||
| 26 | [4] https://www.spinics.net/lists/linux-crypto/msg16294.html | ||
| 27 | [5] https://github.com/cryptodev-linux/cryptodev-linux/pull/14 | ||
| 28 | --- | ||
| 29 | cipherapi.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 30 | cryptlib.c | 40 ++++++++++++++++++---------------------- | ||
| 31 | cryptlib.h | 6 ++++-- | ||
| 32 | ioctl.c | 4 ++-- | ||
| 33 | 4 files changed, 84 insertions(+), 26 deletions(-) | ||
| 34 | create mode 100644 cipherapi.h | ||
| 35 | |||
| 36 | diff --git a/cipherapi.h b/cipherapi.h | ||
| 37 | new file mode 100644 | ||
| 38 | index 0000000..07d9923 | ||
| 39 | --- /dev/null | ||
| 40 | +++ b/cipherapi.h | ||
| 41 | @@ -0,0 +1,60 @@ | ||
| 42 | +#ifndef CIPHERAPI_H | ||
| 43 | +# define CIPHERAPI_H | ||
| 44 | + | ||
| 45 | +#include <linux/version.h> | ||
| 46 | + | ||
| 47 | +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)) | ||
| 48 | +# include <linux/crypto.h> | ||
| 49 | + | ||
| 50 | +typedef struct ablkcipher_alg cryptodev_blkcipher_alg_t; | ||
| 51 | +typedef struct crypto_ablkcipher cryptodev_crypto_blkcipher_t; | ||
| 52 | +typedef struct ablkcipher_request cryptodev_blkcipher_request_t; | ||
| 53 | + | ||
| 54 | +# define cryptodev_crypto_alloc_blkcipher crypto_alloc_ablkcipher | ||
| 55 | +# define cryptodev_crypto_blkcipher_alg crypto_ablkcipher_alg | ||
| 56 | +# define cryptodev_crypto_blkcipher_blocksize crypto_ablkcipher_blocksize | ||
| 57 | +# define cryptodev_crypto_blkcipher_ivsize crypto_ablkcipher_ivsize | ||
| 58 | +# define cryptodev_crypto_blkcipher_alignmask crypto_ablkcipher_alignmask | ||
| 59 | +# define cryptodev_crypto_blkcipher_setkey crypto_ablkcipher_setkey | ||
| 60 | + | ||
| 61 | +static inline void cryptodev_crypto_free_blkcipher(cryptodev_crypto_blkcipher_t *c) { | ||
| 62 | + if (c) | ||
| 63 | + crypto_free_ablkcipher(c); | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +# define cryptodev_blkcipher_request_alloc ablkcipher_request_alloc | ||
| 67 | +# define cryptodev_blkcipher_request_set_callback ablkcipher_request_set_callback | ||
| 68 | + | ||
| 69 | +static inline void cryptodev_blkcipher_request_free(cryptodev_blkcipher_request_t *r) { | ||
| 70 | + if (r) | ||
| 71 | + ablkcipher_request_free(r); | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +# define cryptodev_blkcipher_request_set_crypt ablkcipher_request_set_crypt | ||
| 75 | +# define cryptodev_crypto_blkcipher_encrypt crypto_ablkcipher_encrypt | ||
| 76 | +# define cryptodev_crypto_blkcipher_decrypt crypto_ablkcipher_decrypt | ||
| 77 | +# define cryptodev_crypto_blkcipher_tfm crypto_ablkcipher_tfm | ||
| 78 | +#else | ||
| 79 | +#include <crypto/skcipher.h> | ||
| 80 | + | ||
| 81 | +typedef struct skcipher_alg cryptodev_blkcipher_alg_t; | ||
| 82 | +typedef struct crypto_skcipher cryptodev_crypto_blkcipher_t; | ||
| 83 | +typedef struct skcipher_request cryptodev_blkcipher_request_t; | ||
| 84 | + | ||
| 85 | +# define cryptodev_crypto_alloc_blkcipher crypto_alloc_skcipher | ||
| 86 | +# define cryptodev_crypto_blkcipher_alg crypto_skcipher_alg | ||
| 87 | +# define cryptodev_crypto_blkcipher_blocksize crypto_skcipher_blocksize | ||
| 88 | +# define cryptodev_crypto_blkcipher_ivsize crypto_skcipher_ivsize | ||
| 89 | +# define cryptodev_crypto_blkcipher_alignmask crypto_skcipher_alignmask | ||
| 90 | +# define cryptodev_crypto_blkcipher_setkey crypto_skcipher_setkey | ||
| 91 | +# define cryptodev_crypto_free_blkcipher crypto_free_skcipher | ||
| 92 | +# define cryptodev_blkcipher_request_alloc skcipher_request_alloc | ||
| 93 | +# define cryptodev_blkcipher_request_set_callback skcipher_request_set_callback | ||
| 94 | +# define cryptodev_blkcipher_request_free skcipher_request_free | ||
| 95 | +# define cryptodev_blkcipher_request_set_crypt skcipher_request_set_crypt | ||
| 96 | +# define cryptodev_crypto_blkcipher_encrypt crypto_skcipher_encrypt | ||
| 97 | +# define cryptodev_crypto_blkcipher_decrypt crypto_skcipher_decrypt | ||
| 98 | +# define cryptodev_crypto_blkcipher_tfm crypto_skcipher_tfm | ||
| 99 | +#endif | ||
| 100 | + | ||
| 101 | +#endif | ||
| 102 | diff --git a/cryptlib.c b/cryptlib.c | ||
| 103 | index 5d1a5a9..558d4b8 100644 | ||
| 104 | --- a/cryptlib.c | ||
| 105 | +++ b/cryptlib.c | ||
| 106 | @@ -24,7 +24,6 @@ | ||
| 107 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 108 | */ | ||
| 109 | |||
| 110 | -#include <linux/crypto.h> | ||
| 111 | #include <linux/mm.h> | ||
| 112 | #include <linux/highmem.h> | ||
| 113 | #include <linux/ioctl.h> | ||
| 114 | @@ -38,6 +37,7 @@ | ||
| 115 | #include <linux/rtnetlink.h> | ||
| 116 | #include <crypto/authenc.h> | ||
| 117 | #include "cryptodev_int.h" | ||
| 118 | +#include "cipherapi.h" | ||
| 119 | |||
| 120 | |||
| 121 | static void cryptodev_complete(struct crypto_async_request *req, int err) | ||
| 122 | @@ -129,15 +129,15 @@ int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name, | ||
| 123 | int ret; | ||
| 124 | |||
| 125 | if (aead == 0) { | ||
| 126 | - struct ablkcipher_alg *alg; | ||
| 127 | + cryptodev_blkcipher_alg_t *alg; | ||
| 128 | |||
| 129 | - out->async.s = crypto_alloc_ablkcipher(alg_name, 0, 0); | ||
| 130 | + out->async.s = cryptodev_crypto_alloc_blkcipher(alg_name, 0, 0); | ||
| 131 | if (unlikely(IS_ERR(out->async.s))) { | ||
| 132 | ddebug(1, "Failed to load cipher %s", alg_name); | ||
| 133 | return -EINVAL; | ||
| 134 | } | ||
| 135 | |||
| 136 | - alg = crypto_ablkcipher_alg(out->async.s); | ||
| 137 | + alg = cryptodev_crypto_blkcipher_alg(out->async.s); | ||
| 138 | if (alg != NULL) { | ||
| 139 | /* Was correct key length supplied? */ | ||
| 140 | if (alg->max_keysize > 0 && | ||
| 141 | @@ -150,11 +150,11 @@ int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name, | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | - out->blocksize = crypto_ablkcipher_blocksize(out->async.s); | ||
| 146 | - out->ivsize = crypto_ablkcipher_ivsize(out->async.s); | ||
| 147 | - out->alignmask = crypto_ablkcipher_alignmask(out->async.s); | ||
| 148 | + out->blocksize = cryptodev_crypto_blkcipher_blocksize(out->async.s); | ||
| 149 | + out->ivsize = cryptodev_crypto_blkcipher_ivsize(out->async.s); | ||
| 150 | + out->alignmask = cryptodev_crypto_blkcipher_alignmask(out->async.s); | ||
| 151 | |||
| 152 | - ret = crypto_ablkcipher_setkey(out->async.s, keyp, keylen); | ||
| 153 | + ret = cryptodev_crypto_blkcipher_setkey(out->async.s, keyp, keylen); | ||
| 154 | } else { | ||
| 155 | out->async.as = crypto_alloc_aead(alg_name, 0, 0); | ||
| 156 | if (unlikely(IS_ERR(out->async.as))) { | ||
| 157 | @@ -181,14 +181,14 @@ int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name, | ||
| 158 | init_completion(&out->async.result.completion); | ||
| 159 | |||
| 160 | if (aead == 0) { | ||
| 161 | - out->async.request = ablkcipher_request_alloc(out->async.s, GFP_KERNEL); | ||
| 162 | + out->async.request = cryptodev_blkcipher_request_alloc(out->async.s, GFP_KERNEL); | ||
| 163 | if (unlikely(!out->async.request)) { | ||
| 164 | derr(1, "error allocating async crypto request"); | ||
| 165 | ret = -ENOMEM; | ||
| 166 | goto error; | ||
| 167 | } | ||
| 168 | |||
| 169 | - ablkcipher_request_set_callback(out->async.request, 0, | ||
| 170 | + cryptodev_blkcipher_request_set_callback(out->async.request, 0, | ||
| 171 | cryptodev_complete, &out->async.result); | ||
| 172 | } else { | ||
| 173 | out->async.arequest = aead_request_alloc(out->async.as, GFP_KERNEL); | ||
| 174 | @@ -206,10 +206,8 @@ int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name, | ||
| 175 | return 0; | ||
| 176 | error: | ||
| 177 | if (aead == 0) { | ||
| 178 | - if (out->async.request) | ||
| 179 | - ablkcipher_request_free(out->async.request); | ||
| 180 | - if (out->async.s) | ||
| 181 | - crypto_free_ablkcipher(out->async.s); | ||
| 182 | + cryptodev_blkcipher_request_free(out->async.request); | ||
| 183 | + cryptodev_crypto_free_blkcipher(out->async.s); | ||
| 184 | } else { | ||
| 185 | if (out->async.arequest) | ||
| 186 | aead_request_free(out->async.arequest); | ||
| 187 | @@ -224,10 +222,8 @@ void cryptodev_cipher_deinit(struct cipher_data *cdata) | ||
| 188 | { | ||
| 189 | if (cdata->init) { | ||
| 190 | if (cdata->aead == 0) { | ||
| 191 | - if (cdata->async.request) | ||
| 192 | - ablkcipher_request_free(cdata->async.request); | ||
| 193 | - if (cdata->async.s) | ||
| 194 | - crypto_free_ablkcipher(cdata->async.s); | ||
| 195 | + cryptodev_blkcipher_request_free(cdata->async.request); | ||
| 196 | + cryptodev_crypto_free_blkcipher(cdata->async.s); | ||
| 197 | } else { | ||
| 198 | if (cdata->async.arequest) | ||
| 199 | aead_request_free(cdata->async.arequest); | ||
| 200 | @@ -274,10 +270,10 @@ ssize_t cryptodev_cipher_encrypt(struct cipher_data *cdata, | ||
| 201 | reinit_completion(&cdata->async.result.completion); | ||
| 202 | |||
| 203 | if (cdata->aead == 0) { | ||
| 204 | - ablkcipher_request_set_crypt(cdata->async.request, | ||
| 205 | + cryptodev_blkcipher_request_set_crypt(cdata->async.request, | ||
| 206 | (struct scatterlist *)src, dst, | ||
| 207 | len, cdata->async.iv); | ||
| 208 | - ret = crypto_ablkcipher_encrypt(cdata->async.request); | ||
| 209 | + ret = cryptodev_crypto_blkcipher_encrypt(cdata->async.request); | ||
| 210 | } else { | ||
| 211 | aead_request_set_crypt(cdata->async.arequest, | ||
| 212 | (struct scatterlist *)src, dst, | ||
| 213 | @@ -296,10 +292,10 @@ ssize_t cryptodev_cipher_decrypt(struct cipher_data *cdata, | ||
| 214 | |||
| 215 | reinit_completion(&cdata->async.result.completion); | ||
| 216 | if (cdata->aead == 0) { | ||
| 217 | - ablkcipher_request_set_crypt(cdata->async.request, | ||
| 218 | + cryptodev_blkcipher_request_set_crypt(cdata->async.request, | ||
| 219 | (struct scatterlist *)src, dst, | ||
| 220 | len, cdata->async.iv); | ||
| 221 | - ret = crypto_ablkcipher_decrypt(cdata->async.request); | ||
| 222 | + ret = cryptodev_crypto_blkcipher_decrypt(cdata->async.request); | ||
| 223 | } else { | ||
| 224 | aead_request_set_crypt(cdata->async.arequest, | ||
| 225 | (struct scatterlist *)src, dst, | ||
| 226 | diff --git a/cryptlib.h b/cryptlib.h | ||
| 227 | index d8e8046..8200a1d 100644 | ||
| 228 | --- a/cryptlib.h | ||
| 229 | +++ b/cryptlib.h | ||
| 230 | @@ -11,6 +11,8 @@ struct cryptodev_result { | ||
| 231 | int err; | ||
| 232 | }; | ||
| 233 | |||
| 234 | +#include "cipherapi.h" | ||
| 235 | + | ||
| 236 | struct cipher_data { | ||
| 237 | int init; /* 0 uninitialized */ | ||
| 238 | int blocksize; | ||
| 239 | @@ -20,8 +22,8 @@ struct cipher_data { | ||
| 240 | int alignmask; | ||
| 241 | struct { | ||
| 242 | /* block ciphers */ | ||
| 243 | - struct crypto_ablkcipher *s; | ||
| 244 | - struct ablkcipher_request *request; | ||
| 245 | + cryptodev_crypto_blkcipher_t *s; | ||
| 246 | + cryptodev_blkcipher_request_t *request; | ||
| 247 | |||
| 248 | /* AEAD ciphers */ | ||
| 249 | struct crypto_aead *as; | ||
| 250 | diff --git a/ioctl.c b/ioctl.c | ||
| 251 | index 2e2bdeb..e3b8af1 100644 | ||
| 252 | --- a/ioctl.c | ||
| 253 | +++ b/ioctl.c | ||
| 254 | @@ -35,7 +35,6 @@ | ||
| 255 | */ | ||
| 256 | |||
| 257 | #include <crypto/hash.h> | ||
| 258 | -#include <linux/crypto.h> | ||
| 259 | #include <linux/mm.h> | ||
| 260 | #include <linux/highmem.h> | ||
| 261 | #include <linux/ioctl.h> | ||
| 262 | @@ -54,6 +53,7 @@ | ||
| 263 | #include "cryptodev_int.h" | ||
| 264 | #include "zc.h" | ||
| 265 | #include "version.h" | ||
| 266 | +#include "cipherapi.h" | ||
| 267 | |||
| 268 | MODULE_AUTHOR("Nikos Mavrogiannopoulos <nmav@gnutls.org>"); | ||
| 269 | MODULE_DESCRIPTION("CryptoDev driver"); | ||
| 270 | @@ -1052,7 +1052,7 @@ static int get_session_info(struct fcrypt *fcr, struct session_info_op *siop) | ||
| 271 | |||
| 272 | if (ses_ptr->cdata.init) { | ||
| 273 | if (ses_ptr->cdata.aead == 0) | ||
| 274 | - tfm = crypto_ablkcipher_tfm(ses_ptr->cdata.async.s); | ||
| 275 | + tfm = cryptodev_crypto_blkcipher_tfm(ses_ptr->cdata.async.s); | ||
| 276 | else | ||
| 277 | tfm = crypto_aead_tfm(ses_ptr->cdata.async.as); | ||
| 278 | tfm_info_to_alg_info(&siop->cipher_info, tfm); | ||
| 279 | -- | ||
| 280 | 2.10.2 | ||
| 281 | |||
