Lines Matching refs:Cipher

8 //! use openssl::symm::{encrypt, Cipher};
10 //! let cipher = Cipher::aes_128_cbc();
30 //! use openssl::symm::Cipher;
34 //! let cipher = Cipher::aes_256_cbc();
73 pub struct Cipher(*const ffi::EVP_CIPHER);
75 impl Cipher {
81 pub fn from_nid(nid: Nid) -> Option<Cipher> {
86 Some(Cipher(ptr))
100 pub fn aes_128_ecb() -> Cipher {
101 unsafe { Cipher(ffi::EVP_aes_128_ecb()) }
104 pub fn aes_128_cbc() -> Cipher {
105 unsafe { Cipher(ffi::EVP_aes_128_cbc()) }
109 pub fn aes_128_xts() -> Cipher {
110 unsafe { Cipher(ffi::EVP_aes_128_xts()) }
113 pub fn aes_128_ctr() -> Cipher {
114 unsafe { Cipher(ffi::EVP_aes_128_ctr()) }
118 pub fn aes_128_cfb1() -> Cipher {
119 unsafe { Cipher(ffi::EVP_aes_128_cfb1()) }
122 pub fn aes_128_cfb128() -> Cipher {
123 unsafe { Cipher(ffi::EVP_aes_128_cfb128()) }
127 pub fn aes_128_cfb8() -> Cipher {
128 unsafe { Cipher(ffi::EVP_aes_128_cfb8()) }
131 pub fn aes_128_gcm() -> Cipher {
132 unsafe { Cipher(ffi::EVP_aes_128_gcm()) }
136 pub fn aes_128_ccm() -> Cipher {
137 unsafe { Cipher(ffi::EVP_aes_128_ccm()) }
140 pub fn aes_128_ofb() -> Cipher {
141 unsafe { Cipher(ffi::EVP_aes_128_ofb()) }
146 pub fn aes_128_ocb() -> Cipher {
147 unsafe { Cipher(ffi::EVP_aes_128_ocb()) }
150 pub fn aes_192_ecb() -> Cipher {
151 unsafe { Cipher(ffi::EVP_aes_192_ecb()) }
154 pub fn aes_192_cbc() -> Cipher {
155 unsafe { Cipher(ffi::EVP_aes_192_cbc()) }
158 pub fn aes_192_ctr() -> Cipher {
159 unsafe { Cipher(ffi::EVP_aes_192_ctr()) }
163 pub fn aes_192_cfb1() -> Cipher {
164 unsafe { Cipher(ffi::EVP_aes_192_cfb1()) }
167 pub fn aes_192_cfb128() -> Cipher {
168 unsafe { Cipher(ffi::EVP_aes_192_cfb128()) }
172 pub fn aes_192_cfb8() -> Cipher {
173 unsafe { Cipher(ffi::EVP_aes_192_cfb8()) }
176 pub fn aes_192_gcm() -> Cipher {
177 unsafe { Cipher(ffi::EVP_aes_192_gcm()) }
181 pub fn aes_192_ccm() -> Cipher {
182 unsafe { Cipher(ffi::EVP_aes_192_ccm()) }
185 pub fn aes_192_ofb() -> Cipher {
186 unsafe { Cipher(ffi::EVP_aes_192_ofb()) }
191 pub fn aes_192_ocb() -> Cipher {
192 unsafe { Cipher(ffi::EVP_aes_192_ocb()) }
195 pub fn aes_256_ecb() -> Cipher {
196 unsafe { Cipher(ffi::EVP_aes_256_ecb()) }
199 pub fn aes_256_cbc() -> Cipher {
200 unsafe { Cipher(ffi::EVP_aes_256_cbc()) }
204 pub fn aes_256_xts() -> Cipher {
205 unsafe { Cipher(ffi::EVP_aes_256_xts()) }
208 pub fn aes_256_ctr() -> Cipher {
209 unsafe { Cipher(ffi::EVP_aes_256_ctr()) }
213 pub fn aes_256_cfb1() -> Cipher {
214 unsafe { Cipher(ffi::EVP_aes_256_cfb1()) }
217 pub fn aes_256_cfb128() -> Cipher {
218 unsafe { Cipher(ffi::EVP_aes_256_cfb128()) }
222 pub fn aes_256_cfb8() -> Cipher {
223 unsafe { Cipher(ffi::EVP_aes_256_cfb8()) }
226 pub fn aes_256_gcm() -> Cipher {
227 unsafe { Cipher(ffi::EVP_aes_256_gcm()) }
231 pub fn aes_256_ccm() -> Cipher {
232 unsafe { Cipher(ffi::EVP_aes_256_ccm()) }
235 pub fn aes_256_ofb() -> Cipher {
236 unsafe { Cipher(ffi::EVP_aes_256_ofb()) }
241 pub fn aes_256_ocb() -> Cipher {
242 unsafe { Cipher(ffi::EVP_aes_256_ocb()) }
246 pub fn bf_cbc() -> Cipher {
247 unsafe { Cipher(ffi::EVP_bf_cbc()) }
251 pub fn bf_ecb() -> Cipher {
252 unsafe { Cipher(ffi::EVP_bf_ecb()) }
256 pub fn bf_cfb64() -> Cipher {
257 unsafe { Cipher(ffi::EVP_bf_cfb64()) }
261 pub fn bf_ofb() -> Cipher {
262 unsafe { Cipher(ffi::EVP_bf_ofb()) }
265 pub fn des_cbc() -> Cipher {
266 unsafe { Cipher(ffi::EVP_des_cbc()) }
269 pub fn des_ecb() -> Cipher {
270 unsafe { Cipher(ffi::EVP_des_ecb()) }
273 pub fn des_ede3() -> Cipher {
274 unsafe { Cipher(ffi::EVP_des_ede3()) }
277 pub fn des_ede3_cbc() -> Cipher {
278 unsafe { Cipher(ffi::EVP_des_ede3_cbc()) }
282 pub fn des_ede3_cfb64() -> Cipher {
283 unsafe { Cipher(ffi::EVP_des_ede3_cfb64()) }
287 pub fn rc4() -> Cipher {
288 unsafe { Cipher(ffi::EVP_rc4()) }
293 pub fn chacha20() -> Cipher {
294 unsafe { Cipher(ffi::EVP_chacha20()) }
299 pub fn chacha20_poly1305() -> Cipher {
300 unsafe { Cipher(ffi::EVP_chacha20_poly1305()) }
304 pub fn seed_cbc() -> Cipher {
305 unsafe { Cipher(ffi::EVP_seed_cbc()) }
309 pub fn seed_cfb128() -> Cipher {
310 unsafe { Cipher(ffi::EVP_seed_cfb128()) }
314 pub fn seed_ecb() -> Cipher {
315 unsafe { Cipher(ffi::EVP_seed_ecb()) }
319 pub fn seed_ofb() -> Cipher {
320 unsafe { Cipher(ffi::EVP_seed_ofb()) }
324 pub fn sm4_ecb() -> Cipher {
325 unsafe { Cipher(ffi::EVP_sm4_ecb()) }
329 pub fn sm4_cbc() -> Cipher {
330 unsafe { Cipher(ffi::EVP_sm4_cbc()) }
334 pub fn sm4_ctr() -> Cipher {
335 unsafe { Cipher(ffi::EVP_sm4_ctr()) }
339 pub fn sm4_cfb128() -> Cipher {
340 unsafe { Cipher(ffi::EVP_sm4_cfb128()) }
344 pub fn sm4_ofb() -> Cipher {
345 unsafe { Cipher(ffi::EVP_sm4_ofb()) }
348 /// Creates a `Cipher` from a raw pointer to its OpenSSL type.
353 pub unsafe fn from_ptr(ptr: *const ffi::EVP_CIPHER) -> Cipher {
354 Cipher(ptr)
396 self == Cipher::aes_128_ccm() || self == Cipher::aes_256_ccm()
407 self == Cipher::aes_128_ocb()
408 || self == Cipher::aes_192_ocb()
409 || self == Cipher::aes_256_ocb()
418 unsafe impl Sync for Cipher {}
419 unsafe impl Send for Cipher {}
431 /// use openssl::symm::{Cipher, Mode, Crypter};
440 /// Cipher::aes_128_cbc(),
445 /// let block_size = Cipher::aes_128_cbc().block_size();
467 /// Cipher::aes_128_cbc(),
487 /// types of `Cipher`.
494 t: Cipher,
578 /// where `block_size` is the block size of the cipher (see `Cipher::block_size`).
595 /// where `block_size` is the block size of the cipher (see `Cipher::block_size`).
626 /// use openssl::symm::{encrypt, Cipher};
628 /// let cipher = Cipher::aes_128_cbc();
644 t: Cipher,
665 /// use openssl::symm::{decrypt, Cipher};
667 /// let cipher = Cipher::aes_128_cbc();
683 t: Cipher,
692 t: Cipher,
715 t: Cipher,
746 t: Cipher,
811 super::Cipher::aes_128_ctr(),
841 super::Cipher::aes_256_ecb(),
848 let mut r0 = vec![0; c0.len() + super::Cipher::aes_256_ecb().block_size()];
855 super::Cipher::aes_256_ecb(),
862 let mut p1 = vec![0; r0.len() + super::Cipher::aes_256_ecb().block_size()];
885 super::Cipher::aes_256_cbc(),
892 let mut unciphered_data = vec![0; data.len() + super::Cipher::aes_256_cbc().block_size()];
902 fn cipher_test(ciphertype: super::Cipher, pt: &str, ct: &str, key: &str, iv: &str) {
926 fn cipher_test_nopad(ciphertype: super::Cipher, pt: &str, ct: &str, key: &str, iv: &str) {
967 cipher_test(super::Cipher::rc4(), pt, ct, key, iv);
983 cipher_test(super::Cipher::aes_256_xts(), pt, ct, key, iv);
995 cipher_test(super::Cipher::aes_128_ctr(), pt, ct, key, iv);
1008 cipher_test(super::Cipher::aes_128_cfb1(), pt, ct, key, iv);
1019 cipher_test(super::Cipher::aes_128_cfb128(), pt, ct, key, iv);
1030 cipher_test(super::Cipher::aes_128_cfb8(), pt, ct, key, iv);
1042 cipher_test(super::Cipher::aes_128_ofb(), pt, ct, key, iv);
1054 cipher_test(super::Cipher::aes_192_ctr(), pt, ct, key, iv);
1067 cipher_test(super::Cipher::aes_192_cfb1(), pt, ct, key, iv);
1080 cipher_test(super::Cipher::aes_192_cfb128(), pt, ct, key, iv);
1093 cipher_test(super::Cipher::aes_192_cfb8(), pt, ct, key, iv);
1105 cipher_test(super::Cipher::aes_192_ofb(), pt, ct, key, iv);
1116 cipher_test(super::Cipher::aes_256_cfb1(), pt, ct, key, iv);
1127 cipher_test(super::Cipher::aes_256_cfb128(), pt, ct, key, iv);
1138 cipher_test(super::Cipher::aes_256_cfb8(), pt, ct, key, iv);
1150 cipher_test(super::Cipher::aes_256_ofb(), pt, ct, key, iv);
1167 cipher_test_nopad(super::Cipher::bf_cbc(), pt, ct, key, iv);
1182 cipher_test_nopad(super::Cipher::bf_ecb(), pt, ct, key, iv);
1197 cipher_test_nopad(super::Cipher::bf_cfb64(), pt, ct, key, iv);
1212 cipher_test_nopad(super::Cipher::bf_ofb(), pt, ct, key, iv);
1225 cipher_test(super::Cipher::des_cbc(), pt, ct, key, iv);
1238 cipher_test(super::Cipher::des_ecb(), pt, ct, key, iv);
1248 cipher_test(super::Cipher::des_ede3(), pt, ct, key, iv);
1258 cipher_test(super::Cipher::des_ede3_cbc(), pt, ct, key, iv);
1269 cipher_test(super::Cipher::des_ede3_cfb64(), pt, ct, key, iv);
1285 Cipher::aes_128_gcm(),
1297 Cipher::aes_128_gcm(),
1321 Cipher::aes_128_ccm(),
1334 Cipher::aes_128_ccm(),
1356 Cipher::aes_128_ccm(),
1379 Cipher::aes_256_ccm(),
1392 Cipher::aes_256_ccm(),
1414 Cipher::aes_256_ccm(),
1436 Cipher::aes_128_ocb(),
1449 Cipher::aes_128_ocb(),
1470 Cipher::aes_128_ocb(),
1492 cipher_test(Cipher::chacha20(), pt, ct, key, iv);
1513 Cipher::chacha20_poly1305(),
1525 Cipher::chacha20_poly1305(),
1547 cipher_test(super::Cipher::seed_cbc(), pt, ct, key, iv);
1561 cipher_test(super::Cipher::seed_cfb128(), pt, ct, key, iv);
1575 cipher_test(super::Cipher::seed_ecb(), pt, ct, key, iv);
1589 cipher_test(super::Cipher::seed_ofb(), pt, ct, key, iv);
1616 let block_size = Cipher::sm4_ecb().block_size();
1617 let mut c = Crypter::new(Cipher::sm4_ecb(), Mode::Encrypt, &key, None).unwrap();
1621 let mut r = vec![0; pt.len() + Cipher::sm4_ecb().block_size()];
1626 let mut r1 = vec![0; pt.len() + Cipher::sm4_ecb().block_size()];