Skip to content

Commit c113836

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 7a7d966 + 868a6d8 commit c113836

File tree

9 files changed

+277
-169
lines changed

9 files changed

+277
-169
lines changed

.github/actions/ci_script/action.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 108 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ jobs:
2121
- name: Check formatting
2222
run: cargo fmt --all -- --check
2323

24+
lints:
25+
name: Check lints with clippy
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Check formatting
30+
run: cargo clippy --all-targets -- -D clippy::all -D clippy::cargo
31+
2432
docs:
2533
name: Check documentation
2634
runs-on: ubuntu-latest
@@ -29,17 +37,105 @@ jobs:
2937
- name: Check documentation
3038
run: RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items --no-deps
3139

32-
build:
33-
name: Execute CI script
40+
check:
41+
name: Check for errors
3442
runs-on: ubuntu-latest
43+
continue-on-error: true
44+
strategy:
45+
matrix:
46+
target:
47+
- x86_64-unknown-linux-gnu
48+
- armv7-unknown-linux-gnueabi
49+
- armv7-unknown-linux-gnueabihf
50+
- arm-unknown-linux-gnueabi
51+
- aarch64-unknown-linux-gnu
52+
- i686-unknown-linux-gnu
53+
- loongarch64-unknown-linux-gnu
54+
- powerpc64-unknown-linux-gnu
55+
- powerpc64le-unknown-linux-gnu
56+
- x86_64-pc-windows-msvc
57+
- x86_64-apple-darwin
58+
- aarch64-apple-darwin
59+
- x86_64-unknown-freebsd
60+
- riscv64gc-unknown-linux-gnu
61+
toolchain:
62+
- stable
63+
- "1.77" # MSRV
3564
steps:
3665
- uses: actions/checkout@v4
3766
- name: Setup Rust toolchain
3867
uses: actions-rs/toolchain@v1
3968
with:
40-
toolchain: stable
41-
- name: "Installs SoftHSM and execute tests"
42-
uses: ./.github/actions/ci_script
69+
toolchain: ${{ matrix.toolchain }}
70+
default: true
71+
- name: Install Rust target
72+
run: rustup target add ${{ matrix.target }}
73+
- name: Check source
74+
run: cargo check --target ${{ matrix.target }} --workspace --all-targets
75+
- name: Check all features source
76+
run: cargo check --target ${{ matrix.target }} --all-features --workspace --all-targets
77+
78+
check-matrix:
79+
name: Check if all checks succeeded
80+
if: always()
81+
needs:
82+
- check
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Decide whether the needed jobs succeeded or failed
86+
uses: re-actors/alls-green@release/v1
87+
with:
88+
jobs: ${{ toJSON(needs) }}
89+
90+
tests-softhsm:
91+
name: Run tests against SoftHSM
92+
continue-on-error: true
93+
strategy:
94+
matrix:
95+
target:
96+
- x86_64-unknown-linux-gnu
97+
- i686-unknown-linux-gnu
98+
- aarch64-unknown-linux-gnu
99+
toolchain:
100+
- stable
101+
- "1.77" # MSRV
102+
include:
103+
- target: x86_64-unknown-linux-gnu
104+
runner: ubuntu-latest
105+
- target: i686-unknown-linux-gnu
106+
runner: ubuntu-latest
107+
- target: aarch64-unknown-linux-gnu
108+
runner: ubuntu-24.04-arm
109+
runs-on: ${{ matrix.runner }}
110+
steps:
111+
- uses: actions/checkout@v4
112+
- name: Setup Rust toolchain
113+
uses: actions-rs/toolchain@v1
114+
with:
115+
toolchain: ${{ matrix.toolchain }}
116+
default: true
117+
- name: Install SoftHSM
118+
run: |
119+
if [ "${{ matrix.target }}" = "i686-unknown-linux-gnu" ]; then
120+
sudo dpkg --add-architecture i386
121+
sudo apt-get update -y -qq
122+
sudo apt-get install -y -qq gcc-multilib:i386 libsofthsm2:i386 gcc:i386
123+
else
124+
sudo apt-get update -y -qq
125+
sudo apt-get install -y -qq libsofthsm2
126+
fi
127+
mkdir /tmp/tokens
128+
echo "directories.tokendir = /tmp/tokens" > /tmp/softhsm2.conf
129+
- name: Install Rust target
130+
run: rustup target add ${{ matrix.target }}
131+
- name: Check
132+
run: cargo check --target ${{ matrix.target }} --workspace --all-targets
133+
- name: Test script
134+
env:
135+
TEST_PKCS11_MODULE: /usr/lib/softhsm/libsofthsm2.so
136+
SOFTHSM2_CONF: /tmp/softhsm2.conf
137+
RUSTFLAGS: "-D warnings"
138+
run: RUST_BACKTRACE=1 cargo test --target ${{ matrix.target }}
43139

