mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Drop rust-crypto trait usage
This commit is contained in:
parent
7511a82195
commit
202c0aedcb
5 changed files with 9 additions and 52 deletions
|
@ -40,7 +40,6 @@ use util::errors::APIError;
|
|||
use util::errors;
|
||||
|
||||
use crypto;
|
||||
use crypto::symmetriccipher::SynchronousStreamCipher;
|
||||
|
||||
use std::{cmp, ptr, mem};
|
||||
use std::collections::{HashMap, hash_map, HashSet};
|
||||
|
|
|
@ -9,8 +9,6 @@ use secp256k1::key::{PublicKey,SecretKey};
|
|||
use secp256k1::ecdh::SharedSecret;
|
||||
use secp256k1;
|
||||
|
||||
use crypto::aead::{AeadEncryptor, AeadDecryptor};
|
||||
|
||||
use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
|
||||
use util::{byte_utils,rng};
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
mod real_chacha {
|
||||
use std::cmp;
|
||||
use util::byte_utils::{slice_to_le32, le32_to_array};
|
||||
use crypto::symmetriccipher::SynchronousStreamCipher;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[allow(non_camel_case_types)]
|
||||
|
@ -224,10 +223,8 @@ mod real_chacha {
|
|||
|
||||
self.offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
impl SynchronousStreamCipher for ChaCha20 {
|
||||
fn process(&mut self, input: &[u8], output: &mut [u8]) {
|
||||
pub fn process(&mut self, input: &[u8], output: &mut [u8]) {
|
||||
assert!(input.len() == output.len());
|
||||
let len = input.len();
|
||||
let mut i = 0;
|
||||
|
@ -258,8 +255,6 @@ pub use self::real_chacha::ChaCha20;
|
|||
|
||||
#[cfg(feature = "fuzztarget")]
|
||||
mod fuzzy_chacha {
|
||||
use crypto::symmetriccipher::SynchronousStreamCipher;
|
||||
|
||||
pub struct ChaCha20 {}
|
||||
|
||||
impl ChaCha20 {
|
||||
|
@ -268,10 +263,8 @@ mod fuzzy_chacha {
|
|||
assert!(nonce.len() == 8 || nonce.len() == 12);
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl SynchronousStreamCipher for ChaCha20 {
|
||||
fn process(&mut self, input: &[u8], output: &mut [u8]) {
|
||||
pub fn process(&mut self, input: &[u8], output: &mut [u8]) {
|
||||
output.copy_from_slice(input);
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +277,6 @@ mod test {
|
|||
use std::iter::repeat;
|
||||
|
||||
use super::ChaCha20;
|
||||
use crypto::symmetriccipher::SynchronousStreamCipher;
|
||||
|
||||
#[test]
|
||||
fn test_chacha20_256_tls_vectors() {
|
||||
|
|
|
@ -15,9 +15,6 @@ mod real_chachapoly {
|
|||
use util::chacha20::ChaCha20;
|
||||
use util::poly1305::Poly1305;
|
||||
|
||||
use crypto::aead::{AeadEncryptor,AeadDecryptor};
|
||||
use crypto::symmetriccipher::SynchronousStreamCipher;
|
||||
use crypto::mac::Mac;
|
||||
use crypto::util::fixed_time_eq;
|
||||
|
||||
use util::byte_utils;
|
||||
|
@ -62,10 +59,8 @@ mod real_chachapoly {
|
|||
aad_len: aad.len() as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AeadEncryptor for ChaCha20Poly1305RFC {
|
||||
fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) {
|
||||
pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) {
|
||||
assert!(input.len() == output.len());
|
||||
assert!(self.finished == false);
|
||||
self.cipher.process(input, output);
|
||||
|
@ -77,10 +72,8 @@ mod real_chachapoly {
|
|||
self.mac.input(&byte_utils::le64_to_array(self.data_len as u64));
|
||||
self.mac.raw_result(out_tag);
|
||||
}
|
||||
}
|
||||
|
||||
impl AeadDecryptor for ChaCha20Poly1305RFC {
|
||||
fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool {
|
||||
pub fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool {
|
||||
assert!(input.len() == output.len());
|
||||
assert!(self.finished == false);
|
||||
|
||||
|
@ -109,8 +102,6 @@ pub use self::real_chachapoly::ChaCha20Poly1305RFC;
|
|||
|
||||
#[cfg(feature = "fuzztarget")]
|
||||
mod fuzzy_chachapoly {
|
||||
use crypto::aead::{AeadEncryptor,AeadDecryptor};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ChaCha20Poly1305RFC {
|
||||
tag: [u8; 16],
|
||||
|
@ -132,10 +123,8 @@ mod fuzzy_chachapoly {
|
|||
finished: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AeadEncryptor for ChaCha20Poly1305RFC {
|
||||
fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) {
|
||||
pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) {
|
||||
assert!(input.len() == output.len());
|
||||
assert!(self.finished == false);
|
||||
|
||||
|
@ -143,10 +132,8 @@ mod fuzzy_chachapoly {
|
|||
out_tag.copy_from_slice(&self.tag);
|
||||
self.finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl AeadDecryptor for ChaCha20Poly1305RFC {
|
||||
fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool {
|
||||
pub fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool {
|
||||
assert!(input.len() == output.len());
|
||||
assert!(self.finished == false);
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
use std::cmp::min;
|
||||
use util::byte_utils::{slice_to_le32, le32_to_array};
|
||||
|
||||
use crypto::mac::{Mac, MacResult};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Poly1305 {
|
||||
r : [u32; 5],
|
||||
|
@ -93,7 +91,7 @@ impl Poly1305 {
|
|||
self.h[4] = h4;
|
||||
}
|
||||
|
||||
fn finish(&mut self) {
|
||||
pub fn finish(&mut self) {
|
||||
if self.leftover > 0 {
|
||||
self.buffer[self.leftover] = 1;
|
||||
for i in self.leftover+1..16 {
|
||||
|
@ -158,10 +156,8 @@ impl Poly1305 {
|
|||
self.h[2] = h2;
|
||||
self.h[3] = h3;
|
||||
}
|
||||
}
|
||||
|
||||
impl Mac for Poly1305 {
|
||||
fn input(&mut self, data: &[u8]) {
|
||||
pub fn input(&mut self, data: &[u8]) {
|
||||
assert!(!self.finalized);
|
||||
let mut m = data;
|
||||
|
||||
|
@ -195,19 +191,7 @@ impl Mac for Poly1305 {
|
|||
self.leftover = m.len();
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.h = [0u32; 5];
|
||||
self.leftover = 0;
|
||||
self.finalized = false;
|
||||
}
|
||||
|
||||
fn result(&mut self) -> MacResult {
|
||||
let mut mac = [0u8; 16];
|
||||
self.raw_result(&mut mac);
|
||||
MacResult::new(&mac[..])
|
||||
}
|
||||
|
||||
fn raw_result(&mut self, output: &mut [u8]) {
|
||||
pub fn raw_result(&mut self, output: &mut [u8]) {
|
||||
assert!(output.len() >= 16);
|
||||
if !self.finalized{
|
||||
self.finish();
|
||||
|
@ -217,8 +201,6 @@ impl Mac for Poly1305 {
|
|||
output[8..12].copy_from_slice(&le32_to_array(self.h[2]));
|
||||
output[12..16].copy_from_slice(&le32_to_array(self.h[3]));
|
||||
}
|
||||
|
||||
fn output_bytes(&self) -> usize { 16 }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -226,7 +208,6 @@ mod test {
|
|||
use std::iter::repeat;
|
||||
|
||||
use util::poly1305::Poly1305;
|
||||
use crypto::mac::Mac;
|
||||
|
||||
fn poly1305(key: &[u8], msg: &[u8], mac: &mut [u8]) {
|
||||
let mut poly = Poly1305::new(key);
|
||||
|
|
Loading…
Add table
Reference in a new issue