Skip to content

Latest commit

 

History

History

belt-kwp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

RustCrypto: BelT Key Wrap Algorithm

crate Docs Apache2/MIT licensed Rust Version Build Status

Pure Rust implementation of the belt-kwp key wrapping algorithm defined in STB 4.101.31-2020.

Examples

use hex_literal::hex;
use belt_kwp::cipher::KeyInit;

let x: [u8; 32] = hex!(
    "B194BAC8 0A08F53B 366D008E 584A5DE4"
    "8504FA9D 1BB6C7AC 252E72C2 02FDCE0D"
);
let i: [u8; 16] = hex!("5BE3D612 17B96181 FE6786AD 716B890B");
let k: [u8; 32] = hex!(
    "E9DEE72C 8F0C0FA6 2DDB49F4 6F739647"
    "06075316 ED247A37 39CBA383 03A98BF6"
);
let y: [u8; 48] = hex!(
    "49A38EE1 08D6C742 E52B774F 00A6EF98"
    "B106CBD1 3EA4FB06 80323051 BC04DF76"
    "E487B055 C69BCF54 1176169F 1DC9F6C8"
);

let mut buf = [0u8; 48];

let kw = belt_kwp::BeltKwp::new(&k.into());

let wrapped_key = kw.wrap_key(&x, &i, &mut buf).unwrap();
assert_eq!(wrapped_key, y);

let unwrapped_key = kw.unwrap_key(&y, &i, &mut buf).unwrap();
assert_eq!(unwrapped_key, x);

// If key size is known at compile time, you can use the fixed methods:
use belt_kwp::cipher::consts::U32;

let wrapped_key = kw.wrap_fixed_key::<U32>(&x.into(), &i);
assert_eq!(wrapped_key, y);
let unwrapped_key = kw.unwrap_fixed_key::<U32>(&wrapped_key, &i).unwrap();
assert_eq!(unwrapped_key, x);

Minimum Supported Rust Version

This crate requires Rust 1.81 at a minimum.

We may change the MSRV in the future, but it will be accompanied by a minor version bump.

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.