2 Scatterlist Cryptographic API
6 The Scatterlist Crypto API takes page vectors (scatterlists) as
7 arguments, and works directly on pages. In some cases (e.g. ECB
8 mode ciphers), this will allow for pages to be encrypted in-place
11 One of the initial goals of this design was to readily support IPsec,
12 so that processing can be applied to paged skb's without the need
18 At the lowest level are algorithms, which register dynamically with the
21 'Transforms' are user-instantiated objects, which maintain state, handle all
22 of the implementation logic (e.g. manipulating page vectors), provide an
23 abstraction to the underlying algorithms, and handle common logical
24 operations (e.g. cipher modes, HMAC for digests). However, at the user
25 level they are very simple.
27 Conceptually, the API layering looks like this:
29 [transform api] (user interface)
30 [transform ops] (per-type logic glue e.g. cipher.c, digest.c)
31 [algorithm api] (for registering algorithms)
33 The idea is to make the user interface and algorithm registration API
34 very simple, while hiding the core logic from both. Many good ideas
35 from existing APIs such as Cryptoapi and Nettle have been adapted for this.
37 The API currently supports three types of transforms: Ciphers, Digests and
38 Compressors. The compression algorithms especially seem to be performing
41 Support for hardware crypto devices via an asynchronous interface is
44 Here's an example of how to use the API:
46 #include <linux/crypto.h>
48 struct scatterlist sg[2];
50 struct crypto_tfm *tfm;
52 tfm = crypto_alloc_tfm("md5", 0);
56 /* ... set up the scatterlists ... */
58 crypto_digest_init(tfm);
59 crypto_digest_update(tfm, &sg, 2);
60 crypto_digest_final(tfm, result);
65 Many real examples are available in the regression test module (tcrypt.c).
70 As Triple DES is part of the DES module, for those using modular builds,
71 add the following line to /etc/modprobe.conf:
75 The Null algorithms reside in the crypto_null module, so these lines
78 alias cipher_null crypto_null
79 alias digest_null crypto_null
80 alias compress_null crypto_null
82 The SHA384 algorithm shares code within the SHA512 module, so you'll
89 Transforms may only be allocated in user context, and cryptographic
90 methods may only be called from softirq and user contexts.
92 When using the API for ciphers, performance will be optimal if each
93 scatterlist contains data which is a multiple of the cipher's block
94 size (typically 8 bytes). This prevents having to do any copying
95 across non-aligned page fragment boundaries.
100 When submitting a new algorithm for inclusion, a mandatory requirement
101 is that at least a few test vectors from known sources (preferably
102 standards) be included.
104 Converting existing well known code is preferred, as it is more likely
105 to have been reviewed and widely tested. If submitting code from LGPL
106 sources, please consider changing the license to GPL (see section 3 of
109 Algorithms submitted must also be generally patent-free (e.g. IDEA
110 will not be included in the mainline until around 2011), and be based
111 on a recognized standard and/or have been subjected to appropriate
114 Also check for any RFCs which may relate to the use of specific algorithms,
115 as well as general application notes such as RFC2451 ("The ESP CBC-Mode
118 It's a good idea to avoid using lots of macros and use inlined functions
119 instead, as gcc does a good job with inlining, while excessive use of
120 macros can cause compilation problems on some platforms.
122 Also check the TODO list at the web site listed below to see what people
123 might already be working on.
129 James Morris <jmorris@redhat.com>
130 Cc: David S. Miller <davem@redhat.com>
135 For further patches and various updates, including the current TODO
137 http://samba.org/~jamesm/crypto/
148 The following people provided invaluable feedback during the development
153 Herbert Valerio Riedel
160 Portions of this API were derived from the following projects:
162 Kerneli Cryptoapi (http://www.kerneli.org/)
164 Herbert Valerio Riedel
174 Nettle (http://www.lysator.liu.se/~nisse/nettle/)
177 Original developers of the crypto algorithms:
180 Andrew Tridgell and Steve French (MD4)
183 Jean-Luc Cooke (SHA256, SHA384, SHA512)
184 Kazunori Miyazawa / USAGI (HMAC)
185 Matthew Skala (Twofish)
186 Dag Arne Osvik (Serpent)
188 Kartikey Mahendra Bhatt (CAST6)
190 Jouni Malinen (Michael MIC)
192 SHA1 algorithm contributors:
195 DES algorithm contributors:
200 Blowfish algorithm contributors:
201 Herbert Valerio Riedel
204 Twofish algorithm contributors:
208 SHA256/384/512 algorithm contributors:
211 Herbert Valerio Riedel
213 AES algorithm contributors:
215 Herbert Valerio Riedel
218 Fruhwirth Clemens (i586)
219 Linus Torvalds (i586)
221 CAST5 algorithm contributors:
222 Kartikey Mahendra Bhatt (original developers unknown, FSF copyright).
224 TEA/XTEA algorithm contributors:
228 Khazad algorithm contributors:
231 Whirlpool algorithm contributors:
235 Anubis algorithm contributors:
238 Tiger algorithm contributors:
241 Generic scatterwalk code by Adam J. Richter <adam@yggdrasil.com>
243 Please send any credits updates or corrections to:
244 James Morris <jmorris@redhat.com>