Skip to main content

wrap

Function wrap 

Source
pub fn wrap(suite: Suite, key: &[u8; 32], value: &[u8; 32]) -> Result<[u8; 48]>
Expand description

Seals a 32-byte value under K_wrap with the AEAD of suite, returning ciphertext and tag.

The nonce is twelve zero bytes and the associated data is empty, as the spec requires. A key is used for one value only, which is what makes the fixed nonce safe.

§Errors

Fails when the build’s cipher resolver has no AEAD for suite. That is the honest refusal: sealing under the other suite’s cipher would produce a field the peer cannot open.

§Example

use syncspin_core::noise::Suite;
use syncspin_core::pairing::wrap::{unwrap, wrap};

// The key comes from `k_wrap` in a real flow; any 32 bytes will do here.
let key = [0x42; 32];
let value = [0x24; 32];
let sealed = wrap(Suite::ChaChaPoly, &key, &value).expect("the cipher is available");
assert_eq!(unwrap(Suite::ChaChaPoly, &key, &sealed).expect("round trip"), value);