Changed identity format in transactions, now it will be double Sha256.
Added new checks for forked blocks. Added options table. Added posibility to replace blocks in DB by more appropriate forks. Divided transactions table to domains and zones tables. Added a timestamp to domains and zones table, it will give us possibility to purge old domains. Changed difficulty check to check head and tail (sum of them) of the hash. Added encrypted (by Chacha20) domain name to DomainData, added contacts and owners vectors for it too. Added yggdrasil flag to ZoneData - it will restrict all IPs for domains in particular zone to Yggdrasil only. Changed difficulties of various block types. Added a temporary (for a run) unique ID to all handshakes. Start of signing blocks mining will be after 60 seconds after full block. Added mining status to statusbar.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
use chacha20poly1305::{ChaCha20Poly1305, Key, Nonce};
|
||||
use chacha20poly1305::aead::{Aead, NewAead};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fmt;
|
||||
|
||||
const FAILURE: &str = "encryption failure!";
|
||||
|
||||
/// A small wrap-up to use Chacha20 encryption for domain names.
|
||||
#[derive(Clone)]
|
||||
pub struct Chacha {
|
||||
pub cipher: ChaCha20Poly1305
|
||||
}
|
||||
|
||||
impl Chacha {
|
||||
pub fn new(seed: &[u8]) -> Self {
|
||||
let key = Key::from_slice(seed);
|
||||
let cipher = ChaCha20Poly1305::new(key);
|
||||
Chacha { cipher }
|
||||
}
|
||||
|
||||
pub fn encrypt(&self, data: &[u8], nonce: &[u8]) -> Vec<u8> {
|
||||
let nonce = Nonce::from_slice(nonce);
|
||||
Vec::from(self.cipher.encrypt(nonce, data.as_ref()).expect(FAILURE))
|
||||
}
|
||||
|
||||
pub fn decrypt(&self, data: &[u8], nonce: &[u8]) -> Vec<u8> {
|
||||
let nonce = Nonce::from_slice(nonce);
|
||||
Vec::from(self.cipher.decrypt(nonce, data.as_ref()).expect(FAILURE))
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Chacha {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
fmt.write_str("ChaCha20Poly1305")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::crypto::Chacha;
|
||||
use crate::to_hex;
|
||||
|
||||
#[test]
|
||||
pub fn test_curved_chacha() {
|
||||
let buf = b"178135D209C697625E3EC71DA5C760382E54936F824EE5083908DA66B14ECE18";
|
||||
let keys1 = Chacha::new(b"178135D209C697625E3EC71DA5C76038", );
|
||||
let bytes = keys1.encrypt(b"TEST", &buf[..12]);
|
||||
println!("{}", to_hex(&bytes));
|
||||
|
||||
let keys2 = Chacha::new(b"178135D209C697625E3EC71DA5C76038");
|
||||
let bytes2 = keys2.decrypt(&bytes, &buf[..12]);
|
||||
|
||||
assert_eq!(String::from_utf8(bytes2).unwrap(), "TEST");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
mod chacha;
|
||||
|
||||
pub use chacha::Chacha;
|
||||
Reference in New Issue
Block a user