Trait secp256kfun::hash::Tag

source ·
pub trait Tag: Sized {
    // Required method
    fn tag_vectored<'a>(
        self,
        tag_components: impl Iterator<Item = &'a [u8]> + Clone
    ) -> Self;

    // Provided method
    fn tag(self, tag: &[u8]) -> Self { ... }
}
Expand description

Extension trait for some cryptotraphic function that can be domain separated by a tag. Used for hashes and nonce generators.

This is blanket implemented for all digest hashes where the output size divides the block size using the “tagged hash” algorithm described in [BIP340].

Required Methods§

source

fn tag_vectored<'a>( self, tag_components: impl Iterator<Item = &'a [u8]> + Clone ) -> Self

Takes a tag that is split up into pieces.

use digest::Digest;
use secp256kfun::Tag;
let mut hash1 = sha2::Sha256::default()
    .tag_vectored([b"my-domain".as_slice(), b"/my-purpose".as_slice()].into_iter());
let mut hash2 = sha2::Sha256::default().tag(b"my-domain/my-purpose");
hash1.update(b"hello world");
hash2.update(b"hello world");
assert_eq!(hash1.finalize(), hash2.finalize());

Provided Methods§

source

fn tag(self, tag: &[u8]) -> Self

Returns the tagged (domain separated) instance of self.

When implemented on block hashes, the hashes internal buffer should be empty before calling it.

§Example
use digest::Digest;
use secp256kfun::Tag;
let mut hash = sha2::Sha256::default().tag(b"my-domain/my-purpose");
hash.update(b"hello world");
println!("{:?}", hash.finalize());

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Tag for NoNonces

source§

impl<H: Tag> Tag for Deterministic<H>

source§

impl<H: Tag, R> Tag for Synthetic<H, R>

source§

impl<H: BlockSizeUser + Digest + Default + Clone> Tag for H
where <H as BlockSizeUser>::BlockSize: PartialDiv<H::OutputSize>, <<H as BlockSizeUser>::BlockSize as PartialDiv<H::OutputSize>>::Output: Unsigned,