#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#ifdef WIN32
#pragma pack(push, cryptoki, 1)
#endif

#include "pkcs11.h"

#define CK_FALSE 0
#define CK_TRUE 1

#define NSSCK_VENDOR_PKCS11_RU_TEAM 0xd4321000 //0x80000000|0x54321000
#define NSSCK_VENDOR_PKSC11_RU_TEAM NSSCK_VENDOR_PKCS11_RU_TEAM
#define CK_VENDOR_PKCS11_RU_TEAM_TC26 NSSCK_VENDOR_PKCS11_RU_TEAM

/* LISSI VALUES */
#define CK_VENDOR_PKCS11_RU_LISSI (CK_VENDOR_PKCS11_RU_TEAM_TC26 | 0x800) /* 0x80000000 | 0x54321000 | 0x800*/
#define CK_VENDOR_PKCS11_RU_LISSI_SOFT CK_VENDOR_PKCS11_RU_LISSI

#define CKM_GOSTR3411_12_256_HMAC_KDF (CK_VENDOR_PKCS11_RU_LISSI_SOFT |0x008)
#define CKM_GOST28147_CNT             (CK_VENDOR_PKCS11_RU_LISSI_SOFT |0x025)

/* GOST KEY TYPES */
// TC 26
#define CKK_GOSTR3410_512 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x003)
#define CKK_KUZNYECHIK (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x004)
#define CKK_MAGMA (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x005)
#define CKK_GOSTR3410_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x006)

/* GOST OBJECT ATTRIBUTES */
#define CKA_GOSTR3410PARAMS    CKA_GOSTR3410_PARAMS
#define CKA_GOSTR3411PARAMS    CKA_GOSTR3411_PARAMS
#define CKA_GOST28147PARAMS    CKA_GOST28147_PARAMS

/* GOST MECHANISMS */
// TC 26
#define CKM_GOSTR3410_512_KEY_PAIR_GEN		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x005)
#define CKM_GOSTR3410_512					(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x006)
#define CKM_GOSTR3410_12_DERIVE				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x007)
#define CKM_GOSTR3410_WITH_GOSTR3411_12_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x008)
#define CKM_GOSTR3410_WITH_GOSTR3411_12_512 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x009)

// Придется перейти на эту константу ТК 26
#define CKM_GOSTR3410_PUBLIC_KEY_DERIVE (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x00A)

// TC 26 for GOST R 34.11-2012
#define CKM_GOSTR3411_12_256		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x012)
#define CKM_GOSTR3411_12_512		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x013)
#define CKM_GOSTR3411_12_256_HMAC	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x014)
#define CKM_GOSTR3411_12_512_HMAC	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x015)

#define CKM_TLS_GOST_PRF_2012_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x016)
#define CKM_TLS_GOST_PRF_2012_512 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x017)

#define CKM_MAGMA_ECB			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x018)
#define CKM_KUZNYECHIK_KEY_GEN	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x019)
#define CKM_KUZNYECHIK_ECB		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01A)
#define CKM_KUZNYECHIK_CTR		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01B)
#define CKM_KUZNYECHIK_CFB		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01C)
#define CKM_KUZNYECHIK_OFB		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01D)
#define CKM_KUZNYECHIK_CBC		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01E)
#define CKM_KUZNYECHIK_OMAC		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01F)
#define CKM_MAGMA_CTR			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x020)
#define CKM_MAGMA_CFB			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x021)
#define CKM_MAGMA_OFB			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x022)
#define CKM_MAGMA_CBC			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x023)
#define CKM_MAGMA_OMAC			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x024)

#define CKM_KDF_4357				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x025)
#define CKM_KDF_GOSTR3411_2012_256	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x026)

#define CKM_KUZNYECHIK_KEY_WRAP (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x028)
#define CKM_MAGMA_KEY_WRAP		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x029)
#define CKM_MAGMA_KEY_GEN		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x02A)

#define CKM_TLS_GOST_PRF				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x030)
#define CKM_TLS_GOST_PRE_MASTER_KEY_GEN (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x031)
#define CKM_TLS_GOST_MASTER_KEY_DERIVE	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x032)
#define CKM_TLS_GOST_KEY_AND_MAC_DERIVE (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x033)

