diff options
-rw-r--r-- | include/linux/crypto.h | 246 |
1 files changed, 243 insertions, 3 deletions
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index d45e949699ea..752360e1e8fe 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -127,6 +127,13 @@ struct skcipher_givcrypt_request; | |||
127 | 127 | ||
128 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); | 128 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); |
129 | 129 | ||
130 | /** | ||
131 | * DOC: Block Cipher Context Data Structures | ||
132 | * | ||
133 | * These data structures define the operating context for each block cipher | ||
134 | * type. | ||
135 | */ | ||
136 | |||
130 | struct crypto_async_request { | 137 | struct crypto_async_request { |
131 | struct list_head list; | 138 | struct list_head list; |
132 | crypto_completion_t complete; | 139 | crypto_completion_t complete; |
@@ -194,9 +201,63 @@ struct hash_desc { | |||
194 | u32 flags; | 201 | u32 flags; |
195 | }; | 202 | }; |
196 | 203 | ||
197 | /* | 204 | /** |
198 | * Algorithms: modular crypto algorithm implementations, managed | 205 | * DOC: Block Cipher Algorithm Definitions |
199 | * via crypto_register_alg() and crypto_unregister_alg(). | 206 | * |
207 | * These data structures define modular crypto algorithm implementations, | ||
208 | * managed via crypto_register_alg() and crypto_unregister_alg(). | ||
209 | */ | ||
210 | |||
211 | /** | ||
212 | * struct ablkcipher_alg - asynchronous block cipher definition | ||
213 | * @min_keysize: Minimum key size supported by the transformation. This is the | ||
214 | * smallest key length supported by this transformation algorithm. | ||
215 | * This must be set to one of the pre-defined values as this is | ||
216 | * not hardware specific. Possible values for this field can be | ||
217 | * found via git grep "_MIN_KEY_SIZE" include/crypto/ | ||
218 | * @max_keysize: Maximum key size supported by the transformation. This is the | ||
219 | * largest key length supported by this transformation algorithm. | ||
220 | * This must be set to one of the pre-defined values as this is | ||
221 | * not hardware specific. Possible values for this field can be | ||
222 | * found via git grep "_MAX_KEY_SIZE" include/crypto/ | ||
223 | * @setkey: Set key for the transformation. This function is used to either | ||
224 | * program a supplied key into the hardware or store the key in the | ||
225 | * transformation context for programming it later. Note that this | ||
226 | * function does modify the transformation context. This function can | ||
227 | * be called multiple times during the existence of the transformation | ||
228 | * object, so one must make sure the key is properly reprogrammed into | ||
229 | * the hardware. This function is also responsible for checking the key | ||
230 | * length for validity. In case a software fallback was put in place in | ||
231 | * the @cra_init call, this function might need to use the fallback if | ||
232 | * the algorithm doesn't support all of the key sizes. | ||
233 | * @encrypt: Encrypt a scatterlist of blocks. This function is used to encrypt | ||
234 | * the supplied scatterlist containing the blocks of data. The crypto | ||
235 | * API consumer is responsible for aligning the entries of the | ||
236 | * scatterlist properly and making sure the chunks are correctly | ||
237 | * sized. In case a software fallback was put in place in the | ||
238 | * @cra_init call, this function might need to use the fallback if | ||
239 | * the algorithm doesn't support all of the key sizes. In case the | ||
240 | * key was stored in transformation context, the key might need to be | ||
241 | * re-programmed into the hardware in this function. This function | ||
242 | * shall not modify the transformation context, as this function may | ||
243 | * be called in parallel with the same transformation object. | ||
244 | * @decrypt: Decrypt a single block. This is a reverse counterpart to @encrypt | ||
245 | * and the conditions are exactly the same. | ||
246 | * @givencrypt: Update the IV for encryption. With this function, a cipher | ||
247 | * implementation may provide the function on how to update the IV | ||
248 | * for encryption. | ||
249 | * @givdecrypt: Update the IV for decryption. This is the reverse of | ||
250 | * @givencrypt . | ||
251 | * @geniv: The transformation implementation may use an "IV generator" provided | ||
252 | * by the kernel crypto API. Several use cases have a predefined | ||
253 | * approach how IVs are to be updated. For such use cases, the kernel | ||
254 | * crypto API provides ready-to-use implementations that can be | ||
255 | * referenced with this variable. | ||
256 | * @ivsize: IV size applicable for transformation. The consumer must provide an | ||
257 | * IV of exactly that size to perform the encrypt or decrypt operation. | ||
258 | * | ||
259 | * All fields except @givencrypt , @givdecrypt , @geniv and @ivsize are | ||
260 | * mandatory and must be filled. | ||
200 | */ | 261 | */ |
201 | struct ablkcipher_alg { | 262 | struct ablkcipher_alg { |
202 | int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key, | 263 | int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key, |
@@ -213,6 +274,32 @@ struct ablkcipher_alg { | |||
213 | unsigned int ivsize; | 274 | unsigned int ivsize; |
214 | }; | 275 | }; |
215 | 276 | ||
277 | /** | ||
278 | * struct aead_alg - AEAD cipher definition | ||
279 | * @maxauthsize: Set the maximum authentication tag size supported by the | ||
280 | * transformation. A transformation may support smaller tag sizes. | ||
281 | * As the authentication tag is a message digest to ensure the | ||
282 | * integrity of the encrypted data, a consumer typically wants the | ||
283 | * largest authentication tag possible as defined by this | ||
284 | * variable. | ||
285 | * @setauthsize: Set authentication size for the AEAD transformation. This | ||
286 | * function is used to specify the consumer requested size of the | ||
287 | * authentication tag to be either generated by the transformation | ||
288 | * during encryption or the size of the authentication tag to be | ||
289 | * supplied during the decryption operation. This function is also | ||
290 | * responsible for checking the authentication tag size for | ||
291 | * validity. | ||
292 | * @setkey: see struct ablkcipher_alg | ||
293 | * @encrypt: see struct ablkcipher_alg | ||
294 | * @decrypt: see struct ablkcipher_alg | ||
295 | * @givencrypt: see struct ablkcipher_alg | ||
296 | * @givdecrypt: see struct ablkcipher_alg | ||
297 | * @geniv: see struct ablkcipher_alg | ||
298 | * @ivsize: see struct ablkcipher_alg | ||
299 | * | ||
300 | * All fields except @givencrypt , @givdecrypt , @geniv and @ivsize are | ||
301 | * mandatory and must be filled. | ||
302 | */ | ||
216 | struct aead_alg { | 303 | struct aead_alg { |
217 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | 304 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
218 | unsigned int keylen); | 305 | unsigned int keylen); |
@@ -228,6 +315,18 @@ struct aead_alg { | |||
228 | unsigned int maxauthsize; | 315 | unsigned int maxauthsize; |
229 | }; | 316 | }; |
230 | 317 | ||
318 | /** | ||
319 | * struct blkcipher_alg - synchronous block cipher definition | ||
320 | * @min_keysize: see struct ablkcipher_alg | ||
321 | * @max_keysize: see struct ablkcipher_alg | ||
322 | * @setkey: see struct ablkcipher_alg | ||
323 | * @encrypt: see struct ablkcipher_alg | ||
324 | * @decrypt: see struct ablkcipher_alg | ||
325 | * @geniv: see struct ablkcipher_alg | ||
326 | * @ivsize: see struct ablkcipher_alg | ||
327 | * | ||
328 | * All fields except @geniv and @ivsize are mandatory and must be filled. | ||
329 | */ | ||
231 | struct blkcipher_alg { | 330 | struct blkcipher_alg { |
232 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, | 331 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, |
233 | unsigned int keylen); | 332 | unsigned int keylen); |
@@ -245,6 +344,53 @@ struct blkcipher_alg { | |||
245 | unsigned int ivsize; | 344 | unsigned int ivsize; |
246 | }; | 345 | }; |
247 | 346 | ||
347 | /** | ||
348 | * struct cipher_alg - single-block symmetric ciphers definition | ||
349 | * @cia_min_keysize: Minimum key size supported by the transformation. This is | ||
350 | * the smallest key length supported by this transformation | ||
351 | * algorithm. This must be set to one of the pre-defined | ||
352 | * values as this is not hardware specific. Possible values | ||
353 | * for this field can be found via git grep "_MIN_KEY_SIZE" | ||
354 | * include/crypto/ | ||
355 | * @cia_max_keysize: Maximum key size supported by the transformation. This is | ||
356 | * the largest key length supported by this transformation | ||
357 | * algorithm. This must be set to one of the pre-defined values | ||
358 | * as this is not hardware specific. Possible values for this | ||
359 | * field can be found via git grep "_MAX_KEY_SIZE" | ||
360 | * include/crypto/ | ||
361 | * @cia_setkey: Set key for the transformation. This function is used to either | ||
362 | * program a supplied key into the hardware or store the key in the | ||
363 | * transformation context for programming it later. Note that this | ||
364 | * function does modify the transformation context. This function | ||
365 | * can be called multiple times during the existence of the | ||
366 | * transformation object, so one must make sure the key is properly | ||
367 | * reprogrammed into the hardware. This function is also | ||
368 | * responsible for checking the key length for validity. | ||
369 | * @cia_encrypt: Encrypt a single block. This function is used to encrypt a | ||
370 | * single block of data, which must be @cra_blocksize big. This | ||
371 | * always operates on a full @cra_blocksize and it is not possible | ||
372 | * to encrypt a block of smaller size. The supplied buffers must | ||
373 | * therefore also be at least of @cra_blocksize size. Both the | ||
374 | * input and output buffers are always aligned to @cra_alignmask. | ||
375 | * In case either of the input or output buffer supplied by user | ||
376 | * of the crypto API is not aligned to @cra_alignmask, the crypto | ||
377 | * API will re-align the buffers. The re-alignment means that a | ||
378 | * new buffer will be allocated, the data will be copied into the | ||
379 | * new buffer, then the processing will happen on the new buffer, | ||
380 | * then the data will be copied back into the original buffer and | ||
381 | * finally the new buffer will be freed. In case a software | ||
382 | * fallback was put in place in the @cra_init call, this function | ||
383 | * might need to use the fallback if the algorithm doesn't support | ||
384 | * all of the key sizes. In case the key was stored in | ||
385 | * transformation context, the key might need to be re-programmed | ||
386 | * into the hardware in this function. This function shall not | ||
387 | * modify the transformation context, as this function may be | ||
388 | * called in parallel with the same transformation object. | ||
389 | * @cia_decrypt: Decrypt a single block. This is a reverse counterpart to | ||
390 | * @cia_encrypt, and the conditions are exactly the same. | ||
391 | * | ||
392 | * All fields are mandatory and must be filled. | ||
393 | */ | ||
248 | struct cipher_alg { | 394 | struct cipher_alg { |
249 | unsigned int cia_min_keysize; | 395 | unsigned int cia_min_keysize; |
250 | unsigned int cia_max_keysize; | 396 | unsigned int cia_max_keysize; |
@@ -261,6 +407,25 @@ struct compress_alg { | |||
261 | unsigned int slen, u8 *dst, unsigned int *dlen); | 407 | unsigned int slen, u8 *dst, unsigned int *dlen); |
262 | }; | 408 | }; |
263 | 409 | ||
410 | /** | ||
411 | * struct rng_alg - random number generator definition | ||
412 | * @rng_make_random: The function defined by this variable obtains a random | ||
413 | * number. The random number generator transform must generate | ||
414 | * the random number out of the context provided with this | ||
415 | * call. | ||
416 | * @rng_reset: Reset of the random number generator by clearing the entire state. | ||
417 | * With the invocation of this function call, the random number | ||
418 | * generator shall completely reinitialize its state. If the random | ||
419 | * number generator requires a seed for setting up a new state, | ||
420 | * the seed must be provided by the consumer while invoking this | ||
421 | * function. The required size of the seed is defined with | ||
422 | * @seedsize . | ||
423 | * @seedsize: The seed size required for a random number generator | ||
424 | * initialization defined with this variable. Some random number | ||
425 | * generators like the SP800-90A DRBG does not require a seed as the | ||
426 | * seeding is implemented internally without the need of support by | ||
427 | * the consumer. In this case, the seed size is set to zero. | ||
428 | */ | ||
264 | struct rng_alg { | 429 | struct rng_alg { |
265 | int (*rng_make_random)(struct crypto_rng *tfm, u8 *rdata, | 430 | int (*rng_make_random)(struct crypto_rng *tfm, u8 *rdata, |
266 | unsigned int dlen); | 431 | unsigned int dlen); |
@@ -277,6 +442,81 @@ struct rng_alg { | |||
277 | #define cra_compress cra_u.compress | 442 | #define cra_compress cra_u.compress |
278 | #define cra_rng cra_u.rng | 443 | #define cra_rng cra_u.rng |
279 | 444 | ||
445 | /** | ||
446 | * struct crypto_alg - definition of a cryptograpic cipher algorithm | ||
447 | * @cra_flags: Flags describing this transformation. See include/linux/crypto.h | ||
448 | * CRYPTO_ALG_* flags for the flags which go in here. Those are | ||
449 | * used for fine-tuning the description of the transformation | ||
450 | * algorithm. | ||
451 | * @cra_blocksize: Minimum block size of this transformation. The size in bytes | ||
452 | * of the smallest possible unit which can be transformed with | ||
453 | * this algorithm. The users must respect this value. | ||
454 | * In case of HASH transformation, it is possible for a smaller | ||
455 | * block than @cra_blocksize to be passed to the crypto API for | ||
456 | * transformation, in case of any other transformation type, an | ||
457 | * error will be returned upon any attempt to transform smaller | ||
458 | * than @cra_blocksize chunks. | ||
459 | * @cra_ctxsize: Size of the operational context of the transformation. This | ||
460 | * value informs the kernel crypto API about the memory size | ||
461 | * needed to be allocated for the transformation context. | ||
462 | * @cra_alignmask: Alignment mask for the input and output data buffer. The data | ||
463 | * buffer containing the input data for the algorithm must be | ||
464 | * aligned to this alignment mask. The data buffer for the | ||
465 | * output data must be aligned to this alignment mask. Note that | ||
466 | * the Crypto API will do the re-alignment in software, but | ||
467 | * only under special conditions and there is a performance hit. | ||
468 | * The re-alignment happens at these occasions for different | ||
469 | * @cra_u types: cipher -- For both input data and output data | ||
470 | * buffer; ahash -- For output hash destination buf; shash -- | ||
471 | * For output hash destination buf. | ||
472 | * This is needed on hardware which is flawed by design and | ||
473 | * cannot pick data from arbitrary addresses. | ||
474 | * @cra_priority: Priority of this transformation implementation. In case | ||
475 | * multiple transformations with same @cra_name are available to | ||
476 | * the Crypto API, the kernel will use the one with highest | ||
477 | * @cra_priority. | ||
478 | * @cra_name: Generic name (usable by multiple implementations) of the | ||
479 | * transformation algorithm. This is the name of the transformation | ||
480 | * itself. This field is used by the kernel when looking up the | ||
481 | * providers of particular transformation. | ||
482 | * @cra_driver_name: Unique name of the transformation provider. This is the | ||
483 | * name of the provider of the transformation. This can be any | ||
484 | * arbitrary value, but in the usual case, this contains the | ||
485 | * name of the chip or provider and the name of the | ||
486 | * transformation algorithm. | ||
487 | * @cra_type: Type of the cryptographic transformation. This is a pointer to | ||
488 | * struct crypto_type, which implements callbacks common for all | ||
489 | * trasnformation types. There are multiple options: | ||
490 | * &crypto_blkcipher_type, &crypto_ablkcipher_type, | ||
491 | * &crypto_ahash_type, &crypto_aead_type, &crypto_rng_type. | ||
492 | * This field might be empty. In that case, there are no common | ||
493 | * callbacks. This is the case for: cipher, compress, shash. | ||
494 | * @cra_u: Callbacks implementing the transformation. This is a union of | ||
495 | * multiple structures. Depending on the type of transformation selected | ||
496 | * by @cra_type and @cra_flags above, the associated structure must be | ||
497 | * filled with callbacks. This field might be empty. This is the case | ||
498 | * for ahash, shash. | ||
499 | * @cra_init: Initialize the cryptographic transformation object. This function | ||
500 | * is used to initialize the cryptographic transformation object. | ||
501 | * This function is called only once at the instantiation time, right | ||
502 | * after the transformation context was allocated. In case the | ||
503 | * cryptographic hardware has some special requirements which need to | ||
504 | * be handled by software, this function shall check for the precise | ||
505 | * requirement of the transformation and put any software fallbacks | ||
506 | * in place. | ||
507 | * @cra_exit: Deinitialize the cryptographic transformation object. This is a | ||
508 | * counterpart to @cra_init, used to remove various changes set in | ||
509 | * @cra_init. | ||
510 | * @cra_module: Owner of this transformation implementation. Set to THIS_MODULE | ||
511 | * @cra_list: internally used | ||
512 | * @cra_users: internally used | ||
513 | * @cra_refcnt: internally used | ||
514 | * @cra_destroy: internally used | ||
515 | * | ||
516 | * The struct crypto_alg describes a generic Crypto API algorithm and is common | ||
517 | * for all of the transformations. Any variable not documented here shall not | ||
518 | * be used by a cipher implementation as it is internal to the Crypto API. | ||
519 | */ | ||
280 | struct crypto_alg { | 520 | struct crypto_alg { |
281 | struct list_head cra_list; | 521 | struct list_head cra_list; |
282 | struct list_head cra_users; | 522 | struct list_head cra_users; |