72 lines
2.7 KiB
Rust
72 lines
2.7 KiB
Rust
//! The pure cryptographic steps of pairing (`docs/PROTOCOL.md` 1.5), public so QA can test them against
|
|
//! independent vectors (for example Python `hashlib` + `cryptography` with fixed test keys).
|
|
|
|
use super::{CHALLENGE_LEN, HASH_LEN, Pin, SALT_LEN, SECRET_LEN};
|
|
use crate::Result;
|
|
|
|
/// AES-128 key used for every encrypted pairing value.
|
|
pub type PairingKey = [u8; 16];
|
|
|
|
/// `K = SHA-256(salt ‖ PIN digits)[0..16]`.
|
|
///
|
|
/// # Errors
|
|
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
pub fn derive_key(salt: &[u8; SALT_LEN], pin: &Pin) -> Result<PairingKey> {
|
|
let _ = (salt, pin);
|
|
Err(crate::Error::Unimplemented)
|
|
}
|
|
|
|
/// AES-128-ECB encryption without padding.
|
|
///
|
|
/// # Errors
|
|
/// [`crate::Error::Malformed`] when `data` is not a whole number of 16-byte blocks. Phase A: always
|
|
/// [`crate::Error::Unimplemented`].
|
|
pub fn ecb_encrypt(key: &PairingKey, data: &[u8]) -> Result<Vec<u8>> {
|
|
let _ = (key, data);
|
|
Err(crate::Error::Unimplemented)
|
|
}
|
|
|
|
/// AES-128-ECB decryption without padding.
|
|
///
|
|
/// # Errors
|
|
/// As [`ecb_encrypt`].
|
|
pub fn ecb_decrypt(key: &PairingKey, data: &[u8]) -> Result<Vec<u8>> {
|
|
let _ = (key, data);
|
|
Err(crate::Error::Unimplemented)
|
|
}
|
|
|
|
/// `SHA-256(challenge ‖ cert_signature ‖ secret)`: the host's proof `H_s` (with the client challenge, the host
|
|
/// certificate's signature and the host secret) and the client's proof `H_c` (with the host challenge, the client
|
|
/// certificate's signature and the client secret).
|
|
///
|
|
/// # Errors
|
|
/// [`crate::Error::TooLarge`] for a signature over [`super::MAX_SIGNATURE_BYTES`]. Phase A: always
|
|
/// [`crate::Error::Unimplemented`].
|
|
pub fn proof_hash(
|
|
challenge: &[u8; CHALLENGE_LEN],
|
|
cert_signature: &[u8],
|
|
secret: &[u8; SECRET_LEN],
|
|
) -> Result<[u8; HASH_LEN]> {
|
|
let _ = (challenge, cert_signature, secret);
|
|
Err(crate::Error::Unimplemented)
|
|
}
|
|
|
|
/// Splits a decrypted `challengeresponse` (48 bytes) into the host proof `H_s` and the host challenge `S_c`.
|
|
///
|
|
/// # Errors
|
|
/// [`crate::Error::Malformed`] unless exactly 48 bytes. Phase A: always [`crate::Error::Unimplemented`].
|
|
pub fn split_challenge_response(decrypted: &[u8]) -> Result<([u8; HASH_LEN], [u8; CHALLENGE_LEN])> {
|
|
let _ = decrypted;
|
|
Err(crate::Error::Unimplemented)
|
|
}
|
|
|
|
/// Splits a `pairingsecret` into the host secret (16 bytes) and its signature (the rest).
|
|
///
|
|
/// # Errors
|
|
/// [`crate::Error::Malformed`] when shorter than 17 bytes, [`crate::Error::TooLarge`] when the signature is over
|
|
/// [`super::MAX_SIGNATURE_BYTES`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
pub fn split_pairing_secret(pairing_secret: &[u8]) -> Result<([u8; SECRET_LEN], &[u8])> {
|
|
let _ = pairing_secret;
|
|
Err(crate::Error::Unimplemented)
|
|
}
|