#define CKM_PBA_GOSTR3411_WITH_GOSTR3411_HMAC	(CK_VENDOR_PKCS11_RU_TEAM_TC26|0x035)
#define CKM_GOST28147_PKCS8_KEY_WRAP			(CK_VENDOR_PKCS11_RU_TEAM_TC26|0x036)
// Для обратной совместимости
#define CKM_LISSI_GOSTR3410_PUBLIC_KEY_DERIVE (CK_VENDOR_PKCS11_RU_TEAM_TC26|0x037)
#define CKM_GOST28147_KEY_CPDIVERSIFY	CKM_KDF_4357
#define CKM_GOST28147_KDF				CKM_GOST28147_KEY_CPDIVERSIFY
// Новые экспериментальные механизмы
#define CKM_MAGMA_ACPKM_CTR				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x040)
#define CKM_MAGMA_ACPKM_OMAC			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x041)
#define CKM_KUZNYECHIK_ACPKM_CTR		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x042)
#define CKM_KUZNYECHIK_ACPKM_OMAC		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x043)
#define CKM_KDF_TREE_GOSTR3411_2012_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x044)
#define CKM_GOSTR3410_2012_VKO_256		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x045)
#define CKM_GOSTR3410_2012_VKO_512		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x046)
#define CKM_TLS_TREE_GOSTR3411_2012_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x047)
#define CKM_GOST_CIPHER_KEY_GEN			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x048)
#define CKM_GOST_GENERIC_SECRET_KEY_GEN	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x049)
// Унифицированные механизмы режимов шифрования
#define CKM_GOST_CIPHER_ECB				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x050)
#define CKM_GOST_CIPHER_CBC				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x051)
#define CKM_GOST_CIPHER_CTR				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x052)
#define CKM_GOST_CIPHER_OFB				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x053)
#define CKM_GOST_CIPHER_CFB				(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x054)
#define CKM_GOST_CIPHER_OMAC			(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x055)
#define CKM_GOST_CIPHER_ACPKM_CTR		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x057)
#define CKM_GOST_CIPHER_ACPKM_OMAC		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x058)

#define CKM_GOST_CIPHER_KEY_WRAP		(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x059)
#define CKM_GOST_CIPHER_PKCS8_KEY_WRAP	(CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x05A)

//#define CKD_CPDIVERSIFY_KDF   0x00000009
#define CKD_GOST28147_KDF CKD_CPDIVERSIFY_KDF

#define CKD_GOSTR3411_12_256_HMAC_KDF (CK_VENDOR_PKCS11_RU_LISSI_SOFT |0x01)

#define CKN_LISSI_PIN_CALLBACK (CK_VENDOR_PKCS11_RU_LISSI_SOFT | 0x001)

//#define CKP_PKCS5_PBKD2_HMAC_GOSTR3411 0x00000002
#define CKP_PKCS5_PBKD2_HMAC_GOSTR3411_TC26_V1 (CK_VENDOR_PKCS11_RU_LISSI_SOFT | 0x001)
#define CKP_PKCS5_PBKD2_HMAC_GOSTR3411_2012_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x002)
#define CKP_PKCS5_PBKD2_HMAC_GOSTR3411_2012_512 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x003)

// Structure for CKM_PBA_GOSTR3411_WITH_GOSTR3411_HMAC
typedef struct CK_GOSTR3411_PBE_PARAMS {
    CK_BYTE_PTR     pOID;
    CK_ULONG        ulOIDLen;
    CK_UTF8CHAR_PTR pPassword;
    CK_ULONG        ulPasswordLen;
    CK_CHAR_PTR     pSalt;
    CK_ULONG        ulSaltLen;
    CK_ULONG        ulIteration;
} CK_GOSTR3411_PBE_PARAMS;
typedef CK_GOSTR3411_PBE_PARAMS CK_PTR CK_GOSTR3411_PBE_PARAMS_PTR;

typedef struct CK_GOST28147_PKCS8_KEY_WRAP_PARAMS {
    CK_UTF8CHAR_PTR  pPassword;
    CK_ULONG         ulPasswordLen;
	CK_BYTE_PTR      pHashParOID;
	CK_ULONG         ulHashParOIDLen;
	CK_BYTE_PTR      pSalt;
	CK_ULONG         ulSaltLen;
    CK_ULONG         ulIterCount;
	CK_BYTE_PTR      pCipherParOID;
	CK_ULONG         ulCipherParOIDLen;
	CK_BYTE_PTR      pIV;
	CK_ULONG         ulIVLen;
} CK_GOST28147_PKCS8_KEY_WRAP_PARAMS;
typedef CK_GOST28147_PKCS8_KEY_WRAP_PARAMS CK_PTR  CK_GOST28147_PKCS8_KEY_WRAP_PARAMS_PTR;  

typedef struct CK_TLS_GOST_PRF_PARAMS {
	CK_TLS_PRF_PARAMS  TlsPrfParams;
	CK_BYTE_PTR        pHashParamsOid;
	CK_ULONG           ulHashParamsOidLen;
} CK_TLS_GOST_PRF_PARAMS;
typedef CK_TLS_GOST_PRF_PARAMS CK_PTR CK_TLS_GOST_PRF_PARAMS_PTR;