44140
build-windows:
45141
name: Build on Windows
@@ -65,27 +161,14 @@ jobs:
65161
RUST_BACKTRACE=1 cargo build --all-features &&
66162
RUST_BACKTRACE=1 cargo test
67163
68-
69-
build-msrv:
70-
name: MSRV - Execute CI script
71-
runs-on: ubuntu-latest
72-
steps:
73-
- uses: actions/checkout@v4
74-
- name: Setup Rust toolchain on MSRV
75-
uses: actions-rs/toolchain@v1
76-
with:
77-
toolchain: 1.66.0
78-
- name: "Installs SoftHSM and execute tests"
79-
uses: ./.github/actions/ci_script
80-
81164
links:
82165
name: Check links
83166
runs-on: ubuntu-latest
84167
steps:
85-
- uses: actions/checkout@v4
86-
- name: Link Checker
87-
uses: peter-evans/link-checker@v1
88-
with:
89-
args: -v -r *.md
90-
- name: Fail if there were link errors
91-
run: exit ${{ steps.lc.outputs.exit_code }}
168+
- uses: actions/checkout@v4
169+
- name: Link Checker
170+
uses: peter-evans/link-checker@v1
171+
with:
172+
args: -v -r *.md
173+
- name: Fail if there were link errors
174+
run: exit ${{ steps.lc.outputs.exit_code }}

.github/workflows/nightly.yml

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,6 @@ jobs:
2828
- name: Execute cargo udeps
2929
run: cargo +nightly udeps
3030

31-
build:
32-
name: Execute builds with updated dependencies
33-
runs-on: ubuntu-latest
34-
steps:
35-
- uses: actions/checkout@v4
36-
- name: Setup Rust toolchain
37-
uses: actions-rs/toolchain@v1
38-
with:
39-
toolchain: stable
40-
41-
- name: Install SoftHSM
42-
run: |
43-
sudo apt-get update -y -qq &&
44-
sudo apt-get install -y -qq libsofthsm2 &&
45-
mkdir /tmp/tokens
46-
echo "directories.tokendir = /tmp/tokens" > /tmp/softhsm2.conf
47-
48-
- name: Install Rust targets
49-
run: |
50-
rustup target add armv7-unknown-linux-gnueabi &&
51-
rustup target add armv7-unknown-linux-gnueabihf &&
52-
rustup target add arm-unknown-linux-gnueabi &&
53-
rustup target add aarch64-unknown-linux-gnu &&
54-
rustup target add i686-unknown-linux-gnu &&
55-
rustup target add powerpc64-unknown-linux-gnu &&
56-
rustup target add powerpc64le-unknown-linux-gnu &&
57-
rustup target add x86_64-pc-windows-msvc &&
58-
rustup target add x86_64-apple-darwin &&
59-
rustup target add aarch64-apple-darwin &&
60-
rustup target add x86_64-unknown-freebsd
61-
rustup target add loongarch64-unknown-linux-gnu
62-
rustup target add riscv64gc-unknown-linux-gnu
63-
64-
- name: Test script
65-
env:
66-
TEST_PKCS11_MODULE: /usr/lib/softhsm/libsofthsm2.so
67-
SOFTHSM2_CONF: /tmp/softhsm2.conf
68-
run: |
69-
rm Cargo.lock
70-
./ci.sh
71-
7231
audit:
7332
name: Check for crates with security vulnerabilities
7433
runs-on: ubuntu-latest

ci.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

