Showing the changes to java/pkg/sun/security/pkcs11/wrapper/Functions.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,916 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + */ | |
| 4 | + | |
| 5 | +/* Copyright (c) 2002 Graz University of Technology. All rights reserved. | |
| 6 | + * | |
| 7 | + * Redistribution and use in source and binary forms, with or without | |
| 8 | + * modification, are permitted provided that the following conditions are met: | |
| 9 | + * | |
| 10 | + * 1. Redistributions of source code must retain the above copyright notice, | |
| 11 | + * this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 14 | + * this list of conditions and the following disclaimer in the documentation | |
| 15 | + * and/or other materials provided with the distribution. | |
| 16 | + * | |
| 17 | + * 3. The end-user documentation included with the redistribution, if any, must | |
| 18 | + * include the following acknowledgment: | |
| 19 | + * | |
| 20 | + * "This product includes software developed by IAIK of Graz University of | |
| 21 | + * Technology." | |
| 22 | + * | |
| 23 | + * Alternately, this acknowledgment may appear in the software itself, if | |
| 24 | + * and wherever such third-party acknowledgments normally appear. | |
| 25 | + * | |
| 26 | + * 4. The names "Graz University of Technology" and "IAIK of Graz University of | |
| 27 | + * Technology" must not be used to endorse or promote products derived from | |
| 28 | + * this software without prior written permission. | |
| 29 | + * | |
| 30 | + * 5. Products derived from this software may not be called | |
| 31 | + * "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior | |
| 32 | + * written permission of Graz University of Technology. | |
| 33 | + * | |
| 34 | + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED | |
| 35 | + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 36 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 37 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE | |
| 38 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
| 39 | + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 40 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 41 | + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
| 42 | + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| 43 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 44 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 45 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 46 | + */ | |
| 47 | + | |
| 48 | +package sun.security.pkcs11.wrapper; | |
| 49 | + | |
| 50 | +import java.math.BigInteger; | |
| 51 | + | |
| 52 | +import java.util.*; | |
| 53 | + | |
| 54 | +import static sun.security.pkcs11.wrapper.PKCS11Constants.*; | |
| 55 | + | |
| 56 | +/** | |
| 57 | + * This class contains onyl static methods. It is the place for all functions | |
| 58 | + * that are used by several classes in this package. | |
| 59 | + * | |
| 60 | + * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at> | |
| 61 | + * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at> | |
| 62 | + */ | |
| 63 | +public class Functions { | |
| 64 | + | |
| 65 | + // maps between ids and their names, forward and reverse | |
| 66 | + // ids are stored as Integers to save space | |
| 67 | + // since only the lower 32 bits are ever used anyway | |
| 68 | + | |
| 69 | + // mechanisms (CKM_*) | |
| 70 | + private static final Map<Integer,String> mechNames = | |
| 71 | + new HashMap<Integer,String>(); | |
| 72 | + | |
| 73 | + private static final Map<String,Integer> mechIds = | |
| 74 | + new HashMap<String,Integer>(); | |
| 75 | + | |
| 76 | + // key types (CKK_*) | |
| 77 | + private static final Map<Integer,String> keyNames = | |
| 78 | + new HashMap<Integer,String>(); | |
| 79 | + | |
| 80 | + private static final Map<String,Integer> keyIds = | |
| 81 | + new HashMap<String,Integer>(); | |
| 82 | + | |
| 83 | + // attributes (CKA_*) | |
| 84 | + private static final Map<Integer,String> attributeNames = | |
| 85 | + new HashMap<Integer,String>(); | |
| 86 | + | |
| 87 | + private static final Map<String,Integer> attributeIds = | |
| 88 | + new HashMap<String,Integer>(); | |
| 89 | + | |
| 90 | + // object classes (CKO_*) | |
| 91 | + private static final Map<Integer,String> objectClassNames = | |
| 92 | + new HashMap<Integer,String>(); | |
| 93 | + | |
| 94 | + private static final Map<String,Integer> objectClassIds = | |
| 95 | + new HashMap<String,Integer>(); | |
| 96 | + | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * For converting numbers to their hex presentation. | |
| 100 | + */ | |
| 101 | + private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Converts a long value to a hexadecimal String of length 16. Includes | |
| 105 | + * leading zeros if necessary. | |
| 106 | + * | |
| 107 | + * @param value The long value to be converted. | |
| 108 | + * @return The hexadecimal string representation of the long value. | |
| 109 | + */ | |
| 110 | + public static String toFullHexString(long value) { | |
| 111 | + long currentValue = value; | |
| 112 | + StringBuffer stringBuffer = new StringBuffer(16); | |
| 113 | + for(int j = 0; j < 16; j++) { | |
| 114 | + int currentDigit = (int) currentValue & 0xf; | |
| 115 | + stringBuffer.append(HEX_DIGITS[currentDigit]); | |
| 116 | + currentValue >>>= 4; | |
| 117 | + } | |
| 118 | + | |
| 119 | + return stringBuffer.reverse().toString(); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Converts a int value to a hexadecimal String of length 8. Includes | |
| 124 | + * leading zeros if necessary. | |
| 125 | + * | |
| 126 | + * @param value The int value to be converted. | |
| 127 | + * @return The hexadecimal string representation of the int value. | |
| 128 | + */ | |
| 129 | + public static String toFullHexString(int value) { | |
| 130 | + int currentValue = value; | |
| 131 | + StringBuffer stringBuffer = new StringBuffer(8); | |
| 132 | + for(int i = 0; i < 8; i++) { | |
| 133 | + int currentDigit = currentValue & 0xf; | |
| 134 | + stringBuffer.append(HEX_DIGITS[currentDigit]); | |
| 135 | + currentValue >>>= 4; | |
| 136 | + } | |
| 137 | + | |
| 138 | + return stringBuffer.reverse().toString(); | |
| 139 | + } | |
| 140 | + | |
| 141 | + /** | |
| 142 | + * converts a long value to a hexadecimal String | |
| 143 | + * | |
| 144 | + * @param value the long value to be converted | |
| 145 | + * @return the hexadecimal string representation of the long value | |
| 146 | + */ | |
| 147 | + public static String toHexString(long value) { | |
| 148 | + return Long.toHexString(value); | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Converts a byte array to a hexadecimal String. Each byte is presented by | |
| 153 | + * its two digit hex-code; 0x0A -> "0a", 0x00 -> "00". No leading "0x" is | |
| 154 | + * included in the result. | |
| 155 | + * | |
| 156 | + * @param value the byte array to be converted | |
| 157 | + * @return the hexadecimal string representation of the byte array | |
| 158 | + */ | |
| 159 | + public static String toHexString(byte[] value) { | |
| 160 | + if (value == null) { | |
| 161 | + return null; | |
| 162 | + } | |
| 163 | + | |
| 164 | + StringBuffer buffer = new StringBuffer(2 * value.length); | |
| 165 | + int single; | |
| 166 | + | |
| 167 | + for (int i = 0; i < value.length; i++) { | |
| 168 | + single = value[i] & 0xFF; | |
| 169 | + | |
| 170 | + if (single < 0x10) { | |
| 171 | + buffer.append('0'); | |
| 172 | + } | |
| 173 | + | |
| 174 | + buffer.append(Integer.toString(single, 16)); | |
| 175 | + } | |
| 176 | + | |
| 177 | + return buffer.toString(); | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * converts a long value to a binary String | |
| 182 | + * | |
| 183 | + * @param value the long value to be converted | |
| 184 | + * @return the binary string representation of the long value | |
| 185 | + */ | |
| 186 | + public static String toBinaryString(long value) { | |
| 187 | + return Long.toString(value, 2); | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * converts a byte array to a binary String | |
| 192 | + * | |
| 193 | + * @param value the byte array to be converted | |
| 194 | + * @return the binary string representation of the byte array | |
| 195 | + */ | |
| 196 | + public static String toBinaryString(byte[] value) { | |
| 197 | + BigInteger helpBigInteger = new BigInteger(1, value); | |
| 198 | + | |
| 199 | + return helpBigInteger.toString(2); | |
| 200 | + } | |
| 201 | + | |
| 202 | + private static class Flags { | |
| 203 | + private final long[] flagIds; | |
| 204 | + private final String[] flagNames; | |
| 205 | + Flags(long[] flagIds, String[] flagNames) { | |
| 206 | + if (flagIds.length != flagNames.length) { | |
| 207 | + throw new AssertionError("Array lengths do not match"); | |
| 208 | + } | |
| 209 | + this.flagIds = flagIds; | |
| 210 | + this.flagNames = flagNames; | |
| 211 | + } | |
| 212 | + String toString(long val) { | |
| 213 | + StringBuilder sb = new StringBuilder(); | |
| 214 | + boolean first = true; | |
| 215 | + for (int i = 0; i < flagIds.length; i++) { | |
| 216 | + if ((val & flagIds[i]) != 0) { | |
| 217 | + if (first == false) { | |
| 218 | + sb.append(" | "); | |
| 219 | + } | |
| 220 | + sb.append(flagNames[i]); | |
| 221 | + first = false; | |
| 222 | + } | |
| 223 | + } | |
| 224 | + return sb.toString(); | |
| 225 | + } | |
| 226 | + } | |
| 227 | + | |
| 228 | + private static final Flags slotInfoFlags = new Flags(new long[] { | |
| 229 | + CKF_TOKEN_PRESENT, | |
| 230 | + CKF_REMOVABLE_DEVICE, | |
| 231 | + CKF_HW_SLOT, | |
| 232 | + }, new String[] { | |
| 233 | + "CKF_TOKEN_PRESENT", | |
| 234 | + "CKF_REMOVABLE_DEVICE", | |
| 235 | + "CKF_HW_SLOT", | |
| 236 | + }); | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * converts the long value flags to a SlotInfoFlag string | |
| 240 | + * | |
| 241 | + * @param flags the flags to be converted | |
| 242 | + * @return the SlotInfoFlag string representation of the flags | |
| 243 | + */ | |
| 244 | + public static String slotInfoFlagsToString(long flags) { | |
| 245 | + return slotInfoFlags.toString(flags); | |
| 246 | + } | |
| 247 | + | |
| 248 | + private static final Flags tokenInfoFlags = new Flags(new long[] { | |
| 249 | + CKF_RNG, | |
| 250 | + CKF_WRITE_PROTECTED, | |
| 251 | + CKF_LOGIN_REQUIRED, | |
| 252 | + CKF_USER_PIN_INITIALIZED, | |
| 253 | + CKF_RESTORE_KEY_NOT_NEEDED, | |
| 254 | + CKF_CLOCK_ON_TOKEN, | |
| 255 | + CKF_PROTECTED_AUTHENTICATION_PATH, | |
| 256 | + CKF_DUAL_CRYPTO_OPERATIONS, | |
| 257 | + CKF_TOKEN_INITIALIZED, | |
| 258 | + CKF_SECONDARY_AUTHENTICATION, | |
| 259 | + CKF_USER_PIN_COUNT_LOW, | |
| 260 | + CKF_USER_PIN_FINAL_TRY, | |
| 261 | + CKF_USER_PIN_LOCKED, | |
| 262 | + CKF_USER_PIN_TO_BE_CHANGED, | |
| 263 | + CKF_SO_PIN_COUNT_LOW, | |
| 264 | + CKF_SO_PIN_FINAL_TRY, | |
| 265 | + CKF_SO_PIN_LOCKED, | |
| 266 | + CKF_SO_PIN_TO_BE_CHANGED, | |
| 267 | + }, new String[] { | |
| 268 | + "CKF_RNG", | |
| 269 | + "CKF_WRITE_PROTECTED", | |
| 270 | + "CKF_LOGIN_REQUIRED", | |
| 271 | + "CKF_USER_PIN_INITIALIZED", | |
| 272 | + "CKF_RESTORE_KEY_NOT_NEEDED", | |
| 273 | + "CKF_CLOCK_ON_TOKEN", | |
| 274 | + "CKF_PROTECTED_AUTHENTICATION_PATH", | |
| 275 | + "CKF_DUAL_CRYPTO_OPERATIONS", | |
| 276 | + "CKF_TOKEN_INITIALIZED", | |
| 277 | + "CKF_SECONDARY_AUTHENTICATION", | |
| 278 | + "CKF_USER_PIN_COUNT_LOW", | |
| 279 | + "CKF_USER_PIN_FINAL_TRY", | |
| 280 | + "CKF_USER_PIN_LOCKED", | |
| 281 | + "CKF_USER_PIN_TO_BE_CHANGED", | |
| 282 | + "CKF_SO_PIN_COUNT_LOW", | |
| 283 | + "CKF_SO_PIN_FINAL_TRY", | |
| 284 | + "CKF_SO_PIN_LOCKED", | |
| 285 | + "CKF_SO_PIN_TO_BE_CHANGED", | |
| 286 | + }); | |
| 287 | + | |
| 288 | + /** | |
| 289 | + * converts long value flags to a TokenInfoFlag string | |
| 290 | + * | |
| 291 | + * @param flags the flags to be converted | |
| 292 | + * @return the TokenInfoFlag string representation of the flags | |
| 293 | + */ | |
| 294 | + public static String tokenInfoFlagsToString(long flags) { | |
| 295 | + return tokenInfoFlags.toString(flags); | |
| 296 | + } | |
| 297 | + | |
| 298 | + private static final Flags sessionInfoFlags = new Flags(new long[] { | |
| 299 | + CKF_RW_SESSION, | |
| 300 | + CKF_SERIAL_SESSION, | |
| 301 | + }, new String[] { | |
| 302 | + "CKF_RW_SESSION", | |
| 303 | + "CKF_SERIAL_SESSION", | |
| 304 | + }); | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * converts the long value flags to a SessionInfoFlag string | |
| 308 | + * | |
| 309 | + * @param flags the flags to be converted | |
| 310 | + * @return the SessionInfoFlag string representation of the flags | |
| 311 | + */ | |
| 312 | + public static String sessionInfoFlagsToString(long flags) { | |
| 313 | + return sessionInfoFlags.toString(flags); | |
| 314 | + } | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * converts the long value state to a SessionState string | |
| 318 | + * | |
| 319 | + * @param state the state to be converted | |
| 320 | + * @return the SessionState string representation of the state | |
| 321 | + */ | |
| 322 | + public static String sessionStateToString(long state) { | |
| 323 | + String name; | |
| 324 | + | |
| 325 | + if (state == CKS_RO_PUBLIC_SESSION) { | |
| 326 | + name = "CKS_RO_PUBLIC_SESSION"; | |
| 327 | + } else if (state == CKS_RO_USER_FUNCTIONS) { | |
| 328 | + name = "CKS_RO_USER_FUNCTIONS"; | |
| 329 | + } else if (state == CKS_RW_PUBLIC_SESSION) { | |
| 330 | + name = "CKS_RW_PUBLIC_SESSION"; | |
| 331 | + } else if (state == CKS_RW_USER_FUNCTIONS) { | |
| 332 | + name = "CKS_RW_USER_FUNCTIONS"; | |
| 333 | + } else if (state == CKS_RW_SO_FUNCTIONS) { | |
| 334 | + name = "CKS_RW_SO_FUNCTIONS"; | |
| 335 | + } else { | |
| 336 | + name = "ERROR: unknown session state 0x" + toFullHexString(state); | |
| 337 | + } | |
| 338 | + | |
| 339 | + return name; | |
| 340 | + } | |
| 341 | + | |
| 342 | + private static final Flags mechanismInfoFlags = new Flags(new long[] { | |
| 343 | + CKF_HW, | |
| 344 | + CKF_ENCRYPT, | |
| 345 | + CKF_DECRYPT, | |
| 346 | + CKF_DIGEST, | |
| 347 | + CKF_SIGN, | |
| 348 | + CKF_SIGN_RECOVER, | |
| 349 | + CKF_VERIFY, | |
| 350 | + CKF_VERIFY_RECOVER, | |
| 351 | + CKF_GENERATE, | |
| 352 | + CKF_GENERATE_KEY_PAIR, | |
| 353 | + CKF_WRAP, | |
| 354 | + CKF_UNWRAP, | |
| 355 | + CKF_DERIVE, | |
| 356 | + CKF_EC_F_P, | |
| 357 | + CKF_EC_F_2M, | |
| 358 | + CKF_EC_ECPARAMETERS, | |
| 359 | + CKF_EC_NAMEDCURVE, | |
| 360 | + CKF_EC_UNCOMPRESS, | |
| 361 | + CKF_EC_COMPRESS, | |
| 362 | + CKF_EXTENSION, | |
| 363 | + }, new String[] { | |
| 364 | + "CKF_HW", | |
| 365 | + "CKF_ENCRYPT", | |
| 366 | + "CKF_DECRYPT", | |
| 367 | + "CKF_DIGEST", | |
| 368 | + "CKF_SIGN", | |
| 369 | + "CKF_SIGN_RECOVER", | |
| 370 | + "CKF_VERIFY", | |
| 371 | + "CKF_VERIFY_RECOVER", | |
| 372 | + "CKF_GENERATE", | |
| 373 | + "CKF_GENERATE_KEY_PAIR", | |
| 374 | + "CKF_WRAP", | |
| 375 | + "CKF_UNWRAP", | |
| 376 | + "CKF_DERIVE", | |
| 377 | + "CKF_EC_F_P", | |
| 378 | + "CKF_EC_F_2M", | |
| 379 | + "CKF_EC_ECPARAMETERS", | |
| 380 | + "CKF_EC_NAMEDCURVE", | |
| 381 | + "CKF_EC_UNCOMPRESS", | |
| 382 | + "CKF_EC_COMPRESS", | |
| 383 | + "CKF_EXTENSION", | |
| 384 | + }); | |
| 385 | + | |
| 386 | + /** | |
| 387 | + * converts the long value flags to a MechanismInfoFlag string | |
| 388 | + * | |
| 389 | + * @param flags the flags to be converted | |
| 390 | + * @return the MechanismInfoFlag string representation of the flags | |
| 391 | + */ | |
| 392 | + public static String mechanismInfoFlagsToString(long flags) { | |
| 393 | + return mechanismInfoFlags.toString(flags); | |
| 394 | + } | |
| 395 | + | |
| 396 | + private static String getName(Map<Integer,String> nameMap, long id) { | |
| 397 | + String name = null; | |
| 398 | + if ((id >>> 32) == 0) { | |
| 399 | + name = nameMap.get(Integer.valueOf((int)id)); | |
| 400 | + } | |
| 401 | + if (name == null) { | |
| 402 | + name = "Unknown 0x" + toFullHexString(id); | |
| 403 | + } | |
| 404 | + return name; | |
| 405 | + } | |
| 406 | + | |
| 407 | + public static long getId(Map<String,Integer> idMap, String name) { | |
| 408 | + Integer mech = idMap.get(name); | |
| 409 | + if (mech == null) { | |
| 410 | + throw new IllegalArgumentException("Unknown name " + name); | |
| 411 | + } | |
| 412 | + return mech.intValue() & 0xffffffffL; | |
| 413 | + } | |
| 414 | + | |
| 415 | + public static String getMechanismName(long id) { | |
| 416 | + return getName(mechNames, id); | |
| 417 | + } | |
| 418 | + | |
| 419 | + public static long getMechanismId(String name) { | |
| 420 | + return getId(mechIds, name); | |
| 421 | + } | |
| 422 | + | |
| 423 | + public static String getKeyName(long id) { | |
| 424 | + return getName(keyNames, id); | |
| 425 | + } | |
| 426 | + | |
| 427 | + public static long getKeyId(String name) { | |
| 428 | + return getId(keyIds, name); | |
| 429 | + } | |
| 430 | + | |
| 431 | + public static String getAttributeName(long id) { | |
| 432 | + return getName(attributeNames, id); | |
| 433 | + } | |
| 434 | + | |
| 435 | + public static long getAttributeId(String name) { | |
| 436 | + return getId(attributeIds, name); | |
| 437 | + } | |
| 438 | + | |
| 439 | + public static String getObjectClassName(long id) { | |
| 440 | + return getName(objectClassNames, id); | |
| 441 | + } | |
| 442 | + | |
| 443 | + public static long getObjectClassId(String name) { | |
| 444 | + return getId(objectClassIds, name); | |
| 445 | + } | |
| 446 | + | |
| 447 | + /** | |
| 448 | + * Check the given arrays for equalitiy. This method considers both arrays as | |
| 449 | + * equal, if both are <code>null</code> or both have the same length and | |
| 450 | + * contain exactly the same byte values. | |
| 451 | + * | |
| 452 | + * @param array1 The first array. | |
| 453 | + * @param array2 The second array. | |
| 454 | + * @return True, if both arrays are <code>null</code> or both have the same | |
| 455 | + * length and contain exactly the same byte values. False, otherwise. | |
| 456 | + * @preconditions | |
| 457 | + * @postconditions | |
| 458 | + */ | |
| 459 | + public static boolean equals(byte[] array1, byte[] array2) { | |
| 460 | + return Arrays.equals(array1, array2); | |
| 461 | + } | |
| 462 | + | |
| 463 | + /** | |
| 464 | + * Check the given arrays for equalitiy. This method considers both arrays as | |
| 465 | + * equal, if both are <code>null</code> or both have the same length and | |
| 466 | + * contain exactly the same char values. | |
| 467 | + * | |
| 468 | + * @param array1 The first array. | |
| 469 | + * @param array2 The second array. | |
| 470 | + * @return True, if both arrays are <code>null</code> or both have the same | |
| 471 | + * length and contain exactly the same char values. False, otherwise. | |
| 472 | + * @preconditions | |
| 473 | + * @postconditions | |
| 474 | + */ | |
| 475 | + public static boolean equals(char[] array1, char[] array2) { | |
| 476 | + return Arrays.equals(array1, array2); | |
| 477 | + } | |
| 478 | + | |
| 479 | + /** | |
| 480 | + * Check the given dates for equalitiy. This method considers both dates as | |
| 481 | + * equal, if both are <code>null</code> or both contain exactly the same char | |
| 482 | + * values. | |
| 483 | + * | |
| 484 | + * @param date1 The first date. | |
| 485 | + * @param date2 The second date. | |
| 486 | + * @return True, if both dates are <code>null</code> or both contain the same | |
| 487 | + * char values. False, otherwise. | |
| 488 | + * @preconditions | |
| 489 | + * @postconditions | |
| 490 | + */ | |
| 491 | + public static boolean equals(CK_DATE date1, CK_DATE date2) { | |
| 492 | + boolean equal = false; | |
| 493 | + | |
| 494 | + if (date1 == date2) { | |
| 495 | + equal = true; | |
| 496 | + } else if ((date1 != null) && (date2 != null)) { | |
| 497 | + equal = equals(date1.year, date2.year) | |
| 498 | + && equals(date1.month, date2.month) | |
| 499 | + && equals(date1.day, date2.day); | |
| 500 | + } else { | |
| 501 | + equal = false; | |
| 502 | + } | |
| 503 | + | |
| 504 | + return equal ; | |
| 505 | + } | |
| 506 | + | |
| 507 | + /** | |
| 508 | + * Calculate a hash code for the given byte array. | |
| 509 | + * | |
| 510 | + * @param array The byte array. | |
| 511 | + * @return A hash code for the given array. | |
| 512 | + * @preconditions | |
| 513 | + * @postconditions | |
| 514 | + */ | |
| 515 | + public static int hashCode(byte[] array) { | |
| 516 | + int hash = 0; | |
| 517 | + | |
| 518 | + if (array != null) { | |
| 519 | + for (int i = 0; (i < 4) && (i < array.length); i++) { | |
| 520 | + hash ^= ((int) (0xFF & array[i])) << ((i%4) << 3); | |
| 521 | + } | |
| 522 | + } | |
| 523 | + | |
| 524 | + return hash ; | |
| 525 | + } | |
| 526 | + | |
| 527 | + /** | |
| 528 | + * Calculate a hash code for the given char array. | |
| 529 | + * | |
| 530 | + * @param array The char array. | |
| 531 | + * @return A hash code for the given array. | |
| 532 | + * @preconditions | |
| 533 | + * @postconditions | |
| 534 | + */ | |
| 535 | + public static int hashCode(char[] array) { | |
| 536 | + int hash = 0; | |
| 537 | + | |
| 538 | + if (array != null) { | |
| 539 | + for (int i = 0; (i < 4) && (i < array.length); i++) { | |
| 540 | + hash ^= ((int) (0xFFFF & array[i])) << ((i%2) << 4); | |
| 541 | + } | |
| 542 | + } | |
| 543 | + | |
| 544 | + return hash ; | |
| 545 | + } | |
| 546 | + | |
| 547 | + /** | |
| 548 | + * Calculate a hash code for the given date object. | |
| 549 | + * | |
| 550 | + * @param date The date object. | |
| 551 | + * @return A hash code for the given date. | |
| 552 | + * @preconditions | |
| 553 | + * @postconditions | |
| 554 | + */ | |
| 555 | + public static int hashCode(CK_DATE date) { | |
| 556 | + int hash = 0; | |
| 557 | + | |
| 558 | + if (date != null) { | |
| 559 | + if (date.year.length == 4) { | |
| 560 | + hash ^= ((int) (0xFFFF & date.year[0])) << 16; | |
| 561 | + hash ^= (int) (0xFFFF & date.year[1]); | |
| 562 | + hash ^= ((int) (0xFFFF & date.year[2])) << 16; | |
| 563 | + hash ^= (int) (0xFFFF & date.year[3]); | |
| 564 | + } | |
| 565 | + if (date.month.length == 2) { | |
| 566 | + hash ^= ((int) (0xFFFF & date.month[0])) << 16; | |
| 567 | + hash ^= (int) (0xFFFF & date.month[1]); | |
| 568 | + } | |
| 569 | + if (date.day.length == 2) { | |
| 570 | + hash ^= ((int) (0xFFFF & date.day[0])) << 16; | |
| 571 | + hash ^= (int) (0xFFFF & date.day[1]); | |
| 572 | + } | |
| 573 | + } | |
| 574 | + | |
| 575 | + return hash ; | |
| 576 | + } | |
| 577 | + | |
| 578 | + private static void addMapping(Map<Integer,String> nameMap, | |
| 579 | + Map<String,Integer> idMap, long id, String name) { | |
| 580 | + if ((id >>> 32) != 0) { | |
| 581 | + throw new AssertionError("Id has high bits set: " + id + ", " + name); | |
| 582 | + } | |
| 583 | + Integer intId = Integer.valueOf((int)id); | |
| 584 | + if (nameMap.put(intId, name) != null) { | |
| 585 | + throw new AssertionError("Duplicate id: " + id + ", " + name); | |
| 586 | + } | |
| 587 | + if (idMap.put(name, intId) != null) { | |
| 588 | + throw new AssertionError("Duplicate name: " + id + ", " + name); | |
| 589 | + } | |
| 590 | + } | |
| 591 | + | |
| 592 | + private static void addMech(long id, String name) { | |
| 593 | + addMapping(mechNames, mechIds, id, name); | |
| 594 | + } | |
| 595 | + | |
| 596 | + private static void addKeyType(long id, String name) { | |
| 597 | + addMapping(keyNames, keyIds, id, name); | |
| 598 | + } | |
| 599 | + | |
| 600 | + private static void addAttribute(long id, String name) { | |
| 601 | + addMapping(attributeNames, attributeIds, id, name); | |
| 602 | + } | |
| 603 | + | |
| 604 | + private static void addObjectClass(long id, String name) { | |
| 605 | + addMapping(objectClassNames, objectClassIds, id, name); | |
| 606 | + } | |
| 607 | + | |
| 608 | + static { | |
| 609 | + addMech(CKM_RSA_PKCS_KEY_PAIR_GEN, "CKM_RSA_PKCS_KEY_PAIR_GEN"); | |
| 610 | + addMech(CKM_RSA_PKCS, "CKM_RSA_PKCS"); | |
| 611 | + addMech(CKM_RSA_9796, "CKM_RSA_9796"); | |
| 612 | + addMech(CKM_RSA_X_509, "CKM_RSA_X_509"); | |
| 613 | + addMech(CKM_MD2_RSA_PKCS, "CKM_MD2_RSA_PKCS"); | |
| 614 | + addMech(CKM_MD5_RSA_PKCS, "CKM_MD5_RSA_PKCS"); | |
| 615 | + addMech(CKM_SHA1_RSA_PKCS, "CKM_SHA1_RSA_PKCS"); | |
| 616 | + addMech(CKM_RIPEMD128_RSA_PKCS, "CKM_RIPEMD128_RSA_PKCS"); | |
| 617 | + addMech(CKM_RIPEMD160_RSA_PKCS, "CKM_RIPEMD160_RSA_PKCS"); | |
| 618 | + addMech(CKM_RSA_PKCS_OAEP, "CKM_RSA_PKCS_OAEP"); | |
| 619 | + addMech(CKM_RSA_X9_31_KEY_PAIR_GEN, "CKM_RSA_X9_31_KEY_PAIR_GEN"); | |
| 620 | + addMech(CKM_RSA_X9_31, "CKM_RSA_X9_31"); | |
| 621 | + addMech(CKM_SHA1_RSA_X9_31, "CKM_SHA1_RSA_X9_31"); | |
| 622 | + addMech(CKM_RSA_PKCS_PSS, "CKM_RSA_PKCS_PSS"); | |
| 623 | + addMech(CKM_SHA1_RSA_PKCS_PSS, "CKM_SHA1_RSA_PKCS_PSS"); | |
| 624 | + addMech(CKM_DSA_KEY_PAIR_GEN, "CKM_DSA_KEY_PAIR_GEN"); | |
| 625 | + addMech(CKM_DSA, "CKM_DSA"); | |
| 626 | + addMech(CKM_DSA_SHA1, "CKM_DSA_SHA1"); | |
| 627 | + addMech(CKM_DH_PKCS_KEY_PAIR_GEN, "CKM_DH_PKCS_KEY_PAIR_GEN"); | |
| 628 | + addMech(CKM_DH_PKCS_DERIVE, "CKM_DH_PKCS_DERIVE"); | |
| 629 | + addMech(CKM_X9_42_DH_KEY_PAIR_GEN, "CKM_X9_42_DH_KEY_PAIR_GEN"); | |
| 630 | + addMech(CKM_X9_42_DH_DERIVE, "CKM_X9_42_DH_DERIVE"); | |
| 631 | + addMech(CKM_X9_42_DH_HYBRID_DERIVE, "CKM_X9_42_DH_HYBRID_DERIVE"); | |
| 632 | + addMech(CKM_X9_42_MQV_DERIVE, "CKM_X9_42_MQV_DERIVE"); | |
| 633 | + addMech(CKM_SHA256_RSA_PKCS, "CKM_SHA256_RSA_PKCS"); | |
| 634 | + addMech(CKM_SHA384_RSA_PKCS, "CKM_SHA384_RSA_PKCS"); | |
| 635 | + addMech(CKM_SHA512_RSA_PKCS, "CKM_SHA512_RSA_PKCS"); | |
| 636 | + addMech(CKM_RC2_KEY_GEN, "CKM_RC2_KEY_GEN"); | |
| 637 | + addMech(CKM_RC2_ECB, "CKM_RC2_ECB"); | |
| 638 | + addMech(CKM_RC2_CBC, "CKM_RC2_CBC"); | |
| 639 | + addMech(CKM_RC2_MAC, "CKM_RC2_MAC"); | |
| 640 | + addMech(CKM_RC2_MAC_GENERAL, "CKM_RC2_MAC_GENERAL"); | |
| 641 | + addMech(CKM_RC2_CBC_PAD, "CKM_RC2_CBC_PAD"); | |
| 642 | + addMech(CKM_RC4_KEY_GEN, "CKM_RC4_KEY_GEN"); | |
| 643 | + addMech(CKM_RC4, "CKM_RC4"); | |
| 644 | + addMech(CKM_DES_KEY_GEN, "CKM_DES_KEY_GEN"); | |
| 645 | + addMech(CKM_DES_ECB, "CKM_DES_ECB"); | |
| 646 | + addMech(CKM_DES_CBC, "CKM_DES_CBC"); | |
| 647 | + addMech(CKM_DES_MAC, "CKM_DES_MAC"); | |
| 648 | + addMech(CKM_DES_MAC_GENERAL, "CKM_DES_MAC_GENERAL"); | |
| 649 | + addMech(CKM_DES_CBC_PAD, "CKM_DES_CBC_PAD"); | |
| 650 | + addMech(CKM_DES2_KEY_GEN, "CKM_DES2_KEY_GEN"); | |
| 651 | + addMech(CKM_DES3_KEY_GEN, "CKM_DES3_KEY_GEN"); | |
| 652 | + addMech(CKM_DES3_ECB, "CKM_DES3_ECB"); | |
| 653 | + addMech(CKM_DES3_CBC, "CKM_DES3_CBC"); | |
| 654 | + addMech(CKM_DES3_MAC, "CKM_DES3_MAC"); | |
| 655 | + addMech(CKM_DES3_MAC_GENERAL, "CKM_DES3_MAC_GENERAL"); | |
| 656 | + addMech(CKM_DES3_CBC_PAD, "CKM_DES3_CBC_PAD"); | |
| 657 | + addMech(CKM_CDMF_KEY_GEN, "CKM_CDMF_KEY_GEN"); | |
| 658 | + addMech(CKM_CDMF_ECB, "CKM_CDMF_ECB"); | |
| 659 | + addMech(CKM_CDMF_CBC, "CKM_CDMF_CBC"); | |
| 660 | + addMech(CKM_CDMF_MAC, "CKM_CDMF_MAC"); | |
| 661 | + addMech(CKM_CDMF_MAC_GENERAL, "CKM_CDMF_MAC_GENERAL"); | |
| 662 | + addMech(CKM_CDMF_CBC_PAD, "CKM_CDMF_CBC_PAD"); | |
| 663 | + addMech(CKM_MD2, "CKM_MD2"); | |
| 664 | + addMech(CKM_MD2_HMAC, "CKM_MD2_HMAC"); | |
| 665 | + addMech(CKM_MD2_HMAC_GENERAL, "CKM_MD2_HMAC_GENERAL"); | |
| 666 | + addMech(CKM_MD5, "CKM_MD5"); | |
| 667 | + addMech(CKM_MD5_HMAC, "CKM_MD5_HMAC"); | |
| 668 | + addMech(CKM_MD5_HMAC_GENERAL, "CKM_MD5_HMAC_GENERAL"); | |
| 669 | + addMech(CKM_SHA_1, "CKM_SHA_1"); | |
| 670 | + addMech(CKM_SHA_1_HMAC, "CKM_SHA_1_HMAC"); | |
| 671 | + addMech(CKM_SHA_1_HMAC_GENERAL, "CKM_SHA_1_HMAC_GENERAL"); | |
| 672 | + addMech(CKM_RIPEMD128, "CKM_RIPEMD128"); | |
| 673 | + addMech(CKM_RIPEMD128_HMAC, "CKM_RIPEMD128_HMAC"); | |
| 674 | + addMech(CKM_RIPEMD128_HMAC_GENERAL, "CKM_RIPEMD128_HMAC_GENERAL"); | |
| 675 | + addMech(CKM_RIPEMD160, "CKM_RIPEMD160"); | |
| 676 | + addMech(CKM_RIPEMD160_HMAC, "CKM_RIPEMD160_HMAC"); | |
| 677 | + addMech(CKM_RIPEMD160_HMAC_GENERAL, "CKM_RIPEMD160_HMAC_GENERAL"); | |
| 678 | + addMech(CKM_SHA256, "CKM_SHA256"); | |
| 679 | + addMech(CKM_SHA256_HMAC, "CKM_SHA256_HMAC"); | |
| 680 | + addMech(CKM_SHA256_HMAC_GENERAL, "CKM_SHA256_HMAC_GENERAL"); | |
| 681 | + addMech(CKM_SHA384, "CKM_SHA384"); | |
| 682 | + addMech(CKM_SHA384_HMAC, "CKM_SHA384_HMAC"); | |
| 683 | + addMech(CKM_SHA384_HMAC_GENERAL, "CKM_SHA384_HMAC_GENERAL"); | |
| 684 | + addMech(CKM_SHA512, "CKM_SHA512"); | |
| 685 | + addMech(CKM_SHA512_HMAC, "CKM_SHA512_HMAC"); | |
| 686 | + addMech(CKM_SHA512_HMAC_GENERAL, "CKM_SHA512_HMAC_GENERAL"); | |
| 687 | + addMech(CKM_CAST_KEY_GEN, "CKM_CAST_KEY_GEN"); | |
| 688 | + addMech(CKM_CAST_ECB, "CKM_CAST_ECB"); | |
| 689 | + addMech(CKM_CAST_CBC, "CKM_CAST_CBC"); | |
| 690 | + addMech(CKM_CAST_MAC, "CKM_CAST_MAC"); | |
| 691 | + addMech(CKM_CAST_MAC_GENERAL, "CKM_CAST_MAC_GENERAL"); | |
| 692 | + addMech(CKM_CAST_CBC_PAD, "CKM_CAST_CBC_PAD"); | |
| 693 | + addMech(CKM_CAST3_KEY_GEN, "CKM_CAST3_KEY_GEN"); | |
| 694 | + addMech(CKM_CAST3_ECB, "CKM_CAST3_ECB"); | |
| 695 | + addMech(CKM_CAST3_CBC, "CKM_CAST3_CBC"); | |
| 696 | + addMech(CKM_CAST3_MAC, "CKM_CAST3_MAC"); | |
| 697 | + addMech(CKM_CAST3_MAC_GENERAL, "CKM_CAST3_MAC_GENERAL"); | |
| 698 | + addMech(CKM_CAST3_CBC_PAD, "CKM_CAST3_CBC_PAD"); | |
| 699 | + addMech(CKM_CAST128_KEY_GEN, "CKM_CAST128_KEY_GEN"); | |
| 700 | + addMech(CKM_CAST128_ECB, "CKM_CAST128_ECB"); | |
| 701 | + addMech(CKM_CAST128_CBC, "CKM_CAST128_CBC"); | |
| 702 | + addMech(CKM_CAST128_MAC, "CKM_CAST128_MAC"); | |
| 703 | + addMech(CKM_CAST128_MAC_GENERAL, "CKM_CAST128_MAC_GENERAL"); | |
| 704 | + addMech(CKM_CAST128_CBC_PAD, "CKM_CAST128_CBC_PAD"); | |
| 705 | + addMech(CKM_RC5_KEY_GEN, "CKM_RC5_KEY_GEN"); | |
| 706 | + addMech(CKM_RC5_ECB, "CKM_RC5_ECB"); | |
| 707 | + addMech(CKM_RC5_CBC, "CKM_RC5_CBC"); | |
| 708 | + addMech(CKM_RC5_MAC, "CKM_RC5_MAC"); | |
| 709 | + addMech(CKM_RC5_MAC_GENERAL, "CKM_RC5_MAC_GENERAL"); | |
| 710 | + addMech(CKM_RC5_CBC_PAD, "CKM_RC5_CBC_PAD"); | |
| 711 | + addMech(CKM_IDEA_KEY_GEN, "CKM_IDEA_KEY_GEN"); | |
| 712 | + addMech(CKM_IDEA_ECB, "CKM_IDEA_ECB"); | |
| 713 | + addMech(CKM_IDEA_CBC, "CKM_IDEA_CBC"); | |
| 714 | + addMech(CKM_IDEA_MAC, "CKM_IDEA_MAC"); | |
| 715 | + addMech(CKM_IDEA_MAC_GENERAL, "CKM_IDEA_MAC_GENERAL"); | |
| 716 | + addMech(CKM_IDEA_CBC_PAD, "CKM_IDEA_CBC_PAD"); | |
| 717 | + addMech(CKM_GENERIC_SECRET_KEY_GEN, "CKM_GENERIC_SECRET_KEY_GEN"); | |
| 718 | + addMech(CKM_CONCATENATE_BASE_AND_KEY, "CKM_CONCATENATE_BASE_AND_KEY"); | |
| 719 | + addMech(CKM_CONCATENATE_BASE_AND_DATA, "CKM_CONCATENATE_BASE_AND_DATA"); | |
| 720 | + addMech(CKM_CONCATENATE_DATA_AND_BASE, "CKM_CONCATENATE_DATA_AND_BASE"); | |
| 721 | + addMech(CKM_XOR_BASE_AND_DATA, "CKM_XOR_BASE_AND_DATA"); | |
| 722 | + addMech(CKM_EXTRACT_KEY_FROM_KEY, "CKM_EXTRACT_KEY_FROM_KEY"); | |
| 723 | + addMech(CKM_SSL3_PRE_MASTER_KEY_GEN, "CKM_SSL3_PRE_MASTER_KEY_GEN"); | |
| 724 | + addMech(CKM_SSL3_MASTER_KEY_DERIVE, "CKM_SSL3_MASTER_KEY_DERIVE"); | |
| 725 | + addMech(CKM_SSL3_KEY_AND_MAC_DERIVE, "CKM_SSL3_KEY_AND_MAC_DERIVE"); | |
| 726 | + addMech(CKM_SSL3_MASTER_KEY_DERIVE_DH, "CKM_SSL3_MASTER_KEY_DERIVE_DH"); | |
| 727 | + addMech(CKM_TLS_PRE_MASTER_KEY_GEN, "CKM_TLS_PRE_MASTER_KEY_GEN"); | |
| 728 | + addMech(CKM_TLS_MASTER_KEY_DERIVE, "CKM_TLS_MASTER_KEY_DERIVE"); | |
| 729 | + addMech(CKM_TLS_KEY_AND_MAC_DERIVE, "CKM_TLS_KEY_AND_MAC_DERIVE"); | |
| 730 | + addMech(CKM_TLS_MASTER_KEY_DERIVE_DH, "CKM_TLS_MASTER_KEY_DERIVE_DH"); | |
| 731 | + addMech(CKM_TLS_PRF, "CKM_TLS_PRF"); | |
| 732 | + addMech(CKM_SSL3_MD5_MAC, "CKM_SSL3_MD5_MAC"); | |
| 733 | + addMech(CKM_SSL3_SHA1_MAC, "CKM_SSL3_SHA1_MAC"); | |
| 734 | + addMech(CKM_MD5_KEY_DERIVATION, "CKM_MD5_KEY_DERIVATION"); | |
| 735 | + addMech(CKM_MD2_KEY_DERIVATION, "CKM_MD2_KEY_DERIVATION"); | |
| 736 | + addMech(CKM_SHA1_KEY_DERIVATION, "CKM_SHA1_KEY_DERIVATION"); | |
| 737 | + addMech(CKM_SHA256_KEY_DERIVATION, "CKM_SHA256_KEY_DERIVATION"); | |
| 738 | + addMech(CKM_SHA384_KEY_DERIVATION, "CKM_SHA384_KEY_DERIVATION"); | |
| 739 | + addMech(CKM_SHA512_KEY_DERIVATION, "CKM_SHA512_KEY_DERIVATION"); | |
| 740 | + addMech(CKM_PBE_MD2_DES_CBC, "CKM_PBE_MD2_DES_CBC"); | |
| 741 | + addMech(CKM_PBE_MD5_DES_CBC, "CKM_PBE_MD5_DES_CBC"); | |
| 742 | + addMech(CKM_PBE_MD5_CAST_CBC, "CKM_PBE_MD5_CAST_CBC"); | |
| 743 | + addMech(CKM_PBE_MD5_CAST3_CBC, "CKM_PBE_MD5_CAST3_CBC"); | |
| 744 | + addMech(CKM_PBE_MD5_CAST128_CBC, "CKM_PBE_MD5_CAST128_CBC"); | |
| 745 | + addMech(CKM_PBE_SHA1_CAST128_CBC, "CKM_PBE_SHA1_CAST128_CBC"); | |
| 746 | + addMech(CKM_PBE_SHA1_RC4_128, "CKM_PBE_SHA1_RC4_128"); | |
| 747 | + addMech(CKM_PBE_SHA1_RC4_40, "CKM_PBE_SHA1_RC4_40"); | |
| 748 | + addMech(CKM_PBE_SHA1_DES3_EDE_CBC, "CKM_PBE_SHA1_DES3_EDE_CBC"); | |
| 749 | + addMech(CKM_PBE_SHA1_DES2_EDE_CBC, "CKM_PBE_SHA1_DES2_EDE_CBC"); | |
| 750 | + addMech(CKM_PBE_SHA1_RC2_128_CBC, "CKM_PBE_SHA1_RC2_128_CBC"); | |
| 751 | + addMech(CKM_PBE_SHA1_RC2_40_CBC, "CKM_PBE_SHA1_RC2_40_CBC"); | |
| 752 | + addMech(CKM_PKCS5_PBKD2, "CKM_PKCS5_PBKD2"); | |
| 753 | + addMech(CKM_PBA_SHA1_WITH_SHA1_HMAC, "CKM_PBA_SHA1_WITH_SHA1_HMAC"); | |
| 754 | + addMech(CKM_KEY_WRAP_LYNKS, "CKM_KEY_WRAP_LYNKS"); | |
| 755 | + addMech(CKM_KEY_WRAP_SET_OAEP, "CKM_KEY_WRAP_SET_OAEP"); | |
| 756 | + addMech(CKM_SKIPJACK_KEY_GEN, "CKM_SKIPJACK_KEY_GEN"); | |
| 757 | + addMech(CKM_SKIPJACK_ECB64, "CKM_SKIPJACK_ECB64"); | |
| 758 | + addMech(CKM_SKIPJACK_CBC64, "CKM_SKIPJACK_CBC64"); | |
| 759 | + addMech(CKM_SKIPJACK_OFB64, "CKM_SKIPJACK_OFB64"); | |
| 760 | + addMech(CKM_SKIPJACK_CFB64, "CKM_SKIPJACK_CFB64"); | |
| 761 | + addMech(CKM_SKIPJACK_CFB32, "CKM_SKIPJACK_CFB32"); | |
| 762 | + addMech(CKM_SKIPJACK_CFB16, "CKM_SKIPJACK_CFB16"); | |
| 763 | + addMech(CKM_SKIPJACK_CFB8, "CKM_SKIPJACK_CFB8"); | |
| 764 | + addMech(CKM_SKIPJACK_WRAP, "CKM_SKIPJACK_WRAP"); | |
| 765 | + addMech(CKM_SKIPJACK_PRIVATE_WRAP, "CKM_SKIPJACK_PRIVATE_WRAP"); | |
| 766 | + addMech(CKM_SKIPJACK_RELAYX, "CKM_SKIPJACK_RELAYX"); | |
| 767 | + addMech(CKM_KEA_KEY_PAIR_GEN, "CKM_KEA_KEY_PAIR_GEN"); | |
| 768 | + addMech(CKM_KEA_KEY_DERIVE, "CKM_KEA_KEY_DERIVE"); | |
| 769 | + addMech(CKM_FORTEZZA_TIMESTAMP, "CKM_FORTEZZA_TIMESTAMP"); | |
| 770 | + addMech(CKM_BATON_KEY_GEN, "CKM_BATON_KEY_GEN"); | |
| 771 | + addMech(CKM_BATON_ECB128, "CKM_BATON_ECB128"); | |
| 772 | + addMech(CKM_BATON_ECB96, "CKM_BATON_ECB96"); | |
| 773 | + addMech(CKM_BATON_CBC128, "CKM_BATON_CBC128"); | |
| 774 | + addMech(CKM_BATON_COUNTER, "CKM_BATON_COUNTER"); | |
| 775 | + addMech(CKM_BATON_SHUFFLE, "CKM_BATON_SHUFFLE"); | |
| 776 | + addMech(CKM_BATON_WRAP, "CKM_BATON_WRAP"); | |
| 777 | + addMech(CKM_EC_KEY_PAIR_GEN, "CKM_EC_KEY_PAIR_GEN"); | |
| 778 | + addMech(CKM_ECDSA, "CKM_ECDSA"); | |
| 779 | + addMech(CKM_ECDSA_SHA1, "CKM_ECDSA_SHA1"); | |
| 780 | + addMech(CKM_ECDH1_DERIVE, "CKM_ECDH1_DERIVE"); | |
| 781 | + addMech(CKM_ECDH1_COFACTOR_DERIVE, "CKM_ECDH1_COFACTOR_DERIVE"); | |
| 782 | + addMech(CKM_ECMQV_DERIVE, "CKM_ECMQV_DERIVE"); | |
| 783 | + addMech(CKM_JUNIPER_KEY_GEN, "CKM_JUNIPER_KEY_GEN"); | |
| 784 | + addMech(CKM_JUNIPER_ECB128, "CKM_JUNIPER_ECB128"); | |
| 785 | + addMech(CKM_JUNIPER_CBC128, "CKM_JUNIPER_CBC128"); | |
| 786 | + addMech(CKM_JUNIPER_COUNTER, "CKM_JUNIPER_COUNTER"); | |
| 787 | + addMech(CKM_JUNIPER_SHUFFLE, "CKM_JUNIPER_SHUFFLE"); | |
| 788 | + addMech(CKM_JUNIPER_WRAP, "CKM_JUNIPER_WRAP"); | |
| 789 | + addMech(CKM_FASTHASH, "CKM_FASTHASH"); | |
| 790 | + addMech(CKM_AES_KEY_GEN, "CKM_AES_KEY_GEN"); | |
| 791 | + addMech(CKM_AES_ECB, "CKM_AES_ECB"); | |
| 792 | + addMech(CKM_AES_CBC, "CKM_AES_CBC"); | |
| 793 | + addMech(CKM_AES_MAC, "CKM_AES_MAC"); | |
| 794 | + addMech(CKM_AES_MAC_GENERAL, "CKM_AES_MAC_GENERAL"); | |
| 795 | + addMech(CKM_AES_CBC_PAD, "CKM_AES_CBC_PAD"); | |
| 796 | + addMech(CKM_BLOWFISH_KEY_GEN, "CKM_BLOWFISH_KEY_GEN"); | |
| 797 | + addMech(CKM_BLOWFISH_CBC, "CKM_BLOWFISH_CBC"); | |
| 798 | + addMech(CKM_DSA_PARAMETER_GEN, "CKM_DSA_PARAMETER_GEN"); | |
| 799 | + addMech(CKM_DH_PKCS_PARAMETER_GEN, "CKM_DH_PKCS_PARAMETER_GEN"); | |
| 800 | + addMech(CKM_X9_42_DH_PARAMETER_GEN, "CKM_X9_42_DH_PARAMETER_GEN"); | |
| 801 | + addMech(CKM_VENDOR_DEFINED, "CKM_VENDOR_DEFINED"); | |
| 802 | + | |
| 803 | + addMech(CKM_NSS_TLS_PRF_GENERAL, "CKM_NSS_TLS_PRF_GENERAL"); | |
| 804 | + | |
| 805 | + addMech(PCKM_SECURERANDOM, "SecureRandom"); | |
| 806 | + addMech(PCKM_KEYSTORE, "KeyStore"); | |
| 807 | + | |
| 808 | + addKeyType(CKK_RSA, "CKK_RSA"); | |
| 809 | + addKeyType(CKK_DSA, "CKK_DSA"); | |
| 810 | + addKeyType(CKK_DH, "CKK_DH"); | |
| 811 | + addKeyType(CKK_EC, "CKK_EC"); | |
| 812 | + addKeyType(CKK_X9_42_DH, "CKK_X9_42_DH"); | |
| 813 | + addKeyType(CKK_KEA, "CKK_KEA"); | |
| 814 | + addKeyType(CKK_GENERIC_SECRET, "CKK_GENERIC_SECRET"); | |
| 815 | + addKeyType(CKK_RC2, "CKK_RC2"); | |
| 816 | + addKeyType(CKK_RC4, "CKK_RC4"); | |
| 817 | + addKeyType(CKK_DES, "CKK_DES"); | |
| 818 | + addKeyType(CKK_DES2, "CKK_DES2"); | |
| 819 | + addKeyType(CKK_DES3, "CKK_DES3"); | |
| 820 | + addKeyType(CKK_CAST, "CKK_CAST"); | |
| 821 | + addKeyType(CKK_CAST3, "CKK_CAST3"); | |
| 822 | + addKeyType(CKK_CAST128, "CKK_CAST128"); | |
| 823 | + addKeyType(CKK_RC5, "CKK_RC5"); | |
| 824 | + addKeyType(CKK_IDEA, "CKK_IDEA"); | |
| 825 | + addKeyType(CKK_SKIPJACK, "CKK_SKIPJACK"); | |
| 826 | + addKeyType(CKK_BATON, "CKK_BATON"); | |
| 827 | + addKeyType(CKK_JUNIPER, "CKK_JUNIPER"); | |
| 828 | + addKeyType(CKK_CDMF, "CKK_CDMF"); | |
| 829 | + addKeyType(CKK_AES, "CKK_AES"); | |
| 830 | + addKeyType(CKK_BLOWFISH, "CKK_BLOWFISH"); | |
| 831 | + addKeyType(CKK_VENDOR_DEFINED, "CKK_VENDOR_DEFINED"); | |
| 832 | + | |
| 833 | + addKeyType(PCKK_ANY, "*"); | |
| 834 | + | |
| 835 | + addAttribute(CKA_CLASS, "CKA_CLASS"); | |
| 836 | + addAttribute(CKA_TOKEN, "CKA_TOKEN"); | |
| 837 | + addAttribute(CKA_PRIVATE, "CKA_PRIVATE"); | |
| 838 | + addAttribute(CKA_LABEL, "CKA_LABEL"); | |
| 839 | + addAttribute(CKA_APPLICATION, "CKA_APPLICATION"); | |
| 840 | + addAttribute(CKA_VALUE, "CKA_VALUE"); | |
| 841 | + addAttribute(CKA_OBJECT_ID, "CKA_OBJECT_ID"); | |
| 842 | + addAttribute(CKA_CERTIFICATE_TYPE, "CKA_CERTIFICATE_TYPE"); | |
| 843 | + addAttribute(CKA_ISSUER, "CKA_ISSUER"); | |
| 844 | + addAttribute(CKA_SERIAL_NUMBER, "CKA_SERIAL_NUMBER"); | |
| 845 | + addAttribute(CKA_AC_ISSUER, "CKA_AC_ISSUER"); | |
| 846 | + addAttribute(CKA_OWNER, "CKA_OWNER"); | |
| 847 | + addAttribute(CKA_ATTR_TYPES, "CKA_ATTR_TYPES"); | |
| 848 | + addAttribute(CKA_TRUSTED, "CKA_TRUSTED"); | |
| 849 | + addAttribute(CKA_KEY_TYPE, "CKA_KEY_TYPE"); | |
| 850 | + addAttribute(CKA_SUBJECT, "CKA_SUBJECT"); | |
| 851 | + addAttribute(CKA_ID, "CKA_ID"); | |
| 852 | + addAttribute(CKA_SENSITIVE, "CKA_SENSITIVE"); | |
| 853 | + addAttribute(CKA_ENCRYPT, "CKA_ENCRYPT"); | |
| 854 | + addAttribute(CKA_DECRYPT, "CKA_DECRYPT"); | |
| 855 | + addAttribute(CKA_WRAP, "CKA_WRAP"); | |
| 856 | + addAttribute(CKA_UNWRAP, "CKA_UNWRAP"); | |
| 857 | + addAttribute(CKA_SIGN, "CKA_SIGN"); | |
| 858 | + addAttribute(CKA_SIGN_RECOVER, "CKA_SIGN_RECOVER"); | |
| 859 | + addAttribute(CKA_VERIFY, "CKA_VERIFY"); | |
| 860 | + addAttribute(CKA_VERIFY_RECOVER, "CKA_VERIFY_RECOVER"); | |
| 861 | + addAttribute(CKA_DERIVE, "CKA_DERIVE"); | |
| 862 | + addAttribute(CKA_START_DATE, "CKA_START_DATE"); | |
| 863 | + addAttribute(CKA_END_DATE, "CKA_END_DATE"); | |
| 864 | + addAttribute(CKA_MODULUS, "CKA_MODULUS"); | |
| 865 | + addAttribute(CKA_MODULUS_BITS, "CKA_MODULUS_BITS"); | |
| 866 | + addAttribute(CKA_PUBLIC_EXPONENT, "CKA_PUBLIC_EXPONENT"); | |
| 867 | + addAttribute(CKA_PRIVATE_EXPONENT, "CKA_PRIVATE_EXPONENT"); | |
| 868 | + addAttribute(CKA_PRIME_1, "CKA_PRIME_1"); | |
| 869 | + addAttribute(CKA_PRIME_2, "CKA_PRIME_2"); | |
| 870 | + addAttribute(CKA_EXPONENT_1, "CKA_EXPONENT_1"); | |
| 871 | + addAttribute(CKA_EXPONENT_2, "CKA_EXPONENT_2"); | |
| 872 | + addAttribute(CKA_COEFFICIENT, "CKA_COEFFICIENT"); | |
| 873 | + addAttribute(CKA_PRIME, "CKA_PRIME"); | |
| 874 | + addAttribute(CKA_SUBPRIME, "CKA_SUBPRIME"); | |
| 875 | + addAttribute(CKA_BASE, "CKA_BASE"); | |
| 876 | + addAttribute(CKA_PRIME_BITS, "CKA_PRIME_BITS"); | |
| 877 | + addAttribute(CKA_SUB_PRIME_BITS, "CKA_SUB_PRIME_BITS"); | |
| 878 | + addAttribute(CKA_VALUE_BITS, "CKA_VALUE_BITS"); | |
| 879 | + addAttribute(CKA_VALUE_LEN, "CKA_VALUE_LEN"); | |
| 880 | + addAttribute(CKA_EXTRACTABLE, "CKA_EXTRACTABLE"); | |
| 881 | + addAttribute(CKA_LOCAL, "CKA_LOCAL"); | |
| 882 | + addAttribute(CKA_NEVER_EXTRACTABLE, "CKA_NEVER_EXTRACTABLE"); | |
| 883 | + addAttribute(CKA_ALWAYS_SENSITIVE, "CKA_ALWAYS_SENSITIVE"); | |
| 884 | + addAttribute(CKA_KEY_GEN_MECHANISM, "CKA_KEY_GEN_MECHANISM"); | |
| 885 | + addAttribute(CKA_MODIFIABLE, "CKA_MODIFIABLE"); | |
| 886 | + addAttribute(CKA_EC_PARAMS, "CKA_EC_PARAMS"); | |
| 887 | + addAttribute(CKA_EC_POINT, "CKA_EC_POINT"); | |
| 888 | + addAttribute(CKA_SECONDARY_AUTH, "CKA_SECONDARY_AUTH"); | |
| 889 | + addAttribute(CKA_AUTH_PIN_FLAGS, "CKA_AUTH_PIN_FLAGS"); | |
| 890 | + addAttribute(CKA_HW_FEATURE_TYPE, "CKA_HW_FEATURE_TYPE"); | |
| 891 | + addAttribute(CKA_RESET_ON_INIT, "CKA_RESET_ON_INIT"); | |
| 892 | + addAttribute(CKA_HAS_RESET, "CKA_HAS_RESET"); | |
| 893 | + addAttribute(CKA_VENDOR_DEFINED, "CKA_VENDOR_DEFINED"); | |
| 894 | + addAttribute(CKA_NETSCAPE_DB, "CKA_NETSCAPE_DB"); | |
| 895 | + | |
| 896 | + addAttribute(CKA_NETSCAPE_TRUST_SERVER_AUTH, "CKA_NETSCAPE_TRUST_SERVER_AUTH"); | |
| 897 | + addAttribute(CKA_NETSCAPE_TRUST_CLIENT_AUTH, "CKA_NETSCAPE_TRUST_CLIENT_AUTH"); | |
| 898 | + addAttribute(CKA_NETSCAPE_TRUST_CODE_SIGNING, "CKA_NETSCAPE_TRUST_CODE_SIGNING"); | |
| 899 | + addAttribute(CKA_NETSCAPE_TRUST_EMAIL_PROTECTION, "CKA_NETSCAPE_TRUST_EMAIL_PROTECTION"); | |
| 900 | + addAttribute(CKA_NETSCAPE_CERT_SHA1_HASH, "CKA_NETSCAPE_CERT_SHA1_HASH"); | |
| 901 | + addAttribute(CKA_NETSCAPE_CERT_MD5_HASH, "CKA_NETSCAPE_CERT_MD5_HASH"); | |
| 902 | + | |
| 903 | + addObjectClass(CKO_DATA, "CKO_DATA"); | |
| 904 | + addObjectClass(CKO_CERTIFICATE, "CKO_CERTIFICATE"); | |
| 905 | + addObjectClass(CKO_PUBLIC_KEY, "CKO_PUBLIC_KEY"); | |
| 906 | + addObjectClass(CKO_PRIVATE_KEY, "CKO_PRIVATE_KEY"); | |
| 907 | + addObjectClass(CKO_SECRET_KEY, "CKO_SECRET_KEY"); | |
| 908 | + addObjectClass(CKO_HW_FEATURE, "CKO_HW_FEATURE"); | |
| 909 | + addObjectClass(CKO_DOMAIN_PARAMETERS, "CKO_DOMAIN_PARAMETERS"); | |
| 910 | + addObjectClass(CKO_VENDOR_DEFINED, "CKO_VENDOR_DEFINED"); | |
| 911 | + | |
| 912 | + addObjectClass(PCKO_ANY, "*"); | |
| 913 | + | |
| 914 | + } | |
| 915 | + | |
| 916 | +} | |