⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cspconst.h

📁 基于SD卡的软实现CSP程序
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#ifndef INCL_CSPCONST_H
#define INCL_CSPCONST_H

#pragma once

#include <windows.h>

#define WfSC_CARD_NAME (TEXT("MSCSP T=0\0MSCSP T=1\0"))

#define AUTHPROTOCOL_PIN    0x01 
#define PINRETRY_OVER 0x03
//Extra DLL name and imports.

//GUI LIBRARY
//Note CE only supports GetProcAddressW and the desktop doesn't support it.
const WCHAR WfSC_GUI_LIB_NAME[] = (TEXT("GUI.dll"));
#ifdef _WIN32_WCE //CE (UNICODE strings)
	const WCHAR WfSC_GETPIN_PROC_NAME[] = (TEXT("GetPin"));
	const WCHAR WfSC_WAITFORCARDINSERTION_PROC_NAME[] = (TEXT("WaitForCardInsertion"));
	const WCHAR WfSC_NEWCARD_PROC_NAME[] = (TEXT("NewCard"));
	const WCHAR WfSC_FREEDATA_PROC_NAME[] = (TEXT("FreeData"));
#else  //Desktop (ASCII strings)
	const CHAR WfSC_GETPIN_PROC_NAME[] = ("GetPin");
	const CHAR WfSC_WAITFORCARDINSERTION_PROC_NAME[] = ("WaitForCardInsertion");
	const CHAR WfSC_NEWCARD_PROC_NAME[] = ("NewCard");
	const CHAR WfSC_FREEDATA_PROC_NAME[] = ("FreeData");
#endif

//CAPI2 LIBRARY (used for parsing public keys out of certificates)
const WCHAR WfSC_CAPI2_LIB_NAME[] = (TEXT("crypt32.dll"));
#ifdef _WIN32_WCE //CE (UNICODE strings)
	const WCHAR WfSC_CERTCREATE_PROC_NAME[] = (TEXT("CertCreateCertificateContext"));
	const WCHAR WfSC_CRYPTIMPORTPUBKEYINFOEX_PROC_NAME[] = (TEXT("CryptImportPublicKeyInfoEx"));
	const WCHAR WfSC_CERTFREE_PROC_NAME[] = (TEXT("CertFreeCertificateContext"));

#else //Desktop (ASCII strings)
	const CHAR WfSC_CERTCREATE_PROC_NAME[] = ("CertCreateCertificateContext");
	const WCHAR WfSC_CRYPTIMPORTPUBKEYINFOEX_PROC_NAME[] = (TEXT("CryptImportPublicKeyInfoEx"));
	const CHAR WfSC_CERTFREE_PROC_NAME[] = ("CertFreeCertificateContext");
#endif

#define WfSC_CSP_KP_ROOT (0x1)
#define WfSC_CSP_KP_USER (0x2)

//KP Constants
const WCHAR WfSC_ROOT_NAME[] = (TEXT("root"));
const WCHAR WfSC_USER_NAME[] = (TEXT("User"));
const WCHAR WfSC_NO_PIN_USER[] = (TEXT("NoPINUser"));
#define WfSC_MAX_AUTH_RETRY (0x3)

//For use with sprintf
const WCHAR WfSC_KP_PATH[] = (TEXT("/s/k/%s"));
const WCHAR WfSC_ACL_PATH[]  = (TEXT("/s/a/%s"));
const WCHAR WfSC_MUTEX_NAME[] = (TEXT("MS.Windows.CE.CAPI.CSP.WfSC.CCard.%s"));

//ACLs
const WCHAR WfSC_ACL_KPDIR[] = (TEXT("/s/a/kpdir"));
const WCHAR WfSC_ACL_CRT[] = (TEXT("/s/a/0001.crt"));
const WCHAR WfSC_ACL_KEY[] = (TEXT("/s/a/0001.key"));
const WCHAR WfSC_ACL_LKY[] = (TEXT("/s/a/0001.lky"));
const WCHAR WfSC_ACL_ROT[] = (TEXT("/s/a/0001.rot"));
const WCHAR WfSC_ACL_USR[] = (TEXT("/s/a/0001.usr"));
const WCHAR WfSC_ACL_PUB[] = (TEXT("/s/a/0001.pub"));
const WCHAR WfSC_ACL_DEFAULT[] = (TEXT("/s/a/default"));

//Directories
const WCHAR WfSC_DIR_CONT[] = (TEXT("/Cont"));
const WCHAR WfSC_DIR_CSP[] = (TEXT("/CSP"));

//TODO
//static TCHAR s_szProviderName[] = TEXT("OpenCSP RSA Full Provider 0.1");
//static DWORD s_dwCspType = PROV_RSA_FULL;

//Magic Numbers
#define WfSC_CONT_VER_NUM (1)
#define WfSC_IMP_TYPE (CRYPT_IMPL_MIXED | CRYPT_IMPL_REMOVABLE)

//Buffer sizes
#define MAX_BUFFER (255)
#define MAX_CARD_BUFFER (65535) //ScwAPI doesn't permit larger buffers.
#define MAX_NAME_BUFFER (40)

//Provider info
#define WfSC_PROVIDER_NAME (TEXT("SD Extended Cryptographic Service Provider"))
#define WfSC_PROVIDER_VERSION (0x00000500) //from desktop CSP.

//Default container name
const WCHAR WfSC_DEFAULT_CONTAINER[] = (TEXT("DEFAULT"));

//Container header constants
#define ALG_RSA		(0x1)
#define ALG_DES		(0x2)
#define ALG_DES3	(0x4)

#define OP_SIGN		(0x1)
#define OP_DECRYPT	(0x2)
#define OP_VERIFY	(0x4)
#define OP_ENCRYPT	(0x8)
#define OP_EXCHANGE (0x10)

//ASN.1 Constants
#define ASN1_HI_TAG_FORM (0x1F)
#define ASN1_HI_TAG_CONTINUE (0x80)

#define ASN1_LONG_LENGTH (0x80)
#define ASN1_LONG_LENGTH_BYTES (0x7F)

#define ASN1_SEQUENCE_ID (0x30)

const BYTE kbyoidMD2[] =
{	0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 
    0x48, 0x86, 0xf7, 0x0d, 0x02, 0x02, 0x05, 0x00, 
    0x04, 0x10
};

const BYTE kbyoidMD4[] =
{	0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 
    0x48, 0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 
	0x04, 0x10
};

const BYTE kbyoidMD5[] =
{
	0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 
    0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 
    0x04, 0x10
};

const BYTE kbyoidSHA1[] =
{
	0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,
    0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
};

static BYTE kbyKPData[] = // Cannot be const since hScwWriteFile requires a non-const param
{ 0x0, // Not a group KP, but a userKP.
0x0,  //KP does not belong to any groups.
AUTHPROTOCOL_PIN, // PIN authentication
WfSC_MAX_AUTH_RETRY, //Number of pw retries after success
WfSC_MAX_AUTH_RETRY}; //Number of pw retries currently remaining

#define SIZE_OF_CONTINFO (2)
#define SIZE_OF_KEYINFO (8)

#define CM_SHA			0x80
#define CM_DES			0x90
#define CM_3DES			0xA0 // triple DES
#define CM_RSA			0xB0
#define CM_RSA_CRT		0xC0
#define CM_CRYPTO_NAME	0xF0 // mask for crypto mechanism names

#define CM_KEY_INFILE	0x01	// if key is passed in a file
#define CM_DATA_INFILE	0x02	// if data is passed in a file
#define CM_PROPERTIES	0x0F	// maks for crypto properites

#endif//INCL_CSPCONST_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -