Skip to content

Commit

Permalink
feat: implement params
Browse files Browse the repository at this point in the history
- CK_ECDH2_DERIVE_PARAMS
- CK_ECMQV_DERIVE_PARAMS
- CK_X9_42_DH1_DERIVE_PARAMS
- CK_X9_42_DH2_DERIVE_PARAMS
- CK_X9_42_MQV_DERIVE_PARAMS
- CK_KEA_DERIVE_PARAMS
- CK_RC2_CBC_PARAMS
- CK_RC2_MAC_GENERAL_PARAMS
- CK_RC5_PARAMS
- CK_RC5_CBC_PARAMS
- CK_RC5_MAC_GENERAL_PARAMS
- CK_DES_CBC_ENCRYPT_DATA_PARAMS
- CK_SKIPJACK_PRIVATE_WRAP_PARAMS
- CK_SKIPJACK_RELAYX_PARAMS
  • Loading branch information
microshine committed Jan 16, 2024
1 parent 5eb9345 commit db74f64
Show file tree
Hide file tree
Showing 5 changed files with 782 additions and 4 deletions.
121 changes: 119 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ declare module "pkcs11js" {
/**
* The parameter if required by the mechanism
*/
parameter?: Buffer | IParams;
parameter?: Buffer | number | IParams;
}

//#region Crypto parameters
Expand Down Expand Up @@ -309,6 +309,107 @@ declare module "pkcs11js" {
saltLen: number;
}

interface Ecdh2Derive extends IParams {
kdf: number;
sharedData?: Buffer;
publicData: Buffer;
privateDataLen: number;
privateData: Handle;
publicData2?: Buffer;
}

interface EcmqvDerive extends IParams {
kdf: number;
sharedData?: Buffer;
publicData: Buffer;
privateDataLen: number;
publicData2?: Buffer;
privateData: Handle;
}

interface X942DH1Derive extends IParams {
kdf: number;
otherInfo?: Buffer;
publicData: Buffer;
privateData: Handle;
}

interface X942DH2Derive extends IParams {
kdf: number;
otherInfo?: Buffer;
publicData: Buffer;
privateData: Handle;
privateDataLen: number;
publicData2?: Buffer;
}

interface X942MQvDeriveParams {
kdf: number;
otherInfo?: Buffer;
publicData: Buffer;
privateData: Handle;
publicData2?: Buffer;
publicKey: Handle;
}

interface RC2CBCParams extends IParams {
effectiveBits: number;
iv: Buffer;
}

interface RC2MACGeneralParams extends IParams {
effectiveBits: number;
macLength: number;
}

interface RC5Params extends IParams {
wordSize: number;
rounds: number;
}

interface RC5CBCParams extends RC5Params {
wordSize: number;
rounds: number;
iv: Buffer;
}

interface RC5MACGeneralParams extends RC5Params {
wordSize: number;
rounds: number;
macLength: number;
}

interface DesCbcEncryptDataParams extends IParams {
iv: Buffer;
data?: Buffer;
}

interface SkipjackPrivateWrapParams extends IParams {
password: Buffer;
publicData: Buffer;
primeP: Buffer;
baseG: Buffer;
subprimeQ: Buffer;
randomA: Buffer;
}

interface SkipjackRelayXParams extends IParams {
oldWrappedX: Buffer;
oldPassword: Buffer;
oldPublicData: Buffer;
oldRandomA: Buffer;
newPassword: Buffer;
newPublicData: Buffer;
newRandomA: Buffer;
}

interface PbeParams extends IParams {
initVector: Buffer;
password: Buffer;
salt: Buffer;
iteration: number;
}

//#endregion

