7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /*
30 * Deimos - cryptographic acceleration based upon Broadcom 582x.
31 */
32
33 #include <sys/types.h>
34 #include <sys/ddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/kmem.h>
37 #include <sys/crypto/dca.h>
38 #include <sys/atomic.h>
39
40 /*
41 * Random number implementation.
42 */
43
44 static int dca_rngstart(dca_t *, dca_request_t *);
45 static void dca_rngdone(dca_request_t *, int);
46
47 static void dca_random_done();
48 int dca_random_buffer(dca_t *dca, caddr_t buf, int len);
199 dca_destroyreq(reqp);
200 else
201 dca_freereq(reqp);
202 }
203
204 /*
205 * This gives a 32k random bytes per buffer. The two buffers will switch back
206 * and forth. When a buffer is used up, a request will be submitted to refill
207 * this buffer before switching to the other one
208 */
209
210 #define RANDOM_BUFFER_SIZE (1<<15)
211 #define DCA_RANDOM_MAX_WAIT 10000
212
213 int
214 dca_random_init(dca_t *dca)
215 {
216 /* Mutex for the local random number pool */
217 mutex_init(&dca->dca_random_lock, NULL, MUTEX_DRIVER, NULL);
218
219 if ((dca->dca_buf1 = kmem_alloc(RANDOM_BUFFER_SIZE, KM_SLEEP)) ==
220 NULL) {
221 mutex_destroy(&dca->dca_random_lock);
222 return (CRYPTO_FAILED);
223 }
224
225 if ((dca->dca_buf2 = kmem_alloc(RANDOM_BUFFER_SIZE, KM_SLEEP)) ==
226 NULL) {
227 mutex_destroy(&dca->dca_random_lock);
228 kmem_free(dca->dca_buf1, RANDOM_BUFFER_SIZE);
229 return (CRYPTO_FAILED);
230 }
231
232 return (CRYPTO_SUCCESS);
233 }
234
235 void
236 dca_random_fini(dca_t *dca)
237 {
238 kmem_free(dca->dca_buf1, RANDOM_BUFFER_SIZE);
239 kmem_free(dca->dca_buf2, RANDOM_BUFFER_SIZE);
240 dca->dca_buf1 = dca->dca_buf2 = dca->dca_buf_ptr = NULL;
241 (void) mutex_destroy(&dca->dca_random_lock);
242 }
243
244 int
245 dca_random_buffer(dca_t *dca, caddr_t buf, int len)
246 {
247 int rv;
248 int i, j;
249 char *fill_buf;
250
|
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Deimos - cryptographic acceleration based upon Broadcom 582x.
29 */
30
31 #include <sys/types.h>
32 #include <sys/ddi.h>
33 #include <sys/sunddi.h>
34 #include <sys/kmem.h>
35 #include <sys/crypto/dca.h>
36 #include <sys/atomic.h>
37
38 /*
39 * Random number implementation.
40 */
41
42 static int dca_rngstart(dca_t *, dca_request_t *);
43 static void dca_rngdone(dca_request_t *, int);
44
45 static void dca_random_done();
46 int dca_random_buffer(dca_t *dca, caddr_t buf, int len);
197 dca_destroyreq(reqp);
198 else
199 dca_freereq(reqp);
200 }
201
202 /*
203 * This gives a 32k random bytes per buffer. The two buffers will switch back
204 * and forth. When a buffer is used up, a request will be submitted to refill
205 * this buffer before switching to the other one
206 */
207
208 #define RANDOM_BUFFER_SIZE (1<<15)
209 #define DCA_RANDOM_MAX_WAIT 10000
210
211 int
212 dca_random_init(dca_t *dca)
213 {
214 /* Mutex for the local random number pool */
215 mutex_init(&dca->dca_random_lock, NULL, MUTEX_DRIVER, NULL);
216
217 dca->dca_buf1 = kmem_alloc(RANDOM_BUFFER_SIZE, KM_SLEEP);
218
219 dca->dca_buf2 = kmem_alloc(RANDOM_BUFFER_SIZE, KM_SLEEP);
220
221 return (CRYPTO_SUCCESS);
222 }
223
224 void
225 dca_random_fini(dca_t *dca)
226 {
227 kmem_free(dca->dca_buf1, RANDOM_BUFFER_SIZE);
228 kmem_free(dca->dca_buf2, RANDOM_BUFFER_SIZE);
229 dca->dca_buf1 = dca->dca_buf2 = dca->dca_buf_ptr = NULL;
230 (void) mutex_destroy(&dca->dca_random_lock);
231 }
232
233 int
234 dca_random_buffer(dca_t *dca, caddr_t buf, int len)
235 {
236 int rv;
237 int i, j;
238 char *fill_buf;
239
|