Skip to content

Commit b75be94

Browse files
Rust wrapper: use SHA256::DIGEST_SIZE instead of WC_SHA256_DIGEST_SIZE
1 parent 5b8115e commit b75be94

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

wrapper/rust/wolfssl/src/wolfcrypt/hkdf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ use wolfssl_sys as ws;
5252
/// ```rust
5353
/// use wolfssl::wolfcrypt::hkdf::*;
5454
/// use wolfssl::wolfcrypt::hmac::HMAC;
55-
/// use wolfssl_sys as ws;
55+
/// use wolfssl::wolfcrypt::sha::SHA256;
5656
/// let ikm = b"MyPassword0";
5757
/// let salt = b"12345678ABCDEFGH";
58-
/// let mut extract_out = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
58+
/// let mut extract_out = [0u8; SHA256::DIGEST_SIZE];
5959
/// hkdf_extract(HMAC::TYPE_SHA256, Some(salt), ikm, &mut extract_out).expect("Error with hkdf_extract()");
6060
/// ```
6161
pub fn hkdf_extract(typ: i32, salt: Option<&[u8]>, key: &[u8], out: &mut [u8]) -> Result<(), i32> {
@@ -102,10 +102,10 @@ pub fn hkdf_extract(typ: i32, salt: Option<&[u8]>, key: &[u8], out: &mut [u8]) -
102102
/// ```rust
103103
/// use wolfssl::wolfcrypt::hkdf::*;
104104
/// use wolfssl::wolfcrypt::hmac::HMAC;
105-
/// use wolfssl_sys as ws;
105+
/// use wolfssl::wolfcrypt::sha::SHA256;
106106
/// let ikm = b"MyPassword0";
107107
/// let salt = b"12345678ABCDEFGH";
108-
/// let mut extract_out = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
108+
/// let mut extract_out = [0u8; SHA256::DIGEST_SIZE];
109109
/// hkdf_extract(HMAC::TYPE_SHA256, Some(salt), ikm, &mut extract_out).expect("Error with hkdf_extract()");
110110
/// let info = b"0";
111111
/// let mut expand_out = [0u8; 16];

wrapper/rust/wolfssl/src/wolfcrypt/kdf.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ use wolfssl_sys as ws;
5050
/// ```rust
5151
/// use wolfssl::wolfcrypt::hmac::HMAC;
5252
/// use wolfssl::wolfcrypt::kdf::*;
53-
/// use wolfssl_sys as ws;
54-
/// let mut secret = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
53+
/// use wolfssl::wolfcrypt::sha::SHA256;
54+
/// let mut secret = [0u8; SHA256::DIGEST_SIZE];
5555
/// tls13_hkdf_extract(HMAC::TYPE_SHA256, None, None, &mut secret).expect("Error with tls13_hkdf_extract()");
5656
/// ```
5757
pub fn tls13_hkdf_extract(typ: i32, salt: Option<&[u8]>, key: Option<&mut [u8]>, out: &mut [u8]) -> Result<(), i32> {
@@ -108,7 +108,7 @@ pub fn tls13_hkdf_extract(typ: i32, salt: Option<&[u8]>, key: Option<&mut [u8]>,
108108
/// ```rust
109109
/// use wolfssl::wolfcrypt::hmac::HMAC;
110110
/// use wolfssl::wolfcrypt::kdf::*;
111-
/// use wolfssl_sys as ws;
111+
/// use wolfssl::wolfcrypt::sha::SHA256;
112112
/// let hash_hello1 = [
113113
/// 0x63u8, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
114114
/// 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
@@ -120,11 +120,11 @@ pub fn tls13_hkdf_extract(typ: i32, salt: Option<&[u8]>, key: Option<&mut [u8]>,
120120
/// 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
121121
/// 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
122122
/// ];
123-
/// let mut secret = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
123+
/// let mut secret = [0u8; SHA256::DIGEST_SIZE];
124124
/// tls13_hkdf_extract(HMAC::TYPE_SHA256, None, None, &mut secret).expect("Error with tls13_hkdf_extract()");
125125
/// let protocol_label = b"tls13 ";
126126
/// let ce_traffic_label = b"c e traffic";
127-
/// let mut expand_out = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
127+
/// let mut expand_out = [0u8; SHA256::DIGEST_SIZE];
128128
/// tls13_hkdf_expand_label(HMAC::TYPE_SHA256, &secret,
129129
/// protocol_label, ce_traffic_label,
130130
/// &hash_hello1, &mut expand_out).expect("Error with tls13_hkdf_expand_label()");

wrapper/rust/wolfssl/tests/test_hkdf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use wolfssl::wolfcrypt::hkdf::*;
22
use wolfssl::wolfcrypt::hmac::HMAC;
3-
use wolfssl_sys as ws;
3+
use wolfssl::wolfcrypt::sha::SHA256;
44

55
#[test]
66
fn test_hkdf_extract_expand() {
77
let ikm = b"MyPassword0";
88
let salt = b"12345678ABCDEFGH";
9-
let mut extract_out = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
9+
let mut extract_out = [0u8; SHA256::DIGEST_SIZE];
1010
hkdf_extract(HMAC::TYPE_SHA256, Some(salt), ikm, &mut extract_out).expect("Error with hkdf_extract()");
1111

1212
let info = b"0";

wrapper/rust/wolfssl/tests/test_hmac.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use wolfssl::wolfcrypt::hmac::*;
2-
use wolfssl_sys as ws;
2+
use wolfssl::wolfcrypt::sha::SHA256;
33

44
#[test]
55
fn test_hmac_sha256() {
66
let hmac_size = HMAC::get_hmac_size_by_type(HMAC::TYPE_SHA256).expect("Error with get_hmac_size_by_type()");
7-
assert_eq!(hmac_size, ws::WC_SHA256_DIGEST_SIZE as usize);
7+
assert_eq!(hmac_size, SHA256::DIGEST_SIZE);
88

99
let keys: [&[u8]; 5] = [
1010
b"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
@@ -38,9 +38,9 @@ fn test_hmac_sha256() {
3838
HMAC::new(HMAC::TYPE_SHA256, keys[i]).expect("Error with new()")
3939
};
4040
let hmac_size = hmac.get_hmac_size().expect("Error with get_hmac_size()");
41-
assert_eq!(hmac_size, ws::WC_SHA256_DIGEST_SIZE as usize);
41+
assert_eq!(hmac_size, SHA256::DIGEST_SIZE);
4242
hmac.update(inputs[i]).expect("Error with update()");
43-
let mut hash = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
43+
let mut hash = [0u8; SHA256::DIGEST_SIZE];
4444
hmac.finalize(&mut hash).expect("Error with finalize()");
4545
assert_eq!(*expected[i], hash);
4646
}

wrapper/rust/wolfssl/tests/test_kdf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use wolfssl::wolfcrypt::hmac::HMAC;
22
use wolfssl::wolfcrypt::kdf::*;
3-
use wolfssl_sys as ws;
3+
use wolfssl::wolfcrypt::sha::SHA256;
44

55
#[test]
66
fn test_tls13_hkdf_extract_expand() {
@@ -16,13 +16,13 @@ fn test_tls13_hkdf_extract_expand() {
1616
0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
1717
];
1818

19-
let mut secret = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
19+
let mut secret = [0u8; SHA256::DIGEST_SIZE];
2020

2121
tls13_hkdf_extract(HMAC::TYPE_SHA256, None, None, &mut secret).expect("Error with tls13_hkdf_extract()");
2222

2323
let protocol_label = b"tls13 ";
2424
let ce_traffic_label = b"c e traffic";
25-
let mut expand_out = [0u8; ws::WC_SHA256_DIGEST_SIZE as usize];
25+
let mut expand_out = [0u8; SHA256::DIGEST_SIZE];
2626

2727
tls13_hkdf_expand_label(HMAC::TYPE_SHA256, &secret,
2828
protocol_label, ce_traffic_label,

0 commit comments

Comments
 (0)