1pub mod aes;
2mod checksum;
3mod cipher;
4pub(crate) mod common;
5pub mod des;
6pub mod diffie_hellman;
7pub(crate) mod nfold;
8pub(crate) mod utils;
9
10use ::aes::cipher::inout::PadError;
11use thiserror::Error;
12
13pub const KERBEROS: &[u8; 8] = b"kerberos";
16
17#[derive(Error, Debug)]
18pub enum KerberosCryptoError {
19 #[error("Invalid key length: {0}. Expected: {1}")]
20 KeyLength(usize, usize),
21 #[error("Invalid cipher length: {0}. Expected at least: {1}")]
22 CipherLength(usize, usize),
23 #[error("Invalid algorithm identifier: {0}")]
24 AlgorithmIdentifier(usize),
25 #[error("Invalid algorithm identifier: {0:?}")]
26 AlgorithmIdentifierData(Vec<u8>),
27 #[error("Bad integrity: calculated hmac is different than provided")]
28 IntegrityCheck,
29 #[error("Cipher error: {0}")]
30 CipherError(String),
31 #[error("Padding error: {0:?}")]
32 CipherUnpad(#[from] block_padding::Error),
33 #[error("Padding error: {0:?}")]
34 CipherPad(PadError),
35 #[error("Invalid seed bit len: {0}")]
36 SeedBitLen(String),
37 #[error(transparent)]
38 RandError(#[from] rand::rngs::SysError),
39 #[error(transparent)]
40 TooSmallBuffer(#[from] inout::OutIsTooSmallError),
41 #[error(transparent)]
42 ArrayTryFromSliceError(#[from] std::array::TryFromSliceError),
43}
44
45impl From<PadError> for KerberosCryptoError {
46 fn from(err: PadError) -> Self {
47 Self::CipherPad(err)
48 }
49}
50
51pub struct DecryptWithoutChecksum {
52 pub plaintext: Vec<u8>,
53 pub confounder: Vec<u8>,
54 pub checksum: Vec<u8>,
55 pub ki: Vec<u8>,
56}
57
58pub struct EncryptWithoutChecksum {
59 pub encrypted: Vec<u8>,
60 pub confounder: Vec<u8>,
61 pub ki: Vec<u8>,
62}
63
64pub type KerberosCryptoResult<T> = Result<T, KerberosCryptoError>;
65
66pub use checksum::{Checksum, ChecksumSuite};
67pub use cipher::{Cipher, CipherSuite};