interface KeyPair {
Expand Down Expand Up @@ -1843,7 +1944,7 @@ declare module "pkcs11js" {
const CKF_SERIAL_SESSION: number;
//#endregion

//#region Follows
//#region Mechanism flags
const CKF_HW: number;
const CKF_ENCRYPT: number;
const CKF_DECRYPT: number;
Expand Down Expand Up @@ -1919,6 +2020,22 @@ declare module "pkcs11js" {
const CK_PARAMS_RSA_PSS: number;
const CK_PARAMS_EC_DH: number;
const CK_PARAMS_AES_GCM_v240: number;
const CK_PARAMS_ECDH2_DERIVE: number;
const CK_PARAMS_ECMQV_DERIVE: number;
const CK_PARAMS_X9_42_DH1_DERIVE: number;
const CK_PARAMS_X9_42_DH2_DERIVE: number;
const CK_PARAMS_X9_42_MQV_DERIVE: number;
const CK_PARAMS_KEA_DERIVE: number;
const CK_PARAMS_RC2: number;
const CK_PARAMS_RC2_CBC: number;
const CK_PARAMS_RC2_MAC_GENERAL: number;
const CK_PARAMS_RC5: number;
const CK_PARAMS_RC5_CBC: number;
const CK_PARAMS_RC5_MAC_GENERAL: number;
const CK_PARAMS_DES_CBC_ENCRYPT_DATA: number;
const CK_PARAMS_SKIPJACK_PRIVATE_WRAP: number;
const CK_PARAMS_SKIPJACK_RELAYX: number;
const CK_PARAMS_PBE: number;
//#endregion

//#region User types
Expand Down
16 changes: 16 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ typedef CK_NSS_C_INITIALIZE_ARGS *CK_NSS_C_INITIALIZE_ARGS_PTR;
#define CK_PARAMS_RSA_PSS 5
#define CK_PARAMS_EC_DH 6
#define CK_PARAMS_AES_GCM_v240 7
#define CK_PARAMS_ECDH2_DERIVE 8
#define CK_PARAMS_ECMQV_DERIVE 9
#define CK_PARAMS_X9_42_DH1_DERIVE 10
#define CK_PARAMS_X9_42_DH2_DERIVE 11
#define CK_PARAMS_X9_42_MQV_DERIVE 12
#define CK_PARAMS_KEA_DERIVE 13
#define CK_PARAMS_RC2 14
#define CK_PARAMS_RC2_CBC 15
#define CK_PARAMS_RC2_MAC_GENERAL 16
#define CK_PARAMS_RC5 17
#define CK_PARAMS_RC5_CBC 18
#define CK_PARAMS_RC5_MAC_GENERAL 19
#define CK_PARAMS_DES_CBC_ENCRYPT_DATA 20
#define CK_PARAMS_SKIPJACK_PRIVATE_WRAP 21
#define CK_PARAMS_SKIPJACK_RELAYX 22
#define CK_PARAMS_PBE 23

/**
* @brief Retrieves the name of the error code.
Expand Down
16 changes: 16 additions & 0 deletions src/const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ void set_ckp(napi_env env, napi_value exports)
SET_CONST(CK_PARAMS_RSA_PSS);
SET_CONST(CK_PARAMS_EC_DH);
SET_CONST(CK_PARAMS_AES_GCM_v240);
SET_CONST(CK_PARAMS_ECDH2_DERIVE);
SET_CONST(CK_PARAMS_ECMQV_DERIVE);
SET_CONST(CK_PARAMS_X9_42_DH1_DERIVE);
SET_CONST(CK_PARAMS_X9_42_DH2_DERIVE);
SET_CONST(CK_PARAMS_X9_42_MQV_DERIVE);
SET_CONST(CK_PARAMS_KEA_DERIVE);
SET_CONST(CK_PARAMS_RC2);
SET_CONST(CK_PARAMS_RC2_CBC);
SET_CONST(CK_PARAMS_RC2_MAC_GENERAL);
SET_CONST(CK_PARAMS_RC5);
SET_CONST(CK_PARAMS_RC5_CBC);
SET_CONST(CK_PARAMS_RC5_MAC_GENERAL);
SET_CONST(CK_PARAMS_DES_CBC_ENCRYPT_DATA);
SET_CONST(CK_PARAMS_SKIPJACK_PRIVATE_WRAP);
SET_CONST(CK_PARAMS_SKIPJACK_RELAYX);
SET_CONST(CK_PARAMS_PBE);
}

/**
Expand Down
Loading

0 comments on commit db74f64

Please sign in to comment.