api-intro.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 <linux/crypto.h>
  37. #include <linux/err.h>
  38. #include <linux/scatterlist.h>
  39. struct scatterlist sg[2];
  40. char result[128];
  41. struct crypto_hash *tfm;
  42. struct hash_desc desc;
  43. tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
  44. if (IS_ERR(tfm))
  45. fail();
  46. /* ... set up the scatterlists ... */
  47. desc.tfm = tfm;
  48. desc.flags = 0;
  49. if (crypto_hash_digest(&desc, sg, 2, result))
  50. fail();
  51. crypto_free_hash(tfm);
  52. Many real examples are available in the regression test module (tcrypt.c).
  53. DEVELOPER NOTES
  54. Transforms may only be allocated in user context, and cryptographic
  55. methods may only be called from softirq and user contexts. For
  56. transforms with a setkey method it too should only be called from
  57. user context.
  58. When using the API for ciphers, performance will be optimal if each
  59. scatterlist contains data which is a multiple of the cipher's block
  60. size (typically 8 bytes). This prevents having to do any copying
  61. across non-aligned page fragment boundaries.
  62. ADDING NEW ALGORITHMS
  63. When submitting a new algorithm for inclusion, a mandatory requirement
  64. is that at least a few test vectors from known sources (preferably
  65. standards) be included.
  66. Converting existing well known code is preferred, as it is more likely
  67. to have been reviewed and widely tested. If submitting code from LGPL
  68. sources, please consider changing the license to GPL (see section 3 of
  69. the LGPL).
  70. Algorithms submitted must also be generally patent-free (e.g. IDEA
  71. will not be included in the mainline until around 2011), and be based
  72. on a recognized standard and/or have been subjected to appropriate
  73. peer review.
  74. Also check for any RFCs which may relate to the use of specific algorithms,
  75. as well as general application notes such as RFC2451 ("The ESP CBC-Mode
  76. Cipher Algorithms").
  77. It's a good idea to avoid using lots of macros and use inlined functions
  78. instead, as gcc does a good job with inlining, while excessive use of
  79. macros can cause compilation problems on some platforms.
  80. Also check the TODO list at the web site listed below to see what people
  81. might already be working on.
  82. BUGS
  83. Send bug reports to:
  84. linux-crypto@vger.kernel.org
  85. Cc: Herbert Xu <herbert@gondor.apana.org.au>,
  86. David S. Miller <davem@redhat.com>
  87. FURTHER INFORMATION
  88. For further patches and various updates, including the current TODO
  89. list, see:
  90. http://gondor.apana.org.au/~herbert/crypto/
  91. AUTHORS
  92. James Morris
  93. David S. Miller
  94. Herbert Xu
  95. CREDITS
  96. The following people provided invaluable feedback during the development
  97. of the API:
  98. Alexey Kuznetzov
  99. Rusty Russell
  100. Herbert Valerio Riedel
  101. Jeff Garzik
  102. Michael Richardson
  103. Andrew Morton
  104. Ingo Oeser
  105. Christoph Hellwig
  106. Portions of this API were derived from the following projects:
  107. Kerneli Cryptoapi (http://www.kerneli.org/)
  108. Alexander Kjeldaas
  109. Herbert Valerio Riedel
  110. Kyle McMartin
  111. Jean-Luc Cooke
  112. David Bryson
  113. Clemens Fruhwirth
  114. Tobias Ringstrom
  115. Harald Welte
  116. and;
  117. Nettle (http://www.lysator.liu.se/~nisse/nettle/)
  118. Niels Möller
  119. Original developers of the crypto algorithms:
  120. Dana L. How (DES)
  121. Andrew Tridgell and Steve French (MD4)
  122. Colin Plumb (MD5)
  123. Steve Reid (SHA1)
  124. Jean-Luc Cooke (SHA256, SHA384, SHA512)
  125. Kazunori Miyazawa / USAGI (HMAC)
  126. Matthew Skala (Twofish)
  127. Dag Arne Osvik (Serpent)
  128. Brian Gladman (AES)
  129. Kartikey Mahendra Bhatt (CAST6)
  130. Jon Oberheide (ARC4)
  131. Jouni Malinen (Michael MIC)
  132. NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
  133. SHA1 algorithm contributors:
  134. Jean-Francois Dive
  135. DES algorithm contributors:
  136. Raimar Falke
  137. Gisle Sælensminde
  138. Niels Möller
  139. Blowfish algorithm contributors:
  140. Herbert Valerio Riedel
  141. Kyle McMartin
  142. Twofish algorithm contributors:
  143. Werner Koch
  144. Marc Mutz
  145. SHA256/384/512 algorithm contributors:
  146. Andrew McDonald
  147. Kyle McMartin
  148. Herbert Valerio Riedel
  149. AES algorithm contributors:
  150. Alexander Kjeldaas
  151. Herbert Valerio Riedel
  152. Kyle McMartin
  153. Adam J. Richter
  154. Fruhwirth Clemens (i586)
  155. Linus Torvalds (i586)
  156. CAST5 algorithm contributors:
  157. Kartikey Mahendra Bhatt (original developers unknown, FSF copyright).
  158. TEA/XTEA algorithm contributors:
  159. Aaron Grothe
  160. Michael Ringe
  161. Khazad algorithm contributors:
  162. Aaron Grothe
  163. Whirlpool algorithm contributors:
  164. Aaron Grothe
  165. Jean-Luc Cooke
  166. Anubis algorithm contributors:
  167. Aaron Grothe
  168. Tiger algorithm contributors:
  169. Aaron Grothe
  170. VIA PadLock contributors:
  171. Michal Ludvig
  172. Camellia algorithm contributors:
  173. NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
  174. Generic scatterwalk code by Adam J. Richter <adam@yggdrasil.com>
  175. Please send any credits updates or corrections to:
  176. Herbert Xu <herbert@gondor.apana.org.au>