aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/DocBook
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2016-02-16 05:34:47 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2016-02-16 15:07:54 -0500
commitba871e1d299154953dcee23590c0316283897261 (patch)
treeb435ce3993ea4f5a2b8732a103882ea5152c5900 /Documentation/DocBook
parent3981d37ff380f1033fef839935bbf9774ed48f00 (diff)
crypto: doc - add skcipher API documentation
The crypto API received the skcipher API which is intended to replace the ablkcipher and blkcipher API. This patch adds the skcipher API documentation to the DocBook, updates the code sample (including removing the blkcipher example) replaces the references to ablkcipher and blkcipher with skcipher. Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'Documentation/DocBook')
-rw-r--r--Documentation/DocBook/crypto-API.tmpl204
1 files changed, 74 insertions, 130 deletions
diff --git a/Documentation/DocBook/crypto-API.tmpl b/Documentation/DocBook/crypto-API.tmpl
index 50efc5a14773..348619fcafb8 100644
--- a/Documentation/DocBook/crypto-API.tmpl
+++ b/Documentation/DocBook/crypto-API.tmpl
@@ -348,10 +348,7 @@
348 <para>type: 348 <para>type:
349 <itemizedlist> 349 <itemizedlist>
350 <listitem> 350 <listitem>
351 <para>blkcipher for synchronous block ciphers</para> 351 <para>skcipher for symmetric key ciphers</para>
352 </listitem>
353 <listitem>
354 <para>ablkcipher for asynchronous block ciphers</para>
355 </listitem> 352 </listitem>
356 <listitem> 353 <listitem>
357 <para>cipher for single block ciphers that may be used with 354 <para>cipher for single block ciphers that may be used with
@@ -600,7 +597,7 @@ kernel crypto API | IPSEC Layer
600 v v 597 v v
601+-----------+ +-----------+ 598+-----------+ +-----------+
602| | | | 599| | | |
603| ablkcipher| | ahash | 600| skcipher | | ahash |
604| (ctr) | ---+ | (ghash) | 601| (ctr) | ---+ | (ghash) |
605+-----------+ | +-----------+ 602+-----------+ | +-----------+
606 | 603 |
@@ -661,7 +658,7 @@ kernel crypto API | IPSEC Layer
661 658
662 <listitem> 659 <listitem>
663 <para> 660 <para>
664 The GCM AEAD cipher type implementation now invokes the ABLKCIPHER API 661 The GCM AEAD cipher type implementation now invokes the SKCIPHER API
665 with the instantiated CTR(AES) cipher handle. 662 with the instantiated CTR(AES) cipher handle.
666 </para> 663 </para>
667 664
@@ -672,7 +669,7 @@ kernel crypto API | IPSEC Layer
672 </para> 669 </para>
673 670
674 <para> 671 <para>
675 That means that the ABLKCIPHER implementation of CTR(AES) only 672 That means that the SKCIPHER implementation of CTR(AES) only
676 implements the CTR block chaining mode. After performing the block 673 implements the CTR block chaining mode. After performing the block
677 chaining operation, the CIPHER implementation of AES is invoked. 674 chaining operation, the CIPHER implementation of AES is invoked.
678 </para> 675 </para>
@@ -680,7 +677,7 @@ kernel crypto API | IPSEC Layer
680 677
681 <listitem> 678 <listitem>
682 <para> 679 <para>
683 The ABLKCIPHER of CTR(AES) now invokes the CIPHER API with the AES 680 The SKCIPHER of CTR(AES) now invokes the CIPHER API with the AES
684 cipher handle to encrypt one block. 681 cipher handle to encrypt one block.
685 </para> 682 </para>
686 </listitem> 683 </listitem>
@@ -709,7 +706,7 @@ kernel crypto API | IPSEC Layer
709 <para> 706 <para>
710 For example, CBC(AES) is implemented with cbc.c, and aes-generic.c. The 707 For example, CBC(AES) is implemented with cbc.c, and aes-generic.c. The
711 ASCII art picture above applies as well with the difference that only 708 ASCII art picture above applies as well with the difference that only
712 step (4) is used and the ABLKCIPHER block chaining mode is CBC. 709 step (4) is used and the SKCIPHER block chaining mode is CBC.
713 </para> 710 </para>
714 </sect2> 711 </sect2>
715 712
@@ -907,15 +904,14 @@ kernel crypto API | Caller
907 </sect2> 904 </sect2>
908 </sect1> 905 </sect1>
909 906
910 <sect1><title>Multi-Block Ciphers [BLKCIPHER] [ABLKCIPHER]</title> 907 <sect1><title>Multi-Block Ciphers</title>
911 <para> 908 <para>
912 Example of transformations: cbc(aes), ecb(arc4), ... 909 Example of transformations: cbc(aes), ecb(arc4), ...
913 </para> 910 </para>
914 911
915 <para> 912 <para>
916 This section describes the multi-block cipher transformation 913 This section describes the multi-block cipher transformation
917 implementations for both synchronous [BLKCIPHER] and 914 implementations. The multi-block ciphers are
918 asynchronous [ABLKCIPHER] case. The multi-block ciphers are
919 used for transformations which operate on scatterlists of 915 used for transformations which operate on scatterlists of
920 data supplied to the transformation functions. They output 916 data supplied to the transformation functions. They output
921 the result into a scatterlist of data as well. 917 the result into a scatterlist of data as well.
@@ -924,16 +920,15 @@ kernel crypto API | Caller
924 <sect2><title>Registration Specifics</title> 920 <sect2><title>Registration Specifics</title>
925 921
926 <para> 922 <para>
927 The registration of [BLKCIPHER] or [ABLKCIPHER] algorithms 923 The registration of multi-block cipher algorithms
928 is one of the most standard procedures throughout the crypto API. 924 is one of the most standard procedures throughout the crypto API.
929 </para> 925 </para>
930 926
931 <para> 927 <para>
932 Note, if a cipher implementation requires a proper alignment 928 Note, if a cipher implementation requires a proper alignment
933 of data, the caller should use the functions of 929 of data, the caller should use the functions of
934 crypto_blkcipher_alignmask() or crypto_ablkcipher_alignmask() 930 crypto_skcipher_alignmask() to identify a memory alignment mask.
935 respectively to identify a memory alignment mask. The kernel 931 The kernel crypto API is able to process requests that are unaligned.
936 crypto API is able to process requests that are unaligned.
937 This implies, however, additional overhead as the kernel 932 This implies, however, additional overhead as the kernel
938 crypto API needs to perform the realignment of the data which 933 crypto API needs to perform the realignment of the data which
939 may imply moving of data. 934 may imply moving of data.
@@ -948,14 +943,13 @@ kernel crypto API | Caller
948 943
949 <para> 944 <para>
950 Please refer to the single block cipher description for schematics 945 Please refer to the single block cipher description for schematics
951 of the block cipher usage. The usage patterns are exactly the same 946 of the block cipher usage.
952 for [ABLKCIPHER] and [BLKCIPHER] as they are for plain [CIPHER].
953 </para> 947 </para>
954 </sect2> 948 </sect2>
955 949
956 <sect2><title>Specifics Of Asynchronous Multi-Block Cipher</title> 950 <sect2><title>Specifics Of Asynchronous Multi-Block Cipher</title>
957 <para> 951 <para>
958 There are a couple of specifics to the [ABLKCIPHER] interface. 952 There are a couple of specifics to the asynchronous interface.
959 </para> 953 </para>
960 954
961 <para> 955 <para>
@@ -1695,7 +1689,28 @@ read(opfd, out, outlen);
1695!Finclude/linux/crypto.h cipher_alg 1689!Finclude/linux/crypto.h cipher_alg
1696!Finclude/crypto/rng.h rng_alg 1690!Finclude/crypto/rng.h rng_alg
1697 </sect1> 1691 </sect1>
1698 <sect1><title>Asynchronous Block Cipher API</title> 1692 <sect1><title>Symmetric Key Cipher API</title>
1693!Pinclude/crypto/skcipher.h Symmetric Key Cipher API
1694!Finclude/crypto/skcipher.h crypto_alloc_skcipher
1695!Finclude/crypto/skcipher.h crypto_free_skcipher
1696!Finclude/crypto/skcipher.h crypto_has_skcipher
1697!Finclude/crypto/skcipher.h crypto_skcipher_ivsize
1698!Finclude/crypto/skcipher.h crypto_skcipher_blocksize
1699!Finclude/crypto/skcipher.h crypto_skcipher_setkey
1700!Finclude/crypto/skcipher.h crypto_skcipher_reqtfm
1701!Finclude/crypto/skcipher.h crypto_skcipher_encrypt
1702!Finclude/crypto/skcipher.h crypto_skcipher_decrypt
1703 </sect1>
1704 <sect1><title>Symmetric Key Cipher Request Handle</title>
1705!Pinclude/crypto/skcipher.h Symmetric Key Cipher Request Handle
1706!Finclude/crypto/skcipher.h crypto_skcipher_reqsize
1707!Finclude/crypto/skcipher.h skcipher_request_set_tfm
1708!Finclude/crypto/skcipher.h skcipher_request_alloc
1709!Finclude/crypto/skcipher.h skcipher_request_free
1710!Finclude/crypto/skcipher.h skcipher_request_set_callback
1711!Finclude/crypto/skcipher.h skcipher_request_set_crypt
1712 </sect1>
1713 <sect1><title>Asynchronous Block Cipher API - Deprecated</title>
1699!Pinclude/linux/crypto.h Asynchronous Block Cipher API 1714!Pinclude/linux/crypto.h Asynchronous Block Cipher API
1700!Finclude/linux/crypto.h crypto_alloc_ablkcipher 1715!Finclude/linux/crypto.h crypto_alloc_ablkcipher
1701!Finclude/linux/crypto.h crypto_free_ablkcipher 1716!Finclude/linux/crypto.h crypto_free_ablkcipher
@@ -1707,7 +1722,7 @@ read(opfd, out, outlen);
1707!Finclude/linux/crypto.h crypto_ablkcipher_encrypt 1722!Finclude/linux/crypto.h crypto_ablkcipher_encrypt
1708!Finclude/linux/crypto.h crypto_ablkcipher_decrypt 1723!Finclude/linux/crypto.h crypto_ablkcipher_decrypt
1709 </sect1> 1724 </sect1>
1710 <sect1><title>Asynchronous Cipher Request Handle</title> 1725 <sect1><title>Asynchronous Cipher Request Handle - Deprecated</title>
1711!Pinclude/linux/crypto.h Asynchronous Cipher Request Handle 1726!Pinclude/linux/crypto.h Asynchronous Cipher Request Handle
1712!Finclude/linux/crypto.h crypto_ablkcipher_reqsize 1727!Finclude/linux/crypto.h crypto_ablkcipher_reqsize
1713!Finclude/linux/crypto.h ablkcipher_request_set_tfm 1728!Finclude/linux/crypto.h ablkcipher_request_set_tfm
@@ -1738,7 +1753,7 @@ read(opfd, out, outlen);
1738!Finclude/crypto/aead.h aead_request_set_crypt 1753!Finclude/crypto/aead.h aead_request_set_crypt
1739!Finclude/crypto/aead.h aead_request_set_ad 1754!Finclude/crypto/aead.h aead_request_set_ad
1740 </sect1> 1755 </sect1>
1741 <sect1><title>Synchronous Block Cipher API</title> 1756 <sect1><title>Synchronous Block Cipher API - Deprecated</title>
1742!Pinclude/linux/crypto.h Synchronous Block Cipher API 1757!Pinclude/linux/crypto.h Synchronous Block Cipher API
1743!Finclude/linux/crypto.h crypto_alloc_blkcipher 1758!Finclude/linux/crypto.h crypto_alloc_blkcipher
1744!Finclude/linux/crypto.h crypto_free_blkcipher 1759!Finclude/linux/crypto.h crypto_free_blkcipher
@@ -1843,7 +1858,7 @@ read(opfd, out, outlen);
1843 </chapter> 1858 </chapter>
1844 1859
1845 <chapter id="Code"><title>Code Examples</title> 1860 <chapter id="Code"><title>Code Examples</title>
1846 <sect1><title>Code Example For Asynchronous Block Cipher Operation</title> 1861 <sect1><title>Code Example For Symmetric Key Cipher Operation</title>
1847 <programlisting> 1862 <programlisting>
1848 1863
1849struct tcrypt_result { 1864struct tcrypt_result {
@@ -1852,15 +1867,15 @@ struct tcrypt_result {
1852}; 1867};
1853 1868
1854/* tie all data structures together */ 1869/* tie all data structures together */
1855struct ablkcipher_def { 1870struct skcipher_def {
1856 struct scatterlist sg; 1871 struct scatterlist sg;
1857 struct crypto_ablkcipher *tfm; 1872 struct crypto_skcipher *tfm;
1858 struct ablkcipher_request *req; 1873 struct skcipher_request *req;
1859 struct tcrypt_result result; 1874 struct tcrypt_result result;
1860}; 1875};
1861 1876
1862/* Callback function */ 1877/* Callback function */
1863static void test_ablkcipher_cb(struct crypto_async_request *req, int error) 1878static void test_skcipher_cb(struct crypto_async_request *req, int error)
1864{ 1879{
1865 struct tcrypt_result *result = req-&gt;data; 1880 struct tcrypt_result *result = req-&gt;data;
1866 1881
@@ -1872,15 +1887,15 @@ static void test_ablkcipher_cb(struct crypto_async_request *req, int error)
1872} 1887}
1873 1888
1874/* Perform cipher operation */ 1889/* Perform cipher operation */
1875static unsigned int test_ablkcipher_encdec(struct ablkcipher_def *ablk, 1890static unsigned int test_skcipher_encdec(struct skcipher_def *sk,
1876 int enc) 1891 int enc)
1877{ 1892{
1878 int rc = 0; 1893 int rc = 0;
1879 1894
1880 if (enc) 1895 if (enc)
1881 rc = crypto_ablkcipher_encrypt(ablk-&gt;req); 1896 rc = crypto_skcipher_encrypt(sk-&gt;req);
1882 else 1897 else
1883 rc = crypto_ablkcipher_decrypt(ablk-&gt;req); 1898 rc = crypto_skcipher_decrypt(sk-&gt;req);
1884 1899
1885 switch (rc) { 1900 switch (rc) {
1886 case 0: 1901 case 0:
@@ -1888,52 +1903,52 @@ static unsigned int test_ablkcipher_encdec(struct ablkcipher_def *ablk,
1888 case -EINPROGRESS: 1903 case -EINPROGRESS:
1889 case -EBUSY: 1904 case -EBUSY:
1890 rc = wait_for_completion_interruptible( 1905 rc = wait_for_completion_interruptible(
1891 &amp;ablk-&gt;result.completion); 1906 &amp;sk-&gt;result.completion);
1892 if (!rc &amp;&amp; !ablk-&gt;result.err) { 1907 if (!rc &amp;&amp; !sk-&gt;result.err) {
1893 reinit_completion(&amp;ablk-&gt;result.completion); 1908 reinit_completion(&amp;sk-&gt;result.completion);
1894 break; 1909 break;
1895 } 1910 }
1896 default: 1911 default:
1897 pr_info("ablkcipher encrypt returned with %d result %d\n", 1912 pr_info("skcipher encrypt returned with %d result %d\n",
1898 rc, ablk-&gt;result.err); 1913 rc, sk-&gt;result.err);
1899 break; 1914 break;
1900 } 1915 }
1901 init_completion(&amp;ablk-&gt;result.completion); 1916 init_completion(&amp;sk-&gt;result.completion);
1902 1917
1903 return rc; 1918 return rc;
1904} 1919}
1905 1920
1906/* Initialize and trigger cipher operation */ 1921/* Initialize and trigger cipher operation */
1907static int test_ablkcipher(void) 1922static int test_skcipher(void)
1908{ 1923{
1909 struct ablkcipher_def ablk; 1924 struct skcipher_def sk;
1910 struct crypto_ablkcipher *ablkcipher = NULL; 1925 struct crypto_skcipher *skcipher = NULL;
1911 struct ablkcipher_request *req = NULL; 1926 struct skcipher_request *req = NULL;
1912 char *scratchpad = NULL; 1927 char *scratchpad = NULL;
1913 char *ivdata = NULL; 1928 char *ivdata = NULL;
1914 unsigned char key[32]; 1929 unsigned char key[32];
1915 int ret = -EFAULT; 1930 int ret = -EFAULT;
1916 1931
1917 ablkcipher = crypto_alloc_ablkcipher("cbc-aes-aesni", 0, 0); 1932 skcipher = crypto_alloc_skcipher("cbc-aes-aesni", 0, 0);
1918 if (IS_ERR(ablkcipher)) { 1933 if (IS_ERR(skcipher)) {
1919 pr_info("could not allocate ablkcipher handle\n"); 1934 pr_info("could not allocate skcipher handle\n");
1920 return PTR_ERR(ablkcipher); 1935 return PTR_ERR(skcipher);
1921 } 1936 }
1922 1937
1923 req = ablkcipher_request_alloc(ablkcipher, GFP_KERNEL); 1938 req = skcipher_request_alloc(skcipher, GFP_KERNEL);
1924 if (IS_ERR(req)) { 1939 if (IS_ERR(req)) {
1925 pr_info("could not allocate request queue\n"); 1940 pr_info("could not allocate request queue\n");
1926 ret = PTR_ERR(req); 1941 ret = PTR_ERR(req);
1927 goto out; 1942 goto out;
1928 } 1943 }
1929 1944
1930 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1945 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1931 test_ablkcipher_cb, 1946 test_skcipher_cb,
1932 &amp;ablk.result); 1947 &amp;sk.result);
1933 1948
1934 /* AES 256 with random key */ 1949 /* AES 256 with random key */
1935 get_random_bytes(&amp;key, 32); 1950 get_random_bytes(&amp;key, 32);
1936 if (crypto_ablkcipher_setkey(ablkcipher, key, 32)) { 1951 if (crypto_skcipher_setkey(skcipher, key, 32)) {
1937 pr_info("key could not be set\n"); 1952 pr_info("key could not be set\n");
1938 ret = -EAGAIN; 1953 ret = -EAGAIN;
1939 goto out; 1954 goto out;
@@ -1955,26 +1970,26 @@ static int test_ablkcipher(void)
1955 } 1970 }
1956 get_random_bytes(scratchpad, 16); 1971 get_random_bytes(scratchpad, 16);
1957 1972
1958 ablk.tfm = ablkcipher; 1973 sk.tfm = skcipher;
1959 ablk.req = req; 1974 sk.req = req;
1960 1975
1961 /* We encrypt one block */ 1976 /* We encrypt one block */
1962 sg_init_one(&amp;ablk.sg, scratchpad, 16); 1977 sg_init_one(&amp;sk.sg, scratchpad, 16);
1963 ablkcipher_request_set_crypt(req, &amp;ablk.sg, &amp;ablk.sg, 16, ivdata); 1978 skcipher_request_set_crypt(req, &amp;sk.sg, &amp;sk.sg, 16, ivdata);
1964 init_completion(&amp;ablk.result.completion); 1979 init_completion(&amp;sk.result.completion);
1965 1980
1966 /* encrypt data */ 1981 /* encrypt data */
1967 ret = test_ablkcipher_encdec(&amp;ablk, 1); 1982 ret = test_skcipher_encdec(&amp;sk, 1);
1968 if (ret) 1983 if (ret)
1969 goto out; 1984 goto out;
1970 1985
1971 pr_info("Encryption triggered successfully\n"); 1986 pr_info("Encryption triggered successfully\n");
1972 1987
1973out: 1988out:
1974 if (ablkcipher) 1989 if (skcipher)
1975 crypto_free_ablkcipher(ablkcipher); 1990 crypto_free_skcipher(skcipher);
1976 if (req) 1991 if (req)
1977 ablkcipher_request_free(req); 1992 skcipher_request_free(req);
1978 if (ivdata) 1993 if (ivdata)
1979 kfree(ivdata); 1994 kfree(ivdata);
1980 if (scratchpad) 1995 if (scratchpad)
@@ -1984,77 +1999,6 @@ out:
1984 </programlisting> 1999 </programlisting>
1985 </sect1> 2000 </sect1>
1986 2001
1987 <sect1><title>Code Example For Synchronous Block Cipher Operation</title>
1988 <programlisting>
1989
1990static int test_blkcipher(void)
1991{
1992 struct crypto_blkcipher *blkcipher = NULL;
1993 char *cipher = "cbc(aes)";
1994 // AES 128
1995 charkey =
1996"\x12\x34\x56\x78\x90\xab\xcd\xef\x12\x34\x56\x78\x90\xab\xcd\xef";
1997 chariv =
1998"\x12\x34\x56\x78\x90\xab\xcd\xef\x12\x34\x56\x78\x90\xab\xcd\xef";
1999 unsigned int ivsize = 0;
2000 char *scratchpad = NULL; // holds plaintext and ciphertext
2001 struct scatterlist sg;
2002 struct blkcipher_desc desc;
2003 int ret = -EFAULT;
2004
2005 blkcipher = crypto_alloc_blkcipher(cipher, 0, 0);
2006 if (IS_ERR(blkcipher)) {
2007 printk("could not allocate blkcipher handle for %s\n", cipher);
2008 return -PTR_ERR(blkcipher);
2009 }
2010
2011 if (crypto_blkcipher_setkey(blkcipher, key, strlen(key))) {
2012 printk("key could not be set\n");
2013 ret = -EAGAIN;
2014 goto out;
2015 }
2016
2017 ivsize = crypto_blkcipher_ivsize(blkcipher);
2018 if (ivsize) {
2019 if (ivsize != strlen(iv))
2020 printk("IV length differs from expected length\n");
2021 crypto_blkcipher_set_iv(blkcipher, iv, ivsize);
2022 }
2023
2024 scratchpad = kmalloc(crypto_blkcipher_blocksize(blkcipher), GFP_KERNEL);
2025 if (!scratchpad) {
2026 printk("could not allocate scratchpad for %s\n", cipher);
2027 goto out;
2028 }
2029 /* get some random data that we want to encrypt */
2030 get_random_bytes(scratchpad, crypto_blkcipher_blocksize(blkcipher));
2031
2032 desc.flags = 0;
2033 desc.tfm = blkcipher;
2034 sg_init_one(&amp;sg, scratchpad, crypto_blkcipher_blocksize(blkcipher));
2035
2036 /* encrypt data in place */
2037 crypto_blkcipher_encrypt(&amp;desc, &amp;sg, &amp;sg,
2038 crypto_blkcipher_blocksize(blkcipher));
2039
2040 /* decrypt data in place
2041 * crypto_blkcipher_decrypt(&amp;desc, &amp;sg, &amp;sg,
2042 */ crypto_blkcipher_blocksize(blkcipher));
2043
2044
2045 printk("Cipher operation completed\n");
2046 return 0;
2047
2048out:
2049 if (blkcipher)
2050 crypto_free_blkcipher(blkcipher);
2051 if (scratchpad)
2052 kzfree(scratchpad);
2053 return ret;
2054}
2055 </programlisting>
2056 </sect1>
2057
2058 <sect1><title>Code Example For Use of Operational State Memory With SHASH</title> 2002 <sect1><title>Code Example For Use of Operational State Memory With SHASH</title>
2059 <programlisting> 2003 <programlisting>
2060 2004