diff --git a/Cargo.lock b/Cargo.lock index 14985e08..55052f6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,15 +10,15 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitvec" -version = "0.18.4" +version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2838fdd79e8776dbe07a106c784b0f8dda571a21b2750a092cc4cbaa653c8e" +checksum = "98fcd36dda4e17b7d7abc64cb549bf0201f4ab71e00700c798ca7e62ed3761fa" dependencies = [ "funty", "radium", @@ -60,15 +60,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.62" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cfg-if" @@ -84,9 +78,9 @@ checksum = "a2d9162b7289a46e86208d6af2c686ca5bfde445878c41a458a9fac706252d0b" [[package]] name = "curve25519-dalek" -version = "3.0.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8492de420e9e60bc9a1d66e2dbb91825390b738a388606600663fc529b4b307" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", "digest 0.9.0", @@ -110,7 +104,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -122,7 +116,7 @@ dependencies = [ "bitvec", "const-oid", "ff", - "generic-array 0.14.4", + "generic-array 0.14.5", "group", "rand_core 0.5.1", "subtle", @@ -194,9 +188,9 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "funty" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ba62103ce691c2fd80fbae2213dfdda9ce60804973ac6b6e97de818ea7f52c8" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "generic-array" @@ -209,9 +203,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", "version_check", @@ -219,11 +213,11 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "wasi", ] @@ -245,21 +239,15 @@ version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3934640b1efbc660af5889d041854b6985d403771dc4d5fee984e13e8f82f313" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "elliptic-curve", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" -version = "0.2.80" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "num-bigint" @@ -291,6 +279,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -299,23 +293,23 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "openssl" -version = "0.10.30" +version = "0.10.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" dependencies = [ "bitflags", - "cfg-if 0.1.10", + "cfg-if", "foreign-types", - "lazy_static", "libc", + "once_cell", "openssl-sys", ] [[package]] name = "openssl-sys" -version = "0.9.58" +version = "0.9.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" dependencies = [ "autocfg", "cc", @@ -350,39 +344,39 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.7" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] [[package]] name = "radium" -version = "0.4.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64de9a0c5361e034f1aefc9f71a86871ec870e766fe31a009734a989b329286a" +checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" [[package]] name = "rand" @@ -485,15 +479,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.48" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", @@ -502,9 +496,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", @@ -514,15 +508,15 @@ dependencies = [ [[package]] name = "typenum" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "ursa" @@ -573,15 +567,15 @@ version = "0.5.0" [[package]] name = "vcpkg" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" @@ -619,9 +613,9 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "x25519-dalek" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc614d95359fd7afc321b66d2107ede58b246b844cf5d8a0adcca413e439f088" +checksum = "2392b6b94a576b4e2bf3c5b2757d63f10ada8020a2e4d08ac849ebcf6ea8e077" dependencies = [ "curve25519-dalek", "rand_core 0.5.1", @@ -630,18 +624,18 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.1.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f33972566adbd2d3588b0491eb94b98b43695c4ef897903470ede4f3f5a28a" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.0.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3f369ddb18862aba61aa49bf31e74d29f0f162dec753063200e1dc084345d16" +checksum = "65f1a51723ec88c66d5d1fe80c841f17f63587d6691901d66be9bec6c3b51f73" dependencies = [ "proc-macro2", "quote", diff --git a/README.md b/README.md index 8cd6f2bd..a098c68d 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,6 @@ found in Libursa. Ursa uses the following external dependencies: - [openssl 1.1.0j or greater](https://www.openssl.org/source/openssl-1.1.0j.tar.gz) (Written in C) -- [libsodium 1.0.18 or greater](https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz) (Written in C) - [libsecp256k1](https://github.com/bitcoin-core/secp256k1) (Written in C) These dependencies are used when building in the default secure mode. These @@ -104,9 +103,7 @@ when using portable mode for their applications. # Building from Source -Libursa and Libzmix rely on libsodium for the default -secure mode. Please see the following document for specific platform -installations [here](docs/build-environment.md). +Please see the following document for platform-specific installations [here](docs/build-environment.md). ## Libursa diff --git a/docker/centos/Dockerfile b/docker/centos/Dockerfile index 054838ec..b0900f27 100644 --- a/docker/centos/Dockerfile +++ b/docker/centos/Dockerfile @@ -3,18 +3,10 @@ FROM centos:7 LABEL maintainer="Michael Lodder " ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib ENV LD_LIBRARY_PATH /usr/local/lib WORKDIR /root -RUN yum -y update && yum -y install sudo make autoconf libtool curl python3 pkg-config openssl-devel 2>&1 > /dev/null \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure --disable-dependency-tracking \ - && make \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ +RUN yum -y update \ + && yum -y install sudo make autoconf libtool curl python3 pkg-config openssl-devel 2>&1 > /dev/null \ && curl https://sh.rustup.rs -sSf | sh -s -- -y diff --git a/docker/fedora/Dockerfile b/docker/fedora/Dockerfile index 583fa06f..41a36c06 100644 --- a/docker/fedora/Dockerfile +++ b/docker/fedora/Dockerfile @@ -3,18 +3,10 @@ FROM fedora:29 LABEL maintainer="Michael Lodder " ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib ENV LD_LIBRARY_PATH /usr/local/lib WORKDIR /root -RUN yum -y update && yum -y install sudo make autoconf libtool curl python3 pkg-config openssl-devel 2>&1 > /dev/null \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure --disable-dependency-tracking \ - && make \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ +RUN yum -y update \ + && yum -y install sudo make autoconf libtool curl python3 pkg-config openssl-devel 2>&1 > /dev/null \ && curl https://sh.rustup.rs -sSf | sh -s -- -y diff --git a/docker/suse/Dockerfile b/docker/suse/Dockerfile index 57903beb..db01b45a 100644 --- a/docker/suse/Dockerfile +++ b/docker/suse/Dockerfile @@ -3,18 +3,10 @@ FROM opensuse:leap LABEL maintainer="Michael Lodder " ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib ENV LD_LIBRARY_PATH /usr/local/lib WORKDIR /root -RUN zypper --non-interactive update && zypper --non-interactive install sudo make gcc autoconf libtool curl python3 pkg-config openssl-devel 2>&1 > /dev/null \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure \ - && make \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ +RUN zypper --non-interactive update \ + && zypper --non-interactive install sudo make gcc autoconf libtool curl python3 pkg-config openssl-devel 2>&1 > /dev/null \ && curl https://sh.rustup.rs -sSf | sh -s -- -y diff --git a/docker/ubuntu/Dockerfile b/docker/ubuntu/Dockerfile index 542a643f..86ac9c38 100644 --- a/docker/ubuntu/Dockerfile +++ b/docker/ubuntu/Dockerfile @@ -4,8 +4,6 @@ FROM ubuntu:18.04 ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib -ENV SODIUM_INCLUDE_DIR /usr/local/include ENV LD_LIBRARY_PATH /usr/local/lib ARG DEBIAN_FRONTEND=noninteractive @@ -33,13 +31,5 @@ WORKDIR /root RUN cd /usr/lib/x86_64-linux-gnu \ && ln -s libssl.so.1.0.0 libssl.so.10 \ && ln -s libcrypto.so.1.0.0 libcrypto.so.10 \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ && curl https://sh.rustup.rs -sSf | sh -s -- -y \ && cargo install cargo-deb - diff --git a/docker/ubuntu/ursa-bionic.dockerfile b/docker/ubuntu/ursa-bionic.dockerfile index 542a643f..86ac9c38 100644 --- a/docker/ubuntu/ursa-bionic.dockerfile +++ b/docker/ubuntu/ursa-bionic.dockerfile @@ -4,8 +4,6 @@ FROM ubuntu:18.04 ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib -ENV SODIUM_INCLUDE_DIR /usr/local/include ENV LD_LIBRARY_PATH /usr/local/lib ARG DEBIAN_FRONTEND=noninteractive @@ -33,13 +31,5 @@ WORKDIR /root RUN cd /usr/lib/x86_64-linux-gnu \ && ln -s libssl.so.1.0.0 libssl.so.10 \ && ln -s libcrypto.so.1.0.0 libcrypto.so.10 \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ && curl https://sh.rustup.rs -sSf | sh -s -- -y \ && cargo install cargo-deb - diff --git a/docker/ubuntu/ursa-fossa.dockerfile b/docker/ubuntu/ursa-fossa.dockerfile index 81108d69..e9eb127e 100644 --- a/docker/ubuntu/ursa-fossa.dockerfile +++ b/docker/ubuntu/ursa-fossa.dockerfile @@ -4,8 +4,6 @@ FROM ubuntu:20.04 ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib -ENV SODIUM_INCLUDE_DIR /usr/local/include ENV LD_LIBRARY_PATH /usr/local/lib ARG DEBIAN_FRONTEND=noninteractive @@ -33,13 +31,5 @@ WORKDIR /root RUN cd /usr/lib/x86_64-linux-gnu \ && ln -s libssl.so.1.0.0 libssl.so.10 \ && ln -s libcrypto.so.1.0.0 libcrypto.so.10 \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ && curl https://sh.rustup.rs -sSf | sh -s -- -y \ && cargo install cargo-deb - diff --git a/docker/ubuntu/ursa-xenial.dockerfile b/docker/ubuntu/ursa-xenial.dockerfile index 9ba6fa39..1ae08d31 100644 --- a/docker/ubuntu/ursa-xenial.dockerfile +++ b/docker/ubuntu/ursa-xenial.dockerfile @@ -4,8 +4,6 @@ FROM ubuntu:16.04 ENV PATH /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ENV SODIUM_LIB_DIR /usr/local/lib -ENV SODIUM_INCLUDE_DIR /usr/local/include ENV LD_LIBRARY_PATH /usr/local/lib ARG DEBIAN_FRONTEND=noninteractive @@ -33,13 +31,5 @@ WORKDIR /root RUN cd /usr/lib/x86_64-linux-gnu \ && ln -s libssl.so.1.0.0 libssl.so.10 \ && ln -s libcrypto.so.1.0.0 libcrypto.so.10 \ - && curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz \ - && cd libsodium-1.0.18 \ - && ./autogen.sh \ - && ./configure \ - && make install \ - && cd .. \ - && rm -rf libsodium-1.0.18 \ && curl https://sh.rustup.rs -sSf | sh -s -- -y \ && cargo install cargo-deb - diff --git a/docs/build-environment.md b/docs/build-environment.md index c53fb2dc..ba7a0695 100644 --- a/docs/build-environment.md +++ b/docs/build-environment.md @@ -1,104 +1,89 @@ # Setup your build environment -Libursa relies on libsodium for the default secure mode. The instructions below show the necessary steps to configure the environment to build all modes of libursa. There are convienance docker images in the **docker** folder that can be used. + +The instructions below show the necessary steps to configure the environment to build all modes of libursa. There are convenience docker images in the **docker** folder that can be used. ## Fedora, RedHat, CentOS + 1. Install build tools + ```bash yum -y install make autoconf libtool curl python3 pkg-config openssl-devel ``` + 2. Install rust + ```bash curl -sSf https://sh.rustup.rs | sh -s -- -y ``` + 3. Initialize rust environment + ```bash source ~/.cargo/env ``` -4. Compile and install libsodium 1.0.18 -```bash -curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz -cd libsodium-1.0.18 -./autogen.sh -./configure --disable-dependency-tracking -make -sudo make install -``` -5. Add the libsodium environment variable -```bash -export SODIUM_LIB_DIR=/usr/local/lib -export LD_LIBRARY_PATH=/usr/local/lib -``` ## OpenSUSE + 1. Install build tools + ```bash zypper --non-interactive install make gcc autoconf libtool curl python3 pkg-config openssl-devel ``` + 2. Install rust + ```bash curl -sSf https://sh.rustup.rs | sh -s -- -y ``` + 3. Initialize rust environment + ```bash source ~/.cargo/env ``` -4. Compile and install libsodium 1.0.18 -```bash -curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz -cd libsodium-1.0.18 -./autogen.sh -./configure -make -sudo make install -``` -5. Add the libsodium environment variable -```bash -export SODIUM_LIB_DIR=/usr/local/lib -export LD_LIBRARY_PATH=/usr/local/lib -``` ## Debian, Ubuntu + 1. Install build tools + ```bash apt-get install -y cmake autoconf libtool curl python3 pkg-config libssl-dev ``` + 2. Install rust + ```bash curl -sSf https://sh.rustup.rs | sh -s -- -y ``` + 3. Initialize rust environment + ```bash source ~/.cargo/env ``` -4. Compile and install libsodium 1.0.18 -```bash -curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz -cd libsodium-1.0.18 -./autogen.sh -./configure -make -sudo make install -``` -5. Add the libsodium environment variable -```bash -export SODIUM_LIB_DIR=/usr/local/lib -export LD_LIBRARY_PATH=/usr/local/lib -``` ## Mac OS X -1. Install xcode command line tools + +1. Install xcode command line tools + ```bash xcode-select --install ``` + 2. Install rust + ```bash curl -sSf https://sh.rustup.rs | sh -s -- -y ``` + 3. Install brew + ```bash /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` + 4. Install build tools + ```bash brew install pkg-config brew install automake @@ -106,49 +91,35 @@ brew install autoconf brew install cmake brew install libtool ``` + 5. Initialize rust environment + ```bash source ~/.cargo/env ``` -6. Compile and install libsodium 1.0.18 -```bash -curl -fsSL https://github.com/jedisct1/libsodium/archive/1.0.18.tar.gz | tar -xz -cd libsodium-1.0.18 -./autogen.sh -./configure --prefix=/usr/local -make -sudo make install -``` -7. Add the libsodium environment variables -```bash -export SODIUM_LIB_DIR=/usr/local/lib -export SODIUM_INCLUDE_DIR=/usr/local/include -``` ## Windows 10 -1. Download the most recent Visual Studio Community Edition [here](https://visualstudio.microsoft.com/vs/). This is currently the 2019 version. - - Check the box for *Desktop development with C++* - - In the small menu on the right hand side also check the box for *C++/CLI support* +1. Download the most recent Visual Studio Community Edition [here](https://visualstudio.microsoft.com/vs/). This is currently the 2019 version. + - Check the box for _Desktop development with C++_ + - In the small menu on the right hand side also check the box for _C++/CLI support_ 1. Download git-scm for windows [here](https://git-scm.com/download/win) - - Install git for windows using: - - *Use Git from Git Bash Only* so it doesn't change any path settings of the command prompt - - *Checkout as is, commit Unix-style line endings* - - *Use MinTTY* - - Check all the boxes for: - 1. Enable file system caching - 1. Enable Git Credential Manager - 1. Enable symbolic links + - Install git for windows using: + - _Use Git from Git Bash Only_ so it doesn't change any path settings of the command prompt + - _Checkout as is, commit Unix-style line endings_ + - _Use MinTTY_ + - Check all the boxes for: + 1. Enable file system caching + 1. Enable Git Credential Manager + 1. Enable symbolic links 1. Download rust for windows [here](https://rustup.rs) - - Choose option 1: proceed with installation (default) - - Note: if you have antivirus software on your computer, you will likely have to disable it for Rust to correctly install. In addition, it is advisable to install in a terminal that is "run as an administrator." + - Choose option 1: proceed with installation (default) + - Note: if you have antivirus software on your computer, you will likely have to disable it for Rust to correctly install. In addition, it is advisable to install in a terminal that is "run as an administrator." 1. Download the most recent OpenSSL for windows [here](https://slproweb.com/products/Win32OpenSSL.html) - - Choose for "Copy OpenSSL DLLs to:" *The OpenSSL binaries (/bin) directory* + - Choose for "Copy OpenSSL DLLs to:" _The OpenSSL binaries (/bin) directory_ 1. Set the environment variables - - Note that these may vary. If your Ursa build fails because it cannot find OpenSSL, check your environment variables! - - Windows command prompt: - 1. set OPENSSL_DIR "C:\Program Files\OpenSSL-Win64" - 1. set SODIUM_BUILD_STATIC "1" - - Git Bash - 1. export OPENSSL_DIR=/c/Program Files/OpenSSL-Win64 - 1. export SODIUM_BUILD_STATIC=1 + - Note that these may vary. If your Ursa build fails because it cannot find OpenSSL, check your environment variables! + - Windows command prompt: + `set OPENSSL_DIR "C:\Program Files\OpenSSL-Win64"` + - Git Bash + `export OPENSSL_DIR=/c/Program Files/OpenSSL-Win64` diff --git a/libursa/Cargo.toml b/libursa/Cargo.toml index 6a2102d6..b35b5f93 100644 --- a/libursa/Cargo.toml +++ b/libursa/Cargo.toml @@ -68,16 +68,16 @@ aesgcm = ["aead", "aes-gcm", "hex", "rand", "zeroize"] asm = ["encryption_asm", "ffi", "hashes_asm", "serde", "signatures_asm"] benchmarkaescbc = ["openssl"] benchmarkaesgcm = ["openssl"] -benchmarked25519 = ["libsodium-ffi"] +benchmarked25519 = ["ed25519"] benchmarksecp256k1 = ["bitcoinsecp256k1", "openssl"] -benchmarkxchacha20poly1305 = ["libsodium-ffi"] -bls_bls12381 = ["amcl_wrapper", "hex", "hkdf", "zeroize"] +benchmarkxchacha20poly1305 = ["chacha20poly1305"] +bls_bls12381 = ["amcl_wrapper", "hex", "hkdf", "sha2/std", "zeroize"] bls_bn254 = ["amcl", "failure", "log", "rand", "sha2/std", "sha3"] bls_bn254_asm = ["amcl", "failure", "log", "rand", "sha2/asm", "sha3"] -cl = ["amcl", "failure", "glass_pumpkin", "int_traits", "lazy_static", "log", "num-bigint", "num-integer", "num-traits", "rand", "sha2/std", "time"] -cl_native = ["amcl", "failure", "int_traits", "lazy_static", "log", "openssl", "rand", "time"] +cl = ["amcl", "failure", "glass_pumpkin", "int_traits", "lazy_static", "log", "num-bigint", "num-integer", "num-traits", "rand", "sha2/std"] +cl_native = ["amcl", "failure", "int_traits", "lazy_static", "log", "openssl", "rand"] chacha20poly1305 = ["aead", "hex", "rand", "rustchacha20poly1305", "zeroize"] -chacha20poly1305_native = ["aead", "hex", "lazy_static", "libsodium-ffi", "rand", "zeroize"] +chacha20poly1305_native = ["chacha20poly1305"] ecdh_secp256k1 = ["amcl", "arrayref", "failure", "hex", "rand", "rand_chacha", "k256", "sha2/std", "zeroize"] ecdh_secp256k1_native = ["arrayref", "failure", "hex", "log", "rand", "bitcoinsecp256k1", "rand_chacha", "sha2/std", "zeroize"] ecdh_secp256k1_asm = ["arrayref", "failure", "hex", "log", "rand", "bitcoinsecp256k1", "rand_chacha", "sha2/asm", "zeroize"] @@ -87,8 +87,8 @@ ecdsa_secp256k1_asm = ["arrayref", "failure", "hex", "log", "rand", "bitcoinsecp ed25519 = ["arrayref", "ed25519-dalek/std", "ed25519-dalek/u64_backend", "hex", "rand", "rand_chacha", "sha2/std", "zeroize"] ed25519_asm = ["arrayref", "ed25519-dalek/nightly", "ed25519-dalek/simd_backend", "hex", "rand", "rand_chacha", "sha2/asm", "zeroize"] encryption = ["aescbc", "aesgcm", "chacha20poly1305"] -encryption_asm = ["aescbc_native", "aesgcm_native", "chacha20poly1305_native"] -ffi = ["failure", "ffi-support", "logger", "serde", "serde_json", "time"] +encryption_asm = ["aescbc_native", "aesgcm_native", "chacha20poly1305"] +ffi = ["failure", "ffi-support", "logger", "serde", "serde_json"] hashes = ["blake2/std", "sha2/std", "sha3"] hashes_asm = ["blake2/simd_asm", "sha2/asm", "sha3"] kex = ["ecdh_secp256k1", "x25519"] @@ -97,8 +97,8 @@ kex_asm = ["ecdh_secp256k1_asm", "x25519_asm"] logger = ["env_logger", "log"] portable = ["clear_on_drop/no_cc", "encryption", "hashes", "kex", "serde", "signatures", "sharing"] portable_wasm = ["portable", "wasm"] -sharing = ["failure", "glass_pumpkin", "int_traits", "lazy_static", "num-bigint", "num-integer", "num-traits", "log", "rand", "sha2/std", "time"] -sharing_native = ["failure", "int_traits", "lazy_static", "log", "openssl", "rand", "time"] +sharing = ["failure", "glass_pumpkin", "int_traits", "lazy_static", "num-bigint", "num-integer", "num-traits", "log", "rand", "sha2/std"] +sharing_native = ["failure", "int_traits", "lazy_static", "log", "openssl", "rand"] signatures = ["cl", "ed25519", "ecdsa_secp256k1", "bls_bls12381", "bls_bn254"] signatures_native = ["cl_native", "ed25519", "ecdsa_secp256k1_native", "bls_bls12381", "bls_bn254"] signatures_asm = ["cl_native", "ed25519_asm", "ecdsa_secp256k1_asm", "bls_bls12381", "bls_bn254_asm"] @@ -130,7 +130,6 @@ hmac = { version = "0.11.0", optional = true } int_traits = { version = "0.1.1", optional = true } js-sys = { version = "0.3.13", optional = true } lazy_static = { version = "1.4", optional = true } -libsodium-ffi = { version = "0.2.2", optional = true } log = { version = "0.4.8", optional = true } num-bigint = { version = "0.3.0", features = ["rand"], optional = true} num-integer = { version = "=0.1.42", optional = true } @@ -147,7 +146,6 @@ serde_json = { version = "1.0", optional = true } sha2 = { version = "0.9.5", default-features = false, optional = true } sha3 = { version = "0.9.1", optional = true } subtle = { version = "2.3", optional = true } -time = { version = "0.1", optional = true } wasm-bindgen = { version = "0.2", optional = true, features = ["serde-serialize"] } x25519-dalek = { version = "1.1", optional = true, default-features = false } zeroize = { version = "1.1", features = ["zeroize_derive"], optional = true } @@ -155,7 +153,6 @@ zeroize = { version = "1.1", features = ["zeroize_derive"], optional = true } [dev-dependencies] bytebuffer-rs = "0.3.0" criterion = "0.3" -libsodium-ffi = "0.2.2" openssl = "0.10" k256 = { version = "0.9.6"} bitcoinsecp256k1 = { version = "0.19", package = "secp256k1"} diff --git a/libursa/bin/test_ed25519.rs b/libursa/bin/test_ed25519.rs index 21450234..9935b7c3 100644 --- a/libursa/bin/test_ed25519.rs +++ b/libursa/bin/test_ed25519.rs @@ -1,4 +1,3 @@ -extern crate libsodium_ffi as ffi; extern crate ursa; use ursa::signatures::prelude::*; @@ -10,12 +9,11 @@ use std::time::Instant; fn main() { let letters = b"abcdefghijklmnopqrstuvwxyz"; let trials = 200; - println!("Running 3 tests for ed25519 signing of {} messages", trials); - print!("This library - "); + println!("Running test for ed25519 signing of {} messages", trials); io::stdout().flush().unwrap(); let scheme = Ed25519Sha512::new(); let (p, s) = scheme.keypair(None).unwrap(); - let mut now = Instant::now(); + let now = Instant::now(); for _ in 0..trials { let signature = scheme.sign(&letters[..], &s).unwrap(); @@ -23,31 +21,4 @@ fn main() { } let elapsed = now.elapsed(); println!("{}.{:03}", elapsed.as_secs(), elapsed.subsec_millis()); - - let mut signature = [0u8; 64]; - print!("libsodium based ed25519 - "); - io::stdout().flush().unwrap(); - - now = Instant::now(); - for _ in 0..trials { - unsafe { - ffi::crypto_sign_ed25519_detached( - signature.as_mut_ptr() as *mut u8, - 0u64 as *mut u64, - letters.as_ptr() as *const u8, - letters.len() as u64, - s.as_ptr() as *const u8, - ); - - ffi::crypto_sign_ed25519_verify_detached( - signature.as_ptr() as *const u8, - letters.as_ptr() as *const u8, - letters.len() as u64, - p.as_ptr() as *const u8, - ) - }; - } - - let elapsed = now.elapsed(); - println!("{}.{:03}", elapsed.as_secs(), elapsed.subsec_millis()); } diff --git a/libursa/bin/test_xchacha20poly1305.rs b/libursa/bin/test_xchacha20poly1305.rs index 0a90df8e..aa4bacd4 100644 --- a/libursa/bin/test_xchacha20poly1305.rs +++ b/libursa/bin/test_xchacha20poly1305.rs @@ -1,8 +1,5 @@ -extern crate libsodium_ffi as ffi; -use std::{os::raw, ptr}; extern crate ursa; -use ursa::encryption::random_vec; use ursa::encryption::symm::prelude::*; use std::io; @@ -10,19 +7,17 @@ use std::io::Write; use std::time::Instant; fn main() { - unsafe { ffi::sodium_init() }; let aad = b"test_xchacha20poly1305"; let msg = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/-_"; let trials = 2000; println!( - "Running 2 tests for XChaCha20Poly1305 encryption of {} messages", + "Running test for XChaCha20Poly1305 encryption of {} messages", trials ); - print!("This library - "); io::stdout().flush().unwrap(); let encryptor = SymmetricEncryptor::::default(); - let mut now = Instant::now(); + let now = Instant::now(); for _ in 0..trials { let ciphertext = encryptor.encrypt_easy(&aad[..], &msg[..]).unwrap(); @@ -30,70 +25,4 @@ fn main() { } let elapsed = now.elapsed(); println!("{}.{:03}", elapsed.as_secs(), elapsed.subsec_millis()); - - print!("libsodium - "); - io::stdout().flush().unwrap(); - - let key = random_vec(32).unwrap(); - now = Instant::now(); - for _ in 0..trials { - let ciphertext = xchacha20_poly1305_encrypt(key.as_slice(), &aad[..], &msg[..]); - xchacha20_poly1305_decrypt(key.as_slice(), &aad[..], ciphertext.as_slice()).unwrap(); - } - - let elapsed = now.elapsed(); - println!("{}.{:03}", elapsed.as_secs(), elapsed.subsec_millis()); -} - -fn xchacha20_poly1305_encrypt(key: &[u8], aad: &[u8], msg: &[u8]) -> Vec { - let mut nonce = random_vec(24).unwrap(); - let mut ciphertext = Vec::with_capacity(msg.len() + 16); - let mut clen = ciphertext.len() as raw::c_ulonglong; - - unsafe { - ffi::crypto_aead_xchacha20poly1305_ietf_encrypt( - ciphertext.as_mut_ptr(), - &mut clen, - msg.as_ptr(), - msg.len() as raw::c_ulonglong, - aad.as_ptr(), - aad.len() as raw::c_ulonglong, - ptr::null_mut(), - nonce.as_slice().as_ptr(), - key.as_ptr(), - ); - ciphertext.set_len(clen as usize); - } - nonce.extend_from_slice(ciphertext.as_slice()); - nonce -} - -fn xchacha20_poly1305_decrypt(key: &[u8], aad: &[u8], msg: &[u8]) -> Result, &'static str> { - if msg.len() < 16 { - return Err("Invalid tag length"); - } - - let nonce = Vec::from(&msg[..24]); - let ciphertext = Vec::from(&msg[24..]); - let mut plaintext = Vec::with_capacity(ciphertext.len() - 16); - let mut plen = plaintext.len() as raw::c_ulonglong; - - unsafe { - let res = ffi::crypto_aead_xchacha20poly1305_ietf_decrypt( - plaintext.as_mut_ptr(), - &mut plen, - ptr::null_mut(), - ciphertext.as_ptr(), - ciphertext.len() as raw::c_ulonglong, - aad.as_ptr(), - aad.len() as raw::c_ulonglong, - nonce.as_slice().as_ptr(), - key.as_ptr(), - ); - if res != 0 { - return Err("Decryption Error"); - } - plaintext.set_len(plen as usize); - } - Ok(plaintext) } diff --git a/libursa/src/cl/prover.rs b/libursa/src/cl/prover.rs index 470515df..5f459cb0 100644 --- a/libursa/src/cl/prover.rs +++ b/libursa/src/cl/prover.rs @@ -1908,6 +1908,7 @@ mod tests { use super::*; use cl::issuer; use serde_json; + use std::time::Instant; #[test] fn key_correctness_proof_validation_works_for_deserialized_output_v0_4_1_crypto() { @@ -2211,8 +2212,6 @@ mod tests { assert_eq!(mocks::primary_proof(), proof); } - extern crate time; - /* Results: @@ -2246,25 +2245,23 @@ mod tests { println!("Update Proof test -> start"); let n = 100; - let total_start_time = time::get_time(); + let total_start_time = Instant::now(); let cred_schema = issuer::mocks::credential_schema(); let non_cred_schema = issuer::mocks::non_credential_schema(); let (cred_pub_key, cred_priv_key, cred_key_correctness_proof) = issuer::Issuer::new_credential_def(&cred_schema, &non_cred_schema, true).unwrap(); - let start_time = time::get_time(); + let start_time = Instant::now(); let (rev_key_pub, rev_key_priv, mut rev_reg, mut rev_tails_generator) = issuer::Issuer::new_revocation_registry_def(&cred_pub_key, n, false).unwrap(); let simple_tail_accessor = SimpleTailsAccessor::new(&mut rev_tails_generator).unwrap(); - let end_time = time::get_time(); - println!( "Create RevocationRegistry Time: {:?}", - end_time - start_time + Instant::now() - start_time ); let cred_values = issuer::mocks::credential_values(); @@ -2338,24 +2335,21 @@ mod tests { // Update NonRevoc Credential - let start_time = time::get_time(); + let start_time = Instant::now(); witness .update(rev_idx, n, &rev_reg_delta, &simple_tail_accessor) .unwrap(); - let end_time = time::get_time(); - println!( "Update NonRevocation Credential Time: {:?}", - end_time - start_time + Instant::now() - start_time ); - let total_end_time = time::get_time(); println!( "Total Time for {} credentials: {:?}", n, - total_end_time - total_start_time + Instant::now() - total_start_time ); println!("Update Proof test -> end"); diff --git a/libursa/src/encryption/symm/chacha20poly1305_asm.rs b/libursa/src/encryption/symm/chacha20poly1305_asm.rs deleted file mode 100644 index 5d9fdf08..00000000 --- a/libursa/src/encryption/symm/chacha20poly1305_asm.rs +++ /dev/null @@ -1,116 +0,0 @@ -use super::Encryptor; -use aead::{ - generic_array::{ - typenum::{Unsigned, U0, U12, U16, U32, U36}, - GenericArray, - }, - Aead, Error, NewAead, Payload, -}; -#[cfg(feature = "serde")] -use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer}; -use std::{ - os::raw, - ptr, - sync::atomic::{AtomicBool, Ordering}, -}; -use zeroize::Zeroize; - -lazy_static! { - static ref INIT: AtomicBool = AtomicBool::new(false); -} - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct ChaCha20Poly1305 { - key: GenericArray, -} - -impl Encryptor for ChaCha20Poly1305 { - type MinSize = U36; -} - -impl NewAead for ChaCha20Poly1305 { - type KeySize = U32; - - fn new(key: &GenericArray) -> Self { - if !INIT.load(Ordering::Relaxed) { - INIT.store(true, Ordering::Release); - unsafe { - libsodium_ffi::sodium_init(); - } - } - Self { key: *key } - } -} - -impl Aead for ChaCha20Poly1305 { - type NonceSize = U12; - type TagSize = U16; - type CiphertextOverhead = U0; - - fn encrypt<'msg, 'aad>( - &self, - nonce: &GenericArray, - plaintext: impl Into>, - ) -> Result, Error> { - let payload = plaintext.into(); - let mut ciphertext = Vec::with_capacity(payload.msg.len() + Self::TagSize::to_usize()); - let mut clen = ciphertext.len() as raw::c_ulonglong; - - unsafe { - libsodium_ffi::crypto_aead_chacha20poly1305_ietf_encrypt( - ciphertext.as_mut_ptr(), - &mut clen, - payload.msg.as_ptr(), - payload.msg.len() as raw::c_ulonglong, - payload.aad.as_ptr(), - payload.aad.len() as raw::c_ulonglong, - ptr::null_mut(), - nonce.as_slice().as_ptr(), - self.key.as_slice().as_ptr(), - ); - ciphertext.set_len(clen as usize); - } - Ok(ciphertext) - } - - fn decrypt<'msg, 'aad>( - &self, - nonce: &GenericArray, - ciphertext: impl Into>, - ) -> Result, Error> { - let payload = ciphertext.into(); - if payload.msg.len() < Self::TagSize::to_usize() { - return Err(Error); - } - let mut plaintext = Vec::with_capacity(payload.msg.len() - Self::TagSize::to_usize()); - let mut plen = plaintext.len() as raw::c_ulonglong; - - unsafe { - let res = libsodium_ffi::crypto_aead_chacha20poly1305_ietf_decrypt( - plaintext.as_mut_ptr(), - &mut plen, - ptr::null_mut(), - payload.msg.as_ptr(), - payload.msg.len() as raw::c_ulonglong, - payload.aad.as_ptr(), - payload.aad.len() as raw::c_ulonglong, - nonce.as_slice().as_ptr(), - self.key.as_slice().as_ptr(), - ); - if res != 0 { - return Err(Error); - } - plaintext.set_len(plen as usize); - } - Ok(plaintext) - } -} - -default_impl!(ChaCha20Poly1305); -drop_impl!(ChaCha20Poly1305); -#[cfg(feature = "serde")] -serialize_impl!(ChaCha20Poly1305, ChaCha20Poly1305Visitor); -#[cfg(test)] -mod tests { - tests_impl!(ChaCha20Poly1305); -} diff --git a/libursa/src/encryption/symm/mod.rs b/libursa/src/encryption/symm/mod.rs index 0eda1e73..a82db175 100644 --- a/libursa/src/encryption/symm/mod.rs +++ b/libursa/src/encryption/symm/mod.rs @@ -29,7 +29,7 @@ //! ``` //! //! AES-GCM uses OpenSSL for native mode and the crate `aes-gcm` for portable mode. -//! XCHACHA20POLY1305 uses Libsodium for native mode and the crate `chacha20poly1305` for portable mode. +//! CHACHA20POLY1305 and XCHACHA20POLY1305 use the crate `chacha20poly1305`. //! //! More ciphers will added as needed like AES-GCM-SIV or [XCHACHA20POLY1305-SIV](https://tools.ietf.org/id/draft-madden-generalised-siv-00.html) //! where using poly1305 instead of HMAC might be appropriate. @@ -576,20 +576,10 @@ pub mod aesgcm; #[path = "aesgcm.rs"] pub mod aesgcm; -#[cfg(feature = "chacha20poly1305_native")] -#[path = "chacha20poly1305_asm.rs"] -pub mod chacha20poly1305; - #[cfg(feature = "chacha20poly1305")] -#[path = "chacha20poly1305.rs"] pub mod chacha20poly1305; -#[cfg(feature = "chacha20poly1305_native")] -#[path = "xchacha20poly1305_asm.rs"] -pub mod xchacha20poly1305; - #[cfg(feature = "chacha20poly1305")] -#[path = "xchacha20poly1305.rs"] pub mod xchacha20poly1305; pub mod prelude { @@ -597,9 +587,9 @@ pub mod prelude { pub use super::aescbc::{Aes128CbcHmac256, Aes256CbcHmac512}; #[cfg(any(feature = "aesgcm", feature = "aesgcm_native"))] pub use super::aesgcm::{Aes128Gcm, Aes256Gcm}; - #[cfg(any(feature = "chacha20poly1305", feature = "chacha20poly1305_native"))] + #[cfg(feature = "chacha20poly1305")] pub use super::chacha20poly1305::ChaCha20Poly1305; - #[cfg(any(feature = "chacha20poly1305", feature = "chacha20poly1305_native"))] + #[cfg(feature = "chacha20poly1305")] pub use super::xchacha20poly1305::XChaCha20Poly1305; pub use super::{DynEncryptor, Encryptor, EncryptorType, SymmetricEncryptor}; } diff --git a/libursa/src/encryption/symm/xchacha20poly1305_asm.rs b/libursa/src/encryption/symm/xchacha20poly1305_asm.rs deleted file mode 100644 index 92576f09..00000000 --- a/libursa/src/encryption/symm/xchacha20poly1305_asm.rs +++ /dev/null @@ -1,116 +0,0 @@ -use super::Encryptor; -use aead::{ - generic_array::{ - typenum::{Unsigned, U0, U16, U24, U32, U48}, - GenericArray, - }, - Aead, Error, NewAead, Payload, -}; -#[cfg(feature = "serde")] -use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer}; -use std::{ - os::raw, - ptr, - sync::atomic::{AtomicBool, Ordering}, -}; -use zeroize::Zeroize; - -lazy_static! { - static ref INIT: AtomicBool = AtomicBool::new(false); -} - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct XChaCha20Poly1305 { - key: GenericArray, -} - -impl Encryptor for XChaCha20Poly1305 { - type MinSize = U48; -} - -impl NewAead for XChaCha20Poly1305 { - type KeySize = U32; - - fn new(key: &GenericArray) -> Self { - if !INIT.load(Ordering::Relaxed) { - INIT.store(true, Ordering::Release); - unsafe { - libsodium_ffi::sodium_init(); - } - } - Self { key: *key } - } -} - -impl Aead for XChaCha20Poly1305 { - type NonceSize = U24; - type TagSize = U16; - type CiphertextOverhead = U0; - - fn encrypt<'msg, 'aad>( - &self, - nonce: &GenericArray, - plaintext: impl Into>, - ) -> Result, Error> { - let payload = plaintext.into(); - let mut ciphertext = Vec::with_capacity(payload.msg.len() + Self::TagSize::to_usize()); - let mut clen = ciphertext.len() as raw::c_ulonglong; - - unsafe { - libsodium_ffi::crypto_aead_xchacha20poly1305_ietf_encrypt( - ciphertext.as_mut_ptr(), - &mut clen, - payload.msg.as_ptr(), - payload.msg.len() as raw::c_ulonglong, - payload.aad.as_ptr(), - payload.aad.len() as raw::c_ulonglong, - ptr::null_mut(), - nonce.as_slice().as_ptr(), - self.key.as_slice().as_ptr(), - ); - ciphertext.set_len(clen as usize); - } - Ok(ciphertext) - } - - fn decrypt<'msg, 'aad>( - &self, - nonce: &GenericArray, - ciphertext: impl Into>, - ) -> Result, Error> { - let payload = ciphertext.into(); - if payload.msg.len() < Self::TagSize::to_usize() { - return Err(Error); - } - let mut plaintext = Vec::with_capacity(payload.msg.len() - Self::TagSize::to_usize()); - let mut plen = plaintext.len() as raw::c_ulonglong; - - unsafe { - let res = libsodium_ffi::crypto_aead_xchacha20poly1305_ietf_decrypt( - plaintext.as_mut_ptr(), - &mut plen, - ptr::null_mut(), - payload.msg.as_ptr(), - payload.msg.len() as raw::c_ulonglong, - payload.aad.as_ptr(), - payload.aad.len() as raw::c_ulonglong, - nonce.as_slice().as_ptr(), - self.key.as_slice().as_ptr(), - ); - if res != 0 { - return Err(Error); - } - plaintext.set_len(plen as usize); - } - Ok(plaintext) - } -} - -default_impl!(XChaCha20Poly1305); -drop_impl!(XChaCha20Poly1305); -#[cfg(feature = "serde")] -serialize_impl!(XChaCha20Poly1305, XChaCha20Poly1305Visitor); -#[cfg(test)] -mod tests { - tests_impl!(XChaCha20Poly1305); -} diff --git a/libursa/src/ffi/logger.rs b/libursa/src/ffi/logger.rs index f6234976..513c2baf 100644 --- a/libursa/src/ffi/logger.rs +++ b/libursa/src/ffi/logger.rs @@ -4,7 +4,6 @@ use errors::prelude::*; use ffi::ErrorCode; extern crate log; -extern crate time; use utils::ctypes::*; use utils::logger::{EnabledCB, FlushCB, HLCryptoDefaultLogger, HLCryptoLogger, LogCB}; diff --git a/libursa/src/ffi/signatures/ed25519.rs b/libursa/src/ffi/signatures/ed25519.rs index afa5da37..864fef2a 100644 --- a/libursa/src/ffi/signatures/ed25519.rs +++ b/libursa/src/ffi/signatures/ed25519.rs @@ -382,10 +382,10 @@ mod tests { let pk_wrapper = ByteArray::from(&pk); let res = ursa_ed25519_get_public_key(&pk_wrapper, &mut public_key, &mut error); assert_eq!(res, 0); - assert_eq!( - error.get_message().into_string(), - "KeyGenError(signature error)".to_string() - ); + assert!(error + .get_message() + .as_str() + .starts_with("KeyGenError(signature error")); let seed = ByteArray::default(); let res = ursa_ed25519_keypair_from_seed(&seed, &mut public_key, &mut private_key, &mut error); diff --git a/libursa/src/lib.rs b/libursa/src/lib.rs index 71d6f90d..dd962f2c 100644 --- a/libursa/src/lib.rs +++ b/libursa/src/lib.rs @@ -25,8 +25,6 @@ extern crate block_modes; extern crate block_padding; #[cfg(feature = "hmac")] extern crate hmac; -#[cfg(any(test, feature = "libsodium-ffi"))] -extern crate libsodium_ffi; #[cfg(any(test, feature = "openssl"))] extern crate openssl; #[cfg(feature = "rand")] @@ -219,6 +217,10 @@ pub mod signatures; #[cfg(feature = "wasm")] pub mod wasm; +#[cfg(feature = "chacha20poly1305_native")] +#[warn(dead_code)] +const REMOVED: &str = "Support for libsodium as a backend has been removed. The chacha20poly1305_native feature is currently equivalent to chacha20poly1305, and deprecated."; + pub type CryptoResult = Result; #[derive(Debug)] diff --git a/libursa/src/signatures/ed25519.rs b/libursa/src/signatures/ed25519.rs index f1134509..3eb7a02b 100644 --- a/libursa/src/signatures/ed25519.rs +++ b/libursa/src/signatures/ed25519.rs @@ -170,7 +170,6 @@ mod test { use super::super::{SignatureScheme, Signer}; use super::*; use keys::{KeyGenOption, PrivateKey, PublicKey}; - use libsodium_ffi as ffi; const MESSAGE_1: &[u8] = b"This is a dummy message for use with tests"; const SIGNATURE_1: &str = "451b5b8e8725321541954997781de51f4142e4a56bab68d24f6a6b92615de5eefb74134138315859a32c7cf5fe5a488bc545e2e08e5eedfd1fb10188d532d808"; @@ -215,18 +214,6 @@ mod test { let result = scheme.verify(&MESSAGE_1, hex::decode(SIGNATURE_1).unwrap().as_slice(), &p); assert!(result.is_ok()); assert!(result.unwrap()); - - //Check if signatures produced here can be verified by libsodium - let signature = hex::decode(SIGNATURE_1).unwrap(); - let res = unsafe { - ffi::crypto_sign_ed25519_verify_detached( - signature.as_slice().as_ptr() as *const u8, - MESSAGE_1.as_ptr() as *const u8, - MESSAGE_1.len() as u64, - p.as_ptr() as *const u8, - ) - }; - assert_eq!(res, 0); } #[test] @@ -245,22 +232,6 @@ mod test { assert_eq!(sig.len(), SIGNATURE_SIZE); assert_eq!(hex::encode(sig.as_slice()), SIGNATURE_1); - - //Check if libsodium signs the message and this module still can verify it - //And that private keys can sign with other libraries - let mut signature = [0u8; ffi::crypto_sign_ed25519_BYTES as usize]; - unsafe { - ffi::crypto_sign_ed25519_detached( - signature.as_mut_ptr() as *mut u8, - 0u64 as *mut u64, - MESSAGE_1.as_ptr() as *const u8, - MESSAGE_1.len() as u64, - s.as_ptr() as *const u8, - ) - }; - let result = scheme.verify(&MESSAGE_1, &signature, &p); - assert!(result.is_ok()); - assert!(result.unwrap()); } Err(e) => assert!(false, "{}", e), }