api-intro.txt 6.6 KB

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