nssckmdt.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef NSSCKMDT_H
  5. #define NSSCKMDT_H
  6. /*
  7. * nssckmdt.h
  8. *
  9. * This file specifies the basic types that must be implemented by
  10. * any Module using the NSS Cryptoki Framework.
  11. */
  12. #ifndef NSSBASET_H
  13. #include "nssbaset.h"
  14. #endif /* NSSBASET_H */
  15. #ifndef NSSCKT_H
  16. #include "nssckt.h"
  17. #endif /* NSSCKT_H */
  18. #ifndef NSSCKFWT_H
  19. #include "nssckfwt.h"
  20. #endif /* NSSCKFWT_H */
  21. typedef struct NSSCKMDInstanceStr NSSCKMDInstance;
  22. typedef struct NSSCKMDSlotStr NSSCKMDSlot;
  23. typedef struct NSSCKMDTokenStr NSSCKMDToken;
  24. typedef struct NSSCKMDSessionStr NSSCKMDSession;
  25. typedef struct NSSCKMDCryptoOperationStr NSSCKMDCryptoOperation;
  26. typedef struct NSSCKMDFindObjectsStr NSSCKMDFindObjects;
  27. typedef struct NSSCKMDMechanismStr NSSCKMDMechanism;
  28. typedef struct NSSCKMDObjectStr NSSCKMDObject;
  29. /*
  30. * NSSCKFWItem
  31. *
  32. * This is a structure used by modules to return object attributes.
  33. * The needsFreeing bit indicates whether the object needs to be freed.
  34. * If so, the framework will call the FreeAttribute function on the item
  35. * after it is done using it.
  36. *
  37. */
  38. typedef struct {
  39. PRBool needsFreeing;
  40. NSSItem *item;
  41. } NSSCKFWItem;
  42. /*
  43. * NSSCKMDInstance
  44. *
  45. * This is the basic handle for an instance of a PKCS#11 Module.
  46. * It is returned by the Module's CreateInstance routine, and
  47. * may be obtained from the corresponding NSSCKFWInstance object.
  48. * It contains a pointer for use by the Module, to store any
  49. * instance-related data, and it contains the EPV for a set of
  50. * routines which the Module may implement for use by the Framework.
  51. * Some of these routines are optional; others are mandatory.
  52. */
  53. struct NSSCKMDInstanceStr {
  54. /*
  55. * The Module may use this pointer for its own purposes.
  56. */
  57. void *etc;
  58. /*
  59. * This routine is called by the Framework to initialize
  60. * the Module. This routine is optional; if unimplemented,
  61. * it won't be called. If this routine returns an error,
  62. * then the initialization will fail.
  63. */
  64. CK_RV(PR_CALLBACK *Initialize)
  65. (
  66. NSSCKMDInstance *mdInstance,
  67. NSSCKFWInstance *fwInstance,
  68. NSSUTF8 *configurationData);
  69. /*
  70. * This routine is called when the Framework is finalizing
  71. * the PKCS#11 Module. It is the last thing called before
  72. * the NSSCKFWInstance's NSSArena is destroyed. This routine
  73. * is optional; if unimplemented, it merely won't be called.
  74. */
  75. void(PR_CALLBACK *Finalize)(
  76. NSSCKMDInstance *mdInstance,
  77. NSSCKFWInstance *fwInstance);
  78. /*
  79. * This routine gets the number of slots. This value must
  80. * never change, once the instance is initialized. This
  81. * routine must be implemented. It may return zero on error.
  82. */
  83. CK_ULONG(PR_CALLBACK *GetNSlots)
  84. (
  85. NSSCKMDInstance *mdInstance,
  86. NSSCKFWInstance *fwInstance,
  87. CK_RV *pError);
  88. /*
  89. * This routine returns the version of the Cryptoki standard
  90. * to which this Module conforms. This routine is optional;
  91. * if unimplemented, the Framework uses the version to which
  92. * ~it~ was implemented.
  93. */
  94. CK_VERSION(PR_CALLBACK *GetCryptokiVersion)
  95. (
  96. NSSCKMDInstance *mdInstance,
  97. NSSCKFWInstance *fwInstance);
  98. /*
  99. * This routine returns a pointer to a UTF8-encoded string
  100. * containing the manufacturer ID for this Module. Only
  101. * the characters completely encoded in the first thirty-
  102. * two bytes are significant. This routine is optional.
  103. * The string returned is never freed; if dynamically generated,
  104. * the space for it should be allocated from the NSSArena
  105. * that may be obtained from the NSSCKFWInstance. This
  106. * routine may return NULL upon error; however if *pError
  107. * is CKR_OK, the NULL will be considered the valid response.
  108. */
  109. NSSUTF8 *(PR_CALLBACK *GetManufacturerID)(
  110. NSSCKMDInstance *mdInstance,
  111. NSSCKFWInstance *fwInstance,
  112. CK_RV *pError);
  113. /*
  114. * This routine returns a pointer to a UTF8-encoded string
  115. * containing a description of this Module library. Only
  116. * the characters completely encoded in the first thirty-
  117. * two bytes are significant. This routine is optional.
  118. * The string returned is never freed; if dynamically generated,
  119. * the space for it should be allocated from the NSSArena
  120. * that may be obtained from the NSSCKFWInstance. This
  121. * routine may return NULL upon error; however if *pError
  122. * is CKR_OK, the NULL will be considered the valid response.
  123. */
  124. NSSUTF8 *(PR_CALLBACK *GetLibraryDescription)(
  125. NSSCKMDInstance *mdInstance,
  126. NSSCKFWInstance *fwInstance,
  127. CK_RV *pError);
  128. /*
  129. * This routine returns the version of this Module library.
  130. * This routine is optional; if unimplemented, the Framework
  131. * will assume a Module library version of 0.1.
  132. */
  133. CK_VERSION(PR_CALLBACK *GetLibraryVersion)
  134. (
  135. NSSCKMDInstance *mdInstance,
  136. NSSCKFWInstance *fwInstance);
  137. /*
  138. * This routine returns CK_TRUE if the Module wishes to
  139. * handle session objects. This routine is optional.
  140. * If this routine is NULL, or if it exists but returns
  141. * CK_FALSE, the Framework will assume responsibility
  142. * for managing session objects.
  143. */
  144. CK_BBOOL(PR_CALLBACK *ModuleHandlesSessionObjects)
  145. (
  146. NSSCKMDInstance *mdInstance,
  147. NSSCKFWInstance *fwInstance);
  148. /*
  149. * This routine stuffs pointers to NSSCKMDSlot objects into
  150. * the specified array; one for each slot supported by this
  151. * instance. The Framework will determine the size needed
  152. * for the array by calling GetNSlots. This routine is
  153. * required.
  154. */
  155. CK_RV(PR_CALLBACK *GetSlots)
  156. (
  157. NSSCKMDInstance *mdInstance,
  158. NSSCKFWInstance *fwInstance,
  159. NSSCKMDSlot *slots[]);
  160. /*
  161. * This call returns a pointer to the slot in which an event
  162. * has occurred. If the block argument is CK_TRUE, the call
  163. * should block until a slot event occurs; if CK_FALSE, it
  164. * should check to see if an event has occurred, occurred,
  165. * but return NULL (and set *pError to CK_NO_EVENT) if one
  166. * hasn't. This routine is optional; if unimplemented, the
  167. * Framework will assume that no event has happened. This
  168. * routine may return NULL upon error.
  169. */
  170. NSSCKMDSlot *(PR_CALLBACK *WaitForSlotEvent)(
  171. NSSCKMDInstance *mdInstance,
  172. NSSCKFWInstance *fwInstance,
  173. CK_BBOOL block,
  174. CK_RV *pError);
  175. /*
  176. * This object may be extended in future versions of the
  177. * NSS Cryptoki Framework. To allow for some flexibility
  178. * in the area of binary compatibility, this field should
  179. * be NULL.
  180. */
  181. void *null;
  182. };
  183. /*
  184. * NSSCKMDSlot
  185. *
  186. * This is the basic handle for a PKCS#11 Module Slot. It is
  187. * created by the NSSCKMDInstance->GetSlots call, and may be
  188. * obtained from the Framework's corresponding NSSCKFWSlot
  189. * object. It contains a pointer for use by the Module, to
  190. * store any slot-related data, and it contains the EPV for
  191. * a set of routines which the Module may implement for use
  192. * by the Framework. Some of these routines are optional.
  193. */
  194. struct NSSCKMDSlotStr {
  195. /*
  196. * The Module may use this pointer for its own purposes.
  197. */
  198. void *etc;
  199. /*
  200. * This routine is called during the Framework initialization
  201. * step, after the Framework Instance has obtained the list
  202. * of slots (by calling NSSCKMDInstance->GetSlots). Any slot-
  203. * specific initialization can be done here. This routine is
  204. * optional; if unimplemented, it won't be called. Note that
  205. * if this routine returns an error, the entire Framework
  206. * initialization for this Module will fail.
  207. */
  208. CK_RV(PR_CALLBACK *Initialize)
  209. (
  210. NSSCKMDSlot *mdSlot,
  211. NSSCKFWSlot *fwSlot,
  212. NSSCKMDInstance *mdInstance,
  213. NSSCKFWInstance *fwInstance);
  214. /*
  215. * This routine is called when the Framework is finalizing
  216. * the PKCS#11 Module. This call (for each of the slots)
  217. * is the last thing called before NSSCKMDInstance->Finalize.
  218. * This routine is optional; if unimplemented, it merely
  219. * won't be called. Note: In the rare circumstance that
  220. * the Framework initialization cannot complete (due to,
  221. * for example, memory limitations), this can be called with
  222. * a NULL value for fwSlot.
  223. */
  224. void(PR_CALLBACK *Destroy)(
  225. NSSCKMDSlot *mdSlot,
  226. NSSCKFWSlot *fwSlot,
  227. NSSCKMDInstance *mdInstance,
  228. NSSCKFWInstance *fwInstance);
  229. /*
  230. * This routine returns a pointer to a UTF8-encoded string
  231. * containing a description of this slot. Only the characters
  232. * completely encoded in the first sixty-four bytes are
  233. * significant. This routine is optional. The string
  234. * returned is never freed; if dynamically generated,
  235. * the space for it should be allocated from the NSSArena
  236. * that may be obtained from the NSSCKFWInstance. This
  237. * routine may return NULL upon error; however if *pError
  238. * is CKR_OK, the NULL will be considered the valid response.
  239. */
  240. NSSUTF8 *(PR_CALLBACK *GetSlotDescription)(
  241. NSSCKMDSlot *mdSlot,
  242. NSSCKFWSlot *fwSlot,
  243. NSSCKMDInstance *mdInstance,
  244. NSSCKFWInstance *fwInstance,
  245. CK_RV *pError);
  246. /*
  247. * This routine returns a pointer to a UTF8-encoded string
  248. * containing a description of the manufacturer of this slot.
  249. * Only the characters completely encoded in the first thirty-
  250. * two bytes are significant. This routine is optional.
  251. * The string returned is never freed; if dynamically generated,
  252. * the space for it should be allocated from the NSSArena
  253. * that may be obtained from the NSSCKFWInstance. This
  254. * routine may return NULL upon error; however if *pError
  255. * is CKR_OK, the NULL will be considered the valid response.
  256. */
  257. NSSUTF8 *(PR_CALLBACK *GetManufacturerID)(
  258. NSSCKMDSlot *mdSlot,
  259. NSSCKFWSlot *fwSlot,
  260. NSSCKMDInstance *mdInstance,
  261. NSSCKFWInstance *fwInstance,
  262. CK_RV *pError);
  263. /*
  264. * This routine returns CK_TRUE if a token is present in this
  265. * slot. This routine is optional; if unimplemented, CK_TRUE
  266. * is assumed.
  267. */
  268. CK_BBOOL(PR_CALLBACK *GetTokenPresent)
  269. (
  270. NSSCKMDSlot *mdSlot,
  271. NSSCKFWSlot *fwSlot,
  272. NSSCKMDInstance *mdInstance,
  273. NSSCKFWInstance *fwInstance);
  274. /*
  275. * This routine returns CK_TRUE if the slot supports removable
  276. * tokens. This routine is optional; if unimplemented, CK_FALSE
  277. * is assumed.
  278. */
  279. CK_BBOOL(PR_CALLBACK *GetRemovableDevice)
  280. (
  281. NSSCKMDSlot *mdSlot,
  282. NSSCKFWSlot *fwSlot,
  283. NSSCKMDInstance *mdInstance,
  284. NSSCKFWInstance *fwInstance);
  285. /*
  286. * This routine returns CK_TRUE if this slot is a hardware
  287. * device, or CK_FALSE if this slot is a software device. This
  288. * routine is optional; if unimplemented, CK_FALSE is assumed.
  289. */
  290. CK_BBOOL(PR_CALLBACK *GetHardwareSlot)
  291. (
  292. NSSCKMDSlot *mdSlot,
  293. NSSCKFWSlot *fwSlot,
  294. NSSCKMDInstance *mdInstance,
  295. NSSCKFWInstance *fwInstance);
  296. /*
  297. * This routine returns the version of this slot's hardware.
  298. * This routine is optional; if unimplemented, the Framework
  299. * will assume a hardware version of 0.1.
  300. */
  301. CK_VERSION(PR_CALLBACK *GetHardwareVersion)
  302. (
  303. NSSCKMDSlot *mdSlot,
  304. NSSCKFWSlot *fwSlot,
  305. NSSCKMDInstance *mdInstance,
  306. NSSCKFWInstance *fwInstance);
  307. /*
  308. * This routine returns the version of this slot's firmware.
  309. * This routine is optional; if unimplemented, the Framework
  310. * will assume a hardware version of 0.1.
  311. */
  312. CK_VERSION(PR_CALLBACK *GetFirmwareVersion)
  313. (
  314. NSSCKMDSlot *mdSlot,
  315. NSSCKFWSlot *fwSlot,
  316. NSSCKMDInstance *mdInstance,
  317. NSSCKFWInstance *fwInstance);
  318. /*
  319. * This routine should return a pointer to an NSSCKMDToken
  320. * object corresponding to the token in the specified slot.
  321. * The NSSCKFWToken object passed in has an NSSArena
  322. * available which is dedicated for this token. This routine
  323. * must be implemented. This routine may return NULL upon
  324. * error.
  325. */
  326. NSSCKMDToken *(PR_CALLBACK *GetToken)(
  327. NSSCKMDSlot *mdSlot,
  328. NSSCKFWSlot *fwSlot,
  329. NSSCKMDInstance *mdInstance,
  330. NSSCKFWInstance *fwInstance,
  331. CK_RV *pError);
  332. /*
  333. * This object may be extended in future versions of the
  334. * NSS Cryptoki Framework. To allow for some flexibility
  335. * in the area of binary compatibility, this field should
  336. * be NULL.
  337. */
  338. void *null;
  339. };
  340. /*
  341. * NSSCKMDToken
  342. *
  343. * This is the basic handle for a PKCS#11 Token. It is created by
  344. * the NSSCKMDSlot->GetToken call, and may be obtained from the
  345. * Framework's corresponding NSSCKFWToken object. It contains a
  346. * pointer for use by the Module, to store any token-related
  347. * data, and it contains the EPV for a set of routines which the
  348. * Module may implement for use by the Framework. Some of these
  349. * routines are optional.
  350. */
  351. struct NSSCKMDTokenStr {
  352. /*
  353. * The Module may use this pointer for its own purposes.
  354. */
  355. void *etc;
  356. /*
  357. * This routine is used to prepare a Module token object for
  358. * use. It is called after the NSSCKMDToken object is obtained
  359. * from NSSCKMDSlot->GetToken. It is named "Setup" here because
  360. * Cryptoki already defines "InitToken" to do the process of
  361. * wiping out any existing state on a token and preparing it for
  362. * a new use. This routine is optional; if unimplemented, it
  363. * merely won't be called.
  364. */
  365. CK_RV(PR_CALLBACK *Setup)
  366. (
  367. NSSCKMDToken *mdToken,
  368. NSSCKFWToken *fwToken,
  369. NSSCKMDInstance *mdInstance,
  370. NSSCKFWInstance *fwInstance);
  371. /*
  372. * This routine is called by the Framework whenever it notices
  373. * that the token object is invalid. (Typically this is when a
  374. * routine indicates an error such as CKR_DEVICE_REMOVED). This
  375. * call is the last thing called before the NSSArena in the
  376. * corresponding NSSCKFWToken is destroyed. This routine is
  377. * optional; if unimplemented, it merely won't be called.
  378. */
  379. void(PR_CALLBACK *Invalidate)(
  380. NSSCKMDToken *mdToken,
  381. NSSCKFWToken *fwToken,
  382. NSSCKMDInstance *mdInstance,
  383. NSSCKFWInstance *fwInstance);
  384. /*
  385. * This routine initialises the token in the specified slot.
  386. * This routine is optional; if unimplemented, the Framework
  387. * will fail this operation with an error of CKR_DEVICE_ERROR.
  388. */
  389. CK_RV(PR_CALLBACK *InitToken)
  390. (
  391. NSSCKMDToken *mdToken,
  392. NSSCKFWToken *fwToken,
  393. NSSCKMDInstance *mdInstance,
  394. NSSCKFWInstance *fwInstance,
  395. NSSItem *pin,
  396. NSSUTF8 *label);
  397. /*
  398. * This routine returns a pointer to a UTF8-encoded string
  399. * containing this token's label. Only the characters
  400. * completely encoded in the first thirty-two bytes are
  401. * significant. This routine is optional. The string
  402. * returned is never freed; if dynamically generated,
  403. * the space for it should be allocated from the NSSArena
  404. * that may be obtained from the NSSCKFWInstance. This
  405. * routine may return NULL upon error; however if *pError
  406. * is CKR_OK, the NULL will be considered the valid response.
  407. */
  408. NSSUTF8 *(PR_CALLBACK *GetLabel)(
  409. NSSCKMDToken *mdToken,
  410. NSSCKFWToken *fwToken,
  411. NSSCKMDInstance *mdInstance,
  412. NSSCKFWInstance *fwInstance,
  413. CK_RV *pError);
  414. /*
  415. * This routine returns a pointer to a UTF8-encoded string
  416. * containing this token's manufacturer ID. Only the characters
  417. * completely encoded in the first thirty-two bytes are
  418. * significant. This routine is optional. The string
  419. * returned is never freed; if dynamically generated,
  420. * the space for it should be allocated from the NSSArena
  421. * that may be obtained from the NSSCKFWInstance. This
  422. * routine may return NULL upon error; however if *pError
  423. * is CKR_OK, the NULL will be considered the valid response.
  424. */
  425. NSSUTF8 *(PR_CALLBACK *GetManufacturerID)(
  426. NSSCKMDToken *mdToken,
  427. NSSCKFWToken *fwToken,
  428. NSSCKMDInstance *mdInstance,
  429. NSSCKFWInstance *fwInstance,
  430. CK_RV *pError);
  431. /*
  432. * This routine returns a pointer to a UTF8-encoded string
  433. * containing this token's model name. Only the characters
  434. * completely encoded in the first thirty-two bytes are
  435. * significant. This routine is optional. The string
  436. * returned is never freed; if dynamically generated,
  437. * the space for it should be allocated from the NSSArena
  438. * that may be obtained from the NSSCKFWInstance. This
  439. * routine may return NULL upon error; however if *pError
  440. * is CKR_OK, the NULL will be considered the valid response.
  441. */
  442. NSSUTF8 *(PR_CALLBACK *GetModel)(
  443. NSSCKMDToken *mdToken,
  444. NSSCKFWToken *fwToken,
  445. NSSCKMDInstance *mdInstance,
  446. NSSCKFWInstance *fwInstance,
  447. CK_RV *pError);
  448. /*
  449. * This routine returns a pointer to a UTF8-encoded string
  450. * containing this token's serial number. Only the characters
  451. * completely encoded in the first thirty-two bytes are
  452. * significant. This routine is optional. The string
  453. * returned is never freed; if dynamically generated,
  454. * the space for it should be allocated from the NSSArena
  455. * that may be obtained from the NSSCKFWInstance. This
  456. * routine may return NULL upon error; however if *pError
  457. * is CKR_OK, the NULL will be considered the valid response.
  458. */
  459. NSSUTF8 *(PR_CALLBACK *GetSerialNumber)(
  460. NSSCKMDToken *mdToken,
  461. NSSCKFWToken *fwToken,
  462. NSSCKMDInstance *mdInstance,
  463. NSSCKFWInstance *fwInstance,
  464. CK_RV *pError);
  465. /*
  466. * This routine returns CK_TRUE if the token has its own
  467. * random number generator. This routine is optional; if
  468. * unimplemented, CK_FALSE is assumed.
  469. */
  470. CK_BBOOL(PR_CALLBACK *GetHasRNG)
  471. (
  472. NSSCKMDToken *mdToken,
  473. NSSCKFWToken *fwToken,
  474. NSSCKMDInstance *mdInstance,
  475. NSSCKFWInstance *fwInstance);
  476. /*
  477. * This routine returns CK_TRUE if this token is write-protected.
  478. * This routine is optional; if unimplemented, CK_FALSE is
  479. * assumed.
  480. */
  481. CK_BBOOL(PR_CALLBACK *GetIsWriteProtected)
  482. (
  483. NSSCKMDToken *mdToken,
  484. NSSCKFWToken *fwToken,
  485. NSSCKMDInstance *mdInstance,
  486. NSSCKFWInstance *fwInstance);
  487. /*
  488. * This routine returns CK_TRUE if this token requires a login.
  489. * This routine is optional; if unimplemented, CK_FALSE is
  490. * assumed.
  491. */
  492. CK_BBOOL(PR_CALLBACK *GetLoginRequired)
  493. (
  494. NSSCKMDToken *mdToken,
  495. NSSCKFWToken *fwToken,
  496. NSSCKMDInstance *mdInstance,
  497. NSSCKFWInstance *fwInstance);
  498. /*
  499. * This routine returns CK_TRUE if the normal user's PIN on this
  500. * token has been initialised. This routine is optional; if
  501. * unimplemented, CK_FALSE is assumed.
  502. */
  503. CK_BBOOL(PR_CALLBACK *GetUserPinInitialized)
  504. (
  505. NSSCKMDToken *mdToken,
  506. NSSCKFWToken *fwToken,
  507. NSSCKMDInstance *mdInstance,
  508. NSSCKFWInstance *fwInstance);
  509. /*
  510. * This routine returns CK_TRUE if a successful save of a
  511. * session's cryptographic operations state ~always~ contains
  512. * all keys needed to restore the state of the session. This
  513. * routine is optional; if unimplemented, CK_FALSE is assumed.
  514. */
  515. CK_BBOOL(PR_CALLBACK *GetRestoreKeyNotNeeded)
  516. (
  517. NSSCKMDToken *mdToken,
  518. NSSCKFWToken *fwToken,
  519. NSSCKMDInstance *mdInstance,
  520. NSSCKFWInstance *fwInstance);
  521. /*
  522. * This routine returns CK_TRUE if the token has its own
  523. * hardware clock. This routine is optional; if unimplemented,
  524. * CK_FALSE is assumed.
  525. */
  526. CK_BBOOL(PR_CALLBACK *GetHasClockOnToken)
  527. (
  528. NSSCKMDToken *mdToken,
  529. NSSCKFWToken *fwToken,
  530. NSSCKMDInstance *mdInstance,
  531. NSSCKFWInstance *fwInstance);
  532. /*
  533. * This routine returns CK_TRUE if the token has a protected
  534. * authentication path. This routine is optional; if
  535. * unimplemented, CK_FALSE is assumed.
  536. */
  537. CK_BBOOL(PR_CALLBACK *GetHasProtectedAuthenticationPath)
  538. (
  539. NSSCKMDToken *mdToken,
  540. NSSCKFWToken *fwToken,
  541. NSSCKMDInstance *mdInstance,
  542. NSSCKFWInstance *fwInstance);
  543. /*
  544. * This routine returns CK_TRUE if the token supports dual
  545. * cryptographic operations within a single session. This
  546. * routine is optional; if unimplemented, CK_FALSE is assumed.
  547. */
  548. CK_BBOOL(PR_CALLBACK *GetSupportsDualCryptoOperations)
  549. (
  550. NSSCKMDToken *mdToken,
  551. NSSCKFWToken *fwToken,
  552. NSSCKMDInstance *mdInstance,
  553. NSSCKFWInstance *fwInstance);
  554. /*
  555. * XXX fgmr-- should we have a call to return all the flags
  556. * at once, for folks who already know about Cryptoki?
  557. */
  558. /*
  559. * This routine returns the maximum number of sessions that
  560. * may be opened on this token. This routine is optional;
  561. * if unimplemented, the special value CK_UNAVAILABLE_INFORMATION
  562. * is assumed. XXX fgmr-- or CK_EFFECTIVELY_INFINITE?
  563. */
  564. CK_ULONG(PR_CALLBACK *GetMaxSessionCount)
  565. (
  566. NSSCKMDToken *mdToken,
  567. NSSCKFWToken *fwToken,
  568. NSSCKMDInstance *mdInstance,
  569. NSSCKFWInstance *fwInstance);
  570. /*
  571. * This routine returns the maximum number of read/write
  572. * sesisons that may be opened on this token. This routine
  573. * is optional; if unimplemented, the special value
  574. * CK_UNAVAILABLE_INFORMATION is assumed. XXX fgmr-- or
  575. * CK_EFFECTIVELY_INFINITE?
  576. */
  577. CK_ULONG(PR_CALLBACK *GetMaxRwSessionCount)
  578. (
  579. NSSCKMDToken *mdToken,
  580. NSSCKFWToken *fwToken,
  581. NSSCKMDInstance *mdInstance,
  582. NSSCKFWInstance *fwInstance);
  583. /*
  584. * This routine returns the maximum PIN code length that is
  585. * supported on this token. This routine is optional;
  586. * if unimplemented, the special value CK_UNAVAILABLE_INFORMATION
  587. * is assumed.
  588. */
  589. CK_ULONG(PR_CALLBACK *GetMaxPinLen)
  590. (
  591. NSSCKMDToken *mdToken,
  592. NSSCKFWToken *fwToken,
  593. NSSCKMDInstance *mdInstance,
  594. NSSCKFWInstance *fwInstance);
  595. /*
  596. * This routine returns the minimum PIN code length that is
  597. * supported on this token. This routine is optional; if
  598. * unimplemented, the special value CK_UNAVAILABLE_INFORMATION
  599. * is assumed. XXX fgmr-- or 0?
  600. */
  601. CK_ULONG(PR_CALLBACK *GetMinPinLen)
  602. (
  603. NSSCKMDToken *mdToken,
  604. NSSCKFWToken *fwToken,
  605. NSSCKMDInstance *mdInstance,
  606. NSSCKFWInstance *fwInstance);
  607. /*
  608. * This routine returns the total amount of memory on the token
  609. * in which public objects may be stored. This routine is
  610. * optional; if unimplemented, the special value
  611. * CK_UNAVAILABLE_INFORMATION is assumed.
  612. */
  613. CK_ULONG(PR_CALLBACK *GetTotalPublicMemory)
  614. (
  615. NSSCKMDToken *mdToken,
  616. NSSCKFWToken *fwToken,
  617. NSSCKMDInstance *mdInstance,
  618. NSSCKFWInstance *fwInstance);
  619. /*
  620. * This routine returns the amount of unused memory on the
  621. * token in which public objects may be stored. This routine
  622. * is optional; if unimplemented, the special value
  623. * CK_UNAVAILABLE_INFORMATION is assumed.
  624. */
  625. CK_ULONG(PR_CALLBACK *GetFreePublicMemory)
  626. (
  627. NSSCKMDToken *mdToken,
  628. NSSCKFWToken *fwToken,
  629. NSSCKMDInstance *mdInstance,
  630. NSSCKFWInstance *fwInstance);
  631. /*
  632. * This routine returns the total amount of memory on the token
  633. * in which private objects may be stored. This routine is
  634. * optional; if unimplemented, the special value
  635. * CK_UNAVAILABLE_INFORMATION is assumed.
  636. */
  637. CK_ULONG(PR_CALLBACK *GetTotalPrivateMemory)
  638. (
  639. NSSCKMDToken *mdToken,
  640. NSSCKFWToken *fwToken,
  641. NSSCKMDInstance *mdInstance,
  642. NSSCKFWInstance *fwInstance);
  643. /*
  644. * This routine returns the amount of unused memory on the
  645. * token in which private objects may be stored. This routine
  646. * is optional; if unimplemented, the special value
  647. * CK_UNAVAILABLE_INFORMATION is assumed.
  648. */
  649. CK_ULONG(PR_CALLBACK *GetFreePrivateMemory)
  650. (
  651. NSSCKMDToken *mdToken,
  652. NSSCKFWToken *fwToken,
  653. NSSCKMDInstance *mdInstance,
  654. NSSCKFWInstance *fwInstance);
  655. /*
  656. * This routine returns the version number of this token's
  657. * hardware. This routine is optional; if unimplemented,
  658. * the value 0.1 is assumed.
  659. */
  660. CK_VERSION(PR_CALLBACK *GetHardwareVersion)
  661. (
  662. NSSCKMDToken *mdToken,
  663. NSSCKFWToken *fwToken,
  664. NSSCKMDInstance *mdInstance,
  665. NSSCKFWInstance *fwInstance);
  666. /*
  667. * This routine returns the version number of this token's
  668. * firmware. This routine is optional; if unimplemented,
  669. * the value 0.1 is assumed.
  670. */
  671. CK_VERSION(PR_CALLBACK *GetFirmwareVersion)
  672. (
  673. NSSCKMDToken *mdToken,
  674. NSSCKFWToken *fwToken,
  675. NSSCKMDInstance *mdInstance,
  676. NSSCKFWInstance *fwInstance);
  677. /*
  678. * This routine stuffs the current UTC time, as obtained from
  679. * the token, into the sixteen-byte buffer in the form
  680. * YYYYMMDDhhmmss00. This routine need only be implemented
  681. * by token which indicate that they have a real-time clock.
  682. * XXX fgmr-- think about time formats.
  683. */
  684. CK_RV(PR_CALLBACK *GetUTCTime)
  685. (
  686. NSSCKMDToken *mdToken,
  687. NSSCKFWToken *fwToken,
  688. NSSCKMDInstance *mdInstance,
  689. NSSCKFWInstance *fwInstance,
  690. CK_CHAR utcTime[16]);
  691. /*
  692. * This routine creates a session on the token, and returns
  693. * the corresponding NSSCKMDSession object. The value of
  694. * rw will be CK_TRUE if the session is to be a read/write
  695. * session, or CK_FALSE otherwise. An NSSArena dedicated to
  696. * the new session is available from the specified NSSCKFWSession.
  697. * This routine may return NULL upon error.
  698. */
  699. NSSCKMDSession *(PR_CALLBACK *OpenSession)(
  700. NSSCKMDToken *mdToken,
  701. NSSCKFWToken *fwToken,
  702. NSSCKMDInstance *mdInstance,
  703. NSSCKFWInstance *fwInstance,
  704. NSSCKFWSession *fwSession,
  705. CK_BBOOL rw,
  706. CK_RV *pError);
  707. /*
  708. * This routine returns the number of PKCS#11 Mechanisms
  709. * supported by this token. This routine is optional; if
  710. * unimplemented, zero is assumed.
  711. */
  712. CK_ULONG(PR_CALLBACK *GetMechanismCount)
  713. (
  714. NSSCKMDToken *mdToken,
  715. NSSCKFWToken *fwToken,
  716. NSSCKMDInstance *mdInstance,
  717. NSSCKFWInstance *fwInstance);
  718. /*
  719. * This routine stuffs into the specified array the types
  720. * of the mechanisms supported by this token. The Framework
  721. * determines the size of the array by calling GetMechanismCount.
  722. */
  723. CK_RV(PR_CALLBACK *GetMechanismTypes)
  724. (
  725. NSSCKMDToken *mdToken,
  726. NSSCKFWToken *fwToken,
  727. NSSCKMDInstance *mdInstance,
  728. NSSCKFWInstance *fwInstance,
  729. CK_MECHANISM_TYPE types[]);
  730. /*
  731. * This routine returns a pointer to a Module mechanism
  732. * object corresponding to a specified type. This routine
  733. * need only exist for tokens implementing at least one
  734. * mechanism.
  735. */
  736. NSSCKMDMechanism *(PR_CALLBACK *GetMechanism)(
  737. NSSCKMDToken *mdToken,
  738. NSSCKFWToken *fwToken,
  739. NSSCKMDInstance *mdInstance,
  740. NSSCKFWInstance *fwInstance,
  741. CK_MECHANISM_TYPE which,
  742. CK_RV *pError);
  743. /*
  744. * This object may be extended in future versions of the
  745. * NSS Cryptoki Framework. To allow for some flexibility
  746. * in the area of binary compatibility, this field should
  747. * be NULL.
  748. */
  749. void *null;
  750. };
  751. /*
  752. * NSSCKMDSession
  753. *
  754. * This is the basic handle for a session on a PKCS#11 Token. It
  755. * is created by NSSCKMDToken->OpenSession, and may be obtained
  756. * from the Framework's corresponding NSSCKFWSession object. It
  757. * contains a pointer for use by the Module, to store any session-
  758. * realted data, and it contains the EPV for a set of routines
  759. * which the Module may implement for use by the Framework. Some
  760. * of these routines are optional.
  761. */
  762. struct NSSCKMDSessionStr {
  763. /*
  764. * The Module may use this pointer for its own purposes.
  765. */
  766. void *etc;
  767. /*
  768. * This routine is called by the Framework when a session is
  769. * closed. This call is the last thing called before the
  770. * NSSArena in the correspoinding NSSCKFWSession is destroyed.
  771. * This routine is optional; if unimplemented, it merely won't
  772. * be called.
  773. */
  774. void(PR_CALLBACK *Close)(
  775. NSSCKMDSession *mdSession,
  776. NSSCKFWSession *fwSession,
  777. NSSCKMDToken *mdToken,
  778. NSSCKFWToken *fwToken,
  779. NSSCKMDInstance *mdInstance,
  780. NSSCKFWInstance *fwInstance);
  781. /*
  782. * This routine is used to get any device-specific error.
  783. * This routine is optional.
  784. */
  785. CK_ULONG(PR_CALLBACK *GetDeviceError)
  786. (
  787. NSSCKMDSession *mdSession,
  788. NSSCKFWSession *fwSession,
  789. NSSCKMDToken *mdToken,
  790. NSSCKFWToken *fwToken,
  791. NSSCKMDInstance *mdInstance,
  792. NSSCKFWInstance *fwInstance);
  793. /*
  794. * This routine is used to log in a user to the token. This
  795. * routine is optional, since the Framework's NSSCKFWSession
  796. * object keeps track of the login state.
  797. */
  798. CK_RV(PR_CALLBACK *Login)
  799. (
  800. NSSCKMDSession *mdSession,
  801. NSSCKFWSession *fwSession,
  802. NSSCKMDToken *mdToken,
  803. NSSCKFWToken *fwToken,
  804. NSSCKMDInstance *mdInstance,
  805. NSSCKFWInstance *fwInstance,
  806. CK_USER_TYPE userType,
  807. NSSItem *pin,
  808. CK_STATE oldState,
  809. CK_STATE newState);
  810. /*
  811. * This routine is used to log out a user from the token. This
  812. * routine is optional, since the Framework's NSSCKFWSession
  813. * object keeps track of the login state.
  814. */
  815. CK_RV(PR_CALLBACK *Logout)
  816. (
  817. NSSCKMDSession *mdSession,
  818. NSSCKFWSession *fwSession,
  819. NSSCKMDToken *mdToken,
  820. NSSCKFWToken *fwToken,
  821. NSSCKMDInstance *mdInstance,
  822. NSSCKFWInstance *fwInstance,
  823. CK_STATE oldState,
  824. CK_STATE newState);
  825. /*
  826. * This routine is used to initialize the normal user's PIN or
  827. * password. This will only be called in the "read/write
  828. * security officer functions" state. If this token has a
  829. * protected authentication path, then the pin argument will
  830. * be NULL. This routine is optional; if unimplemented, the
  831. * Framework will return the error CKR_TOKEN_WRITE_PROTECTED.
  832. */
  833. CK_RV(PR_CALLBACK *InitPIN)
  834. (
  835. NSSCKMDSession *mdSession,
  836. NSSCKFWSession *fwSession,
  837. NSSCKMDToken *mdToken,
  838. NSSCKFWToken *fwToken,
  839. NSSCKMDInstance *mdInstance,
  840. NSSCKFWInstance *fwInstance,
  841. NSSItem *pin);
  842. /*
  843. * This routine is used to modify a user's PIN or password. This
  844. * routine will only be called in the "read/write security officer
  845. * functions" or "read/write user functions" state. If this token
  846. * has a protected authentication path, then the pin arguments
  847. * will be NULL. This routine is optional; if unimplemented, the
  848. * Framework will return the error CKR_TOKEN_WRITE_PROTECTED.
  849. */
  850. CK_RV(PR_CALLBACK *SetPIN)
  851. (
  852. NSSCKMDSession *mdSession,
  853. NSSCKFWSession *fwSession,
  854. NSSCKMDToken *mdToken,
  855. NSSCKFWToken *fwToken,
  856. NSSCKMDInstance *mdInstance,
  857. NSSCKFWInstance *fwInstance,
  858. NSSItem *oldPin,
  859. NSSItem *newPin);
  860. /*
  861. * This routine is used to find out how much space would be required
  862. * to save the current operational state. This routine is optional;
  863. * if unimplemented, the Framework will reject any attempts to save
  864. * the operational state with the error CKR_STATE_UNSAVEABLE. This
  865. * routine may return zero on error.
  866. */
  867. CK_ULONG(PR_CALLBACK *GetOperationStateLen)
  868. (
  869. NSSCKMDSession *mdSession,
  870. NSSCKFWSession *fwSession,
  871. NSSCKMDToken *mdToken,
  872. NSSCKFWToken *fwToken,
  873. NSSCKMDInstance *mdInstance,
  874. NSSCKFWInstance *fwInstance,
  875. CK_RV *pError);
  876. /*
  877. * This routine is used to store the current operational state. This
  878. * routine is only required if GetOperationStateLen is implemented
  879. * and can return a nonzero value. The buffer in the specified item
  880. * will be pre-allocated, and the length will specify the amount of
  881. * space available (which may be more than GetOperationStateLen
  882. * asked for, but which will not be smaller).
  883. */
  884. CK_RV(PR_CALLBACK *GetOperationState)
  885. (
  886. NSSCKMDSession *mdSession,
  887. NSSCKFWSession *fwSession,
  888. NSSCKMDToken *mdToken,
  889. NSSCKFWToken *fwToken,
  890. NSSCKMDInstance *mdInstance,
  891. NSSCKFWInstance *fwInstance,
  892. NSSItem *buffer);
  893. /*
  894. * This routine is used to restore an operational state previously
  895. * obtained with GetOperationState. The Framework will take pains
  896. * to be sure that the state is (or was at one point) valid; if the
  897. * Module notices that the state is invalid, it should return an
  898. * error, but it is not required to be paranoid about the issue.
  899. * [XXX fgmr-- should (can?) the framework verify the keys match up?]
  900. * This routine is required only if GetOperationState is implemented.
  901. */
  902. CK_RV(PR_CALLBACK *SetOperationState)
  903. (
  904. NSSCKMDSession *mdSession,
  905. NSSCKFWSession *fwSession,
  906. NSSCKMDToken *mdToken,
  907. NSSCKFWToken *fwToken,
  908. NSSCKMDInstance *mdInstance,
  909. NSSCKFWInstance *fwInstance,
  910. NSSItem *state,
  911. NSSCKMDObject *mdEncryptionKey,
  912. NSSCKFWObject *fwEncryptionKey,
  913. NSSCKMDObject *mdAuthenticationKey,
  914. NSSCKFWObject *fwAuthenticationKey);
  915. /*
  916. * This routine is used to create an object. The specified template
  917. * will only specify a session object if the Module has indicated
  918. * that it wishes to handle its own session objects. This routine
  919. * is optional; if unimplemented, the Framework will reject the
  920. * operation with the error CKR_TOKEN_WRITE_PROTECTED. Space for
  921. * token objects should come from the NSSArena available from the
  922. * NSSCKFWToken object; space for session objects (if supported)
  923. * should come from the NSSArena available from the NSSCKFWSession
  924. * object. The appropriate NSSArena pointer will, as a convenience,
  925. * be passed as the handyArenaPointer argument. This routine may
  926. * return NULL upon error.
  927. */
  928. NSSCKMDObject *(PR_CALLBACK *CreateObject)(
  929. NSSCKMDSession *mdSession,
  930. NSSCKFWSession *fwSession,
  931. NSSCKMDToken *mdToken,
  932. NSSCKFWToken *fwToken,
  933. NSSCKMDInstance *mdInstance,
  934. NSSCKFWInstance *fwInstance,
  935. NSSArena *handyArenaPointer,
  936. CK_ATTRIBUTE_PTR pTemplate,
  937. CK_ULONG ulAttributeCount,
  938. CK_RV *pError);
  939. /*
  940. * This routine is used to make a copy of an object. It is entirely
  941. * optional; if unimplemented, the Framework will try to use
  942. * CreateObject instead. If the Module has indicated that it does
  943. * not wish to handle session objects, then this routine will only
  944. * be called to copy a token object to another token object.
  945. * Otherwise, either the original object or the new may be of
  946. * either the token or session variety. As with CreateObject, the
  947. * handyArenaPointer will point to the appropriate arena for the
  948. * new object. This routine may return NULL upon error.
  949. */
  950. NSSCKMDObject *(PR_CALLBACK *CopyObject)(
  951. NSSCKMDSession *mdSession,
  952. NSSCKFWSession *fwSession,
  953. NSSCKMDToken *mdToken,
  954. NSSCKFWToken *fwToken,
  955. NSSCKMDInstance *mdInstance,
  956. NSSCKFWInstance *fwInstance,
  957. NSSCKMDObject *mdOldObject,
  958. NSSCKFWObject *fwOldObject,
  959. NSSArena *handyArenaPointer,
  960. CK_ATTRIBUTE_PTR pTemplate,
  961. CK_ULONG ulAttributeCount,
  962. CK_RV *pError);
  963. /*
  964. * This routine is used to begin an object search. This routine may
  965. * be unimplemented only if the Module does not handle session
  966. * objects, and if none of its tokens have token objects. The
  967. * NSSCKFWFindObjects pointer has an NSSArena that may be used for
  968. * storage for the life of this "find" operation. This routine may
  969. * return NULL upon error. If the Module can determine immediately
  970. * that the search will not find any matching objects, it may return
  971. * NULL, and specify CKR_OK as the error.
  972. */
  973. NSSCKMDFindObjects *(PR_CALLBACK *FindObjectsInit)(
  974. NSSCKMDSession *mdSession,
  975. NSSCKFWSession *fwSession,
  976. NSSCKMDToken *mdToken,
  977. NSSCKFWToken *fwToken,
  978. NSSCKMDInstance *mdInstance,
  979. NSSCKFWInstance *fwInstance,
  980. CK_ATTRIBUTE_PTR pTemplate,
  981. CK_ULONG ulAttributeCount,
  982. CK_RV *pError);
  983. /*
  984. * This routine seeds the random-number generator. It is
  985. * optional, even if GetRandom is implemented. If unimplemented,
  986. * the Framework will issue the error CKR_RANDOM_SEED_NOT_SUPPORTED.
  987. */
  988. CK_RV(PR_CALLBACK *SeedRandom)
  989. (
  990. NSSCKMDSession *mdSession,
  991. NSSCKFWSession *fwSession,
  992. NSSCKMDToken *mdToken,
  993. NSSCKFWToken *fwToken,
  994. NSSCKMDInstance *mdInstance,
  995. NSSCKFWInstance *fwInstance,
  996. NSSItem *seed);
  997. /*
  998. * This routine gets random data. It is optional. If unimplemented,
  999. * the Framework will issue the error CKR_RANDOM_NO_RNG.
  1000. */
  1001. CK_RV(PR_CALLBACK *GetRandom)
  1002. (
  1003. NSSCKMDSession *mdSession,
  1004. NSSCKFWSession *fwSession,
  1005. NSSCKMDToken *mdToken,
  1006. NSSCKFWToken *fwToken,
  1007. NSSCKMDInstance *mdInstance,
  1008. NSSCKFWInstance *fwInstance,
  1009. NSSItem *buffer);
  1010. /*
  1011. * This object may be extended in future versions of the
  1012. * NSS Cryptoki Framework. To allow for some flexibility
  1013. * in the area of binary compatibility, this field should
  1014. * be NULL.
  1015. */
  1016. void *null;
  1017. };
  1018. /*
  1019. * NSSCKMDFindObjects
  1020. *
  1021. * This is the basic handle for an object search. It is
  1022. * created by NSSCKMDSession->FindObjectsInit, and may be
  1023. * obtained from the Framework's corresponding object.
  1024. * It contains a pointer for use by the Module, to store
  1025. * any search-related data, and it contains the EPV for a
  1026. * set of routines which the Module may implement for use
  1027. * by the Framework. Some of these routines are optional.
  1028. */
  1029. struct NSSCKMDFindObjectsStr {
  1030. /*
  1031. * The Module may use this pointer for its own purposes.
  1032. */
  1033. void *etc;
  1034. /*
  1035. * This routine is called by the Framework to finish a
  1036. * search operation. Note that the Framework may finish
  1037. * a search before it has completed. This routine is
  1038. * optional; if unimplemented, it merely won't be called.
  1039. */
  1040. void(PR_CALLBACK *Final)(
  1041. NSSCKMDFindObjects *mdFindObjects,
  1042. NSSCKFWFindObjects *fwFindObjects,
  1043. NSSCKMDSession *mdSession,
  1044. NSSCKFWSession *fwSession,
  1045. NSSCKMDToken *mdToken,
  1046. NSSCKFWToken *fwToken,
  1047. NSSCKMDInstance *mdInstance,
  1048. NSSCKFWInstance *fwInstance);
  1049. /*
  1050. * This routine is used to obtain another pointer to an
  1051. * object matching the search criteria. This routine is
  1052. * required. If no (more) objects match the search, it
  1053. * should return NULL and set the error to CKR_OK.
  1054. */
  1055. NSSCKMDObject *(PR_CALLBACK *Next)(
  1056. NSSCKMDFindObjects *mdFindObjects,
  1057. NSSCKFWFindObjects *fwFindObjects,
  1058. NSSCKMDSession *mdSession,
  1059. NSSCKFWSession *fwSession,
  1060. NSSCKMDToken *mdToken,
  1061. NSSCKFWToken *fwToken,
  1062. NSSCKMDInstance *mdInstance,
  1063. NSSCKFWInstance *fwInstance,
  1064. NSSArena *arena,
  1065. CK_RV *pError);
  1066. /*
  1067. * This object may be extended in future versions of the
  1068. * NSS Cryptoki Framework. To allow for some flexibility
  1069. * in the area of binary compatibility, this field should
  1070. * be NULL.
  1071. */
  1072. void *null;
  1073. };
  1074. /*
  1075. * NSSCKMDCryptoOperaion
  1076. *
  1077. * This is the basic handle for an encryption, decryption,
  1078. * sign, verify, or hash opertion.
  1079. * created by NSSCKMDMechanism->XXXXInit, and may be
  1080. * obtained from the Framework's corresponding object.
  1081. * It contains a pointer for use by the Module, to store
  1082. * any intermediate data, and it contains the EPV for a
  1083. * set of routines which the Module may implement for use
  1084. * by the Framework. Some of these routines are optional.
  1085. */
  1086. struct NSSCKMDCryptoOperationStr {
  1087. /*
  1088. * The Module may use this pointer for its own purposes.
  1089. */
  1090. void *etc;
  1091. /*
  1092. * This routine is called by the Framework clean up the mdCryptoOperation
  1093. * structure.
  1094. * This routine is optional; if unimplemented, it will be ignored.
  1095. */
  1096. void(PR_CALLBACK *Destroy)(
  1097. NSSCKMDCryptoOperation *mdCryptoOperation,
  1098. NSSCKFWCryptoOperation *fwCryptoOperation,
  1099. NSSCKMDInstance *mdInstance,
  1100. NSSCKFWInstance *fwInstance);
  1101. /*
  1102. * how many bytes do we need to finish this buffer?
  1103. * must be implemented if Final is implemented.
  1104. */
  1105. CK_ULONG(PR_CALLBACK *GetFinalLength)
  1106. (
  1107. NSSCKMDCryptoOperation *mdCryptoOperation,
  1108. NSSCKFWCryptoOperation *fwCryptoOperation,
  1109. NSSCKMDSession *mdSession,
  1110. NSSCKFWSession *fwSession,
  1111. NSSCKMDToken *mdToken,
  1112. NSSCKFWToken *fwToken,
  1113. NSSCKMDInstance *mdInstance,
  1114. NSSCKFWInstance *fwInstance,
  1115. CK_RV *pError);
  1116. /*
  1117. * how many bytes do we need to complete the next operation.
  1118. * used in both Update and UpdateFinal.
  1119. */
  1120. CK_ULONG(PR_CALLBACK *GetOperationLength)
  1121. (
  1122. NSSCKMDCryptoOperation *mdCryptoOperation,
  1123. NSSCKFWCryptoOperation *fwCryptoOperation,
  1124. NSSCKMDSession *mdSession,
  1125. NSSCKFWSession *fwSession,
  1126. NSSCKMDToken *mdToken,
  1127. NSSCKFWToken *fwToken,
  1128. NSSCKMDInstance *mdInstance,
  1129. NSSCKFWInstance *fwInstance,
  1130. const NSSItem *inputBuffer,
  1131. CK_RV *pError);
  1132. /*
  1133. * This routine is called by the Framework to finish a
  1134. * search operation. Note that the Framework may finish
  1135. * a search before it has completed. This routine is
  1136. * optional; if unimplemented, it merely won't be called.
  1137. * The respective final call with fail with CKR_FUNCTION_FAILED
  1138. * Final should not free the mdCryptoOperation.
  1139. */
  1140. CK_RV(PR_CALLBACK *Final)
  1141. (
  1142. NSSCKMDCryptoOperation *mdCryptoOperation,
  1143. NSSCKFWCryptoOperation *fwCryptoOperation,
  1144. NSSCKMDSession *mdSession,
  1145. NSSCKFWSession *fwSession,
  1146. NSSCKMDToken *mdToken,
  1147. NSSCKFWToken *fwToken,
  1148. NSSCKMDInstance *mdInstance,
  1149. NSSCKFWInstance *fwInstance,
  1150. NSSItem *outputBuffer);
  1151. /*
  1152. * This routine is called by the Framework to complete the
  1153. * next step in an encryption/decryption operation.
  1154. * This routine is optional; if unimplemented, the respective
  1155. * update call with fail with CKR_FUNCTION_FAILED.
  1156. * Update should not be implemented for signing/verification/digest
  1157. * mechanisms.
  1158. */
  1159. CK_RV(PR_CALLBACK *Update)
  1160. (
  1161. NSSCKMDCryptoOperation *mdCryptoOperation,
  1162. NSSCKFWCryptoOperation *fwCryptoOperation,
  1163. NSSCKMDSession *mdSession,
  1164. NSSCKFWSession *fwSession,
  1165. NSSCKMDToken *mdToken,
  1166. NSSCKFWToken *fwToken,
  1167. NSSCKMDInstance *mdInstance,
  1168. NSSCKFWInstance *fwInstance,
  1169. const NSSItem *inputBuffer,
  1170. NSSItem *outputBuffer);
  1171. /*
  1172. * This routine is called by the Framework to complete the
  1173. * next step in a signing/verification/digest operation.
  1174. * This routine is optional; if unimplemented, the respective
  1175. * update call with fail with CKR_FUNCTION_FAILED
  1176. * Update should not be implemented for encryption/decryption
  1177. * mechanisms.
  1178. */
  1179. CK_RV(PR_CALLBACK *DigestUpdate)
  1180. (
  1181. NSSCKMDCryptoOperation *mdCryptoOperation,
  1182. NSSCKFWCryptoOperation *fwCryptoOperation,
  1183. NSSCKMDSession *mdSession,
  1184. NSSCKFWSession *fwSession,
  1185. NSSCKMDToken *mdToken,
  1186. NSSCKFWToken *fwToken,
  1187. NSSCKMDInstance *mdInstance,
  1188. NSSCKFWInstance *fwInstance,
  1189. const NSSItem *inputBuffer);
  1190. /*
  1191. * This routine is called by the Framework to complete a
  1192. * single step operation. This routine is optional; if unimplemented,
  1193. * the framework will use the Update and Final functions to complete
  1194. * the operation.
  1195. */
  1196. CK_RV(PR_CALLBACK *UpdateFinal)
  1197. (
  1198. NSSCKMDCryptoOperation *mdCryptoOperation,
  1199. NSSCKFWCryptoOperation *fwCryptoOperation,
  1200. NSSCKMDSession *mdSession,
  1201. NSSCKFWSession *fwSession,
  1202. NSSCKMDToken *mdToken,
  1203. NSSCKFWToken *fwToken,
  1204. NSSCKMDInstance *mdInstance,
  1205. NSSCKFWInstance *fwInstance,
  1206. const NSSItem *inputBuffer,
  1207. NSSItem *outputBuffer);
  1208. /*
  1209. * This routine is called by the Framework to complete next
  1210. * step in a combined operation. The Decrypt/Encrypt mechanism
  1211. * should define and drive the combo step.
  1212. * This routine is optional; if unimplemented,
  1213. * the framework will use the appropriate Update functions to complete
  1214. * the operation.
  1215. */
  1216. CK_RV(PR_CALLBACK *UpdateCombo)
  1217. (
  1218. NSSCKMDCryptoOperation *mdCryptoOperation,
  1219. NSSCKFWCryptoOperation *fwCryptoOperation,
  1220. NSSCKMDCryptoOperation *mdPeerCryptoOperation,
  1221. NSSCKFWCryptoOperation *fwPeerCryptoOperation,
  1222. NSSCKMDSession *mdSession,
  1223. NSSCKFWSession *fwSession,
  1224. NSSCKMDToken *mdToken,
  1225. NSSCKFWToken *fwToken,
  1226. NSSCKMDInstance *mdInstance,
  1227. NSSCKFWInstance *fwInstance,
  1228. const NSSItem *inputBuffer,
  1229. NSSItem *outputBuffer);
  1230. /*
  1231. * Hash a key directly into the digest
  1232. */
  1233. CK_RV(PR_CALLBACK *DigestKey)
  1234. (
  1235. NSSCKMDCryptoOperation *mdCryptoOperation,
  1236. NSSCKFWCryptoOperation *fwCryptoOperation,
  1237. NSSCKMDToken *mdToken,
  1238. NSSCKFWToken *fwToken,
  1239. NSSCKMDInstance *mdInstance,
  1240. NSSCKFWInstance *fwInstance,
  1241. NSSCKMDObject *mdKey,
  1242. NSSCKFWObject *fwKey);
  1243. /*
  1244. * This object may be extended in future versions of the
  1245. * NSS Cryptoki Framework. To allow for some flexibility
  1246. * in the area of binary compatibility, this field should
  1247. * be NULL.
  1248. */
  1249. void *null;
  1250. };
  1251. /*
  1252. * NSSCKMDMechanism
  1253. *
  1254. */
  1255. struct NSSCKMDMechanismStr {
  1256. /*
  1257. * The Module may use this pointer for its own purposes.
  1258. */
  1259. void *etc;
  1260. /*
  1261. * This also frees the fwMechanism if appropriate.
  1262. * If it is not supplied, the Framework will assume that the Token
  1263. * Manages a static list of mechanisms and the function will not be called.
  1264. */
  1265. void(PR_CALLBACK *Destroy)(
  1266. NSSCKMDMechanism *mdMechanism,
  1267. NSSCKFWMechanism *fwMechanism,
  1268. NSSCKMDInstance *mdInstance,
  1269. NSSCKFWInstance *fwInstance);
  1270. /*
  1271. * This routine returns the minimum key size allowed for
  1272. * this mechanism. This routine is optional; if unimplemented,
  1273. * zero will be assumed. This routine may return zero on
  1274. * error; if the error is CKR_OK, zero will be accepted as
  1275. * a valid response.
  1276. */
  1277. CK_ULONG(PR_CALLBACK *GetMinKeySize)
  1278. (
  1279. NSSCKMDMechanism *mdMechanism,
  1280. NSSCKFWMechanism *fwMechanism,
  1281. NSSCKMDToken *mdToken,
  1282. NSSCKFWToken *fwToken,
  1283. NSSCKMDInstance *mdInstance,
  1284. NSSCKFWInstance *fwInstance,
  1285. CK_RV *pError);
  1286. /*
  1287. * This routine returns the maximum key size allowed for
  1288. * this mechanism. This routine is optional; if unimplemented,
  1289. * zero will be assumed. This routine may return zero on
  1290. * error; if the error is CKR_OK, zero will be accepted as
  1291. * a valid response.
  1292. */
  1293. CK_ULONG(PR_CALLBACK *GetMaxKeySize)
  1294. (
  1295. NSSCKMDMechanism *mdMechanism,
  1296. NSSCKFWMechanism *fwMechanism,
  1297. NSSCKMDToken *mdToken,
  1298. NSSCKFWToken *fwToken,
  1299. NSSCKMDInstance *mdInstance,
  1300. NSSCKFWInstance *fwInstance,
  1301. CK_RV *pError);
  1302. /*
  1303. * This routine is called to determine if the mechanism is
  1304. * implemented in hardware or software. It returns CK_TRUE
  1305. * if it is done in hardware.
  1306. */
  1307. CK_BBOOL(PR_CALLBACK *GetInHardware)
  1308. (
  1309. NSSCKMDMechanism *mdMechanism,
  1310. NSSCKFWMechanism *fwMechanism,
  1311. NSSCKMDToken *mdToken,
  1312. NSSCKFWToken *fwToken,
  1313. NSSCKMDInstance *mdInstance,
  1314. NSSCKFWInstance *fwInstance,
  1315. CK_RV *pError);
  1316. /*
  1317. * The crypto routines themselves. Most crypto operations may
  1318. * be performed in two ways, streaming and single-part. The
  1319. * streaming operations involve the use of (typically) three
  1320. * calls-- an Init method to set up the operation, an Update
  1321. * method to feed data to the operation, and a Final method to
  1322. * obtain the final result. Single-part operations involve
  1323. * one method, to perform the crypto operation all at once.
  1324. *
  1325. * The NSS Cryptoki Framework can implement the single-part
  1326. * operations in terms of the streaming operations on behalf
  1327. * of the Module. There are a few variances.
  1328. *
  1329. * Only the Init Functions are defined by the mechanism. Each
  1330. * init function will return a NSSCKFWCryptoOperation which
  1331. * can supply update, final, the single part updateFinal, and
  1332. * the combo updateCombo functions.
  1333. *
  1334. * For simplicity, the routines are listed in summary here:
  1335. *
  1336. * EncryptInit,
  1337. * DecryptInit,
  1338. * DigestInit,
  1339. * SignInit,
  1340. * SignRecoverInit;
  1341. * VerifyInit,
  1342. * VerifyRecoverInit;
  1343. *
  1344. * The key-management routines are
  1345. *
  1346. * GenerateKey
  1347. * GenerateKeyPair
  1348. * WrapKey
  1349. * UnwrapKey
  1350. * DeriveKey
  1351. *
  1352. * All of these routines based on the Cryptoki API;
  1353. * see PKCS#11 for further information.
  1354. */
  1355. /*
  1356. */
  1357. NSSCKMDCryptoOperation *(PR_CALLBACK *EncryptInit)(
  1358. NSSCKMDMechanism *mdMechanism,
  1359. NSSCKFWMechanism *fwMechanism,
  1360. CK_MECHANISM_PTR pMechanism,
  1361. NSSCKMDSession *mdSession,
  1362. NSSCKFWSession *fwSession,
  1363. NSSCKMDToken *mdToken,
  1364. NSSCKFWToken *fwToken,
  1365. NSSCKMDInstance *mdInstance,
  1366. NSSCKFWInstance *fwInstance,
  1367. NSSCKMDObject *mdKey,
  1368. NSSCKFWObject *fwKey,
  1369. CK_RV *pError);
  1370. /*
  1371. */
  1372. NSSCKMDCryptoOperation *(PR_CALLBACK *DecryptInit)(
  1373. NSSCKMDMechanism *mdMechanism,
  1374. NSSCKFWMechanism *fwMechanism,
  1375. CK_MECHANISM_PTR pMechanism,
  1376. NSSCKMDSession *mdSession,
  1377. NSSCKFWSession *fwSession,
  1378. NSSCKMDToken *mdToken,
  1379. NSSCKFWToken *fwToken,
  1380. NSSCKMDInstance *mdInstance,
  1381. NSSCKFWInstance *fwInstance,
  1382. NSSCKMDObject *mdKey,
  1383. NSSCKFWObject *fwKey,
  1384. CK_RV *pError);
  1385. /*
  1386. */
  1387. NSSCKMDCryptoOperation *(PR_CALLBACK *DigestInit)(
  1388. NSSCKMDMechanism *mdMechanism,
  1389. NSSCKFWMechanism *fwMechanism,
  1390. CK_MECHANISM_PTR pMechanism,
  1391. NSSCKMDSession *mdSession,
  1392. NSSCKFWSession *fwSession,
  1393. NSSCKMDToken *mdToken,
  1394. NSSCKFWToken *fwToken,
  1395. NSSCKMDInstance *mdInstance,
  1396. NSSCKFWInstance *fwInstance,
  1397. CK_RV *pError);
  1398. /*
  1399. */
  1400. NSSCKMDCryptoOperation *(PR_CALLBACK *SignInit)(
  1401. NSSCKMDMechanism *mdMechanism,
  1402. NSSCKFWMechanism *fwMechanism,
  1403. CK_MECHANISM_PTR pMechanism,
  1404. NSSCKMDSession *mdSession,
  1405. NSSCKFWSession *fwSession,
  1406. NSSCKMDToken *mdToken,
  1407. NSSCKFWToken *fwToken,
  1408. NSSCKMDInstance *mdInstance,
  1409. NSSCKFWInstance *fwInstance,
  1410. NSSCKMDObject *mdKey,
  1411. NSSCKFWObject *fwKey,
  1412. CK_RV *pError);
  1413. /*
  1414. */
  1415. NSSCKMDCryptoOperation *(PR_CALLBACK *VerifyInit)(
  1416. NSSCKMDMechanism *mdMechanism,
  1417. NSSCKFWMechanism *fwMechanism,
  1418. CK_MECHANISM_PTR pMechanism,
  1419. NSSCKMDSession *mdSession,
  1420. NSSCKFWSession *fwSession,
  1421. NSSCKMDToken *mdToken,
  1422. NSSCKFWToken *fwToken,
  1423. NSSCKMDInstance *mdInstance,
  1424. NSSCKFWInstance *fwInstance,
  1425. NSSCKMDObject *mdKey,
  1426. NSSCKFWObject *fwKey,
  1427. CK_RV *pError);
  1428. /*
  1429. */
  1430. NSSCKMDCryptoOperation *(PR_CALLBACK *SignRecoverInit)(
  1431. NSSCKMDMechanism *mdMechanism,
  1432. NSSCKFWMechanism *fwMechanism,
  1433. CK_MECHANISM_PTR pMechanism,
  1434. NSSCKMDSession *mdSession,
  1435. NSSCKFWSession *fwSession,
  1436. NSSCKMDToken *mdToken,
  1437. NSSCKFWToken *fwToken,
  1438. NSSCKMDInstance *mdInstance,
  1439. NSSCKFWInstance *fwInstance,
  1440. NSSCKMDObject *mdKey,
  1441. NSSCKFWObject *fwKey,
  1442. CK_RV *pError);
  1443. /*
  1444. */
  1445. NSSCKMDCryptoOperation *(PR_CALLBACK *VerifyRecoverInit)(
  1446. NSSCKMDMechanism *mdMechanism,
  1447. NSSCKFWMechanism *fwMechanism,
  1448. CK_MECHANISM_PTR pMechanism,
  1449. NSSCKMDSession *mdSession,
  1450. NSSCKFWSession *fwSession,
  1451. NSSCKMDToken *mdToken,
  1452. NSSCKFWToken *fwToken,
  1453. NSSCKMDInstance *mdInstance,
  1454. NSSCKFWInstance *fwInstance,
  1455. NSSCKMDObject *mdKey,
  1456. NSSCKFWObject *fwKey,
  1457. CK_RV *pError);
  1458. /*
  1459. * Key management operations.
  1460. */
  1461. /*
  1462. * This routine generates a key. This routine may return NULL
  1463. * upon error.
  1464. */
  1465. NSSCKMDObject *(PR_CALLBACK *GenerateKey)(
  1466. NSSCKMDMechanism *mdMechanism,
  1467. NSSCKFWMechanism *fwMechanism,
  1468. CK_MECHANISM_PTR pMechanism,
  1469. NSSCKMDSession *mdSession,
  1470. NSSCKFWSession *fwSession,
  1471. NSSCKMDToken *mdToken,
  1472. NSSCKFWToken *fwToken,
  1473. NSSCKMDInstance *mdInstance,
  1474. NSSCKFWInstance *fwInstance,
  1475. CK_ATTRIBUTE_PTR pTemplate,
  1476. CK_ULONG ulAttributeCount,
  1477. CK_RV *pError);
  1478. /*
  1479. * This routine generates a key pair.
  1480. */
  1481. CK_RV(PR_CALLBACK *GenerateKeyPair)
  1482. (
  1483. NSSCKMDMechanism *mdMechanism,
  1484. NSSCKFWMechanism *fwMechanism,
  1485. CK_MECHANISM_PTR pMechanism,
  1486. NSSCKMDSession *mdSession,
  1487. NSSCKFWSession *fwSession,
  1488. NSSCKMDToken *mdToken,
  1489. NSSCKFWToken *fwToken,
  1490. NSSCKMDInstance *mdInstance,
  1491. NSSCKFWInstance *fwInstance,
  1492. CK_ATTRIBUTE_PTR pPublicKeyTemplate,
  1493. CK_ULONG ulPublicKeyAttributeCount,
  1494. CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
  1495. CK_ULONG ulPrivateKeyAttributeCount,
  1496. NSSCKMDObject **pPublicKey,
  1497. NSSCKMDObject **pPrivateKey);
  1498. /*
  1499. * This routine wraps a key.
  1500. */
  1501. CK_ULONG(PR_CALLBACK *GetWrapKeyLength)
  1502. (
  1503. NSSCKMDMechanism *mdMechanism,
  1504. NSSCKFWMechanism *fwMechanism,
  1505. CK_MECHANISM_PTR pMechanism,
  1506. NSSCKMDSession *mdSession,
  1507. NSSCKFWSession *fwSession,
  1508. NSSCKMDToken *mdToken,
  1509. NSSCKFWToken *fwToken,
  1510. NSSCKMDInstance *mdInstance,
  1511. NSSCKFWInstance *fwInstance,
  1512. NSSCKMDObject *mdWrappingKey,
  1513. NSSCKFWObject *fwWrappingKey,
  1514. NSSCKMDObject *mdWrappedKey,
  1515. NSSCKFWObject *fwWrappedKey,
  1516. CK_RV *pError);
  1517. /*
  1518. * This routine wraps a key.
  1519. */
  1520. CK_RV(PR_CALLBACK *WrapKey)
  1521. (
  1522. NSSCKMDMechanism *mdMechanism,
  1523. NSSCKFWMechanism *fwMechanism,
  1524. CK_MECHANISM_PTR pMechanism,
  1525. NSSCKMDSession *mdSession,
  1526. NSSCKFWSession *fwSession,
  1527. NSSCKMDToken *mdToken,
  1528. NSSCKFWToken *fwToken,
  1529. NSSCKMDInstance *mdInstance,
  1530. NSSCKFWInstance *fwInstance,
  1531. NSSCKMDObject *mdWrappingKey,
  1532. NSSCKFWObject *fwWrappingKey,
  1533. NSSCKMDObject *mdKeyObject,
  1534. NSSCKFWObject *fwKeyObject,
  1535. NSSItem *wrappedKey);
  1536. /*
  1537. * This routine unwraps a key. This routine may return NULL
  1538. * upon error.
  1539. */
  1540. NSSCKMDObject *(PR_CALLBACK *UnwrapKey)(
  1541. NSSCKMDMechanism *mdMechanism,
  1542. NSSCKFWMechanism *fwMechanism,
  1543. CK_MECHANISM_PTR pMechanism,
  1544. NSSCKMDSession *mdSession,
  1545. NSSCKFWSession *fwSession,
  1546. NSSCKMDToken *mdToken,
  1547. NSSCKFWToken *fwToken,
  1548. NSSCKMDInstance *mdInstance,
  1549. NSSCKFWInstance *fwInstance,
  1550. NSSCKMDObject *mdWrappingKey,
  1551. NSSCKFWObject *fwWrappingKey,
  1552. NSSItem *wrappedKey,
  1553. CK_ATTRIBUTE_PTR pTemplate,
  1554. CK_ULONG ulAttributeCount,
  1555. CK_RV *pError);
  1556. /*
  1557. * This routine derives a key. This routine may return NULL
  1558. * upon error.
  1559. */
  1560. NSSCKMDObject *(PR_CALLBACK *DeriveKey)(
  1561. NSSCKMDMechanism *mdMechanism,
  1562. NSSCKFWMechanism *fwMechanism,
  1563. CK_MECHANISM_PTR pMechanism,
  1564. NSSCKMDSession *mdSession,
  1565. NSSCKFWSession *fwSession,
  1566. NSSCKMDToken *mdToken,
  1567. NSSCKFWToken *fwToken,
  1568. NSSCKMDInstance *mdInstance,
  1569. NSSCKFWInstance *fwInstance,
  1570. NSSCKMDObject *mdBaseKey,
  1571. NSSCKFWObject *fwBaseKey,
  1572. CK_ATTRIBUTE_PTR pTemplate,
  1573. CK_ULONG ulAttributeCount,
  1574. CK_RV *pError);
  1575. /*
  1576. * This object may be extended in future versions of the
  1577. * NSS Cryptoki Framework. To allow for some flexibility
  1578. * in the area of binary compatibility, this field should
  1579. * be NULL.
  1580. */
  1581. void *null;
  1582. };
  1583. /*
  1584. * NSSCKMDObject
  1585. *
  1586. * This is the basic handle for any object used by a PKCS#11 Module.
  1587. * Modules must implement it if they support their own objects, and
  1588. * the Framework supports it for Modules that do not handle session
  1589. * objects. This type contains a pointer for use by the implementor,
  1590. * to store any object-specific data, and it contains an EPV for a
  1591. * set of routines used to access the object.
  1592. */
  1593. struct NSSCKMDObjectStr {
  1594. /*
  1595. * The implementation my use this pointer for its own purposes.
  1596. */
  1597. void *etc;
  1598. /*
  1599. * This routine is called by the Framework when it is letting
  1600. * go of an object handle. It can be used by the Module to
  1601. * free any resources tied up by an object "in use." It is
  1602. * optional.
  1603. */
  1604. void(PR_CALLBACK *Finalize)(
  1605. NSSCKMDObject *mdObject,
  1606. NSSCKFWObject *fwObject,
  1607. NSSCKMDSession *mdSession,
  1608. NSSCKFWSession *fwSession,
  1609. NSSCKMDToken *mdToken,
  1610. NSSCKFWToken *fwToken,
  1611. NSSCKMDInstance *mdInstance,
  1612. NSSCKFWInstance *fwInstance);
  1613. /*
  1614. * This routine is used to completely destroy an object.
  1615. * It is optional. The parameter fwObject might be NULL
  1616. * if the framework runs out of memory at the wrong moment.
  1617. */
  1618. CK_RV(PR_CALLBACK *Destroy)
  1619. (
  1620. NSSCKMDObject *mdObject,
  1621. NSSCKFWObject *fwObject,
  1622. NSSCKMDSession *mdSession,
  1623. NSSCKFWSession *fwSession,
  1624. NSSCKMDToken *mdToken,
  1625. NSSCKFWToken *fwToken,
  1626. NSSCKMDInstance *mdInstance,
  1627. NSSCKFWInstance *fwInstance);
  1628. /*
  1629. * This helper routine is used by the Framework, and is especially
  1630. * useful when it is managing session objects on behalf of the
  1631. * Module. This routine is optional; if unimplemented, the
  1632. * Framework will actually look up the CKA_TOKEN attribute. In the
  1633. * event of an error, just make something up-- the Framework will
  1634. * find out soon enough anyway.
  1635. */
  1636. CK_BBOOL(PR_CALLBACK *IsTokenObject)
  1637. (
  1638. NSSCKMDObject *mdObject,
  1639. NSSCKFWObject *fwObject,
  1640. NSSCKMDSession *mdSession,
  1641. NSSCKFWSession *fwSession,
  1642. NSSCKMDToken *mdToken,
  1643. NSSCKFWToken *fwToken,
  1644. NSSCKMDInstance *mdInstance,
  1645. NSSCKFWInstance *fwInstance);
  1646. /*
  1647. * This routine returns the number of attributes of which this
  1648. * object consists. It is mandatory. It can return zero on
  1649. * error.
  1650. */
  1651. CK_ULONG(PR_CALLBACK *GetAttributeCount)
  1652. (
  1653. NSSCKMDObject *mdObject,
  1654. NSSCKFWObject *fwObject,
  1655. NSSCKMDSession *mdSession,
  1656. NSSCKFWSession *fwSession,
  1657. NSSCKMDToken *mdToken,
  1658. NSSCKFWToken *fwToken,
  1659. NSSCKMDInstance *mdInstance,
  1660. NSSCKFWInstance *fwInstance,
  1661. CK_RV *pError);
  1662. /*
  1663. * This routine stuffs the attribute types into the provided array.
  1664. * The array size (as obtained from GetAttributeCount) is passed in
  1665. * as a check; return CKR_BUFFER_TOO_SMALL if the count is wrong
  1666. * (either too big or too small).
  1667. */
  1668. CK_RV(PR_CALLBACK *GetAttributeTypes)
  1669. (
  1670. NSSCKMDObject *mdObject,
  1671. NSSCKFWObject *fwObject,
  1672. NSSCKMDSession *mdSession,
  1673. NSSCKFWSession *fwSession,
  1674. NSSCKMDToken *mdToken,
  1675. NSSCKFWToken *fwToken,
  1676. NSSCKMDInstance *mdInstance,
  1677. NSSCKFWInstance *fwInstance,
  1678. CK_ATTRIBUTE_TYPE_PTR typeArray,
  1679. CK_ULONG ulCount);
  1680. /*
  1681. * This routine returns the size (in bytes) of the specified
  1682. * attribute. It can return zero on error.
  1683. */
  1684. CK_ULONG(PR_CALLBACK *GetAttributeSize)
  1685. (
  1686. NSSCKMDObject *mdObject,
  1687. NSSCKFWObject *fwObject,
  1688. NSSCKMDSession *mdSession,
  1689. NSSCKFWSession *fwSession,
  1690. NSSCKMDToken *mdToken,
  1691. NSSCKFWToken *fwToken,
  1692. NSSCKMDInstance *mdInstance,
  1693. NSSCKFWInstance *fwInstance,
  1694. CK_ATTRIBUTE_TYPE attribute,
  1695. CK_RV *pError);
  1696. /*
  1697. * This routine returns an NSSCKFWItem structure.
  1698. * The item pointer points to an NSSItem containing the attribute value.
  1699. * The needsFreeing bit tells the framework whether to call the
  1700. * FreeAttribute function . Upon error, an NSSCKFWItem structure
  1701. * with a NULL NSSItem item pointer will be returned
  1702. */
  1703. NSSCKFWItem(PR_CALLBACK *GetAttribute)(
  1704. NSSCKMDObject *mdObject,
  1705. NSSCKFWObject *fwObject,
  1706. NSSCKMDSession *mdSession,
  1707. NSSCKFWSession *fwSession,
  1708. NSSCKMDToken *mdToken,
  1709. NSSCKFWToken *fwToken,
  1710. NSSCKMDInstance *mdInstance,
  1711. NSSCKFWInstance *fwInstance,
  1712. CK_ATTRIBUTE_TYPE attribute,
  1713. CK_RV *pError);
  1714. /*
  1715. * This routine returns CKR_OK if the attribute could be freed.
  1716. */
  1717. CK_RV(PR_CALLBACK *FreeAttribute)
  1718. (
  1719. NSSCKFWItem *item);
  1720. /*
  1721. * This routine changes the specified attribute. If unimplemented,
  1722. * the object will be considered read-only.
  1723. */
  1724. CK_RV(PR_CALLBACK *SetAttribute)
  1725. (
  1726. NSSCKMDObject *mdObject,
  1727. NSSCKFWObject *fwObject,
  1728. NSSCKMDSession *mdSession,
  1729. NSSCKFWSession *fwSession,
  1730. NSSCKMDToken *mdToken,
  1731. NSSCKFWToken *fwToken,
  1732. NSSCKMDInstance *mdInstance,
  1733. NSSCKFWInstance *fwInstance,
  1734. CK_ATTRIBUTE_TYPE attribute,
  1735. NSSItem *value);
  1736. /*
  1737. * This routine returns the storage requirements of this object,
  1738. * in bytes. Cryptoki doesn't strictly define the definition,
  1739. * but it should relate to the values returned by the "Get Memory"
  1740. * routines of the NSSCKMDToken. This routine is optional; if
  1741. * unimplemented, the Framework will consider this information
  1742. * sensitive. This routine may return zero on error. If the
  1743. * specified error is CKR_OK, zero will be accepted as a valid
  1744. * response.
  1745. */
  1746. CK_ULONG(PR_CALLBACK *GetObjectSize)
  1747. (
  1748. NSSCKMDObject *mdObject,
  1749. NSSCKFWObject *fwObject,
  1750. NSSCKMDSession *mdSession,
  1751. NSSCKFWSession *fwSession,
  1752. NSSCKMDToken *mdToken,
  1753. NSSCKFWToken *fwToken,
  1754. NSSCKMDInstance *mdInstance,
  1755. NSSCKFWInstance *fwInstance,
  1756. CK_RV *pError);
  1757. /*
  1758. * This object may be extended in future versions of the
  1759. * NSS Cryptoki Framework. To allow for some flexibility
  1760. * in the area of binary compatibility, this field should
  1761. * be NULL.
  1762. */
  1763. void *null;
  1764. };
  1765. #endif /* NSSCKMDT_H */