diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-23 00:04:48 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-23 00:04:48 -0400 |
| commit | 44d21c3f3a2ef2f58b18bda64c52c99e723f3f4a (patch) | |
| tree | 5146cf96cb0dbd7121176d484417ab942c92dcd4 /include | |
| parent | efdfce2b7ff3205ba0fba10270b92b80bbc6187d (diff) | |
| parent | fe55dfdcdfabf160ab0c14617725c57c7a1facfc (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto update from Herbert Xu:
"Here is the crypto update for 4.2:
API:
- Convert RNG interface to new style.
- New AEAD interface with one SG list for AD and plain/cipher text.
All external AEAD users have been converted.
- New asymmetric key interface (akcipher).
Algorithms:
- Chacha20, Poly1305 and RFC7539 support.
- New RSA implementation.
- Jitter RNG.
- DRBG is now seeded with both /dev/random and Jitter RNG. If kernel
pool isn't ready then DRBG will be reseeded when it is.
- DRBG is now the default crypto API RNG, replacing krng.
- 842 compression (previously part of powerpc nx driver).
Drivers:
- Accelerated SHA-512 for arm64.
- New Marvell CESA driver that supports DMA and more algorithms.
- Updated powerpc nx 842 support.
- Added support for SEC1 hardware to talitos"
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (292 commits)
crypto: marvell/cesa - remove COMPILE_TEST dependency
crypto: algif_aead - Temporarily disable all AEAD algorithms
crypto: af_alg - Forbid the use internal algorithms
crypto: echainiv - Only hold RNG during initialisation
crypto: seqiv - Add compatibility support without RNG
crypto: eseqiv - Offer normal cipher functionality without RNG
crypto: chainiv - Offer normal cipher functionality without RNG
crypto: user - Add CRYPTO_MSG_DELRNG
crypto: user - Move cryptouser.h to uapi
crypto: rng - Do not free default RNG when it becomes unused
crypto: skcipher - Allow givencrypt to be NULL
crypto: sahara - propagate the error on clk_disable_unprepare() failure
crypto: rsa - fix invalid select for AKCIPHER
crypto: picoxcell - Update to the current clk API
crypto: nx - Check for bogus firmware properties
crypto: marvell/cesa - add DT bindings documentation
crypto: marvell/cesa - add support for Kirkwood and Dove SoCs
crypto: marvell/cesa - add support for Orion SoCs
crypto: marvell/cesa - add allhwsupport module parameter
crypto: marvell/cesa - add support for all armada SoCs
...
Diffstat (limited to 'include')
| -rw-r--r-- | include/crypto/aead.h | 533 | ||||
| -rw-r--r-- | include/crypto/akcipher.h | 340 | ||||
| -rw-r--r-- | include/crypto/algapi.h | 35 | ||||
| -rw-r--r-- | include/crypto/compress.h | 8 | ||||
| -rw-r--r-- | include/crypto/cryptd.h | 1 | ||||
| -rw-r--r-- | include/crypto/drbg.h | 59 | ||||
| -rw-r--r-- | include/crypto/hash.h | 2 | ||||
| -rw-r--r-- | include/crypto/internal/aead.h | 102 | ||||
| -rw-r--r-- | include/crypto/internal/akcipher.h | 60 | ||||
| -rw-r--r-- | include/crypto/internal/geniv.h | 24 | ||||
| -rw-r--r-- | include/crypto/internal/rng.h | 21 | ||||
| -rw-r--r-- | include/crypto/internal/rsa.h | 27 | ||||
| -rw-r--r-- | include/crypto/md5.h | 5 | ||||
| -rw-r--r-- | include/crypto/null.h | 3 | ||||
| -rw-r--r-- | include/crypto/rng.h | 100 | ||||
| -rw-r--r-- | include/crypto/scatterwalk.h | 4 | ||||
| -rw-r--r-- | include/linux/crypto.h | 501 | ||||
| -rw-r--r-- | include/linux/mbus.h | 5 | ||||
| -rw-r--r-- | include/linux/module.h | 12 | ||||
| -rw-r--r-- | include/linux/mpi.h | 15 | ||||
| -rw-r--r-- | include/linux/nx842.h | 11 | ||||
| -rw-r--r-- | include/linux/random.h | 9 | ||||
| -rw-r--r-- | include/linux/scatterlist.h | 1 | ||||
| -rw-r--r-- | include/linux/sw842.h | 12 | ||||
| -rw-r--r-- | include/net/xfrm.h | 3 | ||||
| -rw-r--r-- | include/uapi/linux/cryptouser.h (renamed from include/linux/cryptouser.h) | 6 |
26 files changed, 1283 insertions, 616 deletions
diff --git a/include/crypto/aead.h b/include/crypto/aead.h index 94b19be67574..7169ad04acc0 100644 --- a/include/crypto/aead.h +++ b/include/crypto/aead.h | |||
| @@ -18,6 +18,65 @@ | |||
| 18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | * DOC: Authenticated Encryption With Associated Data (AEAD) Cipher API | ||
| 22 | * | ||
| 23 | * The AEAD cipher API is used with the ciphers of type CRYPTO_ALG_TYPE_AEAD | ||
| 24 | * (listed as type "aead" in /proc/crypto) | ||
| 25 | * | ||
| 26 | * The most prominent examples for this type of encryption is GCM and CCM. | ||
| 27 | * However, the kernel supports other types of AEAD ciphers which are defined | ||
| 28 | * with the following cipher string: | ||
| 29 | * | ||
| 30 | * authenc(keyed message digest, block cipher) | ||
| 31 | * | ||
| 32 | * For example: authenc(hmac(sha256), cbc(aes)) | ||
| 33 | * | ||
| 34 | * The example code provided for the asynchronous block cipher operation | ||
| 35 | * applies here as well. Naturally all *ablkcipher* symbols must be exchanged | ||
| 36 | * the *aead* pendants discussed in the following. In addition, for the AEAD | ||
| 37 | * operation, the aead_request_set_assoc function must be used to set the | ||
| 38 | * pointer to the associated data memory location before performing the | ||
| 39 | * encryption or decryption operation. In case of an encryption, the associated | ||
| 40 | * data memory is filled during the encryption operation. For decryption, the | ||
| 41 | * associated data memory must contain data that is used to verify the integrity | ||
| 42 | * of the decrypted data. Another deviation from the asynchronous block cipher | ||
| 43 | * operation is that the caller should explicitly check for -EBADMSG of the | ||
| 44 | * crypto_aead_decrypt. That error indicates an authentication error, i.e. | ||
| 45 | * a breach in the integrity of the message. In essence, that -EBADMSG error | ||
| 46 | * code is the key bonus an AEAD cipher has over "standard" block chaining | ||
| 47 | * modes. | ||
| 48 | */ | ||
| 49 | |||
| 50 | /** | ||
| 51 | * struct aead_request - AEAD request | ||
| 52 | * @base: Common attributes for async crypto requests | ||
| 53 | * @old: Boolean whether the old or new AEAD API is used | ||
| 54 | * @assoclen: Length in bytes of associated data for authentication | ||
| 55 | * @cryptlen: Length of data to be encrypted or decrypted | ||
| 56 | * @iv: Initialisation vector | ||
| 57 | * @assoc: Associated data | ||
| 58 | * @src: Source data | ||
| 59 | * @dst: Destination data | ||
| 60 | * @__ctx: Start of private context data | ||
| 61 | */ | ||
| 62 | struct aead_request { | ||
| 63 | struct crypto_async_request base; | ||
| 64 | |||
| 65 | bool old; | ||
| 66 | |||
| 67 | unsigned int assoclen; | ||
| 68 | unsigned int cryptlen; | ||
| 69 | |||
| 70 | u8 *iv; | ||
| 71 | |||
| 72 | struct scatterlist *assoc; | ||
| 73 | struct scatterlist *src; | ||
| 74 | struct scatterlist *dst; | ||
| 75 | |||
| 76 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
| 77 | }; | ||
| 78 | |||
| 79 | /** | ||
| 21 | * struct aead_givcrypt_request - AEAD request with IV generation | 80 | * struct aead_givcrypt_request - AEAD request with IV generation |
| 22 | * @seq: Sequence number for IV generation | 81 | * @seq: Sequence number for IV generation |
| 23 | * @giv: Space for generated IV | 82 | * @giv: Space for generated IV |
| @@ -30,6 +89,474 @@ struct aead_givcrypt_request { | |||
| 30 | struct aead_request areq; | 89 | struct aead_request areq; |
| 31 | }; | 90 | }; |
| 32 | 91 | ||
| 92 | /** | ||
| 93 | * struct aead_alg - AEAD cipher definition | ||
| 94 | * @maxauthsize: Set the maximum authentication tag size supported by the | ||
| 95 | * transformation. A transformation may support smaller tag sizes. | ||
| 96 | * As the authentication tag is a message digest to ensure the | ||
| 97 | * integrity of the encrypted data, a consumer typically wants the | ||
| 98 | * largest authentication tag possible as defined by this | ||
| 99 | * variable. | ||
| 100 | * @setauthsize: Set authentication size for the AEAD transformation. This | ||
| 101 | * function is used to specify the consumer requested size of the | ||
| 102 | * authentication tag to be either generated by the transformation | ||
| 103 | * during encryption or the size of the authentication tag to be | ||
| 104 | * supplied during the decryption operation. This function is also | ||
| 105 | * responsible for checking the authentication tag size for | ||
| 106 | * validity. | ||
| 107 | * @setkey: see struct ablkcipher_alg | ||
| 108 | * @encrypt: see struct ablkcipher_alg | ||
| 109 | * @decrypt: see struct ablkcipher_alg | ||
| 110 | * @geniv: see struct ablkcipher_alg | ||
| 111 | * @ivsize: see struct ablkcipher_alg | ||
| 112 | * @init: Initialize the cryptographic transformation object. This function | ||
| 113 | * is used to initialize the cryptographic transformation object. | ||
| 114 | * This function is called only once at the instantiation time, right | ||
| 115 | * after the transformation context was allocated. In case the | ||
| 116 | * cryptographic hardware has some special requirements which need to | ||
| 117 | * be handled by software, this function shall check for the precise | ||
| 118 | * requirement of the transformation and put any software fallbacks | ||
| 119 | * in place. | ||
| 120 | * @exit: Deinitialize the cryptographic transformation object. This is a | ||
| 121 | * counterpart to @init, used to remove various changes set in | ||
| 122 | * @init. | ||
| 123 | * | ||
| 124 | * All fields except @ivsize is mandatory and must be filled. | ||
| 125 | */ | ||
| 126 | struct aead_alg { | ||
| 127 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | ||
| 128 | unsigned int keylen); | ||
| 129 | int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize); | ||
| 130 | int (*encrypt)(struct aead_request *req); | ||
| 131 | int (*decrypt)(struct aead_request *req); | ||
| 132 | int (*init)(struct crypto_aead *tfm); | ||
| 133 | void (*exit)(struct crypto_aead *tfm); | ||
| 134 | |||
| 135 | const char *geniv; | ||
| 136 | |||
| 137 | unsigned int ivsize; | ||
| 138 | unsigned int maxauthsize; | ||
| 139 | |||
| 140 | struct crypto_alg base; | ||
| 141 | }; | ||
| 142 | |||
| 143 | struct crypto_aead { | ||
| 144 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | ||
| 145 | unsigned int keylen); | ||
| 146 | int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize); | ||
| 147 | int (*encrypt)(struct aead_request *req); | ||
| 148 | int (*decrypt)(struct aead_request *req); | ||
| 149 | int (*givencrypt)(struct aead_givcrypt_request *req); | ||
| 150 | int (*givdecrypt)(struct aead_givcrypt_request *req); | ||
| 151 | |||
| 152 | struct crypto_aead *child; | ||
| 153 | |||
| 154 | unsigned int authsize; | ||
| 155 | unsigned int reqsize; | ||
| 156 | |||
| 157 | struct crypto_tfm base; | ||
| 158 | }; | ||
| 159 | |||
| 160 | static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm) | ||
| 161 | { | ||
| 162 | return container_of(tfm, struct crypto_aead, base); | ||
| 163 | } | ||
| 164 | |||
| 165 | /** | ||
| 166 | * crypto_alloc_aead() - allocate AEAD cipher handle | ||
| 167 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
| 168 | * AEAD cipher | ||
| 169 | * @type: specifies the type of the cipher | ||
| 170 | * @mask: specifies the mask for the cipher | ||
| 171 | * | ||
| 172 | * Allocate a cipher handle for an AEAD. The returned struct | ||
| 173 | * crypto_aead is the cipher handle that is required for any subsequent | ||
| 174 | * API invocation for that AEAD. | ||
| 175 | * | ||
| 176 | * Return: allocated cipher handle in case of success; IS_ERR() is true in case | ||
| 177 | * of an error, PTR_ERR() returns the error code. | ||
| 178 | */ | ||
| 179 | struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask); | ||
| 180 | |||
| 181 | static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) | ||
| 182 | { | ||
| 183 | return &tfm->base; | ||
| 184 | } | ||
| 185 | |||
| 186 | /** | ||
| 187 | * crypto_free_aead() - zeroize and free aead handle | ||
| 188 | * @tfm: cipher handle to be freed | ||
| 189 | */ | ||
| 190 | static inline void crypto_free_aead(struct crypto_aead *tfm) | ||
| 191 | { | ||
| 192 | crypto_destroy_tfm(tfm, crypto_aead_tfm(tfm)); | ||
| 193 | } | ||
| 194 | |||
| 195 | static inline struct crypto_aead *crypto_aead_crt(struct crypto_aead *tfm) | ||
| 196 | { | ||
| 197 | return tfm; | ||
| 198 | } | ||
| 199 | |||
| 200 | static inline struct old_aead_alg *crypto_old_aead_alg(struct crypto_aead *tfm) | ||
| 201 | { | ||
| 202 | return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead; | ||
| 203 | } | ||
| 204 | |||
| 205 | static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm) | ||
| 206 | { | ||
| 207 | return container_of(crypto_aead_tfm(tfm)->__crt_alg, | ||
| 208 | struct aead_alg, base); | ||
| 209 | } | ||
| 210 | |||
| 211 | static inline unsigned int crypto_aead_alg_ivsize(struct aead_alg *alg) | ||
| 212 | { | ||
| 213 | return alg->base.cra_aead.encrypt ? alg->base.cra_aead.ivsize : | ||
| 214 | alg->ivsize; | ||
| 215 | } | ||
| 216 | |||
| 217 | /** | ||
| 218 | * crypto_aead_ivsize() - obtain IV size | ||
| 219 | * @tfm: cipher handle | ||
| 220 | * | ||
| 221 | * The size of the IV for the aead referenced by the cipher handle is | ||
| 222 | * returned. This IV size may be zero if the cipher does not need an IV. | ||
| 223 | * | ||
| 224 | * Return: IV size in bytes | ||
| 225 | */ | ||
| 226 | static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm) | ||
| 227 | { | ||
| 228 | return crypto_aead_alg_ivsize(crypto_aead_alg(tfm)); | ||
| 229 | } | ||
| 230 | |||
| 231 | /** | ||
| 232 | * crypto_aead_authsize() - obtain maximum authentication data size | ||
| 233 | * @tfm: cipher handle | ||
| 234 | * | ||
| 235 | * The maximum size of the authentication data for the AEAD cipher referenced | ||
| 236 | * by the AEAD cipher handle is returned. The authentication data size may be | ||
| 237 | * zero if the cipher implements a hard-coded maximum. | ||
| 238 | * | ||
| 239 | * The authentication data may also be known as "tag value". | ||
| 240 | * | ||
| 241 | * Return: authentication data size / tag size in bytes | ||
| 242 | */ | ||
| 243 | static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm) | ||
| 244 | { | ||
| 245 | return tfm->authsize; | ||
| 246 | } | ||
| 247 | |||
| 248 | /** | ||
| 249 | * crypto_aead_blocksize() - obtain block size of cipher | ||
| 250 | * @tfm: cipher handle | ||
| 251 | * | ||
| 252 | * The block size for the AEAD referenced with the cipher handle is returned. | ||
| 253 | * The caller may use that information to allocate appropriate memory for the | ||
| 254 | * data returned by the encryption or decryption operation | ||
| 255 | * | ||
| 256 | * Return: block size of cipher | ||
| 257 | */ | ||
| 258 | static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm) | ||
| 259 | { | ||
| 260 | return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm)); | ||
| 261 | } | ||
| 262 | |||
| 263 | static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm) | ||
| 264 | { | ||
| 265 | return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm)); | ||
| 266 | } | ||
| 267 | |||
| 268 | static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm) | ||
| 269 | { | ||
| 270 | return crypto_tfm_get_flags(crypto_aead_tfm(tfm)); | ||
| 271 | } | ||
| 272 | |||
| 273 | static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags) | ||
| 274 | { | ||
| 275 | crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags); | ||
| 276 | } | ||
| 277 | |||
| 278 | static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags) | ||
| 279 | { | ||
| 280 | crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags); | ||
| 281 | } | ||
| 282 | |||
| 283 | /** | ||
| 284 | * crypto_aead_setkey() - set key for cipher | ||
| 285 | * @tfm: cipher handle | ||
| 286 | * @key: buffer holding the key | ||
| 287 | * @keylen: length of the key in bytes | ||
| 288 | * | ||
| 289 | * The caller provided key is set for the AEAD referenced by the cipher | ||
| 290 | * handle. | ||
| 291 | * | ||
| 292 | * Note, the key length determines the cipher type. Many block ciphers implement | ||
| 293 | * different cipher modes depending on the key size, such as AES-128 vs AES-192 | ||
| 294 | * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128 | ||
| 295 | * is performed. | ||
| 296 | * | ||
| 297 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | ||
| 298 | */ | ||
| 299 | int crypto_aead_setkey(struct crypto_aead *tfm, | ||
| 300 | const u8 *key, unsigned int keylen); | ||
| 301 | |||
| 302 | /** | ||
| 303 | * crypto_aead_setauthsize() - set authentication data size | ||
| 304 | * @tfm: cipher handle | ||
| 305 | * @authsize: size of the authentication data / tag in bytes | ||
| 306 | * | ||
| 307 | * Set the authentication data size / tag size. AEAD requires an authentication | ||
| 308 | * tag (or MAC) in addition to the associated data. | ||
| 309 | * | ||
| 310 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | ||
| 311 | */ | ||
| 312 | int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); | ||
| 313 | |||
| 314 | static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) | ||
| 315 | { | ||
| 316 | return __crypto_aead_cast(req->base.tfm); | ||
| 317 | } | ||
| 318 | |||
| 319 | /** | ||
| 320 | * crypto_aead_encrypt() - encrypt plaintext | ||
| 321 | * @req: reference to the aead_request handle that holds all information | ||
| 322 | * needed to perform the cipher operation | ||
| 323 | * | ||
| 324 | * Encrypt plaintext data using the aead_request handle. That data structure | ||
| 325 | * and how it is filled with data is discussed with the aead_request_* | ||
| 326 | * functions. | ||
| 327 | * | ||
| 328 | * IMPORTANT NOTE The encryption operation creates the authentication data / | ||
| 329 | * tag. That data is concatenated with the created ciphertext. | ||
| 330 | * The ciphertext memory size is therefore the given number of | ||
| 331 | * block cipher blocks + the size defined by the | ||
| 332 | * crypto_aead_setauthsize invocation. The caller must ensure | ||
| 333 | * that sufficient memory is available for the ciphertext and | ||
| 334 | * the authentication tag. | ||
| 335 | * | ||
| 336 | * Return: 0 if the cipher operation was successful; < 0 if an error occurred | ||
| 337 | */ | ||
| 338 | static inline int crypto_aead_encrypt(struct aead_request *req) | ||
| 339 | { | ||
| 340 | return crypto_aead_reqtfm(req)->encrypt(req); | ||
| 341 | } | ||
| 342 | |||
| 343 | /** | ||
| 344 | * crypto_aead_decrypt() - decrypt ciphertext | ||
| 345 | * @req: reference to the ablkcipher_request handle that holds all information | ||
| 346 | * needed to perform the cipher operation | ||
| 347 | * | ||
| 348 | * Decrypt ciphertext data using the aead_request handle. That data structure | ||
| 349 | * and how it is filled with data is discussed with the aead_request_* | ||
| 350 | * functions. | ||
| 351 | * | ||
| 352 | * IMPORTANT NOTE The caller must concatenate the ciphertext followed by the | ||
| 353 | * authentication data / tag. That authentication data / tag | ||
| 354 | * must have the size defined by the crypto_aead_setauthsize | ||
| 355 | * invocation. | ||
| 356 | * | ||
| 357 | * | ||
| 358 | * Return: 0 if the cipher operation was successful; -EBADMSG: The AEAD | ||
| 359 | * cipher operation performs the authentication of the data during the | ||
| 360 | * decryption operation. Therefore, the function returns this error if | ||
| 361 | * the authentication of the ciphertext was unsuccessful (i.e. the | ||
| 362 | * integrity of the ciphertext or the associated data was violated); | ||
| 363 | * < 0 if an error occurred. | ||
| 364 | */ | ||
| 365 | static inline int crypto_aead_decrypt(struct aead_request *req) | ||
| 366 | { | ||
| 367 | if (req->cryptlen < crypto_aead_authsize(crypto_aead_reqtfm(req))) | ||
| 368 | return -EINVAL; | ||
| 369 | |||
| 370 | return crypto_aead_reqtfm(req)->decrypt(req); | ||
| 371 | } | ||
| 372 | |||
| 373 | /** | ||
| 374 | * DOC: Asynchronous AEAD Request Handle | ||
| 375 | * | ||
| 376 | * The aead_request data structure contains all pointers to data required for | ||
| 377 | * the AEAD cipher operation. This includes the cipher handle (which can be | ||
| 378 | * used by multiple aead_request instances), pointer to plaintext and | ||
| 379 | * ciphertext, asynchronous callback function, etc. It acts as a handle to the | ||
| 380 | * aead_request_* API calls in a similar way as AEAD handle to the | ||
| 381 | * crypto_aead_* API calls. | ||
| 382 | */ | ||
| 383 | |||
| 384 | /** | ||
| 385 | * crypto_aead_reqsize() - obtain size of the request data structure | ||
| 386 | * @tfm: cipher handle | ||
| 387 | * | ||
| 388 | * Return: number of bytes | ||
| 389 | */ | ||
| 390 | unsigned int crypto_aead_reqsize(struct crypto_aead *tfm); | ||
| 391 | |||
| 392 | /** | ||
| 393 | * aead_request_set_tfm() - update cipher handle reference in request | ||
| 394 | * @req: request handle to be modified | ||
| 395 | * @tfm: cipher handle that shall be added to the request handle | ||
| 396 | * | ||
| 397 | * Allow the caller to replace the existing aead handle in the request | ||
| 398 | * data structure with a different one. | ||
| 399 | */ | ||
| 400 | static inline void aead_request_set_tfm(struct aead_request *req, | ||
| 401 | struct crypto_aead *tfm) | ||
| 402 | { | ||
| 403 | req->base.tfm = crypto_aead_tfm(tfm->child); | ||
| 404 | } | ||
| 405 | |||
| 406 | /** | ||
| 407 | * aead_request_alloc() - allocate request data structure | ||
| 408 | * @tfm: cipher handle to be registered with the request | ||
| 409 | * @gfp: memory allocation flag that is handed to kmalloc by the API call. | ||
| 410 | * | ||
| 411 | * Allocate the request data structure that must be used with the AEAD | ||
| 412 | * encrypt and decrypt API calls. During the allocation, the provided aead | ||
| 413 | * handle is registered in the request data structure. | ||
| 414 | * | ||
| 415 | * Return: allocated request handle in case of success; IS_ERR() is true in case | ||
| 416 | * of an error, PTR_ERR() returns the error code. | ||
| 417 | */ | ||
| 418 | static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, | ||
| 419 | gfp_t gfp) | ||
| 420 | { | ||
| 421 | struct aead_request *req; | ||
| 422 | |||
| 423 | req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp); | ||
| 424 | |||
| 425 | if (likely(req)) | ||
| 426 | aead_request_set_tfm(req, tfm); | ||
| 427 | |||
| 428 | return req; | ||
| 429 | } | ||
| 430 | |||
| 431 | /** | ||
| 432 | * aead_request_free() - zeroize and free request data structure | ||
| 433 | * @req: request data structure cipher handle to be freed | ||
| 434 | */ | ||
| 435 | static inline void aead_request_free(struct aead_request *req) | ||
| 436 | { | ||
| 437 | kzfree(req); | ||
| 438 | } | ||
| 439 | |||
| 440 | /** | ||
| 441 | * aead_request_set_callback() - set asynchronous callback function | ||
| 442 | * @req: request handle | ||
| 443 | * @flags: specify zero or an ORing of the flags | ||
| 444 | * CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and | ||
| 445 | * increase the wait queue beyond the initial maximum size; | ||
| 446 | * CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep | ||
| 447 | * @compl: callback function pointer to be registered with the request handle | ||
| 448 | * @data: The data pointer refers to memory that is not used by the kernel | ||
| 449 | * crypto API, but provided to the callback function for it to use. Here, | ||
| 450 | * the caller can provide a reference to memory the callback function can | ||
| 451 | * operate on. As the callback function is invoked asynchronously to the | ||
| 452 | * related functionality, it may need to access data structures of the | ||
| 453 | * related functionality which can be referenced using this pointer. The | ||
| 454 | * callback function can access the memory via the "data" field in the | ||
| 455 | * crypto_async_request data structure provided to the callback function. | ||
| 456 | * | ||
| 457 | * Setting the callback function that is triggered once the cipher operation | ||
| 458 | * completes | ||
| 459 | * | ||
| 460 | * The callback function is registered with the aead_request handle and | ||
| 461 | * must comply with the following template | ||
| 462 | * | ||
| 463 | * void callback_function(struct crypto_async_request *req, int error) | ||
| 464 | */ | ||
| 465 | static inline void aead_request_set_callback(struct aead_request *req, | ||
| 466 | u32 flags, | ||
| 467 | crypto_completion_t compl, | ||
| 468 | void *data) | ||
| 469 | { | ||
| 470 | req->base.complete = compl; | ||
| 471 | req->base.data = data; | ||
| 472 | req->base.flags = flags; | ||
| 473 | } | ||
| 474 | |||
| 475 | /** | ||
| 476 | * aead_request_set_crypt - set data buffers | ||
| 477 | * @req: request handle | ||
| 478 | * @src: source scatter / gather list | ||
| 479 | * @dst: destination scatter / gather list | ||
| 480 | * @cryptlen: number of bytes to process from @src | ||
| 481 | * @iv: IV for the cipher operation which must comply with the IV size defined | ||
| 482 | * by crypto_aead_ivsize() | ||
| 483 | * | ||
| 484 | * Setting the source data and destination data scatter / gather lists which | ||
| 485 | * hold the associated data concatenated with the plaintext or ciphertext. See | ||
| 486 | * below for the authentication tag. | ||
| 487 | * | ||
| 488 | * For encryption, the source is treated as the plaintext and the | ||
| 489 | * destination is the ciphertext. For a decryption operation, the use is | ||
| 490 | * reversed - the source is the ciphertext and the destination is the plaintext. | ||
| 491 | * | ||
| 492 | * For both src/dst the layout is associated data, plain/cipher text, | ||
| 493 | * authentication tag. | ||
| 494 | * | ||
| 495 | * The content of the AD in the destination buffer after processing | ||
| 496 | * will either be untouched, or it will contain a copy of the AD | ||
| 497 | * from the source buffer. In order to ensure that it always has | ||
| 498 | * a copy of the AD, the user must copy the AD over either before | ||
| 499 | * or after processing. Of course this is not relevant if the user | ||
| 500 | * is doing in-place processing where src == dst. | ||
| 501 | * | ||
| 502 | * IMPORTANT NOTE AEAD requires an authentication tag (MAC). For decryption, | ||
| 503 | * the caller must concatenate the ciphertext followed by the | ||
| 504 | * authentication tag and provide the entire data stream to the | ||
| 505 | * decryption operation (i.e. the data length used for the | ||
| 506 | * initialization of the scatterlist and the data length for the | ||
| 507 | * decryption operation is identical). For encryption, however, | ||
| 508 | * the authentication tag is created while encrypting the data. | ||
| 509 | * The destination buffer must hold sufficient space for the | ||
| 510 | * ciphertext and the authentication tag while the encryption | ||
| 511 | * invocation must only point to the plaintext data size. The | ||
| 512 | * following code snippet illustrates the memory usage | ||
| 513 | * buffer = kmalloc(ptbuflen + (enc ? authsize : 0)); | ||
| 514 | * sg_init_one(&sg, buffer, ptbuflen + (enc ? authsize : 0)); | ||
| 515 | * aead_request_set_crypt(req, &sg, &sg, ptbuflen, iv); | ||
| 516 | */ | ||
| 517 | static inline void aead_request_set_crypt(struct aead_request *req, | ||
| 518 | struct scatterlist *src, | ||
| 519 | struct scatterlist *dst, | ||
| 520 | unsigned int cryptlen, u8 *iv) | ||
| 521 | { | ||
| 522 | req->src = src; | ||
| 523 | req->dst = dst; | ||
| 524 | req->cryptlen = cryptlen; | ||
| 525 | req->iv = iv; | ||
| 526 | } | ||
| 527 | |||
| 528 | /** | ||
| 529 | * aead_request_set_assoc() - set the associated data scatter / gather list | ||
| 530 | * @req: request handle | ||
| 531 | * @assoc: associated data scatter / gather list | ||
| 532 | * @assoclen: number of bytes to process from @assoc | ||
| 533 | * | ||
| 534 | * Obsolete, do not use. | ||
| 535 | */ | ||
| 536 | static inline void aead_request_set_assoc(struct aead_request *req, | ||
| 537 | struct scatterlist *assoc, | ||
| 538 | unsigned int assoclen) | ||
| 539 | { | ||
| 540 | req->assoc = assoc; | ||
| 541 | req->assoclen = assoclen; | ||
| 542 | req->old = true; | ||
| 543 | } | ||
| 544 | |||
| 545 | /** | ||
| 546 | * aead_request_set_ad - set associated data information | ||
| 547 | * @req: request handle | ||
| 548 | * @assoclen: number of bytes in associated data | ||
| 549 | * | ||
| 550 | * Setting the AD information. This function sets the length of | ||
| 551 | * the associated data. | ||
| 552 | */ | ||
| 553 | static inline void aead_request_set_ad(struct aead_request *req, | ||
| 554 | unsigned int assoclen) | ||
| 555 | { | ||
| 556 | req->assoclen = assoclen; | ||
| 557 | req->old = false; | ||
| 558 | } | ||
| 559 | |||
| 33 | static inline struct crypto_aead *aead_givcrypt_reqtfm( | 560 | static inline struct crypto_aead *aead_givcrypt_reqtfm( |
| 34 | struct aead_givcrypt_request *req) | 561 | struct aead_givcrypt_request *req) |
| 35 | { | 562 | { |
| @@ -38,14 +565,12 @@ static inline struct crypto_aead *aead_givcrypt_reqtfm( | |||
| 38 | 565 | ||
| 39 | static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req) | 566 | static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req) |
| 40 | { | 567 | { |
| 41 | struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req)); | 568 | return aead_givcrypt_reqtfm(req)->givencrypt(req); |
| 42 | return crt->givencrypt(req); | ||
| 43 | }; | 569 | }; |
| 44 | 570 | ||
| 45 | static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req) | 571 | static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req) |
| 46 | { | 572 | { |
| 47 | struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req)); | 573 | return aead_givcrypt_reqtfm(req)->givdecrypt(req); |
| 48 | return crt->givdecrypt(req); | ||
| 49 | }; | 574 | }; |
| 50 | 575 | ||
| 51 | static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req, | 576 | static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req, |
diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h new file mode 100644 index 000000000000..69d163e39101 --- /dev/null +++ b/include/crypto/akcipher.h | |||
| @@ -0,0 +1,340 @@ | |||
| 1 | /* | ||
| 2 | * Public Key Encryption | ||
| 3 | * | ||
| 4 | * Copyright (c) 2015, Intel Corporation | ||
| 5 | * Authors: Tadeusz Struk <tadeusz.struk@intel.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the Free | ||
| 9 | * Software Foundation; either version 2 of the License, or (at your option) | ||
| 10 | * any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | #ifndef _CRYPTO_AKCIPHER_H | ||
| 14 | #define _CRYPTO_AKCIPHER_H | ||
| 15 | #include <linux/crypto.h> | ||
| 16 | |||
| 17 | /** | ||
| 18 | * struct akcipher_request - public key request | ||
| 19 | * | ||
| 20 | * @base: Common attributes for async crypto requests | ||
| 21 | * @src: Pointer to memory containing the input parameters | ||
| 22 | * The format of the parameter(s) is expeted to be Octet String | ||
| 23 | * @dst: Pointer to memory whare the result will be stored | ||
| 24 | * @src_len: Size of the input parameter | ||
| 25 | * @dst_len: Size of the output buffer. It needs to be at leaset | ||
| 26 | * as big as the expected result depending on the operation | ||
| 27 | * After operation it will be updated with the acctual size of the | ||
| 28 | * result. In case of error, where the dst_len was insufficient, | ||
| 29 | * it will be updated to the size required for the operation. | ||
| 30 | * @__ctx: Start of private context data | ||
| 31 | */ | ||
| 32 | struct akcipher_request { | ||
| 33 | struct crypto_async_request base; | ||
| 34 | void *src; | ||
| 35 | void *dst; | ||
| 36 | unsigned int src_len; | ||
| 37 | unsigned int dst_len; | ||
| 38 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
| 39 | }; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * struct crypto_akcipher - user-instantiated objects which encapsulate | ||
| 43 | * algorithms and core processing logic | ||
| 44 | * | ||
| 45 | * @base: Common crypto API algorithm data structure | ||
| 46 | */ | ||
| 47 | struct crypto_akcipher { | ||
| 48 | struct crypto_tfm base; | ||
| 49 | }; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * struct akcipher_alg - generic public key algorithm | ||
| 53 | * | ||
| 54 | * @sign: Function performs a sign operation as defined by public key | ||
| 55 | * algorithm. In case of error, where the dst_len was insufficient, | ||
| 56 | * the req->dst_len will be updated to the size required for the | ||
| 57 | * operation | ||
| 58 | * @verify: Function performs a sign operation as defined by public key | ||
| 59 | * algorithm. In case of error, where the dst_len was insufficient, | ||
| 60 | * the req->dst_len will be updated to the size required for the | ||
| 61 | * operation | ||
| 62 | * @encrypt: Function performs an encrytp operation as defined by public key | ||
| 63 | * algorithm. In case of error, where the dst_len was insufficient, | ||
| 64 | * the req->dst_len will be updated to the size required for the | ||
| 65 | * operation | ||
| 66 | * @decrypt: Function performs a decrypt operation as defined by public key | ||
| 67 | * algorithm. In case of error, where the dst_len was insufficient, | ||
| 68 | * the req->dst_len will be updated to the size required for the | ||
| 69 | * operation | ||
| 70 | * @setkey: Function invokes the algorithm specific set key function, which | ||
| 71 | * knows how to decode and interpret the BER encoded key | ||
| 72 | * @init: Initialize the cryptographic transformation object. | ||
| 73 | * This function is used to initialize the cryptographic | ||
| 74 | * transformation object. This function is called only once at | ||
| 75 | * the instantiation time, right after the transformation context | ||
| 76 | * was allocated. In case the cryptographic hardware has some | ||
| 77 | * special requirements which need to be handled by software, this | ||
| 78 | * function shall check for the precise requirement of the | ||
| 79 | * transformation and put any software fallbacks in place. | ||
| 80 | * @exit: Deinitialize the cryptographic transformation object. This is a | ||
| 81 | * counterpart to @init, used to remove various changes set in | ||
| 82 | * @init. | ||
| 83 | * | ||
| 84 | * @reqsize: Request context size required by algorithm implementation | ||
| 85 | * @base: Common crypto API algorithm data structure | ||
| 86 | */ | ||
| 87 | struct akcipher_alg { | ||
| 88 | int (*sign)(struct akcipher_request *req); | ||
| 89 | int (*verify)(struct akcipher_request *req); | ||
| 90 | int (*encrypt)(struct akcipher_request *req); | ||
| 91 | int (*decrypt)(struct akcipher_request *req); | ||
| 92 | int (*setkey)(struct crypto_akcipher *tfm, const void *key, | ||
| 93 | unsigned int keylen); | ||
| 94 | int (*init)(struct crypto_akcipher *tfm); | ||
| 95 | void (*exit)(struct crypto_akcipher *tfm); | ||
| 96 | |||
| 97 | unsigned int reqsize; | ||
| 98 | struct crypto_alg base; | ||
| 99 | }; | ||
| 100 | |||
| 101 | /** | ||
| 102 | * DOC: Generic Public Key API | ||
| 103 | * | ||
| 104 | * The Public Key API is used with the algorithms of type | ||
| 105 | * CRYPTO_ALG_TYPE_AKCIPHER (listed as type "akcipher" in /proc/crypto) | ||
| 106 | */ | ||
| 107 | |||
| 108 | /** | ||
| 109 | * crypto_alloc_akcipher() -- allocate AKCIPHER tfm handle | ||
| 110 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
| 111 | * public key algorithm e.g. "rsa" | ||
| 112 | * @type: specifies the type of the algorithm | ||
| 113 | * @mask: specifies the mask for the algorithm | ||
| 114 | * | ||
| 115 | * Allocate a handle for public key algorithm. The returned struct | ||
| 116 | * crypto_akcipher is the handle that is required for any subsequent | ||
| 117 | * API invocation for the public key operations. | ||
| 118 | * | ||
| 119 | * Return: allocated handle in case of success; IS_ERR() is true in case | ||
| 120 | * of an error, PTR_ERR() returns the error code. | ||
| 121 | */ | ||
| 122 | struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, | ||
| 123 | u32 mask); | ||
| 124 | |||
| 125 | static inline struct crypto_tfm *crypto_akcipher_tfm( | ||
| 126 | struct crypto_akcipher *tfm) | ||
| 127 | { | ||
| 128 | return &tfm->base; | ||
| 129 | } | ||
| 130 | |||
| 131 | static inline struct akcipher_alg *__crypto_akcipher_alg(struct crypto_alg *alg) | ||
| 132 | { | ||
| 133 | return container_of(alg, struct akcipher_alg, base); | ||
| 134 | } | ||
| 135 | |||
| 136 | static inline struct crypto_akcipher *__crypto_akcipher_tfm( | ||
| 137 | struct crypto_tfm *tfm) | ||
| 138 | { | ||
| 139 | return container_of(tfm, struct crypto_akcipher, base); | ||
| 140 | } | ||
| 141 | |||
| 142 | static inline struct akcipher_alg *crypto_akcipher_alg( | ||
| 143 | struct crypto_akcipher *tfm) | ||
| 144 | { | ||
| 145 | return __crypto_akcipher_alg(crypto_akcipher_tfm(tfm)->__crt_alg); | ||
| 146 | } | ||
| 147 | |||
| 148 | static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm) | ||
| 149 | { | ||
| 150 | return crypto_akcipher_alg(tfm)->reqsize; | ||
| 151 | } | ||
| 152 | |||
| 153 | static inline void akcipher_request_set_tfm(struct akcipher_request *req, | ||
| 154 | struct crypto_akcipher *tfm) | ||
| 155 | { | ||
| 156 | req->base.tfm = crypto_akcipher_tfm(tfm); | ||
| 157 | } | ||
| 158 | |||
| 159 | static inline struct crypto_akcipher *crypto_akcipher_reqtfm( | ||
| 160 | struct akcipher_request *req) | ||
| 161 | { | ||
| 162 | return __crypto_akcipher_tfm(req->base.tfm); | ||
| 163 | } | ||
| 164 | |||
| 165 | /** | ||
| 166 | * crypto_free_akcipher() -- free AKCIPHER tfm handle | ||
| 167 | * | ||
| 168 | * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() | ||
| 169 | */ | ||
| 170 | static inline void crypto_free_akcipher(struct crypto_akcipher *tfm) | ||
| 171 | { | ||
| 172 | crypto_destroy_tfm(tfm, crypto_akcipher_tfm(tfm)); | ||
| 173 | } | ||
| 174 | |||
| 175 | /** | ||
| 176 | * akcipher_request_alloc() -- allocates public key request | ||
| 177 | * | ||
| 178 | * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() | ||
| 179 | * @gfp: allocation flags | ||
| 180 | * | ||
| 181 | * Return: allocated handle in case of success or NULL in case of an error. | ||
| 182 | */ | ||
| 183 | static inline struct akcipher_request *akcipher_request_alloc( | ||
| 184 | struct crypto_akcipher *tfm, gfp_t gfp) | ||
| 185 | { | ||
| 186 | struct akcipher_request *req; | ||
| 187 | |||
| 188 | req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp); | ||
| 189 | if (likely(req)) | ||
| 190 | akcipher_request_set_tfm(req, tfm); | ||
| 191 | |||
| 192 | return req; | ||
| 193 | } | ||
| 194 | |||
| 195 | /** | ||
| 196 | * akcipher_request_free() -- zeroize and free public key request | ||
| 197 | * | ||
| 198 | * @req: request to free | ||
| 199 | */ | ||
| 200 | static inline void akcipher_request_free(struct akcipher_request *req) | ||
| 201 | { | ||
| 202 | kzfree(req); | ||
| 203 | } | ||
| 204 | |||
| 205 | /** | ||
| 206 | * akcipher_request_set_callback() -- Sets an asynchronous callback. | ||
| 207 | * | ||
| 208 | * Callback will be called when an asynchronous operation on a given | ||
| 209 | * request is finished. | ||
| 210 | * | ||
| 211 | * @req: request that the callback will be set for | ||
| 212 | * @flgs: specify for instance if the operation may backlog | ||
| 213 | * @cmlp: callback which will be called | ||
| 214 | * @data: private data used by the caller | ||
| 215 | */ | ||
| 216 | static inline void akcipher_request_set_callback(struct akcipher_request *req, | ||
| 217 | u32 flgs, | ||
| 218 | crypto_completion_t cmpl, | ||
| 219 | void *data) | ||
| 220 | { | ||
| 221 | req->base.complete = cmpl; | ||
| 222 | req->base.data = data; | ||
| 223 | req->base.flags = flgs; | ||
| 224 | } | ||
| 225 | |||
| 226 | /** | ||
| 227 | * akcipher_request_set_crypt() -- Sets reqest parameters | ||
| 228 | * | ||
| 229 | * Sets parameters required by crypto operation | ||
| 230 | * | ||
| 231 | * @req: public key request | ||
| 232 | * @src: ptr to input parameter | ||
| 233 | * @dst: ptr of output parameter | ||
| 234 | * @src_len: size of the input buffer | ||
| 235 | * @dst_len: size of the output buffer. It will be updated by the | ||
| 236 | * implementation to reflect the acctual size of the result | ||
| 237 | */ | ||
| 238 | static inline void akcipher_request_set_crypt(struct akcipher_request *req, | ||
| 239 | void *src, void *dst, | ||
| 240 | unsigned int src_len, | ||
| 241 | unsigned int dst_len) | ||
| 242 | { | ||
| 243 | req->src = src; | ||
| 244 | req->dst = dst; | ||
| 245 | req->src_len = src_len; | ||
| 246 | req->dst_len = dst_len; | ||
| 247 | } | ||
| 248 | |||
| 249 | /** | ||
| 250 | * crypto_akcipher_encrypt() -- Invoke public key encrypt operation | ||
| 251 | * | ||
| 252 | * Function invokes the specific public key encrypt operation for a given | ||
| 253 | * public key algorithm | ||
| 254 | * | ||
| 255 | * @req: asymmetric key request | ||
| 256 | * | ||
| 257 | * Return: zero on success; error code in case of error | ||
| 258 | */ | ||
| 259 | static inline int crypto_akcipher_encrypt(struct akcipher_request *req) | ||
| 260 | { | ||
| 261 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
| 262 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
| 263 | |||
| 264 | return alg->encrypt(req); | ||
| 265 | } | ||
| 266 | |||
| 267 | /** | ||
| 268 | * crypto_akcipher_decrypt() -- Invoke public key decrypt operation | ||
| 269 | * | ||
| 270 | * Function invokes the specific public key decrypt operation for a given | ||
| 271 | * public key algorithm | ||
| 272 | * | ||
| 273 | * @req: asymmetric key request | ||
| 274 | * | ||
| 275 | * Return: zero on success; error code in case of error | ||
| 276 | */ | ||
| 277 | static inline int crypto_akcipher_decrypt(struct akcipher_request *req) | ||
| 278 | { | ||
| 279 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
| 280 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
| 281 | |||
| 282 | return alg->decrypt(req); | ||
| 283 | } | ||
| 284 | |||
| 285 | /** | ||
| 286 | * crypto_akcipher_sign() -- Invoke public key sign operation | ||
| 287 | * | ||
| 288 | * Function invokes the specific public key sign operation for a given | ||
| 289 | * public key algorithm | ||
| 290 | * | ||
| 291 | * @req: asymmetric key request | ||
| 292 | * | ||
| 293 | * Return: zero on success; error code in case of error | ||
| 294 | */ | ||
| 295 | static inline int crypto_akcipher_sign(struct akcipher_request *req) | ||
| 296 | { | ||
| 297 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
| 298 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
| 299 | |||
| 300 | return alg->sign(req); | ||
| 301 | } | ||
| 302 | |||
| 303 | /** | ||
| 304 | * crypto_akcipher_verify() -- Invoke public key verify operation | ||
| 305 | * | ||
| 306 | * Function invokes the specific public key verify operation for a given | ||
| 307 | * public key algorithm | ||
| 308 | * | ||
| 309 | * @req: asymmetric key request | ||
| 310 | * | ||
| 311 | * Return: zero on success; error code in case of error | ||
| 312 | */ | ||
| 313 | static inline int crypto_akcipher_verify(struct akcipher_request *req) | ||
| 314 | { | ||
| 315 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
| 316 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
| 317 | |||
| 318 | return alg->verify(req); | ||
| 319 | } | ||
| 320 | |||
| 321 | /** | ||
| 322 | * crypto_akcipher_setkey() -- Invoke public key setkey operation | ||
| 323 | * | ||
| 324 | * Function invokes the algorithm specific set key function, which knows | ||
| 325 | * how to decode and interpret the encoded key | ||
| 326 | * | ||
| 327 | * @tfm: tfm handle | ||
| 328 | * @key: BER encoded private or public key | ||
| 329 | * @keylen: length of the key | ||
| 330 | * | ||
| 331 | * Return: zero on success; error code in case of error | ||
| 332 | */ | ||
| 333 | static inline int crypto_akcipher_setkey(struct crypto_akcipher *tfm, void *key, | ||
| 334 | unsigned int keylen) | ||
| 335 | { | ||
| 336 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
| 337 | |||
| 338 | return alg->setkey(tfm, key, keylen); | ||
| 339 | } | ||
| 340 | #endif | ||
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 0ecb7688af71..d4ebf6e9af6a 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
| 19 | 19 | ||
| 20 | struct crypto_aead; | ||
| 20 | struct module; | 21 | struct module; |
| 21 | struct rtattr; | 22 | struct rtattr; |
| 22 | struct seq_file; | 23 | struct seq_file; |
| @@ -126,7 +127,6 @@ struct ablkcipher_walk { | |||
| 126 | }; | 127 | }; |
| 127 | 128 | ||
| 128 | extern const struct crypto_type crypto_ablkcipher_type; | 129 | extern const struct crypto_type crypto_ablkcipher_type; |
| 129 | extern const struct crypto_type crypto_aead_type; | ||
| 130 | extern const struct crypto_type crypto_blkcipher_type; | 130 | extern const struct crypto_type crypto_blkcipher_type; |
| 131 | 131 | ||
| 132 | void crypto_mod_put(struct crypto_alg *alg); | 132 | void crypto_mod_put(struct crypto_alg *alg); |
| @@ -144,6 +144,8 @@ int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, | |||
| 144 | int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg, | 144 | int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg, |
| 145 | struct crypto_instance *inst, | 145 | struct crypto_instance *inst, |
| 146 | const struct crypto_type *frontend); | 146 | const struct crypto_type *frontend); |
| 147 | int crypto_grab_spawn(struct crypto_spawn *spawn, const char *name, | ||
| 148 | u32 type, u32 mask); | ||
| 147 | 149 | ||
| 148 | void crypto_drop_spawn(struct crypto_spawn *spawn); | 150 | void crypto_drop_spawn(struct crypto_spawn *spawn); |
| 149 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, | 151 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, |
| @@ -239,22 +241,6 @@ static inline void *crypto_ablkcipher_ctx_aligned(struct crypto_ablkcipher *tfm) | |||
| 239 | return crypto_tfm_ctx_aligned(&tfm->base); | 241 | return crypto_tfm_ctx_aligned(&tfm->base); |
| 240 | } | 242 | } |
| 241 | 243 | ||
| 242 | static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm) | ||
| 243 | { | ||
| 244 | return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead; | ||
| 245 | } | ||
| 246 | |||
| 247 | static inline void *crypto_aead_ctx(struct crypto_aead *tfm) | ||
| 248 | { | ||
| 249 | return crypto_tfm_ctx(&tfm->base); | ||
| 250 | } | ||
| 251 | |||
| 252 | static inline struct crypto_instance *crypto_aead_alg_instance( | ||
| 253 | struct crypto_aead *aead) | ||
| 254 | { | ||
| 255 | return crypto_tfm_alg_instance(&aead->base); | ||
| 256 | } | ||
| 257 | |||
| 258 | static inline struct crypto_blkcipher *crypto_spawn_blkcipher( | 244 | static inline struct crypto_blkcipher *crypto_spawn_blkcipher( |
| 259 | struct crypto_spawn *spawn) | 245 | struct crypto_spawn *spawn) |
| 260 | { | 246 | { |
| @@ -363,21 +349,6 @@ static inline int ablkcipher_tfm_in_queue(struct crypto_queue *queue, | |||
| 363 | return crypto_tfm_in_queue(queue, crypto_ablkcipher_tfm(tfm)); | 349 | return crypto_tfm_in_queue(queue, crypto_ablkcipher_tfm(tfm)); |
| 364 | } | 350 | } |
| 365 | 351 | ||
| 366 | static inline void *aead_request_ctx(struct aead_request *req) | ||
| 367 | { | ||
| 368 | return req->__ctx; | ||
| 369 | } | ||
| 370 | |||
| 371 | static inline void aead_request_complete(struct aead_request *req, int err) | ||
| 372 | { | ||
| 373 | req->base.complete(&req->base, err); | ||
| 374 | } | ||
| 375 | |||
| 376 | static inline u32 aead_request_flags(struct aead_request *req) | ||
| 377 | { | ||
| 378 | return req->base.flags; | ||
| 379 | } | ||
| 380 | |||
| 381 | static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, | 352 | static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, |
| 382 | u32 type, u32 mask) | 353 | u32 type, u32 mask) |
| 383 | { | 354 | { |
diff --git a/include/crypto/compress.h b/include/crypto/compress.h index 86163ef24219..5b67af834d83 100644 --- a/include/crypto/compress.h +++ b/include/crypto/compress.h | |||
| @@ -55,14 +55,14 @@ struct crypto_pcomp { | |||
| 55 | }; | 55 | }; |
| 56 | 56 | ||
| 57 | struct pcomp_alg { | 57 | struct pcomp_alg { |
| 58 | int (*compress_setup)(struct crypto_pcomp *tfm, void *params, | 58 | int (*compress_setup)(struct crypto_pcomp *tfm, const void *params, |
| 59 | unsigned int len); | 59 | unsigned int len); |
| 60 | int (*compress_init)(struct crypto_pcomp *tfm); | 60 | int (*compress_init)(struct crypto_pcomp *tfm); |
| 61 | int (*compress_update)(struct crypto_pcomp *tfm, | 61 | int (*compress_update)(struct crypto_pcomp *tfm, |
| 62 | struct comp_request *req); | 62 | struct comp_request *req); |
| 63 | int (*compress_final)(struct crypto_pcomp *tfm, | 63 | int (*compress_final)(struct crypto_pcomp *tfm, |
| 64 | struct comp_request *req); | 64 | struct comp_request *req); |
| 65 | int (*decompress_setup)(struct crypto_pcomp *tfm, void *params, | 65 | int (*decompress_setup)(struct crypto_pcomp *tfm, const void *params, |
| 66 | unsigned int len); | 66 | unsigned int len); |
| 67 | int (*decompress_init)(struct crypto_pcomp *tfm); | 67 | int (*decompress_init)(struct crypto_pcomp *tfm); |
| 68 | int (*decompress_update)(struct crypto_pcomp *tfm, | 68 | int (*decompress_update)(struct crypto_pcomp *tfm, |
| @@ -97,7 +97,7 @@ static inline struct pcomp_alg *crypto_pcomp_alg(struct crypto_pcomp *tfm) | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | static inline int crypto_compress_setup(struct crypto_pcomp *tfm, | 99 | static inline int crypto_compress_setup(struct crypto_pcomp *tfm, |
| 100 | void *params, unsigned int len) | 100 | const void *params, unsigned int len) |
| 101 | { | 101 | { |
| 102 | return crypto_pcomp_alg(tfm)->compress_setup(tfm, params, len); | 102 | return crypto_pcomp_alg(tfm)->compress_setup(tfm, params, len); |
| 103 | } | 103 | } |
| @@ -120,7 +120,7 @@ static inline int crypto_compress_final(struct crypto_pcomp *tfm, | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | static inline int crypto_decompress_setup(struct crypto_pcomp *tfm, | 122 | static inline int crypto_decompress_setup(struct crypto_pcomp *tfm, |
| 123 | void *params, unsigned int len) | 123 | const void *params, unsigned int len) |
| 124 | { | 124 | { |
| 125 | return crypto_pcomp_alg(tfm)->decompress_setup(tfm, params, len); | 125 | return crypto_pcomp_alg(tfm)->decompress_setup(tfm, params, len); |
| 126 | } | 126 | } |
diff --git a/include/crypto/cryptd.h b/include/crypto/cryptd.h index ba98918bbd9b..1547f540c920 100644 --- a/include/crypto/cryptd.h +++ b/include/crypto/cryptd.h | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | #include <linux/crypto.h> | 15 | #include <linux/crypto.h> |
| 16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
| 17 | #include <crypto/aead.h> | ||
| 17 | #include <crypto/hash.h> | 18 | #include <crypto/hash.h> |
| 18 | 19 | ||
| 19 | struct cryptd_ablkcipher { | 20 | struct cryptd_ablkcipher { |
diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h index 5186f750c713..9756c70899d8 100644 --- a/include/crypto/drbg.h +++ b/include/crypto/drbg.h | |||
| @@ -49,8 +49,9 @@ | |||
| 49 | #include <crypto/internal/rng.h> | 49 | #include <crypto/internal/rng.h> |
| 50 | #include <crypto/rng.h> | 50 | #include <crypto/rng.h> |
| 51 | #include <linux/fips.h> | 51 | #include <linux/fips.h> |
| 52 | #include <linux/spinlock.h> | 52 | #include <linux/mutex.h> |
| 53 | #include <linux/list.h> | 53 | #include <linux/list.h> |
| 54 | #include <linux/workqueue.h> | ||
| 54 | 55 | ||
| 55 | /* | 56 | /* |
| 56 | * Concatenation Helper and string operation helper | 57 | * Concatenation Helper and string operation helper |
| @@ -104,12 +105,13 @@ struct drbg_test_data { | |||
| 104 | }; | 105 | }; |
| 105 | 106 | ||
| 106 | struct drbg_state { | 107 | struct drbg_state { |
| 107 | spinlock_t drbg_lock; /* lock around DRBG */ | 108 | struct mutex drbg_mutex; /* lock around DRBG */ |
| 108 | unsigned char *V; /* internal state 10.1.1.1 1a) */ | 109 | unsigned char *V; /* internal state 10.1.1.1 1a) */ |
| 109 | /* hash: static value 10.1.1.1 1b) hmac / ctr: key */ | 110 | /* hash: static value 10.1.1.1 1b) hmac / ctr: key */ |
| 110 | unsigned char *C; | 111 | unsigned char *C; |
| 111 | /* Number of RNG requests since last reseed -- 10.1.1.1 1c) */ | 112 | /* Number of RNG requests since last reseed -- 10.1.1.1 1c) */ |
| 112 | size_t reseed_ctr; | 113 | size_t reseed_ctr; |
| 114 | size_t reseed_threshold; | ||
| 113 | /* some memory the DRBG can use for its operation */ | 115 | /* some memory the DRBG can use for its operation */ |
| 114 | unsigned char *scratchpad; | 116 | unsigned char *scratchpad; |
| 115 | void *priv_data; /* Cipher handle */ | 117 | void *priv_data; /* Cipher handle */ |
| @@ -119,9 +121,12 @@ struct drbg_state { | |||
| 119 | bool fips_primed; /* Continuous test primed? */ | 121 | bool fips_primed; /* Continuous test primed? */ |
| 120 | unsigned char *prev; /* FIPS 140-2 continuous test value */ | 122 | unsigned char *prev; /* FIPS 140-2 continuous test value */ |
| 121 | #endif | 123 | #endif |
| 124 | struct work_struct seed_work; /* asynchronous seeding support */ | ||
| 125 | struct crypto_rng *jent; | ||
| 122 | const struct drbg_state_ops *d_ops; | 126 | const struct drbg_state_ops *d_ops; |
| 123 | const struct drbg_core *core; | 127 | const struct drbg_core *core; |
| 124 | struct drbg_test_data *test_data; | 128 | struct drbg_string test_data; |
| 129 | struct random_ready_callback random_ready; | ||
| 125 | }; | 130 | }; |
| 126 | 131 | ||
| 127 | static inline __u8 drbg_statelen(struct drbg_state *drbg) | 132 | static inline __u8 drbg_statelen(struct drbg_state *drbg) |
| @@ -177,19 +182,8 @@ static inline size_t drbg_max_requests(struct drbg_state *drbg) | |||
| 177 | } | 182 | } |
| 178 | 183 | ||
| 179 | /* | 184 | /* |
| 180 | * kernel crypto API input data structure for DRBG generate in case dlen | ||
| 181 | * is set to 0 | ||
| 182 | */ | ||
| 183 | struct drbg_gen { | ||
| 184 | unsigned char *outbuf; /* output buffer for random numbers */ | ||
| 185 | unsigned int outlen; /* size of output buffer */ | ||
| 186 | struct drbg_string *addtl; /* additional information string */ | ||
| 187 | struct drbg_test_data *test_data; /* test data */ | ||
| 188 | }; | ||
| 189 | |||
| 190 | /* | ||
| 191 | * This is a wrapper to the kernel crypto API function of | 185 | * This is a wrapper to the kernel crypto API function of |
| 192 | * crypto_rng_get_bytes() to allow the caller to provide additional data. | 186 | * crypto_rng_generate() to allow the caller to provide additional data. |
| 193 | * | 187 | * |
| 194 | * @drng DRBG handle -- see crypto_rng_get_bytes | 188 | * @drng DRBG handle -- see crypto_rng_get_bytes |
| 195 | * @outbuf output buffer -- see crypto_rng_get_bytes | 189 | * @outbuf output buffer -- see crypto_rng_get_bytes |
| @@ -204,21 +198,15 @@ static inline int crypto_drbg_get_bytes_addtl(struct crypto_rng *drng, | |||
| 204 | unsigned char *outbuf, unsigned int outlen, | 198 | unsigned char *outbuf, unsigned int outlen, |
| 205 | struct drbg_string *addtl) | 199 | struct drbg_string *addtl) |
| 206 | { | 200 | { |
| 207 | int ret; | 201 | return crypto_rng_generate(drng, addtl->buf, addtl->len, |
| 208 | struct drbg_gen genbuf; | 202 | outbuf, outlen); |
| 209 | genbuf.outbuf = outbuf; | ||
| 210 | genbuf.outlen = outlen; | ||
| 211 | genbuf.addtl = addtl; | ||
| 212 | genbuf.test_data = NULL; | ||
| 213 | ret = crypto_rng_get_bytes(drng, (u8 *)&genbuf, 0); | ||
| 214 | return ret; | ||
| 215 | } | 203 | } |
| 216 | 204 | ||
| 217 | /* | 205 | /* |
| 218 | * TEST code | 206 | * TEST code |
| 219 | * | 207 | * |
| 220 | * This is a wrapper to the kernel crypto API function of | 208 | * This is a wrapper to the kernel crypto API function of |
| 221 | * crypto_rng_get_bytes() to allow the caller to provide additional data and | 209 | * crypto_rng_generate() to allow the caller to provide additional data and |
| 222 | * allow furnishing of test_data | 210 | * allow furnishing of test_data |
| 223 | * | 211 | * |
| 224 | * @drng DRBG handle -- see crypto_rng_get_bytes | 212 | * @drng DRBG handle -- see crypto_rng_get_bytes |
| @@ -236,14 +224,10 @@ static inline int crypto_drbg_get_bytes_addtl_test(struct crypto_rng *drng, | |||
| 236 | struct drbg_string *addtl, | 224 | struct drbg_string *addtl, |
| 237 | struct drbg_test_data *test_data) | 225 | struct drbg_test_data *test_data) |
| 238 | { | 226 | { |
| 239 | int ret; | 227 | crypto_rng_set_entropy(drng, test_data->testentropy->buf, |
| 240 | struct drbg_gen genbuf; | 228 | test_data->testentropy->len); |
| 241 | genbuf.outbuf = outbuf; | 229 | return crypto_rng_generate(drng, addtl->buf, addtl->len, |
| 242 | genbuf.outlen = outlen; | 230 | outbuf, outlen); |
| 243 | genbuf.addtl = addtl; | ||
| 244 | genbuf.test_data = test_data; | ||
| 245 | ret = crypto_rng_get_bytes(drng, (u8 *)&genbuf, 0); | ||
| 246 | return ret; | ||
| 247 | } | 231 | } |
| 248 | 232 | ||
| 249 | /* | 233 | /* |
| @@ -264,14 +248,9 @@ static inline int crypto_drbg_reset_test(struct crypto_rng *drng, | |||
| 264 | struct drbg_string *pers, | 248 | struct drbg_string *pers, |
| 265 | struct drbg_test_data *test_data) | 249 | struct drbg_test_data *test_data) |
| 266 | { | 250 | { |
| 267 | int ret; | 251 | crypto_rng_set_entropy(drng, test_data->testentropy->buf, |
| 268 | struct drbg_gen genbuf; | 252 | test_data->testentropy->len); |
| 269 | genbuf.outbuf = NULL; | 253 | return crypto_rng_reset(drng, pers->buf, pers->len); |
| 270 | genbuf.outlen = 0; | ||
| 271 | genbuf.addtl = pers; | ||
| 272 | genbuf.test_data = test_data; | ||
| 273 | ret = crypto_rng_reset(drng, (u8 *)&genbuf, 0); | ||
| 274 | return ret; | ||
| 275 | } | 254 | } |
| 276 | 255 | ||
| 277 | /* DRBG type flags */ | 256 | /* DRBG type flags */ |
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 98abda9ed3aa..57c8a6ee33c2 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
| @@ -66,7 +66,7 @@ struct ahash_request { | |||
| 66 | /** | 66 | /** |
| 67 | * struct ahash_alg - asynchronous message digest definition | 67 | * struct ahash_alg - asynchronous message digest definition |
| 68 | * @init: Initialize the transformation context. Intended only to initialize the | 68 | * @init: Initialize the transformation context. Intended only to initialize the |
| 69 | * state of the HASH transformation at the begining. This shall fill in | 69 | * state of the HASH transformation at the beginning. This shall fill in |
| 70 | * the internal structures used during the entire duration of the whole | 70 | * the internal structures used during the entire duration of the whole |
| 71 | * transformation. No data processing happens at this point. | 71 | * transformation. No data processing happens at this point. |
| 72 | * @update: Push a chunk of data into the driver for transformation. This | 72 | * @update: Push a chunk of data into the driver for transformation. This |
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h index 2eba340230a7..4b2547186519 100644 --- a/include/crypto/internal/aead.h +++ b/include/crypto/internal/aead.h | |||
| @@ -15,16 +15,75 @@ | |||
| 15 | 15 | ||
| 16 | #include <crypto/aead.h> | 16 | #include <crypto/aead.h> |
| 17 | #include <crypto/algapi.h> | 17 | #include <crypto/algapi.h> |
| 18 | #include <linux/stddef.h> | ||
| 18 | #include <linux/types.h> | 19 | #include <linux/types.h> |
| 19 | 20 | ||
| 20 | struct rtattr; | 21 | struct rtattr; |
| 21 | 22 | ||
| 23 | struct aead_instance { | ||
| 24 | union { | ||
| 25 | struct { | ||
| 26 | char head[offsetof(struct aead_alg, base)]; | ||
| 27 | struct crypto_instance base; | ||
| 28 | } s; | ||
| 29 | struct aead_alg alg; | ||
| 30 | }; | ||
| 31 | }; | ||
| 32 | |||
| 22 | struct crypto_aead_spawn { | 33 | struct crypto_aead_spawn { |
| 23 | struct crypto_spawn base; | 34 | struct crypto_spawn base; |
| 24 | }; | 35 | }; |
| 25 | 36 | ||
| 37 | extern const struct crypto_type crypto_aead_type; | ||
| 26 | extern const struct crypto_type crypto_nivaead_type; | 38 | extern const struct crypto_type crypto_nivaead_type; |
| 27 | 39 | ||
| 40 | static inline void *crypto_aead_ctx(struct crypto_aead *tfm) | ||
| 41 | { | ||
| 42 | return crypto_tfm_ctx(&tfm->base); | ||
| 43 | } | ||
| 44 | |||
| 45 | static inline struct crypto_instance *crypto_aead_alg_instance( | ||
| 46 | struct crypto_aead *aead) | ||
| 47 | { | ||
| 48 | return crypto_tfm_alg_instance(&aead->base); | ||
| 49 | } | ||
| 50 | |||
| 51 | static inline struct crypto_instance *aead_crypto_instance( | ||
| 52 | struct aead_instance *inst) | ||
| 53 | { | ||
| 54 | return container_of(&inst->alg.base, struct crypto_instance, alg); | ||
| 55 | } | ||
| 56 | |||
| 57 | static inline struct aead_instance *aead_instance(struct crypto_instance *inst) | ||
| 58 | { | ||
| 59 | return container_of(&inst->alg, struct aead_instance, alg.base); | ||
| 60 | } | ||
| 61 | |||
| 62 | static inline struct aead_instance *aead_alg_instance(struct crypto_aead *aead) | ||
| 63 | { | ||
| 64 | return aead_instance(crypto_aead_alg_instance(aead)); | ||
| 65 | } | ||
| 66 | |||
| 67 | static inline void *aead_instance_ctx(struct aead_instance *inst) | ||
| 68 | { | ||
| 69 | return crypto_instance_ctx(aead_crypto_instance(inst)); | ||
| 70 | } | ||
| 71 | |||
| 72 | static inline void *aead_request_ctx(struct aead_request *req) | ||
| 73 | { | ||
| 74 | return req->__ctx; | ||
| 75 | } | ||
| 76 | |||
| 77 | static inline void aead_request_complete(struct aead_request *req, int err) | ||
| 78 | { | ||
| 79 | req->base.complete(&req->base, err); | ||
| 80 | } | ||
| 81 | |||
| 82 | static inline u32 aead_request_flags(struct aead_request *req) | ||
| 83 | { | ||
| 84 | return req->base.flags; | ||
| 85 | } | ||
| 86 | |||
| 28 | static inline void crypto_set_aead_spawn( | 87 | static inline void crypto_set_aead_spawn( |
| 29 | struct crypto_aead_spawn *spawn, struct crypto_instance *inst) | 88 | struct crypto_aead_spawn *spawn, struct crypto_instance *inst) |
| 30 | { | 89 | { |
| @@ -47,24 +106,27 @@ static inline struct crypto_alg *crypto_aead_spawn_alg( | |||
| 47 | return spawn->base.alg; | 106 | return spawn->base.alg; |
| 48 | } | 107 | } |
| 49 | 108 | ||
| 109 | static inline struct aead_alg *crypto_spawn_aead_alg( | ||
| 110 | struct crypto_aead_spawn *spawn) | ||
| 111 | { | ||
| 112 | return container_of(spawn->base.alg, struct aead_alg, base); | ||
| 113 | } | ||
| 114 | |||
| 50 | static inline struct crypto_aead *crypto_spawn_aead( | 115 | static inline struct crypto_aead *crypto_spawn_aead( |
| 51 | struct crypto_aead_spawn *spawn) | 116 | struct crypto_aead_spawn *spawn) |
| 52 | { | 117 | { |
| 53 | return __crypto_aead_cast( | 118 | return crypto_spawn_tfm2(&spawn->base); |
| 54 | crypto_spawn_tfm(&spawn->base, CRYPTO_ALG_TYPE_AEAD, | ||
| 55 | CRYPTO_ALG_TYPE_MASK)); | ||
| 56 | } | 119 | } |
| 57 | 120 | ||
| 58 | struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl, | 121 | struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, |
| 59 | struct rtattr **tb, u32 type, | 122 | struct rtattr **tb, u32 type, u32 mask); |
| 60 | u32 mask); | 123 | void aead_geniv_free(struct aead_instance *inst); |
| 61 | void aead_geniv_free(struct crypto_instance *inst); | ||
| 62 | int aead_geniv_init(struct crypto_tfm *tfm); | 124 | int aead_geniv_init(struct crypto_tfm *tfm); |
| 63 | void aead_geniv_exit(struct crypto_tfm *tfm); | 125 | void aead_geniv_exit(struct crypto_tfm *tfm); |
| 64 | 126 | ||
| 65 | static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv) | 127 | static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv) |
| 66 | { | 128 | { |
| 67 | return crypto_aead_crt(geniv)->base; | 129 | return geniv->child; |
| 68 | } | 130 | } |
| 69 | 131 | ||
| 70 | static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req) | 132 | static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req) |
| @@ -78,5 +140,29 @@ static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req, | |||
| 78 | aead_request_complete(&req->areq, err); | 140 | aead_request_complete(&req->areq, err); |
| 79 | } | 141 | } |
| 80 | 142 | ||
| 143 | static inline void crypto_aead_set_reqsize(struct crypto_aead *aead, | ||
| 144 | unsigned int reqsize) | ||
| 145 | { | ||
| 146 | crypto_aead_crt(aead)->reqsize = reqsize; | ||
| 147 | } | ||
| 148 | |||
| 149 | static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg *alg) | ||
| 150 | { | ||
| 151 | return alg->base.cra_aead.encrypt ? alg->base.cra_aead.maxauthsize : | ||
| 152 | alg->maxauthsize; | ||
| 153 | } | ||
| 154 | |||
| 155 | static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead) | ||
| 156 | { | ||
| 157 | return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead)); | ||
| 158 | } | ||
| 159 | |||
| 160 | int crypto_register_aead(struct aead_alg *alg); | ||
| 161 | void crypto_unregister_aead(struct aead_alg *alg); | ||
| 162 | int crypto_register_aeads(struct aead_alg *algs, int count); | ||
| 163 | void crypto_unregister_aeads(struct aead_alg *algs, int count); | ||
| 164 | int aead_register_instance(struct crypto_template *tmpl, | ||
| 165 | struct aead_instance *inst); | ||
| 166 | |||
| 81 | #endif /* _CRYPTO_INTERNAL_AEAD_H */ | 167 | #endif /* _CRYPTO_INTERNAL_AEAD_H */ |
| 82 | 168 | ||
diff --git a/include/crypto/internal/akcipher.h b/include/crypto/internal/akcipher.h new file mode 100644 index 000000000000..9a2bda15e454 --- /dev/null +++ b/include/crypto/internal/akcipher.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | /* | ||
| 2 | * Public Key Encryption | ||
| 3 | * | ||
| 4 | * Copyright (c) 2015, Intel Corporation | ||
| 5 | * Authors: Tadeusz Struk <tadeusz.struk@intel.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the Free | ||
| 9 | * Software Foundation; either version 2 of the License, or (at your option) | ||
| 10 | * any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | #ifndef _CRYPTO_AKCIPHER_INT_H | ||
| 14 | #define _CRYPTO_AKCIPHER_INT_H | ||
| 15 | #include <crypto/akcipher.h> | ||
| 16 | |||
| 17 | /* | ||
| 18 | * Transform internal helpers. | ||
| 19 | */ | ||
| 20 | static inline void *akcipher_request_ctx(struct akcipher_request *req) | ||
| 21 | { | ||
| 22 | return req->__ctx; | ||
| 23 | } | ||
| 24 | |||
| 25 | static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm) | ||
| 26 | { | ||
| 27 | return tfm->base.__crt_ctx; | ||
| 28 | } | ||
| 29 | |||
| 30 | static inline void akcipher_request_complete(struct akcipher_request *req, | ||
| 31 | int err) | ||
| 32 | { | ||
| 33 | req->base.complete(&req->base, err); | ||
| 34 | } | ||
| 35 | |||
| 36 | static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm) | ||
| 37 | { | ||
| 38 | return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name; | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * crypto_register_akcipher() -- Register public key algorithm | ||
| 43 | * | ||
| 44 | * Function registers an implementation of a public key verify algorithm | ||
| 45 | * | ||
| 46 | * @alg: algorithm definition | ||
| 47 | * | ||
| 48 | * Return: zero on success; error code in case of error | ||
| 49 | */ | ||
| 50 | int crypto_register_akcipher(struct akcipher_alg *alg); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * crypto_unregister_akcipher() -- Unregister public key algorithm | ||
| 54 | * | ||
| 55 | * Function unregisters an implementation of a public key verify algorithm | ||
| 56 | * | ||
| 57 | * @alg: algorithm definition | ||
| 58 | */ | ||
| 59 | void crypto_unregister_akcipher(struct akcipher_alg *alg); | ||
| 60 | #endif | ||
diff --git a/include/crypto/internal/geniv.h b/include/crypto/internal/geniv.h new file mode 100644 index 000000000000..9ca9b871aba5 --- /dev/null +++ b/include/crypto/internal/geniv.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | * geniv: IV generation | ||
| 3 | * | ||
| 4 | * Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms of the GNU General Public License as published by the Free | ||
| 8 | * Software Foundation; either version 2 of the License, or (at your option) | ||
| 9 | * any later version. | ||
| 10 | * | ||
| 11 | */ | ||
| 12 | |||
| 13 | #ifndef _CRYPTO_INTERNAL_GENIV_H | ||
| 14 | #define _CRYPTO_INTERNAL_GENIV_H | ||
| 15 | |||
| 16 | #include <crypto/internal/aead.h> | ||
| 17 | #include <linux/spinlock.h> | ||
| 18 | |||
| 19 | struct aead_geniv_ctx { | ||
| 20 | spinlock_t lock; | ||
| 21 | struct crypto_aead *child; | ||
| 22 | }; | ||
| 23 | |||
| 24 | #endif /* _CRYPTO_INTERNAL_GENIV_H */ | ||
diff --git a/include/crypto/internal/rng.h b/include/crypto/internal/rng.h index 896973369573..a52ef3483dd7 100644 --- a/include/crypto/internal/rng.h +++ b/include/crypto/internal/rng.h | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * RNG: Random Number Generator algorithms under the crypto API | 2 | * RNG: Random Number Generator algorithms under the crypto API |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com> | 4 | * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com> |
| 5 | * Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au> | ||
| 5 | * | 6 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it | 7 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the Free | 8 | * under the terms of the GNU General Public License as published by the Free |
| @@ -16,11 +17,29 @@ | |||
| 16 | #include <crypto/algapi.h> | 17 | #include <crypto/algapi.h> |
| 17 | #include <crypto/rng.h> | 18 | #include <crypto/rng.h> |
| 18 | 19 | ||
| 19 | extern const struct crypto_type crypto_rng_type; | 20 | int crypto_register_rng(struct rng_alg *alg); |
| 21 | void crypto_unregister_rng(struct rng_alg *alg); | ||
| 22 | int crypto_register_rngs(struct rng_alg *algs, int count); | ||
| 23 | void crypto_unregister_rngs(struct rng_alg *algs, int count); | ||
| 24 | |||
| 25 | #if defined(CONFIG_CRYPTO_RNG) || defined(CONFIG_CRYPTO_RNG_MODULE) | ||
| 26 | int crypto_del_default_rng(void); | ||
| 27 | #else | ||
| 28 | static inline int crypto_del_default_rng(void) | ||
| 29 | { | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | #endif | ||
| 20 | 33 | ||
| 21 | static inline void *crypto_rng_ctx(struct crypto_rng *tfm) | 34 | static inline void *crypto_rng_ctx(struct crypto_rng *tfm) |
| 22 | { | 35 | { |
| 23 | return crypto_tfm_ctx(&tfm->base); | 36 | return crypto_tfm_ctx(&tfm->base); |
| 24 | } | 37 | } |
| 25 | 38 | ||
| 39 | static inline void crypto_rng_set_entropy(struct crypto_rng *tfm, | ||
| 40 | const u8 *data, unsigned int len) | ||
| 41 | { | ||
| 42 | crypto_rng_alg(tfm)->set_ent(tfm, data, len); | ||
| 43 | } | ||
| 44 | |||
| 26 | #endif | 45 | #endif |
diff --git a/include/crypto/internal/rsa.h b/include/crypto/internal/rsa.h new file mode 100644 index 000000000000..a8c86365439f --- /dev/null +++ b/include/crypto/internal/rsa.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* | ||
| 2 | * RSA internal helpers | ||
| 3 | * | ||
| 4 | * Copyright (c) 2015, Intel Corporation | ||
| 5 | * Authors: Tadeusz Struk <tadeusz.struk@intel.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the Free | ||
| 9 | * Software Foundation; either version 2 of the License, or (at your option) | ||
| 10 | * any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | #ifndef _RSA_HELPER_ | ||
| 14 | #define _RSA_HELPER_ | ||
| 15 | #include <linux/mpi.h> | ||
| 16 | |||
| 17 | struct rsa_key { | ||
| 18 | MPI n; | ||
| 19 | MPI e; | ||
| 20 | MPI d; | ||
| 21 | }; | ||
| 22 | |||
| 23 | int rsa_parse_key(struct rsa_key *rsa_key, const void *key, | ||
| 24 | unsigned int key_len); | ||
| 25 | |||
| 26 | void rsa_free_key(struct rsa_key *rsa_key); | ||
| 27 | #endif | ||
diff --git a/include/crypto/md5.h b/include/crypto/md5.h index 65f299b08b0d..146af825eedb 100644 --- a/include/crypto/md5.h +++ b/include/crypto/md5.h | |||
| @@ -8,6 +8,11 @@ | |||
| 8 | #define MD5_BLOCK_WORDS 16 | 8 | #define MD5_BLOCK_WORDS 16 |
| 9 | #define MD5_HASH_WORDS 4 | 9 | #define MD5_HASH_WORDS 4 |
| 10 | 10 | ||
| 11 | #define MD5_H0 0x67452301UL | ||
| 12 | #define MD5_H1 0xefcdab89UL | ||
| 13 | #define MD5_H2 0x98badcfeUL | ||
| 14 | #define MD5_H3 0x10325476UL | ||
| 15 | |||
| 11 | struct md5_state { | 16 | struct md5_state { |
| 12 | u32 hash[MD5_HASH_WORDS]; | 17 | u32 hash[MD5_HASH_WORDS]; |
| 13 | u32 block[MD5_BLOCK_WORDS]; | 18 | u32 block[MD5_BLOCK_WORDS]; |
diff --git a/include/crypto/null.h b/include/crypto/null.h index b7c864cc70df..06dc30d9f56e 100644 --- a/include/crypto/null.h +++ b/include/crypto/null.h | |||
| @@ -8,4 +8,7 @@ | |||
| 8 | #define NULL_DIGEST_SIZE 0 | 8 | #define NULL_DIGEST_SIZE 0 |
| 9 | #define NULL_IV_SIZE 0 | 9 | #define NULL_IV_SIZE 0 |
| 10 | 10 | ||
| 11 | struct crypto_blkcipher *crypto_get_default_null_skcipher(void); | ||
| 12 | void crypto_put_default_null_skcipher(void); | ||
| 13 | |||
| 11 | #endif | 14 | #endif |
diff --git a/include/crypto/rng.h b/include/crypto/rng.h index 6e28ea5be9f1..b95ede354a66 100644 --- a/include/crypto/rng.h +++ b/include/crypto/rng.h | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * RNG: Random Number Generator algorithms under the crypto API | 2 | * RNG: Random Number Generator algorithms under the crypto API |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com> | 4 | * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com> |
| 5 | * Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au> | ||
| 5 | * | 6 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it | 7 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the Free | 8 | * under the terms of the GNU General Public License as published by the Free |
| @@ -15,6 +16,50 @@ | |||
| 15 | 16 | ||
| 16 | #include <linux/crypto.h> | 17 | #include <linux/crypto.h> |
| 17 | 18 | ||
| 19 | struct crypto_rng; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * struct rng_alg - random number generator definition | ||
| 23 | * | ||
| 24 | * @generate: The function defined by this variable obtains a | ||
| 25 | * random number. The random number generator transform | ||
| 26 | * must generate the random number out of the context | ||
| 27 | * provided with this call, plus any additional data | ||
| 28 | * if provided to the call. | ||
| 29 | * @seed: Seed or reseed the random number generator. With the | ||
| 30 | * invocation of this function call, the random number | ||
| 31 | * generator shall become ready for generation. If the | ||
| 32 | * random number generator requires a seed for setting | ||
| 33 | * up a new state, the seed must be provided by the | ||
| 34 | * consumer while invoking this function. The required | ||
| 35 | * size of the seed is defined with @seedsize . | ||
| 36 | * @set_ent: Set entropy that would otherwise be obtained from | ||
| 37 | * entropy source. Internal use only. | ||
| 38 | * @seedsize: The seed size required for a random number generator | ||
| 39 | * initialization defined with this variable. Some | ||
| 40 | * random number generators does not require a seed | ||
| 41 | * as the seeding is implemented internally without | ||
| 42 | * the need of support by the consumer. In this case, | ||
| 43 | * the seed size is set to zero. | ||
| 44 | * @base: Common crypto API algorithm data structure. | ||
| 45 | */ | ||
| 46 | struct rng_alg { | ||
| 47 | int (*generate)(struct crypto_rng *tfm, | ||
| 48 | const u8 *src, unsigned int slen, | ||
| 49 | u8 *dst, unsigned int dlen); | ||
| 50 | int (*seed)(struct crypto_rng *tfm, const u8 *seed, unsigned int slen); | ||
| 51 | void (*set_ent)(struct crypto_rng *tfm, const u8 *data, | ||
| 52 | unsigned int len); | ||
| 53 | |||
| 54 | unsigned int seedsize; | ||
| 55 | |||
| 56 | struct crypto_alg base; | ||
| 57 | }; | ||
| 58 | |||
| 59 | struct crypto_rng { | ||
| 60 | struct crypto_tfm base; | ||
| 61 | }; | ||
| 62 | |||
| 18 | extern struct crypto_rng *crypto_default_rng; | 63 | extern struct crypto_rng *crypto_default_rng; |
| 19 | 64 | ||
| 20 | int crypto_get_default_rng(void); | 65 | int crypto_get_default_rng(void); |
| @@ -27,11 +72,6 @@ void crypto_put_default_rng(void); | |||
| 27 | * CRYPTO_ALG_TYPE_RNG (listed as type "rng" in /proc/crypto) | 72 | * CRYPTO_ALG_TYPE_RNG (listed as type "rng" in /proc/crypto) |
| 28 | */ | 73 | */ |
| 29 | 74 | ||
| 30 | static inline struct crypto_rng *__crypto_rng_cast(struct crypto_tfm *tfm) | ||
| 31 | { | ||
| 32 | return (struct crypto_rng *)tfm; | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | 75 | /** |
| 36 | * crypto_alloc_rng() -- allocate RNG handle | 76 | * crypto_alloc_rng() -- allocate RNG handle |
| 37 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | 77 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the |
| @@ -52,15 +92,7 @@ static inline struct crypto_rng *__crypto_rng_cast(struct crypto_tfm *tfm) | |||
| 52 | * Return: allocated cipher handle in case of success; IS_ERR() is true in case | 92 | * Return: allocated cipher handle in case of success; IS_ERR() is true in case |
| 53 | * of an error, PTR_ERR() returns the error code. | 93 | * of an error, PTR_ERR() returns the error code. |
| 54 | */ | 94 | */ |
| 55 | static inline struct crypto_rng *crypto_alloc_rng(const char *alg_name, | 95 | struct crypto_rng *crypto_alloc_rng(const char *alg_name, u32 type, u32 mask); |
| 56 | u32 type, u32 mask) | ||
| 57 | { | ||
| 58 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 59 | type |= CRYPTO_ALG_TYPE_RNG; | ||
| 60 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 61 | |||
| 62 | return __crypto_rng_cast(crypto_alloc_base(alg_name, type, mask)); | ||
| 63 | } | ||
| 64 | 96 | ||
| 65 | static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm) | 97 | static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm) |
| 66 | { | 98 | { |
| @@ -77,12 +109,8 @@ static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm) | |||
| 77 | */ | 109 | */ |
| 78 | static inline struct rng_alg *crypto_rng_alg(struct crypto_rng *tfm) | 110 | static inline struct rng_alg *crypto_rng_alg(struct crypto_rng *tfm) |
| 79 | { | 111 | { |
| 80 | return &crypto_rng_tfm(tfm)->__crt_alg->cra_rng; | 112 | return container_of(crypto_rng_tfm(tfm)->__crt_alg, |
| 81 | } | 113 | struct rng_alg, base); |
| 82 | |||
| 83 | static inline struct rng_tfm *crypto_rng_crt(struct crypto_rng *tfm) | ||
| 84 | { | ||
| 85 | return &crypto_rng_tfm(tfm)->crt_rng; | ||
| 86 | } | 114 | } |
| 87 | 115 | ||
| 88 | /** | 116 | /** |
| @@ -91,7 +119,28 @@ static inline struct rng_tfm *crypto_rng_crt(struct crypto_rng *tfm) | |||
| 91 | */ | 119 | */ |
| 92 | static inline void crypto_free_rng(struct crypto_rng *tfm) | 120 | static inline void crypto_free_rng(struct crypto_rng *tfm) |
| 93 | { | 121 | { |
| 94 | crypto_free_tfm(crypto_rng_tfm(tfm)); | 122 | crypto_destroy_tfm(tfm, crypto_rng_tfm(tfm)); |
| 123 | } | ||
| 124 | |||
| 125 | /** | ||
| 126 | * crypto_rng_generate() - get random number | ||
| 127 | * @tfm: cipher handle | ||
| 128 | * @src: Input buffer holding additional data, may be NULL | ||
| 129 | * @slen: Length of additional data | ||
| 130 | * @dst: output buffer holding the random numbers | ||
| 131 | * @dlen: length of the output buffer | ||
| 132 | * | ||
| 133 | * This function fills the caller-allocated buffer with random | ||
| 134 | * numbers using the random number generator referenced by the | ||
| 135 | * cipher handle. | ||
| 136 | * | ||
| 137 | * Return: 0 function was successful; < 0 if an error occurred | ||
| 138 | */ | ||
| 139 | static inline int crypto_rng_generate(struct crypto_rng *tfm, | ||
| 140 | const u8 *src, unsigned int slen, | ||
| 141 | u8 *dst, unsigned int dlen) | ||
| 142 | { | ||
| 143 | return crypto_rng_alg(tfm)->generate(tfm, src, slen, dst, dlen); | ||
| 95 | } | 144 | } |
| 96 | 145 | ||
| 97 | /** | 146 | /** |
| @@ -108,7 +157,7 @@ static inline void crypto_free_rng(struct crypto_rng *tfm) | |||
| 108 | static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, | 157 | static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, |
| 109 | u8 *rdata, unsigned int dlen) | 158 | u8 *rdata, unsigned int dlen) |
| 110 | { | 159 | { |
| 111 | return crypto_rng_crt(tfm)->rng_gen_random(tfm, rdata, dlen); | 160 | return crypto_rng_generate(tfm, NULL, 0, rdata, dlen); |
| 112 | } | 161 | } |
| 113 | 162 | ||
| 114 | /** | 163 | /** |
| @@ -128,11 +177,8 @@ static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, | |||
| 128 | * | 177 | * |
| 129 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | 178 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred |
| 130 | */ | 179 | */ |
| 131 | static inline int crypto_rng_reset(struct crypto_rng *tfm, | 180 | int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, |
| 132 | u8 *seed, unsigned int slen) | 181 | unsigned int slen); |
| 133 | { | ||
| 134 | return crypto_rng_crt(tfm)->rng_reset(tfm, seed, slen); | ||
| 135 | } | ||
| 136 | 182 | ||
| 137 | /** | 183 | /** |
| 138 | * crypto_rng_seedsize() - obtain seed size of RNG | 184 | * crypto_rng_seedsize() - obtain seed size of RNG |
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h index 20e4226a2e14..96670e7e7c14 100644 --- a/include/crypto/scatterwalk.h +++ b/include/crypto/scatterwalk.h | |||
| @@ -102,4 +102,8 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | |||
| 102 | 102 | ||
| 103 | int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes); | 103 | int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes); |
| 104 | 104 | ||
| 105 | struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2], | ||
| 106 | struct scatterlist *src, | ||
| 107 | unsigned int len); | ||
| 108 | |||
| 105 | #endif /* _CRYPTO_SCATTERWALK_H */ | 109 | #endif /* _CRYPTO_SCATTERWALK_H */ |
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 10df5d2d093a..81ef938b0a8e 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 | 53 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 |
| 54 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a | 54 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a |
| 55 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c | 55 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c |
| 56 | #define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d | ||
| 56 | #define CRYPTO_ALG_TYPE_PCOMPRESS 0x0000000f | 57 | #define CRYPTO_ALG_TYPE_PCOMPRESS 0x0000000f |
| 57 | 58 | ||
| 58 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 59 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
| @@ -101,6 +102,12 @@ | |||
| 101 | #define CRYPTO_ALG_INTERNAL 0x00002000 | 102 | #define CRYPTO_ALG_INTERNAL 0x00002000 |
| 102 | 103 | ||
| 103 | /* | 104 | /* |
| 105 | * Temporary flag used to prevent legacy AEAD implementations from | ||
| 106 | * being used by user-space. | ||
| 107 | */ | ||
| 108 | #define CRYPTO_ALG_AEAD_NEW 0x00004000 | ||
| 109 | |||
| 110 | /* | ||
| 104 | * Transform masks and values (for crt_flags). | 111 | * Transform masks and values (for crt_flags). |
| 105 | */ | 112 | */ |
| 106 | #define CRYPTO_TFM_REQ_MASK 0x000fff00 | 113 | #define CRYPTO_TFM_REQ_MASK 0x000fff00 |
| @@ -138,9 +145,9 @@ struct crypto_async_request; | |||
| 138 | struct crypto_aead; | 145 | struct crypto_aead; |
| 139 | struct crypto_blkcipher; | 146 | struct crypto_blkcipher; |
| 140 | struct crypto_hash; | 147 | struct crypto_hash; |
| 141 | struct crypto_rng; | ||
| 142 | struct crypto_tfm; | 148 | struct crypto_tfm; |
| 143 | struct crypto_type; | 149 | struct crypto_type; |
| 150 | struct aead_request; | ||
| 144 | struct aead_givcrypt_request; | 151 | struct aead_givcrypt_request; |
| 145 | struct skcipher_givcrypt_request; | 152 | struct skcipher_givcrypt_request; |
| 146 | 153 | ||
| @@ -175,32 +182,6 @@ struct ablkcipher_request { | |||
| 175 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | 182 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
| 176 | }; | 183 | }; |
| 177 | 184 | ||
| 178 | /** | ||
| 179 | * struct aead_request - AEAD request | ||
| 180 | * @base: Common attributes for async crypto requests | ||
| 181 | * @assoclen: Length in bytes of associated data for authentication | ||
| 182 | * @cryptlen: Length of data to be encrypted or decrypted | ||
| 183 | * @iv: Initialisation vector | ||
| 184 | * @assoc: Associated data | ||
| 185 | * @src: Source data | ||
| 186 | * @dst: Destination data | ||
| 187 | * @__ctx: Start of private context data | ||
| 188 | */ | ||
| 189 | struct aead_request { | ||
| 190 | struct crypto_async_request base; | ||
| 191 | |||
| 192 | unsigned int assoclen; | ||
| 193 | unsigned int cryptlen; | ||
| 194 | |||
| 195 | u8 *iv; | ||
| 196 | |||
| 197 | struct scatterlist *assoc; | ||
| 198 | struct scatterlist *src; | ||
| 199 | struct scatterlist *dst; | ||
| 200 | |||
| 201 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
| 202 | }; | ||
| 203 | |||
| 204 | struct blkcipher_desc { | 185 | struct blkcipher_desc { |
| 205 | struct crypto_blkcipher *tfm; | 186 | struct crypto_blkcipher *tfm; |
| 206 | void *info; | 187 | void *info; |
| @@ -294,7 +275,7 @@ struct ablkcipher_alg { | |||
| 294 | }; | 275 | }; |
| 295 | 276 | ||
| 296 | /** | 277 | /** |
| 297 | * struct aead_alg - AEAD cipher definition | 278 | * struct old_aead_alg - AEAD cipher definition |
| 298 | * @maxauthsize: Set the maximum authentication tag size supported by the | 279 | * @maxauthsize: Set the maximum authentication tag size supported by the |
| 299 | * transformation. A transformation may support smaller tag sizes. | 280 | * transformation. A transformation may support smaller tag sizes. |
| 300 | * As the authentication tag is a message digest to ensure the | 281 | * As the authentication tag is a message digest to ensure the |
| @@ -319,7 +300,7 @@ struct ablkcipher_alg { | |||
| 319 | * All fields except @givencrypt , @givdecrypt , @geniv and @ivsize are | 300 | * All fields except @givencrypt , @givdecrypt , @geniv and @ivsize are |
| 320 | * mandatory and must be filled. | 301 | * mandatory and must be filled. |
| 321 | */ | 302 | */ |
| 322 | struct aead_alg { | 303 | struct old_aead_alg { |
| 323 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | 304 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
| 324 | unsigned int keylen); | 305 | unsigned int keylen); |
| 325 | int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize); | 306 | int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize); |
| @@ -426,40 +407,12 @@ struct compress_alg { | |||
| 426 | unsigned int slen, u8 *dst, unsigned int *dlen); | 407 | unsigned int slen, u8 *dst, unsigned int *dlen); |
| 427 | }; | 408 | }; |
| 428 | 409 | ||
| 429 | /** | ||
| 430 | * struct rng_alg - random number generator definition | ||
| 431 | * @rng_make_random: The function defined by this variable obtains a random | ||
| 432 | * number. The random number generator transform must generate | ||
| 433 | * the random number out of the context provided with this | ||
| 434 | * call. | ||
| 435 | * @rng_reset: Reset of the random number generator by clearing the entire state. | ||
| 436 | * With the invocation of this function call, the random number | ||
| 437 | * generator shall completely reinitialize its state. If the random | ||
| 438 | * number generator requires a seed for setting up a new state, | ||
| 439 | * the seed must be provided by the consumer while invoking this | ||
| 440 | * function. The required size of the seed is defined with | ||
| 441 | * @seedsize . | ||
| 442 | * @seedsize: The seed size required for a random number generator | ||
| 443 | * initialization defined with this variable. Some random number | ||
| 444 | * generators like the SP800-90A DRBG does not require a seed as the | ||
| 445 | * seeding is implemented internally without the need of support by | ||
| 446 | * the consumer. In this case, the seed size is set to zero. | ||
| 447 | */ | ||
| 448 | struct rng_alg { | ||
| 449 | int (*rng_make_random)(struct crypto_rng *tfm, u8 *rdata, | ||
| 450 | unsigned int dlen); | ||
| 451 | int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen); | ||
| 452 | |||
| 453 | unsigned int seedsize; | ||
| 454 | }; | ||
| 455 | |||
| 456 | 410 | ||
| 457 | #define cra_ablkcipher cra_u.ablkcipher | 411 | #define cra_ablkcipher cra_u.ablkcipher |
| 458 | #define cra_aead cra_u.aead | 412 | #define cra_aead cra_u.aead |
| 459 | #define cra_blkcipher cra_u.blkcipher | 413 | #define cra_blkcipher cra_u.blkcipher |
| 460 | #define cra_cipher cra_u.cipher | 414 | #define cra_cipher cra_u.cipher |
| 461 | #define cra_compress cra_u.compress | 415 | #define cra_compress cra_u.compress |
| 462 | #define cra_rng cra_u.rng | ||
| 463 | 416 | ||
| 464 | /** | 417 | /** |
| 465 | * struct crypto_alg - definition of a cryptograpic cipher algorithm | 418 | * struct crypto_alg - definition of a cryptograpic cipher algorithm |
| @@ -505,7 +458,7 @@ struct rng_alg { | |||
| 505 | * transformation algorithm. | 458 | * transformation algorithm. |
| 506 | * @cra_type: Type of the cryptographic transformation. This is a pointer to | 459 | * @cra_type: Type of the cryptographic transformation. This is a pointer to |
| 507 | * struct crypto_type, which implements callbacks common for all | 460 | * struct crypto_type, which implements callbacks common for all |
| 508 | * trasnformation types. There are multiple options: | 461 | * transformation types. There are multiple options: |
| 509 | * &crypto_blkcipher_type, &crypto_ablkcipher_type, | 462 | * &crypto_blkcipher_type, &crypto_ablkcipher_type, |
| 510 | * &crypto_ahash_type, &crypto_aead_type, &crypto_rng_type. | 463 | * &crypto_ahash_type, &crypto_aead_type, &crypto_rng_type. |
| 511 | * This field might be empty. In that case, there are no common | 464 | * This field might be empty. In that case, there are no common |
| @@ -555,11 +508,10 @@ struct crypto_alg { | |||
| 555 | 508 | ||
| 556 | union { | 509 | union { |
| 557 | struct ablkcipher_alg ablkcipher; | 510 | struct ablkcipher_alg ablkcipher; |
| 558 | struct aead_alg aead; | 511 | struct old_aead_alg aead; |
| 559 | struct blkcipher_alg blkcipher; | 512 | struct blkcipher_alg blkcipher; |
| 560 | struct cipher_alg cipher; | 513 | struct cipher_alg cipher; |
| 561 | struct compress_alg compress; | 514 | struct compress_alg compress; |
| 562 | struct rng_alg rng; | ||
| 563 | } cra_u; | 515 | } cra_u; |
| 564 | 516 | ||
| 565 | int (*cra_init)(struct crypto_tfm *tfm); | 517 | int (*cra_init)(struct crypto_tfm *tfm); |
| @@ -567,7 +519,7 @@ struct crypto_alg { | |||
| 567 | void (*cra_destroy)(struct crypto_alg *alg); | 519 | void (*cra_destroy)(struct crypto_alg *alg); |
| 568 | 520 | ||
| 569 | struct module *cra_module; | 521 | struct module *cra_module; |
| 570 | }; | 522 | } CRYPTO_MINALIGN_ATTR; |
| 571 | 523 | ||
| 572 | /* | 524 | /* |
| 573 | * Algorithm registration interface. | 525 | * Algorithm registration interface. |
| @@ -602,21 +554,6 @@ struct ablkcipher_tfm { | |||
| 602 | unsigned int reqsize; | 554 | unsigned int reqsize; |
| 603 | }; | 555 | }; |
| 604 | 556 | ||
| 605 | struct aead_tfm { | ||
| 606 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | ||
| 607 | unsigned int keylen); | ||
| 608 | int (*encrypt)(struct aead_request *req); | ||
| 609 | int (*decrypt)(struct aead_request *req); | ||
| 610 | int (*givencrypt)(struct aead_givcrypt_request *req); | ||
| 611 | int (*givdecrypt)(struct aead_givcrypt_request *req); | ||
| 612 | |||
| 613 | struct crypto_aead *base; | ||
| 614 | |||
| 615 | unsigned int ivsize; | ||
| 616 | unsigned int authsize; | ||
| 617 | unsigned int reqsize; | ||
| 618 | }; | ||
| 619 | |||
| 620 | struct blkcipher_tfm { | 557 | struct blkcipher_tfm { |
| 621 | void *iv; | 558 | void *iv; |
| 622 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, | 559 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, |
| @@ -655,19 +592,11 @@ struct compress_tfm { | |||
| 655 | u8 *dst, unsigned int *dlen); | 592 | u8 *dst, unsigned int *dlen); |
| 656 | }; | 593 | }; |
| 657 | 594 | ||
| 658 | struct rng_tfm { | ||
| 659 | int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata, | ||
| 660 | unsigned int dlen); | ||
| 661 | int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen); | ||
| 662 | }; | ||
| 663 | |||
| 664 | #define crt_ablkcipher crt_u.ablkcipher | 595 | #define crt_ablkcipher crt_u.ablkcipher |
| 665 | #define crt_aead crt_u.aead | ||
| 666 | #define crt_blkcipher crt_u.blkcipher | 596 | #define crt_blkcipher crt_u.blkcipher |
| 667 | #define crt_cipher crt_u.cipher | 597 | #define crt_cipher crt_u.cipher |
| 668 | #define crt_hash crt_u.hash | 598 | #define crt_hash crt_u.hash |
| 669 | #define crt_compress crt_u.compress | 599 | #define crt_compress crt_u.compress |
| 670 | #define crt_rng crt_u.rng | ||
| 671 | 600 | ||
| 672 | struct crypto_tfm { | 601 | struct crypto_tfm { |
| 673 | 602 | ||
| @@ -675,12 +604,10 @@ struct crypto_tfm { | |||
| 675 | 604 | ||
| 676 | union { | 605 | union { |
| 677 | struct ablkcipher_tfm ablkcipher; | 606 | struct ablkcipher_tfm ablkcipher; |
| 678 | struct aead_tfm aead; | ||
| 679 | struct blkcipher_tfm blkcipher; | 607 | struct blkcipher_tfm blkcipher; |
| 680 | struct cipher_tfm cipher; | 608 | struct cipher_tfm cipher; |
| 681 | struct hash_tfm hash; | 609 | struct hash_tfm hash; |
| 682 | struct compress_tfm compress; | 610 | struct compress_tfm compress; |
| 683 | struct rng_tfm rng; | ||
| 684 | } crt_u; | 611 | } crt_u; |
| 685 | 612 | ||
| 686 | void (*exit)(struct crypto_tfm *tfm); | 613 | void (*exit)(struct crypto_tfm *tfm); |
| @@ -694,10 +621,6 @@ struct crypto_ablkcipher { | |||
| 694 | struct crypto_tfm base; | 621 | struct crypto_tfm base; |
| 695 | }; | 622 | }; |
| 696 | 623 | ||
| 697 | struct crypto_aead { | ||
| 698 | struct crypto_tfm base; | ||
| 699 | }; | ||
| 700 | |||
| 701 | struct crypto_blkcipher { | 624 | struct crypto_blkcipher { |
| 702 | struct crypto_tfm base; | 625 | struct crypto_tfm base; |
| 703 | }; | 626 | }; |
| @@ -714,10 +637,6 @@ struct crypto_hash { | |||
| 714 | struct crypto_tfm base; | 637 | struct crypto_tfm base; |
| 715 | }; | 638 | }; |
| 716 | 639 | ||
| 717 | struct crypto_rng { | ||
| 718 | struct crypto_tfm base; | ||
| 719 | }; | ||
| 720 | |||
| 721 | enum { | 640 | enum { |
| 722 | CRYPTOA_UNSPEC, | 641 | CRYPTOA_UNSPEC, |
| 723 | CRYPTOA_ALG, | 642 | CRYPTOA_ALG, |
| @@ -1194,400 +1113,6 @@ static inline void ablkcipher_request_set_crypt( | |||
| 1194 | } | 1113 | } |
| 1195 | 1114 | ||
| 1196 | /** | 1115 | /** |
| 1197 | * DOC: Authenticated Encryption With Associated Data (AEAD) Cipher API | ||
| 1198 | * | ||
| 1199 | * The AEAD cipher API is used with the ciphers of type CRYPTO_ALG_TYPE_AEAD | ||
| 1200 | * (listed as type "aead" in /proc/crypto) | ||
| 1201 | * | ||
| 1202 | * The most prominent examples for this type of encryption is GCM and CCM. | ||
| 1203 | * However, the kernel supports other types of AEAD ciphers which are defined | ||
| 1204 | * with the following cipher string: | ||
| 1205 | * | ||
| 1206 | * authenc(keyed message digest, block cipher) | ||
| 1207 | * | ||
| 1208 | * For example: authenc(hmac(sha256), cbc(aes)) | ||
| 1209 | * | ||
| 1210 | * The example code provided for the asynchronous block cipher operation | ||
| 1211 | * applies here as well. Naturally all *ablkcipher* symbols must be exchanged | ||
| 1212 | * the *aead* pendants discussed in the following. In addtion, for the AEAD | ||
| 1213 | * operation, the aead_request_set_assoc function must be used to set the | ||
| 1214 | * pointer to the associated data memory location before performing the | ||
| 1215 | * encryption or decryption operation. In case of an encryption, the associated | ||
| 1216 | * data memory is filled during the encryption operation. For decryption, the | ||
| 1217 | * associated data memory must contain data that is used to verify the integrity | ||
| 1218 | * of the decrypted data. Another deviation from the asynchronous block cipher | ||
| 1219 | * operation is that the caller should explicitly check for -EBADMSG of the | ||
| 1220 | * crypto_aead_decrypt. That error indicates an authentication error, i.e. | ||
| 1221 | * a breach in the integrity of the message. In essence, that -EBADMSG error | ||
| 1222 | * code is the key bonus an AEAD cipher has over "standard" block chaining | ||
| 1223 | * modes. | ||
| 1224 | */ | ||
| 1225 | |||
| 1226 | static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm) | ||
| 1227 | { | ||
| 1228 | return (struct crypto_aead *)tfm; | ||
| 1229 | } | ||
| 1230 | |||
| 1231 | /** | ||
| 1232 | * crypto_alloc_aead() - allocate AEAD cipher handle | ||
| 1233 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
| 1234 | * AEAD cipher | ||
| 1235 | * @type: specifies the type of the cipher | ||
| 1236 | * @mask: specifies the mask for the cipher | ||
| 1237 | * | ||
| 1238 | * Allocate a cipher handle for an AEAD. The returned struct | ||
| 1239 | * crypto_aead is the cipher handle that is required for any subsequent | ||
| 1240 | * API invocation for that AEAD. | ||
| 1241 | * | ||
| 1242 | * Return: allocated cipher handle in case of success; IS_ERR() is true in case | ||
| 1243 | * of an error, PTR_ERR() returns the error code. | ||
| 1244 | */ | ||
| 1245 | struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask); | ||
| 1246 | |||
| 1247 | static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) | ||
| 1248 | { | ||
| 1249 | return &tfm->base; | ||
| 1250 | } | ||
| 1251 | |||
| 1252 | /** | ||
| 1253 | * crypto_free_aead() - zeroize and free aead handle | ||
| 1254 | * @tfm: cipher handle to be freed | ||
| 1255 | */ | ||
| 1256 | static inline void crypto_free_aead(struct crypto_aead *tfm) | ||
| 1257 | { | ||
| 1258 | crypto_free_tfm(crypto_aead_tfm(tfm)); | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | static inline struct aead_tfm *crypto_aead_crt(struct crypto_aead *tfm) | ||
| 1262 | { | ||
| 1263 | return &crypto_aead_tfm(tfm)->crt_aead; | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | /** | ||
| 1267 | * crypto_aead_ivsize() - obtain IV size | ||
| 1268 | * @tfm: cipher handle | ||
| 1269 | * | ||
| 1270 | * The size of the IV for the aead referenced by the cipher handle is | ||
| 1271 | * returned. This IV size may be zero if the cipher does not need an IV. | ||
| 1272 | * | ||
| 1273 | * Return: IV size in bytes | ||
| 1274 | */ | ||
| 1275 | static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm) | ||
| 1276 | { | ||
| 1277 | return crypto_aead_crt(tfm)->ivsize; | ||
| 1278 | } | ||
| 1279 | |||
| 1280 | /** | ||
| 1281 | * crypto_aead_authsize() - obtain maximum authentication data size | ||
| 1282 | * @tfm: cipher handle | ||
| 1283 | * | ||
| 1284 | * The maximum size of the authentication data for the AEAD cipher referenced | ||
| 1285 | * by the AEAD cipher handle is returned. The authentication data size may be | ||
| 1286 | * zero if the cipher implements a hard-coded maximum. | ||
| 1287 | * | ||
| 1288 | * The authentication data may also be known as "tag value". | ||
| 1289 | * | ||
| 1290 | * Return: authentication data size / tag size in bytes | ||
| 1291 | */ | ||
| 1292 | static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm) | ||
| 1293 | { | ||
| 1294 | return crypto_aead_crt(tfm)->authsize; | ||
| 1295 | } | ||
| 1296 | |||
| 1297 | /** | ||
| 1298 | * crypto_aead_blocksize() - obtain block size of cipher | ||
| 1299 | * @tfm: cipher handle | ||
| 1300 | * | ||
| 1301 | * The block size for the AEAD referenced with the cipher handle is returned. | ||
| 1302 | * The caller may use that information to allocate appropriate memory for the | ||
| 1303 | * data returned by the encryption or decryption operation | ||
| 1304 | * | ||
| 1305 | * Return: block size of cipher | ||
| 1306 | */ | ||
| 1307 | static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm) | ||
| 1308 | { | ||
| 1309 | return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm)); | ||
| 1310 | } | ||
| 1311 | |||
| 1312 | static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm) | ||
| 1313 | { | ||
| 1314 | return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm)); | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm) | ||
| 1318 | { | ||
| 1319 | return crypto_tfm_get_flags(crypto_aead_tfm(tfm)); | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags) | ||
| 1323 | { | ||
| 1324 | crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags); | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags) | ||
| 1328 | { | ||
| 1329 | crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags); | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | /** | ||
| 1333 | * crypto_aead_setkey() - set key for cipher | ||
| 1334 | * @tfm: cipher handle | ||
| 1335 | * @key: buffer holding the key | ||
| 1336 | * @keylen: length of the key in bytes | ||
| 1337 | * | ||
| 1338 | * The caller provided key is set for the AEAD referenced by the cipher | ||
| 1339 | * handle. | ||
| 1340 | * | ||
| 1341 | * Note, the key length determines the cipher type. Many block ciphers implement | ||
| 1342 | * different cipher modes depending on the key size, such as AES-128 vs AES-192 | ||
| 1343 | * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128 | ||
| 1344 | * is performed. | ||
| 1345 | * | ||
| 1346 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | ||
| 1347 | */ | ||
| 1348 | static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key, | ||
| 1349 | unsigned int keylen) | ||
| 1350 | { | ||
| 1351 | struct aead_tfm *crt = crypto_aead_crt(tfm); | ||
| 1352 | |||
| 1353 | return crt->setkey(crt->base, key, keylen); | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | /** | ||
| 1357 | * crypto_aead_setauthsize() - set authentication data size | ||
| 1358 | * @tfm: cipher handle | ||
| 1359 | * @authsize: size of the authentication data / tag in bytes | ||
| 1360 | * | ||
| 1361 | * Set the authentication data size / tag size. AEAD requires an authentication | ||
| 1362 | * tag (or MAC) in addition to the associated data. | ||
| 1363 | * | ||
| 1364 | * Return: 0 if the setting of the key was successful; < 0 if an error occurred | ||
| 1365 | */ | ||
| 1366 | int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); | ||
| 1367 | |||
| 1368 | static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) | ||
| 1369 | { | ||
| 1370 | return __crypto_aead_cast(req->base.tfm); | ||
| 1371 | } | ||
| 1372 | |||
| 1373 | /** | ||
| 1374 | * crypto_aead_encrypt() - encrypt plaintext | ||
| 1375 | * @req: reference to the aead_request handle that holds all information | ||
| 1376 | * needed to perform the cipher operation | ||
| 1377 | * | ||
| 1378 | * Encrypt plaintext data using the aead_request handle. That data structure | ||
| 1379 | * and how it is filled with data is discussed with the aead_request_* | ||
| 1380 | * functions. | ||
| 1381 | * | ||
| 1382 | * IMPORTANT NOTE The encryption operation creates the authentication data / | ||
| 1383 | * tag. That data is concatenated with the created ciphertext. | ||
| 1384 | * The ciphertext memory size is therefore the given number of | ||
| 1385 | * block cipher blocks + the size defined by the | ||
| 1386 | * crypto_aead_setauthsize invocation. The caller must ensure | ||
| 1387 | * that sufficient memory is available for the ciphertext and | ||
| 1388 | * the authentication tag. | ||
| 1389 | * | ||
| 1390 | * Return: 0 if the cipher operation was successful; < 0 if an error occurred | ||
| 1391 | */ | ||
| 1392 | static inline int crypto_aead_encrypt(struct aead_request *req) | ||
| 1393 | { | ||
| 1394 | return crypto_aead_crt(crypto_aead_reqtfm(req))->encrypt(req); | ||
| 1395 | } | ||
| 1396 | |||
| 1397 | /** | ||
| 1398 | * crypto_aead_decrypt() - decrypt ciphertext | ||
| 1399 | * @req: reference to the ablkcipher_request handle that holds all information | ||
| 1400 | * needed to perform the cipher operation | ||
| 1401 | * | ||
| 1402 | * Decrypt ciphertext data using the aead_request handle. That data structure | ||
| 1403 | * and how it is filled with data is discussed with the aead_request_* | ||
| 1404 | * functions. | ||
| 1405 | * | ||
| 1406 | * IMPORTANT NOTE The caller must concatenate the ciphertext followed by the | ||
| 1407 | * authentication data / tag. That authentication data / tag | ||
| 1408 | * must have the size defined by the crypto_aead_setauthsize | ||
| 1409 | * invocation. | ||
| 1410 | * | ||
| 1411 | * | ||
| 1412 | * Return: 0 if the cipher operation was successful; -EBADMSG: The AEAD | ||
| 1413 | * cipher operation performs the authentication of the data during the | ||
| 1414 | * decryption operation. Therefore, the function returns this error if | ||
| 1415 | * the authentication of the ciphertext was unsuccessful (i.e. the | ||
| 1416 | * integrity of the ciphertext or the associated data was violated); | ||
| 1417 | * < 0 if an error occurred. | ||
| 1418 | */ | ||
| 1419 | static inline int crypto_aead_decrypt(struct aead_request *req) | ||
| 1420 | { | ||
| 1421 | if (req->cryptlen < crypto_aead_authsize(crypto_aead_reqtfm(req))) | ||
| 1422 | return -EINVAL; | ||
| 1423 | |||
| 1424 | return crypto_aead_crt(crypto_aead_reqtfm(req))->decrypt(req); | ||
| 1425 | } | ||
| 1426 | |||
| 1427 | /** | ||
| 1428 | * DOC: Asynchronous AEAD Request Handle | ||
| 1429 | * | ||
| 1430 | * The aead_request data structure contains all pointers to data required for | ||
| 1431 | * the AEAD cipher operation. This includes the cipher handle (which can be | ||
| 1432 | * used by multiple aead_request instances), pointer to plaintext and | ||
| 1433 | * ciphertext, asynchronous callback function, etc. It acts as a handle to the | ||
| 1434 | * aead_request_* API calls in a similar way as AEAD handle to the | ||
| 1435 | * crypto_aead_* API calls. | ||
| 1436 | */ | ||
| 1437 | |||
| 1438 | /** | ||
| 1439 | * crypto_aead_reqsize() - obtain size of the request data structure | ||
| 1440 | * @tfm: cipher handle | ||
| 1441 | * | ||
| 1442 | * Return: number of bytes | ||
| 1443 | */ | ||
| 1444 | static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm) | ||
| 1445 | { | ||
| 1446 | return crypto_aead_crt(tfm)->reqsize; | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | /** | ||
| 1450 | * aead_request_set_tfm() - update cipher handle reference in request | ||
| 1451 | * @req: request handle to be modified | ||
| 1452 | * @tfm: cipher handle that shall be added to the request handle | ||
| 1453 | * | ||
| 1454 | * Allow the caller to replace the existing aead handle in the request | ||
| 1455 | * data structure with a different one. | ||
| 1456 | */ | ||
| 1457 | static inline void aead_request_set_tfm(struct aead_request *req, | ||
| 1458 | struct crypto_aead *tfm) | ||
| 1459 | { | ||
| 1460 | req->base.tfm = crypto_aead_tfm(crypto_aead_crt(tfm)->base); | ||
| 1461 | } | ||
| 1462 | |||
| 1463 | /** | ||
| 1464 | * aead_request_alloc() - allocate request data structure | ||
| 1465 | * @tfm: cipher handle to be registered with the request | ||
| 1466 | * @gfp: memory allocation flag that is handed to kmalloc by the API call. | ||
| 1467 | * | ||
| 1468 | * Allocate the request data structure that must be used with the AEAD | ||
| 1469 | * encrypt and decrypt API calls. During the allocation, the provided aead | ||
| 1470 | * handle is registered in the request data structure. | ||
| 1471 | * | ||
| 1472 | * Return: allocated request handle in case of success; IS_ERR() is true in case | ||
| 1473 | * of an error, PTR_ERR() returns the error code. | ||
| 1474 | */ | ||
| 1475 | static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, | ||
| 1476 | gfp_t gfp) | ||
| 1477 | { | ||
| 1478 | struct aead_request *req; | ||
| 1479 | |||
| 1480 | req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp); | ||
| 1481 | |||
| 1482 | if (likely(req)) | ||
| 1483 | aead_request_set_tfm(req, tfm); | ||
| 1484 | |||
| 1485 | return req; | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | /** | ||
| 1489 | * aead_request_free() - zeroize and free request data structure | ||
| 1490 | * @req: request data structure cipher handle to be freed | ||
| 1491 | */ | ||
| 1492 | static inline void aead_request_free(struct aead_request *req) | ||
| 1493 | { | ||
| 1494 | kzfree(req); | ||
| 1495 | } | ||
| 1496 | |||
| 1497 | /** | ||
| 1498 | * aead_request_set_callback() - set asynchronous callback function | ||
| 1499 | * @req: request handle | ||
| 1500 | * @flags: specify zero or an ORing of the flags | ||
| 1501 | * CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and | ||
| 1502 | * increase the wait queue beyond the initial maximum size; | ||
| 1503 | * CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep | ||
| 1504 | * @compl: callback function pointer to be registered with the request handle | ||
| 1505 | * @data: The data pointer refers to memory that is not used by the kernel | ||
| 1506 | * crypto API, but provided to the callback function for it to use. Here, | ||
| 1507 | * the caller can provide a reference to memory the callback function can | ||
| 1508 | * operate on. As the callback function is invoked asynchronously to the | ||
| 1509 | * related functionality, it may need to access data structures of the | ||
| 1510 | * related functionality which can be referenced using this pointer. The | ||
| 1511 | * callback function can access the memory via the "data" field in the | ||
| 1512 | * crypto_async_request data structure provided to the callback function. | ||
| 1513 | * | ||
| 1514 | * Setting the callback function that is triggered once the cipher operation | ||
| 1515 | * completes | ||
| 1516 | * | ||
| 1517 | * The callback function is registered with the aead_request handle and | ||
| 1518 | * must comply with the following template | ||
| 1519 | * | ||
| 1520 | * void callback_function(struct crypto_async_request *req, int error) | ||
| 1521 | */ | ||
| 1522 | static inline void aead_request_set_callback(struct aead_request *req, | ||
| 1523 | u32 flags, | ||
| 1524 | crypto_completion_t compl, | ||
| 1525 | void *data) | ||
| 1526 | { | ||
| 1527 | req->base.complete = compl; | ||
| 1528 | req->base.data = data; | ||
| 1529 | req->base.flags = flags; | ||
| 1530 | } | ||
| 1531 | |||
| 1532 | /** | ||
| 1533 | * aead_request_set_crypt - set data buffers | ||
| 1534 | * @req: request handle | ||
| 1535 | * @src: source scatter / gather list | ||
| 1536 | * @dst: destination scatter / gather list | ||
| 1537 | * @cryptlen: number of bytes to process from @src | ||
| 1538 | * @iv: IV for the cipher operation which must comply with the IV size defined | ||
| 1539 | * by crypto_aead_ivsize() | ||
| 1540 | * | ||
| 1541 | * Setting the source data and destination data scatter / gather lists. | ||
| 1542 | * | ||
| 1543 | * For encryption, the source is treated as the plaintext and the | ||
| 1544 | * destination is the ciphertext. For a decryption operation, the use is | ||
| 1545 | * reversed - the source is the ciphertext and the destination is the plaintext. | ||
| 1546 | * | ||
| 1547 | * IMPORTANT NOTE AEAD requires an authentication tag (MAC). For decryption, | ||
| 1548 | * the caller must concatenate the ciphertext followed by the | ||
| 1549 | * authentication tag and provide the entire data stream to the | ||
| 1550 | * decryption operation (i.e. the data length used for the | ||
| 1551 | * initialization of the scatterlist and the data length for the | ||
| 1552 | * decryption operation is identical). For encryption, however, | ||
| 1553 | * the authentication tag is created while encrypting the data. | ||
| 1554 | * The destination buffer must hold sufficient space for the | ||
| 1555 | * ciphertext and the authentication tag while the encryption | ||
| 1556 | * invocation must only point to the plaintext data size. The | ||
| 1557 | * following code snippet illustrates the memory usage | ||
| 1558 | * buffer = kmalloc(ptbuflen + (enc ? authsize : 0)); | ||
| 1559 | * sg_init_one(&sg, buffer, ptbuflen + (enc ? authsize : 0)); | ||
| 1560 | * aead_request_set_crypt(req, &sg, &sg, ptbuflen, iv); | ||
| 1561 | */ | ||
| 1562 | static inline void aead_request_set_crypt(struct aead_request *req, | ||
| 1563 | struct scatterlist *src, | ||
| 1564 | struct scatterlist *dst, | ||
| 1565 | unsigned int cryptlen, u8 *iv) | ||
| 1566 | { | ||
| 1567 | req->src = src; | ||
| 1568 | req->dst = dst; | ||
| 1569 | req->cryptlen = cryptlen; | ||
| 1570 | req->iv = iv; | ||
| 1571 | } | ||
| 1572 | |||
| 1573 | /** | ||
| 1574 | * aead_request_set_assoc() - set the associated data scatter / gather list | ||
| 1575 | * @req: request handle | ||
| 1576 | * @assoc: associated data scatter / gather list | ||
| 1577 | * @assoclen: number of bytes to process from @assoc | ||
| 1578 | * | ||
| 1579 | * For encryption, the memory is filled with the associated data. For | ||
| 1580 | * decryption, the memory must point to the associated data. | ||
| 1581 | */ | ||
| 1582 | static inline void aead_request_set_assoc(struct aead_request *req, | ||
| 1583 | struct scatterlist *assoc, | ||
| 1584 | unsigned int assoclen) | ||
| 1585 | { | ||
| 1586 | req->assoc = assoc; | ||
| 1587 | req->assoclen = assoclen; | ||
| 1588 | } | ||
| 1589 | |||
| 1590 | /** | ||
| 1591 | * DOC: Synchronous Block Cipher API | 1116 | * DOC: Synchronous Block Cipher API |
| 1592 | * | 1117 | * |
| 1593 | * The synchronous block cipher API is used with the ciphers of type | 1118 | * The synchronous block cipher API is used with the ciphers of type |
diff --git a/include/linux/mbus.h b/include/linux/mbus.h index 611b69fa8594..1f7bc630d225 100644 --- a/include/linux/mbus.h +++ b/include/linux/mbus.h | |||
| @@ -54,11 +54,16 @@ struct mbus_dram_target_info | |||
| 54 | */ | 54 | */ |
| 55 | #ifdef CONFIG_PLAT_ORION | 55 | #ifdef CONFIG_PLAT_ORION |
| 56 | extern const struct mbus_dram_target_info *mv_mbus_dram_info(void); | 56 | extern const struct mbus_dram_target_info *mv_mbus_dram_info(void); |
| 57 | extern const struct mbus_dram_target_info *mv_mbus_dram_info_nooverlap(void); | ||
| 57 | #else | 58 | #else |
| 58 | static inline const struct mbus_dram_target_info *mv_mbus_dram_info(void) | 59 | static inline const struct mbus_dram_target_info *mv_mbus_dram_info(void) |
| 59 | { | 60 | { |
| 60 | return NULL; | 61 | return NULL; |
| 61 | } | 62 | } |
| 63 | static inline const struct mbus_dram_target_info *mv_mbus_dram_info_nooverlap(void) | ||
| 64 | { | ||
| 65 | return NULL; | ||
| 66 | } | ||
| 62 | #endif | 67 | #endif |
| 63 | 68 | ||
| 64 | int mvebu_mbus_save_cpu_target(u32 *store_addr); | 69 | int mvebu_mbus_save_cpu_target(u32 *store_addr); |
diff --git a/include/linux/module.h b/include/linux/module.h index c883b86ea964..1e5436042eb0 100644 --- a/include/linux/module.h +++ b/include/linux/module.h | |||
| @@ -655,4 +655,16 @@ static inline void module_bug_finalize(const Elf_Ehdr *hdr, | |||
| 655 | static inline void module_bug_cleanup(struct module *mod) {} | 655 | static inline void module_bug_cleanup(struct module *mod) {} |
| 656 | #endif /* CONFIG_GENERIC_BUG */ | 656 | #endif /* CONFIG_GENERIC_BUG */ |
| 657 | 657 | ||
| 658 | #ifdef CONFIG_MODULE_SIG | ||
| 659 | static inline bool module_sig_ok(struct module *module) | ||
| 660 | { | ||
| 661 | return module->sig_ok; | ||
| 662 | } | ||
| 663 | #else /* !CONFIG_MODULE_SIG */ | ||
| 664 | static inline bool module_sig_ok(struct module *module) | ||
| 665 | { | ||
| 666 | return true; | ||
| 667 | } | ||
| 668 | #endif /* CONFIG_MODULE_SIG */ | ||
| 669 | |||
| 658 | #endif /* _LINUX_MODULE_H */ | 670 | #endif /* _LINUX_MODULE_H */ |
diff --git a/include/linux/mpi.h b/include/linux/mpi.h index 5af1b81def49..641b7d6fd096 100644 --- a/include/linux/mpi.h +++ b/include/linux/mpi.h | |||
| @@ -81,6 +81,8 @@ MPI mpi_read_from_buffer(const void *buffer, unsigned *ret_nread); | |||
| 81 | int mpi_fromstr(MPI val, const char *str); | 81 | int mpi_fromstr(MPI val, const char *str); |
| 82 | u32 mpi_get_keyid(MPI a, u32 *keyid); | 82 | u32 mpi_get_keyid(MPI a, u32 *keyid); |
| 83 | void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign); | 83 | void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign); |
| 84 | int mpi_read_buffer(MPI a, uint8_t *buf, unsigned buf_len, unsigned *nbytes, | ||
| 85 | int *sign); | ||
| 84 | void *mpi_get_secure_buffer(MPI a, unsigned *nbytes, int *sign); | 86 | void *mpi_get_secure_buffer(MPI a, unsigned *nbytes, int *sign); |
| 85 | int mpi_set_buffer(MPI a, const void *buffer, unsigned nbytes, int sign); | 87 | int mpi_set_buffer(MPI a, const void *buffer, unsigned nbytes, int sign); |
| 86 | 88 | ||
| @@ -142,4 +144,17 @@ int mpi_rshift(MPI x, MPI a, unsigned n); | |||
| 142 | /*-- mpi-inv.c --*/ | 144 | /*-- mpi-inv.c --*/ |
| 143 | int mpi_invm(MPI x, MPI u, MPI v); | 145 | int mpi_invm(MPI x, MPI u, MPI v); |
| 144 | 146 | ||
| 147 | /* inline functions */ | ||
| 148 | |||
| 149 | /** | ||
| 150 | * mpi_get_size() - returns max size required to store the number | ||
| 151 | * | ||
| 152 | * @a: A multi precision integer for which we want to allocate a bufer | ||
| 153 | * | ||
| 154 | * Return: size required to store the number | ||
| 155 | */ | ||
| 156 | static inline unsigned int mpi_get_size(MPI a) | ||
| 157 | { | ||
| 158 | return a->nlimbs * BYTES_PER_MPI_LIMB; | ||
| 159 | } | ||
| 145 | #endif /*G10_MPI_H */ | 160 | #endif /*G10_MPI_H */ |
diff --git a/include/linux/nx842.h b/include/linux/nx842.h deleted file mode 100644 index a4d324c6406a..000000000000 --- a/include/linux/nx842.h +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | #ifndef __NX842_H__ | ||
| 2 | #define __NX842_H__ | ||
| 3 | |||
| 4 | int nx842_get_workmem_size(void); | ||
| 5 | int nx842_get_workmem_size_aligned(void); | ||
| 6 | int nx842_compress(const unsigned char *in, unsigned int in_len, | ||
| 7 | unsigned char *out, unsigned int *out_len, void *wrkmem); | ||
| 8 | int nx842_decompress(const unsigned char *in, unsigned int in_len, | ||
| 9 | unsigned char *out, unsigned int *out_len, void *wrkmem); | ||
| 10 | |||
| 11 | #endif | ||
diff --git a/include/linux/random.h b/include/linux/random.h index b05856e16b75..e651874df2c9 100644 --- a/include/linux/random.h +++ b/include/linux/random.h | |||
| @@ -6,14 +6,23 @@ | |||
| 6 | #ifndef _LINUX_RANDOM_H | 6 | #ifndef _LINUX_RANDOM_H |
| 7 | #define _LINUX_RANDOM_H | 7 | #define _LINUX_RANDOM_H |
| 8 | 8 | ||
| 9 | #include <linux/list.h> | ||
| 9 | #include <uapi/linux/random.h> | 10 | #include <uapi/linux/random.h> |
| 10 | 11 | ||
| 12 | struct random_ready_callback { | ||
| 13 | struct list_head list; | ||
| 14 | void (*func)(struct random_ready_callback *rdy); | ||
| 15 | struct module *owner; | ||
| 16 | }; | ||
| 17 | |||
| 11 | extern void add_device_randomness(const void *, unsigned int); | 18 | extern void add_device_randomness(const void *, unsigned int); |
| 12 | extern void add_input_randomness(unsigned int type, unsigned int code, | 19 | extern void add_input_randomness(unsigned int type, unsigned int code, |
| 13 | unsigned int value); | 20 | unsigned int value); |
| 14 | extern void add_interrupt_randomness(int irq, int irq_flags); | 21 | extern void add_interrupt_randomness(int irq, int irq_flags); |
| 15 | 22 | ||
| 16 | extern void get_random_bytes(void *buf, int nbytes); | 23 | extern void get_random_bytes(void *buf, int nbytes); |
| 24 | extern int add_random_ready_callback(struct random_ready_callback *rdy); | ||
| 25 | extern void del_random_ready_callback(struct random_ready_callback *rdy); | ||
| 17 | extern void get_random_bytes_arch(void *buf, int nbytes); | 26 | extern void get_random_bytes_arch(void *buf, int nbytes); |
| 18 | void generate_random_uuid(unsigned char uuid_out[16]); | 27 | void generate_random_uuid(unsigned char uuid_out[16]); |
| 19 | extern int random_int_secret_init(void); | 28 | extern int random_int_secret_init(void); |
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index ed8f9e70df9b..a0edb992c9c3 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h | |||
| @@ -221,6 +221,7 @@ static inline void *sg_virt(struct scatterlist *sg) | |||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | int sg_nents(struct scatterlist *sg); | 223 | int sg_nents(struct scatterlist *sg); |
| 224 | int sg_nents_for_len(struct scatterlist *sg, u64 len); | ||
| 224 | struct scatterlist *sg_next(struct scatterlist *); | 225 | struct scatterlist *sg_next(struct scatterlist *); |
| 225 | struct scatterlist *sg_last(struct scatterlist *s, unsigned int); | 226 | struct scatterlist *sg_last(struct scatterlist *s, unsigned int); |
| 226 | void sg_init_table(struct scatterlist *, unsigned int); | 227 | void sg_init_table(struct scatterlist *, unsigned int); |
diff --git a/include/linux/sw842.h b/include/linux/sw842.h new file mode 100644 index 000000000000..109ba041c2ae --- /dev/null +++ b/include/linux/sw842.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #ifndef __SW842_H__ | ||
| 2 | #define __SW842_H__ | ||
| 3 | |||
| 4 | #define SW842_MEM_COMPRESS (0xf000) | ||
| 5 | |||
| 6 | int sw842_compress(const u8 *src, unsigned int srclen, | ||
| 7 | u8 *dst, unsigned int *destlen, void *wmem); | ||
| 8 | |||
| 9 | int sw842_decompress(const u8 *src, unsigned int srclen, | ||
| 10 | u8 *dst, unsigned int *destlen); | ||
| 11 | |||
| 12 | #endif | ||
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 36ac102c97c7..f0ee97eec24d 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
| @@ -168,6 +168,7 @@ struct xfrm_state { | |||
| 168 | struct xfrm_algo *ealg; | 168 | struct xfrm_algo *ealg; |
| 169 | struct xfrm_algo *calg; | 169 | struct xfrm_algo *calg; |
| 170 | struct xfrm_algo_aead *aead; | 170 | struct xfrm_algo_aead *aead; |
| 171 | const char *geniv; | ||
| 171 | 172 | ||
| 172 | /* Data for encapsulator */ | 173 | /* Data for encapsulator */ |
| 173 | struct xfrm_encap_tmpl *encap; | 174 | struct xfrm_encap_tmpl *encap; |
| @@ -1314,6 +1315,7 @@ static inline int xfrm_id_proto_match(u8 proto, u8 userproto) | |||
| 1314 | * xfrm algorithm information | 1315 | * xfrm algorithm information |
| 1315 | */ | 1316 | */ |
| 1316 | struct xfrm_algo_aead_info { | 1317 | struct xfrm_algo_aead_info { |
| 1318 | char *geniv; | ||
| 1317 | u16 icv_truncbits; | 1319 | u16 icv_truncbits; |
| 1318 | }; | 1320 | }; |
| 1319 | 1321 | ||
| @@ -1323,6 +1325,7 @@ struct xfrm_algo_auth_info { | |||
| 1323 | }; | 1325 | }; |
| 1324 | 1326 | ||
| 1325 | struct xfrm_algo_encr_info { | 1327 | struct xfrm_algo_encr_info { |
| 1328 | char *geniv; | ||
| 1326 | u16 blockbits; | 1329 | u16 blockbits; |
| 1327 | u16 defkeybits; | 1330 | u16 defkeybits; |
| 1328 | }; | 1331 | }; |
diff --git a/include/linux/cryptouser.h b/include/uapi/linux/cryptouser.h index 4abf2ea6a887..2e67bb64c1da 100644 --- a/include/linux/cryptouser.h +++ b/include/uapi/linux/cryptouser.h | |||
| @@ -25,6 +25,7 @@ enum { | |||
| 25 | CRYPTO_MSG_DELALG, | 25 | CRYPTO_MSG_DELALG, |
| 26 | CRYPTO_MSG_UPDATEALG, | 26 | CRYPTO_MSG_UPDATEALG, |
| 27 | CRYPTO_MSG_GETALG, | 27 | CRYPTO_MSG_GETALG, |
| 28 | CRYPTO_MSG_DELRNG, | ||
| 28 | __CRYPTO_MSG_MAX | 29 | __CRYPTO_MSG_MAX |
| 29 | }; | 30 | }; |
| 30 | #define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1) | 31 | #define CRYPTO_MSG_MAX (__CRYPTO_MSG_MAX - 1) |
| @@ -43,6 +44,7 @@ enum crypto_attr_type_t { | |||
| 43 | CRYPTOCFGA_REPORT_COMPRESS, /* struct crypto_report_comp */ | 44 | CRYPTOCFGA_REPORT_COMPRESS, /* struct crypto_report_comp */ |
| 44 | CRYPTOCFGA_REPORT_RNG, /* struct crypto_report_rng */ | 45 | CRYPTOCFGA_REPORT_RNG, /* struct crypto_report_rng */ |
| 45 | CRYPTOCFGA_REPORT_CIPHER, /* struct crypto_report_cipher */ | 46 | CRYPTOCFGA_REPORT_CIPHER, /* struct crypto_report_cipher */ |
| 47 | CRYPTOCFGA_REPORT_AKCIPHER, /* struct crypto_report_akcipher */ | ||
| 46 | __CRYPTOCFGA_MAX | 48 | __CRYPTOCFGA_MAX |
| 47 | 49 | ||
| 48 | #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1) | 50 | #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1) |
| @@ -101,5 +103,9 @@ struct crypto_report_rng { | |||
| 101 | unsigned int seedsize; | 103 | unsigned int seedsize; |
| 102 | }; | 104 | }; |
| 103 | 105 | ||
| 106 | struct crypto_report_akcipher { | ||
| 107 | char type[CRYPTO_MAX_NAME]; | ||
| 108 | }; | ||
| 109 | |||
| 104 | #define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \ | 110 | #define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \ |
| 105 | sizeof(struct crypto_report_blkcipher)) | 111 | sizeof(struct crypto_report_blkcipher)) |
