1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <cryptoutil.h> 29 30 /* 31 * Get the key type for the given mechanism 32 * 33 * All mechanisms in PKCS #11 v2.20 are listed here. 34 */ 35 CK_RV pkcs11_mech2keytype(CK_MECHANISM_TYPE mech_type,CK_KEY_TYPE * ktype)36pkcs11_mech2keytype(CK_MECHANISM_TYPE mech_type, CK_KEY_TYPE *ktype) 37 { 38 39 CK_RV rv = CKR_OK; 40 41 switch (mech_type) { 42 43 case CKM_RSA_PKCS_KEY_PAIR_GEN: 44 case CKM_RSA_PKCS: 45 case CKM_RSA_9796: 46 case CKM_RSA_X_509: 47 case CKM_MD2_RSA_PKCS: 48 case CKM_MD5_RSA_PKCS: 49 case CKM_SHA1_RSA_PKCS: 50 case CKM_SHA256_RSA_PKCS: 51 case CKM_SHA384_RSA_PKCS: 52 case CKM_SHA512_RSA_PKCS: 53 case CKM_SHA256_RSA_PKCS_PSS: 54 case CKM_SHA384_RSA_PKCS_PSS: 55 case CKM_SHA512_RSA_PKCS_PSS: 56 case CKM_SHA224_RSA_PKCS: 57 case CKM_SHA224_RSA_PKCS_PSS: 58 case CKM_RIPEMD128_RSA_PKCS: 59 case CKM_RIPEMD160_RSA_PKCS: 60 case CKM_RSA_PKCS_OAEP: 61 case CKM_RSA_X9_31_KEY_PAIR_GEN: 62 case CKM_RSA_X9_31: 63 case CKM_SHA1_RSA_X9_31: 64 case CKM_RSA_PKCS_PSS: 65 case CKM_SHA1_RSA_PKCS_PSS: 66 case CKM_DH_PKCS_PARAMETER_GEN: 67 *ktype = CKK_RSA; 68 break; 69 70 case CKM_DSA_KEY_PAIR_GEN: 71 case CKM_DSA: 72 case CKM_DSA_SHA1: 73 case CKM_DSA_PARAMETER_GEN: 74 case CKM_FORTEZZA_TIMESTAMP: 75 *ktype = CKK_DSA; 76 break; 77 78 case CKM_DH_PKCS_KEY_PAIR_GEN: 79 case CKM_DH_PKCS_DERIVE: 80 *ktype = CKK_DH; 81 break; 82 83 case CKM_ECDSA: 84 case CKM_ECDSA_SHA1: 85 case CKM_EC_KEY_PAIR_GEN: 86 case CKM_ECDH1_DERIVE: 87 case CKM_ECDH1_COFACTOR_DERIVE: 88 case CKM_ECMQV_DERIVE: 89 *ktype = CKK_EC; 90 break; 91 92 case CKM_X9_42_DH_KEY_PAIR_GEN: 93 case CKM_X9_42_DH_DERIVE: 94 case CKM_X9_42_DH_HYBRID_DERIVE: 95 case CKM_X9_42_MQV_DERIVE: 96 case CKM_X9_42_DH_PARAMETER_GEN: 97 *ktype = CKK_X9_42_DH; 98 break; 99 100 case CKM_KEA_KEY_PAIR_GEN: 101 case CKM_KEA_KEY_DERIVE: 102 *ktype = CKK_KEA; 103 break; 104 105 case CKM_MD2: 106 case CKM_MD2_HMAC: 107 case CKM_MD2_HMAC_GENERAL: 108 case CKM_MD5: 109 case CKM_MD5_HMAC: 110 case CKM_MD5_HMAC_GENERAL: 111 case CKM_SHA_1: 112 case CKM_SHA_1_HMAC: 113 case CKM_SHA_1_HMAC_GENERAL: 114 case CKM_SHA256: 115 case CKM_SHA256_HMAC: 116 case CKM_SHA256_HMAC_GENERAL: 117 case CKM_SHA224: 118 case CKM_SHA224_HMAC: 119 case CKM_SHA224_HMAC_GENERAL: 120 case CKM_SHA384: 121 case CKM_SHA384_HMAC: 122 case CKM_SHA384_HMAC_GENERAL: 123 case CKM_SHA512: 124 case CKM_SHA512_HMAC: 125 case CKM_SHA512_HMAC_GENERAL: 126 case CKM_GENERIC_SECRET_KEY_GEN: 127 case CKM_FASTHASH: 128 case CKM_PKCS5_PBKD2: 129 case CKM_PBA_SHA1_WITH_SHA1_HMAC: 130 case CKM_SSL3_MD5_MAC: 131 case CKM_SSL3_SHA1_MAC: 132 case CKM_SSL3_PRE_MASTER_KEY_GEN: 133 case CKM_SSL3_MASTER_KEY_DERIVE: 134 case CKM_SSL3_KEY_AND_MAC_DERIVE: 135 case CKM_SSL3_MASTER_KEY_DERIVE_DH: 136 case CKM_TLS_PRE_MASTER_KEY_GEN: 137 case CKM_TLS_MASTER_KEY_DERIVE: 138 case CKM_TLS_KEY_AND_MAC_DERIVE: 139 case CKM_TLS_MASTER_KEY_DERIVE_DH: 140 case CKM_TLS_PRF: 141 case CKM_WTLS_PRE_MASTER_KEY_GEN: 142 case CKM_WTLS_MASTER_KEY_DERIVE: 143 case CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC: 144 case CKM_WTLS_PRF: 145 case CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE: 146 case CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE: 147 case CKM_CONCATENATE_BASE_AND_KEY: 148 case CKM_CONCATENATE_BASE_AND_DATA: 149 case CKM_CONCATENATE_DATA_AND_BASE: 150 case CKM_XOR_BASE_AND_DATA: 151 case CKM_EXTRACT_KEY_FROM_KEY: 152 case CKM_RIPEMD128: 153 case CKM_RIPEMD128_HMAC: 154 case CKM_RIPEMD128_HMAC_GENERAL: 155 case CKM_RIPEMD160: 156 case CKM_RIPEMD160_HMAC: 157 case CKM_RIPEMD160_HMAC_GENERAL: 158 case CKM_SHA1_KEY_DERIVATION: 159 case CKM_SHA256_KEY_DERIVATION: 160 case CKM_SHA384_KEY_DERIVATION: 161 case CKM_SHA512_KEY_DERIVATION: 162 case CKM_SHA224_KEY_DERIVATION: 163 case CKM_MD5_KEY_DERIVATION: 164 case CKM_MD2_KEY_DERIVATION: 165 /* not sure the following 2 should be CKK_DES or not */ 166 case CKM_KEY_WRAP_LYNKS: /* wrap/unwrap secret key w/ DES key */ 167 case CKM_KEY_WRAP_SET_OAEP: /* wrap/unwarp DES key w/ RSA key */ 168 *ktype = CKK_GENERIC_SECRET; 169 break; 170 171 case CKM_RC2_KEY_GEN: 172 case CKM_RC2_ECB: 173 case CKM_RC2_CBC: 174 case CKM_RC2_MAC: 175 case CKM_RC2_MAC_GENERAL: 176 case CKM_RC2_CBC_PAD: 177 case CKM_PBE_SHA1_RC2_128_CBC: 178 case CKM_PBE_SHA1_RC2_40_CBC: 179 *ktype = CKK_RC2; 180 break; 181 182 case CKM_RC4_KEY_GEN: 183 case CKM_RC4: 184 case CKM_PBE_SHA1_RC4_128: 185 case CKM_PBE_SHA1_RC4_40: 186 *ktype = CKK_RC4; 187 break; 188 189 case CKM_DES_KEY_GEN: 190 case CKM_DES_ECB: 191 case CKM_DES_CBC: 192 case CKM_DES_MAC: 193 case CKM_DES_MAC_GENERAL: 194 case CKM_DES_CBC_PAD: 195 case CKM_PBE_MD2_DES_CBC: 196 case CKM_PBE_MD5_DES_CBC: 197 case CKM_DES_OFB64: 198 case CKM_DES_OFB8: 199 case CKM_DES_CFB64: 200 case CKM_DES_CFB8: 201 case CKM_DES_ECB_ENCRYPT_DATA: 202 case CKM_DES_CBC_ENCRYPT_DATA: 203 *ktype = CKK_DES; 204 break; 205 206 case CKM_DES2_KEY_GEN: 207 case CKM_PBE_SHA1_DES2_EDE_CBC: 208 *ktype = CKK_DES2; 209 break; 210 211 case CKM_DES3_KEY_GEN: 212 case CKM_DES3_ECB: 213 case CKM_DES3_CBC: 214 case CKM_DES3_MAC: 215 case CKM_DES3_MAC_GENERAL: 216 case CKM_DES3_CBC_PAD: 217 case CKM_PBE_SHA1_DES3_EDE_CBC: 218 case CKM_DES3_ECB_ENCRYPT_DATA: 219 case CKM_DES3_CBC_ENCRYPT_DATA: 220 *ktype = CKK_DES3; 221 break; 222 223 case CKM_CAST_KEY_GEN: 224 case CKM_CAST_ECB: 225 case CKM_CAST_CBC: 226 case CKM_CAST_MAC: 227 case CKM_CAST_MAC_GENERAL: 228 case CKM_CAST_CBC_PAD: 229 case CKM_PBE_MD5_CAST_CBC: 230 *ktype = CKK_CAST; 231 break; 232 233 case CKM_CAST3_KEY_GEN: 234 case CKM_CAST3_ECB: 235 case CKM_CAST3_CBC: 236 case CKM_CAST3_MAC: 237 case CKM_CAST3_MAC_GENERAL: 238 case CKM_CAST3_CBC_PAD: 239 case CKM_PBE_MD5_CAST3_CBC: 240 *ktype = CKK_CAST3; 241 break; 242 243 case CKM_CAST128_KEY_GEN: 244 case CKM_CAST128_ECB: 245 case CKM_CAST128_CBC: 246 case CKM_CAST128_MAC: 247 case CKM_CAST128_MAC_GENERAL: 248 case CKM_CAST128_CBC_PAD: 249 case CKM_PBE_MD5_CAST128_CBC: 250 case CKM_PBE_SHA1_CAST128_CBC: 251 *ktype = CKK_CAST128; 252 break; 253 254 case CKM_RC5_KEY_GEN: 255 case CKM_RC5_ECB: 256 case CKM_RC5_CBC: 257 case CKM_RC5_MAC: 258 case CKM_RC5_MAC_GENERAL: 259 case CKM_RC5_CBC_PAD: 260 *ktype = CKK_RC5; 261 break; 262 263 case CKM_IDEA_KEY_GEN: 264 case CKM_IDEA_ECB: 265 case CKM_IDEA_CBC: 266 case CKM_IDEA_MAC: 267 case CKM_IDEA_MAC_GENERAL: 268 case CKM_IDEA_CBC_PAD: 269 *ktype = CKK_IDEA; 270 break; 271 272 case CKM_SKIPJACK_KEY_GEN: 273 case CKM_SKIPJACK_ECB64: 274 case CKM_SKIPJACK_CBC64: 275 case CKM_SKIPJACK_OFB64: 276 case CKM_SKIPJACK_CFB64: 277 case CKM_SKIPJACK_CFB32: 278 case CKM_SKIPJACK_CFB16: 279 case CKM_SKIPJACK_CFB8: 280 case CKM_SKIPJACK_WRAP: 281 case CKM_SKIPJACK_PRIVATE_WRAP: 282 case CKM_SKIPJACK_RELAYX: 283 *ktype = CKK_SKIPJACK; 284 break; 285 286 case CKM_BATON_KEY_GEN: 287 case CKM_BATON_ECB128: 288 case CKM_BATON_ECB96: 289 case CKM_BATON_CBC128: 290 case CKM_BATON_COUNTER: 291 case CKM_BATON_SHUFFLE: 292 case CKM_BATON_WRAP: 293 *ktype = CKK_BATON; 294 break; 295 296 case CKM_JUNIPER_KEY_GEN: 297 case CKM_JUNIPER_ECB128: 298 case CKM_JUNIPER_CBC128: 299 case CKM_JUNIPER_COUNTER: 300 case CKM_JUNIPER_SHUFFLE: 301 case CKM_JUNIPER_WRAP: 302 *ktype = CKK_JUNIPER; 303 break; 304 305 case CKM_CDMF_KEY_GEN: 306 case CKM_CDMF_ECB: 307 case CKM_CDMF_CBC: 308 case CKM_CDMF_MAC: 309 case CKM_CDMF_MAC_GENERAL: 310 case CKM_CDMF_CBC_PAD: 311 *ktype = CKK_CDMF; 312 break; 313 314 case CKM_AES_KEY_GEN: 315 case CKM_AES_ECB: 316 case CKM_AES_CBC: 317 case CKM_AES_MAC: 318 case CKM_AES_MAC_GENERAL: 319 case CKM_AES_CBC_PAD: 320 case CKM_AES_CTR: 321 case CKM_AES_ECB_ENCRYPT_DATA: 322 case CKM_AES_CBC_ENCRYPT_DATA: 323 *ktype = CKK_AES; 324 break; 325 326 case CKM_BLOWFISH_KEY_GEN: 327 case CKM_BLOWFISH_CBC: 328 *ktype = CKK_BLOWFISH; 329 break; 330 331 case CKM_TWOFISH_KEY_GEN: 332 case CKM_TWOFISH_CBC: 333 *ktype = CKK_TWOFISH; 334 break; 335 336 case CKM_SECURID_KEY_GEN: 337 case CKM_SECURID: 338 *ktype = CKK_SECURID; 339 break; 340 341 case CKM_HOTP_KEY_GEN: 342 case CKM_HOTP: 343 *ktype = CKK_HOTP; 344 break; 345 346 case CKM_ACTI: 347 case CKM_ACTI_KEY_GEN: 348 *ktype = CKK_ACTI; 349 break; 350 351 case CKM_CAMELLIA_KEY_GEN: 352 case CKM_CAMELLIA_ECB: 353 case CKM_CAMELLIA_CBC: 354 case CKM_CAMELLIA_MAC: 355 case CKM_CAMELLIA_MAC_GENERAL: 356 case CKM_CAMELLIA_CBC_PAD: 357 case CKM_CAMELLIA_ECB_ENCRYPT_DATA: 358 case CKM_CAMELLIA_CBC_ENCRYPT_DATA: 359 case CKM_CAMELLIA_CTR: 360 *ktype = CKK_CAMELLIA; 361 break; 362 363 case CKM_ARIA_KEY_GEN: 364 case CKM_ARIA_ECB: 365 case CKM_ARIA_CBC: 366 case CKM_ARIA_MAC: 367 case CKM_ARIA_MAC_GENERAL: 368 case CKM_ARIA_CBC_PAD: 369 case CKM_ARIA_ECB_ENCRYPT_DATA: 370 case CKM_ARIA_CBC_ENCRYPT_DATA: 371 *ktype = CKK_ARIA; 372 break; 373 374 default: 375 rv = CKR_MECHANISM_INVALID; 376 break; 377 } 378 379 return (rv); 380 } 381