Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/*!
 * @header
 * Provides an interface for managing nonces to govern the lifetime of a
 * personalization performed with TSS. A nonce managed by this interface may
 * be used in a TSS signing request as the value for the BNCH tag.
 *
 * These interfaces require the caller to possess the
 *
 *     com.apple.private.security.AppleImage4.user-client
 *
 * entitlement.
 *
 * @section Threat Model
 * The adversary possesses the following:
 *
 *     1. a manifest which was previously valid but has since been invalidated
 *        by rolling the nonce associated with it
 *     2. user-level code execution
 *     3. knowledge of the raw nonce value for the previously-valid manifest
 *
 * The defense against this adversary is a system in which knowledge of the raw
 * nonce is insufficient to impact the evaluation of a personalization. This
 * system has the following characteristics:
 *
 *     1. A nonce seed is stored in an nvram variable which is only writable by
 *        the kernel
 *     2. When making a new signing request, the nonce seed is encrypted by a
 *        UID1-derived key in-kernel and then hashed -- the output of this
 *        operation the nonce to be used in the signing request
 *     3. On boot, AppleImage4 obtains the nonce seed from nvram and stores it
 *        in a data structure which will be covered by KTRR
 *     4. When evaluating a manifest, AppleImage4 reads the raw nonce from the
 *        KTRR-covered data structure and validates it with the same
 *        transformation as was done in (2)
 *     5. When the nonce is to be invalidated, AppleImage4 sets a flag in an
 *        nvram variable which is only writable by the kernel
 *     6. On the subsequent boot, AppleImage4 notices the flag, generates a new
 *        nonce and repeats the procedure in (3)
 *
 * In this system, the raw nonce seed never leaves the kernel, and the nonce
 * itself is a non-reversible representation of the seed.
 */


#ifndef __IMG4_NONCE_H
#define __IMG4_NONCE_H

#ifndef __IMG4_INDIRECT
#error "Please #include <img4/firmware.h> instead of this file directly"
#endif // __IMG4_INDIRECT

__BEGIN_DECLS
OS_ASSUME_NONNULL_BEGIN
OS_ASSUME_PTR_ABI_SINGLE_BEGIN

/*!
 * @typedef img4_nonce_domain_t
 * An opaque type describing a nonce domain.
 */
IMG4_API_AVAILABLE_20181106
typedef struct _img4_nonce_domain img4_nonce_domain_t;

/*!
 * @const IMG4_NONCE_STRUCT_VERSION
 * The version of the {@link img4_nonce_t} structure supported by the
 * implementation.
 */
#define IMG4_NONCE_STRUCT_VERSION ((img4_struct_version_t)0)
#define IMG4_NONCE_VERSION IMG4_NONCE_STRUCT_VERSION

/*!
 * @const IMG4_NONCE_MAX_LENGTH
 * The maximum length of a nonce. Currently, this is the length of a SHA2-384
 * hash.
 */
#define IMG4_NONCE_MAX_LENGTH (48u)

/*!
 * @typedef img4_nonce_domain_index_t
 * An enumeration describing nonce domains.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_TEST
 * The enumerated constant corresponding to the internal test nonce domain.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_TRUST_CACHE
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_TRUST_CACHE}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_PDI
 * The enumerated constant corresponding to {@link IMG4_NONCE_DOMAIN_TRUST_PDI}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_CRYPTEX
 * The enumerated constant corresponding to {@link IMG4_NONCE_DOMAIN_CRYPTEX}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_DDI
 * The enumerated constant corresponding to {@link IMG4_NONCE_DOMAIN_DDI}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_EPHEMERAL_CRYPTEX
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_EPHEMERAL_CRYPTEX}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_SNUF_STUB
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_CRYPTEX1_SNUF_STUB}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_BOOT
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_CRYPTEX1_BOOT}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_ASSET
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_CRYPTEX1_ASSET}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_GENERIC
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_CRYPTEX1_GENERIC}.
 *
 * @const IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_SIMULATOR
 * The enumerated constant corresponding to
 * {@link IMG4_NONCE_DOMAIN_CRYPTEX1_SIMULATOR}.
 *
 * @const _IMG4_NONCE_DOMAIN_INDEX_CNT
 * A sentinel value indicating the number of nonce domains.
 */
IMG4_API_AVAILABLE_20210521
OS_CLOSED_ENUM(img4_nonce_domain_index, uint64_t,
	IMG4_NONCE_DOMAIN_INDEX_TEST = 0,
	IMG4_NONCE_DOMAIN_INDEX_TRUST_CACHE,
	IMG4_NONCE_DOMAIN_INDEX_PDI,
	IMG4_NONCE_DOMAIN_INDEX_CRYPTEX,
	IMG4_NONCE_DOMAIN_INDEX_DDI,
	IMG4_NONCE_DOMAIN_INDEX_EPHEMERAL_CRYPTEX,
	IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_SNUF_STUB,
	IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_BOOT,
	IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_ASSET,
	IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_GENERIC,
	IMG4_NONCE_DOMAIN_INDEX_CRYPTEX1_SIMULATOR,
	_IMG4_NONCE_DOMAIN_INDEX_CNT,
);

