5个版本
0.2.2 | 2023年7月28日 |
---|---|
0.2.1 | 2023年3月17日 |
0.2.0 | 2022年8月1日 |
0.1.1 | 2022年6月21日 |
0.1.0 | 2022年6月18日 |
#1796 in 加密学
140KB
589 行
ISAP
ISAP(轻量级认证加密和关联数据方案)的纯Rust实现。这个crate实现了ISAP的第2版。默认情况下,提供了Keccak(功能 keccak
)和Ascon(功能 ascon
)变换的实现。有关所有其他功能的文档,请参阅aead
crate。
安全注意事项
此crate未接受安全审计。使用风险自负。
许可证
此crate受MIT许可证的许可。
lib.rs
:
用法
简单用法(分配,无关联数据)
use isap_aead::IsapAscon128; // Or `IsapAscon128A`, `IsapKeccak128`, `IsapKeccak128A`
use isap_aead::aead::{Aead, KeyInit};
let key = b"very secret key.";
let cipher = IsapAscon128::new(key.into());
let nonce = b"unique nonce 012"; // 128-bits; unique per message
let ciphertext = cipher.encrypt(nonce.into(), b"plaintext message".as_ref())
.expect("encryption failure!"); // NOTE: handle this error to avoid panics!
let plaintext = cipher.decrypt(nonce.into(), ciphertext.as_ref())
.expect("decryption failure!"); // NOTE: handle this error to avoid panics!
assert_eq!(&plaintext, b"plaintext message");
原地使用(消除alloc
要求)
与其他实现aead
接口的crate类似,此crate还提供了一个可选的alloc
功能,可以在例如没有堆的微控制器环境中禁用。有关详细信息,请参阅aead::AeadInPlace
。
use isap_aead::IsapAscon128; // Or `IsapAscon128A`, `IsapKeccak128`, `IsapKeccak128A`
use isap_aead::aead::{AeadInPlace, KeyInit};
use isap_aead::aead::heapless::Vec;
let key = b"very secret key.";
let cipher = IsapAscon128::new(key.into());
let nonce = b"unique nonce 012"; // 128-bits; unique per message
let mut buffer: Vec<u8, 128> = Vec::new(); // Buffer needs 16-bytes overhead for authentication tag
buffer.extend_from_slice(b"plaintext message");
// Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
cipher.encrypt_in_place(nonce.into(), b"", &mut buffer).expect("encryption failure!");
// `buffer` now contains the message ciphertext
assert_ne!(&buffer, b"plaintext message");
// Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
cipher.decrypt_in_place(nonce.into(), b"", &mut buffer).expect("decryption failure!");
assert_eq!(&buffer, b"plaintext message");
同样,启用此crate的arrayvec
功能将为arrayvec::ArrayVec
提供aead::Buffer
的实现。
依赖关系
~0.6–1.3MB
~29K SLoC