Commit graph

13 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 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
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
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 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 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 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 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 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