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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-FileCopyrightText: 2022 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! The `abcrypt` crate is an implementation of the [abcrypt encrypted data
//! format].
//!
//! This crate supports version 1 of the abcrypt format.
//!
//! # Examples
//!
//! ## Encryption and decryption
//!
//! ```
//! # #[cfg(feature = "alloc")]
//! # {
//! use abcrypt::{Decryptor, Encryptor, argon2::Params};
//!
//! let data = b"Hello, world!\n";
//! let passphrase = "passphrase";
//!
//! // Encrypt `data` using `passphrase`.
//! let params = Params::new(32, 3, 4, None).unwrap();
//! let ciphertext = Encryptor::with_params(data, passphrase, params)
//! .map(|c| c.encrypt_to_vec())
//! .unwrap();
//! assert_ne!(ciphertext, data);
//!
//! // And decrypt it back.
//! let plaintext = Decryptor::new(&ciphertext, passphrase)
//! .and_then(|c| c.decrypt_to_vec())
//! .unwrap();
//! assert_eq!(plaintext, data);
//! # }
//! ```
//!
//! ### `no_std` support
//!
//! This crate supports `no_std` mode and can be used without the `alloc` crate
//! and the `std` crate. Disables the `default` feature to enable this.
//!
//! <div class="warning">
//!
//! Note that the memory blocks used by Argon2 when calculating a derived key is
//! limited to 256 KiB when the `alloc` feature is disabled.
//!
//! </div>
//!
//! ```
//! use abcrypt::{
//! Argon2, Decryptor, Encryptor,
//! argon2::{Algorithm, Params, Version},
//! };
//!
//! let data = b"Hello, world!\n";
//! let passphrase = "passphrase";
//!
//! // Encrypt `data` using `passphrase`.
//! let params = Params::new(32, 3, 4, None).unwrap();
//! let cipher = Encryptor::with_params(data, passphrase, params).unwrap();
//! let mut buf = [u8::default(); 178];
//! cipher.encrypt(&mut buf);
//! assert_ne!(buf.as_slice(), data);
//!
//! let argon2 = Argon2::new(buf).unwrap();
//! assert_eq!(argon2.variant(), Algorithm::Argon2id);
//! assert_eq!(argon2.version(), Version::V0x13);
//!
//! // And decrypt it back.
//! let cipher = Decryptor::new(&buf, passphrase).unwrap();
//! let mut buf = [u8::default(); 14];
//! cipher.decrypt(&mut buf).unwrap();
//! assert_eq!(buf, *data);
//! ```
//!
//! ## Extracting the Argon2 parameters in the encrypted data
//!
//! ```
//! # #[cfg(feature = "alloc")]
//! # {
//! use abcrypt::{Encryptor, argon2};
//!
//! let data = b"Hello, world!\n";
//! let passphrase = "passphrase";
//!
//! // Encrypt `data` using `passphrase`.
//! let ciphertext = Encryptor::new(data, passphrase)
//! .map(|c| c.encrypt_to_vec())
//! .unwrap();
//!
//! // And extract the Argon2 parameters from it.
//! let params = abcrypt::Params::new(ciphertext).unwrap();
//! assert_eq!(params.memory_cost(), argon2::Params::DEFAULT_M_COST);
//! assert_eq!(params.time_cost(), argon2::Params::DEFAULT_T_COST);
//! assert_eq!(params.parallelism(), argon2::Params::DEFAULT_P_COST);
//! # }
//! ```
//!
//! [abcrypt encrypted data format]: https://sorairolake.github.io/abcrypt/book/format.html
// Lint levels of rustc.
extern crate alloc;
extern crate std;
pub use argon2;
pub use blake2;
pub use chacha20poly1305;
pub use crate::;
pub use crate::;
// 1 MiB.
const MEMORY_BLOCKS: = ;
const AAD: & = &;