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.
29 #include <sys/types.h>
30 #include <security/cryptoki.h>
31 #include <cryptoutil.h>
32 #include "softGlobal.h"
33 #include "softSession.h"
36 C_SeedRandom(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pSeed
, CK_ULONG ulSeedLen
)
40 soft_session_t
*session_p
;
41 boolean_t lock_held
= B_FALSE
;
43 if (!softtoken_initialized
)
44 return (CKR_CRYPTOKI_NOT_INITIALIZED
);
46 /* Obtain the session pointer just for validity check. */
47 rv
= handle2session(hSession
, &session_p
);
51 SES_REFRELE(session_p
, lock_held
);
53 if ((pSeed
== NULL
) || (ulSeedLen
== 0)) {
54 return (CKR_ARGUMENTS_BAD
);
57 if (pkcs11_seed_urandom(pSeed
, ulSeedLen
) < 0) {
59 return (CKR_RANDOM_SEED_NOT_SUPPORTED
);
60 return (CKR_DEVICE_ERROR
);
67 C_GenerateRandom(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pRandomData
,
72 soft_session_t
*session_p
;
73 boolean_t lock_held
= B_FALSE
;
75 if (!softtoken_initialized
)
76 return (CKR_CRYPTOKI_NOT_INITIALIZED
);
78 /* Obtain the session pointer just for validity check. */
79 rv
= handle2session(hSession
, &session_p
);
83 SES_REFRELE(session_p
, lock_held
);
85 if ((pRandomData
== NULL
) || (ulRandomLen
== 0)) {
86 return (CKR_ARGUMENTS_BAD
);
89 if (pkcs11_get_urandom(pRandomData
, ulRandomLen
) < 0)
90 return (CKR_DEVICE_ERROR
);