From patchwork Sun Nov 16 02:29:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 5312951 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 17045C11AC for ; Sun, 16 Nov 2014 02:51:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A514201DD for ; Sun, 16 Nov 2014 02:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC6EC20123 for ; Sun, 16 Nov 2014 02:51:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932152AbaKPCv1 (ORCPT ); Sat, 15 Nov 2014 21:51:27 -0500 Received: from mail.eperm.de ([89.247.134.16]:54555 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754952AbaKPCrz (ORCPT ); Sat, 15 Nov 2014 21:47:55 -0500 X-AuthUser: sm@eperm.de Received: from tachyon.chronox.de by mail.eperm.de with [XMail 1.27 ESMTP Server] id for from ; Sun, 16 Nov 2014 03:47:49 +0100 From: Stephan Mueller To: Herbert Xu Cc: Daniel Borkmann , quentin.gouchet@gmail.com, LKML , linux-crypto@vger.kernel.org, ABI/API Subject: [PATCH v2 10/10] crypto: AF_ALG: document the user space interface Date: Sun, 16 Nov 2014 03:29:31 +0100 Message-ID: <1857073.eyqAXtMAM7@tachyon.chronox.de> User-Agent: KMail/4.14.2 (Linux/3.17.2-300.fc21.x86_64; KDE/4.14.2; x86_64; ; ) In-Reply-To: <5365136.g8vbXlhRyC@tachyon.chronox.de> References: <5365136.g8vbXlhRyC@tachyon.chronox.de> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 ======================