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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! AES-128-CTR stream cipher for WASI (WebAssembly System Interface).
//!
//! Provides encryption and decryption using AES-128 in CTR mode.
//!
//! ## Example
//! ```rust
//! use aes_wasm::aes128ctr::{encrypt, decrypt, Key, IV};
//! let key = Key::default();
//! let iv = IV::default();
//! let msg = b"hello";
//! let ciphertext = encrypt(msg, &key, iv);
//! let plaintext = decrypt(ciphertext, &key, iv);
//! assert_eq!(plaintext, msg);
//! ```
pub use crate::*;
/// The length of the key in bytes.
///
/// This constant is used for key array sizing.
pub const KEY_LEN: usize = 16;
/// The length of the IV in bytes.
///
/// This constant is used for IV array sizing.
pub const IV_LEN: usize = 16;
/// Key type for AES-128-CTR (16 bytes).
pub type Key = ;
/// IV type for AES-128-CTR (16 bytes).
pub type IV = ;
/// Encrypts a message using AES-128 in CTR mode.
///
/// # Arguments
/// * `msg` - The plaintext message to encrypt.
/// * `key` - Reference to the secret key.
/// * `iv` - Initialization vector.
///
/// # Returns
/// Ciphertext as a `Vec<u8>`.
///
/// # Example
/// ```
/// use aes_wasm::aes128ctr::{encrypt, Key, IV};
/// let key = Key::default();
/// let iv = IV::default();
/// let msg = b"hello";
/// let ciphertext = encrypt(msg, &key, iv);
/// ```
/// Decrypts a ciphertext using AES-128 in CTR mode.
///
/// # Arguments
/// * `ciphertext` - The ciphertext to decrypt.
/// * `key` - Reference to the secret key.
/// * `iv` - Initialization vector.
///
/// # Returns
/// Plaintext as a `Vec<u8>`.
///
/// # Example
/// ```
/// use aes_wasm::aes128ctr::{encrypt, decrypt, Key, IV};
/// let key = Key::default();
/// let iv = IV::default();
/// let msg = b"hello";
/// let ciphertext = encrypt(msg, &key, iv);
/// let plaintext = decrypt(ciphertext, &key, iv);
/// ```