Skip to content

Commit bcef572

Browse files
Merge pull request #19 from gasbytes/ci-cd
Add Github Actions workflow for CI/CD
2 parents 3bd438a + 7c19791 commit bcef572

File tree

28 files changed

+324
-228
lines changed

28 files changed

+324
-228
lines changed

.github/workflows/macos-build.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: macOS Build and Test
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
macos-build:
11+
name: Build and Test (macOS)
12+
runs-on: macos-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Build Prerequisites
17+
run: |
18+
brew install autoconf libtool automake
19+
20+
- name: Install Rust
21+
uses: dtolnay/rust-toolchain@master
22+
with:
23+
toolchain: stable
24+
components: rustfmt, clippy
25+
26+
- name: Cache Rust dependencies
27+
uses: actions/cache@v3
28+
with:
29+
path: |
30+
~/.cargo/registry
31+
~/.cargo/git
32+
target
33+
key: macos-cargo-${{ hashFiles('**/Cargo.lock') }}
34+
restore-keys: |
35+
macos-cargo-
36+
37+
- name: Build and Test wolfcrypt-rs
38+
run: |
39+
cd wolfcrypt-rs
40+
make build
41+
make test
42+
43+
- name: Build and Test rustls-wolfcrypt-provider
44+
run: |
45+
cd rustls-wolfcrypt-provider
46+
make build
47+
make test
48+
49+
- name: Check formatting
50+
run: |
51+
cd wolfcrypt-rs
52+
cargo fmt --all -- --check
53+
cd ../rustls-wolfcrypt-provider
54+
cargo fmt --all -- --check
55+
56+
- name: Run clippy
57+
run: |
58+
cd wolfcrypt-rs
59+
cargo clippy -- -D warnings
60+
cd ../rustls-wolfcrypt-provider
61+
cargo clippy -- -D warnings

.github/workflows/ubuntu-build.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Ubuntu Build and Test
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
ubuntu-build:
11+
name: Build and Test (Ubuntu)
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Build Prerequisites
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y build-essential autoconf libtool
20+
21+
- name: Install Rust
22+
uses: dtolnay/rust-toolchain@master
23+
with:
24+
toolchain: stable
25+
components: rustfmt, clippy
26+
27+
- name: Cache Rust dependencies
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.cargo/registry
32+
~/.cargo/git
33+
target
34+
key: ubuntu-cargo-${{ hashFiles('**/Cargo.lock') }}
35+
restore-keys: |
36+
ubuntu-cargo-
37+
38+
- name: Build and Test wolfcrypt-rs
39+
run: |
40+
cd wolfcrypt-rs
41+
make build
42+
make test
43+
44+
- name: Build and Test rustls-wolfcrypt-provider
45+
run: |
46+
cd rustls-wolfcrypt-provider
47+
make build
48+
make test
49+
50+
- name: Check formatting
51+
run: |
52+
cd wolfcrypt-rs
53+
cargo fmt --all -- --check
54+
cd ../rustls-wolfcrypt-provider
55+
cargo fmt --all -- --check
56+
57+
- name: Run clippy
58+
run: |
59+
cd wolfcrypt-rs
60+
cargo clippy -- -D warnings
61+
cd ../rustls-wolfcrypt-provider
62+
cargo clippy -- -D warnings

rustls-wolfcrypt-provider/src/aead/aes128gcm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::check_if_zero;
2-
use crate::types::types::*;
2+
use crate::types::*;
33
use alloc::boxed::Box;
44
use alloc::vec;
55
use core::mem;

rustls-wolfcrypt-provider/src/aead/aes256gcm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::check_if_zero;
2-
use crate::types::types::*;
2+
use crate::types::*;
33
use alloc::boxed::Box;
44
use alloc::vec;
55
use core::mem;

rustls-wolfcrypt-provider/src/hkdf.rs

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use rustls::crypto::tls13::{self, Hkdf as RustlsHkdf};
21
use alloc::boxed::Box;
32
use alloc::vec;
4-
use core::mem;
53
use alloc::vec::Vec;
4+
use core::mem;
5+
use rustls::crypto::tls13::{self, Hkdf as RustlsHkdf};
66
use wolfcrypt_rs::*;
77

88
use crate::error::check_if_zero;
9-
use crate::hmac::hmac::WCShaHmac;
9+
use crate::hmac::WCShaHmac;
1010

1111
pub struct WCHkdfUsingHmac(pub WCShaHmac);
1212

@@ -42,7 +42,11 @@ impl RustlsHkdf for WCHkdfUsingHmac {
4242
};
4343
check_if_zero(ret).unwrap();
4444

45-
Box::new(WolfHkdfExpander::new(extracted_key, self.0.hash_type().try_into().unwrap(), self.0.hash_len()))
45+
Box::new(WolfHkdfExpander::new(
46+
extracted_key,
47+
self.0.hash_type().try_into().unwrap(),
48+
self.0.hash_len(),
49+
))
4650
}
4751

