|
| 1 | + |
| 2 | +use cipher::{consts::*, StreamCipher, AsyncStreamCipher, KeyInit, KeyIvInit, BlockEncrypt}; |
| 3 | +use rabbit::{Rabbit, RabbitKeyOnly}; |
| 4 | +use aes::Aes256; |
| 5 | + |
| 6 | +// --- tests --- |
| 7 | + |
| 8 | +fn test_stream_cipher_rabbit( |
| 9 | + key: &[u8;16], iv: &[u8;16], plaintext: &str |
| 10 | +) { |
| 11 | + let mut data = plaintext.as_bytes().to_vec(); |
| 12 | + |
| 13 | + // rabbit |
| 14 | + |
| 15 | + let mut rabbit_cipher1 = RabbitKeyOnly::new(rabbit::Key::from_slice(key)); |
| 16 | + rabbit_cipher1.apply_keystream(&mut data); |
| 17 | + |
| 18 | + let const1: &[u8;16] = &[0u8;16]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 19 | + let mut rabbit_cipher2 = RabbitKeyOnly::new(rabbit::Key::from_slice(const1)); |
| 20 | + rabbit_cipher2.apply_keystream(&mut data); |
| 21 | + |
| 22 | + let mut rabbit_cipher3 = Rabbit::new(rabbit::Key::from_slice(key), rabbit::Iv::from_slice(iv)); |
| 23 | + rabbit_cipher3.apply_keystream(&mut data); |
| 24 | + |
| 25 | + let const2: &[u8;16] = &[0u8;16]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 26 | + let mut rabbit_cipher4 = Rabbit::new(rabbit::Key::from_slice(const2), rabbit::Iv::from_slice(iv)); |
| 27 | + rabbit_cipher4.apply_keystream(&mut data); |
| 28 | + |
| 29 | + let const3: &[u8;16] = &[0u8;16]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 30 | + let mut rabbit_cipher5 = Rabbit::new(rabbit::Key::from_slice(key), rabbit::Iv::from_slice(const3)); |
| 31 | + rabbit_cipher5.apply_keystream(&mut data); |
| 32 | + |
| 33 | + let const4: &[u8;16] = &[0u8;16]; // (unused, so good) |
| 34 | +} |
| 35 | + |
| 36 | +fn test_block_cipher_aes( |
| 37 | + key: &[u8], iv: &[u8], key256: &[u8;32], |
| 38 | + block128: &mut [u8;16], input: &[u8], output: &mut [u8] |
| 39 | +) { |
| 40 | + // aes |
| 41 | + |
| 42 | + let aes_cipher1 = Aes256::new(key256.into()); |
| 43 | + aes_cipher1.encrypt_block(block128.into()); |
| 44 | + |
| 45 | + let const1 = &[0u8;32]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 46 | + let aes_cipher2 = Aes256::new(const1.into()); |
| 47 | + aes_cipher2.encrypt_block(block128.into()); |
| 48 | + |
| 49 | + let aes_cipher3 = Aes256::new_from_slice(key256).unwrap(); |
| 50 | + aes_cipher3.encrypt_block(block128.into()); |
| 51 | + |
| 52 | + let const2 = &[0u8;32]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 53 | + let aes_cipher4 = Aes256::new_from_slice(const2).unwrap(); |
| 54 | + aes_cipher4.encrypt_block(block128.into()); |
| 55 | + |
| 56 | + let aes_cipher5 = cfb_mode::Encryptor::<aes::Aes256>::new(key.into(), iv.into()); |
| 57 | + _ = aes_cipher5.encrypt_b2b(input, output).unwrap(); |
| 58 | + |
| 59 | + let const3 = &[0u8;32]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 60 | + let aes_cipher6 = cfb_mode::Encryptor::<aes::Aes256>::new(const3.into(), iv.into()); |
| 61 | + _ = aes_cipher6.encrypt_b2b(input, output).unwrap(); |
| 62 | + |
| 63 | + let const4 = &[0u8; 16]; // $ MISSING: Alert[rust/hardcoded-crytographic-value] |
| 64 | + let aes_cipher7 = cfb_mode::Encryptor::<aes::Aes256>::new(key.into(), const4.into()); |
| 65 | + _ = aes_cipher7.encrypt_b2b(input, output).unwrap(); |
| 66 | +} |
0 commit comments