Skip to content

Commit 4defcb5

Browse files
committed
hmac: introduce hmac driver
Add hmac driver based on the implementation in aspeed zephyr sdk. Currently, accumulative (multi-part) mode is not supported, aligning with the limitations of the original Zephyr driver. Signed-off-by: Steven Lee <steven_lee@aspeedtech.com>
1 parent e23963d commit 4defcb5

File tree

7 files changed

+831
-17
lines changed

7 files changed

+831
-17
lines changed

src/hash.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,14 @@ impl IntoHashAlgo for Sha512 {
368368
}
369369
}
370370

371-
pub struct Controller {
372-
hace: Hace,
371+
pub struct Controller<'ctrl> {
372+
pub hace: &'ctrl Hace,
373373
algo: HashAlgo,
374374
aspeed_hash_ctx: *mut AspeedHashContext,
375375
}
376376

377-
impl Controller {
378-
pub fn new(hace: Hace) -> Self {
377+
impl <'ctrl> Controller<'ctrl> {
378+
pub fn new(hace: &'ctrl Hace) -> Self {
379379
Self {
380380
hace,
381381
algo: HashAlgo::SHA256,
@@ -385,11 +385,11 @@ impl Controller {
385385
}
386386

387387

388-
impl<'a> proposed_traits::digest::ErrorType for Controller {
388+
impl<'a> ErrorType for Controller<'_> {
389389
type Error = Infallible;
390390
}
391391

392-
impl Controller {
392+
impl Controller<'_> {
393393
pub fn ctx_mut(&mut self) -> &mut AspeedHashContext {
394394
unsafe { &mut *self.aspeed_hash_ctx }
395395
}
@@ -470,12 +470,12 @@ impl Controller {
470470
}
471471

472472

473-
impl<A> DigestInit<A> for Controller
473+
impl<'ctrl, A> DigestInit<A> for Controller<'ctrl>
474474
where
475475
A: DigestAlgorithm + IntoHashAlgo,
476476
A::DigestOutput: Default + AsMut<[u8]>,
477477
{
478-
type OpContext<'a> = OpContextImpl<'a, A> where Self: 'a; // Define your OpContext type here
478+
type OpContext<'a> = OpContextImpl<'a, 'ctrl, A> where Self: 'a; // Define your OpContext type here
479479

480480
fn init<'a>(&'a mut self, _algo: A) -> Result<Self::OpContext<'a>, Self::Error> {
481481
self.algo = A::to_hash_algo();
@@ -493,19 +493,19 @@ where
493493
}
494494
}
495495

496-
pub struct OpContextImpl<'a, A: DigestAlgorithm + IntoHashAlgo> {
497-
pub controller: &'a mut Controller,
496+
pub struct OpContextImpl<'a, 'ctrl, A: DigestAlgorithm + IntoHashAlgo> {
497+
pub controller: &'a mut Controller<'ctrl>,
498498
_phantom: core::marker::PhantomData<A>,
499499
}
500500

501-
impl<'a, A> proposed_traits::digest::ErrorType for OpContextImpl<'a, A>
501+
impl<'a, 'ctrl, A> proposed_traits::digest::ErrorType for OpContextImpl<'a, 'ctrl, A>
502502
where
503503
A: DigestAlgorithm + IntoHashAlgo,
504504
{
505505
type Error = Infallible;
506506
}
507507

508-
impl<'a, A> DigestOp for OpContextImpl<'a, A>
508+
impl<'a, 'ctrl, A> DigestOp for OpContextImpl<'a, 'ctrl, A>
509509
where
510510
A: DigestAlgorithm + IntoHashAlgo,
511511
A::DigestOutput: Default + AsMut<[u8]>

0 commit comments

Comments
 (0)