2020-06-15 14:50:09 +08:00
|
|
|
.. SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
=============================
|
|
|
|
Scatterlist Cryptographic API
|
|
|
|
=============================
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
The Scatterlist Crypto API takes page vectors (scatterlists) as
|
|
|
|
arguments, and works directly on pages. In some cases (e.g. ECB
|
|
|
|
mode ciphers), this will allow for pages to be encrypted in-place
|
|
|
|
with no copying.
|
|
|
|
|
|
|
|
One of the initial goals of this design was to readily support IPsec,
|
|
|
|
so that processing can be applied to paged skb's without the need
|
|
|
|
for linearization.
|
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Details
|
|
|
|
=======
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
At the lowest level are algorithms, which register dynamically with the
|
|
|
|
API.
|
|
|
|
|
|
|
|
'Transforms' are user-instantiated objects, which maintain state, handle all
|
2020-06-15 14:50:09 +08:00
|
|
|
of the implementation logic (e.g. manipulating page vectors) and provide an
|
|
|
|
abstraction to the underlying algorithms. However, at the user
|
2005-04-17 06:20:36 +08:00
|
|
|
level they are very simple.
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Conceptually, the API layering looks like this::
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
[transform api] (user interface)
|
2006-08-20 13:17:04 +08:00
|
|
|
[transform ops] (per-type logic glue e.g. cipher.c, compress.c)
|
2005-04-17 06:20:36 +08:00
|
|
|
[algorithm api] (for registering algorithms)
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
The idea is to make the user interface and algorithm registration API
|
|
|
|
very simple, while hiding the core logic from both. Many good ideas
|
|
|
|
from existing APIs such as Cryptoapi and Nettle have been adapted for this.
|
|
|
|
|
2007-11-15 19:00:06 +08:00
|
|
|
The API currently supports five main types of transforms: AEAD (Authenticated
|
|
|
|
Encryption with Associated Data), Block Ciphers, Ciphers, Compressors and
|
|
|
|
Hashes.
|
|
|
|
|
|
|
|
Please note that Block Ciphers is somewhat of a misnomer. It is in fact
|
|
|
|
meant to support all ciphers including stream ciphers. The difference
|
|
|
|
between Block Ciphers and Ciphers is that the latter operates on exactly
|
|
|
|
one block while the former can operate on an arbitrary amount of data,
|
|
|
|
subject to block size requirements (i.e., non-stream ciphers can only
|
|
|
|
process multiples of blocks).
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Here's an example of how to use the API::
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-11-30 21:16:09 +08:00
|
|
|
#include <crypto/hash.h>
|
2006-08-20 13:17:04 +08:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/scatterlist.h>
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scatterlist sg[2];
|
|
|
|
char result[128];
|
2016-02-01 21:36:50 +08:00
|
|
|
struct crypto_ahash *tfm;
|
|
|
|
struct ahash_request *req;
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2016-02-01 21:36:50 +08:00
|
|
|
tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
|
2006-08-20 13:17:04 +08:00
|
|
|
if (IS_ERR(tfm))
|
2005-04-17 06:20:36 +08:00
|
|
|
fail();
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ... set up the scatterlists ... */
|
2006-08-20 13:17:04 +08:00
|
|
|
|
2016-02-01 21:36:50 +08:00
|
|
|
req = ahash_request_alloc(tfm, GFP_ATOMIC);
|
|
|
|
if (!req)
|
2006-08-20 13:17:04 +08:00
|
|
|
fail();
|
2016-02-01 21:36:50 +08:00
|
|
|
|
|
|
|
ahash_request_set_callback(req, 0, NULL, NULL);
|
|
|
|
ahash_request_set_crypt(req, sg, result, 2);
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2016-02-01 21:36:50 +08:00
|
|
|
if (crypto_ahash_digest(req))
|
|
|
|
fail();
|
|
|
|
|
|
|
|
ahash_request_free(req);
|
|
|
|
crypto_free_ahash(tfm);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Many real examples are available in the regression test module (tcrypt.c).
|
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Developer Notes
|
|
|
|
===============
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Transforms may only be allocated in user context, and cryptographic
|
2007-11-15 19:00:06 +08:00
|
|
|
methods may only be called from softirq and user contexts. For
|
|
|
|
transforms with a setkey method it too should only be called from
|
|
|
|
user context.
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
When using the API for ciphers, performance will be optimal if each
|
|
|
|
scatterlist contains data which is a multiple of the cipher's block
|
|
|
|
size (typically 8 bytes). This prevents having to do any copying
|
|
|
|
across non-aligned page fragment boundaries.
|
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Adding New Algorithms
|
|
|
|
=====================
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
When submitting a new algorithm for inclusion, a mandatory requirement
|
|
|
|
is that at least a few test vectors from known sources (preferably
|
|
|
|
standards) be included.
|
|
|
|
|
|
|
|
Converting existing well known code is preferred, as it is more likely
|
|
|
|
to have been reviewed and widely tested. If submitting code from LGPL
|
|
|
|
sources, please consider changing the license to GPL (see section 3 of
|
|
|
|
the LGPL).
|
|
|
|
|
|
|
|
Algorithms submitted must also be generally patent-free (e.g. IDEA
|
|
|
|
will not be included in the mainline until around 2011), and be based
|
|
|
|
on a recognized standard and/or have been subjected to appropriate
|
|
|
|
peer review.
|
|
|
|
|
|
|
|
Also check for any RFCs which may relate to the use of specific algorithms,
|
|
|
|
as well as general application notes such as RFC2451 ("The ESP CBC-Mode
|
|
|
|
Cipher Algorithms").
|
|
|
|
|
|
|
|
It's a good idea to avoid using lots of macros and use inlined functions
|
|
|
|
instead, as gcc does a good job with inlining, while excessive use of
|
|
|
|
macros can cause compilation problems on some platforms.
|
|
|
|
|
|
|
|
Also check the TODO list at the web site listed below to see what people
|
|
|
|
might already be working on.
|
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Bugs
|
|
|
|
====
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Send bug reports to:
|
2020-06-15 14:50:09 +08:00
|
|
|
linux-crypto@vger.kernel.org
|
|
|
|
|
|
|
|
Cc:
|
|
|
|
Herbert Xu <herbert@gondor.apana.org.au>,
|
2007-11-15 19:00:06 +08:00
|
|
|
David S. Miller <davem@redhat.com>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Further Information
|
|
|
|
===================
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
For further patches and various updates, including the current TODO
|
|
|
|
list, see:
|
2006-08-20 13:17:04 +08:00
|
|
|
http://gondor.apana.org.au/~herbert/crypto/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Authors
|
|
|
|
=======
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
- James Morris
|
|
|
|
- David S. Miller
|
|
|
|
- Herbert Xu
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
Credits
|
|
|
|
=======
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
The following people provided invaluable feedback during the development
|
|
|
|
of the API:
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
- Alexey Kuznetzov
|
|
|
|
- Rusty Russell
|
|
|
|
- Herbert Valerio Riedel
|
|
|
|
- Jeff Garzik
|
|
|
|
- Michael Richardson
|
|
|
|
- Andrew Morton
|
|
|
|
- Ingo Oeser
|
|
|
|
- Christoph Hellwig
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Portions of this API were derived from the following projects:
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Kerneli Cryptoapi (http://www.kerneli.org/)
|
2020-06-15 14:50:09 +08:00
|
|
|
- Alexander Kjeldaas
|
|
|
|
- Herbert Valerio Riedel
|
|
|
|
- Kyle McMartin
|
|
|
|
- Jean-Luc Cooke
|
|
|
|
- David Bryson
|
|
|
|
- Clemens Fruhwirth
|
|
|
|
- Tobias Ringstrom
|
|
|
|
- Harald Welte
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
and;
|
2020-06-15 14:50:09 +08:00
|
|
|
|
2020-07-20 00:49:59 +08:00
|
|
|
Nettle (https://www.lysator.liu.se/~nisse/nettle/)
|
2020-06-15 14:50:09 +08:00
|
|
|
- Niels Möller
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Original developers of the crypto algorithms:
|
|
|
|
|
2020-06-15 14:50:09 +08:00
|
|
|
- Dana L. How (DES)
|
|
|
|
- Andrew Tridgell and Steve French (MD4)
|
|
|
|
- Colin Plumb (MD5)
|
|
|
|
- Steve Reid (SHA1)
|
|
|
|
- Jean-Luc Cooke (SHA256, SHA384, SHA512)
|
|
|
|
- Kazunori Miyazawa / USAGI (HMAC)
|
|
|
|
- Matthew Skala (Twofish)
|
|
|
|
- Dag Arne Osvik (Serpent)
|
|
|
|
- Brian Gladman (AES)
|
|
|
|
- Kartikey Mahendra Bhatt (CAST6)
|
|
|
|
- Jon Oberheide (ARC4)
|
|
|
|
- Jouni Malinen (Michael MIC)
|
|
|
|
- NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
SHA1 algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Jean-Francois Dive
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
DES algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Raimar Falke
|
|
|
|
- Gisle Sælensminde
|
|
|
|
- Niels Möller
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Blowfish algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Herbert Valerio Riedel
|
|
|
|
- Kyle McMartin
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Twofish algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Werner Koch
|
|
|
|
- Marc Mutz
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
SHA256/384/512 algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Andrew McDonald
|
|
|
|
- Kyle McMartin
|
|
|
|
- Herbert Valerio Riedel
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
AES algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Alexander Kjeldaas
|
|
|
|
- Herbert Valerio Riedel
|
|
|
|
- Kyle McMartin
|
|
|
|
- Adam J. Richter
|
|
|
|
- Fruhwirth Clemens (i586)
|
|
|
|
- Linus Torvalds (i586)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
CAST5 algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Kartikey Mahendra Bhatt (original developers unknown, FSF copyright).
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
TEA/XTEA algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Aaron Grothe
|
|
|
|
- Michael Ringe
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Khazad algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Aaron Grothe
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Whirlpool algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Aaron Grothe
|
|
|
|
- Jean-Luc Cooke
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Anubis algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Aaron Grothe
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
Tiger algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Aaron Grothe
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-20 13:17:04 +08:00
|
|
|
VIA PadLock contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- Michal Ludvig
|
2006-08-20 13:17:04 +08:00
|
|
|
|
2006-10-22 13:06:46 +08:00
|
|
|
Camellia algorithm contributors:
|
2020-06-15 14:50:09 +08:00
|
|
|
- NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
|
2006-10-22 13:06:46 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Generic scatterwalk code by Adam J. Richter <adam@yggdrasil.com>
|
|
|
|
|
|
|
|
Please send any credits updates or corrections to:
|
2006-08-20 13:17:04 +08:00
|
|
|
Herbert Xu <herbert@gondor.apana.org.au>
|