Skip to content

Commit b77c1f3

Browse files
committed
Remove duplicated code.
Signed-off-by: Steven Lee <steven_lee@aspeedtech.com>
1 parent 227f92b commit b77c1f3

File tree

2 files changed

+3
-140
lines changed

2 files changed

+3
-140
lines changed

src/hace_controller.rs

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ const SHA512_256_IV: [u32; 16] = [
118118

119119

120120
const HACE_SHA_BE_EN: u32 = 1 << 3;
121-
pub const HACE_SG_EN: u32 = 1 << 18;
122121
const HACE_CMD_ACC_MODE: u32 = 1 << 8;
122+
pub const HACE_SG_EN: u32 = 1 << 18;
123+
pub const HACE_SG_LAST: u32 = 1 << 31;
123124

124125
const HACE_ALGO_SHA1: u32 = 1 << 5;
125126
const HACE_ALGO_SHA224: u32 = 1 << 6;
@@ -270,86 +271,6 @@ impl HashAlgo {
270271
}
271272
}
272273

273-
pub trait IntoHashAlgo {
274-
fn to_hash_algo() -> HashAlgo;
275-
}
276-
277-
pub struct Digest48(pub [u8; 48]);
278-
279-
impl Default for Digest48 {
280-
fn default() -> Self {
281-
Digest48([0u8; 48])
282-
}
283-
}
284-
285-
impl AsRef<[u8]> for Digest48 {
286-
fn as_ref(&self) -> &[u8] {
287-
&self.0
288-
}
289-
}
290-
291-
impl AsMut<[u8]> for Digest48 {
292-
fn as_mut(&mut self) -> &mut [u8] {
293-
&mut self.0
294-
}
295-
}
296-
297-
pub struct Digest64(pub [u8; 64]);
298-
impl Default for Digest64 {
299-
fn default() -> Self {
300-
Digest64([0u8; 64])
301-
}
302-
}
303-
304-
impl AsRef<[u8]> for Digest64 {
305-
fn as_ref(&self) -> &[u8] {
306-
&self.0
307-
}
308-
}
309-
310-
impl AsMut<[u8]> for Digest64 {
311-
fn as_mut(&mut self) -> &mut [u8] {
312-
&mut self.0
313-
}
314-
}
315-
316-
317-
pub struct Sha1;
318-
pub struct Sha224;
319-
pub struct Sha256;
320-
pub struct Sha384;
321-
pub struct Sha512;
322-
323-
impl Default for Sha256 {
324-
fn default() -> Self { Sha256 }
325-
}
326-
327-
impl Default for Sha384 {
328-
fn default() -> Self { Sha384 }
329-
}
330-
331-
impl Default for Sha512 {
332-
fn default() -> Self { Sha512 }
333-
}
334-
335-
impl IntoHashAlgo for Sha256 {
336-
fn to_hash_algo() -> HashAlgo {
337-
HashAlgo::SHA256
338-
}
339-
}
340-
341-
impl IntoHashAlgo for Sha384 {
342-
fn to_hash_algo() -> HashAlgo {
343-
HashAlgo::SHA384
344-
}
345-
}
346-
347-
impl IntoHashAlgo for Sha512 {
348-
fn to_hash_algo() -> HashAlgo {
349-
HashAlgo::SHA512
350-
}
351-
}
352-
353274
pub struct HaceController<'ctrl> {
354275
pub hace: &'ctrl Hace,
355276
pub algo: HashAlgo,

src/hash.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,6 @@
11
use proposed_traits::digest::*;
22
use core::convert::Infallible;
3-
use crate::hace_controller::HaceController;
4-
use crate::hace_controller::HashAlgo;
5-
6-
const HACE_SG_LAST: u32 = 1 << 31;
7-
#[derive(Default, Copy, Clone)]
8-
pub struct AspeedSg {
9-
pub len: u32,
10-
pub addr: u32,
11-
}
12-
13-
impl AspeedSg {
14-
pub const fn new() -> Self {
15-
Self { len: 0, addr: 0 }
16-
}
17-
}
18-
19-
20-
#[repr(C)]
21-
#[repr(align(64))]
22-
pub struct AspeedHashContext {
23-
pub sg: [AspeedSg; 2],
24-
pub digest: [u8; 64],
25-
pub method: u32,
26-
pub block_size: u32,
27-
pub digcnt: [u64; 2],
28-
pub bufcnt: u32,
29-
pub buffer: [u8; 256],
30-
pub iv_size: u8,
31-
}
32-
33-
impl Default for AspeedHashContext {
34-
fn default() -> Self {
35-
Self {
36-
sg: [AspeedSg::default(); 2],
37-
digest: [0; 64],
38-
method: 0,
39-
block_size: 0,
40-
digcnt: [0; 2],
41-
bufcnt: 0,
42-
buffer: [0; 256],
43-
iv_size: 0,
44-
}
45-
}
46-
}
47-
48-
impl AspeedHashContext {
49-
pub const fn new() -> Self {
50-
Self {
51-
sg: [AspeedSg::new(), AspeedSg::new()],
52-
digest: [0; 64],
53-
method: 0,
54-
block_size: 0,
55-
digcnt: [0; 2],
56-
bufcnt: 0,
57-
buffer: [0; 256],
58-
iv_size: 0,
59-
}
60-
}
61-
}
3+
use crate::hace_controller::{HaceController, HashAlgo, HACE_SG_LAST};
624

635
// DigestAlgorithm implementation for HashAlgo
646
impl DigestAlgorithm for HashAlgo {

0 commit comments

Comments
 (0)