From: "Jason A. Donenfeld" <Jason@zx2c4.com> To: email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>, Samuel Neves <firstname.lastname@example.org>, Andy Lutomirski <email@example.com>, Jean-Philippe Aumasson <firstname.lastname@example.org> Subject: [PATCH net-next v6 02/23] zinc: introduce minimal cryptography library Date: Tue, 25 Sep 2018 16:56:01 +0200 [thread overview] Message-ID: <20180925145622.29959-3-Jason@zx2c4.com> (raw) In-Reply-To: <20180925145622.29959-1-Jason@zx2c4.com> Zinc stands for "Zinc Is Neat Crypto" or "Zinc as IN Crypto" or maybe just "Zx2c4's INsane Cryptolib." It's also short, easy to type, and plays nicely with the recent trend of naming crypto libraries after elements. The guiding principle is "don't overdo it". It's less of a library and more of a directory tree for organizing well-curated direct implementations of cryptography primitives. Zinc is a new cryptography API that is much more minimal and lower-level than the current one. It intends to complement it and provide a basis upon which the current crypto API might build, as the provider of software implementations of cryptographic primitives. It is motivated by three primary observations in crypto API design: * Highly composable "cipher modes" and related abstractions from 90s cryptographers did not turn out to be as terrific an idea as hoped, leading to a host of API misuse problems. * Most programmers are afraid of crypto code, and so prefer to integrate it into libraries in a highly abstracted manner, so as to shield themselves from implementation details. Cryptographers, on the other hand, prefer simple direct implementations, which they're able to verify for high assurance and optimize in accordance with their expertise. * Overly abstracted and flexible cryptography APIs lead to a host of dangerous problems and performance issues. The kernel is in the business usually not of coming up with new uses of crypto, but rather implementing various constructions, which means it essentially needs a library of primitives, not a highly abstracted enterprise-ready pluggable system, with a few particular exceptions. This last observation has seen itself play out several times over and over again within the kernel: * The perennial move of actual primitives away from crypto/ and into lib/, so that users can actually call these functions directly with no overhead and without lots of allocations, function pointers, string specifier parsing, and general clunkiness. For example: sha256, chacha20, siphash, sha1, and so forth live in lib/ rather than in crypto/. Zinc intends to stop the cluttering of lib/ and introduce these direct primitives into their proper place, lib/zinc/. * An abundance of misuse bugs with the present crypto API that have been very unpleasant to clean up. * A hesitance to even use cryptography, because of the overhead and headaches involved in accessing the routines. Zinc goes in a rather different direction. Rather than providing a thoroughly designed and abstracted API, Zinc gives you simple functions, which implement some primitive, or some particular and specific construction of primitives. It is not dynamic in the least, though one could imagine implementing a complex dynamic dispatch mechanism (such as the current crypto API) on top of these basic functions. After all, dynamic dispatch is usually needed for applications with cipher agility, such as IPsec, dm-crypt, AF_ALG, and so forth, and the existing crypto API will continue to play that role. However, Zinc will provide a non- haphazard way of directly utilizing crypto routines in applications that do have neither the need nor desire for abstraction and dynamic dispatch. It also organizes the implementations in a simple, straight-forward, and direct manner, making it enjoyable and intuitive to work on. Rather than moving optimized assembly implementations into arch/, it keeps them all together in lib/zinc/, making it simple and obvious to compare and contrast what's happening. This is, notably, exactly what the lib/raid6/ tree does, and that seems to work out rather well. It's also the pattern of most successful crypto libraries. The architecture- specific glue-code is made a part of each translation unit, rather than being in a separate one, so that generic and architecture-optimized code are combined at compile-time, and incompatibility branches compiled out by the optimizer. All implementations have been extensively tested and fuzzed, and are selected for their quality, trustworthiness, and performance. Wherever possible and performant, formally verified implementations are used, such as those from HACL*  and Fiat-Crypto . The routines also take special care to zero out secrets using memzero_explicit (and future work is planned to have gcc do this more reliably and performantly with compiler plugins). The performance of the selected implementations is state-of-the-art and unrivaled on a broad array of hardware, though of course we will continue to fine tune these to the hardware demands needed by kernel contributors. Each implementation also comes with extensive self-tests and crafted test vectors, pulled from various places such as Wycheproof . Regularity of function signatures is important, so that users can easily "guess" the name of the function they want. Though, individual primitives are oftentimes not trivially interchangeable, having been designed for different things and requiring different parameters and semantics, and so the function signatures they provide will directly reflect the realities of the primitives' usages, rather than hiding it behind (inevitably leaky) abstractions. Also, in contrast to the current crypto API, Zinc functions can work on stack buffers, and can be called with different keys, without requiring allocations or locking. SIMD is used automatically when available, though some routines may benefit from either having their SIMD disabled for particular invocations, or to have the SIMD initialization calls amortized over several invocations of the function, and so Zinc utilizes function signatures enabling that in conjunction with the recently introduced simd_context_t. More generally, Zinc provides function signatures that allow just what is required by the various callers. This isn't to say that users of the functions will be permitted to pollute the function semantics with weird particular needs, but we are trying very hard not to overdo it, and that means looking carefully at what's actually necessary, and doing just that, and not much more than that. Remember: practicality and cleanliness rather than over-zealous infrastructure. Zinc provides also an opening for the best implementers in academia to contribute their time and effort to the kernel, by being sufficiently simple and inviting. In discussing this commit with some of the best and brightest over the last few years, there are many who are eager to devote rare talent and energy to this effort. Following the merging of this, I expect for the primitives that currently exist in lib/ to work their way into lib/zinc/, after intense scrutiny of each implementation, potentially replacing them with either formally-verified implementations, or better studied and faster state-of-the-art implementations. Also following the merging of this, I expect for the old crypto API implementations to be ported over to use Zinc for their software-based implementations. As Zinc is simply library code, its config options are un-menued, with the exception of CONFIG_ZINC_DEBUG, which enables various selftests and BUG_ONs.  https://github.com/project-everest/hacl-star  https://github.com/mit-plv/fiat-crypto  https://cr.yp.to/ecdh.html  https://cr.yp.to/chacha.html  https://cr.yp.to/snuffle/xsalsa-20081128.pdf  https://cr.yp.to/mac.html  https://blake2.net/  https://tools.ietf.org/html/rfc8439  https://github.com/google/wycheproof Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Cc: Samuel Neves <email@example.com> Cc: Andy Lutomirski <firstname.lastname@example.org> Cc: Greg KH <email@example.com> Cc: Jean-Philippe Aumasson <firstname.lastname@example.org> --- MAINTAINERS | 8 ++++++++ lib/Kconfig | 2 ++ lib/Makefile | 2 ++ lib/zinc/Kconfig | 32 ++++++++++++++++++++++++++++++++ lib/zinc/Makefile | 3 +++ 5 files changed, 47 insertions(+) create mode 100644 lib/zinc/Kconfig create mode 100644 lib/zinc/Makefile diff --git a/MAINTAINERS b/MAINTAINERS index 4327777dce57..5967c737f3ce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16170,6 +16170,14 @@ Q: https://patchwork.linuxtv.org/project/linux-media/list/ S: Maintained F: drivers/media/dvb-frontends/zd1301_demod* +ZINC CRYPTOGRAPHY LIBRARY +M: Jason A. Donenfeld <Jason@zx2c4.com> +M: Samuel Neves <email@example.com> +S: Maintained +F: lib/zinc/ +F: include/zinc/ +L: firstname.lastname@example.org + ZPOOL COMPRESSED PAGE STORAGE API M: Dan Streetman <email@example.com> L: firstname.lastname@example.org diff --git a/lib/Kconfig b/lib/Kconfig index a3928d4438b5..3e6848269c66 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -485,6 +485,8 @@ config GLOB_SELFTEST module load) by a small amount, so you're welcome to play with it, but you probably don't need it. +source "lib/zinc/Kconfig" + # # Netlink attribute parsing support is select'ed if needed # diff --git a/lib/Makefile b/lib/Makefile index ca3f7ebb900d..571d28d3f143 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -214,6 +214,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o obj-$(CONFIG_ASN1) += asn1_decoder.o +obj-y += zinc/ + obj-$(CONFIG_FONT_SUPPORT) += fonts/ obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.o diff --git a/lib/zinc/Kconfig b/lib/zinc/Kconfig new file mode 100644 index 000000000000..4e2e59126a67 --- /dev/null +++ b/lib/zinc/Kconfig @@ -0,0 +1,32 @@ +config ZINC_DEBUG + bool "Zinc cryptography library debugging and self-tests" + help + This builds a series of self-tests for the Zinc crypto library, which + help diagnose any cryptographic algorithm implementation issues that + might be at the root cause of potential bugs. It also adds various + debugging traps. + + Unless you're developing and testing cryptographic routines, or are + especially paranoid about correctness on your hardware, you may say + N here. + +config ZINC_ARCH_ARM + def_bool y + depends on ARM && !64BIT + +config ZINC_ARCH_ARM64 + def_bool y + depends on ARM64 && 64BIT + +config ZINC_ARCH_X86_64 + def_bool y + depends on X86_64 && 64BIT + depends on !UML + +config ZINC_ARCH_MIPS + def_bool y + depends on MIPS && CPU_MIPS32_R2 && !64BIT + +config ZINC_ARCH_MIPS64 + def_bool y + depends on MIPS && 64BIT diff --git a/lib/zinc/Makefile b/lib/zinc/Makefile new file mode 100644 index 000000000000..a61c80d676cb --- /dev/null +++ b/lib/zinc/Makefile @@ -0,0 +1,3 @@ +ccflags-y := -O2 +ccflags-y += -D'pr_fmt(fmt)="zinc: " fmt' +ccflags-$(CONFIG_ZINC_DEBUG) += -DDEBUG -- 2.19.0
next prev parent reply other threads:[~2018-09-25 14:56 UTC|newest] Thread overview: 146+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-25 14:55 [PATCH net-next v6 00/23] WireGuard: Secure Network Tunnel Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 01/23] asm: simd context helper API Jason A. Donenfeld 2018-09-28 8:28 ` Ard Biesheuvel 2018-09-28 8:49 ` Ard Biesheuvel 2018-09-28 13:47 ` Jason A. Donenfeld 2018-09-28 13:52 ` Ard Biesheuvel 2018-09-28 13:59 ` Jason A. Donenfeld 2018-09-28 14:00 ` Ard Biesheuvel 2018-09-28 14:01 ` Jason A. Donenfeld 2018-09-30 4:20 ` Joe Perches 2018-09-30 5:35 ` Andy Lutomirski 2018-10-01 1:43 ` Jason A. Donenfeld 2018-10-02 7:18 ` Ard Biesheuvel 2018-09-28 13:45 ` Jason A. Donenfeld 2018-09-25 14:56 ` Jason A. Donenfeld [this message] 2018-09-25 18:33 ` [PATCH net-next v6 02/23] zinc: introduce minimal cryptography library Joe Perches 2018-09-25 19:43 ` Jason A. Donenfeld 2018-09-25 20:00 ` Andy Lutomirski 2018-09-25 20:02 ` Jason A. Donenfeld 2018-09-25 20:05 ` Joe Perches 2018-09-25 20:12 ` Jason A. Donenfeld 2018-09-25 20:21 ` Joe Perches 2018-09-25 20:54 ` Jason A. Donenfeld 2018-09-25 21:02 ` Joe Perches 2018-09-25 21:03 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 03/23] zinc: ChaCha20 generic C implementation and selftest Jason A. Donenfeld 2018-09-28 15:40 ` Ard Biesheuvel 2018-09-29 1:53 ` Jason A. Donenfeld 2018-10-02 3:15 ` Herbert Xu 2018-10-02 3:18 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 04/23] zinc: ChaCha20 x86_64 implementation Jason A. Donenfeld 2018-09-28 15:47 ` Ard Biesheuvel 2018-09-29 2:01 ` Jason A. Donenfeld 2018-09-29 7:56 ` Borislav Petkov 2018-09-29 8:00 ` Ard Biesheuvel 2018-09-29 8:11 ` Borislav Petkov 2018-09-29 8:27 ` Abel Vesa 2018-10-02 1:09 ` Jason A. Donenfeld 2018-10-02 1:07 ` Jason A. Donenfeld 2018-10-02 3:18 ` Herbert Xu 2018-10-02 3:20 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 05/23] zinc: import Andy Polyakov's ChaCha20 ARM and ARM64 implementations Jason A. Donenfeld 2018-09-28 15:49 ` Ard Biesheuvel 2018-09-28 15:51 ` Ard Biesheuvel 2018-09-28 15:57 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 06/23] zinc: port " Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 07/23] zinc: " Jason A. Donenfeld 2018-09-26 8:59 ` Ard Biesheuvel 2018-09-26 13:32 ` Jason A. Donenfeld 2018-09-26 14:02 ` Ard Biesheuvel 2018-09-26 15:41 ` Jason A. Donenfeld 2018-09-26 16:54 ` Ard Biesheuvel 2018-09-26 17:07 ` Jason A. Donenfeld 2018-09-26 17:37 ` Eric Biggers 2018-09-26 17:46 ` Jason A. Donenfeld 2018-09-26 15:41 ` Ard Biesheuvel 2018-09-26 15:45 ` Jason A. Donenfeld 2018-09-26 15:49 ` Jason A. Donenfeld 2018-09-26 15:51 ` Ard Biesheuvel 2018-09-26 15:58 ` Jason A. Donenfeld 2018-09-27 0:04 ` Jason A. Donenfeld 2018-09-27 13:26 ` Jason A. Donenfeld 2018-09-27 15:19 ` Jason A. Donenfeld 2018-09-27 16:26 ` Andy Lutomirski 2018-09-27 17:06 ` Jason A. Donenfeld 2018-09-26 16:21 ` Andy Lutomirski 2018-09-26 17:03 ` Jason A. Donenfeld 2018-09-26 17:08 ` Ard Biesheuvel 2018-09-26 17:23 ` Andy Lutomirski 2018-09-26 14:36 ` Andrew Lunn 2018-09-26 15:25 ` Jason A. Donenfeld 2018-09-28 16:01 ` Ard Biesheuvel 2018-09-29 2:20 ` Jason A. Donenfeld 2018-09-29 6:16 ` Ard Biesheuvel 2018-09-30 2:33 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 08/23] zinc: ChaCha20 MIPS32r2 implementation Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 09/23] zinc: Poly1305 generic C implementations and selftest Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 10/23] zinc: Poly1305 x86_64 implementation Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 11/23] zinc: import Andy Polyakov's Poly1305 ARM and ARM64 implementations Jason A. Donenfeld 2018-10-03 6:12 ` Eric Biggers 2018-10-03 7:58 ` Ard Biesheuvel 2018-10-03 14:08 ` Jason A. Donenfeld 2018-10-03 14:45 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 12/23] zinc: " Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 13/23] zinc: Poly1305 MIPS32r2 and MIPS64 implementations Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 14/23] zinc: ChaCha20Poly1305 construction and selftest Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 15/23] zinc: BLAKE2s generic C implementation " Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 16/23] zinc: BLAKE2s x86_64 implementation Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 17/23] zinc: Curve25519 generic C implementations and selftest Jason A. Donenfeld 2018-09-25 18:38 ` Joe Perches 2018-09-25 14:56 ` [PATCH net-next v6 18/23] zinc: Curve25519 x86_64 implementation Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 19/23] zinc: Curve25519 ARM implementation Jason A. Donenfeld 2018-10-02 16:59 ` Ard Biesheuvel 2018-10-02 21:35 ` Richard Weinberger 2018-10-03 1:03 ` Jason A. Donenfeld 2018-10-05 15:05 ` D. J. Bernstein 2018-10-05 15:16 ` Ard Biesheuvel 2018-10-05 18:40 ` Jason A. Donenfeld 2018-10-03 3:10 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 20/23] crypto: port Poly1305 to Zinc Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 21/23] crypto: port ChaCha20 " Jason A. Donenfeld 2018-10-02 3:26 ` Herbert Xu 2018-10-02 3:31 ` Jason A. Donenfeld 2018-10-03 5:56 ` Eric Biggers 2018-10-03 14:01 ` Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 22/23] security/keys: rewrite big_key crypto to use Zinc Jason A. Donenfeld 2018-09-25 14:56 ` [PATCH net-next v6 23/23] net: WireGuard secure network tunnel Jason A. Donenfeld 2018-09-26 16:00 ` Ivan Labáth 2018-09-26 16:04 ` Jason A. Donenfeld 2018-11-05 13:06 ` Ivan Labáth 2018-11-12 23:53 ` Jason A. Donenfeld 2018-11-13 0:10 ` Dave Taht 2018-11-13 0:13 ` Jason A. Donenfeld 2018-09-27 1:15 ` Andrew Lunn 2018-09-27 22:37 ` Jason A. Donenfeld 2018-09-28 1:09 ` Jason A. Donenfeld 2018-09-28 15:01 ` Andrew Lunn 2018-09-28 15:04 ` Jason A. Donenfeld 2018-10-03 11:15 ` Ard Biesheuvel 2018-10-03 14:12 ` Jason A. Donenfeld 2018-10-03 14:13 ` Ard Biesheuvel 2018-10-03 14:25 ` Ard Biesheuvel 2018-10-03 14:28 ` Jason A. Donenfeld 2018-09-27 18:29 ` [PATCH net-next v6 00/23] WireGuard: Secure Network Tunnel Eric Biggers 2018-09-27 21:35 ` Jason A. Donenfeld 2018-09-28 1:17 ` Eric Biggers 2018-09-28 2:35 ` Jason A. Donenfeld 2018-09-28 4:55 ` Eric Biggers 2018-09-28 5:46 ` Jason A. Donenfeld 2018-09-28 7:52 ` Ard Biesheuvel 2018-09-28 13:40 ` Jason A. Donenfeld 2018-10-02 3:39 ` Herbert Xu 2018-10-02 3:45 ` Jason A. Donenfeld 2018-10-02 3:49 ` Herbert Xu 2018-10-02 6:04 ` Ard Biesheuvel 2018-10-02 6:43 ` Richard Weinberger 2018-10-02 12:22 ` Jason A. Donenfeld 2018-10-03 6:49 ` Eric Biggers 2018-10-05 13:13 ` Jason A. Donenfeld 2018-10-05 13:37 ` Richard Weinberger 2018-10-05 13:46 ` Jason A. Donenfeld 2018-10-05 13:53 ` Richard Weinberger 2018-10-05 17:50 ` David Miller 2018-09-28 17:47 ` Ard Biesheuvel 2018-09-29 2:40 ` Jason A. Donenfeld 2018-09-29 5:35 ` Willy Tarreau
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=20180925145622.29959-3-Jason@zx2c4.com \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH net-next v6 02/23] zinc: introduce minimal cryptography library' \ /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
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).