/*!
 * @typedef img4_nonce_t
 * A structure describing a nonce.
 *
 * @field i4n_version
 * The version of the structure. When declaring this structure, you must
 * initialize this field to {@link IMG4_NONCE_VERSION}.
 *
 * @field i4n_nonce
 * The bytes comprising the nonce.
 *
 * @field i4n_length
 * The length of the nonce. Will be at most {@link IMG4_NONCE_MAX_LENGTH}.
 *
 * @discussion
 * The {@link i4n_nonce} field was previously const. This was a terrible idea,
 * and the const storage qualifier was removed without adjusting the structure
 * version.
 */
IMG4_API_AVAILABLE_20181106
typedef struct _img4_nonce {
	img4_struct_version_t i4n_version;
	uint8_t i4n_nonce[IMG4_NONCE_MAX_LENGTH];
	uint32_t i4n_length;
} img4_nonce_t;

/*!
 * @const IMG4_NONCE_INIT
 * A convenience initializer for {@link img4_nonce_t} which ensures that the
 * {@link i4n_version} field is properly initialized.
 */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define IMG4_NONCE_INIT (img4_nonce_t){.i4n_version = IMG4_NONCE_STRUCT_VERSION}
#elif defined(__cplusplus) && __cplusplus >= 201103L
#define IMG4_NONCE_INIT (img4_nonce_t{IMG4_NONCE_STRUCT_VERSION})
#elif defined(__cplusplus)
#define IMG4_NONCE_INIT \
		(img4_nonce_t((img4_nonce_t){IMG4_NONCE_STRUCT_VERSION}))
#else
#define IMG4_NONCE_INIT {IMG4_NONCE_STRUCT_VERSION}
#endif

/*!
 * @const IMG4_NONCE_ZERO
 * A convenience initializer for {@link img4_nonce_t} which initializes a 48-
 * byte nonce of all zeroes.
 */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define IMG4_NONCE_ZERO (img4_nonce_t){ \
	.i4n_version = IMG4_NONCE_STRUCT_VERSION, \
	.i4n_nonce = {0}, \
	.i4n_length = IMG4_NONCE_MAX_LENGTH, \
}
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_TRUST_CACHE
 * The nonce domain governing trust cache personalizations. Use of this domain
 * requires the
 *
 *     com.apple.private.img4.nonce.trust-cache
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20181106
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_trust_cache;
#define IMG4_NONCE_DOMAIN_TRUST_CACHE (&_img4_nonce_domain_trust_cache)
#else
#define IMG4_NONCE_DOMAIN_TRUST_CACHE (img4if->i4if_v1.nonce_domain_trust_cache)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_PDI
 * The nonce domain governing disk image personalizations. Use of this domain
 * requires the
 *
 *     com.apple.private.img4.nonce.pdi
 *
 * entitlement. The nonce for this domain is regenerated once every boot.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20181106
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_pdi;
#define IMG4_NONCE_DOMAIN_PDI (&_img4_nonce_domain_pdi)
#else
#define IMG4_NONCE_DOMAIN_PDI (img4if->i4if_v3.nonce_domain_pdi)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_CRYPTEX
 * The nonce domain governing cryptex personalizations. Use of this domain
 * requires the
 *
 *     com.apple.private.img4.nonce.cryptex
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20181106
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_cryptex;
#define IMG4_NONCE_DOMAIN_CRYPTEX (&_img4_nonce_domain_cryptex)
#else
#define IMG4_NONCE_DOMAIN_CRYPTEX (img4if->i4if_v3.nonce_domain_cryptex)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_DDI
 * The nonce domain governing developer disk image personalizations. Use of this
 * domain requires the
 *
 *     com.apple.private.img4.nonce.ddi
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20181106
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_ddi;
#define IMG4_NONCE_DOMAIN_DDI (&_img4_nonce_domain_ddi)
#else
#define IMG4_NONCE_DOMAIN_DDI (img4if->i4if_v12.nonce_domain_ddi)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_EPHEMERAL_CRYPTEX
 * The nonce domain governing ephemeral cryptex personalizations. Use of this
 * domain requires the
 *
 *     com.apple.private.img4.nonce.ephemeral-cryptex
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20210305
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_ephemeral_cryptex;
#define IMG4_NONCE_DOMAIN_EPHEMERAL_CRYPTEX \
		(&_img4_nonce_domain_ephemeral_cryptex)
