]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Use scrypt from libsodium
authorChris Webb <chris@arachsys.com>
Sat, 23 Oct 2021 15:49:25 +0000 (16:49 +0100)
committerKent Overstreet <kent.overstreet@gmail.com>
Sat, 23 Oct 2021 16:16:08 +0000 (12:16 -0400)
bcachefs-tools has both libscrypt and libsodium as build dependencies,
but libsodium already includes the same scrypt implementation as libscrypt,
originally written by Colin Percival.

Use the libsodium copy, dropping the extra libscrypt dependency.

Explicitly adopt the default scrypt N, r and p values from libscrypt to
avoid unintended changes in the default work parameters for bcachefs.

Signed-off-by: Chris Webb <chris@arachsys.com>
.travis.yml
INSTALL
Makefile
crypto.c
debian/control
default.nix
packaging/bcachefs-tools.spec

index 947997b3a2a8cc8223eb6abc455a20ac91d9276e..e66f0c2a0e9cc3592315ec61bfce726735fcc76a 100644 (file)
@@ -19,7 +19,6 @@ addons:
             - libblkid-dev
             - libkeyutils-dev
             - liblz4-dev
-            - libscrypt-dev
             - libsodium-dev
             - liburcu-dev
             - libzstd-dev
diff --git a/INSTALL b/INSTALL
index f1d38774c7904f9cd468b5870802682a23019926..b4d60bf48db87b0fff8d7653740d0f443131fe2a 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -6,7 +6,6 @@ Dependencies:
  * libblkid
  * libkeyutils
  * liblz4
- * libscrypt
  * libsodium
  * liburcu
  * libuuid
@@ -17,7 +16,7 @@ Dependencies:
 
 Debian (Bullseye or later) and Ubuntu (20.04 or later): you can install these with
     apt install -y pkg-config libaio-dev libblkid-dev libkeyutils-dev \
-        liblz4-dev libscrypt-dev libsodium-dev liburcu-dev libzstd-dev \
+        liblz4-dev libsodium-dev liburcu-dev libzstd-dev \
         uuid-dev zlib1g-dev valgrind libudev-dev git build-essential \
         python3 python3-docutils
 
@@ -25,10 +24,10 @@ Fedora: install the "Development tools" group along with:
     dnf install -y libaio-devel libsodium-devel \
         libblkid-devel libzstd-devel zlib-devel userspace-rcu-devel \
         lz4-devel libuuid-devel valgrind-devel keyutils-libs-devel \
-        libscrypt-devel findutils
+        findutils
 
 Arch: install bcachefs-tools-git from the AUR.
-Or to build from source, install libscrypt from the AUR along with,
+Or to build from source, install build dependencies with
     pacman -S base-devel libaio keyutils libsodium liburcu zstd valgrind
 
 Then, just make && make install
index e4f6820fbc66e9ca63c05a8f066c4566c157edc6..e94419fb021cfc3c654e5d71645f2f89149f6c7f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -73,7 +73,7 @@ endif
 
 CFLAGS+=$(PKGCONFIG_CFLAGS)
 LDLIBS+=$(PKGCONFIG_LDLIBS)
-LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio -ldl
+LDLIBS+=-lm -lpthread -lrt -lkeyutils -laio -ldl
 LDLIBS+=$(EXTRA_LDLIBS)
 
 ifeq ($(PREFIX),/usr)
index 7f7fbd5a337ac8d04585f30cfc468720892d6037..43753a3e8902e019371d5258b37681ff320211b2 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -12,7 +12,7 @@
 
 #include <keyutils.h>
 #include <linux/random.h>
-#include <libscrypt.h>
+#include <sodium/crypto_pwhash_scryptsalsa208sha256.h>
 #include <uuid/uuid.h>
 
 #include "libbcachefs/checksum.h"
