Skip to main content

Crate signed_crypto

Crate signed_crypto 

Source
Expand description

§signed-crypto

A Rust library for encrypted payloads with built-in integrity verification.

§Package Format

Encrypted payloads follow this structure:

initVector:16 || E(payload:?) || I(signature:4)

where:

  • initVector = timestamp:8 || serverId:8
  • E(payload) = AES-256/CTR64 encryption with encryption key
  • I(signature) = First 4 bytes of HMAC-SHA256(integrityKey, payload || initVector)

§Example

use signed_crypto::{Crypto, Keys};

let keys = Keys::new(&[0u8; 32], &[0u8; 32])?;
let crypto = Crypto::new(keys);

// Encrypt
let payload = b"Hello, world!";
let mut pkg = crypto.init_plain_data(payload.len(), None)?;
crypto.set_payload(&mut pkg, payload)?;
let encrypted = crypto.encrypt(&pkg)?;

// Decrypt
let decrypted = crypto.decrypt(&encrypted)?;
assert_eq!(crypto.payload(&decrypted), Some(payload.as_slice()));

Structs§

Crypto
Main cryptographic operations instance.
Keys
Holds the encryption and integrity keys.

Enums§

CryptoError
Errors that can occur during cryptographic operations.