WireGuard: Secure Network Tunnel
Subsystems (26)
Jason A. Donenfeld
maintainerv3 cover WireGuard: Secure Network Tunnel
This patchset is available on git.kernel.org in this branch, where it may be pulled directly for inclusion into net-next:
* https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/log/?h=jd/wireguard
WireGuard is a secure network tunnel written especially for Linux, which has faced around three years of serious development, deployment, and scrutiny. It delivers excellent performance and is extremely easy to use and configure. It has been designed with the primary goal of being both easy to audit by virtue of being small and highly secure from a cryptography and systems security perspective. WireGuard is used by some massive companies pushing enormous amounts of traffic, and likely already today you've consumed bytes that at some point transited through a WireGuard tunnel. Even as an out-of-tree module, WireGuard has been integrated into various userspace tools, Linux distributions, mobile phones, and data centers. There are ports in several languages to several operating systems, and even commercial hardware and services sold integrating WireGuard. It is time, therefore, for WireGuard to be properly integrated into Linux.
Ample information, including documentation, installation instructions, and project details, is available at:
* https://www.wireguard.com/
* https://www.wireguard.com/papers/wireguard.pdf
As it is currently an out-of-tree module, it lives in its own git repo and has its own mailing list, and every commit for the module is tested against every stable kernel since 3.10 on a variety of architectures using an extensive test suite:
* https://git.zx2c4.com/WireGuard
https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/WireGuard.git/
* https://lists.zx2c4.com/mailman/listinfo/wireguard
* https://www.wireguard.com/build-status/
The project has been broadly discussed at conferences, and was presented to the Netdev developers in Seoul last November, where a paper was released detailing some interesting aspects of the project. Dave asked me after the talk if I would consider sending in a v1 "sooner rather than later", hence this patchset. A decision is still waiting from the Linux Plumbers Conference, but an update on these topics may be presented in Vancouver in a few months. Prior presentations:
* https://www.wireguard.com/presentations/
* https://www.wireguard.com/papers/wireguard-netdev22.pdf
The cryptography in the protocol itself has been formally verified by several independent academic teams with positive results, and I know of two additional efforts on their way to further corroborate those findings. The version 1 protocol is "complete", and so the purpose of this review is to assess the implementation of the protocol. However, it still may be of interest to know that the thing you're reviewing uses a protocol with various nice security properties:
* https://www.wireguard.com/formal-verification/
This patchset is divided into three segments. The first introduces a very simple helper for working with the FPU state for the purposes of amortizing SIMD operations. The second segment is a small collection of cryptographic primitives, split up into several commits by primitive and by hardware. The third is WireGuard itself, presented as an unintrusive and self-contained virtual network driver.
It is intended that this entire patch series enter the kernel through DaveM's net-next tree. Subsequently, WireGuard patches will go through DaveM's net-next tree, while Zinc patches will go through Greg KH's tree.
Changes v2->v3:
- 80 column formatting of Zinc.
- Remaining relevant checkpatch.pl concerns in WireGuard addressed.
- More idomatic ARM assembly or Curve25519.
- Numerous cleanups.
- Corrected licensing situation of CRYPTOGAMS-based code (from Andy Polyakov).
Enjoy,
Jason
Jason A. Donenfeld
maintainerPATCH v3 1/17 asm: simd context helper API
Sometimes it's useful to amortize calls to XSAVE/XRSTOR and the related FPU/SIMD functions over a number of calls, because FPU restoration is quite expensive. This adds a simple header for carrying out this pattern:
simd_context_t simd_context = simd_get();
while ((item = get_item_from_queue()) != NULL) {
encrypt_item(item, simd_context);
simd_context = simd_relax(simd_context);
}
simd_put(simd_context);The relaxation step ensures that we don't trample over preemption, and the get/put API should be a familiar paradigm in the kernel.
--- arch/alpha/include/asm/Kbuild | 5 ++-- arch/arc/include/asm/Kbuild | 1 + arch/arm/include/asm/simd.h | 42 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/simd.h | 37 +++++++++++++++++++++----- arch/c6x/include/asm/Kbuild | 3 ++- arch/h8300/include/asm/Kbuild | 3 ++- arch/hexagon/include/asm/Kbuild | 1 + arch/ia64/include/asm/Kbuild | 1 + arch/m68k/include/asm/Kbuild | 1 + arch/microblaze/include/asm/Kbuild | 1 + arch/mips/include/asm/Kbuild | 1 + arch/nds32/include/asm/Kbuild | 7 ++--- arch/nios2/include/asm/Kbuild | 1 + arch/openrisc/include/asm/Kbuild | 7 ++--- arch/parisc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/Kbuild | 3 ++- arch/riscv/include/asm/Kbuild | 3 ++- arch/s390/include/asm/Kbuild | 3 ++- arch/sh/include/asm/Kbuild | 1 + arch/sparc/include/asm/Kbuild | 1 + arch/um/include/asm/Kbuild | 3 ++- arch/unicore32/include/asm/Kbuild | 1 + arch/x86/include/asm/simd.h | 30 ++++++++++++++++++++- arch/xtensa/include/asm/Kbuild | 1 + include/asm-generic/simd.h | 15 +++++++++++ include/linux/simd.h | 28 ++++++++++++++++++++ 26 files changed, 180 insertions(+), 21 deletions(-) create mode 100644 arch/arm/include/asm/simd.h create mode 100644 include/linux/simd.h
arch/alpha/include/asm/Kbuild +3 -2
@@ -2,14 +2,15 @@ generic-y += compat.h +generic-y += current.h generic-y += exec.h generic-y += export.h generic-y += fb.h generic-y += irq_work.h +generic-y += kprobes.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += sections.h +generic-y += simd.h generic-y += trace_clock.h -generic-y += current.h -generic-y += kprobes.h
arch/arc/include/asm/Kbuild +1 -0
@@ -22,6 +22,7 @@ generic-y += parport.h generic-y += pci.h generic-y += percpu.h generic-y += preempt.h +generic-y += simd.h generic-y += topology.h generic-y += trace_clock.h generic-y += user.h
arch/arm/include/asm/simd.h new file +42 -0
42 lines not on this page · raw message
arch/arm64/include/asm/simd.h +31 -6
@@ -1,11 +1,10 @@ -/* -* Copyright (C) 2017 Linaro Ltd. <[email protected]> +/* SPDX-License-Identifier: GPL-2.0 * -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published -* by the Free Software Foundation. +* Copyright (C) 2017 Linaro Ltd. <[email protected]> +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. */ +#include <linux/simd.h> #ifndef __ASM_SIMD_H#define __ASM_SIMD_H
@@ -16,6 +15,8 @@#include <linux/types.h> #ifdef CONFIG_KERNEL_MODE_NEON +#include <asm/neon.h> +#include <asm/simd.h> DECLARE_PER_CPU (bool, kernel_neon_busy);
@@ -40,12 +41,36 @@ static __must_check inline bool may_use_simd(void) !this_cpu_read (kernel_neon_busy); } +static inline simd_context_t simd_get (void ) +{ +bool have_simd =may_use_simd (); +if (have_simd) +kernel_neon_begin (); +return have_simd ?HAVE_FULL_SIMD :HAVE_NO_SIMD ; +} + +static inline void simd_put (simd_context_t prior_context) +{ +if (prior_context !=HAVE_NO_SIMD ) +kernel_neon_end (); +} +#else /* ! CONFIG_KERNEL_MODE_NEON */ -static __must_check inline bool may_use_simd (void ) { +static __must_check inline bool may_use_simd (void ) +{return false; } +static inline simd_context_t simd_get (void ) +{ +return HAVE_NO_SIMD ; +} + +static inline void simd_put (simd_context_t prior_context) +{ +} +#endif /* ! CONFIG_KERNEL_MODE_NEON */ #endif
arch/c6x/include/asm/Kbuild +2 -1
@@ -5,8 +5,8 @@ generic-y += compat.h generic-y += current.h generic-y += device.h generic-y += div64.h -generic-y += dma.h generic-y += dma-mapping.h +generic-y += dma.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
@@ -30,6 +30,7 @@ generic-y += pgalloc.h generic-y += preempt.h generic-y += segment.h generic-y += serial.h +generic-y += simd.h generic-y += tlbflush.h generic-y += topology.h generic-y += trace_clock.h
arch/h8300/include/asm/Kbuild +2 -1
@@ -8,8 +8,8 @@ generic-y += current.h generic-y += delay.h generic-y += device.h generic-y += div64.h -generic-y += dma.h generic-y += dma-mapping.h +generic-y += dma.h generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h
@@ -39,6 +39,7 @@ generic-y += preempt.h generic-y += scatterlist.h generic-y += sections.h generic-y += serial.h +generic-y += simd.h generic-y += sizes.h generic-y += spinlock.h generic-y += timex.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -29,6 +29,7 @@ generic-y += rwsem.h generic-y += sections.h generic-y += segment.h generic-y += serial.h +generic-y += simd.h generic-y += sizes.h generic-y += topology.h generic-y += trace_clock.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -4,6 +4,7 @@ generic-y += irq_work.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h generic-y += preempt.h +generic-y += simd.h generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -19,6 +19,7 @@ generic-y += mm-arch-hooks.h generic-y += percpu.h generic-y += preempt.h generic-y += sections.h +generic-y += simd.h generic-y += spinlock.h generic-y += topology.h generic-y += trace_clock.h
arch/microblaze/include/asm/Kbuild +1 -0
@@ -25,6 +25,7 @@ generic-y += parport.h generic-y += percpu.h generic-y += preempt.h generic-y += serial.h +generic-y += simd.h generic-y += syscalls.h generic-y += topology.h generic-y += trace_clock.h
arch/mips/include/asm/Kbuild +1 -0
@@ -16,6 +16,7 @@ generic-y += qrwlock.h generic-y += qspinlock.h generic-y += sections.h generic-y += segment.h +generic-y += simd.h generic-y += trace_clock.h generic-y += unaligned.h generic-y += user.h
arch/nds32/include/asm/Kbuild +4 -3
@@ -7,14 +7,14 @@ generic-y += bug.h generic-y += bugs.h generic-y += checksum.h generic-y += clkdev.h -generic-y += cmpxchg.h generic-y += cmpxchg-local.h +generic-y += cmpxchg.h generic-y += compat.h generic-y += cputime.h generic-y += device.h generic-y += div64.h -generic-y += dma.h generic-y += dma-mapping.h +generic-y += dma.h generic-y += emergency-restart.h generic-y += errno.h generic-y += exec.h
@@ -46,14 +46,15 @@ generic-y += sections.h generic-y += segment.h generic-y += serial.h generic-y += shmbuf.h +generic-y += simd.h generic-y += sizes.h generic-y += stat.h generic-y += switch_to.h generic-y += timex.h generic-y += topology.h generic-y += trace_clock.h -generic-y += xor.h generic-y += unaligned.h generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h +generic-y += xor.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -33,6 +33,7 @@ generic-y += preempt.h generic-y += sections.h generic-y += segment.h generic-y += serial.h +generic-y += simd.h generic-y += spinlock.h generic-y += topology.h generic-y += trace_clock.h
arch/openrisc/include/asm/Kbuild +4 -3
@@ -28,12 +28,13 @@ generic-y += module.h generic-y += pci.h generic-y += percpu.h generic-y += preempt.h -generic-y += qspinlock_types.h -generic-y += qspinlock.h -generic-y += qrwlock_types.h generic-y += qrwlock.h +generic-y += qrwlock_types.h +generic-y += qspinlock.h +generic-y += qspinlock_types.h generic-y += sections.h generic-y += segment.h +generic-y += simd.h generic-y += string.h generic-y += switch_to.h generic-y += topology.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -17,6 +17,7 @@ generic-y += percpu.h generic-y += preempt.h generic-y += seccomp.h generic-y += segment.h +generic-y += simd.h generic-y += topology.h generic-y += trace_clock.h generic-y += user.h
arch/powerpc/include/asm/Kbuild +2 -1
@@ -4,7 +4,8 @@ generic-y += irq_regs.h generic-y += irq_work.h generic-y += local64.h generic-y += mcs_spinlock.h +generic-y += msi.h generic-y += preempt.h generic-y += rwsem.h +generic-y += simd.h generic-y += vtime.h -generic-y += msi.h
arch/riscv/include/asm/Kbuild +2 -1
@@ -5,9 +5,9 @@ generic-y += compat.h generic-y += cputime.h generic-y += device.h generic-y += div64.h -generic-y += dma.h generic-y += dma-contiguous.h generic-y += dma-mapping.h +generic-y += dma.h generic-y += emergency-restart.h generic-y += errno.h generic-y += exec.h
@@ -46,6 +46,7 @@ generic-y += setup.h generic-y += shmbuf.h generic-y += shmparam.h generic-y += signal.h +generic-y += simd.h generic-y += socket.h generic-y += sockios.h generic-y += stat.h
arch/s390/include/asm/Kbuild +2 -1
@@ -7,9 +7,9 @@ generated-y += unistd_nr.h generic-y += asm-offsets.h generic-y += cacheflush.h generic-y += device.h +generic-y += div64.h generic-y += dma-contiguous.h generic-y += dma-mapping.h -generic-y += div64.h generic-y += emergency-restart.h generic-y += export.h generic-y += fb.h
@@ -22,6 +22,7 @@ generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += rwsem.h +generic-y += simd.h generic-y += trace_clock.h generic-y += unaligned.h generic-y += word-at-a-time.h
arch/sh/include/asm/Kbuild +1 -0
@@ -16,6 +16,7 @@ generic-y += percpu.h generic-y += preempt.h generic-y += rwsem.h generic-y += serial.h +generic-y += simd.h generic-y += sizes.h generic-y += trace_clock.h generic-y += xor.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -17,5 +17,6 @@ generic-y += msi.h generic-y += preempt.h generic-y += rwsem.h generic-y += serial.h +generic-y += simd.h generic-y += trace_clock.h generic-y += word-at-a-time.h
arch/um/include/asm/Kbuild +2 -1
@@ -16,15 +16,16 @@ generic-y += io.h generic-y += irq_regs.h generic-y += irq_work.h generic-y += kdebug.h +generic-y += kprobes.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h generic-y += param.h generic-y += pci.h generic-y += percpu.h generic-y += preempt.h +generic-y += simd.h generic-y += switch_to.h generic-y += topology.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += xor.h -generic-y += kprobes.h
arch/unicore32/include/asm/Kbuild +1 -0
@@ -27,6 +27,7 @@ generic-y += preempt.h generic-y += sections.h generic-y += segment.h generic-y += serial.h +generic-y += simd.h generic-y += sizes.h generic-y += syscalls.h generic-y += topology.h
arch/x86/include/asm/simd.h +29 -1
@@ -1,4 +1,11 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#include <linux/simd.h> +#ifndef _ASM_SIMD_H +#define _ASM_SIMD_H#include <asm/fpu/api.h>
@@ -10,3 +17,24 @@ static __must_check inline bool may_use_simd(void) {return irq_fpu_usable (); } + +static inline simd_context_t simd_get (void ) +{ +bool have_simd = false; +#if !defined(CONFIG_UML ) + have_simd =may_use_simd (); +if (have_simd) +kernel_fpu_begin (); +#endif +return have_simd ?HAVE_FULL_SIMD :HAVE_NO_SIMD ; +} + +static inline void simd_put (simd_context_t prior_context) +{ +#if !defined(CONFIG_UML ) +if (prior_context !=HAVE_NO_SIMD ) +kernel_fpu_end (); +#endif +} + +#endif /* _ASM_SIMD_H */
arch/xtensa/include/asm/Kbuild +1 -0
@@ -24,6 +24,7 @@ generic-y += percpu.h generic-y += preempt.h generic-y += rwsem.h generic-y += sections.h +generic-y += simd.h generic-y += topology.h generic-y += trace_clock.h generic-y += word-at-a-time.h
include/asm-generic/simd.h +15 -0
@@ -1,5 +1,9 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/simd.h> +#ifndef _ASM_SIMD_H +#define _ASM_SIMD_H +#include <linux/hardirq.h> /*
@@ -13,3 +17,14 @@ static __must_check inline bool may_use_simd(void) {return !in_interrupt (); } + +static inline simd_context_t simd_get (void ) +{ +return HAVE_NO_SIMD ; +} + +static inline void simd_put (simd_context_t prior_context) +{ +} + +#endif /* _ASM_SIMD_H */
include/linux/simd.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _SIMD_H +#define _SIMD_H + +typedef enum { +HAVE_NO_SIMD , +HAVE_FULL_SIMD +}simd_context_t ; + +#include <linux/sched.h> +#include <asm/simd.h> + +static inline simd_context_t simd_relax (simd_context_t prior_context) +{ +#ifdef CONFIG_PREEMPT +if (prior_context !=HAVE_NO_SIMD &&need_resched ()) { +simd_put (prior_context); +return simd_get (); + } +#endif +return prior_context; +} + +#endif /* _SIMD_H */
Signature · 1 line
2.18.0
Re: [PATCH net-next v3 01/17] asm: simd context helper API
Quoted 11 lines · Jason A. Donenfeld
Sometimes it's useful to amortize calls to XSAVE/XRSTOR and the related FPU/SIMD functions over a number of calls, because FPU restoration is quite expensive. This adds a simple header for carrying out this pattern:
simd_context_t simd_context = simd_get(); while ((item = get_item_from_queue()) != NULL) { encrypt_item(item, simd_context); simd_context = simd_relax(simd_context); } simd_put(simd_context);
Quoted 2 lines
The relaxation step ensures that we don't trample over preemption, and the get/put API should be a familiar paradigm in the kernel.
Given that it's always supposed to be used like that, mightn't it be better if simd_relax() took a pointer to the context, so the call is just
simd_relax(&simd_context);
?
The inlining means that there won't actually be a pointer dereference in the emitted code.
If simd_put() also took a pointer then it could set the context back to HAVE_NO_SIMD as well?
- Kevin
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 01/17] asm: simd context helper API
Quoted 6 lines · Kevin Easton
Given that it's always supposed to be used like that, mightn't it be better if
simd_relax()took a pointer to the context, so the call is justsimd_relax(&simd_context);
Quoted 7 lines
?
The inlining means that there won't actually be a pointer dereference in the emitted code.
If
simd_put()also took a pointer then it could set the context back toHAVE_NO_SIMDas well?
That's sort of a neat idea. I guess in this scheme, you'd envision:
simd_context_t simd_context;
simd_get(&simd_context); simd_relax(&simd_context); simd_put(&simd_context);
And this way, if simd_context ever becomes a heavier struct, it can be modified in place rather than returned by value from the function. On the other hand, it's a little bit more annoying to type and makes it harder to do declaration and initialization on the same line.
Re: [PATCH net-next v3 01/17] asm: simd context helper API
Quoted 23 lines · Jason A. Donenfeld
Quoted 6 lines · Kevin Easton
Given that it's always supposed to be used like that, mightn't it be better if
simd_relax()took a pointer to the context, so the call is justsimd_relax(&simd_context);Quoted 7 lines
?
The inlining means that there won't actually be a pointer dereference in the emitted code.
If
simd_put()also took a pointer then it could set the context back toHAVE_NO_SIMDas well?That's sort of a neat idea. I guess in this scheme, you'd envision:
simd_context_t simd_context; simd_get(&simd_context); simd_relax(&simd_context); simd_put(&simd_context);
Quoted 4 lines
And this way, if
simd_contextever becomes a heavier struct, it can be modified in place rather than returned by value from the function. On the other hand, it's a little bit more annoying to type and makes it harder to do declaration and initialization on the same line.
Yes. It's also how most get/put APIs already work in the kernel, eg kref_get/put (mostly because they tend to be 'getting/putting' an already-initialized object, though).
- Kevin
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 01/17] asm: simd context helper API
Quoted 3 lines · Kevin Easton
Yes. It's also how most get/put APIs already work in the kernel, eg kref_get/put (mostly because they tend to be 'getting/putting' an already-initialized object, though).
Right; in this case the object wouldn't be initialized yet, which might defeat the purpose, since one advantage of the & way you mentioned is _put modifies the context.
Andy - any opinions on this? The tl;dr is:
1) what we have now:
simd_context_t simd_context = simd_get();
for (item in items) {
do_something(item);
simd_context = simd_relax(simd_context);
}simd_put();
2) what kevin is proposing:
simd_context_t simd_context;
simd_get(&simd_context);
for (item in items) {
do_something(item);
simd_relax(&simd_context);
}simd_put(&simd_context);
I can see pros and cons of each approach.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 01/17] asm: simd context helper API
Quoted 1 line · Jason A. Donenfeld
simd_put();
Rather, simd_put(simd_context);
Re: [PATCH net-next v3 01/17] asm: simd context helper API
In reply to Jason A. DonenfeldQuoted 27 lines · Jason A. Donenfeld
Quoted 5 lines · Kevin Easton
Yes. It's also how most get/put APIs already work in the kernel, eg kref_get/put (mostly because they tend to be 'getting/putting' an already-initialized object, though).
Right; in this case the object wouldn't be initialized yet, which might defeat the purpose, since one advantage of the & way you mentioned is
_putmodifies the context.Andy - any opinions on this? The tl;dr is:
1) what we have now:
simd_context_tsimd_context=simd_get();for (item in items) { do_something(item); simd_context = simd_relax(simd_context); }
simd_put();2) what kevin is proposing:
simd_context_tsimd_context;
Quoted 8 lines
simd_get(&simd_context);for (item in items) { do_something(item); simd_relax(&simd_context); }
simd_put(&simd_context);I can see pros and cons of each approach.
I have no strong opinion, except that, if you paint the bikeshed “pass by value”, then simd_get and simd_relax should probably have warn_unused_result set.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 01/17] asm: simd context helper API
Quoted 1 line · Andy Lutomirski
I have no strong opinion, except that, if you paint the bikeshed “pass by value”, then
simd_getandsimd_relaxshould probably havewarn_unused_resultset.
Good idea.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 01/17] asm: simd context helper API
In reply to Kevin EastonHey Kevin,
I found numerous other advantages in doing it the way you suggested (which also helped squash some bugs), and so this will be part of v5. Thanks for the suggestion.
Regards,
Jason
Jason A. Donenfeld
maintainerPATCH v3 2/17 zinc: introduce minimal cryptography library
In reply to Jason A. DonenfeldZinc 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* [1] and Fiat-Crypto [2]. 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 [9].
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.
[1] https://github.com/project-everest/hacl-star
[2] https://github.com/mit-plv/fiat-crypto
[3] https://cr.yp.to/ecdh.html
[4] https://cr.yp.to/chacha.html
[5] https://cr.yp.to/snuffle/xsalsa-20081128.pdf
[6] https://cr.yp.to/mac.html
[7] https://blake2.net/
[8] https://tools.ietf.org/html/rfc8439
[9] https://github.com/google/wycheproof
--- MAINTAINERS | 8 ++++++++ lib/Kconfig | 2 ++ lib/Makefile | 2 ++ lib/zinc/Kconfig | 20 ++++++++++++++++++++ lib/zinc/Makefile | 8 ++++++++ lib/zinc/main.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+) create mode 100644 lib/zinc/Kconfig create mode 100644 lib/zinc/Makefile create mode 100644 lib/zinc/main.c
MAINTAINERS +8 -0
@@ -16160,6 +16160,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 <[email protected]> +M: Samuel Neves <[email protected]> +S: Maintained +F: lib/zinc/ +F: include/zinc/ +L: [email protected] + ZPOOL COMPRESSED PAGE STORAGE API M: Dan Streetman <[email protected]> L: [email protected]
lib/Kconfig +2 -0
@@ -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 #
lib/Makefile +2 -0
@@ -214,6 +214,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o obj-$(CONFIG_ASN1) += asn1_decoder.o +obj-$(CONFIG_ZINC) += zinc/ + obj-$(CONFIG_FONT_SUPPORT) += fonts/ obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.o
lib/zinc/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +config ZINC + tristate + select CRYPTO_BLKCIPHER + select VFP + select VFPv3 + select NEON + select KERNEL_MODE_NEON + +config ZINC_DEBUG + bool "Zinc cryptography library debugging and self-tests" + depends on ZINC + 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.
lib/zinc/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +ccflags-y := -O3 +ccflags-y += -Wframe-larger-than=8192 +ccflags-y += -D'pr_fmt(fmt)=KBUILD_MODNAME ": " fmt' +ccflags-$(CONFIG_ZINC_DEBUG) += -DDEBUG + +zinc-y += main.o + +obj-$(CONFIG_ZINC) := zinc.o
lib/zinc/main.c new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#include <linux/init.h> +#include <linux/module.h> + +#ifdef DEBUG +#define selftest (which) do { \ + if (!which ## _selftest()) \ + return -ENOTRECOVERABLE; \ +} while (0) +#else +#define selftest (which) +#endif + +static int __init mod_init (void ) +{ +return 0 ; +} + +static void __exit mod_exit(void) +{ +} + +module_init (mod_init); +module_exit (mod_exit); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Zinc cryptography library" ); +MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" );
Signature · 1 line
2.18.0
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 123 lines · Jason A. Donenfeld
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 intolib/, 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 inlib/rather than incrypto/. Zinc intends to stop the cluttering oflib/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 inlib/zinc/, making it simple and obvious to compare and contrast what's happening. This is, notably, exactly what thelib/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* [1] and Fiat-Crypto [2]. 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 [9].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 intolib/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.
Quoted 8 lines
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 andBUG_ONs.
In spite of the wall of text, you fail to point out exactly why the existing AEAD API in unsuitable, and why fixing it is not an option.
As I pointed out in a previous version, I don't think we need a separate crypto API/library in the kernel, and I don't think you have convinced anyone else yet either.
Perhaps you can devote /your/ rare talent and energy to improving what we already have for everybody's sake, rather than providing a completely separate crypto stack that only benefits WireGuard (unless you yourself port the existing crypto API software algorithms to this crypto stack first and present *that* work as a convincing case in itself)
I won't go into the 1000s lines of generated assembly again - you already know my position on that topic.
Please refrain from sending a v4 with just a couple of more tweaks on top - these are fundamental issues that require discussion before there is any chance of this being merged.
Quoted 153 lines
[1] https://github.com/project-everest/hacl-star
[2] https://github.com/mit-plv/fiat-crypto
[3] https://cr.yp.to/ecdh.html
[4] https://cr.yp.to/chacha.html
[5] https://cr.yp.to/snuffle/xsalsa-20081128.pdf
[6] https://cr.yp.to/mac.html
[7] https://blake2.net/
[8] https://tools.ietf.org/html/rfc8439
[9] https://github.com/google/wycheproofSigned-off-by Jason A. Donenfeld <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Greg KH <[email protected]>Cc Samuel Neves <[email protected]>Cc Jean-Philippe Aumasson <[email protected]>--- MAINTAINERS | 8 ++++++++ lib/Kconfig | 2 ++ lib/Makefile | 2 ++ lib/zinc/Kconfig | 20 ++++++++++++++++++++ lib/zinc/Makefile | 8 ++++++++ lib/zinc/main.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+) create mode 100644 lib/zinc/Kconfig create mode 100644 lib/zinc/Makefile create mode 100644 lib/zinc/main.cMAINTAINERS +8
-0@@ -16160,6 +16160,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 <[email protected]> +M: Samuel Neves <[email protected]> +S: Maintained +F: lib/zinc/ +F: include/zinc/ +L: [email protected] + ZPOOL COMPRESSED PAGE STORAGE API M: Dan Streetman <[email protected]> L: [email protected]lib/Kconfig +2
-0@@ -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 #lib/Makefile +2
-0@@ -214,6 +214,8 @@ obj-$(CONFIG_PERCPU_TEST) += percpu_test.o obj-$(CONFIG_ASN1) += asn1_decoder.o +obj-$(CONFIG_ZINC) += zinc/ + obj-$(CONFIG_FONT_SUPPORT) += fonts/ obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.olib/zinc/Kconfig new file +20
-0@@ -0,0 +1,20 @@ +config ZINC + tristate + select CRYPTO_BLKCIPHER + select VFP + select VFPv3 + select NEON + select KERNEL_MODE_NEON + +config ZINC_DEBUG + bool "Zinc cryptography library debugging and self-tests" + depends on ZINC + 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.lib/zinc/Makefile new file +8
-0@@ -0,0 +1,8 @@ +ccflags-y := -O3 +ccflags-y += -Wframe-larger-than=8192 +ccflags-y += -D'pr_fmt(fmt)=KBUILD_MODNAME ": " fmt' +ccflags-$(CONFIG_ZINC_DEBUG) += -DDEBUG + +zinc-y += main.o + +obj-$(CONFIG_ZINC) := zinc.olib/zinc/main.c new file +31
-1@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#include <linux/init.h> +#include <linux/module.h> + +#ifdef DEBUG +#define selftest (which) do { \ + if (!which ## _selftest()) \ + return -ENOTRECOVERABLE; \ +} while (0) +#else +#define selftest (which) +#endif + +static int __init mod_init (void ) +{ +return 0 ; +} + +static void __exit mod_exit(void) +{ +} + +module_init (mod_init); +module_exit (mod_exit); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Zinc cryptography library" ); +MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" ); --2.18.0
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 11 lines · Ard Biesheuvel
Quoted 4 lines
As Zinc is simply library code, its config options are un-menued, with the exception of
CONFIG_ZINC_DEBUG, which enables various selftests andBUG_ONs.In spite of the wall of text, you fail to point out exactly why the existing AEAD API in unsuitable, and why fixing it is not an option.
As I pointed out in a previous version, I don't think we need a separate crypto API/library in the kernel, and I don't think you have convinced anyone else yet either.
Um, then why do people keep sprinkling new crypto/hash code all around the kernel tree? It's because what we have as a crypto api is complex and is hard to use for many in-kernel users.
Something like this new interface (zinc) is a much "saner" api for writing kernel code that has to interact with crypto/hash primitives.
I see no reason why the existing crypto code can be redone to use the zinc crypto primitives over time, making there only be one main location for the crypto algorithms. But to do it the other way around is pretty much impossible given the complexities in the existing api that has been created over time.
Not to say that the existing api is not a viable one, but ugh, really? You have to admit it is a pain to try to use in any "normal" type of "here's a bytestream, go give me a hash" type of method, right?
Also there is the added benefit that the crypto primitives here have been audited by a number of people (so Jason stated), and they are written in a way that the crypto community can more easily interact and contribute to. Which is _way_ better than what we have today.
So this gets my "stamp of approval" for whatever it is worth :)
thanks,
greg k-h
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 30 lines · Greg Kroah-Hartman
Quoted 11 lines · Ard Biesheuvel
Quoted 4 lines
As Zinc is simply library code, its config options are un-menued, with the exception of
CONFIG_ZINC_DEBUG, which enables various selftests andBUG_ONs.In spite of the wall of text, you fail to point out exactly why the existing AEAD API in unsuitable, and why fixing it is not an option.
As I pointed out in a previous version, I don't think we need a separate crypto API/library in the kernel, and I don't think you have convinced anyone else yet either.
Um, then why do people keep sprinkling new
crypto/hashcode all around the kernel tree? It's because what we have as a crypto api is complex and is hard to use for many in-kernel users.Something like this new interface (zinc) is a much "saner" api for writing kernel code that has to interact with
crypto/hashprimitives.I see no reason why the existing crypto code can be redone to use the zinc crypto primitives over time, making there only be one main location for the crypto algorithms. But to do it the other way around is pretty much impossible given the complexities in the existing api that has been created over time.
Not to say that the existing api is not a viable one, but ugh, really? You have to admit it is a pain to try to use in any "normal" type of "here's a bytestream, go give me a hash" type of method, right?
Quoted 7 lines
Also there is the added benefit that the crypto primitives here have been audited by a number of people (so Jason stated), and they are written in a way that the crypto community can more easily interact and contribute to. Which is _way_ better than what we have today.
So this gets my "stamp of approval" for whatever it is worth :)
I think you mean you see no reason why it *cannot* be converted? The conversions definitely *should* be done, just like how some of the existing crypto API algorithms like SHA-256 already wrap implementations in lib/. In my view, lib/zinc/ isn't fundamentally different from what we already have for some algorithms. So it's misguided to design/present it as some novel thing, which unfortunately this patchset still does to a large extent. (The actual new thing is how architecture-specific implementations are handled.)
Of course, the real problem is that even after multiple revisions of this patchset, there's still no actual conversions of the existing crypto API algorithms over to use the new implementations. "Zinc" is still completely separate from the existing crypto API.
So, it's not yet clear that the conversions will actually work out without problems that would require changes in "Zinc". I don't think it makes sense to merge all this stuff without doing the conversions, or at the very least demonstrating how they will be done.
In particular, in its current form "Zinc" is useless for anyone that needs the existing crypto API. For example, for HPolyC,
(https://lkml.org/lkml/2018/8/6/857), I need to make improvements to ChaCha and Poly1305 in the existing crypto API, e.g. to add support for XChaCha and NEON-accelerated Poly1305. Having completely separate ChaCha and Poly1305 implementations in Zinc doesn't help at all. If anything, it makes things harder because people will have to review/maintain both sets of implementations; and when trying to make the improvements I need, I'll find myself in the middle of a holy war between two competing camps who each have their own opinion about The Right Way To Do Crypto, and their own crypto implementations and APIs in the kernel.
- Eric
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 4 lines · Eric Biggers
Of course, the real problem is that even after multiple revisions of this patchset, there's still no actual conversions of the existing crypto API algorithms over to use the new implementations. "Zinc" is still completely separate from the existing crypto API.
No this is not, "the real problem [...] after multiple revisions" because I've offered to do this and stated pretty clearly my intent to do so. But, as I've mentioned before, I'd really prefer to land this series through net-next, and then after we can turn our attention to integrating this into the existing crypto API. This series is already big enough and I would really prefer not to further complicate it.
So, what you want is going to happen. There isn't some kind of fundamental problem here. This is more of a discussion on scheduling/trees/mergecycles than anything else.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 10 lines · Jason A. Donenfeld
Quoted 4 lines · Eric Biggers
Of course, the real problem is that even after multiple revisions of this patchset, there's still no actual conversions of the existing crypto API algorithms over to use the new implementations. "Zinc" is still completely separate from the existing crypto API.
No this is not, "the real problem [...] after multiple revisions" because I've offered to do this and stated pretty clearly my intent to do so. But, as I've mentioned before, I'd really prefer to land this series through net-next
Hi Jason
Just as an FYI:
1) I don't think anybody in netdev has taken a serious look at the network code yet. There is little point until the controversial part of the code, Zinc, has been sorted out.
2) I personally would be surprised if DaveM took this code without having an Acked-by from the crypto subsystem people. In the same way, i doubt the crypto people would take an Ethernet driver without having DaveM's Acked-by.
Andrew
David Miller
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
From: Andrew Lunn <[email protected]>
Date: Wed, 12 Sep 2018 01:30:15 +0200
Quoted 10 lines
Just as an FYI:
1) I don't think anybody in netdev has taken a serious look at the network code yet. There is little point until the controversial part of the code, Zinc, has been sorted out.
2) I personally would be surprised if DaveM took this code without having an Acked-by from the crypto subsystem people. In the same way, i doubt the crypto people would take an Ethernet driver without having DaveM's Acked-by.
Both of Andrew's statements are completely true.
I'm not looking at any of the networking bits until the crypto stuff is fully sorted and fully supported and Ack'd by crypto folks.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 4 lines · David Miller
Both of Andrew's statements are completely true.
I'm not looking at any of the networking bits until the crypto stuff is fully sorted and fully supported and Ack'd by crypto folks.
Seems reasonable to me.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to David MillerQuoted 15 lines · David Miller
From: Andrew Lunn <[email protected]>
Date: Wed, 12 Sep 2018 01:30:15 +0200Quoted 10 lines
Just as an FYI:
1) I don't think anybody in netdev has taken a serious look at the network code yet. There is little point until the controversial part of the code, Zinc, has been sorted out.
2) I personally would be surprised if DaveM took this code without having an Acked-by from the crypto subsystem people. In the same way, i doubt the crypto people would take an Ethernet driver without having DaveM's Acked-by.
Quoted 4 lines
Both of Andrew's statements are completely true.
I'm not looking at any of the networking bits until the crypto stuff is fully sorted and fully supported and Ack'd by crypto folks.
So, as a process question, whom exactly are we waiting for:
CRYPTO API
M: Herbert Xu <[email protected]> M: "David S. Miller" <[email protected]> L: [email protected]
Herbert hasn't replied to any of these submissions. You're the other maintainer :)
To the extent that you (DaveM) want my ack, here's what I think of the series so far:
The new APIs to the crypto primitives are good. For code that wants to do a specific known crypto operation, they are much, much more pleasant to use than the existing crypto API. The code cleanups in the big keys patch speak for themselves IMO. I have no problem with the addition of a brand-new API to the kernel, especially when it's a nice one like Zinc's, even if that API starts out with only a couple of users.
Zinc's arrangement of arch code is just fine. Sure, there are arguments that putting arch-specific code in arch/ is better, but this is mostly bikeshedding IMO.
There has been some discussion of the exact best way to handle simd_relax() and some other minor nitpicks of API details. This kind of stuff doesn't need to block the series -- it can always be reworked down the road if needed.
There are two things I don't like right now, though:
1. Zinc conflates the addition of a new API with the replacement of some algorithm implementations. This is problematic. Look at the recent benchmarks of ipsec before and after this series. Apparently big packets get faster and small packets get slower. It would be really nice to bisect the series to narrow down *where* the regression came from, but, as currently structured, you can't.
The right way to do this is to rearrange the series. First, the new Zinc APIs should be added, and they should be backed with the *existing* crypto code. (If the code needs to be moved or copied to a new location, so be it. The patch will be messy because somehow the Zinc API is going to have to dispatch to the arch-specific code, and the way that the crypto API handles it is not exactly friendly to this type of use. So be it.) Then another patch should switch the crypto API to use the Zinc interface. That patch, *by itself*, can be benchmarked. If it causes a regression for small ipsec packets, then it can be tracked down relatively easily. Once this is all done, the actual crypto implementation can be changed, and that changed can be reviewed on its own merits.
As a simplistic example, I wrote this code a while back:
and its two parents. This series added a more Zinc-like API to SHA256. And it did it without replacing the SHA256 implementation. Doing this for Zinc would be a bit more complication, since the arch code would need to be invoked too, but it should be doable.
FWIW, Wireguard should not actually depend on the replacement of the crypto implementation.
2. The new Zinc crypto implementations look like they're brand new. I realize that they have some history, some of them are derived from OpenSSL, etc, but none of this is really apparent in the patches themselves. It would be great if the kernel could literally share the same code as something like OpenSSL, since OpenSSL gets much more attention than the kernel's crypto. Failing that, it would be nice if the patches made it more clear how the code differs from its origin. At the very least, though, if the replacement of the crypto code were, as above, a patch that just replaced the crypto code, it would be much easier to review and benchmark intelligently.
--Andy
David Miller
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
From: Andy Lutomirski <[email protected]>
Date: Sun, 16 Sep 2018 21:09:11 -0700
Quoted 7 lines
CRYPTO API
M: Herbert Xu <[email protected]> M: "David S. Miller" <[email protected]> L: [email protected]Herbert hasn't replied to any of these submissions. You're the other maintainer :)
Herbert is the primary crypto maintainer, I haven't done a serious review of crypto code in ages.
So yes, Herbert review is what is important here.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 11 lines · David Miller
From: Andy Lutomirski <[email protected]>
Date: Sun, 16 Sep 2018 21:09:11 -0700Quoted 5 lines
CRYPTO API
M: Herbert Xu <[email protected]> M: "David S. Miller" <[email protected]> L: [email protected]
Quoted 7 lines
Quoted 2 lines
Herbert hasn't replied to any of these submissions. You're the other maintainer :)
Herbert is the primary crypto maintainer, I haven't done a serious review of crypto code in ages.
So yes, Herbert review is what is important here.
Would you accept Ard’s (and/or Eric Biggers’, perhaps, as an alternative)? Or, if you really want Herbert’s review, can you ask him to review it? (Hi Herbert!)
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 1 line · Andy Lutomirski
Would you accept Ard’s (and/or Eric Biggers’, perhaps, as an alternative)? Or, if you really want Herbert’s review, can you ask him to review it? (Hi Herbert!)
Preferably Eric's.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiHey Andy,
Thanks a lot for your feedback.
Quoted 7 lines · Andy Lutomirski
1. Zinc conflates the addition of a new API with the replacement of some algorithm implementations. This is problematic. Look at the recent benchmarks of ipsec before and after this series. Apparently big packets get faster and small packets get slower. It would be really nice to bisect the series to narrow down *where* the regression came from, but, as currently structured, you can't.
Quoted 12 lines
The right way to do this is to rearrange the series. First, the new Zinc APIs should be added, and they should be backed with the *existing* crypto code. (If the code needs to be moved or copied to a new location, so be it. The patch will be messy because somehow the Zinc API is going to have to dispatch to the arch-specific code, and the way that the crypto API handles it is not exactly friendly to this type of use. So be it.) Then another patch should switch the crypto API to use the Zinc interface. That patch, *by itself*, can be benchmarked. If it causes a regression for small ipsec packets, then it can be tracked down relatively easily. Once this is all done, the actual crypto implementation can be changed, and that changed can be reviewed on its own merits.
That ipsec regression was less related to the implementation and more related to calling kernel_fpu_begin() unnecessarily, something I've now fixed. So I'm not sure that's such a good example. However, I can try to implement Zinc over the existing assembly (Martin's and Ard's), first, as you've described. This will be a pretty large amount of work, but if you think it's worth it for the commit history, then I'll do it.
Quoted 4 lines
2. The new Zinc crypto implementations look like they're brand new. I realize that they have some history, some of them are derived from OpenSSL, etc, but none of this is really apparent in the patches themselves.
The whole point of going with these is that they _aren't_ brand new, yet they are very fast. Eyeballs and fuzzer hours are important, and AndyP's seems to get the most eyeballs and fuzzer hours, generally.
Quoted 5 lines
it would be nice if
the patches made it more clear how the code differs from its origin. At the very least, though, if the replacement of the crypto code were, as above, a patch that just replaced the crypto code, it would be much easier to review and benchmark intelligently.
You seem to have replied to the v3 thread, not the v4 thread. I've already started to include lots of detail about the origins of the code and [any] important differences in v4, and I'll continue to add more detail for v5.
On <https://git.zx2c4.com/linux-dev/log/>, have a look at AndyP's x86_64 ones:
- zinc: ChaCha20 x86_64 implementation
- zinc: Poly1305 x86_64 implementation
For the arm/arm64 ones, the changes were even more trivial, so much so that at Ard's urging, I included a cleaned-up diff inside the commit message:
- zinc: ChaCha20 ARM and ARM64 implementations
- zinc: Poly1305 ARM and ARM64 implementations
How's that level of detail looking to you?
Thanks again for the review.
Regards,
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 30 lines · Jason A. Donenfeld
Hey Andy,
Thanks a lot for your feedback.
Quoted 8 lines · Andy Lutomirski
1. Zinc conflates the addition of a new API with the replacement of some algorithm implementations. This is problematic. Look at the recent benchmarks of ipsec before and after this series. Apparently big packets get faster and small packets get slower. It would be really nice to bisect the series to narrow down *where* the regression came from, but, as currently structured, you can't.
Quoted 12 lines
The right way to do this is to rearrange the series. First, the new Zinc APIs should be added, and they should be backed with the *existing* crypto code. (If the code needs to be moved or copied to a new location, so be it. The patch will be messy because somehow the Zinc API is going to have to dispatch to the arch-specific code, and the way that the crypto API handles it is not exactly friendly to this type of use. So be it.) Then another patch should switch the crypto API to use the Zinc interface. That patch, *by itself*, can be benchmarked. If it causes a regression for small ipsec packets, then it can be tracked down relatively easily. Once this is all done, the actual crypto implementation can be changed, and that changed can be reviewed on its own merits.
Quoted 7 lines
That ipsec regression was less related to the implementation and more related to calling
kernel_fpu_begin()unnecessarily, something I've now fixed. So I'm not sure that's such a good example. However, I can try to implement Zinc over the existing assembly (Martin's and Ard's), first, as you've described. This will be a pretty large amount of work, but if you think it's worth it for the commit history, then I'll do it.
Ard, what do you think? I think it would
be nice, but if the authors of that assembly are convinced it should be replaced, then this step is optional IMO.
Quoted 16 lines
Quoted 5 lines
2. The new Zinc crypto implementations look like they're brand new. I realize that they have some history, some of them are derived from OpenSSL, etc, but none of this is really apparent in the patches themselves.
The whole point of going with these is that they _aren't_ brand new, yet they are very fast. Eyeballs and fuzzer hours are important, and AndyP's seems to get the most eyeballs and fuzzer hours, generally.
Quoted 5 lines
it would be nice if
the patches made it more clear how the code differs from its origin. At the very least, though, if the replacement of the crypto code were, as above, a patch that just replaced the crypto code, it would be much easier to review and benchmark intelligently.
Quoted 4 lines
You seem to have replied to the v3 thread, not the v4 thread. I've already started to include lots of detail about the origins of the code and [any] important differences in v4, and I'll continue to add more detail for v5.
This is indeed better. Ard’s reply covers this better.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 2 lines · Andy Lutomirski
Ard, what do you think? I think it would
be nice, but if the authors of that assembly are convinced it should be replaced, then this step is optional IMO.
I just spent several hours reworking everything for ChaCha. That was the easy one. Poly1305 will be much harder. Work in progress, I guess, but erf it's rough.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiQuoted 1 line · Andy Lutomirski
be nice, but if the authors of that assembly are convinced it should be replaced, then this step is optional IMO.
I think this actually makes the patchset and maintenance of it a lot more confusing, so I'm going to abort doing this. I'd rather make the convincing argument for the assembly anyway.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiQuoted 38 lines · Andy Lutomirski
Quoted 30 lines · Jason A. Donenfeld
Hey Andy,
Thanks a lot for your feedback.
Quoted 8 lines · Andy Lutomirski
1. Zinc conflates the addition of a new API with the replacement of some algorithm implementations. This is problematic. Look at the recent benchmarks of ipsec before and after this series. Apparently big packets get faster and small packets get slower. It would be really nice to bisect the series to narrow down *where* the regression came from, but, as currently structured, you can't.
Quoted 12 lines
The right way to do this is to rearrange the series. First, the new Zinc APIs should be added, and they should be backed with the *existing* crypto code. (If the code needs to be moved or copied to a new location, so be it. The patch will be messy because somehow the Zinc API is going to have to dispatch to the arch-specific code, and the way that the crypto API handles it is not exactly friendly to this type of use. So be it.) Then another patch should switch the crypto API to use the Zinc interface. That patch, *by itself*, can be benchmarked. If it causes a regression for small ipsec packets, then it can be tracked down relatively easily. Once this is all done, the actual crypto implementation can be changed, and that changed can be reviewed on its own merits.
Quoted 7 lines
That ipsec regression was less related to the implementation and more related to calling
kernel_fpu_begin()unnecessarily, something I've now fixed. So I'm not sure that's such a good example. However, I can try to implement Zinc over the existing assembly (Martin's and Ard's), first, as you've described. This will be a pretty large amount of work, but if you think it's worth it for the commit history, then I'll do it.
Quoted 3 lines
Ard, what do you think? I think it would
be nice, but if the authors of that assembly are convinced it should be replaced, then this step is optional IMO.
I don't think there is any problem with switching to faster code immediately, as long as we have data that supports the claim that it is actually faster on hardware people care about. The arm64 ChaCha20 code in the kernel is slower than the OpenSSL code as far as I know, so I have no problems whatsoever with dropping it. The ARM version, however, is slower on Cortex-A7 (according to Eric's benchmarks), which is the only 32-bit ARM core anybody cares about these days.
Quoted 22 lines
Quoted 16 lines
Quoted 5 lines
2. The new Zinc crypto implementations look like they're brand new. I realize that they have some history, some of them are derived from OpenSSL, etc, but none of this is really apparent in the patches themselves.
The whole point of going with these is that they _aren't_ brand new, yet they are very fast. Eyeballs and fuzzer hours are important, and AndyP's seems to get the most eyeballs and fuzzer hours, generally.
Quoted 5 lines
it would be nice if
the patches made it more clear how the code differs from its origin. At the very least, though, if the replacement of the crypto code were, as above, a patch that just replaced the crypto code, it would be much easier to review and benchmark intelligently.Quoted 4 lines
You seem to have replied to the v3 thread, not the v4 thread. I've already started to include lots of detail about the origins of the code and [any] important differences in v4, and I'll continue to add more detail for v5.
This is indeed better. Ard’s reply covers this better.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Ard,
Quoted 2 lines · Ard Biesheuvel
as long as we have data that supports the claim that it is actually faster on hardware people care about.
Seems reasonable. I'll next be turning my attention back to ARM performance. I'll try to gather some numbers. Expect data at some point next week.
Regards,
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiQuoted 85 lines · Andy Lutomirski
Quoted 15 lines · David Miller
From: Andrew Lunn <[email protected]>
Date: Wed, 12 Sep 2018 01:30:15 +0200Quoted 10 lines
Just as an FYI:
1) I don't think anybody in netdev has taken a serious look at the network code yet. There is little point until the controversial part of the code, Zinc, has been sorted out.
2) I personally would be surprised if DaveM took this code without having an Acked-by from the crypto subsystem people. In the same way, i doubt the crypto people would take an Ethernet driver without having DaveM's Acked-by.
Quoted 4 lines
Both of Andrew's statements are completely true.
I'm not looking at any of the networking bits until the crypto stuff is fully sorted and fully supported and Ack'd by crypto folks.
So, as a process question, whom exactly are we waiting for:
CRYPTO API
M: Herbert Xu <[email protected]> M: "David S. Miller" <[email protected]> L: [email protected]Herbert hasn't replied to any of these submissions. You're the other maintainer :)
To the extent that you (DaveM) want my ack, here's what I think of the series so far:
The new APIs to the crypto primitives are good. For code that wants to do a specific known crypto operation, they are much, much more pleasant to use than the existing crypto API. The code cleanups in the big keys patch speak for themselves IMO. I have no problem with the addition of a brand-new API to the kernel, especially when it's a nice one like Zinc's, even if that API starts out with only a couple of users.
Zinc's arrangement of arch code is just fine. Sure, there are arguments that putting arch-specific code in
arch/is better, but this is mostly bikeshedding IMO.There has been some discussion of the exact best way to handle
simd_relax()and some other minor nitpicks of API details. This kind of stuff doesn't need to block the series -- it can always be reworked down the road if needed.There are two things I don't like right now, though:
1. Zinc conflates the addition of a new API with the replacement of some algorithm implementations. This is problematic. Look at the recent benchmarks of ipsec before and after this series. Apparently big packets get faster and small packets get slower. It would be really nice to bisect the series to narrow down *where* the regression came from, but, as currently structured, you can't.
The right way to do this is to rearrange the series. First, the new Zinc APIs should be added, and they should be backed with the *existing* crypto code. (If the code needs to be moved or copied to a new location, so be it. The patch will be messy because somehow the Zinc API is going to have to dispatch to the arch-specific code, and the way that the crypto API handles it is not exactly friendly to this type of use. So be it.) Then another patch should switch the crypto API to use the Zinc interface. That patch, *by itself*, can be benchmarked. If it causes a regression for small ipsec packets, then it can be tracked down relatively easily. Once this is all done, the actual crypto implementation can be changed, and that changed can be reviewed on its own merits.
As a simplistic example, I wrote this code a while back:
and its two parents. This series added a more Zinc-like API to SHA256. And it did it without replacing the SHA256 implementation. Doing this for Zinc would be a bit more complication, since the arch code would need to be invoked too, but it should be doable.
FWIW, Wireguard should not actually depend on the replacement of the crypto implementation.
Quoted 11 lines
2. The new Zinc crypto implementations look like they're brand new. I realize that they have some history, some of them are derived from OpenSSL, etc, but none of this is really apparent in the patches themselves. It would be great if the kernel could literally share the same code as something like OpenSSL, since OpenSSL gets much more attention than the kernel's crypto. Failing that, it would be nice if the patches made it more clear how the code differs from its origin. At the very least, though, if the replacement of the crypto code were, as above, a patch that just replaced the crypto code, it would be much easier to review and benchmark intelligently.
OK, so let me summarize my remaining concerns as well. I may be a bit more finicky than Andy, though.
First of all, the rate at which new revisions of this series are appearing increases the review effort unnecessarily, especially given that the latest version seemed to have some issues that would have been spotted by a simple build test. I would like to urge Jason to bear with us and bring this discussion to a close before resubmitting.
As far as I can tell (i.e., as a user not a network dev), WireGuard is an excellent piece of code, and I would like to see it merged. I also think there is little disagreement about the quality of the proposed algorithm implementations and the usefulness of having a set of easy to use solid crypto primitives in addition to or complementing the current crypto API.
I do have some concerns over how the code is organized though:
* simd_relax() is currently not called by the crypto routines themselves. This means that the worst case scheduling latency is unbounded, which is unacceptable for the -rt kernel. The worst case scheduling latency should never be proportional to the input size. (Apologies for not spotting that earlier)
* Using a cute name for the crypto library [that will end up being the preferred choice for casual use only] may confuse people, given that we have lots of code in crypto/ already. I'd much prefer using, e.g., crypto/lib and crypto/api (regardless of where the arch specific pieces live)
* I'd prefer the arch specific pieces to live under arch, but I can live with keeping them in a single place, as long as the arch maintainers have some kind of jurisdiction over them. I also think there should be some overlap between the maintainership responsibilities of the two generic pieces (api and lib).
* (Nit) The GCC command line -include'd .h files contain variable and function definitions so they are actually .c files.
* (Nit) Referencing CONFIG_xxx macros from -include'd files adds the implicit assumption that the -include appears after the -include of kconfig.h.
* Adding /conditional/ -include's (or #include's) increases the size of the validation space, which is why we generally prefer unconditional includes (and static inline stubs), and 'if (IS_ENABLED(CONFIG_xxx))' over #ifdef CONFIG_xxx
* The current organization of the code puts all available (for the arch) versions of all routines into a single module, which can only be built in once we update random.c to use Zinc's chacha20 routines. This bloats the core kernel (which is a huge deal for embedded systems that have very strict boot requirements). It also makes it impossible to simply blacklist a module if you, for instance, prefer to use the [potentially more power efficient] scalar code over the SIMD code when using a distro kernel.
[To summarize the 4 points above, I'd much rather see a more conventional organization where different parts are provided by different modules. I don't think the argument that inlining is needed for performance is actually valid, given that we have branch predictors and static keys, and the arch SIMD code is built as separate object files anyway]
* If we reuse source files from OpenSSL, we should use that actual source which is the perlasm not the emitted assembler. Also, we should work with Andy Polyakov (as I have done several times over the past 5+ years) to upstream the changes we apply to the kernel version of the code. The same applies to code from other sources, btw, but I am not personally familiar with them.
* If upstreaming the changes is not an option, they should be applied as a separate patch and not hidden in a 5000 line patch without any justification or documentation (but Jason is already working on that)
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 26 lines · Ard Biesheuvel
As far as I can tell (i.e., as a user not a network dev), WireGuard is an excellent piece of code, and I would like to see it merged. I also think there is little disagreement about the quality of the proposed algorithm implementations and the usefulness of having a set of easy to use solid crypto primitives in addition to or complementing the current crypto API.
I do have some concerns over how the code is organized though:
*
simd_relax()is currently not called by the crypto routines themselves. This means that the worst case scheduling latency is unbounded, which is unacceptable for the -rt kernel. The worst case scheduling latency should never be proportional to the input size. (Apologies for not spotting that earlier)* Using a cute name for the crypto library [that will end up being the preferred choice for casual use only] may confuse people, given that we have lots of code in
crypto/already. I'd much prefer using, e.g.,crypto/libandcrypto/api(regardless of where the arch specific pieces live)
Quoted 8 lines
* I'd prefer the arch specific pieces to live under arch, but I can live with keeping them in a single place, as long as the arch maintainers have some kind of jurisdiction over them. I also think there should be some overlap between the maintainership responsibilities of the two generic pieces (api and lib).
* (Nit) The GCC command line -include'd .h files contain variable and function definitions so they are actually .c files.
Hmm. I would suggest just getting rid of the -include magic entirely. The resulting ifdef will be more comprehensible.
Quoted 8 lines
* The current organization of the code puts all available (for the arch) versions of all routines into a single module, which can only be built in once we update
random.cto use Zinc's chacha20 routines. This bloats the core kernel (which is a huge deal for embedded systems that have very strict boot requirements). It also makes it impossible to simply blacklist a module if you, for instance, prefer to use the [potentially more power efficient] scalar code over the SIMD code when using a distro kernel.
I think the module organization needs to change. It needs to be possible to have chacha20 built in but AES or whatever as a module.
Quoted 7 lines
[To summarize the 4 points above, I'd much rather see a more conventional organization where different parts are provided by different modules. I don't think the argument that inlining is needed for performance is actually valid, given that we have branch predictors and static keys, and the arch SIMD code is built as separate object files anyway]
I might have agreed before Spectre :(. Unfortunately, unless we do some magic, I think the code would look something like:
if (static_branch_likely(have_simd)) arch_chacha20();
...where arch_chacha20 is a *pointer*. And that will generate a retpoline and run very, very slowly. (I just rewrote some of the x86 entry code to eliminate one retpoline. I got a 5% speedup on some tests according to the kbuild bot.)
So, if we really wanted modules, we’d need a new dynamic patching mechanism.
I would suggest instead adding two boot (or debugfs) options:
simd=off: disables simd_get using a static branch.
crypto_chacha20_nosimd: Does what it sounds like.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 4 lines · Andy Lutomirski
Quoted 2 lines
* (Nit) The GCC command line -include'd .h files contain variable and function definitions so they are actually .c files.
Hmm. I would suggest just getting rid of the -include magic entirely. The resulting ifdef will be more comprehensible.
I really don't think so, actually. The way the -include stuff works now is that the glue code is inlined in the same place that the assembly object file is added to the build object list, so it gels together cleanly, as the thing is defined and set in one single place. I could go back to the ifdefs - and even make them as clean as possible - but I think that puts more things in more places and is therefore more confusing. The -include system now works extremely well.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 8 lines · Jason A. Donenfeld
Quoted 4 lines · Andy Lutomirski
Quoted 2 lines
* (Nit) The GCC command line -include'd .h files contain variable and function definitions so they are actually .c files.
Hmm. I would suggest just getting rid of the -include magic entirely. The resulting ifdef will be more comprehensible.
Quoted 8 lines
I really don't think so, actually. The way the -include stuff works now is that the glue code is inlined in the same place that the assembly object file is added to the build object list, so it gels together cleanly, as the thing is defined and set in one single place. I could go back to the ifdefs - and even make them as clean as possible - but I think that puts more things in more places and is therefore more confusing. The -include system now works extremely well.
Is it really better than:
#ifdef CONFIG_X86_64
#include "whatever"
#endif
It seems a more obfuscated than needed to put the equivalent of that into the Makefile, and I don't think people really like searching through the Makefile to figure out why the code does what it does.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 7 lines · Andy Lutomirski
#ifdef
CONFIG_X86_64
#include "whatever"
#endifIt seems a more obfuscated than needed to put the equivalent of that into the
Makefile, and I don't think people really like searching through theMakefileto figure out why the code does what it does.
Okay, I'll change it back to ifdefs for v5.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiQuoted 1 line · Andy Lutomirski
I think the module organization needs to change. It needs to be possible to have chacha20 built in but AES or whatever as a module.
Okay, I'll do that for v5.
Quoted 5 lines
I might have agreed before Spectre :(. Unfortunately, unless we do some magic, I think the code would look something like:
if (
static_branch_likely(have_simd))arch_chacha20();...where
arch_chacha20is a *pointer*. And that will generate a retpoline and run very, very slowly. (I just rewrote some of the x86 entry code to eliminate one retpoline. I got a 5% speedup on some tests according to the kbuild bot.)
Actually, the way it works now benefits from the compilers inliner and the branch predictor. I benchmarked this without any retpoline slowdowns, and the branch predictor becomes correct pretty much all the time. We can tinker with this after the initial merge, if you really want, but avoiding function pointers and instead using ordinary branches really winds up being quite fast.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 10 lines · Jason A. Donenfeld
Quoted 1 line · Andy Lutomirski
I think the module organization needs to change. It needs to be possible to have chacha20 built in but AES or whatever as a module.
Okay, I'll do that for v5.
Quoted 4 lines
I might have agreed before Spectre :(. Unfortunately, unless we do some magic, I think the code would look something like:
if (
static_branch_likely(have_simd))arch_chacha20();
Quoted 8 lines
Quoted 1 line
...where
arch_chacha20is a *pointer*. And that will generate a retpoline and run very, very slowly. (I just rewrote some of the x86 entry code to eliminate one retpoline. I got a 5% speedup on some tests according to the kbuild bot.)Actually, the way it works now benefits from the compilers inliner and the branch predictor. I benchmarked this without any retpoline slowdowns, and the branch predictor becomes correct pretty much all the time. We can tinker with this after the initial merge, if you really want, but avoiding function pointers and instead using ordinary branches really winds up being quite fast.
Indeed. What I'm saying is that you shouldn't refactor it this way because it will be slow. I agree it would be conceptually nice to be able to blacklist a chacha20_x86_64 module to disable the asm, but I think it would be very hard to get good performance.
--Andy
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 4 lines · Andy Lutomirski
Indeed. What I'm saying is that you shouldn't refactor it this way because it will be slow. I agree it would be conceptually nice to be able to blacklist a
chacha20_x86_64module to disable the asm, but I think it would be very hard to get good performance.
I hadn't understood your nosimd=1 command line suggestion the first time through, but now I see what you were after. This would be really easy to add. And I can do it for v5 if you want. But I'm kind of loath to add too much stuff to the initial patchset. Do you think this is an important feature to have for it? Or should I leave it for later?
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 10 lines · Jason A. Donenfeld
Quoted 6 lines · Andy Lutomirski
Indeed. What I'm saying is that you shouldn't refactor it this way because it will be slow. I agree it would be conceptually nice to be able to blacklist a
chacha20_x86_64module to disable the asm, but I think it would be very hard to get good performance.
Quoted 5 lines
I hadn't understood your nosimd=1 command line suggestion the first time through, but now I see what you were after. This would be really easy to add. And I can do it for v5 if you want. But I'm kind of loath to add too much stuff to the initial patchset. Do you think this is an important feature to have for it? Or should I leave it for later?
I think it’s fine for later. It’s potentially useful for benchmarking and debugging.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hey Andy,
Quoted 1 line · Andy Lutomirski
I think it’s fine for later. It’s potentially useful for benchmarking and debugging.
I went ahead and added it anyway in the end. It was really quite easy to do, and it sets a good template for future primitives that are added to Zinc.
Meanwhile, I've fully triaged the regression Martin found, and in the same test he performed, the Zinc code now runs faster than the old code (which should be no surprise).
I've also finished getting rid of -include, per your suggestion, and modularizing each algorithm to be loadable independently, per your suggestion.
All and all, v5 is turning out really well, and I'll probably submit it sometime soon. My tree was just added to the kbuild test bot, so I'll hopefully get an email about any breakage *before* I submit this time.
Regards,
Jason
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Ard BiesheuvelHi Ard,
Quoted 2 lines · Ard Biesheuvel
OK, so let me summarize my remaining concerns as well. I may be a bit more finicky than Andy, though.
Yes, and generally hostile to this whole initiative since the beginning. But I am very grateful for your reviews nonetheless, and I'll do my best to incorporate as much as is reasonable.
Quoted 2 lines
I would like to urge Jason to
bear with us and bring this discussion to a close before resubmitting.
What I fear is that either:
- You don't like the Zinc initiative in one way or another, and the desire to "keep discussing" and adding more things is less out of their necessity and more out of a desire to stall it indefinitely.
- You're going to bikeshed and bikeshed and waste tons of time until Zinc copies lots of the same design decisions from the present crypto API.
I do sincerely hope these are only fears and not what actually is going on. I'll do my best to take into serious consideration what you say -- many are indeed extremely helpful -- but I certainly won't be wholesale accepting all the things you've mentioned.
Nevertheless, I'll make sure v5 has a pretty healthy quantity of improvements in it before resubmitting.
Quoted 5 lines
*
simd_relax()is currently not called by the crypto routines themselves. This means that the worst case scheduling latency is unbounded, which is unacceptable for the -rt kernel. The worst case scheduling latency should never be proportional to the input size. (Apologies for not spotting that earlier)
Good catch. I actually did this correct when porting the crypto API to use Zinc (in those later top commits in v4), but I hadn't in the Zinc code itself. I'll address this for v5.
Quoted 2 lines
maintainership
responsibilities
Samuel and I intend to maintain Zinc in lib/zinc/ and send future updates to it through Greg's tree, as mentioned in the 00/ cover letter. The maintainership of the existing crypto API won't change.
Quoted 5 lines
* The current organization of the code puts all available (for the arch) versions of all routines into a single module, which can only be built in once we update
random.cto use Zinc's chacha20 routines. This bloats the core kernel (which is a huge deal for embedded systems that have very strict boot requirements).
I'll split each Zinc primitive into a separate module for v5, per your and Andy's desire. And the SIMD code is already toggle-able via a Kconfig menu option.
Quoted 4 lines
we should
work with Andy Polyakov (as I have done several times over the past 5+ years) to upstream the changes we apply to the kernel version of the code.
Indeed this is the intent.
Quoted 2 lines
The same applies to code from other sources, btw, but I am not personally familiar with them.
Good news on this front:
- Rene wrote the MIPS code specifically for WireGuard, so that _is_ upstream.
- Samuel wrote the BLAKE2 assembly, and he's the co-maintainer of Zinc with me.
- I talk to Dan and Peter a decent amount about qhasm.
- I'm in very close contact with the team behind HACL*, and they're treating Zinc as a target -- stylistically and with regards to kernel requirements -- which means they're looking at what's happening in this patchset and adjusting accordingly.
Quoted 3 lines
* If upstreaming the changes is not an option, they should be applied as a separate patch and not hidden in a 5000 line patch without any justification or documentation (but Jason is already working on that)
Indeed this is already underway.
Thanks again for your review.
Jason
Herbert Xu
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Jason:
Quoted 13 lines · Jason A. Donenfeld
Quoted 2 lines · Ard Biesheuvel
OK, so let me summarize my remaining concerns as well. I may be a bit more finicky than Andy, though.
Yes, and generally hostile to this whole initiative since the beginning. But I am very grateful for your reviews nonetheless, and I'll do my best to incorporate as much as is reasonable.
Quoted 2 lines
I would like to urge Jason to
bear with us and bring this discussion to a close before resubmitting.
Quoted 7 lines
What I fear is that either:
- You don't like the Zinc initiative in one way or another, and the desire to "keep discussing" and adding more things is less out of their necessity and more out of a desire to stall it indefinitely.
- You're going to bikeshed and bikeshed and waste tons of time until Zinc copies lots of the same design decisions from the present crypto API.
That may be your view but from what I've read Ard has been very constructive in pointing out issues in your submission. If your response to criticism is to dismiss them as hostile then I'm afraid that we will not be able to progress on this patch series.
Please keep in mind that this is a large project that has to support multiple users on one hand (not just WireGuard) and complex hardware acceleration drivers on the other. Ard has been one of the most prolific contributors to the crypto code and his review should be taken seriously.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Herbert,
Quoted 7 lines · Herbert Xu
That may be your view but from what I've read Ard has been very constructive in pointing out issues in your submission. Please keep in mind that this is a large project that has to support multiple users on one hand (not just WireGuard) and complex hardware acceleration drivers on the other. Ard has been one of the most prolific contributors to the crypto code and his review should be taken seriously.
I'm well aware, which is why I also wrote:
"I do sincerely hope these are only fears and not what actually is going on. I'll do my best to take into serious consideration what you say -- many are indeed extremely helpful"
Worry not, I've been working around the clock to implement suggestions from Ard and from others.
I'll be submitting v5 fairly soon, which will probably be a good spot for you to review as well, if you're interested. I'm just going to give kbuild testbot a few more hours on it first.
Regards,
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Jason A. DonenfeldQuoted 14 lines · Jason A. Donenfeld
Hi Ard,
Quoted 2 lines · Ard Biesheuvel
OK, so let me summarize my remaining concerns as well. I may be a bit more finicky than Andy, though.
Yes, and generally hostile to this whole initiative since the beginning. But I am very grateful for your reviews nonetheless, and I'll do my best to incorporate as much as is reasonable.
Quoted 2 lines
I would like to urge Jason to
bear with us and bring this discussion to a close before resubmitting.
Quoted 8 lines
What I fear is that either:
- You don't like the Zinc initiative in one way or another, and the desire to "keep discussing" and adding more things is less out of their necessity and more out of a desire to stall it indefinitely.
- You're going to bikeshed and bikeshed and waste tons of time until Zinc copies lots of the same design decisions from the present crypto API.
Given that you show no interest whatsoever in gaining an understanding of the underlying requirements that we have to deal with in the crypto API, the only way to get my point across is by repeatedly stating it in response to your patches. Also, sending out a new series each time with only half of the review comments addressed doesn't make me a bikeshedder.
Quoted 5 lines
I do sincerely hope these are only fears and not what actually is going on. I'll do my best to take into serious consideration what you say -- many are indeed extremely helpful -- but I certainly won't be wholesale accepting all the things you've mentioned.
I have pointed out to you numerous times (as has Eric) that the ChaCha20 ARM code you are importing from the OpenSSL project has been found to be slower on Cortex-A7, which represents the vast majority of devices expected to be in the field in 1~2 years. Yet, we are at the fifth revision now where you are replacing the existing code. Also, I have asked you more than once to split out your changes to the upstream OpenSSL code into separate patches so we can more easily track them, but v5 now puts them in the commit log (again) [but in a corrupted way - the preprocessor directives are filtered out by git-commit], which means we cannot use git diff/blame etc to look at them.
Upstreaming code is about taking an interest in other people's use cases, and about choosing your battles. It is unfortunate that we have spent all this time talking about a couple of crypto routines, while the actual meat of your submission is in WireGuard itself, which I'm sure you much rather talk about.
Quoted 56 lines
Quoted 5 lines
*
simd_relax()is currently not called by the crypto routines themselves. This means that the worst case scheduling latency is unbounded, which is unacceptable for the -rt kernel. The worst case scheduling latency should never be proportional to the input size. (Apologies for not spotting that earlier)Good catch. I actually did this correct when porting the crypto API to use Zinc (in those later top commits in v4), but I hadn't in the Zinc code itself. I'll address this for v5.
Quoted 2 lines
maintainership
responsibilitiesSamuel and I intend to maintain Zinc in
lib/zinc/and send future updates to it through Greg's tree, as mentioned in the 00/ cover letter. The maintainership of the existing crypto API won't change.Quoted 5 lines
* The current organization of the code puts all available (for the arch) versions of all routines into a single module, which can only be built in once we update
random.cto use Zinc's chacha20 routines. This bloats the core kernel (which is a huge deal for embedded systems that have very strict boot requirements).I'll split each Zinc primitive into a separate module for v5, per your and Andy's desire. And the SIMD code is already toggle-able via a
Kconfigmenu option.Quoted 4 lines
we should
work with Andy Polyakov (as I have done several times over the past 5+ years) to upstream the changes we apply to the kernel version of the code.Indeed this is the intent.
Quoted 2 lines
The same applies to code from other sources, btw, but I am not personally familiar with them.
Good news on this front:
- Rene wrote the MIPS code specifically for WireGuard, so that _is_ upstream.
- Samuel wrote the BLAKE2 assembly, and he's the co-maintainer of Zinc with me.
- I talk to Dan and Peter a decent amount about qhasm.
- I'm in very close contact with the team behind HACL*, and they're treating Zinc as a target -- stylistically and with regards to kernel requirements -- which means they're looking at what's happening in this patchset and adjusting accordingly.Quoted 3 lines
* If upstreaming the changes is not an option, they should be applied as a separate patch and not hidden in a 5000 line patch without any justification or documentation (but Jason is already working on that)
Indeed this is already underway.
Thanks again for your review.
Jason
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Ard,
Quoted 7 lines · Ard Biesheuvel
Quoted 2 lines · Jason A. Donenfeld
Hi Ard,
Given that you show no interest whatsoever in gaining an understanding of the underlying requirements that we have to deal with in the crypto API, the only way to get my point across is by repeatedly stating it
Sorry if I've come across that way, but I am certainly interested in gaining such an understanding of said requirements.
Quoted 4 lines
I have pointed out to you numerous times (as has Eric) that the ChaCha20 ARM code you are importing from the OpenSSL project has been found to be slower on Cortex-A7, which represents the vast majority of devices expected to be in the field in 1~2 years.
I mentioned in the other thread that I intend immanently to begin benching on a variety of ARM boards, and I should have numbers and results and conclusions somewhat soon for the list.
My initial notion here was that it'd be better to go with AndyP's code no matter what, and then later work with him on contributing said improvements, and then port these back to the kernel. However, you and Andy made a compelling point about code replacement -- that it's okay to replace all in one go only if there are positive benchmark results. So I think what I'll do to appease this is -- if the benchmarks are indeed how Eric suggested -- stick with your faster code, and then follow up with replacement plans after the merge. (I feel a bit more comfortable with varying ChaCha code, because implementations tend to be pretty straight forward and harder to screw up in subtle ways than, say, poly1305 or curve25519.)
Quoted 6 lines
have asked you more than once to split out your changes to the upstream OpenSSL code into separate patches so we can more easily track them, but v5 now puts them in the commit log (again) [but in a corrupted way - the preprocessor directives are filtered out by git-commit], which means we cannot use git diff/blame etc to look at them.
Didnt't realize this was so important to you. It's trivial to do, so I'll do that for AndyP's implementations for the next revision.
Quoted 5 lines
Upstreaming code is about taking an interest in other people's use cases, and about choosing your battles. It is unfortunate that we have spent all this time talking about a couple of crypto routines, while the actual meat of your submission is in WireGuard itself, which I'm sure you much rather talk about.
I don't find it unfortunate; getting the crypto right is of the utmost importance.
Regards,
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 7 lines · Jason A. Donenfeld
Hi Ard,
Quoted 4 lines · Ard Biesheuvel
Quoted 2 lines · Jason A. Donenfeld
Hi Ard,
Quoted 7 lines
Quoted 3 lines
Given that you show no interest whatsoever in gaining an understanding of the underlying requirements that we have to deal with in the crypto API, the only way to get my point across is by repeatedly stating it
Sorry if I've come across that way, but I am certainly interested in gaining such an understanding of said requirements.
Excellent.
So you are probably aware that there is a big push in the industry these days towards high-performance accelerators on a coherent fabric, potentially with device side caches, and this is the main reason that the crypto API abstractions are the way they are today.
So while standardizing on Chacha20Poly1305 in WireGuard [while still a policy decision in my view] seems reasonable to me, the decision to limit WireGuard to synchronous software implementations seems to me like something we may want to revisit in the future. What is your view on that? And is the ChaCha20/Poly1305 AEAD construction in WireGuard identical to the one in RFC 7539, i.e., could an accelerator built for the IPsec flavor of ChaCha20Poly1305 potentially be reused for WireGuard?
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Eric BiggersQuoted 51 lines · Eric Biggers
Quoted 32 lines · Greg Kroah-Hartman
Quoted 11 lines · Ard Biesheuvel
Quoted 4 lines
As Zinc is simply library code, its config options are un-menued, with the exception of
CONFIG_ZINC_DEBUG, which enables various selftests andBUG_ONs.In spite of the wall of text, you fail to point out exactly why the existing AEAD API in unsuitable, and why fixing it is not an option.
As I pointed out in a previous version, I don't think we need a separate crypto API/library in the kernel, and I don't think you have convinced anyone else yet either.
Um, then why do people keep sprinkling new
crypto/hashcode all around the kernel tree? It's because what we have as a crypto api is complex and is hard to use for many in-kernel users.Something like this new interface (zinc) is a much "saner" api for writing kernel code that has to interact with
crypto/hashprimitives.I see no reason why the existing crypto code can be redone to use the zinc crypto primitives over time, making there only be one main location for the crypto algorithms. But to do it the other way around is pretty much impossible given the complexities in the existing api that has been created over time.
Not to say that the existing api is not a viable one, but ugh, really? You have to admit it is a pain to try to use in any "normal" type of "here's a bytestream, go give me a hash" type of method, right?
Quoted 7 lines
Also there is the added benefit that the crypto primitives here have been audited by a number of people (so Jason stated), and they are written in a way that the crypto community can more easily interact and contribute to. Which is _way_ better than what we have today.
So this gets my "stamp of approval" for whatever it is worth :)
I think you mean you see no reason why it *cannot* be converted? The conversions definitely *should* be done, just like how some of the existing crypto API algorithms like SHA-256 already wrap implementations in
lib/. In my view,lib/zinc/isn't fundamentally different from what we already have for some algorithms. So it's misguided to design/present it as some novel thing, which unfortunately this patchset still does to a large extent. (The actual new thing is how architecture-specific implementations are handled.)
Quoted 5 lines
Of course, the real problem is that even after multiple revisions of this patchset, there's still no actual conversions of the existing crypto API algorithms over to use the new implementations. "Zinc" is still completely separate from the existing crypto API.
Jason, can you do one of these conversions as an example?
Quoted 18 lines
So, it's not yet clear that the conversions will actually work out without problems that would require changes in "Zinc". I don't think it makes sense to merge all this stuff without doing the conversions, or at the very least demonstrating how they will be done.
In particular, in its current form "Zinc" is useless for anyone that needs the existing crypto API. For example, for HPolyC,
(https://lkml.org/lkml/2018/8/6/857), I need to make improvements to ChaCha and Poly1305 in the existing crypto API, e.g. to add support for XChaCha and NEON-accelerated Poly1305. Having completely separate ChaCha and Poly1305 implementations in Zinc doesn't help at all. If anything, it makes things harder because people will have to review/maintain both sets of implementations; and when trying to make the improvements I need, I'll find myself in the middle of a holy war between two competing camps who each have their own opinion about The Right Way To Do Crypto, and their own crypto implementations and APIs in the kernel.- Eric
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 1 line · Andy Lutomirski
Jason, can you do one of these conversions as an example?
My preference is really to leave that to a different patch series. But if you think I *must*, then I shall.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 11 lines · Jason A. Donenfeld
Quoted 3 lines · Andy Lutomirski
Jason, can you do one of these conversions as an example?
My preference is really to leave that to a different patch series. But if you think I *must*, then I shall.
I think Ard’s point is valid: in the long run we don’t want two competing software implementations of each primitive. It clearly *should* be possible to make crypto API call into zinc for synchronous software operations, but a demonstration of how this actually works and that there isn’t some change to zinc to make it would well would be in order, I think.
IMO the right approach is do one conversion right away and save the rest for later.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Andy,
Quoted 3 lines · Andy Lutomirski
I think Ard’s point is valid: in the long run we don’t want two competing software implementations of each primitive. It clearly *should* be possible to make crypto API call into zinc for synchronous software operations, but a demonstration of how this actually works and that there isn’t some change to zinc to make it would well would be in order, I think.
IMO the right approach is do one conversion right away and save the rest for later.
Alright, I'll go ahead and do this for v4. Thanks for the guidance.
Jason
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Eric, Andy,
Quoted 4 lines · Andy Lutomirski
Quoted 3 lines
I think Ard’s point is valid: in the long run we don’t want two competing software implementations of each primitive. It clearly *should* be possible to make crypto API call into zinc for synchronous software operations, but a demonstration of how this actually works and that there isn’t some change to zinc to make it would well would be in order, I think.
IMO the right approach is do one conversion right away and save the rest for later.
It turned out to be fairly straight forward and quick to do. I'm on a
transatlantic plane so the connection is super spotty, but you can
check out the three commits added to:
<https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/log?h=jd/wireguard>
-- the two "crypto:" commits and the one "random:" commit.
Alternatively, you can look directly at
<https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/tree/crypto/poly1305_zinc.c?h=jd/wireguard>
and <https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/tree/crypto/chacha20_zinc.c?h=jd/wireguard>.
I'll be refining and checking these over the next week or so, but the
basics were super easy to do.
Jason
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Ard BiesheuvelHello Ard,
I realize you've put a lot of good and hard work into the existing crypto API, and that my writing in these commit messages might be a bit too bristly and dismissive of that hard work. So I think in a sense it's understandable that you've responded as such here. But hopefully I can address your concerns. One thing to keep in mind is that Zinc endeavors to provide the basis for simple and direct functions to software algorithms. This is fairly modest goal. Just some functions that do some stuff in software. Around these you'll still be able to have complicated and impressive dynamic dispatch and asynchronous mechanisms such as the present crypto API. Zinc is merely getting the software implementation side done in a very simple and direct way. So I don't think there's a good reason for so much antagonism, despite a perhaps overbearing tone of my commit messages. Rather, I expect that we'll wind up working together on this quite a bit down the line.
Quoted 2 lines
In spite of the wall of text, you fail to point out exactly why the existing AEAD API in unsuitable, and why fixing it is not an option.
I thought I had addressed this. Firstly, there's a need for more than just AEAD, but ignoring that, the AEAD API is a big full API that does lots of things, makes allocations, parses descriptors, and so forth. I'm sure this kind of highly-engineered approach will continue to improve over time in that highly engineered direction. Zinc is doing something a bit different: it's providing a series of simple functions for various cryptographic routines. This is a considerably different goal -- perhaps even a complementary one -- to the AEAD API.
Quoted 2 lines
I don't think you have
convinced anyone else yet either.
Please only speak for yourself and refrain from rhetoric like this, which is patently false.
Quoted 2 lines
Please refrain from sending a v4 with just a couple of more tweaks on top
Sorry, no, I'm not going to stop working hard on this because you're wary of a new approach. I will continue to improve the submission until it is mergable, and I do not intend to stop.
Anyway, it sounds like this whole thing may have ruffled your feathers a bit. Will you be at Linux Plumbers Conference in November? I'm planning on attending, and perhaps we could find some time there to sit down and talk one on one a bit.
Regards,
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 18 lines · Jason A. Donenfeld
Hello Ard,
I realize you've put a lot of good and hard work into the existing crypto API, and that my writing in these commit messages might be a bit too bristly and dismissive of that hard work. So I think in a sense it's understandable that you've responded as such here. But hopefully I can address your concerns. One thing to keep in mind is that Zinc endeavors to provide the basis for simple and direct functions to software algorithms. This is fairly modest goal. Just some functions that do some stuff in software. Around these you'll still be able to have complicated and impressive dynamic dispatch and asynchronous mechanisms such as the present crypto API. Zinc is merely getting the software implementation side done in a very simple and direct way. So I don't think there's a good reason for so much antagonism, despite a perhaps overbearing tone of my commit messages. Rather, I expect that we'll wind up working together on this quite a bit down the line.
No worries, it takes more than this to piss me off. I do take pride in my work, but I am perfectly aware that I am not a rare talent like Andy Polyakov, which is actually why I have worked extensively with him in the past to get kernel specific changes to the ARM/arm64 NEON code into upstream OpenSSL, so that we could use the upstream code unmodified and benefit from upstream review. [1] [2]
In this series, you are dumping a huge volume of unannotated, generated asm into the kernel which has been modified [by you] to [among other things?] adhere to the kernel API (without documenting what the changes are exactly). How does that live up to the promise of better, peer reviewed code?
Then there is the performance claim. We know for instance that the OpenSSL ARM NEON code for ChaCha20 is faster on cores that happen to possess a micro-architectural property that ALU instructions are essentially free when they are interleaved with SIMD instructions. But we also know that a) Cortex-A7, which is a relevant target, is not one of those cores, and b) that chip designers are not likely to optimize for that particular usage pattern so relying on it in generic code is unwise in general.
I am also concerned about your claim that all software algorithms will be moved into this crypto library. You are not specific about whose responsibility it will be that this is going to happen in a timely fashion. But more importantly, it is not clear at all how you expect this to work for, e.g., h/w instruction based SHAxxx or AES in various chaining modes, which should be used only on cores that implement those instructions (note that on arm64, we have optional instructions for AES, PMULL, SHA1, SHA256, SHA512, SHA3, SM3 and SM4). Are all those implementations (only few of which will be used on a certain core) going to be part of the monolithic library? What are the APIs going to look like for block ciphers, taking chaining modes into account?
I'm sure it is rather simple to port the crypto API implementation of ChaCha20 to use your library. I am more concerned about how your library is going to expand to cover all other software algorithms that we currently use in the kernel.
Quoted 12 lines
Quoted 2 lines
In spite of the wall of text, you fail to point out exactly why the existing AEAD API in unsuitable, and why fixing it is not an option.
I thought I had addressed this. Firstly, there's a need for more than just AEAD, but ignoring that, the AEAD API is a big full API that does lots of things, makes allocations, parses descriptors, and so forth. I'm sure this kind of highly-engineered approach will continue to improve over time in that highly engineered direction. Zinc is doing something a bit different: it's providing a series of simple functions for various cryptographic routines. This is a considerably different goal -- perhaps even a complementary one -- to the AEAD API.
I understand how your crypto library is different from the crypto API. But the question was why WireGuard cannot make use of the crypto APIs AEAD interface. And note that this is an honest question: I know that the crypto API is cumbersome to use in general, but it would be very helpful to understand where exactly the impedance mismatch is between what your code needs and what the crypto API provides.
Quoted 6 lines
Quoted 2 lines
I don't think you have
convinced anyone else yet either.Please only speak for yourself and refrain from rhetoric like this, which is patently false.
Fair enough. You have clearly convinced Greg :-)
Quoted 7 lines
Quoted 2 lines
Please refrain from sending a v4 with just a couple of more tweaks on top
Sorry, no, I'm not going to stop working hard on this because you're wary of a new approach. I will continue to improve the submission until it is mergable, and I do not intend to stop.
Of course. But please respond to all the concerns, not just the low hanging fruit. I have already mentioned a couple of times that I object to dumping large volumes of generated assembly into the kernel tree without any annotation whatsoever, or any documentation about how the generated code was hand tweaked before submission. You have not responded to that concern yet.
Quoted 5 lines
Anyway, it sounds like this whole thing may have ruffled your feathers a bit. Will you be at Linux Plumbers Conference in November? I'm planning on attending, and perhaps we could find some time there to sit down and talk one on one a bit.
That would be good, yes. I will be there.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e4e7f10bfc4069925e99cc4b428c3434e30b6c3f
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7918ecef073fe80eeb399a37d8d48561864eedf1
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 5 lines · Ard Biesheuvel
I realize you've put a lot of good and hard work into the existing I am also concerned about your claim that all software algorithms will be moved into this crypto library. You are not specific about whose responsibility it will be that this is going to happen in a timely fashion. But more importantly, it is not clear at all how you expect
Quoted 8 lines
this to work for, e.g., h/w instruction based SHAxxx or AES in various chaining modes, which should be used only on cores that implement those instructions (note that on arm64, we have optional instructions for AES, PMULL, SHA1, SHA256, SHA512, SHA3, SM3 and SM4). Are all those implementations (only few of which will be used on a certain core) going to be part of the monolithic library? What are the APIs going to look like for block ciphers, taking chaining modes into account?
I'm not convinced that there's any real need for *all* crypto algorithms to move into lib/zinc or to move at all. As I see it, there are two classes of crypto algorithms in the kernel:
a) Crypto that is used by code that chooses its algorithm statically and wants synchronous operations. These include everything in drivers/char/random.c, but also a bunch of various networking things that are hardcoded and basically everything that uses stack buffers. (This means it includes all the code that I broke when I did VMAP_STACK. Sign.)
b) Crypto that is used dynamically. This includes dm-crypt (aes-xts-plain64, aes-cbc-essiv, etc), all the ALG_IF interfaces, a lot of IPSEC stuff, possibly KCM, and probably many more. These will get comparatively little benefit from being converted to a zinc-like interface. For some of these cases, it wouldn't make any sense at all to convert them. Certainly the ones that do async hardware crypto using DMA engines will never look at all like zinc, even under the hood.
I think that, as a short-term goal, it makes a lot of sense to have implementations of the crypto that *new* kernel code (like Wireguard) wants to use in style (a) that live in /lib, and it obviously makes sense to consolidate their implementations with the crypto/ implementations in a timely manner. As a medium-term goal, adding more algorithms as needed for things that could use the simpler APIs (Bluetooth, perhaps) would make sense.
But I see no reason at all that /lib should ever contain a grab-bag of crypto implementations just for the heck of it. They should have real in-kernel users IMO. And this means that there will probably always be some crypto implementations in crypto/ for things like aes-xts.
--Andy
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 44 lines · Andy Lutomirski
Quoted 5 lines · Ard Biesheuvel
I realize you've put a lot of good and hard work into the existing I am also concerned about your claim that all software algorithms will be moved into this crypto library. You are not specific about whose responsibility it will be that this is going to happen in a timely fashion. But more importantly, it is not clear at all how you expect
Quoted 8 lines
this to work for, e.g., h/w instruction based SHAxxx or AES in various chaining modes, which should be used only on cores that implement those instructions (note that on arm64, we have optional instructions for AES, PMULL, SHA1, SHA256, SHA512, SHA3, SM3 and SM4). Are all those implementations (only few of which will be used on a certain core) going to be part of the monolithic library? What are the APIs going to look like for block ciphers, taking chaining modes into account?
I'm not convinced that there's any real need for *all* crypto algorithms to move into lib/zinc or to move at all. As I see it, there are two classes of crypto algorithms in the kernel:
a) Crypto that is used by code that chooses its algorithm statically and wants synchronous operations. These include everything in
drivers/char/random.c, but also a bunch of various networking things that are hardcoded and basically everything that uses stack buffers. (This means it includes all the code that I broke when I didVMAP_STACK. Sign.)b) Crypto that is used dynamically. This includes dm-crypt (aes-xts-plain64, aes-cbc-essiv, etc), all the
ALG_IFinterfaces, a lot of IPSEC stuff, possibly KCM, and probably many more. These will get comparatively little benefit from being converted to a zinc-like interface. For some of these cases, it wouldn't make any sense at all to convert them. Certainly the ones that do async hardware crypto using DMA engines will never look at all like zinc, even under the hood.I think that, as a short-term goal, it makes a lot of sense to have implementations of the crypto that *new* kernel code (like Wireguard) wants to use in style (a) that live in /lib, and it obviously makes sense to consolidate their implementations with the
crypto/implementations in a timely manner. As a medium-term goal, adding more algorithms as needed for things that could use the simpler APIs (Bluetooth, perhaps) would make sense.
Quoted 5 lines
But I see no reason at all that /lib should ever contain a grab-bag of crypto implementations just for the heck of it. They should have real in-kernel users IMO. And this means that there will probably always be some crypto implementations in
crypto/for things like aes-xts.
But one of the supposed selling points of this crypto library is that it gives engineers who are frightened of crypto in general and the crypto API in particular simple and easy to use crypto primitives rather than having to jump through the crypto API's hoops.
A crypto library whose only encryption algorithm is a stream cipher does *not* deliver on that promise, since it is only suitable for cases where IVs are guaranteed not to be reused. You yourself were bitten by the clunkiness of the crypto API when attempting to use the SHA26 code, right? So shouldn't we move that into this crypto library as well?
I think it is reasonable for WireGuard to standardize on ChaCha20/Poly1305 only, although I have my concerns about the flag day that will be required if this 'one true cipher' ever does turn out to be compromised (either that, or we will have to go back in time and add some kind of protocol versioning to existing deployments of WireGuard)
And frankly, if the code were as good as the prose, we wouldn't be having this discussion. Zinc adds its own clunky ways to mix arch and generic code, involving GCC -include command line arguments and #ifdefs everywhere. My review comments on this were completely ignored by Jason.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 4 lines · Ard Biesheuvel
But one of the supposed selling points of this crypto library is that it gives engineers who are frightened of crypto in general and the crypto API in particular simple and easy to use crypto primitives rather than having to jump through the crypto API's hoops.
The goal is for engineers who want to specifically use algorithm X from within the kernel in a non-dynamic way to be able to then use algorithm X with a simple function call. The goal is not to open it up to people who have no idea what they're doing; for that a NaCL-like library with functions like "crypto_box_open" or something would fit the bill; but that's also not what we're trying to do here. Please don't confuse the design goals. The rest of your email is therefore a bit of a straw man; cut the rhetoric out.
Quoted 3 lines
A crypto library whose only encryption algorithm is a stream cipher does *not* deliver on that promise, since it is only suitable for cases where IVs are guaranteed not to be reused.
False. We also offer XChaCha20Poly1305, which takes a massive nonce, suitable for random generation.
If there became a useful case for AES-PMAC-SIV or even AES-GCM or something to that extent, then Zinc would add that as required. But we're not going to start adding random ciphers unless they're needed.
Quoted 4 lines
You yourself were
bitten by the clunkiness of the crypto API when attempting to use the SHA26 code, right? So shouldn't we move that into this crypto library as well?
As stated in the initial commit, and in numerous other emails stretching back a year, yes, sha256 and other things in lib/ are going to be put into Zinc following the initial merge of Zinc. These changes will happen incrementally, like everything else that happens in the kernel. Sha256, in particular, is probably the first thing I'll port post-merge.
Quoted 6 lines
I think it is reasonable for WireGuard to standardize on ChaCha20/Poly1305 only, although I have my concerns about the flag day that will be required if this 'one true cipher' ever does turn out to be compromised (either that, or we will have to go back in time and add some kind of protocol versioning to existing deployments of WireGuard)
Those concerns are not valid and have already been addressed (to you, I believe) on this mailing list and elsewhere. WireGuard is versioned, hence there's no need to "add" versioning, and it is prepared to roll out new cryptography in a subsequent version should there be any issues. In other words, your concern is based on a misunderstanding of the protocol. If you have issues, however, with the design decisions of WireGuard, something that's been heavily discussed with members of the linux kernel community, networking community, cryptography community, and so forth, for the last 3 years, I invite you to bring them up on <[email protected]>.
Quoted 2 lines
And frankly, if the code were as good as the prose, we wouldn't be having this discussion.
Please cut out this rhetoric. That's an obviously unprovable statement, but it probably isn't true anyway. I wish you'd stick to technical concerns only, rather than what appears to be a desire to derail this by any means necessary.
Quoted 4 lines
Zinc adds its own clunky ways to mix arch and
generic code, involving GCC -include command line arguments and #ifdefs everywhere. My review comments on this were completely ignored by Jason.
No, they were not ignored. v2 cleaned up the #ifdefs. v4 has already cleaned up the makefile stuff and will be even cleaner. Good things await, don't worry.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 20 lines · Jason A. Donenfeld
Quoted 4 lines · Ard Biesheuvel
But one of the supposed selling points of this crypto library is that it gives engineers who are frightened of crypto in general and the crypto API in particular simple and easy to use crypto primitives rather than having to jump through the crypto API's hoops.
The goal is for engineers who want to specifically use algorithm X from within the kernel in a non-dynamic way to be able to then use algorithm X with a simple function call. The goal is not to open it up to people who have no idea what they're doing; for that a NaCL-like library with functions like "
crypto_box_open" or something would fit the bill; but that's also not what we're trying to do here. Please don't confuse the design goals. The rest of your email is therefore a bit of a straw man; cut the rhetoric out.Quoted 3 lines
A crypto library whose only encryption algorithm is a stream cipher does *not* deliver on that promise, since it is only suitable for cases where IVs are guaranteed not to be reused.
Quoted 7 lines
False. We also offer XChaCha20Poly1305, which takes a massive nonce, suitable for random generation.
If there became a useful case for AES-PMAC-SIV or even AES-GCM or something to that extent, then Zinc would add that as required. But we're not going to start adding random ciphers unless they're needed.
I'd prefer it if all the accelerated software implementations live in the same place. But I do strongly prefer arch code to live in arch/$arch, simply because of the maintenance scope for arch developers and maintainers.
I think AES-GCM is a useful example here. I really like the SIMD token abstraction a lot, but I would like to understand how this would work in Zinc if you have
a) a generic implementation
b) perhaps an arch specific scalar implementation
c) a pure NEON implementation
d) an implementation using AES instructions but not the PMULL instructions
e) an implementation that uses AES and PMULL instructions.
On arch/arm64 we support code patching, on other arches it may be different. We also support udev loading of modules depending on CPU capabilities, which means only the implementation you are likely to use will be loaded, and other modules are disregarded.
I am not asking you to implement this now. But I do want to understand how these use cases fit into Zinc. And note that this has nothing to do with the crypto API: this could simply be a synchronous aes_gcm_encrypt() library function that maps to any of the above at runtime depending on the platform's capabilities.
Quoted 5 lines
Quoted 4 lines
You yourself were
bitten by the clunkiness of the crypto API when attempting to use the SHA26 code, right? So shouldn't we move that into this crypto library as well?
Quoted 7 lines
As stated in the initial commit, and in numerous other emails stretching back a year, yes, sha256 and other things in
lib/are going to be put into Zinc following the initial merge of Zinc. These changes will happen incrementally, like everything else that happens in the kernel. Sha256, in particular, is probably the first thing I'll port post-merge.
Excellent.
Quoted 7 lines
Quoted 6 lines
I think it is reasonable for WireGuard to standardize on ChaCha20/Poly1305 only, although I have my concerns about the flag day that will be required if this 'one true cipher' ever does turn out to be compromised (either that, or we will have to go back in time and add some kind of protocol versioning to existing deployments of WireGuard)
Quoted 11 lines
Those concerns are not valid and have already been addressed (to you, I believe) on this mailing list and elsewhere. WireGuard is versioned, hence there's no need to "add" versioning, and it is prepared to roll out new cryptography in a subsequent version should there be any issues. In other words, your concern is based on a misunderstanding of the protocol. If you have issues, however, with the design decisions of WireGuard, something that's been heavily discussed with members of the linux kernel community, networking community, cryptography community, and so forth, for the last 3 years, I invite you to bring them up on <[email protected]>.
I'd prefer to have the discussion here, if you don't mind.
IIUC clients and servers need to run the same version of the protocol. So does it require a flag day to switch the world over to the new version when the old one is deprecated?
Quoted 8 lines
Quoted 2 lines
And frankly, if the code were as good as the prose, we wouldn't be having this discussion.
Please cut out this rhetoric. That's an obviously unprovable statement, but it probably isn't true anyway. I wish you'd stick to technical concerns only, rather than what appears to be a desire to derail this by any means necessary.
I apologize if I hit a nerve there, that was not my intention.
I am not an 'entrenched crypto API guy that is out to get you'. I am a core ARM developer that takes an interest in crypto, shares your concern about the usability of the crypto API, and tries to ensure that what we end up is maintainable and usable for everybody.
Quoted 9 lines
Quoted 4 lines
Zinc adds its own clunky ways to mix arch and
generic code, involving GCC -include command line arguments and #ifdefs everywhere. My review comments on this were completely ignored by Jason.No, they were not ignored. v2 cleaned up the #ifdefs. v4 has already cleaned up the makefile stuff and will be even cleaner. Good things await, don't worry.
You know what? If you're up for it, let's not wait until Plumbers, but instead, let's collaborate off list to get this into shape.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 3 lines · Ard Biesheuvel
I'd prefer it if all the accelerated software implementations live in the same place. But I do strongly prefer arch code to live in
arch/$arch
Zinc follows the scheme of the raid6 code, as well as of most other crypto libraries: code is grouped by cipher, making it easy for people to work with and understand differing implementations. It also allows us to trivially link these together at compile time rather than at link time, which makes cipher selection much more efficient. It's really much more maintainable this way.
Quoted 8 lines
I think AES-GCM is a useful example here. I really like the SIMD token abstraction a lot, but I would like to understand how this would work in Zinc if you have
a) a generic implementation
b) perhaps an arch specific scalar implementation
c) a pure NEON implementation
d) an implementation using AES instructions but not the PMULL instructions
e) an implementation that uses AES and PMULL instructions.
The same way that Zinc currently chooses between the five different implementations for, say, x86_64 ChaCha20:
- Generic C scalar
- SSSE3
- AVX2
- AVX512F
- AVX512VL
We make a decision based on CPU capabilities, SIMD context, and input length, and then choose the right function.
Quoted 2 lines
You know what? If you're up for it, let's not wait until Plumbers, but instead, let's collaborate off list to get this into shape.
Sure, sounds good.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 25 lines · Jason A. Donenfeld
Quoted 3 lines · Ard Biesheuvel
I'd prefer it if all the accelerated software implementations live in the same place. But I do strongly prefer arch code to live in
arch/$archZinc follows the scheme of the raid6 code, as well as of most other crypto libraries: code is grouped by cipher, making it easy for people to work with and understand differing implementations. It also allows us to trivially link these together at compile time rather than at link time, which makes cipher selection much more efficient. It's really much more maintainable this way.
Quoted 8 lines
I think AES-GCM is a useful example here. I really like the SIMD token abstraction a lot, but I would like to understand how this would work in Zinc if you have
a) a generic implementation
b) perhaps an arch specific scalar implementation
c) a pure NEON implementation
d) an implementation using AES instructions but not the PMULL instructions
e) an implementation that uses AES and PMULL instructions.The same way that Zinc currently chooses between the five different implementations for, say,
x86_64ChaCha20:
Quoted 9 lines
- Generic C scalar
- SSSE3
- AVX2
- AVX512F
- AVX512VLWe make a decision based on CPU capabilities, SIMD context, and input length, and then choose the right function.
OK, so given random.c's future dependency on Zinc (for ChaCha20), and the fact that Zinc is one monolithic piece of code, all versions of all algorithms will always be statically linked into the kernel proper. I'm not sure that is acceptable.
Quoted 5 lines
Quoted 2 lines
You know what? If you're up for it, let's not wait until Plumbers, but instead, let's collaborate off list to get this into shape.
Sure, sounds good.
BTW you haven't answered my question yet about what happens when the WireGuard protocol version changes: will we need a flag day and switch all deployments over at the same time?
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 4 lines · Ard Biesheuvel
OK, so given random.c's future dependency on Zinc (for ChaCha20), and the fact that Zinc is one monolithic piece of code, all versions of all algorithms will always be statically linked into the kernel proper. I'm not sure that is acceptable.
v4 already addresses that issue, actually. I'll post it shortly.
Quoted 3 lines
BTW you haven't answered my question yet about what happens when the WireGuard protocol version changes: will we need a flag day and switch all deployments over at the same time?
No, that won't be necessary, necessarily. Peers are individually versioned and the protocol is fairly flexible in this regard.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiQuoted 1 line · Andy Lutomirski
On Wed, Sep 12, 2018 at 3:56 PM, Ard Biesheuvel
...
Quoted 8 lines
b) Crypto that is used dynamically. This includes dm-crypt (aes-xts-plain64, aes-cbc-essiv, etc), all the
ALG_IFinterfaces, a lot of IPSEC stuff, possibly KCM, and probably many more. These will get comparatively little benefit from being converted to a zinc-like interface. For some of these cases, it wouldn't make any sense at all to convert them. Certainly the ones that do async hardware crypto using DMA engines will never look at all like zinc, even under the hood.
Please note, that dm-crypt now uses not only block ciphers and modes, but also authenticated encryption and hashes (for ESSIV and HMAC in authenticated composed modes) and RNG (for random IV). We use crypto API, including async variants (I hope correctly :)
There is a long time battle to move initialization vectors generators from dm-crypt to crypto API. If there are any plans to use a new library, this issue should be discussed as well.
(Some dm-crypt IV generators are disk encryption specific, some do more that just IV so porting is not straightforward etc).
Related problem here is an optimization of chain of sectors encryption - if we have new crypto API, it would be nice if can take chain of sectors so possible implementation can process this chain in one batch (every sector need to be tweaked by differently generated IV - and we are back in problem above).
I think filesystem encryption uses the same pattern.
And btw, we use the same algorithms through AF_ALG in userspace (cryptsetup).
So please, if you mention dm-crypt, note that it is very complex crypto API consumer :) And everything is dynamic, configurable through dm-crypt options.
That said, I would be more than happy to help in experiments to porting dm-crypt to any other crypto library, but if it doesn't not help with problems mentioned above, I do not see any compelling reason for the new library for dm-crypt...
Milan
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Milan,
Quoted 20 lines · Milan Broz
Please note, that dm-crypt now uses not only block ciphers and modes, but also authenticated encryption and hashes (for ESSIV and HMAC in authenticated composed modes) and RNG (for random IV). We use crypto API, including async variants (I hope correctly :)
There is a long time battle to move initialization vectors generators from dm-crypt to crypto API. If there are any plans to use a new library, this issue should be discussed as well.
(Some dm-crypt IV generators are disk encryption specific, some do more that just IV so porting is not straightforward etc).Related problem here is an optimization of chain of sectors encryption - if we have new crypto API, it would be nice if can take chain of sectors so possible implementation can process this chain in one batch (every sector need to be tweaked by differently generated IV - and we are back in problem above).
I think filesystem encryption uses the same pattern.And btw, we use the same algorithms through
AF_ALGin userspace (cryptsetup).
Quoted 7 lines
So please, if you mention dm-crypt, note that it is very complex crypto API consumer :) And everything is dynamic, configurable through dm-crypt options.
That said, I would be more than happy to help in experiments to porting dm-crypt to any other crypto library, but if it doesn't not help with problems mentioned above, I do not see any compelling reason for the new library for dm-crypt...
dm-crypt is probably a good consumer of the existing crypto API and won't be impacted by the introduction of Zinc, which is really just the exposure of a couple low level simple crypto functions, and not a fancy API like the crypto API which dm-crypt happily uses.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Milan BrozQuoted 15 lines · Milan Broz
Quoted 3 lines · Andy Lutomirski
On Wed, Sep 12, 2018 at 3:56 PM, Ard Biesheuvel
...
Quoted 8 lines
b) Crypto that is used dynamically. This includes dm-crypt (aes-xts-plain64, aes-cbc-essiv, etc), all the
ALG_IFinterfaces, a lot of IPSEC stuff, possibly KCM, and probably many more. These will get comparatively little benefit from being converted to a zinc-like interface. For some of these cases, it wouldn't make any sense at all to convert them. Certainly the ones that do async hardware crypto using DMA engines will never look at all like zinc, even under the hood.
Quoted 4 lines
Please note, that dm-crypt now uses not only block ciphers and modes, but also authenticated encryption and hashes (for ESSIV and HMAC in authenticated composed modes) and RNG (for random IV). We use crypto API, including async variants (I hope correctly :)
Right. And all this is why I don’t think dm-crypt should use zinc, at least not any time soon.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Andy LutomirskiQuoted 10 lines · Andy Lutomirski
I'm not convinced that there's any real need for *all* crypto algorithms to move into lib/zinc or to move at all. As I see it, there are two classes of crypto algorithms in the kernel:
a) Crypto that is used by code that chooses its algorithm statically and wants synchronous operations. These include everything in
drivers/char/random.c, but also a bunch of various networking things that are hardcoded and basically everything that uses stack buffers. (This means it includes all the code that I broke when I didVMAP_STACK. Sign.)
Right, exactly. This is what will wind up using Zinc. I'm working on an example usage of this for v4 of the patch submission, which you can ogle in a preview here if you're curious:
https://git.zx2c4.com/linux-dev/commit/?h=big_key_rewrite
28 insertions, 206 deletions :-D
Quoted 8 lines
b) Crypto that is used dynamically. This includes dm-crypt (aes-xts-plain64, aes-cbc-essiv, etc), all the
ALG_IFinterfaces, a lot of IPSEC stuff, possibly KCM, and probably many more. These will get comparatively little benefit from being converted to a zinc-like interface. For some of these cases, it wouldn't make any sense at all to convert them. Certainly the ones that do async hardware crypto using DMA engines will never look at all like zinc, even under the hood.
Right, this is what the crypto API will continue to be used for.
Quoted 7 lines
I think that, as a short-term goal, it makes a lot of sense to have implementations of the crypto that *new* kernel code (like Wireguard) wants to use in style (a) that live in /lib, and it obviously makes sense to consolidate their implementations with the
crypto/implementations in a timely manner. As a medium-term goal, adding more algorithms as needed for things that could use the simpler APIs (Bluetooth, perhaps) would make sense.
Agreed 100%. With regards to "consolidate their implementations" -- I've actually already done this after your urging yesterday, and so that will be a part of v4.
Quoted 4 lines
But I see no reason at all that /lib should ever contain a grab-bag of crypto implementations just for the heck of it. They should have real in-kernel users IMO. And this means that there will probably always be some crypto implementations in
crypto/for things like aes-xts.
Right, precisely.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 12 lines · Jason A. Donenfeld
Quoted 10 lines · Andy Lutomirski
I'm not convinced that there's any real need for *all* crypto algorithms to move into lib/zinc or to move at all. As I see it, there are two classes of crypto algorithms in the kernel:
a) Crypto that is used by code that chooses its algorithm statically and wants synchronous operations. These include everything in
drivers/char/random.c, but also a bunch of various networking things that are hardcoded and basically everything that uses stack buffers. (This means it includes all the code that I broke when I didVMAP_STACK. Sign.)
Quoted 8 lines
Right, exactly. This is what will wind up using Zinc. I'm working on an example usage of this for v4 of the patch submission, which you can ogle in a preview here if you're curious:
https://git.zx2c4.com/linux-dev/commit/?h=big_key_rewrite
28 insertions, 206 deletions :-D
I must say, that actually looks pretty good.
Quoted 32 lines
Quoted 8 lines
b) Crypto that is used dynamically. This includes dm-crypt (aes-xts-plain64, aes-cbc-essiv, etc), all the
ALG_IFinterfaces, a lot of IPSEC stuff, possibly KCM, and probably many more. These will get comparatively little benefit from being converted to a zinc-like interface. For some of these cases, it wouldn't make any sense at all to convert them. Certainly the ones that do async hardware crypto using DMA engines will never look at all like zinc, even under the hood.Right, this is what the crypto API will continue to be used for.
Quoted 7 lines
I think that, as a short-term goal, it makes a lot of sense to have implementations of the crypto that *new* kernel code (like Wireguard) wants to use in style (a) that live in /lib, and it obviously makes sense to consolidate their implementations with the
crypto/implementations in a timely manner. As a medium-term goal, adding more algorithms as needed for things that could use the simpler APIs (Bluetooth, perhaps) would make sense.Agreed 100%. With regards to "consolidate their implementations" -- I've actually already done this after your urging yesterday, and so that will be a part of v4.
Quoted 4 lines
But I see no reason at all that /lib should ever contain a grab-bag of crypto implementations just for the heck of it. They should have real in-kernel users IMO. And this means that there will probably always be some crypto implementations in
crypto/for things like aes-xts.Right, precisely.
Jason
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Ard BiesheuvelHi Ard,
Quoted 5 lines · Ard Biesheuvel
In this series, you are dumping a huge volume of unannotated, generated asm into the kernel which has been modified [by you] to [among other things?] adhere to the kernel API (without documenting what the changes are exactly). How does that live up to the promise of better, peer reviewed code?
The code still benefits from the review that's gone into OpenSSL. It's not modified in ways that would affect the cryptographic operations being done. It's modified to be suitable for kernel space.
Quoted 8 lines
Then there is the performance claim. We know for instance that the OpenSSL ARM NEON code for ChaCha20 is faster on cores that happen to possess a micro-architectural property that ALU instructions are essentially free when they are interleaved with SIMD instructions. But we also know that a) Cortex-A7, which is a relevant target, is not one of those cores, and b) that chip designers are not likely to optimize for that particular usage pattern so relying on it in generic code is unwise in general.
That's interesting. I'll bring this up with AndyP. FWIW, if you think you have a real and compelling claim here, I'd be much more likely to accept a different ChaCha20 implementation than I would be to accept a different Poly1305 implementation. (It's a *lot* harder to screw up ChaCha20 than it is to screw up Poly1305.)
Quoted 2 lines
I am also concerned about your claim that all software algorithms will be moved into this crypto library.
I'll defer to Andy's response here, which I think is a correct one:
https://lkml.org/lkml/2018/9/13/27
The short answer is that Zinc is going to be adding the ciphers that people want to use for normal reasons from normal code. For example, after this merges, we'll next be working on moving the remaining non-optimized C code out of lib/ that's called by places (such as SHA2).
Quoted 3 lines
You are not specific about whose
responsibility it will be that this is going to happen in a timely fashion.
I thought I laid out the roadmap for this in the commit message. In case I wasn't clear: my plan is to tackle lib/ after merging, and I plan to do so in a timely manner. It's a pretty common tactic to keep layering on tasks, "what about X?", "what about Y?", "I won't agree unless Z!" -- when in reality kernel development and refactorings are done incrementally. I've been around on this list contributing code for long enough that you should have a decent amount of confidence that I'm not just going to disappear working on this or something insane like that. And neither are the two academic cryptographers CC'd on this thread. So, as Andy said, we're going to be porting to Zinc the primitives that are useful for the various applications of Zinc. This means yes, we'll have SHA2 in there.
Quoted 4 lines
chaining modes
What are the APIs
going to look like for block ciphers, taking chaining modes into account?
As mentioned in the commit message and numerous times, we're not trying to make a win32-like crypto API here or to remake the existing Linux crypto API. Rather we're providing libraries of specific functions that are useful for various circumstances. For example, if AES-GCM is desired at some point, then we'll have a similar API for that as we do for ChaPoly -- one that takes buffers and one that takes sg. Likewise, hash functions use the familiar init/update/final. "Generic" chaining modes aren't really part of the equation or design goals.
Again, I realize you've spent a long time working on the existing crypto API, and so your questions and concerns are in the line of, "how are we going to make Zinc look like the existing crypto API in functionality?" But that's not what we're up to here. We have a different and complementary design goal. I understand why you're squirming, but please recognize we're working on different things.
Quoted 4 lines
I'm sure it is rather simple to port the crypto API implementation of ChaCha20 to use your library. I am more concerned about how your library is going to expand to cover all other software algorithms that we currently use in the kernel.
The subset of algorithms we add will be developed with the same methodology as the present ones. There is nothing making this particularly difficult or even more difficult for other primitives than it was for ChaCha20. It's especially easy, in fact, since we're following similar design methodologies as the vast majority of other cryptography libraries that have been developed. Namely, we're creating simple things called "functions".
Quoted 3 lines
Of course. But please respond to all the concerns, You have not
responded to that concern yet.
Sorry, it's certainly not my intention. I've been on vacation with my family for the last several weeks, and only returned home sleep-deprived last night after 4 days of plane delays. I've now rested and will resume working on this full-time and I'll try my best to address concerns, and also go back through emails to find things I might have missed. (First, though, I'm going to deal with getting back the three suitcases the airline lost in transit...)
Quoted 6 lines
Quoted 4 lines
Anyway, it sounds like this whole thing may have ruffled your feathers a bit. Will you be at Linux Plumbers Conference in November? I'm planning on attending, and perhaps we could find some time there to sit down and talk one on one a bit.
That would be good, yes. I will be there.
Looking forward to talking to you there, and hopefully we can put to rest any lingering concerns.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 10 lines · Jason A. Donenfeld
Hi Ard,
Quoted 5 lines · Ard Biesheuvel
In this series, you are dumping a huge volume of unannotated, generated asm into the kernel which has been modified [by you] to [among other things?] adhere to the kernel API (without documenting what the changes are exactly). How does that live up to the promise of better, peer reviewed code?
Quoted 4 lines
The code still benefits from the review that's gone into OpenSSL. It's not modified in ways that would affect the cryptographic operations being done. It's modified to be suitable for kernel space.
So could we please at least have those changes as a separate patch then?
Quoted 9 lines
Quoted 8 lines
Then there is the performance claim. We know for instance that the OpenSSL ARM NEON code for ChaCha20 is faster on cores that happen to possess a micro-architectural property that ALU instructions are essentially free when they are interleaved with SIMD instructions. But we also know that a) Cortex-A7, which is a relevant target, is not one of those cores, and b) that chip designers are not likely to optimize for that particular usage pattern so relying on it in generic code is unwise in general.
Quoted 6 lines
That's interesting. I'll bring this up with AndyP. FWIW, if you think you have a real and compelling claim here, I'd be much more likely to accept a different ChaCha20 implementation than I would be to accept a different Poly1305 implementation. (It's a *lot* harder to screw up ChaCha20 than it is to screw up Poly1305.)
The question is really whether we want different implementations in the crypto API and in zinc.
Quoted 12 lines
Quoted 2 lines
I am also concerned about your claim that all software algorithms will be moved into this crypto library.
I'll defer to Andy's response here, which I think is a correct one:
https://lkml.org/lkml/2018/9/13/27The short answer is that Zinc is going to be adding the ciphers that people want to use for normal reasons from normal code. For example, after this merges, we'll next be working on moving the remaining non-optimized C code out of
lib/that's called by places (such as SHA2).
Excellent.
Quoted 32 lines
Quoted 3 lines
You are not specific about whose
responsibility it will be that this is going to happen in a timely fashion.I thought I laid out the roadmap for this in the commit message. In case I wasn't clear: my plan is to tackle
lib/after merging, and I plan to do so in a timely manner. It's a pretty common tactic to keep layering on tasks, "what about X?", "what about Y?", "I won't agree unless Z!" -- when in reality kernel development and refactorings are done incrementally. I've been around on this list contributing code for long enough that you should have a decent amount of confidence that I'm not just going to disappear working on this or something insane like that. And neither are the two academic cryptographers CC'd on this thread. So, as Andy said, we're going to be porting to Zinc the primitives that are useful for the various applications of Zinc. This means yes, we'll have SHA2 in there.Quoted 4 lines
chaining modes
What are the APIs
going to look like for block ciphers, taking chaining modes into account?As mentioned in the commit message and numerous times, we're not trying to make a win32-like crypto API here or to remake the existing Linux crypto API. Rather we're providing libraries of specific functions that are useful for various circumstances. For example, if AES-GCM is desired at some point, then we'll have a similar API for that as we do for ChaPoly -- one that takes buffers and one that takes sg. Likewise, hash functions use the familiar
init/update/final. "Generic" chaining modes aren't really part of the equation or design goals.
Quoted 4 lines
Again, I realize you've spent a long time working on the existing crypto API, and so your questions and concerns are in the line of, "how are we going to make Zinc look like the existing crypto API in functionality?"
You are completely missing my point. I am not particularly invested in the crypto API, and I share the concerns about its usability. That is why I want to make sure that your solution actually results in a net improvement for everybody, not just for WireGuard, in a maintainable way.
Quoted 40 lines
But that's not what we're up to here. We have a different and complementary design goal. I understand why you're squirming, but please recognize we're working on different things.
Quoted 4 lines
I'm sure it is rather simple to port the crypto API implementation of ChaCha20 to use your library. I am more concerned about how your library is going to expand to cover all other software algorithms that we currently use in the kernel.
The subset of algorithms we add will be developed with the same methodology as the present ones. There is nothing making this particularly difficult or even more difficult for other primitives than it was for ChaCha20. It's especially easy, in fact, since we're following similar design methodologies as the vast majority of other cryptography libraries that have been developed. Namely, we're creating simple things called "functions".
Quoted 3 lines
Of course. But please respond to all the concerns, You have not
responded to that concern yet.Sorry, it's certainly not my intention. I've been on vacation with my family for the last several weeks, and only returned home sleep-deprived last night after 4 days of plane delays. I've now rested and will resume working on this full-time and I'll try my best to address concerns, and also go back through emails to find things I might have missed. (First, though, I'm going to deal with getting back the three suitcases the airline lost in transit...)
Quoted 6 lines
Quoted 4 lines
Anyway, it sounds like this whole thing may have ruffled your feathers a bit. Will you be at Linux Plumbers Conference in November? I'm planning on attending, and perhaps we could find some time there to sit down and talk one on one a bit.
That would be good, yes. I will be there.
Looking forward to talking to you there, and hopefully we can put to rest any lingering concerns.
Jason
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 5 lines · Ard Biesheuvel
Quoted 3 lines
The code still benefits from the review that's gone into OpenSSL. It's not modified in ways that would affect the cryptographic operations being done. It's modified to be suitable for kernel space.
So could we please at least have those changes as a separate patch then?
I'll experiment with a couple ways of trying to communicate with precision what's been changed from OpenSSL for the next round of patches.
Quoted 8 lines
Quoted 5 lines
That's interesting. I'll bring this up with AndyP. FWIW, if you think you have a real and compelling claim here, I'd be much more likely to accept a different ChaCha20 implementation than I would be to accept a different Poly1305 implementation. (It's a *lot* harder to screw up ChaCha20 than it is to screw up Poly1305.)
The question is really whether we want different implementations in the crypto API and in zinc.
Per earlier in this discussion, I've already authored patches that replaces the crypto API's implementations with simple calls to Zinc, so that code isn't duplicated. These will be in v4 and you can comment on the approach then.
Quoted 5 lines
You are completely missing my point. I am not particularly invested in the crypto API, and I share the concerns about its usability. That is why I want to make sure that your solution actually results in a net improvement for everybody, not just for WireGuard, in a maintainable way.
Right, likewise. I've put quite a bit of effort into separating Zinc into Zinc and not into something part of WireGuard. The motivation for doing so is a decent amount of call sites all around the kernel that I'd like to gradually fix up.
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
In reply to Ard BiesheuvelQuoted 4 lines · Ard Biesheuvel
I won't go into the 1000s lines of generated assembly again - you already know my position on that topic.
I'd strongly prefer the assembly to be readable too. Jason, I'm not sure if you've actually read through the asm from the OpenSSL implementations, but the generated .S files actually do lose a lot of semantic information that was in the original .pl scripts. For example, in the Poly1305 NEON implementation which I'm especially interested in (but you could check any of the other generated files too), the original .pl script has register aliases showing the meaning of each register. Just grabbing a random hunk:
vshr.u64 $T0,$D3,#26
vmovn.i64 $D3#lo,$D3
vshr.u64 $T1,$D0,#26
vmovn.i64 $D0#lo,$D0
vadd.i64 $D4,$D4,$T0 @ h3 -> h4
vbic.i32 $D3#lo,#0xfc000000
vsri.u32 $H4,$H3,#8 @ base 2^32 -> base 2^26
vadd.i64 $D1,$D1,$T1 @ h0 -> h1
vshl.u32 $H3,$H3,#18
vbic.i32 $D0#lo,#0xfc000000(Yes, it's still not *that* readable, but D0-D4 and H0-H4 map directly to d0-d4 and h0-h4 in the C implementation. So someone familiar with Poly1305 implementations can figure it out.)
In contrast, the generated .S file just has the raw registers. It's difficult to remember what each register is used for. In fact, someone who actually wanted to figure it out would probably find themselves referring to the .pl script -- which raises the question of why the .S file is the "source" and not the .pl script...
vshr.u64 q15,q8,#26
vmovn.i64 d16,q8
vshr.u64 q4,q5,#26
vmovn.i64 d10,q5
vadd.i64 q9,q9,q15 @ h3 -> h4
vbic.i32 d16,#0xfc000000
vsri.u32 q14,q13,#8 @ base 2^32 -> base 2^26
vadd.i64 q6,q6,q4 @ h0 -> h1
vshl.u32 q13,q13,#18
vbic.i32 d10,#0xfc000000- Eric
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Hi Eric,
Quoted 4 lines · Eric Biggers
I'd strongly prefer the assembly to be readable too. Jason, I'm not sure if you've actually read through the asm from the OpenSSL implementations, but the generated .S files actually do lose a lot of semantic information that was in the original .pl scripts.
The thing to keep in mind is that the .S was not directly and blindly generated from the .pl. We started with the output of the .pl, and then, particularly in the case of x86_64, worked with it a lot, and now it's something a bit different. We've definitely spent a lot of time reading that assembly.
I'll see if I can improve the readability with some register name remapping on ARM. No guarantees, but I'll play a bit and see if I can make it a bit better.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 8 lines · Jason A. Donenfeld
Hi Eric,
Quoted 4 lines · Eric Biggers
I'd strongly prefer the assembly to be readable too. Jason, I'm not sure if you've actually read through the asm from the OpenSSL implementations, but the generated .S files actually do lose a lot of semantic information that was in the original .pl scripts.
Quoted 6 lines
The thing to keep in mind is that the .S was not directly and blindly generated from the .pl. We started with the output of the .pl, and then, particularly in the case of
x86_64, worked with it a lot, and now it's something a bit different. We've definitely spent a lot of time reading that assembly.
Can we please have those changes as a separate patch? Preferably to the .pl file rather than the .S file, so we can easily distinguish the code from upstream from the code that you modified.
Quoted 5 lines
I'll see if I can improve the readability with some register name remapping on ARM. No guarantees, but I'll play a bit and see if I can make it a bit better.
Jason
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 16 lines · Ard Biesheuvel
Quoted 8 lines · Jason A. Donenfeld
Hi Eric,
Quoted 4 lines · Eric Biggers
I'd strongly prefer the assembly to be readable too. Jason, I'm not sure if you've actually read through the asm from the OpenSSL implementations, but the generated .S files actually do lose a lot of semantic information that was in the original .pl scripts.
Quoted 6 lines
The thing to keep in mind is that the .S was not directly and blindly generated from the .pl. We started with the output of the .pl, and then, particularly in the case of
x86_64, worked with it a lot, and now it's something a bit different. We've definitely spent a lot of time reading that assembly.
Quoted 9 lines
Can we please have those changes as a separate patch? Preferably to the .pl file rather than the .S file, so we can easily distinguish the code from upstream from the code that you modified.
Quoted 5 lines
I'll see if I can improve the readability with some register name remapping on ARM. No guarantees, but I'll play a bit and see if I can make it a bit better.
Jason
FWIW, yesterday I made a modified version of poly1305-armv4.pl that generates an asm file that works in kernel mode. The changes are actually pretty small, and I think we can get them upstream into OpenSSL like they were for sha256-armv4.pl and sha512-armv4.pl. I'll start a thread with Andy Polyakov and you two.
But I don't have time to help with all the many OpenSSL asm files Jason is proposing, just maybe poly1305-armv4 and chacha-armv4 for now.
- Eric
Re: [PATCH net-next v3 02/17] zinc: introduce minimal cryptography library
Quoted 27 lines · Eric Biggers
Quoted 16 lines · Ard Biesheuvel
Quoted 8 lines · Jason A. Donenfeld
Hi Eric,
Quoted 4 lines · Eric Biggers
I'd strongly prefer the assembly to be readable too. Jason, I'm not sure if you've actually read through the asm from the OpenSSL implementations, but the generated .S files actually do lose a lot of semantic information that was in the original .pl scripts.
Quoted 6 lines
The thing to keep in mind is that the .S was not directly and blindly generated from the .pl. We started with the output of the .pl, and then, particularly in the case of
x86_64, worked with it a lot, and now it's something a bit different. We've definitely spent a lot of time reading that assembly.Quoted 9 lines
Can we please have those changes as a separate patch? Preferably to the .pl file rather than the .S file, so we can easily distinguish the code from upstream from the code that you modified.
Quoted 5 lines
I'll see if I can improve the readability with some register name remapping on ARM. No guarantees, but I'll play a bit and see if I can make it a bit better.
Jason
Quoted 8 lines
FWIW, yesterday I made a modified version of poly1305-armv4.pl that generates an asm file that works in kernel mode. The changes are actually pretty small, and I think we can get them upstream into OpenSSL like they were for sha256-armv4.pl and sha512-armv4.pl. I'll start a thread with Andy Polyakov and you two.
But I don't have time to help with all the many OpenSSL asm files Jason is proposing, just maybe poly1305-armv4 and chacha-armv4 for now.
Thanks Eric. I reached out to Andy Polyakov off line, and he is happy to work with us again on this, although he did point out that our experiences on ARM may not extrapolate to x86_64, given the fact that the perl sources there also contain parameterization for the calling convention differences between Windows and SysV.
Jason A. Donenfeld
maintainerPATCH v3 3/17 zinc: ChaCha20 generic C implementation
In reply to Jason A. DonenfeldThis implements the ChaCha20 permutation as a single C statement, by way of the comma operator, which the compiler is able to simplify terrifically.
Information: https://cr.yp.to/chacha.html
--- include/zinc/chacha20.h | 53 +++++++++++ lib/zinc/Kconfig | 4 + lib/zinc/Makefile | 4 + lib/zinc/chacha20/chacha20.c | 168 +++++++++++++++++++++++++++++++++++ lib/zinc/main.c | 5 ++ 5 files changed, 234 insertions(+) create mode 100644 include/zinc/chacha20.h create mode 100644 lib/zinc/chacha20/chacha20.c
include/zinc/chacha20.h new file +53 -0
@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _ZINC_CHACHA20_H +#define _ZINC_CHACHA20_H + +#include <asm/unaligned.h> +#include <linux/simd.h> +#include <linux/kernel.h> +#include <linux/types.h> + +enum { +CHACHA20_IV_SIZE =16 , +CHACHA20_KEY_SIZE =32 , +CHACHA20_BLOCK_SIZE =64 , +HCHACHA20_KEY_SIZE =32 , +HCHACHA20_NONCE_SIZE =16 +}; + +struct chacha20_ctx { +u32 key[8 ]; +u32 counter[4 ]; +}__aligned(32) ; + +void chacha20_fpu_init (void ); + +static inline void chacha20_init (struct chacha20_ctx *state, +const u8 key[CHACHA20_KEY_SIZE ], +const u64 nonce) +{ + state->key[0 ] =get_unaligned_le32 (key +0 ); + state->key[1 ] =get_unaligned_le32 (key +4 ); + state->key[2 ] =get_unaligned_le32 (key +8 ); + state->key[3 ] =get_unaligned_le32 (key +12 ); + state->key[4 ] =get_unaligned_le32 (key +16 ); + state->key[5 ] =get_unaligned_le32 (key +20 ); + state->key[6 ] =get_unaligned_le32 (key +24 ); + state->key[7 ] =get_unaligned_le32 (key +28 ); + state->counter[0 ] = state->counter[1 ] =0 ; + state->counter[2 ] = nonce &U32_MAX ; + state->counter[3 ] = nonce >>32 ; +} +void chacha20 (struct chacha20_ctx *state,u8 *dst,const u8 *src,u32 len, +simd_context_t simd_context); + +/* Derived key should be 32-bit aligned */ +void hchacha20 (u8 derived_key[CHACHA20_KEY_SIZE ], +const u8 nonce[HCHACHA20_NONCE_SIZE ], +const u8 key[HCHACHA20_KEY_SIZE ],simd_context_t simd_context); + +#endif /* _ZINC_CHACHA20_H */
lib/zinc/Kconfig +4 -0
@@ -6,6 +6,10 @@ config ZINC select NEON select KERNEL_MODE_NEON +config ZINC_CHACHA20 + bool + select ZINC + config ZINC_DEBUG bool "Zinc cryptography library debugging and self-tests" depends on ZINC
lib/zinc/Makefile +4 -0
@@ -3,6 +3,10 @@ ccflags-y += -Wframe-larger-than=8192 ccflags-y += -D'pr_fmt(fmt)=KBUILD_MODNAME ": " fmt' ccflags-$(CONFIG_ZINC_DEBUG) += -DDEBUG +ifeq ($(CONFIG_ZINC_CHACHA20),y) +zinc-y += chacha20/chacha20.o +endif + zinc-y += main.o obj-$(CONFIG_ZINC) := zinc.o
lib/zinc/chacha20/chacha20.c new file +168 -0
168 lines not on this page · raw message
lib/zinc/main.c +5 -0
@@ -3,6 +3,8 @@* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. */ +#include <zinc/chacha20.h> +#include <linux/init.h> #include <linux/module.h>
@@ -17,6 +19,9 @@static int __init mod_init (void ) { +#ifdef CONFIG_ZINC_CHACHA20 +chacha20_fpu_init (); +#endif return 0 ; }
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 4/17 zinc: ChaCha20 ARM and ARM64 implementations
In reply to Jason A. DonenfeldThese NEON and non-NEON implementations come from Andy Polyakov's implementation, with several modifications for being friendly to kernel space.
--- lib/zinc/Makefile | 8 + lib/zinc/chacha20/chacha20-arm-glue.h | 50 + lib/zinc/chacha20/chacha20-arm.S | 1473 +++++++++++++++++++ lib/zinc/chacha20/chacha20-arm64.S | 1942 +++++++++++++++++++++++++ 4 files changed, 3473 insertions(+) create mode 100644 lib/zinc/chacha20/chacha20-arm-glue.h create mode 100644 lib/zinc/chacha20/chacha20-arm.S create mode 100644 lib/zinc/chacha20/chacha20-arm64.S
lib/zinc/Makefile +8 -0
@@ -5,6 +5,14 @@ ccflags-$(CONFIG_ZINC_DEBUG) += -DDEBUG ifeq ($(CONFIG_ZINC_CHACHA20),y) zinc-y += chacha20/chacha20.o +ifeq ($(CONFIG_ARM),y) +zinc-y += chacha20/chacha20-arm.o +CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-arm-glue.h +endif +ifeq ($(CONFIG_ARM64),y) +zinc-y += chacha20/chacha20-arm64.o +CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-arm-glue.h +endif endif zinc-y += main.o
lib/zinc/chacha20/chacha20-arm-glue.h new file +50 -0
50 lines not on this page · raw message
lib/zinc/chacha20/chacha20-arm.S new file +1473 -0
1,473 lines not on this page · raw message
lib/zinc/chacha20/chacha20-arm64.S new file +1942 -0
1,463 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.18.0
Part of the diff is not shown here. View the raw message.
Jason A. Donenfeld
maintainerPATCH v3 5/17 zinc: ChaCha20 x86_64 implementation
In reply to Jason A. DonenfeldThis provides SSSE3, AVX-2, AVX-512F, and AVX-512VL implementations for ChaCha20. The AVX-512F implementation is disabled on Skylake, due to throttling, and the VL ymm implementation is used instead. These come from Andy Polyakov's implementation, with some heavy modifications from Samuel Neves and me.
--- lib/zinc/Makefile | 4 + lib/zinc/chacha20/chacha20-x86_64-glue.h | 102 + lib/zinc/chacha20/chacha20-x86_64.S | 2632 ++++++++++++++++++++++ 3 files changed, 2738 insertions(+) create mode 100644 lib/zinc/chacha20/chacha20-x86_64-glue.h create mode 100644 lib/zinc/chacha20/chacha20-x86_64.S
lib/zinc/Makefile +4 -0
@@ -5,6 +5,10 @@ ccflags-$(CONFIG_ZINC_DEBUG) += -DDEBUG ifeq ($(CONFIG_ZINC_CHACHA20),y) zinc-y += chacha20/chacha20.o +ifeq ($(CONFIG_X86_64)$(CONFIG_UML),y) +zinc-y += chacha20/chacha20-x86_64.o +CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-x86_64-glue.h +endif ifeq ($(CONFIG_ARM),y) zinc-y += chacha20/chacha20-arm.o CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-arm-glue.h
lib/zinc/chacha20/chacha20-x86_64-glue.h new file +102 -0
102 lines not on this page · raw message
lib/zinc/chacha20/chacha20-x86_64.S new file +2632 -0
2,632 lines not on this page · raw message
Signature · 1 line
2.18.0
Re: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Quoted 3 lines · Jason A. Donenfeld
lib/zinc/Makefile | 4 + lib/zinc/chacha20/chacha20-x86_64-glue.h | 102 + lib/zinc/chacha20/chacha20-x86_64.S | 2632 ++++++++++++++++++++++
Just a stupid question. What's the rationale of putting that into lib/zinc instead of having it in arch/x86/crypto?
Thanks,
tglx
Re: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Quoted 8 lines · Thomas Gleixner
Quoted 3 lines · Jason A. Donenfeld
lib/zinc/Makefile | 4 + lib/zinc/chacha20/chacha20-x86_64-glue.h | 102 + lib/zinc/chacha20/chacha20-x86_64.S | 2632 ++++++++++++++++++++++Just a stupid question. What's the rationale of putting that into lib/zinc instead of having it in
arch/x86/crypto?
This is covered on the 02/17 commit message, whose relevant paragraph follows:
Quoted 11 lines
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 inlib/zinc/, making it simple and obvious to compare and contrast what's happening. This is, notably, exactly what thelib/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.
Re: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Quoted 11 lines · Samuel Neves
Quoted 8 lines · Thomas Gleixner
Quoted 3 lines · Jason A. Donenfeld
lib/zinc/Makefile | 4 + lib/zinc/chacha20/chacha20-x86_64-glue.h | 102 + lib/zinc/chacha20/chacha20-x86_64.S | 2632 ++++++++++++++++++++++Just a stupid question. What's the rationale of putting that into lib/zinc instead of having it in
arch/x86/crypto?This is covered on the 02/17 commit message, whose relevant paragraph follows:
Well, being only cc'ed on only half of the patches does not really help.
Quoted 11 lines
Quoted 11 lines
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 inlib/zinc/, making it simple and obvious to compare and contrast what's happening. This is, notably, exactly what thelib/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.
Fair enough.
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Hey Thomas,
Quoted 2 lines · Thomas Gleixner
Quoted 1 line
This is covered on the 02/17 commit message, whose relevant paragraph follows:
Well, being only cc'ed on only half of the patches does not really help.
Sorry about that. I'm happy to Cc you on the whole series for next round if you want. Just let me know. In the meantime:
https://patchwork.ozlabs.org/project/netdev/list/?series=65056
https://lore.kernel.org/lkml/[email protected]/T/
Regards,
Jason
Re: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Quoted 8 lines · Jason A. Donenfeld
Hey Thomas,
Quoted 2 lines · Thomas Gleixner
Quoted 1 line
This is covered on the 02/17 commit message, whose relevant paragraph follows:
Well, being only cc'ed on only half of the patches does not really help.
Sorry about that. I'm happy to Cc you on the whole series for next round if you want. Just let me know. In the meantime:
Na, all good. I'm fine with the answer and reviewing that ASM maze is way over my limited crypto knowledge anyway. I definitely would enjoy refreshing the math behind it, but that surely would be way outside of your envisioned time frame for getting this merged :)
Thanks,
tglx
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Quoted 4 lines · Thomas Gleixner
Na, all good. I'm fine with the answer and reviewing that ASM maze is way over my limited crypto knowledge anyway. I definitely would enjoy refreshing the math behind it, but that surely would be way outside of your envisioned time frame for getting this merged :)
Well, if you're at LPC, we can nerd out a bit on some crypto math if you want. :-P
Re: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
In reply to Jason A. DonenfeldQuoted 6 lines · Jason A. Donenfeld
Hey Thomas,
Quoted 2 lines · Thomas Gleixner
Quoted 1 line
This is covered on the 02/17 commit message, whose relevant paragraph follows:
Well, being only cc'ed on only half of the patches does not really help.
Quoted 8 lines
Sorry about that. I'm happy to Cc you on the whole series for next round if you want. Just let me know. In the meantime:
https://patchwork.ozlabs.org/project/netdev/list/?series=65056
https://lore.kernel.org/lkml/[email protected]/T/Regards,
Jason
Please Cc linux-crypto on the whole patch series, including the cover letter.
- Eric
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 05/17] zinc: ChaCha20 x86_64 implementation
Quoted 1 line · Eric Biggers
Please Cc linux-crypto on the whole patch series, including the cover letter.
Ack.
Jason A. Donenfeld
maintainerPATCH v3 6/17 zinc: ChaCha20 MIPS32r2 implementation
In reply to Jason A. DonenfeldThis MIPS32r2 implementation comes from René van Dorst and me and results in a nice speedup on the usual OpenWRT targets.
--- lib/zinc/Makefile | 4 + lib/zinc/chacha20/chacha20-mips-glue.h | 28 ++ lib/zinc/chacha20/chacha20-mips.S | 474 +++++++++++++++++++++++++ 3 files changed, 506 insertions(+) create mode 100644 lib/zinc/chacha20/chacha20-mips-glue.h create mode 100644 lib/zinc/chacha20/chacha20-mips.S
lib/zinc/Makefile +4 -0
@@ -17,6 +17,10 @@ ifeq ($(CONFIG_ARM64),y) zinc-y += chacha20/chacha20-arm64.o CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-arm-glue.h endif +ifeq ($(CONFIG_MIPS)$(CONFIG_CPU_MIPS32_R2),yy) +zinc-y += chacha20/chacha20-mips.o +CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-mips-glue.h +endif endif zinc-y += main.o
lib/zinc/chacha20/chacha20-mips-glue.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#include <zinc/chacha20.h> + +asmlinkage void chacha20_mips(u8 *out, const u8 *in, const size_t len, +const u32 key[8 ],const u32 counter[4 ]); +void __init chacha20_fpu_init (void ) +{ +} + +static inline bool chacha20_arch (u8 *dst,const u8 *src,const size_t len, +const u32 key[8 ],const u32 counter[4 ], +simd_context_t simd_context) +{ +chacha20_mips (dst, src, len, key, counter); +return true; +} + +static inline bool hchacha20_arch (u8 *derived_key,const u8 *nonce, +const u8 *key,simd_context_t simd_context) +{ +return false; +} + +#define HAVE_CHACHA20_ARCH_IMPLEMENTATION
lib/zinc/chacha20/chacha20-mips.S new file +474 -0
474 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 7/17 zinc: Poly1305 generic C implementation and selftest
In reply to Jason A. DonenfeldThe C implementation is based on Andy Polyakov's implementation, heavily modified by Samuel Neves.
Information: https://cr.yp.to/mac.html
--- include/zinc/poly1305.h | 38 + lib/zinc/Kconfig | 4 + lib/zinc/Makefile | 4 + lib/zinc/main.c | 5 + lib/zinc/poly1305/poly1305.c | 291 +++++++ lib/zinc/selftest/poly1305.h | 1572 ++++++++++++++++++++++++++++++++++ 6 files changed, 1914 insertions(+) create mode 100644 include/zinc/poly1305.h create mode 100644 lib/zinc/poly1305/poly1305.c create mode 100644 lib/zinc/selftest/poly1305.h
include/zinc/poly1305.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _ZINC_POLY1305_H +#define _ZINC_POLY1305_H + +#include <linux/simd.h> +#include <linux/types.h> + +enum poly1305_lengths { +POLY1305_BLOCK_SIZE =16 , +POLY1305_KEY_SIZE =32 , +POLY1305_MAC_SIZE =16 +}; + +struct poly1305_ctx { +u8 opaque[24 *sizeof (u64)]; +u32 nonce[4 ]; +u8 data[POLY1305_BLOCK_SIZE ]; +size_t num; +}__aligned(8) ; + +void poly1305_fpu_init (void ); + +void poly1305_init (struct poly1305_ctx *ctx,const u8 key[POLY1305_KEY_SIZE ], +simd_context_t simd_context); +void poly1305_update (struct poly1305_ctx *ctx,const u8 *inp,const size_t len, +simd_context_t simd_context); +void poly1305_finish (struct poly1305_ctx *ctx,u8 mac[POLY1305_MAC_SIZE ], +simd_context_t simd_context); + +#ifdef DEBUG +bool poly1305_selftest (void ); +#endif + +#endif /* _ZINC_POLY1305_H */
lib/zinc/Kconfig +4 -0
@@ -10,6 +10,10 @@ config ZINC_CHACHA20 bool select ZINC +config ZINC_POLY1305 + bool + select ZINC + config ZINC_DEBUG bool "Zinc cryptography library debugging and self-tests" depends on ZINC
lib/zinc/Makefile +4 -0
@@ -23,6 +23,10 @@ CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-mips-glue.h endif endif +ifeq ($(CONFIG_ZINC_POLY1305),y) +zinc-y += poly1305/poly1305.o +endif + zinc-y += main.o obj-$(CONFIG_ZINC) := zinc.o
lib/zinc/main.c +5 -0
@@ -4,6 +4,7 @@*/ #include <zinc/chacha20.h> +#include <zinc/poly1305.h> #include <linux/init.h> #include <linux/module.h>
@@ -21,6 +22,10 @@ static int __init mod_init(void) {#ifdef CONFIG_ZINC_CHACHA20 chacha20_fpu_init (); +#endif +#ifdef CONFIG_ZINC_POLY1305 +poly1305_fpu_init (); +selftest (poly1305);#endif return 0 ; }
lib/zinc/poly1305/poly1305.c new file +291 -0
291 lines not on this page · raw message
lib/zinc/selftest/poly1305.h new file +1572 -0
1,572 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 07/17] zinc: Poly1305 generic C implementation and selftest
Sorry, this 07/17 is old cruft that was erroneously sitting around in my v3 directory. Please look only at the real 07/17 instead:
https://patchwork.ozlabs.org/patch/968359/
My scripts have been adjusted so that this kind of clash doesn't happen again.
Jason A. Donenfeld
maintainerPATCH v3 7/17 zinc: Poly1305 generic C implementations and selftest
In reply to Jason A. DonenfeldThese two C implementations -- a 32x32 one and a 64x64 one, depending on the platform -- come from Andrew Moon's public domain poly1305-donna portable code, modified for usage in the kernel and for usage with accelerated primitives.
Information: https://cr.yp.to/mac.html
--- include/zinc/poly1305.h | 38 ++ lib/zinc/Kconfig | 4 + lib/zinc/Makefile | 4 + lib/zinc/main.c | 5 + lib/zinc/poly1305/poly1305-donna32.h | 198 ++++++ lib/zinc/poly1305/poly1305-donna64.h | 177 ++++++ lib/zinc/poly1305/poly1305.c | 131 ++++ lib/zinc/selftest/poly1305.h | 874 +++++++++++++++++++++++++++ 8 files changed, 1431 insertions(+) create mode 100644 include/zinc/poly1305.h create mode 100644 lib/zinc/poly1305/poly1305-donna32.h create mode 100644 lib/zinc/poly1305/poly1305-donna64.h create mode 100644 lib/zinc/poly1305/poly1305.c create mode 100644 lib/zinc/selftest/poly1305.h
include/zinc/poly1305.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _ZINC_POLY1305_H +#define _ZINC_POLY1305_H + +#include <linux/simd.h> +#include <linux/types.h> + +enum poly1305_lengths { +POLY1305_BLOCK_SIZE =16 , +POLY1305_KEY_SIZE =32 , +POLY1305_MAC_SIZE =16 +}; + +struct poly1305_ctx { +u8 opaque[24 *sizeof (u64)]; +u32 nonce[4 ]; +u8 data[POLY1305_BLOCK_SIZE ]; +size_t num; +}__aligned(8) ; + +void poly1305_fpu_init (void ); + +void poly1305_init (struct poly1305_ctx *ctx,const u8 key[POLY1305_KEY_SIZE ], +simd_context_t simd_context); +void poly1305_update (struct poly1305_ctx *ctx,const u8 *inp,const size_t len, +simd_context_t simd_context); +void poly1305_finish (struct poly1305_ctx *ctx,u8 mac[POLY1305_MAC_SIZE ], +simd_context_t simd_context); + +#ifdef DEBUG +bool poly1305_selftest (void ); +#endif + +#endif /* _ZINC_POLY1305_H */
lib/zinc/Kconfig +4 -0
@@ -10,6 +10,10 @@ config ZINC_CHACHA20 bool select ZINC +config ZINC_POLY1305 + bool + select ZINC + config ZINC_DEBUG bool "Zinc cryptography library debugging and self-tests" depends on ZINC
lib/zinc/Makefile +4 -0
@@ -23,6 +23,10 @@ CFLAGS_chacha20.o += -include $(srctree)/$(src)/chacha20/chacha20-mips-glue.h endif endif +ifeq ($(CONFIG_ZINC_POLY1305),y) +zinc-y += poly1305/poly1305.o +endif + zinc-y += main.o obj-$(CONFIG_ZINC) := zinc.o
lib/zinc/main.c +5 -0
@@ -4,6 +4,7 @@*/ #include <zinc/chacha20.h> +#include <zinc/poly1305.h> #include <linux/init.h> #include <linux/module.h>
@@ -21,6 +22,10 @@ static int __init mod_init(void) {#ifdef CONFIG_ZINC_CHACHA20 chacha20_fpu_init (); +#endif +#ifdef CONFIG_ZINC_POLY1305 +poly1305_fpu_init (); +selftest (poly1305);#endif return 0 ; }
lib/zinc/poly1305/poly1305-donna32.h new file +198 -0
198 lines not on this page · raw message
lib/zinc/poly1305/poly1305-donna64.h new file +177 -0
177 lines not on this page · raw message
lib/zinc/poly1305/poly1305.c new file +131 -0
131 lines not on this page · raw message
lib/zinc/selftest/poly1305.h new file +874 -0
874 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 8/17 zinc: Poly1305 ARM and ARM64 implementations
In reply to Jason A. DonenfeldThese NEON and non-NEON implementations come from Andy Polyakov's implementation, with several modifications for being friendly to kernel space.
--- lib/zinc/Makefile | 8 + lib/zinc/poly1305/poly1305-arm-glue.h | 69 ++ lib/zinc/poly1305/poly1305-arm.S | 1117 +++++++++++++++++++++++++ lib/zinc/poly1305/poly1305-arm64.S | 822 ++++++++++++++++++ 4 files changed, 2016 insertions(+) create mode 100644 lib/zinc/poly1305/poly1305-arm-glue.h create mode 100644 lib/zinc/poly1305/poly1305-arm.S create mode 100644 lib/zinc/poly1305/poly1305-arm64.S
lib/zinc/Makefile +8 -0
@@ -25,6 +25,14 @@ endif ifeq ($(CONFIG_ZINC_POLY1305),y) zinc-y += poly1305/poly1305.o +ifeq ($(CONFIG_ARM),y) +zinc-y += poly1305/poly1305-arm.o +CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-arm-glue.h +endif +ifeq ($(CONFIG_ARM64),y) +zinc-y += poly1305/poly1305-arm64.o +CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-arm-glue.h +endif endif zinc-y += main.o
lib/zinc/poly1305/poly1305-arm-glue.h new file +69 -0
69 lines not on this page · raw message
lib/zinc/poly1305/poly1305-arm.S new file +1117 -0
1,117 lines not on this page · raw message
lib/zinc/poly1305/poly1305-arm64.S new file +822 -0
822 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 9/17 zinc: Poly1305 x86_64 implementation
In reply to Jason A. DonenfeldThis provides AVX, AVX-2, and AVX-512F implementations for Poly1305. The AVX-512F implementation is disabled on Skylake, due to throttling. These come from Andy Polyakov's implementation, with some heavy modifications from Samuel Neves and me.
--- lib/zinc/Makefile | 4 + lib/zinc/poly1305/poly1305-x86_64-glue.h | 109 + lib/zinc/poly1305/poly1305-x86_64.S | 2792 ++++++++++++++++++++++ 3 files changed, 2905 insertions(+) create mode 100644 lib/zinc/poly1305/poly1305-x86_64-glue.h create mode 100644 lib/zinc/poly1305/poly1305-x86_64.S
lib/zinc/Makefile +4 -0
@@ -25,6 +25,10 @@ endif ifeq ($(CONFIG_ZINC_POLY1305),y) zinc-y += poly1305/poly1305.o +ifeq ($(CONFIG_X86_64)$(CONFIG_UML),y) +zinc-y += poly1305/poly1305-x86_64.o +CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-x86_64-glue.h +endif ifeq ($(CONFIG_ARM),y) zinc-y += poly1305/poly1305-arm.o CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-arm-glue.h
lib/zinc/poly1305/poly1305-x86_64-glue.h new file +109 -0
109 lines not on this page · raw message
lib/zinc/poly1305/poly1305-x86_64.S new file +2792 -0
2,792 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 10/17 zinc: Poly1305 MIPS32r2 and MIPS64 implementations
In reply to Jason A. DonenfeldThis MIPS32r2 implementation comes from René van Dorst and me and results in a nice speedup on the usual OpenWRT targets. The MIPS64 implementation comes from Andy Polyakov with some kernel-friendly modifications from me and results in a nice speedup on commodity Octeon hardware.
--- lib/zinc/Makefile | 8 + lib/zinc/poly1305/poly1305-mips-glue.h | 40 +++ lib/zinc/poly1305/poly1305-mips.S | 417 +++++++++++++++++++++++++ lib/zinc/poly1305/poly1305-mips64.S | 359 +++++++++++++++++++++ 4 files changed, 824 insertions(+) create mode 100644 lib/zinc/poly1305/poly1305-mips-glue.h create mode 100644 lib/zinc/poly1305/poly1305-mips.S create mode 100644 lib/zinc/poly1305/poly1305-mips64.S
lib/zinc/Makefile +8 -0
@@ -37,6 +37,14 @@ ifeq ($(CONFIG_ARM64),y) zinc-y += poly1305/poly1305-arm64.o CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-arm-glue.h endif +ifeq ($(CONFIG_MIPS)$(CONFIG_CPU_MIPS32_R2),yy) +zinc-y += poly1305/poly1305-mips.o +CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-mips-glue.h +endif +ifeq ($(CONFIG_MIPS)$(CONFIG_64BIT),yy) +zinc-y += poly1305/poly1305-mips64.o +CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-mips-glue.h +endif endif zinc-y += main.o
lib/zinc/poly1305/poly1305-mips-glue.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#include <zinc/poly1305.h> + +asmlinkage void poly1305_init_mips(void *ctx, const u8 key[16]); +asmlinkage void poly1305_blocks_mips(void *ctx, const u8 *inp, const size_t len, +const u32 padbit); +asmlinkage void poly1305_emit_mips(void *ctx, u8 mac[16], const u32 nonce[4]); +void __init poly1305_fpu_init (void ) +{ +} + +static inline bool poly1305_init_arch (void *ctx, +const u8 key[POLY1305_KEY_SIZE ], +simd_context_t simd_context) +{ +poly1305_init_mips (ctx, key); +return true; +} + +static inline bool poly1305_blocks_arch (void *ctx,const u8 *inp, +const size_t len,const u32 padbit, +simd_context_t simd_context) +{ +poly1305_blocks_mips (ctx, inp, len, padbit); +return true; +} + +static inline bool poly1305_emit_arch (void *ctx,u8 mac[POLY1305_MAC_SIZE ], +const u32 nonce[4 ], +simd_context_t simd_context) +{ +poly1305_emit_mips (ctx, mac, nonce); +return true; +} + +#define HAVE_POLY1305_ARCH_IMPLEMENTATION
lib/zinc/poly1305/poly1305-mips.S new file +417 -0
417 lines not on this page · raw message
lib/zinc/poly1305/poly1305-mips64.S new file +359 -0
359 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 11/17 zinc: ChaCha20Poly1305 construction and selftest
In reply to Jason A. DonenfeldThis is an implementation of the ChaCha20Poly1305 AEAD, with an easy API for encrypting either contiguous buffers or scatter gather lists (such as those created from skb_to_sgvec).
Information: https://tools.ietf.org/html/rfc8439
--- include/zinc/chacha20poly1305.h | 54 + lib/zinc/Kconfig | 6 + lib/zinc/Makefile | 4 + lib/zinc/chacha20poly1305.c | 333 ++ lib/zinc/main.c | 4 + lib/zinc/selftest/chacha20poly1305.h | 7848 ++++++++++++++++++++++++++ 6 files changed, 8249 insertions(+) create mode 100644 include/zinc/chacha20poly1305.h create mode 100644 lib/zinc/chacha20poly1305.c create mode 100644 lib/zinc/selftest/chacha20poly1305.h
include/zinc/chacha20poly1305.h new file +54 -0
@@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _ZINC_CHACHA20POLY1305_H +#define _ZINC_CHACHA20POLY1305_H + +#include <linux/simd.h> +#include <linux/types.h> + +struct scatterlist ; + +enum chacha20poly1305_lengths { +XCHACHA20POLY1305_NONCELEN =24 , +CHACHA20POLY1305_KEYLEN =32 , +CHACHA20POLY1305_AUTHTAGLEN =16 +}; + +void chacha20poly1305_encrypt (u8 *dst,const u8 *src,const size_t src_len, +const u8 *ad,const size_t ad_len, +const u64 nonce, +const u8 key[CHACHA20POLY1305_KEYLEN ]); + +bool __must_check chacha20poly1305_encrypt_sg ( +struct scatterlist *dst,struct scatterlist *src,const size_t src_len, +const u8 *ad,const size_t ad_len,const u64 nonce, +const u8 key[CHACHA20POLY1305_KEYLEN ],simd_context_t simd_context); + +bool __must_check +chacha20poly1305_decrypt (u8 *dst,const u8 *src,const size_t src_len, +const u8 *ad,const size_t ad_len,const u64 nonce, +const u8 key[CHACHA20POLY1305_KEYLEN ]); + +bool __must_check chacha20poly1305_decrypt_sg ( +struct scatterlist *dst,struct scatterlist *src,const size_t src_len, +const u8 *ad,const size_t ad_len,const u64 nonce, +const u8 key[CHACHA20POLY1305_KEYLEN ],simd_context_t simd_context); + +void xchacha20poly1305_encrypt (u8 *dst,const u8 *src,const size_t src_len, +const u8 *ad,const size_t ad_len, +const u8 nonce[XCHACHA20POLY1305_NONCELEN ], +const u8 key[CHACHA20POLY1305_KEYLEN ]); + +bool __must_check xchacha20poly1305_decrypt ( +u8 *dst,const u8 *src,const size_t src_len,const u8 *ad, +const size_t ad_len,const u8 nonce[XCHACHA20POLY1305_NONCELEN ], +const u8 key[CHACHA20POLY1305_KEYLEN ]); + +#ifdef DEBUG +bool chacha20poly1305_selftest (void ); +#endif + +#endif /* _ZINC_CHACHA20POLY1305_H */
lib/zinc/Kconfig +6 -0
@@ -14,6 +14,12 @@ config ZINC_POLY1305 bool select ZINC +config ZINC_CHACHA20POLY1305 + bool + select ZINC + select ZINC_CHACHA20 + select ZINC_POLY1305 + config ZINC_DEBUG bool "Zinc cryptography library debugging and self-tests" depends on ZINC
lib/zinc/Makefile +4 -0
@@ -47,6 +47,10 @@ CFLAGS_poly1305.o += -include $(srctree)/$(src)/poly1305/poly1305-mips-glue.h endif endif +ifeq ($(CONFIG_ZINC_CHACHA20POLY1305),y) +zinc-y += chacha20poly1305.o +endif + zinc-y += main.o obj-$(CONFIG_ZINC) := zinc.o
lib/zinc/chacha20poly1305.c new file +333 -0
333 lines not on this page · raw message
lib/zinc/main.c +4 -0
@@ -3,6 +3,7 @@* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. */ +#include <zinc/chacha20poly1305.h> #include <zinc/chacha20.h> #include <zinc/poly1305.h>
@@ -26,6 +27,9 @@ static int __init mod_init(void)#ifdef CONFIG_ZINC_POLY1305 poly1305_fpu_init ();selftest (poly1305); +#endif +#ifdef CONFIG_ZINC_CHACHA20POLY1305 +selftest (chacha20poly1305);#endif return 0 ; }
lib/zinc/selftest/chacha20poly1305.h new file +7848 -0
2,575 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.18.0
Part of the diff is not shown here. View the raw message.
Jason A. Donenfeld
maintainerPATCH v3 12/17 zinc: BLAKE2s generic C implementation and selftest
In reply to Jason A. DonenfeldThe C implementation was originally based on Samuel Neves' public domain reference implementation but has since been heavily modified for the kernel. We're able to do compile-time optimizations by moving some scaffolding around the final function into the header file.
Information: https://blake2.net/
--- include/zinc/blake2s.h | 101 ++ lib/zinc/Kconfig | 4 + lib/zinc/Makefile | 4 + lib/zinc/blake2s/blake2s.c | 274 +++++ lib/zinc/main.c | 5 + lib/zinc/selftest/blake2s.h | 2095 +++++++++++++++++++++++++++++++++++ 6 files changed, 2483 insertions(+) create mode 100644 include/zinc/blake2s.h create mode 100644 lib/zinc/blake2s/blake2s.c create mode 100644 lib/zinc/selftest/blake2s.h
include/zinc/blake2s.h new file +101 -0
@@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _ZINC_BLAKE2S_H +#define _ZINC_BLAKE2S_H + +#include <linux/types.h> +#include <linux/kernel.h> +#include <crypto/algapi.h> + +enum blake2s_lengths { +BLAKE2S_BLOCKBYTES =64 , +BLAKE2S_OUTBYTES =32 , +BLAKE2S_KEYBYTES =32 +}; + +struct blake2s_state { +u32 h[8 ]; +u32 t[2 ]; +u32 f[2 ]; +u8 buf[BLAKE2S_BLOCKBYTES ]; +size_t buflen; +u8 last_node; +}; + +void blake2s_init (struct blake2s_state *state,const size_t outlen); +void blake2s_init_key (struct blake2s_state *state,const size_t outlen, +const void *key,const size_t keylen); +void blake2s_update (struct blake2s_state *state,const u8 *in,size_t inlen); +void __blake2s_final (struct blake2s_state *state); +static inline void blake2s_final (struct blake2s_state *state,u8 *out, +const size_t outlen) +{ +int i; + +#ifdef DEBUG +BUG_ON (!out || !outlen || outlen >BLAKE2S_OUTBYTES ); +#endif +__blake2s_final (state); + +if (__builtin_constant_p (outlen) && !(outlen %sizeof (u32))) { +if (IS_ENABLED (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) || +IS_ALIGNED ((unsigned long )out, __alignof__(u32 ))) { +__le32 *outwords = (__le32 *)out; + +for (i =0 ; i < outlen /sizeof (u32); ++i) + outwords[i] =cpu_to_le32 (state->h[i]); + }else { +__le32 buffer[BLAKE2S_OUTBYTES ]; + +for (i =0 ; i < outlen /sizeof (u32); ++i) + buffer[i] =cpu_to_le32 (state->h[i]); +memcpy (out, buffer, outlen); +memzero_explicit (buffer,sizeof (buffer)); + } + }else { +u8 buffer[BLAKE2S_OUTBYTES ]__aligned(__alignof__(u32)) ; +__le32 *outwords = (__le32 *)buffer; + +for (i =0 ; i <8 ; ++i) + outwords[i] =cpu_to_le32 (state->h[i]); +memcpy (out, buffer, outlen); +memzero_explicit (buffer,sizeof (buffer)); + } + +memzero_explicit (state,sizeof (*state)); +} + +static inline void blake2s (u8 *out,const u8 *in,const u8 *key, +const size_t outlen,const size_t inlen, +const size_t keylen) +{ +struct blake2s_state state; + +#ifdef DEBUG +BUG_ON ((!in && inlen >0 ) || !out || !outlen || + outlen >BLAKE2S_OUTBYTES || keylen >BLAKE2S_KEYBYTES || + (!key && keylen)); +#endif + +if (keylen) +blake2s_init_key (&state, outlen, key, keylen); +else +blake2s_init (&state, outlen); + +blake2s_update (&state, in, inlen); +blake2s_final (&state, out, outlen); +} + +void blake2s_hmac (u8 *out,const u8 *in,const u8 *key,const size_t outlen, +const size_t inlen,const size_t keylen); + +void blake2s_fpu_init (void ); + +#ifdef DEBUG +bool blake2s_selftest (void ); +#endif + +#endif /* _ZINC_BLAKE2S_H */
lib/zinc/Kconfig +4 -0
@@ -20,6 +20,10 @@ config ZINC_CHACHA20POLY1305 select ZINC_CHACHA20 select ZINC_POLY1305 +config ZINC_BLAKE2S + bool + select ZINC + config ZINC_DEBUG bool "Zinc cryptography library debugging and self-tests" depends on ZINC
lib/zinc/Makefile +4 -0
@@ -51,6 +51,10 @@ ifeq ($(CONFIG_ZINC_CHACHA20POLY1305),y) zinc-y += chacha20poly1305.o endif +ifeq ($(CONFIG_ZINC_BLAKE2S),y) +zinc-y += blake2s/blake2s.o +endif + zinc-y += main.o obj-$(CONFIG_ZINC) := zinc.o
lib/zinc/blake2s/blake2s.c new file +274 -0
274 lines not on this page · raw message
lib/zinc/main.c +5 -0
@@ -6,6 +6,7 @@#include <zinc/chacha20poly1305.h> #include <zinc/chacha20.h> #include <zinc/poly1305.h> +#include <zinc/blake2s.h> #include <linux/init.h> #include <linux/module.h>
@@ -30,6 +31,10 @@ static int __init mod_init(void)#endif #ifdef CONFIG_ZINC_CHACHA20POLY1305 selftest (chacha20poly1305); +#endif +#ifdef CONFIG_ZINC_BLAKE2S +blake2s_fpu_init (); +selftest (blake2s);#endif return 0 ; }
lib/zinc/selftest/blake2s.h new file +2095 -0
2,095 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 13/17 zinc: BLAKE2s x86_64 implementation
In reply to Jason A. DonenfeldThese implementations from Samuel Neves support AVX and AVX-512VL. Originally this used AVX-512F, but Skylake thermal throttling made AVX-512VL more attractive and possible to do with negligable difference.
--- lib/zinc/Makefile | 4 + lib/zinc/blake2s/blake2s-x86_64-glue.h | 62 +++ lib/zinc/blake2s/blake2s-x86_64.S | 685 +++++++++++++++++++++++++ 3 files changed, 751 insertions(+) create mode 100644 lib/zinc/blake2s/blake2s-x86_64-glue.h create mode 100644 lib/zinc/blake2s/blake2s-x86_64.S
lib/zinc/Makefile +4 -0
@@ -53,6 +53,10 @@ endif ifeq ($(CONFIG_ZINC_BLAKE2S),y) zinc-y += blake2s/blake2s.o +ifeq ($(CONFIG_X86_64)$(CONFIG_UML),y) +zinc-y += blake2s/blake2s-x86_64.o +CFLAGS_blake2s.o += -include $(srctree)/$(src)/blake2s/blake2s-x86_64-glue.h +endif endif zinc-y += main.o
lib/zinc/blake2s/blake2s-x86_64-glue.h new file +62 -0
62 lines not on this page · raw message
lib/zinc/blake2s/blake2s-x86_64.S new file +685 -0
685 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 14/17 zinc: Curve25519 generic C implementations and selftest
In reply to Jason A. DonenfeldThis contains two formally verified C implementations of the Curve25519 scalar multiplication function, one for 32-bit systems, and one for 64-bit systems whose compiler supports efficient 128-bit integer types. Not only are these implementations formally verified, but they are also the fastest available C implementations. They have been modified to be friendly to kernel space and to be generally less horrendous looking, but still an effort has been made to retain their formally verified characteristic, and so the C might look slightly unidiomatic.
The 64-bit version comes from HACL*: https://github.com/project-everest/hacl-star
The 32-bit version comes from Fiat: https://github.com/mit-plv/fiat-crypto
Information: https://cr.yp.to/ecdh.html
--- include/zinc/curve25519.h | 28 + lib/zinc/Kconfig | 4 + lib/zinc/Makefile | 4 + lib/zinc/curve25519/curve25519-fiat32.h | 862 +++++++++++++++ lib/zinc/curve25519/curve25519-hacl64.h | 785 ++++++++++++++ lib/zinc/curve25519/curve25519.c | 83 ++ lib/zinc/main.c | 5 + lib/zinc/selftest/curve25519.h | 1321 +++++++++++++++++++++++ 8 files changed, 3092 insertions(+) create mode 100644 include/zinc/curve25519.h create mode 100644 lib/zinc/curve25519/curve25519-fiat32.h create mode 100644 lib/zinc/curve25519/curve25519-hacl64.h create mode 100644 lib/zinc/curve25519/curve25519.c create mode 100644 lib/zinc/selftest/curve25519.h
include/zinc/curve25519.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _ZINC_CURVE25519_H +#define _ZINC_CURVE25519_H + +#include <linux/types.h> + +enum curve25519_lengths { +CURVE25519_POINT_SIZE =32 +}; + +bool __must_check curve25519 (u8 mypublic[CURVE25519_POINT_SIZE ], +const u8 secret[CURVE25519_POINT_SIZE ], +const u8 basepoint[CURVE25519_POINT_SIZE ]); +void curve25519_generate_secret (u8 secret[CURVE25519_POINT_SIZE ]); +bool __must_check curve25519_generate_public ( +u8 pub[CURVE25519_POINT_SIZE ],const u8 secret[CURVE25519_POINT_SIZE ]); + +void curve25519_fpu_init (void ); + +#ifdef DEBUG +bool curve25519_selftest (void ); +#endif + +#endif /* _ZINC_CURVE25519_H */
lib/zinc/Kconfig +4 -0
@@ -24,6 +24,10 @@ config ZINC_BLAKE2S bool select ZINC +config ZINC_CURVE25519 + bool + select ZINC + config ZINC_DEBUG bool "Zinc cryptography library debugging and self-tests" depends on ZINC
lib/zinc/Makefile +4 -0
@@ -51,6 +51,10 @@ ifeq ($(CONFIG_ZINC_CHACHA20POLY1305),y) zinc-y += chacha20poly1305.o endif +ifeq ($(CONFIG_ZINC_CURVE25519),y) +zinc-y += curve25519/curve25519.o +endif + ifeq ($(CONFIG_ZINC_BLAKE2S),y) zinc-y += blake2s/blake2s.o ifeq ($(CONFIG_X86_64)$(CONFIG_UML),y)
lib/zinc/curve25519/curve25519-fiat32.h new file +862 -0
862 lines not on this page · raw message
lib/zinc/curve25519/curve25519-hacl64.h new file +785 -0
785 lines not on this page · raw message
lib/zinc/curve25519/curve25519.c new file +83 -0
83 lines not on this page · raw message
lib/zinc/main.c +5 -0
@@ -7,6 +7,7 @@#include <zinc/chacha20.h> #include <zinc/poly1305.h> #include <zinc/blake2s.h> +#include <zinc/curve25519.h> #include <linux/init.h> #include <linux/module.h>
@@ -35,6 +36,10 @@ static int __init mod_init(void)#ifdef CONFIG_ZINC_BLAKE2S blake2s_fpu_init ();selftest (blake2s); +#endif +#ifdef CONFIG_ZINC_CURVE25519 +curve25519_fpu_init (); +selftest (curve25519);#endif return 0 ; }
lib/zinc/selftest/curve25519.h new file +1321 -0
1,205 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.18.0
Part of the diff is not shown here. View the raw message.
Jason A. Donenfeld
maintainerPATCH v3 15/17 zinc: Curve25519 ARM implementation
In reply to Jason A. DonenfeldThis comes from Dan Bernstein and Peter Schwabe's public domain NEON code, and has been modified to be friendly for kernel space, as well as removing some qhasm strangeness to be more idiomatic.
--- lib/zinc/Makefile | 4 + lib/zinc/curve25519/curve25519-arm-glue.h | 46 + lib/zinc/curve25519/curve25519-arm.S | 2095 +++++++++++++++++++++ 3 files changed, 2145 insertions(+) create mode 100644 lib/zinc/curve25519/curve25519-arm-glue.h create mode 100644 lib/zinc/curve25519/curve25519-arm.S
lib/zinc/Makefile +4 -0
@@ -53,6 +53,10 @@ endif ifeq ($(CONFIG_ZINC_CURVE25519),y) zinc-y += curve25519/curve25519.o +ifeq ($(CONFIG_ARM)$(CONFIG_KERNEL_MODE_NEON),yy) +zinc-y += curve25519/curve25519-arm.o +CFLAGS_curve25519.o += -include $(srctree)/$(src)/curve25519/curve25519-arm-glue.h +endif endif ifeq ($(CONFIG_ZINC_BLAKE2S),y)
lib/zinc/curve25519/curve25519-arm-glue.h new file +46 -0
46 lines not on this page · raw message
lib/zinc/curve25519/curve25519-arm.S new file +2095 -0
2,095 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 16/17 zinc: Curve25519 x86_64 implementation
In reply to Jason A. DonenfeldThis implementation is the fastest available x86_64 implementation, and unlike Sandy2x, it doesn't requie use of the floating point registers at all. Instead it makes use of BMI2 and ADX, available on recent microarchitectures. The implementation was written by Armando Faz-Hernández with contributions (upstream) from Samuel Neves and me, in addition to further changes in the kernel implementation from us.
--- lib/zinc/Makefile | 3 + lib/zinc/curve25519/curve25519-x86_64-glue.h | 50 + lib/zinc/curve25519/curve25519-x86_64.h | 2333 ++++++++++++++++++ 3 files changed, 2386 insertions(+) create mode 100644 lib/zinc/curve25519/curve25519-x86_64-glue.h create mode 100644 lib/zinc/curve25519/curve25519-x86_64.h
lib/zinc/Makefile +3 -0
@@ -57,6 +57,9 @@ ifeq ($(CONFIG_ARM)$(CONFIG_KERNEL_MODE_NEON),yy) zinc-y += curve25519/curve25519-arm.o CFLAGS_curve25519.o += -include $(srctree)/$(src)/curve25519/curve25519-arm-glue.h endif +ifeq ($(CONFIG_X86_64)$(CONFIG_UML),y) +CFLAGS_curve25519.o += -include $(srctree)/$(src)/curve25519/curve25519-x86_64-glue.h +endif endif ifeq ($(CONFIG_ZINC_BLAKE2S),y)
lib/zinc/curve25519/curve25519-x86_64-glue.h new file +50 -0
50 lines not on this page · raw message
lib/zinc/curve25519/curve25519-x86_64.h new file +2333 -0
2,333 lines not on this page · raw message
Signature · 1 line
2.18.0
Jason A. Donenfeld
maintainerPATCH v3 17/17 net: WireGuard secure network tunnel
In reply to Jason A. DonenfeldWireGuard is a layer 3 secure networking tunnel made specifically for the kernel, that aims to be much simpler and easier to audit than IPsec. Extensive documentation and description of the protocol and considerations, along with formal proofs of the cryptography, are available at:
* https://www.wireguard.com/
* https://www.wireguard.com/papers/wireguard.pdf
This commit implements WireGuard as a simple network device driver, accessible in the usual RTNL way used by virtual network drivers. It makes use of the udp_tunnel APIs, GRO, GSO, NAPI, and the usual set of networking subsystem APIs. It has a somewhat novel multicore queueing system designed for maximum throughput and minimal latency of encryption operations, but it is implemented modestly using workqueues and NAPI. Configuration is done via generic Netlink, and following a review from the Netlink maintainer a year ago, several high profile userspace have already implemented the API.
This commit also comes with several different tests, both in-kernel tests and out-of-kernel tests based on network namespaces, taking profit of the fact that sockets used by WireGuard intentionally stay in the namespace the WireGuard interface was originally created, exactly like the semantics of userspace tun devices. See wireguard.com/netns/ for pictures and examples.
The source code is fairly short, but rather than combining everything into a single file, WireGuard is developed as cleanly separable files, making auditing and comprehension easier. Things are laid out as follows:
* noise.[ch], cookie.[ch], messages.h: These implement the bulk of the cryptographic aspects of the protocol, and are mostly data-only in nature, taking in buffers of bytes and spitting out buffers of bytes. They also handle reference counting for their various shared pieces of data, like keys and key lists.
* ratelimiter.[ch]: Used as an integral part of cookie.[ch] for ratelimiting certain types of cryptographic operations in accordance with particular WireGuard semantics.
* allowedips.[ch], hashtables.[ch]: The main lookup structures of WireGuard, the former being trie-like with particular semantics, an integral part of the design of the protocol, and the latter just being nice helper functions around the specific hashtables we use.
* device.[ch]: Implementation of functions for the netdevice and for rtnl, responsible for maintaining the life of a given interface and wiring it up to the rest of WireGuard.
* peer.[ch]: Each interface has a list of peers, with helper functions available here for creation, destruction, and reference counting.
* socket.[ch]: Implementation of functions related to udp_socket and the general set of kernel socket APIs, for sending and receiving ciphertext UDP packets, and taking care of WireGuard-specific sticky socket routing semantics for the automatic roaming.
* netlink.[ch]: Userspace API entry point for configuring WireGuard peers and devices. The API has been implemented by several userspace tools and network management utility, and the WireGuard project distributes the basic wg(8) tool.
* queueing.[ch]: Shared function on the rx and tx path for handling the various queues used in the multicore algorithms.
* send.c: Handles encrypting outgoing packets in parallel on multiple cores, before sending them in order on a single core, via workqueues and ring buffers. Also handles sending handshake and cookie messages as part of the protocol, in parallel.
* receive.c: Handles decrypting incoming packets in parallel on multiple cores, before passing them off in order to be ingested via the rest of the networking subsystem with GRO via the typical NAPI poll function. Also handles receiving handshake and cookie messages as part of the protocol, in parallel.
* timers.[ch]: Uses the timer wheel to implement protocol particular event timeouts, and gives a set of very simple event-driven entry point functions for callers.
* main.c, version.h: Initialization and deinitialization of the module.
* selftest/*.h: Runtime unit tests for some of the most security sensitive functions.
* tools/testing/selftests/wireguard/netns.sh: Aforementioned testing script using network namespaces.
This commit aims to be as self-contained as possible, implementing WireGuard as a standalone module not needing much special handling or coordination from the network subsystem. I expect for future optimizations to the network stack to positively improve WireGuard, and vice-versa, but for the time being, this exists as intentionally standalone.
We introduce a menu option for CONFIG_WIREGUARD, as well as providing a verbose debug log and self-tests via CONFIG_WIREGUARD_DEBUG.
--- MAINTAINERS | 8 + drivers/net/Kconfig | 30 + drivers/net/Makefile | 1 + drivers/net/wireguard/Makefile | 18 + drivers/net/wireguard/allowedips.c | 404 ++++++++++ drivers/net/wireguard/allowedips.h | 55 ++ drivers/net/wireguard/cookie.c | 234 ++++++ drivers/net/wireguard/cookie.h | 59 ++ drivers/net/wireguard/device.c | 438 +++++++++++ drivers/net/wireguard/device.h | 65 ++ drivers/net/wireguard/hashtables.c | 209 +++++ drivers/net/wireguard/hashtables.h | 63 ++ drivers/net/wireguard/main.c | 65 ++ drivers/net/wireguard/messages.h | 128 +++ drivers/net/wireguard/netlink.c | 605 ++++++++++++++ drivers/net/wireguard/netlink.h | 12 + drivers/net/wireguard/noise.c | 784 +++++++++++++++++++ drivers/net/wireguard/noise.h | 129 +++ drivers/net/wireguard/peer.c | 191 +++++ drivers/net/wireguard/peer.h | 87 ++ drivers/net/wireguard/queueing.c | 52 ++ drivers/net/wireguard/queueing.h | 193 +++++ drivers/net/wireguard/ratelimiter.c | 220 ++++++ drivers/net/wireguard/ratelimiter.h | 19 + drivers/net/wireguard/receive.c | 597 ++++++++++++++ drivers/net/wireguard/selftest/allowedips.h | 656 ++++++++++++++++ drivers/net/wireguard/selftest/counter.h | 103 +++ drivers/net/wireguard/selftest/ratelimiter.h | 174 ++++ drivers/net/wireguard/send.c | 420 ++++++++++ drivers/net/wireguard/socket.c | 435 ++++++++++ drivers/net/wireguard/socket.h | 44 ++ drivers/net/wireguard/timers.c | 256 ++++++ drivers/net/wireguard/timers.h | 30 + drivers/net/wireguard/version.h | 1 + include/uapi/linux/wireguard.h | 190 +++++ tools/testing/selftests/wireguard/netns.sh | 499 ++++++++++++ 36 files changed, 7474 insertions(+) create mode 100644 drivers/net/wireguard/Makefile create mode 100644 drivers/net/wireguard/allowedips.c create mode 100644 drivers/net/wireguard/allowedips.h create mode 100644 drivers/net/wireguard/cookie.c create mode 100644 drivers/net/wireguard/cookie.h create mode 100644 drivers/net/wireguard/device.c create mode 100644 drivers/net/wireguard/device.h create mode 100644 drivers/net/wireguard/hashtables.c create mode 100644 drivers/net/wireguard/hashtables.h create mode 100644 drivers/net/wireguard/main.c create mode 100644 drivers/net/wireguard/messages.h create mode 100644 drivers/net/wireguard/netlink.c create mode 100644 drivers/net/wireguard/netlink.h create mode 100644 drivers/net/wireguard/noise.c create mode 100644 drivers/net/wireguard/noise.h create mode 100644 drivers/net/wireguard/peer.c create mode 100644 drivers/net/wireguard/peer.h create mode 100644 drivers/net/wireguard/queueing.c create mode 100644 drivers/net/wireguard/queueing.h create mode 100644 drivers/net/wireguard/ratelimiter.c create mode 100644 drivers/net/wireguard/ratelimiter.h create mode 100644 drivers/net/wireguard/receive.c create mode 100644 drivers/net/wireguard/selftest/allowedips.h create mode 100644 drivers/net/wireguard/selftest/counter.h create mode 100644 drivers/net/wireguard/selftest/ratelimiter.h create mode 100644 drivers/net/wireguard/send.c create mode 100644 drivers/net/wireguard/socket.c create mode 100644 drivers/net/wireguard/socket.h create mode 100644 drivers/net/wireguard/timers.c create mode 100644 drivers/net/wireguard/timers.h create mode 100644 drivers/net/wireguard/version.h create mode 100644 include/uapi/linux/wireguard.h create mode 100755 tools/testing/selftests/wireguard/netns.sh
MAINTAINERS +8 -0
@@ -15813,6 +15813,14 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-ws16c48.c +WIREGUARD SECURE NETWORK TUNNEL +M: Jason A. Donenfeld <[email protected]> +S: Maintained +F: drivers/net/wireguard/ +F: tools/testing/selftests/wireguard/ +L: [email protected] +L: [email protected] + WISTRON LAPTOP BUTTON DRIVER M: Miloslav Trmac <[email protected]> S: Maintained
drivers/net/Kconfig +30 -0
@@ -70,6 +70,36 @@ config DUMMY To compile this driver as a module, choose M here: the module will be called dummy. +config WIREGUARD + tristate "WireGuard secure network tunnel" + depends on NET && INET + select NET_UDP_TUNNEL + select DST_CACHE + select ZINC_CHACHA20POLY1305 + select ZINC_BLAKE2S + select ZINC_CURVE25519 + default m + help + WireGuard is a secure, fast, and easy to use replacement for IPSec + that uses modern cryptography and clever networking tricks. It's + designed to be fairly general purpose and abstract enough to fit most + use cases, while at the same time remaining extremely simple to + configure. See www.wireguard.com for more info. + + It's safe to say Y or M here, as the driver is very lightweight and + is only in use when an administrator chooses to add an interface. + +config WIREGUARD_DEBUG + bool "Debugging checks and verbose messages" + depends on WIREGUARD + help + This will write log messages for handshake and other events + that occur for a WireGuard interface. It will also perform some + extra validation checks and unit tests at various points. This is + only useful for debugging. + + Say N here unless you know what you're doing. + config EQUALIZER tristate "EQL (serial line load balancing) support" ---help---
drivers/net/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_RIONET) += rionet.o obj-$(CONFIG_NET_TEAM) += team/ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_TAP) += tap.o +obj-$(CONFIG_WIREGUARD) += wireguard/ obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VXLAN) += vxlan.o
drivers/net/wireguard/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +ccflags-y := -O3 +ccflags-y += -D'pr_fmt(fmt)=KBUILD_MODNAME ": " fmt' +ccflags-$(CONFIG_WIREGUARD_DEBUG) += -DDEBUG +wireguard-y := main.o +wireguard-y += noise.o +wireguard-y += device.o +wireguard-y += peer.o +wireguard-y += timers.o +wireguard-y += queueing.o +wireguard-y += send.o +wireguard-y += receive.o +wireguard-y += socket.o +wireguard-y += hashtables.o +wireguard-y += allowedips.o +wireguard-y += ratelimiter.o +wireguard-y += cookie.o +wireguard-y += netlink.o +obj-$(CONFIG_WIREGUARD) := wireguard.o
drivers/net/wireguard/allowedips.c new file +404 -0
404 lines not on this page · raw message
drivers/net/wireguard/allowedips.h new file +55 -0
55 lines not on this page · raw message
drivers/net/wireguard/cookie.c new file +234 -0
234 lines not on this page · raw message
drivers/net/wireguard/cookie.h new file +59 -0
59 lines not on this page · raw message
drivers/net/wireguard/device.c new file +438 -0
438 lines not on this page · raw message
drivers/net/wireguard/device.h new file +65 -0
65 lines not on this page · raw message
drivers/net/wireguard/hashtables.c new file +209 -0
209 lines not on this page · raw message
drivers/net/wireguard/hashtables.h new file +63 -0
63 lines not on this page · raw message
drivers/net/wireguard/main.c new file +65 -0
65 lines not on this page · raw message
drivers/net/wireguard/messages.h new file +128 -0
128 lines not on this page · raw message
drivers/net/wireguard/netlink.c new file +605 -0
605 lines not on this page · raw message
drivers/net/wireguard/netlink.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#ifndef _WG_NETLINK_H +#define _WG_NETLINK_H + +int genetlink_init (void ); +void genetlink_uninit (void ); + +#endif /* _WG_NETLINK_H */
drivers/net/wireguard/noise.c new file +784 -0
588 lines not on this page · raw message
drivers/net/wireguard/noise.h new file +129 -0
129 lines not on this page · raw message
drivers/net/wireguard/peer.c new file +191 -0
191 lines not on this page · raw message
drivers/net/wireguard/peer.h new file +87 -0
87 lines not on this page · raw message
drivers/net/wireguard/queueing.c new file +52 -0
52 lines not on this page · raw message
drivers/net/wireguard/queueing.h new file +193 -0
193 lines not on this page · raw message
drivers/net/wireguard/ratelimiter.c new file +220 -0
220 lines not on this page · raw message
drivers/net/wireguard/ratelimiter.h new file +19 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireguard/receive.c new file +597 -0
597 lines not on this page · raw message
drivers/net/wireguard/selftest/allowedips.h new file +656 -0
656 lines not on this page · raw message
drivers/net/wireguard/selftest/counter.h new file +103 -0
103 lines not on this page · raw message
drivers/net/wireguard/selftest/ratelimiter.h new file +174 -0
174 lines not on this page · raw message
drivers/net/wireguard/send.c new file +420 -0
420 lines not on this page · raw message
drivers/net/wireguard/socket.c new file +435 -0
435 lines not on this page · raw message
drivers/net/wireguard/socket.h new file +44 -0
44 lines not on this page · raw message
drivers/net/wireguard/timers.c new file +256 -0
256 lines not on this page · raw message
drivers/net/wireguard/timers.h new file +30 -0
Lines of this file are not shown. View the raw message.
drivers/net/wireguard/version.h new file +1 -0
Lines of this file are not shown. View the raw message.
include/uapi/linux/wireguard.h new file +190 -0
190 lines not on this page · raw message
tools/testing/selftests/wireguard/netns.sh new file +499 -0
499 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.18.0
Part of the diff is not shown here. View the raw message.
kbuild test robot
build botRe: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
I love your patch! Yet something to improve:
Hi Jason,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Jason-A-Donenfeld/WireGuard-Secure-Network-Tunnel/20180911-185037
config: um-i386_defconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=um SUBARCH=i386All error/warnings (new ones prefixed by >>):
In file included from lib/zinc/chacha20/chacha20-x86_64-glue.h:8:0,
from <command-line>:0:
>> arch/x86/include/asm/cpufeature.h:134:34: warning: 'struct cpuinfo_x86' declared inside parameter list will not be visible outside of this definition or declaration
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
^~~~~~~~~~~
In file included from include/linux/compiler_types.h:64:0,
from <command-line>:0:
arch/x86/include/asm/cpufeature.h: In function '_static_cpu_has':
>> arch/x86/include/asm/cpufeature.h:198:52: error: 'struct cpuinfo_um' has no member named 'x86_capability'
[cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
^
include/linux/compiler-gcc.h:182:47: note: in definition of macro 'asm_volatile_goto'
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
^
In file included from lib/zinc/chacha20/chacha20-x86_64-glue.h:8:0,
from <command-line>:0:
lib/zinc/chacha20/chacha20-x86_64-glue.h: In function 'chacha20_fpu_init':
>> arch/x86/include/asm/cpufeature.h:65:28: error: 'REQUIRED_MASK0' undeclared (first use in this function); did you mean 'DISABLED_MASK0'?
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/chacha20/chacha20-x86_64-glue.h:36:23: note: in expansion of macro 'boot_cpu_has'
chacha20_use_ssse3 = boot_cpu_has(X86_FEATURE_SSSE3);
^~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:65:28: note: each undeclared identifier is reported only once for each function it appears in
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/chacha20/chacha20-x86_64-glue.h:36:23: note: in expansion of macro 'boot_cpu_has'
chacha20_use_ssse3 = boot_cpu_has(X86_FEATURE_SSSE3);
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:66:28: error: 'REQUIRED_MASK1' undeclared (first use in this function); did you mean 'REQUIRED_MASK0'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/chacha20/chacha20-x86_64-glue.h:36:23: note: in expansion of macro 'boot_cpu_has'
chacha20_use_ssse3 = boot_cpu_has(X86_FEATURE_SSSE3);
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:67:28: error: 'REQUIRED_MASK2' undeclared (first use in this function); did you mean 'REQUIRED_MASK1'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 2, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/chacha20/chacha20-x86_64-glue.h:36:23: note: in expansion of macro 'boot_cpu_has'
chacha20_use_ssse3 = boot_cpu_has(X86_FEATURE_SSSE3);
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:68:28: error: 'REQUIRED_MASK3' undeclared (first use in this function); did you mean 'REQUIRED_MASK2'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 3, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
--
In file included from lib/zinc/poly1305/poly1305-x86_64-glue.h:7:0,
from <command-line>:0:
>> arch/x86/include/asm/cpufeature.h:134:34: warning: 'struct cpuinfo_x86' declared inside parameter list will not be visible outside of this definition or declaration
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
^~~~~~~~~~~
In file included from include/linux/compiler_types.h:64:0,
from <command-line>:0:
arch/x86/include/asm/cpufeature.h: In function '_static_cpu_has':
>> arch/x86/include/asm/cpufeature.h:198:52: error: 'struct cpuinfo_um' has no member named 'x86_capability'
[cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
^
include/linux/compiler-gcc.h:182:47: note: in definition of macro 'asm_volatile_goto'
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
^
In file included from lib/zinc/poly1305/poly1305-x86_64-glue.h:7:0,
from <command-line>:0:
lib/zinc/poly1305/poly1305-x86_64-glue.h: In function 'poly1305_fpu_init':
>> arch/x86/include/asm/cpufeature.h:65:28: error: 'REQUIRED_MASK0' undeclared (first use in this function); did you mean 'DISABLED_MASK0'?
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/poly1305/poly1305-x86_64-glue.h:39:3: note: in expansion of macro 'boot_cpu_has'
boot_cpu_has(X86_FEATURE_AVX) &&
^~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:65:28: note: each undeclared identifier is reported only once for each function it appears in
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/poly1305/poly1305-x86_64-glue.h:39:3: note: in expansion of macro 'boot_cpu_has'
boot_cpu_has(X86_FEATURE_AVX) &&
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:66:28: error: 'REQUIRED_MASK1' undeclared (first use in this function); did you mean 'REQUIRED_MASK0'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/poly1305/poly1305-x86_64-glue.h:39:3: note: in expansion of macro 'boot_cpu_has'
boot_cpu_has(X86_FEATURE_AVX) &&
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:67:28: error: 'REQUIRED_MASK2' undeclared (first use in this function); did you mean 'REQUIRED_MASK1'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 2, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/poly1305/poly1305-x86_64-glue.h:39:3: note: in expansion of macro 'boot_cpu_has'
boot_cpu_has(X86_FEATURE_AVX) &&
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:68:28: error: 'REQUIRED_MASK3' undeclared (first use in this function); did you mean 'REQUIRED_MASK2'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 3, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
--
lib/zinc/poly1305/poly1305-x86_64.S: Assembler messages:
>> lib/zinc/poly1305/poly1305-x86_64.S:25: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:26: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:27: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:28: Error: bad register name `%rax'
>> lib/zinc/poly1305/poly1305-x86_64.S:30: Error: bad register name `%rsi'
lib/zinc/poly1305/poly1305-x86_64.S:33: Error: bad register name `%rax'
>> lib/zinc/poly1305/poly1305-x86_64.S:34: Error: bad register name `%rcx'
>> lib/zinc/poly1305/poly1305-x86_64.S:35: Error: bad register name `%rsi)'
lib/zinc/poly1305/poly1305-x86_64.S:36: Error: bad register name `%rsi)'
lib/zinc/poly1305/poly1305-x86_64.S:37: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:38: Error: bad register name `%rcx'
>> lib/zinc/poly1305/poly1305-x86_64.S:47: Error: bad register name `%rdx'
>> lib/zinc/poly1305/poly1305-x86_64.S:50: Error: bad register name `%rbx'
>> lib/zinc/poly1305/poly1305-x86_64.S:51: Error: bad register name `%r12'
>> lib/zinc/poly1305/poly1305-x86_64.S:52: Error: bad register name `%r13'
>> lib/zinc/poly1305/poly1305-x86_64.S:53: Error: bad register name `%r14'
>> lib/zinc/poly1305/poly1305-x86_64.S:54: Error: bad register name `%r15'
>> lib/zinc/poly1305/poly1305-x86_64.S:55: Error: bad register name `%rdi'
lib/zinc/poly1305/poly1305-x86_64.S:59: Error: bad register name `%rdx'
>> lib/zinc/poly1305/poly1305-x86_64.S:61: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:62: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:64: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:65: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:66: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:68: Error: bad register name `%r13'
lib/zinc/poly1305/poly1305-x86_64.S:69: Error: bad register name `%r13'
lib/zinc/poly1305/poly1305-x86_64.S:70: Error: bad register name `%r12'
lib/zinc/poly1305/poly1305-x86_64.S:71: Error: bad register name `%r12'
lib/zinc/poly1305/poly1305-x86_64.S:77: Error: bad register name `%rsi)'
lib/zinc/poly1305/poly1305-x86_64.S:78: Error: bad register name `%rsi)'
lib/zinc/poly1305/poly1305-x86_64.S:79: Error: bad register name `%rsi)'
lib/zinc/poly1305/poly1305-x86_64.S:80: Error: bad register name `%rcx'
lib/zinc/poly1305/poly1305-x86_64.S:81: Error: bad register name `%r14'
lib/zinc/poly1305/poly1305-x86_64.S:82: Error: bad register name `%rax'
>> lib/zinc/poly1305/poly1305-x86_64.S:83: Error: bad register name `%r11'
lib/zinc/poly1305/poly1305-x86_64.S:84: Error: bad register name `%rdx'
lib/zinc/poly1305/poly1305-x86_64.S:86: Error: bad register name `%r14'
lib/zinc/poly1305/poly1305-x86_64.S:87: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:88: Error: bad register name `%r11'
lib/zinc/poly1305/poly1305-x86_64.S:89: Error: bad register name `%rdx'
lib/zinc/poly1305/poly1305-x86_64.S:91: Error: bad register name `%rbx'
lib/zinc/poly1305/poly1305-x86_64.S:92: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:93: Error: bad register name `%r13'
lib/zinc/poly1305/poly1305-x86_64.S:94: Error: bad register name `%rdx'
lib/zinc/poly1305/poly1305-x86_64.S:96: Error: bad register name `%rbx'
>> lib/zinc/poly1305/poly1305-x86_64.S:97: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:98: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:99: Error: bad register name `%rdx'
lib/zinc/poly1305/poly1305-x86_64.S:101: Error: bad register name `%r13'
lib/zinc/poly1305/poly1305-x86_64.S:102: Error: bad register name `%rbx'
>> lib/zinc/poly1305/poly1305-x86_64.S:103: Error: bad register name `%r8'
lib/zinc/poly1305/poly1305-x86_64.S:104: Error: bad register name `%rdi'
lib/zinc/poly1305/poly1305-x86_64.S:106: Error: bad register name `%r11'
>> lib/zinc/poly1305/poly1305-x86_64.S:107: Error: bad register name `%r9'
lib/zinc/poly1305/poly1305-x86_64.S:108: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:109: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:111: Error: bad register name `%rdi'
lib/zinc/poly1305/poly1305-x86_64.S:112: Error: bad register name `%rdi'
lib/zinc/poly1305/poly1305-x86_64.S:113: Error: bad register name `%rdi'
lib/zinc/poly1305/poly1305-x86_64.S:114: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:115: Error: bad register name `%rdi'
lib/zinc/poly1305/poly1305-x86_64.S:116: Error: bad register name `%rax'
lib/zinc/poly1305/poly1305-x86_64.S:117: Error: bad register name `%rbx'
lib/zinc/poly1305/poly1305-x86_64.S:118: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:120: Error: bad register name `%r12'
lib/zinc/poly1305/poly1305-x86_64.S:121: Error: bad register name `%r15'
>> lib/zinc/poly1305/poly1305-x86_64.S:124: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:126: Error: bad register name `%r14'
lib/zinc/poly1305/poly1305-x86_64.S:127: Error: bad register name `%rbx'
lib/zinc/poly1305/poly1305-x86_64.S:128: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:130: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:131: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:132: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:133: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:134: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:135: Error: bad register name `%rsp)'
lib/zinc/poly1305/poly1305-x86_64.S:144: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:145: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:146: Error: bad register name `%rdi)'
lib/zinc/poly1305/poly1305-x86_64.S:148: Error: bad register name `%r8'
lib/zinc/poly1305/poly1305-x86_64.S:149: Error: bad register name `%r8'
lib/zinc/poly1305/poly1305-x86_64.S:150: Error: bad register name `%r9'
lib/zinc/poly1305/poly1305-x86_64.S:151: Error: bad register name `%r9'
lib/zinc/poly1305/poly1305-x86_64.S:152: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:153: Error: bad register name `%r10'
lib/zinc/poly1305/poly1305-x86_64.S:154: Error: bad register name `%r8'
lib/zinc/poly1305/poly1305-x86_64.S:155: Error: bad register name `%r9'
>> lib/zinc/poly1305/poly1305-x86_64.S:157: Error: bad register name `%rdx)' lib/zinc/poly1305/poly1305-x86_64.S:158: Error: bad register name %rdx)' lib/zinc/poly1305/poly1305-x86_64.S:159: Error: bad register name %rax' lib/zinc/poly1305/poly1305-x86_64.S:160: Error: bad register name `%rcx'
--
In file included from lib/zinc/curve25519/curve25519-x86_64-glue.h:8:0,
from <command-line>:0:
>> arch/x86/include/asm/cpufeature.h:134:34: warning: 'struct cpuinfo_x86' declared inside parameter list will not be visible outside of this definition or declaration
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
^~~~~~~~~~~
In file included from include/linux/compiler_types.h:64:0,
from <command-line>:0:
arch/x86/include/asm/cpufeature.h: In function '_static_cpu_has':
>> arch/x86/include/asm/cpufeature.h:198:52: error: 'struct cpuinfo_um' has no member named 'x86_capability'
[cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
^
include/linux/compiler-gcc.h:182:47: note: in definition of macro 'asm_volatile_goto'
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
^
In file included from lib/zinc/curve25519/curve25519-x86_64-glue.h:8:0,
from <command-line>:0:
lib/zinc/curve25519/curve25519-x86_64-glue.h: In function 'curve25519_fpu_init':
>> arch/x86/include/asm/cpufeature.h:65:28: error: 'REQUIRED_MASK0' undeclared (first use in this function); did you mean 'DISABLED_MASK0'?
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/curve25519/curve25519-x86_64-glue.h:18:24: note: in expansion of macro 'boot_cpu_has'
curve25519_use_bmi2 = boot_cpu_has(X86_FEATURE_BMI2);
^~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:65:28: note: each undeclared identifier is reported only once for each function it appears in
( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/curve25519/curve25519-x86_64-glue.h:18:24: note: in expansion of macro 'boot_cpu_has'
curve25519_use_bmi2 = boot_cpu_has(X86_FEATURE_BMI2);
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:66:28: error: 'REQUIRED_MASK1' undeclared (first use in this function); did you mean 'REQUIRED_MASK0'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/curve25519/curve25519-x86_64-glue.h:18:24: note: in expansion of macro 'boot_cpu_has'
curve25519_use_bmi2 = boot_cpu_has(X86_FEATURE_BMI2);
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:67:28: error: 'REQUIRED_MASK2' undeclared (first use in this function); did you mean 'REQUIRED_MASK1'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 2, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
>> lib/zinc/curve25519/curve25519-x86_64-glue.h:18:24: note: in expansion of macro 'boot_cpu_has'
curve25519_use_bmi2 = boot_cpu_has(X86_FEATURE_BMI2);
^~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:68:28: error: 'REQUIRED_MASK3' undeclared (first use in this function); did you mean 'REQUIRED_MASK2'?
CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 3, feature_bit) || \
^
arch/x86/include/asm/cpufeature.h:62:44: note: in definition of macro 'CHECK_BIT_IN_MASK_WORD'
(((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
^~~~~~~~
>> arch/x86/include/asm/cpufeature.h:111:32: note: in expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/cpufeature.h:129:27: note: in expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~..
vim +198 arch/x86/include/asm/cpufeature.h
80a208bd arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-06-24 50
0f8d2b92 include/asm-x86/cpufeature.h Ingo Molnar 2008-02-26 51 #define test_cpu_cap(c, bit) \
0f8d2b92 include/asm-x86/cpufeature.h Ingo Molnar 2008-02-26 @52 test_bit(bit, (unsigned long *)((c)->x86_capability))
0f8d2b92 include/asm-x86/cpufeature.h Ingo Molnar 2008-02-26 53
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 54 /*
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 55 * There are 32 bits/features in each mask word. The high bits
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 56 * (selected with (bit>>5) give us the word number and the low 5
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 57 * bits give us the bit/feature number inside the word.
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 58 * (1UL<<((bit)&31) gives us a mask for the feature_bit so we can
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 59 * see if it is set in the mask word.
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 60 */
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 61 #define CHECK_BIT_IN_MASK_WORD(maskname, word, bit) \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 62 (((bit)>>5)==(word) && (1UL<<((bit)&31) & maskname##word ))
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 63
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 64 #define REQUIRED_MASK_BIT_SET(feature_bit) \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @65 ( CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 0, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @66 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 1, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @67 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 2, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @68 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 3, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @69 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 4, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @70 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 5, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @71 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 6, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @72 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 7, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @73 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 8, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @74 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 9, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @75 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 10, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @76 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 11, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @77 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 12, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @78 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 13, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @79 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 14, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @80 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 15, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @81 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 16, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @82 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \
95ca0ee8 arch/x86/include/asm/cpufeature.h David Woodhouse 2018-01-25 @83 CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \
1e61f78b arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 @84 REQUIRED_MASK_CHECK || \
95ca0ee8 arch/x86/include/asm/cpufeature.h David Woodhouse 2018-01-25 85 BUILD_BUG_ON_ZERO(NCAPINTS != 19))
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 86
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 87 #define DISABLED_MASK_BIT_SET(feature_bit) \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 88 ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 89 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 1, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 90 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 2, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 91 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 3, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 92 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 4, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 93 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 5, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 94 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 6, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 95 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 7, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 96 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 8, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 97 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 9, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 98 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 10, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 99 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 11, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 100 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 12, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 101 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 13, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 102 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 14, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 103 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 15, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 104 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 16, feature_bit) || \
8eda072e arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 105 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \
95ca0ee8 arch/x86/include/asm/cpufeature.h David Woodhouse 2018-01-25 106 CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \
1e61f78b arch/x86/include/asm/cpufeature.h Dave Hansen 2016-06-29 107 DISABLED_MASK_CHECK || \
95ca0ee8 arch/x86/include/asm/cpufeature.h David Woodhouse 2018-01-25 108 BUILD_BUG_ON_ZERO(NCAPINTS != 19))
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 109
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 110 #define cpu_has(c, bit) \
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 @111 (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
0f8d2b92 include/asm-x86/cpufeature.h Ingo Molnar 2008-02-26 @112 test_cpu_cap(c, bit))
0f8d2b92 include/asm-x86/cpufeature.h Ingo Molnar 2008-02-26 113
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 114 #define this_cpu_has(bit) \
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 115 (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 116 x86_this_cpu_test_bit(bit, (unsigned long *)&cpu_info.x86_capability))
349c004e arch/x86/include/asm/cpufeature.h Christoph Lameter 2011-03-12 117
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 118 /*
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 119 * This macro is for detection of features which need kernel
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 120 * infrastructure to be used. It may *not* directly test the CPU
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 121 * itself. Use the cpu_has() family if you want true runtime
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 122 * testing of CPU features, like in hypervisor code where you are
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 123 * supporting a possible guest feature where host support for it
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 124 * is not relevant.
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 125 */
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 126 #define cpu_feature_enabled(bit) \
f2cc8e07 arch/x86/include/asm/cpufeature.h Borislav Petkov 2016-02-16 127 (__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 : static_cpu_has(bit))
381aa07a arch/x86/include/asm/cpufeature.h Dave Hansen 2014-09-11 128
7b11fb51 include/asm-x86/cpufeature.h H. Peter Anvin 2008-01-30 @129 #define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
7b11fb51 include/asm-x86/cpufeature.h H. Peter Anvin 2008-01-30 130
53756d37 include/asm-x86/cpufeature.h Jeremy Fitzhardinge 2008-01-30 131 #define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capability))
0b00de85 arch/x86/include/asm/cpufeature.h Andi Kleen 2017-10-13 132
0b00de85 arch/x86/include/asm/cpufeature.h Andi Kleen 2017-10-13 133 extern void setup_clear_cpu_cap(unsigned int bit);
0b00de85 arch/x86/include/asm/cpufeature.h Andi Kleen 2017-10-13 @134 extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
0b00de85 arch/x86/include/asm/cpufeature.h Andi Kleen 2017-10-13 135
404ee5b1 include/asm-x86/cpufeature.h Andi Kleen 2008-01-30 136 #define setup_force_cpu_cap(bit) do { \
404ee5b1 include/asm-x86/cpufeature.h Andi Kleen 2008-01-30 137 set_cpu_cap(&boot_cpu_data, bit); \
3e0c3737 arch/x86/include/asm/cpufeature.h Yinghai Lu 2009-05-09 138 set_bit(bit, (unsigned long *)cpu_caps_set); \
404ee5b1 include/asm-x86/cpufeature.h Andi Kleen 2008-01-30 139 } while (0)
53756d37 include/asm-x86/cpufeature.h Jeremy Fitzhardinge 2008-01-30 140
6cbd2171 arch/x86/include/asm/cpufeature.h Thomas Gleixner 2017-12-04 141 #define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit)
6cbd2171 arch/x86/include/asm/cpufeature.h Thomas Gleixner 2017-12-04 142
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 143 #if defined(__clang__) && !defined(CC_HAVE_ASM_GOTO)
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 144
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 145 /*
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 146 * Workaround for the sake of BPF compilation which utilizes kernel
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 147 * headers, but clang does not support ASM GOTO and fails the build.
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 148 */
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 149 #ifndef __BPF_TRACING__
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 150 #warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 151 #endif
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 152
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 153 #define static_cpu_has(bit) boot_cpu_has(bit)
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 154
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 155 #else
b1ae32db arch/x86/include/asm/cpufeature.h Alexei Starovoitov 2018-05-13 156
a3c8acd0 arch/x86/include/asm/cpufeature.h H. Peter Anvin 2010-05-11 157 /*
a3c8acd0 arch/x86/include/asm/cpufeature.h H. Peter Anvin 2010-05-11 158 * Static testing of CPU features. Used the same as boot_cpu_has().
a362bf9f arch/x86/include/asm/cpufeature.h Borislav Petkov 2016-01-27 159 * These will statically patch the target code for additional
a362bf9f arch/x86/include/asm/cpufeature.h Borislav Petkov 2016-01-27 160 * performance.
a3c8acd0 arch/x86/include/asm/cpufeature.h H. Peter Anvin 2010-05-11 161 */
bc696ca0 arch/x86/include/asm/cpufeature.h Borislav Petkov 2016-01-26 162 static __always_inline __pure bool _static_cpu_has(u16 bit)
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 163 {
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 164 asm_volatile_goto("1: jmp 6f\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 165 "2:\n"
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 166 ".skip -(((5f-4f) - (2b-1b)) > 0) * "
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 167 "((5f-4f) - (2b-1b)),0x90\n"
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 168 "3:\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 169 ".section .altinstructions,\"a\"\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 170 " .long 1b - .\n" /* src offset */
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 171 " .long 4f - .\n" /* repl offset */
3197b04b arch/x86/include/asm/cpufeature.h Peter Zijlstra 2018-01-16 172 " .word %P[always]\n" /* always replace */
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 173 " .byte 3b - 1b\n" /* src len */
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 174 " .byte 5f - 4f\n" /* repl len */
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 175 " .byte 3b - 2b\n" /* pad len */
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 176 ".previous\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 177 ".section .altinstr_replacement,\"ax\"\n"
48c7a250 arch/x86/include/asm/cpufeature.h Borislav Petkov 2015-01-05 178 "4: jmp %l[t_no]\n"
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 179 "5:\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 180 ".previous\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 181 ".section .altinstructions,\"a\"\n"
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 182 " .long 1b - .\n" /* src offset */
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 183 " .long 0\n" /* no replacement */
3197b04b arch/x86/include/asm/cpufeature.h Peter Zijlstra 2018-01-16 184 " .word %P[feature]\n" /* feature bit */
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 185 " .byte 3b - 1b\n" /* src len */
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 186 " .byte 0\n" /* repl len */
4332195c arch/x86/include/asm/cpufeature.h Borislav Petkov 2014-12-27 187 " .byte 0\n" /* pad len */
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 188 ".previous\n"
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 189 ".section .altinstr_aux,\"ax\"\n"
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 190 "6:\n"
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 191 " testb %[bitnum],%[cap_byte]\n"
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 192 " jnz %l[t_yes]\n"
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 193 " jmp %l[t_no]\n"
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 194 ".previous\n"
3197b04b arch/x86/include/asm/cpufeature.h Peter Zijlstra 2018-01-16 195 : : [feature] "i" (bit),
3197b04b arch/x86/include/asm/cpufeature.h Peter Zijlstra 2018-01-16 196 [always] "i" (X86_FEATURE_ALWAYS),
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 197 [bitnum] "i" (1 << (bit & 7)),
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 @198 [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 199 : : t_yes, t_no);
2476f2fa arch/x86/include/asm/cpufeature.h Brian Gerst 2016-01-27 200 t_yes:
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 201 return true;
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 202 t_no:
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 203 return false;
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 204 }
4a90a99c arch/x86/include/asm/cpufeature.h Borislav Petkov 2013-06-09 205 :::::: The code at line 198 was first introduced by commit
:::::: 2476f2fa20568bd5d9e09cd35bcd73e99a6f4cc6 x86/alternatives: Discard dynamic check after init
:::::: TO: Brian Gerst <[email protected]>
:::::: CC: Ingo Molnar <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
Hi friendly kbuild test robot,
Quoted 2 lines · kbuild test robot
I love your patch! Yet something to improve:
make ARCH=um SUBARCH=i386
I've now fixed this problem and it will be in v4.
Regards,
Jason, a human
kbuild test robot
build botRe: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
In reply to Jason A. DonenfeldI love your patch! Yet something to improve:
Hi Jason,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Jason-A-Donenfeld/WireGuard-Secure-Network-Tunnel/20180911-185037
config: arm-at91_dt_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm
All errors (new ones prefixed by >>):
arch/arm/vfp/vfphw.S: Assembler messages:
>> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c0' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c1' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c2' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c3' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c4' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c5' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c6' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c7' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c8' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c9' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c10' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c11' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c12' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c13' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c14' in ARM mode >> arch/arm/vfp/vfphw.S:299: Error: selected processor does not support `mrrc p11,3,r0,r1,c15' in ARM mode >> arch/arm/vfp/vfphw.S:321: Error: selected processor does not support `mcrr p11,3,r0,r1,c0' in ARM mode >> arch/arm/vfp/vfphw.S:321: Error: selected processor does not support `mcrr p11,3,r0,r1,c1' in ARM mode >> arch/arm/vfp/vfphw.S:321: Error: selected processor does not support `mcrr p11,3,r0,r1,c2' in ARM mode >> arch/arm/vfp/vfphw.S:321: Error: selected processor does not support `mcrr p11,3,r0,r1,c3' in ARM mode
vim +299 arch/arm/vfp/vfphw.S
^1da177e Linus Torvalds 2005-04-16 285 93ed3970 Catalin Marinas 2008-08-28 286 ENTRY(vfp_get_double) 07f33a03 Catalin Marinas 2009-07-24 287 tbl_branch r0, r3, #3 ^1da177e Linus Torvalds 2005-04-16 288 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 07f33a03 Catalin Marinas 2009-07-24 289 1: fmrrd r0, r1, d\dr 6ebbf2ce Russell King 2014-06-30 290 ret lr 07f33a03 Catalin Marinas 2009-07-24 291 .org 1b + 8 ^1da177e Linus Torvalds 2005-04-16 292 .endr 25ebee02 Catalin Marinas 2007-09-25 293 #ifdef CONFIG_VFPv3 25ebee02 Catalin Marinas 2007-09-25 294 @ d16 - d31 registers 25ebee02 Catalin Marinas 2007-09-25 295 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 07f33a03 Catalin Marinas 2009-07-24 296 1: mrrc p11, 3, r0, r1, c\dr @ fmrrd r0, r1, d\dr 6ebbf2ce Russell King 2014-06-30 297 ret lr 07f33a03 Catalin Marinas 2009-07-24 298 .org 1b + 8 25ebee02 Catalin Marinas 2007-09-25 @299 .endr 25ebee02 Catalin Marinas 2007-09-25 300 #endif ^1da177e Linus Torvalds 2005-04-16 301 25ebee02 Catalin Marinas 2007-09-25 302 @ virtual register 16 (or 32 if VFPv3) for compare with zero ^1da177e Linus Torvalds 2005-04-16 303 mov r0, #0 ^1da177e Linus Torvalds 2005-04-16 304 mov r1, #0 6ebbf2ce Russell King 2014-06-30 305 ret lr 93ed3970 Catalin Marinas 2008-08-28 306 ENDPROC(vfp_get_double) ^1da177e Linus Torvalds 2005-04-16 307 93ed3970 Catalin Marinas 2008-08-28 308 ENTRY(vfp_put_double) 07f33a03 Catalin Marinas 2009-07-24 309 tbl_branch r2, r3, #3 ^1da177e Linus Torvalds 2005-04-16 310 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 07f33a03 Catalin Marinas 2009-07-24 311 1: fmdrr d\dr, r0, r1 6ebbf2ce Russell King 2014-06-30 312 ret lr 07f33a03 Catalin Marinas 2009-07-24 313 .org 1b + 8 ^1da177e Linus Torvalds 2005-04-16 314 .endr 25ebee02 Catalin Marinas 2007-09-25 315 #ifdef CONFIG_VFPv3 25ebee02 Catalin Marinas 2007-09-25 316 @ d16 - d31 registers 25ebee02 Catalin Marinas 2007-09-25 317 .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 138de1c4 Russell King 2010-05-27 318 1: mcrr p11, 3, r0, r1, c\dr @ fmdrr r0, r1, d\dr 6ebbf2ce Russell King 2014-06-30 319 ret lr 07f33a03 Catalin Marinas 2009-07-24 320 .org 1b + 8
25ebee02 Catalin Marinas 2007-09-25 @321 .endr
:::::: The code at line 299 was first introduced by commit
:::::: 25ebee020bd34d1f4c5678538204f0b10bf9f6d5 [ARM] 4583/1: ARMv7: Add VFPv3 support
:::::: TO: Catalin Marinas <[email protected]> :::::: CC: Russell King <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
Hello again Mr. Ro Bot,
Quoted 7 lines · kbuild test robot
I love your patch! Yet something to improve:
All errors (new ones prefixed by >>):
arch/arm/vfp/vfphw.S: Assembler messages:Quoted 2 lines
Quoted 2 lines
arch/arm/vfp/vfphw.S:299: Error: selected processor does not supportmrrc p11,3,r0,r1,c0' in ARM mode arch/arm/vfp/vfphw.S:299: Error: selected processor does not supportmrrc p11,3,r0,r1,c1' in ARM mode:::::: The code at line 299 was first introduced by commit
::::::25ebee020bd34d1f4c5678538204f0b10bf9f6d5[ARM] 4583/1: ARMv7: Add VFPv3 support
I've also fixed this for v4 of the submission. Sorry about that.
Jason
Re: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
In reply to Jason A. DonenfeldQuoted 4 lines · Jason A. Donenfeld
Signed-off-by Jason A. Donenfeld <[email protected]>Cc David Miller <[email protected]>Cc Greg KH <[email protected]>---
Hi Jason
I don't know if any of the crypto people are reviewing the networking code, but i don't think there are many networking people reviewing the crypto code.
So please can you put the change log between versions for the networking code here, where we can easily see it.
Quoted 21 lines
+++
b/drivers/net/wireguard/allowedips.cdrivers/net/wireguard/allowedips.c new file +19
-0@@ -0,0 +1,404 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. +*/ + +#include "allowedips.h" +#include "peer.h" + +struct allowedips_node { +struct wireguard_peer __rcu *peer; +struct rcu_head rcu; +struct allowedips_node __rcu *bit[2 ]; +/* While it may seem scandalous that we waste space for v4, +* we're alloc'ing to the nearest power of 2 anyway, so this +* doesn't actually make a difference. +*/ +u8 bits[16 ]__aligned(__alignof(u64)) ; +u8 cidr, bit_at_a, bit_at_b; +};
drivers/net/wireguard/allowedips.c line 29
Quoted 10 lines
drivers/net/wireguard/allowedips.c new file +10
-0+ +static __always_inline void swap_endian(u8 *dst, const u8 *src, u8 bits) +{ +if (bits ==32 ) + *(u32 *)dst =be32_to_cpu (*(const __be32 *)src); +else if (bits ==128 ) { + ((u64 *)dst)[0 ] =be64_to_cpu (((const __be64 *)src)[0 ]); + ((u64 *)dst)[1 ] =be64_to_cpu (((const __be64 *)src)[1 ]); + } +}
I see you have yet again completely ignored my request to either
1) Remove the inline
2) Argue why it should be kept.
Ignoring reviewer comments is not going to help your cause.
drivers/net/wireguard/allowedips.c line 319
Quoted 5 lines
drivers/net/wireguard/allowedips.c new file +5
-0+void allowedips_init (struct allowedips *table) +{ + table->root4 = table->root6 =NULL ; + table->seq =1 ; +}
You have a number of global scope functions which are polluting the namespace. Anything which is global scope needs a prefix. If my grep-foo is correct, the prefix wg_ is currently unused. It is also reasonably normal for static members to also make use of the prefix, but not a must.
Andrew
Jason A. Donenfeld
maintainerRe: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
Hello Andrew,
Quoted 6 lines · Andrew Lunn
I don't know if any of the crypto people are reviewing the networking code, but i don't think there are many networking people reviewing the crypto code.
So please can you put the change log between versions for the networking code here, where we can easily see it.
All submissions >v1 have had a changelog in the 00/17 commit.
Quoted 3 lines
I see you have yet again completely ignored my request to either
1) Remove the inline
2) Argue why it should be kept.
Most uses of inline are this way after checking the compiler output on several platforms. (Generally my build-run-test cycle is actually build-IDAPro-run-test.) If you feel that's been done too liberally, I'm happy to spend time rechecking each use case.
Re: [PATCH net-next v3 17/17] net: WireGuard secure network tunnel
Quoted 4 lines
Most uses of inline are this way after checking the compiler output on several platforms. (Generally my build-run-test cycle is actually build-IDAPro-run-test.) If you feel that's been done too liberally, I'm happy to spend time rechecking each use case.
Hi Jason
I really expect DaveM is going to come along and tell you to remove them all.
You need a strong argument that they are needed, since this goes against the general consensus in the kernel, that the compiler is better at this than humans.
Andrew