xref: /titanic_50/usr/src/lib/libwanbootutil/common/key_util.h (revision abc79d9dd51e98eafb6fc25b4a0b4f66bef40b00)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_KEY_UTIL_H
28 #define	_KEY_UTIL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <sys/types.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /* Key algorithms */
40 typedef enum {
41 	WBKU_KEY_3DES,
42 	WBKU_KEY_AES_128,
43 	WBKU_KEY_HMAC_SHA1,
44 	WBKU_KEY_RSA,
45 	WBKU_KEY_UNKNOWN
46 } wbku_key_type_t;
47 
48 /* Algorithm keywords */
49 #define	WBKU_KW_3DES		"3des"
50 #define	WBKU_KW_AES_128		"aes"
51 #define	WBKU_KW_HMAC_SHA1	"sha1"
52 #define	WBKU_KW_RSA		"rsa"
53 
54 /* Algorithm types */
55 #define	WBKU_ENCR_KEY	(uint_t)0x1
56 #define	WBKU_HASH_KEY	(uint_t)0x2
57 #define	WBKU_ANY_KEY	(WBKU_ENCR_KEY | WBKU_HASH_KEY)
58 
59 /* Return codes */
60 typedef enum {
61 	WBKU_SUCCESS,
62 	WBKU_INTERNAL_ERR,
63 	WBKU_WRITE_ERR,
64 	WBKU_NOKEY,
65 	WBKU_BAD_KEYTYPE
66 } wbku_retcode_t;
67 
68 #define	WBKU_NRET		(WBKU_BAD_KEYTYPE + 1)
69 
70 /* The master key file location. */
71 #define	MASTER_KEY_FILE	"/etc/netboot/keystore"
72 
73 /* The root directory for all client keys */
74 #define	CLIENT_KEY_DIR	"/etc/netboot"
75 
76 /* The structure that defines the attributes of a particular key type */
77 typedef struct key_attr {
78 	wbku_key_type_t ka_type; /* key type */
79 	uint_t ka_atype;	/* key algorithm type */
80 	uint_t ka_len;		/* length of the current key */
81 	uint_t ka_minlen;	/* shortest allowable key value */
82 	uint_t ka_maxlen;	/* maximum allowable key length */
83 	char *ka_str;		/* key string identifier */
84 	char *ka_oid;		/* key algorithm oid */
85 	boolean_t (*ka_keycheck)(const uint8_t *); /* keycheck function */
86 } wbku_key_attr_t;
87 
88 extern void wbku_errinit(const char *);
89 extern void wbku_printerr(const char *, ...);
90 extern const char *wbku_retmsg(wbku_retcode_t);
91 extern wbku_retcode_t wbku_str_to_keyattr(const char *, wbku_key_attr_t *,
92     uint_t);
93 extern wbku_retcode_t wbku_find_key(FILE *, fpos_t *, wbku_key_attr_t *,
94     uint8_t *, boolean_t);
95 extern wbku_retcode_t wbku_write_key(FILE *, const fpos_t *,
96     const wbku_key_attr_t *, uint8_t *, boolean_t);
97 extern wbku_retcode_t wbku_delete_key(FILE *, FILE *, const wbku_key_attr_t *);
98 
99 #ifdef	__cplusplus
100 }
101 #endif
102 
103 #endif	/* _KEY_UTIL_H */
104