From 4acbe61e1399b7890561c2465921c437faf1b211 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Wed, 8 Apr 2026 08:03:56 +1000 Subject: [PATCH] Fix PKCS#11 struct packing on Windows to match NSS 1-byte alignment via ahochheiden in https://phabricator.services.mozilla.com/D292613 --- .../support/rc_crypto/nss/nss_sys/src/bindings/pkcs11n.rs | 8 ++++++-- .../support/rc_crypto/nss/nss_sys/src/bindings/pkcs11t.rs | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11n.rs b/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11n.rs index 3d1818931d..ac5639a0be 100644 --- a/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11n.rs +++ b/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11n.rs @@ -12,7 +12,9 @@ pub const CKM_NSS_HKDF_SHA256: u32 = CKM_NSS + 4; pub const CKM_NSS_HKDF_SHA384: u32 = CKM_NSS + 5; pub type CK_GCM_PARAMS = CK_GCM_PARAMS_V3; -#[repr(C)] +// On Windows, PKCS#11 structs use 1-byte packing (see pkcs11p.h). +#[cfg_attr(target_os = "windows", repr(C, packed))] +#[cfg_attr(not(target_os = "windows"), repr(C))] pub struct CK_GCM_PARAMS_V3 { pub pIv: CK_BYTE_PTR, pub ulIvLen: CK_ULONG, @@ -21,7 +23,9 @@ pub struct CK_GCM_PARAMS_V3 { pub ulAADLen: CK_ULONG, pub ulTagBits: CK_ULONG, } -#[repr(C)] +// On Windows, PKCS#11 structs use 1-byte packing (see pkcs11p.h). +#[cfg_attr(target_os = "windows", repr(C, packed))] +#[cfg_attr(not(target_os = "windows"), repr(C))] pub struct CK_NSS_HKDFParams { pub bExtract: CK_BBOOL, pub pSalt: CK_BYTE_PTR, diff --git a/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11t.rs b/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11t.rs index 6596a2fd66..ed080949c6 100644 --- a/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11t.rs +++ b/components/support/rc_crypto/nss/nss_sys/src/bindings/pkcs11t.rs @@ -16,7 +16,9 @@ pub type CK_OBJECT_CLASS = CK_ULONG; pub type CK_KEY_TYPE = CK_ULONG; pub type CK_ATTRIBUTE_TYPE = CK_ULONG; pub type CK_FLAGS = CK_ULONG; -#[repr(C)] +// On Windows, PKCS#11 structs use 1-byte packing (see pkcs11p.h). +#[cfg_attr(target_os = "windows", repr(C, packed))] +#[cfg_attr(not(target_os = "windows"), repr(C))] #[derive(Clone, Copy)] pub struct CK_ATTRIBUTE { pub type_: CK_ATTRIBUTE_TYPE,