4852
fn expander_for_okm(
@@ -74,28 +78,13 @@ impl RustlsHkdf for WCHkdfUsingHmac {
7478
};
7579
check_if_zero(ret).unwrap();
7680

77-
ret = unsafe {
78-
wc_HmacUpdate(
79-
&mut hmac_ctx,
80-
message.as_ptr(),
81-
message.len() as u32,
82-
)
83-
};
81+
ret = unsafe { wc_HmacUpdate(&mut hmac_ctx, message.as_ptr(), message.len() as u32) };
8482
check_if_zero(ret).unwrap();
8583

86-
ret = unsafe {
87-
wc_HmacFinal(
88-
&mut hmac_ctx,
89-
hmac.as_mut_ptr(),
90-
)
91-
};
84+
ret = unsafe { wc_HmacFinal(&mut hmac_ctx, hmac.as_mut_ptr()) };
9285
check_if_zero(ret).unwrap();
9386

94-
unsafe {
95-
wc_HmacFree(
96-
&mut hmac_ctx,
97-
)
98-
};
87+
unsafe { wc_HmacFree(&mut hmac_ctx) };
9988
check_if_zero(ret).unwrap();
10089

10190
rustls::crypto::hmac::Tag::new(&hmac)
@@ -104,9 +93,9 @@ impl RustlsHkdf for WCHkdfUsingHmac {
10493

10594
/// Expander implementation that holds the extracted key material from HKDF extract phase
10695
struct WolfHkdfExpander {
107-
extracted_key: Vec<u8>, // The pseudorandom key (PRK) output from HKDF-Extract
96+
extracted_key: Vec<u8>, // The pseudorandom key (PRK) output from HKDF-Extract
10897
hash_type: i32, // The wolfSSL hash algorithm identifier
109-
hash_len: usize, // Length of the hash function output
98+
hash_len: usize, // Length of the hash function output
11099
}
111100

112101
impl WolfHkdfExpander {
@@ -126,7 +115,7 @@ impl tls13::HkdfExpander for WolfHkdfExpander {
126115
output: &mut [u8],
127116
) -> Result<(), tls13::OutputLengthError> {
128117
let info_concat = info.concat();
129-
118+
130119
if output.len() > 255 * self.hash_len {
131120
return Err(tls13::OutputLengthError);
132121
}
@@ -142,7 +131,7 @@ impl tls13::HkdfExpander for WolfHkdfExpander {
142131
output.len() as u32,
143132
);
144133
}
145-
134+
146135
Ok(())
147136
}
148137

@@ -179,10 +168,10 @@ mod tests {
179168

180169
let hkdf = WCHkdfUsingHmac(WCShaHmac::new(wc_HashType_WC_HASH_TYPE_SHA256));
181170
let expander = hkdf.extract_from_secret(Some(&salt), &ikm);
182-
171+
183172
let mut okm = vec![0u8; 42]; // Length from test vector
184173
expander.expand_slice(&[&info], &mut okm).unwrap();
185-
174+
186175
assert_eq!(&okm[..], &expected_okm[..]);
187176
}
188177

@@ -194,13 +183,13 @@ mod tests {
194183
let ikm = hex!("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
195184
let salt = hex!("000102030405060708090a0b0c");
196185
let info = hex!("f0f1f2f3f4f5f6f7f8f9");
197-
186+
198187
let hkdf = WCHkdfUsingHmac(WCShaHmac::new(wc_HashType_WC_HASH_TYPE_SHA384));
199188
let expander = hkdf.extract_from_secret(Some(&salt), &ikm);
200-
189+
201190
let mut okm = vec![0u8; 48]; // SHA384 output length
202191
expander.expand_slice(&[&info], &mut okm).unwrap();
203-
192+
204193
// Just verify we can generate output - actual value would need a verified test vector
205194
assert!(!okm.iter().all(|&x| x == 0));
206195
}
@@ -211,12 +200,12 @@ mod tests {
211200
fn test_hkdf_output_length_limit() {
212201
let hkdf = WCHkdfUsingHmac(WCShaHmac::new(wc_HashType_WC_HASH_TYPE_SHA256));
213202
let expander = hkdf.extract_from_zero_ikm(None);
214-
203+
215204
// Maximum allowed length (255 * hash_len)
216205
let max_len = 255 * 32;
217206
let mut okm = vec![0u8; max_len];
218207
assert!(expander.expand_slice(&[&[]], &mut okm).is_ok());
219-
208+
220209
// Exceeding maximum length should fail
221210
let mut okm = vec![0u8; max_len + 1];
222211
assert!(expander.expand_slice(&[&[]], &mut okm).is_err());
@@ -229,17 +218,17 @@ mod tests {
229218
let hkdf = WCHkdfUsingHmac(WCShaHmac::new(wc_HashType_WC_HASH_TYPE_SHA256));
230219
let salt = hex!("000102030405060708090a0b0c");
231220
let info = hex!("f0f1f2f3f4f5f6f7f8f9");
232-
221+
233222
let expander = hkdf.extract_from_zero_ikm(Some(&salt));
234-
223+
235224
let mut okm1 = vec![0u8; 32];
236225
expander.expand_slice(&[&info], &mut okm1).unwrap();
237-
226+
238227
// Verify that zero IKM produces consistent output
239228
let expander2 = hkdf.extract_from_zero_ikm(Some(&salt));
240229
let mut okm2 = vec![0u8; 32];
241230
expander2.expand_slice(&[&info], &mut okm2).unwrap();
242-
231+
243232
assert_eq!(okm1, okm2);
244233
}
245234

@@ -252,22 +241,24 @@ mod tests {
252241
let info1 = hex!("f0f1f2f3");
253242
let info2 = hex!("f4f5f6f7");
254243
let info3 = hex!("f8f9");
255-
244+
256245
let expander = hkdf.extract_from_zero_ikm(Some(&salt));
257-
246+
258247
// Test with multiple info components
259248
let mut okm1 = vec![0u8; 32];
260-
expander.expand_slice(&[&info1, &info2, &info3], &mut okm1).unwrap();
261-
249+
expander
250+
.expand_slice(&[&info1, &info2, &info3], &mut okm1)
251+
.unwrap();
252+
262253
// Test with concatenated info
263254
let mut info_concat = Vec::new();
264255
info_concat.extend_from_slice(&info1);
265256
info_concat.extend_from_slice(&info2);
266257
info_concat.extend_from_slice(&info3);
267-
258+
268259
let mut okm2 = vec![0u8; 32];
269260
expander.expand_slice(&[&info_concat], &mut okm2).unwrap();
270-
261+
271262
// Results should be identical
272263
assert_eq!(okm1, okm2);
273264
}

rustls-wolfcrypt-provider/src/hmac/hmac.rs renamed to rustls-wolfcrypt-provider/src/hmac/mod.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::{error::check_if_zero, types::types::*};
2-
use alloc::{boxed::Box, vec::Vec, vec};
1+
use crate::{error::check_if_zero, types::*};
2+
use alloc::{boxed::Box, vec, vec::Vec};
33
use core::mem;
44
use foreign_types::ForeignType;
55
use rustls::crypto;
@@ -102,24 +102,14 @@ impl WCHmacKey {
102102
}
103103

104104
fn hmac_update(&self, hmac_object: HmacObject, input: &[u8]) {
105-
let ret = unsafe {
106-
wc_HmacUpdate(
107-
hmac_object.as_ptr(),
108-
input.as_ptr(),
109-
input.len() as word32
110-
)
111-
};
105+
let ret =
106+
unsafe { wc_HmacUpdate(hmac_object.as_ptr(), input.as_ptr(), input.len() as word32) };
112107
check_if_zero(ret).unwrap();
113108
}
114109

115110
fn hmac_final(&self, hmac_object: HmacObject) -> Vec<u8> {
116111
let mut digest = vec![0u8; self.variant.digest_size()];
117-
let ret = unsafe {
118-
wc_HmacFinal(
119-
hmac_object.as_ptr(),
120-
digest.as_mut_ptr()
121-
)
122-
};
112+
let ret = unsafe { wc_HmacFinal(hmac_object.as_ptr(), digest.as_mut_ptr()) };
123113
check_if_zero(ret).unwrap();
124114
digest
125115
}

rustls-wolfcrypt-provider/src/hmac/sha256hmac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{error::check_if_zero, types::types::*};
1+
use crate::{error::check_if_zero, types::*};
22
use alloc::boxed::Box;
33
use alloc::vec::Vec;
44
use core::mem;

rustls-wolfcrypt-provider/src/hmac/sha384hmac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{error::check_if_zero, types::types::*};
1+
use crate::{error::check_if_zero, types::*};
22
use alloc::boxed::Box;
33
use alloc::vec::Vec;
44
use core::mem;

rustls-wolfcrypt-provider/src/kx/sec256r1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{error::check_if_zero, types::types::*};
1+
use crate::{error::check_if_zero, types::*};
22
use alloc::boxed::Box;
33
use alloc::vec;
44
use alloc::vec::Vec;

rustls-wolfcrypt-provider/src/kx/sec384r1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::*;
2-
use crate::types::types::*;
2+
use crate::types::*;
33
use alloc::boxed::Box;
44
use alloc::vec;
55
use alloc::vec::Vec;

0 commit comments

Comments
 (0)