Commit Graph

61 Commits

Author SHA1 Message Date
David Sterba 32880fa518 btrfs-progs: crypto: add openssl as crypto provider
https://www.openssl.org/ Is a well known cryptography library and since
freshly released version 3.2 it also supports variable digest size of
blake2b, so we can now add it among the crypto providers.

Configure with --with-crypto=openssl.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-30 22:04:45 +01:00
David Sterba 5221aedc00 btrfs-progs: crypto: add Botan as crypto provider
https://botan.randombit.net/ Botan is a cryptography library with C
bindings and provides what we need (sha256 and blake2b), among many
others. Add it to the list of crypto backends if somebody wants to use
it.

Currently the version 2.19 is the latest one. Botan3 3.2.0 exists but
does not seem to be widely available in distros yet.

Configure with --with-crypto=botan.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-30 22:04:45 +01:00
David Sterba 21aa6777b2 btrfs-progs: clean up includes, using include-what-you-use
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:57 +02:00
David Sterba 7db445a3de btrfs-progs: crypto: unify naming of crc32c implementations
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-02 18:05:38 +02:00
David Sterba 03f41ac508 btrfs-progs: detect PCLMUL CPU support for accelerated crc32c
The accelerated crc32c needs to check for two CPU features, the crc32c
instructions is in SSE 4.2 and 'pclmulqdq' is a separate. There's still
old hardware used that does not have the PCLMUL instructions. Detect it
and make it the condition.

The pclmul is not supported on old compilers so also add a
configure-time detection and leave the SSE 4.2 only implementation as
the accelerated one if possible.

Issue: #676
Signed-off-by: David Sterba <dsterba@suse.com>
2023-09-13 00:38:50 +02:00
Ariadne Conill b390c276c2 btrfs-progs: crypto: fix readonly relocation of the jumptable
Without this, the btrfs programs fail to link when build with -Wl,-z,relro,
due to the jumptable containing relocations.

Pull-request: #675
Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-09-12 22:08:02 +02:00
David Sterba 588f82f333 btrfs-progs: hash-vectest: make test_hash static to fix build warning
The warning:

