8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / pkcs11 / pkcs11_softtoken / common / softRand.c
blob9c602110c196b7e8a26652c9fdce541efdedf4dd
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <security/cryptoki.h>
31 #include <cryptoutil.h>
32 #include "softGlobal.h"
33 #include "softSession.h"
35 CK_RV
36 C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, CK_ULONG ulSeedLen)
39 CK_RV rv;
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);
48 if (rv != CKR_OK)
49 return (rv);
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) {
58 if (errno == EACCES)
59 return (CKR_RANDOM_SEED_NOT_SUPPORTED);
60 return (CKR_DEVICE_ERROR);
62 return (CKR_OK);
66 CK_RV
67 C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pRandomData,
68 CK_ULONG ulRandomLen)
71 CK_RV rv;
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);
80 if (rv != CKR_OK)
81 return (rv);
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);
91 return (CKR_OK);