typedef struct CK_TLS_GOST_MASTER_KEY_DERIVE_PARAMS {
	CK_SSL3_RANDOM_DATA RandomInfo;
	CK_BYTE_PTR         pHashParamsOid;
	CK_ULONG            ulHashParamsOidLen;
} CK_TLS_GOST_MASTER_KEY_DERIVE_PARAMS;
typedef CK_TLS_GOST_MASTER_KEY_DERIVE_PARAMS CK_PTR CK_TLS_GOST_MASTER_KEY_DERIVE_PARAMS_PTR;

typedef struct CK_TLS_GOST_KEY_MAT_PARAMS {
	CK_SSL3_KEY_MAT_PARAMS KeyMatParams;
	CK_BYTE_PTR           pHashParamsOid;
	CK_ULONG               ulHashParamsOidLen;
} CK_TLS_GOST_KEY_MAT_PARAMS;
typedef CK_TLS_GOST_KEY_MAT_PARAMS CK_PTR CK_TLS_GOST_KEY_MAT_PARAMS_PTR;

typedef struct CK_TC26_KEY_WRAP_PARAMS {
	CK_BYTE_PTR      pIV;
	CK_ULONG         ulIVLen;
	CK_OBJECT_HANDLE hMacKey;
} CK_TC26_KEY_WRAP_PARAMS;
typedef CK_TC26_KEY_WRAP_PARAMS CK_PTR  CK_TC26_KEY_WRAP_PARAMS_PTR;  

typedef struct CK_TC26_ACPKM_CTR_PARAMS {
	CK_BYTE_PTR pIV;
	CK_ULONG ulIVLen;
	CK_ULONG ulGammaBlockLen;
	CK_ULONG ulSectionLen;
} CK_TC26_ACPKM_CTR_PARAMS;
typedef CK_TC26_ACPKM_CTR_PARAMS CK_PTR  CK_TC26_ACPKM_CTR_PARAMS_PTR;  

typedef struct CK_TC26_ACPKM_OMAC_PARAMS {
	CK_ULONG ulSectionLen;	
	CK_ULONG ulKeyChangeSectionLen;
	CK_ULONG ulOmacLen;
} CK_TC26_ACPKM_OMAC_PARAMS;
typedef CK_TC26_ACPKM_OMAC_PARAMS CK_PTR  CK_TC26_ACPKM_OMAC_PARAMS_PTR;  

typedef struct CK_TC26_KDF_GOSTR3411_2012_256_PARAMS {
	CK_BYTE_PTR pLabel;
	CK_ULONG ulLabelLen;
	CK_BYTE_PTR pSeed;
	CK_ULONG ulSeedLen;
} CK_TC26_KDF_GOSTR3411_2012_256_PARAMS;
typedef CK_TC26_KDF_GOSTR3411_2012_256_PARAMS CK_PTR  CK_TC26_KDF_GOSTR3411_2012_256_PARAMS_PTR;  

typedef struct CK_TC26_KDF_TREE_GOSTR3411_2012_256_PARAMS {
	CK_BYTE_PTR pLabel;
	CK_ULONG ulLabelLen;
	CK_BYTE_PTR pSeed;
	CK_ULONG ulSeedLen;
	CK_ULONG ulCounterBytes;
} CK_TC26_KDF_TREE_GOSTR3411_2012_256_PARAMS;
typedef CK_TC26_KDF_TREE_GOSTR3411_2012_256_PARAMS CK_PTR  CK_TC26_KDF_TREE_GOSTR3411_2012_256_PARAMS_PTR;  

typedef struct CK_TC26_GOSTR3410_2012_VKO_PARAMS {
    CK_BYTE_PTR               pPublicData;
    CK_ULONG                  ulPublicDataLen;
    CK_BYTE_PTR               pUKM;
    CK_ULONG                  ulUKMLen;
} CK_TC26_GOSTR3410_2012_VKO_PARAMS;
typedef CK_TC26_GOSTR3410_2012_VKO_PARAMS CK_PTR  CK_TC26_GOSTR3410_2012_VKO_PARAMS_PTR;  

typedef struct CK_GOST_CIPHER_PKCS8_KEY_WRAP_PARAMS {
	CK_CHAR_PTR      pPassword;
	CK_ULONG         ulPasswordLen;
    CK_BYTE_PTR      pSalt;
    CK_ULONG         ulSaltLen;
	CK_ULONG         ulIterCount;
	CK_KEY_TYPE      cipherKeyType;
    CK_BYTE_PTR      pIV;
    CK_ULONG         ulIVLen;
} CK_GOST_CIPHER_PKCS8_KEY_WRAP_PARAMS;
typedef CK_GOST_CIPHER_PKCS8_KEY_WRAP_PARAMS CK_PTR  CK_GOST_CIPHER_PKCS8_KEY_WRAP_PARAMS_PTR;  

#ifdef WIN32

#pragma pack(pop, cryptoki)
#endif

#ifdef __cplusplus
}
#endif
