1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! # aes-wasm
//!
//! High-performance AEAD, stream cipher, and MAC primitives for WebAssembly/WASI.
//!
//! This crate provides a simple, dependency-free API for cryptography in WASI environments.
//!
//! ## Example: AES-128-GCM
//! ```rust
//! use aes_wasm::aes128gcm::{encrypt, decrypt, Key, Nonce};
//! let key = Key::default();
//! let nonce = Nonce::default();
//! let msg = b"hello world";
//! let ad = b"extra data";
//! let ciphertext = encrypt(msg, ad, &key, nonce);
//! let plaintext = decrypt(ciphertext, ad, &key, nonce).unwrap();
//! assert_eq!(plaintext, msg);
//! ```
//!
//! AEAD ciphers for WebAssembly, including AEGIS, AES-GCM, AES-OCB, AES-CBC, AES-CTR, and CMAC.
//!
//! This crate provides high-performance AEAD and MAC primitives for use in WebAssembly environments.
//! It exposes a simple API for encryption, decryption, and authentication using modern ciphers.
//!
//! # Example
//! ```
//! use aes_wasm::aes128gcm::{encrypt, decrypt, Key, Nonce};
//! let key = Key::default();
//! let nonce = Nonce::default();
//! let msg = b"hello";
//! let ad = b"ad";
//! let ciphertext = encrypt(msg, ad, &key, nonce);
//! let plaintext = decrypt(ciphertext, ad, &key, nonce).unwrap();
//! assert_eq!(plaintext, msg);
//! ```
use ;
/// Error type for AEAD operations.
///
/// This error is returned when authentication fails during decryption.
///
/// # Example
/// ```
/// use aes_wasm::aes128gcm::{decrypt, Key, Nonce};
/// use aes_wasm::Error;
/// let key = Key::default();
/// let nonce = Nonce::default();
/// let ad = b"ad";
/// // Intentionally use invalid ciphertext
/// let ciphertext = b"invalid";
/// let result = decrypt(ciphertext, ad, &key, nonce);
/// assert_eq!(result, Err(Error::VerificationFailed));
/// ```