linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Daniel Borkmann <dborkman@redhat.com>,
	quentin.gouchet@gmail.com, LKML <linux-kernel@vger.kernel.org>,
	linux-crypto@vger.kernel.org, ABI/API <linux-api@vger.kernel.org>
Subject: [PATCH v2 10/10] crypto: AF_ALG: document the user space interface
Date: Sun, 16 Nov 2014 03:29:31 +0100	[thread overview]
Message-ID: <1857073.eyqAXtMAM7@tachyon.chronox.de> (raw)
In-Reply-To: <5365136.g8vbXlhRyC@tachyon.chronox.de>

The extension of the user space interface documentation covers all
aspects of the patchset, including:

	* AEAD cipher interface

	* RNG cipher interface

	* getsockopt interface

Signed-off-by: Stephan Mueller <smueller@chronox.de>
---
 Documentation/crypto/crypto-API-userspace.txt | 95 ++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 2 deletions(-)

diff --git a/Documentation/crypto/crypto-API-userspace.txt b/Documentation/crypto/crypto-API-userspace.txt
index ac619cd..5090b05 100644
--- a/Documentation/crypto/crypto-API-userspace.txt
+++ b/Documentation/crypto/crypto-API-userspace.txt
@@ -30,8 +30,9 @@ ciphers are accessible:
 
 	* Symmetric ciphers
 
-Note, AEAD ciphers are currently not supported via the symmetric cipher
-interface.
+	* AEAD ciphers
+
+	* Random number generators
 
 The interface is provided via Netlink using the type AF_ALG. In addition, the
 setsockopt option type is SOL_ALG. In case the user space header files do not
@@ -85,6 +86,7 @@ If a consumer on the other hand wants to maintain the plaintext and the
 ciphertext in different memory locations, all a consumer needs to do is to
 provide different memory pointers for the encryption and decryption operation.
 
+
 Message digest API
 ==================
 
@@ -169,6 +171,69 @@ as large as to hold all blocks of the encrypted or decrypted data. If the output
 data size is smaller, only as many blocks are returned that fit into that
 output buffer size.
 
+
+AEAD cipher API
+===============
+
+The operation is identical to the symmetric cipher API. However, an AEAD
+cipher requires additional information, such as the authentication tag and
+the associated data. This data is to be supplied in addition to the normal
+symmetric cipher data like key and IV discussed for the symmetric ciphers.
+
+During initialization, the struct sockaddr data structure must be filled as
+follows:
+
+struct sockaddr_alg sa = {
+	.salg_family = AF_ALG,
+	.salg_type = "aead", /* this selects the AEAD cipher */
+	.salg_name = "gcm(aes)" /* this is the cipher name */
+};
+
+The discussion about the sendmsg given for the symmetric cipher applies for
+the AEAD interface as well. In addition to the plaintext / ciphertext data and
+the IV, the following data must be supplied with the cmsghdr data structure:
+
+	* The AEAD authentication tag size is set with the flag
+	  ALG_SET_AEAD_AUTHSIZE. The integer value of the authentication tag
+	  size must be provided in the data field of the cmsghdr structure.
+
+	* The AEAD associated data is set with the flag ALG_SET_AEAD_ASSOC.
+	  The data is set the same way as for the IV by supplying the associated
+	  data in the data field of the cmsghdr structure.
+
+The authentication tag itself, however, is handled in a different way to comply
+with the specifics of the kernel crypto API and to avoid copying the
+authentication tag around in memory. The authentication tag is added to the
+memory that immediately follows the ciphertext.
+
+	* When performing an encryption operation, the resulting ciphertext
+	  buffer will hold the tag as follows: ciphertext || tag.  The consumer
+	  must ensure that the ciphertext buffer is large enough to hold the
+	  ciphertext together with the tag of the size set by the consumer using
+	  the ALG_SET_AEAD_AUTHSIZE cmsghdr flag as discussed above.
+
+	* When performing a decryption operation, the initial ciphertext buffer
+	  must hold the tag as follows: ciphertext || tag. The resulting
+	  plaintext has the same size as the ciphertext.
+
+Note: Authentication errors during decryption are marked with a failing
+read/recv system call whose errno is set to EBADMSG.
+
+
+Random number generator API
+===========================
+
+Compared to the symmetric ciphers, the random number generator API is simple:
+it only supports the system calls of read/recv.
+
+The consumer must observe the returned size of the read/recv system calls and
+potentially make subsequent calls if the returned length of random numbers is
+smaller than the expected length.
+
+When initializing a random number generator instance, the AF_ALG interface
+handler ensures that it is appropriately seeded.
+
+
 Setsockopt interface
 ====================
 
@@ -190,6 +255,32 @@ optname:
 
 		- the hash cipher type (keyed message digests)
 
