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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Random Number Generation Functions
28 * (as defined in PKCS#11 spec section 11.15)
32 #include <sys/types.h>
38 #include "metaGlobal.h"
43 * Unlike most other metaslot functions, meta_SeedRandom does not distribute
44 * the call to a specific provider. Rather, we assume that the /dev/urandom
45 * implementation is a kCF consumer, and is pulling randomness from everywhere
46 * it can. Thus, by seeding /dev/urandom we let kCF potentially do all the
50 * 1) /dev/urandom vs. /dev/random... Unfortunately P11 does not allow app
51 * to request a "quality", so we'll just assume urandom is good enough.
52 * Concerned apps can pull hardcore randomness from specific places they
53 * trust (eg by checking for CKF_HW?)..
57 meta_SeedRandom(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pSeed
,
61 meta_session_t
*session
;
63 if (pSeed
== NULL
|| ulSeedLen
== 0)
64 return (CKR_ARGUMENTS_BAD
);
66 /* Just check handle for validity, we don't need it for anything. */
67 rv
= meta_handle2session(hSession
, &session
);
72 if (pkcs11_seed_urandom(pSeed
, ulSeedLen
) < 0) {
74 return (CKR_RANDOM_SEED_NOT_SUPPORTED
);
75 return (CKR_DEVICE_ERROR
);
83 * Unlike most other metaslot functions, meta_GenerateRandom does not distribute
84 * the call to a specific provider. Rather, we assume that the /dev/urandom
85 * implementation is a kCF consumer, and is pulling randomness from everywhere
86 * it can. Thus, by reading /dev/urandom we let kCF potentially do all the
91 meta_GenerateRandom(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pRandomData
,
95 meta_session_t
*session
;
97 if (pRandomData
== NULL
|| ulRandomLen
< 1)
98 return (CKR_ARGUMENTS_BAD
);
100 /* Just check handle for validity, we don't need it for anything. */
101 rv
= meta_handle2session(hSession
, &session
);
106 if (pkcs11_get_urandom(pRandomData
, ulRandomLen
) < 0) {
107 return (CKR_DEVICE_ERROR
);