1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Convert Algorithm names as strings to PKCS#11 Mech numbers and vice versa. 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <string.h> 34*0Sstevel@tonic-gate #include <stdlib.h> 35*0Sstevel@tonic-gate #include <stdio.h> 36*0Sstevel@tonic-gate #include <security/cryptoki.h> 37*0Sstevel@tonic-gate #include <security/pkcs11t.h> 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate #include <cryptoutil.h> 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate /* 42*0Sstevel@tonic-gate * The table below is dynamically generated by parsing pkcs11t.h 43*0Sstevel@tonic-gate * from the Makefile. 44*0Sstevel@tonic-gate */ 45*0Sstevel@tonic-gate static const struct { 46*0Sstevel@tonic-gate const char *str; 47*0Sstevel@tonic-gate CK_MECHANISM_TYPE mech; 48*0Sstevel@tonic-gate } mapping[] = { 49*0Sstevel@tonic-gate { "CKM_RSA_PKCS_KEY_PAIR_GEN", CKM_RSA_PKCS_KEY_PAIR_GEN }, 50*0Sstevel@tonic-gate { "CKM_RSA_PKCS", CKM_RSA_PKCS }, 51*0Sstevel@tonic-gate { "CKM_RSA_9796", CKM_RSA_9796 }, 52*0Sstevel@tonic-gate { "CKM_RSA_X_509", CKM_RSA_X_509 }, 53*0Sstevel@tonic-gate { "CKM_MD2_RSA_PKCS", CKM_MD2_RSA_PKCS }, 54*0Sstevel@tonic-gate { "CKM_MD5_RSA_PKCS", CKM_MD5_RSA_PKCS }, 55*0Sstevel@tonic-gate { "CKM_SHA1_RSA_PKCS", CKM_SHA1_RSA_PKCS }, 56*0Sstevel@tonic-gate { "CKM_RIPEMD128_RSA_PKCS", CKM_RIPEMD128_RSA_PKCS }, 57*0Sstevel@tonic-gate { "CKM_RIPEMD160_RSA_PKCS", CKM_RIPEMD160_RSA_PKCS }, 58*0Sstevel@tonic-gate { "CKM_RSA_PKCS_OAEP", CKM_RSA_PKCS_OAEP }, 59*0Sstevel@tonic-gate { "CKM_RSA_X9_31_KEY_PAIR_GEN", CKM_RSA_X9_31_KEY_PAIR_GEN }, 60*0Sstevel@tonic-gate { "CKM_RSA_X9_31", CKM_RSA_X9_31 }, 61*0Sstevel@tonic-gate { "CKM_SHA1_RSA_X9_31", CKM_SHA1_RSA_X9_31 }, 62*0Sstevel@tonic-gate { "CKM_RSA_PKCS_PSS", CKM_RSA_PKCS_PSS }, 63*0Sstevel@tonic-gate { "CKM_SHA1_RSA_PKCS_PSS", CKM_SHA1_RSA_PKCS_PSS }, 64*0Sstevel@tonic-gate { "CKM_DSA_KEY_PAIR_GEN", CKM_DSA_KEY_PAIR_GEN }, 65*0Sstevel@tonic-gate { "CKM_DSA", CKM_DSA }, 66*0Sstevel@tonic-gate { "CKM_DSA_SHA1", CKM_DSA_SHA1 }, 67*0Sstevel@tonic-gate { "CKM_DH_PKCS_KEY_PAIR_GEN", CKM_DH_PKCS_KEY_PAIR_GEN }, 68*0Sstevel@tonic-gate { "CKM_DH_PKCS_DERIVE", CKM_DH_PKCS_DERIVE }, 69*0Sstevel@tonic-gate { "CKM_X9_42_DH_KEY_PAIR_GEN", CKM_X9_42_DH_KEY_PAIR_GEN }, 70*0Sstevel@tonic-gate { "CKM_X9_42_DH_DERIVE", CKM_X9_42_DH_DERIVE }, 71*0Sstevel@tonic-gate { "CKM_X9_42_DH_HYBRID_DERIVE", CKM_X9_42_DH_HYBRID_DERIVE }, 72*0Sstevel@tonic-gate { "CKM_X9_42_MQV_DERIVE", CKM_X9_42_MQV_DERIVE }, 73*0Sstevel@tonic-gate { "CKM_RC2_KEY_GEN", CKM_RC2_KEY_GEN }, 74*0Sstevel@tonic-gate { "CKM_RC2_ECB", CKM_RC2_ECB }, 75*0Sstevel@tonic-gate { "CKM_RC2_CBC", CKM_RC2_CBC }, 76*0Sstevel@tonic-gate { "CKM_RC2_MAC", CKM_RC2_MAC }, 77*0Sstevel@tonic-gate { "CKM_RC2_MAC_GENERAL", CKM_RC2_MAC_GENERAL }, 78*0Sstevel@tonic-gate { "CKM_RC2_CBC_PAD", CKM_RC2_CBC_PAD }, 79*0Sstevel@tonic-gate { "CKM_RC4_KEY_GEN", CKM_RC4_KEY_GEN }, 80*0Sstevel@tonic-gate { "CKM_RC4", CKM_RC4 }, 81*0Sstevel@tonic-gate { "CKM_DES_KEY_GEN", CKM_DES_KEY_GEN }, 82*0Sstevel@tonic-gate { "CKM_DES_ECB", CKM_DES_ECB }, 83*0Sstevel@tonic-gate { "CKM_DES_CBC", CKM_DES_CBC }, 84*0Sstevel@tonic-gate { "CKM_DES_MAC", CKM_DES_MAC }, 85*0Sstevel@tonic-gate { "CKM_DES_MAC_GENERAL", CKM_DES_MAC_GENERAL }, 86*0Sstevel@tonic-gate { "CKM_DES_CBC_PAD", CKM_DES_CBC_PAD }, 87*0Sstevel@tonic-gate { "CKM_DES2_KEY_GEN", CKM_DES2_KEY_GEN }, 88*0Sstevel@tonic-gate { "CKM_DES3_KEY_GEN", CKM_DES3_KEY_GEN }, 89*0Sstevel@tonic-gate { "CKM_DES3_ECB", CKM_DES3_ECB }, 90*0Sstevel@tonic-gate { "CKM_DES3_CBC", CKM_DES3_CBC }, 91*0Sstevel@tonic-gate { "CKM_DES3_MAC", CKM_DES3_MAC }, 92*0Sstevel@tonic-gate { "CKM_DES3_MAC_GENERAL", CKM_DES3_MAC_GENERAL }, 93*0Sstevel@tonic-gate { "CKM_DES3_CBC_PAD", CKM_DES3_CBC_PAD }, 94*0Sstevel@tonic-gate { "CKM_CDMF_KEY_GEN", CKM_CDMF_KEY_GEN }, 95*0Sstevel@tonic-gate { "CKM_CDMF_ECB", CKM_CDMF_ECB }, 96*0Sstevel@tonic-gate { "CKM_CDMF_CBC", CKM_CDMF_CBC }, 97*0Sstevel@tonic-gate { "CKM_CDMF_MAC", CKM_CDMF_MAC }, 98*0Sstevel@tonic-gate { "CKM_CDMF_MAC_GENERAL", CKM_CDMF_MAC_GENERAL }, 99*0Sstevel@tonic-gate { "CKM_CDMF_CBC_PAD", CKM_CDMF_CBC_PAD }, 100*0Sstevel@tonic-gate { "CKM_MD2", CKM_MD2 }, 101*0Sstevel@tonic-gate { "CKM_MD2_HMAC", CKM_MD2_HMAC }, 102*0Sstevel@tonic-gate { "CKM_MD2_HMAC_GENERAL", CKM_MD2_HMAC_GENERAL }, 103*0Sstevel@tonic-gate { "CKM_MD5", CKM_MD5 }, 104*0Sstevel@tonic-gate { "CKM_MD5_HMAC", CKM_MD5_HMAC }, 105*0Sstevel@tonic-gate { "CKM_MD5_HMAC_GENERAL", CKM_MD5_HMAC_GENERAL }, 106*0Sstevel@tonic-gate { "CKM_SHA_1", CKM_SHA_1 }, 107*0Sstevel@tonic-gate { "CKM_SHA_1_HMAC", CKM_SHA_1_HMAC }, 108*0Sstevel@tonic-gate { "CKM_SHA_1_HMAC_GENERAL", CKM_SHA_1_HMAC_GENERAL }, 109*0Sstevel@tonic-gate { "CKM_RIPEMD128", CKM_RIPEMD128 }, 110*0Sstevel@tonic-gate { "CKM_RIPEMD128_HMAC", CKM_RIPEMD128_HMAC }, 111*0Sstevel@tonic-gate { "CKM_RIPEMD128_HMAC_GENERAL", CKM_RIPEMD128_HMAC_GENERAL }, 112*0Sstevel@tonic-gate { "CKM_RIPEMD160", CKM_RIPEMD160 }, 113*0Sstevel@tonic-gate { "CKM_RIPEMD160_HMAC", CKM_RIPEMD160_HMAC }, 114*0Sstevel@tonic-gate { "CKM_RIPEMD160_HMAC_GENERAL", CKM_RIPEMD160_HMAC_GENERAL }, 115*0Sstevel@tonic-gate { "CKM_CAST_KEY_GEN", CKM_CAST_KEY_GEN }, 116*0Sstevel@tonic-gate { "CKM_CAST_ECB", CKM_CAST_ECB }, 117*0Sstevel@tonic-gate { "CKM_CAST_CBC", CKM_CAST_CBC }, 118*0Sstevel@tonic-gate { "CKM_CAST_MAC", CKM_CAST_MAC }, 119*0Sstevel@tonic-gate { "CKM_CAST_MAC_GENERAL", CKM_CAST_MAC_GENERAL }, 120*0Sstevel@tonic-gate { "CKM_CAST_CBC_PAD", CKM_CAST_CBC_PAD }, 121*0Sstevel@tonic-gate { "CKM_CAST3_KEY_GEN", CKM_CAST3_KEY_GEN }, 122*0Sstevel@tonic-gate { "CKM_CAST3_ECB", CKM_CAST3_ECB }, 123*0Sstevel@tonic-gate { "CKM_CAST3_CBC", CKM_CAST3_CBC }, 124*0Sstevel@tonic-gate { "CKM_CAST3_MAC", CKM_CAST3_MAC }, 125*0Sstevel@tonic-gate { "CKM_CAST3_MAC_GENERAL", CKM_CAST3_MAC_GENERAL }, 126*0Sstevel@tonic-gate { "CKM_CAST3_CBC_PAD", CKM_CAST3_CBC_PAD }, 127*0Sstevel@tonic-gate { "CKM_CAST5_KEY_GEN", CKM_CAST5_KEY_GEN }, 128*0Sstevel@tonic-gate { "CKM_CAST128_KEY_GEN", CKM_CAST128_KEY_GEN }, 129*0Sstevel@tonic-gate { "CKM_CAST5_ECB", CKM_CAST5_ECB }, 130*0Sstevel@tonic-gate { "CKM_CAST128_ECB", CKM_CAST128_ECB }, 131*0Sstevel@tonic-gate { "CKM_CAST5_CBC", CKM_CAST5_CBC }, 132*0Sstevel@tonic-gate { "CKM_CAST128_CBC", CKM_CAST128_CBC }, 133*0Sstevel@tonic-gate { "CKM_CAST5_MAC", CKM_CAST5_MAC }, 134*0Sstevel@tonic-gate { "CKM_CAST128_MAC", CKM_CAST128_MAC }, 135*0Sstevel@tonic-gate { "CKM_CAST5_MAC_GENERAL", CKM_CAST5_MAC_GENERAL }, 136*0Sstevel@tonic-gate { "CKM_CAST128_MAC_GENERAL", CKM_CAST128_MAC_GENERAL }, 137*0Sstevel@tonic-gate { "CKM_CAST5_CBC_PAD", CKM_CAST5_CBC_PAD }, 138*0Sstevel@tonic-gate { "CKM_CAST128_CBC_PAD", CKM_CAST128_CBC_PAD }, 139*0Sstevel@tonic-gate { "CKM_RC5_KEY_GEN", CKM_RC5_KEY_GEN }, 140*0Sstevel@tonic-gate { "CKM_RC5_ECB", CKM_RC5_ECB }, 141*0Sstevel@tonic-gate { "CKM_RC5_CBC", CKM_RC5_CBC }, 142*0Sstevel@tonic-gate { "CKM_RC5_MAC", CKM_RC5_MAC }, 143*0Sstevel@tonic-gate { "CKM_RC5_MAC_GENERAL", CKM_RC5_MAC_GENERAL }, 144*0Sstevel@tonic-gate { "CKM_RC5_CBC_PAD", CKM_RC5_CBC_PAD }, 145*0Sstevel@tonic-gate { "CKM_IDEA_KEY_GEN", CKM_IDEA_KEY_GEN }, 146*0Sstevel@tonic-gate { "CKM_IDEA_ECB", CKM_IDEA_ECB }, 147*0Sstevel@tonic-gate { "CKM_IDEA_CBC", CKM_IDEA_CBC }, 148*0Sstevel@tonic-gate { "CKM_IDEA_MAC", CKM_IDEA_MAC }, 149*0Sstevel@tonic-gate { "CKM_IDEA_MAC_GENERAL", CKM_IDEA_MAC_GENERAL }, 150*0Sstevel@tonic-gate { "CKM_IDEA_CBC_PAD", CKM_IDEA_CBC_PAD }, 151*0Sstevel@tonic-gate { "CKM_GENERIC_SECRET_KEY_GEN", CKM_GENERIC_SECRET_KEY_GEN }, 152*0Sstevel@tonic-gate { "CKM_CONCATENATE_BASE_AND_KEY", CKM_CONCATENATE_BASE_AND_KEY }, 153*0Sstevel@tonic-gate { "CKM_CONCATENATE_BASE_AND_DATA", CKM_CONCATENATE_BASE_AND_DATA }, 154*0Sstevel@tonic-gate { "CKM_CONCATENATE_DATA_AND_BASE", CKM_CONCATENATE_DATA_AND_BASE }, 155*0Sstevel@tonic-gate { "CKM_XOR_BASE_AND_DATA", CKM_XOR_BASE_AND_DATA }, 156*0Sstevel@tonic-gate { "CKM_EXTRACT_KEY_FROM_KEY", CKM_EXTRACT_KEY_FROM_KEY }, 157*0Sstevel@tonic-gate { "CKM_SSL3_PRE_MASTER_KEY_GEN", CKM_SSL3_PRE_MASTER_KEY_GEN }, 158*0Sstevel@tonic-gate { "CKM_SSL3_MASTER_KEY_DERIVE", CKM_SSL3_MASTER_KEY_DERIVE }, 159*0Sstevel@tonic-gate { "CKM_SSL3_KEY_AND_MAC_DERIVE", CKM_SSL3_KEY_AND_MAC_DERIVE }, 160*0Sstevel@tonic-gate { "CKM_SSL3_MASTER_KEY_DERIVE_DH", CKM_SSL3_MASTER_KEY_DERIVE_DH }, 161*0Sstevel@tonic-gate { "CKM_TLS_PRE_MASTER_KEY_GEN", CKM_TLS_PRE_MASTER_KEY_GEN }, 162*0Sstevel@tonic-gate { "CKM_TLS_MASTER_KEY_DERIVE", CKM_TLS_MASTER_KEY_DERIVE }, 163*0Sstevel@tonic-gate { "CKM_TLS_KEY_AND_MAC_DERIVE", CKM_TLS_KEY_AND_MAC_DERIVE }, 164*0Sstevel@tonic-gate { "CKM_TLS_MASTER_KEY_DERIVE_DH", CKM_TLS_MASTER_KEY_DERIVE_DH }, 165*0Sstevel@tonic-gate { "CKM_SSL3_MD5_MAC", CKM_SSL3_MD5_MAC }, 166*0Sstevel@tonic-gate { "CKM_SSL3_SHA1_MAC", CKM_SSL3_SHA1_MAC }, 167*0Sstevel@tonic-gate { "CKM_MD5_KEY_DERIVATION", CKM_MD5_KEY_DERIVATION }, 168*0Sstevel@tonic-gate { "CKM_MD2_KEY_DERIVATION", CKM_MD2_KEY_DERIVATION }, 169*0Sstevel@tonic-gate { "CKM_SHA1_KEY_DERIVATION", CKM_SHA1_KEY_DERIVATION }, 170*0Sstevel@tonic-gate { "CKM_PBE_MD2_DES_CBC", CKM_PBE_MD2_DES_CBC }, 171*0Sstevel@tonic-gate { "CKM_PBE_MD5_DES_CBC", CKM_PBE_MD5_DES_CBC }, 172*0Sstevel@tonic-gate { "CKM_PBE_MD5_CAST_CBC", CKM_PBE_MD5_CAST_CBC }, 173*0Sstevel@tonic-gate { "CKM_PBE_MD5_CAST3_CBC", CKM_PBE_MD5_CAST3_CBC }, 174*0Sstevel@tonic-gate { "CKM_PBE_MD5_CAST5_CBC", CKM_PBE_MD5_CAST5_CBC }, 175*0Sstevel@tonic-gate { "CKM_PBE_MD5_CAST128_CBC", CKM_PBE_MD5_CAST128_CBC }, 176*0Sstevel@tonic-gate { "CKM_PBE_SHA1_CAST5_CBC", CKM_PBE_SHA1_CAST5_CBC }, 177*0Sstevel@tonic-gate { "CKM_PBE_SHA1_CAST128_CBC", CKM_PBE_SHA1_CAST128_CBC }, 178*0Sstevel@tonic-gate { "CKM_PBE_SHA1_RC4_128", CKM_PBE_SHA1_RC4_128 }, 179*0Sstevel@tonic-gate { "CKM_PBE_SHA1_RC4_40", CKM_PBE_SHA1_RC4_40 }, 180*0Sstevel@tonic-gate { "CKM_PBE_SHA1_DES3_EDE_CBC", CKM_PBE_SHA1_DES3_EDE_CBC }, 181*0Sstevel@tonic-gate { "CKM_PBE_SHA1_DES2_EDE_CBC", CKM_PBE_SHA1_DES2_EDE_CBC }, 182*0Sstevel@tonic-gate { "CKM_PBE_SHA1_RC2_128_CBC", CKM_PBE_SHA1_RC2_128_CBC }, 183*0Sstevel@tonic-gate { "CKM_PBE_SHA1_RC2_40_CBC", CKM_PBE_SHA1_RC2_40_CBC }, 184*0Sstevel@tonic-gate { "CKM_PKCS5_PBKD2", CKM_PKCS5_PBKD2 }, 185*0Sstevel@tonic-gate { "CKM_PBA_SHA1_WITH_SHA1_HMAC", CKM_PBA_SHA1_WITH_SHA1_HMAC }, 186*0Sstevel@tonic-gate { "CKM_KEY_WRAP_LYNKS", CKM_KEY_WRAP_LYNKS }, 187*0Sstevel@tonic-gate { "CKM_KEY_WRAP_SET_OAEP", CKM_KEY_WRAP_SET_OAEP }, 188*0Sstevel@tonic-gate { "CKM_SKIPJACK_KEY_GEN", CKM_SKIPJACK_KEY_GEN }, 189*0Sstevel@tonic-gate { "CKM_SKIPJACK_ECB64", CKM_SKIPJACK_ECB64 }, 190*0Sstevel@tonic-gate { "CKM_SKIPJACK_CBC64", CKM_SKIPJACK_CBC64 }, 191*0Sstevel@tonic-gate { "CKM_SKIPJACK_OFB64", CKM_SKIPJACK_OFB64 }, 192*0Sstevel@tonic-gate { "CKM_SKIPJACK_CFB64", CKM_SKIPJACK_CFB64 }, 193*0Sstevel@tonic-gate { "CKM_SKIPJACK_CFB32", CKM_SKIPJACK_CFB32 }, 194*0Sstevel@tonic-gate { "CKM_SKIPJACK_CFB16", CKM_SKIPJACK_CFB16 }, 195*0Sstevel@tonic-gate { "CKM_SKIPJACK_CFB8", CKM_SKIPJACK_CFB8 }, 196*0Sstevel@tonic-gate { "CKM_SKIPJACK_WRAP", CKM_SKIPJACK_WRAP }, 197*0Sstevel@tonic-gate { "CKM_SKIPJACK_PRIVATE_WRAP", CKM_SKIPJACK_PRIVATE_WRAP }, 198*0Sstevel@tonic-gate { "CKM_SKIPJACK_RELAYX", CKM_SKIPJACK_RELAYX }, 199*0Sstevel@tonic-gate { "CKM_KEA_KEY_PAIR_GEN", CKM_KEA_KEY_PAIR_GEN }, 200*0Sstevel@tonic-gate { "CKM_KEA_KEY_DERIVE", CKM_KEA_KEY_DERIVE }, 201*0Sstevel@tonic-gate { "CKM_FORTEZZA_TIMESTAMP", CKM_FORTEZZA_TIMESTAMP }, 202*0Sstevel@tonic-gate { "CKM_BATON_KEY_GEN", CKM_BATON_KEY_GEN }, 203*0Sstevel@tonic-gate { "CKM_BATON_ECB128", CKM_BATON_ECB128 }, 204*0Sstevel@tonic-gate { "CKM_BATON_ECB96", CKM_BATON_ECB96 }, 205*0Sstevel@tonic-gate { "CKM_BATON_CBC128", CKM_BATON_CBC128 }, 206*0Sstevel@tonic-gate { "CKM_BATON_COUNTER", CKM_BATON_COUNTER }, 207*0Sstevel@tonic-gate { "CKM_BATON_SHUFFLE", CKM_BATON_SHUFFLE }, 208*0Sstevel@tonic-gate { "CKM_BATON_WRAP", CKM_BATON_WRAP }, 209*0Sstevel@tonic-gate { "CKM_ECDSA_KEY_PAIR_GEN", CKM_ECDSA_KEY_PAIR_GEN }, 210*0Sstevel@tonic-gate { "CKM_EC_KEY_PAIR_GEN", CKM_EC_KEY_PAIR_GEN }, 211*0Sstevel@tonic-gate { "CKM_ECDSA", CKM_ECDSA }, 212*0Sstevel@tonic-gate { "CKM_ECDSA_SHA1", CKM_ECDSA_SHA1 }, 213*0Sstevel@tonic-gate { "CKM_ECDH1_DERIVE", CKM_ECDH1_DERIVE }, 214*0Sstevel@tonic-gate { "CKM_ECDH1_COFACTOR_DERIVE", CKM_ECDH1_COFACTOR_DERIVE }, 215*0Sstevel@tonic-gate { "CKM_ECMQV_DERIVE", CKM_ECMQV_DERIVE }, 216*0Sstevel@tonic-gate { "CKM_JUNIPER_KEY_GEN", CKM_JUNIPER_KEY_GEN }, 217*0Sstevel@tonic-gate { "CKM_JUNIPER_ECB128", CKM_JUNIPER_ECB128 }, 218*0Sstevel@tonic-gate { "CKM_JUNIPER_CBC128", CKM_JUNIPER_CBC128 }, 219*0Sstevel@tonic-gate { "CKM_JUNIPER_COUNTER", CKM_JUNIPER_COUNTER }, 220*0Sstevel@tonic-gate { "CKM_JUNIPER_SHUFFLE", CKM_JUNIPER_SHUFFLE }, 221*0Sstevel@tonic-gate { "CKM_JUNIPER_WRAP", CKM_JUNIPER_WRAP }, 222*0Sstevel@tonic-gate { "CKM_FASTHASH", CKM_FASTHASH }, 223*0Sstevel@tonic-gate { "CKM_AES_KEY_GEN", CKM_AES_KEY_GEN }, 224*0Sstevel@tonic-gate { "CKM_AES_ECB", CKM_AES_ECB }, 225*0Sstevel@tonic-gate { "CKM_AES_CBC", CKM_AES_CBC }, 226*0Sstevel@tonic-gate { "CKM_AES_MAC", CKM_AES_MAC }, 227*0Sstevel@tonic-gate { "CKM_AES_MAC_GENERAL", CKM_AES_MAC_GENERAL }, 228*0Sstevel@tonic-gate { "CKM_AES_CBC_PAD", CKM_AES_CBC_PAD }, 229*0Sstevel@tonic-gate { "CKM_DSA_PARAMETER_GEN", CKM_DSA_PARAMETER_GEN }, 230*0Sstevel@tonic-gate { "CKM_DH_PKCS_PARAMETER_GEN", CKM_DH_PKCS_PARAMETER_GEN }, 231*0Sstevel@tonic-gate { "CKM_X9_42_DH_PARAMETER_GEN", CKM_X9_42_DH_PARAMETER_GEN }, 232*0Sstevel@tonic-gate { "CKM_VENDOR_DEFINED", CKM_VENDOR_DEFINED }, 233*0Sstevel@tonic-gate { NULL, 0 } 234*0Sstevel@tonic-gate }; 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate /* 237*0Sstevel@tonic-gate * pkcs11_mech2str - convert PKCS#11 mech to a string 238*0Sstevel@tonic-gate * 239*0Sstevel@tonic-gate * Anything below CKM_VENDOR_DEFINED that wasn't in the mapping table 240*0Sstevel@tonic-gate * at build time causes NULL to be returned. Anything above it also 241*0Sstevel@tonic-gate * returns NULL since we have no way to know what its real name is. 242*0Sstevel@tonic-gate */ 243*0Sstevel@tonic-gate char 244*0Sstevel@tonic-gate *pkcs11_mech2str(CK_MECHANISM_TYPE mech) 245*0Sstevel@tonic-gate { 246*0Sstevel@tonic-gate int i; 247*0Sstevel@tonic-gate char buf[11]; /* Num chars for representing ulong in ASCII */ 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate if (mech > CKM_VENDOR_DEFINED) { 250*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%#lx", mech); 251*0Sstevel@tonic-gate return (strdup(buf)); 252*0Sstevel@tonic-gate } 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate for (i = 0; mapping[i].str; i++) { 255*0Sstevel@tonic-gate if (mapping[i].mech == mech) 256*0Sstevel@tonic-gate return (strdup(mapping[i].str)); 257*0Sstevel@tonic-gate } 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate return (NULL); 260*0Sstevel@tonic-gate } 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gate /* 263*0Sstevel@tonic-gate * pkcs11_str2mech - convert a string into a PKCS#11 mech number. 264*0Sstevel@tonic-gate * 265*0Sstevel@tonic-gate * Since there isn't reserved value for an invalid mech we return 266*0Sstevel@tonic-gate * CKR_MECHANISM_INVALID for anything we don't recognise. 267*0Sstevel@tonic-gate * The value in mech isn't meaningful in these cases. 268*0Sstevel@tonic-gate */ 269*0Sstevel@tonic-gate CK_RV 270*0Sstevel@tonic-gate pkcs11_str2mech(char *mech_str, CK_MECHANISM_TYPE_PTR mech) 271*0Sstevel@tonic-gate { 272*0Sstevel@tonic-gate int i; 273*0Sstevel@tonic-gate char *tmech_str; 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate if (mech_str == NULL) 276*0Sstevel@tonic-gate return (CKR_MECHANISM_INVALID); 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate if (strncasecmp(mech_str, "0x8", 3) == 0) { 279*0Sstevel@tonic-gate cryptodebug("pkcs11_str2mech: hex string passed in: %s", 280*0Sstevel@tonic-gate mech_str); 281*0Sstevel@tonic-gate *mech = strtoll(mech_str, NULL, 16); 282*0Sstevel@tonic-gate return (CKR_OK); 283*0Sstevel@tonic-gate } 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate if (strncasecmp(mech_str, "CKM_", 4) != 0) { 286*0Sstevel@tonic-gate size_t tmech_strlen = strlen(mech_str) + 4 + 1; 287*0Sstevel@tonic-gate cryptodebug("pkcs11_str2mech: no CKM_ prefix: %s", mech_str); 288*0Sstevel@tonic-gate tmech_str = malloc(tmech_strlen * sizeof (char)); 289*0Sstevel@tonic-gate (void) snprintf(tmech_str, tmech_strlen, "CKM_%s", mech_str); 290*0Sstevel@tonic-gate cryptodebug("pkcs11_str2mech: with prefix: %s", tmech_str); 291*0Sstevel@tonic-gate } else { 292*0Sstevel@tonic-gate tmech_str = mech_str; 293*0Sstevel@tonic-gate } 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gate for (i = 0; mapping[i].str; i++) { 296*0Sstevel@tonic-gate if (strcasecmp(mapping[i].str, tmech_str) == 0) { 297*0Sstevel@tonic-gate *mech = mapping[i].mech; 298*0Sstevel@tonic-gate if (tmech_str != mech_str) 299*0Sstevel@tonic-gate free(tmech_str); 300*0Sstevel@tonic-gate return (CKR_OK); 301*0Sstevel@tonic-gate } 302*0Sstevel@tonic-gate } 303*0Sstevel@tonic-gate if (tmech_str != mech_str) 304*0Sstevel@tonic-gate free(tmech_str); 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate return (CKR_MECHANISM_INVALID); 307*0Sstevel@tonic-gate } 308