#else
#define IMG4_NONCE_DOMAIN_EPHEMERAL_CRYPTEX \
		(img4if->i4if_v12.nonce_domain_ephemeral_cryptex)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_CRYPTEX1_SNUF_STUB
 * The nonce domain which acts as a null stub for the snuf value for Cryptex1
 * processors. This domain corresponds to a value of 0 for the
 * Cryptex1,NonceDomain tag. Use of this domain requires the
 *
 *     com.apple.private.img4.nonce.cryptex1.snuf-stub
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20220322
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_cryptex1_snuf_stub;
#define IMG4_NONCE_DOMAIN_CRYPTEX1_SNUF_STUB \
		(&_img4_nonce_domain_cryptex1_snuf_stub)
#else
#define IMG4_NONCE_DOMAIN_CRYPTEX1_SNUF_STUB \
		(img4if->i4if_v18.nonce_domain_cryptex1_snuf_stub)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_CRYPTEX1_BOOT
 * The nonce domain governing personalizations for the virtual Cryptex1
 * coprocessor's boot objects. This domain corresponds to a value of 1 for the
 * Cryptex1,NonceDomain tag. Use of this domain requires the
 *
 *     com.apple.private.img4.nonce.cryptex1.boot
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20211112
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_cryptex1_boot;
#define IMG4_NONCE_DOMAIN_CRYPTEX1_BOOT \
		(&_img4_nonce_domain_cryptex1_boot)
#else
#define IMG4_NONCE_DOMAIN_CRYPTEX1_BOOT \
		(img4if->i4if_v16.nonce_domain_cryptex1_boot)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_CRYPTEX1_ASSET
 * The nonce domain governing personalizations for the virtual Cryptex1
 * coprocessor's asset brain objects. This domain corresponds to a value of 2
 * for the Cryptex1,NonceDomain tag. Use of this domain requires the
 *
 *     com.apple.private.img4.nonce.cryptex1.asset
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20211112
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_cryptex1_asset;
#define IMG4_NONCE_DOMAIN_CRYPTEX1_ASSET \
		(&_img4_nonce_domain_cryptex1_asset)
#else
#define IMG4_NONCE_DOMAIN_CRYPTEX1_ASSET \
		(img4if->i4if_v16.nonce_domain_cryptex1_asset)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_CRYPTEX1_GENERIC
 * The nonce domain governing personalizations for the virtual Cryptex1
 * coprocessor's generic supplemental objects. This domain corresponds to a
 * value of 3 for the Cryptex1,NonceDomain tag. Use of this domain requires the
 *
 *     com.apple.private.img4.nonce.cryptex1.supplemental
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20221202
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_cryptex1_generic;
#define IMG4_NONCE_DOMAIN_CRYPTEX1_GENERIC \
		(&_img4_nonce_domain_cryptex1_generic)
#else
#define IMG4_NONCE_DOMAIN_CRYPTEX1_GENERIC \
		(img4if->i4if_v20.nonce_domain_cryptex1_generic)
#endif

