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
//! # Utility Functions
//!
//! This module provides low-level utility functions used throughout the library
//! for password encoding and cryptographic operations.
use crateAescryptError;
/// Convert UTF-8 password bytes to UTF-16LE encoding.
///
/// This function is used for ACKDF (AES Crypt Key Derivation Function) in v0-v2 files,
/// which require passwords to be encoded as UTF-16LE before hashing.
///
/// # Arguments
///
/// * `input_utf8` - UTF-8 encoded password bytes
///
/// # Returns
///
/// Returns a `Vec<u8>` containing the UTF-16LE encoded password, or an error if
/// the input is not valid UTF-8.
///
/// # Errors
///
/// Returns [`AescryptError::Crypto`] if the input is not valid UTF-8.
///
/// # Example
///
/// ```
/// use aescrypt_rs::utilities::utf8_to_utf16le;
///
/// let utf8_bytes = b"Hello";
/// let utf16le = utf8_to_utf16le(utf8_bytes)?;
/// // utf16le now contains: [0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00]
/// # Ok::<(), aescrypt_rs::AescryptError>(())
/// ```
/// XOR two 16-byte blocks together, writing the result to the output buffer.
///
/// This function performs byte-wise XOR of two 16-byte blocks, which is used
/// in CBC mode encryption/decryption for chaining blocks together.
///
/// # Arguments
///
/// * `block_a` - First 16-byte block
/// * `block_b` - Second 16-byte block
/// * `output` - Output buffer (must be at least 16 bytes)
///
/// # Panics
///
/// Panics if `block_a`, `block_b`, or `output` are shorter than 16 bytes.
///
/// # Example
///
/// ```
/// use aescrypt_rs::utilities::xor_blocks;
///
/// let block_a = [0xFF; 16];
/// let block_b = [0xAA; 16];
/// let mut output = [0u8; 16];
///
/// xor_blocks(&block_a, &block_b, &mut output);
/// // output now contains: [0x55; 16] (0xFF ^ 0xAA = 0x55)
/// ```
pub const