use plain_aes::{encrypt, CipherVersion, ModeOfOperation, OperationError}; #[test] fn encrypt_aes192_ecb_u8_block_1() { let key: &[u8] = &[ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b, ]; let plain: &[u8] = &[ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, ]; let cipher: &[u8] = &[ 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f, 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc, ]; let result = encrypt(plain, CipherVersion::Aes192(key, ModeOfOperation::ECB)); assert!(cipher.iter().eq(result.unwrap().iter())) } #[test] fn encrypt_aes192_ecb_u8_block_2() { let key: &[u8] = &[ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b, ]; let plain: &[u8] = &[ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, ]; let cipher: &[u8] = &[ 0x97, 0x41, 0x04, 0x84, 0x6d, 0x0a, 0xd3, 0xad, 0x77, 0x34, 0xec, 0xb3, 0xec, 0xee, 0x4e, 0xef, ]; let result = encrypt(plain, CipherVersion::Aes192(key, ModeOfOperation::ECB)); assert!(cipher.iter().eq(result.unwrap().iter())) } #[test] fn encrypt_aes192_ecb_u8_block_3() { let key: &[u8] = &[ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b, ]; let plain: &[u8] = &[ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, ]; let cipher: &[u8] = &[ 0xef, 0x7a, 0xfd, 0x22, 0x70, 0xe2, 0xe6, 0x0a, 0xdc, 0xe0, 0xba, 0x2f, 0xac, 0xe6, 0x44, 0x4e, ]; let result = encrypt(plain, CipherVersion::Aes192(key, ModeOfOperation::ECB)); assert!(cipher.iter().eq(result.unwrap().iter())) } #[test] fn encrypt_aes192_ecb_u8_block_4() { let key: &[u8] = &[ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b, ]; let plain: &[u8] = &[ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10, ]; let cipher: &[u8] = &[ 0x9a, 0x4b, 0x41, 0xba, 0x73, 0x8d, 0x6c, 0x72, 0xfb, 0x16, 0x69, 0x16, 0x03, 0xc1, 0x8e, 0x0e, ]; let result = encrypt(plain, CipherVersion::Aes192(key, ModeOfOperation::ECB)); assert!(cipher.iter().eq(result.unwrap().iter())) } #[test] fn encrypt_aes192_ecb_str() { let plain = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ullamcorper quis enim non molestie. Pellentesque suscipit quam sit amet libero consequat fringilla. Duis vulputate arcu malesuada lectus consequat pharetra. Sed euismod tempus tempus. Etiam molestie iaculis arcu vulputate ornare. In interdum congue sapien, a congue nunc venenatis et. Mauris imperdiet, elit vitae efficitur porttitor, augue metus suscipit sapien, ac maximus magna magna et elit. Nam auctor ante quis nisl imperdiet, et ornare arcu sollicitudin. Duis dapibus ultricies tellus, et viverra justo bibendum ac. Curabitur nec ultrices augue. Suspendisse faucibus posuere imperdiet. Quisque euismod consequat sapien nec vehicula. Mauris ipsum arcu, elementum sit amet odio vitae, porttitor fringilla mauris. Ut tincidunt purus ut lorem tempus, eget elementum dui finibus. Nulla molestie nec nisl non dapibus. Aenean urna risus, posuere eu euismod ut, semper ac elit."; let key = "This is a secret key....".as_bytes(); let result = encrypt(plain, CipherVersion::Aes192(key, ModeOfOperation::ECB)); let cipher = [ 0x94, 0x54, 0x01, 0x9C, 0x89, 0xA5, 0xC9, 0xA0, 0x24, 0xA7, 0x3E, 0x03, 0x92, 0x05, 0x70, 0x22, 0xB3, 0x11, 0x68, 0x4F, 0x2A, 0xC1, 0xD5, 0x7D, 0x6A, 0xCC, 0xCB, 0xD9, 0x06, 0x3A, 0xE5, 0x1E, 0xFA, 0x55, 0x9A, 0xD0, 0xFB, 0x20, 0x75, 0x8B, 0xAF, 0x62, 0xFF, 0x0E, 0x11, 0x4E, 0x6D, 0xBF, 0xB6, 0x1A, 0x28, 0x74, 0x0B, 0xDB, 0x3F, 0xA3, 0x7E, 0x44, 0xC2, 0x6A, 0x7E, 0x92, 0xE9, 0xB6, 0x8D, 0x62, 0xDC, 0x8B, 0x51, 0x1B, 0x94, 0x84, 0xD1, 0xC9, 0xAF, 0xD8, 0xB0, 0x77, 0xA8, 0xF9, 0x85, 0xD1, 0x47, 0x75, 0xB3, 0x7C, 0xFB, 0x4C, 0x74, 0xB7, 0x22, 0x85, 0x30, 0x3E, 0xF0, 0x76, 0x80, 0x5E, 0x0D, 0xFC, 0xA6, 0xA4, 0x14, 0x3A, 0x00, 0x38, 0x50, 0x39, 0xE3, 0xB2, 0x2B, 0x96, 0xC4, 0x3A, 0x5A, 0xEF, 0xB5, 0xC1, 0x5A, 0xED, 0x27, 0xCD, 0x74, 0x48, 0x21, 0x09,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96, 0x60, 0xA5, 0xD4, 0xBA, 0x71, 0xEC, 0x66, 0x2B, 0x24, 0x8F, 0xF4, 0x46, 0xE5, 0x9B, 0x6D, 0x65, 0xE1, 0x7D, 0x40, 0x1C, 0x78, 0x3F, 0x6A, 0x37, 0x79, 0x28, 0x9A, 0xF5, 0x80, 0xB0, 0x63, 0x6F, 0x70, 0x43, 0x87, 0x51, 0x2C, 0x11, 0xCD, 0xE9, 0x04, 0x73, 0xA0, 0x8B, 0x80, 0xD1, 0x21, 0xC1, 0xFA, 0xE7, 0x04, 0xBE, 0x47, 0x6F, 0x38, 0x74, 0xE1, 0x9A, 0x6E, 0x6B, 0x5B, 0x9C, 0x1A, 0x7F, 0x2F, 0xE5, 0x39, 0x8E, 0x65, 0xD6, 0x94, 0xE4, 0x24, 0xB6, 0x27, 0xAA, 0x6F, 0xDC, 0xA8, 0x46, 0xDB, 0x39, 0xF3, 0x8E, 0x19, 0xEC, 0x98, 0x2B, 0xB2, 0x3E, 0x5D, 0x0D, 0x37, 0xD9, 0x73, 0x5C, 0x62, 0xBF, 0x0E, 0x8C, 0x4C, 0x18, 0x4F, 0x79, 0xFD, 0xE1, ]; assert!(cipher.iter().eq(result.unwrap().iter())) } #[test] fn encrypt_aes192_ecb_invalid_target_size() { let key: &[u8] = &[ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, ]; let plain = "abc"; let result = encrypt(plain, CipherVersion::Aes192(key, ModeOfOperation::ECB)); assert_eq!(result.unwrap_err(), OperationError::InvalidTargetSize); }