/*!
 * @const IMG4_NONCE_DOMAIN_CRYPTEX1_SIMULATOR
 * The nonce domain governing personalizations for the virtual Cryptex1
 * coprocessor's Simulator runtime objects. This domain corresponds to a value
 * of 4 for the Cryptex1,NonceDomain tag. Use of this domain requires the
 *
 *     com.apple.private.img4.nonce.cryptex1.simulator
 *
 * entitlement.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20221202
OS_EXPORT
const struct _img4_nonce_domain _img4_nonce_domain_cryptex1_simulator;
#define IMG4_NONCE_DOMAIN_CRYPTEX1_SIMULATOR \
		(&_img4_nonce_domain_cryptex1_simulator)
#else
#define IMG4_NONCE_DOMAIN_CRYPTEX1_SIMULATOR \
		(img4if->i4if_v20.nonce_domain_cryptex1_simulator)
#endif

/*!
 * @function img4_nonce_domain_copy_nonce
 * Copies the current value of the nonce in the given domain.
 *
 * @param nd
 * The nonce domain.
 *
 * @param n
 * Upon successful return, storage that will contain the current nonce. The
 * provided structure's {@link i4n_version} must be initialized to
 * {@link IMG4_NONCE_VERSION}.
 *
 * @result
 * Upon success, zero is returned. The implementation may also return one of the
 * following error codes directly:
 *
 *     [ESTALE]     The nonce for the given domain has been invalidated, and the
 *                  host must reboot in order to generate a new one
 *     [EPERM]      The caller lacked the entitlement necessary to read the
 *                  given nonce
 *     [ENOTSUP]    Nonce management is not available on the host
 *     [EACCES]     The nonce requested is not accessible in this environment
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20210305
OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
errno_t
img4_nonce_domain_copy_nonce(const img4_nonce_domain_t *nd, img4_nonce_t *n);
#else
#define img4_nonce_domain_copy_nonce(...) \
		(img4if->i4if_v1.nonce_domain_copy_nonce(__VA_ARGS__))
#endif

/*!
 * @function img4_nonce_domain_roll_nonce
 * Invalidates the current nonce for the given domain and forces a re-generation
 * of the domain's nonce seed at the next boot.
 *
 * @param nd
 * The nonce domain.
 *
 * @result
 * Upon success, zero is returned. The kernel implementation will never return
 * a non-zero code. The userspace implementation may return one of the following
 * error codes directly:
 *
 *     [EPERM]      The caller lacked the entitlement necessary to roll the
 *                  given nonce
 *     [EROFS]      The boot mode didn't allow committing to non-volatile storage
 *     [ENOTSUP]    Nonce management is not available on the host
 *     [EACCES]     The nonce requested is not accessible in this environment
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20181106
OS_EXPORT OS_WARN_RESULT OS_NONNULL1
errno_t
img4_nonce_domain_roll_nonce(const img4_nonce_domain_t *nd);
#else
#define img4_nonce_domain_roll_nonce(...) \
		(img4if->i4if_v1.nonce_domain_roll_nonce(__VA_ARGS__))
#endif

/*!
 * @function img4_nonce_domain_preroll_nonce
 * Generates a new nonce seed and returns the resulting hash. The new nonce seed
 * will be in force at the next reboot if and only if the boot manifest hash
 * changes. Otherwise, the current nonce seed value will remain stable (modulo
 * the regeneration policy associated with its domain).
 *
 * @param nd
 * The nonce domain.
 *
 * @param n
 * Upon successful return, storage that will contain the current nonce. The
 * provided structure's {@link i4n_version} must be initialized to
 * {@link IMG4_NONCE_VERSION}.
 *
 * @result
 * Upon success, zero is returned. The kernel implementation will never return
 * a non-zero code. The userspace implementation may return one of the following
 * error codes directly:
 *
 *     [EPERM]      The caller lacked the entitlement necessary to roll the
 *                  given nonce
 *     [EROFS]      The boot mode didn't allow committing to non-volatile storage
 *     [ENOTSUP]    Nonce management is not available on the host
 *     [EACCES]     The nonce requested is not accessible in this environment
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_FALL_2021_B
OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
errno_t
img4_nonce_domain_preroll_nonce(const img4_nonce_domain_t *nd, img4_nonce_t *n);
#else
#define img4_nonce_domain_preroll_nonce(...) \
		(img4if->i4if_v14.nonce_domain_preroll_nonce(__VA_ARGS__))
#endif

/*!
 * @function img4_nonce_domain_peek_nonce
 * Copies the current proposed value of a nonce domain.
 *
 * @param nd
 * The nonce domain.
 *
 * @param n
 * Upon successful return, storage that will contain the current proposed
 * nonce. The provided structure's {@link i4n_version} must be initialized to
 * {@link IMG4_NONCE_VERSION}.
 *
 * @result
 * Upon success, zero is returned. The implementation may also return one of the
 * following error codes directly:
 *
 *     [EPERM]      The caller lacked the entitlement necessary to roll the
 *                  given nonce
 *     [ENOENT]     The nonce doesn't have a proposed value
 *     [ENOTSUP]    Nonce management is not available on the host
 *     [EACCES]     The nonce requested is not accessible in this environment
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20220714
OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2
errno_t
img4_nonce_domain_peek_nonce(const img4_nonce_domain_t *nd, img4_nonce_t *n);
#else
#define img4_nonce_domain_peek_nonce(...) \
		(img4if->i4if_v19.nonce_domain_peek_nonce(__VA_ARGS__))
#endif

/*!
 * @function img4_nonce_domain_get_from_handle
 * Obtains the nonce domain for the given integer handle.
 *
 * @param handle
 * The nonce domain handle.
 *
 * @result
 * The nonce domain associated with the provided handle. If no domain is
 * associated with the handle, NULL is returned.
 */
#if !XNU_KERNEL_PRIVATE
IMG4_API_AVAILABLE_20221202
OS_EXPORT OS_WARN_RESULT
const img4_nonce_domain_t *_Nullable
img4_nonce_domain_get_from_handle(uint32_t handle);
#else
#define img4_nonce_domain_get_from_handle(...) \
		(img4if->i4if_v20.nonce_domain_get_from_handle(__VA_ARGS__))
#endif

OS_ASSUME_PTR_ABI_SINGLE_END
OS_ASSUME_NONNULL_END
__END_DECLS

#endif // __IMG4_NONCE_H