crypto/hash-vectest.c:559:5: warning: no previous prototype for ‘test_hash’ [-Wmissing-prototypes]
  559 | int test_hash(const struct hash_testspec *sp

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
David Sterba 83ac6e0a72 btrfs-progs: crypto: make the PCL implementation default for crc32c
Drop the old native intel implementation and use the PCL one. Remove the
artifical CPU flags.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
David Sterba 992be8b50a btrfs-progs: crypto: add PCL based implementation for crc32c
Copy faster implementation of crc32c from linux kernel as of 6.5-rc7
(x86_64, arch/x86/crypto/crc32c-pcl-intel-asm_64.S). This needs
assembler build support, so detect target architecture so
cross-compilation still works.

Add a special CPU flag so the old and new implementations can be
benchmarked and verified separately.

Sample benchmark:

CPU flags: 0x1ff
CPU features: SSE2 SSSE3 SSE41 SSE42 SHA AVX AVX2 CRC32C_PCL
Block size:     4096
Iterations:     1000000
Implementation: builtin
Units:          CPU cycles

      NULL-NOP: cycles:     77177218, cycles/i       77
   NULL-MEMCPY: cycles:    226313072, cycles/i      226,    62133.395 MiB/s
    CRC32C-ref: cycles:  24418596066, cycles/i    24418,      575.859 MiB/s
     CRC32C-NI: cycles:   1188335920, cycles/i     1188,    11833.073 MiB/s
    CRC32C-PCL: cycles:    463193456, cycles/i      463,    30358.037 MiB/s
        XXHASH: cycles:    851606646, cycles/i      851,    16511.916 MiB/s
    SHA256-ref: cycles:  74476234956, cycles/i    74476,      188.808 MiB/s
     SHA256-NI: cycles:  34198637428, cycles/i    34198,      411.177 MiB/s
    BLAKE2-ref: cycles:  14761411664, cycles/i    14761,      952.597 MiB/s
   BLAKE2-SSE2: cycles:  18101896796, cycles/i    18101,      776.807 MiB/s
  BLAKE2-SSE41: cycles:  12599091062, cycles/i    12599,     1116.087 MiB/s
   BLAKE2-AVX2: cycles:   9668247506, cycles/i     9668,     1454.418 MiB/s

The new implementation is about 2.5x faster.

Note: there new version does not work on musl because of linkage
problems (relocations in .rodata), so it's still using the old
implementation.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:24 +02:00
Qu Wenruo 8b826e1cb7 btrfs-progs: crypto: declare SHA256 x86 optimized implementation
The optimized implementation sha256_process_x86() is not declared
anywhere, this can be caught by -Wmissing-prototypes option.

Just declare it properly in sha.h.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:31 +02:00
Qu Wenruo 903e93e814 btrfs-progs: crypto: move optimized declarations to blake2b.h
This is to avoid -Wmissing-prototypes warnings.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:31 +02:00
Qu Wenruo 9c2b07e901 btrfs-progs: crypto: remove unused blake2 code
We don't use the simple API and the self testing code.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:31 +02:00
David Sterba 474c980386 btrfs-progs: crypto: remove unused declarations of blake2 variants
We use only the 2b variant, we can remove the rest.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-03-17 01:16:02 +01:00
Tino Mai 0da635fd1b btrfs-progs: crypto: fix SSE2/SSE4.1 detection of BLAKE2
On recent x86-64 system with march=native|<cpu>|<microarchitecture
level> gcc/clang will automatically define all the available vector
extensions macros. crypto/blake2-config.h then correctly set all the
HAVE_<EXTENSION> macros.

crypto/blake2-round.h then checks the HAVE_<EXTENSION> macros for
including further headers:

    #if defined(HAVE_SSE41)
    #include "blake2b-load-sse41.h"
    #else
    #include "blake2b-load-sse2.h"
    #endif

which is wrong. On recent systems it always results in including
blake2b-load-sse41.h. crypto/blake2-round.h itself is included by
crypto/blake2b-sse2.c and now we have a SSE2/SSE4.1 code mixing
resulting in the incompatible type for argument build errors described
in #589.

The idea is to remove the lines above from crypto/blake2-round.h and put
the includes directly into crypto/blake2b-sse2.c and
crypto/blake2b-sse41.c respectively.

Note this slightly diverges from the upstream BLAKE2 sources.

Pull-request: #591
Author: Tino Mai <mai.tino@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-03-07 20:50:06 +01:00
Alexander Kanavin 2aa6854bb0 btrfs-progs: crypto: add missing ssse3 header for blake2-sse2 implementation
Otherwise, the following error occurs:

| In file included from crypto/blake2b-sse2.c:30:
| crypto/blake2b-sse2.c: In function 'blake2b_compress_sse2':
| crypto/blake2b-round.h:32:22: warning: implicit declaration of function '_mm_shuffle_epi8'; did you mean '_mm_shuffle_epi32'? [-Wimplicit-function-declaration]
|    32 |     : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \
|       |                      ^~~~~~~~~~~~~~~~

Note: it's not yet clear what affects this build failure as it otherwise
builds in the tested configurations (gcc/clang, arch, distro), but it
apparently fixes the build in some environments.

Pull-request: #588
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
[ add note ]
Signed-off-by: David Sterba <dsterba@suse.com>
2023-03-03 16:54:17 +01:00
David Sterba 02d3723993 btrfs-progs: hash-vectest: verify vectors against configured implementation
Add entries for all crypto backends and test the ones that match what
was configured with --with-crypto.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-03-01 15:53:26 +01:00
David Sterba bbcd599062 btrfs-progs: hash-speedtest: benchmark the configured backend
Change what hash-speedtest benchmarks according to the
--with-crypto=backend option. Until now it would run the same version
under different names inherited from the builting.

At configure time detect availability of all backends and define all
macros.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-03-01 15:53:26 +01:00
David Sterba 4fc291a465 btrfs-progs: fix detection of accelerated implementation.
The build fails with crypto backends other than builtin, the
initializers cannot be reached as they're ifdef-ed out.  Move
hash_init_accel under the right condition and delete the
algorithm-specific initializers as they're used only by the hash test
and that can simply call hash_init_accel to set the implementation.

All the -m flags need to be detected at configure time and the flag used
for ifdef (HAVE_CFLAG_m*), not the actual feature defined by compiler as
the dispatcher function is not built with the -m flags.

The uname check for x86_64 must be dropped so on i386/i586 we can still
build accelerated version.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-03-01 15:10:21 +01:00
David Sterba 140234dc0d btrfs-progs: move include from toplevel directory to include/
In order to reduce number of files in the toplevel directory,

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:23 +01:00
David Sterba 3d9217f7ab btrfs-progs: hash-speedtest: select implementation by features
Now put all the recent changes into action. Add a callback that will
reinitialize the implementation pointers according to the desired
feature. Reference implementations use the NONE CPU flag to distinguish
them from the rest.

Example results:

$ hash-speedtest
CPU flags: 0xff
CPU features: SSE2 SSSE3 SSE41 SSE42 SHA AVX AVX2
Block size:     4096
Iterations:     1000000
Implementation: builtin
Units:          CPU cycles

    NULL-NOP: cycles:     67129026, cycles/i       67
 NULL-MEMCPY: cycles:    231303654, cycles/i      231,    60792.500 MiB/s
  CRC32C-ref: cycles:  23982698042, cycles/i    23982,      586.322 MiB/s
   CRC32C-NI: cycles:   1168017624, cycles/i     1168,    12038.828 MiB/s
      XXHASH: cycles:    838434468, cycles/i      838,    16771.152 MiB/s
  SHA256-ref: cycles:  68296865380, cycles/i    68296,      205.889 MiB/s
   SHA256-NI: cycles:  29748853920, cycles/i    29748,      472.676 MiB/s
  BLAKE2-ref: cycles:  14532177414, cycles/i    14532,      967.617 MiB/s
 BLAKE2-SSE2: cycles:  17762215810, cycles/i    17762,      791.657 MiB/s
BLAKE2-SSE41: cycles:  12370044656, cycles/i    12370,     1136.744 MiB/s
 BLAKE2-AVX2: cycles:   9472823338, cycles/i     9472,     1484.412 MiB/s

Previously:

Block size:     4096
Iterations:     1000000
Implementation: builtin
Units:          CPU cycles

    NULL-NOP: cycles:     67714016, cycles/i       67
 NULL-MEMCPY: cycles:    234140818, cycles/i      234,    60055.762 MiB/s
      CRC32C: cycles:   1187358432, cycles/i     1187,    11842.733 MiB/s
      XXHASH: cycles:   1897530684, cycles/i     1897,     7410.448 MiB/s
      SHA256: cycles:  69855340702, cycles/i    69855,      201.296 MiB/s
      BLAKE2: cycles:  14713130972, cycles/i    14713,      955.716 MiB/s

The CPU is i7-11700 3.60GHz and not the same as previous results
mentioned in changelogs so the results are incomparable. Otherwise, the
updated xxhash implementation is twice as fast, no significant changes
for the rest.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:22 +01:00
David Sterba 8a60fde969 btrfs-progs: crypto: use common CPU feature detection for crc32c
The crc32c selection has been already using the pointer-based approach
so drop the cpuid detection and use our common code for that.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:22 +01:00
David Sterba bbf703bfd3 btrfs-progs: crypto: call sha256 implementations by pointer
Change how sha256 implementation is selected. Instead of an if-else
check in the block processing function select the best version and assign
the function pointer. This is slightly faster.

At this point the selection is not implemented properly in
hash-speedtest so all results are from the fastest version. This will
be fixed once all algorithms are converted.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:10:58 +01:00
David Sterba d1c366ee42 btrfs-progs: crypto: call blake2 implementations by pointer
Change how blake2 implementation is selected. Instead of an if-else check
inside blake2b_compress each time, select the best one and assign the
function pointer. This is slightly faster.

At this point the selection is not implemented properly in
hash-speedtest so all results are from the fastest version. This will
be fixed once all algorithms are converted.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:53:43 +01:00
David Sterba 24ec095295 btrfs-progs: crypto: add common function for accelerated initialization
Prepare a single location that will detect or set accelerated versions
of hash algorithms. Right now it's the crc32c, blake2 and sha256 do
an if-else switch while crc32c sets a function pointer.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:31 +01:00
David Sterba 7f0035c9d1 btrfs-progs: crypto: update xxhash
Update xxhash implementation from https://github.com/Cyan4973/xxHash.
This has moved a lot of code so the diff is huge, plus the code we don't
need now for btrfs has been removed (XXH3, XXH32).

There's no significant change in performance.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:31 +01:00
David Sterba 6048ff5a47 btrfs-progs: crypto: clean up types and includes for crc32c
There are some stale headers that we don't need and the int types are
using the kernel types and pull kerncompat.h. As this is a basic header
that should minimize dependencies use the standard int types.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:30 +01:00
David Sterba 076891943a btrfs-progs: crypto: test all implementations
Now that there are more implementations for the hashes test them all on
the vectors if the CPU supports that.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:30 +01:00
David Sterba e772621053 btrfs-progs: crypto: add more test vectors
Add test vectors that are longer that the internal block length.
Accelerated implementations may not be used on the short or unpaded
blocks but we need to test them as well.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:30 +01:00
David Sterba 6a7a0d8af8 btrfs-progs: crypto: add accelerated SHA256 implementation
Copy sha256-x86.c from https://github.com/noloader/SHA-Intrinsics, that
uses the compiler intrinsics to implement the update step with the
native x86_64 instructions.

To avoid dependencies of the reference code and the x86 version, check
runtime support only if the compiler also supports -msha.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:30 +01:00
David Sterba 7d1353fa01 btrfs-progs: hash-speedtest: add accelerated BLAKE2 implementations
Benchmark all accelerated implementations if the CPU supports them. Set
the level before each test, expecting that the implementation switches
the implementation dynamically.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:30 +01:00
David Sterba 23cb9771bc btrfs-progs: crypto: add AVX2 implementation of BLAKE2
Copy AVX2 implementation from https://github.com/sneves/blake2-avx2 .
Though this is marked experimental, libsodium uses this version.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:29 +01:00
David Sterba d61739003d btrfs-progs: crypto: add SSE4.1 implementation of BLAKE2
Copy SSE4.1 implementation from https://github.com/BLAKE2/BLAKE2 .

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:06 +01:00
David Sterba 1f2117eae8 btrfs-progs: crypto: add SSE2 implementation of BLAKE2
Copy implementation from https://github.com/BLAKE2/BLAKE2, add runtime
detection of SSE2 and add the switch function.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:48:24 +01:00
Qu Wenruo 3a1d4aa089 btrfs-progs: fix fallthrough cases with proper attributes
[FALSE ALERT]
Unlike gcc, clang doesn't really understand the comments, thus it's
reportings tons of fall through related errors:

  cmds/reflink.c:124:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
                  case 'r':
                  ^
  cmds/reflink.c:124:3: note: insert '__attribute__((fallthrough));' to silence this warning
                  case 'r':
                  ^
                  __attribute__((fallthrough));
  cmds/reflink.c:124:3: note: insert 'break;' to avoid fall-through
                  case 'r':
                  ^
                  break;

[CAUSE]
Although gcc is fine with /* fallthrough */ comments, clang is not.

[FIX]
So just introduce a fallthrough macro to handle the situation properly,
and use that macro instead.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-18 17:44:02 +01:00
David Sterba 0e38e1c4f2 btrfs-progs: use error helper for messages in non-kernel code
Lots of code still uses fprintf(stderr, "...") that should be the
error() helper. The kernel-shared code is left out of the conversion for
now.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 00610f5853 btrfs-progs: libbtrfs: remove unneeded BTRFS_FLAT_INCLUDES protections
Remove the switch for local and system-wide headers in headers that are
not part of libbtrfs anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 732d73dc1f btrfs-progs: remove btrfs_crc32c alias
There's an ancient macro btrfs_crc32c which is just wrapping crc32c and
not doing anything else, so we can use the crc helper directly.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba c3ee6a8a09 btrfs-progs: unify GPL header comments
Add the GPL v2 header to files where it was missing and is not from an
external source, update to the most recent version with the address.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 13:58:44 +02:00
David Sterba 9527bc0649 btrfs-progs: crypto: add perf support to speed test
Use perf events to read the cycle count, this should work on all
architectures. Enabled by option --perf and the sysctl
kernel.perf_event_paranoid must be 0 or 1.

The results are roughly the same as for raw cycles on x86_64 but worse
because of the additional overhead (read, context switch):

Block size:     4096
Iterations:     100000
Implementation: builtin
Units:          CPU cycles

    NULL-NOP: cycles:     42719688, cycles/i      427
 NULL-MEMCPY: cycles:     72941208, cycles/i      729,    18670.314 MiB/s
      CRC32C: cycles:    183709926, cycles/i     1837,     7413.009 MiB/s
      XXHASH: cycles:    136727614, cycles/i     1367,     9960.264 MiB/s
      SHA256: cycles:  10711594532, cycles/i   107115,      127.137 MiB/s
      BLAKE2: cycles:   2256957529, cycles/i    22569,      603.398 MiB/s

Block size:     4096
Iterations:     100000
Implementation: builtin
Units:          perf event: CPU cycles

    NULL-NOP: perf_c:     29649530, perf_c/i      296
 NULL-MEMCPY: perf_c:     59954062, perf_c/i      599,    15137.464 MiB/s
      CRC32C: perf_c:    179009071, perf_c/i     1790,     6929.460 MiB/s
      XXHASH: perf_c:    136413509, perf_c/i     1364,     9982.950 MiB/s
      SHA256: perf_c:  10997356664, perf_c/i   109973,      127.046 MiB/s
      BLAKE2: perf_c:   2379077576, perf_c/i    23790,      588.780 MiB/s

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-01 22:19:38 +02:00
David Sterba 1d4bab875a btrfs-progs: drop "2b" from blake2 in speed test
Internally it's blake2b but for the user facing output or other command
line interfaces let's call it just BLAKE2.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-01 21:17:50 +02:00
David Sterba 5734073b15 btrfs-progs: crypto: fix printf warnings in hash-speedtest
With explicit width the default alignment is to the right, using space
is a gnu extension. Fix the following warnings:

  crypto/hash-speedtest.c: In function ‘main’:
  crypto/hash-speedtest.c:152:15: warning: ' ' flag used with ‘%s’ gnu_printf format [-Wformat=]
    152 |   printf("% 12s: ", c->name);
	|               ^
  crypto/hash-speedtest.c:172:21: warning: ' ' flag used with ‘%u’ gnu_printf format [-Wformat=]
    172 |   printf("%s: % 12llu, %s/i % 8llu",
	|                     ^
  crypto/hash-speedtest.c:172:34: warning: ' ' flag used with ‘%u’ gnu_printf format [-Wformat=]
    172 |   printf("%s: % 12llu, %s/i % 8llu",
	|                                  ^

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-27 11:00:17 +02:00
David Sterba 133dd6c6c3 btrfs-progs: crypto: print throughput in hash-speedtest
Calculate the estimated throughput as a number that's comparable across
machines.

  $ ./hash-speedtest --cycles
  Block size:     4096
  Iterations:     100000
  Implementation: builtin
  Units:          cycles

      NULL-NOP: cycles:     42928902, cycles/i      429
   NULL-MEMCPY: cycles:     73014868, cycles/i      730,    18651.186 MiB/s
	CRC32C: cycles:    182293290, cycles/i     1822,     7470.579 MiB/s
	XXHASH: cycles:    138085981, cycles/i     1380,     9862.272 MiB/s
	SHA256: cycles:  10576270837, cycles/i   105762,      128.764 MiB/s
       BLAKE2b: cycles:   2263761293, cycles/i    22637,      601.585 MiB/s

  $ ./hash-speedtest --time
  Block size:     4096
  Iterations:     100000
  Implementation: builtin
  Units:          nsecs

      NULL-NOP: nsecs:     12164607, nsecs/i      121
   NULL-MEMCPY: nsecs:     20423641, nsecs/i      204,    19095.518 MiB/s
	CRC32C: nsecs:     51972794, nsecs/i      519,     7503.926 MiB/s
	XXHASH: nsecs:     38935164, nsecs/i      389,    10016.651 MiB/s
	SHA256: nsecs:   3030944497, nsecs/i    30309,      128.673 MiB/s
       BLAKE2b: nsecs:    648489262, nsecs/i     6484,      601.398 MiB/s

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-26 23:09:52 +02:00
David Sterba 55bf9b749d btrfs-progs: crypto: add time-based measurement to hash-speedtest
People are interested in measuring the hash performance on non-x86_64
architectures. Add option to do time-based measurements (in nanoseconds)
in case there's no support for clock-based measurements.

  $ ./hash-speedtest --cycles
  Block size:     4096
  Iterations:     100000
  Implementation: builtin
  Units:          cycles

      NULL-NOP: cycles:     43035633, cycles/i      430
   NULL-MEMCPY: cycles:     72478624, cycles/i      724
	CRC32C: cycles:    181712982, cycles/i     1817
	XXHASH: cycles:    136251305, cycles/i     1362
	SHA256: cycles:  10758567410, cycles/i   107585
       BLAKE2b: cycles:   2249704806, cycles/i    22497

  $ ./hash-speedtest --time
  Block size:     4096
  Iterations:     100000
  Implementation: builtin
  Units:          nsecs

      NULL-NOP:  nsecs:     12459033, nsecs/i      124
   NULL-MEMCPY:  nsecs:     20687845, nsecs/i      206
	CRC32C:  nsecs:     52648264, nsecs/i      526
	XXHASH:  nsecs:     39591766, nsecs/i      395
	SHA256:  nsecs:   3079668837, nsecs/i    30796
       BLAKE2b:  nsecs:    644766582, nsecs/i     6447

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-26 22:42:59 +02:00
David Sterba fb98c1e9fc btrfs-progs: crypto: remove unused sha256 definitions
Remove:

- sha1, sha384, sha512 related structures and helpers
- HKDF definitions
- USHA definitions

Keep HMAC.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba 05a92e6424 btrfs-progs: crypto: add test vectors
Add test vectors, a subset without keys as found in linux kernel sources
in crypto/test-mgr.h for all supported hash algorithms.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
Adam Borowski c615287cc0 btrfs-progs: a bunch of typo fixes
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
David Sterba 297c71ee3b btrfs-progs: build: add support for libkcapi as crypto backend
https://github.com/smuellerDD/libkcapi allows user-space to access the
Linux kernel crypto API.  Uses netlink interface and exports easy to use
APIs.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-09 22:19:07 +02:00
David Sterba 82464a03e7 btrfs-progs: add more hash implementation providers
For environments that require certified implementations of cryptographic
primitives allow to select a library providing them. The requirements
are SHA256 and BLAKE2 (with the 2b variant and 256 bit digest).

For now there are two: libgrcrypt and libsodium (openssl does not
provide the BLAKE2b-256). Accellerated versions are typically provided
and automatically selected.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:40 +02:00
Adam Borowski 3d379b1341 btrfs-progs: lots of typo fixes (codespell)
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:38 +02:00
Nikolay Borisov 5b13164cf9 btrfs-progs: fix xxhash on big endian machines
xxhash's state and results are always in little, but in progs after the
hash was calculated it was copied to the final buffer via memcpy,
meaning it'd be parsed as a big endian number on big endian machines.
This is incompatible with the kernel implementation of xxhash which
results in erroneous "checksum didn't match" errors on mount.

Fix it by using put_unaligned_le64 which always ensures the resulting
checksum will be copied in little endian format as the kernel expects
it.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=206835
Fixes: f070ece2e9 ("btrfs-progs: add xxhash64 to mkfs")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:35 +02:00