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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! # HiAE - High-throughput Authenticated Encryption
//!
//! This crate provides an implementation of the HiAE (High-throughput Authenticated Encryption)
//! algorithm as specified in the IETF Internet-Draft.
//!
//! HiAE is designed for high-performance authenticated encryption with cross-platform efficiency,
//! particularly optimized for both ARM NEON and x86-64 AES-NI architectures.
//!
//! ## Features
//!
//! - **High Performance**: Leverages platform-specific SIMD instructions (ARM NEON, x86-64 AES-NI)
//! - **Security**: 256-bit keys, 128-bit nonces and tags, constant-time operations
//! - **Cross-Platform**: Optimized for both ARM and x86 architectures
//! - **Memory Safe**: Implemented in Rust with secure memory management
//! - **No-std Compatible**: Can be used in embedded environments
//!
//! ## Usage
//!
//! ```rust
//! use hiae::{encrypt, decrypt};
//!
//! let key = [0u8; 32]; // 256-bit key
//! let nonce = [0u8; 16]; // 128-bit nonce
//! let plaintext = b"Hello, world!";
//! let aad = b"additional data";
//!
//! // Encrypt
//! let (ciphertext, tag) = encrypt(plaintext, aad, &key, &nonce)?;
//!
//! // Decrypt
//! let decrypted = decrypt(&ciphertext, &tag, aad, &key, &nonce)?;
//! assert_eq!(decrypted, plaintext);
//! # Ok::<(), hiae::Error>(())
//! ```
extern crate alloc;
pub use ;
use Vec;
/// Encrypts plaintext with associated data using HiAE.
///
/// # Arguments
///
/// * `plaintext` - The data to encrypt
/// * `aad` - Additional authenticated data (not encrypted, but authenticated)
/// * `key` - 256-bit encryption key
/// * `nonce` - 128-bit nonce (must be unique for each encryption with the same key)
///
/// # Returns
///
/// A tuple of (ciphertext, authentication_tag) on success, or an error.
///
/// # Security
///
/// - The nonce MUST NOT be reused with the same key
/// - The key MUST be randomly chosen from a uniform distribution
///
/// # Example
///
/// ```rust
/// use hiae::encrypt;
///
/// let key = [0u8; 32];
/// let nonce = [0u8; 16];
/// let plaintext = b"secret message";
/// let aad = b"public header";
///
/// let (ciphertext, tag) = encrypt(plaintext, aad, &key, &nonce)?;
/// # Ok::<(), hiae::Error>(())
/// ```
/// Decrypts ciphertext and verifies the authentication tag.
///
/// # Arguments
///
/// * `ciphertext` - The encrypted data
/// * `tag` - 128-bit authentication tag
/// * `aad` - Additional authenticated data (must match encryption)
/// * `key` - 256-bit encryption key (must match encryption)
/// * `nonce` - 128-bit nonce (must match encryption)
///
/// # Returns
///
/// The decrypted plaintext on success, or an error if tag verification fails.
///
/// # Security
///
/// - If tag verification fails, no plaintext data is returned
/// - Tag comparison is performed in constant time
///
/// # Example
///
/// ```rust
/// use hiae::{encrypt, decrypt};
///
/// let key = [0u8; 32];
/// let nonce = [0u8; 16];
/// let plaintext = b"secret message";
/// let aad = b"public header";
///
/// let (ciphertext, tag) = encrypt(plaintext, aad, &key, &nonce)?;
/// let decrypted = decrypt(&ciphertext, &tag, aad, &key, &nonce)?;
///
/// assert_eq!(decrypted, plaintext);
/// # Ok::<(), hiae::Error>(())
/// ```