PKCS#11规范培训PPT课件.ppt 129页

  • 520.50 KB
  • 2022-04-29 14:40:14 发布

PKCS#11规范培训PPT课件.ppt

  • 129页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'PKCS#11标准介绍软件开发中心安全软件部 写在前面的PKCS11是什么为什么会有PKCS11PKCS11能干什么PKCS11的特点 PKCS11是什么PKCS系列规范的第11部分CryptographicTokenInterfaceSTD68个函数接口应用程序与加密Token之间的接口 为什么会有PKCS11为使用加密Token的应用程序提供统一的编程接口为应用程序提供独立于设备的编程接口屏蔽加密设备的复杂性应用程序可以方便的更换设备既生瑜何生亮PKCS11vsCSP PKCS11能干什么完成所有(据我所知)的密码操作加密解密签名验证摘要密钥生成/派生对象的创建,存储,查找,修改,使用,删除应用程序会话管理 PKCS11的特点跨平台可扩展支持多设备,多线程更专注于加密Token简化的应用模式(一个User,一个SO) 内容关于PKCS#11概述基本概念IV.典型对象属性分析V.API分析与应用实例 关于PKCS#11是一套针对加密Token的应用编程接口屏蔽了硬件细节针对ANSIC编写的接口也称作Cryptoki广泛应用于Token相关的产品中(例如Netscape,Mozilla,Firefox,Thunderbird)简化的应用模式(一个User,一个SO) 7816-1/2/3/4/5/6/8ASN.1PKCS-1/13/14/15,7816-15,DES,AES,SHA,MD2,MD5,…PKCS-11,CSPX509,PKCS-3/5/7/8/9/10/12SSL,S/MIMEIE,Outlook,Foxmail,Word,Netscape,Mozilla,Firefox,Thunderbird关于PKCS#11 内容关于PKCS#11概述基本概念IV.典型对象属性分析V.API分析与应用实例 概述总体模型 概述Token逻辑视图ObjectCertificateKeyDataSecretKeyPrivateKeyPublicKey令牌逻辑视图是一个能存储对象和能执行密码函数的设备 概述函数接口概述——通用目的函数 概述函数接口概述——槽和令牌管理函数 概述函数接口概述——会话管理函数 概述函数接口概述——对象管理函数 概述函数接口概述——加密和解密函数 概述函数接口概述——摘要计算函数 概述函数接口概述——签名和MAC计算函数 概述函数接口概述——签名和MAC验证函数 概述函数接口概述——双功能密码函数 概述函数接口概述——密钥管理函数 概述函数接口概述——其他函数 内容关于PKCS#11概述基本概念IV.典型对象属性分析V.API分析与应用实例 基本概念Slot&TokenObjectAttributeUsersSessions状态转换(与Session有关)Mechnism应用程序与多线程 3.1Slot&Token基本概念 基本概念3.2Object对象的层次结构 基本概念3.2ObjectToken对象Sesssion对象Public对象Private对象 基本概念3.3Attribute对象包括一套属性,每个对象都具有一个给定值。一个对象处理的每个属性都有一个唯一确定的值。 Cryptokiprovidesfunctionsforcreating,destroying,andcopyingobjectsingeneral,andforobtainingandmodifyingthevaluesoftheirattributes.Someofthecryptographicfunctions(e.g.,C_GenerateKey)alsocreatekeyobjectstoholdtheirresults.Objectsarealways“well-formed”inCryptoki—thatis,anobjectalwayscontainsallrequiredattributes,andtheattributesarealwaysconsistentwithoneanotherfromthetimetheobjectiscreated.Thiscontrastswithsomeobject-basedparadigmswhereanobjecthasnoattributesotherthanperhapsaclasswhenitiscreated,andisuninitializedforsometime.InCryptoki,objectsarealwaysinitialized.基本概念—Attribute Atokencanholdseveralidenticalobjects,i.e.,itispermissiblefortwoormoreobjectstohaveexactlythesamevaluesforalltheirattributes.InmostcaseseachtypeofobjectintheCryptokispecificationpossessesacompletelywell-definedsetofCryptokiattributes.Someoftheseattributespossessdefaultvalues,andneednotbespecifiedwhencreatinganobject;someofthesedefaultvaluesmayevenbetheemptystring(“”).Nonetheless,theobjectpossessestheseattributes.Agivenobjecthasasinglevalueforeachattributeitpossesses,eveniftheattributeisavendorspecificattributewhosemeaningisoutsidethescopeofCryptoki.InadditiontopossessingCryptokiattributes,objectsmaypossessadditionalvendorspecificattributeswhosemeaningsandvaluesarenotspecifiedbyCryptoki.基本概念—Attribute 基本概念3.4UsersPKCS11识别两种令牌用户类型。一个类型就是安全官员(SO)。另一个类型就是普通用户。只有普通用户才能访问令牌上的私有对象,而且只有普通用户在得到授权后才能进行这种访问。一些令牌可能需要用户在执行令牌上的任意密码功能之前得到授权,不管令牌是否涉及私有对象。SO的作用是初始化一个令牌,设置普通用户的PIN(或由Cryptoki版本以外的方式确定普通用户怎样得到授权),或许还要操作某些公共对象。普通用户只有在SO设置普通用户的PIN以后才能注册。 3.5Sessions基本概念会话在应用程序和令牌之间提供一个逻辑连接。Cryptoki需要用令牌打开一个以上的会话以便使用令牌的对象和函数。会话可以是读/写(R/W)会话,也可以是只读(R/O)会话。读/写和只读指的是通向令牌对象的入口,而不是会话对象。在这两种会话类型下,应用程序能够创建、读、写和破坏会话对象。但是,只有在读/写会话中,应用程序能够创建、修改和破坏令牌对象。 3.6状态转换(与Session有关)一个打开的会话可以在几种状态之一。会话状态决定通向对象和在会话上执行的函数允许的通道。基本概念打开一个会话后,应用程序便可访问令牌的公共对象。所给应用程序的所有线程可访问相同会话和相同会话对象。为了访问令牌私有对象,不同用户必须先登录并得到授权。当关闭一个会话后,在该会话过程中创建的任何会话对象都会被破坏。这甚至适用于其它会话正在使用的会话对象。如果单个应用程序打开同一令牌的多个会话,并使用其中一个创建会话对象,那么这些会话对象就可以被该应用程序的所有会话看到。但是,当创建对象的会话关闭时,对象也被破坏了。Cryptoki支持在多令牌上的多个会话。应用程序可以和一个以上的令牌进行一个以上的会话。一个令牌可以和一个以上的应用程序进行多个会话。但是,一个特定的令牌可能要求应用程序只能有限定数量的会话,或只能有限定数量的读/写会话。 状态转换–只读会话基本概念—状态转换 StateDescriptionR/OPublicSessionTheapplicationhasopenedaread-onlysession.Theapplicationhasread-onlyaccesstopublictokenobjectsandread/writeaccesstopublicsessionobjects.R/OUserFunctionsThenormaluserhasbeenauthenticatedtothetoken.Theapplicationhasread-onlyaccesstoalltokenobjects(publicorprivate)andread/writeaccesstoallsessionobjects(publicorprivate).ROsession基本概念—状态转换Note:Read-OnlySOSessiondonotexists. 状态转换–读写会话基本概念—状态转换 RWsessionStateDescriptionR/WPublicSessionTheapplicationhasopenedaread/writesession.Theapplicationhasread/writeaccesstoallpublicobjects.R/WSOFunctionsTheSecurityOfficerhasbeenauthenticatedtothetoken.Theapplicationhasread/writeaccessonlytopublicobjectsonthetoken,nottoprivateobjects.TheSOcansetthenormaluser’sPIN.R/WUserFunctionsThenormaluserhasbeenauthenticatedtothetoken.Theapplicationhasread/writeaccesstoallobjects.基本概念—状态转换 状态转换–会话权限TypeofobjectTypeofsessionR/OPublicR/WPublicR/OUserR/WUserR/WSOPublicsessionobjectR/WR/WR/WR/WR/WPrivatesessionobjectR/WR/WPublictokenobjectR/OR/WR/OR/WR/WPrivatetokenobjectR/OR/W基本概念—状态转换 Sessionevents基本概念—状态转换 在CryptokiVersion2.1中,使用令牌的一个应用程序的所有会话必须有相同的登录/注销状态(对于一个给定的应用程序和令牌,只能处于下列情况之一:所有会话是公共会话,所有会话是SO会话或所有会话是用户会话)。当一个应用程序的会话登录一个令牌,使用该令牌的应用程序的所有会话也被登录;当一个应用程序的会话注销一个令牌,该应用程序的所有会话也被注销。同样,例如,如果使用令牌的一个应用程序已经有一个打开的R/O用户,并且用该令牌打开一个R/W会话,该R/W会话会自动地登录。这意味着一个给定的应用程序使用一个给定的令牌不可能同时有打开的SO会话和用户会话。这也意味着如果使用一个令牌,一个应用程序有一个R/WSO会话,那么它不能用这个令牌打开一个R/O会话,因为R/OSO会话不存在。同理,如果一个应用程序有一个打开的R/O会话,那么它不可能作为SO把其它会话登录到该令牌。基本概念—状态转换 机制描述了密码操作应该怎样被执行typedefstructCK_MECHANISM{CK_MECHANISM_TYPEmechanism;CK_VOID_PTRpParameter;CK_ULONGulParameterLen;}CK_MECHANISM;C_GetMechanismList获取支持的机制列表基本概念—机制3.7Mechanism 调用C_Initialize后的应用程序才称为“Cryptoki应用程序”Cryptoki应用程序是否需要Cryptoki的多线程支持,需要在C_Initialize函数中指定。3.8应用程序与多线程基本概念 内容关于PKCS#11概述基本概念IV.典型对象属性分析V.API分析与应用实例 4.1对象属性脚注说明1MustbespecifiedwhenobjectiscreatedwithC_CreateObject.2MustnotbespecifiedwhenobjectiscreatedwithC_CreateObject.3MustbespecifiedwhenobjectisgeneratedwithC_GenerateKeyorC_GenerateKeyPair.4MustnotbespecifiedwhenobjectisgeneratedwithC_GenerateKeyorC_GenerateKeyPair.5MustbespecifiedwhenobjectisunwrappedwithC_UnwrapKey.6MustnotbespecifiedwhenobjectisunwrappedwithC_UnwrapKey.7CannotberevealedifobjecthasitsCKA_SENSITIVEattributesettoCK_TRUEoritsCKA_EXTRACTABLEattributesettoCK_FALSE.IV典型对象属性分析 4.1对象属性脚注说明8MaybemodifiedafterobjectiscreatedwithaC_SetAttributeValuecall,orintheprocessofcopyingobjectwithaC_CopyObjectcall.However,itispossiblethataparticulartokenmaynotpermitmodificationoftheattributeduringthecourseofaC_CopyObjectcall.9Defaultvalueistoken-specific,andmaydependonthevaluesofotherattributes.10CanonlybesettoCK_TRUEbytheSOuser.11AttributecannotbechangedoncesettoCK_TRUE.Itbecomesareadonlyattribute.12AttributecannotbechangedoncesettoCK_FALSE.Itbecomesareadonlyattribute.IV典型对象属性分析 4.2通用对象属性AttributeDataTypeMeaningCKA_CLASSCK_OBJECT_CLASSObjectclass(type) 4.3通用存储对象属性AttributeDataTypeMeaningCKA_TOKENCK_BBOOLCK_TRUEifobjectisatokenobject;CK_FALSEifobjectisasessionobject.DefaultisCK_FALSE.CKA_PRIVATECK_BBOOLCK_TRUEifobjectisaprivateobject;CK_FALSEifobjectisapublicobject.Defaultvalueistoken-specific,andmaydependonthevaluesofotherattributesoftheobject.CKA_MODIFIABLECK_BBOOLCK_TRUEifobjectcanbemodifiedDefaultisCK_TRUE.CKA_LABELRFC2279stringDescriptionoftheobject(defaultempty).当对象创建以后,只有CKA_TOKEN值可以被修改 4.4数据对象属性AttributeDatatypeMeaningCKA_APPLICATIONRFC2279stringDescriptionoftheapplicationthatmanagestheobject(defaultempty)CKA_OBJECT_IDByteArrayDER-encodingoftheobjectidentifierindicatingthedataobjecttype(defaultempty)CKA_VALUEBytearrayValueoftheobject(defaultempty) 4.5通用证书对象属性AttributeDatatypeMeaningCKA_CERTIFICATE_TYPE1CK_CERTIFICATE_TYPETypeofcertificateCKA_TRUSTED10CK_BBOOLThecertificatecanbetrustedfortheapplicationthatitwascreated.CKA_CERTIFICATE_CATEGORYCK_ULONGCategorizationofthecertificate: 0=unspecified(defaultvalue),1=tokenuser,2=authority,3=otherentityCKA_CHECK_VALUEBytearrayChecksumCKA_START_DATECK_DATEStartdateforthecertificate(defaultempty)CKA_END_DATECK_DATEEnddateforthecertificate(defaultempty) 4.6X.509公钥证书对象AttributeDatatypeMeaningCKA_SUBJECT1BytearrayDER-encodingofthecertificatesubjectnameCKA_IDBytearrayKeyidentifierforpublic/privatekeypair(defaultempty)CKA_ISSUERBytearrayDER-encodingofthecertificateissuername(defaultempty)CKA_SERIAL_NUMBERBytearrayDER-encodingofthecertificateserialnumber(defaultempty)CKA_VALUE1BytearrayBER-encodingofthecertificateCKA_URL3RFC2279stringIfnotemptythisattributegivestheURLwherethecompletecertificatecanbeobtained(defaultempty)CKA_HASH_OF_SUBJECT_PUBLIC_KEY4BytearraySHA-1hashofthesubjectpublickey(defaultempty)CKA_HASH_OF_ISSUER_PUBLIC_KEY4BytearraySHA-1hashoftheissuerpublickey(defaultempty)CKA_JAVA_MIDP_SECURITY_DOMAINCK_ULONGJavaMIDPsecuritydomain:0=unspecified(defaultvalue),1=manufacturer,2=operator,3=thirdparty 4.7WTLS公钥证书对象AttributeDatatypeMeaningCKA_SUBJECT1BytearrayWTLS-encoding(Identifiertype)ofthecertificatesubjectCKA_ISSUER2BytearrayWTLS-encoding(Identifiertype)ofthecertificateissuer(defaultempty)CKA_VALUEBytearrayWTLS-encodingofthecertificateCKA_URL3RFC2279stringIfnotemptythisattributegivestheURLwherethecompletecertificatecanbeobtainedCKA_HASH_OF_SUBJECT_PUBLIC_KEY4BytearraySHA-1hashofthesubjectpublickey(defaultempty)CKA_HASH_OF_ISSUER_PUBLIC_KEY4BytearraySHA-1hashoftheissuerpublickey(defaultempty) 4.8X.509属性证书对象AttributeDataTypeMeaningCKA_OWNER1ByteArrayDER-encodingoftheattributecertificate"ssubjectfield.ThisisdistinctfromtheCKA_SUBJECTattributecontainedinCKC_X_509certificatesbecausetheASN.1syntaxandencodingaredifferent.CKA_AC_ISSUERByteArrayDER-encodingoftheattributecertificate"sissuerfield.ThisisdistinctfromtheCKA_ISSUERattributecontainedinCKC_X_509certificatesbecausetheASN.1syntaxandencodingaredifferent.(defaultempty)CKA_SERIAL_NUMBERByteArrayDER-encodingofthecertificateserialnumber.(defaultempty)CKA_ATTR_TYPESByteArrayBER-encodingofasequenceofobjectidentifiervaluescorrespondingtotheattributetypescontainedinthecertificate.Whenpresent,thisfieldoffersanopportunityforapplicationstosearchforaparticularattributecertificatewithoutfetchingandparsingthecertificateitself.(defaultempty)CKA_VALUE1ByteArrayBER-encodingofthecertificate. 4.9通用KEY属性AttributeDataTypeMeaningCKA_KEY_TYPE1,5CK_KEY_TYPETypeofkeyCKA_ID8BytearrayKeyidentifierforkey(defaultempty)CKA_START_DATE8CK_DATEStartdateforthekey(defaultempty)CKA_END_DATE8CK_DATEEnddateforthekey(defaultempty)CKA_DERIVE8CK_BBOOLCK_TRUEifkeysupportskeyderivation(i.e.,ifotherkeyscanbederivedfromthisone(defaultCK_FALSE)CKA_LOCAL2,4,6CK_BBOOLCK_TRUEonlyifkeywaseithergeneratedlocally(i.e.,onthetoken)withaC_GenerateKeyorC_GenerateKeyPaircallcreatedwithaC_CopyObjectcallasacopyofakeywhichhaditsCKA_LOCALattributesettoCK_TRUECKA_KEY_GEN_ MECHANISM2,4,6CK_MECHANISM_TYPEIdentifierofthemechanismusedtogeneratethekeymaterial.CKA_ALLOWED_MECHANISMSCK_MECHANISM_TYPE_PTR,pointertoaCK_MECHANISM_TYPEarrayAlistofmechanismsallowedtobeusedwiththiskey.ThenumberofmechanismsinthearrayistheulValueLencomponentoftheattributedividedbythesizeofCK_MECHANISM_TYPE. 4.10通用公钥对象AttributeDatatypeMeaningCKA_SUBJECT8BytearrayDER-encodingofthekeysubjectname(defaultempty)CKA_ENCRYPT8CK_BBOOLCK_TRUEifkeysupportsencryption9CKA_VERIFY8CK_BBOOLCK_TRUEifkeysupportsverificationwherethesignatureisanappendixtothedata9CKA_VERIFY_RECOVER8CK_BBOOLCK_TRUEifkeysupportsverificationwherethedataisrecoveredfromthesignature9CKA_WRAP8CK_BBOOLCK_TRUEifkeysupportswrapping(i.e.,canbeusedtowrapotherkeys)9CKA_TRUSTED10CK_BBOOLThekeycanbetrustedfortheapplicationthatitwascreated.ThewrappingkeycanbeusedtowrapkeyswithCKA_WRAP_WITH_TRUSTEDsettoCK_TRUE.CKA_WRAP_TEMPLATECK_ATTRIBUTE_PTRForwrappingkeys.Theattributetemplatetomatchagainstanykeyswrappedusingthiswrappingkey.Keysthatdonotmatchcannotbewrapped.ThenumberofattributesinthearrayistheulValueLencomponentoftheattributedividedbythesizeofCK_ATTRIBUTE. RSA公钥对象属性 4.11通用私钥对象(1)AttributeDatatypeMeaningCKA_SUBJECT8BytearrayDER-encodingofcertificatesubjectname(defaultempty)CKA_SENSITIVE8CK_BBOOLCK_TRUEifkeyissensitive9CKA_DECRYPT8CK_BBOOLCK_TRUEifkeysupportsdecryption9CKA_SIGN8CK_BBOOLCK_TRUEifkeysupportssignatureswherethesignatureisanappendixtothedata9CKA_SIGN_RECOVER8CK_BBOOLCK_TRUEifkeysupportssignatureswherethedatacanberecoveredfromthesignature9CKA_UNWRAP8CK_BBOOLCK_TRUEifkeysupportsunwrapping(i.e.,canbeusedtounwrapotherkeys)9CKA_EXTRACTABLE8,12CK_BBOOLCK_TRUEifkeyisextractableandcanbewrapped9CKA_ALWAYS_SENSITIVE2,4,6CK_BBOOLCK_TRUEifkeyhasalwayshadtheCKA_SENSITIVEattributesettoCK_TRUECKA_NEVER_EXTRACTABLE2,4,6CK_BBOOLCK_TRUEifkeyhasneverhadtheCKA_EXTRACTABLEattributesettoCK_TRUE 4.11通用私钥对象(2)AttributeDataTypeMeaningCKA_WRAP_WITH_TRUSTED11CK_BBOOLCK_TRUEifthekeycanonlybewrappedwithawrappingkeythathasCKA_TRUSTEDsettoCK_TRUE.DefaultisCK_FALSE.CKA_UNWRAP_TEMPLATECK_ATTRIBUTE_PTRForwrappingkeys.Theattributetemplatetoapplytoanykeysunwrappedusingthiswrappingkey.Anyusersuppliedtemplateisappliedafterthistemplateasiftheobjecthasalreadybeencreated.ThenumberofattributesinthearrayistheulValueLencomponentoftheattributedividedbythesizeofCK_ATTRIBUTE.CKA_ALWAYS_AUTHENTICATECK_BBOOLIfCK_TRUE,theuserhastosupplythePINforeachuse(signordecrypt)withthekey.DefaultisCK_FALSE. RSA私钥对象属性 4.12通用密钥对象(1)AttributeDataTypeMeaningCKA_SENSITIVE8,11CK_BBOOLCK_TRUEifobjectissensitive(defaultCK_FALSE)CKA_ENCRYPT8CK_BBOOLCK_TRUEifkeysupportsencryption9CKA_DECRYPT8CK_BBOOLCK_TRUEifkeysupportsdecryption9CKA_SIGN8CK_BBOOLCK_TRUEifkeysupportssignatures(i.e.,authenticationcodes)wherethesignatureisanappendixtothedata9CKA_VERIFY8CK_BBOOLCK_TRUEifkeysupportsverification(i.e.,ofauthenticationcodes)wherethesignatureisanappendixtothedata9CKA_WRAP8CK_BBOOLCK_TRUEifkeysupportswrapping(i.e.,canbeusedtowrapotherkeys)9CKA_UNWRAP8CK_BBOOLCK_TRUEifkeysupportsunwrapping(i.e.,canbeusedtounwrapotherkeys)9CKA_ALWAYS_SENSITIVE2,4,6CK_BBOOLCK_TRUEifkeyisextractableandcanbewrapped9CKA_NEVER_EXTRACTABLE2,4,6CK_BBOOLCK_TRUEifkeyhasalwayshadtheCKA_SENSITIVEattributesettoCK_TRUE 4.12通用密钥对象(2)AttributeDataTypeMeaningCKA_CHECK_VALUEBytearrayKeychecksumCKA_WRAP_WITH_TRUSTED11CK_BBOOLCK_TRUEifthekeycanonlybewrappedwithawrappingkeythathasCKA_TRUSTEDsettoCK_TRUE.DefaultisCK_FALSE.CKA_TRUSTED10CK_BBOOLThewrappingkeycanbeusedtowrapkeyswithCKA_WRAP_WITH_TRUSTEDsettoCK_TRUE.CKA_WRAP_TEMPLATECK_ATTRIBUTE_PTRForwrappingkeys.Theattributetemplatetomatchagainstanykeyswrappedusingthiswrappingkey.Keysthatdonotmatchcannotbewrapped.ThenumberofattributesinthearrayistheulValueLencomponentoftheattributedividedbythesizeofCK_ATTRIBUTECKA_UNWRAP_TEMPLATECK_ATTRIBUTE_PTRForwrappingkeys.Theattributetemplatetoapplytoanykeysunwrappedusingthiswrappingkey.Anyusersuppliedtemplateisappliedafterthistemplateasiftheobjecthasalreadybeencreated.ThenumberofattributesinthearrayistheulValueLencomponentoftheattributedividedbythesizeofCK_ATTRIBUTE. DES密钥对象属性 RC4密钥对象属性 4.13对象属性总结PKCS#11规定了每个对象的每一个属性属性脚注表非常重要,对象的创建、修改、拷贝等操作时设定的属性模板应不违背属性标注(例如,在C_GenerateKey生成3DES密钥时需要指定CKA_KEY_TYPE,而不能指定CKA_LOCAL)。PKCS#11标准的各个版本中对象属性的脚注存在差别(例如,Ver2.1中C_GenerateKeyPair时必须指定CKA_PUBLIC_EXPONENT,而在Ver2.2中可以不用指定此属性) 内容关于PKCS#11概述基本概念典型对象属性分析API分析与应用实例 VAPI分析与应用实例通用目的函数Initialize,cleanup,informationaboutthelibraryitselfSlot/Token管理函数GetSlotInfo,GetTokenInfo,…会话管理函数OpenSession,CloseSession…对象管理函数Create,Destroy,Copy ⅢAPI分析与应用实例(2)加密函数解密函数摘要函数签名函数校验函数密钥管理函数…… 通用目的函数1.C_InitializeCK_DEFINE_FUNCTION(CK_RV,C_Initialize)(CK_VOID_PTRpInitArgs);typedefstructCK_C_INITIALIZE_ARGS{CK_CREATEMUTEXCreateMutex;CK_DESTROYMUTEXDestroyMutex;CK_LOCKMUTEXLockMutex;CK_UNLOCKMUTEXUnlockMutex;CK_FLAGSflags;CK_VOID_PTRpReserved;}CK_C_INITIALIZE_ARGS;2.C_FinalizeCK_DEFINE_FUNCTION(CK_RV,C_Finalize)(CK_VOID_PTRpReserved); 通用目的函数3.C_GetInfoCK_DEFINE_FUNCTION(CK_RV,C_GetInfo)(CK_INFO_PTRpInfo);4.C_GetFunctionListCK_DEFINE_FUNCTION(CK_RV,C_GetFunctionList)( CK_FUNCTION_LIST_PTR_PTRppFunctionList ); Slot/Token管理函数C_GetSlotListCK_DEFINE_FUNCTION(CK_RV,C_GetSlotList)(CK_BBOOLtokenPresent, CK_SLOT_ID_PTRpSlotList, CK_ULONG_PTRpulCount); Slot/Token管理函数2.C_GetSlotInfoCK_DEFINE_FUNCTION(CK_RV,C_GetSlotInfo)(CK_SLOT_IDslotID, CK_SLOT_INFO_PTRpInfo); Slot/Token管理函数3.C_GetTokenInfoCK_DEFINE_FUNCTION(CK_RV,C_GetTokenInfo)(CK_SLOT_IDslotID, CK_TOKEN_INFO_PTRpInfo); Slot/Token管理函数4.C_WaitForSlotEventCK_DEFINE_FUNCTION(CK_RV,C_WaitForSlotEvent)(CK_FLAGSflags, CK_SLOT_ID_PTRpSlot, CK_VOID_PTRpReserved); Slot/Token管理函数5.C_GetMechanismListCK_DEFINE_FUNCTION(CK_RV,C_GetMechanismList)(CK_SLOT_IDslotID, CK_MECHANISM_TYPE_PTRpMechanismList, CK_ULONG_PTRpulCount); Slot/Token管理函数6.C_GetMechanismInfoCK_DEFINE_FUNCTION(CK_RV,C_GetMechanismInfo)(CK_SLOT_IDslotID, CK_MECHANISM_TYPEtype, CK_MECHANISM_INFO_PTRpInfo); Slot/Token管理函数7.C_InitTokenCK_DEFINE_FUNCTION(CK_RV,C_InitToken)(CK_SLOT_IDslotID, CK_UTF8CHAR_PTRpPin, CK_ULONGulPinLen, CK_UTF8CHAR_PTRpLabel); Slot/Token管理函数8.C_InitPINCK_DEFINE_FUNCTION(CK_RV,C_InitPIN)(CK_SESSION_HANDLEhSession, CK_UTF8CHAR_PTRpPin, CK_ULONGulPinLen); Slot/Token管理函数9.C_SetPINCK_DEFINE_FUNCTION(CK_RV,C_SetPIN)(CK_SESSION_HANDLEhSession, CK_UTF8CHAR_PTRpOldPin, CK_ULONGulOldLen, CK_UTF8CHAR_PTRpNewPin, CK_ULONGulNewLen); 会话管理函数1.C_OpenSessionCK_DEFINE_FUNCTION(CK_RV,C_OpenSession)(CK_SLOT_IDslotID, CK_FLAGSflags, CK_VOID_PTRpApplication, CK_NOTIFYNotify, CK_SESSION_HANDLE_PTRphSession); 会话管理函数2.C_CloseSessionCK_DEFINE_FUNCTION(CK_RV,C_CloseSession)(CK_SESSION_HANDLEhSession); 会话管理函数3.C_CloseAllSessionsCK_DEFINE_FUNCTION(CK_RV,C_CloseAllSessions)(CK_SLOT_IDslotID); 会话管理函数4.C_GetSessionInfoCK_DEFINE_FUNCTION(CK_RV,C_GetSessionInfo)(CK_SESSION_HANDLEhSession, CK_SESSION_INFO_PTRpInfo); 会话管理函数5.C_GetOperationStateCK_DEFINE_FUNCTION(CK_RV,C_GetOperationState)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpOperationState, CK_ULONG_PTRpulOperationStateLen); 会话管理函数6.C_SetOperationStateCK_DEFINE_FUNCTION(CK_RV,C_SetOperationState)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpOperationState, CK_ULONGulOperationStateLen, CK_OBJECT_HANDLEhEncryptionKey, CK_OBJECT_HANDLEhAuthenticationKey); 会话管理函数7.C_LoginCK_DEFINE_FUNCTION(CK_RV,C_Login)(CK_SESSION_HANDLEhSession, CK_USER_TYPEuserType, CK_UTF8CHAR_PTRpPin, CK_ULONGulPinLen); 会话管理函数8.C_LogoutCK_DEFINE_FUNCTION(CK_RV,C_Logout)(CK_SESSION_HANDLEhSession); 对象管理函数1.C_CreateObjectCK_DEFINE_FUNCTION(CK_RV,C_CreateObject)(CK_SESSION_HANDLEhSession, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulCount, CK_OBJECT_HANDLE_PTRphObject); 对象管理函数2.C_CopyObjectCK_DEFINE_FUNCTION(CK_RV,C_CopyObject)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLEhObject, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulCount, CK_OBJECT_HANDLE_PTRphNewObject); 对象管理函数3.C_DestroyObjectCK_DEFINE_FUNCTION(CK_RV,C_DestroyObject)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLEhObject); 对象管理函数4.C_GetObjectSizeCK_DEFINE_FUNCTION(CK_RV,C_GetObjectSize)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLEhObject, CK_ULONG_PTRpulSize); 对象管理函数5.C_GetAttributeValueCK_DEFINE_FUNCTION(CK_RV,C_GetAttributeValue)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLEhObject, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulCount); 对象管理函数6.C_SetAttributeValueCK_DEFINE_FUNCTION(CK_RV,C_SetAttributeValue)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLEhObject, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulCount); 对象管理函数7.C_FindObjectsInitCK_DEFINE_FUNCTION(CK_RV,C_FindObjectsInit)(CK_SESSION_HANDLEhSession, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulCount); 对象管理函数8.C_FindObjectsCK_DEFINE_FUNCTION(CK_RV,C_FindObjects)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLE_PTRphObject, CK_ULONGulMaxObjectCount, CK_ULONG_PTRpulObjectCount); 对象管理函数9.C_FindObjectsFinalCK_DEFINE_FUNCTION(CK_RV,C_FindObjectsFinal)(CK_SESSION_HANDLEhSession); 加密函数1.C_EncryptInitCK_DEFINE_FUNCTION(CK_RV,C_EncryptInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhKey); 加密函数2.C_EncryptCK_DEFINE_FUNCTION(CK_RV,C_Encrypt)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpData, CK_ULONGulDataLen, CK_BYTE_PTRpEncryptedData, CK_ULONG_PTRpulEncryptedDataLen); 加密函数3.C_EncryptUpdateCK_DEFINE_FUNCTION(CK_RV,C_EncryptUpdate)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpPart, CK_ULONGulPartLen, CK_BYTE_PTRpEncryptedPart, CK_ULONG_PTRpulEncryptedPartLen); 加密函数4.C_EncryptFinalCK_DEFINE_FUNCTION(CK_RV,C_EncryptFinal)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpLastEncryptedPart, CK_ULONG_PTRpulLastEncryptedPartLen); 解密函数1.C_DecryptInitCK_DEFINE_FUNCTION(CK_RV,C_DecryptInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhKey); 解密函数2.C_DecryptCK_DEFINE_FUNCTION(CK_RV,C_Decrypt)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpEncryptedData, CK_ULONGulEncryptedDataLen, CK_BYTE_PTRpData, CK_ULONG_PTRpulDataLen); 解密函数3.C_DecryptUpdateCK_DEFINE_FUNCTION(CK_RV,C_DecryptUpdate)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpEncryptedPart, CK_ULONGulEncryptedPartLen, CK_BYTE_PTRpPart, CK_ULONG_PTRpulPartLen); 解密函数4.C_DecryptFinalCK_DEFINE_FUNCTION(CK_RV,C_DecryptFinal)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpLastPart, CK_ULONG_PTRpulLastPartLen); 摘要函数1.C_DigestInitCK_DEFINE_FUNCTION(CK_RV,C_DigestInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism); 摘要函数2.C_DigestCK_DEFINE_FUNCTION(CK_RV,C_Digest)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpData, CK_ULONGulDataLen, CK_BYTE_PTRpDigest, CK_ULONG_PTRpulDigestLen); 摘要函数3.C_DigestUpdateCK_DEFINE_FUNCTION(CK_RV,C_DigestUpdate)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpPart, CK_ULONGulPartLen); 摘要函数4.C_DigestKeyCK_DEFINE_FUNCTION(CK_RV,C_DigestKey)(CK_SESSION_HANDLEhSession, CK_OBJECT_HANDLEhKey); 摘要函数5.C_DigestFinalCK_DEFINE_FUNCTION(CK_RV,C_DigestFinal)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpDigest, CK_ULONG_PTRpulDigestLen); 签名函数1.C_SignInitCK_DEFINE_FUNCTION(CK_RV,C_SignInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhKey); 签名函数2.C_SignCK_DEFINE_FUNCTION(CK_RV,C_Sign)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpData, CK_ULONGulDataLen, CK_BYTE_PTRpSignature, CK_ULONG_PTRpulSignatureLen); 签名函数3.C_SignUpdateCK_DEFINE_FUNCTION(CK_RV,C_SignUpdate)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpPart, CK_ULONGulPartLen); 签名函数4.C_SignFinalCK_DEFINE_FUNCTION(CK_RV,C_SignFinal)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpSignature, CK_ULONG_PTRpulSignatureLen); 签名函数5.C_SignRecoverInitCK_DEFINE_FUNCTION(CK_RV,C_SignRecoverInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhKey); 签名函数6.C_SignRecoverCK_DEFINE_FUNCTION(CK_RV,C_SignRecover)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpData, CK_ULONGulDataLen, CK_BYTE_PTRpSignature, CK_ULONG_PTRpulSignatureLen); 校验函数1.C_VerifyInitCK_DEFINE_FUNCTION(CK_RV,C_VerifyInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhKey); 校验函数2.C_VerifyCK_DEFINE_FUNCTION(CK_RV,C_Verify)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpData, CK_ULONGulDataLen, CK_BYTE_PTRpSignature, CK_ULONGulSignatureLen); 校验函数3.C_VerifyUpdateCK_DEFINE_FUNCTION(CK_RV,C_VerifyUpdate)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpPart, CK_ULONGulPartLen); 校验函数4.C_VerifyFinalCK_DEFINE_FUNCTION(CK_RV,C_VerifyFinal)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpSignature, CK_ULONGulSignatureLen); 校验函数5.C_VerifyRecoverInitCK_DEFINE_FUNCTION(CK_RV,C_VerifyRecoverInit)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhKey); 校验函数6.C_VerifyRecoverCK_DEFINE_FUNCTION(CK_RV,C_VerifyRecover)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpSignature, CK_ULONGulSignatureLen, CK_BYTE_PTRpData, CK_ULONG_PTRpulDataLen); KEY管理函数1.C_GenerateKeyCK_DEFINE_FUNCTION(CK_RV,C_GenerateKey)(CK_SESSION_HANDLEhSession CK_MECHANISM_PTRpMechanism, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulCount, CK_OBJECT_HANDLE_PTRphKey); KEY管理函数2.C_GenerateKeyPairCK_DEFINE_FUNCTION(CK_RV,C_GenerateKeyPair)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_ATTRIBUTE_PTRpPublicKeyTemplate, CK_ULONGulPublicKeyAttributeCount, CK_ATTRIBUTE_PTRpPrivateKeyTemplate, CK_ULONGulPrivateKeyAttributeCount, CK_OBJECT_HANDLE_PTRphPublicKey, CK_OBJECT_HANDLE_PTRphPrivateKey); KEY管理函数3.C_WrapKeyCK_DEFINE_FUNCTION(CK_RV,C_WrapKey)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhWrappingKey, CK_OBJECT_HANDLEhKey, CK_BYTE_PTRpWrappedKey, CK_ULONG_PTRpulWrappedKeyLen); KEY管理函数4.C_UnwrapKeyCK_DEFINE_FUNCTION(CK_RV,C_UnwrapKey)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhUnwrappingKey, CK_BYTE_PTRpWrappedKey, CK_ULONGulWrappedKeyLen, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulAttributeCount, CK_OBJECT_HANDLE_PTRphKey); KEY管理函数4.C_DeriveKeyCK_DEFINE_FUNCTION(CK_RV,C_DeriveKey)(CK_SESSION_HANDLEhSession, CK_MECHANISM_PTRpMechanism, CK_OBJECT_HANDLEhBaseKey, CK_ATTRIBUTE_PTRpTemplate, CK_ULONGulAttributeCount, CK_OBJECT_HANDLE_PTRphKey); 产生随机数函数1.C_SeedRandomCK_DEFINE_FUNCTION(CK_RV,C_SeedRandom)(CK_SESSION_HANDLEhSession, CK_BYTE_PTRpSeed, CK_ULONGulSeedLen); 产生随机数函数2.C_GenerateRandomCK_DEFINE_FUNCTION(CK_RV,C_GenerateRandom)(CK_SESSION_HANDLEhSession,CK_BYTE_PTRpRandomData,CK_ULONGulRandomLen); 使用PKCS#11注意事项如果函数返回值为CKR_OK,则表明函数执行成功,如果返回值为其他值,返回值只能大致描述出现的错误,但不能精确表达运行中发生的错误。除了C_GetFunctionList外都要在执行C_Initialize后执行。注意内存空间的使用。 Question/Answer'