Browse code

Remove miekg/pkcs11 from vendor.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/06/21 06:00:09
Showing 10 changed files
... ...
@@ -58,7 +58,6 @@ github.com/mistifyio/go-zfs 22c9b32c84eb0d0c6f4043b6e90fc94073de92fa
58 58
 github.com/pborman/uuid v1.0
59 59
 
60 60
 google.golang.org/grpc v1.3.0
61
-github.com/miekg/pkcs11 df8ae6ca730422dba20c768ff38ef7d79077a59f
62 61
 
63 62
 # When updating, also update RUNC_COMMIT in hack/dockerfile/binaries-commits accordingly
64 63
 github.com/opencontainers/runc 2d41c047c83e09a6d61d464906feb2a2f3c52aa4 https://github.com/docker/runc
65 64
deleted file mode 100644
... ...
@@ -1,27 +0,0 @@
1
-Copyright (c) 2013 Miek Gieben. All rights reserved.
2
-
3
-Redistribution and use in source and binary forms, with or without
4
-modification, are permitted provided that the following conditions are
5
-met:
6
-
7
-   * Redistributions of source code must retain the above copyright
8
-notice, this list of conditions and the following disclaimer.
9
-   * Redistributions in binary form must reproduce the above
10
-copyright notice, this list of conditions and the following disclaimer
11
-in the documentation and/or other materials provided with the
12
-distribution.
13
-   * Neither the name of Miek Gieben nor the names of its
14
-contributors may be used to endorse or promote products derived from
15
-this software without specific prior written permission.
16
-
17
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1
deleted file mode 100644
... ...
@@ -1,64 +0,0 @@
1
-# PKCS#11 [![Build Status](https://travis-ci.org/miekg/pkcs11.png?branch=master)](https://travis-ci.org/miekg/pkcs11)
2
-
3
-This is a Go implementation of the PKCS#11 API. It wraps the library closely, but uses Go idiom
4
-were it makes sense. It has been tested with SoftHSM.
5
-
6
-## SoftHSM
7
-
8
-* Make it use a custom configuration file `export SOFTHSM_CONF=$PWD/softhsm.conf`
9
-
10
-* Then use `softhsm` to init it
11
-
12
-        softhsm --init-token --slot 0 --label test --pin 1234
13
-
14
-* Then use `libsofthsm.so` as the pkcs11 module:
15
-
16
-        p := pkcs11.New("/usr/lib/softhsm/libsofthsm.so")
17
-
18
-## Examples
19
-
20
-A skeleton program would look somewhat like this (yes, pkcs#11 is verbose):
21
-
22
-    p := pkcs11.New("/usr/lib/softhsm/libsofthsm.so")
23
-    err := p.Initialize()
24
-    if err != nil {
25
-        panic(err)
26
-    }
27
-
28
-    defer p.Destroy()
29
-    defer p.Finalize()
30
-
31
-    slots, err := p.GetSlotList(true)
32
-    if err != nil {
33
-        panic(err)
34
-    }
35
-
36
-    session, err := p.OpenSession(slots[0], pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION)
37
-    if err != nil {
38
-        panic(err)
39
-    }
40
-    defer p.CloseSession(session)
41
-
42
-    err = p.Login(session, pkcs11.CKU_USER, "1234")
43
-    if err != nil {
44
-        panic(err)
45
-    }
46
-    defer p.Logout(session)
47
-
48
-    p.DigestInit(session, []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_SHA_1, nil)})
49
-    hash, err := p.Digest(session, []byte("this is a string"))
50
-    if err != nil {
51
-        panic(err)
52
-    }
53
-
54
-    for _, d := range hash {
55
-            fmt.Printf("%x", d)
56
-    }
57
-    fmt.Println()
58
-
59
-Further examples are included in the tests.
60
-
61
-# TODO
62
-
63
-* Fix/double check endian stuff, see types.go NewAttribute()
64
-* Look at the memory copying in fast functions (sign, hash etc)
65 1
deleted file mode 100644
... ...
@@ -1,565 +0,0 @@
1
-// Copyright 2013 Miek Gieben. All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package pkcs11
6
-
7
-const (
8
-	CKU_SO               uint = 0
9
-	CKU_USER             uint = 1
10
-	CKU_CONTEXT_SPECIFIC uint = 2
11
-)
12
-
13
-const (
14
-	CKO_DATA              uint = 0x00000000
15
-	CKO_CERTIFICATE       uint = 0x00000001
16
-	CKO_PUBLIC_KEY        uint = 0x00000002
17
-	CKO_PRIVATE_KEY       uint = 0x00000003
18
-	CKO_SECRET_KEY        uint = 0x00000004
19
-	CKO_HW_FEATURE        uint = 0x00000005
20
-	CKO_DOMAIN_PARAMETERS uint = 0x00000006
21
-	CKO_MECHANISM         uint = 0x00000007
22
-	CKO_OTP_KEY           uint = 0x00000008
23
-	CKO_VENDOR_DEFINED    uint = 0x80000000
24
-)
25
-
26
-// Generated with: awk '/#define CK[AFKMRC]/{ print $2 "=" $3 }' pkcs11t.h
27
-
28
-// All the flag (CKF_), attribute (CKA_), error code (CKR_), key type (CKK_), certificate type (CKC_) and
29
-// mechanism (CKM_) constants as defined in PKCS#11.
30
-const (
31
-	CKF_TOKEN_PRESENT                    = 0x00000001
32
-	CKF_REMOVABLE_DEVICE                 = 0x00000002
33
-	CKF_HW_SLOT                          = 0x00000004
34
-	CKF_RNG                              = 0x00000001
35
-	CKF_WRITE_PROTECTED                  = 0x00000002
36
-	CKF_LOGIN_REQUIRED                   = 0x00000004
37
-	CKF_USER_PIN_INITIALIZED             = 0x00000008
38
-	CKF_RESTORE_KEY_NOT_NEEDED           = 0x00000020
39
-	CKF_CLOCK_ON_TOKEN                   = 0x00000040
40
-	CKF_PROTECTED_AUTHENTICATION_PATH    = 0x00000100
41
-	CKF_DUAL_CRYPTO_OPERATIONS           = 0x00000200
42
-	CKF_TOKEN_INITIALIZED                = 0x00000400
43
-	CKF_SECONDARY_AUTHENTICATION         = 0x00000800
44
-	CKF_USER_PIN_COUNT_LOW               = 0x00010000
45
-	CKF_USER_PIN_FINAL_TRY               = 0x00020000
46
-	CKF_USER_PIN_LOCKED                  = 0x00040000
47
-	CKF_USER_PIN_TO_BE_CHANGED           = 0x00080000
48
-	CKF_SO_PIN_COUNT_LOW                 = 0x00100000
49
-	CKF_SO_PIN_FINAL_TRY                 = 0x00200000
50
-	CKF_SO_PIN_LOCKED                    = 0x00400000
51
-	CKF_SO_PIN_TO_BE_CHANGED             = 0x00800000
52
-	CKF_RW_SESSION                       = 0x00000002
53
-	CKF_SERIAL_SESSION                   = 0x00000004
54
-	CKK_RSA                              = 0x00000000
55
-	CKK_DSA                              = 0x00000001
56
-	CKK_DH                               = 0x00000002
57
-	CKK_ECDSA                            = 0x00000003
58
-	CKK_EC                               = 0x00000003
59
-	CKK_X9_42_DH                         = 0x00000004
60
-	CKK_KEA                              = 0x00000005
61
-	CKK_GENERIC_SECRET                   = 0x00000010
62
-	CKK_RC2                              = 0x00000011
63
-	CKK_RC4                              = 0x00000012
64
-	CKK_DES                              = 0x00000013
65
-	CKK_DES2                             = 0x00000014
66
-	CKK_DES3                             = 0x00000015
67
-	CKK_CAST                             = 0x00000016
68
-	CKK_CAST3                            = 0x00000017
69
-	CKK_CAST5                            = 0x00000018
70
-	CKK_CAST128                          = 0x00000018
71
-	CKK_RC5                              = 0x00000019
72
-	CKK_IDEA                             = 0x0000001A
73
-	CKK_SKIPJACK                         = 0x0000001B
74
-	CKK_BATON                            = 0x0000001C
75
-	CKK_JUNIPER                          = 0x0000001D
76
-	CKK_CDMF                             = 0x0000001E
77
-	CKK_AES                              = 0x0000001F
78
-	CKK_BLOWFISH                         = 0x00000020
79
-	CKK_TWOFISH                          = 0x00000021
80
-	CKK_SECURID                          = 0x00000022
81
-	CKK_HOTP                             = 0x00000023
82
-	CKK_ACTI                             = 0x00000024
83
-	CKK_CAMELLIA                         = 0x00000025
84
-	CKK_ARIA                             = 0x00000026
85
-	CKK_VENDOR_DEFINED                   = 0x80000000
86
-	CKC_X_509                            = 0x00000000
87
-	CKC_X_509_ATTR_CERT                  = 0x00000001
88
-	CKC_WTLS                             = 0x00000002
89
-	CKC_VENDOR_DEFINED                   = 0x80000000
90
-	CKF_ARRAY_ATTRIBUTE                  = 0x40000000
91
-	CKA_CLASS                            = 0x00000000
92
-	CKA_TOKEN                            = 0x00000001
93
-	CKA_PRIVATE                          = 0x00000002
94
-	CKA_LABEL                            = 0x00000003
95
-	CKA_APPLICATION                      = 0x00000010
96
-	CKA_VALUE                            = 0x00000011
97
-	CKA_OBJECT_ID                        = 0x00000012
98
-	CKA_CERTIFICATE_TYPE                 = 0x00000080
99
-	CKA_ISSUER                           = 0x00000081
100
-	CKA_SERIAL_NUMBER                    = 0x00000082
101
-	CKA_AC_ISSUER                        = 0x00000083
102
-	CKA_OWNER                            = 0x00000084
103
-	CKA_ATTR_TYPES                       = 0x00000085
104
-	CKA_TRUSTED                          = 0x00000086
105
-	CKA_CERTIFICATE_CATEGORY             = 0x00000087
106
-	CKA_JAVA_MIDP_SECURITY_DOMAIN        = 0x00000088
107
-	CKA_URL                              = 0x00000089
108
-	CKA_HASH_OF_SUBJECT_PUBLIC_KEY       = 0x0000008A
109
-	CKA_HASH_OF_ISSUER_PUBLIC_KEY        = 0x0000008B
110
-	CKA_CHECK_VALUE                      = 0x00000090
111
-	CKA_KEY_TYPE                         = 0x00000100
112
-	CKA_SUBJECT                          = 0x00000101
113
-	CKA_ID                               = 0x00000102
114
-	CKA_SENSITIVE                        = 0x00000103
115
-	CKA_ENCRYPT                          = 0x00000104
116
-	CKA_DECRYPT                          = 0x00000105
117
-	CKA_WRAP                             = 0x00000106
118
-	CKA_UNWRAP                           = 0x00000107
119
-	CKA_SIGN                             = 0x00000108
120
-	CKA_SIGN_RECOVER                     = 0x00000109
121
-	CKA_VERIFY                           = 0x0000010A
122
-	CKA_VERIFY_RECOVER                   = 0x0000010B
123
-	CKA_DERIVE                           = 0x0000010C
124
-	CKA_START_DATE                       = 0x00000110
125
-	CKA_END_DATE                         = 0x00000111
126
-	CKA_MODULUS                          = 0x00000120
127
-	CKA_MODULUS_BITS                     = 0x00000121
128
-	CKA_PUBLIC_EXPONENT                  = 0x00000122
129
-	CKA_PRIVATE_EXPONENT                 = 0x00000123
130
-	CKA_PRIME_1                          = 0x00000124
131
-	CKA_PRIME_2                          = 0x00000125
132
-	CKA_EXPONENT_1                       = 0x00000126
133
-	CKA_EXPONENT_2                       = 0x00000127
134
-	CKA_COEFFICIENT                      = 0x00000128
135
-	CKA_PRIME                            = 0x00000130
136
-	CKA_SUBPRIME                         = 0x00000131
137
-	CKA_BASE                             = 0x00000132
138
-	CKA_PRIME_BITS                       = 0x00000133
139
-	CKA_SUBPRIME_BITS                    = 0x00000134
140
-	CKA_SUB_PRIME_BITS                   = CKA_SUBPRIME_BITS
141
-	CKA_VALUE_BITS                       = 0x00000160
142
-	CKA_VALUE_LEN                        = 0x00000161
143
-	CKA_EXTRACTABLE                      = 0x00000162
144
-	CKA_LOCAL                            = 0x00000163
145
-	CKA_NEVER_EXTRACTABLE                = 0x00000164
146
-	CKA_ALWAYS_SENSITIVE                 = 0x00000165
147
-	CKA_KEY_GEN_MECHANISM                = 0x00000166
148
-	CKA_MODIFIABLE                       = 0x00000170
149
-	CKA_ECDSA_PARAMS                     = 0x00000180
150
-	CKA_EC_PARAMS                        = 0x00000180
151
-	CKA_EC_POINT                         = 0x00000181
152
-	CKA_SECONDARY_AUTH                   = 0x00000200
153
-	CKA_AUTH_PIN_FLAGS                   = 0x00000201
154
-	CKA_ALWAYS_AUTHENTICATE              = 0x00000202
155
-	CKA_WRAP_WITH_TRUSTED                = 0x00000210
156
-	CKA_WRAP_TEMPLATE                    = (CKF_ARRAY_ATTRIBUTE | 0x00000211)
157
-	CKA_UNWRAP_TEMPLATE                  = (CKF_ARRAY_ATTRIBUTE | 0x00000212)
158
-	CKA_OTP_FORMAT                       = 0x00000220
159
-	CKA_OTP_LENGTH                       = 0x00000221
160
-	CKA_OTP_TIME_INTERVAL                = 0x00000222
161
-	CKA_OTP_USER_FRIENDLY_MODE           = 0x00000223
162
-	CKA_OTP_CHALLENGE_REQUIREMENT        = 0x00000224
163
-	CKA_OTP_TIME_REQUIREMENT             = 0x00000225
164
-	CKA_OTP_COUNTER_REQUIREMENT          = 0x00000226
165
-	CKA_OTP_PIN_REQUIREMENT              = 0x00000227
166
-	CKA_OTP_COUNTER                      = 0x0000022E
167
-	CKA_OTP_TIME                         = 0x0000022F
168
-	CKA_OTP_USER_IDENTIFIER              = 0x0000022A
169
-	CKA_OTP_SERVICE_IDENTIFIER           = 0x0000022B
170
-	CKA_OTP_SERVICE_LOGO                 = 0x0000022C
171
-	CKA_OTP_SERVICE_LOGO_TYPE            = 0x0000022D
172
-	CKA_HW_FEATURE_TYPE                  = 0x00000300
173
-	CKA_RESET_ON_INIT                    = 0x00000301
174
-	CKA_HAS_RESET                        = 0x00000302
175
-	CKA_PIXEL_X                          = 0x00000400
176
-	CKA_PIXEL_Y                          = 0x00000401
177
-	CKA_RESOLUTION                       = 0x00000402
178
-	CKA_CHAR_ROWS                        = 0x00000403
179
-	CKA_CHAR_COLUMNS                     = 0x00000404
180
-	CKA_COLOR                            = 0x00000405
181
-	CKA_BITS_PER_PIXEL                   = 0x00000406
182
-	CKA_CHAR_SETS                        = 0x00000480
183
-	CKA_ENCODING_METHODS                 = 0x00000481
184
-	CKA_MIME_TYPES                       = 0x00000482
185
-	CKA_MECHANISM_TYPE                   = 0x00000500
186
-	CKA_REQUIRED_CMS_ATTRIBUTES          = 0x00000501
187
-	CKA_DEFAULT_CMS_ATTRIBUTES           = 0x00000502
188
-	CKA_SUPPORTED_CMS_ATTRIBUTES         = 0x00000503
189
-	CKA_ALLOWED_MECHANISMS               = (CKF_ARRAY_ATTRIBUTE | 0x00000600)
190
-	CKA_VENDOR_DEFINED                   = 0x80000000
191
-	CKM_RSA_PKCS_KEY_PAIR_GEN            = 0x00000000
192
-	CKM_RSA_PKCS                         = 0x00000001
193
-	CKM_RSA_9796                         = 0x00000002
194
-	CKM_RSA_X_509                        = 0x00000003
195
-	CKM_MD2_RSA_PKCS                     = 0x00000004
196
-	CKM_MD5_RSA_PKCS                     = 0x00000005
197
-	CKM_SHA1_RSA_PKCS                    = 0x00000006
198
-	CKM_RIPEMD128_RSA_PKCS               = 0x00000007
199
-	CKM_RIPEMD160_RSA_PKCS               = 0x00000008
200
-	CKM_RSA_PKCS_OAEP                    = 0x00000009
201
-	CKM_RSA_X9_31_KEY_PAIR_GEN           = 0x0000000A
202
-	CKM_RSA_X9_31                        = 0x0000000B
203
-	CKM_SHA1_RSA_X9_31                   = 0x0000000C
204
-	CKM_RSA_PKCS_PSS                     = 0x0000000D
205
-	CKM_SHA1_RSA_PKCS_PSS                = 0x0000000E
206
-	CKM_DSA_KEY_PAIR_GEN                 = 0x00000010
207
-	CKM_DSA                              = 0x00000011
208
-	CKM_DSA_SHA1                         = 0x00000012
209
-	CKM_DH_PKCS_KEY_PAIR_GEN             = 0x00000020
210
-	CKM_DH_PKCS_DERIVE                   = 0x00000021
211
-	CKM_X9_42_DH_KEY_PAIR_GEN            = 0x00000030
212
-	CKM_X9_42_DH_DERIVE                  = 0x00000031
213
-	CKM_X9_42_DH_HYBRID_DERIVE           = 0x00000032
214
-	CKM_X9_42_MQV_DERIVE                 = 0x00000033
215
-	CKM_SHA256_RSA_PKCS                  = 0x00000040
216
-	CKM_SHA384_RSA_PKCS                  = 0x00000041
217
-	CKM_SHA512_RSA_PKCS                  = 0x00000042
218
-	CKM_SHA256_RSA_PKCS_PSS              = 0x00000043
219
-	CKM_SHA384_RSA_PKCS_PSS              = 0x00000044
220
-	CKM_SHA512_RSA_PKCS_PSS              = 0x00000045
221
-	CKM_SHA224_RSA_PKCS                  = 0x00000046
222
-	CKM_SHA224_RSA_PKCS_PSS              = 0x00000047
223
-	CKM_RC2_KEY_GEN                      = 0x00000100
224
-	CKM_RC2_ECB                          = 0x00000101
225
-	CKM_RC2_CBC                          = 0x00000102
226
-	CKM_RC2_MAC                          = 0x00000103
227
-	CKM_RC2_MAC_GENERAL                  = 0x00000104
228
-	CKM_RC2_CBC_PAD                      = 0x00000105
229
-	CKM_RC4_KEY_GEN                      = 0x00000110
230
-	CKM_RC4                              = 0x00000111
231
-	CKM_DES_KEY_GEN                      = 0x00000120
232
-	CKM_DES_ECB                          = 0x00000121
233
-	CKM_DES_CBC                          = 0x00000122
234
-	CKM_DES_MAC                          = 0x00000123
235
-	CKM_DES_MAC_GENERAL                  = 0x00000124
236
-	CKM_DES_CBC_PAD                      = 0x00000125
237
-	CKM_DES2_KEY_GEN                     = 0x00000130
238
-	CKM_DES3_KEY_GEN                     = 0x00000131
239
-	CKM_DES3_ECB                         = 0x00000132
240
-	CKM_DES3_CBC                         = 0x00000133
241
-	CKM_DES3_MAC                         = 0x00000134
242
-	CKM_DES3_MAC_GENERAL                 = 0x00000135
243
-	CKM_DES3_CBC_PAD                     = 0x00000136
244
-	CKM_CDMF_KEY_GEN                     = 0x00000140
245
-	CKM_CDMF_ECB                         = 0x00000141
246
-	CKM_CDMF_CBC                         = 0x00000142
247
-	CKM_CDMF_MAC                         = 0x00000143
248
-	CKM_CDMF_MAC_GENERAL                 = 0x00000144
249
-	CKM_CDMF_CBC_PAD                     = 0x00000145
250
-	CKM_DES_OFB64                        = 0x00000150
251
-	CKM_DES_OFB8                         = 0x00000151
252
-	CKM_DES_CFB64                        = 0x00000152
253
-	CKM_DES_CFB8                         = 0x00000153
254
-	CKM_MD2                              = 0x00000200
255
-	CKM_MD2_HMAC                         = 0x00000201
256
-	CKM_MD2_HMAC_GENERAL                 = 0x00000202
257
-	CKM_MD5                              = 0x00000210
258
-	CKM_MD5_HMAC                         = 0x00000211
259
-	CKM_MD5_HMAC_GENERAL                 = 0x00000212
260
-	CKM_SHA_1                            = 0x00000220
261
-	CKM_SHA_1_HMAC                       = 0x00000221
262
-	CKM_SHA_1_HMAC_GENERAL               = 0x00000222
263
-	CKM_RIPEMD128                        = 0x00000230
264
-	CKM_RIPEMD128_HMAC                   = 0x00000231
265
-	CKM_RIPEMD128_HMAC_GENERAL           = 0x00000232
266
-	CKM_RIPEMD160                        = 0x00000240
267
-	CKM_RIPEMD160_HMAC                   = 0x00000241
268
-	CKM_RIPEMD160_HMAC_GENERAL           = 0x00000242
269
-	CKM_SHA256                           = 0x00000250
270
-	CKM_SHA256_HMAC                      = 0x00000251
271
-	CKM_SHA256_HMAC_GENERAL              = 0x00000252
272
-	CKM_SHA224                           = 0x00000255
273
-	CKM_SHA224_HMAC                      = 0x00000256
274
-	CKM_SHA224_HMAC_GENERAL              = 0x00000257
275
-	CKM_SHA384                           = 0x00000260
276
-	CKM_SHA384_HMAC                      = 0x00000261
277
-	CKM_SHA384_HMAC_GENERAL              = 0x00000262
278
-	CKM_SHA512                           = 0x00000270
279
-	CKM_SHA512_HMAC                      = 0x00000271
280
-	CKM_SHA512_HMAC_GENERAL              = 0x00000272
281
-	CKM_SECURID_KEY_GEN                  = 0x00000280
282
-	CKM_SECURID                          = 0x00000282
283
-	CKM_HOTP_KEY_GEN                     = 0x00000290
284
-	CKM_HOTP                             = 0x00000291
285
-	CKM_ACTI                             = 0x000002A0
286
-	CKM_ACTI_KEY_GEN                     = 0x000002A1
287
-	CKM_CAST_KEY_GEN                     = 0x00000300
288
-	CKM_CAST_ECB                         = 0x00000301
289
-	CKM_CAST_CBC                         = 0x00000302
290
-	CKM_CAST_MAC                         = 0x00000303
291
-	CKM_CAST_MAC_GENERAL                 = 0x00000304
292
-	CKM_CAST_CBC_PAD                     = 0x00000305
293
-	CKM_CAST3_KEY_GEN                    = 0x00000310
294
-	CKM_CAST3_ECB                        = 0x00000311
295
-	CKM_CAST3_CBC                        = 0x00000312
296
-	CKM_CAST3_MAC                        = 0x00000313
297
-	CKM_CAST3_MAC_GENERAL                = 0x00000314
298
-	CKM_CAST3_CBC_PAD                    = 0x00000315
299
-	CKM_CAST5_KEY_GEN                    = 0x00000320
300
-	CKM_CAST128_KEY_GEN                  = 0x00000320
301
-	CKM_CAST5_ECB                        = 0x00000321
302
-	CKM_CAST128_ECB                      = 0x00000321
303
-	CKM_CAST5_CBC                        = 0x00000322
304
-	CKM_CAST128_CBC                      = 0x00000322
305
-	CKM_CAST5_MAC                        = 0x00000323
306
-	CKM_CAST128_MAC                      = 0x00000323
307
-	CKM_CAST5_MAC_GENERAL                = 0x00000324
308
-	CKM_CAST128_MAC_GENERAL              = 0x00000324
309
-	CKM_CAST5_CBC_PAD                    = 0x00000325
310
-	CKM_CAST128_CBC_PAD                  = 0x00000325
311
-	CKM_RC5_KEY_GEN                      = 0x00000330
312
-	CKM_RC5_ECB                          = 0x00000331
313
-	CKM_RC5_CBC                          = 0x00000332
314
-	CKM_RC5_MAC                          = 0x00000333
315
-	CKM_RC5_MAC_GENERAL                  = 0x00000334
316
-	CKM_RC5_CBC_PAD                      = 0x00000335
317
-	CKM_IDEA_KEY_GEN                     = 0x00000340
318
-	CKM_IDEA_ECB                         = 0x00000341
319
-	CKM_IDEA_CBC                         = 0x00000342
320
-	CKM_IDEA_MAC                         = 0x00000343
321
-	CKM_IDEA_MAC_GENERAL                 = 0x00000344
322
-	CKM_IDEA_CBC_PAD                     = 0x00000345
323
-	CKM_GENERIC_SECRET_KEY_GEN           = 0x00000350
324
-	CKM_CONCATENATE_BASE_AND_KEY         = 0x00000360
325
-	CKM_CONCATENATE_BASE_AND_DATA        = 0x00000362
326
-	CKM_CONCATENATE_DATA_AND_BASE        = 0x00000363
327
-	CKM_XOR_BASE_AND_DATA                = 0x00000364
328
-	CKM_EXTRACT_KEY_FROM_KEY             = 0x00000365
329
-	CKM_SSL3_PRE_MASTER_KEY_GEN          = 0x00000370
330
-	CKM_SSL3_MASTER_KEY_DERIVE           = 0x00000371
331
-	CKM_SSL3_KEY_AND_MAC_DERIVE          = 0x00000372
332
-	CKM_SSL3_MASTER_KEY_DERIVE_DH        = 0x00000373
333
-	CKM_TLS_PRE_MASTER_KEY_GEN           = 0x00000374
334
-	CKM_TLS_MASTER_KEY_DERIVE            = 0x00000375
335
-	CKM_TLS_KEY_AND_MAC_DERIVE           = 0x00000376
336
-	CKM_TLS_MASTER_KEY_DERIVE_DH         = 0x00000377
337
-	CKM_TLS_PRF                          = 0x00000378
338
-	CKM_SSL3_MD5_MAC                     = 0x00000380
339
-	CKM_SSL3_SHA1_MAC                    = 0x00000381
340
-	CKM_MD5_KEY_DERIVATION               = 0x00000390
341
-	CKM_MD2_KEY_DERIVATION               = 0x00000391
342
-	CKM_SHA1_KEY_DERIVATION              = 0x00000392
343
-	CKM_SHA256_KEY_DERIVATION            = 0x00000393
344
-	CKM_SHA384_KEY_DERIVATION            = 0x00000394
345
-	CKM_SHA512_KEY_DERIVATION            = 0x00000395
346
-	CKM_SHA224_KEY_DERIVATION            = 0x00000396
347
-	CKM_PBE_MD2_DES_CBC                  = 0x000003A0
348
-	CKM_PBE_MD5_DES_CBC                  = 0x000003A1
349
-	CKM_PBE_MD5_CAST_CBC                 = 0x000003A2
350
-	CKM_PBE_MD5_CAST3_CBC                = 0x000003A3
351
-	CKM_PBE_MD5_CAST5_CBC                = 0x000003A4
352
-	CKM_PBE_MD5_CAST128_CBC              = 0x000003A4
353
-	CKM_PBE_SHA1_CAST5_CBC               = 0x000003A5
354
-	CKM_PBE_SHA1_CAST128_CBC             = 0x000003A5
355
-	CKM_PBE_SHA1_RC4_128                 = 0x000003A6
356
-	CKM_PBE_SHA1_RC4_40                  = 0x000003A7
357
-	CKM_PBE_SHA1_DES3_EDE_CBC            = 0x000003A8
358
-	CKM_PBE_SHA1_DES2_EDE_CBC            = 0x000003A9
359
-	CKM_PBE_SHA1_RC2_128_CBC             = 0x000003AA
360
-	CKM_PBE_SHA1_RC2_40_CBC              = 0x000003AB
361
-	CKM_PKCS5_PBKD2                      = 0x000003B0
362
-	CKM_PBA_SHA1_WITH_SHA1_HMAC          = 0x000003C0
363
-	CKM_WTLS_PRE_MASTER_KEY_GEN          = 0x000003D0
364
-	CKM_WTLS_MASTER_KEY_DERIVE           = 0x000003D1
365
-	CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC    = 0x000003D2
366
-	CKM_WTLS_PRF                         = 0x000003D3
367
-	CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE   = 0x000003D4
368
-	CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE   = 0x000003D5
369
-	CKM_KEY_WRAP_LYNKS                   = 0x00000400
370
-	CKM_KEY_WRAP_SET_OAEP                = 0x00000401
371
-	CKM_CMS_SIG                          = 0x00000500
372
-	CKM_KIP_DERIVE                       = 0x00000510
373
-	CKM_KIP_WRAP                         = 0x00000511
374
-	CKM_KIP_MAC                          = 0x00000512
375
-	CKM_CAMELLIA_KEY_GEN                 = 0x00000550
376
-	CKM_CAMELLIA_ECB                     = 0x00000551
377
-	CKM_CAMELLIA_CBC                     = 0x00000552
378
-	CKM_CAMELLIA_MAC                     = 0x00000553
379
-	CKM_CAMELLIA_MAC_GENERAL             = 0x00000554
380
-	CKM_CAMELLIA_CBC_PAD                 = 0x00000555
381
-	CKM_CAMELLIA_ECB_ENCRYPT_DATA        = 0x00000556
382
-	CKM_CAMELLIA_CBC_ENCRYPT_DATA        = 0x00000557
383
-	CKM_CAMELLIA_CTR                     = 0x00000558
384
-	CKM_ARIA_KEY_GEN                     = 0x00000560
385
-	CKM_ARIA_ECB                         = 0x00000561
386
-	CKM_ARIA_CBC                         = 0x00000562
387
-	CKM_ARIA_MAC                         = 0x00000563
388
-	CKM_ARIA_MAC_GENERAL                 = 0x00000564
389
-	CKM_ARIA_CBC_PAD                     = 0x00000565
390
-	CKM_ARIA_ECB_ENCRYPT_DATA            = 0x00000566
391
-	CKM_ARIA_CBC_ENCRYPT_DATA            = 0x00000567
392
-	CKM_SKIPJACK_KEY_GEN                 = 0x00001000
393
-	CKM_SKIPJACK_ECB64                   = 0x00001001
394
-	CKM_SKIPJACK_CBC64                   = 0x00001002
395
-	CKM_SKIPJACK_OFB64                   = 0x00001003
396
-	CKM_SKIPJACK_CFB64                   = 0x00001004
397
-	CKM_SKIPJACK_CFB32                   = 0x00001005
398
-	CKM_SKIPJACK_CFB16                   = 0x00001006
399
-	CKM_SKIPJACK_CFB8                    = 0x00001007
400
-	CKM_SKIPJACK_WRAP                    = 0x00001008
401
-	CKM_SKIPJACK_PRIVATE_WRAP            = 0x00001009
402
-	CKM_SKIPJACK_RELAYX                  = 0x0000100a
403
-	CKM_KEA_KEY_PAIR_GEN                 = 0x00001010
404
-	CKM_KEA_KEY_DERIVE                   = 0x00001011
405
-	CKM_FORTEZZA_TIMESTAMP               = 0x00001020
406
-	CKM_BATON_KEY_GEN                    = 0x00001030
407
-	CKM_BATON_ECB128                     = 0x00001031
408
-	CKM_BATON_ECB96                      = 0x00001032
409
-	CKM_BATON_CBC128                     = 0x00001033
410
-	CKM_BATON_COUNTER                    = 0x00001034
411
-	CKM_BATON_SHUFFLE                    = 0x00001035
412
-	CKM_BATON_WRAP                       = 0x00001036
413
-	CKM_ECDSA_KEY_PAIR_GEN               = 0x00001040
414
-	CKM_EC_KEY_PAIR_GEN                  = 0x00001040
415
-	CKM_ECDSA                            = 0x00001041
416
-	CKM_ECDSA_SHA1                       = 0x00001042
417
-	CKM_ECDH1_DERIVE                     = 0x00001050
418
-	CKM_ECDH1_COFACTOR_DERIVE            = 0x00001051
419
-	CKM_ECMQV_DERIVE                     = 0x00001052
420
-	CKM_JUNIPER_KEY_GEN                  = 0x00001060
421
-	CKM_JUNIPER_ECB128                   = 0x00001061
422
-	CKM_JUNIPER_CBC128                   = 0x00001062
423
-	CKM_JUNIPER_COUNTER                  = 0x00001063
424
-	CKM_JUNIPER_SHUFFLE                  = 0x00001064
425
-	CKM_JUNIPER_WRAP                     = 0x00001065
426
-	CKM_FASTHASH                         = 0x00001070
427
-	CKM_AES_KEY_GEN                      = 0x00001080
428
-	CKM_AES_ECB                          = 0x00001081
429
-	CKM_AES_CBC                          = 0x00001082
430
-	CKM_AES_MAC                          = 0x00001083
431
-	CKM_AES_MAC_GENERAL                  = 0x00001084
432
-	CKM_AES_CBC_PAD                      = 0x00001085
433
-	CKM_AES_CTR                          = 0x00001086
434
-	CKM_BLOWFISH_KEY_GEN                 = 0x00001090
435
-	CKM_BLOWFISH_CBC                     = 0x00001091
436
-	CKM_TWOFISH_KEY_GEN                  = 0x00001092
437
-	CKM_TWOFISH_CBC                      = 0x00001093
438
-	CKM_DES_ECB_ENCRYPT_DATA             = 0x00001100
439
-	CKM_DES_CBC_ENCRYPT_DATA             = 0x00001101
440
-	CKM_DES3_ECB_ENCRYPT_DATA            = 0x00001102
441
-	CKM_DES3_CBC_ENCRYPT_DATA            = 0x00001103
442
-	CKM_AES_ECB_ENCRYPT_DATA             = 0x00001104
443
-	CKM_AES_CBC_ENCRYPT_DATA             = 0x00001105
444
-	CKM_DSA_PARAMETER_GEN                = 0x00002000
445
-	CKM_DH_PKCS_PARAMETER_GEN            = 0x00002001
446
-	CKM_X9_42_DH_PARAMETER_GEN           = 0x00002002
447
-	CKM_VENDOR_DEFINED                   = 0x80000000
448
-	CKF_HW                               = 0x00000001
449
-	CKF_ENCRYPT                          = 0x00000100
450
-	CKF_DECRYPT                          = 0x00000200
451
-	CKF_DIGEST                           = 0x00000400
452
-	CKF_SIGN                             = 0x00000800
453
-	CKF_SIGN_RECOVER                     = 0x00001000
454
-	CKF_VERIFY                           = 0x00002000
455
-	CKF_VERIFY_RECOVER                   = 0x00004000
456
-	CKF_GENERATE                         = 0x00008000
457
-	CKF_GENERATE_KEY_PAIR                = 0x00010000
458
-	CKF_WRAP                             = 0x00020000
459
-	CKF_UNWRAP                           = 0x00040000
460
-	CKF_DERIVE                           = 0x00080000
461
-	CKF_EC_F_P                           = 0x00100000
462
-	CKF_EC_F_2M                          = 0x00200000
463
-	CKF_EC_ECPARAMETERS                  = 0x00400000
464
-	CKF_EC_NAMEDCURVE                    = 0x00800000
465
-	CKF_EC_UNCOMPRESS                    = 0x01000000
466
-	CKF_EC_COMPRESS                      = 0x02000000
467
-	CKF_EXTENSION                        = 0x80000000
468
-	CKR_OK                               = 0x00000000
469
-	CKR_CANCEL                           = 0x00000001
470
-	CKR_HOST_MEMORY                      = 0x00000002
471
-	CKR_SLOT_ID_INVALID                  = 0x00000003
472
-	CKR_GENERAL_ERROR                    = 0x00000005
473
-	CKR_FUNCTION_FAILED                  = 0x00000006
474
-	CKR_ARGUMENTS_BAD                    = 0x00000007
475
-	CKR_NO_EVENT                         = 0x00000008
476
-	CKR_NEED_TO_CREATE_THREADS           = 0x00000009
477
-	CKR_CANT_LOCK                        = 0x0000000A
478
-	CKR_ATTRIBUTE_READ_ONLY              = 0x00000010
479
-	CKR_ATTRIBUTE_SENSITIVE              = 0x00000011
480
-	CKR_ATTRIBUTE_TYPE_INVALID           = 0x00000012
481
-	CKR_ATTRIBUTE_VALUE_INVALID          = 0x00000013
482
-	CKR_DATA_INVALID                     = 0x00000020
483
-	CKR_DATA_LEN_RANGE                   = 0x00000021
484
-	CKR_DEVICE_ERROR                     = 0x00000030
485
-	CKR_DEVICE_MEMORY                    = 0x00000031
486
-	CKR_DEVICE_REMOVED                   = 0x00000032
487
-	CKR_ENCRYPTED_DATA_INVALID           = 0x00000040
488
-	CKR_ENCRYPTED_DATA_LEN_RANGE         = 0x00000041
489
-	CKR_FUNCTION_CANCELED                = 0x00000050
490
-	CKR_FUNCTION_NOT_PARALLEL            = 0x00000051
491
-	CKR_FUNCTION_NOT_SUPPORTED           = 0x00000054
492
-	CKR_KEY_HANDLE_INVALID               = 0x00000060
493
-	CKR_KEY_SIZE_RANGE                   = 0x00000062
494
-	CKR_KEY_TYPE_INCONSISTENT            = 0x00000063
495
-	CKR_KEY_NOT_NEEDED                   = 0x00000064
496
-	CKR_KEY_CHANGED                      = 0x00000065
497
-	CKR_KEY_NEEDED                       = 0x00000066
498
-	CKR_KEY_INDIGESTIBLE                 = 0x00000067
499
-	CKR_KEY_FUNCTION_NOT_PERMITTED       = 0x00000068
500
-	CKR_KEY_NOT_WRAPPABLE                = 0x00000069
501
-	CKR_KEY_UNEXTRACTABLE                = 0x0000006A
502
-	CKR_MECHANISM_INVALID                = 0x00000070
503
-	CKR_MECHANISM_PARAM_INVALID          = 0x00000071
504
-	CKR_OBJECT_HANDLE_INVALID            = 0x00000082
505
-	CKR_OPERATION_ACTIVE                 = 0x00000090
506
-	CKR_OPERATION_NOT_INITIALIZED        = 0x00000091
507
-	CKR_PIN_INCORRECT                    = 0x000000A0
508
-	CKR_PIN_INVALID                      = 0x000000A1
509
-	CKR_PIN_LEN_RANGE                    = 0x000000A2
510
-	CKR_PIN_EXPIRED                      = 0x000000A3
511
-	CKR_PIN_LOCKED                       = 0x000000A4
512
-	CKR_SESSION_CLOSED                   = 0x000000B0
513
-	CKR_SESSION_COUNT                    = 0x000000B1
514
-	CKR_SESSION_HANDLE_INVALID           = 0x000000B3
515
-	CKR_SESSION_PARALLEL_NOT_SUPPORTED   = 0x000000B4
516
-	CKR_SESSION_READ_ONLY                = 0x000000B5
517
-	CKR_SESSION_EXISTS                   = 0x000000B6
518
-	CKR_SESSION_READ_ONLY_EXISTS         = 0x000000B7
519
-	CKR_SESSION_READ_WRITE_SO_EXISTS     = 0x000000B8
520
-	CKR_SIGNATURE_INVALID                = 0x000000C0
521
-	CKR_SIGNATURE_LEN_RANGE              = 0x000000C1
522
-	CKR_TEMPLATE_INCOMPLETE              = 0x000000D0
523
-	CKR_TEMPLATE_INCONSISTENT            = 0x000000D1
524
-	CKR_TOKEN_NOT_PRESENT                = 0x000000E0
525
-	CKR_TOKEN_NOT_RECOGNIZED             = 0x000000E1
526
-	CKR_TOKEN_WRITE_PROTECTED            = 0x000000E2
527
-	CKR_UNWRAPPING_KEY_HANDLE_INVALID    = 0x000000F0
528
-	CKR_UNWRAPPING_KEY_SIZE_RANGE        = 0x000000F1
529
-	CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT = 0x000000F2
530
-	CKR_USER_ALREADY_LOGGED_IN           = 0x00000100
531
-	CKR_USER_NOT_LOGGED_IN               = 0x00000101
532
-	CKR_USER_PIN_NOT_INITIALIZED         = 0x00000102
533
-	CKR_USER_TYPE_INVALID                = 0x00000103
534
-	CKR_USER_ANOTHER_ALREADY_LOGGED_IN   = 0x00000104
535
-	CKR_USER_TOO_MANY_TYPES              = 0x00000105
536
-	CKR_WRAPPED_KEY_INVALID              = 0x00000110
537
-	CKR_WRAPPED_KEY_LEN_RANGE            = 0x00000112
538
-	CKR_WRAPPING_KEY_HANDLE_INVALID      = 0x00000113
539
-	CKR_WRAPPING_KEY_SIZE_RANGE          = 0x00000114
540
-	CKR_WRAPPING_KEY_TYPE_INCONSISTENT   = 0x00000115
541
-	CKR_RANDOM_SEED_NOT_SUPPORTED        = 0x00000120
542
-	CKR_RANDOM_NO_RNG                    = 0x00000121
543
-	CKR_DOMAIN_PARAMS_INVALID            = 0x00000130
544
-	CKR_BUFFER_TOO_SMALL                 = 0x00000150
545
-	CKR_SAVED_STATE_INVALID              = 0x00000160
546
-	CKR_INFORMATION_SENSITIVE            = 0x00000170
547
-	CKR_STATE_UNSAVEABLE                 = 0x00000180
548
-	CKR_CRYPTOKI_NOT_INITIALIZED         = 0x00000190
549
-	CKR_CRYPTOKI_ALREADY_INITIALIZED     = 0x00000191
550
-	CKR_MUTEX_BAD                        = 0x000001A0
551
-	CKR_MUTEX_NOT_LOCKED                 = 0x000001A1
552
-	CKR_NEW_PIN_MODE                     = 0x000001B0
553
-	CKR_NEXT_OTP                         = 0x000001B1
554
-	CKR_FUNCTION_REJECTED                = 0x00000200
555
-	CKR_VENDOR_DEFINED                   = 0x80000000
556
-	CKF_LIBRARY_CANT_CREATE_OS_THREADS   = 0x00000001
557
-	CKF_OS_LOCKING_OK                    = 0x00000002
558
-	CKF_DONT_BLOCK                       = 1
559
-	CKF_NEXT_OTP                         = 0x00000001
560
-	CKF_EXCLUDE_TIME                     = 0x00000002
561
-	CKF_EXCLUDE_COUNTER                  = 0x00000004
562
-	CKF_EXCLUDE_CHALLENGE                = 0x00000008
563
-	CKF_EXCLUDE_PIN                      = 0x00000010
564
-	CKF_USER_FRIENDLY_OTP                = 0x00000020
565
-)
566 1
deleted file mode 100644
... ...
@@ -1,98 +0,0 @@
1
-// Copyright 2013 Miek Gieben. All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package pkcs11
6
-
7
-// awk '/#define CKR_/{ print $3":\""$2"\"," }' pkcs11t.h
8
-
9
-var strerror = map[uint]string{
10
-	0x00000000: "CKR_OK",
11
-	0x00000001: "CKR_CANCEL",
12
-	0x00000002: "CKR_HOST_MEMORY",
13
-	0x00000003: "CKR_SLOT_ID_INVALID",
14
-	0x00000005: "CKR_GENERAL_ERROR",
15
-	0x00000006: "CKR_FUNCTION_FAILED",
16
-	0x00000007: "CKR_ARGUMENTS_BAD",
17
-	0x00000008: "CKR_NO_EVENT",
18
-	0x00000009: "CKR_NEED_TO_CREATE_THREADS",
19
-	0x0000000A: "CKR_CANT_LOCK",
20
-	0x00000010: "CKR_ATTRIBUTE_READ_ONLY",
21
-	0x00000011: "CKR_ATTRIBUTE_SENSITIVE",
22
-	0x00000012: "CKR_ATTRIBUTE_TYPE_INVALID",
23
-	0x00000013: "CKR_ATTRIBUTE_VALUE_INVALID",
24
-	0x00000020: "CKR_DATA_INVALID",
25
-	0x00000021: "CKR_DATA_LEN_RANGE",
26
-	0x00000030: "CKR_DEVICE_ERROR",
27
-	0x00000031: "CKR_DEVICE_MEMORY",
28
-	0x00000032: "CKR_DEVICE_REMOVED",
29
-	0x00000040: "CKR_ENCRYPTED_DATA_INVALID",
30
-	0x00000041: "CKR_ENCRYPTED_DATA_LEN_RANGE",
31
-	0x00000050: "CKR_FUNCTION_CANCELED",
32
-	0x00000051: "CKR_FUNCTION_NOT_PARALLEL",
33
-	0x00000054: "CKR_FUNCTION_NOT_SUPPORTED",
34
-	0x00000060: "CKR_KEY_HANDLE_INVALID",
35
-	0x00000062: "CKR_KEY_SIZE_RANGE",
36
-	0x00000063: "CKR_KEY_TYPE_INCONSISTENT",
37
-	0x00000064: "CKR_KEY_NOT_NEEDED",
38
-	0x00000065: "CKR_KEY_CHANGED",
39
-	0x00000066: "CKR_KEY_NEEDED",
40
-	0x00000067: "CKR_KEY_INDIGESTIBLE",
41
-	0x00000068: "CKR_KEY_FUNCTION_NOT_PERMITTED",
42
-	0x00000069: "CKR_KEY_NOT_WRAPPABLE",
43
-	0x0000006A: "CKR_KEY_UNEXTRACTABLE",
44
-	0x00000070: "CKR_MECHANISM_INVALID",
45
-	0x00000071: "CKR_MECHANISM_PARAM_INVALID",
46
-	0x00000082: "CKR_OBJECT_HANDLE_INVALID",
47
-	0x00000090: "CKR_OPERATION_ACTIVE",
48
-	0x00000091: "CKR_OPERATION_NOT_INITIALIZED",
49
-	0x000000A0: "CKR_PIN_INCORRECT",
50
-	0x000000A1: "CKR_PIN_INVALID",
51
-	0x000000A2: "CKR_PIN_LEN_RANGE",
52
-	0x000000A3: "CKR_PIN_EXPIRED",
53
-	0x000000A4: "CKR_PIN_LOCKED",
54
-	0x000000B0: "CKR_SESSION_CLOSED",
55
-	0x000000B1: "CKR_SESSION_COUNT",
56
-	0x000000B3: "CKR_SESSION_HANDLE_INVALID",
57
-	0x000000B4: "CKR_SESSION_PARALLEL_NOT_SUPPORTED",
58
-	0x000000B5: "CKR_SESSION_READ_ONLY",
59
-	0x000000B6: "CKR_SESSION_EXISTS",
60
-	0x000000B7: "CKR_SESSION_READ_ONLY_EXISTS",
61
-	0x000000B8: "CKR_SESSION_READ_WRITE_SO_EXISTS",
62
-	0x000000C0: "CKR_SIGNATURE_INVALID",
63
-	0x000000C1: "CKR_SIGNATURE_LEN_RANGE",
64
-	0x000000D0: "CKR_TEMPLATE_INCOMPLETE",
65
-	0x000000D1: "CKR_TEMPLATE_INCONSISTENT",
66
-	0x000000E0: "CKR_TOKEN_NOT_PRESENT",
67
-	0x000000E1: "CKR_TOKEN_NOT_RECOGNIZED",
68
-	0x000000E2: "CKR_TOKEN_WRITE_PROTECTED",
69
-	0x000000F0: "CKR_UNWRAPPING_KEY_HANDLE_INVALID",
70
-	0x000000F1: "CKR_UNWRAPPING_KEY_SIZE_RANGE",
71
-	0x000000F2: "CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT",
72
-	0x00000100: "CKR_USER_ALREADY_LOGGED_IN",
73
-	0x00000101: "CKR_USER_NOT_LOGGED_IN",
74
-	0x00000102: "CKR_USER_PIN_NOT_INITIALIZED",
75
-	0x00000103: "CKR_USER_TYPE_INVALID",
76
-	0x00000104: "CKR_USER_ANOTHER_ALREADY_LOGGED_IN",
77
-	0x00000105: "CKR_USER_TOO_MANY_TYPES",
78
-	0x00000110: "CKR_WRAPPED_KEY_INVALID",
79
-	0x00000112: "CKR_WRAPPED_KEY_LEN_RANGE",
80
-	0x00000113: "CKR_WRAPPING_KEY_HANDLE_INVALID",
81
-	0x00000114: "CKR_WRAPPING_KEY_SIZE_RANGE",
82
-	0x00000115: "CKR_WRAPPING_KEY_TYPE_INCONSISTENT",
83
-	0x00000120: "CKR_RANDOM_SEED_NOT_SUPPORTED",
84
-	0x00000121: "CKR_RANDOM_NO_RNG",
85
-	0x00000130: "CKR_DOMAIN_PARAMS_INVALID",
86
-	0x00000150: "CKR_BUFFER_TOO_SMALL",
87
-	0x00000160: "CKR_SAVED_STATE_INVALID",
88
-	0x00000170: "CKR_INFORMATION_SENSITIVE",
89
-	0x00000180: "CKR_STATE_UNSAVEABLE",
90
-	0x00000190: "CKR_CRYPTOKI_NOT_INITIALIZED",
91
-	0x00000191: "CKR_CRYPTOKI_ALREADY_INITIALIZED",
92
-	0x000001A0: "CKR_MUTEX_BAD",
93
-	0x000001A1: "CKR_MUTEX_NOT_LOCKED",
94
-	0x000001B0: "CKR_NEW_PIN_MODE",
95
-	0x000001B1: "CKR_NEXT_OTP",
96
-	0x00000200: "CKR_FUNCTION_REJECTED",
97
-	0x80000000: "CKR_VENDOR_DEFINED",
98
-}
99 1
deleted file mode 100644
... ...
@@ -1,1575 +0,0 @@
1
-// Copyright 2013 Miek Gieben. All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-// Package pkcs11 is a wrapper around the PKCS#11 cryptographic library.
6
-package pkcs11
7
-
8
-// It is *assumed*, that:
9
-//
10
-// * Go's uint size == PKCS11's CK_ULONG size
11
-// * CK_ULONG never overflows an Go int
12
-
13
-/*
14
-#cgo LDFLAGS: -lltdl
15
-#define CK_PTR *
16
-#ifndef NULL_PTR
17
-#define NULL_PTR 0
18
-#endif
19
-#define CK_DEFINE_FUNCTION(returnType, name) returnType name
20
-#define CK_DECLARE_FUNCTION(returnType, name) returnType name
21
-#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
22
-#define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
23
-
24
-#include <stdlib.h>
25
-#include <stdio.h>
26
-#include <ltdl.h>
27
-#include <unistd.h>
28
-#include "pkcs11.h"
29
-
30
-struct ctx {
31
-	lt_dlhandle handle;
32
-	CK_FUNCTION_LIST_PTR sym;
33
-};
34
-
35
-// New initializes a ctx and fills the symbol table.
36
-struct ctx *New(const char *module)
37
-{
38
-	if (lt_dlinit() != 0) {
39
-		return NULL;
40
-	}
41
-	CK_C_GetFunctionList list;
42
-	struct ctx *c = calloc(1, sizeof(struct ctx));
43
-	c->handle = lt_dlopen(module);
44
-	if (c->handle == NULL) {
45
-		free(c);
46
-		return NULL;
47
-	}
48
-	list = (CK_C_GetFunctionList) lt_dlsym(c->handle, "C_GetFunctionList");
49
-	if (list == NULL) {
50
-		free(c);
51
-		return NULL;
52
-	}
53
-	list(&c->sym);
54
-	return c;
55
-}
56
-
57
-// Destroy cleans up a ctx.
58
-void Destroy(struct ctx *c)
59
-{
60
-	if (!c) {
61
-		return;
62
-	}
63
-	if (c->handle == NULL) {
64
-		return;
65
-	}
66
-	if (lt_dlclose(c->handle) < 0) {
67
-		return;
68
-	}
69
-	lt_dlexit();
70
-	free(c);
71
-}
72
-
73
-CK_RV Initialize(struct ctx * c, CK_VOID_PTR initArgs)
74
-{
75
-	return c->sym->C_Initialize(initArgs);
76
-}
77
-
78
-CK_RV Finalize(struct ctx * c)
79
-{
80
-	return c->sym->C_Finalize(NULL);
81
-}
82
-
83
-CK_RV GetInfo(struct ctx * c, CK_INFO_PTR info)
84
-{
85
-	return c->sym->C_GetInfo(info);
86
-}
87
-
88
-CK_RV GetSlotList(struct ctx * c, CK_BBOOL tokenPresent,
89
-		  CK_ULONG_PTR * slotList, CK_ULONG_PTR ulCount)
90
-{
91
-	CK_RV e = c->sym->C_GetSlotList(tokenPresent, NULL, ulCount);
92
-	if (e != CKR_OK) {
93
-		return e;
94
-	}
95
-	*slotList = calloc(*ulCount, sizeof(CK_SLOT_ID));
96
-	e = c->sym->C_GetSlotList(tokenPresent, *slotList, ulCount);
97
-	return e;
98
-}
99
-
100
-CK_RV GetSlotInfo(struct ctx * c, CK_ULONG slotID, CK_SLOT_INFO_PTR info)
101
-{
102
-	CK_RV e = c->sym->C_GetSlotInfo((CK_SLOT_ID) slotID, info);
103
-	return e;
104
-}
105
-
106
-CK_RV GetTokenInfo(struct ctx * c, CK_ULONG slotID, CK_TOKEN_INFO_PTR info)
107
-{
108
-	CK_RV e = c->sym->C_GetTokenInfo((CK_SLOT_ID) slotID, info);
109
-	return e;
110
-}
111
-
112
-CK_RV GetMechanismList(struct ctx * c, CK_ULONG slotID,
113
-		       CK_ULONG_PTR * mech, CK_ULONG_PTR mechlen)
114
-{
115
-	CK_RV e =
116
-	    c->sym->C_GetMechanismList((CK_SLOT_ID) slotID, NULL, mechlen);
117
-	if (e != CKR_OK) {
118
-		return e;
119
-	}
120
-	*mech = calloc(*mechlen, sizeof(CK_MECHANISM_TYPE));
121
-	e = c->sym->C_GetMechanismList((CK_SLOT_ID) slotID,
122
-				       (CK_MECHANISM_TYPE_PTR) * mech, mechlen);
123
-	return e;
124
-}
125
-
126
-CK_RV GetMechanismInfo(struct ctx * c, CK_ULONG slotID, CK_MECHANISM_TYPE mech,
127
-		       CK_MECHANISM_INFO_PTR info)
128
-{
129
-	CK_RV e = c->sym->C_GetMechanismInfo((CK_SLOT_ID) slotID, mech, info);
130
-	return e;
131
-}
132
-
133
-CK_RV InitToken(struct ctx * c, CK_ULONG slotID, char *pin, CK_ULONG pinlen,
134
-		char *label)
135
-{
136
-	CK_RV e =
137
-	    c->sym->C_InitToken((CK_SLOT_ID) slotID, (CK_UTF8CHAR_PTR) pin,
138
-				pinlen, (CK_UTF8CHAR_PTR) label);
139
-	return e;
140
-}
141
-
142
-CK_RV InitPIN(struct ctx * c, CK_SESSION_HANDLE sh, char *pin, CK_ULONG pinlen)
143
-{
144
-	CK_RV e = c->sym->C_InitPIN(sh, (CK_UTF8CHAR_PTR) pin, pinlen);
145
-	return e;
146
-}
147
-
148
-CK_RV SetPIN(struct ctx * c, CK_SESSION_HANDLE sh, char *oldpin,
149
-	     CK_ULONG oldpinlen, char *newpin, CK_ULONG newpinlen)
150
-{
151
-	CK_RV e = c->sym->C_SetPIN(sh, (CK_UTF8CHAR_PTR) oldpin, oldpinlen,
152
-				   (CK_UTF8CHAR_PTR) newpin, newpinlen);
153
-	return e;
154
-}
155
-
156
-CK_RV OpenSession(struct ctx * c, CK_ULONG slotID, CK_ULONG flags,
157
-		  CK_SESSION_HANDLE_PTR session)
158
-{
159
-	CK_RV e =
160
-	    c->sym->C_OpenSession((CK_SLOT_ID) slotID, (CK_FLAGS) flags, NULL,
161
-				  NULL, session);
162
-	return e;
163
-}
164
-
165
-CK_RV CloseSession(struct ctx * c, CK_SESSION_HANDLE session)
166
-{
167
-	CK_RV e = c->sym->C_CloseSession(session);
168
-	return e;
169
-}
170
-
171
-CK_RV CloseAllSessions(struct ctx * c, CK_ULONG slotID)
172
-{
173
-	CK_RV e = c->sym->C_CloseAllSessions(slotID);
174
-	return e;
175
-}
176
-
177
-CK_RV GetSessionInfo(struct ctx * c, CK_SESSION_HANDLE session,
178
-		     CK_SESSION_INFO_PTR info)
179
-{
180
-	CK_RV e = c->sym->C_GetSessionInfo(session, info);
181
-	return e;
182
-}
183
-
184
-CK_RV GetOperationState(struct ctx * c, CK_SESSION_HANDLE session,
185
-			CK_BYTE_PTR * state, CK_ULONG_PTR statelen)
186
-{
187
-	CK_RV rv = c->sym->C_GetOperationState(session, NULL, statelen);
188
-	if (rv != CKR_OK) {
189
-		return rv;
190
-	}
191
-	*state = calloc(*statelen, sizeof(CK_BYTE));
192
-	if (*state == NULL) {
193
-		return CKR_HOST_MEMORY;
194
-	}
195
-	rv = c->sym->C_GetOperationState(session, *state, statelen);
196
-	return rv;
197
-}
198
-
199
-CK_RV SetOperationState(struct ctx * c, CK_SESSION_HANDLE session,
200
-			CK_BYTE_PTR state, CK_ULONG statelen,
201
-			CK_OBJECT_HANDLE encryptkey, CK_OBJECT_HANDLE authkey)
202
-{
203
-	return c->sym->C_SetOperationState(session, state, statelen, encryptkey,
204
-					   authkey);
205
-}
206
-
207
-CK_RV Login(struct ctx *c, CK_SESSION_HANDLE session, CK_USER_TYPE userType,
208
-	    char *pin, CK_ULONG pinLen)
209
-{
210
-	if (pinLen == 0) {
211
-		pin = NULL;
212
-	}
213
-	CK_RV e =
214
-	    c->sym->C_Login(session, userType, (CK_UTF8CHAR_PTR) pin, pinLen);
215
-	return e;
216
-}
217
-
218
-CK_RV Logout(struct ctx * c, CK_SESSION_HANDLE session)
219
-{
220
-	CK_RV e = c->sym->C_Logout(session);
221
-	return e;
222
-}
223
-
224
-CK_RV CreateObject(struct ctx * c, CK_SESSION_HANDLE session,
225
-		   CK_ATTRIBUTE_PTR temp, CK_ULONG tempCount,
226
-		   CK_OBJECT_HANDLE_PTR obj)
227
-{
228
-	CK_RV e = c->sym->C_CreateObject(session, temp, tempCount, obj);
229
-	return e;
230
-}
231
-
232
-CK_RV CopyObject(struct ctx * c, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE o,
233
-		 CK_ATTRIBUTE_PTR temp, CK_ULONG tempCount,
234
-		 CK_OBJECT_HANDLE_PTR obj)
235
-{
236
-	CK_RV e = c->sym->C_CopyObject(session, o, temp, tempCount, obj);
237
-	return e;
238
-}
239
-
240
-CK_RV DestroyObject(struct ctx * c, CK_SESSION_HANDLE session,
241
-		    CK_OBJECT_HANDLE object)
242
-{
243
-	CK_RV e = c->sym->C_DestroyObject(session, object);
244
-	return e;
245
-}
246
-
247
-CK_RV GetObjectSize(struct ctx * c, CK_SESSION_HANDLE session,
248
-		    CK_OBJECT_HANDLE object, CK_ULONG_PTR size)
249
-{
250
-	CK_RV e = c->sym->C_GetObjectSize(session, object, size);
251
-	return e;
252
-}
253
-
254
-CK_RV GetAttributeValue(struct ctx * c, CK_SESSION_HANDLE session,
255
-			CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR temp,
256
-			CK_ULONG templen)
257
-{
258
-	// Call for the first time, check the returned ulValue in the attributes, then
259
-	// allocate enough space and try again.
260
-	CK_RV e = c->sym->C_GetAttributeValue(session, object, temp, templen);
261
-	if (e != CKR_OK) {
262
-		return e;
263
-	}
264
-	CK_ULONG i;
265
-	for (i = 0; i < templen; i++) {
266
-		if ((CK_LONG) temp[i].ulValueLen == -1) {
267
-			// either access denied or no such object
268
-			continue;
269
-		}
270
-		temp[i].pValue = calloc(temp[i].ulValueLen, sizeof(CK_BYTE));
271
-	}
272
-	e = c->sym->C_GetAttributeValue(session, object, temp, templen);
273
-	return e;
274
-}
275
-
276
-CK_RV SetAttributeValue(struct ctx * c, CK_SESSION_HANDLE session,
277
-			CK_OBJECT_HANDLE object, CK_ATTRIBUTE_PTR temp,
278
-			CK_ULONG templen)
279
-{
280
-	CK_RV e = c->sym->C_SetAttributeValue(session, object, temp, templen);
281
-	return e;
282
-}
283
-
284
-CK_RV FindObjectsInit(struct ctx * c, CK_SESSION_HANDLE session,
285
-		      CK_ATTRIBUTE_PTR temp, CK_ULONG tempCount)
286
-{
287
-	CK_RV e = c->sym->C_FindObjectsInit(session, temp, tempCount);
288
-	return e;
289
-}
290
-
291
-CK_RV FindObjects(struct ctx * c, CK_SESSION_HANDLE session,
292
-		  CK_OBJECT_HANDLE_PTR * obj, CK_ULONG max,
293
-		  CK_ULONG_PTR objCount)
294
-{
295
-	*obj = calloc(max, sizeof(CK_OBJECT_HANDLE));
296
-	CK_RV e = c->sym->C_FindObjects(session, *obj, max, objCount);
297
-	return e;
298
-}
299
-
300
-CK_RV FindObjectsFinal(struct ctx * c, CK_SESSION_HANDLE session)
301
-{
302
-	CK_RV e = c->sym->C_FindObjectsFinal(session);
303
-	return e;
304
-}
305
-
306
-CK_RV EncryptInit(struct ctx * c, CK_SESSION_HANDLE session,
307
-		  CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key)
308
-{
309
-	CK_RV e = c->sym->C_EncryptInit(session, mechanism, key);
310
-	return e;
311
-}
312
-
313
-CK_RV Encrypt(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR message,
314
-	      CK_ULONG mlen, CK_BYTE_PTR * enc, CK_ULONG_PTR enclen)
315
-{
316
-	CK_RV rv = c->sym->C_Encrypt(session, message, mlen, NULL, enclen);
317
-	if (rv != CKR_OK) {
318
-		return rv;
319
-	}
320
-	*enc = calloc(*enclen, sizeof(CK_BYTE));
321
-	if (*enc == NULL) {
322
-		return CKR_HOST_MEMORY;
323
-	}
324
-	rv = c->sym->C_Encrypt(session, message, mlen, *enc, enclen);
325
-	return rv;
326
-}
327
-
328
-CK_RV EncryptUpdate(struct ctx * c, CK_SESSION_HANDLE session,
329
-		    CK_BYTE_PTR plain, CK_ULONG plainlen, CK_BYTE_PTR * cipher,
330
-		    CK_ULONG_PTR cipherlen)
331
-{
332
-	CK_RV rv =
333
-	    c->sym->C_EncryptUpdate(session, plain, plainlen, NULL, cipherlen);
334
-	if (rv != CKR_OK) {
335
-		return rv;
336
-	}
337
-	*cipher = calloc(*cipherlen, sizeof(CK_BYTE));
338
-	if (*cipher == NULL) {
339
-		return CKR_HOST_MEMORY;
340
-	}
341
-	rv = c->sym->C_EncryptUpdate(session, plain, plainlen, *cipher,
342
-				     cipherlen);
343
-	return rv;
344
-}
345
-
346
-CK_RV EncryptFinal(struct ctx * c, CK_SESSION_HANDLE session,
347
-		   CK_BYTE_PTR * cipher, CK_ULONG_PTR cipherlen)
348
-{
349
-	CK_RV rv = c->sym->C_EncryptFinal(session, NULL, cipherlen);
350
-	if (rv != CKR_OK) {
351
-		return rv;
352
-	}
353
-	*cipher = calloc(*cipherlen, sizeof(CK_BYTE));
354
-	if (*cipher == NULL) {
355
-		return CKR_HOST_MEMORY;
356
-	}
357
-	rv = c->sym->C_EncryptFinal(session, *cipher, cipherlen);
358
-	return rv;
359
-}
360
-
361
-CK_RV DecryptInit(struct ctx * c, CK_SESSION_HANDLE session,
362
-		  CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key)
363
-{
364
-	CK_RV e = c->sym->C_DecryptInit(session, mechanism, key);
365
-	return e;
366
-}
367
-
368
-CK_RV Decrypt(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR cypher,
369
-	      CK_ULONG clen, CK_BYTE_PTR * plain, CK_ULONG_PTR plainlen)
370
-{
371
-	CK_RV e = c->sym->C_Decrypt(session, cypher, clen, NULL, plainlen);
372
-	if (e != CKR_OK) {
373
-		return e;
374
-	}
375
-	*plain = calloc(*plainlen, sizeof(CK_BYTE));
376
-	if (*plain == NULL) {
377
-		return CKR_HOST_MEMORY;
378
-	}
379
-	e = c->sym->C_Decrypt(session, cypher, clen, *plain, plainlen);
380
-	return e;
381
-}
382
-
383
-CK_RV DecryptUpdate(struct ctx * c, CK_SESSION_HANDLE session,
384
-		    CK_BYTE_PTR cipher, CK_ULONG cipherlen, CK_BYTE_PTR * part,
385
-		    CK_ULONG_PTR partlen)
386
-{
387
-	CK_RV rv =
388
-	    c->sym->C_DecryptUpdate(session, cipher, cipherlen, NULL, partlen);
389
-	if (rv != CKR_OK) {
390
-		return rv;
391
-	}
392
-	*part = calloc(*partlen, sizeof(CK_BYTE));
393
-	if (*part == NULL) {
394
-		return CKR_HOST_MEMORY;
395
-	}
396
-	rv = c->sym->C_DecryptUpdate(session, cipher, cipherlen, *part,
397
-				     partlen);
398
-	return rv;
399
-}
400
-
401
-CK_RV DecryptFinal(struct ctx * c, CK_SESSION_HANDLE session,
402
-		   CK_BYTE_PTR * plain, CK_ULONG_PTR plainlen)
403
-{
404
-	CK_RV rv = c->sym->C_DecryptFinal(session, NULL, plainlen);
405
-	if (rv != CKR_OK) {
406
-		return rv;
407
-	}
408
-	*plain = calloc(*plainlen, sizeof(CK_BYTE));
409
-	if (*plain == NULL) {
410
-		return CKR_HOST_MEMORY;
411
-	}
412
-	rv = c->sym->C_DecryptFinal(session, *plain, plainlen);
413
-	return rv;
414
-}
415
-
416
-CK_RV DigestInit(struct ctx * c, CK_SESSION_HANDLE session,
417
-		 CK_MECHANISM_PTR mechanism)
418
-{
419
-	CK_RV e = c->sym->C_DigestInit(session, mechanism);
420
-	return e;
421
-}
422
-
423
-CK_RV Digest(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR message,
424
-	     CK_ULONG mlen, CK_BYTE_PTR * hash, CK_ULONG_PTR hashlen)
425
-{
426
-	CK_RV rv = c->sym->C_Digest(session, message, mlen, NULL, hashlen);
427
-	if (rv != CKR_OK) {
428
-		return rv;
429
-	}
430
-	*hash = calloc(*hashlen, sizeof(CK_BYTE));
431
-	if (*hash == NULL) {
432
-		return CKR_HOST_MEMORY;
433
-	}
434
-	rv = c->sym->C_Digest(session, message, mlen, *hash, hashlen);
435
-	return rv;
436
-}
437
-
438
-CK_RV DigestUpdate(struct ctx * c, CK_SESSION_HANDLE session,
439
-		   CK_BYTE_PTR message, CK_ULONG mlen)
440
-{
441
-	CK_RV rv = c->sym->C_DigestUpdate(session, message, mlen);
442
-	return rv;
443
-}
444
-
445
-CK_RV DigestKey(struct ctx * c, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key)
446
-{
447
-	CK_RV rv = c->sym->C_DigestKey(session, key);
448
-	return rv;
449
-}
450
-
451
-CK_RV DigestFinal(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR * hash,
452
-		  CK_ULONG_PTR hashlen)
453
-{
454
-	CK_RV rv = c->sym->C_DigestFinal(session, NULL, hashlen);
455
-	if (rv != CKR_OK) {
456
-		return rv;
457
-	}
458
-	*hash = calloc(*hashlen, sizeof(CK_BYTE));
459
-	if (*hash == NULL) {
460
-		return CKR_HOST_MEMORY;
461
-	}
462
-	rv = c->sym->C_DigestFinal(session, *hash, hashlen);
463
-	return rv;
464
-}
465
-
466
-CK_RV SignInit(struct ctx * c, CK_SESSION_HANDLE session,
467
-	       CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE key)
468
-{
469
-	CK_RV e = c->sym->C_SignInit(session, mechanism, key);
470
-	return e;
471
-}
472
-
473
-CK_RV Sign(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR message,
474
-	   CK_ULONG mlen, CK_BYTE_PTR * sig, CK_ULONG_PTR siglen)
475
-{
476
-	CK_RV rv = c->sym->C_Sign(session, message, mlen, NULL, siglen);
477
-	if (rv != CKR_OK) {
478
-		return rv;
479
-	}
480
-	*sig = calloc(*siglen, sizeof(CK_BYTE));
481
-	if (*sig == NULL) {
482
-		return CKR_HOST_MEMORY;
483
-	}
484
-	rv = c->sym->C_Sign(session, message, mlen, *sig, siglen);
485
-	return rv;
486
-}
487
-
488
-CK_RV SignUpdate(struct ctx * c, CK_SESSION_HANDLE session,
489
-		 CK_BYTE_PTR message, CK_ULONG mlen)
490
-{
491
-	CK_RV rv = c->sym->C_SignUpdate(session, message, mlen);
492
-	return rv;
493
-}
494
-
495
-CK_RV SignFinal(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR * sig,
496
-		CK_ULONG_PTR siglen)
497
-{
498
-	CK_RV rv = c->sym->C_SignFinal(session, NULL, siglen);
499
-	if (rv != CKR_OK) {
500
-		return rv;
501
-	}
502
-	*sig = calloc(*siglen, sizeof(CK_BYTE));
503
-	if (*sig == NULL) {
504
-		return CKR_HOST_MEMORY;
505
-	}
506
-	rv = c->sym->C_SignFinal(session, *sig, siglen);
507
-	return rv;
508
-}
509
-
510
-CK_RV SignRecoverInit(struct ctx * c, CK_SESSION_HANDLE session,
511
-		      CK_MECHANISM_PTR mech, CK_OBJECT_HANDLE key)
512
-{
513
-	CK_RV rv = c->sym->C_SignRecoverInit(session, mech, key);
514
-	return rv;
515
-}
516
-
517
-CK_RV SignRecover(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR data,
518
-		  CK_ULONG datalen, CK_BYTE_PTR * sig, CK_ULONG_PTR siglen)
519
-{
520
-	CK_RV rv = c->sym->C_SignRecover(session, data, datalen, NULL, siglen);
521
-	if (rv != CKR_OK) {
522
-		return rv;
523
-	}
524
-	*sig = calloc(*siglen, sizeof(CK_BYTE));
525
-	if (*sig == NULL) {
526
-		return CKR_HOST_MEMORY;
527
-	}
528
-	rv = c->sym->C_SignRecover(session, data, datalen, *sig, siglen);
529
-	return rv;
530
-}
531
-
532
-CK_RV VerifyInit(struct ctx * c, CK_SESSION_HANDLE session,
533
-		 CK_MECHANISM_PTR mech, CK_OBJECT_HANDLE key)
534
-{
535
-	CK_RV rv = c->sym->C_VerifyInit(session, mech, key);
536
-	return rv;
537
-}
538
-
539
-CK_RV Verify(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR message,
540
-	     CK_ULONG mesglen, CK_BYTE_PTR sig, CK_ULONG siglen)
541
-{
542
-	CK_RV rv = c->sym->C_Verify(session, message, mesglen, sig, siglen);
543
-	return rv;
544
-}
545
-
546
-CK_RV VerifyUpdate(struct ctx * c, CK_SESSION_HANDLE session,
547
-		   CK_BYTE_PTR part, CK_ULONG partlen)
548
-{
549
-	CK_RV rv = c->sym->C_VerifyUpdate(session, part, partlen);
550
-	return rv;
551
-}
552
-
553
-CK_RV VerifyFinal(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR sig,
554
-		  CK_ULONG siglen)
555
-{
556
-	CK_RV rv = c->sym->C_VerifyFinal(session, sig, siglen);
557
-	return rv;
558
-}
559
-
560
-CK_RV VerifyRecoverInit(struct ctx * c, CK_SESSION_HANDLE session,
561
-			CK_MECHANISM_PTR mech, CK_OBJECT_HANDLE key)
562
-{
563
-	CK_RV rv = c->sym->C_VerifyRecoverInit(session, mech, key);
564
-	return rv;
565
-}
566
-
567
-CK_RV VerifyRecover(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR sig,
568
-		    CK_ULONG siglen, CK_BYTE_PTR * data, CK_ULONG_PTR datalen)
569
-{
570
-	CK_RV rv = c->sym->C_VerifyRecover(session, sig, siglen, NULL, datalen);
571
-	if (rv != CKR_OK) {
572
-		return rv;
573
-	}
574
-	*data = calloc(*datalen, sizeof(CK_BYTE));
575
-	if (*data == NULL) {
576
-		return CKR_HOST_MEMORY;
577
-	}
578
-	rv = c->sym->C_VerifyRecover(session, sig, siglen, *data, datalen);
579
-	return rv;
580
-}
581
-
582
-CK_RV DigestEncryptUpdate(struct ctx * c, CK_SESSION_HANDLE session,
583
-			  CK_BYTE_PTR part, CK_ULONG partlen, CK_BYTE_PTR * enc,
584
-			  CK_ULONG_PTR enclen)
585
-{
586
-	CK_RV rv =
587
-	    c->sym->C_DigestEncryptUpdate(session, part, partlen, NULL, enclen);
588
-	if (rv != CKR_OK) {
589
-		return rv;
590
-	}
591
-	*enc = calloc(*enclen, sizeof(CK_BYTE));
592
-	if (*enc == NULL) {
593
-		return CKR_HOST_MEMORY;
594
-	}
595
-	rv = c->sym->C_DigestEncryptUpdate(session, part, partlen, *enc,
596
-					   enclen);
597
-	return rv;
598
-}
599
-
600
-CK_RV DecryptDigestUpdate(struct ctx * c, CK_SESSION_HANDLE session,
601
-			  CK_BYTE_PTR cipher, CK_ULONG cipherlen,
602
-			  CK_BYTE_PTR * part, CK_ULONG_PTR partlen)
603
-{
604
-	CK_RV rv =
605
-	    c->sym->C_DecryptDigestUpdate(session, cipher, cipherlen, NULL,
606
-					  partlen);
607
-	if (rv != CKR_OK) {
608
-		return rv;
609
-	}
610
-	*part = calloc(*partlen, sizeof(CK_BYTE));
611
-	if (*part == NULL) {
612
-		return CKR_HOST_MEMORY;
613
-	}
614
-	rv = c->sym->C_DecryptDigestUpdate(session, cipher, cipherlen, *part,
615
-					   partlen);
616
-	return rv;
617
-}
618
-
619
-CK_RV SignEncryptUpdate(struct ctx * c, CK_SESSION_HANDLE session,
620
-			CK_BYTE_PTR part, CK_ULONG partlen, CK_BYTE_PTR * enc,
621
-			CK_ULONG_PTR enclen)
622
-{
623
-	CK_RV rv =
624
-	    c->sym->C_SignEncryptUpdate(session, part, partlen, NULL, enclen);
625
-	if (rv != CKR_OK) {
626
-		return rv;
627
-	}
628
-	*enc = calloc(*enclen, sizeof(CK_BYTE));
629
-	if (*enc == NULL) {
630
-		return CKR_HOST_MEMORY;
631
-	}
632
-	rv = c->sym->C_SignEncryptUpdate(session, part, partlen, *enc, enclen);
633
-	return rv;
634
-}
635
-
636
-CK_RV DecryptVerifyUpdate(struct ctx * c, CK_SESSION_HANDLE session,
637
-			  CK_BYTE_PTR cipher, CK_ULONG cipherlen,
638
-			  CK_BYTE_PTR * part, CK_ULONG_PTR partlen)
639
-{
640
-	CK_RV rv =
641
-	    c->sym->C_DecryptVerifyUpdate(session, cipher, cipherlen, NULL,
642
-					  partlen);
643
-	if (rv != CKR_OK) {
644
-		return rv;
645
-	}
646
-	*part = calloc(*partlen, sizeof(CK_BYTE));
647
-	if (*part == NULL) {
648
-		return CKR_HOST_MEMORY;
649
-	}
650
-	rv = c->sym->C_DecryptVerifyUpdate(session, cipher, cipherlen, *part,
651
-					   partlen);
652
-	return rv;
653
-}
654
-
655
-CK_RV GenerateKey(struct ctx * c, CK_SESSION_HANDLE session,
656
-		  CK_MECHANISM_PTR mechanism, CK_ATTRIBUTE_PTR temp,
657
-		  CK_ULONG tempCount, CK_OBJECT_HANDLE_PTR key)
658
-{
659
-	CK_RV e =
660
-	    c->sym->C_GenerateKey(session, mechanism, temp, tempCount, key);
661
-	return e;
662
-}
663
-
664
-CK_RV GenerateKeyPair(struct ctx * c, CK_SESSION_HANDLE session,
665
-		      CK_MECHANISM_PTR mechanism, CK_ATTRIBUTE_PTR pub,
666
-		      CK_ULONG pubCount, CK_ATTRIBUTE_PTR priv,
667
-		      CK_ULONG privCount, CK_OBJECT_HANDLE_PTR pubkey,
668
-		      CK_OBJECT_HANDLE_PTR privkey)
669
-{
670
-	CK_RV e =
671
-	    c->sym->C_GenerateKeyPair(session, mechanism, pub, pubCount, priv,
672
-				      privCount,
673
-				      pubkey, privkey);
674
-	return e;
675
-}
676
-
677
-CK_RV WrapKey(struct ctx * c, CK_SESSION_HANDLE session,
678
-	      CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE wrappingkey,
679
-	      CK_OBJECT_HANDLE key, CK_BYTE_PTR * wrapped,
680
-	      CK_ULONG_PTR wrappedlen)
681
-{
682
-	CK_RV rv = c->sym->C_WrapKey(session, mechanism, wrappingkey, key, NULL,
683
-				     wrappedlen);
684
-	if (rv != CKR_OK) {
685
-		return rv;
686
-	}
687
-	*wrapped = calloc(*wrappedlen, sizeof(CK_BYTE));
688
-	if (*wrapped == NULL) {
689
-		return CKR_HOST_MEMORY;
690
-	}
691
-	rv = c->sym->C_WrapKey(session, mechanism, wrappingkey, key, *wrapped,
692
-			       wrappedlen);
693
-	return rv;
694
-}
695
-
696
-CK_RV DeriveKey(struct ctx * c, CK_SESSION_HANDLE session,
697
-		CK_MECHANISM_PTR mech, CK_OBJECT_HANDLE basekey,
698
-		CK_ATTRIBUTE_PTR a, CK_ULONG alen, CK_OBJECT_HANDLE_PTR key)
699
-{
700
-	CK_RV e = c->sym->C_DeriveKey(session, mech, basekey, a, alen, key);
701
-	return e;
702
-}
703
-
704
-CK_RV UnwrapKey(struct ctx * c, CK_SESSION_HANDLE session,
705
-		CK_MECHANISM_PTR mech, CK_OBJECT_HANDLE unwrappingkey,
706
-		CK_BYTE_PTR wrappedkey, CK_ULONG wrappedkeylen,
707
-		CK_ATTRIBUTE_PTR a, CK_ULONG alen, CK_OBJECT_HANDLE_PTR key)
708
-{
709
-	CK_RV e = c->sym->C_UnwrapKey(session, mech, unwrappingkey, wrappedkey,
710
-				      wrappedkeylen, a, alen, key);
711
-	return e;
712
-}
713
-
714
-CK_RV SeedRandom(struct ctx * c, CK_SESSION_HANDLE session, CK_BYTE_PTR seed,
715
-		 CK_ULONG seedlen)
716
-{
717
-	CK_RV e = c->sym->C_SeedRandom(session, seed, seedlen);
718
-	return e;
719
-}
720
-
721
-CK_RV GenerateRandom(struct ctx * c, CK_SESSION_HANDLE session,
722
-		     CK_BYTE_PTR * rand, CK_ULONG length)
723
-{
724
-	*rand = calloc(length, sizeof(CK_BYTE));
725
-	if (*rand == NULL) {
726
-		return CKR_HOST_MEMORY;
727
-	}
728
-	CK_RV e = c->sym->C_GenerateRandom(session, *rand, length);
729
-	return e;
730
-}
731
-
732
-CK_RV WaitForSlotEvent(struct ctx * c, CK_FLAGS flags, CK_ULONG_PTR slot)
733
-{
734
-	CK_RV e =
735
-	    c->sym->C_WaitForSlotEvent(flags, (CK_SLOT_ID_PTR) slot, NULL);
736
-	return e;
737
-}
738
-*/
739
-import "C"
740
-import "strings"
741
-
742
-import "unsafe"
743
-
744
-// Ctx contains the current pkcs11 context.
745
-type Ctx struct {
746
-	ctx *C.struct_ctx
747
-}
748
-
749
-// New creates a new context and initializes the module/library for use.
750
-func New(module string) *Ctx {
751
-	c := new(Ctx)
752
-	mod := C.CString(module)
753
-	defer C.free(unsafe.Pointer(mod))
754
-	c.ctx = C.New(mod)
755
-	if c.ctx == nil {
756
-		return nil
757
-	}
758
-	return c
759
-}
760
-
761
-// Destroy unloads the module/library and frees any remaining memory.
762
-func (c *Ctx) Destroy() {
763
-	if c == nil || c.ctx == nil {
764
-		return
765
-	}
766
-	C.Destroy(c.ctx)
767
-	c.ctx = nil
768
-}
769
-
770
-/* Initialize initializes the Cryptoki library. */
771
-func (c *Ctx) Initialize() error {
772
-	args := &C.CK_C_INITIALIZE_ARGS{nil, nil, nil, nil, C.CKF_OS_LOCKING_OK, nil}
773
-	e := C.Initialize(c.ctx, C.CK_VOID_PTR(args))
774
-	return toError(e)
775
-}
776
-
777
-/* Finalize indicates that an application is done with the Cryptoki library. */
778
-func (c *Ctx) Finalize() error {
779
-	if c.ctx == nil {
780
-		return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
781
-	}
782
-	e := C.Finalize(c.ctx)
783
-	return toError(e)
784
-}
785
-
786
-/* GetInfo returns general information about Cryptoki. */
787
-func (c *Ctx) GetInfo() (Info, error) {
788
-	var p C.CK_INFO
789
-	e := C.GetInfo(c.ctx, C.CK_INFO_PTR(&p))
790
-	i := Info{
791
-		CryptokiVersion:    toVersion(p.cryptokiVersion),
792
-		ManufacturerID:     strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&p.manufacturerID[0]), 32)), " "),
793
-		Flags:              uint(p.flags),
794
-		LibraryDescription: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&p.libraryDescription[0]), 32)), " "),
795
-		LibraryVersion:     toVersion(p.libraryVersion),
796
-	}
797
-	return i, toError(e)
798
-}
799
-
800
-/* GetSlotList obtains a list of slots in the system. */
801
-func (c *Ctx) GetSlotList(tokenPresent bool) ([]uint, error) {
802
-	var (
803
-		slotList C.CK_ULONG_PTR
804
-		ulCount  C.CK_ULONG
805
-	)
806
-	e := C.GetSlotList(c.ctx, cBBool(tokenPresent), &slotList, &ulCount)
807
-	if toError(e) != nil {
808
-		return nil, toError(e)
809
-	}
810
-	l := toList(slotList, ulCount)
811
-	return l, nil
812
-}
813
-
814
-/* GetSlotInfo obtains information about a particular slot in the system. */
815
-func (c *Ctx) GetSlotInfo(slotID uint) (SlotInfo, error) {
816
-	var csi C.CK_SLOT_INFO
817
-	e := C.GetSlotInfo(c.ctx, C.CK_ULONG(slotID), &csi)
818
-	s := SlotInfo{
819
-		SlotDescription: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&csi.slotDescription[0]), 64)), " "),
820
-		ManufacturerID:  strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&csi.manufacturerID[0]), 32)), " "),
821
-		Flags:           uint(csi.flags),
822
-		HardwareVersion: toVersion(csi.hardwareVersion),
823
-		FirmwareVersion: toVersion(csi.firmwareVersion),
824
-	}
825
-	return s, toError(e)
826
-}
827
-
828
-// GetTokenInfo obtains information about a particular token
829
-// in the system.
830
-func (c *Ctx) GetTokenInfo(slotID uint) (TokenInfo, error) {
831
-	var cti C.CK_TOKEN_INFO
832
-	e := C.GetTokenInfo(c.ctx, C.CK_ULONG(slotID), &cti)
833
-	s := TokenInfo{
834
-		Label:              strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.label[0]), 32)), " "),
835
-		ManufacturerID:     strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.manufacturerID[0]), 32)), " "),
836
-		Model:              strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.model[0]), 16)), " "),
837
-		SerialNumber:       strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.serialNumber[0]), 16)), " "),
838
-		Flags:              uint(cti.flags),
839
-		MaxSessionCount:    uint(cti.ulMaxSessionCount),
840
-		SessionCount:       uint(cti.ulSessionCount),
841
-		MaxRwSessionCount:  uint(cti.ulMaxRwSessionCount),
842
-		RwSessionCount:     uint(cti.ulRwSessionCount),
843
-		MaxPinLen:          uint(cti.ulMaxPinLen),
844
-		MinPinLen:          uint(cti.ulMinPinLen),
845
-		TotalPublicMemory:  uint(cti.ulTotalPublicMemory),
846
-		FreePublicMemory:   uint(cti.ulFreePublicMemory),
847
-		TotalPrivateMemory: uint(cti.ulTotalPrivateMemory),
848
-		FreePrivateMemory:  uint(cti.ulFreePrivateMemory),
849
-		HardwareVersion:    toVersion(cti.hardwareVersion),
850
-		FirmwareVersion:    toVersion(cti.firmwareVersion),
851
-		UTCTime:            strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.utcTime[0]), 16)), " "),
852
-	}
853
-	return s, toError(e)
854
-}
855
-
856
-/* GetMechanismList obtains a list of mechanism types supported by a token. */
857
-func (c *Ctx) GetMechanismList(slotID uint) ([]*Mechanism, error) {
858
-	var (
859
-		mech    C.CK_ULONG_PTR // in pkcs#11 we're all CK_ULONGs \o/
860
-		mechlen C.CK_ULONG
861
-	)
862
-	e := C.GetMechanismList(c.ctx, C.CK_ULONG(slotID), &mech, &mechlen)
863
-	if toError(e) != nil {
864
-		return nil, toError(e)
865
-	}
866
-	// Although the function returns only type, cast them back into real
867
-	// attributes as this is used in other functions.
868
-	m := make([]*Mechanism, int(mechlen))
869
-	for i, typ := range toList(mech, mechlen) {
870
-		m[i] = NewMechanism(typ, nil)
871
-	}
872
-	return m, nil
873
-}
874
-
875
-// GetMechanismInfo obtains information about a particular
876
-// mechanism possibly supported by a token.
877
-func (c *Ctx) GetMechanismInfo(slotID uint, m []*Mechanism) (MechanismInfo, error) {
878
-	var cm C.CK_MECHANISM_INFO
879
-	e := C.GetMechanismInfo(c.ctx, C.CK_ULONG(slotID), C.CK_MECHANISM_TYPE(m[0].Mechanism),
880
-		C.CK_MECHANISM_INFO_PTR(&cm))
881
-	mi := MechanismInfo{
882
-		MinKeySize: uint(cm.ulMinKeySize),
883
-		MaxKeySize: uint(cm.ulMaxKeySize),
884
-		Flags:      uint(cm.flags),
885
-	}
886
-	return mi, toError(e)
887
-}
888
-
889
-// InitToken initializes a token. The label must be 32 characters
890
-// long, it is blank padded if it is not. If it is longer it is capped
891
-// to 32 characters.
892
-func (c *Ctx) InitToken(slotID uint, pin string, label string) error {
893
-	p := C.CString(pin)
894
-	defer C.free(unsafe.Pointer(p))
895
-	ll := len(label)
896
-	for ll < 32 {
897
-		label += " "
898
-		ll++
899
-	}
900
-	l := C.CString(label[:32])
901
-	defer C.free(unsafe.Pointer(l))
902
-	e := C.InitToken(c.ctx, C.CK_ULONG(slotID), p, C.CK_ULONG(len(pin)), l)
903
-	return toError(e)
904
-}
905
-
906
-/* InitPIN initializes the normal user's PIN. */
907
-func (c *Ctx) InitPIN(sh SessionHandle, pin string) error {
908
-	p := C.CString(pin)
909
-	defer C.free(unsafe.Pointer(p))
910
-	e := C.InitPIN(c.ctx, C.CK_SESSION_HANDLE(sh), p, C.CK_ULONG(len(pin)))
911
-	return toError(e)
912
-}
913
-
914
-/* SetPIN modifies the PIN of the user who is logged in. */
915
-func (c *Ctx) SetPIN(sh SessionHandle, oldpin string, newpin string) error {
916
-	old := C.CString(oldpin)
917
-	defer C.free(unsafe.Pointer(old))
918
-	new := C.CString(newpin)
919
-	defer C.free(unsafe.Pointer(new))
920
-	e := C.SetPIN(c.ctx, C.CK_SESSION_HANDLE(sh), old, C.CK_ULONG(len(oldpin)), new, C.CK_ULONG(len(newpin)))
921
-	return toError(e)
922
-}
923
-
924
-/* OpenSession opens a session between an application and a token. */
925
-func (c *Ctx) OpenSession(slotID uint, flags uint) (SessionHandle, error) {
926
-	var s C.CK_SESSION_HANDLE
927
-	e := C.OpenSession(c.ctx, C.CK_ULONG(slotID), C.CK_ULONG(flags), C.CK_SESSION_HANDLE_PTR(&s))
928
-	return SessionHandle(s), toError(e)
929
-}
930
-
931
-/* CloseSession closes a session between an application and a token. */
932
-func (c *Ctx) CloseSession(sh SessionHandle) error {
933
-	if c.ctx == nil {
934
-		return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
935
-	}
936
-	e := C.CloseSession(c.ctx, C.CK_SESSION_HANDLE(sh))
937
-	return toError(e)
938
-}
939
-
940
-/* CloseAllSessions closes all sessions with a token. */
941
-func (c *Ctx) CloseAllSessions(slotID uint) error {
942
-	if c.ctx == nil {
943
-		return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
944
-	}
945
-	e := C.CloseAllSessions(c.ctx, C.CK_ULONG(slotID))
946
-	return toError(e)
947
-}
948
-
949
-/* GetSessionInfo obtains information about the session. */
950
-func (c *Ctx) GetSessionInfo(sh SessionHandle) (SessionInfo, error) {
951
-	var csi C.CK_SESSION_INFO
952
-	e := C.GetSessionInfo(c.ctx, C.CK_SESSION_HANDLE(sh), &csi)
953
-	s := SessionInfo{SlotID: uint(csi.slotID),
954
-		State:       uint(csi.state),
955
-		Flags:       uint(csi.flags),
956
-		DeviceError: uint(csi.ulDeviceError),
957
-	}
958
-	return s, toError(e)
959
-}
960
-
961
-/* GetOperationState obtains the state of the cryptographic operation in a session. */
962
-func (c *Ctx) GetOperationState(sh SessionHandle) ([]byte, error) {
963
-	var (
964
-		state    C.CK_BYTE_PTR
965
-		statelen C.CK_ULONG
966
-	)
967
-	e := C.GetOperationState(c.ctx, C.CK_SESSION_HANDLE(sh), &state, &statelen)
968
-	if toError(e) != nil {
969
-		return nil, toError(e)
970
-	}
971
-	b := C.GoBytes(unsafe.Pointer(state), C.int(statelen))
972
-	C.free(unsafe.Pointer(state))
973
-	return b, nil
974
-}
975
-
976
-/* SetOperationState restores the state of the cryptographic operation in a session. */
977
-func (c *Ctx) SetOperationState(sh SessionHandle, state []byte, encryptKey, authKey ObjectHandle) error {
978
-	e := C.SetOperationState(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&state[0])),
979
-		C.CK_ULONG(len(state)), C.CK_OBJECT_HANDLE(encryptKey), C.CK_OBJECT_HANDLE(authKey))
980
-	return toError(e)
981
-}
982
-
983
-/* Login logs a user into a token. */
984
-func (c *Ctx) Login(sh SessionHandle, userType uint, pin string) error {
985
-	p := C.CString(pin)
986
-	defer C.free(unsafe.Pointer(p))
987
-	e := C.Login(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_USER_TYPE(userType), p, C.CK_ULONG(len(pin)))
988
-	return toError(e)
989
-}
990
-
991
-/* Logout logs a user out from a token. */
992
-func (c *Ctx) Logout(sh SessionHandle) error {
993
-	if c.ctx == nil {
994
-		return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
995
-	}
996
-	e := C.Logout(c.ctx, C.CK_SESSION_HANDLE(sh))
997
-	return toError(e)
998
-}
999
-
1000
-/* CreateObject creates a new object. */
1001
-func (c *Ctx) CreateObject(sh SessionHandle, temp []*Attribute) (ObjectHandle, error) {
1002
-	var obj C.CK_OBJECT_HANDLE
1003
-	arena, t, tcount := cAttributeList(temp)
1004
-	defer arena.Free()
1005
-	e := C.CreateObject(c.ctx, C.CK_SESSION_HANDLE(sh), t, tcount, C.CK_OBJECT_HANDLE_PTR(&obj))
1006
-	e1 := toError(e)
1007
-	if e1 == nil {
1008
-		return ObjectHandle(obj), nil
1009
-	}
1010
-	return 0, e1
1011
-}
1012
-
1013
-/* CopyObject copies an object, creating a new object for the copy. */
1014
-func (c *Ctx) CopyObject(sh SessionHandle, o ObjectHandle, temp []*Attribute) (ObjectHandle, error) {
1015
-	var obj C.CK_OBJECT_HANDLE
1016
-	arena, t, tcount := cAttributeList(temp)
1017
-	defer arena.Free()
1018
-
1019
-	e := C.CopyObject(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(o), t, tcount, C.CK_OBJECT_HANDLE_PTR(&obj))
1020
-	e1 := toError(e)
1021
-	if e1 == nil {
1022
-		return ObjectHandle(obj), nil
1023
-	}
1024
-	return 0, e1
1025
-}
1026
-
1027
-/* DestroyObject destroys an object. */
1028
-func (c *Ctx) DestroyObject(sh SessionHandle, oh ObjectHandle) error {
1029
-	e := C.DestroyObject(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(oh))
1030
-	return toError(e)
1031
-}
1032
-
1033
-/* GetObjectSize gets the size of an object in bytes. */
1034
-func (c *Ctx) GetObjectSize(sh SessionHandle, oh ObjectHandle) (uint, error) {
1035
-	var size C.CK_ULONG
1036
-	e := C.GetObjectSize(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(oh), &size)
1037
-	return uint(size), toError(e)
1038
-}
1039
-
1040
-/* GetAttributeValue obtains the value of one or more object attributes. */
1041
-func (c *Ctx) GetAttributeValue(sh SessionHandle, o ObjectHandle, a []*Attribute) ([]*Attribute, error) {
1042
-	// copy the attribute list and make all the values nil, so that
1043
-	// the C function can (allocate) fill them in
1044
-	pa := make([]C.CK_ATTRIBUTE, len(a))
1045
-	for i := 0; i < len(a); i++ {
1046
-		pa[i]._type = C.CK_ATTRIBUTE_TYPE(a[i].Type)
1047
-	}
1048
-	e := C.GetAttributeValue(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(o), C.CK_ATTRIBUTE_PTR(&pa[0]), C.CK_ULONG(len(a)))
1049
-	if toError(e) != nil {
1050
-		return nil, toError(e)
1051
-	}
1052
-	a1 := make([]*Attribute, len(a))
1053
-	for i, c := range pa {
1054
-		x := new(Attribute)
1055
-		x.Type = uint(c._type)
1056
-		if int(c.ulValueLen) != -1 {
1057
-			x.Value = C.GoBytes(unsafe.Pointer(c.pValue), C.int(c.ulValueLen))
1058
-			C.free(unsafe.Pointer(c.pValue))
1059
-		}
1060
-		a1[i] = x
1061
-	}
1062
-	return a1, nil
1063
-}
1064
-
1065
-/* SetAttributeValue modifies the value of one or more object attributes */
1066
-func (c *Ctx) SetAttributeValue(sh SessionHandle, o ObjectHandle, a []*Attribute) error {
1067
-	arena, pa, palen := cAttributeList(a)
1068
-	defer arena.Free()
1069
-	e := C.SetAttributeValue(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(o), pa, palen)
1070
-	return toError(e)
1071
-}
1072
-
1073
-// FindObjectsInit initializes a search for token and session
1074
-// objects that match a template.
1075
-func (c *Ctx) FindObjectsInit(sh SessionHandle, temp []*Attribute) error {
1076
-	arena, t, tcount := cAttributeList(temp)
1077
-	defer arena.Free()
1078
-	e := C.FindObjectsInit(c.ctx, C.CK_SESSION_HANDLE(sh), t, tcount)
1079
-	return toError(e)
1080
-}
1081
-
1082
-// FindObjects continues a search for token and session
1083
-// objects that match a template, obtaining additional object
1084
-// handles. The returned boolean indicates if the list would
1085
-// have been larger than max.
1086
-func (c *Ctx) FindObjects(sh SessionHandle, max int) ([]ObjectHandle, bool, error) {
1087
-	var (
1088
-		objectList C.CK_OBJECT_HANDLE_PTR
1089
-		ulCount    C.CK_ULONG
1090
-	)
1091
-	e := C.FindObjects(c.ctx, C.CK_SESSION_HANDLE(sh), &objectList, C.CK_ULONG(max), &ulCount)
1092
-	if toError(e) != nil {
1093
-		return nil, false, toError(e)
1094
-	}
1095
-	l := toList(C.CK_ULONG_PTR(unsafe.Pointer(objectList)), ulCount)
1096
-	// Make again a new list of the correct type.
1097
-	// This is copying data, but this is not an often used function.
1098
-	o := make([]ObjectHandle, len(l))
1099
-	for i, v := range l {
1100
-		o[i] = ObjectHandle(v)
1101
-	}
1102
-	return o, ulCount > C.CK_ULONG(max), nil
1103
-}
1104
-
1105
-/* FindObjectsFinal finishes a search for token and session objects. */
1106
-func (c *Ctx) FindObjectsFinal(sh SessionHandle) error {
1107
-	e := C.FindObjectsFinal(c.ctx, C.CK_SESSION_HANDLE(sh))
1108
-	return toError(e)
1109
-}
1110
-
1111
-/* EncryptInit initializes an encryption operation. */
1112
-func (c *Ctx) EncryptInit(sh SessionHandle, m []*Mechanism, o ObjectHandle) error {
1113
-	arena, mech, _ := cMechanismList(m)
1114
-	defer arena.Free()
1115
-	e := C.EncryptInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(o))
1116
-	return toError(e)
1117
-}
1118
-
1119
-/* Encrypt encrypts single-part data. */
1120
-func (c *Ctx) Encrypt(sh SessionHandle, message []byte) ([]byte, error) {
1121
-	var (
1122
-		enc    C.CK_BYTE_PTR
1123
-		enclen C.CK_ULONG
1124
-	)
1125
-	e := C.Encrypt(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&message[0])), C.CK_ULONG(len(message)), &enc, &enclen)
1126
-	if toError(e) != nil {
1127
-		return nil, toError(e)
1128
-	}
1129
-	s := C.GoBytes(unsafe.Pointer(enc), C.int(enclen))
1130
-	C.free(unsafe.Pointer(enc))
1131
-	return s, nil
1132
-}
1133
-
1134
-/* EncryptUpdate continues a multiple-part encryption operation. */
1135
-func (c *Ctx) EncryptUpdate(sh SessionHandle, plain []byte) ([]byte, error) {
1136
-	var (
1137
-		part    C.CK_BYTE_PTR
1138
-		partlen C.CK_ULONG
1139
-	)
1140
-	e := C.EncryptUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&plain[0])), C.CK_ULONG(len(plain)), &part, &partlen)
1141
-	if toError(e) != nil {
1142
-		return nil, toError(e)
1143
-	}
1144
-	h := C.GoBytes(unsafe.Pointer(part), C.int(partlen))
1145
-	C.free(unsafe.Pointer(part))
1146
-	return h, nil
1147
-}
1148
-
1149
-// EncryptFinal finishes a multiple-part encryption operation.
1150
-func (c *Ctx) EncryptFinal(sh SessionHandle) ([]byte, error) {
1151
-	var (
1152
-		enc    C.CK_BYTE_PTR
1153
-		enclen C.CK_ULONG
1154
-	)
1155
-	e := C.EncryptFinal(c.ctx, C.CK_SESSION_HANDLE(sh), &enc, &enclen)
1156
-	if toError(e) != nil {
1157
-		return nil, toError(e)
1158
-	}
1159
-	h := C.GoBytes(unsafe.Pointer(enc), C.int(enclen))
1160
-	C.free(unsafe.Pointer(enc))
1161
-	return h, nil
1162
-}
1163
-
1164
-/* DecryptInit initializes a decryption operation. */
1165
-func (c *Ctx) DecryptInit(sh SessionHandle, m []*Mechanism, o ObjectHandle) error {
1166
-	arena, mech, _ := cMechanismList(m)
1167
-	defer arena.Free()
1168
-	e := C.DecryptInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(o))
1169
-	return toError(e)
1170
-}
1171
-
1172
-/* Decrypt decrypts encrypted data in a single part. */
1173
-func (c *Ctx) Decrypt(sh SessionHandle, cypher []byte) ([]byte, error) {
1174
-	var (
1175
-		plain    C.CK_BYTE_PTR
1176
-		plainlen C.CK_ULONG
1177
-	)
1178
-	e := C.Decrypt(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&cypher[0])), C.CK_ULONG(len(cypher)), &plain, &plainlen)
1179
-	if toError(e) != nil {
1180
-		return nil, toError(e)
1181
-	}
1182
-	s := C.GoBytes(unsafe.Pointer(plain), C.int(plainlen))
1183
-	C.free(unsafe.Pointer(plain))
1184
-	return s, nil
1185
-}
1186
-
1187
-/* DecryptUpdate continues a multiple-part decryption operation. */
1188
-func (c *Ctx) DecryptUpdate(sh SessionHandle, cipher []byte) ([]byte, error) {
1189
-	var (
1190
-		part    C.CK_BYTE_PTR
1191
-		partlen C.CK_ULONG
1192
-	)
1193
-	e := C.DecryptUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&cipher[0])), C.CK_ULONG(len(cipher)), &part, &partlen)
1194
-	if toError(e) != nil {
1195
-		return nil, toError(e)
1196
-	}
1197
-	h := C.GoBytes(unsafe.Pointer(part), C.int(partlen))
1198
-	C.free(unsafe.Pointer(part))
1199
-	return h, nil
1200
-}
1201
-
1202
-/* DecryptFinal finishes a multiple-part decryption operation. */
1203
-func (c *Ctx) DecryptFinal(sh SessionHandle) ([]byte, error) {
1204
-	var (
1205
-		plain    C.CK_BYTE_PTR
1206
-		plainlen C.CK_ULONG
1207
-	)
1208
-	e := C.DecryptFinal(c.ctx, C.CK_SESSION_HANDLE(sh), &plain, &plainlen)
1209
-	if toError(e) != nil {
1210
-		return nil, toError(e)
1211
-	}
1212
-	h := C.GoBytes(unsafe.Pointer(plain), C.int(plainlen))
1213
-	C.free(unsafe.Pointer(plain))
1214
-	return h, nil
1215
-}
1216
-
1217
-/* DigestInit initializes a message-digesting operation. */
1218
-func (c *Ctx) DigestInit(sh SessionHandle, m []*Mechanism) error {
1219
-	arena, mech, _ := cMechanismList(m)
1220
-	defer arena.Free()
1221
-	e := C.DigestInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech)
1222
-	return toError(e)
1223
-}
1224
-
1225
-/* Digest digests message in a single part. */
1226
-func (c *Ctx) Digest(sh SessionHandle, message []byte) ([]byte, error) {
1227
-	var (
1228
-		hash    C.CK_BYTE_PTR
1229
-		hashlen C.CK_ULONG
1230
-	)
1231
-	e := C.Digest(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&message[0])), C.CK_ULONG(len(message)), &hash, &hashlen)
1232
-	if toError(e) != nil {
1233
-		return nil, toError(e)
1234
-	}
1235
-	h := C.GoBytes(unsafe.Pointer(hash), C.int(hashlen))
1236
-	C.free(unsafe.Pointer(hash))
1237
-	return h, nil
1238
-}
1239
-
1240
-/* DigestUpdate continues a multiple-part message-digesting operation. */
1241
-func (c *Ctx) DigestUpdate(sh SessionHandle, message []byte) error {
1242
-	e := C.DigestUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&message[0])), C.CK_ULONG(len(message)))
1243
-	if toError(e) != nil {
1244
-		return toError(e)
1245
-	}
1246
-	return nil
1247
-}
1248
-
1249
-// DigestKey continues a multi-part message-digesting
1250
-// operation, by digesting the value of a secret key as part of
1251
-// the data already digested.
1252
-func (c *Ctx) DigestKey(sh SessionHandle, key ObjectHandle) error {
1253
-	e := C.DigestKey(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(key))
1254
-	if toError(e) != nil {
1255
-		return toError(e)
1256
-	}
1257
-	return nil
1258
-}
1259
-
1260
-/* DigestFinal finishes a multiple-part message-digesting operation. */
1261
-func (c *Ctx) DigestFinal(sh SessionHandle) ([]byte, error) {
1262
-	var (
1263
-		hash    C.CK_BYTE_PTR
1264
-		hashlen C.CK_ULONG
1265
-	)
1266
-	e := C.DigestFinal(c.ctx, C.CK_SESSION_HANDLE(sh), &hash, &hashlen)
1267
-	if toError(e) != nil {
1268
-		return nil, toError(e)
1269
-	}
1270
-	h := C.GoBytes(unsafe.Pointer(hash), C.int(hashlen))
1271
-	C.free(unsafe.Pointer(hash))
1272
-	return h, nil
1273
-}
1274
-
1275
-// SignInit initializes a signature (private key encryption)
1276
-// operation, where the signature is (will be) an appendix to
1277
-// the data, and plaintext cannot be recovered from the
1278
-// signature.
1279
-func (c *Ctx) SignInit(sh SessionHandle, m []*Mechanism, o ObjectHandle) error {
1280
-	arena, mech, _ := cMechanismList(m) // Only the first is used, but still use a list.
1281
-	defer arena.Free()
1282
-	e := C.SignInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(o))
1283
-	return toError(e)
1284
-}
1285
-
1286
-// Sign signs (encrypts with private key) data in a single part, where the signature
1287
-// is (will be) an appendix to the data, and plaintext cannot be recovered from the signature.
1288
-func (c *Ctx) Sign(sh SessionHandle, message []byte) ([]byte, error) {
1289
-	var (
1290
-		sig    C.CK_BYTE_PTR
1291
-		siglen C.CK_ULONG
1292
-	)
1293
-	e := C.Sign(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&message[0])), C.CK_ULONG(len(message)), &sig, &siglen)
1294
-	if toError(e) != nil {
1295
-		return nil, toError(e)
1296
-	}
1297
-	s := C.GoBytes(unsafe.Pointer(sig), C.int(siglen))
1298
-	C.free(unsafe.Pointer(sig))
1299
-	return s, nil
1300
-}
1301
-
1302
-// SignUpdate continues a multiple-part signature operation,
1303
-// where the signature is (will be) an appendix to the data,
1304
-// and plaintext cannot be recovered from the signature.
1305
-func (c *Ctx) SignUpdate(sh SessionHandle, message []byte) error {
1306
-	e := C.SignUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&message[0])), C.CK_ULONG(len(message)))
1307
-	return toError(e)
1308
-}
1309
-
1310
-/* SignFinal finishes a multiple-part signature operation returning the signature. */
1311
-func (c *Ctx) SignFinal(sh SessionHandle) ([]byte, error) {
1312
-	var (
1313
-		sig    C.CK_BYTE_PTR
1314
-		siglen C.CK_ULONG
1315
-	)
1316
-	e := C.SignFinal(c.ctx, C.CK_SESSION_HANDLE(sh), &sig, &siglen)
1317
-	if toError(e) != nil {
1318
-		return nil, toError(e)
1319
-	}
1320
-	h := C.GoBytes(unsafe.Pointer(sig), C.int(siglen))
1321
-	C.free(unsafe.Pointer(sig))
1322
-	return h, nil
1323
-}
1324
-
1325
-// SignRecoverInit initializes a signature operation, where
1326
-// the data can be recovered from the signature.
1327
-func (c *Ctx) SignRecoverInit(sh SessionHandle, m []*Mechanism, key ObjectHandle) error {
1328
-	arena, mech, _ := cMechanismList(m)
1329
-	defer arena.Free()
1330
-	e := C.SignRecoverInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(key))
1331
-	return toError(e)
1332
-}
1333
-
1334
-// SignRecover signs data in a single operation, where the
1335
-// data can be recovered from the signature.
1336
-func (c *Ctx) SignRecover(sh SessionHandle, data []byte) ([]byte, error) {
1337
-	var (
1338
-		sig    C.CK_BYTE_PTR
1339
-		siglen C.CK_ULONG
1340
-	)
1341
-	e := C.SignRecover(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&data[0])), C.CK_ULONG(len(data)), &sig, &siglen)
1342
-	if toError(e) != nil {
1343
-		return nil, toError(e)
1344
-	}
1345
-	h := C.GoBytes(unsafe.Pointer(sig), C.int(siglen))
1346
-	C.free(unsafe.Pointer(sig))
1347
-	return h, nil
1348
-}
1349
-
1350
-// VerifyInit initializes a verification operation, where the
1351
-// signature is an appendix to the data, and plaintext cannot
1352
-// be recovered from the signature (e.g. DSA).
1353
-func (c *Ctx) VerifyInit(sh SessionHandle, m []*Mechanism, key ObjectHandle) error {
1354
-	arena, mech, _ := cMechanismList(m) // only use one here
1355
-	defer arena.Free()
1356
-	e := C.VerifyInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(key))
1357
-	return toError(e)
1358
-}
1359
-
1360
-// Verify verifies a signature in a single-part operation,
1361
-// where the signature is an appendix to the data, and plaintext
1362
-// cannot be recovered from the signature.
1363
-func (c *Ctx) Verify(sh SessionHandle, data []byte, signature []byte) error {
1364
-	e := C.Verify(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&data[0])), C.CK_ULONG(len(data)), C.CK_BYTE_PTR(unsafe.Pointer(&signature[0])), C.CK_ULONG(len(signature)))
1365
-	return toError(e)
1366
-}
1367
-
1368
-// VerifyUpdate continues a multiple-part verification
1369
-// operation, where the signature is an appendix to the data,
1370
-// and plaintext cannot be recovered from the signature.
1371
-func (c *Ctx) VerifyUpdate(sh SessionHandle, part []byte) error {
1372
-	e := C.VerifyUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&part[0])), C.CK_ULONG(len(part)))
1373
-	return toError(e)
1374
-}
1375
-
1376
-// VerifyFinal finishes a multiple-part verification
1377
-// operation, checking the signature.
1378
-func (c *Ctx) VerifyFinal(sh SessionHandle, signature []byte) error {
1379
-	e := C.VerifyFinal(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&signature[0])), C.CK_ULONG(len(signature)))
1380
-	return toError(e)
1381
-}
1382
-
1383
-// VerifyRecoverInit initializes a signature verification
1384
-// operation, where the data is recovered from the signature.
1385
-func (c *Ctx) VerifyRecoverInit(sh SessionHandle, m []*Mechanism, key ObjectHandle) error {
1386
-	arena, mech, _ := cMechanismList(m)
1387
-	defer arena.Free()
1388
-	e := C.VerifyRecoverInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(key))
1389
-	return toError(e)
1390
-}
1391
-
1392
-// VerifyRecover verifies a signature in a single-part
1393
-// operation, where the data is recovered from the signature.
1394
-func (c *Ctx) VerifyRecover(sh SessionHandle, signature []byte) ([]byte, error) {
1395
-	var (
1396
-		data    C.CK_BYTE_PTR
1397
-		datalen C.CK_ULONG
1398
-	)
1399
-	e := C.DecryptVerifyUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&signature[0])), C.CK_ULONG(len(signature)), &data, &datalen)
1400
-	if toError(e) != nil {
1401
-		return nil, toError(e)
1402
-	}
1403
-	h := C.GoBytes(unsafe.Pointer(data), C.int(datalen))
1404
-	C.free(unsafe.Pointer(data))
1405
-	return h, nil
1406
-}
1407
-
1408
-// DigestEncryptUpdate continues a multiple-part digesting
1409
-// and encryption operation.
1410
-func (c *Ctx) DigestEncryptUpdate(sh SessionHandle, part []byte) ([]byte, error) {
1411
-	var (
1412
-		enc    C.CK_BYTE_PTR
1413
-		enclen C.CK_ULONG
1414
-	)
1415
-	e := C.DigestEncryptUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&part[0])), C.CK_ULONG(len(part)), &enc, &enclen)
1416
-	if toError(e) != nil {
1417
-		return nil, toError(e)
1418
-	}
1419
-	h := C.GoBytes(unsafe.Pointer(enc), C.int(enclen))
1420
-	C.free(unsafe.Pointer(enc))
1421
-	return h, nil
1422
-}
1423
-
1424
-/* DecryptDigestUpdate continues a multiple-part decryption and digesting operation. */
1425
-func (c *Ctx) DecryptDigestUpdate(sh SessionHandle, cipher []byte) ([]byte, error) {
1426
-	var (
1427
-		part    C.CK_BYTE_PTR
1428
-		partlen C.CK_ULONG
1429
-	)
1430
-	e := C.DecryptDigestUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&cipher[0])), C.CK_ULONG(len(cipher)), &part, &partlen)
1431
-	if toError(e) != nil {
1432
-		return nil, toError(e)
1433
-	}
1434
-	h := C.GoBytes(unsafe.Pointer(part), C.int(partlen))
1435
-	C.free(unsafe.Pointer(part))
1436
-	return h, nil
1437
-}
1438
-
1439
-/* SignEncryptUpdate continues a multiple-part signing and encryption operation. */
1440
-func (c *Ctx) SignEncryptUpdate(sh SessionHandle, part []byte) ([]byte, error) {
1441
-	var (
1442
-		enc    C.CK_BYTE_PTR
1443
-		enclen C.CK_ULONG
1444
-	)
1445
-	e := C.SignEncryptUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&part[0])), C.CK_ULONG(len(part)), &enc, &enclen)
1446
-	if toError(e) != nil {
1447
-		return nil, toError(e)
1448
-	}
1449
-	h := C.GoBytes(unsafe.Pointer(enc), C.int(enclen))
1450
-	C.free(unsafe.Pointer(enc))
1451
-	return h, nil
1452
-}
1453
-
1454
-/* DecryptVerifyUpdate continues a multiple-part decryption and verify operation. */
1455
-func (c *Ctx) DecryptVerifyUpdate(sh SessionHandle, cipher []byte) ([]byte, error) {
1456
-	var (
1457
-		part    C.CK_BYTE_PTR
1458
-		partlen C.CK_ULONG
1459
-	)
1460
-	e := C.DecryptVerifyUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&cipher[0])), C.CK_ULONG(len(cipher)), &part, &partlen)
1461
-	if toError(e) != nil {
1462
-		return nil, toError(e)
1463
-	}
1464
-	h := C.GoBytes(unsafe.Pointer(part), C.int(partlen))
1465
-	C.free(unsafe.Pointer(part))
1466
-	return h, nil
1467
-}
1468
-
1469
-/* GenerateKey generates a secret key, creating a new key object. */
1470
-func (c *Ctx) GenerateKey(sh SessionHandle, m []*Mechanism, temp []*Attribute) (ObjectHandle, error) {
1471
-	var key C.CK_OBJECT_HANDLE
1472
-	attrarena, t, tcount := cAttributeList(temp)
1473
-	defer attrarena.Free()
1474
-	mecharena, mech, _ := cMechanismList(m)
1475
-	defer mecharena.Free()
1476
-	e := C.GenerateKey(c.ctx, C.CK_SESSION_HANDLE(sh), mech, t, tcount, C.CK_OBJECT_HANDLE_PTR(&key))
1477
-	e1 := toError(e)
1478
-	if e1 == nil {
1479
-		return ObjectHandle(key), nil
1480
-	}
1481
-	return 0, e1
1482
-}
1483
-
1484
-/* GenerateKeyPair generates a public-key/private-key pair creating new key objects. */
1485
-func (c *Ctx) GenerateKeyPair(sh SessionHandle, m []*Mechanism, public, private []*Attribute) (ObjectHandle, ObjectHandle, error) {
1486
-	var (
1487
-		pubkey  C.CK_OBJECT_HANDLE
1488
-		privkey C.CK_OBJECT_HANDLE
1489
-	)
1490
-	pubarena, pub, pubcount := cAttributeList(public)
1491
-	defer pubarena.Free()
1492
-	privarena, priv, privcount := cAttributeList(private)
1493
-	defer privarena.Free()
1494
-	mecharena, mech, _ := cMechanismList(m)
1495
-	defer mecharena.Free()
1496
-	e := C.GenerateKeyPair(c.ctx, C.CK_SESSION_HANDLE(sh), mech, pub, pubcount, priv, privcount, C.CK_OBJECT_HANDLE_PTR(&pubkey), C.CK_OBJECT_HANDLE_PTR(&privkey))
1497
-	e1 := toError(e)
1498
-	if e1 == nil {
1499
-		return ObjectHandle(pubkey), ObjectHandle(privkey), nil
1500
-	}
1501
-	return 0, 0, e1
1502
-}
1503
-
1504
-/* WrapKey wraps (i.e., encrypts) a key. */
1505
-func (c *Ctx) WrapKey(sh SessionHandle, m []*Mechanism, wrappingkey, key ObjectHandle) ([]byte, error) {
1506
-	var (
1507
-		wrappedkey    C.CK_BYTE_PTR
1508
-		wrappedkeylen C.CK_ULONG
1509
-	)
1510
-	arena, mech, _ := cMechanismList(m)
1511
-	defer arena.Free()
1512
-	e := C.WrapKey(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(wrappingkey), C.CK_OBJECT_HANDLE(key), &wrappedkey, &wrappedkeylen)
1513
-	if toError(e) != nil {
1514
-		return nil, toError(e)
1515
-	}
1516
-	h := C.GoBytes(unsafe.Pointer(wrappedkey), C.int(wrappedkeylen))
1517
-	C.free(unsafe.Pointer(wrappedkey))
1518
-	return h, nil
1519
-}
1520
-
1521
-/* UnwrapKey unwraps (decrypts) a wrapped key, creating a new key object. */
1522
-func (c *Ctx) UnwrapKey(sh SessionHandle, m []*Mechanism, unwrappingkey ObjectHandle, wrappedkey []byte, a []*Attribute) (ObjectHandle, error) {
1523
-	var key C.CK_OBJECT_HANDLE
1524
-	attrarena, ac, aclen := cAttributeList(a)
1525
-	defer attrarena.Free()
1526
-	mecharena, mech, _ := cMechanismList(m)
1527
-	defer mecharena.Free()
1528
-	e := C.UnwrapKey(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(unwrappingkey), C.CK_BYTE_PTR(unsafe.Pointer(&wrappedkey[0])), C.CK_ULONG(len(wrappedkey)), ac, aclen, &key)
1529
-	return ObjectHandle(key), toError(e)
1530
-}
1531
-
1532
-// DeriveKey derives a key from a base key, creating a new key object. */
1533
-func (c *Ctx) DeriveKey(sh SessionHandle, m []*Mechanism, basekey ObjectHandle, a []*Attribute) (ObjectHandle, error) {
1534
-	var key C.CK_OBJECT_HANDLE
1535
-	attrarena, ac, aclen := cAttributeList(a)
1536
-	defer attrarena.Free()
1537
-	mecharena, mech, _ := cMechanismList(m)
1538
-	defer mecharena.Free()
1539
-	e := C.DeriveKey(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(basekey), ac, aclen, &key)
1540
-	return ObjectHandle(key), toError(e)
1541
-}
1542
-
1543
-// SeedRandom mixes additional seed material into the token's
1544
-// random number generator.
1545
-func (c *Ctx) SeedRandom(sh SessionHandle, seed []byte) error {
1546
-	e := C.SeedRandom(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&seed[0])), C.CK_ULONG(len(seed)))
1547
-	return toError(e)
1548
-}
1549
-
1550
-/* GenerateRandom generates random data. */
1551
-func (c *Ctx) GenerateRandom(sh SessionHandle, length int) ([]byte, error) {
1552
-	var rand C.CK_BYTE_PTR
1553
-	e := C.GenerateRandom(c.ctx, C.CK_SESSION_HANDLE(sh), &rand, C.CK_ULONG(length))
1554
-	if toError(e) != nil {
1555
-		return nil, toError(e)
1556
-	}
1557
-	h := C.GoBytes(unsafe.Pointer(rand), C.int(length))
1558
-	C.free(unsafe.Pointer(rand))
1559
-	return h, nil
1560
-}
1561
-
1562
-// WaitForSlotEvent returns a channel which returns a slot event
1563
-// (token insertion, removal, etc.) when it occurs.
1564
-func (c *Ctx) WaitForSlotEvent(flags uint) chan SlotEvent {
1565
-	sl := make(chan SlotEvent, 1) // hold one element
1566
-	go c.waitForSlotEventHelper(flags, sl)
1567
-	return sl
1568
-}
1569
-
1570
-func (c *Ctx) waitForSlotEventHelper(f uint, sl chan SlotEvent) {
1571
-	var slotID C.CK_ULONG
1572
-	C.WaitForSlotEvent(c.ctx, C.CK_FLAGS(f), &slotID)
1573
-	sl <- SlotEvent{uint(slotID)}
1574
-	close(sl) // TODO(miek): Sending and then closing ...?
1575
-}
1576 1
deleted file mode 100644
... ...
@@ -1,299 +0,0 @@
1
-/* pkcs11.h include file for PKCS #11. */
2
-/* $Revision: 1.2 $ */
3
-
4
-/* License to copy and use this software is granted provided that it is
5
- * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
6
- * (Cryptoki)" in all material mentioning or referencing this software.
7
-
8
- * License is also granted to make and use derivative works provided that
9
- * such works are identified as "derived from the RSA Security Inc. PKCS #11
10
- * Cryptographic Token Interface (Cryptoki)" in all material mentioning or 
11
- * referencing the derived work.
12
-
13
- * RSA Security Inc. makes no representations concerning either the 
14
- * merchantability of this software or the suitability of this software for
15
- * any particular purpose. It is provided "as is" without express or implied
16
- * warranty of any kind.
17
- */
18
-
19
-#ifndef _PKCS11_H_
20
-#define _PKCS11_H_ 1
21
-
22
-#ifdef __cplusplus
23
-extern "C" {
24
-#endif
25
-
26
-/* Before including this file (pkcs11.h) (or pkcs11t.h by
27
- * itself), 6 platform-specific macros must be defined.  These
28
- * macros are described below, and typical definitions for them
29
- * are also given.  Be advised that these definitions can depend
30
- * on both the platform and the compiler used (and possibly also
31
- * on whether a Cryptoki library is linked statically or
32
- * dynamically).
33
- *
34
- * In addition to defining these 6 macros, the packing convention
35
- * for Cryptoki structures should be set.  The Cryptoki
36
- * convention on packing is that structures should be 1-byte
37
- * aligned.
38
- *
39
- * If you're using Microsoft Developer Studio 5.0 to produce
40
- * Win32 stuff, this might be done by using the following
41
- * preprocessor directive before including pkcs11.h or pkcs11t.h:
42
- *
43
- * #pragma pack(push, cryptoki, 1)
44
- *
45
- * and using the following preprocessor directive after including
46
- * pkcs11.h or pkcs11t.h:
47
- *
48
- * #pragma pack(pop, cryptoki)
49
- *
50
- * If you're using an earlier version of Microsoft Developer
51
- * Studio to produce Win16 stuff, this might be done by using
52
- * the following preprocessor directive before including
53
- * pkcs11.h or pkcs11t.h:
54
- *
55
- * #pragma pack(1)
56
- *
57
- * In a UNIX environment, you're on your own for this.  You might
58
- * not need to do (or be able to do!) anything.
59
- *
60
- *
61
- * Now for the macros:
62
- *
63
- *
64
- * 1. CK_PTR: The indirection string for making a pointer to an
65
- * object.  It can be used like this:
66
- *
67
- * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
68
- *
69
- * If you're using Microsoft Developer Studio 5.0 to produce
70
- * Win32 stuff, it might be defined by:
71
- *
72
- * #define CK_PTR *
73
- *
74
- * If you're using an earlier version of Microsoft Developer
75
- * Studio to produce Win16 stuff, it might be defined by:
76
- *
77
- * #define CK_PTR far *
78
- *
79
- * In a typical UNIX environment, it might be defined by:
80
- *
81
- * #define CK_PTR *
82
- *
83
- *
84
- * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
85
- * an exportable Cryptoki library function definition out of a
86
- * return type and a function name.  It should be used in the
87
- * following fashion to define the exposed Cryptoki functions in
88
- * a Cryptoki library:
89
- *
90
- * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
91
- *   CK_VOID_PTR pReserved
92
- * )
93
- * {
94
- *   ...
95
- * }
96
- *
97
- * If you're using Microsoft Developer Studio 5.0 to define a
98
- * function in a Win32 Cryptoki .dll, it might be defined by:
99
- *
100
- * #define CK_DEFINE_FUNCTION(returnType, name) \
101
- *   returnType __declspec(dllexport) name
102
- *
103
- * If you're using an earlier version of Microsoft Developer
104
- * Studio to define a function in a Win16 Cryptoki .dll, it
105
- * might be defined by:
106
- *
107
- * #define CK_DEFINE_FUNCTION(returnType, name) \
108
- *   returnType __export _far _pascal name
109
- *
110
- * In a UNIX environment, it might be defined by:
111
- *
112
- * #define CK_DEFINE_FUNCTION(returnType, name) \
113
- *   returnType name
114
- *
115
- *
116
- * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
117
- * an importable Cryptoki library function declaration out of a
118
- * return type and a function name.  It should be used in the
119
- * following fashion:
120
- *
121
- * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
122
- *   CK_VOID_PTR pReserved
123
- * );
124
- *
125
- * If you're using Microsoft Developer Studio 5.0 to declare a
126
- * function in a Win32 Cryptoki .dll, it might be defined by:
127
- *
128
- * #define CK_DECLARE_FUNCTION(returnType, name) \
129
- *   returnType __declspec(dllimport) name
130
- *
131
- * If you're using an earlier version of Microsoft Developer
132
- * Studio to declare a function in a Win16 Cryptoki .dll, it
133
- * might be defined by:
134
- *
135
- * #define CK_DECLARE_FUNCTION(returnType, name) \
136
- *   returnType __export _far _pascal name
137
- *
138
- * In a UNIX environment, it might be defined by:
139
- *
140
- * #define CK_DECLARE_FUNCTION(returnType, name) \
141
- *   returnType name
142
- *
143
- *
144
- * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
145
- * which makes a Cryptoki API function pointer declaration or
146
- * function pointer type declaration out of a return type and a
147
- * function name.  It should be used in the following fashion:
148
- *
149
- * // Define funcPtr to be a pointer to a Cryptoki API function
150
- * // taking arguments args and returning CK_RV.
151
- * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
152
- *
153
- * or
154
- *
155
- * // Define funcPtrType to be the type of a pointer to a
156
- * // Cryptoki API function taking arguments args and returning
157
- * // CK_RV, and then define funcPtr to be a variable of type
158
- * // funcPtrType.
159
- * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
160
- * funcPtrType funcPtr;
161
- *
162
- * If you're using Microsoft Developer Studio 5.0 to access
163
- * functions in a Win32 Cryptoki .dll, in might be defined by:
164
- *
165
- * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
166
- *   returnType __declspec(dllimport) (* name)
167
- *
168
- * If you're using an earlier version of Microsoft Developer
169
- * Studio to access functions in a Win16 Cryptoki .dll, it might
170
- * be defined by:
171
- *
172
- * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
173
- *   returnType __export _far _pascal (* name)
174
- *
175
- * In a UNIX environment, it might be defined by:
176
- *
177
- * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
178
- *   returnType (* name)
179
- *
180
- *
181
- * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
182
- * a function pointer type for an application callback out of
183
- * a return type for the callback and a name for the callback.
184
- * It should be used in the following fashion:
185
- *
186
- * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
187
- *
188
- * to declare a function pointer, myCallback, to a callback
189
- * which takes arguments args and returns a CK_RV.  It can also
190
- * be used like this:
191
- *
192
- * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
193
- * myCallbackType myCallback;
194
- *
195
- * If you're using Microsoft Developer Studio 5.0 to do Win32
196
- * Cryptoki development, it might be defined by:
197
- *
198
- * #define CK_CALLBACK_FUNCTION(returnType, name) \
199
- *   returnType (* name)
200
- *
201
- * If you're using an earlier version of Microsoft Developer
202
- * Studio to do Win16 development, it might be defined by:
203
- *
204
- * #define CK_CALLBACK_FUNCTION(returnType, name) \
205
- *   returnType _far _pascal (* name)
206
- *
207
- * In a UNIX environment, it might be defined by:
208
- *
209
- * #define CK_CALLBACK_FUNCTION(returnType, name) \
210
- *   returnType (* name)
211
- *
212
- *
213
- * 6. NULL_PTR: This macro is the value of a NULL pointer.
214
- *
215
- * In any ANSI/ISO C environment (and in many others as well),
216
- * this should best be defined by
217
- *
218
- * #ifndef NULL_PTR
219
- * #define NULL_PTR 0
220
- * #endif
221
- */
222
-
223
-
224
-/* All the various Cryptoki types and #define'd values are in the
225
- * file pkcs11t.h. */
226
-#include "pkcs11t.h"
227
-
228
-#define __PASTE(x,y)      x##y
229
-
230
-
231
-/* ==============================================================
232
- * Define the "extern" form of all the entry points.
233
- * ==============================================================
234
- */
235
-
236
-#define CK_NEED_ARG_LIST  1
237
-#define CK_PKCS11_FUNCTION_INFO(name) \
238
-  extern CK_DECLARE_FUNCTION(CK_RV, name)
239
-
240
-/* pkcs11f.h has all the information about the Cryptoki
241
- * function prototypes. */
242
-#include "pkcs11f.h"
243
-
244
-#undef CK_NEED_ARG_LIST
245
-#undef CK_PKCS11_FUNCTION_INFO
246
-
247
-
248
-/* ==============================================================
249
- * Define the typedef form of all the entry points.  That is, for
250
- * each Cryptoki function C_XXX, define a type CK_C_XXX which is
251
- * a pointer to that kind of function.
252
- * ==============================================================
253
- */
254
-
255
-#define CK_NEED_ARG_LIST  1
256
-#define CK_PKCS11_FUNCTION_INFO(name) \
257
-  typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
258
-
259
-/* pkcs11f.h has all the information about the Cryptoki
260
- * function prototypes. */
261
-#include "pkcs11f.h"
262
-
263
-#undef CK_NEED_ARG_LIST
264
-#undef CK_PKCS11_FUNCTION_INFO
265
-
266
-
267
-/* ==============================================================
268
- * Define structed vector of entry points.  A CK_FUNCTION_LIST
269
- * contains a CK_VERSION indicating a library's Cryptoki version
270
- * and then a whole slew of function pointers to the routines in
271
- * the library.  This type was declared, but not defined, in
272
- * pkcs11t.h.
273
- * ==============================================================
274
- */
275
-
276
-#define CK_PKCS11_FUNCTION_INFO(name) \
277
-  __PASTE(CK_,name) name;
278
-  
279
-struct CK_FUNCTION_LIST {
280
-
281
-  CK_VERSION    version;  /* Cryptoki version */
282
-
283
-/* Pile all the function pointers into the CK_FUNCTION_LIST. */
284
-/* pkcs11f.h has all the information about the Cryptoki
285
- * function prototypes. */
286
-#include "pkcs11f.h"
287
-
288
-};
289
-
290
-#undef CK_PKCS11_FUNCTION_INFO
291
-
292
-
293
-#undef __PASTE
294
-
295
-#ifdef __cplusplus
296
-}
297
-#endif
298
-
299
-#endif
300 1
deleted file mode 100644
... ...
@@ -1,910 +0,0 @@
1
-/* pkcs11f.h include file for PKCS #11. */
2
-/* $Revision: 1.2 $ */
3
-
4
-/* License to copy and use this software is granted provided that it is
5
- * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
6
- * (Cryptoki)" in all material mentioning or referencing this software.
7
-
8
- * License is also granted to make and use derivative works provided that
9
- * such works are identified as "derived from the RSA Security Inc. PKCS #11
10
- * Cryptographic Token Interface (Cryptoki)" in all material mentioning or 
11
- * referencing the derived work.
12
-
13
- * RSA Security Inc. makes no representations concerning either the 
14
- * merchantability of this software or the suitability of this software for
15
- * any particular purpose. It is provided "as is" without express or implied
16
- * warranty of any kind.
17
- */
18
-
19
-/* This header file contains pretty much everything about all the */
20
-/* Cryptoki function prototypes.  Because this information is */
21
-/* used for more than just declaring function prototypes, the */
22
-/* order of the functions appearing herein is important, and */
23
-/* should not be altered. */
24
-
25
-/* General-purpose */
26
-
27
-/* C_Initialize initializes the Cryptoki library. */
28
-CK_PKCS11_FUNCTION_INFO(C_Initialize)
29
-#ifdef CK_NEED_ARG_LIST
30
-(
31
-  CK_VOID_PTR   pInitArgs  /* if this is not NULL_PTR, it gets
32
-                            * cast to CK_C_INITIALIZE_ARGS_PTR
33
-                            * and dereferenced */
34
-);
35
-#endif
36
-
37
-
38
-/* C_Finalize indicates that an application is done with the
39
- * Cryptoki library. */
40
-CK_PKCS11_FUNCTION_INFO(C_Finalize)
41
-#ifdef CK_NEED_ARG_LIST
42
-(
43
-  CK_VOID_PTR   pReserved  /* reserved.  Should be NULL_PTR */
44
-);
45
-#endif
46
-
47
-
48
-/* C_GetInfo returns general information about Cryptoki. */
49
-CK_PKCS11_FUNCTION_INFO(C_GetInfo)
50
-#ifdef CK_NEED_ARG_LIST
51
-(
52
-  CK_INFO_PTR   pInfo  /* location that receives information */
53
-);
54
-#endif
55
-
56
-
57
-/* C_GetFunctionList returns the function list. */
58
-CK_PKCS11_FUNCTION_INFO(C_GetFunctionList)
59
-#ifdef CK_NEED_ARG_LIST
60
-(
61
-  CK_FUNCTION_LIST_PTR_PTR ppFunctionList  /* receives pointer to
62
-                                            * function list */
63
-);
64
-#endif
65
-
66
-
67
-
68
-/* Slot and token management */
69
-
70
-/* C_GetSlotList obtains a list of slots in the system. */
71
-CK_PKCS11_FUNCTION_INFO(C_GetSlotList)
72
-#ifdef CK_NEED_ARG_LIST
73
-(
74
-  CK_BBOOL       tokenPresent,  /* only slots with tokens? */
75
-  CK_SLOT_ID_PTR pSlotList,     /* receives array of slot IDs */
76
-  CK_ULONG_PTR   pulCount       /* receives number of slots */
77
-);
78
-#endif
79
-
80
-
81
-/* C_GetSlotInfo obtains information about a particular slot in
82
- * the system. */
83
-CK_PKCS11_FUNCTION_INFO(C_GetSlotInfo)
84
-#ifdef CK_NEED_ARG_LIST
85
-(
86
-  CK_SLOT_ID       slotID,  /* the ID of the slot */
87
-  CK_SLOT_INFO_PTR pInfo    /* receives the slot information */
88
-);
89
-#endif
90
-
91
-
92
-/* C_GetTokenInfo obtains information about a particular token
93
- * in the system. */
94
-CK_PKCS11_FUNCTION_INFO(C_GetTokenInfo)
95
-#ifdef CK_NEED_ARG_LIST
96
-(
97
-  CK_SLOT_ID        slotID,  /* ID of the token's slot */
98
-  CK_TOKEN_INFO_PTR pInfo    /* receives the token information */
99
-);
100
-#endif
101
-
102
-
103
-/* C_GetMechanismList obtains a list of mechanism types
104
- * supported by a token. */
105
-CK_PKCS11_FUNCTION_INFO(C_GetMechanismList)
106
-#ifdef CK_NEED_ARG_LIST
107
-(
108
-  CK_SLOT_ID            slotID,          /* ID of token's slot */
109
-  CK_MECHANISM_TYPE_PTR pMechanismList,  /* gets mech. array */
110
-  CK_ULONG_PTR          pulCount         /* gets # of mechs. */
111
-);
112
-#endif
113
-
114
-
115
-/* C_GetMechanismInfo obtains information about a particular
116
- * mechanism possibly supported by a token. */
117
-CK_PKCS11_FUNCTION_INFO(C_GetMechanismInfo)
118
-#ifdef CK_NEED_ARG_LIST
119
-(
120
-  CK_SLOT_ID            slotID,  /* ID of the token's slot */
121
-  CK_MECHANISM_TYPE     type,    /* type of mechanism */
122
-  CK_MECHANISM_INFO_PTR pInfo    /* receives mechanism info */
123
-);
124
-#endif
125
-
126
-
127
-/* C_InitToken initializes a token. */
128
-CK_PKCS11_FUNCTION_INFO(C_InitToken)
129
-#ifdef CK_NEED_ARG_LIST
130
-/* pLabel changed from CK_CHAR_PTR to CK_UTF8CHAR_PTR for v2.10 */
131
-(
132
-  CK_SLOT_ID      slotID,    /* ID of the token's slot */
133
-  CK_UTF8CHAR_PTR pPin,      /* the SO's initial PIN */
134
-  CK_ULONG        ulPinLen,  /* length in bytes of the PIN */
135
-  CK_UTF8CHAR_PTR pLabel     /* 32-byte token label (blank padded) */
136
-);
137
-#endif
138
-
139
-
140
-/* C_InitPIN initializes the normal user's PIN. */
141
-CK_PKCS11_FUNCTION_INFO(C_InitPIN)
142
-#ifdef CK_NEED_ARG_LIST
143
-(
144
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
145
-  CK_UTF8CHAR_PTR   pPin,      /* the normal user's PIN */
146
-  CK_ULONG          ulPinLen   /* length in bytes of the PIN */
147
-);
148
-#endif
149
-
150
-
151
-/* C_SetPIN modifies the PIN of the user who is logged in. */
152
-CK_PKCS11_FUNCTION_INFO(C_SetPIN)
153
-#ifdef CK_NEED_ARG_LIST
154
-(
155
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
156
-  CK_UTF8CHAR_PTR   pOldPin,   /* the old PIN */
157
-  CK_ULONG          ulOldLen,  /* length of the old PIN */
158
-  CK_UTF8CHAR_PTR   pNewPin,   /* the new PIN */
159
-  CK_ULONG          ulNewLen   /* length of the new PIN */
160
-);
161
-#endif
162
-
163
-
164
-
165
-/* Session management */
166
-
167
-/* C_OpenSession opens a session between an application and a
168
- * token. */
169
-CK_PKCS11_FUNCTION_INFO(C_OpenSession)
170
-#ifdef CK_NEED_ARG_LIST
171
-(
172
-  CK_SLOT_ID            slotID,        /* the slot's ID */
173
-  CK_FLAGS              flags,         /* from CK_SESSION_INFO */
174
-  CK_VOID_PTR           pApplication,  /* passed to callback */
175
-  CK_NOTIFY             Notify,        /* callback function */
176
-  CK_SESSION_HANDLE_PTR phSession      /* gets session handle */
177
-);
178
-#endif
179
-
180
-
181
-/* C_CloseSession closes a session between an application and a
182
- * token. */
183
-CK_PKCS11_FUNCTION_INFO(C_CloseSession)
184
-#ifdef CK_NEED_ARG_LIST
185
-(
186
-  CK_SESSION_HANDLE hSession  /* the session's handle */
187
-);
188
-#endif
189
-
190
-/* C_CloseAllSessions closes all sessions with a token. */
191
-CK_PKCS11_FUNCTION_INFO(C_CloseAllSessions)
192
-#ifdef CK_NEED_ARG_LIST
193
-(
194
-  CK_SLOT_ID     slotID  /* the token's slot */
195
-);
196
-#endif
197
-
198
-
199
-/* C_GetSessionInfo obtains information about the session. */
200
-CK_PKCS11_FUNCTION_INFO(C_GetSessionInfo)
201
-#ifdef CK_NEED_ARG_LIST
202
-(
203
-  CK_SESSION_HANDLE   hSession,  /* the session's handle */
204
-  CK_SESSION_INFO_PTR pInfo      /* receives session info */
205
-);
206
-#endif
207
-
208
-
209
-/* C_GetOperationState obtains the state of the cryptographic operation
210
- * in a session. */
211
-CK_PKCS11_FUNCTION_INFO(C_GetOperationState)
212
-#ifdef CK_NEED_ARG_LIST
213
-(
214
-  CK_SESSION_HANDLE hSession,             /* session's handle */
215
-  CK_BYTE_PTR       pOperationState,      /* gets state */
216
-  CK_ULONG_PTR      pulOperationStateLen  /* gets state length */
217
-);
218
-#endif
219
-
220
-
221
-/* C_SetOperationState restores the state of the cryptographic
222
- * operation in a session. */
223
-CK_PKCS11_FUNCTION_INFO(C_SetOperationState)
224
-#ifdef CK_NEED_ARG_LIST
225
-(
226
-  CK_SESSION_HANDLE hSession,            /* session's handle */
227
-  CK_BYTE_PTR      pOperationState,      /* holds state */
228
-  CK_ULONG         ulOperationStateLen,  /* holds state length */
229
-  CK_OBJECT_HANDLE hEncryptionKey,       /* en/decryption key */
230
-  CK_OBJECT_HANDLE hAuthenticationKey    /* sign/verify key */
231
-);
232
-#endif
233
-
234
-
235
-/* C_Login logs a user into a token. */
236
-CK_PKCS11_FUNCTION_INFO(C_Login)
237
-#ifdef CK_NEED_ARG_LIST
238
-(
239
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
240
-  CK_USER_TYPE      userType,  /* the user type */
241
-  CK_UTF8CHAR_PTR   pPin,      /* the user's PIN */
242
-  CK_ULONG          ulPinLen   /* the length of the PIN */
243
-);
244
-#endif
245
-
246
-
247
-/* C_Logout logs a user out from a token. */
248
-CK_PKCS11_FUNCTION_INFO(C_Logout)
249
-#ifdef CK_NEED_ARG_LIST
250
-(
251
-  CK_SESSION_HANDLE hSession  /* the session's handle */
252
-);
253
-#endif
254
-
255
-
256
-
257
-/* Object management */
258
-
259
-/* C_CreateObject creates a new object. */
260
-CK_PKCS11_FUNCTION_INFO(C_CreateObject)
261
-#ifdef CK_NEED_ARG_LIST
262
-(
263
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
264
-  CK_ATTRIBUTE_PTR  pTemplate,   /* the object's template */
265
-  CK_ULONG          ulCount,     /* attributes in template */
266
-  CK_OBJECT_HANDLE_PTR phObject  /* gets new object's handle. */
267
-);
268
-#endif
269
-
270
-/* C_CopyObject copies an object, creating a new object for the
271
- * copy. */
272
-CK_PKCS11_FUNCTION_INFO(C_CopyObject)
273
-#ifdef CK_NEED_ARG_LIST
274
-(
275
-  CK_SESSION_HANDLE    hSession,    /* the session's handle */
276
-  CK_OBJECT_HANDLE     hObject,     /* the object's handle */
277
-  CK_ATTRIBUTE_PTR     pTemplate,   /* template for new object */
278
-  CK_ULONG             ulCount,     /* attributes in template */
279
-  CK_OBJECT_HANDLE_PTR phNewObject  /* receives handle of copy */
280
-);
281
-#endif
282
-
283
-
284
-/* C_DestroyObject destroys an object. */
285
-CK_PKCS11_FUNCTION_INFO(C_DestroyObject)
286
-#ifdef CK_NEED_ARG_LIST
287
-(
288
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
289
-  CK_OBJECT_HANDLE  hObject    /* the object's handle */
290
-);
291
-#endif
292
-
293
-
294
-/* C_GetObjectSize gets the size of an object in bytes. */
295
-CK_PKCS11_FUNCTION_INFO(C_GetObjectSize)
296
-#ifdef CK_NEED_ARG_LIST
297
-(
298
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
299
-  CK_OBJECT_HANDLE  hObject,   /* the object's handle */
300
-  CK_ULONG_PTR      pulSize    /* receives size of object */
301
-);
302
-#endif
303
-
304
-
305
-/* C_GetAttributeValue obtains the value of one or more object
306
- * attributes. */
307
-CK_PKCS11_FUNCTION_INFO(C_GetAttributeValue)
308
-#ifdef CK_NEED_ARG_LIST
309
-(
310
-  CK_SESSION_HANDLE hSession,   /* the session's handle */
311
-  CK_OBJECT_HANDLE  hObject,    /* the object's handle */
312
-  CK_ATTRIBUTE_PTR  pTemplate,  /* specifies attrs; gets vals */
313
-  CK_ULONG          ulCount     /* attributes in template */
314
-);
315
-#endif
316
-
317
-
318
-/* C_SetAttributeValue modifies the value of one or more object
319
- * attributes */
320
-CK_PKCS11_FUNCTION_INFO(C_SetAttributeValue)
321
-#ifdef CK_NEED_ARG_LIST
322
-(
323
-  CK_SESSION_HANDLE hSession,   /* the session's handle */
324
-  CK_OBJECT_HANDLE  hObject,    /* the object's handle */
325
-  CK_ATTRIBUTE_PTR  pTemplate,  /* specifies attrs and values */
326
-  CK_ULONG          ulCount     /* attributes in template */
327
-);
328
-#endif
329
-
330
-
331
-/* C_FindObjectsInit initializes a search for token and session
332
- * objects that match a template. */
333
-CK_PKCS11_FUNCTION_INFO(C_FindObjectsInit)
334
-#ifdef CK_NEED_ARG_LIST
335
-(
336
-  CK_SESSION_HANDLE hSession,   /* the session's handle */
337
-  CK_ATTRIBUTE_PTR  pTemplate,  /* attribute values to match */
338
-  CK_ULONG          ulCount     /* attrs in search template */
339
-);
340
-#endif
341
-
342
-
343
-/* C_FindObjects continues a search for token and session
344
- * objects that match a template, obtaining additional object
345
- * handles. */
346
-CK_PKCS11_FUNCTION_INFO(C_FindObjects)
347
-#ifdef CK_NEED_ARG_LIST
348
-(
349
- CK_SESSION_HANDLE    hSession,          /* session's handle */
350
- CK_OBJECT_HANDLE_PTR phObject,          /* gets obj. handles */
351
- CK_ULONG             ulMaxObjectCount,  /* max handles to get */
352
- CK_ULONG_PTR         pulObjectCount     /* actual # returned */
353
-);
354
-#endif
355
-
356
-
357
-/* C_FindObjectsFinal finishes a search for token and session
358
- * objects. */
359
-CK_PKCS11_FUNCTION_INFO(C_FindObjectsFinal)
360
-#ifdef CK_NEED_ARG_LIST
361
-(
362
-  CK_SESSION_HANDLE hSession  /* the session's handle */
363
-);
364
-#endif
365
-
366
-
367
-
368
-/* Encryption and decryption */
369
-
370
-/* C_EncryptInit initializes an encryption operation. */
371
-CK_PKCS11_FUNCTION_INFO(C_EncryptInit)
372
-#ifdef CK_NEED_ARG_LIST
373
-(
374
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
375
-  CK_MECHANISM_PTR  pMechanism,  /* the encryption mechanism */
376
-  CK_OBJECT_HANDLE  hKey         /* handle of encryption key */
377
-);
378
-#endif
379
-
380
-
381
-/* C_Encrypt encrypts single-part data. */
382
-CK_PKCS11_FUNCTION_INFO(C_Encrypt)
383
-#ifdef CK_NEED_ARG_LIST
384
-(
385
-  CK_SESSION_HANDLE hSession,            /* session's handle */
386
-  CK_BYTE_PTR       pData,               /* the plaintext data */
387
-  CK_ULONG          ulDataLen,           /* bytes of plaintext */
388
-  CK_BYTE_PTR       pEncryptedData,      /* gets ciphertext */
389
-  CK_ULONG_PTR      pulEncryptedDataLen  /* gets c-text size */
390
-);
391
-#endif
392
-
393
-
394
-/* C_EncryptUpdate continues a multiple-part encryption
395
- * operation. */
396
-CK_PKCS11_FUNCTION_INFO(C_EncryptUpdate)
397
-#ifdef CK_NEED_ARG_LIST
398
-(
399
-  CK_SESSION_HANDLE hSession,           /* session's handle */
400
-  CK_BYTE_PTR       pPart,              /* the plaintext data */
401
-  CK_ULONG          ulPartLen,          /* plaintext data len */
402
-  CK_BYTE_PTR       pEncryptedPart,     /* gets ciphertext */
403
-  CK_ULONG_PTR      pulEncryptedPartLen /* gets c-text size */
404
-);
405
-#endif
406
-
407
-
408
-/* C_EncryptFinal finishes a multiple-part encryption
409
- * operation. */
410
-CK_PKCS11_FUNCTION_INFO(C_EncryptFinal)
411
-#ifdef CK_NEED_ARG_LIST
412
-(
413
-  CK_SESSION_HANDLE hSession,                /* session handle */
414
-  CK_BYTE_PTR       pLastEncryptedPart,      /* last c-text */
415
-  CK_ULONG_PTR      pulLastEncryptedPartLen  /* gets last size */
416
-);
417
-#endif
418
-
419
-
420
-/* C_DecryptInit initializes a decryption operation. */
421
-CK_PKCS11_FUNCTION_INFO(C_DecryptInit)
422
-#ifdef CK_NEED_ARG_LIST
423
-(
424
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
425
-  CK_MECHANISM_PTR  pMechanism,  /* the decryption mechanism */
426
-  CK_OBJECT_HANDLE  hKey         /* handle of decryption key */
427
-);
428
-#endif
429
-
430
-
431
-/* C_Decrypt decrypts encrypted data in a single part. */
432
-CK_PKCS11_FUNCTION_INFO(C_Decrypt)
433
-#ifdef CK_NEED_ARG_LIST
434
-(
435
-  CK_SESSION_HANDLE hSession,           /* session's handle */
436
-  CK_BYTE_PTR       pEncryptedData,     /* ciphertext */
437
-  CK_ULONG          ulEncryptedDataLen, /* ciphertext length */
438
-  CK_BYTE_PTR       pData,              /* gets plaintext */
439
-  CK_ULONG_PTR      pulDataLen          /* gets p-text size */
440
-);
441
-#endif
442
-
443
-
444
-/* C_DecryptUpdate continues a multiple-part decryption
445
- * operation. */
446
-CK_PKCS11_FUNCTION_INFO(C_DecryptUpdate)
447
-#ifdef CK_NEED_ARG_LIST
448
-(
449
-  CK_SESSION_HANDLE hSession,            /* session's handle */
450
-  CK_BYTE_PTR       pEncryptedPart,      /* encrypted data */
451
-  CK_ULONG          ulEncryptedPartLen,  /* input length */
452
-  CK_BYTE_PTR       pPart,               /* gets plaintext */
453
-  CK_ULONG_PTR      pulPartLen           /* p-text size */
454
-);
455
-#endif
456
-
457
-
458
-/* C_DecryptFinal finishes a multiple-part decryption
459
- * operation. */
460
-CK_PKCS11_FUNCTION_INFO(C_DecryptFinal)
461
-#ifdef CK_NEED_ARG_LIST
462
-(
463
-  CK_SESSION_HANDLE hSession,       /* the session's handle */
464
-  CK_BYTE_PTR       pLastPart,      /* gets plaintext */
465
-  CK_ULONG_PTR      pulLastPartLen  /* p-text size */
466
-);
467
-#endif
468
-
469
-
470
-
471
-/* Message digesting */
472
-
473
-/* C_DigestInit initializes a message-digesting operation. */
474
-CK_PKCS11_FUNCTION_INFO(C_DigestInit)
475
-#ifdef CK_NEED_ARG_LIST
476
-(
477
-  CK_SESSION_HANDLE hSession,   /* the session's handle */
478
-  CK_MECHANISM_PTR  pMechanism  /* the digesting mechanism */
479
-);
480
-#endif
481
-
482
-
483
-/* C_Digest digests data in a single part. */
484
-CK_PKCS11_FUNCTION_INFO(C_Digest)
485
-#ifdef CK_NEED_ARG_LIST
486
-(
487
-  CK_SESSION_HANDLE hSession,     /* the session's handle */
488
-  CK_BYTE_PTR       pData,        /* data to be digested */
489
-  CK_ULONG          ulDataLen,    /* bytes of data to digest */
490
-  CK_BYTE_PTR       pDigest,      /* gets the message digest */
491
-  CK_ULONG_PTR      pulDigestLen  /* gets digest length */
492
-);
493
-#endif
494
-
495
-
496
-/* C_DigestUpdate continues a multiple-part message-digesting
497
- * operation. */
498
-CK_PKCS11_FUNCTION_INFO(C_DigestUpdate)
499
-#ifdef CK_NEED_ARG_LIST
500
-(
501
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
502
-  CK_BYTE_PTR       pPart,     /* data to be digested */
503
-  CK_ULONG          ulPartLen  /* bytes of data to be digested */
504
-);
505
-#endif
506
-
507
-
508
-/* C_DigestKey continues a multi-part message-digesting
509
- * operation, by digesting the value of a secret key as part of
510
- * the data already digested. */
511
-CK_PKCS11_FUNCTION_INFO(C_DigestKey)
512
-#ifdef CK_NEED_ARG_LIST
513
-(
514
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
515
-  CK_OBJECT_HANDLE  hKey       /* secret key to digest */
516
-);
517
-#endif
518
-
519
-
520
-/* C_DigestFinal finishes a multiple-part message-digesting
521
- * operation. */
522
-CK_PKCS11_FUNCTION_INFO(C_DigestFinal)
523
-#ifdef CK_NEED_ARG_LIST
524
-(
525
-  CK_SESSION_HANDLE hSession,     /* the session's handle */
526
-  CK_BYTE_PTR       pDigest,      /* gets the message digest */
527
-  CK_ULONG_PTR      pulDigestLen  /* gets byte count of digest */
528
-);
529
-#endif
530
-
531
-
532
-
533
-/* Signing and MACing */
534
-
535
-/* C_SignInit initializes a signature (private key encryption)
536
- * operation, where the signature is (will be) an appendix to
537
- * the data, and plaintext cannot be recovered from the
538
- *signature. */
539
-CK_PKCS11_FUNCTION_INFO(C_SignInit)
540
-#ifdef CK_NEED_ARG_LIST
541
-(
542
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
543
-  CK_MECHANISM_PTR  pMechanism,  /* the signature mechanism */
544
-  CK_OBJECT_HANDLE  hKey         /* handle of signature key */
545
-);
546
-#endif
547
-
548
-
549
-/* C_Sign signs (encrypts with private key) data in a single
550
- * part, where the signature is (will be) an appendix to the
551
- * data, and plaintext cannot be recovered from the signature. */
552
-CK_PKCS11_FUNCTION_INFO(C_Sign)
553
-#ifdef CK_NEED_ARG_LIST
554
-(
555
-  CK_SESSION_HANDLE hSession,        /* the session's handle */
556
-  CK_BYTE_PTR       pData,           /* the data to sign */
557
-  CK_ULONG          ulDataLen,       /* count of bytes to sign */
558
-  CK_BYTE_PTR       pSignature,      /* gets the signature */
559
-  CK_ULONG_PTR      pulSignatureLen  /* gets signature length */
560
-);
561
-#endif
562
-
563
-
564
-/* C_SignUpdate continues a multiple-part signature operation,
565
- * where the signature is (will be) an appendix to the data, 
566
- * and plaintext cannot be recovered from the signature. */
567
-CK_PKCS11_FUNCTION_INFO(C_SignUpdate)
568
-#ifdef CK_NEED_ARG_LIST
569
-(
570
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
571
-  CK_BYTE_PTR       pPart,     /* the data to sign */
572
-  CK_ULONG          ulPartLen  /* count of bytes to sign */
573
-);
574
-#endif
575
-
576
-
577
-/* C_SignFinal finishes a multiple-part signature operation, 
578
- * returning the signature. */
579
-CK_PKCS11_FUNCTION_INFO(C_SignFinal)
580
-#ifdef CK_NEED_ARG_LIST
581
-(
582
-  CK_SESSION_HANDLE hSession,        /* the session's handle */
583
-  CK_BYTE_PTR       pSignature,      /* gets the signature */
584
-  CK_ULONG_PTR      pulSignatureLen  /* gets signature length */
585
-);
586
-#endif
587
-
588
-
589
-/* C_SignRecoverInit initializes a signature operation, where
590
- * the data can be recovered from the signature. */
591
-CK_PKCS11_FUNCTION_INFO(C_SignRecoverInit)
592
-#ifdef CK_NEED_ARG_LIST
593
-(
594
-  CK_SESSION_HANDLE hSession,   /* the session's handle */
595
-  CK_MECHANISM_PTR  pMechanism, /* the signature mechanism */
596
-  CK_OBJECT_HANDLE  hKey        /* handle of the signature key */
597
-);
598
-#endif
599
-
600
-
601
-/* C_SignRecover signs data in a single operation, where the
602
- * data can be recovered from the signature. */
603
-CK_PKCS11_FUNCTION_INFO(C_SignRecover)
604
-#ifdef CK_NEED_ARG_LIST
605
-(
606
-  CK_SESSION_HANDLE hSession,        /* the session's handle */
607
-  CK_BYTE_PTR       pData,           /* the data to sign */
608
-  CK_ULONG          ulDataLen,       /* count of bytes to sign */
609
-  CK_BYTE_PTR       pSignature,      /* gets the signature */
610
-  CK_ULONG_PTR      pulSignatureLen  /* gets signature length */
611
-);
612
-#endif
613
-
614
-
615
-
616
-/* Verifying signatures and MACs */
617
-
618
-/* C_VerifyInit initializes a verification operation, where the
619
- * signature is an appendix to the data, and plaintext cannot
620
- *  cannot be recovered from the signature (e.g. DSA). */
621
-CK_PKCS11_FUNCTION_INFO(C_VerifyInit)
622
-#ifdef CK_NEED_ARG_LIST
623
-(
624
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
625
-  CK_MECHANISM_PTR  pMechanism,  /* the verification mechanism */
626
-  CK_OBJECT_HANDLE  hKey         /* verification key */ 
627
-);
628
-#endif
629
-
630
-
631
-/* C_Verify verifies a signature in a single-part operation, 
632
- * where the signature is an appendix to the data, and plaintext
633
- * cannot be recovered from the signature. */
634
-CK_PKCS11_FUNCTION_INFO(C_Verify)
635
-#ifdef CK_NEED_ARG_LIST
636
-(
637
-  CK_SESSION_HANDLE hSession,       /* the session's handle */
638
-  CK_BYTE_PTR       pData,          /* signed data */
639
-  CK_ULONG          ulDataLen,      /* length of signed data */
640
-  CK_BYTE_PTR       pSignature,     /* signature */
641
-  CK_ULONG          ulSignatureLen  /* signature length*/
642
-);
643
-#endif
644
-
645
-
646
-/* C_VerifyUpdate continues a multiple-part verification
647
- * operation, where the signature is an appendix to the data, 
648
- * and plaintext cannot be recovered from the signature. */
649
-CK_PKCS11_FUNCTION_INFO(C_VerifyUpdate)
650
-#ifdef CK_NEED_ARG_LIST
651
-(
652
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
653
-  CK_BYTE_PTR       pPart,     /* signed data */
654
-  CK_ULONG          ulPartLen  /* length of signed data */
655
-);
656
-#endif
657
-
658
-
659
-/* C_VerifyFinal finishes a multiple-part verification
660
- * operation, checking the signature. */
661
-CK_PKCS11_FUNCTION_INFO(C_VerifyFinal)
662
-#ifdef CK_NEED_ARG_LIST
663
-(
664
-  CK_SESSION_HANDLE hSession,       /* the session's handle */
665
-  CK_BYTE_PTR       pSignature,     /* signature to verify */
666
-  CK_ULONG          ulSignatureLen  /* signature length */
667
-);
668
-#endif
669
-
670
-
671
-/* C_VerifyRecoverInit initializes a signature verification
672
- * operation, where the data is recovered from the signature. */
673
-CK_PKCS11_FUNCTION_INFO(C_VerifyRecoverInit)
674
-#ifdef CK_NEED_ARG_LIST
675
-(
676
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
677
-  CK_MECHANISM_PTR  pMechanism,  /* the verification mechanism */
678
-  CK_OBJECT_HANDLE  hKey         /* verification key */
679
-);
680
-#endif
681
-
682
-
683
-/* C_VerifyRecover verifies a signature in a single-part
684
- * operation, where the data is recovered from the signature. */
685
-CK_PKCS11_FUNCTION_INFO(C_VerifyRecover)
686
-#ifdef CK_NEED_ARG_LIST
687
-(
688
-  CK_SESSION_HANDLE hSession,        /* the session's handle */
689
-  CK_BYTE_PTR       pSignature,      /* signature to verify */
690
-  CK_ULONG          ulSignatureLen,  /* signature length */
691
-  CK_BYTE_PTR       pData,           /* gets signed data */
692
-  CK_ULONG_PTR      pulDataLen       /* gets signed data len */
693
-);
694
-#endif
695
-
696
-
697
-
698
-/* Dual-function cryptographic operations */
699
-
700
-/* C_DigestEncryptUpdate continues a multiple-part digesting
701
- * and encryption operation. */
702
-CK_PKCS11_FUNCTION_INFO(C_DigestEncryptUpdate)
703
-#ifdef CK_NEED_ARG_LIST
704
-(
705
-  CK_SESSION_HANDLE hSession,            /* session's handle */
706
-  CK_BYTE_PTR       pPart,               /* the plaintext data */
707
-  CK_ULONG          ulPartLen,           /* plaintext length */
708
-  CK_BYTE_PTR       pEncryptedPart,      /* gets ciphertext */
709
-  CK_ULONG_PTR      pulEncryptedPartLen  /* gets c-text length */
710
-);
711
-#endif
712
-
713
-
714
-/* C_DecryptDigestUpdate continues a multiple-part decryption and
715
- * digesting operation. */
716
-CK_PKCS11_FUNCTION_INFO(C_DecryptDigestUpdate)
717
-#ifdef CK_NEED_ARG_LIST
718
-(
719
-  CK_SESSION_HANDLE hSession,            /* session's handle */
720
-  CK_BYTE_PTR       pEncryptedPart,      /* ciphertext */
721
-  CK_ULONG          ulEncryptedPartLen,  /* ciphertext length */
722
-  CK_BYTE_PTR       pPart,               /* gets plaintext */
723
-  CK_ULONG_PTR      pulPartLen           /* gets plaintext len */
724
-);
725
-#endif
726
-
727
-
728
-/* C_SignEncryptUpdate continues a multiple-part signing and
729
- * encryption operation. */
730
-CK_PKCS11_FUNCTION_INFO(C_SignEncryptUpdate)
731
-#ifdef CK_NEED_ARG_LIST
732
-(
733
-  CK_SESSION_HANDLE hSession,            /* session's handle */
734
-  CK_BYTE_PTR       pPart,               /* the plaintext data */
735
-  CK_ULONG          ulPartLen,           /* plaintext length */
736
-  CK_BYTE_PTR       pEncryptedPart,      /* gets ciphertext */
737
-  CK_ULONG_PTR      pulEncryptedPartLen  /* gets c-text length */
738
-);
739
-#endif
740
-
741
-
742
-/* C_DecryptVerifyUpdate continues a multiple-part decryption and
743
- * verify operation. */
744
-CK_PKCS11_FUNCTION_INFO(C_DecryptVerifyUpdate)
745
-#ifdef CK_NEED_ARG_LIST
746
-(
747
-  CK_SESSION_HANDLE hSession,            /* session's handle */
748
-  CK_BYTE_PTR       pEncryptedPart,      /* ciphertext */
749
-  CK_ULONG          ulEncryptedPartLen,  /* ciphertext length */
750
-  CK_BYTE_PTR       pPart,               /* gets plaintext */
751
-  CK_ULONG_PTR      pulPartLen           /* gets p-text length */
752
-);
753
-#endif
754
-
755
-
756
-
757
-/* Key management */
758
-
759
-/* C_GenerateKey generates a secret key, creating a new key
760
- * object. */
761
-CK_PKCS11_FUNCTION_INFO(C_GenerateKey)
762
-#ifdef CK_NEED_ARG_LIST
763
-(
764
-  CK_SESSION_HANDLE    hSession,    /* the session's handle */
765
-  CK_MECHANISM_PTR     pMechanism,  /* key generation mech. */
766
-  CK_ATTRIBUTE_PTR     pTemplate,   /* template for new key */
767
-  CK_ULONG             ulCount,     /* # of attrs in template */
768
-  CK_OBJECT_HANDLE_PTR phKey        /* gets handle of new key */
769
-);
770
-#endif
771
-
772
-
773
-/* C_GenerateKeyPair generates a public-key/private-key pair, 
774
- * creating new key objects. */
775
-CK_PKCS11_FUNCTION_INFO(C_GenerateKeyPair)
776
-#ifdef CK_NEED_ARG_LIST
777
-(
778
-  CK_SESSION_HANDLE    hSession,                    /* session
779
-                                                     * handle */
780
-  CK_MECHANISM_PTR     pMechanism,                  /* key-gen
781
-                                                     * mech. */
782
-  CK_ATTRIBUTE_PTR     pPublicKeyTemplate,          /* template
783
-                                                     * for pub.
784
-                                                     * key */
785
-  CK_ULONG             ulPublicKeyAttributeCount,   /* # pub.
786
-                                                     * attrs. */
787
-  CK_ATTRIBUTE_PTR     pPrivateKeyTemplate,         /* template
788
-                                                     * for priv.
789
-                                                     * key */
790
-  CK_ULONG             ulPrivateKeyAttributeCount,  /* # priv.
791
-                                                     * attrs. */
792
-  CK_OBJECT_HANDLE_PTR phPublicKey,                 /* gets pub.
793
-                                                     * key
794
-                                                     * handle */
795
-  CK_OBJECT_HANDLE_PTR phPrivateKey                 /* gets
796
-                                                     * priv. key
797
-                                                     * handle */
798
-);
799
-#endif
800
-
801
-
802
-/* C_WrapKey wraps (i.e., encrypts) a key. */
803
-CK_PKCS11_FUNCTION_INFO(C_WrapKey)
804
-#ifdef CK_NEED_ARG_LIST
805
-(
806
-  CK_SESSION_HANDLE hSession,        /* the session's handle */
807
-  CK_MECHANISM_PTR  pMechanism,      /* the wrapping mechanism */
808
-  CK_OBJECT_HANDLE  hWrappingKey,    /* wrapping key */
809
-  CK_OBJECT_HANDLE  hKey,            /* key to be wrapped */
810
-  CK_BYTE_PTR       pWrappedKey,     /* gets wrapped key */
811
-  CK_ULONG_PTR      pulWrappedKeyLen /* gets wrapped key size */
812
-);
813
-#endif
814
-
815
-
816
-/* C_UnwrapKey unwraps (decrypts) a wrapped key, creating a new
817
- * key object. */
818
-CK_PKCS11_FUNCTION_INFO(C_UnwrapKey)
819
-#ifdef CK_NEED_ARG_LIST
820
-(
821
-  CK_SESSION_HANDLE    hSession,          /* session's handle */
822
-  CK_MECHANISM_PTR     pMechanism,        /* unwrapping mech. */
823
-  CK_OBJECT_HANDLE     hUnwrappingKey,    /* unwrapping key */
824
-  CK_BYTE_PTR          pWrappedKey,       /* the wrapped key */
825
-  CK_ULONG             ulWrappedKeyLen,   /* wrapped key len */
826
-  CK_ATTRIBUTE_PTR     pTemplate,         /* new key template */
827
-  CK_ULONG             ulAttributeCount,  /* template length */
828
-  CK_OBJECT_HANDLE_PTR phKey              /* gets new handle */
829
-);
830
-#endif
831
-
832
-
833
-/* C_DeriveKey derives a key from a base key, creating a new key
834
- * object. */
835
-CK_PKCS11_FUNCTION_INFO(C_DeriveKey)
836
-#ifdef CK_NEED_ARG_LIST
837
-(
838
-  CK_SESSION_HANDLE    hSession,          /* session's handle */
839
-  CK_MECHANISM_PTR     pMechanism,        /* key deriv. mech. */
840
-  CK_OBJECT_HANDLE     hBaseKey,          /* base key */
841
-  CK_ATTRIBUTE_PTR     pTemplate,         /* new key template */
842
-  CK_ULONG             ulAttributeCount,  /* template length */
843
-  CK_OBJECT_HANDLE_PTR phKey              /* gets new handle */
844
-);
845
-#endif
846
-
847
-
848
-
849
-/* Random number generation */
850
-
851
-/* C_SeedRandom mixes additional seed material into the token's
852
- * random number generator. */
853
-CK_PKCS11_FUNCTION_INFO(C_SeedRandom)
854
-#ifdef CK_NEED_ARG_LIST
855
-(
856
-  CK_SESSION_HANDLE hSession,  /* the session's handle */
857
-  CK_BYTE_PTR       pSeed,     /* the seed material */
858
-  CK_ULONG          ulSeedLen  /* length of seed material */
859
-);
860
-#endif
861
-
862
-
863
-/* C_GenerateRandom generates random data. */
864
-CK_PKCS11_FUNCTION_INFO(C_GenerateRandom)
865
-#ifdef CK_NEED_ARG_LIST
866
-(
867
-  CK_SESSION_HANDLE hSession,    /* the session's handle */
868
-  CK_BYTE_PTR       RandomData,  /* receives the random data */
869
-  CK_ULONG          ulRandomLen  /* # of bytes to generate */
870
-);
871
-#endif
872
-
873
-
874
-
875
-/* Parallel function management */
876
-
877
-/* C_GetFunctionStatus is a legacy function; it obtains an
878
- * updated status of a function running in parallel with an
879
- * application. */
880
-CK_PKCS11_FUNCTION_INFO(C_GetFunctionStatus)
881
-#ifdef CK_NEED_ARG_LIST
882
-(
883
-  CK_SESSION_HANDLE hSession  /* the session's handle */
884
-);
885
-#endif
886
-
887
-
888
-/* C_CancelFunction is a legacy function; it cancels a function
889
- * running in parallel. */
890
-CK_PKCS11_FUNCTION_INFO(C_CancelFunction)
891
-#ifdef CK_NEED_ARG_LIST
892
-(
893
-  CK_SESSION_HANDLE hSession  /* the session's handle */
894
-);
895
-#endif
896
-
897
-
898
-
899
-/* Functions added in for Cryptoki Version 2.01 or later */
900
-
901
-/* C_WaitForSlotEvent waits for a slot event (token insertion,
902
- * removal, etc.) to occur. */
903
-CK_PKCS11_FUNCTION_INFO(C_WaitForSlotEvent)
904
-#ifdef CK_NEED_ARG_LIST
905
-(
906
-  CK_FLAGS flags,        /* blocking/nonblocking flag */
907
-  CK_SLOT_ID_PTR pSlot,  /* location that receives the slot ID */
908
-  CK_VOID_PTR pRserved   /* reserved.  Should be NULL_PTR */
909
-);
910
-#endif
911 1
deleted file mode 100644
... ...
@@ -1,1885 +0,0 @@
1
-/* pkcs11t.h include file for PKCS #11. */
2
-/* $Revision: 1.2 $ */
3
-
4
-/* License to copy and use this software is granted provided that it is
5
- * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
6
- * (Cryptoki)" in all material mentioning or referencing this software.
7
-
8
- * License is also granted to make and use derivative works provided that
9
- * such works are identified as "derived from the RSA Security Inc. PKCS #11
10
- * Cryptographic Token Interface (Cryptoki)" in all material mentioning or
11
- * referencing the derived work.
12
-
13
- * RSA Security Inc. makes no representations concerning either the
14
- * merchantability of this software or the suitability of this software for
15
- * any particular purpose. It is provided "as is" without express or implied
16
- * warranty of any kind.
17
- */
18
-
19
-/* See top of pkcs11.h for information about the macros that
20
- * must be defined and the structure-packing conventions that
21
- * must be set before including this file. */
22
-
23
-#ifndef _PKCS11T_H_
24
-#define _PKCS11T_H_ 1
25
-
26
-#define CRYPTOKI_VERSION_MAJOR 2
27
-#define CRYPTOKI_VERSION_MINOR 20
28
-#define CRYPTOKI_VERSION_AMENDMENT 3
29
-
30
-#define CK_TRUE 1
31
-#define CK_FALSE 0
32
-
33
-#ifndef CK_DISABLE_TRUE_FALSE
34
-#ifndef FALSE
35
-#define FALSE CK_FALSE
36
-#endif
37
-
38
-#ifndef TRUE
39
-#define TRUE CK_TRUE
40
-#endif
41
-#endif
42
-
43
-/* an unsigned 8-bit value */
44
-typedef unsigned char     CK_BYTE;
45
-
46
-/* an unsigned 8-bit character */
47
-typedef CK_BYTE           CK_CHAR;
48
-
49
-/* an 8-bit UTF-8 character */
50
-typedef CK_BYTE           CK_UTF8CHAR;
51
-
52
-/* a BYTE-sized Boolean flag */
53
-typedef CK_BYTE           CK_BBOOL;
54
-
55
-/* an unsigned value, at least 32 bits long */
56
-typedef unsigned long int CK_ULONG;
57
-
58
-/* a signed value, the same size as a CK_ULONG */
59
-/* CK_LONG is new for v2.0 */
60
-typedef long int          CK_LONG;
61
-
62
-/* at least 32 bits; each bit is a Boolean flag */
63
-typedef CK_ULONG          CK_FLAGS;
64
-
65
-
66
-/* some special values for certain CK_ULONG variables */
67
-#define CK_UNAVAILABLE_INFORMATION (~0UL)
68
-#define CK_EFFECTIVELY_INFINITE    0
69
-
70
-
71
-typedef CK_BYTE     CK_PTR   CK_BYTE_PTR;
72
-typedef CK_CHAR     CK_PTR   CK_CHAR_PTR;
73
-typedef CK_UTF8CHAR CK_PTR   CK_UTF8CHAR_PTR;
74
-typedef CK_ULONG    CK_PTR   CK_ULONG_PTR;
75
-typedef void        CK_PTR   CK_VOID_PTR;
76
-
77
-/* Pointer to a CK_VOID_PTR-- i.e., pointer to pointer to void */
78
-typedef CK_VOID_PTR CK_PTR CK_VOID_PTR_PTR;
79
-
80
-
81
-/* The following value is always invalid if used as a session */
82
-/* handle or object handle */
83
-#define CK_INVALID_HANDLE 0
84
-
85
-
86
-typedef struct CK_VERSION {
87
-  CK_BYTE       major;  /* integer portion of version number */
88
-  CK_BYTE       minor;  /* 1/100ths portion of version number */
89
-} CK_VERSION;
90
-
91
-typedef CK_VERSION CK_PTR CK_VERSION_PTR;
92
-
93
-
94
-typedef struct CK_INFO {
95
-  /* manufacturerID and libraryDecription have been changed from
96
-   * CK_CHAR to CK_UTF8CHAR for v2.10 */
97
-  CK_VERSION    cryptokiVersion;     /* Cryptoki interface ver */
98
-  CK_UTF8CHAR   manufacturerID[32];  /* blank padded */
99
-  CK_FLAGS      flags;               /* must be zero */
100
-
101
-  /* libraryDescription and libraryVersion are new for v2.0 */
102
-  CK_UTF8CHAR   libraryDescription[32];  /* blank padded */
103
-  CK_VERSION    libraryVersion;          /* version of library */
104
-} CK_INFO;
105
-
106
-typedef CK_INFO CK_PTR    CK_INFO_PTR;
107
-
108
-
109
-/* CK_NOTIFICATION enumerates the types of notifications that
110
- * Cryptoki provides to an application */
111
-/* CK_NOTIFICATION has been changed from an enum to a CK_ULONG
112
- * for v2.0 */
113
-typedef CK_ULONG CK_NOTIFICATION;
114
-#define CKN_SURRENDER       0
115
-
116
-/* The following notification is new for PKCS #11 v2.20 amendment 3 */
117
-#define CKN_OTP_CHANGED     1
118
-
119
-
120
-typedef CK_ULONG          CK_SLOT_ID;
121
-
122
-typedef CK_SLOT_ID CK_PTR CK_SLOT_ID_PTR;
123
-
124
-
125
-/* CK_SLOT_INFO provides information about a slot */
126
-typedef struct CK_SLOT_INFO {
127
-  /* slotDescription and manufacturerID have been changed from
128
-   * CK_CHAR to CK_UTF8CHAR for v2.10 */
129
-  CK_UTF8CHAR   slotDescription[64];  /* blank padded */
130
-  CK_UTF8CHAR   manufacturerID[32];   /* blank padded */
131
-  CK_FLAGS      flags;
132
-
133
-  /* hardwareVersion and firmwareVersion are new for v2.0 */
134
-  CK_VERSION    hardwareVersion;  /* version of hardware */
135
-  CK_VERSION    firmwareVersion;  /* version of firmware */
136
-} CK_SLOT_INFO;
137
-
138
-/* flags: bit flags that provide capabilities of the slot
139
- *      Bit Flag              Mask        Meaning
140
- */
141
-#define CKF_TOKEN_PRESENT     0x00000001  /* a token is there */
142
-#define CKF_REMOVABLE_DEVICE  0x00000002  /* removable devices*/
143
-#define CKF_HW_SLOT           0x00000004  /* hardware slot */
144
-
145
-typedef CK_SLOT_INFO CK_PTR CK_SLOT_INFO_PTR;
146
-
147
-
148
-/* CK_TOKEN_INFO provides information about a token */
149
-typedef struct CK_TOKEN_INFO {
150
-  /* label, manufacturerID, and model have been changed from
151
-   * CK_CHAR to CK_UTF8CHAR for v2.10 */
152
-  CK_UTF8CHAR   label[32];           /* blank padded */
153
-  CK_UTF8CHAR   manufacturerID[32];  /* blank padded */
154
-  CK_UTF8CHAR   model[16];           /* blank padded */
155
-  CK_CHAR       serialNumber[16];    /* blank padded */
156
-  CK_FLAGS      flags;               /* see below */
157
-
158
-  /* ulMaxSessionCount, ulSessionCount, ulMaxRwSessionCount,
159
-   * ulRwSessionCount, ulMaxPinLen, and ulMinPinLen have all been
160
-   * changed from CK_USHORT to CK_ULONG for v2.0 */
161
-  CK_ULONG      ulMaxSessionCount;     /* max open sessions */
162
-  CK_ULONG      ulSessionCount;        /* sess. now open */
163
-  CK_ULONG      ulMaxRwSessionCount;   /* max R/W sessions */
164
-  CK_ULONG      ulRwSessionCount;      /* R/W sess. now open */
165
-  CK_ULONG      ulMaxPinLen;           /* in bytes */
166
-  CK_ULONG      ulMinPinLen;           /* in bytes */
167
-  CK_ULONG      ulTotalPublicMemory;   /* in bytes */
168
-  CK_ULONG      ulFreePublicMemory;    /* in bytes */
169
-  CK_ULONG      ulTotalPrivateMemory;  /* in bytes */
170
-  CK_ULONG      ulFreePrivateMemory;   /* in bytes */
171
-
172
-  /* hardwareVersion, firmwareVersion, and time are new for
173
-   * v2.0 */
174
-  CK_VERSION    hardwareVersion;       /* version of hardware */
175
-  CK_VERSION    firmwareVersion;       /* version of firmware */
176
-  CK_CHAR       utcTime[16];           /* time */
177
-} CK_TOKEN_INFO;
178
-
179
-/* The flags parameter is defined as follows:
180
- *      Bit Flag                    Mask        Meaning
181
- */
182
-#define CKF_RNG                     0x00000001  /* has random #
183
-                                                 * generator */
184
-#define CKF_WRITE_PROTECTED         0x00000002  /* token is
185
-                                                 * write-
186
-                                                 * protected */
187
-#define CKF_LOGIN_REQUIRED          0x00000004  /* user must
188
-                                                 * login */
189
-#define CKF_USER_PIN_INITIALIZED    0x00000008  /* normal user's
190
-                                                 * PIN is set */
191
-
192
-/* CKF_RESTORE_KEY_NOT_NEEDED is new for v2.0.  If it is set,
193
- * that means that *every* time the state of cryptographic
194
- * operations of a session is successfully saved, all keys
195
- * needed to continue those operations are stored in the state */
196
-#define CKF_RESTORE_KEY_NOT_NEEDED  0x00000020
197
-
198
-/* CKF_CLOCK_ON_TOKEN is new for v2.0.  If it is set, that means
199
- * that the token has some sort of clock.  The time on that
200
- * clock is returned in the token info structure */
201
-#define CKF_CLOCK_ON_TOKEN          0x00000040
202
-
203
-/* CKF_PROTECTED_AUTHENTICATION_PATH is new for v2.0.  If it is
204
- * set, that means that there is some way for the user to login
205
- * without sending a PIN through the Cryptoki library itself */
206
-#define CKF_PROTECTED_AUTHENTICATION_PATH 0x00000100
207
-
208
-/* CKF_DUAL_CRYPTO_OPERATIONS is new for v2.0.  If it is true,
209
- * that means that a single session with the token can perform
210
- * dual simultaneous cryptographic operations (digest and
211
- * encrypt; decrypt and digest; sign and encrypt; and decrypt
212
- * and sign) */
213
-#define CKF_DUAL_CRYPTO_OPERATIONS  0x00000200
214
-
215
-/* CKF_TOKEN_INITIALIZED if new for v2.10. If it is true, the
216
- * token has been initialized using C_InitializeToken or an
217
- * equivalent mechanism outside the scope of PKCS #11.
218
- * Calling C_InitializeToken when this flag is set will cause
219
- * the token to be reinitialized. */
220
-#define CKF_TOKEN_INITIALIZED       0x00000400
221
-
222
-/* CKF_SECONDARY_AUTHENTICATION if new for v2.10. If it is
223
- * true, the token supports secondary authentication for
224
- * private key objects. This flag is deprecated in v2.11 and
225
-   onwards. */
226
-#define CKF_SECONDARY_AUTHENTICATION  0x00000800
227
-
228
-/* CKF_USER_PIN_COUNT_LOW if new for v2.10. If it is true, an
229
- * incorrect user login PIN has been entered at least once
230
- * since the last successful authentication. */
231
-#define CKF_USER_PIN_COUNT_LOW       0x00010000
232
-
233
-/* CKF_USER_PIN_FINAL_TRY if new for v2.10. If it is true,
234
- * supplying an incorrect user PIN will it to become locked. */
235
-#define CKF_USER_PIN_FINAL_TRY       0x00020000
236
-
237
-/* CKF_USER_PIN_LOCKED if new for v2.10. If it is true, the
238
- * user PIN has been locked. User login to the token is not
239
- * possible. */
240
-#define CKF_USER_PIN_LOCKED          0x00040000
241
-
242
-/* CKF_USER_PIN_TO_BE_CHANGED if new for v2.10. If it is true,
243
- * the user PIN value is the default value set by token
244
- * initialization or manufacturing, or the PIN has been
245
- * expired by the card. */
246
-#define CKF_USER_PIN_TO_BE_CHANGED   0x00080000
247
-
248
-/* CKF_SO_PIN_COUNT_LOW if new for v2.10. If it is true, an
249
- * incorrect SO login PIN has been entered at least once since
250
- * the last successful authentication. */
251
-#define CKF_SO_PIN_COUNT_LOW         0x00100000
252
-
253
-/* CKF_SO_PIN_FINAL_TRY if new for v2.10. If it is true,
254
- * supplying an incorrect SO PIN will it to become locked. */
255
-#define CKF_SO_PIN_FINAL_TRY         0x00200000
256
-
257
-/* CKF_SO_PIN_LOCKED if new for v2.10. If it is true, the SO
258
- * PIN has been locked. SO login to the token is not possible.
259
- */
260
-#define CKF_SO_PIN_LOCKED            0x00400000
261
-
262
-/* CKF_SO_PIN_TO_BE_CHANGED if new for v2.10. If it is true,
263
- * the SO PIN value is the default value set by token
264
- * initialization or manufacturing, or the PIN has been
265
- * expired by the card. */
266
-#define CKF_SO_PIN_TO_BE_CHANGED     0x00800000
267
-
268
-typedef CK_TOKEN_INFO CK_PTR CK_TOKEN_INFO_PTR;
269
-
270
-
271
-/* CK_SESSION_HANDLE is a Cryptoki-assigned value that
272
- * identifies a session */
273
-typedef CK_ULONG          CK_SESSION_HANDLE;
274
-
275
-typedef CK_SESSION_HANDLE CK_PTR CK_SESSION_HANDLE_PTR;
276
-
277
-
278
-/* CK_USER_TYPE enumerates the types of Cryptoki users */
279
-/* CK_USER_TYPE has been changed from an enum to a CK_ULONG for
280
- * v2.0 */
281
-typedef CK_ULONG          CK_USER_TYPE;
282
-/* Security Officer */
283
-#define CKU_SO    0
284
-/* Normal user */
285
-#define CKU_USER  1
286
-/* Context specific (added in v2.20) */
287
-#define CKU_CONTEXT_SPECIFIC   2
288
-
289
-/* CK_STATE enumerates the session states */
290
-/* CK_STATE has been changed from an enum to a CK_ULONG for
291
- * v2.0 */
292
-typedef CK_ULONG          CK_STATE;
293
-#define CKS_RO_PUBLIC_SESSION  0
294
-#define CKS_RO_USER_FUNCTIONS  1
295
-#define CKS_RW_PUBLIC_SESSION  2
296
-#define CKS_RW_USER_FUNCTIONS  3
297
-#define CKS_RW_SO_FUNCTIONS    4
298
-
299
-
300
-/* CK_SESSION_INFO provides information about a session */
301
-typedef struct CK_SESSION_INFO {
302
-  CK_SLOT_ID    slotID;
303
-  CK_STATE      state;
304
-  CK_FLAGS      flags;          /* see below */
305
-
306
-  /* ulDeviceError was changed from CK_USHORT to CK_ULONG for
307
-   * v2.0 */
308
-  CK_ULONG      ulDeviceError;  /* device-dependent error code */
309
-} CK_SESSION_INFO;
310
-
311
-/* The flags are defined in the following table:
312
- *      Bit Flag                Mask        Meaning
313
- */
314
-#define CKF_RW_SESSION          0x00000002  /* session is r/w */
315
-#define CKF_SERIAL_SESSION      0x00000004  /* no parallel */
316
-
317
-typedef CK_SESSION_INFO CK_PTR CK_SESSION_INFO_PTR;
318
-
319
-
320
-/* CK_OBJECT_HANDLE is a token-specific identifier for an
321
- * object  */
322
-typedef CK_ULONG          CK_OBJECT_HANDLE;
323
-
324
-typedef CK_OBJECT_HANDLE CK_PTR CK_OBJECT_HANDLE_PTR;
325
-
326
-
327
-/* CK_OBJECT_CLASS is a value that identifies the classes (or
328
- * types) of objects that Cryptoki recognizes.  It is defined
329
- * as follows: */
330
-/* CK_OBJECT_CLASS was changed from CK_USHORT to CK_ULONG for
331
- * v2.0 */
332
-typedef CK_ULONG          CK_OBJECT_CLASS;
333
-
334
-/* The following classes of objects are defined: */
335
-/* CKO_HW_FEATURE is new for v2.10 */
336
-/* CKO_DOMAIN_PARAMETERS is new for v2.11 */
337
-/* CKO_MECHANISM is new for v2.20 */
338
-#define CKO_DATA              0x00000000
339
-#define CKO_CERTIFICATE       0x00000001
340
-#define CKO_PUBLIC_KEY        0x00000002
341
-#define CKO_PRIVATE_KEY       0x00000003
342
-#define CKO_SECRET_KEY        0x00000004
343
-#define CKO_HW_FEATURE        0x00000005
344
-#define CKO_DOMAIN_PARAMETERS 0x00000006
345
-#define CKO_MECHANISM         0x00000007
346
-
347
-/* CKO_OTP_KEY is new for PKCS #11 v2.20 amendment 1 */
348
-#define CKO_OTP_KEY           0x00000008
349
-
350
-#define CKO_VENDOR_DEFINED    0x80000000
351
-
352
-typedef CK_OBJECT_CLASS CK_PTR CK_OBJECT_CLASS_PTR;
353
-
354
-/* CK_HW_FEATURE_TYPE is new for v2.10. CK_HW_FEATURE_TYPE is a
355
- * value that identifies the hardware feature type of an object
356
- * with CK_OBJECT_CLASS equal to CKO_HW_FEATURE. */
357
-typedef CK_ULONG          CK_HW_FEATURE_TYPE;
358
-
359
-/* The following hardware feature types are defined */
360
-/* CKH_USER_INTERFACE is new for v2.20 */
361
-#define CKH_MONOTONIC_COUNTER  0x00000001
362
-#define CKH_CLOCK           0x00000002
363
-#define CKH_USER_INTERFACE  0x00000003
364
-#define CKH_VENDOR_DEFINED  0x80000000
365
-
366
-/* CK_KEY_TYPE is a value that identifies a key type */
367
-/* CK_KEY_TYPE was changed from CK_USHORT to CK_ULONG for v2.0 */
368
-typedef CK_ULONG          CK_KEY_TYPE;
369
-
370
-/* the following key types are defined: */
371
-#define CKK_RSA             0x00000000
372
-#define CKK_DSA             0x00000001
373
-#define CKK_DH              0x00000002
374
-
375
-/* CKK_ECDSA and CKK_KEA are new for v2.0 */
376
-/* CKK_ECDSA is deprecated in v2.11, CKK_EC is preferred. */
377
-#define CKK_ECDSA           0x00000003
378
-#define CKK_EC              0x00000003
379
-#define CKK_X9_42_DH        0x00000004
380
-#define CKK_KEA             0x00000005
381
-
382
-#define CKK_GENERIC_SECRET  0x00000010
383
-#define CKK_RC2             0x00000011
384
-#define CKK_RC4             0x00000012
385
-#define CKK_DES             0x00000013
386
-#define CKK_DES2            0x00000014
387
-#define CKK_DES3            0x00000015
388
-
389
-/* all these key types are new for v2.0 */
390
-#define CKK_CAST            0x00000016
391
-#define CKK_CAST3           0x00000017
392
-/* CKK_CAST5 is deprecated in v2.11, CKK_CAST128 is preferred. */
393
-#define CKK_CAST5           0x00000018
394
-#define CKK_CAST128         0x00000018
395
-#define CKK_RC5             0x00000019
396
-#define CKK_IDEA            0x0000001A
397
-#define CKK_SKIPJACK        0x0000001B
398
-#define CKK_BATON           0x0000001C
399
-#define CKK_JUNIPER         0x0000001D
400
-#define CKK_CDMF            0x0000001E
401
-#define CKK_AES             0x0000001F
402
-
403
-/* BlowFish and TwoFish are new for v2.20 */
404
-#define CKK_BLOWFISH        0x00000020
405
-#define CKK_TWOFISH         0x00000021
406
-
407
-/* SecurID, HOTP, and ACTI are new for PKCS #11 v2.20 amendment 1 */
408
-#define CKK_SECURID         0x00000022
409
-#define CKK_HOTP            0x00000023
410
-#define CKK_ACTI            0x00000024
411
-
412
-/* Camellia is new for PKCS #11 v2.20 amendment 3 */
413
-#define CKK_CAMELLIA                   0x00000025
414
-/* ARIA is new for PKCS #11 v2.20 amendment 3 */
415
-#define CKK_ARIA                       0x00000026
416
-
417
-
418
-#define CKK_VENDOR_DEFINED  0x80000000
419
-
420
-
421
-/* CK_CERTIFICATE_TYPE is a value that identifies a certificate
422
- * type */
423
-/* CK_CERTIFICATE_TYPE was changed from CK_USHORT to CK_ULONG
424
- * for v2.0 */
425
-typedef CK_ULONG          CK_CERTIFICATE_TYPE;
426
-
427
-/* The following certificate types are defined: */
428
-/* CKC_X_509_ATTR_CERT is new for v2.10 */
429
-/* CKC_WTLS is new for v2.20 */
430
-#define CKC_X_509           0x00000000
431
-#define CKC_X_509_ATTR_CERT 0x00000001
432
-#define CKC_WTLS            0x00000002
433
-#define CKC_VENDOR_DEFINED  0x80000000
434
-
435
-
436
-/* CK_ATTRIBUTE_TYPE is a value that identifies an attribute
437
- * type */
438
-/* CK_ATTRIBUTE_TYPE was changed from CK_USHORT to CK_ULONG for
439
- * v2.0 */
440
-typedef CK_ULONG          CK_ATTRIBUTE_TYPE;
441
-
442
-/* The CKF_ARRAY_ATTRIBUTE flag identifies an attribute which
443
-   consists of an array of values. */
444
-#define CKF_ARRAY_ATTRIBUTE    0x40000000
445
-
446
-/* The following OTP-related defines are new for PKCS #11 v2.20 amendment 1
447
-   and relates to the CKA_OTP_FORMAT attribute */
448
-#define CK_OTP_FORMAT_DECIMAL      0
449
-#define CK_OTP_FORMAT_HEXADECIMAL  1
450
-#define CK_OTP_FORMAT_ALPHANUMERIC 2
451
-#define CK_OTP_FORMAT_BINARY       3
452
-
453
-/* The following OTP-related defines are new for PKCS #11 v2.20 amendment 1
454
-   and relates to the CKA_OTP_..._REQUIREMENT attributes */
455
-#define CK_OTP_PARAM_IGNORED       0
456
-#define CK_OTP_PARAM_OPTIONAL      1
457
-#define CK_OTP_PARAM_MANDATORY     2
458
-
459
-/* The following attribute types are defined: */
460
-#define CKA_CLASS              0x00000000
461
-#define CKA_TOKEN              0x00000001
462
-#define CKA_PRIVATE            0x00000002
463
-#define CKA_LABEL              0x00000003
464
-#define CKA_APPLICATION        0x00000010
465
-#define CKA_VALUE              0x00000011
466
-
467
-/* CKA_OBJECT_ID is new for v2.10 */
468
-#define CKA_OBJECT_ID          0x00000012
469
-
470
-#define CKA_CERTIFICATE_TYPE   0x00000080
471
-#define CKA_ISSUER             0x00000081
472
-#define CKA_SERIAL_NUMBER      0x00000082
473
-
474
-/* CKA_AC_ISSUER, CKA_OWNER, and CKA_ATTR_TYPES are new
475
- * for v2.10 */
476
-#define CKA_AC_ISSUER          0x00000083
477
-#define CKA_OWNER              0x00000084
478
-#define CKA_ATTR_TYPES         0x00000085
479
-
480
-/* CKA_TRUSTED is new for v2.11 */
481
-#define CKA_TRUSTED            0x00000086
482
-
483
-/* CKA_CERTIFICATE_CATEGORY ...
484
- * CKA_CHECK_VALUE are new for v2.20 */
485
-#define CKA_CERTIFICATE_CATEGORY        0x00000087
486
-#define CKA_JAVA_MIDP_SECURITY_DOMAIN   0x00000088
487
-#define CKA_URL                         0x00000089
488
-#define CKA_HASH_OF_SUBJECT_PUBLIC_KEY  0x0000008A
489
-#define CKA_HASH_OF_ISSUER_PUBLIC_KEY   0x0000008B
490
-#define CKA_CHECK_VALUE                 0x00000090
491
-
492
-#define CKA_KEY_TYPE           0x00000100
493
-#define CKA_SUBJECT            0x00000101
494
-#define CKA_ID                 0x00000102
495
-#define CKA_SENSITIVE          0x00000103
496
-#define CKA_ENCRYPT            0x00000104
497
-#define CKA_DECRYPT            0x00000105
498
-#define CKA_WRAP               0x00000106
499
-#define CKA_UNWRAP             0x00000107
500
-#define CKA_SIGN               0x00000108
501
-#define CKA_SIGN_RECOVER       0x00000109
502
-#define CKA_VERIFY             0x0000010A
503
-#define CKA_VERIFY_RECOVER     0x0000010B
504
-#define CKA_DERIVE             0x0000010C
505
-#define CKA_START_DATE         0x00000110
506
-#define CKA_END_DATE           0x00000111
507
-#define CKA_MODULUS            0x00000120
508
-#define CKA_MODULUS_BITS       0x00000121
509
-#define CKA_PUBLIC_EXPONENT    0x00000122
510
-#define CKA_PRIVATE_EXPONENT   0x00000123
511
-#define CKA_PRIME_1            0x00000124
512
-#define CKA_PRIME_2            0x00000125
513
-#define CKA_EXPONENT_1         0x00000126
514
-#define CKA_EXPONENT_2         0x00000127
515
-#define CKA_COEFFICIENT        0x00000128
516
-#define CKA_PRIME              0x00000130
517
-#define CKA_SUBPRIME           0x00000131
518
-#define CKA_BASE               0x00000132
519
-
520
-/* CKA_PRIME_BITS and CKA_SUB_PRIME_BITS are new for v2.11 */
521
-#define CKA_PRIME_BITS         0x00000133
522
-#define CKA_SUBPRIME_BITS      0x00000134
523
-#define CKA_SUB_PRIME_BITS     CKA_SUBPRIME_BITS
524
-/* (To retain backwards-compatibility) */
525
-
526
-#define CKA_VALUE_BITS         0x00000160
527
-#define CKA_VALUE_LEN          0x00000161
528
-
529
-/* CKA_EXTRACTABLE, CKA_LOCAL, CKA_NEVER_EXTRACTABLE,
530
- * CKA_ALWAYS_SENSITIVE, CKA_MODIFIABLE, CKA_ECDSA_PARAMS,
531
- * and CKA_EC_POINT are new for v2.0 */
532
-#define CKA_EXTRACTABLE        0x00000162
533
-#define CKA_LOCAL              0x00000163
534
-#define CKA_NEVER_EXTRACTABLE  0x00000164
535
-#define CKA_ALWAYS_SENSITIVE   0x00000165
536
-
537
-/* CKA_KEY_GEN_MECHANISM is new for v2.11 */
538
-#define CKA_KEY_GEN_MECHANISM  0x00000166
539
-
540
-#define CKA_MODIFIABLE         0x00000170
541
-
542
-/* CKA_ECDSA_PARAMS is deprecated in v2.11,
543
- * CKA_EC_PARAMS is preferred. */
544
-#define CKA_ECDSA_PARAMS       0x00000180
545
-#define CKA_EC_PARAMS          0x00000180
546
-
547
-#define CKA_EC_POINT           0x00000181
548
-
549
-/* CKA_SECONDARY_AUTH, CKA_AUTH_PIN_FLAGS,
550
- * are new for v2.10. Deprecated in v2.11 and onwards. */
551
-#define CKA_SECONDARY_AUTH     0x00000200
552
-#define CKA_AUTH_PIN_FLAGS     0x00000201
553
-
554
-/* CKA_ALWAYS_AUTHENTICATE ...
555
- * CKA_UNWRAP_TEMPLATE are new for v2.20 */
556
-#define CKA_ALWAYS_AUTHENTICATE  0x00000202
557
-
558
-#define CKA_WRAP_WITH_TRUSTED    0x00000210
559
-#define CKA_WRAP_TEMPLATE        (CKF_ARRAY_ATTRIBUTE|0x00000211)
560
-#define CKA_UNWRAP_TEMPLATE      (CKF_ARRAY_ATTRIBUTE|0x00000212)
561
-
562
-/* CKA_OTP... atttributes are new for PKCS #11 v2.20 amendment 3. */
563
-#define CKA_OTP_FORMAT                0x00000220
564
-#define CKA_OTP_LENGTH                0x00000221
565
-#define CKA_OTP_TIME_INTERVAL         0x00000222
566
-#define CKA_OTP_USER_FRIENDLY_MODE    0x00000223
567
-#define CKA_OTP_CHALLENGE_REQUIREMENT 0x00000224
568
-#define CKA_OTP_TIME_REQUIREMENT      0x00000225
569
-#define CKA_OTP_COUNTER_REQUIREMENT   0x00000226
570
-#define CKA_OTP_PIN_REQUIREMENT       0x00000227
571
-#define CKA_OTP_COUNTER               0x0000022E
572
-#define CKA_OTP_TIME                  0x0000022F
573
-#define CKA_OTP_USER_IDENTIFIER       0x0000022A
574
-#define CKA_OTP_SERVICE_IDENTIFIER    0x0000022B
575
-#define CKA_OTP_SERVICE_LOGO          0x0000022C
576
-#define CKA_OTP_SERVICE_LOGO_TYPE     0x0000022D
577
-
578
-
579
-/* CKA_HW_FEATURE_TYPE, CKA_RESET_ON_INIT, and CKA_HAS_RESET
580
- * are new for v2.10 */
581
-#define CKA_HW_FEATURE_TYPE    0x00000300
582
-#define CKA_RESET_ON_INIT      0x00000301
583
-#define CKA_HAS_RESET          0x00000302
584
-
585
-/* The following attributes are new for v2.20 */
586
-#define CKA_PIXEL_X                     0x00000400
587
-#define CKA_PIXEL_Y                     0x00000401
588
-#define CKA_RESOLUTION                  0x00000402
589
-#define CKA_CHAR_ROWS                   0x00000403
590
-#define CKA_CHAR_COLUMNS                0x00000404
591
-#define CKA_COLOR                       0x00000405
592
-#define CKA_BITS_PER_PIXEL              0x00000406
593
-#define CKA_CHAR_SETS                   0x00000480
594
-#define CKA_ENCODING_METHODS            0x00000481
595
-#define CKA_MIME_TYPES                  0x00000482
596
-#define CKA_MECHANISM_TYPE              0x00000500
597
-#define CKA_REQUIRED_CMS_ATTRIBUTES     0x00000501
598
-#define CKA_DEFAULT_CMS_ATTRIBUTES      0x00000502
599
-#define CKA_SUPPORTED_CMS_ATTRIBUTES    0x00000503
600
-#define CKA_ALLOWED_MECHANISMS          (CKF_ARRAY_ATTRIBUTE|0x00000600)
601
-
602
-#define CKA_VENDOR_DEFINED     0x80000000
603
-
604
-/* CK_ATTRIBUTE is a structure that includes the type, length
605
- * and value of an attribute */
606
-typedef struct CK_ATTRIBUTE {
607
-  CK_ATTRIBUTE_TYPE type;
608
-  CK_VOID_PTR       pValue;
609
-
610
-  /* ulValueLen went from CK_USHORT to CK_ULONG for v2.0 */
611
-  CK_ULONG          ulValueLen;  /* in bytes */
612
-} CK_ATTRIBUTE;
613
-
614
-typedef CK_ATTRIBUTE CK_PTR CK_ATTRIBUTE_PTR;
615
-
616
-
617
-/* CK_DATE is a structure that defines a date */
618
-typedef struct CK_DATE{
619
-  CK_CHAR       year[4];   /* the year ("1900" - "9999") */
620
-  CK_CHAR       month[2];  /* the month ("01" - "12") */
621
-  CK_CHAR       day[2];    /* the day   ("01" - "31") */
622
-} CK_DATE;
623
-
624
-
625
-/* CK_MECHANISM_TYPE is a value that identifies a mechanism
626
- * type */
627
-/* CK_MECHANISM_TYPE was changed from CK_USHORT to CK_ULONG for
628
- * v2.0 */
629
-typedef CK_ULONG          CK_MECHANISM_TYPE;
630
-
631
-/* the following mechanism types are defined: */
632
-#define CKM_RSA_PKCS_KEY_PAIR_GEN      0x00000000
633
-#define CKM_RSA_PKCS                   0x00000001
634
-#define CKM_RSA_9796                   0x00000002
635
-#define CKM_RSA_X_509                  0x00000003
636
-
637
-/* CKM_MD2_RSA_PKCS, CKM_MD5_RSA_PKCS, and CKM_SHA1_RSA_PKCS
638
- * are new for v2.0.  They are mechanisms which hash and sign */
639
-#define CKM_MD2_RSA_PKCS               0x00000004
640
-#define CKM_MD5_RSA_PKCS               0x00000005
641
-#define CKM_SHA1_RSA_PKCS              0x00000006
642
-
643
-/* CKM_RIPEMD128_RSA_PKCS, CKM_RIPEMD160_RSA_PKCS, and
644
- * CKM_RSA_PKCS_OAEP are new for v2.10 */
645
-#define CKM_RIPEMD128_RSA_PKCS         0x00000007
646
-#define CKM_RIPEMD160_RSA_PKCS         0x00000008
647
-#define CKM_RSA_PKCS_OAEP              0x00000009
648
-
649
-/* CKM_RSA_X9_31_KEY_PAIR_GEN, CKM_RSA_X9_31, CKM_SHA1_RSA_X9_31,
650
- * CKM_RSA_PKCS_PSS, and CKM_SHA1_RSA_PKCS_PSS are new for v2.11 */
651
-#define CKM_RSA_X9_31_KEY_PAIR_GEN     0x0000000A
652
-#define CKM_RSA_X9_31                  0x0000000B
653
-#define CKM_SHA1_RSA_X9_31             0x0000000C
654
-#define CKM_RSA_PKCS_PSS               0x0000000D
655
-#define CKM_SHA1_RSA_PKCS_PSS          0x0000000E
656
-
657
-#define CKM_DSA_KEY_PAIR_GEN           0x00000010
658
-#define CKM_DSA                        0x00000011
659
-#define CKM_DSA_SHA1                   0x00000012
660
-#define CKM_DH_PKCS_KEY_PAIR_GEN       0x00000020
661
-#define CKM_DH_PKCS_DERIVE             0x00000021
662
-
663
-/* CKM_X9_42_DH_KEY_PAIR_GEN, CKM_X9_42_DH_DERIVE,
664
- * CKM_X9_42_DH_HYBRID_DERIVE, and CKM_X9_42_MQV_DERIVE are new for
665
- * v2.11 */
666
-#define CKM_X9_42_DH_KEY_PAIR_GEN      0x00000030
667
-#define CKM_X9_42_DH_DERIVE            0x00000031
668
-#define CKM_X9_42_DH_HYBRID_DERIVE     0x00000032
669
-#define CKM_X9_42_MQV_DERIVE           0x00000033
670
-
671
-/* CKM_SHA256/384/512 are new for v2.20 */
672
-#define CKM_SHA256_RSA_PKCS            0x00000040
673
-#define CKM_SHA384_RSA_PKCS            0x00000041
674
-#define CKM_SHA512_RSA_PKCS            0x00000042
675
-#define CKM_SHA256_RSA_PKCS_PSS        0x00000043
676
-#define CKM_SHA384_RSA_PKCS_PSS        0x00000044
677
-#define CKM_SHA512_RSA_PKCS_PSS        0x00000045
678
-
679
-/* SHA-224 RSA mechanisms are new for PKCS #11 v2.20 amendment 3 */
680
-#define CKM_SHA224_RSA_PKCS            0x00000046
681
-#define CKM_SHA224_RSA_PKCS_PSS        0x00000047
682
-
683
-#define CKM_RC2_KEY_GEN                0x00000100
684
-#define CKM_RC2_ECB                    0x00000101
685
-#define CKM_RC2_CBC                    0x00000102
686
-#define CKM_RC2_MAC                    0x00000103
687
-
688
-/* CKM_RC2_MAC_GENERAL and CKM_RC2_CBC_PAD are new for v2.0 */
689
-#define CKM_RC2_MAC_GENERAL            0x00000104
690
-#define CKM_RC2_CBC_PAD                0x00000105
691
-
692
-#define CKM_RC4_KEY_GEN                0x00000110
693
-#define CKM_RC4                        0x00000111
694
-#define CKM_DES_KEY_GEN                0x00000120
695
-#define CKM_DES_ECB                    0x00000121
696
-#define CKM_DES_CBC                    0x00000122
697
-#define CKM_DES_MAC                    0x00000123
698
-
699
-/* CKM_DES_MAC_GENERAL and CKM_DES_CBC_PAD are new for v2.0 */
700
-#define CKM_DES_MAC_GENERAL            0x00000124
701
-#define CKM_DES_CBC_PAD                0x00000125
702
-
703
-#define CKM_DES2_KEY_GEN               0x00000130
704
-#define CKM_DES3_KEY_GEN               0x00000131
705
-#define CKM_DES3_ECB                   0x00000132
706
-#define CKM_DES3_CBC                   0x00000133
707
-#define CKM_DES3_MAC                   0x00000134
708
-
709
-/* CKM_DES3_MAC_GENERAL, CKM_DES3_CBC_PAD, CKM_CDMF_KEY_GEN,
710
- * CKM_CDMF_ECB, CKM_CDMF_CBC, CKM_CDMF_MAC,
711
- * CKM_CDMF_MAC_GENERAL, and CKM_CDMF_CBC_PAD are new for v2.0 */
712
-#define CKM_DES3_MAC_GENERAL           0x00000135
713
-#define CKM_DES3_CBC_PAD               0x00000136
714
-#define CKM_CDMF_KEY_GEN               0x00000140
715
-#define CKM_CDMF_ECB                   0x00000141
716
-#define CKM_CDMF_CBC                   0x00000142
717
-#define CKM_CDMF_MAC                   0x00000143
718
-#define CKM_CDMF_MAC_GENERAL           0x00000144
719
-#define CKM_CDMF_CBC_PAD               0x00000145
720
-
721
-/* the following four DES mechanisms are new for v2.20 */
722
-#define CKM_DES_OFB64                  0x00000150
723
-#define CKM_DES_OFB8                   0x00000151
724
-#define CKM_DES_CFB64                  0x00000152
725
-#define CKM_DES_CFB8                   0x00000153
726
-
727
-#define CKM_MD2                        0x00000200
728
-
729
-/* CKM_MD2_HMAC and CKM_MD2_HMAC_GENERAL are new for v2.0 */
730
-#define CKM_MD2_HMAC                   0x00000201
731
-#define CKM_MD2_HMAC_GENERAL           0x00000202
732
-
733
-#define CKM_MD5                        0x00000210
734
-
735
-/* CKM_MD5_HMAC and CKM_MD5_HMAC_GENERAL are new for v2.0 */
736
-#define CKM_MD5_HMAC                   0x00000211
737
-#define CKM_MD5_HMAC_GENERAL           0x00000212
738
-
739
-#define CKM_SHA_1                      0x00000220
740
-
741
-/* CKM_SHA_1_HMAC and CKM_SHA_1_HMAC_GENERAL are new for v2.0 */
742
-#define CKM_SHA_1_HMAC                 0x00000221
743
-#define CKM_SHA_1_HMAC_GENERAL         0x00000222
744
-
745
-/* CKM_RIPEMD128, CKM_RIPEMD128_HMAC,
746
- * CKM_RIPEMD128_HMAC_GENERAL, CKM_RIPEMD160, CKM_RIPEMD160_HMAC,
747
- * and CKM_RIPEMD160_HMAC_GENERAL are new for v2.10 */
748
-#define CKM_RIPEMD128                  0x00000230
749
-#define CKM_RIPEMD128_HMAC             0x00000231
750
-#define CKM_RIPEMD128_HMAC_GENERAL     0x00000232
751
-#define CKM_RIPEMD160                  0x00000240
752
-#define CKM_RIPEMD160_HMAC             0x00000241
753
-#define CKM_RIPEMD160_HMAC_GENERAL     0x00000242
754
-
755
-/* CKM_SHA256/384/512 are new for v2.20 */
756
-#define CKM_SHA256                     0x00000250
757
-#define CKM_SHA256_HMAC                0x00000251
758
-#define CKM_SHA256_HMAC_GENERAL        0x00000252
759
-
760
-/* SHA-224 is new for PKCS #11 v2.20 amendment 3 */
761
-#define CKM_SHA224                     0x00000255
762
-#define CKM_SHA224_HMAC                0x00000256
763
-#define CKM_SHA224_HMAC_GENERAL        0x00000257
764
-
765
-#define CKM_SHA384                     0x00000260
766
-#define CKM_SHA384_HMAC                0x00000261
767
-#define CKM_SHA384_HMAC_GENERAL        0x00000262
768
-#define CKM_SHA512                     0x00000270
769
-#define CKM_SHA512_HMAC                0x00000271
770
-#define CKM_SHA512_HMAC_GENERAL        0x00000272
771
-
772
-/* SecurID is new for PKCS #11 v2.20 amendment 1 */
773
-#define CKM_SECURID_KEY_GEN            0x00000280
774
-#define CKM_SECURID                    0x00000282
775
-
776
-/* HOTP is new for PKCS #11 v2.20 amendment 1 */
777
-#define CKM_HOTP_KEY_GEN    0x00000290
778
-#define CKM_HOTP            0x00000291
779
-
780
-/* ACTI is new for PKCS #11 v2.20 amendment 1 */
781
-#define CKM_ACTI            0x000002A0
782
-#define CKM_ACTI_KEY_GEN    0x000002A1
783
-
784
-/* All of the following mechanisms are new for v2.0 */
785
-/* Note that CAST128 and CAST5 are the same algorithm */
786
-#define CKM_CAST_KEY_GEN               0x00000300
787
-#define CKM_CAST_ECB                   0x00000301
788
-#define CKM_CAST_CBC                   0x00000302
789
-#define CKM_CAST_MAC                   0x00000303
790
-#define CKM_CAST_MAC_GENERAL           0x00000304
791
-#define CKM_CAST_CBC_PAD               0x00000305
792
-#define CKM_CAST3_KEY_GEN              0x00000310
793
-#define CKM_CAST3_ECB                  0x00000311
794
-#define CKM_CAST3_CBC                  0x00000312
795
-#define CKM_CAST3_MAC                  0x00000313
796
-#define CKM_CAST3_MAC_GENERAL          0x00000314
797
-#define CKM_CAST3_CBC_PAD              0x00000315
798
-#define CKM_CAST5_KEY_GEN              0x00000320
799
-#define CKM_CAST128_KEY_GEN            0x00000320
800
-#define CKM_CAST5_ECB                  0x00000321
801
-#define CKM_CAST128_ECB                0x00000321
802
-#define CKM_CAST5_CBC                  0x00000322
803
-#define CKM_CAST128_CBC                0x00000322
804
-#define CKM_CAST5_MAC                  0x00000323
805
-#define CKM_CAST128_MAC                0x00000323
806
-#define CKM_CAST5_MAC_GENERAL          0x00000324
807
-#define CKM_CAST128_MAC_GENERAL        0x00000324
808
-#define CKM_CAST5_CBC_PAD              0x00000325
809
-#define CKM_CAST128_CBC_PAD            0x00000325
810
-#define CKM_RC5_KEY_GEN                0x00000330
811
-#define CKM_RC5_ECB                    0x00000331
812
-#define CKM_RC5_CBC                    0x00000332
813
-#define CKM_RC5_MAC                    0x00000333
814
-#define CKM_RC5_MAC_GENERAL            0x00000334
815
-#define CKM_RC5_CBC_PAD                0x00000335
816
-#define CKM_IDEA_KEY_GEN               0x00000340
817
-#define CKM_IDEA_ECB                   0x00000341
818
-#define CKM_IDEA_CBC                   0x00000342
819
-#define CKM_IDEA_MAC                   0x00000343
820
-#define CKM_IDEA_MAC_GENERAL           0x00000344
821
-#define CKM_IDEA_CBC_PAD               0x00000345
822
-#define CKM_GENERIC_SECRET_KEY_GEN     0x00000350
823
-#define CKM_CONCATENATE_BASE_AND_KEY   0x00000360
824
-#define CKM_CONCATENATE_BASE_AND_DATA  0x00000362
825
-#define CKM_CONCATENATE_DATA_AND_BASE  0x00000363
826
-#define CKM_XOR_BASE_AND_DATA          0x00000364
827
-#define CKM_EXTRACT_KEY_FROM_KEY       0x00000365
828
-#define CKM_SSL3_PRE_MASTER_KEY_GEN    0x00000370
829
-#define CKM_SSL3_MASTER_KEY_DERIVE     0x00000371
830
-#define CKM_SSL3_KEY_AND_MAC_DERIVE    0x00000372
831
-
832
-/* CKM_SSL3_MASTER_KEY_DERIVE_DH, CKM_TLS_PRE_MASTER_KEY_GEN,
833
- * CKM_TLS_MASTER_KEY_DERIVE, CKM_TLS_KEY_AND_MAC_DERIVE, and
834
- * CKM_TLS_MASTER_KEY_DERIVE_DH are new for v2.11 */
835
-#define CKM_SSL3_MASTER_KEY_DERIVE_DH  0x00000373
836
-#define CKM_TLS_PRE_MASTER_KEY_GEN     0x00000374
837
-#define CKM_TLS_MASTER_KEY_DERIVE      0x00000375
838
-#define CKM_TLS_KEY_AND_MAC_DERIVE     0x00000376
839
-#define CKM_TLS_MASTER_KEY_DERIVE_DH   0x00000377
840
-
841
-/* CKM_TLS_PRF is new for v2.20 */
842
-#define CKM_TLS_PRF                    0x00000378
843
-
844
-#define CKM_SSL3_MD5_MAC               0x00000380
845
-#define CKM_SSL3_SHA1_MAC              0x00000381
846
-#define CKM_MD5_KEY_DERIVATION         0x00000390
847
-#define CKM_MD2_KEY_DERIVATION         0x00000391
848
-#define CKM_SHA1_KEY_DERIVATION        0x00000392
849
-
850
-/* CKM_SHA256/384/512 are new for v2.20 */
851
-#define CKM_SHA256_KEY_DERIVATION      0x00000393
852
-#define CKM_SHA384_KEY_DERIVATION      0x00000394
853
-#define CKM_SHA512_KEY_DERIVATION      0x00000395
854
-
855
-/* SHA-224 key derivation is new for PKCS #11 v2.20 amendment 3 */
856
-#define CKM_SHA224_KEY_DERIVATION      0x00000396
857
-
858
-#define CKM_PBE_MD2_DES_CBC            0x000003A0
859
-#define CKM_PBE_MD5_DES_CBC            0x000003A1
860
-#define CKM_PBE_MD5_CAST_CBC           0x000003A2
861
-#define CKM_PBE_MD5_CAST3_CBC          0x000003A3
862
-#define CKM_PBE_MD5_CAST5_CBC          0x000003A4
863
-#define CKM_PBE_MD5_CAST128_CBC        0x000003A4
864
-#define CKM_PBE_SHA1_CAST5_CBC         0x000003A5
865
-#define CKM_PBE_SHA1_CAST128_CBC       0x000003A5
866
-#define CKM_PBE_SHA1_RC4_128           0x000003A6
867
-#define CKM_PBE_SHA1_RC4_40            0x000003A7
868
-#define CKM_PBE_SHA1_DES3_EDE_CBC      0x000003A8
869
-#define CKM_PBE_SHA1_DES2_EDE_CBC      0x000003A9
870
-#define CKM_PBE_SHA1_RC2_128_CBC       0x000003AA
871
-#define CKM_PBE_SHA1_RC2_40_CBC        0x000003AB
872
-
873
-/* CKM_PKCS5_PBKD2 is new for v2.10 */
874
-#define CKM_PKCS5_PBKD2                0x000003B0
875
-
876
-#define CKM_PBA_SHA1_WITH_SHA1_HMAC    0x000003C0
877
-
878
-/* WTLS mechanisms are new for v2.20 */
879
-#define CKM_WTLS_PRE_MASTER_KEY_GEN         0x000003D0
880
-#define CKM_WTLS_MASTER_KEY_DERIVE          0x000003D1
881
-#define CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC   0x000003D2
882
-#define CKM_WTLS_PRF                        0x000003D3
883
-#define CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE  0x000003D4
884
-#define CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE  0x000003D5
885
-
886
-#define CKM_KEY_WRAP_LYNKS             0x00000400
887
-#define CKM_KEY_WRAP_SET_OAEP          0x00000401
888
-
889
-/* CKM_CMS_SIG is new for v2.20 */
890
-#define CKM_CMS_SIG                    0x00000500
891
-
892
-/* CKM_KIP mechanisms are new for PKCS #11 v2.20 amendment 2 */
893
-#define CKM_KIP_DERIVE	               0x00000510
894
-#define CKM_KIP_WRAP	               0x00000511
895
-#define CKM_KIP_MAC	               0x00000512
896
-
897
-/* Camellia is new for PKCS #11 v2.20 amendment 3 */
898
-#define CKM_CAMELLIA_KEY_GEN           0x00000550
899
-#define CKM_CAMELLIA_ECB               0x00000551
900
-#define CKM_CAMELLIA_CBC               0x00000552
901
-#define CKM_CAMELLIA_MAC               0x00000553
902
-#define CKM_CAMELLIA_MAC_GENERAL       0x00000554
903
-#define CKM_CAMELLIA_CBC_PAD           0x00000555
904
-#define CKM_CAMELLIA_ECB_ENCRYPT_DATA  0x00000556
905
-#define CKM_CAMELLIA_CBC_ENCRYPT_DATA  0x00000557
906
-#define CKM_CAMELLIA_CTR               0x00000558
907
-
908
-/* ARIA is new for PKCS #11 v2.20 amendment 3 */
909
-#define CKM_ARIA_KEY_GEN               0x00000560
910
-#define CKM_ARIA_ECB                   0x00000561
911
-#define CKM_ARIA_CBC                   0x00000562
912
-#define CKM_ARIA_MAC                   0x00000563
913
-#define CKM_ARIA_MAC_GENERAL           0x00000564
914
-#define CKM_ARIA_CBC_PAD               0x00000565
915
-#define CKM_ARIA_ECB_ENCRYPT_DATA      0x00000566
916
-#define CKM_ARIA_CBC_ENCRYPT_DATA      0x00000567
917
-
918
-/* Fortezza mechanisms */
919
-#define CKM_SKIPJACK_KEY_GEN           0x00001000
920
-#define CKM_SKIPJACK_ECB64             0x00001001
921
-#define CKM_SKIPJACK_CBC64             0x00001002
922
-#define CKM_SKIPJACK_OFB64             0x00001003
923
-#define CKM_SKIPJACK_CFB64             0x00001004
924
-#define CKM_SKIPJACK_CFB32             0x00001005
925
-#define CKM_SKIPJACK_CFB16             0x00001006
926
-#define CKM_SKIPJACK_CFB8              0x00001007
927
-#define CKM_SKIPJACK_WRAP              0x00001008
928
-#define CKM_SKIPJACK_PRIVATE_WRAP      0x00001009
929
-#define CKM_SKIPJACK_RELAYX            0x0000100a
930
-#define CKM_KEA_KEY_PAIR_GEN           0x00001010
931
-#define CKM_KEA_KEY_DERIVE             0x00001011
932
-#define CKM_FORTEZZA_TIMESTAMP         0x00001020
933
-#define CKM_BATON_KEY_GEN              0x00001030
934
-#define CKM_BATON_ECB128               0x00001031
935
-#define CKM_BATON_ECB96                0x00001032
936
-#define CKM_BATON_CBC128               0x00001033
937
-#define CKM_BATON_COUNTER              0x00001034
938
-#define CKM_BATON_SHUFFLE              0x00001035
939
-#define CKM_BATON_WRAP                 0x00001036
940
-
941
-/* CKM_ECDSA_KEY_PAIR_GEN is deprecated in v2.11,
942
- * CKM_EC_KEY_PAIR_GEN is preferred */
943
-#define CKM_ECDSA_KEY_PAIR_GEN         0x00001040
944
-#define CKM_EC_KEY_PAIR_GEN            0x00001040
945
-
946
-#define CKM_ECDSA                      0x00001041
947
-#define CKM_ECDSA_SHA1                 0x00001042
948
-
949
-/* CKM_ECDH1_DERIVE, CKM_ECDH1_COFACTOR_DERIVE, and CKM_ECMQV_DERIVE
950
- * are new for v2.11 */
951
-#define CKM_ECDH1_DERIVE               0x00001050
952
-#define CKM_ECDH1_COFACTOR_DERIVE      0x00001051
953
-#define CKM_ECMQV_DERIVE               0x00001052
954
-
955
-#define CKM_JUNIPER_KEY_GEN            0x00001060
956
-#define CKM_JUNIPER_ECB128             0x00001061
957
-#define CKM_JUNIPER_CBC128             0x00001062
958
-#define CKM_JUNIPER_COUNTER            0x00001063
959
-#define CKM_JUNIPER_SHUFFLE            0x00001064
960
-#define CKM_JUNIPER_WRAP               0x00001065
961
-#define CKM_FASTHASH                   0x00001070
962
-
963
-/* CKM_AES_KEY_GEN, CKM_AES_ECB, CKM_AES_CBC, CKM_AES_MAC,
964
- * CKM_AES_MAC_GENERAL, CKM_AES_CBC_PAD, CKM_DSA_PARAMETER_GEN,
965
- * CKM_DH_PKCS_PARAMETER_GEN, and CKM_X9_42_DH_PARAMETER_GEN are
966
- * new for v2.11 */
967
-#define CKM_AES_KEY_GEN                0x00001080
968
-#define CKM_AES_ECB                    0x00001081
969
-#define CKM_AES_CBC                    0x00001082
970
-#define CKM_AES_MAC                    0x00001083
971
-#define CKM_AES_MAC_GENERAL            0x00001084
972
-#define CKM_AES_CBC_PAD                0x00001085
973
-
974
-/* AES counter mode is new for PKCS #11 v2.20 amendment 3 */
975
-#define CKM_AES_CTR                    0x00001086
976
-
977
-/* BlowFish and TwoFish are new for v2.20 */
978
-#define CKM_BLOWFISH_KEY_GEN           0x00001090
979
-#define CKM_BLOWFISH_CBC               0x00001091
980
-#define CKM_TWOFISH_KEY_GEN            0x00001092
981
-#define CKM_TWOFISH_CBC                0x00001093
982
-
983
-
984
-/* CKM_xxx_ENCRYPT_DATA mechanisms are new for v2.20 */
985
-#define CKM_DES_ECB_ENCRYPT_DATA       0x00001100
986
-#define CKM_DES_CBC_ENCRYPT_DATA       0x00001101
987
-#define CKM_DES3_ECB_ENCRYPT_DATA      0x00001102
988
-#define CKM_DES3_CBC_ENCRYPT_DATA      0x00001103
989
-#define CKM_AES_ECB_ENCRYPT_DATA       0x00001104
990
-#define CKM_AES_CBC_ENCRYPT_DATA       0x00001105
991
-
992
-#define CKM_DSA_PARAMETER_GEN          0x00002000
993
-#define CKM_DH_PKCS_PARAMETER_GEN      0x00002001
994
-#define CKM_X9_42_DH_PARAMETER_GEN     0x00002002
995
-
996
-#define CKM_VENDOR_DEFINED             0x80000000
997
-
998
-typedef CK_MECHANISM_TYPE CK_PTR CK_MECHANISM_TYPE_PTR;
999
-
1000
-
1001
-/* CK_MECHANISM is a structure that specifies a particular
1002
- * mechanism  */
1003
-typedef struct CK_MECHANISM {
1004
-  CK_MECHANISM_TYPE mechanism;
1005
-  CK_VOID_PTR       pParameter;
1006
-
1007
-  /* ulParameterLen was changed from CK_USHORT to CK_ULONG for
1008
-   * v2.0 */
1009
-  CK_ULONG          ulParameterLen;  /* in bytes */
1010
-} CK_MECHANISM;
1011
-
1012
-typedef CK_MECHANISM CK_PTR CK_MECHANISM_PTR;
1013
-
1014
-
1015
-/* CK_MECHANISM_INFO provides information about a particular
1016
- * mechanism */
1017
-typedef struct CK_MECHANISM_INFO {
1018
-    CK_ULONG    ulMinKeySize;
1019
-    CK_ULONG    ulMaxKeySize;
1020
-    CK_FLAGS    flags;
1021
-} CK_MECHANISM_INFO;
1022
-
1023
-/* The flags are defined as follows:
1024
- *      Bit Flag               Mask        Meaning */
1025
-#define CKF_HW                 0x00000001  /* performed by HW */
1026
-
1027
-/* The flags CKF_ENCRYPT, CKF_DECRYPT, CKF_DIGEST, CKF_SIGN,
1028
- * CKG_SIGN_RECOVER, CKF_VERIFY, CKF_VERIFY_RECOVER,
1029
- * CKF_GENERATE, CKF_GENERATE_KEY_PAIR, CKF_WRAP, CKF_UNWRAP,
1030
- * and CKF_DERIVE are new for v2.0.  They specify whether or not
1031
- * a mechanism can be used for a particular task */
1032
-#define CKF_ENCRYPT            0x00000100
1033
-#define CKF_DECRYPT            0x00000200
1034
-#define CKF_DIGEST             0x00000400
1035
-#define CKF_SIGN               0x00000800
1036
-#define CKF_SIGN_RECOVER       0x00001000
1037
-#define CKF_VERIFY             0x00002000
1038
-#define CKF_VERIFY_RECOVER     0x00004000
1039
-#define CKF_GENERATE           0x00008000
1040
-#define CKF_GENERATE_KEY_PAIR  0x00010000
1041
-#define CKF_WRAP               0x00020000
1042
-#define CKF_UNWRAP             0x00040000
1043
-#define CKF_DERIVE             0x00080000
1044
-
1045
-/* CKF_EC_F_P, CKF_EC_F_2M, CKF_EC_ECPARAMETERS, CKF_EC_NAMEDCURVE,
1046
- * CKF_EC_UNCOMPRESS, and CKF_EC_COMPRESS are new for v2.11. They
1047
- * describe a token's EC capabilities not available in mechanism
1048
- * information. */
1049
-#define CKF_EC_F_P             0x00100000
1050
-#define CKF_EC_F_2M            0x00200000
1051
-#define CKF_EC_ECPARAMETERS    0x00400000
1052
-#define CKF_EC_NAMEDCURVE      0x00800000
1053
-#define CKF_EC_UNCOMPRESS      0x01000000
1054
-#define CKF_EC_COMPRESS        0x02000000
1055
-
1056
-#define CKF_EXTENSION          0x80000000 /* FALSE for this version */
1057
-
1058
-typedef CK_MECHANISM_INFO CK_PTR CK_MECHANISM_INFO_PTR;
1059
-
1060
-
1061
-/* CK_RV is a value that identifies the return value of a
1062
- * Cryptoki function */
1063
-/* CK_RV was changed from CK_USHORT to CK_ULONG for v2.0 */
1064
-typedef CK_ULONG          CK_RV;
1065
-
1066
-#define CKR_OK                                0x00000000
1067
-#define CKR_CANCEL                            0x00000001
1068
-#define CKR_HOST_MEMORY                       0x00000002
1069
-#define CKR_SLOT_ID_INVALID                   0x00000003
1070
-
1071
-/* CKR_FLAGS_INVALID was removed for v2.0 */
1072
-
1073
-/* CKR_GENERAL_ERROR and CKR_FUNCTION_FAILED are new for v2.0 */
1074
-#define CKR_GENERAL_ERROR                     0x00000005
1075
-#define CKR_FUNCTION_FAILED                   0x00000006
1076
-
1077
-/* CKR_ARGUMENTS_BAD, CKR_NO_EVENT, CKR_NEED_TO_CREATE_THREADS,
1078
- * and CKR_CANT_LOCK are new for v2.01 */
1079
-#define CKR_ARGUMENTS_BAD                     0x00000007
1080
-#define CKR_NO_EVENT                          0x00000008
1081
-#define CKR_NEED_TO_CREATE_THREADS            0x00000009
1082
-#define CKR_CANT_LOCK                         0x0000000A
1083
-
1084
-#define CKR_ATTRIBUTE_READ_ONLY               0x00000010
1085
-#define CKR_ATTRIBUTE_SENSITIVE               0x00000011
1086
-#define CKR_ATTRIBUTE_TYPE_INVALID            0x00000012
1087
-#define CKR_ATTRIBUTE_VALUE_INVALID           0x00000013
1088
-#define CKR_DATA_INVALID                      0x00000020
1089
-#define CKR_DATA_LEN_RANGE                    0x00000021
1090
-#define CKR_DEVICE_ERROR                      0x00000030
1091
-#define CKR_DEVICE_MEMORY                     0x00000031
1092
-#define CKR_DEVICE_REMOVED                    0x00000032
1093
-#define CKR_ENCRYPTED_DATA_INVALID            0x00000040
1094
-#define CKR_ENCRYPTED_DATA_LEN_RANGE          0x00000041
1095
-#define CKR_FUNCTION_CANCELED                 0x00000050
1096
-#define CKR_FUNCTION_NOT_PARALLEL             0x00000051
1097
-
1098
-/* CKR_FUNCTION_NOT_SUPPORTED is new for v2.0 */
1099
-#define CKR_FUNCTION_NOT_SUPPORTED            0x00000054
1100
-
1101
-#define CKR_KEY_HANDLE_INVALID                0x00000060
1102
-
1103
-/* CKR_KEY_SENSITIVE was removed for v2.0 */
1104
-
1105
-#define CKR_KEY_SIZE_RANGE                    0x00000062
1106
-#define CKR_KEY_TYPE_INCONSISTENT             0x00000063
1107
-
1108
-/* CKR_KEY_NOT_NEEDED, CKR_KEY_CHANGED, CKR_KEY_NEEDED,
1109
- * CKR_KEY_INDIGESTIBLE, CKR_KEY_FUNCTION_NOT_PERMITTED,
1110
- * CKR_KEY_NOT_WRAPPABLE, and CKR_KEY_UNEXTRACTABLE are new for
1111
- * v2.0 */
1112
-#define CKR_KEY_NOT_NEEDED                    0x00000064
1113
-#define CKR_KEY_CHANGED                       0x00000065
1114
-#define CKR_KEY_NEEDED                        0x00000066
1115
-#define CKR_KEY_INDIGESTIBLE                  0x00000067
1116
-#define CKR_KEY_FUNCTION_NOT_PERMITTED        0x00000068
1117
-#define CKR_KEY_NOT_WRAPPABLE                 0x00000069
1118
-#define CKR_KEY_UNEXTRACTABLE                 0x0000006A
1119
-
1120
-#define CKR_MECHANISM_INVALID                 0x00000070
1121
-#define CKR_MECHANISM_PARAM_INVALID           0x00000071
1122
-
1123
-/* CKR_OBJECT_CLASS_INCONSISTENT and CKR_OBJECT_CLASS_INVALID
1124
- * were removed for v2.0 */
1125
-#define CKR_OBJECT_HANDLE_INVALID             0x00000082
1126
-#define CKR_OPERATION_ACTIVE                  0x00000090
1127
-#define CKR_OPERATION_NOT_INITIALIZED         0x00000091
1128
-#define CKR_PIN_INCORRECT                     0x000000A0
1129
-#define CKR_PIN_INVALID                       0x000000A1
1130
-#define CKR_PIN_LEN_RANGE                     0x000000A2
1131
-
1132
-/* CKR_PIN_EXPIRED and CKR_PIN_LOCKED are new for v2.0 */
1133
-#define CKR_PIN_EXPIRED                       0x000000A3
1134
-#define CKR_PIN_LOCKED                        0x000000A4
1135
-
1136
-#define CKR_SESSION_CLOSED                    0x000000B0
1137
-#define CKR_SESSION_COUNT                     0x000000B1
1138
-#define CKR_SESSION_HANDLE_INVALID            0x000000B3
1139
-#define CKR_SESSION_PARALLEL_NOT_SUPPORTED    0x000000B4
1140
-#define CKR_SESSION_READ_ONLY                 0x000000B5
1141
-#define CKR_SESSION_EXISTS                    0x000000B6
1142
-
1143
-/* CKR_SESSION_READ_ONLY_EXISTS and
1144
- * CKR_SESSION_READ_WRITE_SO_EXISTS are new for v2.0 */
1145
-#define CKR_SESSION_READ_ONLY_EXISTS          0x000000B7
1146
-#define CKR_SESSION_READ_WRITE_SO_EXISTS      0x000000B8
1147
-
1148
-#define CKR_SIGNATURE_INVALID                 0x000000C0
1149
-#define CKR_SIGNATURE_LEN_RANGE               0x000000C1
1150
-#define CKR_TEMPLATE_INCOMPLETE               0x000000D0
1151
-#define CKR_TEMPLATE_INCONSISTENT             0x000000D1
1152
-#define CKR_TOKEN_NOT_PRESENT                 0x000000E0
1153
-#define CKR_TOKEN_NOT_RECOGNIZED              0x000000E1
1154
-#define CKR_TOKEN_WRITE_PROTECTED             0x000000E2
1155
-#define CKR_UNWRAPPING_KEY_HANDLE_INVALID     0x000000F0
1156
-#define CKR_UNWRAPPING_KEY_SIZE_RANGE         0x000000F1
1157
-#define CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT  0x000000F2
1158
-#define CKR_USER_ALREADY_LOGGED_IN            0x00000100
1159
-#define CKR_USER_NOT_LOGGED_IN                0x00000101
1160
-#define CKR_USER_PIN_NOT_INITIALIZED          0x00000102
1161
-#define CKR_USER_TYPE_INVALID                 0x00000103
1162
-
1163
-/* CKR_USER_ANOTHER_ALREADY_LOGGED_IN and CKR_USER_TOO_MANY_TYPES
1164
- * are new to v2.01 */
1165
-#define CKR_USER_ANOTHER_ALREADY_LOGGED_IN    0x00000104
1166
-#define CKR_USER_TOO_MANY_TYPES               0x00000105
1167
-
1168
-#define CKR_WRAPPED_KEY_INVALID               0x00000110
1169
-#define CKR_WRAPPED_KEY_LEN_RANGE             0x00000112
1170
-#define CKR_WRAPPING_KEY_HANDLE_INVALID       0x00000113
1171
-#define CKR_WRAPPING_KEY_SIZE_RANGE           0x00000114
1172
-#define CKR_WRAPPING_KEY_TYPE_INCONSISTENT    0x00000115
1173
-#define CKR_RANDOM_SEED_NOT_SUPPORTED         0x00000120
1174
-
1175
-/* These are new to v2.0 */
1176
-#define CKR_RANDOM_NO_RNG                     0x00000121
1177
-
1178
-/* These are new to v2.11 */
1179
-#define CKR_DOMAIN_PARAMS_INVALID             0x00000130
1180
-
1181
-/* These are new to v2.0 */
1182
-#define CKR_BUFFER_TOO_SMALL                  0x00000150
1183
-#define CKR_SAVED_STATE_INVALID               0x00000160
1184
-#define CKR_INFORMATION_SENSITIVE             0x00000170
1185
-#define CKR_STATE_UNSAVEABLE                  0x00000180
1186
-
1187
-/* These are new to v2.01 */
1188
-#define CKR_CRYPTOKI_NOT_INITIALIZED          0x00000190
1189
-#define CKR_CRYPTOKI_ALREADY_INITIALIZED      0x00000191
1190
-#define CKR_MUTEX_BAD                         0x000001A0
1191
-#define CKR_MUTEX_NOT_LOCKED                  0x000001A1
1192
-
1193
-/* The following return values are new for PKCS #11 v2.20 amendment 3 */
1194
-#define CKR_NEW_PIN_MODE                      0x000001B0
1195
-#define CKR_NEXT_OTP                          0x000001B1
1196
-
1197
-/* This is new to v2.20 */
1198
-#define CKR_FUNCTION_REJECTED                 0x00000200
1199
-
1200
-#define CKR_VENDOR_DEFINED                    0x80000000
1201
-
1202
-
1203
-/* CK_NOTIFY is an application callback that processes events */
1204
-typedef CK_CALLBACK_FUNCTION(CK_RV, CK_NOTIFY)(
1205
-  CK_SESSION_HANDLE hSession,     /* the session's handle */
1206
-  CK_NOTIFICATION   event,
1207
-  CK_VOID_PTR       pApplication  /* passed to C_OpenSession */
1208
-);
1209
-
1210
-
1211
-/* CK_FUNCTION_LIST is a structure holding a Cryptoki spec
1212
- * version and pointers of appropriate types to all the
1213
- * Cryptoki functions */
1214
-/* CK_FUNCTION_LIST is new for v2.0 */
1215
-typedef struct CK_FUNCTION_LIST CK_FUNCTION_LIST;
1216
-
1217
-typedef CK_FUNCTION_LIST CK_PTR CK_FUNCTION_LIST_PTR;
1218
-
1219
-typedef CK_FUNCTION_LIST_PTR CK_PTR CK_FUNCTION_LIST_PTR_PTR;
1220
-
1221
-
1222
-/* CK_CREATEMUTEX is an application callback for creating a
1223
- * mutex object */
1224
-typedef CK_CALLBACK_FUNCTION(CK_RV, CK_CREATEMUTEX)(
1225
-  CK_VOID_PTR_PTR ppMutex  /* location to receive ptr to mutex */
1226
-);
1227
-
1228
-
1229
-/* CK_DESTROYMUTEX is an application callback for destroying a
1230
- * mutex object */
1231
-typedef CK_CALLBACK_FUNCTION(CK_RV, CK_DESTROYMUTEX)(
1232
-  CK_VOID_PTR pMutex  /* pointer to mutex */
1233
-);
1234
-
1235
-
1236
-/* CK_LOCKMUTEX is an application callback for locking a mutex */
1237
-typedef CK_CALLBACK_FUNCTION(CK_RV, CK_LOCKMUTEX)(
1238
-  CK_VOID_PTR pMutex  /* pointer to mutex */
1239
-);
1240
-
1241
-
1242
-/* CK_UNLOCKMUTEX is an application callback for unlocking a
1243
- * mutex */
1244
-typedef CK_CALLBACK_FUNCTION(CK_RV, CK_UNLOCKMUTEX)(
1245
-  CK_VOID_PTR pMutex  /* pointer to mutex */
1246
-);
1247
-
1248
-
1249
-/* CK_C_INITIALIZE_ARGS provides the optional arguments to
1250
- * C_Initialize */
1251
-typedef struct CK_C_INITIALIZE_ARGS {
1252
-  CK_CREATEMUTEX CreateMutex;
1253
-  CK_DESTROYMUTEX DestroyMutex;
1254
-  CK_LOCKMUTEX LockMutex;
1255
-  CK_UNLOCKMUTEX UnlockMutex;
1256
-  CK_FLAGS flags;
1257
-  CK_VOID_PTR pReserved;
1258
-} CK_C_INITIALIZE_ARGS;
1259
-
1260
-/* flags: bit flags that provide capabilities of the slot
1261
- *      Bit Flag                           Mask       Meaning
1262
- */
1263
-#define CKF_LIBRARY_CANT_CREATE_OS_THREADS 0x00000001
1264
-#define CKF_OS_LOCKING_OK                  0x00000002
1265
-
1266
-typedef CK_C_INITIALIZE_ARGS CK_PTR CK_C_INITIALIZE_ARGS_PTR;
1267
-
1268
-
1269
-/* additional flags for parameters to functions */
1270
-
1271
-/* CKF_DONT_BLOCK is for the function C_WaitForSlotEvent */
1272
-#define CKF_DONT_BLOCK     1
1273
-
1274
-/* CK_RSA_PKCS_OAEP_MGF_TYPE is new for v2.10.
1275
- * CK_RSA_PKCS_OAEP_MGF_TYPE  is used to indicate the Message
1276
- * Generation Function (MGF) applied to a message block when
1277
- * formatting a message block for the PKCS #1 OAEP encryption
1278
- * scheme. */
1279
-typedef CK_ULONG CK_RSA_PKCS_MGF_TYPE;
1280
-
1281
-typedef CK_RSA_PKCS_MGF_TYPE CK_PTR CK_RSA_PKCS_MGF_TYPE_PTR;
1282
-
1283
-/* The following MGFs are defined */
1284
-/* CKG_MGF1_SHA256, CKG_MGF1_SHA384, and CKG_MGF1_SHA512
1285
- * are new for v2.20 */
1286
-#define CKG_MGF1_SHA1         0x00000001
1287
-#define CKG_MGF1_SHA256       0x00000002
1288
-#define CKG_MGF1_SHA384       0x00000003
1289
-#define CKG_MGF1_SHA512       0x00000004
1290
-/* SHA-224 is new for PKCS #11 v2.20 amendment 3 */
1291
-#define CKG_MGF1_SHA224       0x00000005
1292
-
1293
-/* CK_RSA_PKCS_OAEP_SOURCE_TYPE is new for v2.10.
1294
- * CK_RSA_PKCS_OAEP_SOURCE_TYPE  is used to indicate the source
1295
- * of the encoding parameter when formatting a message block
1296
- * for the PKCS #1 OAEP encryption scheme. */
1297
-typedef CK_ULONG CK_RSA_PKCS_OAEP_SOURCE_TYPE;
1298
-
1299
-typedef CK_RSA_PKCS_OAEP_SOURCE_TYPE CK_PTR CK_RSA_PKCS_OAEP_SOURCE_TYPE_PTR;
1300
-
1301
-/* The following encoding parameter sources are defined */
1302
-#define CKZ_DATA_SPECIFIED    0x00000001
1303
-
1304
-/* CK_RSA_PKCS_OAEP_PARAMS is new for v2.10.
1305
- * CK_RSA_PKCS_OAEP_PARAMS provides the parameters to the
1306
- * CKM_RSA_PKCS_OAEP mechanism. */
1307
-typedef struct CK_RSA_PKCS_OAEP_PARAMS {
1308
-        CK_MECHANISM_TYPE hashAlg;
1309
-        CK_RSA_PKCS_MGF_TYPE mgf;
1310
-        CK_RSA_PKCS_OAEP_SOURCE_TYPE source;
1311
-        CK_VOID_PTR pSourceData;
1312
-        CK_ULONG ulSourceDataLen;
1313
-} CK_RSA_PKCS_OAEP_PARAMS;
1314
-
1315
-typedef CK_RSA_PKCS_OAEP_PARAMS CK_PTR CK_RSA_PKCS_OAEP_PARAMS_PTR;
1316
-
1317
-/* CK_RSA_PKCS_PSS_PARAMS is new for v2.11.
1318
- * CK_RSA_PKCS_PSS_PARAMS provides the parameters to the
1319
- * CKM_RSA_PKCS_PSS mechanism(s). */
1320
-typedef struct CK_RSA_PKCS_PSS_PARAMS {
1321
-        CK_MECHANISM_TYPE    hashAlg;
1322
-        CK_RSA_PKCS_MGF_TYPE mgf;
1323
-        CK_ULONG             sLen;
1324
-} CK_RSA_PKCS_PSS_PARAMS;
1325
-
1326
-typedef CK_RSA_PKCS_PSS_PARAMS CK_PTR CK_RSA_PKCS_PSS_PARAMS_PTR;
1327
-
1328
-/* CK_EC_KDF_TYPE is new for v2.11. */
1329
-typedef CK_ULONG CK_EC_KDF_TYPE;
1330
-
1331
-/* The following EC Key Derivation Functions are defined */
1332
-#define CKD_NULL                 0x00000001
1333
-#define CKD_SHA1_KDF             0x00000002
1334
-
1335
-/* CK_ECDH1_DERIVE_PARAMS is new for v2.11.
1336
- * CK_ECDH1_DERIVE_PARAMS provides the parameters to the
1337
- * CKM_ECDH1_DERIVE and CKM_ECDH1_COFACTOR_DERIVE mechanisms,
1338
- * where each party contributes one key pair.
1339
- */
1340
-typedef struct CK_ECDH1_DERIVE_PARAMS {
1341
-  CK_EC_KDF_TYPE kdf;
1342
-  CK_ULONG ulSharedDataLen;
1343
-  CK_BYTE_PTR pSharedData;
1344
-  CK_ULONG ulPublicDataLen;
1345
-  CK_BYTE_PTR pPublicData;
1346
-} CK_ECDH1_DERIVE_PARAMS;
1347
-
1348
-typedef CK_ECDH1_DERIVE_PARAMS CK_PTR CK_ECDH1_DERIVE_PARAMS_PTR;
1349
-
1350
-
1351
-/* CK_ECDH2_DERIVE_PARAMS is new for v2.11.
1352
- * CK_ECDH2_DERIVE_PARAMS provides the parameters to the
1353
- * CKM_ECMQV_DERIVE mechanism, where each party contributes two key pairs. */
1354
-typedef struct CK_ECDH2_DERIVE_PARAMS {
1355
-  CK_EC_KDF_TYPE kdf;
1356
-  CK_ULONG ulSharedDataLen;
1357
-  CK_BYTE_PTR pSharedData;
1358
-  CK_ULONG ulPublicDataLen;
1359
-  CK_BYTE_PTR pPublicData;
1360
-  CK_ULONG ulPrivateDataLen;
1361
-  CK_OBJECT_HANDLE hPrivateData;
1362
-  CK_ULONG ulPublicDataLen2;
1363
-  CK_BYTE_PTR pPublicData2;
1364
-} CK_ECDH2_DERIVE_PARAMS;
1365
-
1366
-typedef CK_ECDH2_DERIVE_PARAMS CK_PTR CK_ECDH2_DERIVE_PARAMS_PTR;
1367
-
1368
-typedef struct CK_ECMQV_DERIVE_PARAMS {
1369
-  CK_EC_KDF_TYPE kdf;
1370
-  CK_ULONG ulSharedDataLen;
1371
-  CK_BYTE_PTR pSharedData;
1372
-  CK_ULONG ulPublicDataLen;
1373
-  CK_BYTE_PTR pPublicData;
1374
-  CK_ULONG ulPrivateDataLen;
1375
-  CK_OBJECT_HANDLE hPrivateData;
1376
-  CK_ULONG ulPublicDataLen2;
1377
-  CK_BYTE_PTR pPublicData2;
1378
-  CK_OBJECT_HANDLE publicKey;
1379
-} CK_ECMQV_DERIVE_PARAMS;
1380
-
1381
-typedef CK_ECMQV_DERIVE_PARAMS CK_PTR CK_ECMQV_DERIVE_PARAMS_PTR;
1382
-
1383
-/* Typedefs and defines for the CKM_X9_42_DH_KEY_PAIR_GEN and the
1384
- * CKM_X9_42_DH_PARAMETER_GEN mechanisms (new for PKCS #11 v2.11) */
1385
-typedef CK_ULONG CK_X9_42_DH_KDF_TYPE;
1386
-typedef CK_X9_42_DH_KDF_TYPE CK_PTR CK_X9_42_DH_KDF_TYPE_PTR;
1387
-
1388
-/* The following X9.42 DH key derivation functions are defined
1389
-   (besides CKD_NULL already defined : */
1390
-#define CKD_SHA1_KDF_ASN1        0x00000003
1391
-#define CKD_SHA1_KDF_CONCATENATE 0x00000004
1392
-
1393
-/* CK_X9_42_DH1_DERIVE_PARAMS is new for v2.11.
1394
- * CK_X9_42_DH1_DERIVE_PARAMS provides the parameters to the
1395
- * CKM_X9_42_DH_DERIVE key derivation mechanism, where each party
1396
- * contributes one key pair */
1397
-typedef struct CK_X9_42_DH1_DERIVE_PARAMS {
1398
-  CK_X9_42_DH_KDF_TYPE kdf;
1399
-  CK_ULONG ulOtherInfoLen;
1400
-  CK_BYTE_PTR pOtherInfo;
1401
-  CK_ULONG ulPublicDataLen;
1402
-  CK_BYTE_PTR pPublicData;
1403
-} CK_X9_42_DH1_DERIVE_PARAMS;
1404
-
1405
-typedef struct CK_X9_42_DH1_DERIVE_PARAMS CK_PTR CK_X9_42_DH1_DERIVE_PARAMS_PTR;
1406
-
1407
-/* CK_X9_42_DH2_DERIVE_PARAMS is new for v2.11.
1408
- * CK_X9_42_DH2_DERIVE_PARAMS provides the parameters to the
1409
- * CKM_X9_42_DH_HYBRID_DERIVE and CKM_X9_42_MQV_DERIVE key derivation
1410
- * mechanisms, where each party contributes two key pairs */
1411
-typedef struct CK_X9_42_DH2_DERIVE_PARAMS {
1412
-  CK_X9_42_DH_KDF_TYPE kdf;
1413
-  CK_ULONG ulOtherInfoLen;
1414
-  CK_BYTE_PTR pOtherInfo;
1415
-  CK_ULONG ulPublicDataLen;
1416
-  CK_BYTE_PTR pPublicData;
1417
-  CK_ULONG ulPrivateDataLen;
1418
-  CK_OBJECT_HANDLE hPrivateData;
1419
-  CK_ULONG ulPublicDataLen2;
1420
-  CK_BYTE_PTR pPublicData2;
1421
-} CK_X9_42_DH2_DERIVE_PARAMS;
1422
-
1423
-typedef CK_X9_42_DH2_DERIVE_PARAMS CK_PTR CK_X9_42_DH2_DERIVE_PARAMS_PTR;
1424
-
1425
-typedef struct CK_X9_42_MQV_DERIVE_PARAMS {
1426
-  CK_X9_42_DH_KDF_TYPE kdf;
1427
-  CK_ULONG ulOtherInfoLen;
1428
-  CK_BYTE_PTR pOtherInfo;
1429
-  CK_ULONG ulPublicDataLen;
1430
-  CK_BYTE_PTR pPublicData;
1431
-  CK_ULONG ulPrivateDataLen;
1432
-  CK_OBJECT_HANDLE hPrivateData;
1433
-  CK_ULONG ulPublicDataLen2;
1434
-  CK_BYTE_PTR pPublicData2;
1435
-  CK_OBJECT_HANDLE publicKey;
1436
-} CK_X9_42_MQV_DERIVE_PARAMS;
1437
-
1438
-typedef CK_X9_42_MQV_DERIVE_PARAMS CK_PTR CK_X9_42_MQV_DERIVE_PARAMS_PTR;
1439
-
1440
-/* CK_KEA_DERIVE_PARAMS provides the parameters to the
1441
- * CKM_KEA_DERIVE mechanism */
1442
-/* CK_KEA_DERIVE_PARAMS is new for v2.0 */
1443
-typedef struct CK_KEA_DERIVE_PARAMS {
1444
-  CK_BBOOL      isSender;
1445
-  CK_ULONG      ulRandomLen;
1446
-  CK_BYTE_PTR   pRandomA;
1447
-  CK_BYTE_PTR   pRandomB;
1448
-  CK_ULONG      ulPublicDataLen;
1449
-  CK_BYTE_PTR   pPublicData;
1450
-} CK_KEA_DERIVE_PARAMS;
1451
-
1452
-typedef CK_KEA_DERIVE_PARAMS CK_PTR CK_KEA_DERIVE_PARAMS_PTR;
1453
-
1454
-
1455
-/* CK_RC2_PARAMS provides the parameters to the CKM_RC2_ECB and
1456
- * CKM_RC2_MAC mechanisms.  An instance of CK_RC2_PARAMS just
1457
- * holds the effective keysize */
1458
-typedef CK_ULONG          CK_RC2_PARAMS;
1459
-
1460
-typedef CK_RC2_PARAMS CK_PTR CK_RC2_PARAMS_PTR;
1461
-
1462
-
1463
-/* CK_RC2_CBC_PARAMS provides the parameters to the CKM_RC2_CBC
1464
- * mechanism */
1465
-typedef struct CK_RC2_CBC_PARAMS {
1466
-  /* ulEffectiveBits was changed from CK_USHORT to CK_ULONG for
1467
-   * v2.0 */
1468
-  CK_ULONG      ulEffectiveBits;  /* effective bits (1-1024) */
1469
-
1470
-  CK_BYTE       iv[8];            /* IV for CBC mode */
1471
-} CK_RC2_CBC_PARAMS;
1472
-
1473
-typedef CK_RC2_CBC_PARAMS CK_PTR CK_RC2_CBC_PARAMS_PTR;
1474
-
1475
-
1476
-/* CK_RC2_MAC_GENERAL_PARAMS provides the parameters for the
1477
- * CKM_RC2_MAC_GENERAL mechanism */
1478
-/* CK_RC2_MAC_GENERAL_PARAMS is new for v2.0 */
1479
-typedef struct CK_RC2_MAC_GENERAL_PARAMS {
1480
-  CK_ULONG      ulEffectiveBits;  /* effective bits (1-1024) */
1481
-  CK_ULONG      ulMacLength;      /* Length of MAC in bytes */
1482
-} CK_RC2_MAC_GENERAL_PARAMS;
1483
-
1484
-typedef CK_RC2_MAC_GENERAL_PARAMS CK_PTR \
1485
-  CK_RC2_MAC_GENERAL_PARAMS_PTR;
1486
-
1487
-
1488
-/* CK_RC5_PARAMS provides the parameters to the CKM_RC5_ECB and
1489
- * CKM_RC5_MAC mechanisms */
1490
-/* CK_RC5_PARAMS is new for v2.0 */
1491
-typedef struct CK_RC5_PARAMS {
1492
-  CK_ULONG      ulWordsize;  /* wordsize in bits */
1493
-  CK_ULONG      ulRounds;    /* number of rounds */
1494
-} CK_RC5_PARAMS;
1495
-
1496
-typedef CK_RC5_PARAMS CK_PTR CK_RC5_PARAMS_PTR;
1497
-
1498
-
1499
-/* CK_RC5_CBC_PARAMS provides the parameters to the CKM_RC5_CBC
1500
- * mechanism */
1501
-/* CK_RC5_CBC_PARAMS is new for v2.0 */
1502
-typedef struct CK_RC5_CBC_PARAMS {
1503
-  CK_ULONG      ulWordsize;  /* wordsize in bits */
1504
-  CK_ULONG      ulRounds;    /* number of rounds */
1505
-  CK_BYTE_PTR   pIv;         /* pointer to IV */
1506
-  CK_ULONG      ulIvLen;     /* length of IV in bytes */
1507
-} CK_RC5_CBC_PARAMS;
1508
-
1509
-typedef CK_RC5_CBC_PARAMS CK_PTR CK_RC5_CBC_PARAMS_PTR;
1510
-
1511
-
1512
-/* CK_RC5_MAC_GENERAL_PARAMS provides the parameters for the
1513
- * CKM_RC5_MAC_GENERAL mechanism */
1514
-/* CK_RC5_MAC_GENERAL_PARAMS is new for v2.0 */
1515
-typedef struct CK_RC5_MAC_GENERAL_PARAMS {
1516
-  CK_ULONG      ulWordsize;   /* wordsize in bits */
1517
-  CK_ULONG      ulRounds;     /* number of rounds */
1518
-  CK_ULONG      ulMacLength;  /* Length of MAC in bytes */
1519
-} CK_RC5_MAC_GENERAL_PARAMS;
1520
-
1521
-typedef CK_RC5_MAC_GENERAL_PARAMS CK_PTR \
1522
-  CK_RC5_MAC_GENERAL_PARAMS_PTR;
1523
-
1524
-
1525
-/* CK_MAC_GENERAL_PARAMS provides the parameters to most block
1526
- * ciphers' MAC_GENERAL mechanisms.  Its value is the length of
1527
- * the MAC */
1528
-/* CK_MAC_GENERAL_PARAMS is new for v2.0 */
1529
-typedef CK_ULONG          CK_MAC_GENERAL_PARAMS;
1530
-
1531
-typedef CK_MAC_GENERAL_PARAMS CK_PTR CK_MAC_GENERAL_PARAMS_PTR;
1532
-
1533
-/* CK_DES/AES_ECB/CBC_ENCRYPT_DATA_PARAMS are new for v2.20 */
1534
-typedef struct CK_DES_CBC_ENCRYPT_DATA_PARAMS {
1535
-  CK_BYTE      iv[8];
1536
-  CK_BYTE_PTR  pData;
1537
-  CK_ULONG     length;
1538
-} CK_DES_CBC_ENCRYPT_DATA_PARAMS;
1539
-
1540
-typedef CK_DES_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_DES_CBC_ENCRYPT_DATA_PARAMS_PTR;
1541
-
1542
-typedef struct CK_AES_CBC_ENCRYPT_DATA_PARAMS {
1543
-  CK_BYTE      iv[16];
1544
-  CK_BYTE_PTR  pData;
1545
-  CK_ULONG     length;
1546
-} CK_AES_CBC_ENCRYPT_DATA_PARAMS;
1547
-
1548
-typedef CK_AES_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_AES_CBC_ENCRYPT_DATA_PARAMS_PTR;
1549
-
1550
-/* CK_SKIPJACK_PRIVATE_WRAP_PARAMS provides the parameters to the
1551
- * CKM_SKIPJACK_PRIVATE_WRAP mechanism */
1552
-/* CK_SKIPJACK_PRIVATE_WRAP_PARAMS is new for v2.0 */
1553
-typedef struct CK_SKIPJACK_PRIVATE_WRAP_PARAMS {
1554
-  CK_ULONG      ulPasswordLen;
1555
-  CK_BYTE_PTR   pPassword;
1556
-  CK_ULONG      ulPublicDataLen;
1557
-  CK_BYTE_PTR   pPublicData;
1558
-  CK_ULONG      ulPAndGLen;
1559
-  CK_ULONG      ulQLen;
1560
-  CK_ULONG      ulRandomLen;
1561
-  CK_BYTE_PTR   pRandomA;
1562
-  CK_BYTE_PTR   pPrimeP;
1563
-  CK_BYTE_PTR   pBaseG;
1564
-  CK_BYTE_PTR   pSubprimeQ;
1565
-} CK_SKIPJACK_PRIVATE_WRAP_PARAMS;
1566
-
1567
-typedef CK_SKIPJACK_PRIVATE_WRAP_PARAMS CK_PTR \
1568
-  CK_SKIPJACK_PRIVATE_WRAP_PTR;
1569
-
1570
-
1571
-/* CK_SKIPJACK_RELAYX_PARAMS provides the parameters to the
1572
- * CKM_SKIPJACK_RELAYX mechanism */
1573
-/* CK_SKIPJACK_RELAYX_PARAMS is new for v2.0 */
1574
-typedef struct CK_SKIPJACK_RELAYX_PARAMS {
1575
-  CK_ULONG      ulOldWrappedXLen;
1576
-  CK_BYTE_PTR   pOldWrappedX;
1577
-  CK_ULONG      ulOldPasswordLen;
1578
-  CK_BYTE_PTR   pOldPassword;
1579
-  CK_ULONG      ulOldPublicDataLen;
1580
-  CK_BYTE_PTR   pOldPublicData;
1581
-  CK_ULONG      ulOldRandomLen;
1582
-  CK_BYTE_PTR   pOldRandomA;
1583
-  CK_ULONG      ulNewPasswordLen;
1584
-  CK_BYTE_PTR   pNewPassword;
1585
-  CK_ULONG      ulNewPublicDataLen;
1586
-  CK_BYTE_PTR   pNewPublicData;
1587
-  CK_ULONG      ulNewRandomLen;
1588
-  CK_BYTE_PTR   pNewRandomA;
1589
-} CK_SKIPJACK_RELAYX_PARAMS;
1590
-
1591
-typedef CK_SKIPJACK_RELAYX_PARAMS CK_PTR \
1592
-  CK_SKIPJACK_RELAYX_PARAMS_PTR;
1593
-
1594
-
1595
-typedef struct CK_PBE_PARAMS {
1596
-  CK_BYTE_PTR      pInitVector;
1597
-  CK_UTF8CHAR_PTR  pPassword;
1598
-  CK_ULONG         ulPasswordLen;
1599
-  CK_BYTE_PTR      pSalt;
1600
-  CK_ULONG         ulSaltLen;
1601
-  CK_ULONG         ulIteration;
1602
-} CK_PBE_PARAMS;
1603
-
1604
-typedef CK_PBE_PARAMS CK_PTR CK_PBE_PARAMS_PTR;
1605
-
1606
-
1607
-/* CK_KEY_WRAP_SET_OAEP_PARAMS provides the parameters to the
1608
- * CKM_KEY_WRAP_SET_OAEP mechanism */
1609
-/* CK_KEY_WRAP_SET_OAEP_PARAMS is new for v2.0 */
1610
-typedef struct CK_KEY_WRAP_SET_OAEP_PARAMS {
1611
-  CK_BYTE       bBC;     /* block contents byte */
1612
-  CK_BYTE_PTR   pX;      /* extra data */
1613
-  CK_ULONG      ulXLen;  /* length of extra data in bytes */
1614
-} CK_KEY_WRAP_SET_OAEP_PARAMS;
1615
-
1616
-typedef CK_KEY_WRAP_SET_OAEP_PARAMS CK_PTR \
1617
-  CK_KEY_WRAP_SET_OAEP_PARAMS_PTR;
1618
-
1619
-
1620
-typedef struct CK_SSL3_RANDOM_DATA {
1621
-  CK_BYTE_PTR  pClientRandom;
1622
-  CK_ULONG     ulClientRandomLen;
1623
-  CK_BYTE_PTR  pServerRandom;
1624
-  CK_ULONG     ulServerRandomLen;
1625
-} CK_SSL3_RANDOM_DATA;
1626
-
1627
-
1628
-typedef struct CK_SSL3_MASTER_KEY_DERIVE_PARAMS {
1629
-  CK_SSL3_RANDOM_DATA RandomInfo;
1630
-  CK_VERSION_PTR pVersion;
1631
-} CK_SSL3_MASTER_KEY_DERIVE_PARAMS;
1632
-
1633
-typedef struct CK_SSL3_MASTER_KEY_DERIVE_PARAMS CK_PTR \
1634
-  CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR;
1635
-
1636
-
1637
-typedef struct CK_SSL3_KEY_MAT_OUT {
1638
-  CK_OBJECT_HANDLE hClientMacSecret;
1639
-  CK_OBJECT_HANDLE hServerMacSecret;
1640
-  CK_OBJECT_HANDLE hClientKey;
1641
-  CK_OBJECT_HANDLE hServerKey;
1642
-  CK_BYTE_PTR      pIVClient;
1643
-  CK_BYTE_PTR      pIVServer;
1644
-} CK_SSL3_KEY_MAT_OUT;
1645
-
1646
-typedef CK_SSL3_KEY_MAT_OUT CK_PTR CK_SSL3_KEY_MAT_OUT_PTR;
1647
-
1648
-
1649
-typedef struct CK_SSL3_KEY_MAT_PARAMS {
1650
-  CK_ULONG                ulMacSizeInBits;
1651
-  CK_ULONG                ulKeySizeInBits;
1652
-  CK_ULONG                ulIVSizeInBits;
1653
-  CK_BBOOL                bIsExport;
1654
-  CK_SSL3_RANDOM_DATA     RandomInfo;
1655
-  CK_SSL3_KEY_MAT_OUT_PTR pReturnedKeyMaterial;
1656
-} CK_SSL3_KEY_MAT_PARAMS;
1657
-
1658
-typedef CK_SSL3_KEY_MAT_PARAMS CK_PTR CK_SSL3_KEY_MAT_PARAMS_PTR;
1659
-
1660
-/* CK_TLS_PRF_PARAMS is new for version 2.20 */
1661
-typedef struct CK_TLS_PRF_PARAMS {
1662
-  CK_BYTE_PTR  pSeed;
1663
-  CK_ULONG     ulSeedLen;
1664
-  CK_BYTE_PTR  pLabel;
1665
-  CK_ULONG     ulLabelLen;
1666
-  CK_BYTE_PTR  pOutput;
1667
-  CK_ULONG_PTR pulOutputLen;
1668
-} CK_TLS_PRF_PARAMS;
1669
-
1670
-typedef CK_TLS_PRF_PARAMS CK_PTR CK_TLS_PRF_PARAMS_PTR;
1671
-
1672
-/* WTLS is new for version 2.20 */
1673
-typedef struct CK_WTLS_RANDOM_DATA {
1674
-  CK_BYTE_PTR pClientRandom;
1675
-  CK_ULONG    ulClientRandomLen;
1676
-  CK_BYTE_PTR pServerRandom;
1677
-  CK_ULONG    ulServerRandomLen;
1678
-} CK_WTLS_RANDOM_DATA;
1679
-
1680
-typedef CK_WTLS_RANDOM_DATA CK_PTR CK_WTLS_RANDOM_DATA_PTR;
1681
-
1682
-typedef struct CK_WTLS_MASTER_KEY_DERIVE_PARAMS {
1683
-  CK_MECHANISM_TYPE   DigestMechanism;
1684
-  CK_WTLS_RANDOM_DATA RandomInfo;
1685
-  CK_BYTE_PTR         pVersion;
1686
-} CK_WTLS_MASTER_KEY_DERIVE_PARAMS;
1687
-
1688
-typedef CK_WTLS_MASTER_KEY_DERIVE_PARAMS CK_PTR \
1689
-  CK_WTLS_MASTER_KEY_DERIVE_PARAMS_PTR;
1690
-
1691
-typedef struct CK_WTLS_PRF_PARAMS {
1692
-  CK_MECHANISM_TYPE DigestMechanism;
1693
-  CK_BYTE_PTR       pSeed;
1694
-  CK_ULONG          ulSeedLen;
1695
-  CK_BYTE_PTR       pLabel;
1696
-  CK_ULONG          ulLabelLen;
1697
-  CK_BYTE_PTR       pOutput;
1698
-  CK_ULONG_PTR      pulOutputLen;
1699
-} CK_WTLS_PRF_PARAMS;
1700
-
1701
-typedef CK_WTLS_PRF_PARAMS CK_PTR CK_WTLS_PRF_PARAMS_PTR;
1702
-
1703
-typedef struct CK_WTLS_KEY_MAT_OUT {
1704
-  CK_OBJECT_HANDLE hMacSecret;
1705
-  CK_OBJECT_HANDLE hKey;
1706
-  CK_BYTE_PTR      pIV;
1707
-} CK_WTLS_KEY_MAT_OUT;
1708
-
1709
-typedef CK_WTLS_KEY_MAT_OUT CK_PTR CK_WTLS_KEY_MAT_OUT_PTR;
1710
-
1711
-typedef struct CK_WTLS_KEY_MAT_PARAMS {
1712
-  CK_MECHANISM_TYPE       DigestMechanism;
1713
-  CK_ULONG                ulMacSizeInBits;
1714
-  CK_ULONG                ulKeySizeInBits;
1715
-  CK_ULONG                ulIVSizeInBits;
1716
-  CK_ULONG                ulSequenceNumber;
1717
-  CK_BBOOL                bIsExport;
1718
-  CK_WTLS_RANDOM_DATA     RandomInfo;
1719
-  CK_WTLS_KEY_MAT_OUT_PTR pReturnedKeyMaterial;
1720
-} CK_WTLS_KEY_MAT_PARAMS;
1721
-
1722
-typedef CK_WTLS_KEY_MAT_PARAMS CK_PTR CK_WTLS_KEY_MAT_PARAMS_PTR;
1723
-
1724
-/* CMS is new for version 2.20 */
1725
-typedef struct CK_CMS_SIG_PARAMS {
1726
-  CK_OBJECT_HANDLE      certificateHandle;
1727
-  CK_MECHANISM_PTR      pSigningMechanism;
1728
-  CK_MECHANISM_PTR      pDigestMechanism;
1729
-  CK_UTF8CHAR_PTR       pContentType;
1730
-  CK_BYTE_PTR           pRequestedAttributes;
1731
-  CK_ULONG              ulRequestedAttributesLen;
1732
-  CK_BYTE_PTR           pRequiredAttributes;
1733
-  CK_ULONG              ulRequiredAttributesLen;
1734
-} CK_CMS_SIG_PARAMS;
1735
-
1736
-typedef CK_CMS_SIG_PARAMS CK_PTR CK_CMS_SIG_PARAMS_PTR;
1737
-
1738
-typedef struct CK_KEY_DERIVATION_STRING_DATA {
1739
-  CK_BYTE_PTR pData;
1740
-  CK_ULONG    ulLen;
1741
-} CK_KEY_DERIVATION_STRING_DATA;
1742
-
1743
-typedef CK_KEY_DERIVATION_STRING_DATA CK_PTR \
1744
-  CK_KEY_DERIVATION_STRING_DATA_PTR;
1745
-
1746
-
1747
-/* The CK_EXTRACT_PARAMS is used for the
1748
- * CKM_EXTRACT_KEY_FROM_KEY mechanism.  It specifies which bit
1749
- * of the base key should be used as the first bit of the
1750
- * derived key */
1751
-/* CK_EXTRACT_PARAMS is new for v2.0 */
1752
-typedef CK_ULONG CK_EXTRACT_PARAMS;
1753
-
1754
-typedef CK_EXTRACT_PARAMS CK_PTR CK_EXTRACT_PARAMS_PTR;
1755
-
1756
-/* CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE is new for v2.10.
1757
- * CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE is used to
1758
- * indicate the Pseudo-Random Function (PRF) used to generate
1759
- * key bits using PKCS #5 PBKDF2. */
1760
-typedef CK_ULONG CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE;
1761
-
1762
-typedef CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE CK_PTR CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE_PTR;
1763
-
1764
-/* The following PRFs are defined in PKCS #5 v2.0. */
1765
-#define CKP_PKCS5_PBKD2_HMAC_SHA1 0x00000001
1766
-
1767
-
1768
-/* CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE is new for v2.10.
1769
- * CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE is used to indicate the
1770
- * source of the salt value when deriving a key using PKCS #5
1771
- * PBKDF2. */
1772
-typedef CK_ULONG CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE;
1773
-
1774
-typedef CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE CK_PTR CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE_PTR;
1775
-
1776
-/* The following salt value sources are defined in PKCS #5 v2.0. */
1777
-#define CKZ_SALT_SPECIFIED        0x00000001
1778
-
1779
-/* CK_PKCS5_PBKD2_PARAMS is new for v2.10.
1780
- * CK_PKCS5_PBKD2_PARAMS is a structure that provides the
1781
- * parameters to the CKM_PKCS5_PBKD2 mechanism. */
1782
-typedef struct CK_PKCS5_PBKD2_PARAMS {
1783
-        CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE           saltSource;
1784
-        CK_VOID_PTR                                pSaltSourceData;
1785
-        CK_ULONG                                   ulSaltSourceDataLen;
1786
-        CK_ULONG                                   iterations;
1787
-        CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE prf;
1788
-        CK_VOID_PTR                                pPrfData;
1789
-        CK_ULONG                                   ulPrfDataLen;
1790
-        CK_UTF8CHAR_PTR                            pPassword;
1791
-        CK_ULONG_PTR                               ulPasswordLen;
1792
-} CK_PKCS5_PBKD2_PARAMS;
1793
-
1794
-typedef CK_PKCS5_PBKD2_PARAMS CK_PTR CK_PKCS5_PBKD2_PARAMS_PTR;
1795
-
1796
-/* All CK_OTP structs are new for PKCS #11 v2.20 amendment 3 */
1797
-
1798
-typedef CK_ULONG CK_OTP_PARAM_TYPE;
1799
-typedef CK_OTP_PARAM_TYPE CK_PARAM_TYPE; /* B/w compatibility */
1800
-
1801
-typedef struct CK_OTP_PARAM {
1802
-    CK_OTP_PARAM_TYPE type;
1803
-    CK_VOID_PTR pValue;
1804
-    CK_ULONG ulValueLen;
1805
-} CK_OTP_PARAM;
1806
-
1807
-typedef CK_OTP_PARAM CK_PTR CK_OTP_PARAM_PTR;
1808
-
1809
-typedef struct CK_OTP_PARAMS {
1810
-    CK_OTP_PARAM_PTR pParams;
1811
-    CK_ULONG ulCount;
1812
-} CK_OTP_PARAMS;
1813
-
1814
-typedef CK_OTP_PARAMS CK_PTR CK_OTP_PARAMS_PTR;
1815
-
1816
-typedef struct CK_OTP_SIGNATURE_INFO {
1817
-    CK_OTP_PARAM_PTR pParams;
1818
-    CK_ULONG ulCount;
1819
-} CK_OTP_SIGNATURE_INFO;
1820
-
1821
-typedef CK_OTP_SIGNATURE_INFO CK_PTR CK_OTP_SIGNATURE_INFO_PTR;
1822
-
1823
-/* The following OTP-related defines are new for PKCS #11 v2.20 amendment 1 */
1824
-#define CK_OTP_VALUE          0
1825
-#define CK_OTP_PIN            1
1826
-#define CK_OTP_CHALLENGE      2
1827
-#define CK_OTP_TIME           3
1828
-#define CK_OTP_COUNTER        4
1829
-#define CK_OTP_FLAGS          5
1830
-#define CK_OTP_OUTPUT_LENGTH  6
1831
-#define CK_OTP_OUTPUT_FORMAT  7
1832
-
1833
-/* The following OTP-related defines are new for PKCS #11 v2.20 amendment 1 */
1834
-#define CKF_NEXT_OTP          0x00000001
1835
-#define CKF_EXCLUDE_TIME      0x00000002
1836
-#define CKF_EXCLUDE_COUNTER   0x00000004
1837
-#define CKF_EXCLUDE_CHALLENGE 0x00000008
1838
-#define CKF_EXCLUDE_PIN       0x00000010
1839
-#define CKF_USER_FRIENDLY_OTP 0x00000020
1840
-
1841
-/* CK_KIP_PARAMS is new for PKCS #11 v2.20 amendment 2 */
1842
-typedef struct CK_KIP_PARAMS {
1843
-    CK_MECHANISM_PTR  pMechanism;
1844
-    CK_OBJECT_HANDLE  hKey;
1845
-    CK_BYTE_PTR       pSeed;
1846
-    CK_ULONG          ulSeedLen;
1847
-} CK_KIP_PARAMS;
1848
-
1849
-typedef CK_KIP_PARAMS CK_PTR CK_KIP_PARAMS_PTR;
1850
-
1851
-/* CK_AES_CTR_PARAMS is new for PKCS #11 v2.20 amendment 3 */
1852
-typedef struct CK_AES_CTR_PARAMS {
1853
-    CK_ULONG ulCounterBits;
1854
-    CK_BYTE cb[16];
1855
-} CK_AES_CTR_PARAMS;
1856
-
1857
-typedef CK_AES_CTR_PARAMS CK_PTR CK_AES_CTR_PARAMS_PTR;
1858
-
1859
-/* CK_CAMELLIA_CTR_PARAMS is new for PKCS #11 v2.20 amendment 3 */
1860
-typedef struct CK_CAMELLIA_CTR_PARAMS {
1861
-    CK_ULONG ulCounterBits;
1862
-    CK_BYTE cb[16];
1863
-} CK_CAMELLIA_CTR_PARAMS;
1864
-
1865
-typedef CK_CAMELLIA_CTR_PARAMS CK_PTR CK_CAMELLIA_CTR_PARAMS_PTR;
1866
-
1867
-/* CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS is new for PKCS #11 v2.20 amendment 3 */
1868
-typedef struct CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS {
1869
-    CK_BYTE      iv[16];
1870
-    CK_BYTE_PTR  pData;
1871
-    CK_ULONG     length;
1872
-} CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS;
1873
-
1874
-typedef CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS_PTR;
1875
-
1876
-/* CK_ARIA_CBC_ENCRYPT_DATA_PARAMS is new for PKCS #11 v2.20 amendment 3 */
1877
-typedef struct CK_ARIA_CBC_ENCRYPT_DATA_PARAMS {
1878
-    CK_BYTE      iv[16];
1879
-    CK_BYTE_PTR  pData;
1880
-    CK_ULONG     length;
1881
-} CK_ARIA_CBC_ENCRYPT_DATA_PARAMS;
1882
-
1883
-typedef CK_ARIA_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_ARIA_CBC_ENCRYPT_DATA_PARAMS_PTR;
1884
-
1885
-#endif
1886 1
deleted file mode 100644
... ...
@@ -1,267 +0,0 @@
1
-// Copyright 2013 Miek Gieben. All rights reserved.
2
-// Use of this source code is governed by a BSD-style
3
-// license that can be found in the LICENSE file.
4
-
5
-package pkcs11
6
-
7
-/*
8
-#define CK_PTR *
9
-#ifndef NULL_PTR
10
-#define NULL_PTR 0
11
-#endif
12
-#define CK_DEFINE_FUNCTION(returnType, name) returnType name
13
-#define CK_DECLARE_FUNCTION(returnType, name) returnType name
14
-#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
15
-#define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
16
-
17
-#include <stdlib.h>
18
-#include <string.h>
19
-#include "pkcs11.h"
20
-
21
-CK_ULONG Index(CK_ULONG_PTR array, CK_ULONG i)
22
-{
23
-	return array[i];
24
-}
25
-*/
26
-import "C"
27
-
28
-import (
29
-	"fmt"
30
-	"time"
31
-	"unsafe"
32
-)
33
-
34
-type arena []unsafe.Pointer
35
-
36
-func (a *arena) Allocate(obj []byte) (C.CK_VOID_PTR, C.CK_ULONG) {
37
-	cobj := C.calloc(C.size_t(len(obj)), 1)
38
-	*a = append(*a, cobj)
39
-	C.memmove(cobj, unsafe.Pointer(&obj[0]), C.size_t(len(obj)))
40
-	return C.CK_VOID_PTR(cobj), C.CK_ULONG(len(obj))
41
-}
42
-
43
-func (a arena) Free() {
44
-	for _, p := range a {
45
-		C.free(p)
46
-	}
47
-}
48
-
49
-// toList converts from a C style array to a []uint.
50
-func toList(clist C.CK_ULONG_PTR, size C.CK_ULONG) []uint {
51
-	l := make([]uint, int(size))
52
-	for i := 0; i < len(l); i++ {
53
-		l[i] = uint(C.Index(clist, C.CK_ULONG(i)))
54
-	}
55
-	defer C.free(unsafe.Pointer(clist))
56
-	return l
57
-}
58
-
59
-// cBBool converts a bool to a CK_BBOOL.
60
-func cBBool(x bool) C.CK_BBOOL {
61
-	if x {
62
-		return C.CK_BBOOL(C.CK_TRUE)
63
-	}
64
-	return C.CK_BBOOL(C.CK_FALSE)
65
-}
66
-
67
-func uintToBytes(x uint64) []byte {
68
-	ul := C.CK_ULONG(x)
69
-	return C.GoBytes(unsafe.Pointer(&ul), C.int(unsafe.Sizeof(ul)))
70
-}
71
-
72
-// Error represents an PKCS#11 error.
73
-type Error uint
74
-
75
-func (e Error) Error() string {
76
-	return fmt.Sprintf("pkcs11: 0x%X: %s", uint(e), strerror[uint(e)])
77
-}
78
-
79
-func toError(e C.CK_RV) error {
80
-	if e == C.CKR_OK {
81
-		return nil
82
-	}
83
-	return Error(e)
84
-}
85
-
86
-/* SessionHandle is a Cryptoki-assigned value that identifies a session. */
87
-type SessionHandle uint
88
-
89
-/* ObjectHandle is a token-specific identifier for an object.  */
90
-type ObjectHandle uint
91
-
92
-// Version represents any version information from the library.
93
-type Version struct {
94
-	Major byte
95
-	Minor byte
96
-}
97
-
98
-func toVersion(version C.CK_VERSION) Version {
99
-	return Version{byte(version.major), byte(version.minor)}
100
-}
101
-
102
-// SlotEvent holds the SlotID which for which an slot event (token insertion,
103
-// removal, etc.) occurred.
104
-type SlotEvent struct {
105
-	SlotID uint
106
-}
107
-
108
-// Info provides information about the library and hardware used.
109
-type Info struct {
110
-	CryptokiVersion    Version
111
-	ManufacturerID     string
112
-	Flags              uint
113
-	LibraryDescription string
114
-	LibraryVersion     Version
115
-}
116
-
117
-/* SlotInfo provides information about a slot. */
118
-type SlotInfo struct {
119
-	SlotDescription string // 64 bytes.
120
-	ManufacturerID  string // 32 bytes.
121
-	Flags           uint
122
-	HardwareVersion Version
123
-	FirmwareVersion Version
124
-}
125
-
126
-/* TokenInfo provides information about a token. */
127
-type TokenInfo struct {
128
-	Label              string
129
-	ManufacturerID     string
130
-	Model              string
131
-	SerialNumber       string
132
-	Flags              uint
133
-	MaxSessionCount    uint
134
-	SessionCount       uint
135
-	MaxRwSessionCount  uint
136
-	RwSessionCount     uint
137
-	MaxPinLen          uint
138
-	MinPinLen          uint
139
-	TotalPublicMemory  uint
140
-	FreePublicMemory   uint
141
-	TotalPrivateMemory uint
142
-	FreePrivateMemory  uint
143
-	HardwareVersion    Version
144
-	FirmwareVersion    Version
145
-	UTCTime            string
146
-}
147
-
148
-/* SesionInfo provides information about a session. */
149
-type SessionInfo struct {
150
-	SlotID      uint
151
-	State       uint
152
-	Flags       uint
153
-	DeviceError uint
154
-}
155
-
156
-// Attribute holds an attribute type/value combination.
157
-type Attribute struct {
158
-	Type  uint
159
-	Value []byte
160
-}
161
-
162
-// NewAttribute allocates a Attribute and returns a pointer to it.
163
-// Note that this is merely a convience function, as values returned
164
-// from the HSM are not converted back to Go values, those are just raw
165
-// byte slices.
166
-func NewAttribute(typ uint, x interface{}) *Attribute {
167
-	// This function nicely transforms *to* an attribute, but there is
168
-	// no corresponding function that transform back *from* an attribute,
169
-	// which in PKCS#11 is just an byte array.
170
-	a := new(Attribute)
171
-	a.Type = typ
172
-	if x == nil {
173
-		return a
174
-	}
175
-	switch v := x.(type) {
176
-	case bool:
177
-		if v {
178
-			a.Value = []byte{1}
179
-		} else {
180
-			a.Value = []byte{0}
181
-		}
182
-	case int:
183
-		a.Value = uintToBytes(uint64(v))
184
-	case uint:
185
-		a.Value = uintToBytes(uint64(v))
186
-	case string:
187
-		a.Value = []byte(v)
188
-	case []byte:
189
-		a.Value = v
190
-	case time.Time: // for CKA_DATE
191
-		a.Value = cDate(v)
192
-	default:
193
-		panic("pkcs11: unhandled attribute type")
194
-	}
195
-	return a
196
-}
197
-
198
-// cAttribute returns the start address and the length of an attribute list.
199
-func cAttributeList(a []*Attribute) (arena, C.CK_ATTRIBUTE_PTR, C.CK_ULONG) {
200
-	var arena arena
201
-	if len(a) == 0 {
202
-		return nil, nil, 0
203
-	}
204
-	pa := make([]C.CK_ATTRIBUTE, len(a))
205
-	for i := 0; i < len(a); i++ {
206
-		pa[i]._type = C.CK_ATTRIBUTE_TYPE(a[i].Type)
207
-		if a[i].Value == nil {
208
-			continue
209
-		}
210
-		pa[i].pValue, pa[i].ulValueLen = arena.Allocate(a[i].Value)
211
-	}
212
-	return arena, C.CK_ATTRIBUTE_PTR(&pa[0]), C.CK_ULONG(len(a))
213
-}
214
-
215
-func cDate(t time.Time) []byte {
216
-	b := make([]byte, 8)
217
-	year, month, day := t.Date()
218
-	y := fmt.Sprintf("%4d", year)
219
-	m := fmt.Sprintf("%02d", month)
220
-	d1 := fmt.Sprintf("%02d", day)
221
-	b[0], b[1], b[2], b[3] = y[0], y[1], y[2], y[3]
222
-	b[4], b[5] = m[0], m[1]
223
-	b[6], b[7] = d1[0], d1[1]
224
-	return b
225
-}
226
-
227
-// Mechanism holds an mechanism type/value combination.
228
-type Mechanism struct {
229
-	Mechanism uint
230
-	Parameter []byte
231
-}
232
-
233
-func NewMechanism(mech uint, x interface{}) *Mechanism {
234
-	m := new(Mechanism)
235
-	m.Mechanism = mech
236
-	if x == nil {
237
-		return m
238
-	}
239
-
240
-	// Add any parameters passed (For now presume always bytes were passed in, is there another case?)
241
-	m.Parameter = x.([]byte)
242
-
243
-	return m
244
-}
245
-
246
-func cMechanismList(m []*Mechanism) (arena, C.CK_MECHANISM_PTR, C.CK_ULONG) {
247
-	var arena arena
248
-	if len(m) == 0 {
249
-		return nil, nil, 0
250
-	}
251
-	pm := make([]C.CK_MECHANISM, len(m))
252
-	for i := 0; i < len(m); i++ {
253
-		pm[i].mechanism = C.CK_MECHANISM_TYPE(m[i].Mechanism)
254
-		if m[i].Parameter == nil {
255
-			continue
256
-		}
257
-		pm[i].pParameter, pm[i].ulParameterLen = arena.Allocate(m[i].Parameter)
258
-	}
259
-	return arena, C.CK_MECHANISM_PTR(&pm[0]), C.CK_ULONG(len(m))
260
-}
261
-
262
-// MechanismInfo provides information about a particular mechanism.
263
-type MechanismInfo struct {
264
-	MinKeySize uint
265
-	MaxKeySize uint
266
-	Flags      uint
267
-}