Skip to content

RFC, v2: "New" /dev/crypto user-space interface

Miloslav Trmač linux-crypto lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest19 patches 24 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/19User-space API definitionDocumentation/crypto/userspace.txt include/linux/Kbuild include/linux/ncr.h+784 -010 replies
2/19Add CRYPTO_USERSPACE config optioncrypto/Kconfig crypto/Makefile crypto/userspace/Makefile+8 -00 replies
3/19Add libtommath headerscrypto/userspace/libtommath/tommath.h crypto/userspace/libtommath/tommath_class.h crypto/userspace/libtommath/tommath_superclass.h+1630 -00 replies
4/19Add libtomcrypt headerscrypto/userspace/libtomcrypt/headers/tomcrypt.h crypto/userspace/libtomcrypt/headers/tomcrypt_argchk.h crypto/userspace/libtomcrypt/headers/tomcrypt_cfg.h +7 more+1561 -00 replies
5/19Add internal /dev/crypto implementation headerscrypto/userspace/cryptodev_int.h crypto/userspace/ncr-dh.h crypto/userspace/ncr-int.h +1 more+407 -00 replies
6/19Add ioctl() argument and attribute handling utilscrypto/userspace/Makefile crypto/userspace/utils.c crypto/userspace/utils.h+400 -03 replies
7/19Add crypto API utilities.crypto/userspace/Makefile crypto/userspace/cryptodev_cipher.c crypto/userspace/cryptodev_main.c+353 -10 replies
8/19Add per-process and per-user limitscrypto/userspace/Makefile crypto/userspace/ncr-limits.c+248 -10 replies
9/19Add libtommath implementationcrypto/userspace/Makefile crypto/userspace/libtommath/LICENSE crypto/userspace/libtommath/bn_error.c +118 more+9425 -10 replies
10/19Add libtomcrypt implementationcrypto/userspace/Makefile crypto/userspace/libtomcrypt/hashes/crypt_hash_is_valid.c crypto/userspace/libtomcrypt/hashes/hash_get_oid.c +75 more+8526 -10 replies
10/19Add libtommath implementationcrypto/userspace/Makefile crypto/userspace/libtomcrypt/hashes/crypt_hash_is_valid.c crypto/userspace/libtomcrypt/hashes/hash_get_oid.c +75 more+8526 -10 replies
11/19Add algorithm properties table.crypto/userspace/Makefile crypto/userspace/ncr-sessions.c+151 -10 replies
12/19Add DH implementation and pubkey abstraction layercrypto/userspace/Makefile crypto/userspace/ncr-dh.c crypto/userspace/ncr-pk.c+942 -10 replies
13/19Add /dev/crypto auditing infrastructureinclude/linux/audit.h kernel/auditfilter.c kernel/auditsc.c+176 -00 replies
14/19Add most operations on key objects.crypto/userspace/Makefile crypto/userspace/ncr-key.c+690 -10 replies
15/19Add key wrapping operationscrypto/userspace/Makefile crypto/userspace/ncr-key-storage.c crypto/userspace/ncr-key-wrap.c +1 more+931 -20 replies
16/19Add helpers for zero-copy userspace accesscrypto/userspace/cryptodev_main.c+87 -00 replies
17/19Add session operationscrypto/userspace/ncr-sessions.c crypto/userspace/ncr.c+1039 -00 replies
18/19Add ioctl handlerscrypto/userspace/ncr.c+405 -00 replies
19/19Finally, add the /dev/crypto device.crypto/userspace/cryptodev_main.c+130 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/19] RFC, v2: "New" /dev/crypto user-space interface

Hello,
following is a patchset providing an user-space interface to the kernel crypto API. It is based on the older, BSD-compatible, implementation, but the user-space interface is different.

Major changes since the previous post:
* "struct nlattr"-based extensible attributes used for extensibility of most operations, both for input and output attributes
* algorithms (ciphers, key wrapping, key derivation) are identified using strings in the userspace API
* Full compat_ioctl implementation
* Version number added to the data format used when wrapping keys for storage
* Patch set split into smaller parts, reordered to keep the tree buildable. (If you want to review primarily the user-space API, see patches 1,14,15,17,18.)

The libtom* patches will probably still be too large for the mailing list; the whole patch set is also available at
http://people.redhat.com/mitr/cryptodev-ncr/v2/ .

Original patch set description follows.

These are the major differences compared to the BSD-like interface:

* The API supports key storage and management inside the kernel. An application can thus ask the kernel to generate a key; the key is then referenced via an integer identifier, and the application can be prevented from accessing the raw key data. Such a key can, if so configured, still be wrapped for key transport to the recipient of the message, and unwrapped by the recipient.

The kernel key storage does not span system reboots, but applications can also wrap the keys for persistent storage, receiving an encrypted blob that does not reveal the raw key data, but can be later loaded back into the kernel.

* More algorithms and mechanisms are supported by the API, including public key algorithms (RSA/DSA encryption and signing, D-H key derivation, key wrapping).

Motivations for the extensions: governments are asking for more security features in the operating systems they procure, which make user-space implementations impractical. A few examples:

* Advanced crypto module for OSPP for Common Criteria requires OS services implementing several low-level crypto algorithms (e.g. AES, RSA). This requires the separation of crypto services from the consumer of those services. (The threat model is that apps tend to have more vulnerabilities than libraries and compromise of the app will lead to the ability to access key material.) An user-space library is not separated, options are a) root running daemon that does crypto, but this would be slow due to context switches, scheduler mismatching and all the IPC overhead and b) use crypto that is in the kernel.

* FIPS-140-3 calls out for cryptographic functions to be non-debuggable (ptrace) meaning that you cannot get to the key material. The solution is the same as above.

* GPOSPP requires auditing for crypto events (so does FIPS-140 level 2 cert). To do this you need any crypto to have CAP_AUDIT_WRITE permissions which means making everything that links to openssl, libgcrypt, or nss setuid root. Making firefox and 400 other applications setuid root is a non-starter. So, the solution is again to use crypto in the kernel where auditing needs no special permissions.

Other advantages to having kernel crypto available to user space:

* User space will be able to take advantage of kernel drivers for hardware crypto accelerators.

* glibc, which in some configurations links to libfreebl3.so for hashes necessary for crypt(), will be able to use the kernel implementation; this means one less library to load and dynamically link for each such process.

The code is derived from the original cryptodev-linux patch set; most of the new implementation was written by Nikos Mavrogiannopoulos <[email protected]>. Attributions are included in the respective source files.