picky_krb/crypto/
mod.rs

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::block_padding::UnpadError;
11use ::aes::cipher::inout::PadError;
12use thiserror::Error;
13
14/// https://www.rfc-editor.org/rfc/rfc3962.html#section-4
15/// the 8-octet ASCII string "kerberos"
16pub const KERBEROS: &[u8; 8] = b"kerberos";
17
18#[derive(Error, Debug)]
19pub enum KerberosCryptoError {
20    #[error("Invalid key length: {0}. Expected: {1}")]
21    KeyLength(usize, usize),
22    #[error("Invalid cipher length: {0}. Expected at least: {1}")]
23    CipherLength(usize, usize),
24    #[error("Invalid algorithm identifier: {0}")]
25    AlgorithmIdentifier(usize),
26    #[error("Invalid algorithm identifier: {0:?}")]
27    AlgorithmIdentifierData(Vec<u8>),
28    #[error("Bad integrity: calculated hmac is different than provided")]
29    IntegrityCheck,
30    #[error("Cipher error: {0}")]
31    CipherError(String),
32    #[error("Padding error: {0:?}")]
33    CipherUnpad(UnpadError),
34    #[error("Padding error: {0:?}")]
35    CipherPad(PadError),
36    #[error("Invalid seed bit len: {0}")]
37    SeedBitLen(String),
38    #[error(transparent)]
39    RandError(#[from] rand::rand_core::OsError),
40    #[error(transparent)]
41    TooSmallBuffer(#[from] inout::OutIsTooSmallError),
42    #[error(transparent)]
43    ArrayTryFromSliceError(#[from] std::array::TryFromSliceError),
44}
45
46impl From<UnpadError> for KerberosCryptoError {
47    fn from(err: UnpadError) -> Self {
48        Self::CipherUnpad(err)
49    }
50}
51
52impl From<PadError> for KerberosCryptoError {
53    fn from(err: PadError) -> Self {
54        Self::CipherPad(err)
55    }
56}
57
58pub struct DecryptWithoutChecksum {
59    pub plaintext: Vec<u8>,
60    pub confounder: Vec<u8>,
61    pub checksum: Vec<u8>,
62    pub ki: Vec<u8>,
63}
64
65pub struct EncryptWithoutChecksum {
66    pub encrypted: Vec<u8>,
67    pub confounder: Vec<u8>,
68    pub ki: Vec<u8>,
69}
70
71pub type KerberosCryptoResult<T> = Result<T, KerberosCryptoError>;
72
73pub use checksum::{Checksum, ChecksumSuite};
74pub use cipher::{Cipher, CipherSuite};