diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/algapi.h | 36 | ||||
-rw-r--r-- | include/linux/crypto.h | 187 |
2 files changed, 219 insertions, 4 deletions
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 60d06e784be3..fef272a8ceeb 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -98,6 +98,7 @@ extern const struct crypto_type crypto_ablkcipher_type; | |||
98 | extern const struct crypto_type crypto_aead_type; | 98 | extern const struct crypto_type crypto_aead_type; |
99 | extern const struct crypto_type crypto_blkcipher_type; | 99 | extern const struct crypto_type crypto_blkcipher_type; |
100 | extern const struct crypto_type crypto_hash_type; | 100 | extern const struct crypto_type crypto_hash_type; |
101 | extern const struct crypto_type crypto_ahash_type; | ||
101 | 102 | ||
102 | void crypto_mod_put(struct crypto_alg *alg); | 103 | void crypto_mod_put(struct crypto_alg *alg); |
103 | 104 | ||
@@ -314,5 +315,40 @@ static inline int crypto_requires_sync(u32 type, u32 mask) | |||
314 | return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC; | 315 | return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC; |
315 | } | 316 | } |
316 | 317 | ||
318 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | ||
319 | { | ||
320 | return crypto_tfm_ctx(&tfm->base); | ||
321 | } | ||
322 | |||
323 | static inline struct ahash_alg *crypto_ahash_alg( | ||
324 | struct crypto_ahash *tfm) | ||
325 | { | ||
326 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; | ||
327 | } | ||
328 | |||
329 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | ||
330 | struct ahash_request *request) | ||
331 | { | ||
332 | return crypto_enqueue_request(queue, &request->base); | ||
333 | } | ||
334 | |||
335 | static inline struct ahash_request *ahash_dequeue_request( | ||
336 | struct crypto_queue *queue) | ||
337 | { | ||
338 | return ahash_request_cast(crypto_dequeue_request(queue)); | ||
339 | } | ||
340 | |||
341 | static inline void *ahash_request_ctx(struct ahash_request *req) | ||
342 | { | ||
343 | return req->__ctx; | ||
344 | } | ||
345 | |||
346 | static inline int ahash_tfm_in_queue(struct crypto_queue *queue, | ||
347 | struct crypto_ahash *tfm) | ||
348 | { | ||
349 | return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); | ||
350 | } | ||
351 | |||
352 | |||
317 | #endif /* _CRYPTO_ALGAPI_H */ | 353 | #endif /* _CRYPTO_ALGAPI_H */ |
318 | 354 | ||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 425824bd49f3..b6efe569128d 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -30,15 +30,17 @@ | |||
30 | */ | 30 | */ |
31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f | 31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f |
32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 | 32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 |
33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 | 33 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000002 |
34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 | 34 | #define CRYPTO_ALG_TYPE_AEAD 0x00000003 |
35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 | 35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 |
36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 | 36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 |
37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 | 37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 |
38 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000008 | 38 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000008 |
39 | #define CRYPTO_ALG_TYPE_AEAD 0x00000009 | 39 | #define CRYPTO_ALG_TYPE_HASH 0x00000009 |
40 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a | ||
40 | 41 | ||
41 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 42 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
43 | #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c | ||
42 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c | 44 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c |
43 | 45 | ||
44 | #define CRYPTO_ALG_LARVAL 0x00000010 | 46 | #define CRYPTO_ALG_LARVAL 0x00000010 |
@@ -102,6 +104,7 @@ struct crypto_async_request; | |||
102 | struct crypto_aead; | 104 | struct crypto_aead; |
103 | struct crypto_blkcipher; | 105 | struct crypto_blkcipher; |
104 | struct crypto_hash; | 106 | struct crypto_hash; |
107 | struct crypto_ahash; | ||
105 | struct crypto_tfm; | 108 | struct crypto_tfm; |
106 | struct crypto_type; | 109 | struct crypto_type; |
107 | struct aead_givcrypt_request; | 110 | struct aead_givcrypt_request; |
@@ -131,6 +134,18 @@ struct ablkcipher_request { | |||
131 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | 134 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
132 | }; | 135 | }; |
133 | 136 | ||
137 | struct ahash_request { | ||
138 | struct crypto_async_request base; | ||
139 | |||
140 | void *info; | ||
141 | |||
142 | unsigned int nbytes; | ||
143 | struct scatterlist *src; | ||
144 | u8 *result; | ||
145 | |||
146 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
147 | }; | ||
148 | |||
134 | /** | 149 | /** |
135 | * struct aead_request - AEAD request | 150 | * struct aead_request - AEAD request |
136 | * @base: Common attributes for async crypto requests | 151 | * @base: Common attributes for async crypto requests |
@@ -195,6 +210,17 @@ struct ablkcipher_alg { | |||
195 | unsigned int ivsize; | 210 | unsigned int ivsize; |
196 | }; | 211 | }; |
197 | 212 | ||
213 | struct ahash_alg { | ||
214 | int (*init)(struct ahash_request *req); | ||
215 | int (*update)(struct ahash_request *req); | ||
216 | int (*final)(struct ahash_request *req); | ||
217 | int (*digest)(struct ahash_request *req); | ||
218 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
219 | unsigned int keylen); | ||
220 | |||
221 | unsigned int digestsize; | ||
222 | }; | ||
223 | |||
198 | struct aead_alg { | 224 | struct aead_alg { |
199 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | 225 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
200 | unsigned int keylen); | 226 | unsigned int keylen); |
@@ -272,6 +298,7 @@ struct compress_alg { | |||
272 | #define cra_cipher cra_u.cipher | 298 | #define cra_cipher cra_u.cipher |
273 | #define cra_digest cra_u.digest | 299 | #define cra_digest cra_u.digest |
274 | #define cra_hash cra_u.hash | 300 | #define cra_hash cra_u.hash |
301 | #define cra_ahash cra_u.ahash | ||
275 | #define cra_compress cra_u.compress | 302 | #define cra_compress cra_u.compress |
276 | 303 | ||
277 | struct crypto_alg { | 304 | struct crypto_alg { |
@@ -298,6 +325,7 @@ struct crypto_alg { | |||
298 | struct cipher_alg cipher; | 325 | struct cipher_alg cipher; |
299 | struct digest_alg digest; | 326 | struct digest_alg digest; |
300 | struct hash_alg hash; | 327 | struct hash_alg hash; |
328 | struct ahash_alg ahash; | ||
301 | struct compress_alg compress; | 329 | struct compress_alg compress; |
302 | } cra_u; | 330 | } cra_u; |
303 | 331 | ||
@@ -383,6 +411,19 @@ struct hash_tfm { | |||
383 | unsigned int digestsize; | 411 | unsigned int digestsize; |
384 | }; | 412 | }; |
385 | 413 | ||
414 | struct ahash_tfm { | ||
415 | int (*init)(struct ahash_request *req); | ||
416 | int (*update)(struct ahash_request *req); | ||
417 | int (*final)(struct ahash_request *req); | ||
418 | int (*digest)(struct ahash_request *req); | ||
419 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
420 | unsigned int keylen); | ||
421 | |||
422 | unsigned int digestsize; | ||
423 | struct crypto_ahash *base; | ||
424 | unsigned int reqsize; | ||
425 | }; | ||
426 | |||
386 | struct compress_tfm { | 427 | struct compress_tfm { |
387 | int (*cot_compress)(struct crypto_tfm *tfm, | 428 | int (*cot_compress)(struct crypto_tfm *tfm, |
388 | const u8 *src, unsigned int slen, | 429 | const u8 *src, unsigned int slen, |
@@ -397,6 +438,7 @@ struct compress_tfm { | |||
397 | #define crt_blkcipher crt_u.blkcipher | 438 | #define crt_blkcipher crt_u.blkcipher |
398 | #define crt_cipher crt_u.cipher | 439 | #define crt_cipher crt_u.cipher |
399 | #define crt_hash crt_u.hash | 440 | #define crt_hash crt_u.hash |
441 | #define crt_ahash crt_u.ahash | ||
400 | #define crt_compress crt_u.compress | 442 | #define crt_compress crt_u.compress |
401 | 443 | ||
402 | struct crypto_tfm { | 444 | struct crypto_tfm { |
@@ -409,6 +451,7 @@ struct crypto_tfm { | |||
409 | struct blkcipher_tfm blkcipher; | 451 | struct blkcipher_tfm blkcipher; |
410 | struct cipher_tfm cipher; | 452 | struct cipher_tfm cipher; |
411 | struct hash_tfm hash; | 453 | struct hash_tfm hash; |
454 | struct ahash_tfm ahash; | ||
412 | struct compress_tfm compress; | 455 | struct compress_tfm compress; |
413 | } crt_u; | 456 | } crt_u; |
414 | 457 | ||
@@ -441,6 +484,10 @@ struct crypto_hash { | |||
441 | struct crypto_tfm base; | 484 | struct crypto_tfm base; |
442 | }; | 485 | }; |
443 | 486 | ||
487 | struct crypto_ahash { | ||
488 | struct crypto_tfm base; | ||
489 | }; | ||
490 | |||
444 | enum { | 491 | enum { |
445 | CRYPTOA_UNSPEC, | 492 | CRYPTOA_UNSPEC, |
446 | CRYPTOA_ALG, | 493 | CRYPTOA_ALG, |
@@ -1264,5 +1311,137 @@ static inline int crypto_comp_decompress(struct crypto_comp *tfm, | |||
1264 | src, slen, dst, dlen); | 1311 | src, slen, dst, dlen); |
1265 | } | 1312 | } |
1266 | 1313 | ||
1314 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | ||
1315 | { | ||
1316 | return (struct crypto_ahash *)tfm; | ||
1317 | } | ||
1318 | |||
1319 | static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, | ||
1320 | u32 type, u32 mask) | ||
1321 | { | ||
1322 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
1323 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
1324 | type |= CRYPTO_ALG_TYPE_AHASH; | ||
1325 | mask |= CRYPTO_ALG_TYPE_AHASH_MASK; | ||
1326 | |||
1327 | return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
1328 | } | ||
1329 | |||
1330 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | ||
1331 | { | ||
1332 | return &tfm->base; | ||
1333 | } | ||
1334 | |||
1335 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) | ||
1336 | { | ||
1337 | crypto_free_tfm(crypto_ahash_tfm(tfm)); | ||
1338 | } | ||
1339 | |||
1340 | static inline unsigned int crypto_ahash_alignmask( | ||
1341 | struct crypto_ahash *tfm) | ||
1342 | { | ||
1343 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); | ||
1344 | } | ||
1345 | |||
1346 | static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) | ||
1347 | { | ||
1348 | return &crypto_ahash_tfm(tfm)->crt_ahash; | ||
1349 | } | ||
1350 | |||
1351 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) | ||
1352 | { | ||
1353 | return crypto_ahash_crt(tfm)->digestsize; | ||
1354 | } | ||
1355 | |||
1356 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) | ||
1357 | { | ||
1358 | return crypto_tfm_get_flags(crypto_ahash_tfm(tfm)); | ||
1359 | } | ||
1360 | |||
1361 | static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags) | ||
1362 | { | ||
1363 | crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags); | ||
1364 | } | ||
1365 | |||
1366 | static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags) | ||
1367 | { | ||
1368 | crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags); | ||
1369 | } | ||
1370 | |||
1371 | static inline struct crypto_ahash *crypto_ahash_reqtfm( | ||
1372 | struct ahash_request *req) | ||
1373 | { | ||
1374 | return __crypto_ahash_cast(req->base.tfm); | ||
1375 | } | ||
1376 | |||
1377 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | ||
1378 | { | ||
1379 | return crypto_ahash_crt(tfm)->reqsize; | ||
1380 | } | ||
1381 | |||
1382 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | ||
1383 | const u8 *key, unsigned int keylen) | ||
1384 | { | ||
1385 | struct ahash_tfm *crt = crypto_ahash_crt(tfm); | ||
1386 | |||
1387 | return crt->setkey(crt->base, key, keylen); | ||
1388 | } | ||
1389 | |||
1390 | static inline int crypto_ahash_digest(struct ahash_request *req) | ||
1391 | { | ||
1392 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | ||
1393 | return crt->digest(req); | ||
1394 | } | ||
1395 | |||
1396 | static inline void ahash_request_set_tfm(struct ahash_request *req, | ||
1397 | struct crypto_ahash *tfm) | ||
1398 | { | ||
1399 | req->base.tfm = crypto_ahash_tfm(crypto_ahash_crt(tfm)->base); | ||
1400 | } | ||
1401 | |||
1402 | static inline struct ahash_request *ahash_request_alloc( | ||
1403 | struct crypto_ahash *tfm, gfp_t gfp) | ||
1404 | { | ||
1405 | struct ahash_request *req; | ||
1406 | |||
1407 | req = kmalloc(sizeof(struct ahash_request) + | ||
1408 | crypto_ahash_reqsize(tfm), gfp); | ||
1409 | |||
1410 | if (likely(req)) | ||
1411 | ahash_request_set_tfm(req, tfm); | ||
1412 | |||
1413 | return req; | ||
1414 | } | ||
1415 | |||
1416 | static inline void ahash_request_free(struct ahash_request *req) | ||
1417 | { | ||
1418 | kfree(req); | ||
1419 | } | ||
1420 | |||
1421 | static inline struct ahash_request *ahash_request_cast( | ||
1422 | struct crypto_async_request *req) | ||
1423 | { | ||
1424 | return container_of(req, struct ahash_request, base); | ||
1425 | } | ||
1426 | |||
1427 | static inline void ahash_request_set_callback(struct ahash_request *req, | ||
1428 | u32 flags, | ||
1429 | crypto_completion_t complete, | ||
1430 | void *data) | ||
1431 | { | ||
1432 | req->base.complete = complete; | ||
1433 | req->base.data = data; | ||
1434 | req->base.flags = flags; | ||
1435 | } | ||
1436 | |||
1437 | static inline void ahash_request_set_crypt(struct ahash_request *req, | ||
1438 | struct scatterlist *src, u8 *result, | ||
1439 | unsigned int nbytes) | ||
1440 | { | ||
1441 | req->src = src; | ||
1442 | req->nbytes = nbytes; | ||
1443 | req->result = result; | ||
1444 | } | ||
1445 | |||
1267 | #endif /* _LINUX_CRYPTO_H */ | 1446 | #endif /* _LINUX_CRYPTO_H */ |
1268 | 1447 | ||