use nss_sys::nspr::PRBool;
use nss_sys::{PK11SlotInfoStr, SECAlgorithmIDStr, SECItemStr, SECStatus};
pub(super) type SECOidTag = u32;
pub(super) type CKMechanismType = std::ffi::c_ulong;
pub(super) type CKAttributeType = std::ffi::c_ulong;
pub(super) type CKRsaPkcsMgfType = std::ffi::c_ulong;
pub(super) type CKRsaPkcsOaepSourceType = std::ffi::c_ulong;
pub(super) const SEC_OID_MD5: SECOidTag = 3;
pub(super) const SEC_OID_SHA1: SECOidTag = 4;
pub(super) const SEC_OID_SHA224: SECOidTag = 238; pub(super) const SEC_OID_SHA256: SECOidTag = 191;
pub(super) const SEC_OID_SHA384: SECOidTag = 192;
pub(super) const SEC_OID_SHA512: SECOidTag = 193;
pub(super) const SEC_OID_SHA3_256: SECOidTag = 365; pub(super) const SEC_OID_SHA3_384: SECOidTag = 366; pub(super) const SEC_OID_SHA3_512: SECOidTag = 367;
pub(super) const SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION: SECOidTag = 194;
pub(super) const SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION: SECOidTag = 195;
pub(super) const SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION: SECOidTag = 196;
pub(super) const SEC_OID_ANSIX962_ECDSA_SHA256_SIGNATURE: SECOidTag = 278;
pub(super) const SEC_OID_ANSIX962_ECDSA_SHA384_SIGNATURE: SECOidTag = 279;
pub(super) const SEC_OID_ANSIX962_ECDSA_SHA512_SIGNATURE: SECOidTag = 280;
pub(super) const SEC_OID_ED25519_SIGNATURE: SECOidTag = 373;
pub(super) const SEC_OID_ML_DSA_44: SECOidTag = 391;
pub(super) const SEC_OID_ML_DSA_65: SECOidTag = 392;
pub(super) const SEC_OID_ML_DSA_87: SECOidTag = 393;
pub(super) const CKM_RSA_PKCS: CKMechanismType = 0x0000_0001;
pub(super) const CKM_RSA_PKCS_OAEP: CKMechanismType = 0x0000_0009;
pub(super) const CKM_RSA_PKCS_KEY_PAIR_GEN: CKMechanismType = 0x0000_0000;
pub(super) const CKM_SHA256_RSA_PKCS_PSS: CKMechanismType = 0x0000_0043;
pub(super) const CKM_SHA512_RSA_PKCS_PSS: CKMechanismType = 0x0000_0045;
pub(super) const CKM_EC_KEY_PAIR_GEN: CKMechanismType = 0x0000_1040;
pub(super) const CKM_EC_EDWARDS_KEY_PAIR_GEN: CKMechanismType = 0x0000_1055;
pub(super) const CKM_EDDSA: CKMechanismType = 0x0000_1057;
pub(super) const CKM_ML_DSA_KEY_PAIR_GEN: CKMechanismType = 0x0000_001C;
pub(super) const CKM_ML_DSA: CKMechanismType = 0x0000_001D;
pub(super) const CKP_ML_DSA_44: std::ffi::c_ulong = 1;
pub(super) const CKP_ML_DSA_65: std::ffi::c_ulong = 2;
pub(super) const CKP_ML_DSA_87: std::ffi::c_ulong = 3;
pub(super) type CkHedgeType = std::ffi::c_ulong;
pub(super) const CKH_HEDGE_PREFERRED: CkHedgeType = 0x0000_0000;
#[repr(C)]
pub(super) struct CkSignAdditionalContext {
pub hedge_variant: CkHedgeType,
pub p_context: *const u8,
pub ul_context_len: std::ffi::c_ulong,
}
#[repr(C)]
pub(super) struct CkRsaPkcsPssParams {
pub hash_alg: CKMechanismType,
pub mgf: CKRsaPkcsMgfType,
pub s_len: std::ffi::c_ulong,
}
pub(super) type CkBbool = u8;
#[repr(C)]
pub(super) struct CkEddsaParams {
pub ph_flag: CkBbool,
pub ul_context_data_len: std::ffi::c_ulong,
pub p_context_data: *const u8,
}
pub(super) const CKM_SHA_1: CKMechanismType = 0x0000_0220;
pub(super) const CKM_SHA224: CKMechanismType = 0x0000_0255;
pub(super) const CKM_SHA256: CKMechanismType = 0x0000_0250;
pub(super) const CKM_SHA384: CKMechanismType = 0x0000_0260;
pub(super) const CKM_SHA512: CKMechanismType = 0x0000_0270;
pub(super) const CKM_MD5_HMAC: CKMechanismType = 0x0000_0211;
pub(super) const CKM_SHA_1_HMAC: CKMechanismType = 0x0000_0221;
pub(super) const CKM_SHA224_HMAC: CKMechanismType = 0x0000_0256;
pub(super) const CKM_SHA256_HMAC: CKMechanismType = 0x0000_0251;
pub(super) const CKM_SHA384_HMAC: CKMechanismType = 0x0000_0261;
pub(super) const CKM_SHA512_HMAC: CKMechanismType = 0x0000_0271;
pub(super) const CKM_AES_CBC: CKMechanismType = 0x0000_1022;
pub(super) const CKM_AES_CBC_PAD: CKMechanismType = 0x0000_1025;
pub(super) const CKM_AES_GCM: CKMechanismType = 0x0000_1087;
pub(super) const CKM_DES3_CBC: CKMechanismType = 0x0000_0122;
pub(super) const CKM_DES3_CBC_PAD: CKMechanismType = 0x0000_0125;
#[repr(C)]
pub(super) struct CkAesGcmParams {
pub iv_ptr: *const u8,
pub iv_len: std::ffi::c_ulong,
pub iv_bits: std::ffi::c_ulong,
pub aad_ptr: *const u8,
pub aad_len: std::ffi::c_ulong,
pub tag_bits: std::ffi::c_ulong,
}
pub(super) const CKG_MGF1_SHA1: CKRsaPkcsMgfType = 0x0000_0001;
pub(super) const CKG_MGF1_SHA224: CKRsaPkcsMgfType = 0x0000_0005;
pub(super) const CKG_MGF1_SHA256: CKRsaPkcsMgfType = 0x0000_0002;
pub(super) const CKG_MGF1_SHA384: CKRsaPkcsMgfType = 0x0000_0003;
pub(super) const CKG_MGF1_SHA512: CKRsaPkcsMgfType = 0x0000_0004;
pub(super) const CKA_ENCRYPT: CKAttributeType = 0x0000_0104;
pub(super) const CKA_DECRYPT: CKAttributeType = 0x0000_0105;
pub(super) const CKZ_DATA_SPECIFIED: CKRsaPkcsOaepSourceType = 0x0000_0001;
pub(super) const PK11_ORIGIN_UNWRAP: std::ffi::c_uint = 4;
pub(super) const KU_DIGITAL_SIGNATURE: std::ffi::c_uint = 0x80;
pub(super) const KU_KEY_ENCIPHERMENT: std::ffi::c_uint = 0x20;
#[repr(C)]
pub(super) struct PK11RsaGenParams {
pub(super) key_size_in_bits: std::ffi::c_int,
pub(super) pe: std::ffi::c_ulong,
}
pub(super) enum SECKEYPrivateKeyStr {}
pub(super) enum SECKEYPublicKeyStr {}
pub(super) enum CERTSubjectPublicKeyInfoStr {}
pub(super) enum PK11SymKeyStr {}
pub(super) enum PK11ContextStr {}
#[repr(C)]
pub(super) struct PRCList {
pub(super) next: *mut PRCList,
pub(super) prev: *mut PRCList,
}
#[repr(C)]
pub(super) struct SECKEYPrivateKeyList {
pub(super) arena: *mut std::ffi::c_void, pub(super) list: PRCList,
}
#[repr(C)]
pub(super) struct SECKEYPrivateKeyListNode {
pub(super) links: PRCList,
pub(super) key: *mut SECKEYPrivateKeyStr,
pub(super) arena: *mut std::ffi::c_void, }
#[repr(C)]
pub(super) struct CkRsaPkcsOaepParams {
pub(super) hash_alg: CKMechanismType,
pub(super) mgf: CKRsaPkcsMgfType,
pub(super) source: CKRsaPkcsOaepSourceType,
pub(super) p_source_data: *mut std::ffi::c_void,
pub(super) ul_source_data_len: std::ffi::c_ulong,
}
extern "C" {
pub(super) fn PK11_GetInternalSlot() -> *mut PK11SlotInfoStr;
pub(super) fn PK11_FreeSlot(slot: *mut PK11SlotInfoStr);
pub(super) fn PK11_FindSlotByName(name: *const std::ffi::c_char) -> *mut PK11SlotInfoStr;
pub(super) fn PK11_Authenticate(
slot: *mut PK11SlotInfoStr,
loadCerts: PRBool,
wincx: *const std::ffi::c_char,
) -> SECStatus;
pub(super) fn PK11_GenerateKeyPair(
slot: *mut PK11SlotInfoStr,
type_: CKMechanismType,
param: *mut std::ffi::c_void,
pubk: *mut *mut SECKEYPublicKeyStr,
is_perm: nss_sys::nspr::PRBool,
is_sensitive: nss_sys::nspr::PRBool,
wincx: *mut std::ffi::c_void,
) -> *mut SECKEYPrivateKeyStr;
pub(super) fn PK11_ExportDERPrivateKeyInfo(
priv_key: *mut SECKEYPrivateKeyStr,
wincx: *mut std::ffi::c_void,
) -> *mut SECItemStr;
pub(super) fn SECKEY_DestroyPrivateKey(key: *mut SECKEYPrivateKeyStr);
pub(super) fn SECKEY_DestroyPublicKey(key: *mut SECKEYPublicKeyStr);
pub(super) fn SECKEY_DecodeDERSubjectPublicKeyInfo(
spkider: *const SECItemStr,
) -> *mut CERTSubjectPublicKeyInfoStr;
pub(super) fn SECKEY_DestroySubjectPublicKeyInfo(spki: *mut CERTSubjectPublicKeyInfoStr);
pub(super) fn SECKEY_ExtractPublicKey(
spki: *const CERTSubjectPublicKeyInfoStr,
) -> *mut SECKEYPublicKeyStr;
pub(super) fn SECKEY_PublicKeyStrength(pubk: *const SECKEYPublicKeyStr) -> std::ffi::c_uint;
pub(super) fn PK11_ImportDERPrivateKeyInfoAndReturnKey(
slot: *mut PK11SlotInfoStr,
der_pki: *const SECItemStr,
nickname: *const SECItemStr,
public_value: *const SECItemStr,
is_perm: PRBool,
is_private: PRBool,
usage: std::ffi::c_uint,
privk: *mut *mut SECKEYPrivateKeyStr,
wincx: *mut std::ffi::c_void,
) -> SECStatus;
pub(super) fn PK11_ImportSymKey(
slot: *mut PK11SlotInfoStr,
mech: CKMechanismType,
origin: std::ffi::c_uint,
operation: CKAttributeType,
key: *const SECItemStr,
wincx: *mut std::ffi::c_void,
) -> *mut PK11SymKeyStr;
pub(super) fn PK11_FreeSymKey(key: *mut PK11SymKeyStr);
pub(super) fn PK11_ListPrivKeysInSlot(
slot: *mut PK11SlotInfoStr,
nickname: *mut std::ffi::c_char,
wincx: *const std::ffi::c_void,
) -> *mut SECKEYPrivateKeyList;
pub(super) fn SECKEY_DestroyPrivateKeyList(keys: *mut SECKEYPrivateKeyList);
pub(super) fn SECKEY_CopyPrivateKey(
privkey: *mut SECKEYPrivateKeyStr,
) -> *mut SECKEYPrivateKeyStr;
pub(super) fn SECKEY_ConvertToPublicKey(
privkey: *mut SECKEYPrivateKeyStr,
) -> *mut SECKEYPublicKeyStr;
pub(super) fn SECKEY_EncodeDERSubjectPublicKeyInfo(
pubkey: *const SECKEYPublicKeyStr,
) -> *mut SECItemStr;
pub(super) fn PK11_PubEncrypt(
key: *mut SECKEYPublicKeyStr,
type_: CKMechanismType,
param: *mut SECItemStr,
out: *mut u8,
out_len: *mut std::ffi::c_uint,
max_len: std::ffi::c_uint,
data: *const u8,
data_len: std::ffi::c_uint,
wincx: *mut std::ffi::c_void,
) -> SECStatus;
pub(super) fn PK11_PrivDecrypt(
key: *mut SECKEYPrivateKeyStr,
type_: CKMechanismType,
param: *mut SECItemStr,
out: *mut u8,
out_len: *mut std::ffi::c_uint,
max_len: std::ffi::c_uint,
data: *const u8,
data_len: std::ffi::c_uint,
) -> SECStatus;
pub(super) fn SEC_SignData(
result: *mut SECItemStr,
buf: *const u8,
len: std::ffi::c_int,
pk: *mut SECKEYPrivateKeyStr,
algid: SECOidTag,
) -> SECStatus;
pub(super) fn PK11_Sign(
key: *mut SECKEYPrivateKeyStr,
sig: *mut SECItemStr,
hash: *const SECItemStr,
) -> SECStatus;
pub(super) fn PK11_SignatureLen(key: *const SECKEYPrivateKeyStr) -> std::ffi::c_int;
pub(super) fn PK11_SignWithMechanism(
key: *mut SECKEYPrivateKeyStr,
mechanism: CKMechanismType,
param: *const SECItemStr,
sig: *mut SECItemStr,
hash: *const SECItemStr,
) -> SECStatus;
pub(super) fn VFY_VerifyDataWithAlgorithmID(
buf: *const u8,
len: std::ffi::c_int,
key: *const SECKEYPublicKeyStr,
sig: *const SECItemStr,
sig_alg: *const SECAlgorithmIDStr,
canon_alg: *const SECAlgorithmIDStr,
wincx: *mut std::ffi::c_void,
) -> SECStatus;
pub(super) fn PK11_Verify(
key: *mut SECKEYPublicKeyStr,
sig: *const SECItemStr,
hash: *const SECItemStr,
wincx: *mut std::ffi::c_void,
) -> SECStatus;
pub(super) fn PK11_VerifyWithMechanism(
key: *mut SECKEYPublicKeyStr,
mechanism: CKMechanismType,
param: *const SECItemStr,
sig: *const SECItemStr,
hash: *const SECItemStr,
wincx: *mut std::ffi::c_void,
) -> SECStatus;
pub(super) fn PK11_CreateContextBySymKey(
mech: CKMechanismType,
operation: CKAttributeType,
sym_key: *mut PK11SymKeyStr,
param: *const SECItemStr,
) -> *mut PK11ContextStr;
pub(super) fn PK11_DestroyContext(context: *mut PK11ContextStr, freeit: PRBool);
pub(super) fn PK11_DigestOp(
context: *mut PK11ContextStr,
in_data: *const u8,
len: std::ffi::c_uint,
) -> SECStatus;
pub(super) fn PK11_DigestFinal(
context: *mut PK11ContextStr,
data: *mut u8,
out_len: *mut std::ffi::c_uint,
length: std::ffi::c_uint,
) -> SECStatus;
pub(super) fn PK11_CipherOp(
context: *mut PK11ContextStr,
out: *mut u8,
out_len: *mut std::ffi::c_int,
maxout: std::ffi::c_int,
data: *const u8,
data_len: std::ffi::c_int,
) -> SECStatus;
pub(super) fn PK11_CreateDigestContext(hash_alg: SECOidTag) -> *mut PK11ContextStr;
pub(super) fn PK11_DigestBegin(cx: *mut PK11ContextStr) -> SECStatus;
pub(super) fn PK11_HashBuf(
hash_alg: SECOidTag,
out: *mut u8,
data: *const u8,
len: std::ffi::c_int,
) -> SECStatus;
pub(super) fn PK11_GenerateRandom(buf: *mut u8, len: std::ffi::c_int) -> SECStatus;
pub(super) fn SECITEM_FreeItem(item: *mut SECItemStr, freeit: PRBool);
}