1 package iaik.pkcs.pkcs11.wrapper;
2 
3 import java.math.BigInteger;
4 import java.util.Hashtable;
5 
6 /**
7  * This class contains onyl static methods. It is the place for all functions
8  * that are used by several classes in this package.
9  *
10  * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
11  * @author Martin Schl�ffer <schlaeff@sbox.tugraz.at>
12  */
13 public class Functions {
14 
15 	/**
16 	 * Maps mechanism codes as Long to their names as Strings.
17 	 */
18 	protected static Hashtable mechansimNames_;
19 
20 	/**
21 	 * This table contains the mechanisms that are full encrypt/decrypt
22 	 * mechanisms; i.e. mechanisms that support the update functoins.
23 	 * The Long values of the mechanisms are the keys, and the mechanism
24 	 * names are the values.
25 	 */
26 	protected static Hashtable fullEncryptDecryptMechanisms_;
27 
28 	/**
29 	 * This table contains the mechanisms that are single-operation
30 	 * encrypt/decrypt mechanisms; i.e. mechanisms that do not support the update
31 	 * functoins.
32 	 * The Long values of the mechanisms are the keys, and the mechanism
33 	 * names are the values.
34 	 */
35 	protected static Hashtable singleOperationEncryptDecryptMechanisms_;
36 
37 	/**
38 	 * This table contains the mechanisms that are full sign/verify
39 	 * mechanisms; i.e. mechanisms that support the update functoins.
40 	 * The Long values of the mechanisms are the keys, and the mechanism
41 	 * names are the values.
42 	 */
43 	protected static Hashtable fullSignVerifyMechanisms_;
44 
45 	/**
46 	 * This table contains the mechanisms that are single-operation
47 	 * sign/verify mechanisms; i.e. mechanisms that do not support the update
48 	 * functoins.
49 	 * The Long values of the mechanisms are the keys, and the mechanism
50 	 * names are the values.
51 	 */
52 	protected static Hashtable singleOperationSignVerifyMechanisms_;
53 
54 	/**
55 	 * This table contains the mechanisms that are sign/verify mechanisms with
56 	 * message recovery.
57 	 * The Long values of the mechanisms are the keys, and the mechanism
58 	 * names are the values.
59 	 */
60 	protected static Hashtable signVerifyRecoverMechanisms_;
61 
62 	/**
63 	 * This table contains the mechanisms that are digest mechanisms.
64 	 * The Long values of the mechanisms are the keys, and the mechanism
65 	 * names are the values.
66 	 */
67 	protected static Hashtable digestMechanisms_;
68 
69 	/**
70 	 * This table contains the mechanisms that key generation mechanisms; i.e.
71 	 * mechanisms for generating symmetric keys.
72 	 * The Long values of the mechanisms are the keys, and the mechanism
73 	 * names are the values.
74 	 */
75 	protected static Hashtable keyGenerationMechanisms_;
76 
77 	/**
78 	 * This table contains the mechanisms that key-pair generation mechanisms;
79 	 * i.e. mechanisms for generating key-pairs.
80 	 * The Long values of the mechanisms are the keys, and the mechanism
81 	 * names are the values.
82 	 */
83 	protected static Hashtable keyPairGenerationMechanisms_;
84 
85 	/**
86 	 * This table contains the mechanisms that are wrap/unwrap mechanisms.
87 	 * The Long values of the mechanisms are the keys, and the mechanism
88 	 * names are the values.
89 	 */
90 	protected static Hashtable wrapUnwrapMechanisms_;
91 
92 	/**
93 	 * This table contains the mechanisms that are key derivation mechanisms.
94 	 * The Long values of the mechanisms are the keys, and the mechanism
95 	 * names are the values.
96 	 */
97 	protected static Hashtable keyDerivationMechanisms_;
98 
99 	/**
100 	 * For converting numbers to their hex presentation.
101 	 */
102 	protected static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7',
103 	    '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
104 
105 	/**
106 	 * Converts a long value to a hexadecimal String of length 16. Includes
107 	 * leading zeros if necessary.
108 	 *
109 	 * @param value The long value to be converted.
110 	 * @return The hexadecimal string representation of the long value.
111 	 */
toFullHexString(long value)112 	public static String toFullHexString(long value) {
113 		long currentValue = value;
114 		StringBuffer stringBuffer = new StringBuffer(16);
115 		for (int j = 0; j < 16; j++) {
116 			int currentDigit = (int) currentValue & 0xf;
117 			stringBuffer.append(HEX_DIGITS[currentDigit]);
118 			currentValue >>>= 4;
119 		}
120 
121 		return stringBuffer.reverse().toString();
122 	}
123 
124 	/**
125 	 * Converts a int value to a hexadecimal String of length 8. Includes
126 	 * leading zeros if necessary.
127 	 *
128 	 * @param value The int value to be converted.
129 	 * @return The hexadecimal string representation of the int value.
130 	 */
toFullHexString(int value)131 	public static String toFullHexString(int value) {
132 		int currentValue = value;
133 		StringBuffer stringBuffer = new StringBuffer(8);
134 		for (int i = 0; i < 8; i++) {
135 			int currentDigit = currentValue & 0xf;
136 			stringBuffer.append(HEX_DIGITS[currentDigit]);
137 			currentValue >>>= 4;
138 		}
139 
140 		return stringBuffer.reverse().toString();
141 	}
142 
143 	/**
144 	 * Converts a long value to a hexadecimal String.
145 	 *
146 	 * @param value The long value to be converted.
147 	 * @return The hexadecimal string representation of the long value.
148 	 */
toHexString(long value)149 	public static String toHexString(long value) {
150 		return Long.toHexString(value);
151 	}
152 
153 	/**
154 	 * Converts a byte array to a hexadecimal String. Each byte is presented by
155 	 * its two digit hex-code; 0x0A -> "0a", 0x00 -> "00". No leading "0x" is
156 	 * included in the result.
157 	 *
158 	 * @param value the byte array to be converted
159 	 * @return the hexadecimal string representation of the byte array
160 	 */
toHexString(byte[] value)161 	public static String toHexString(byte[] value) {
162 		if (value == null) {
163 			return null;
164 		}
165 
166 		StringBuffer buffer = new StringBuffer(2 * value.length);
167 		int single;
168 
169 		for (int i = 0; i < value.length; i++) {
170 			single = value[i] & 0xFF;
171 
172 			if (single < 0x10) {
173 				buffer.append('0');
174 			}
175 
176 			buffer.append(Integer.toString(single, 16));
177 		}
178 
179 		return buffer.toString();
180 	}
181 
182 	/**
183 	 * Converts a long value to a binary String.
184 	 *
185 	 * @param value the long value to be converted.
186 	 * @return the binary string representation of the long value.
187 	 */
toBinaryString(long value)188 	public static String toBinaryString(long value) {
189 		return Long.toString(value, 2);
190 	}
191 
192 	/**
193 	 * Converts a byte array to a binary String.
194 	 *
195 	 * @param value The byte array to be converted.
196 	 * @return The binary string representation of the byte array.
197 	 */
toBinaryString(byte[] value)198 	public static String toBinaryString(byte[] value) {
199 		BigInteger helpBigInteger = new BigInteger(1, value);
200 
201 		return helpBigInteger.toString(2);
202 	}
203 
204 	/**
205 	 * Converts the long value flags to a SlotInfoFlag string.
206 	 *
207 	 * @param flags The flags to be converted.
208 	 * @return The SlotInfoFlag string representation of the flags.
209 	 */
slotInfoFlagsToString(long flags)210 	public static String slotInfoFlagsToString(long flags) {
211 		StringBuffer buffer = new StringBuffer();
212 		boolean notFirst = false;
213 
214 		if ((flags & PKCS11Constants.CKF_TOKEN_PRESENT) != 0L) {
215 			buffer.append("CKF_TOKEN_PRESENT");
216 
217 			notFirst = true;
218 		}
219 
220 		if ((flags & PKCS11Constants.CKF_REMOVABLE_DEVICE) != 0L) {
221 			if (notFirst) {
222 				buffer.append(" | ");
223 			}
224 
225 			buffer.append("CKF_TOKEN_PRESENT");
226 
227 			notFirst = true;
228 		}
229 
230 		if ((flags & PKCS11Constants.CKF_HW_SLOT) != 0L) {
231 			if (notFirst) {
232 				buffer.append(" | ");
233 			}
234 
235 			buffer.append("CKF_HW_SLOT");
236 		}
237 
238 		return buffer.toString();
239 	}
240 
241 	/**
242 	 * Converts long value flags to a TokenInfoFlag string.
243 	 *
244 	 * @param flags The flags to be converted.
245 	 * @return The TokenInfoFlag string representation of the flags.
246 	 */
tokenInfoFlagsToString(long flags)247 	public static String tokenInfoFlagsToString(long flags) {
248 		StringBuffer buffer = new StringBuffer();
249 		boolean notFirst = false;
250 
251 		if ((flags & PKCS11Constants.CKF_RNG) != 0L) {
252 			buffer.append("CKF_RNG");
253 
254 			notFirst = true;
255 		}
256 
257 		if ((flags & PKCS11Constants.CKF_WRITE_PROTECTED) != 0L) {
258 			if (notFirst) {
259 				buffer.append(" | ");
260 			}
261 
262 			buffer.append("CKF_WRITE_PROTECTED");
263 
264 			notFirst = true;
265 		}
266 
267 		if ((flags & PKCS11Constants.CKF_LOGIN_REQUIRED) != 0L) {
268 			if (notFirst) {
269 				buffer.append(" | ");
270 			}
271 
272 			buffer.append("CKF_LOGIN_REQUIRED");
273 
274 			notFirst = true;
275 		}
276 
277 		if ((flags & PKCS11Constants.CKF_USER_PIN_INITIALIZED) != 0L) {
278 			if (notFirst) {
279 				buffer.append(" | ");
280 			}
281 
282 			buffer.append("CKF_USER_PIN_INITIALIZED");
283 
284 			notFirst = true;
285 		}
286 
287 		if ((flags & PKCS11Constants.CKF_RESTORE_KEY_NOT_NEEDED) != 0L) {
288 			if (notFirst) {
289 				buffer.append(" | ");
290 			}
291 
292 			buffer.append("CKF_RESTORE_KEY_NOT_NEEDED");
293 
294 			notFirst = true;
295 		}
296 
297 		if ((flags & PKCS11Constants.CKF_CLOCK_ON_TOKEN) != 0L) {
298 			if (notFirst) {
299 				buffer.append(" | ");
300 			}
301 
302 			buffer.append("CKF_CLOCK_ON_TOKEN");
303 
304 			notFirst = true;
305 		}
306 
307 		if ((flags & PKCS11Constants.CKF_PROTECTED_AUTHENTICATION_PATH) != 0L) {
308 			if (notFirst) {
309 				buffer.append(" | ");
310 			}
311 
312 			buffer.append("CKF_PROTECTED_AUTHENTICATION_PATH");
313 
314 			notFirst = true;
315 		}
316 
317 		if ((flags & PKCS11Constants.CKF_DUAL_CRYPTO_OPERATIONS) != 0L) {
318 			if (notFirst) {
319 				buffer.append(" | ");
320 			}
321 
322 			buffer.append("CKF_DUAL_CRYPTO_OPERATIONS");
323 
324 			notFirst = true;
325 		}
326 
327 		if ((flags & PKCS11Constants.CKF_TOKEN_INITIALIZED) != 0L) {
328 			if (notFirst) {
329 				buffer.append(" | ");
330 			}
331 
332 			buffer.append("CKF_TOKEN_INITIALIZED");
333 
334 			notFirst = true;
335 		}
336 
337 		if ((flags & PKCS11Constants.CKF_SECONDARY_AUTHENTICATION) != 0L) {
338 			if (notFirst) {
339 				buffer.append(" | ");
340 			}
341 
342 			buffer.append("CKF_SECONDARY_AUTHENTICATION");
343 
344 			notFirst = true;
345 		}
346 
347 		if ((flags & PKCS11Constants.CKF_USER_PIN_COUNT_LOW) != 0L) {
348 			if (notFirst) {
349 				buffer.append(" | ");
350 			}
351 
352 			buffer.append("CKF_USER_PIN_COUNT_LOW");
353 
354 			notFirst = true;
355 		}
356 
357 		if ((flags & PKCS11Constants.CKF_USER_PIN_FINAL_TRY) != 0L) {
358 			if (notFirst) {
359 				buffer.append(" | ");
360 			}
361 
362 			buffer.append("CKF_USER_PIN_FINAL_TRY");
363 
364 			notFirst = true;
365 		}
366 
367 		if ((flags & PKCS11Constants.CKF_USER_PIN_LOCKED) != 0L) {
368 			if (notFirst) {
369 				buffer.append(" | ");
370 			}
371 
372 			buffer.append("CKF_USER_PIN_LOCKED");
373 
374 			notFirst = true;
375 		}
376 
377 		if ((flags & PKCS11Constants.CKF_USER_PIN_TO_BE_CHANGED) != 0L) {
378 			if (notFirst) {
379 				buffer.append(" | ");
380 			}
381 
382 			buffer.append("CKF_USER_PIN_TO_BE_CHANGED");
383 
384 			notFirst = true;
385 		}
386 
387 		if ((flags & PKCS11Constants.CKF_SO_PIN_COUNT_LOW) != 0L) {
388 			if (notFirst) {
389 				buffer.append(" | ");
390 			}
391 
392 			buffer.append("CKF_SO_PIN_COUNT_LOW");
393 
394 			notFirst = true;
395 		}
396 
397 		if ((flags & PKCS11Constants.CKF_SO_PIN_FINAL_TRY) != 0L) {
398 			if (notFirst) {
399 				buffer.append(" | ");
400 			}
401 
402 			buffer.append("CKF_SO_PIN_FINAL_TRY");
403 
404 			notFirst = true;
405 		}
406 
407 		if ((flags & PKCS11Constants.CKF_SO_PIN_LOCKED) != 0L) {
408 			if (notFirst) {
409 				buffer.append(" | ");
410 			}
411 
412 			buffer.append("CKF_USER_PIN_FINAL_TRY");
413 
414 			notFirst = true;
415 		}
416 
417 		if ((flags & PKCS11Constants.CKF_SO_PIN_TO_BE_CHANGED) != 0L) {
418 			if (notFirst) {
419 				buffer.append(" | ");
420 			}
421 
422 			buffer.append("CKF_USER_PIN_LOCKED");
423 
424 			notFirst = true;
425 		}
426 
427 		return buffer.toString();
428 	}
429 
430 	/**
431 	 * Converts the long value flags to a SessionInfoFlag string.
432 	 *
433 	 * @param flags The flags to be converted.
434 	 * @return The SessionInfoFlag string representation of the flags.
435 	 */
sessionInfoFlagsToString(long flags)436 	public static String sessionInfoFlagsToString(long flags) {
437 		StringBuffer buffer = new StringBuffer();
438 		boolean notFirst = false;
439 
440 		if ((flags & PKCS11Constants.CKF_RW_SESSION) != 0L) {
441 			buffer.append("CKF_RW_SESSION");
442 
443 			notFirst = true;
444 		}
445 
446 		if ((flags & PKCS11Constants.CKF_SERIAL_SESSION) != 0L) {
447 			if (notFirst) {
448 				buffer.append(" | ");
449 			}
450 
451 			buffer.append("CKF_SERIAL_SESSION");
452 		}
453 
454 		return buffer.toString();
455 	}
456 
457 	/**
458 	 * Converts the long value state to a SessionState string.
459 	 *
460 	 * @param state The state to be converted.
461 	 * @return The SessionState string representation of the state.
462 	 */
sessionStateToString(long state)463 	public static String sessionStateToString(long state) {
464 		String name;
465 
466 		if (state == PKCS11Constants.CKS_RO_PUBLIC_SESSION) {
467 			name = "CKS_RO_PUBLIC_SESSION";
468 		} else if (state == PKCS11Constants.CKS_RO_USER_FUNCTIONS) {
469 			name = "CKS_RO_USER_FUNCTIONS";
470 		} else if (state == PKCS11Constants.CKS_RW_PUBLIC_SESSION) {
471 			name = "CKS_RW_PUBLIC_SESSION";
472 		} else if (state == PKCS11Constants.CKS_RW_USER_FUNCTIONS) {
473 			name = "CKS_RW_USER_FUNCTIONS";
474 		} else if (state == PKCS11Constants.CKS_RW_SO_FUNCTIONS) {
475 			name = "CKS_RW_SO_FUNCTIONS";
476 		} else {
477 			name = "ERROR: unknown session state 0x" + toFullHexString(state);
478 		}
479 
480 		return name;
481 	}
482 
483 	/**
484 	 * Converts the long value flags to a MechanismInfoFlag string.
485 	 *
486 	 * @param flags The flags to be converted to a string representation.
487 	 * @return The MechanismInfoFlag string representation of the flags.
488 	 */
mechanismInfoFlagsToString(long flags)489 	public static String mechanismInfoFlagsToString(long flags) {
490 		StringBuffer buffer = new StringBuffer();
491 		boolean notFirst = false;
492 
493 		if ((flags & PKCS11Constants.CKF_HW) != 0L) {
494 			buffer.append("CKF_HW");
495 
496 			notFirst = true;
497 		}
498 
499 		if ((flags & PKCS11Constants.CKF_ENCRYPT) != 0L) {
500 			if (notFirst) {
501 				buffer.append(" | ");
502 			}
503 
504 			buffer.append("CKF_ENCRYPT");
505 
506 			notFirst = true;
507 		}
508 
509 		if ((flags & PKCS11Constants.CKF_DECRYPT) != 0L) {
510 			if (notFirst) {
511 				buffer.append(" | ");
512 			}
513 
514 			buffer.append("CKF_DECRYPT");
515 
516 			notFirst = true;
517 		}
518 
519 		if ((flags & PKCS11Constants.CKF_DIGEST) != 0L) {
520 			if (notFirst) {
521 				buffer.append(" | ");
522 			}
523 
524 			buffer.append("CKF_DIGEST");
525 
526 			notFirst = true;
527 		}
528 
529 		if ((flags & PKCS11Constants.CKF_SIGN) != 0L) {
530 			if (notFirst) {
531 				buffer.append(" | ");
532 			}
533 
534 			buffer.append("CKF_SIGN");
535 
536 			notFirst = true;
537 		}
538 
539 		if ((flags & PKCS11Constants.CKF_SIGN_RECOVER) != 0L) {
540 			if (notFirst) {
541 				buffer.append(" | ");
542 			}
543 
544 			buffer.append("CKF_SIGN_RECOVER");
545 
546 			notFirst = true;
547 		}
548 
549 		if ((flags & PKCS11Constants.CKF_VERIFY) != 0L) {
550 			if (notFirst) {
551 				buffer.append(" | ");
552 			}
553 
554 			buffer.append("CKF_VERIFY");
555 
556 			notFirst = true;
557 		}
558 
559 		if ((flags & PKCS11Constants.CKF_VERIFY_RECOVER) != 0L) {
560 			if (notFirst) {
561 				buffer.append(" | ");
562 			}
563 
564 			buffer.append("CKF_VERIFY_RECOVER");
565 
566 			notFirst = true;
567 		}
568 
569 		if ((flags & PKCS11Constants.CKF_GENERATE) != 0L) {
570 			if (notFirst) {
571 				buffer.append(" | ");
572 			}
573 
574 			buffer.append("CKF_GENERATE");
575 
576 			notFirst = true;
577 		}
578 
579 		if ((flags & PKCS11Constants.CKF_GENERATE_KEY_PAIR) != 0L) {
580 			if (notFirst) {
581 				buffer.append(" | ");
582 			}
583 
584 			buffer.append("CKF_GENERATE_KEY_PAIR");
585 
586 			notFirst = true;
587 		}
588 
589 		if ((flags & PKCS11Constants.CKF_WRAP) != 0L) {
590 			if (notFirst) {
591 				buffer.append(" | ");
592 			}
593 
594 			buffer.append("CKF_WRAP");
595 
596 			notFirst = true;
597 		}
598 
599 		if ((flags & PKCS11Constants.CKF_UNWRAP) != 0L) {
600 			if (notFirst) {
601 				buffer.append(" | ");
602 			}
603 
604 			buffer.append("CKF_UNWRAP");
605 
606 			notFirst = true;
607 		}
608 
609 		if ((flags & PKCS11Constants.CKF_DERIVE) != 0L) {
610 			if (notFirst) {
611 				buffer.append(" | ");
612 			}
613 
614 			buffer.append("CKF_DERIVE");
615 
616 			notFirst = true;
617 		}
618 
619 		if ((flags & PKCS11Constants.CKF_EC_F_P) != 0L) {
620 			if (notFirst) {
621 				buffer.append(" | ");
622 			}
623 
624 			buffer.append("CKF_EC_F_P");
625 
626 			notFirst = true;
627 		}
628 
629 		if ((flags & PKCS11Constants.CKF_EC_F_2M) != 0L) {
630 			if (notFirst) {
631 				buffer.append(" | ");
632 			}
633 
634 			buffer.append("CKF_EC_F_2M");
635 
636 			notFirst = true;
637 		}
638 
639 		if ((flags & PKCS11Constants.CKF_EC_ECPARAMETERS) != 0L) {
640 			if (notFirst) {
641 				buffer.append(" | ");
642 			}
643 
644 			buffer.append("CKF_EC_ECPARAMETERS");
645 
646 			notFirst = true;
647 		}
648 
649 		if ((flags & PKCS11Constants.CKF_EC_NAMEDCURVE) != 0L) {
650 			if (notFirst) {
651 				buffer.append(" | ");
652 			}
653 
654 			buffer.append("CKF_EC_NAMEDCURVE");
655 
656 			notFirst = true;
657 		}
658 
659 		if ((flags & PKCS11Constants.CKF_EC_UNCOMPRESS) != 0L) {
660 			if (notFirst) {
661 				buffer.append(" | ");
662 			}
663 
664 			buffer.append("CKF_EC_UNCOMPRESS");
665 
666 			notFirst = true;
667 		}
668 
669 		if ((flags & PKCS11Constants.CKF_EC_COMPRESS) != 0L) {
670 			if (notFirst) {
671 				buffer.append(" | ");
672 			}
673 
674 			buffer.append("CKF_EC_COMPRESS");
675 
676 			notFirst = true;
677 		}
678 
679 		if ((flags & PKCS11Constants.CKF_EXTENSION) != 0L) {
680 			if (notFirst) {
681 				buffer.append(" | ");
682 			}
683 
684 			buffer.append("CKF_EXTENSION");
685 
686 			notFirst = true;
687 		}
688 
689 		return buffer.toString();
690 	}
691 
692 	/**
693 	 * Converts the long value code of a mechanism to a name.
694 	 *
695 	 * @param mechansimCode The code of the mechanism to be converted to a string.
696 	 * @return The string representation of the mechanism.
697 	 */
mechanismCodeToString(long mechansimCode)698 	public static String mechanismCodeToString(long mechansimCode) {
699 		if (mechansimNames_ == null) {
700 			Hashtable mechansimNames = new Hashtable(200);
701 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_PKCS_KEY_PAIR_GEN),
702 			    PKCS11Constants.NAME_CKM_RSA_PKCS_KEY_PAIR_GEN);
703 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_PKCS),
704 			    PKCS11Constants.NAME_CKM_RSA_PKCS);
705 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_9796),
706 			    PKCS11Constants.NAME_CKM_RSA_9796);
707 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_X_509),
708 			    PKCS11Constants.NAME_CKM_RSA_X_509);
709 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD2_RSA_PKCS),
710 			    PKCS11Constants.NAME_CKM_MD2_RSA_PKCS);
711 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD5_RSA_PKCS),
712 			    PKCS11Constants.NAME_CKM_MD5_RSA_PKCS);
713 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA1_RSA_PKCS),
714 			    PKCS11Constants.NAME_CKM_SHA1_RSA_PKCS);
715 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD128_RSA_PKCS),
716 			    PKCS11Constants.NAME_CKM_RIPEMD128_RSA_PKCS);
717 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD160_RSA_PKCS),
718 			    PKCS11Constants.NAME_CKM_RIPEMD160_RSA_PKCS);
719 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_PKCS_OAEP),
720 			    PKCS11Constants.NAME_CKM_RSA_PKCS_OAEP);
721 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_X9_31_KEY_PAIR_GEN),
722 			    PKCS11Constants.NAME_CKM_RSA_X9_31_KEY_PAIR_GEN);
723 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_X9_31),
724 			    PKCS11Constants.NAME_CKM_RSA_X9_31);
725 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA1_RSA_X9_31),
726 			    PKCS11Constants.NAME_CKM_SHA1_RSA_X9_31);
727 			mechansimNames.put(new Long(PKCS11Constants.CKM_RSA_PKCS_PSS),
728 			    PKCS11Constants.NAME_CKM_RSA_PKCS_PSS);
729 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA1_RSA_PKCS_PSS),
730 			    PKCS11Constants.NAME_CKM_SHA1_RSA_PKCS_PSS);
731 			mechansimNames.put(new Long(PKCS11Constants.CKM_DSA_KEY_PAIR_GEN),
732 			    PKCS11Constants.NAME_CKM_DSA_KEY_PAIR_GEN);
733 			mechansimNames.put(new Long(PKCS11Constants.CKM_DSA), PKCS11Constants.NAME_CKM_DSA);
734 			mechansimNames.put(new Long(PKCS11Constants.CKM_DSA_SHA1),
735 			    PKCS11Constants.NAME_CKM_DSA_SHA1);
736 			mechansimNames.put(new Long(PKCS11Constants.CKM_DH_PKCS_KEY_PAIR_GEN),
737 			    PKCS11Constants.NAME_CKM_DH_PKCS_KEY_PAIR_GEN);
738 			mechansimNames.put(new Long(PKCS11Constants.CKM_DH_PKCS_DERIVE),
739 			    PKCS11Constants.NAME_CKM_DH_PKCS_DERIVE);
740 			mechansimNames.put(new Long(PKCS11Constants.CKM_X9_42_DH_KEY_PAIR_GEN),
741 			    PKCS11Constants.NAME_CKM_X9_42_DH_KEY_PAIR_GEN);
742 			mechansimNames.put(new Long(PKCS11Constants.CKM_X9_42_DH_DERIVE),
743 			    PKCS11Constants.NAME_CKM_X9_42_DH_DERIVE);
744 			mechansimNames.put(new Long(PKCS11Constants.CKM_X9_42_DH_HYBRID_DERIVE),
745 			    PKCS11Constants.NAME_CKM_X9_42_DH_HYBRID_DERIVE);
746 			mechansimNames.put(new Long(PKCS11Constants.CKM_X9_42_MQV_DERIVE),
747 			    PKCS11Constants.NAME_CKM_X9_42_MQV_DERIVE);
748 
749 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA256_RSA_PKCS),
750 			    PKCS11Constants.NAME_CKM_SHA256_RSA_PKCS);
751 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA384_RSA_PKCS),
752 			    PKCS11Constants.NAME_CKM_SHA384_RSA_PKCS);
753 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA512_RSA_PKCS),
754 			    PKCS11Constants.NAME_CKM_SHA512_RSA_PKCS);
755 
756 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA256_RSA_PKCS_PSS),
757 			    PKCS11Constants.NAME_CKM_SHA256_RSA_PKCS_PSS);
758 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA384_RSA_PKCS_PSS),
759 			    PKCS11Constants.NAME_CKM_SHA384_RSA_PKCS_PSS);
760 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA512_RSA_PKCS_PSS),
761 			    PKCS11Constants.NAME_CKM_SHA512_RSA_PKCS_PSS);
762 
763 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC2_KEY_GEN),
764 			    PKCS11Constants.NAME_CKM_RC2_KEY_GEN);
765 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC2_ECB),
766 			    PKCS11Constants.NAME_CKM_RC2_ECB);
767 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC2_CBC),
768 			    PKCS11Constants.NAME_CKM_RC2_CBC);
769 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC2_MAC),
770 			    PKCS11Constants.NAME_CKM_RC2_MAC);
771 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC2_MAC_GENERAL),
772 			    PKCS11Constants.NAME_CKM_RC2_MAC_GENERAL);
773 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC2_CBC_PAD),
774 			    PKCS11Constants.NAME_CKM_RC2_CBC_PAD);
775 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC4_KEY_GEN),
776 			    PKCS11Constants.NAME_CKM_RC4_KEY_GEN);
777 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC4), PKCS11Constants.NAME_CKM_RC4);
778 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_KEY_GEN),
779 			    PKCS11Constants.NAME_CKM_DES_KEY_GEN);
780 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_ECB),
781 			    PKCS11Constants.NAME_CKM_DES_ECB);
782 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_CBC),
783 			    PKCS11Constants.NAME_CKM_DES_CBC);
784 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_MAC),
785 			    PKCS11Constants.NAME_CKM_DES_MAC);
786 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_MAC_GENERAL),
787 			    PKCS11Constants.NAME_CKM_DES_MAC_GENERAL);
788 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_CBC_PAD),
789 			    PKCS11Constants.NAME_CKM_DES_CBC_PAD);
790 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES2_KEY_GEN),
791 			    PKCS11Constants.NAME_CKM_DES2_KEY_GEN);
792 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_KEY_GEN),
793 			    PKCS11Constants.NAME_CKM_DES3_KEY_GEN);
794 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_ECB),
795 			    PKCS11Constants.NAME_CKM_DES3_ECB);
796 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_CBC),
797 			    PKCS11Constants.NAME_CKM_DES3_CBC);
798 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_MAC),
799 			    PKCS11Constants.NAME_CKM_DES3_MAC);
800 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_MAC_GENERAL),
801 			    PKCS11Constants.NAME_CKM_DES3_MAC_GENERAL);
802 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_CBC_PAD),
803 			    PKCS11Constants.NAME_CKM_DES3_CBC_PAD);
804 			mechansimNames.put(new Long(PKCS11Constants.CKM_CDMF_KEY_GEN),
805 			    PKCS11Constants.NAME_CKM_CDMF_KEY_GEN);
806 			mechansimNames.put(new Long(PKCS11Constants.CKM_CDMF_ECB),
807 			    PKCS11Constants.NAME_CKM_CDMF_ECB);
808 			mechansimNames.put(new Long(PKCS11Constants.CKM_CDMF_CBC),
809 			    PKCS11Constants.NAME_CKM_CDMF_CBC);
810 			mechansimNames.put(new Long(PKCS11Constants.CKM_CDMF_MAC),
811 			    PKCS11Constants.NAME_CKM_CDMF_MAC);
812 			mechansimNames.put(new Long(PKCS11Constants.CKM_CDMF_MAC_GENERAL),
813 			    PKCS11Constants.NAME_CKM_CDMF_MAC_GENERAL);
814 			mechansimNames.put(new Long(PKCS11Constants.CKM_CDMF_CBC_PAD),
815 			    PKCS11Constants.NAME_CKM_CDMF_CBC_PAD);
816 
817 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_OFB64),
818 			    PKCS11Constants.NAME_CKM_DES_OFB64);
819 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_OFB8),
820 			    PKCS11Constants.NAME_CKM_DES_OFB8);
821 
822 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_CFB64),
823 			    PKCS11Constants.NAME_CKM_DES_CFB64);
824 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_CFB8),
825 			    PKCS11Constants.NAME_CKM_DES_CFB8);
826 
827 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD2), PKCS11Constants.NAME_CKM_MD2);
828 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD2_HMAC),
829 			    PKCS11Constants.NAME_CKM_MD2_HMAC);
830 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD2_HMAC_GENERAL),
831 			    PKCS11Constants.NAME_CKM_MD2_HMAC_GENERAL);
832 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD5), PKCS11Constants.NAME_CKM_MD5);
833 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD5_HMAC),
834 			    PKCS11Constants.NAME_CKM_MD5_HMAC);
835 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD5_HMAC_GENERAL),
836 			    PKCS11Constants.NAME_CKM_MD5_HMAC_GENERAL);
837 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA_1),
838 			    PKCS11Constants.NAME_CKM_SHA_1);
839 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA_1_HMAC),
840 			    PKCS11Constants.NAME_CKM_SHA_1_HMAC);
841 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA_1_HMAC_GENERAL),
842 			    PKCS11Constants.NAME_CKM_SHA_1_HMAC_GENERAL);
843 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD128),
844 			    PKCS11Constants.NAME_CKM_RIPEMD128);
845 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD128_HMAC),
846 			    PKCS11Constants.NAME_CKM_RIPEMD128_HMAC);
847 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD128_HMAC_GENERAL),
848 			    PKCS11Constants.NAME_CKM_RIPEMD128_HMAC_GENERAL);
849 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD160),
850 			    PKCS11Constants.NAME_CKM_RIPEMD160);
851 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD160_HMAC),
852 			    PKCS11Constants.NAME_CKM_RIPEMD160_HMAC);
853 			mechansimNames.put(new Long(PKCS11Constants.CKM_RIPEMD160_HMAC_GENERAL),
854 			    PKCS11Constants.NAME_CKM_RIPEMD160_HMAC_GENERAL);
855 
856 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA256),
857 			    PKCS11Constants.NAME_CKM_SHA256);
858 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA256_HMAC),
859 			    PKCS11Constants.NAME_CKM_SHA256_HMAC);
860 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA256_HMAC_GENERAL),
861 			    PKCS11Constants.NAME_CKM_SHA256_HMAC_GENERAL);
862 
863 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA384),
864 			    PKCS11Constants.NAME_CKM_SHA384);
865 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA384_HMAC),
866 			    PKCS11Constants.NAME_CKM_SHA384_HMAC);
867 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA384_HMAC_GENERAL),
868 			    PKCS11Constants.NAME_CKM_SHA384_HMAC_GENERAL);
869 
870 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA512),
871 			    PKCS11Constants.NAME_CKM_SHA512);
872 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA512_HMAC),
873 			    PKCS11Constants.NAME_CKM_SHA512_HMAC);
874 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA512_HMAC_GENERAL),
875 			    PKCS11Constants.NAME_CKM_SHA512_HMAC_GENERAL);
876 
877 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST_KEY_GEN),
878 			    PKCS11Constants.NAME_CKM_CAST_KEY_GEN);
879 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST_ECB),
880 			    PKCS11Constants.NAME_CKM_CAST_ECB);
881 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST_CBC),
882 			    PKCS11Constants.NAME_CKM_CAST_CBC);
883 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST_MAC),
884 			    PKCS11Constants.NAME_CKM_CAST_MAC);
885 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST_MAC_GENERAL),
886 			    PKCS11Constants.NAME_CKM_CAST_MAC_GENERAL);
887 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST_CBC_PAD),
888 			    PKCS11Constants.NAME_CKM_CAST_CBC_PAD);
889 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST3_KEY_GEN),
890 			    PKCS11Constants.NAME_CKM_CAST3_KEY_GEN);
891 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST3_ECB),
892 			    PKCS11Constants.NAME_CKM_CAST3_ECB);
893 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST3_CBC),
894 			    PKCS11Constants.NAME_CKM_CAST3_CBC);
895 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST3_MAC),
896 			    PKCS11Constants.NAME_CKM_CAST3_MAC);
897 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST3_MAC_GENERAL),
898 			    PKCS11Constants.NAME_CKM_CAST3_MAC_GENERAL);
899 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST3_CBC_PAD),
900 			    PKCS11Constants.NAME_CKM_CAST3_CBC_PAD);
901 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST5_KEY_GEN),
902 			    PKCS11Constants.NAME_CKM_CAST5_KEY_GEN);
903 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST128_KEY_GEN),
904 			    PKCS11Constants.NAME_CKM_CAST128_KEY_GEN);
905 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST5_ECB),
906 			    PKCS11Constants.NAME_CKM_CAST5_ECB);
907 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST128_ECB),
908 			    PKCS11Constants.NAME_CKM_CAST128_ECB);
909 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST5_CBC),
910 			    PKCS11Constants.NAME_CKM_CAST5_CBC);
911 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST128_CBC),
912 			    PKCS11Constants.NAME_CKM_CAST128_CBC);
913 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST5_MAC),
914 			    PKCS11Constants.NAME_CKM_CAST5_MAC);
915 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST128_MAC),
916 			    PKCS11Constants.NAME_CKM_CAST128_MAC);
917 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST5_MAC_GENERAL),
918 			    PKCS11Constants.NAME_CKM_CAST5_MAC_GENERAL);
919 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST128_MAC_GENERAL),
920 			    PKCS11Constants.NAME_CKM_CAST128_MAC_GENERAL);
921 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST5_CBC_PAD),
922 			    PKCS11Constants.NAME_CKM_CAST5_CBC_PAD);
923 			mechansimNames.put(new Long(PKCS11Constants.CKM_CAST128_CBC_PAD),
924 			    PKCS11Constants.NAME_CKM_CAST128_CBC_PAD);
925 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC5_KEY_GEN),
926 			    PKCS11Constants.NAME_CKM_RC5_KEY_GEN);
927 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC5_ECB),
928 			    PKCS11Constants.NAME_CKM_RC5_ECB);
929 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC5_CBC),
930 			    PKCS11Constants.NAME_CKM_RC5_CBC);
931 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC5_MAC),
932 			    PKCS11Constants.NAME_CKM_RC5_MAC);
933 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC5_MAC_GENERAL),
934 			    PKCS11Constants.NAME_CKM_RC5_MAC_GENERAL);
935 			mechansimNames.put(new Long(PKCS11Constants.CKM_RC5_CBC_PAD),
936 			    PKCS11Constants.NAME_CKM_RC5_CBC_PAD);
937 			mechansimNames.put(new Long(PKCS11Constants.CKM_IDEA_KEY_GEN),
938 			    PKCS11Constants.NAME_CKM_IDEA_KEY_GEN);
939 			mechansimNames.put(new Long(PKCS11Constants.CKM_IDEA_ECB),
940 			    PKCS11Constants.NAME_CKM_IDEA_ECB);
941 			mechansimNames.put(new Long(PKCS11Constants.CKM_IDEA_CBC),
942 			    PKCS11Constants.NAME_CKM_IDEA_CBC);
943 			mechansimNames.put(new Long(PKCS11Constants.CKM_IDEA_MAC),
944 			    PKCS11Constants.NAME_CKM_IDEA_MAC);
945 			mechansimNames.put(new Long(PKCS11Constants.CKM_IDEA_MAC_GENERAL),
946 			    PKCS11Constants.NAME_CKM_IDEA_MAC_GENERAL);
947 			mechansimNames.put(new Long(PKCS11Constants.CKM_IDEA_CBC_PAD),
948 			    PKCS11Constants.NAME_CKM_IDEA_CBC_PAD);
949 			mechansimNames.put(new Long(PKCS11Constants.CKM_GENERIC_SECRET_KEY_GEN),
950 			    PKCS11Constants.NAME_CKM_GENERIC_SECRET_KEY_GEN);
951 			mechansimNames.put(new Long(PKCS11Constants.CKM_CONCATENATE_BASE_AND_KEY),
952 			    PKCS11Constants.NAME_CKM_CONCATENATE_BASE_AND_KEY);
953 			mechansimNames.put(new Long(PKCS11Constants.CKM_CONCATENATE_BASE_AND_DATA),
954 			    PKCS11Constants.NAME_CKM_CONCATENATE_BASE_AND_DATA);
955 			mechansimNames.put(new Long(PKCS11Constants.CKM_CONCATENATE_DATA_AND_BASE),
956 			    PKCS11Constants.NAME_CKM_CONCATENATE_DATA_AND_BASE);
957 			mechansimNames.put(new Long(PKCS11Constants.CKM_XOR_BASE_AND_DATA),
958 			    PKCS11Constants.NAME_CKM_XOR_BASE_AND_DATA);
959 			mechansimNames.put(new Long(PKCS11Constants.CKM_EXTRACT_KEY_FROM_KEY),
960 			    PKCS11Constants.NAME_CKM_EXTRACT_KEY_FROM_KEY);
961 			mechansimNames.put(new Long(PKCS11Constants.CKM_SSL3_PRE_MASTER_KEY_GEN),
962 			    PKCS11Constants.NAME_CKM_SSL3_PRE_MASTER_KEY_GEN);
963 			mechansimNames.put(new Long(PKCS11Constants.CKM_SSL3_MASTER_KEY_DERIVE),
964 			    PKCS11Constants.NAME_CKM_SSL3_MASTER_KEY_DERIVE);
965 			mechansimNames.put(new Long(PKCS11Constants.CKM_SSL3_KEY_AND_MAC_DERIVE),
966 			    PKCS11Constants.NAME_CKM_SSL3_KEY_AND_MAC_DERIVE);
967 			mechansimNames.put(new Long(PKCS11Constants.CKM_SSL3_MASTER_KEY_DERIVE_DH),
968 			    PKCS11Constants.NAME_CKM_SSL3_MASTER_KEY_DERIVE_DH);
969 			mechansimNames.put(new Long(PKCS11Constants.CKM_TLS_PRE_MASTER_KEY_GEN),
970 			    PKCS11Constants.NAME_CKM_TLS_PRE_MASTER_KEY_GEN);
971 			mechansimNames.put(new Long(PKCS11Constants.CKM_TLS_MASTER_KEY_DERIVE),
972 			    PKCS11Constants.NAME_CKM_TLS_MASTER_KEY_DERIVE);
973 			mechansimNames.put(new Long(PKCS11Constants.CKM_TLS_KEY_AND_MAC_DERIVE),
974 			    PKCS11Constants.NAME_CKM_TLS_KEY_AND_MAC_DERIVE);
975 			mechansimNames.put(new Long(PKCS11Constants.CKM_TLS_MASTER_KEY_DERIVE_DH),
976 			    PKCS11Constants.NAME_CKM_TLS_MASTER_KEY_DERIVE_DH);
977 			mechansimNames.put(new Long(PKCS11Constants.CKM_SSL3_MD5_MAC),
978 			    PKCS11Constants.NAME_CKM_SSL3_MD5_MAC);
979 			mechansimNames.put(new Long(PKCS11Constants.CKM_SSL3_SHA1_MAC),
980 			    PKCS11Constants.NAME_CKM_SSL3_SHA1_MAC);
981 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD5_KEY_DERIVATION),
982 			    PKCS11Constants.NAME_CKM_MD5_KEY_DERIVATION);
983 			mechansimNames.put(new Long(PKCS11Constants.CKM_MD2_KEY_DERIVATION),
984 			    PKCS11Constants.NAME_CKM_MD2_KEY_DERIVATION);
985 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA1_KEY_DERIVATION),
986 			    PKCS11Constants.NAME_CKM_SHA1_KEY_DERIVATION);
987 
988 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA256_KEY_DERIVATION),
989 			    PKCS11Constants.NAME_CKM_SHA256_KEY_DERIVATION);
990 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA384_KEY_DERIVATION),
991 			    PKCS11Constants.NAME_CKM_SHA384_KEY_DERIVATION);
992 			mechansimNames.put(new Long(PKCS11Constants.CKM_SHA512_KEY_DERIVATION),
993 			    PKCS11Constants.NAME_CKM_SHA512_KEY_DERIVATION);
994 
995 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_MD2_DES_CBC),
996 			    PKCS11Constants.NAME_CKM_PBE_MD2_DES_CBC);
997 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_MD5_DES_CBC),
998 			    PKCS11Constants.NAME_CKM_PBE_MD5_DES_CBC);
999 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST_CBC),
1000 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST_CBC);
1001 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST3_CBC),
1002 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST3_CBC);
1003 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST5_CBC),
1004 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST5_CBC);
1005 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST128_CBC),
1006 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST128_CBC);
1007 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_CAST5_CBC),
1008 			    PKCS11Constants.NAME_CKM_PBE_SHA1_CAST5_CBC);
1009 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_CAST128_CBC),
1010 			    PKCS11Constants.NAME_CKM_PBE_SHA1_CAST128_CBC);
1011 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC4_128),
1012 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC4_128);
1013 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC4_40),
1014 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC4_40);
1015 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_DES3_EDE_CBC),
1016 			    PKCS11Constants.NAME_CKM_PBE_SHA1_DES3_EDE_CBC);
1017 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_DES2_EDE_CBC),
1018 			    PKCS11Constants.NAME_CKM_PBE_SHA1_DES2_EDE_CBC);
1019 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC2_128_CBC),
1020 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC2_128_CBC);
1021 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC2_40_CBC),
1022 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC2_40_CBC);
1023 			mechansimNames.put(new Long(PKCS11Constants.CKM_PKCS5_PBKD2),
1024 			    PKCS11Constants.NAME_CKM_PKCS5_PBKD2);
1025 			mechansimNames.put(new Long(PKCS11Constants.CKM_PBA_SHA1_WITH_SHA1_HMAC),
1026 			    PKCS11Constants.NAME_CKM_PBA_SHA1_WITH_SHA1_HMAC);
1027 
1028 			mechansimNames.put(new Long(PKCS11Constants.CKM_WTLS_PRE_MASTER_KEY_GEN),
1029 			    PKCS11Constants.NAME_CKM_WTLS_PRE_MASTER_KEY_GEN);
1030 			mechansimNames.put(new Long(PKCS11Constants.CKM_WTLS_MASTER_KEY_DERIVE),
1031 			    PKCS11Constants.NAME_CKM_WTLS_MASTER_KEY_DERIVE);
1032 			mechansimNames.put(new Long(PKCS11Constants.CKM_WTLS_MASTER_KEY_DERVIE_DH_ECC),
1033 			    PKCS11Constants.NAME_CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC);
1034 			mechansimNames.put(new Long(PKCS11Constants.CKM_WTLS_PRF),
1035 			    PKCS11Constants.NAME_CKM_WTLS_PRF);
1036 			mechansimNames.put(new Long(PKCS11Constants.CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE),
1037 			    PKCS11Constants.NAME_CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE);
1038 			mechansimNames.put(new Long(PKCS11Constants.CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE),
1039 			    PKCS11Constants.NAME_CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE);
1040 
1041 			mechansimNames.put(new Long(PKCS11Constants.CKM_KEY_WRAP_LYNKS),
1042 			    PKCS11Constants.NAME_CKM_KEY_WRAP_LYNKS);
1043 			mechansimNames.put(new Long(PKCS11Constants.CKM_KEY_WRAP_SET_OAEP),
1044 			    PKCS11Constants.NAME_CKM_KEY_WRAP_SET_OAEP);
1045 
1046 			mechansimNames.put(new Long(PKCS11Constants.CKM_CMS_SIG),
1047 			    PKCS11Constants.NAME_CKM_CMS_SIG);
1048 
1049 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_KEY_GEN),
1050 			    PKCS11Constants.NAME_CKM_SKIPJACK_KEY_GEN);
1051 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_ECB64),
1052 			    PKCS11Constants.NAME_CKM_SKIPJACK_ECB64);
1053 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_CBC64),
1054 			    PKCS11Constants.NAME_CKM_SKIPJACK_CBC64);
1055 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_OFB64),
1056 			    PKCS11Constants.NAME_CKM_SKIPJACK_OFB64);
1057 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB64),
1058 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB64);
1059 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB32),
1060 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB32);
1061 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB16),
1062 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB16);
1063 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB8),
1064 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB8);
1065 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_WRAP),
1066 			    PKCS11Constants.NAME_CKM_SKIPJACK_WRAP);
1067 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_PRIVATE_WRAP),
1068 			    PKCS11Constants.NAME_CKM_SKIPJACK_PRIVATE_WRAP);
1069 			mechansimNames.put(new Long(PKCS11Constants.CKM_SKIPJACK_RELAYX),
1070 			    PKCS11Constants.NAME_CKM_SKIPJACK_RELAYX);
1071 			mechansimNames.put(new Long(PKCS11Constants.CKM_KEA_KEY_PAIR_GEN),
1072 			    PKCS11Constants.NAME_CKM_KEA_KEY_PAIR_GEN);
1073 			mechansimNames.put(new Long(PKCS11Constants.CKM_KEA_KEY_DERIVE),
1074 			    PKCS11Constants.NAME_CKM_KEA_KEY_DERIVE);
1075 			mechansimNames.put(new Long(PKCS11Constants.CKM_FORTEZZA_TIMESTAMP),
1076 			    PKCS11Constants.NAME_CKM_FORTEZZA_TIMESTAMP);
1077 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_KEY_GEN),
1078 			    PKCS11Constants.NAME_CKM_BATON_KEY_GEN);
1079 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_ECB128),
1080 			    PKCS11Constants.NAME_CKM_BATON_ECB128);
1081 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_ECB96),
1082 			    PKCS11Constants.NAME_CKM_BATON_ECB96);
1083 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_CBC128),
1084 			    PKCS11Constants.NAME_CKM_BATON_CBC128);
1085 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_COUNTER),
1086 			    PKCS11Constants.NAME_CKM_BATON_COUNTER);
1087 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_SHUFFLE),
1088 			    PKCS11Constants.NAME_CKM_BATON_SHUFFLE);
1089 			mechansimNames.put(new Long(PKCS11Constants.CKM_BATON_WRAP),
1090 			    PKCS11Constants.NAME_CKM_BATON_WRAP);
1091 			mechansimNames.put(new Long(PKCS11Constants.CKM_ECDSA_KEY_PAIR_GEN),
1092 			    PKCS11Constants.NAME_CKM_ECDSA_KEY_PAIR_GEN);
1093 			mechansimNames.put(new Long(PKCS11Constants.CKM_EC_KEY_PAIR_GEN),
1094 			    PKCS11Constants.NAME_CKM_EC_KEY_PAIR_GEN);
1095 			mechansimNames.put(new Long(PKCS11Constants.CKM_ECDSA),
1096 			    PKCS11Constants.NAME_CKM_ECDSA);
1097 			mechansimNames.put(new Long(PKCS11Constants.CKM_ECDSA_SHA1),
1098 			    PKCS11Constants.NAME_CKM_ECDSA_SHA1);
1099 			mechansimNames.put(new Long(PKCS11Constants.CKM_ECDH1_DERIVE),
1100 			    PKCS11Constants.NAME_CKM_ECDH1_DERIVE);
1101 			mechansimNames.put(new Long(PKCS11Constants.CKM_ECDH1_COFACTOR_DERIVE),
1102 			    PKCS11Constants.NAME_CKM_ECDH1_COFACTOR_DERIVE);
1103 			mechansimNames.put(new Long(PKCS11Constants.CKM_ECMQV_DERIVE),
1104 			    PKCS11Constants.NAME_CKM_ECMQV_DERIVE);
1105 			mechansimNames.put(new Long(PKCS11Constants.CKM_JUNIPER_KEY_GEN),
1106 			    PKCS11Constants.NAME_CKM_JUNIPER_KEY_GEN);
1107 			mechansimNames.put(new Long(PKCS11Constants.CKM_JUNIPER_ECB128),
1108 			    PKCS11Constants.NAME_CKM_JUNIPER_ECB128);
1109 			mechansimNames.put(new Long(PKCS11Constants.CKM_JUNIPER_CBC128),
1110 			    PKCS11Constants.NAME_CKM_JUNIPER_CBC128);
1111 			mechansimNames.put(new Long(PKCS11Constants.CKM_JUNIPER_COUNTER),
1112 			    PKCS11Constants.NAME_CKM_JUNIPER_COUNTER);
1113 			mechansimNames.put(new Long(PKCS11Constants.CKM_JUNIPER_SHUFFLE),
1114 			    PKCS11Constants.NAME_CKM_JUNIPER_SHUFFLE);
1115 			mechansimNames.put(new Long(PKCS11Constants.CKM_JUNIPER_WRAP),
1116 			    PKCS11Constants.NAME_CKM_JUNIPER_WRAP);
1117 			mechansimNames.put(new Long(PKCS11Constants.CKM_FASTHASH),
1118 			    PKCS11Constants.NAME_CKM_FASTHASH);
1119 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_KEY_GEN),
1120 			    PKCS11Constants.NAME_CKM_AES_KEY_GEN);
1121 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_ECB),
1122 			    PKCS11Constants.NAME_CKM_AES_ECB);
1123 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_CBC),
1124 			    PKCS11Constants.NAME_CKM_AES_CBC);
1125 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_MAC),
1126 			    PKCS11Constants.NAME_CKM_AES_MAC);
1127 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_MAC_GENERAL),
1128 			    PKCS11Constants.NAME_CKM_AES_MAC_GENERAL);
1129 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_CBC_PAD),
1130 			    PKCS11Constants.NAME_CKM_AES_CBC_PAD);
1131 
1132 			mechansimNames.put(new Long(PKCS11Constants.CKM_BLOWFISH_KEY_GEN),
1133 			    PKCS11Constants.NAME_CKM_BLOWFISH_KEY_GEN);
1134 			mechansimNames.put(new Long(PKCS11Constants.CKM_BLOWFISH_CBC),
1135 			    PKCS11Constants.NAME_CKM_BLOWFISH_CBC);
1136 
1137 			mechansimNames.put(new Long(PKCS11Constants.CKM_TWOFISH_KEY_GEN),
1138 			    PKCS11Constants.NAME_CKM_TWOFISH_KEY_GEN);
1139 			mechansimNames.put(new Long(PKCS11Constants.CKM_TWOFISH_CBC),
1140 			    PKCS11Constants.NAME_CKM_TWOFISH_CBC);
1141 
1142 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_ECB_ENCRYPT_DATA),
1143 			    PKCS11Constants.NAME_CKM_DES_ECB_ENCRYPT_DATA);
1144 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES_CBC_ENCRYPT_DATA),
1145 			    PKCS11Constants.NAME_CKM_DES_CBC_ENCRYPT_DATA);
1146 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_ECB_ENCRYPT_DATA),
1147 			    PKCS11Constants.NAME_CKM_DES3_ECB_ENCRYPT_DATA);
1148 			mechansimNames.put(new Long(PKCS11Constants.CKM_DES3_CBC_ENCRYPT_DATA),
1149 			    PKCS11Constants.NAME_CKM_DES3_CBC_ENCRYPT_DATA);
1150 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_ECB_ENCRYPT_DATA),
1151 			    PKCS11Constants.NAME_CKM_AES_ECB_ENCRYPT_DATA);
1152 			mechansimNames.put(new Long(PKCS11Constants.CKM_AES_CBC_ENCRYPT_DATA),
1153 			    PKCS11Constants.NAME_CKM_AES_CBC_ENCRYPT_DATA);
1154 
1155 			mechansimNames.put(new Long(PKCS11Constants.CKM_DSA_PARAMETER_GEN),
1156 			    PKCS11Constants.NAME_CKM_DSA_PARAMETER_GEN);
1157 			mechansimNames.put(new Long(PKCS11Constants.CKM_DH_PKCS_PARAMETER_GEN),
1158 			    PKCS11Constants.NAME_CKM_DH_PKCS_PARAMETER_GEN);
1159 			mechansimNames.put(new Long(PKCS11Constants.CKM_X9_42_DH_PARAMETER_GEN),
1160 			    PKCS11Constants.NAME_CKM_X9_42_DH_PARAMETER_GEN);
1161 			mechansimNames.put(new Long(PKCS11Constants.CKM_VENDOR_DEFINED),
1162 			    PKCS11Constants.NAME_CKM_VENDOR_DEFINED);
1163 			mechansimNames_ = mechansimNames;
1164 		}
1165 
1166 		Long mechansimCodeObject = new Long(mechansimCode);
1167 		Object entry = mechansimNames_.get(mechansimCodeObject);
1168 
1169 		String mechanismName = (entry != null) ? entry.toString()
1170 		    : "Unknwon mechanism with code: 0x" + toFullHexString(mechansimCode);
1171 
1172 		return mechanismName;
1173 	}
1174 
1175 	/**
1176 	 * Converts the long value classType to a string representation of it.
1177 	 *
1178 	 * @param classType The classType to be converted.
1179 	 * @return The string representation of the classType.
1180 	 */
classTypeToString(long classType)1181 	public static String classTypeToString(long classType) {
1182 		String name;
1183 
1184 		if (classType == PKCS11Constants.CKO_DATA) {
1185 			name = "CKO_DATA";
1186 		} else if (classType == PKCS11Constants.CKO_CERTIFICATE) {
1187 			name = "CKO_CERTIFICATE";
1188 		} else if (classType == PKCS11Constants.CKO_PUBLIC_KEY) {
1189 			name = "CKO_PUBLIC_KEY";
1190 		} else if (classType == PKCS11Constants.CKO_PRIVATE_KEY) {
1191 			name = "CKO_PRIVATE_KEY";
1192 		} else if (classType == PKCS11Constants.CKO_SECRET_KEY) {
1193 			name = "CKO_SECRET_KEY";
1194 		} else if (classType == PKCS11Constants.CKO_HW_FEATURE) {
1195 			name = "CKO_HW_FEATURE";
1196 		} else if (classType == PKCS11Constants.CKO_DOMAIN_PARAMETERS) {
1197 			name = "CKO_DOMAIN_PARAMETERS";
1198 		} else if (classType == PKCS11Constants.CKO_VENDOR_DEFINED) {
1199 			name = "CKO_VENDOR_DEFINED";
1200 		} else {
1201 			name = "ERROR: unknown classType with code: 0x" + toFullHexString(classType);
1202 		}
1203 
1204 		return name;
1205 	}
1206 
1207 	/**
1208 	 * Check the given arrays for equalitiy. This method considers both arrays as
1209 	 * equal, if both are <code>null</code> or both have the same length and
1210 	 * contain exactly the same byte values.
1211 	 *
1212 	 * @param array1 The first array.
1213 	 * @param array2 The second array.
1214 	 * @return True, if both arrays are <code>null</code> or both have the same
1215 	 *         length and contain exactly the same byte values. False, otherwise.
1216 	 * @preconditions
1217 	 * @postconditions
1218 	 */
equals(byte[] array1, byte[] array2)1219 	public static boolean equals(byte[] array1, byte[] array2) {
1220 		boolean equal = false;
1221 
1222 		if (array1 == array2) {
1223 			equal = true;
1224 		} else if ((array1 != null) && (array2 != null)) {
1225 			int length = array1.length;
1226 			if (length == array2.length) {
1227 				equal = true;
1228 				for (int i = 0; i < length; i++) {
1229 					if (array1[i] != array2[i]) {
1230 						equal = false;
1231 						break;
1232 					}
1233 				}
1234 			} else {
1235 				equal = false;
1236 			}
1237 		} else {
1238 			equal = false;
1239 		}
1240 
1241 		return equal;
1242 	}
1243 
1244 	/**
1245 	 * Check the given arrays for equalitiy. This method considers both arrays as
1246 	 * equal, if both are <code>null</code> or both have the same length and
1247 	 * contain exactly the same char values.
1248 	 *
1249 	 * @param array1 The first array.
1250 	 * @param array2 The second array.
1251 	 * @return True, if both arrays are <code>null</code> or both have the same
1252 	 *         length and contain exactly the same char values. False, otherwise.
1253 	 * @preconditions
1254 	 * @postconditions
1255 	 */
equals(char[] array1, char[] array2)1256 	public static boolean equals(char[] array1, char[] array2) {
1257 		boolean equal = false;
1258 
1259 		if (array1 == array2) {
1260 			equal = true;
1261 		} else if ((array1 != null) && (array2 != null)) {
1262 			int length = array1.length;
1263 			if (length == array2.length) {
1264 				equal = true;
1265 				for (int i = 0; i < length; i++) {
1266 					if (array1[i] != array2[i]) {
1267 						equal = false;
1268 						break;
1269 					}
1270 				}
1271 			} else {
1272 				equal = false;
1273 			}
1274 		} else {
1275 			equal = false;
1276 		}
1277 
1278 		return equal;
1279 	}
1280 
1281 	/**
1282 	 * Check the given arrays for equality. This method considers both arrays as
1283 	 * equal, if both are <code>null</code> or both have the same length and
1284 	 * contain exactly the same byte values.
1285 	 *
1286 	 * @param array1 The first array.
1287 	 * @param array2 The second array.
1288 	 * @return True, if both arrays are <code>null</code> or both have the same
1289 	 *         length and contain exactly the same byte values. False, otherwise.
1290 	 * @preconditions
1291 	 * @postconditions
1292 	 */
equals(long[] array1, long[] array2)1293 	public static boolean equals(long[] array1, long[] array2) {
1294 		boolean equal = false;
1295 
1296 		if (array1 == array2) {
1297 			equal = true;
1298 		} else if ((array1 != null) && (array2 != null)) {
1299 			int length = array1.length;
1300 			if (length == array2.length) {
1301 				equal = true;
1302 				for (int i = 0; i < length; i++) {
1303 					if (array1[i] != array2[i]) {
1304 						equal = false;
1305 						break;
1306 					}
1307 				}
1308 			} else {
1309 				equal = false;
1310 			}
1311 		} else {
1312 			equal = false;
1313 		}
1314 
1315 		return equal;
1316 	}
1317 
1318 	/**
1319 	 * Check the given dates for equalitiy. This method considers both dates as
1320 	 * equal, if both are <code>null</code> or both contain exactly the same char
1321 	 * values.
1322 	 *
1323 	 * @param date1 The first date.
1324 	 * @param date2 The second date.
1325 	 * @return True, if both dates are <code>null</code> or both contain the same
1326 	 *         char values. False, otherwise.
1327 	 * @preconditions
1328 	 * @postconditions
1329 	 */
equals(CK_DATE date1, CK_DATE date2)1330 	public static boolean equals(CK_DATE date1, CK_DATE date2) {
1331 		boolean equal = false;
1332 
1333 		if (date1 == date2) {
1334 			equal = true;
1335 		} else if ((date1 != null) && (date2 != null)) {
1336 			equal = equals(date1.year, date2.year) && equals(date1.month, date2.month)
1337 			    && equals(date1.day, date2.day);
1338 		} else {
1339 			equal = false;
1340 		}
1341 
1342 		return equal;
1343 	}
1344 
1345 	/**
1346 	 * Calculate a hash code for the given byte array.
1347 	 *
1348 	 * @param array The byte array.
1349 	 * @return A hash code for the given array.
1350 	 * @preconditions
1351 	 * @postconditions
1352 	 */
hashCode(byte[] array)1353 	public static int hashCode(byte[] array) {
1354 		int hash = 0;
1355 
1356 		if (array != null) {
1357 			for (int i = 0; (i < 4) && (i < array.length); i++) {
1358 				hash ^= (0xFF & array[i]) << ((i % 4) << 3);
1359 			}
1360 		}
1361 
1362 		return hash;
1363 	}
1364 
1365 	/**
1366 	 * Calculate a hash code for the given char array.
1367 	 *
1368 	 * @param array The char array.
1369 	 * @return A hash code for the given array.
1370 	 * @preconditions
1371 	 * @postconditions
1372 	 */
hashCode(char[] array)1373 	public static int hashCode(char[] array) {
1374 		int hash = 0;
1375 
1376 		if (array != null) {
1377 			for (int i = 0; (i < 4) && (i < array.length); i++) {
1378 				//	      hash ^= (0xFFFFFFFF & (array[i]>>32)); // this is useless since char is 16bit wide
1379 				hash ^= (0xFFFFFFFF & array[i]);
1380 			}
1381 		}
1382 
1383 		return hash;
1384 	}
1385 
1386 	/**
1387 	 * Calculate a hash code for the given long array.
1388 	 *
1389 	 * @param array The long array.
1390 	 * @return A hash code for the given array.
1391 	 * @preconditions
1392 	 * @postconditions
1393 	 */
hashCode(long[] array)1394 	public static int hashCode(long[] array) {
1395 		int hash = 0;
1396 
1397 		if (array != null) {
1398 			for (int i = 0; (i < 4) && (i < array.length); i++) {
1399 				hash ^= (0xFFFFFFFF & (array[i] >> 4));
1400 				hash ^= (0xFFFFFFFF & array[i]);
1401 			}
1402 		}
1403 
1404 		return hash;
1405 	}
1406 
1407 	/**
1408 	 * Calculate a hash code for the given date object.
1409 	 *
1410 	 * @param date The date object.
1411 	 * @return A hash code for the given date.
1412 	 * @preconditions
1413 	 * @postconditions
1414 	 */
hashCode(CK_DATE date)1415 	public static int hashCode(CK_DATE date) {
1416 		int hash = 0;
1417 
1418 		if (date != null) {
1419 			if (date.year.length == 4) {
1420 				hash ^= (0xFFFF & date.year[0]) << 16;
1421 				hash ^= 0xFFFF & date.year[1];
1422 				hash ^= (0xFFFF & date.year[2]) << 16;
1423 				hash ^= 0xFFFF & date.year[3];
1424 			}
1425 			if (date.month.length == 2) {
1426 				hash ^= (0xFFFF & date.month[0]) << 16;
1427 				hash ^= 0xFFFF & date.month[1];
1428 			}
1429 			if (date.day.length == 2) {
1430 				hash ^= (0xFFFF & date.day[0]) << 16;
1431 				hash ^= 0xFFFF & date.day[1];
1432 			}
1433 		}
1434 
1435 		return hash;
1436 	}
1437 
1438 	/**
1439 	 * This method checks, if the mechanism with the given code is a full
1440 	 * encrypt/decrypt mechanism; i.e. it supports the encryptUpdate()
1441 	 * and decryptUpdate() functions.
1442 	 * This is the information as provided by the table on page 229
1443 	 * of the PKCS#11 v2.11 standard.
1444 	 * If this method returns true, the mechanism can be used with the encrypt and
1445 	 * decrypt functions including encryptUpdate and decryptUpdate.
1446 	 *
1447 	 * @param mechanismCode The code of the mechanism to check.
1448 	 * @return True, if the provided mechanism is a full encrypt/decrypt
1449 	 *         mechanism. False, otherwise.
1450 	 * @preconditions
1451 	 * @postconditions
1452 	 */
isFullEncryptDecryptMechanism(long mechanismCode)1453 	public static boolean isFullEncryptDecryptMechanism(long mechanismCode) {
1454 		// build the hashtable on demand (=first use)
1455 		if (fullEncryptDecryptMechanisms_ == null) {
1456 			Hashtable fullEncryptDecryptMechanisms = new Hashtable();
1457 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC2_ECB),
1458 			    PKCS11Constants.NAME_CKM_RC2_ECB);
1459 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC2_CBC),
1460 			    PKCS11Constants.NAME_CKM_RC2_CBC);
1461 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC2_CBC_PAD),
1462 			    PKCS11Constants.NAME_CKM_RC2_CBC_PAD);
1463 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC4),
1464 			    PKCS11Constants.NAME_CKM_RC4);
1465 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_ECB),
1466 			    PKCS11Constants.NAME_CKM_DES_ECB);
1467 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_CBC),
1468 			    PKCS11Constants.NAME_CKM_DES_CBC);
1469 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_CBC_PAD),
1470 			    PKCS11Constants.NAME_CKM_DES_CBC_PAD);
1471 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES3_ECB),
1472 			    PKCS11Constants.NAME_CKM_DES3_ECB);
1473 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES3_CBC),
1474 			    PKCS11Constants.NAME_CKM_DES3_CBC);
1475 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES3_CBC_PAD),
1476 			    PKCS11Constants.NAME_CKM_DES3_CBC_PAD);
1477 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_ECB),
1478 			    PKCS11Constants.NAME_CKM_CDMF_ECB);
1479 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_CBC),
1480 			    PKCS11Constants.NAME_CKM_CDMF_CBC);
1481 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_CBC_PAD),
1482 			    PKCS11Constants.NAME_CKM_CDMF_CBC_PAD);
1483 
1484 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_OFB64),
1485 			    PKCS11Constants.NAME_CKM_DES_OFB64);
1486 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_OFB8),
1487 			    PKCS11Constants.NAME_CKM_DES_OFB8);
1488 
1489 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_CFB64),
1490 			    PKCS11Constants.NAME_CKM_DES_CFB64);
1491 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_DES_CFB8),
1492 			    PKCS11Constants.NAME_CKM_DES_CFB8);
1493 
1494 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST_ECB),
1495 			    PKCS11Constants.NAME_CKM_CAST_ECB);
1496 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST_CBC),
1497 			    PKCS11Constants.NAME_CKM_CAST_CBC);
1498 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST_CBC_PAD),
1499 			    PKCS11Constants.NAME_CKM_CAST_CBC_PAD);
1500 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_ECB),
1501 			    PKCS11Constants.NAME_CKM_CAST3_ECB);
1502 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_CBC),
1503 			    PKCS11Constants.NAME_CKM_CAST3_CBC);
1504 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_CBC_PAD),
1505 			    PKCS11Constants.NAME_CKM_CAST3_CBC_PAD);
1506 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_ECB),
1507 			    PKCS11Constants.NAME_CKM_CAST5_ECB);
1508 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_ECB),
1509 			    PKCS11Constants.NAME_CKM_CAST128_ECB);
1510 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_CBC),
1511 			    PKCS11Constants.NAME_CKM_CAST5_CBC);
1512 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_CBC),
1513 			    PKCS11Constants.NAME_CKM_CAST128_CBC);
1514 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_CBC_PAD),
1515 			    PKCS11Constants.NAME_CKM_CAST5_CBC_PAD);
1516 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_CBC_PAD),
1517 			    PKCS11Constants.NAME_CKM_CAST128_CBC_PAD);
1518 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC5_ECB),
1519 			    PKCS11Constants.NAME_CKM_RC5_ECB);
1520 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC5_CBC),
1521 			    PKCS11Constants.NAME_CKM_RC5_CBC);
1522 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RC5_CBC_PAD),
1523 			    PKCS11Constants.NAME_CKM_RC5_CBC_PAD);
1524 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_AES_ECB),
1525 			    PKCS11Constants.NAME_CKM_AES_ECB);
1526 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_AES_CBC),
1527 			    PKCS11Constants.NAME_CKM_AES_CBC);
1528 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_AES_CBC_PAD),
1529 			    PKCS11Constants.NAME_CKM_AES_CBC_PAD);
1530 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_BLOWFISH_CBC),
1531 			    PKCS11Constants.NAME_CKM_BLOWFISH_CBC);
1532 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_TWOFISH_CBC),
1533 			    PKCS11Constants.NAME_CKM_TWOFISH_CBC);
1534 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_ECB),
1535 			    PKCS11Constants.NAME_CKM_IDEA_ECB);
1536 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_CBC),
1537 			    PKCS11Constants.NAME_CKM_IDEA_CBC);
1538 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_CBC_PAD),
1539 			    PKCS11Constants.NAME_CKM_IDEA_CBC_PAD);
1540 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_ECB64),
1541 			    PKCS11Constants.NAME_CKM_SKIPJACK_ECB64);
1542 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_CBC64),
1543 			    PKCS11Constants.NAME_CKM_SKIPJACK_CBC64);
1544 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_OFB64),
1545 			    PKCS11Constants.NAME_CKM_SKIPJACK_OFB64);
1546 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB64),
1547 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB64);
1548 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB32),
1549 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB32);
1550 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB16),
1551 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB16);
1552 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_CFB8),
1553 			    PKCS11Constants.NAME_CKM_SKIPJACK_CFB8);
1554 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_BATON_ECB128),
1555 			    PKCS11Constants.NAME_CKM_BATON_ECB128);
1556 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_BATON_ECB96),
1557 			    PKCS11Constants.NAME_CKM_BATON_ECB96);
1558 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_BATON_CBC128),
1559 			    PKCS11Constants.NAME_CKM_BATON_CBC128);
1560 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_BATON_COUNTER),
1561 			    PKCS11Constants.NAME_CKM_BATON_COUNTER);
1562 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_BATON_SHUFFLE),
1563 			    PKCS11Constants.NAME_CKM_BATON_SHUFFLE);
1564 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_JUNIPER_ECB128),
1565 			    PKCS11Constants.NAME_CKM_JUNIPER_ECB128);
1566 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_JUNIPER_CBC128),
1567 			    PKCS11Constants.NAME_CKM_JUNIPER_CBC128);
1568 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_JUNIPER_COUNTER),
1569 			    PKCS11Constants.NAME_CKM_JUNIPER_COUNTER);
1570 			fullEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_JUNIPER_SHUFFLE),
1571 			    PKCS11Constants.NAME_CKM_JUNIPER_SHUFFLE);
1572 			fullEncryptDecryptMechanisms_ = fullEncryptDecryptMechanisms;
1573 		}
1574 
1575 		return fullEncryptDecryptMechanisms_.containsKey(new Long(mechanismCode));
1576 	}
1577 
1578 	/**
1579 	 * This method checks, if the mechanism with the given code is a
1580 	 * single-operation encrypt/decrypt mechanism; i.e. it does not support the
1581 	 * encryptUpdate() and decryptUpdate() functions.
1582 	 * This is the information as provided by the table on page 229
1583 	 * of the PKCS#11 v2.11 standard.
1584 	 * If this method returns true, the mechanism can be used with the encrypt and
1585 	 * decrypt functions excluding encryptUpdate and decryptUpdate.
1586 	 *
1587 	 * @param mechanismCode The code of the mechanism to check.
1588 	 * @return True, if the provided mechanism is a single-operation
1589 	 *         encrypt/decrypt mechanism. False, otherwise.
1590 	 * @preconditions
1591 	 * @postconditions
1592 	 */
isSingleOperationEncryptDecryptMechanism(long mechanismCode)1593 	public static boolean isSingleOperationEncryptDecryptMechanism(long mechanismCode) {
1594 		// build the hashtable on demand (=first use)
1595 		if (singleOperationEncryptDecryptMechanisms_ == null) {
1596 			Hashtable singleOperationEncryptDecryptMechanisms = new Hashtable();
1597 			singleOperationEncryptDecryptMechanisms.put(new Long(PKCS11Constants.CKM_RSA_PKCS),
1598 			    PKCS11Constants.NAME_CKM_RSA_PKCS);
1599 			singleOperationEncryptDecryptMechanisms.put(new Long(
1600 			    PKCS11Constants.CKM_RSA_PKCS_OAEP), PKCS11Constants.NAME_CKM_RSA_PKCS_OAEP);
1601 			singleOperationEncryptDecryptMechanisms.put(
1602 			    new Long(PKCS11Constants.CKM_RSA_X_509), PKCS11Constants.NAME_CKM_RSA_X_509);
1603 			singleOperationEncryptDecryptMechanisms_ = singleOperationEncryptDecryptMechanisms;
1604 		}
1605 
1606 		return singleOperationEncryptDecryptMechanisms_.containsKey(new Long(mechanismCode));
1607 	}
1608 
1609 	/**
1610 	 * This method checks, if the mechanism with the given code is a full
1611 	 * sign/verify mechanism; i.e. it supports the signUpdate()
1612 	 * and verifyUpdate() functions.
1613 	 * This is the information as provided by the table on page 229
1614 	 * of the PKCS#11 v2.11 standard.
1615 	 * If this method returns true, the mechanism can be used with the sign and
1616 	 * verify functions including signUpdate and verifyUpdate.
1617 	 *
1618 	 * @param mechanismCode The code of the mechanism to check.
1619 	 * @return True, if the provided mechanism is a full sign/verify
1620 	 *         mechanism. False, otherwise.
1621 	 * @preconditions
1622 	 * @postconditions
1623 	 */
isFullSignVerifyMechanism(long mechanismCode)1624 	public static boolean isFullSignVerifyMechanism(long mechanismCode) {
1625 		// build the hashtable on demand (=first use)
1626 		if (fullSignVerifyMechanisms_ == null) {
1627 			Hashtable fullSignVerifyMechanisms = new Hashtable();
1628 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_MD2_RSA_PKCS),
1629 			    PKCS11Constants.NAME_CKM_MD2_RSA_PKCS);
1630 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_MD5_RSA_PKCS),
1631 			    PKCS11Constants.NAME_CKM_MD5_RSA_PKCS);
1632 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA1_RSA_PKCS),
1633 			    PKCS11Constants.NAME_CKM_SHA1_RSA_PKCS);
1634 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD128_RSA_PKCS),
1635 			    PKCS11Constants.NAME_CKM_RIPEMD128_RSA_PKCS);
1636 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD160_RSA_PKCS),
1637 			    PKCS11Constants.NAME_CKM_RIPEMD160_RSA_PKCS);
1638 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA1_RSA_PKCS_PSS),
1639 			    PKCS11Constants.NAME_CKM_SHA1_RSA_PKCS_PSS);
1640 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA1_RSA_X9_31),
1641 			    PKCS11Constants.NAME_CKM_SHA1_RSA_X9_31);
1642 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_DSA_SHA1),
1643 			    PKCS11Constants.NAME_CKM_DSA_SHA1);
1644 
1645 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA256_RSA_PKCS),
1646 			    PKCS11Constants.NAME_CKM_SHA256_RSA_PKCS);
1647 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA384_RSA_PKCS),
1648 			    PKCS11Constants.NAME_CKM_SHA384_RSA_PKCS);
1649 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA512_RSA_PKCS),
1650 			    PKCS11Constants.NAME_CKM_SHA512_RSA_PKCS);
1651 
1652 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA256_RSA_PKCS_PSS),
1653 			    PKCS11Constants.NAME_CKM_SHA256_RSA_PKCS_PSS);
1654 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA384_RSA_PKCS_PSS),
1655 			    PKCS11Constants.NAME_CKM_SHA384_RSA_PKCS_PSS);
1656 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA512_RSA_PKCS_PSS),
1657 			    PKCS11Constants.NAME_CKM_SHA512_RSA_PKCS_PSS);
1658 
1659 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RC2_MAC),
1660 			    PKCS11Constants.NAME_CKM_RC2_MAC);
1661 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RC2_MAC_GENERAL),
1662 			    PKCS11Constants.NAME_CKM_RC2_MAC_GENERAL);
1663 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_DES_MAC),
1664 			    PKCS11Constants.NAME_CKM_DES_MAC);
1665 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_DES_MAC_GENERAL),
1666 			    PKCS11Constants.NAME_CKM_DES_MAC_GENERAL);
1667 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_DES3_MAC),
1668 			    PKCS11Constants.NAME_CKM_DES3_MAC);
1669 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_DES3_MAC_GENERAL),
1670 			    PKCS11Constants.NAME_CKM_DES3_MAC_GENERAL);
1671 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_MAC),
1672 			    PKCS11Constants.NAME_CKM_CDMF_MAC);
1673 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_MAC_GENERAL),
1674 			    PKCS11Constants.NAME_CKM_CDMF_MAC_GENERAL);
1675 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_MD2_HMAC),
1676 			    PKCS11Constants.NAME_CKM_MD2_HMAC);
1677 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_MD2_HMAC_GENERAL),
1678 			    PKCS11Constants.NAME_CKM_MD2_HMAC_GENERAL);
1679 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_MD5_HMAC),
1680 			    PKCS11Constants.NAME_CKM_MD5_HMAC);
1681 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_MD5_HMAC_GENERAL),
1682 			    PKCS11Constants.NAME_CKM_MD5_HMAC_GENERAL);
1683 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA_1_HMAC),
1684 			    PKCS11Constants.NAME_CKM_SHA_1_HMAC);
1685 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA_1_HMAC_GENERAL),
1686 			    PKCS11Constants.NAME_CKM_SHA_1_HMAC_GENERAL);
1687 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD128_HMAC),
1688 			    PKCS11Constants.NAME_CKM_RIPEMD128_HMAC);
1689 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD128_HMAC_GENERAL),
1690 			    PKCS11Constants.NAME_CKM_RIPEMD128_HMAC_GENERAL);
1691 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD160_HMAC),
1692 			    PKCS11Constants.NAME_CKM_RIPEMD160_HMAC);
1693 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD160_HMAC_GENERAL),
1694 			    PKCS11Constants.NAME_CKM_RIPEMD160_HMAC_GENERAL);
1695 
1696 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA256_HMAC),
1697 			    PKCS11Constants.NAME_CKM_SHA256_HMAC);
1698 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA256_HMAC_GENERAL),
1699 			    PKCS11Constants.NAME_CKM_SHA256_HMAC_GENERAL);
1700 
1701 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA384_HMAC),
1702 			    PKCS11Constants.NAME_CKM_SHA384_HMAC);
1703 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA384_HMAC_GENERAL),
1704 			    PKCS11Constants.NAME_CKM_SHA384_HMAC_GENERAL);
1705 
1706 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA512_HMAC),
1707 			    PKCS11Constants.NAME_CKM_SHA512_HMAC);
1708 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SHA512_HMAC_GENERAL),
1709 			    PKCS11Constants.NAME_CKM_SHA512_HMAC_GENERAL);
1710 
1711 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST_MAC),
1712 			    PKCS11Constants.NAME_CKM_CAST_MAC);
1713 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST_MAC_GENERAL),
1714 			    PKCS11Constants.NAME_CKM_CAST_MAC_GENERAL);
1715 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_MAC),
1716 			    PKCS11Constants.NAME_CKM_CAST3_MAC);
1717 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_MAC_GENERAL),
1718 			    PKCS11Constants.NAME_CKM_CAST3_MAC_GENERAL);
1719 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_MAC),
1720 			    PKCS11Constants.NAME_CKM_CAST5_MAC);
1721 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_MAC),
1722 			    PKCS11Constants.NAME_CKM_CAST128_MAC);
1723 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_MAC_GENERAL),
1724 			    PKCS11Constants.NAME_CKM_CAST5_MAC_GENERAL);
1725 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_MAC_GENERAL),
1726 			    PKCS11Constants.NAME_CKM_CAST128_MAC_GENERAL);
1727 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RC5_MAC),
1728 			    PKCS11Constants.NAME_CKM_RC5_MAC);
1729 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RC5_MAC_GENERAL),
1730 			    PKCS11Constants.NAME_CKM_RC5_MAC_GENERAL);
1731 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_AES_MAC),
1732 			    PKCS11Constants.NAME_CKM_AES_MAC);
1733 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_AES_MAC_GENERAL),
1734 			    PKCS11Constants.NAME_CKM_AES_MAC_GENERAL);
1735 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_MAC),
1736 			    PKCS11Constants.NAME_CKM_IDEA_MAC);
1737 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_MAC_GENERAL),
1738 			    PKCS11Constants.NAME_CKM_IDEA_MAC_GENERAL);
1739 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SSL3_MD5_MAC),
1740 			    PKCS11Constants.NAME_CKM_SSL3_MD5_MAC);
1741 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_SSL3_SHA1_MAC),
1742 			    PKCS11Constants.NAME_CKM_SSL3_SHA1_MAC);
1743 			fullSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_ECDSA_SHA1),
1744 			    PKCS11Constants.NAME_CKM_ECDSA_SHA1);
1745 			fullSignVerifyMechanisms_ = fullSignVerifyMechanisms;
1746 		}
1747 
1748 		return fullSignVerifyMechanisms_.containsKey(new Long(mechanismCode));
1749 	}
1750 
1751 	/**
1752 	 * This method checks, if the mechanism with the given code is a
1753 	 * single-operation sign/verify mechanism; i.e. it does not support the
1754 	 * signUpdate() and encryptUpdate() functions.
1755 	 * This is the information as provided by the table on page 229
1756 	 * of the PKCS#11 v2.11 standard.
1757 	 * If this method returns true, the mechanism can be used with the sign and
1758 	 * verify functions excluding signUpdate and encryptUpdate.
1759 	 *
1760 	 * @param mechanismCode The code of the mechanism to check.
1761 	 * @return True, if the provided mechanism is a single-operation
1762 	 *         sign/verify mechanism. False, otherwise.
1763 	 * @preconditions
1764 	 * @postconditions
1765 	 */
isSingleOperationSignVerifyMechanism(long mechanismCode)1766 	public static boolean isSingleOperationSignVerifyMechanism(long mechanismCode) {
1767 		// build the hashtable on demand (=first use)
1768 		if (singleOperationSignVerifyMechanisms_ == null) {
1769 			Hashtable singleOperationSignVerifyMechanisms = new Hashtable();
1770 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RSA_PKCS),
1771 			    PKCS11Constants.NAME_CKM_RSA_PKCS);
1772 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RSA_PKCS_PSS),
1773 			    PKCS11Constants.NAME_CKM_RSA_PKCS_PSS);
1774 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RSA_9796),
1775 			    PKCS11Constants.NAME_CKM_RSA_9796);
1776 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RSA_X_509),
1777 			    PKCS11Constants.NAME_CKM_RSA_X_509);
1778 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_RSA_X9_31),
1779 			    PKCS11Constants.NAME_CKM_RSA_X9_31);
1780 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_DSA),
1781 			    PKCS11Constants.NAME_CKM_DSA);
1782 			singleOperationSignVerifyMechanisms.put(new Long(
1783 			    PKCS11Constants.CKM_FORTEZZA_TIMESTAMP),
1784 			    PKCS11Constants.NAME_CKM_FORTEZZA_TIMESTAMP);
1785 			singleOperationSignVerifyMechanisms.put(new Long(PKCS11Constants.CKM_ECDSA),
1786 			    PKCS11Constants.NAME_CKM_ECDSA);
1787 			singleOperationSignVerifyMechanisms_ = singleOperationSignVerifyMechanisms;
1788 		}
1789 
1790 		return singleOperationSignVerifyMechanisms_.containsKey(new Long(mechanismCode));
1791 	}
1792 
1793 	/**
1794 	 * This method checks, if the mechanism with the given code is a sign/verify
1795 	 * mechanism with message recovery.
1796 	 * This is the information as provided by the table on page 229
1797 	 * of the PKCS#11 v2.11 standard.
1798 	 * If this method returns true, the mechanism can be used with the signRecover
1799 	 * and verifyRecover functions.
1800 	 *
1801 	 * @param mechanismCode The code of the mechanism to check.
1802 	 * @return True, if the provided mechanism is a sign/verify mechanism with
1803 	 *         message recovery. False, otherwise.
1804 	 * @preconditions
1805 	 * @postconditions
1806 	 */
isSignVerifyRecoverMechanism(long mechanismCode)1807 	public static boolean isSignVerifyRecoverMechanism(long mechanismCode) {
1808 		// build the hashtable on demand (=first use)
1809 		if (signVerifyRecoverMechanisms_ == null) {
1810 			Hashtable signVerifyRecoverMechanisms = new Hashtable();
1811 			signVerifyRecoverMechanisms.put(new Long(PKCS11Constants.CKM_RSA_PKCS),
1812 			    PKCS11Constants.NAME_CKM_RSA_PKCS);
1813 			signVerifyRecoverMechanisms.put(new Long(PKCS11Constants.CKM_RSA_9796),
1814 			    PKCS11Constants.NAME_CKM_RSA_9796);
1815 			signVerifyRecoverMechanisms.put(new Long(PKCS11Constants.CKM_RSA_X_509),
1816 			    PKCS11Constants.NAME_CKM_RSA_X_509);
1817 			signVerifyRecoverMechanisms_ = signVerifyRecoverMechanisms;
1818 		}
1819 
1820 		return signVerifyRecoverMechanisms_.containsKey(new Long(mechanismCode));
1821 	}
1822 
1823 	/**
1824 	 * This method checks, if the mechanism with the given code is a digest
1825 	 * mechanism.
1826 	 * This is the information as provided by the table on page 229
1827 	 * of the PKCS#11 v2.11 standard.
1828 	 * If this method returns true, the mechanism can be used with the digest
1829 	 * functions.
1830 	 *
1831 	 * @param mechanismCode The code of the mechanism to check.
1832 	 * @return True, if the provided mechanism is a digest mechanism. False,
1833 	 *         otherwise.
1834 	 * @preconditions
1835 	 * @postconditions
1836 	 */
isDigestMechanism(long mechanismCode)1837 	public static boolean isDigestMechanism(long mechanismCode) {
1838 		// build the hashtable on demand (=first use)
1839 		if (digestMechanisms_ == null) {
1840 			Hashtable digestMechanisms = new Hashtable();
1841 			digestMechanisms.put(new Long(PKCS11Constants.CKM_MD2),
1842 			    PKCS11Constants.NAME_CKM_MD2);
1843 			digestMechanisms.put(new Long(PKCS11Constants.CKM_MD5),
1844 			    PKCS11Constants.NAME_CKM_MD5);
1845 			digestMechanisms.put(new Long(PKCS11Constants.CKM_SHA_1),
1846 			    PKCS11Constants.NAME_CKM_SHA_1);
1847 			digestMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD128),
1848 			    PKCS11Constants.NAME_CKM_RIPEMD128);
1849 			digestMechanisms.put(new Long(PKCS11Constants.CKM_RIPEMD160),
1850 			    PKCS11Constants.NAME_CKM_RIPEMD160);
1851 			digestMechanisms.put(new Long(PKCS11Constants.CKM_SHA256),
1852 			    PKCS11Constants.NAME_CKM_SHA256);
1853 			digestMechanisms.put(new Long(PKCS11Constants.CKM_SHA384),
1854 			    PKCS11Constants.NAME_CKM_SHA384);
1855 			digestMechanisms.put(new Long(PKCS11Constants.CKM_SHA512),
1856 			    PKCS11Constants.NAME_CKM_SHA512);
1857 			digestMechanisms.put(new Long(PKCS11Constants.CKM_FASTHASH),
1858 			    PKCS11Constants.NAME_CKM_FASTHASH);
1859 			digestMechanisms_ = digestMechanisms;
1860 		}
1861 
1862 		return digestMechanisms_.containsKey(new Long(mechanismCode));
1863 	}
1864 
1865 	/**
1866 	 * This method checks, if the mechanism with the given code is a key
1867 	 * generation mechanism for generating symmetric keys.
1868 	 * This is the information as provided by the table on page 229
1869 	 * of the PKCS#11 v2.11 standard.
1870 	 * If this method returns true, the mechanism can be used with the generateKey
1871 	 * function.
1872 	 *
1873 	 * @param mechanismCode The code of the mechanism to check.
1874 	 * @return True, if the provided mechanism is a key generation mechanism.
1875 	 *         False, otherwise.
1876 	 * @preconditions
1877 	 * @postconditions
1878 	 */
isKeyGenerationMechanism(long mechanismCode)1879 	public static boolean isKeyGenerationMechanism(long mechanismCode) {
1880 		// build the hashtable on demand (=first use)
1881 		if (keyGenerationMechanisms_ == null) {
1882 			Hashtable keyGenerationMechanisms = new Hashtable();
1883 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DSA_PARAMETER_GEN),
1884 			    PKCS11Constants.NAME_CKM_DSA_PARAMETER_GEN);
1885 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DH_PKCS_PARAMETER_GEN),
1886 			    PKCS11Constants.NAME_CKM_DH_PKCS_PARAMETER_GEN);
1887 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_X9_42_DH_PARAMETER_GEN),
1888 			    PKCS11Constants.NAME_CKM_X9_42_DH_PARAMETER_GEN);
1889 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_RC2_KEY_GEN),
1890 			    PKCS11Constants.NAME_CKM_RC2_KEY_GEN);
1891 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_RC4_KEY_GEN),
1892 			    PKCS11Constants.NAME_CKM_RC4_KEY_GEN);
1893 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DES_KEY_GEN),
1894 			    PKCS11Constants.NAME_CKM_DES_KEY_GEN);
1895 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DES2_KEY_GEN),
1896 			    PKCS11Constants.NAME_CKM_DES2_KEY_GEN);
1897 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DES3_KEY_GEN),
1898 			    PKCS11Constants.NAME_CKM_DES3_KEY_GEN);
1899 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_KEY_GEN),
1900 			    PKCS11Constants.NAME_CKM_CDMF_KEY_GEN);
1901 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_CAST_KEY_GEN),
1902 			    PKCS11Constants.NAME_CKM_CAST_KEY_GEN);
1903 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_KEY_GEN),
1904 			    PKCS11Constants.NAME_CKM_CAST3_KEY_GEN);
1905 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_KEY_GEN),
1906 			    PKCS11Constants.NAME_CKM_CAST5_KEY_GEN);
1907 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_KEY_GEN),
1908 			    PKCS11Constants.NAME_CKM_CAST128_KEY_GEN);
1909 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_RC5_KEY_GEN),
1910 			    PKCS11Constants.NAME_CKM_RC5_KEY_GEN);
1911 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_AES_KEY_GEN),
1912 			    PKCS11Constants.NAME_CKM_AES_KEY_GEN);
1913 
1914 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_BLOWFISH_KEY_GEN),
1915 			    PKCS11Constants.NAME_CKM_BLOWFISH_KEY_GEN);
1916 
1917 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_TWOFISH_KEY_GEN),
1918 			    PKCS11Constants.NAME_CKM_TWOFISH_KEY_GEN);
1919 
1920 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_KEY_GEN),
1921 			    PKCS11Constants.NAME_CKM_IDEA_KEY_GEN);
1922 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_GENERIC_SECRET_KEY_GEN),
1923 			    PKCS11Constants.NAME_CKM_GENERIC_SECRET_KEY_GEN);
1924 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_SSL3_PRE_MASTER_KEY_GEN),
1925 			    PKCS11Constants.NAME_CKM_SSL3_PRE_MASTER_KEY_GEN);
1926 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_TLS_PRE_MASTER_KEY_GEN),
1927 			    PKCS11Constants.NAME_CKM_TLS_PRE_MASTER_KEY_GEN);
1928 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_MD2_DES_CBC),
1929 			    PKCS11Constants.NAME_CKM_PBE_MD2_DES_CBC);
1930 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_MD5_DES_CBC),
1931 			    PKCS11Constants.NAME_CKM_PBE_MD5_DES_CBC);
1932 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST_CBC),
1933 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST_CBC);
1934 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST3_CBC),
1935 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST3_CBC);
1936 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST5_CBC),
1937 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST5_CBC);
1938 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_MD5_CAST128_CBC),
1939 			    PKCS11Constants.NAME_CKM_PBE_MD5_CAST128_CBC);
1940 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_CAST5_CBC),
1941 			    PKCS11Constants.NAME_CKM_PBE_SHA1_CAST5_CBC);
1942 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_CAST128_CBC),
1943 			    PKCS11Constants.NAME_CKM_PBE_SHA1_CAST128_CBC);
1944 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC4_128),
1945 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC4_128);
1946 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC4_40),
1947 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC4_40);
1948 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_DES3_EDE_CBC),
1949 			    PKCS11Constants.NAME_CKM_PBE_SHA1_DES3_EDE_CBC);
1950 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_DES2_EDE_CBC),
1951 			    PKCS11Constants.NAME_CKM_PBE_SHA1_DES2_EDE_CBC);
1952 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC2_128_CBC),
1953 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC2_128_CBC);
1954 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBE_SHA1_RC2_40_CBC),
1955 			    PKCS11Constants.NAME_CKM_PBE_SHA1_RC2_40_CBC);
1956 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PKCS5_PBKD2),
1957 			    PKCS11Constants.NAME_CKM_PKCS5_PBKD2);
1958 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_PBA_SHA1_WITH_SHA1_HMAC),
1959 			    PKCS11Constants.NAME_CKM_PBA_SHA1_WITH_SHA1_HMAC);
1960 
1961 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_WTLS_PRE_MASTER_KEY_GEN),
1962 			    PKCS11Constants.NAME_CKM_WTLS_PRE_MASTER_KEY_GEN);
1963 
1964 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_KEY_GEN),
1965 			    PKCS11Constants.NAME_CKM_SKIPJACK_KEY_GEN);
1966 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_BATON_KEY_GEN),
1967 			    PKCS11Constants.NAME_CKM_BATON_KEY_GEN);
1968 			keyGenerationMechanisms.put(new Long(PKCS11Constants.CKM_JUNIPER_KEY_GEN),
1969 			    PKCS11Constants.NAME_CKM_JUNIPER_KEY_GEN);
1970 			keyGenerationMechanisms_ = keyGenerationMechanisms;
1971 		}
1972 
1973 		return keyGenerationMechanisms_.containsKey(new Long(mechanismCode));
1974 	}
1975 
1976 	/**
1977 	 * This method checks, if the mechanism with the given code is a key-pair
1978 	 * generation mechanism for generating key-pairs.
1979 	 * This is the information as provided by the table on page 229
1980 	 * of the PKCS#11 v2.11 standard.
1981 	 * If this method returns true, the mechanism can be used with the generateKeyPair
1982 	 * function.
1983 	 *
1984 	 * @param mechanismCode The code of the mechanism to check.
1985 	 * @return True, if the provided mechanism is a key-pair generation mechanism.
1986 	 *         False, otherwise.
1987 	 * @preconditions
1988 	 * @postconditions
1989 	 */
isKeyPairGenerationMechanism(long mechanismCode)1990 	public static boolean isKeyPairGenerationMechanism(long mechanismCode) {
1991 		// build the hashtable on demand (=first use)
1992 		if (keyPairGenerationMechanisms_ == null) {
1993 			Hashtable keyPairGenerationMechanisms = new Hashtable();
1994 			keyPairGenerationMechanisms.put(
1995 			    new Long(PKCS11Constants.CKM_RSA_PKCS_KEY_PAIR_GEN),
1996 			    PKCS11Constants.NAME_CKM_RSA_PKCS_KEY_PAIR_GEN);
1997 			keyPairGenerationMechanisms.put(
1998 			    new Long(PKCS11Constants.CKM_RSA_X9_31_KEY_PAIR_GEN),
1999 			    PKCS11Constants.NAME_CKM_RSA_X9_31_KEY_PAIR_GEN);
2000 			keyPairGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DSA_KEY_PAIR_GEN),
2001 			    PKCS11Constants.NAME_CKM_DSA_KEY_PAIR_GEN);
2002 			keyPairGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DH_PKCS_KEY_PAIR_GEN),
2003 			    PKCS11Constants.NAME_CKM_DH_PKCS_KEY_PAIR_GEN);
2004 			keyPairGenerationMechanisms.put(new Long(PKCS11Constants.CKM_KEA_KEY_PAIR_GEN),
2005 			    PKCS11Constants.NAME_CKM_KEA_KEY_PAIR_GEN);
2006 			keyPairGenerationMechanisms.put(new Long(PKCS11Constants.CKM_ECDSA_KEY_PAIR_GEN),
2007 			    PKCS11Constants.NAME_CKM_ECDSA_KEY_PAIR_GEN);
2008 			keyPairGenerationMechanisms.put(new Long(PKCS11Constants.CKM_EC_KEY_PAIR_GEN),
2009 			    PKCS11Constants.NAME_CKM_EC_KEY_PAIR_GEN);
2010 			keyPairGenerationMechanisms.put(new Long(PKCS11Constants.CKM_DH_PKCS_KEY_PAIR_GEN),
2011 			    PKCS11Constants.NAME_CKM_DH_PKCS_KEY_PAIR_GEN);
2012 			keyPairGenerationMechanisms.put(
2013 			    new Long(PKCS11Constants.CKM_X9_42_DH_KEY_PAIR_GEN),
2014 			    PKCS11Constants.NAME_CKM_X9_42_DH_KEY_PAIR_GEN);
2015 			keyPairGenerationMechanisms_ = keyPairGenerationMechanisms;
2016 		}
2017 
2018 		return keyPairGenerationMechanisms_.containsKey(new Long(mechanismCode));
2019 	}
2020 
2021 	/**
2022 	 * This method checks, if the mechanism with the given code is a
2023 	 * wrap/unwrap mechanism; i.e. it supports the wrapKey()
2024 	 * and unwrapKey() functions.
2025 	 * This is the information as provided by the table on page 229
2026 	 * of the PKCS#11 v2.11 standard.
2027 	 * If this method returns true, the mechanism can be used with the wrapKey
2028 	 * and unwrapKey functions.
2029 	 *
2030 	 * @param mechanismCode The code of the mechanism to check.
2031 	 * @return True, if the provided mechanism is a wrap/unwrap mechanism.
2032 	 *         False, otherwise.
2033 	 * @preconditions
2034 	 * @postconditions
2035 	 */
isWrapUnwrapMechanism(long mechanismCode)2036 	public static boolean isWrapUnwrapMechanism(long mechanismCode) {
2037 		// build the hashtable on demand (=first use)
2038 		if (wrapUnwrapMechanisms_ == null) {
2039 			Hashtable wrapUnwrapMechanisms = new Hashtable();
2040 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RSA_PKCS),
2041 			    PKCS11Constants.NAME_CKM_RSA_PKCS);
2042 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RSA_X_509),
2043 			    PKCS11Constants.NAME_CKM_RSA_X_509);
2044 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RSA_PKCS_OAEP),
2045 			    PKCS11Constants.NAME_CKM_RSA_PKCS_OAEP);
2046 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RC2_ECB),
2047 			    PKCS11Constants.NAME_CKM_RC2_ECB);
2048 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RC2_CBC),
2049 			    PKCS11Constants.NAME_CKM_RC2_CBC);
2050 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RC2_CBC_PAD),
2051 			    PKCS11Constants.NAME_CKM_RC2_CBC_PAD);
2052 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_DES_ECB),
2053 			    PKCS11Constants.NAME_CKM_DES_ECB);
2054 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_DES_CBC),
2055 			    PKCS11Constants.NAME_CKM_DES_CBC);
2056 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_DES_CBC_PAD),
2057 			    PKCS11Constants.NAME_CKM_DES_CBC_PAD);
2058 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_DES3_ECB),
2059 			    PKCS11Constants.NAME_CKM_DES3_ECB);
2060 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_DES3_CBC),
2061 			    PKCS11Constants.NAME_CKM_DES3_CBC);
2062 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_DES3_CBC_PAD),
2063 			    PKCS11Constants.NAME_CKM_DES3_CBC_PAD);
2064 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_ECB),
2065 			    PKCS11Constants.NAME_CKM_CDMF_ECB);
2066 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_CBC),
2067 			    PKCS11Constants.NAME_CKM_CDMF_CBC);
2068 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CDMF_CBC_PAD),
2069 			    PKCS11Constants.NAME_CKM_CDMF_CBC_PAD);
2070 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST_ECB),
2071 			    PKCS11Constants.NAME_CKM_CAST_ECB);
2072 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST_CBC),
2073 			    PKCS11Constants.NAME_CKM_CAST_CBC);
2074 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST_CBC_PAD),
2075 			    PKCS11Constants.NAME_CKM_CAST_CBC_PAD);
2076 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_ECB),
2077 			    PKCS11Constants.NAME_CKM_CAST3_ECB);
2078 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_CBC),
2079 			    PKCS11Constants.NAME_CKM_CAST3_CBC);
2080 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST3_CBC_PAD),
2081 			    PKCS11Constants.NAME_CKM_CAST3_CBC_PAD);
2082 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_ECB),
2083 			    PKCS11Constants.NAME_CKM_CAST5_ECB);
2084 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_ECB),
2085 			    PKCS11Constants.NAME_CKM_CAST128_ECB);
2086 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_CBC),
2087 			    PKCS11Constants.NAME_CKM_CAST5_CBC);
2088 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_CBC),
2089 			    PKCS11Constants.NAME_CKM_CAST128_CBC);
2090 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST5_CBC_PAD),
2091 			    PKCS11Constants.NAME_CKM_CAST5_CBC_PAD);
2092 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_CAST128_CBC_PAD),
2093 			    PKCS11Constants.NAME_CKM_CAST128_CBC_PAD);
2094 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RC5_ECB),
2095 			    PKCS11Constants.NAME_CKM_RC5_ECB);
2096 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RC5_CBC),
2097 			    PKCS11Constants.NAME_CKM_RC5_CBC);
2098 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_RC5_CBC_PAD),
2099 			    PKCS11Constants.NAME_CKM_RC5_CBC_PAD);
2100 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_ECB),
2101 			    PKCS11Constants.NAME_CKM_IDEA_ECB);
2102 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_CBC),
2103 			    PKCS11Constants.NAME_CKM_IDEA_CBC);
2104 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_IDEA_CBC_PAD),
2105 			    PKCS11Constants.NAME_CKM_IDEA_CBC_PAD);
2106 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_KEY_WRAP_LYNKS),
2107 			    PKCS11Constants.NAME_CKM_KEY_WRAP_LYNKS);
2108 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_KEY_WRAP_SET_OAEP),
2109 			    PKCS11Constants.NAME_CKM_KEY_WRAP_SET_OAEP);
2110 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_WRAP),
2111 			    PKCS11Constants.NAME_CKM_SKIPJACK_WRAP);
2112 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_PRIVATE_WRAP),
2113 			    PKCS11Constants.NAME_CKM_SKIPJACK_PRIVATE_WRAP);
2114 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_SKIPJACK_RELAYX),
2115 			    PKCS11Constants.NAME_CKM_SKIPJACK_RELAYX);
2116 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_BATON_WRAP),
2117 			    PKCS11Constants.NAME_CKM_BATON_WRAP);
2118 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_JUNIPER_WRAP),
2119 			    PKCS11Constants.NAME_CKM_JUNIPER_WRAP);
2120 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_AES_ECB),
2121 			    PKCS11Constants.NAME_CKM_AES_ECB);
2122 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_AES_CBC),
2123 			    PKCS11Constants.NAME_CKM_AES_CBC);
2124 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_AES_CBC_PAD),
2125 			    PKCS11Constants.NAME_CKM_AES_CBC_PAD);
2126 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_BLOWFISH_CBC),
2127 			    PKCS11Constants.NAME_CKM_BLOWFISH_CBC);
2128 			wrapUnwrapMechanisms.put(new Long(PKCS11Constants.CKM_TWOFISH_CBC),
2129 			    PKCS11Constants.NAME_CKM_TWOFISH_CBC);
2130 			wrapUnwrapMechanisms_ = wrapUnwrapMechanisms;
2131 		}
2132 
2133 		return wrapUnwrapMechanisms_.containsKey(new Long(mechanismCode));
2134 	}
2135 
2136 	/**
2137 	 * This method checks, if the mechanism with the given code is a
2138 	 * key derivation mechanism.
2139 	 * This is the information as provided by the table on page 229
2140 	 * of the PKCS#11 v2.11 standard.
2141 	 * If this method returns true, the mechanism can be used with the deriveKey
2142 	 * function.
2143 	 *
2144 	 * @param mechanismCode The code of the mechanism to check.
2145 	 * @return True, if the provided mechanism is a key derivation mechanism.
2146 	 *         False, otherwise.
2147 	 * @preconditions
2148 	 * @postconditions
2149 	 */
isKeyDerivationMechanism(long mechanismCode)2150 	public static boolean isKeyDerivationMechanism(long mechanismCode) {
2151 		// build the hashtable on demand (=first use)
2152 		if (keyDerivationMechanisms_ == null) {
2153 			Hashtable keyDerivationMechanisms = new Hashtable();
2154 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_DH_PKCS_DERIVE),
2155 			    PKCS11Constants.NAME_CKM_DH_PKCS_DERIVE);
2156 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_CONCATENATE_BASE_AND_KEY),
2157 			    PKCS11Constants.NAME_CKM_CONCATENATE_BASE_AND_KEY);
2158 			keyDerivationMechanisms.put(
2159 			    new Long(PKCS11Constants.CKM_CONCATENATE_BASE_AND_DATA),
2160 			    PKCS11Constants.NAME_CKM_CONCATENATE_BASE_AND_DATA);
2161 			keyDerivationMechanisms.put(
2162 			    new Long(PKCS11Constants.CKM_CONCATENATE_DATA_AND_BASE),
2163 			    PKCS11Constants.NAME_CKM_CONCATENATE_DATA_AND_BASE);
2164 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_XOR_BASE_AND_DATA),
2165 			    PKCS11Constants.NAME_CKM_XOR_BASE_AND_DATA);
2166 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_EXTRACT_KEY_FROM_KEY),
2167 			    PKCS11Constants.NAME_CKM_EXTRACT_KEY_FROM_KEY);
2168 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_SSL3_MASTER_KEY_DERIVE),
2169 			    PKCS11Constants.NAME_CKM_SSL3_MASTER_KEY_DERIVE);
2170 			keyDerivationMechanisms.put(
2171 			    new Long(PKCS11Constants.CKM_SSL3_MASTER_KEY_DERIVE_DH),
2172 			    PKCS11Constants.NAME_CKM_SSL3_MASTER_KEY_DERIVE_DH);
2173 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_SSL3_KEY_AND_MAC_DERIVE),
2174 			    PKCS11Constants.NAME_CKM_SSL3_KEY_AND_MAC_DERIVE);
2175 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_TLS_MASTER_KEY_DERIVE),
2176 			    PKCS11Constants.NAME_CKM_TLS_MASTER_KEY_DERIVE);
2177 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_TLS_MASTER_KEY_DERIVE_DH),
2178 			    PKCS11Constants.NAME_CKM_TLS_MASTER_KEY_DERIVE_DH);
2179 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_TLS_KEY_AND_MAC_DERIVE),
2180 			    PKCS11Constants.NAME_CKM_TLS_KEY_AND_MAC_DERIVE);
2181 
2182 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_TLS_PRF),
2183 			    PKCS11Constants.NAME_CKM_TLS_PRF);
2184 
2185 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_MD5_KEY_DERIVATION),
2186 			    PKCS11Constants.NAME_CKM_MD5_KEY_DERIVATION);
2187 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_MD2_KEY_DERIVATION),
2188 			    PKCS11Constants.NAME_CKM_MD2_KEY_DERIVATION);
2189 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_SHA1_KEY_DERIVATION),
2190 			    PKCS11Constants.NAME_CKM_SHA1_KEY_DERIVATION);
2191 
2192 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_SHA256_KEY_DERIVATION),
2193 			    PKCS11Constants.NAME_CKM_SHA256_KEY_DERIVATION);
2194 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_SHA384_KEY_DERIVATION),
2195 			    PKCS11Constants.NAME_CKM_SHA384_KEY_DERIVATION);
2196 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_SHA512_KEY_DERIVATION),
2197 			    PKCS11Constants.NAME_CKM_SHA512_KEY_DERIVATION);
2198 
2199 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_WTLS_MASTER_KEY_DERIVE),
2200 			    PKCS11Constants.NAME_CKM_TLS_MASTER_KEY_DERIVE);
2201 			keyDerivationMechanisms.put(new Long(
2202 			    PKCS11Constants.CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC),
2203 			    PKCS11Constants.NAME_CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC);
2204 			keyDerivationMechanisms.put(new Long(
2205 			    PKCS11Constants.CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE),
2206 			    PKCS11Constants.NAME_CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE);
2207 			keyDerivationMechanisms.put(new Long(
2208 			    PKCS11Constants.CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE),
2209 			    PKCS11Constants.NAME_CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE);
2210 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_WTLS_PRF),
2211 			    PKCS11Constants.NAME_CKM_WTLS_PRF);
2212 
2213 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_KEA_KEY_DERIVE),
2214 			    PKCS11Constants.NAME_CKM_KEA_KEY_DERIVE);
2215 
2216 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_DES_ECB_ENCRYPT_DATA),
2217 			    PKCS11Constants.NAME_CKM_DES_ECB_ENCRYPT_DATA);
2218 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_DES_CBC_ENCRYPT_DATA),
2219 			    PKCS11Constants.NAME_CKM_DES_CBC_ENCRYPT_DATA);
2220 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_DES3_ECB_ENCRYPT_DATA),
2221 			    PKCS11Constants.NAME_CKM_DES3_ECB_ENCRYPT_DATA);
2222 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_DES3_CBC_ENCRYPT_DATA),
2223 			    PKCS11Constants.NAME_CKM_DES3_CBC_ENCRYPT_DATA);
2224 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_AES_ECB_ENCRYPT_DATA),
2225 			    PKCS11Constants.NAME_CKM_AES_ECB_ENCRYPT_DATA);
2226 			keyDerivationMechanisms.put(new Long(PKCS11Constants.CKM_AES_CBC_ENCRYPT_DATA),
2227 			    PKCS11Constants.NAME_CKM_AES_CBC_ENCRYPT_DATA);
2228 
2229 			keyDerivationMechanisms_ = keyDerivationMechanisms;
2230 		}
2231 
2232 		return keyDerivationMechanisms_.containsKey(new Long(mechanismCode));
2233 	}
2234 
2235 }
2236