Skip to content

Fix Windows build compatibility #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
- name: "Installs SoftHSM and execute tests"
uses: ./.github/actions/ci_script

build-windows:
name: Build on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- run: cargo check --all-features --workspace --all-targets

tests-kryoptic:
name: Run tests against Kryoptic
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions cryptoki/src/mechanism/kbkdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-curr/v3.0/os/pkcs11-curr-v3.0-os.html#_Toc30061446>

use core::{convert::TryInto, marker::PhantomData, ptr};
use std::mem::size_of;
use std::num::NonZeroUsize;

use cryptoki_sys::{
Expand Down
4 changes: 2 additions & 2 deletions cryptoki/src/slot/slot_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::fmt::Debug;
bitflags! {
/// Collection of flags defined for [`CK_SLOT_INFO`]
struct SlotInfoFlags: CK_FLAGS {
const TOKEN_PRESENT=CKF_TOKEN_PRESENT;
const REMOVABLE_DEVICE=CKF_REMOVABLE_DEVICE;
const TOKEN_PRESENT = CKF_TOKEN_PRESENT;
const REMOVABLE_DEVICE = CKF_REMOVABLE_DEVICE;
const HW_SLOT = CKF_HW_SLOT;
}
}
Expand Down
9 changes: 8 additions & 1 deletion cryptoki/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ pub struct Ulong {
val: CK_ULONG,
}

impl Ulong {
/// Create a new variable
#[must_use]
pub const fn new(ulong: CK_ULONG) -> Self {
Ulong { val: ulong }
}
}

impl Deref for Ulong {
type Target = CK_ULONG;

Expand Down Expand Up @@ -284,7 +292,6 @@ pub type RawAuthPin = SecretBox<Vec<u8>>;

#[cfg(test)]
mod test {

use super::*;
const UTC_TIME: UtcTime = UtcTime {
year: 1970,
Expand Down
78 changes: 39 additions & 39 deletions cryptoki/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use cryptoki::object::{
Attribute, AttributeInfo, AttributeType, KeyType, ObjectClass, ObjectHandle,
};
use cryptoki::session::{SessionState, UserType};
use cryptoki::types::AuthPin;
use cryptoki::types::{AuthPin, Ulong};
use serial_test::serial;
use std::collections::HashMap;
use std::num::NonZeroUsize;
Expand All @@ -27,8 +27,8 @@ use std::thread;
use cryptoki::mechanism::ekdf::AesCbcDeriveParams;
use testresult::TestResult;

const AES128_BLOCK_SIZE: usize = 128 / 8;
const AES256_BLOCK_SIZE: usize = 256 / 8;
const AES128_BLOCK_SIZE: Ulong = Ulong::new(128 / 8);
const AES256_BLOCK_SIZE: Ulong = Ulong::new(256 / 8);

#[test]
#[serial]
Expand Down Expand Up @@ -455,7 +455,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
let template = vec![
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand All @@ -473,7 +473,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
session.encrypt_init(&Mechanism::AesEcb, key)?;

let mut encrypted_data = vec![];
for part in data.chunks(AES128_BLOCK_SIZE) {
for part in data.chunks(AES128_BLOCK_SIZE.into()) {
encrypted_data.extend(session.encrypt_update(part)?);
}
encrypted_data.extend(session.encrypt_final()?);
Expand All @@ -482,7 +482,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
session.decrypt_init(&Mechanism::AesEcb, key)?;

let mut decrypted_data = vec![];
for part in encrypted_data.chunks(AES128_BLOCK_SIZE) {
for part in encrypted_data.chunks(AES128_BLOCK_SIZE.into()) {
decrypted_data.extend(session.decrypt_update(part)?);
}
decrypted_data.extend(session.decrypt_final()?);
Expand Down Expand Up @@ -566,7 +566,7 @@ fn encrypt_decrypt_multipart_already_initialized() -> TestResult {
let template = vec![
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down Expand Up @@ -1197,7 +1197,7 @@ fn get_attribute_info_test() -> TestResult {
session.generate_key_pair(&mechanism, &pub_key_template, &priv_key_template)?;

let pub_attribs = vec![AttributeType::PublicExponent, AttributeType::Modulus];
let mut priv_attribs = [
let priv_attribs = [
AttributeType::PublicExponent,
AttributeType::Modulus,
AttributeType::PrivateExponent,
Expand Down Expand Up @@ -1678,7 +1678,7 @@ fn sha256_digest_multipart_with_key() -> TestResult {
let key_template = vec![
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
// Key must be non-sensitive and extractable to get its bytes and digest them directly, for comparison
Attribute::Sensitive(false),
Attribute::Extractable(true),
Expand Down Expand Up @@ -2179,7 +2179,7 @@ fn kbkdf_counter_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2190,7 +2190,7 @@ fn kbkdf_counter_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down Expand Up @@ -2234,7 +2234,7 @@ fn kbkdf_counter_mode() -> TestResult {
let wanted_attributes = [
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
Attribute::Sign(false),
Expand Down Expand Up @@ -2272,7 +2272,7 @@ fn kbkdf_feedback_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2283,7 +2283,7 @@ fn kbkdf_feedback_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down Expand Up @@ -2350,7 +2350,7 @@ fn kbkdf_feedback_mode() -> TestResult {
let wanted_attributes = [
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
Attribute::Sign(false),
Expand Down Expand Up @@ -2389,7 +2389,7 @@ fn kbkdf_double_pipeline_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2400,7 +2400,7 @@ fn kbkdf_double_pipeline_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down Expand Up @@ -2440,7 +2440,7 @@ fn kbkdf_double_pipeline_mode() -> TestResult {
let wanted_attributes = [
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
Attribute::Sign(false),
Expand Down Expand Up @@ -2478,7 +2478,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2490,7 +2490,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
],
Expand All @@ -2499,7 +2499,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Sign(true),
Attribute::Verify(true),
],
Expand Down Expand Up @@ -2570,7 +2570,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
vec![
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
Attribute::Sign(false),
Expand All @@ -2580,7 +2580,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
vec![
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Encrypt(false),
Attribute::Decrypt(false),
Attribute::Sign(true),
Expand Down Expand Up @@ -2634,7 +2634,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2646,7 +2646,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
],
Expand All @@ -2655,7 +2655,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Sign(true),
Attribute::Verify(true),
],
Expand Down Expand Up @@ -2759,7 +2759,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
vec![
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
Attribute::Sign(false),
Expand All @@ -2769,7 +2769,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
vec![
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Encrypt(false),
Attribute::Decrypt(false),
Attribute::Sign(true),
Expand Down Expand Up @@ -2819,7 +2819,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2831,7 +2831,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
],
Expand All @@ -2840,7 +2840,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Sign(true),
Attribute::Verify(true),
],
Expand Down Expand Up @@ -2907,7 +2907,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
vec![
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
Attribute::Sign(false),
Expand All @@ -2917,7 +2917,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
vec![
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES128_BLOCK_SIZE),
Attribute::Encrypt(false),
Attribute::Decrypt(false),
Attribute::Sign(true),
Expand Down Expand Up @@ -2971,7 +2971,7 @@ fn kbkdf_invalid_data_params_counter_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -2982,7 +2982,7 @@ fn kbkdf_invalid_data_params_counter_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down Expand Up @@ -3120,7 +3120,7 @@ fn kbkdf_invalid_data_params_feedback_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -3131,7 +3131,7 @@ fn kbkdf_invalid_data_params_feedback_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down Expand Up @@ -3243,7 +3243,7 @@ fn kbkdf_invalid_data_params_double_pipeline_mode() -> TestResult {
let base_template = [
Attribute::Token(true),
Attribute::Private(false),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Derive(true),
];
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
Expand All @@ -3254,7 +3254,7 @@ fn kbkdf_invalid_data_params_double_pipeline_mode() -> TestResult {
Attribute::Private(false),
Attribute::Class(ObjectClass::SECRET_KEY),
Attribute::KeyType(KeyType::AES),
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
Attribute::ValueLen(AES256_BLOCK_SIZE),
Attribute::Encrypt(true),
Attribute::Decrypt(true),
];
Expand Down
Loading