Skip to content
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

Add #[no_mangle] attributes to all functions #231

Merged
merged 1 commit into from
Feb 21, 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
5 changes: 5 additions & 0 deletions pkcs11/src/api/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
lock_session,
};

#[no_mangle]
pub extern "C" fn C_DecryptInit(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand Down Expand Up @@ -36,6 +37,7 @@ pub extern "C" fn C_DecryptInit(
}
}

#[no_mangle]
pub extern "C" fn C_Decrypt(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pEncryptedData: cryptoki_sys::CK_BYTE_PTR,
Expand Down Expand Up @@ -96,6 +98,7 @@ pub extern "C" fn C_Decrypt(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_DecryptUpdate(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pEncryptedPart: cryptoki_sys::CK_BYTE_PTR,
Expand Down Expand Up @@ -127,6 +130,7 @@ pub extern "C" fn C_DecryptUpdate(
}
}

#[no_mangle]
pub extern "C" fn C_DecryptFinal(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pLastPart: cryptoki_sys::CK_BYTE_PTR,
Expand Down Expand Up @@ -189,6 +193,7 @@ pub extern "C" fn C_DecryptFinal(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_DecryptVerifyUpdate(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pEncryptedPart: cryptoki_sys::CK_BYTE_PTR,
Expand Down
7 changes: 7 additions & 0 deletions pkcs11/src/api/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use log::trace;

#[no_mangle]
pub extern "C" fn C_DigestInit(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: *mut cryptoki_sys::CK_MECHANISM,
Expand All @@ -17,6 +18,7 @@ pub extern "C" fn C_DigestInit(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_Digest(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pData: *mut cryptoki_sys::CK_BYTE,
Expand All @@ -33,6 +35,7 @@ pub extern "C" fn C_Digest(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_DigestUpdate(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pPart: *mut cryptoki_sys::CK_BYTE,
Expand All @@ -47,6 +50,7 @@ pub extern "C" fn C_DigestUpdate(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_DigestFinal(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pDigest: *mut cryptoki_sys::CK_BYTE,
Expand All @@ -61,6 +65,7 @@ pub extern "C" fn C_DigestFinal(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_DigestKey(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
hKey: cryptoki_sys::CK_OBJECT_HANDLE,
Expand All @@ -70,6 +75,7 @@ pub extern "C" fn C_DigestKey(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_DigestEncryptUpdate(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pPart: cryptoki_sys::CK_BYTE_PTR,
Expand All @@ -82,6 +88,7 @@ pub extern "C" fn C_DigestEncryptUpdate(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_DecryptDigestUpdate(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pEncryptedPart: cryptoki_sys::CK_BYTE_PTR,
Expand Down
4 changes: 4 additions & 0 deletions pkcs11/src/api/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
lock_session,
};

#[no_mangle]
pub extern "C" fn C_EncryptInit(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand Down Expand Up @@ -39,6 +40,7 @@ pub extern "C" fn C_EncryptInit(
}
}

#[no_mangle]
pub extern "C" fn C_Encrypt(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pData: cryptoki_sys::CK_BYTE_PTR,
Expand Down Expand Up @@ -107,6 +109,7 @@ pub extern "C" fn C_Encrypt(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_EncryptUpdate(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pPart: cryptoki_sys::CK_BYTE_PTR,
Expand Down Expand Up @@ -171,6 +174,7 @@ pub extern "C" fn C_EncryptUpdate(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_EncryptFinal(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pLastEncryptedPart: cryptoki_sys::CK_BYTE_PTR,
Expand Down
7 changes: 7 additions & 0 deletions pkcs11/src/api/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
read_session,
};

#[no_mangle]
pub extern "C" fn C_GenerateKey(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand Down Expand Up @@ -75,6 +76,7 @@ pub extern "C" fn C_GenerateKey(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_GenerateKeyPair(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand Down Expand Up @@ -157,6 +159,7 @@ pub extern "C" fn C_GenerateKeyPair(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_WrapKey(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand All @@ -170,6 +173,7 @@ pub extern "C" fn C_WrapKey(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_UnwrapKey(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand All @@ -185,6 +189,7 @@ pub extern "C" fn C_UnwrapKey(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_DeriveKey(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pMechanism: cryptoki_sys::CK_MECHANISM_PTR,
Expand All @@ -199,6 +204,7 @@ pub extern "C" fn C_DeriveKey(
}

// we silently ignore this function as NetHSM handles the random number generation
#[no_mangle]
pub extern "C" fn C_SeedRandom(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pSeed: cryptoki_sys::CK_BYTE_PTR,
Expand All @@ -209,6 +215,7 @@ pub extern "C" fn C_SeedRandom(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_GenerateRandom(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
RandomData: cryptoki_sys::CK_BYTE_PTR,
Expand Down
3 changes: 3 additions & 0 deletions pkcs11/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub extern "C" fn C_GetFunctionList(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_Initialize(pInitArgs: CK_VOID_PTR) -> CK_RV {
trace!("C_Initialize() called with args: {:?}", pInitArgs);

Expand Down Expand Up @@ -104,6 +105,7 @@ pub extern "C" fn C_Initialize(pInitArgs: CK_VOID_PTR) -> CK_RV {
}
}

#[no_mangle]
pub extern "C" fn C_Finalize(pReserved: CK_VOID_PTR) -> CK_RV {
trace!("C_Finalize() called");

Expand All @@ -119,6 +121,7 @@ pub extern "C" fn C_Finalize(pReserved: CK_VOID_PTR) -> CK_RV {
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_GetInfo(pInfo: CK_INFO_PTR) -> CK_RV {
trace!("C_GetInfo() called");

Expand Down
9 changes: 9 additions & 0 deletions pkcs11/src/api/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
lock_session, read_session,
};

#[no_mangle]
pub extern "C" fn C_FindObjectsInit(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pTemplate: cryptoki_sys::CK_ATTRIBUTE_PTR,
Expand All @@ -28,6 +29,7 @@ pub extern "C" fn C_FindObjectsInit(
}
}

#[no_mangle]
pub extern "C" fn C_FindObjects(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
phObject: cryptoki_sys::CK_OBJECT_HANDLE_PTR,
Expand Down Expand Up @@ -60,6 +62,7 @@ pub extern "C" fn C_FindObjects(

cryptoki_sys::CKR_OK
}
#[no_mangle]
pub extern "C" fn C_FindObjectsFinal(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
) -> cryptoki_sys::CK_RV {
Expand All @@ -71,6 +74,7 @@ pub extern "C" fn C_FindObjectsFinal(

cryptoki_sys::CKR_OK
}
#[no_mangle]
pub extern "C" fn C_GetAttributeValue(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
hObject: cryptoki_sys::CK_OBJECT_HANDLE,
Expand Down Expand Up @@ -112,6 +116,7 @@ pub extern "C" fn C_GetAttributeValue(

object.fill_attr_template(&mut template)
}
#[no_mangle]
pub extern "C" fn C_GetObjectSize(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
hObject: cryptoki_sys::CK_OBJECT_HANDLE,
Expand Down Expand Up @@ -140,6 +145,7 @@ pub extern "C" fn C_GetObjectSize(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_CreateObject(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pTemplate: cryptoki_sys::CK_ATTRIBUTE_PTR,
Expand Down Expand Up @@ -182,6 +188,7 @@ pub extern "C" fn C_CreateObject(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_CopyObject(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
hObject: cryptoki_sys::CK_OBJECT_HANDLE,
Expand All @@ -194,6 +201,7 @@ pub extern "C" fn C_CopyObject(
cryptoki_sys::CKR_ACTION_PROHIBITED
}

#[no_mangle]
pub extern "C" fn C_DestroyObject(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
hObject: cryptoki_sys::CK_OBJECT_HANDLE,
Expand All @@ -208,6 +216,7 @@ pub extern "C" fn C_DestroyObject(
}
}

#[no_mangle]
pub extern "C" fn C_SetAttributeValue(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
hObject: cryptoki_sys::CK_OBJECT_HANDLE,
Expand Down
2 changes: 2 additions & 0 deletions pkcs11/src/api/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use log::{error, trace};

use crate::lock_session;

#[no_mangle]
pub extern "C" fn C_InitPIN(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
uPin: cryptoki_sys::CK_UTF8CHAR_PTR,
Expand All @@ -16,6 +17,7 @@ pub extern "C" fn C_InitPIN(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_SetPIN(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pOldPin: cryptoki_sys::CK_UTF8CHAR_PTR,
Expand Down
8 changes: 8 additions & 0 deletions pkcs11/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::backend::slot::get_slot;
use crate::data::SESSION_MANAGER;
use crate::read_session;

#[no_mangle]
pub extern "C" fn C_OpenSession(
slotID: cryptoki_sys::CK_SLOT_ID,
flags: cryptoki_sys::CK_FLAGS,
Expand Down Expand Up @@ -46,6 +47,7 @@ pub extern "C" fn C_OpenSession(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_CloseSession(hSession: cryptoki_sys::CK_SESSION_HANDLE) -> cryptoki_sys::CK_RV {
trace!("C_CloseSession() called with session handle {}.", hSession);

Expand All @@ -63,6 +65,7 @@ pub extern "C" fn C_CloseSession(hSession: cryptoki_sys::CK_SESSION_HANDLE) -> c
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_CloseAllSessions(slotID: cryptoki_sys::CK_SLOT_ID) -> cryptoki_sys::CK_RV {
trace!("C_CloseAllSessions() called");

Expand All @@ -81,6 +84,7 @@ pub extern "C" fn C_CloseAllSessions(slotID: cryptoki_sys::CK_SLOT_ID) -> crypto
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_GetSessionInfo(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pInfo: cryptoki_sys::CK_SESSION_INFO_PTR,
Expand All @@ -103,6 +107,7 @@ pub extern "C" fn C_GetSessionInfo(
cryptoki_sys::CKR_OK
}

#[no_mangle]
pub extern "C" fn C_GetOperationState(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pOperationState: cryptoki_sys::CK_BYTE_PTR,
Expand All @@ -113,6 +118,7 @@ pub extern "C" fn C_GetOperationState(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_SetOperationState(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
pOperationState: cryptoki_sys::CK_BYTE_PTR,
Expand All @@ -125,6 +131,7 @@ pub extern "C" fn C_SetOperationState(
cryptoki_sys::CKR_FUNCTION_NOT_SUPPORTED
}

#[no_mangle]
pub extern "C" fn C_GetFunctionStatus(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
) -> cryptoki_sys::CK_RV {
Expand All @@ -133,6 +140,7 @@ pub extern "C" fn C_GetFunctionStatus(
cryptoki_sys::CKR_FUNCTION_NOT_PARALLEL
}

#[no_mangle]
pub extern "C" fn C_CancelFunction(
hSession: cryptoki_sys::CK_SESSION_HANDLE,
) -> cryptoki_sys::CK_RV {
Expand Down
Loading
Loading