feat: fix finalizatin

This commit is contained in:
2023-10-22 17:03:09 +08:00
parent 4e29789792
commit 6bdd2704b2
3 changed files with 5 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "chacha20-poly1305-stream"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Cesar Eduardo Barros <cesarb@cesarb.eti.br>", "Hatter Jiang <jht5945@gmail.com>"]
description = "A pure Rust implementation of the ChaCha20-Poly1305 AEAD from RFC 7539."

View File

@@ -63,7 +63,7 @@ impl ChaCha20Poly1305StreamDecryptor {
}
/// Finalize decrypt
pub fn finalize(mut self) -> Result<Vec<u8>, String> {
pub fn finalize(&mut self) -> Result<Vec<u8>, String> {
if self.message_buffer.len() < 16 {
return Err("Bad tag length".to_string());
}
@@ -84,7 +84,7 @@ impl ChaCha20Poly1305StreamDecryptor {
let message_tag = &self.message_buffer[last_payload_len..];
self.poly1305.block([self.adata_len.to_le(), self.message_len.to_le()].as_bytes());
let poly1305_tag = self.poly1305.tag();
let poly1305_tag = self.poly1305.clone().tag();
let tag = poly1305_tag.as_bytes();
if message_tag != tag {
Err(format!("Tag mismatch, expected: {}, actual: {}",

View File

@@ -62,7 +62,7 @@ impl ChaCha20Poly1305StreamEncryptor {
}
/// Finalize encrypt
pub fn finalize(mut self) -> (Vec<u8>, Vec<u8>) {
pub fn finalize(&mut self) -> (Vec<u8>, Vec<u8>) {
let mut last_block = vec![];
if !self.message_buffer.is_empty() {
let mut buf = [u32x4::default(); 4];
@@ -76,7 +76,7 @@ impl ChaCha20Poly1305StreamEncryptor {
}
self.poly1305.block([self.adata_len.to_le(), self.message_len.to_le()].as_bytes());
let tag = self.poly1305.tag().as_bytes().to_vec();
let tag = self.poly1305.clone().tag().as_bytes().to_vec();
(last_block, tag)
}