@@ -84,12 +84,13 @@ struct bch_key derive_passphrase(struct bch_sb_field_crypt *crypt,
 
        switch (BCH_CRYPT_KDF_TYPE(crypt)) {
        case BCH_KDF_SCRYPT:
-               ret = libscrypt_scrypt((void *) passphrase, strlen(passphrase),
-                                      salt, sizeof(salt),
-                                      1ULL << BCH_KDF_SCRYPT_N(crypt),
-                                      1ULL << BCH_KDF_SCRYPT_R(crypt),
-                                      1ULL << BCH_KDF_SCRYPT_P(crypt),
-                                      (void *) &key, sizeof(key));
+               ret = crypto_pwhash_scryptsalsa208sha256_ll(
+                       (void *) passphrase, strlen(passphrase),
+                       salt, sizeof(salt),
+                       1ULL << BCH_KDF_SCRYPT_N(crypt),
+                       1ULL << BCH_KDF_SCRYPT_R(crypt),
+                       1ULL << BCH_KDF_SCRYPT_P(crypt),
+                       (void *) &key, sizeof(key));
                if (ret)
                        die("scrypt error: %i", ret);
                break;
@@ -170,9 +171,9 @@ void bch_sb_crypt_init(struct bch_sb *sb,
        if (passphrase) {
 
                SET_BCH_CRYPT_KDF_TYPE(crypt, BCH_KDF_SCRYPT);
-               SET_BCH_KDF_SCRYPT_N(crypt, ilog2(SCRYPT_N));
-               SET_BCH_KDF_SCRYPT_R(crypt, ilog2(SCRYPT_r));
-               SET_BCH_KDF_SCRYPT_P(crypt, ilog2(SCRYPT_p));
+               SET_BCH_KDF_SCRYPT_N(crypt, ilog2(16384));
+               SET_BCH_KDF_SCRYPT_R(crypt, ilog2(8));
+               SET_BCH_KDF_SCRYPT_P(crypt, ilog2(16));
 
                struct bch_key passphrase_key = derive_passphrase(crypt, passphrase);
 
index f8752bb778d00823dff9e3737b8cee6c9c44b13a..091161dad7023588741dffcafb7dadfa4b1c9989 100644 (file)
@@ -4,7 +4,7 @@ Section: utils
 Priority: optional
 Standards-Version: 3.9.5
 Build-Depends: debhelper (>= 9), pkg-config, libaio-dev, libblkid-dev,
-       libkeyutils-dev, liblz4-dev, libscrypt-dev, libsodium-dev, liburcu-dev,
+       libkeyutils-dev, liblz4-dev, libsodium-dev, liburcu-dev,
        libzstd-dev, uuid-dev, zlib1g-dev, python3, python3-docutils
 Homepage: https://bcachefs.org/
 
index eee7300f44d24f9df50995d5bfef582808e1aa60..48f2aa93bacabffcd38f70ad59fda0ce64391157 100644 (file)
@@ -5,7 +5,6 @@
 , pkg-config
 , attr
 , libuuid
-, libscrypt
 , libsodium
 , keyutils
 
@@ -71,7 +70,6 @@ stdenv.mkDerivation {
                keyutils # libkeyutils
                lz4 # liblz4
                
-               libscrypt
                libsodium
                liburcu
                libuuid
index 4946cef947dc641e2970433d9e1df30c17e86fe0..00d0fbb47e35e2c6e332ea36bbdaa4685341452f 100644 (file)
@@ -15,7 +15,6 @@ BuildRequires:  keyutils-libs-devel
 BuildRequires:  libaio-devel
 BuildRequires:  libattr-devel
 BuildRequires:  libblkid-devel
-BuildRequires:  libscrypt-devel
 BuildRequires:  libsodium-devel
 BuildRequires:  libtool-ltdl-devel
 BuildRequires:  libuuid-devel
@@ -32,7 +31,6 @@ Requires:   keyutils-libs
 Requires:   libaio
 Requires:   libattr
 Requires:   libblkid
-Requires:   libscrypt
 Requires:   libsodium
 Requires:   libtool-ltdl
 Requires:   libuuid