1 /*
2 * CDDL HEADER START
3 *
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.
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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/errno.h>
29 #include <sys/kmem.h>
30 #include <sys/systm.h>
31 #include <sys/sha1.h>
32 #include <sys/crypto/common.h>
33 #include <sys/cmn_err.h>
34 #include <rng/fips_random.h>
35
36
37 int
n2rng_fips_rng_post(void)38 n2rng_fips_rng_post(void)
39 {
40 static uint8_t XKeyValue[] = {
41 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00
44 };
45
46 static uint8_t XSeed[] = {
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x00
50 };
51
52 static uint8_t rng_known_GENX[] = {
53 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
54 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
55 0xaf, 0xd8, 0x07, 0x09
56 };
57
58 uint8_t GENX[SHA1_HASH_SIZE];
59 uint8_t XKey[SHA1_HASH_SIZE];
60
61 (void) memcpy(XKey, XKeyValue, SHA1_HASH_SIZE);
62
63 /* Generate X with a known seed. */
64 fips_random_inner(
65 (uint32_t *)(void *)XKey,
66 (uint32_t *)(void *)GENX,
67 (uint32_t *)(void *)XSeed);
68
69 /* Verify GENX to perform the RNG integrity check */
70 if ((memcmp(GENX, rng_known_GENX, (SHA1_HASH_SIZE)) != 0))
71 return (CRYPTO_DEVICE_ERROR);
72 else
73 return (CRYPTO_SUCCESS);
74 }
75