cryptoki-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["api-bindings", "external-ffi-bindings", "cryptography", "hardware
1010
license = "Apache-2.0"
1111
repository = "https://github.com/parallaxsecond/rust-cryptoki"
1212
documentation = "https://docs.rs/crate/cryptoki-sys"
13-
rust-version = "1.77.0"
13+
rust-version = "1.77"
1414

1515
[build-dependencies]
1616
bindgen = { version = "0.72.0", optional = true }

cryptoki/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["api-bindings", "external-ffi-bindings", "cryptography", "hardware
1010
license = "Apache-2.0"
1111
repository = "https://github.com/parallaxsecond/rust-cryptoki"
1212
documentation = "https://docs.rs/crate/cryptoki"
13-
rust-version = "1.77.0"
13+
rust-version = "1.77"
1414

1515
[dependencies]
1616
bitflags = "2.9.1"

cryptoki/src/mechanism/elliptic_curve.rs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,45 @@ pub struct EcKdf<'a> {
8282
shared_data: Option<&'a [u8]>,
8383
}
8484

85-
impl EcKdf<'_> {
85+
macro_rules! ansi {
86+
{ $func_name: ident, $algo: ident, $algo_name: literal } => {
87+
#[doc = "The key derivation function based on "]
88+
#[doc = $algo_name]
89+
#[doc = " as defined in the ANSI X9.63 standard. The
90+
derived key is produced by concatenating hashes of
91+
the shared value followed by 00000001, 00000002,
92+
etc. until we find enough bytes to fill the
93+
`CKA_VALUE_LEN` of the derived key."]
94+
pub fn $func_name(shared_data: &'a [u8]) -> Self {
95+
Self {
96+
kdf_type: $algo,
97+
shared_data: Some(shared_data),
98+
}
99+
}
100+
}
101+
}
102+
103+
macro_rules! sp800 {
104+
{ $func_name: ident, $algo: ident, $algo_name: literal } => {
105+
#[doc = "The key derivation function based on "]
106+
#[doc = $algo_name]
107+
#[doc = " as defined in the [NIST SP800-56A standard, revision
108+
2](http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Ar2.pdf),
109+
section 5.8.1.1. The derived key is produced by
110+
concatenating hashes of 00000001, 00000002,
111+
etc. followed by the shared value until we find
112+
enough bytes to fill the `CKA_VALUE_LEN` of the
113+
derived key."]
114+
pub fn $func_name(shared_data: &'a [u8]) -> Self {
115+
Self {
116+
kdf_type: $algo,
117+
shared_data: Some(shared_data),
118+
}
119+
}
120+
}
121+
}
122+
123+
impl<'a> EcKdf<'a> {
86124
/// The null transformation. The derived key value is produced by
87125
/// taking bytes from the left of the agreed value. The new key
88126
/// size is limited to the size of the agreed value.
@@ -93,16 +131,25 @@ impl EcKdf<'_> {
93131
}
94132
}
95133

96-
/// The key derivation function based on sha256 as defined in the ANSI X9.63 standard. The
97-
/// derived key is produced by concatenating hashes of the shared
98-
/// value followed by 00000001, 00000002, etc. until we find
99-
/// enough bytes to fill the `CKA_VALUE_LEN` of the derived key.
100-
pub fn sha256() -> Self {
101-
Self {
102-
kdf_type: CKD_SHA256_KDF,
103-
shared_data: None,
104-
}
105-
}
134+
ansi!(sha1, CKD_SHA1_KDF, "SHA1");
135+
ansi!(sha224, CKD_SHA224_KDF, "SHA224");
136+
ansi!(sha256, CKD_SHA256_KDF, "SHA256");
137+
ansi!(sha384, CKD_SHA384_KDF, "SHA384");
138+
ansi!(sha512, CKD_SHA512_KDF, "SHA512");
139+
ansi!(sha3_224, CKD_SHA3_224_KDF, "SHA3_224");
140+
ansi!(sha3_256, CKD_SHA3_256_KDF, "SHA3_256");
141+
ansi!(sha3_384, CKD_SHA3_384_KDF, "SHA3_384");
142+
ansi!(sha3_512, CKD_SHA3_512_KDF, "SHA3_512");
143+
144+
sp800!(sha1_sp800, CKD_SHA1_KDF_SP800, "SHA1");
145+
sp800!(sha224_sp800, CKD_SHA224_KDF_SP800, "SHA224");
146+
sp800!(sha256_sp800, CKD_SHA256_KDF_SP800, "SHA256");
147+
sp800!(sha384_sp800, CKD_SHA384_KDF_SP800, "SHA384");
148+
sp800!(sha512_sp800, CKD_SHA512_KDF_SP800, "SHA512");
149+
sp800!(sha3_224_sp800, CKD_SHA3_224_KDF_SP800, "SHA3_224");
150+
sp800!(sha3_256_sp800, CKD_SHA3_256_KDF_SP800, "SHA3_256");
151+
sp800!(sha3_384_sp800, CKD_SHA3_384_KDF_SP800, "SHA3_384");
152+
sp800!(sha3_512_sp800, CKD_SHA3_512_KDF_SP800, "SHA3_512");
106153

107154
// The intention here is to be able to support other methods with
108155
// shared data, without it being a breaking change, by just adding

0 commit comments

Comments
 (0)