4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "kernelGlobal.h"
31 #include <security/cryptoki.h>
32 #include <sys/crypto/common.h>
33 #include <sys/crypto/ioctl.h>
36 C_SeedRandom(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pSeed
, CK_ULONG ulSeedLen
)
38 kernel_session_t
*session_p
;
39 crypto_seed_random_t seed_random
;
40 boolean_t ses_lock_held
= B_FALSE
;
44 if (!kernel_initialized
)
45 return (CKR_CRYPTOKI_NOT_INITIALIZED
);
47 /* Obtain the session pointer. */
48 rv
= handle2session(hSession
, &session_p
);
52 if ((pSeed
== NULL
) || (ulSeedLen
== 0)) {
53 REFRELE(session_p
, ses_lock_held
);
54 return (CKR_ARGUMENTS_BAD
);
57 seed_random
.sr_session
= session_p
->k_session
;
58 seed_random
.sr_seedbuf
= (caddr_t
)pSeed
;
59 seed_random
.sr_seedlen
= ulSeedLen
;
61 while ((r
= ioctl(kernel_fd
, CRYPTO_SEED_RANDOM
, &seed_random
)) < 0) {
66 rv
= CKR_FUNCTION_FAILED
;
68 if (seed_random
.sr_return_value
!= CRYPTO_SUCCESS
) {
69 rv
= crypto2pkcs11_error_number(
70 seed_random
.sr_return_value
);
76 REFRELE(session_p
, ses_lock_held
);
81 C_GenerateRandom(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pRandomData
,
84 kernel_session_t
*session_p
;
85 crypto_generate_random_t generate_random
;
86 boolean_t ses_lock_held
= B_FALSE
;
90 if (!kernel_initialized
)
91 return (CKR_CRYPTOKI_NOT_INITIALIZED
);
93 /* Obtain the session pointer. */
94 rv
= handle2session(hSession
, &session_p
);
98 if ((pRandomData
== NULL
) || (ulRandomLen
== 0)) {
99 REFRELE(session_p
, ses_lock_held
);
100 return (CKR_ARGUMENTS_BAD
);
103 generate_random
.gr_session
= session_p
->k_session
;
104 generate_random
.gr_buf
= (caddr_t
)pRandomData
;
105 generate_random
.gr_buflen
= ulRandomLen
;
107 while ((r
= ioctl(kernel_fd
, CRYPTO_GENERATE_RANDOM
,
108 &generate_random
)) < 0) {
113 rv
= CKR_FUNCTION_FAILED
;
115 if (generate_random
.gr_return_value
!= CRYPTO_SUCCESS
) {
116 rv
= crypto2pkcs11_error_number(
117 generate_random
.gr_return_value
);
123 REFRELE(session_p
, ses_lock_held
);