Root/include/crypto/skcipher.h

1/*
2 * Symmetric key ciphers.
3 *
4 * Copyright (c) 2007 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_SKCIPHER_H
14#define _CRYPTO_SKCIPHER_H
15
16#include <linux/crypto.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19
20/**
21 * struct skcipher_givcrypt_request - Crypto request with IV generation
22 * @seq: Sequence number for IV generation
23 * @giv: Space for generated IV
24 * @creq: The crypto request itself
25 */
26struct skcipher_givcrypt_request {
27    u64 seq;
28    u8 *giv;
29
30    struct ablkcipher_request creq;
31};
32
33static inline struct crypto_ablkcipher *skcipher_givcrypt_reqtfm(
34    struct skcipher_givcrypt_request *req)
35{
36    return crypto_ablkcipher_reqtfm(&req->creq);
37}
38
39static inline int crypto_skcipher_givencrypt(
40    struct skcipher_givcrypt_request *req)
41{
42    struct ablkcipher_tfm *crt =
43        crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req));
44    return crt->givencrypt(req);
45};
46
47static inline int crypto_skcipher_givdecrypt(
48    struct skcipher_givcrypt_request *req)
49{
50    struct ablkcipher_tfm *crt =
51        crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req));
52    return crt->givdecrypt(req);
53};
54
55static inline void skcipher_givcrypt_set_tfm(
56    struct skcipher_givcrypt_request *req, struct crypto_ablkcipher *tfm)
57{
58    req->creq.base.tfm = crypto_ablkcipher_tfm(tfm);
59}
60
61static inline struct skcipher_givcrypt_request *skcipher_givcrypt_cast(
62    struct crypto_async_request *req)
63{
64    return container_of(ablkcipher_request_cast(req),
65                struct skcipher_givcrypt_request, creq);
66}
67
68static inline struct skcipher_givcrypt_request *skcipher_givcrypt_alloc(
69    struct crypto_ablkcipher *tfm, gfp_t gfp)
70{
71    struct skcipher_givcrypt_request *req;
72
73    req = kmalloc(sizeof(struct skcipher_givcrypt_request) +
74              crypto_ablkcipher_reqsize(tfm), gfp);
75
76    if (likely(req))
77        skcipher_givcrypt_set_tfm(req, tfm);
78
79    return req;
80}
81
82static inline void skcipher_givcrypt_free(struct skcipher_givcrypt_request *req)
83{
84    kfree(req);
85}
86
87static inline void skcipher_givcrypt_set_callback(
88    struct skcipher_givcrypt_request *req, u32 flags,
89    crypto_completion_t complete, void *data)
90{
91    ablkcipher_request_set_callback(&req->creq, flags, complete, data);
92}
93
94static inline void skcipher_givcrypt_set_crypt(
95    struct skcipher_givcrypt_request *req,
96    struct scatterlist *src, struct scatterlist *dst,
97    unsigned int nbytes, void *iv)
98{
99    ablkcipher_request_set_crypt(&req->creq, src, dst, nbytes, iv);
100}
101
102static inline void skcipher_givcrypt_set_giv(
103    struct skcipher_givcrypt_request *req, u8 *giv, u64 seq)
104{
105    req->giv = giv;
106    req->seq = seq;
107}
108
109#endif /* _CRYPTO_SKCIPHER_H */
110
111

Archive Download this file



interactive