Skip to content

Commit f82776f

Browse files
committed
Fixes
1 parent f2fe157 commit f82776f

2 files changed

Lines changed: 12 additions & 29 deletions

File tree

src/aead.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ mod recprot {
245245
mod recprot {
246246
use std::{
247247
fmt,
248-
os::raw::{c_char, c_int, c_uint, c_ulong},
248+
os::raw::{c_char, c_int, c_uint},
249249
ptr::{null, null_mut},
250250
};
251251

@@ -271,24 +271,8 @@ mod recprot {
271271
reason = "NONCE_LEN = 12 and TAG_LEN = 16 both fit in u32"
272272
)]
273273
const TAG_LEN_C: c_uint = TAG_LEN as c_uint;
274-
// On Windows c_ulong is u32; on other platforms it is u64 (same width as usize),
275-
// so cast_possible_truncation only fires on Windows.
276-
#[cfg_attr(
277-
target_os = "windows",
278-
expect(
279-
clippy::cast_possible_truncation,
280-
reason = "NONCE_LEN = 12 fits in u32"
281-
)
282-
)]
283-
const NONCE_LEN_UL: c_ulong = NONCE_LEN as c_ulong;
284-
#[cfg_attr(
285-
target_os = "windows",
286-
expect(
287-
clippy::cast_possible_truncation,
288-
reason = "TAG_LEN * 8 = 128 fits in u32"
289-
)
290-
)]
291-
const TAG_BITS_UL: c_ulong = (TAG_LEN * 8) as c_ulong;
274+
const NONCE_LEN_UL: u64 = NONCE_LEN as u64;
275+
const TAG_BITS_UL: u64 = (TAG_LEN * 8) as u64;
292276
#[expect(
293277
clippy::cast_possible_truncation,
294278
reason = "CK_GCM_MESSAGE_PARAMS is a small fixed struct"

src/freebl.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// self-test gate. This is intentional for neqo (non-FIPS) and saves ~7.6%
1414
// CPU on the PK11_AEADOp hot path (sftk_SessionFromHandle + mutex overhead).
1515

16-
use std::os::raw::{c_int, c_uchar, c_uint, c_ulong, c_void};
16+
use std::os::raw::{c_int, c_uchar, c_uint, c_void};
1717

1818
// NSS_AES_GCM = 4 (from blapit.h)
1919
pub const NSS_AES_GCM: c_int = 4;
@@ -35,23 +35,22 @@ pub type ChaCha20Poly1305Context = ChaCha20Poly1305ContextStr;
3535
// For CKG_NO_GENERATE (ivGenerator = 0), pIv/ulIvLen supply the full nonce.
3636
// For encrypt, pTag is the output tag buffer; for decrypt, pTag is the input
3737
// tag to verify. ulTagBits = TAG_LEN * 8 = 128.
38+
//
39+
// CK_ULONG is `unsigned long` in C, i.e, 64 bit on NSS platforms.
3840
#[repr(C)]
3941
#[derive(Copy, Clone)]
4042
#[expect(non_snake_case, reason = "PKCS#11 naming conventions.")]
4143
pub struct CK_GCM_MESSAGE_PARAMS {
4244
pub pIv: *mut c_uchar,
43-
pub ulIvLen: c_ulong,
44-
pub ulIvFixedBits: c_ulong,
45-
pub ivGenerator: c_ulong, // CK_GENERATOR_FUNCTION; 0 = CKG_NO_GENERATE
45+
pub ulIvLen: u64,
46+
pub ulIvFixedBits: u64,
47+
pub ivGenerator: u64, // CK_GENERATOR_FUNCTION; 0 = CKG_NO_GENERATE
4648
pub pTag: *mut c_uchar,
47-
pub ulTagBits: c_ulong,
49+
pub ulTagBits: u64,
4850
}
4951

50-
// On LP64 (Linux/macOS) pointer == c_ulong == 8 bytes, so all 6 fields are
51-
// the same width. On Windows LLP64, c_ulong is 4 bytes but pointers are 8,
52-
// so the layout differs and the check would be wrong — skip it there.
53-
#[cfg(not(target_os = "windows"))]
54-
const _: () = assert!(size_of::<CK_GCM_MESSAGE_PARAMS>() == 6 * size_of::<c_ulong>());
52+
// All six fields are 8 bytes (two pointers + four u64s).
53+
const _: () = assert!(size_of::<CK_GCM_MESSAGE_PARAMS>() == 48);
5554

5655
unsafe extern "C" {
5756
/// Allocate and initialise an AES context. Pass `NULL` for `iv` when

0 commit comments

Comments
 (0)