dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / pkcs11 / libpkcs11 / common / pkcs11Rand.c
blobdc1f3a6980577300326801a2a61d842c4bc9c384
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <security/cryptoki.h>
30 #include "pkcs11Global.h"
31 #include "pkcs11Session.h"
32 #include "pkcs11Slot.h"
35 * C_SeedRandom will verify that the session handle is valid within
36 * the framework, that random numbers are not disabled for the slot
37 * associated with this session, and then redirect to the underlying
38 * provider.
40 CK_RV
41 C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, CK_ULONG ulSeedLen)
43 CK_RV rv;
44 pkcs11_session_t *sessp;
45 CK_SLOT_ID slotid;
47 /* Check for a fastpath */
48 if (purefastpath || policyfastpath) {
49 /* Check if random number functions are allowed */
50 if (policyfastpath &&
51 slottable->st_slots[fast_slot]->sl_norandom) {
52 return (CKR_FUNCTION_FAILED);
54 return (fast_funcs->C_SeedRandom(hSession, pSeed, ulSeedLen));
57 if (!pkcs11_initialized) {
58 return (CKR_CRYPTOKI_NOT_INITIALIZED);
61 /* Obtain the session pointer */
62 HANDLE2SESSION(hSession, sessp, rv);
64 if (rv != CKR_OK) {
65 return (rv);
68 slotid = sessp->se_slotid;
70 /* Check if random number functions are allowed */
71 if (slottable->st_slots[slotid]->sl_norandom)
72 return (CKR_FUNCTION_FAILED);
74 /* Pass data to the provider */
75 rv = FUNCLIST(slotid)->C_SeedRandom(sessp->se_handle, pSeed,
76 ulSeedLen);
78 /* Present consistent interface to the application */
79 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
80 return (CKR_FUNCTION_FAILED);
83 return (rv);
87 * C_GenerateRandom will verify that the session handle is valid within
88 * the framework, that random numbers are not disabled for the slot
89 * associated with this session, and then redirect to the underlying
90 * provider.
92 CK_RV
93 C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pRandomData,
94 CK_ULONG ulRandomLen)
96 CK_RV rv;
97 pkcs11_session_t *sessp;
98 CK_SLOT_ID slotid;
100 /* Check for a fastpath */
101 if (purefastpath || policyfastpath) {
102 /* Check if random number functions are allowed */
103 if (policyfastpath &&
104 slottable->st_slots[fast_slot]->sl_norandom) {
105 return (CKR_FUNCTION_FAILED);
107 return (fast_funcs->C_GenerateRandom(hSession, pRandomData,
108 ulRandomLen));
111 if (!pkcs11_initialized) {
112 return (CKR_CRYPTOKI_NOT_INITIALIZED);
115 /* Obtain the session pointer */
116 HANDLE2SESSION(hSession, sessp, rv);
118 if (rv != CKR_OK) {
119 return (rv);
122 slotid = sessp->se_slotid;
124 /* Check if random number functions are allowed */
125 if (slottable->st_slots[slotid]->sl_norandom)
126 return (CKR_FUNCTION_FAILED);
128 /* Pass data to the provider */
129 rv = FUNCLIST(sessp->se_slotid)->C_GenerateRandom(sessp->se_handle,
130 pRandomData, ulRandomLen);
132 /* Present consistent interface to the application */
133 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
134 return (CKR_FUNCTION_FAILED);
137 return (rv);