17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5dec2a5a1Smcpowers * Common Development and Distribution License (the "License").
6dec2a5a1Smcpowers * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*d288ba74SAnthony Scarpino * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Convert Algorithm names as strings to PKCS#11 Mech numbers and vice versa.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
302321aa36Sda73024 #include <limits.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <security/cryptoki.h>
357c478bd9Sstevel@tonic-gate #include <security/pkcs11t.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include <cryptoutil.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /*
40dec2a5a1Smcpowers * This table is a one-to-one mapping between mechanism names and numbers.
41dec2a5a1Smcpowers * As such, it should not contain deprecated mechanism names (aliases).
427c478bd9Sstevel@tonic-gate */
432321aa36Sda73024 typedef struct {
447c478bd9Sstevel@tonic-gate const char *str;
457c478bd9Sstevel@tonic-gate CK_MECHANISM_TYPE mech;
462321aa36Sda73024 } pkcs11_mapping_t;
472321aa36Sda73024
482321aa36Sda73024 /*
492321aa36Sda73024 * Note: elements in this table MUST be in numeric order,
502321aa36Sda73024 * since bsearch(3C) is used to search this table.
512321aa36Sda73024 */
522321aa36Sda73024 static const pkcs11_mapping_t mapping[] = {
537c478bd9Sstevel@tonic-gate { "CKM_RSA_PKCS_KEY_PAIR_GEN", CKM_RSA_PKCS_KEY_PAIR_GEN },
547c478bd9Sstevel@tonic-gate { "CKM_RSA_PKCS", CKM_RSA_PKCS },
557c478bd9Sstevel@tonic-gate { "CKM_RSA_9796", CKM_RSA_9796 },
567c478bd9Sstevel@tonic-gate { "CKM_RSA_X_509", CKM_RSA_X_509 },
577c478bd9Sstevel@tonic-gate { "CKM_MD2_RSA_PKCS", CKM_MD2_RSA_PKCS },
587c478bd9Sstevel@tonic-gate { "CKM_MD5_RSA_PKCS", CKM_MD5_RSA_PKCS },
597c478bd9Sstevel@tonic-gate { "CKM_SHA1_RSA_PKCS", CKM_SHA1_RSA_PKCS },
607c478bd9Sstevel@tonic-gate { "CKM_RIPEMD128_RSA_PKCS", CKM_RIPEMD128_RSA_PKCS },
617c478bd9Sstevel@tonic-gate { "CKM_RIPEMD160_RSA_PKCS", CKM_RIPEMD160_RSA_PKCS },
627c478bd9Sstevel@tonic-gate { "CKM_RSA_PKCS_OAEP", CKM_RSA_PKCS_OAEP },
637c478bd9Sstevel@tonic-gate { "CKM_RSA_X9_31_KEY_PAIR_GEN", CKM_RSA_X9_31_KEY_PAIR_GEN },
647c478bd9Sstevel@tonic-gate { "CKM_RSA_X9_31", CKM_RSA_X9_31 },
657c478bd9Sstevel@tonic-gate { "CKM_SHA1_RSA_X9_31", CKM_SHA1_RSA_X9_31 },
667c478bd9Sstevel@tonic-gate { "CKM_RSA_PKCS_PSS", CKM_RSA_PKCS_PSS },
677c478bd9Sstevel@tonic-gate { "CKM_SHA1_RSA_PKCS_PSS", CKM_SHA1_RSA_PKCS_PSS },
687c478bd9Sstevel@tonic-gate { "CKM_DSA_KEY_PAIR_GEN", CKM_DSA_KEY_PAIR_GEN },
697c478bd9Sstevel@tonic-gate { "CKM_DSA", CKM_DSA },
707c478bd9Sstevel@tonic-gate { "CKM_DSA_SHA1", CKM_DSA_SHA1 },
717c478bd9Sstevel@tonic-gate { "CKM_DH_PKCS_KEY_PAIR_GEN", CKM_DH_PKCS_KEY_PAIR_GEN },
727c478bd9Sstevel@tonic-gate { "CKM_DH_PKCS_DERIVE", CKM_DH_PKCS_DERIVE },
737c478bd9Sstevel@tonic-gate { "CKM_X9_42_DH_KEY_PAIR_GEN", CKM_X9_42_DH_KEY_PAIR_GEN },
747c478bd9Sstevel@tonic-gate { "CKM_X9_42_DH_DERIVE", CKM_X9_42_DH_DERIVE },
757c478bd9Sstevel@tonic-gate { "CKM_X9_42_DH_HYBRID_DERIVE", CKM_X9_42_DH_HYBRID_DERIVE },
767c478bd9Sstevel@tonic-gate { "CKM_X9_42_MQV_DERIVE", CKM_X9_42_MQV_DERIVE },
77f66d273dSizick { "CKM_SHA256_RSA_PKCS", CKM_SHA256_RSA_PKCS },
78f66d273dSizick { "CKM_SHA384_RSA_PKCS", CKM_SHA384_RSA_PKCS },
79f66d273dSizick { "CKM_SHA512_RSA_PKCS", CKM_SHA512_RSA_PKCS },
80f66d273dSizick { "CKM_SHA256_RSA_PKCS_PSS", CKM_SHA256_RSA_PKCS_PSS },
81f66d273dSizick { "CKM_SHA384_RSA_PKCS_PSS", CKM_SHA384_RSA_PKCS_PSS },
82f66d273dSizick { "CKM_SHA512_RSA_PKCS_PSS", CKM_SHA512_RSA_PKCS_PSS },
831e9884acSmcpowers { "CKM_SHA224_RSA_PKCS", CKM_SHA224_RSA_PKCS },
841e9884acSmcpowers { "CKM_SHA224_RSA_PKCS_PSS", CKM_SHA224_RSA_PKCS_PSS },
857c478bd9Sstevel@tonic-gate { "CKM_RC2_KEY_GEN", CKM_RC2_KEY_GEN },
867c478bd9Sstevel@tonic-gate { "CKM_RC2_ECB", CKM_RC2_ECB },
877c478bd9Sstevel@tonic-gate { "CKM_RC2_CBC", CKM_RC2_CBC },
887c478bd9Sstevel@tonic-gate { "CKM_RC2_MAC", CKM_RC2_MAC },
897c478bd9Sstevel@tonic-gate { "CKM_RC2_MAC_GENERAL", CKM_RC2_MAC_GENERAL },
907c478bd9Sstevel@tonic-gate { "CKM_RC2_CBC_PAD", CKM_RC2_CBC_PAD },
917c478bd9Sstevel@tonic-gate { "CKM_RC4_KEY_GEN", CKM_RC4_KEY_GEN },
927c478bd9Sstevel@tonic-gate { "CKM_RC4", CKM_RC4 },
937c478bd9Sstevel@tonic-gate { "CKM_DES_KEY_GEN", CKM_DES_KEY_GEN },
947c478bd9Sstevel@tonic-gate { "CKM_DES_ECB", CKM_DES_ECB },
957c478bd9Sstevel@tonic-gate { "CKM_DES_CBC", CKM_DES_CBC },
967c478bd9Sstevel@tonic-gate { "CKM_DES_MAC", CKM_DES_MAC },
977c478bd9Sstevel@tonic-gate { "CKM_DES_MAC_GENERAL", CKM_DES_MAC_GENERAL },
987c478bd9Sstevel@tonic-gate { "CKM_DES_CBC_PAD", CKM_DES_CBC_PAD },
997c478bd9Sstevel@tonic-gate { "CKM_DES2_KEY_GEN", CKM_DES2_KEY_GEN },
1007c478bd9Sstevel@tonic-gate { "CKM_DES3_KEY_GEN", CKM_DES3_KEY_GEN },
1017c478bd9Sstevel@tonic-gate { "CKM_DES3_ECB", CKM_DES3_ECB },
1027c478bd9Sstevel@tonic-gate { "CKM_DES3_CBC", CKM_DES3_CBC },
1037c478bd9Sstevel@tonic-gate { "CKM_DES3_MAC", CKM_DES3_MAC },
1047c478bd9Sstevel@tonic-gate { "CKM_DES3_MAC_GENERAL", CKM_DES3_MAC_GENERAL },
1057c478bd9Sstevel@tonic-gate { "CKM_DES3_CBC_PAD", CKM_DES3_CBC_PAD },
1067c478bd9Sstevel@tonic-gate { "CKM_CDMF_KEY_GEN", CKM_CDMF_KEY_GEN },
1077c478bd9Sstevel@tonic-gate { "CKM_CDMF_ECB", CKM_CDMF_ECB },
1087c478bd9Sstevel@tonic-gate { "CKM_CDMF_CBC", CKM_CDMF_CBC },
1097c478bd9Sstevel@tonic-gate { "CKM_CDMF_MAC", CKM_CDMF_MAC },
1107c478bd9Sstevel@tonic-gate { "CKM_CDMF_MAC_GENERAL", CKM_CDMF_MAC_GENERAL },
1117c478bd9Sstevel@tonic-gate { "CKM_CDMF_CBC_PAD", CKM_CDMF_CBC_PAD },
112f66d273dSizick { "CKM_DES_OFB64", CKM_DES_OFB64 },
113f66d273dSizick { "CKM_DES_OFB8", CKM_DES_OFB8 },
114f66d273dSizick { "CKM_DES_CFB64", CKM_DES_CFB64 },
115f66d273dSizick { "CKM_DES_CFB8", CKM_DES_CFB8 },
1167c478bd9Sstevel@tonic-gate { "CKM_MD2", CKM_MD2 },
1177c478bd9Sstevel@tonic-gate { "CKM_MD2_HMAC", CKM_MD2_HMAC },
1187c478bd9Sstevel@tonic-gate { "CKM_MD2_HMAC_GENERAL", CKM_MD2_HMAC_GENERAL },
1197c478bd9Sstevel@tonic-gate { "CKM_MD5", CKM_MD5 },
1207c478bd9Sstevel@tonic-gate { "CKM_MD5_HMAC", CKM_MD5_HMAC },
1217c478bd9Sstevel@tonic-gate { "CKM_MD5_HMAC_GENERAL", CKM_MD5_HMAC_GENERAL },
1227c478bd9Sstevel@tonic-gate { "CKM_SHA_1", CKM_SHA_1 },
1237c478bd9Sstevel@tonic-gate { "CKM_SHA_1_HMAC", CKM_SHA_1_HMAC },
1247c478bd9Sstevel@tonic-gate { "CKM_SHA_1_HMAC_GENERAL", CKM_SHA_1_HMAC_GENERAL },
1257c478bd9Sstevel@tonic-gate { "CKM_RIPEMD128", CKM_RIPEMD128 },
1267c478bd9Sstevel@tonic-gate { "CKM_RIPEMD128_HMAC", CKM_RIPEMD128_HMAC },
1277c478bd9Sstevel@tonic-gate { "CKM_RIPEMD128_HMAC_GENERAL", CKM_RIPEMD128_HMAC_GENERAL },
1287c478bd9Sstevel@tonic-gate { "CKM_RIPEMD160", CKM_RIPEMD160 },
1297c478bd9Sstevel@tonic-gate { "CKM_RIPEMD160_HMAC", CKM_RIPEMD160_HMAC },
1307c478bd9Sstevel@tonic-gate { "CKM_RIPEMD160_HMAC_GENERAL", CKM_RIPEMD160_HMAC_GENERAL },
131f66d273dSizick { "CKM_SHA256", CKM_SHA256 },
132f66d273dSizick { "CKM_SHA256_HMAC", CKM_SHA256_HMAC },
133f66d273dSizick { "CKM_SHA256_HMAC_GENERAL", CKM_SHA256_HMAC_GENERAL },
1341e9884acSmcpowers { "CKM_SHA224", CKM_SHA224 },
1351e9884acSmcpowers { "CKM_SHA224_HMAC", CKM_SHA224_HMAC },
1361e9884acSmcpowers { "CKM_SHA224_HMAC_GENERAL", CKM_SHA224_HMAC_GENERAL },
137f66d273dSizick { "CKM_SHA384", CKM_SHA384 },
138f66d273dSizick { "CKM_SHA384_HMAC", CKM_SHA384_HMAC },
139f66d273dSizick { "CKM_SHA384_HMAC_GENERAL", CKM_SHA384_HMAC_GENERAL },
140f66d273dSizick { "CKM_SHA512", CKM_SHA512 },
141f66d273dSizick { "CKM_SHA512_HMAC", CKM_SHA512_HMAC },
142f66d273dSizick { "CKM_SHA512_HMAC_GENERAL", CKM_SHA512_HMAC_GENERAL },
1431e9884acSmcpowers { "CKM_SECURID_KEY_GEN", CKM_SECURID_KEY_GEN },
1441e9884acSmcpowers { "CKM_SECURID", CKM_SECURID },
1451e9884acSmcpowers { "CKM_HOTP_KEY_GEN", CKM_HOTP_KEY_GEN },
1461e9884acSmcpowers { "CKM_HOTP", CKM_HOTP },
1471e9884acSmcpowers { "CKM_ACTI", CKM_ACTI },
1481e9884acSmcpowers { "CKM_ACTI_KEY_GEN", CKM_ACTI_KEY_GEN },
1497c478bd9Sstevel@tonic-gate { "CKM_CAST_KEY_GEN", CKM_CAST_KEY_GEN },
1507c478bd9Sstevel@tonic-gate { "CKM_CAST_ECB", CKM_CAST_ECB },
1517c478bd9Sstevel@tonic-gate { "CKM_CAST_CBC", CKM_CAST_CBC },
1527c478bd9Sstevel@tonic-gate { "CKM_CAST_MAC", CKM_CAST_MAC },
1537c478bd9Sstevel@tonic-gate { "CKM_CAST_MAC_GENERAL", CKM_CAST_MAC_GENERAL },
1547c478bd9Sstevel@tonic-gate { "CKM_CAST_CBC_PAD", CKM_CAST_CBC_PAD },
1557c478bd9Sstevel@tonic-gate { "CKM_CAST3_KEY_GEN", CKM_CAST3_KEY_GEN },
1567c478bd9Sstevel@tonic-gate { "CKM_CAST3_ECB", CKM_CAST3_ECB },
1577c478bd9Sstevel@tonic-gate { "CKM_CAST3_CBC", CKM_CAST3_CBC },
1587c478bd9Sstevel@tonic-gate { "CKM_CAST3_MAC", CKM_CAST3_MAC },
1597c478bd9Sstevel@tonic-gate { "CKM_CAST3_MAC_GENERAL", CKM_CAST3_MAC_GENERAL },
1607c478bd9Sstevel@tonic-gate { "CKM_CAST3_CBC_PAD", CKM_CAST3_CBC_PAD },
1617c478bd9Sstevel@tonic-gate { "CKM_CAST5_KEY_GEN", CKM_CAST5_KEY_GEN },
1627c478bd9Sstevel@tonic-gate { "CKM_CAST128_KEY_GEN", CKM_CAST128_KEY_GEN },
1637c478bd9Sstevel@tonic-gate { "CKM_CAST5_ECB", CKM_CAST5_ECB },
1647c478bd9Sstevel@tonic-gate { "CKM_CAST128_ECB", CKM_CAST128_ECB },
1657c478bd9Sstevel@tonic-gate { "CKM_CAST5_CBC", CKM_CAST5_CBC },
1667c478bd9Sstevel@tonic-gate { "CKM_CAST128_CBC", CKM_CAST128_CBC },
1677c478bd9Sstevel@tonic-gate { "CKM_CAST5_MAC", CKM_CAST5_MAC },
1687c478bd9Sstevel@tonic-gate { "CKM_CAST128_MAC", CKM_CAST128_MAC },
1697c478bd9Sstevel@tonic-gate { "CKM_CAST5_MAC_GENERAL", CKM_CAST5_MAC_GENERAL },
1707c478bd9Sstevel@tonic-gate { "CKM_CAST128_MAC_GENERAL", CKM_CAST128_MAC_GENERAL },
1717c478bd9Sstevel@tonic-gate { "CKM_CAST5_CBC_PAD", CKM_CAST5_CBC_PAD },
1727c478bd9Sstevel@tonic-gate { "CKM_CAST128_CBC_PAD", CKM_CAST128_CBC_PAD },
1737c478bd9Sstevel@tonic-gate { "CKM_RC5_KEY_GEN", CKM_RC5_KEY_GEN },
1747c478bd9Sstevel@tonic-gate { "CKM_RC5_ECB", CKM_RC5_ECB },
1757c478bd9Sstevel@tonic-gate { "CKM_RC5_CBC", CKM_RC5_CBC },
1767c478bd9Sstevel@tonic-gate { "CKM_RC5_MAC", CKM_RC5_MAC },
1777c478bd9Sstevel@tonic-gate { "CKM_RC5_MAC_GENERAL", CKM_RC5_MAC_GENERAL },
1787c478bd9Sstevel@tonic-gate { "CKM_RC5_CBC_PAD", CKM_RC5_CBC_PAD },
1797c478bd9Sstevel@tonic-gate { "CKM_IDEA_KEY_GEN", CKM_IDEA_KEY_GEN },
1807c478bd9Sstevel@tonic-gate { "CKM_IDEA_ECB", CKM_IDEA_ECB },
1817c478bd9Sstevel@tonic-gate { "CKM_IDEA_CBC", CKM_IDEA_CBC },
1827c478bd9Sstevel@tonic-gate { "CKM_IDEA_MAC", CKM_IDEA_MAC },
1837c478bd9Sstevel@tonic-gate { "CKM_IDEA_MAC_GENERAL", CKM_IDEA_MAC_GENERAL },
1847c478bd9Sstevel@tonic-gate { "CKM_IDEA_CBC_PAD", CKM_IDEA_CBC_PAD },
1857c478bd9Sstevel@tonic-gate { "CKM_GENERIC_SECRET_KEY_GEN", CKM_GENERIC_SECRET_KEY_GEN },
1867c478bd9Sstevel@tonic-gate { "CKM_CONCATENATE_BASE_AND_KEY", CKM_CONCATENATE_BASE_AND_KEY },
1877c478bd9Sstevel@tonic-gate { "CKM_CONCATENATE_BASE_AND_DATA", CKM_CONCATENATE_BASE_AND_DATA },
1887c478bd9Sstevel@tonic-gate { "CKM_CONCATENATE_DATA_AND_BASE", CKM_CONCATENATE_DATA_AND_BASE },
1897c478bd9Sstevel@tonic-gate { "CKM_XOR_BASE_AND_DATA", CKM_XOR_BASE_AND_DATA },
1907c478bd9Sstevel@tonic-gate { "CKM_EXTRACT_KEY_FROM_KEY", CKM_EXTRACT_KEY_FROM_KEY },
1917c478bd9Sstevel@tonic-gate { "CKM_SSL3_PRE_MASTER_KEY_GEN", CKM_SSL3_PRE_MASTER_KEY_GEN },
1927c478bd9Sstevel@tonic-gate { "CKM_SSL3_MASTER_KEY_DERIVE", CKM_SSL3_MASTER_KEY_DERIVE },
1937c478bd9Sstevel@tonic-gate { "CKM_SSL3_KEY_AND_MAC_DERIVE", CKM_SSL3_KEY_AND_MAC_DERIVE },
1947c478bd9Sstevel@tonic-gate { "CKM_SSL3_MASTER_KEY_DERIVE_DH", CKM_SSL3_MASTER_KEY_DERIVE_DH },
1957c478bd9Sstevel@tonic-gate { "CKM_TLS_PRE_MASTER_KEY_GEN", CKM_TLS_PRE_MASTER_KEY_GEN },
1967c478bd9Sstevel@tonic-gate { "CKM_TLS_MASTER_KEY_DERIVE", CKM_TLS_MASTER_KEY_DERIVE },
1977c478bd9Sstevel@tonic-gate { "CKM_TLS_KEY_AND_MAC_DERIVE", CKM_TLS_KEY_AND_MAC_DERIVE },
1987c478bd9Sstevel@tonic-gate { "CKM_TLS_MASTER_KEY_DERIVE_DH", CKM_TLS_MASTER_KEY_DERIVE_DH },
199f66d273dSizick { "CKM_TLS_PRF", CKM_TLS_PRF },
2007c478bd9Sstevel@tonic-gate { "CKM_SSL3_MD5_MAC", CKM_SSL3_MD5_MAC },
2017c478bd9Sstevel@tonic-gate { "CKM_SSL3_SHA1_MAC", CKM_SSL3_SHA1_MAC },
2027c478bd9Sstevel@tonic-gate { "CKM_MD5_KEY_DERIVATION", CKM_MD5_KEY_DERIVATION },
2037c478bd9Sstevel@tonic-gate { "CKM_MD2_KEY_DERIVATION", CKM_MD2_KEY_DERIVATION },
2047c478bd9Sstevel@tonic-gate { "CKM_SHA1_KEY_DERIVATION", CKM_SHA1_KEY_DERIVATION },
205f66d273dSizick { "CKM_SHA256_KEY_DERIVATION", CKM_SHA256_KEY_DERIVATION },
206f66d273dSizick { "CKM_SHA384_KEY_DERIVATION", CKM_SHA384_KEY_DERIVATION },
207f66d273dSizick { "CKM_SHA512_KEY_DERIVATION", CKM_SHA512_KEY_DERIVATION },
2081e9884acSmcpowers { "CKM_SHA224_KEY_DERIVATION", CKM_SHA224_KEY_DERIVATION },
2097c478bd9Sstevel@tonic-gate { "CKM_PBE_MD2_DES_CBC", CKM_PBE_MD2_DES_CBC },
2107c478bd9Sstevel@tonic-gate { "CKM_PBE_MD5_DES_CBC", CKM_PBE_MD5_DES_CBC },
2117c478bd9Sstevel@tonic-gate { "CKM_PBE_MD5_CAST_CBC", CKM_PBE_MD5_CAST_CBC },
2127c478bd9Sstevel@tonic-gate { "CKM_PBE_MD5_CAST3_CBC", CKM_PBE_MD5_CAST3_CBC },
2137c478bd9Sstevel@tonic-gate { "CKM_PBE_MD5_CAST5_CBC", CKM_PBE_MD5_CAST5_CBC },
2147c478bd9Sstevel@tonic-gate { "CKM_PBE_MD5_CAST128_CBC", CKM_PBE_MD5_CAST128_CBC },
2157c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_CAST5_CBC", CKM_PBE_SHA1_CAST5_CBC },
2167c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_CAST128_CBC", CKM_PBE_SHA1_CAST128_CBC },
2177c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_RC4_128", CKM_PBE_SHA1_RC4_128 },
2187c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_RC4_40", CKM_PBE_SHA1_RC4_40 },
2197c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_DES3_EDE_CBC", CKM_PBE_SHA1_DES3_EDE_CBC },
2207c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_DES2_EDE_CBC", CKM_PBE_SHA1_DES2_EDE_CBC },
2217c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_RC2_128_CBC", CKM_PBE_SHA1_RC2_128_CBC },
2227c478bd9Sstevel@tonic-gate { "CKM_PBE_SHA1_RC2_40_CBC", CKM_PBE_SHA1_RC2_40_CBC },
2237c478bd9Sstevel@tonic-gate { "CKM_PKCS5_PBKD2", CKM_PKCS5_PBKD2 },
2247c478bd9Sstevel@tonic-gate { "CKM_PBA_SHA1_WITH_SHA1_HMAC", CKM_PBA_SHA1_WITH_SHA1_HMAC },
225*d288ba74SAnthony Scarpino { "CKM_WTLS_PRE_MASTER_KEY_GEN", CKM_WTLS_PRE_MASTER_KEY_GEN },
226*d288ba74SAnthony Scarpino { "CKM_WTLS_MASTER_KEY_DERIVE", CKM_WTLS_MASTER_KEY_DERIVE },
227*d288ba74SAnthony Scarpino { "CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC",
228*d288ba74SAnthony Scarpino CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC },
229*d288ba74SAnthony Scarpino { "CKM_WTLS_PRF", CKM_WTLS_PRF },
230*d288ba74SAnthony Scarpino { "CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE",
231*d288ba74SAnthony Scarpino CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE },
232*d288ba74SAnthony Scarpino { "CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE",
233*d288ba74SAnthony Scarpino CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE },
2347c478bd9Sstevel@tonic-gate { "CKM_KEY_WRAP_LYNKS", CKM_KEY_WRAP_LYNKS },
2357c478bd9Sstevel@tonic-gate { "CKM_KEY_WRAP_SET_OAEP", CKM_KEY_WRAP_SET_OAEP },
2361e9884acSmcpowers { "CKM_KIP_DERIVE", CKM_KIP_DERIVE },
2371e9884acSmcpowers { "CKM_KIP_WRAP", CKM_KIP_WRAP },
2381e9884acSmcpowers { "CKM_KIP_MAC", CKM_KIP_MAC },
2391e9884acSmcpowers { "CKM_CAMELLIA_KEY_GEN", CKM_CAMELLIA_KEY_GEN },
2401e9884acSmcpowers { "CKM_CAMELLIA_ECB", CKM_CAMELLIA_ECB },
2411e9884acSmcpowers { "CKM_CAMELLIA_CBC", CKM_CAMELLIA_CBC },
2421e9884acSmcpowers { "CKM_CAMELLIA_MAC", CKM_CAMELLIA_MAC },
2431e9884acSmcpowers { "CKM_CAMELLIA_MAC_GENERAL", CKM_CAMELLIA_MAC_GENERAL },
2441e9884acSmcpowers { "CKM_CAMELLIA_CBC_PAD", CKM_CAMELLIA_CBC_PAD },
2451e9884acSmcpowers { "CKM_CAMELLIA_ECB_ENCRYPT_DATA", CKM_CAMELLIA_ECB_ENCRYPT_DATA },
2461e9884acSmcpowers { "CKM_CAMELLIA_CBC_ENCRYPT_DATA", CKM_CAMELLIA_CBC_ENCRYPT_DATA },
2471e9884acSmcpowers { "CKM_CAMELLIA_CTR", CKM_CAMELLIA_CTR },
2481e9884acSmcpowers { "CKM_ARIA_KEY_GEN", CKM_ARIA_KEY_GEN },
2491e9884acSmcpowers { "CKM_ARIA_ECB", CKM_ARIA_ECB },
2501e9884acSmcpowers { "CKM_ARIA_CBC", CKM_ARIA_CBC },
2511e9884acSmcpowers { "CKM_ARIA_MAC", CKM_ARIA_MAC },
2521e9884acSmcpowers { "CKM_ARIA_MAC_GENERAL", CKM_ARIA_MAC_GENERAL },
2531e9884acSmcpowers { "CKM_ARIA_CBC_PAD", CKM_ARIA_CBC_PAD },
2541e9884acSmcpowers { "CKM_ARIA_ECB_ENCRYPT_DATA", CKM_ARIA_ECB_ENCRYPT_DATA },
2551e9884acSmcpowers { "CKM_ARIA_CBC_ENCRYPT_DATA", CKM_ARIA_CBC_ENCRYPT_DATA },
256*d288ba74SAnthony Scarpino { "CKM_CMS_SIG", CKM_CMS_SIG },
2577c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_KEY_GEN", CKM_SKIPJACK_KEY_GEN },
2587c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_ECB64", CKM_SKIPJACK_ECB64 },
2597c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_CBC64", CKM_SKIPJACK_CBC64 },
2607c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_OFB64", CKM_SKIPJACK_OFB64 },
2617c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_CFB64", CKM_SKIPJACK_CFB64 },
2627c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_CFB32", CKM_SKIPJACK_CFB32 },
2637c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_CFB16", CKM_SKIPJACK_CFB16 },
2647c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_CFB8", CKM_SKIPJACK_CFB8 },
2657c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_WRAP", CKM_SKIPJACK_WRAP },
2667c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_PRIVATE_WRAP", CKM_SKIPJACK_PRIVATE_WRAP },
2677c478bd9Sstevel@tonic-gate { "CKM_SKIPJACK_RELAYX", CKM_SKIPJACK_RELAYX },
2687c478bd9Sstevel@tonic-gate { "CKM_KEA_KEY_PAIR_GEN", CKM_KEA_KEY_PAIR_GEN },
2697c478bd9Sstevel@tonic-gate { "CKM_KEA_KEY_DERIVE", CKM_KEA_KEY_DERIVE },
2707c478bd9Sstevel@tonic-gate { "CKM_FORTEZZA_TIMESTAMP", CKM_FORTEZZA_TIMESTAMP },
2717c478bd9Sstevel@tonic-gate { "CKM_BATON_KEY_GEN", CKM_BATON_KEY_GEN },
2727c478bd9Sstevel@tonic-gate { "CKM_BATON_ECB128", CKM_BATON_ECB128 },
2737c478bd9Sstevel@tonic-gate { "CKM_BATON_ECB96", CKM_BATON_ECB96 },
2747c478bd9Sstevel@tonic-gate { "CKM_BATON_CBC128", CKM_BATON_CBC128 },
2757c478bd9Sstevel@tonic-gate { "CKM_BATON_COUNTER", CKM_BATON_COUNTER },
2767c478bd9Sstevel@tonic-gate { "CKM_BATON_SHUFFLE", CKM_BATON_SHUFFLE },
2777c478bd9Sstevel@tonic-gate { "CKM_BATON_WRAP", CKM_BATON_WRAP },
2787c478bd9Sstevel@tonic-gate { "CKM_EC_KEY_PAIR_GEN", CKM_EC_KEY_PAIR_GEN },
2797c478bd9Sstevel@tonic-gate { "CKM_ECDSA", CKM_ECDSA },
2807c478bd9Sstevel@tonic-gate { "CKM_ECDSA_SHA1", CKM_ECDSA_SHA1 },
2817c478bd9Sstevel@tonic-gate { "CKM_ECDH1_DERIVE", CKM_ECDH1_DERIVE },
2827c478bd9Sstevel@tonic-gate { "CKM_ECDH1_COFACTOR_DERIVE", CKM_ECDH1_COFACTOR_DERIVE },
2837c478bd9Sstevel@tonic-gate { "CKM_ECMQV_DERIVE", CKM_ECMQV_DERIVE },
2847c478bd9Sstevel@tonic-gate { "CKM_JUNIPER_KEY_GEN", CKM_JUNIPER_KEY_GEN },
2857c478bd9Sstevel@tonic-gate { "CKM_JUNIPER_ECB128", CKM_JUNIPER_ECB128 },
2867c478bd9Sstevel@tonic-gate { "CKM_JUNIPER_CBC128", CKM_JUNIPER_CBC128 },
2877c478bd9Sstevel@tonic-gate { "CKM_JUNIPER_COUNTER", CKM_JUNIPER_COUNTER },
2887c478bd9Sstevel@tonic-gate { "CKM_JUNIPER_SHUFFLE", CKM_JUNIPER_SHUFFLE },
2897c478bd9Sstevel@tonic-gate { "CKM_JUNIPER_WRAP", CKM_JUNIPER_WRAP },
2907c478bd9Sstevel@tonic-gate { "CKM_FASTHASH", CKM_FASTHASH },
2917c478bd9Sstevel@tonic-gate { "CKM_AES_KEY_GEN", CKM_AES_KEY_GEN },
2927c478bd9Sstevel@tonic-gate { "CKM_AES_ECB", CKM_AES_ECB },
2937c478bd9Sstevel@tonic-gate { "CKM_AES_CBC", CKM_AES_CBC },
2947c478bd9Sstevel@tonic-gate { "CKM_AES_MAC", CKM_AES_MAC },
2957c478bd9Sstevel@tonic-gate { "CKM_AES_MAC_GENERAL", CKM_AES_MAC_GENERAL },
2967c478bd9Sstevel@tonic-gate { "CKM_AES_CBC_PAD", CKM_AES_CBC_PAD },
2971e9884acSmcpowers { "CKM_AES_CTR", CKM_AES_CTR },
298f66d273dSizick { "CKM_BLOWFISH_KEY_GEN", CKM_BLOWFISH_KEY_GEN },
299f66d273dSizick { "CKM_BLOWFISH_CBC", CKM_BLOWFISH_CBC },
300f66d273dSizick { "CKM_TWOFISH_KEY_GEN", CKM_TWOFISH_KEY_GEN },
301f66d273dSizick { "CKM_TWOFISH_CBC", CKM_TWOFISH_CBC },
302f66d273dSizick { "CKM_DES_ECB_ENCRYPT_DATA", CKM_DES_ECB_ENCRYPT_DATA },
303f66d273dSizick { "CKM_DES_CBC_ENCRYPT_DATA", CKM_DES_CBC_ENCRYPT_DATA },
304f66d273dSizick { "CKM_DES3_ECB_ENCRYPT_DATA", CKM_DES3_ECB_ENCRYPT_DATA },
305f66d273dSizick { "CKM_DES3_CBC_ENCRYPT_DATA", CKM_DES3_CBC_ENCRYPT_DATA },
306f66d273dSizick { "CKM_AES_ECB_ENCRYPT_DATA", CKM_AES_ECB_ENCRYPT_DATA },
307f66d273dSizick { "CKM_AES_CBC_ENCRYPT_DATA", CKM_AES_CBC_ENCRYPT_DATA },
3087c478bd9Sstevel@tonic-gate { "CKM_DSA_PARAMETER_GEN", CKM_DSA_PARAMETER_GEN },
3097c478bd9Sstevel@tonic-gate { "CKM_DH_PKCS_PARAMETER_GEN", CKM_DH_PKCS_PARAMETER_GEN },
3107c478bd9Sstevel@tonic-gate { "CKM_X9_42_DH_PARAMETER_GEN", CKM_X9_42_DH_PARAMETER_GEN },
3112321aa36Sda73024 /*
31276d1b5a9Sda73024 * Values >= 0x8000000 (CKM_VENDOR_DEFINED) are represented
3132321aa36Sda73024 * as strings with hexadecimal numbers (e.g., "0x8123456").
3142321aa36Sda73024 */
3157c478bd9Sstevel@tonic-gate { NULL, 0 }
3167c478bd9Sstevel@tonic-gate };
3177c478bd9Sstevel@tonic-gate
3182321aa36Sda73024
3192321aa36Sda73024 /*
3202321aa36Sda73024 * pkcs11_mech_comp - compare two pkcs11_mapping_t structures
3212321aa36Sda73024 *
3222321aa36Sda73024 * Return a strcmp-like result (positive, zero, or negative).
3232321aa36Sda73024 * For use with bsearch(3C) in pkcs11_mech2str().
3242321aa36Sda73024 */
3252321aa36Sda73024 static int
pkcs11_mech_comp(const void * mapping1,const void * mapping2)3262321aa36Sda73024 pkcs11_mech_comp(const void *mapping1, const void *mapping2) {
3272321aa36Sda73024 return (((pkcs11_mapping_t *)mapping1)->mech -
3282321aa36Sda73024 ((pkcs11_mapping_t *)mapping2)->mech);
3292321aa36Sda73024 }
3302321aa36Sda73024
3312321aa36Sda73024
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate * pkcs11_mech2str - convert PKCS#11 mech to a string
3347c478bd9Sstevel@tonic-gate *
3357c478bd9Sstevel@tonic-gate * Anything below CKM_VENDOR_DEFINED that wasn't in the mapping table
3367c478bd9Sstevel@tonic-gate * at build time causes NULL to be returned. Anything above it also
3372321aa36Sda73024 * returns NULL since we have no way to know its real name.
3387c478bd9Sstevel@tonic-gate */
3392321aa36Sda73024 const char
pkcs11_mech2str(CK_MECHANISM_TYPE mech)3407c478bd9Sstevel@tonic-gate *pkcs11_mech2str(CK_MECHANISM_TYPE mech)
3417c478bd9Sstevel@tonic-gate {
3422321aa36Sda73024 pkcs11_mapping_t target;
3432321aa36Sda73024 pkcs11_mapping_t *result = NULL;
3447c478bd9Sstevel@tonic-gate
34576d1b5a9Sda73024 if (mech >= CKM_VENDOR_DEFINED) {
3462321aa36Sda73024 return (NULL);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
3492321aa36Sda73024 /* Search for the mechanism number using bsearch(3C) */
3502321aa36Sda73024 target.mech = mech;
3512321aa36Sda73024 target.str = NULL;
3522321aa36Sda73024 result = (pkcs11_mapping_t *)bsearch((void *)&target, (void *)mapping,
3532321aa36Sda73024 (sizeof (mapping) / sizeof (pkcs11_mapping_t)) - 1,
3542321aa36Sda73024 sizeof (pkcs11_mapping_t), pkcs11_mech_comp);
3552321aa36Sda73024 if (result != NULL) {
3562321aa36Sda73024 return (result->str);
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate return (NULL);
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate * pkcs11_str2mech - convert a string into a PKCS#11 mech number.
3647c478bd9Sstevel@tonic-gate *
3652321aa36Sda73024 * Since there isn't a reserved value for an invalid mech we return
3667c478bd9Sstevel@tonic-gate * CKR_MECHANISM_INVALID for anything we don't recognise.
3677c478bd9Sstevel@tonic-gate * The value in mech isn't meaningful in these cases.
3687c478bd9Sstevel@tonic-gate */
3697c478bd9Sstevel@tonic-gate CK_RV
pkcs11_str2mech(char * mech_str,CK_MECHANISM_TYPE_PTR mech)3707c478bd9Sstevel@tonic-gate pkcs11_str2mech(char *mech_str, CK_MECHANISM_TYPE_PTR mech)
3717c478bd9Sstevel@tonic-gate {
3727c478bd9Sstevel@tonic-gate int i;
3732321aa36Sda73024 int compare_off = 0;
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate if (mech_str == NULL)
3767c478bd9Sstevel@tonic-gate return (CKR_MECHANISM_INVALID);
3777c478bd9Sstevel@tonic-gate
3782321aa36Sda73024 if (strncasecmp(mech_str, "0x", 2) == 0) {
3792321aa36Sda73024 long long llnum;
3807c478bd9Sstevel@tonic-gate cryptodebug("pkcs11_str2mech: hex string passed in: %s",
3817c478bd9Sstevel@tonic-gate mech_str);
3822321aa36Sda73024 llnum = strtoll(mech_str, NULL, 16);
3832321aa36Sda73024 if ((llnum >= CKM_VENDOR_DEFINED) && (llnum <= UINT_MAX)) {
3842321aa36Sda73024 *mech = llnum;
3857c478bd9Sstevel@tonic-gate return (CKR_OK);
3867c478bd9Sstevel@tonic-gate } else {
3872321aa36Sda73024 return (CKR_MECHANISM_INVALID);
3882321aa36Sda73024 }
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate
3912321aa36Sda73024 /* If there's no CKM_ prefix, then ignore it in comparisons */
3922321aa36Sda73024 if (strncasecmp(mech_str, "CKM_", 4) != 0) {
3932321aa36Sda73024 cryptodebug("pkcs11_str2mech: no CKM_ prefix: %s", mech_str);
3942321aa36Sda73024 cryptodebug("pkcs11_str2mech: with prefix: CKM_%s", mech_str);
3952321aa36Sda73024 compare_off = 4;
3962321aa36Sda73024 }
3972321aa36Sda73024
3982321aa36Sda73024 /* Linear search for a matching string */
3997c478bd9Sstevel@tonic-gate for (i = 0; mapping[i].str; i++) {
4002321aa36Sda73024 if (strcasecmp(&mapping[i].str[compare_off], mech_str) == 0) {
4017c478bd9Sstevel@tonic-gate *mech = mapping[i].mech;
4027c478bd9Sstevel@tonic-gate return (CKR_OK);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate return (CKR_MECHANISM_INVALID);
4077c478bd9Sstevel@tonic-gate }
408