1*4f1223e8SApple OSS Distributions /*
2*4f1223e8SApple OSS Distributions * Copyright © 2017-2024 Apple Inc. All rights reserved.
3*4f1223e8SApple OSS Distributions *
4*4f1223e8SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*4f1223e8SApple OSS Distributions *
6*4f1223e8SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*4f1223e8SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*4f1223e8SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*4f1223e8SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*4f1223e8SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*4f1223e8SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*4f1223e8SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*4f1223e8SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*4f1223e8SApple OSS Distributions *
15*4f1223e8SApple OSS Distributions * Please obtain a copy of the License at
16*4f1223e8SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*4f1223e8SApple OSS Distributions *
18*4f1223e8SApple OSS Distributions * The Original Code and all software distributed under the License are
19*4f1223e8SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*4f1223e8SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*4f1223e8SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*4f1223e8SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*4f1223e8SApple OSS Distributions * Please see the License for the specific language governing rights and
24*4f1223e8SApple OSS Distributions * limitations under the License.
25*4f1223e8SApple OSS Distributions *
26*4f1223e8SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*4f1223e8SApple OSS Distributions */
28*4f1223e8SApple OSS Distributions /*!
29*4f1223e8SApple OSS Distributions * @header
30*4f1223e8SApple OSS Distributions * Common types shared across the Image4 trust evaluation API.
31*4f1223e8SApple OSS Distributions */
32*4f1223e8SApple OSS Distributions #ifndef __IMAGE4_API_TYPES_H
33*4f1223e8SApple OSS Distributions #define __IMAGE4_API_TYPES_H
34*4f1223e8SApple OSS Distributions
35*4f1223e8SApple OSS Distributions #include <image4/image4.h>
36*4f1223e8SApple OSS Distributions #include <stdint.h>
37*4f1223e8SApple OSS Distributions #include <stddef.h>
38*4f1223e8SApple OSS Distributions
39*4f1223e8SApple OSS Distributions __BEGIN_DECLS
40*4f1223e8SApple OSS Distributions OS_ASSUME_NONNULL_BEGIN
41*4f1223e8SApple OSS Distributions OS_ASSUME_PTR_ABI_SINGLE_BEGIN
42*4f1223e8SApple OSS Distributions
43*4f1223e8SApple OSS Distributions #pragma mark Definitions
44*4f1223e8SApple OSS Distributions /*!
45*4f1223e8SApple OSS Distributions * @const IMAGE4_DIGEST_MAX_LEN
46*4f1223e8SApple OSS Distributions * The maximum size of a digest.
47*4f1223e8SApple OSS Distributions */
48*4f1223e8SApple OSS Distributions #define IMAGE4_DIGEST_MAX_LEN (64u)
49*4f1223e8SApple OSS Distributions
50*4f1223e8SApple OSS Distributions /*!
51*4f1223e8SApple OSS Distributions * @const IMAGE4_NONCE_MAX_LEN
52*4f1223e8SApple OSS Distributions * The maximum size of a nonce.
53*4f1223e8SApple OSS Distributions */
54*4f1223e8SApple OSS Distributions #define IMAGE4_NONCE_MAX_LEN (16u)
55*4f1223e8SApple OSS Distributions
56*4f1223e8SApple OSS Distributions #pragma mark Supporting Types
57*4f1223e8SApple OSS Distributions /*!
58*4f1223e8SApple OSS Distributions * @typedef image4_struct_version_t
59*4f1223e8SApple OSS Distributions * The version of a structure in the API.
60*4f1223e8SApple OSS Distributions */
61*4f1223e8SApple OSS Distributions typedef uint16_t image4_struct_version_t;
62*4f1223e8SApple OSS Distributions
63*4f1223e8SApple OSS Distributions /*!
64*4f1223e8SApple OSS Distributions * @typedef image4_coprocessor_handle_t
65*4f1223e8SApple OSS Distributions * A handle which specifies a particular execution environment within a
66*4f1223e8SApple OSS Distributions * coprocessor.
67*4f1223e8SApple OSS Distributions */
68*4f1223e8SApple OSS Distributions typedef uint64_t image4_coprocessor_handle_t;
69*4f1223e8SApple OSS Distributions
70*4f1223e8SApple OSS Distributions /*!
71*4f1223e8SApple OSS Distributions * @const IMAGE4_COPROCESSOR_HANDLE_NULL
72*4f1223e8SApple OSS Distributions * An coprocessor handle which is invalid for all coprocessors. This constant is
73*4f1223e8SApple OSS Distributions * suitable for initialization purposes only.
74*4f1223e8SApple OSS Distributions */
75*4f1223e8SApple OSS Distributions #define IMAGE4_COPROCESSOR_HANDLE_NULL ((image4_coprocessor_handle_t)0xffff)
76*4f1223e8SApple OSS Distributions
77*4f1223e8SApple OSS Distributions /*!
78*4f1223e8SApple OSS Distributions * @typedef image4_secure_boot_t
79*4f1223e8SApple OSS Distributions * An enumeration of secure boot levels.
80*4f1223e8SApple OSS Distributions *
81*4f1223e8SApple OSS Distributions * @const IMAGE4_SECURE_BOOT_FULL
82*4f1223e8SApple OSS Distributions * Secure Boot will only accept a live, personalized manifest.
83*4f1223e8SApple OSS Distributions *
84*4f1223e8SApple OSS Distributions * @const IMAGE4_SECURE_BOOT_REDUCED
85*4f1223e8SApple OSS Distributions * Secure Boot will only accept a globally-signed manifest whose lifetime is not
86*4f1223e8SApple OSS Distributions * entangled with the individual silicon instance. The manifest's lifetime may
87*4f1223e8SApple OSS Distributions * be statically constrained in other ways, but the device cannot unilaterally
88*4f1223e8SApple OSS Distributions * host the manifest without a software change.
89*4f1223e8SApple OSS Distributions *
90*4f1223e8SApple OSS Distributions * @const IMAGE4_SECURE_BOOT_LEAST
91*4f1223e8SApple OSS Distributions * Secure Boot will accept any Apple-signed manifest, and the manifest will not
92*4f1223e8SApple OSS Distributions * be meaningfully enforced.
93*4f1223e8SApple OSS Distributions *
94*4f1223e8SApple OSS Distributions * @const IMAGE4_SECURE_BOOT_NONE
95*4f1223e8SApple OSS Distributions * Secure Boot does not meaningfully exist.
96*4f1223e8SApple OSS Distributions */
97*4f1223e8SApple OSS Distributions OS_CLOSED_ENUM(image4_secure_boot, uint64_t,
98*4f1223e8SApple OSS Distributions IMAGE4_SECURE_BOOT_FULL,
99*4f1223e8SApple OSS Distributions IMAGE4_SECURE_BOOT_REDUCED,
100*4f1223e8SApple OSS Distributions IMAGE4_SECURE_BOOT_LEAST,
101*4f1223e8SApple OSS Distributions IMAGE4_SECURE_BOOT_NONE,
102*4f1223e8SApple OSS Distributions _IMAGE4_SECURE_BOOT_CNT,
103*4f1223e8SApple OSS Distributions );
104*4f1223e8SApple OSS Distributions
105*4f1223e8SApple OSS Distributions /*!
106*4f1223e8SApple OSS Distributions * @function image4_secure_boot_check
107*4f1223e8SApple OSS Distributions * Checks the secure boot level to ensure that it represents a valid, known
108*4f1223e8SApple OSS Distributions * secure boot configuration.
109*4f1223e8SApple OSS Distributions *
110*4f1223e8SApple OSS Distributions * @param sb
111*4f1223e8SApple OSS Distributions * The secure boot level.
112*4f1223e8SApple OSS Distributions *
113*4f1223e8SApple OSS Distributions * @result
114*4f1223e8SApple OSS Distributions * If the {@link sb} is a valid secure boot level, zero is returned. Otherwise,
115*4f1223e8SApple OSS Distributions * a non-zero value is returned.
116*4f1223e8SApple OSS Distributions */
117*4f1223e8SApple OSS Distributions OS_ALWAYS_INLINE OS_WARN_RESULT
118*4f1223e8SApple OSS Distributions static inline int
image4_secure_boot_check(image4_secure_boot_t sb)119*4f1223e8SApple OSS Distributions image4_secure_boot_check(image4_secure_boot_t sb)
120*4f1223e8SApple OSS Distributions {
121*4f1223e8SApple OSS Distributions if (sb > _IMAGE4_SECURE_BOOT_CNT) {
122*4f1223e8SApple OSS Distributions __builtin_trap();
123*4f1223e8SApple OSS Distributions }
124*4f1223e8SApple OSS Distributions if (sb == _IMAGE4_SECURE_BOOT_CNT) {
125*4f1223e8SApple OSS Distributions return 1;
126*4f1223e8SApple OSS Distributions }
127*4f1223e8SApple OSS Distributions return 0;
128*4f1223e8SApple OSS Distributions }
129*4f1223e8SApple OSS Distributions
130*4f1223e8SApple OSS Distributions #pragma mark API Objects
131*4f1223e8SApple OSS Distributions /*!
132*4f1223e8SApple OSS Distributions * @typedef image4_coprocessor_t
133*4f1223e8SApple OSS Distributions * An opaque structure representing a coprocessor.
134*4f1223e8SApple OSS Distributions */
135*4f1223e8SApple OSS Distributions typedef struct _image4_coprocessor image4_coprocessor_t;
136*4f1223e8SApple OSS Distributions
137*4f1223e8SApple OSS Distributions /*!
138*4f1223e8SApple OSS Distributions * @typedef image4_environment_t
139*4f1223e8SApple OSS Distributions * An opaque structure representing an Image4 trust evaluation environment.
140*4f1223e8SApple OSS Distributions */
141*4f1223e8SApple OSS Distributions typedef struct _image4_environment image4_environment_t;
142*4f1223e8SApple OSS Distributions
143*4f1223e8SApple OSS Distributions /*!
144*4f1223e8SApple OSS Distributions * @typedef image4_identifier_t
145*4f1223e8SApple OSS Distributions * An opaque structure representing an Image4 identifier.
146*4f1223e8SApple OSS Distributions */
147*4f1223e8SApple OSS Distributions typedef struct _image4_identifier image4_identifier_t;
148*4f1223e8SApple OSS Distributions
149*4f1223e8SApple OSS Distributions /*!
150*4f1223e8SApple OSS Distributions * @typedef image4_trust_evaluation_t
151*4f1223e8SApple OSS Distributions * An opaque structure representing an Image4 trust evaluation.
152*4f1223e8SApple OSS Distributions */
153*4f1223e8SApple OSS Distributions typedef struct _image4_trust_evaluation image4_trust_evaluation_t;
154*4f1223e8SApple OSS Distributions
155*4f1223e8SApple OSS Distributions /*!
156*4f1223e8SApple OSS Distributions * @typedef image4_trust_t
157*4f1223e8SApple OSS Distributions * An opaque structure representing an Image4 trust object which performs
158*4f1223e8SApple OSS Distributions * evaluations.
159*4f1223e8SApple OSS Distributions */
160*4f1223e8SApple OSS Distributions typedef struct _image4_trust image4_trust_t;
161*4f1223e8SApple OSS Distributions
162*4f1223e8SApple OSS Distributions OS_ASSUME_PTR_ABI_SINGLE_END
163*4f1223e8SApple OSS Distributions OS_ASSUME_NONNULL_END
164*4f1223e8SApple OSS Distributions __END_DECLS
165*4f1223e8SApple OSS Distributions
166*4f1223e8SApple OSS Distributions #endif // __IMAGE4_API_TYPES_H
167