Add chacha-sys crate (#4620)
* af9ff9c7f9/src/cpu-crypt
* Add chacha-sys crate
* Remove chacha feature
* Remove erasure feature
* Add .gitignore
This commit is contained in:
@ -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<Blocktree>,
|
||||
slice: u64,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<u64>,
|
||||
sha_state: Hash,
|
||||
#[cfg(feature = "chacha")]
|
||||
num_chacha_blocks: usize,
|
||||
#[cfg(feature = "chacha")]
|
||||
blocktree: Arc<Blocktree>,
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user