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
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]
23 * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This provides the interface to store a named key in stable local
31 * storage. These keys are retrieved and used by OBP and WAN boot
32 * to do decryption and HMAC verification of network-downloaded data.
35 #include <sys/promimpl.h>
36 #ifdef PROM_32BIT_ADDRS
37 #include <sys/sunddi.h>
38 #endif /* PROM_32BIT_ADDRS */
41 prom_set_security_key(char *keyname
, caddr_t buf
, int buflen
, int *reslen
,
47 #ifdef PROM_32BIT_ADDRS
48 char *okeyname
= NULL
;
52 if ((uintptr_t)keyname
> (uint32_t)-1) {
54 keynamelen
= prom_strlen(okeyname
) + 1; /* include '\0' */
55 keyname
= promplat_alloc(keynamelen
);
58 (void) prom_strcpy(keyname
, okeyname
);
62 * A key length of zero is used to delete the named key.
63 * No need to reallocate and copy buf[] in this case.
65 if (buflen
> 0 && ((uintptr_t)buf
> (uint32_t)-1)) {
67 buf
= promplat_alloc(buflen
);
68 if ((buf
== NULL
) && (okeyname
!= NULL
)) {
69 promplat_free(keyname
, keynamelen
);
72 promplat_bcopy(obuf
, buf
, buflen
);
74 #endif /* PROM_32BIT_ADDRS */
77 * The arguments to the SUNW,set-security-key service
78 * that stores a key are
79 * ci[0] the service name
80 * ci[1] the number of ``in'' arguments
81 * ci[2] the number of ``out'' arguments
82 * ci[3] the key's name, as a string
83 * ci[4] the key buffer itself
84 * ci[5] the length of the key buffer
86 * When p1275_cif_handler() returns, the return value is
87 * ci[6] the length of the key stored, or (if
88 * negative) an error code.
90 ci
[0] = p1275_ptr2cell("SUNW,set-security-key");
93 ci
[3] = p1275_ptr2cell(keyname
);
94 ci
[4] = p1275_ptr2cell(buf
);
95 ci
[5] = p1275_uint2cell(buflen
);
98 rv
= p1275_cif_handler(ci
);
101 #ifdef PROM_32BIT_ADDRS
102 if (okeyname
!= NULL
)
103 promplat_free(keyname
, keynamelen
);
105 promplat_free(buf
, buflen
);
106 #endif /* PROM_32BIT_ADDRS */
111 result
= p1275_cell2int(ci
[6]);
123 prom_get_security_key(char *keyname
, caddr_t buf
, int buflen
, int *keylen
,
129 #ifdef PROM_32BIT_ADDRS
130 char *okeyname
= NULL
;
134 if ((uintptr_t)keyname
> (uint32_t)-1) {
136 keynamelen
= prom_strlen(okeyname
) + 1; /* include '\0' */
137 keyname
= promplat_alloc(keynamelen
);
140 (void) prom_strcpy(keyname
, okeyname
);
142 if ((uintptr_t)buf
> (uint32_t)-1) {
144 buf
= promplat_alloc(buflen
);
145 if ((buf
== NULL
) && (okeyname
!= NULL
)) {
146 promplat_free(keyname
, keynamelen
);
150 #endif /* PROM_32BIT_ADDRS */
153 * The arguments to the SUNW,get-security-key service
154 * that stores a key are
155 * ci[0] the service name
156 * ci[1] the number of ``in'' arguments
157 * ci[2] the number of ``out'' arguments
158 * ci[3] the key's name, as a string
159 * ci[4] the key buffer itself
160 * ci[5] the length of the key buffer
162 * When p1275_cif_handler() returns, the return value is
163 * ci[6] the length of the key, or (if
164 * negative) an error code.
166 ci
[0] = p1275_ptr2cell("SUNW,get-security-key");
169 ci
[3] = p1275_ptr2cell(keyname
);
170 ci
[4] = p1275_ptr2cell(buf
);
171 ci
[5] = p1275_uint2cell(buflen
);
174 rv
= p1275_cif_handler(ci
);
177 #ifdef PROM_32BIT_ADDRS
178 if (okeyname
!= NULL
)
179 promplat_free(keyname
, keynamelen
);
181 promplat_bcopy(buf
, obuf
, buflen
);
182 promplat_free(buf
, buflen
);
184 #endif /* PROM_32BIT_ADDRS */
189 result
= p1275_cell2int(ci
[6]);