+
+Getsockopt interface
+====================
+
+To allow consumers to obtain information about the allocated cipher, the
+following getsockopt calls with the optval set to the listed flags are provided.
+
+The getsockopt system call must be invoked with the file descriptor of the open
+cipher (i.e. the file descriptor returned by the accept system call).
+
+	* ALG_GET_BLOCKSIZE -- Return the block size of the cipher in the
+	  optlen field of getsockopt. This call is only applicable to
+	  symmetric and AEAD ciphers.
+
+	* ALG_GET_IVSIZE -- Return the IV size of the cipher in the optlen field
+	  of getsockopt. This call is only applicable to symmetric and AEAD
+	  ciphers.
+
+	* ALG_GET_AEAD_AUTHSIZE -- Return the maximum supported authentication
+	  tag size in the optlen field of getsockopt. This call is only
+	  applicable to AEAD ciphers.
+
+	* ALG_GET_DIGESTSIZE -- Return the digest size in the optlen field of
+	  getsockopt. This call is only applicable to message digests.
+
+
 User space API example
 ======================
 
-- 
2.1.0

      parent reply	other threads:[~2014-11-16  2:29 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-16  2:23 [PATCH v2 00/10] crypto: AF_ALG: add AEAD and RNG support Stephan Mueller
2014-11-16  2:23 ` [PATCH v2 01/10] crypto: AF_ALG: add user space interface for AEAD Stephan Mueller
2014-11-18 14:06   ` Herbert Xu
     [not found]     ` <20141118140631.GA12100-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-19  0:34       ` Stephan Mueller
2014-11-19  4:20     ` Stephan Mueller
     [not found]       ` <2398701.sGeMzIcHaz-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-19  4:27         ` Herbert Xu
     [not found]           ` <20141119042704.GA19258-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-19  6:30             ` Stephan Mueller
     [not found]               ` <12318471.ucMNmAKX0e-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-19  6:45                 ` Herbert Xu
2014-11-16  2:24 ` [PATCH v2 02/10] crypto: AF_ALG: user space interface for cipher info Stephan Mueller
2014-11-18 14:08   ` Herbert Xu
2014-11-19  1:02     ` Stephan Mueller
2014-11-19  1:05       ` Herbert Xu
     [not found]     ` <20141118140822.GB12100-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-20  4:03       ` Stephan Mueller
     [not found]         ` <16101836.sTaxopCThb-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-20  4:07           ` Herbert Xu
     [not found]             ` <20141120040748.GB28420-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-20  4:14               ` Stephan Mueller
     [not found]                 ` <1886827.KUDIsNtfuk-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-20  4:18                   ` Herbert Xu
     [not found]                     ` <20141120041824.GA28612-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-20  4:23                       ` Stephan Mueller
     [not found]                         ` <3538055.XH2t7HNEVj-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-20  4:46                           ` crypto: user - Allow get request with empty driver name Herbert Xu
2014-11-20  7:11                             ` Steffen Klassert
2014-11-20  7:45                               ` Herbert Xu
     [not found]                                 ` <20141120074526.GB29544-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-20  8:04                                   ` Steffen Klassert
     [not found]                                     ` <20141120080406.GV6390-opNxpl+3fjRBDgjK7y7TUQ@public.gmane.org>
2014-11-20 13:07                                       ` Stephan Mueller
     [not found]                             ` <20141120044650.GA28691-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-20 13:02                               ` Stephan Mueller
2014-11-20 13:10                                 ` Stephan Mueller
     [not found]                                   ` <2283056.kKnMJs7Bfg-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-20 13:40                                     ` Herbert Xu
2014-11-20 16:08                                       ` Stephan Mueller
     [not found]                                         ` <6655976.jRkjMUZ19x-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-21  2:31                                           ` Herbert Xu
     [not found]                                             ` <20141121023131.GA3873-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>
2014-11-21  2:42                                               ` Stephan Mueller
2014-11-21  4:40                                 ` Stephan Mueller
2014-11-20  7:05           ` [PATCH v2 02/10] crypto: AF_ALG: user space interface for cipher info Steffen Klassert
2014-11-20  6:32         ` Steffen Klassert
2014-11-16  2:25 ` [PATCH v2 03/10] crypto: AF_ALG: extend data structuers for AEAD Stephan Mueller
2014-11-16  2:25 ` [PATCH v2 04/10] crypto: AF_ALG: crypto API calls to inline functions Stephan Mueller
2014-11-16  2:26 ` [PATCH v2 05/10] crypto: AF_ALG: add AEAD support Stephan Mueller
     [not found] ` <5365136.g8vbXlhRyC-PJstQz4BMNNP20K/wil9xYQuADTiUCJX@public.gmane.org>
2014-11-16  2:26   ` [PATCH v2 06/10] crypto: AF_ALG: make setkey optional Stephan Mueller
2014-11-18 14:10     ` Herbert Xu
2014-11-19  2:36       ` Stephan Mueller
2014-11-16  2:28   ` [PATCH v2 08/10] crypto: AF_ALG: enable RNG interface compilation Stephan Mueller
2014-11-16  2:27 ` [PATCH v2 07/10] crypto: AF_ALG: add random number generator support Stephan Mueller
2014-11-16  2:28 ` [PATCH v2 09/10] crypto: AF_ALG: user space interface for hash info Stephan Mueller
2014-11-16  2:29 ` Stephan Mueller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1857073.eyqAXtMAM7@tachyon.chronox.de \
    --to=smueller@chronox.de \
    --cc=dborkman@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quentin.gouchet@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).