diff --git a/Cargo.lock b/Cargo.lock index eb153446b..f82baa989 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,7 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -300,13 +300,13 @@ name = "bzip2-sys" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -365,7 +365,7 @@ name = "clear_on_drop" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1249,7 +1249,7 @@ name = "libloading" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1259,7 +1259,7 @@ version = "5.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bindgen 0.47.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1367,7 +1367,7 @@ name = "miniz_oxide_c_api" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1456,7 +1456,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1554,7 +1554,7 @@ name = "openssl-sys" version = "0.9.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1896,7 +1896,7 @@ name = "reed-solomon-erasure" version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1967,7 +1967,7 @@ name = "ring" version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2211,6 +2211,7 @@ dependencies = [ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "solana-budget-api 0.16.0", "solana-budget-program 0.16.0", + "solana-chacha-sys 0.16.0", "solana-client 0.16.0", "solana-config-program 0.16.0", "solana-drone 0.16.0", @@ -2348,6 +2349,13 @@ dependencies = [ "solana-sdk 0.16.0", ] +[[package]] +name = "solana-chacha-sys" +version = "0.16.0" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "solana-client" version = "0.16.0" @@ -2918,7 +2926,7 @@ name = "sys-info" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3491,7 +3499,7 @@ dependencies = [ "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" "checksum bzip2-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6584aa36f5ad4c9247f5323b0a42f37802b37a836f0ad87084d7a33961abe25f" -"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" +"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" "checksum cexpr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "644d693ecfa91955ed32dcc7eda4914e1be97a641fb6f0645a37348e20b230da" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" diff --git a/Cargo.toml b/Cargo.toml index 646bf91e2..352ef9194 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "bench-exchange", "bench-streamer", "bench-tps", + "chacha-sys", "client", "core", "drone", diff --git a/bench-exchange/Cargo.toml b/bench-exchange/Cargo.toml index 5e60402a6..58f3e0996 100644 --- a/bench-exchange/Cargo.toml +++ b/bench-exchange/Cargo.toml @@ -38,4 +38,4 @@ ws = "0.8.1" [features] cuda = ["solana/cuda"] -erasure = [] + diff --git a/bench-streamer/Cargo.toml b/bench-streamer/Cargo.toml index 84b873f0f..b753e1fb7 100644 --- a/bench-streamer/Cargo.toml +++ b/bench-streamer/Cargo.toml @@ -15,4 +15,4 @@ solana-netutil = { path = "../netutil", version = "0.16.0" } [features] cuda = ["solana/cuda"] -erasure = [] + diff --git a/bench-tps/Cargo.toml b/bench-tps/Cargo.toml index 27fef50cf..03720311c 100644 --- a/bench-tps/Cargo.toml +++ b/bench-tps/Cargo.toml @@ -23,4 +23,4 @@ solana-sdk = { path = "../sdk", version = "0.16.0" } [features] cuda = ["solana/cuda"] -erasure = [] + diff --git a/chacha-sys/.gitignore b/chacha-sys/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/chacha-sys/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/chacha-sys/Cargo.toml b/chacha-sys/Cargo.toml new file mode 100644 index 000000000..d30cea957 --- /dev/null +++ b/chacha-sys/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "solana-chacha-sys" +version = "0.16.0" +description = "Solana chacha-sys" +authors = ["Solana Maintainers "] +repository = "https://github.com/solana-labs/solana" +homepage = "https://solana.com/" +license = "Apache-2.0" +edition = "2018" + +[build-dependencies] +cc = "1.0.37" diff --git a/chacha-sys/build.rs b/chacha-sys/build.rs new file mode 100644 index 000000000..9d4b546f4 --- /dev/null +++ b/chacha-sys/build.rs @@ -0,0 +1,8 @@ +extern crate cc; + +fn main() { + cc::Build::new() + .file("cpu-crypt/chacha20_core.c") + .file("cpu-crypt/chacha_cbc.c") + .compile("libcpu-crypt"); +} diff --git a/chacha-sys/cpu-crypt/.gitignore b/chacha-sys/cpu-crypt/.gitignore new file mode 100644 index 000000000..151080d12 --- /dev/null +++ b/chacha-sys/cpu-crypt/.gitignore @@ -0,0 +1 @@ +release/ diff --git a/chacha-sys/cpu-crypt/Makefile b/chacha-sys/cpu-crypt/Makefile new file mode 100644 index 000000000..53a705af2 --- /dev/null +++ b/chacha-sys/cpu-crypt/Makefile @@ -0,0 +1,25 @@ +V:=debug + +LIB:=cpu-crypt + +CFLAGS_common:=-Wall -Werror -pedantic -fPIC +CFLAGS_release:=-march=native -O3 $(CFLAGS_common) +CFLAGS_debug:=-g $(CFLAGS_common) +CFLAGS:=$(CFLAGS_$V) + +all: $V/lib$(LIB).a + +$V/chacha20_core.o: chacha20_core.c chacha.h + @mkdir -p $(@D) + $(CC) $(CFLAGS) -c $< -o $@ + +$V/chacha_cbc.o: chacha_cbc.c chacha.h + @mkdir -p $(@D) + $(CC) $(CFLAGS) -c $< -o $@ + +$V/lib$(LIB).a: $V/chacha20_core.o $V/chacha_cbc.o + $(AR) rcs $@ $^ + +.PHONY:clean +clean: + rm -rf $V diff --git a/chacha-sys/cpu-crypt/chacha.h b/chacha-sys/cpu-crypt/chacha.h new file mode 100644 index 000000000..ca3fc31a6 --- /dev/null +++ b/chacha-sys/cpu-crypt/chacha.h @@ -0,0 +1,35 @@ +#ifndef HEADER_CHACHA_H +# define HEADER_CHACHA_H + +#include +#include +# include +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned int u32; + +#define CHACHA_KEY_SIZE 32 +#define CHACHA_NONCE_SIZE 12 +#define CHACHA_BLOCK_SIZE 64 +#define CHACHA_ROUNDS 500 + +void chacha20_encrypt(const u32 input[16], + unsigned char output[64], + int num_rounds); + +void chacha20_encrypt_ctr(const uint8_t *in, uint8_t *out, size_t in_len, + const uint8_t key[CHACHA_KEY_SIZE], const uint8_t nonce[CHACHA_NONCE_SIZE], + uint32_t counter); + +void chacha20_cbc128_encrypt(const unsigned char* in, unsigned char* out, + uint32_t len, const uint8_t* key, + unsigned char* ivec); + + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/chacha-sys/cpu-crypt/chacha20_core.c b/chacha-sys/cpu-crypt/chacha20_core.c new file mode 100644 index 000000000..7360ff050 --- /dev/null +++ b/chacha-sys/cpu-crypt/chacha20_core.c @@ -0,0 +1,102 @@ +#include "chacha.h" + +#define ROTL32(v, n) (((v) << (n)) | ((v) >> (32 - (n)))) + +#define ROTATE(v, c) ROTL32((v), (c)) + +#define XOR(v, w) ((v) ^ (w)) + +#define PLUS(x, y) ((x) + (y)) + +#define U32TO8_LITTLE(p, v) \ +{ (p)[0] = ((v) ) & 0xff; (p)[1] = ((v) >> 8) & 0xff; \ + (p)[2] = ((v) >> 16) & 0xff; (p)[3] = ((v) >> 24) & 0xff; } + +#define U8TO32_LITTLE(p) \ + (((u32)((p)[0]) ) | ((u32)((p)[1]) << 8) | \ + ((u32)((p)[2]) << 16) | ((u32)((p)[3]) << 24) ) + +#define QUARTERROUND(a,b,c,d) \ + x[a] = PLUS(x[a],x[b]); x[d] = ROTATE(XOR(x[d],x[a]),16); \ + x[c] = PLUS(x[c],x[d]); x[b] = ROTATE(XOR(x[b],x[c]),12); \ + x[a] = PLUS(x[a],x[b]); x[d] = ROTATE(XOR(x[d],x[a]), 8); \ + x[c] = PLUS(x[c],x[d]); x[b] = ROTATE(XOR(x[b],x[c]), 7); + +// sigma contains the ChaCha constants, which happen to be an ASCII string. +static const uint8_t sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', + '2', '-', 'b', 'y', 't', 'e', ' ', 'k' }; + +void chacha20_encrypt(const u32 input[16], + unsigned char output[64], + int num_rounds) +{ + u32 x[16]; + int i; + memcpy(x, input, sizeof(u32) * 16); + for (i = num_rounds; i > 0; i -= 2) { + QUARTERROUND( 0, 4, 8,12) + QUARTERROUND( 1, 5, 9,13) + QUARTERROUND( 2, 6,10,14) + QUARTERROUND( 3, 7,11,15) + QUARTERROUND( 0, 5,10,15) + QUARTERROUND( 1, 6,11,12) + QUARTERROUND( 2, 7, 8,13) + QUARTERROUND( 3, 4, 9,14) + } + for (i = 0; i < 16; ++i) { + x[i] = PLUS(x[i], input[i]); + } + for (i = 0; i < 16; ++i) { + U32TO8_LITTLE(output + 4 * i, x[i]); + } +} + +void chacha20_encrypt_ctr(const uint8_t *in, uint8_t *out, size_t in_len, + const uint8_t key[CHACHA_KEY_SIZE], + const uint8_t nonce[CHACHA_NONCE_SIZE], + uint32_t counter) +{ + uint32_t input[16]; + uint8_t buf[64]; + size_t todo, i; + + input[0] = U8TO32_LITTLE(sigma + 0); + input[1] = U8TO32_LITTLE(sigma + 4); + input[2] = U8TO32_LITTLE(sigma + 8); + input[3] = U8TO32_LITTLE(sigma + 12); + + input[4] = U8TO32_LITTLE(key + 0); + input[5] = U8TO32_LITTLE(key + 4); + input[6] = U8TO32_LITTLE(key + 8); + input[7] = U8TO32_LITTLE(key + 12); + + input[8] = U8TO32_LITTLE(key + 16); + input[9] = U8TO32_LITTLE(key + 20); + input[10] = U8TO32_LITTLE(key + 24); + input[11] = U8TO32_LITTLE(key + 28); + + input[12] = counter; + input[13] = U8TO32_LITTLE(nonce + 0); + input[14] = U8TO32_LITTLE(nonce + 4); + input[15] = U8TO32_LITTLE(nonce + 8); + + while (in_len > 0) { + todo = sizeof(buf); + if (in_len < todo) { + todo = in_len; + } + + chacha20_encrypt(input, buf, 20); + for (i = 0; i < todo; i++) { + out[i] = in[i] ^ buf[i]; + } + + out += todo; + in += todo; + in_len -= todo; + + input[12]++; + } +} + + diff --git a/chacha-sys/cpu-crypt/chacha_cbc.c b/chacha-sys/cpu-crypt/chacha_cbc.c new file mode 100644 index 000000000..c9379eee1 --- /dev/null +++ b/chacha-sys/cpu-crypt/chacha_cbc.c @@ -0,0 +1,72 @@ +#include "chacha.h" + +#if !defined(STRICT_ALIGNMENT) && !defined(PEDANTIC) +# define STRICT_ALIGNMENT 0 +#endif + +void chacha20_cbc128_encrypt(const unsigned char* in, unsigned char* out, + uint32_t len, const uint8_t* key, + unsigned char* ivec) +{ + size_t n; + unsigned char *iv = ivec; + + if (len == 0) { + return; + } + +#if !defined(OPENSSL_SMALL_FOOTPRINT) + if (STRICT_ALIGNMENT && + ((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) { + while (len >= CHACHA_BLOCK_SIZE) { + for (n = 0; n < CHACHA_BLOCK_SIZE; ++n) { + out[n] = in[n] ^ iv[n]; + //printf("%x ", out[n]); + } + chacha20_encrypt((const u32*)out, out, CHACHA_ROUNDS); + iv = out; + len -= CHACHA_BLOCK_SIZE; + in += CHACHA_BLOCK_SIZE; + out += CHACHA_BLOCK_SIZE; + } + } else { + while (len >= CHACHA_BLOCK_SIZE) { + for (n = 0; n < CHACHA_BLOCK_SIZE; n += sizeof(size_t)) { + *(size_t *)(out + n) = + *(size_t *)(in + n) ^ *(size_t *)(iv + n); + //printf("%zu ", *(size_t *)(iv + n)); + } + chacha20_encrypt((const u32*)out, out, CHACHA_ROUNDS); + iv = out; + len -= CHACHA_BLOCK_SIZE; + in += CHACHA_BLOCK_SIZE; + out += CHACHA_BLOCK_SIZE; + } + } +#endif + while (len) { + for (n = 0; n < CHACHA_BLOCK_SIZE && n < len; ++n) { + out[n] = in[n] ^ iv[n]; + } + for (; n < CHACHA_BLOCK_SIZE; ++n) { + out[n] = iv[n]; + } + chacha20_encrypt((const u32*)out, out, CHACHA_ROUNDS); + iv = out; + if (len <= CHACHA_BLOCK_SIZE) { + break; + } + len -= CHACHA_BLOCK_SIZE; + in += CHACHA_BLOCK_SIZE; + out += CHACHA_BLOCK_SIZE; + } + memcpy(ivec, iv, CHACHA_BLOCK_SIZE); + +} + +void chacha20_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t in_len, + const uint8_t key[CHACHA_KEY_SIZE], uint8_t* ivec) +{ + chacha20_cbc128_encrypt(in, out, in_len, key, ivec); +} + diff --git a/chacha-sys/src/lib.rs b/chacha-sys/src/lib.rs new file mode 100644 index 000000000..9a0b3f7b9 --- /dev/null +++ b/chacha-sys/src/lib.rs @@ -0,0 +1,21 @@ +extern "C" { + fn chacha20_cbc_encrypt( + input: *const u8, + output: *mut u8, + in_len: usize, + key: *const u8, + ivec: *mut u8, + ); +} + +pub fn chacha_cbc_encrypt(input: &[u8], output: &mut [u8], key: &[u8], ivec: &mut [u8]) { + unsafe { + chacha20_cbc_encrypt( + input.as_ptr(), + output.as_mut_ptr(), + input.len(), + key.as_ptr(), + ivec.as_mut_ptr(), + ); + } +} diff --git a/ci/test-stable.sh b/ci/test-stable.sh index d70daaf3a..f242cdc3d 100755 --- a/ci/test-stable.sh +++ b/ci/test-stable.sh @@ -55,7 +55,7 @@ test-stable-perf) --no-default-features --features=bpf_c,bpf_rust # Run root package tests with these features - ROOT_FEATURES=erasure,chacha + ROOT_FEATURES= if [[ $(uname) = Darwin ]]; then ./build-perf-libs.sh else diff --git a/core/Cargo.toml b/core/Cargo.toml index 3c845f82e..6b4330013 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,9 +14,7 @@ edition = "2018" codecov = { repository = "solana-labs/solana", branch = "master", service = "github" } [features] -chacha = [] cuda = [] -erasure = [] kvstore = ["solana-kvstore"] [dependencies] @@ -49,6 +47,7 @@ serde_derive = "1.0.92" serde_json = "1.0.39" solana-budget-api = { path = "../programs/budget_api", version = "0.16.0" } solana-budget-program = { path = "../programs/budget_program", version = "0.16.0" } +solana-chacha-sys = { path = "../chacha-sys", version = "0.16.0" } solana-client = { path = "../client", version = "0.16.0" } solana-config-program = { path = "../programs/config_program", version = "0.16.0" } solana-drone = { path = "../drone", version = "0.16.0" } diff --git a/core/build.rs b/core/build.rs index 9e55e08c3..917232e91 100644 --- a/core/build.rs +++ b/core/build.rs @@ -13,10 +13,9 @@ fn main() { }; let perf_libs_dir = perf_libs_dir.to_str().unwrap(); - let chacha = !env::var("CARGO_FEATURE_CHACHA").is_err(); let cuda = !env::var("CARGO_FEATURE_CUDA").is_err(); - if chacha || cuda { + if cuda { // Ensure `perf_libs_dir` exists. It's been observed that // a cargo:rerun-if-changed= directive with a non-existent // directory triggers a rebuild on every |cargo build| invocation @@ -29,9 +28,6 @@ fn main() { println!("cargo:rerun-if-changed={}", perf_libs_dir); println!("cargo:rustc-link-search=native={}", perf_libs_dir); } - if chacha { - println!("cargo:rerun-if-changed={}/libcpu-crypt.a", perf_libs_dir); - } if cuda { let cuda_home = match env::var("CUDA_HOME") { Ok(cuda_home) => cuda_home, diff --git a/core/src/chacha.rs b/core/src/chacha.rs index a07342337..7bb957ef8 100644 --- a/core/src/chacha.rs +++ b/core/src/chacha.rs @@ -6,32 +6,11 @@ use std::io::{BufWriter, Write}; use std::path::Path; use std::sync::Arc; +pub use solana_chacha_sys::chacha_cbc_encrypt; + pub const CHACHA_BLOCK_SIZE: usize = 64; pub const CHACHA_KEY_SIZE: usize = 32; -#[link(name = "cpu-crypt")] -extern "C" { - fn chacha20_cbc_encrypt( - input: *const u8, - output: *mut u8, - in_len: usize, - key: *const u8, - ivec: *mut u8, - ); -} - -pub fn chacha_cbc_encrypt(input: &[u8], output: &mut [u8], key: &[u8], ivec: &mut [u8]) { - unsafe { - chacha20_cbc_encrypt( - input.as_ptr(), - output.as_mut_ptr(), - input.len(), - key.as_ptr(), - ivec.as_mut_ptr(), - ); - } -} - pub fn chacha_cbc_encrypt_ledger( blocktree: &Arc, slice: u64, diff --git a/core/src/lib.rs b/core/src/lib.rs index 5350b4adb..7e78c174a 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -9,9 +9,8 @@ pub mod bank_forks; pub mod banking_stage; pub mod blob_fetch_stage; pub mod broadcast_stage; -#[cfg(feature = "chacha")] pub mod chacha; -#[cfg(all(feature = "chacha", feature = "cuda"))] +#[cfg(cuda)] pub mod chacha_cuda; pub mod cluster_info_vote_listener; #[macro_use] @@ -75,7 +74,6 @@ pub mod window_service; extern crate solana_budget_program; #[cfg(test)] -#[cfg(any(feature = "chacha", feature = "cuda"))] #[macro_use] extern crate hex_literal; diff --git a/core/src/replicator.rs b/core/src/replicator.rs index 51d9857d3..1005becad 100644 --- a/core/src/replicator.rs +++ b/core/src/replicator.rs @@ -1,6 +1,5 @@ use crate::blob_fetch_stage::BlobFetchStage; use crate::blocktree::Blocktree; -#[cfg(feature = "chacha")] use crate::chacha::{chacha_cbc_encrypt_ledger, CHACHA_BLOCK_SIZE}; use crate::cluster_info::{ClusterInfo, Node}; use crate::contact_info::ContactInfo; @@ -59,9 +58,7 @@ pub struct Replicator { ledger_data_file_encrypted: PathBuf, sampling_offsets: Vec, sha_state: Hash, - #[cfg(feature = "chacha")] num_chacha_blocks: usize, - #[cfg(feature = "chacha")] blocktree: Arc, } @@ -296,9 +293,7 @@ impl Replicator { ledger_data_file_encrypted: PathBuf::default(), sampling_offsets: vec![], sha_state: Hash::default(), - #[cfg(feature = "chacha")] num_chacha_blocks: 0, - #[cfg(feature = "chacha")] blocktree, }) } @@ -375,7 +370,6 @@ impl Replicator { let ledger_path = Path::new(&self.ledger_path); self.ledger_data_file_encrypted = ledger_path.join("ledger.enc"); - #[cfg(feature = "chacha")] { let mut ivec = [0u8; 64]; ivec.copy_from_slice(&self.signature.to_bytes()); @@ -400,10 +394,6 @@ impl Replicator { fn create_sampling_offsets(&mut self) { self.sampling_offsets.clear(); - #[cfg(not(feature = "chacha"))] - self.sampling_offsets.push(0); - - #[cfg(feature = "chacha")] { use crate::storage_stage::NUM_STORAGE_SAMPLES; use rand::SeedableRng; diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index 0624c91ff..bcdead33d 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -4,7 +4,7 @@ use crate::bank_forks::BankForks; use crate::blocktree::Blocktree; -#[cfg(all(feature = "chacha", feature = "cuda"))] +#[cfg(cuda)] use crate::chacha_cuda::chacha_cbc_encrypt_file_many_keys; use crate::cluster_info::ClusterInfo; use crate::result::{Error, Result}; @@ -336,7 +336,7 @@ impl StorageStage { // TODO: cuda required to generate the reference values // but if it is missing, then we need to take care not to // process storage mining results. - #[cfg(all(feature = "chacha", feature = "cuda"))] + #[cfg(cuda)] { // Lock the keys, since this is the IV memory, // it will be updated in-place by the encryption. @@ -669,10 +669,10 @@ mod tests { exit.store(true, Ordering::Relaxed); storage_stage.join().unwrap(); - #[cfg(not(all(feature = "cuda", feature = "chacha")))] + #[cfg(not(cuda))] assert_eq!(result, Hash::default()); - #[cfg(all(feature = "cuda", feature = "chacha"))] + #[cfg(cuda)] assert_ne!(result, Hash::default()); remove_dir_all(ledger_path).unwrap(); diff --git a/drone/Cargo.toml b/drone/Cargo.toml index f2c765b6f..727d0c8bf 100644 --- a/drone/Cargo.toml +++ b/drone/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" [features] cuda = [] -erasure = [] + [dependencies] bincode = "1.1.4" diff --git a/genesis/Cargo.toml b/genesis/Cargo.toml index 16de3eeec..a3c22fca7 100644 --- a/genesis/Cargo.toml +++ b/genesis/Cargo.toml @@ -38,4 +38,4 @@ hashbrown = "0.3.0" [features] cuda = ["solana/cuda"] -erasure = [] + diff --git a/gossip/Cargo.toml b/gossip/Cargo.toml index 7f6e7529d..95ea603a5 100644 --- a/gossip/Cargo.toml +++ b/gossip/Cargo.toml @@ -17,6 +17,5 @@ solana-netutil = { path = "../netutil", version = "0.16.0" } solana-sdk = { path = "../sdk", version = "0.16.0" } [features] -chacha = [] cuda = [] -erasure = [] + diff --git a/install/Cargo.toml b/install/Cargo.toml index 500cf3bea..12fb9ad3b 100644 --- a/install/Cargo.toml +++ b/install/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://solana.com/" [features] cuda = [] -erasure = [] + [dependencies] bincode = "1.1.4" diff --git a/keygen/Cargo.toml b/keygen/Cargo.toml index e4fe1f9ec..cc87f0089 100644 --- a/keygen/Cargo.toml +++ b/keygen/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" [features] cuda = [] -erasure = [] + [dependencies] clap = "2.33" diff --git a/ledger-tool/Cargo.toml b/ledger-tool/Cargo.toml index 4f4a42851..b9aa3f137 100644 --- a/ledger-tool/Cargo.toml +++ b/ledger-tool/Cargo.toml @@ -21,4 +21,4 @@ assert_cmd = "0.11" [features] cuda = ["solana/cuda"] -erasure = [] + diff --git a/multinode-demo/common.sh b/multinode-demo/common.sh index 7f03ba4ad..73846a4fe 100644 --- a/multinode-demo/common.sh +++ b/multinode-demo/common.sh @@ -38,10 +38,6 @@ else program=${BASH_REMATCH[1]} features+="cuda," fi - if [[ $program = replicator ]]; then - features+="chacha," - fi - if [[ -r "$SOLANA_ROOT/$program"/Cargo.toml ]]; then maybe_package="--package solana-$program" fi diff --git a/net/README.md b/net/README.md index 4a1cd3a99..4e7cc48bf 100644 --- a/net/README.md +++ b/net/README.md @@ -76,7 +76,7 @@ is detected at runtime and the CUDA build is auto selected. If deploying a locally-built network, first run `./fetch-perf-libs.sh` then ensure the `cuda` feature is specified at network start: ```bash -$ ./net.sh start -f "cuda,erasure" +$ ./net.sh start -f "cuda" ``` ### How to interact with a CD testnet deployed by ci/testnet-deploy.sh diff --git a/replicator/Cargo.toml b/replicator/Cargo.toml index 5214462e6..a545b194d 100644 --- a/replicator/Cargo.toml +++ b/replicator/Cargo.toml @@ -15,5 +15,4 @@ solana-netutil = { path = "../netutil", version = "0.16.0" } solana-sdk = { path = "../sdk", version = "0.16.0" } [features] -chacha = ["solana/chacha"] cuda = ["solana/cuda"] diff --git a/validator/Cargo.toml b/validator/Cargo.toml index 0448bb74a..aa14f6f24 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -23,6 +23,4 @@ solana-vote-api = { path = "../programs/vote_api", version = "0.16.0" } solana-vote-signer = { path = "../vote-signer", version = "0.16.0" } [features] -chacha = ["solana/chacha"] cuda = ["solana/cuda"] -erasure = ["solana/erasure"] diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index d4d813db4..210dfbd97 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -35,4 +35,4 @@ solana-budget-program = { path = "../programs/budget_program", version = "0.16.0 [features] cuda = [] -erasure = [] +