xref: /titanic_44/usr/src/uts/common/sys/crypto/elfsign.h (revision 8339b41da2395f0525c46ceedfeb01961893ec44)
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  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _SYS_CRYPTO_ELFSIGN_H
26 #define	_SYS_CRYPTO_ELFSIGN_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * Consolidation Private Interface for elfsign/libpkcs11/kcfd
34  */
35 
36 #include <sys/types.h>
37 #include <sys/param.h>
38 
39 /*
40  * Project Private structures and types used for communication between kcfd
41  * and KCF over the door.
42  */
43 
44 typedef enum ELFsign_status_e {
45 	ELFSIGN_UNKNOWN,
46 	ELFSIGN_SUCCESS,
47 	ELFSIGN_FAILED,
48 	ELFSIGN_NOTSIGNED,
49 	ELFSIGN_INVALID_CERTPATH,
50 	ELFSIGN_INVALID_ELFOBJ,
51 	ELFSIGN_UNAVAILABLE
52 } ELFsign_status_t;
53 
54 
55 /* Version values for da_version in kcf_door_args_t */
56 #define	KCF_KCFD_VERSION1	1
57 #define	KCFD_FIPS140_INTCHECK	2
58 
59 #define	SIG_MAX_LENGTH		1024
60 
61 #define	ELF_SIGNATURE_SECTION	".SUNW_signature"
62 
63 typedef struct kcf_door_arg_s {
64 	short		da_version;
65 	boolean_t	da_iskernel;
66 
67 	union {
68 		char filename[MAXPATHLEN];	/* For request */
69 
70 		struct kcf_door_result_s {	/* For response */
71 			ELFsign_status_t	status;
72 			uint32_t		siglen;
73 			uchar_t			signature[1];
74 		} result;
75 	} da_u;
76 } kcf_door_arg_t;
77 
78 typedef uint32_t	filesig_vers_t;
79 
80 /*
81  * File Signature Structure
82  *	Applicable to ELF and other file formats
83  */
84 struct filesignatures {
85 	uint32_t	filesig_cnt;	/* count of signatures */
86 	uint32_t	filesig_pad;	/* unused */
87 	union {
88 		char	filesig_data[1];
89 		struct filesig {	/* one of these for each signature */
90 			uint32_t	filesig_size;
91 			filesig_vers_t	filesig_version;
92 			union {
93 				struct filesig_version1 {
94 					uint32_t	filesig_v1_dnsize;
95 					uint32_t	filesig_v1_sigsize;
96 					uint32_t	filesig_v1_oidsize;
97 					char	filesig_v1_data[1];
98 				} filesig_v1;
99 				struct filesig_version3 {
100 					uint64_t	filesig_v3_time;
101 					uint32_t	filesig_v3_dnsize;
102 					uint32_t	filesig_v3_sigsize;
103 					uint32_t	filesig_v3_oidsize;
104 					char	filesig_v3_data[1];
105 				} filesig_v3;
106 			} _u2;
107 		} filesig_sig;
108 		uint64_t filesig_align;
109 	} _u1;
110 };
111 #define	filesig_sig		_u1.filesig_sig
112 
113 #define	filesig_v1_dnsize	_u2.filesig_v1.filesig_v1_dnsize
114 #define	filesig_v1_sigsize	_u2.filesig_v1.filesig_v1_sigsize
115 #define	filesig_v1_oidsize	_u2.filesig_v1.filesig_v1_oidsize
116 #define	filesig_v1_data		_u2.filesig_v1.filesig_v1_data
117 
118 #define	filesig_v3_time		_u2.filesig_v3.filesig_v3_time
119 #define	filesig_v3_dnsize	_u2.filesig_v3.filesig_v3_dnsize
120 #define	filesig_v3_sigsize	_u2.filesig_v3.filesig_v3_sigsize
121 #define	filesig_v3_oidsize	_u2.filesig_v3.filesig_v3_oidsize
122 #define	filesig_v3_data		_u2.filesig_v3.filesig_v3_data
123 
124 #define	filesig_ALIGN(s)	(((s) + sizeof (uint64_t) - 1) & \
125 				    (-sizeof (uint64_t)))
126 #define	filesig_next(ptr)	(struct filesig *)((void *)((char *)(ptr) + \
127 				    filesig_ALIGN((ptr)->filesig_size)))
128 
129 #define	FILESIG_UNKNOWN		0	/* unrecognized version */
130 #define	FILESIG_VERSION1	1	/* version1, all but sig section */
131 #define	FILESIG_VERSION2	2	/* version1 format, SHF_ALLOC only */
132 #define	FILESIG_VERSION3	3	/* version3, all but sig section */
133 #define	FILESIG_VERSION4	4	/* version3 format, SHF_ALLOC only */
134 
135 #ifndef	_KERNEL
136 
137 #define	_PATH_KCFD_DOOR	"/etc/svc/volatile/kcfd_door"
138 
139 #endif	/* _KERNEL */
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* _SYS_CRYPTO_ELFSIGN_H */
146