blob: 45d943fcae5b72ade50624a768b9dd8f67555247 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2 Scatterlist Cryptographic API
3
4INTRODUCTION
5
6The Scatterlist Crypto API takes page vectors (scatterlists) as
7arguments, and works directly on pages. In some cases (e.g. ECB
8mode ciphers), this will allow for pages to be encrypted in-place
9with no copying.
10
11One of the initial goals of this design was to readily support IPsec,
12so that processing can be applied to paged skb's without the need
13for linearization.
14
15
16DETAILS
17
18At the lowest level are algorithms, which register dynamically with the
19API.
20
21'Transforms' are user-instantiated objects, which maintain state, handle all
Herbert Xu878b9012006-08-20 15:17:04 +100022of the implementation logic (e.g. manipulating page vectors) and provide an
23abstraction to the underlying algorithms. However, at the user
Linus Torvalds1da177e2005-04-16 15:20:36 -070024level they are very simple.
25
26Conceptually, the API layering looks like this:
27
28 [transform api] (user interface)
Herbert Xu878b9012006-08-20 15:17:04 +100029 [transform ops] (per-type logic glue e.g. cipher.c, compress.c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 [algorithm api] (for registering algorithms)
31
32The idea is to make the user interface and algorithm registration API
33very simple, while hiding the core logic from both. Many good ideas
34from existing APIs such as Cryptoapi and Nettle have been adapted for this.
35
Herbert Xu86f578d2007-11-15 19:00:06 +080036The API currently supports five main types of transforms: AEAD (Authenticated
37Encryption with Associated Data), Block Ciphers, Ciphers, Compressors and
38Hashes.
39
40Please note that Block Ciphers is somewhat of a misnomer. It is in fact
41meant to support all ciphers including stream ciphers. The difference
42between Block Ciphers and Ciphers is that the latter operates on exactly
43one block while the former can operate on an arbitrary amount of data,
44subject to block size requirements (i.e., non-stream ciphers can only
45process multiples of blocks).
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047Here's an example of how to use the API:
48
Baruch Siach450a6c32016-11-30 15:16:09 +020049 #include <crypto/hash.h>
Herbert Xu878b9012006-08-20 15:17:04 +100050 #include <linux/err.h>
51 #include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 struct scatterlist sg[2];
54 char result[128];
Herbert Xu8bc618d2016-02-01 21:36:50 +080055 struct crypto_ahash *tfm;
56 struct ahash_request *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Herbert Xu8bc618d2016-02-01 21:36:50 +080058 tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
Herbert Xu878b9012006-08-20 15:17:04 +100059 if (IS_ERR(tfm))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 fail();
61
62 /* ... set up the scatterlists ... */
Herbert Xu878b9012006-08-20 15:17:04 +100063
Herbert Xu8bc618d2016-02-01 21:36:50 +080064 req = ahash_request_alloc(tfm, GFP_ATOMIC);
65 if (!req)
Herbert Xu878b9012006-08-20 15:17:04 +100066 fail();
Herbert Xu8bc618d2016-02-01 21:36:50 +080067
68 ahash_request_set_callback(req, 0, NULL, NULL);
69 ahash_request_set_crypt(req, sg, result, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Herbert Xu8bc618d2016-02-01 21:36:50 +080071 if (crypto_ahash_digest(req))
72 fail();
73
74 ahash_request_free(req);
75 crypto_free_ahash(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77
78Many real examples are available in the regression test module (tcrypt.c).
79
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081DEVELOPER NOTES
82
83Transforms may only be allocated in user context, and cryptographic
Herbert Xu86f578d2007-11-15 19:00:06 +080084methods may only be called from softirq and user contexts. For
85transforms with a setkey method it too should only be called from
86user context.
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88When using the API for ciphers, performance will be optimal if each
89scatterlist contains data which is a multiple of the cipher's block
90size (typically 8 bytes). This prevents having to do any copying
91across non-aligned page fragment boundaries.
92
93
94ADDING NEW ALGORITHMS
95
96When submitting a new algorithm for inclusion, a mandatory requirement
97is that at least a few test vectors from known sources (preferably
98standards) be included.
99
100Converting existing well known code is preferred, as it is more likely
101to have been reviewed and widely tested. If submitting code from LGPL
102sources, please consider changing the license to GPL (see section 3 of
103the LGPL).
104
105Algorithms submitted must also be generally patent-free (e.g. IDEA
106will not be included in the mainline until around 2011), and be based
107on a recognized standard and/or have been subjected to appropriate
108peer review.
109
110Also check for any RFCs which may relate to the use of specific algorithms,
111as well as general application notes such as RFC2451 ("The ESP CBC-Mode
112Cipher Algorithms").
113
114It's a good idea to avoid using lots of macros and use inlined functions
115instead, as gcc does a good job with inlining, while excessive use of
116macros can cause compilation problems on some platforms.
117
118Also check the TODO list at the web site listed below to see what people
119might already be working on.
120
121
122BUGS
123
124Send bug reports to:
Herbert Xu86f578d2007-11-15 19:00:06 +0800125linux-crypto@vger.kernel.org
126Cc: Herbert Xu <herbert@gondor.apana.org.au>,
127 David S. Miller <davem@redhat.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129
130FURTHER INFORMATION
131
132For further patches and various updates, including the current TODO
133list, see:
Herbert Xu878b9012006-08-20 15:17:04 +1000134http://gondor.apana.org.au/~herbert/crypto/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136
137AUTHORS
138
139James Morris
140David S. Miller
Herbert Xu878b9012006-08-20 15:17:04 +1000141Herbert Xu
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143
144CREDITS
145
146The following people provided invaluable feedback during the development
147of the API:
148
149 Alexey Kuznetzov
150 Rusty Russell
151 Herbert Valerio Riedel
152 Jeff Garzik
153 Michael Richardson
154 Andrew Morton
155 Ingo Oeser
156 Christoph Hellwig
157
158Portions of this API were derived from the following projects:
159
160 Kerneli Cryptoapi (http://www.kerneli.org/)
161 Alexander Kjeldaas
162 Herbert Valerio Riedel
163 Kyle McMartin
164 Jean-Luc Cooke
165 David Bryson
166 Clemens Fruhwirth
167 Tobias Ringstrom
168 Harald Welte
169
170and;
171
172 Nettle (http://www.lysator.liu.se/~nisse/nettle/)
John Anthony Kazos Jrbe2a6082007-05-09 08:50:42 +0200173 Niels Möller
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175Original developers of the crypto algorithms:
176
177 Dana L. How (DES)
178 Andrew Tridgell and Steve French (MD4)
179 Colin Plumb (MD5)
180 Steve Reid (SHA1)
181 Jean-Luc Cooke (SHA256, SHA384, SHA512)
182 Kazunori Miyazawa / USAGI (HMAC)
183 Matthew Skala (Twofish)
184 Dag Arne Osvik (Serpent)
185 Brian Gladman (AES)
186 Kartikey Mahendra Bhatt (CAST6)
187 Jon Oberheide (ARC4)
188 Jouni Malinen (Michael MIC)
Noriaki TAKAMIYAdc2e2f32006-10-22 15:06:46 +1000189 NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191SHA1 algorithm contributors:
192 Jean-Francois Dive
193
194DES algorithm contributors:
195 Raimar Falke
John Anthony Kazos Jrbe2a6082007-05-09 08:50:42 +0200196 Gisle Sælensminde
197 Niels Möller
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199Blowfish algorithm contributors:
200 Herbert Valerio Riedel
201 Kyle McMartin
202
203Twofish algorithm contributors:
204 Werner Koch
205 Marc Mutz
206
207SHA256/384/512 algorithm contributors:
208 Andrew McDonald
209 Kyle McMartin
210 Herbert Valerio Riedel
211
212AES algorithm contributors:
213 Alexander Kjeldaas
214 Herbert Valerio Riedel
215 Kyle McMartin
216 Adam J. Richter
217 Fruhwirth Clemens (i586)
218 Linus Torvalds (i586)
219
220CAST5 algorithm contributors:
221 Kartikey Mahendra Bhatt (original developers unknown, FSF copyright).
222
223TEA/XTEA algorithm contributors:
224 Aaron Grothe
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700225 Michael Ringe
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227Khazad algorithm contributors:
228 Aaron Grothe
229
230Whirlpool algorithm contributors:
231 Aaron Grothe
232 Jean-Luc Cooke
233
234Anubis algorithm contributors:
235 Aaron Grothe
236
237Tiger algorithm contributors:
238 Aaron Grothe
239
Herbert Xu878b9012006-08-20 15:17:04 +1000240VIA PadLock contributors:
241 Michal Ludvig
242
Noriaki TAKAMIYAdc2e2f32006-10-22 15:06:46 +1000243Camellia algorithm contributors:
244 NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246Generic scatterwalk code by Adam J. Richter <adam@yggdrasil.com>
247
248Please send any credits updates or corrections to:
Herbert Xu878b9012006-08-20 15:17:04 +1000249Herbert Xu <herbert@gondor.apana.org.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250