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