Hash

Struct Hash 

Source
pub struct Hash { /* private fields */ }
Expand description

Hash subsystem.

Provides hardware-accelerated hash functions including SHA-2, SHA-3, SHAKE, HMAC, and HKDF.

§Example

use quantacore::{initialize, open_first_device, HashAlgorithm};

initialize().unwrap();
let device = open_first_device().unwrap();
let hash = device.hash();

// One-shot hashing
let digest = hash.sha256(b"Hello, World!").unwrap();
println!("SHA-256: {}", hex::encode(&digest));

// Incremental hashing
let mut ctx = hash.create_context(HashAlgorithm::Sha3_256).unwrap();
ctx.update(b"Hello, ").unwrap();
ctx.update(b"World!").unwrap();
let digest = ctx.finalize().unwrap();

Implementations§

Source§

impl Hash

Source

pub fn hash(&self, algorithm: HashAlgorithm, data: &[u8]) -> Result<Vec<u8>>

Compute a hash digest.

§Arguments
  • algorithm - The hash algorithm to use
  • data - The data to hash
§Returns

The hash digest.

Source

pub fn sha256(&self, data: &[u8]) -> Result<Vec<u8>>

Compute SHA-256 digest.

Source

pub fn sha384(&self, data: &[u8]) -> Result<Vec<u8>>

Compute SHA-384 digest.

Source

pub fn sha512(&self, data: &[u8]) -> Result<Vec<u8>>

Compute SHA-512 digest.

Source

pub fn sha3_256(&self, data: &[u8]) -> Result<Vec<u8>>

Compute SHA3-256 digest.

Source

pub fn sha3_384(&self, data: &[u8]) -> Result<Vec<u8>>

Compute SHA3-384 digest.

Source

pub fn sha3_512(&self, data: &[u8]) -> Result<Vec<u8>>

Compute SHA3-512 digest.

Source

pub fn shake128(&self, data: &[u8], output_len: usize) -> Result<Vec<u8>>

Compute SHAKE128 output.

§Arguments
  • data - The input data
  • output_len - The desired output length in bytes
Source

pub fn shake256(&self, data: &[u8], output_len: usize) -> Result<Vec<u8>>

Compute SHAKE256 output.

§Arguments
  • data - The input data
  • output_len - The desired output length in bytes
Source

pub fn create_context(&self, algorithm: HashAlgorithm) -> Result<HashContext>

Create a hash context for incremental hashing.

§Example
let mut ctx = hash.create_context(HashAlgorithm::Sha256).unwrap();
ctx.update(b"part 1").unwrap();
ctx.update(b"part 2").unwrap();
let digest = ctx.finalize().unwrap();
Source

pub fn hmac( &self, algorithm: HashAlgorithm, key: &[u8], data: &[u8], ) -> Result<Vec<u8>>

Compute HMAC.

§Arguments
  • algorithm - The hash algorithm to use
  • key - The HMAC key
  • data - The data to authenticate
§Returns

The MAC tag.

Source

pub fn hmac_sha256(&self, key: &[u8], data: &[u8]) -> Result<Vec<u8>>

Compute HMAC-SHA256.

Source

pub fn hmac_sha384(&self, key: &[u8], data: &[u8]) -> Result<Vec<u8>>

Compute HMAC-SHA384.

Source

pub fn hmac_sha512(&self, key: &[u8], data: &[u8]) -> Result<Vec<u8>>

Compute HMAC-SHA512.

Source

pub fn hkdf( &self, algorithm: HashAlgorithm, ikm: &[u8], salt: &[u8], info: &[u8], output_len: usize, ) -> Result<Vec<u8>>

Derive a key using HKDF.

§Arguments
  • algorithm - The hash algorithm to use
  • ikm - Input keying material
  • salt - Optional salt (can be empty)
  • info - Optional context info (can be empty)
  • output_len - Desired output length
§Returns

The derived key material.

Source

pub fn hkdf_sha256( &self, ikm: &[u8], salt: &[u8], info: &[u8], output_len: usize, ) -> Result<Vec<u8>>

Derive a key using HKDF-SHA256.

Trait Implementations§

Source§

impl Clone for Hash

Source§

fn clone(&self) -> Hash

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Hash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Hash

§

impl RefUnwindSafe for Hash

§

impl Send for Hash

§

impl Sync for Hash

§

impl Unpin for Hash

§

impl UnwindSafe for Hash

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.