mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-06 17:59:11 +00:00
feat(encrypt): Add XOR and ChaCha20 encryption with low-end device optimization and openssl support. (#1186)
Add ChaCha20 XOR algorithm, extend AES-GCM-256 capabilities, and integrate OpenSSL support. --------- Co-authored-by: Sijie.Sun <sunsijie@buaa.edu.cn>
This commit is contained in:
@@ -296,6 +296,29 @@ impl GlobalCtx {
|
||||
key
|
||||
}
|
||||
|
||||
pub fn get_256_key(&self) -> [u8; 32] {
|
||||
let mut key = [0u8; 32];
|
||||
let secret = self
|
||||
.config
|
||||
.get_network_identity()
|
||||
.network_secret
|
||||
.unwrap_or_default();
|
||||
// fill key according to network secret
|
||||
let mut hasher = DefaultHasher::new();
|
||||
hasher.write(secret.as_bytes());
|
||||
hasher.write(b"easytier-256bit-key"); // 添加固定盐值以区分128位和256位密钥
|
||||
|
||||
// 生成32字节密钥
|
||||
for i in 0..4 {
|
||||
let chunk_start = i * 8;
|
||||
let chunk_end = chunk_start + 8;
|
||||
hasher.write(&key[0..chunk_start]);
|
||||
hasher.write(&[i as u8]); // 添加索引以确保每个8字节块都不同
|
||||
key[chunk_start..chunk_end].copy_from_slice(&hasher.finish().to_be_bytes());
|
||||
}
|
||||
key
|
||||
}
|
||||
|
||||
pub fn enable_exit_node(&self) -> bool {
|
||||
self.enable_exit_node
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user