xref: /xnu-11417.121.6/osfmk/corecrypto/cc_debug.h (revision a1e26a70f38d1d7daa7b49b258e2f8538ad81650)
1*a1e26a70SApple OSS Distributions /* Copyright (c) (2012,2014-2019,2021,2022) Apple Inc. All rights reserved.
2*a1e26a70SApple OSS Distributions  *
3*a1e26a70SApple OSS Distributions  * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4*a1e26a70SApple OSS Distributions  * is contained in the License.txt file distributed with corecrypto) and only to
5*a1e26a70SApple OSS Distributions  * people who accept that license. IMPORTANT:  Any license rights granted to you by
6*a1e26a70SApple OSS Distributions  * Apple Inc. (if any) are limited to internal use within your organization only on
7*a1e26a70SApple OSS Distributions  * devices and computers you own or control, for the sole purpose of verifying the
8*a1e26a70SApple OSS Distributions  * security characteristics and correct functioning of the Apple Software.  You may
9*a1e26a70SApple OSS Distributions  * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
10*a1e26a70SApple OSS Distributions  *
11*a1e26a70SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
12*a1e26a70SApple OSS Distributions  *
13*a1e26a70SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
14*a1e26a70SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
15*a1e26a70SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
16*a1e26a70SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
17*a1e26a70SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
18*a1e26a70SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
19*a1e26a70SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
20*a1e26a70SApple OSS Distributions  * terms of an Apple operating system software license agreement.
21*a1e26a70SApple OSS Distributions  *
22*a1e26a70SApple OSS Distributions  * Please obtain a copy of the License at
23*a1e26a70SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
24*a1e26a70SApple OSS Distributions  *
25*a1e26a70SApple OSS Distributions  * The Original Code and all software distributed under the License are
26*a1e26a70SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
27*a1e26a70SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
28*a1e26a70SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
29*a1e26a70SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
30*a1e26a70SApple OSS Distributions  * Please see the License for the specific language governing rights and
31*a1e26a70SApple OSS Distributions  * limitations under the License.
32*a1e26a70SApple OSS Distributions  *
33*a1e26a70SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34*a1e26a70SApple OSS Distributions  */
35*a1e26a70SApple OSS Distributions 
36*a1e26a70SApple OSS Distributions //debug configuration header file
37*a1e26a70SApple OSS Distributions #ifndef _CORECRYPTO_CCN_DEBUG_H_
38*a1e26a70SApple OSS Distributions #define _CORECRYPTO_CCN_DEBUG_H_
39*a1e26a70SApple OSS Distributions 
40*a1e26a70SApple OSS Distributions #include <corecrypto/cc_config.h>
41*a1e26a70SApple OSS Distributions 
42*a1e26a70SApple OSS Distributions // DO NOT INCLUDE this HEADER file in CoreCrypto files added for XNU project or headers
43*a1e26a70SApple OSS Distributions // included by external clients.
44*a1e26a70SApple OSS Distributions 
45*a1e26a70SApple OSS Distributions // ========================
46*a1e26a70SApple OSS Distributions // Printf for corecrypto
47*a1e26a70SApple OSS Distributions // ========================
48*a1e26a70SApple OSS Distributions #if CC_KERNEL
49*a1e26a70SApple OSS Distributions     #include <pexpert/pexpert.h>
50*a1e26a70SApple OSS Distributions     #define cc_printf(x...) kprintf(x)
51*a1e26a70SApple OSS Distributions     #if !CONFIG_EMBEDDED
52*a1e26a70SApple OSS Distributions extern int printf(const char *format, ...) __cc_printflike(1, 2);
53*a1e26a70SApple OSS Distributions     #endif
54*a1e26a70SApple OSS Distributions #elif CC_IBOOT || CC_RTKIT || CC_RTKITROM
55*a1e26a70SApple OSS Distributions     #include <stdio.h>
56*a1e26a70SApple OSS Distributions     #define cc_printf(x...) printf(x)
57*a1e26a70SApple OSS Distributions #elif CC_SGX || CC_EFI
58*a1e26a70SApple OSS Distributions     #define cc_printf(x...)
59*a1e26a70SApple OSS Distributions #elif CC_TXM
60*a1e26a70SApple OSS Distributions     #define cc_printf(x...)
61*a1e26a70SApple OSS Distributions #elif CC_SPTM
62*a1e26a70SApple OSS Distributions     #define cc_printf(x...)
63*a1e26a70SApple OSS Distributions #else
64*a1e26a70SApple OSS Distributions     #include <stdio.h>
65*a1e26a70SApple OSS Distributions     #define cc_printf(x...) fprintf(stderr, x)
66*a1e26a70SApple OSS Distributions #endif
67*a1e26a70SApple OSS Distributions 
68*a1e26a70SApple OSS Distributions // ========================
69*a1e26a70SApple OSS Distributions // Integer types
70*a1e26a70SApple OSS Distributions // ========================
71*a1e26a70SApple OSS Distributions 
72*a1e26a70SApple OSS Distributions #if CC_KERNEL
73*a1e26a70SApple OSS Distributions /* Those are not defined in libkern */
74*a1e26a70SApple OSS Distributions #define PRIx64 "llx"
75*a1e26a70SApple OSS Distributions #define PRIx32 "x"
76*a1e26a70SApple OSS Distributions #define PRIx16 "hx"
77*a1e26a70SApple OSS Distributions #define PRIx8  "hhx"
78*a1e26a70SApple OSS Distributions #else
79*a1e26a70SApple OSS Distributions #include <inttypes.h>
80*a1e26a70SApple OSS Distributions #endif
81*a1e26a70SApple OSS Distributions 
82*a1e26a70SApple OSS Distributions #if  CCN_UNIT_SIZE == 8
83*a1e26a70SApple OSS Distributions #define CCPRIx_UNIT ".016" PRIx64
84*a1e26a70SApple OSS Distributions #elif  CCN_UNIT_SIZE == 4
85*a1e26a70SApple OSS Distributions #define CCPRIx_UNIT ".08" PRIx32
86*a1e26a70SApple OSS Distributions #else
87*a1e26a70SApple OSS Distributions #error invalid CCN_UNIT_SIZE
88*a1e26a70SApple OSS Distributions #endif
89*a1e26a70SApple OSS Distributions 
90*a1e26a70SApple OSS Distributions // ========================
91*a1e26a70SApple OSS Distributions // Print utilities for corecrypto
92*a1e26a70SApple OSS Distributions // ========================
93*a1e26a70SApple OSS Distributions 
94*a1e26a70SApple OSS Distributions #include <corecrypto/cc.h>
95*a1e26a70SApple OSS Distributions 
96*a1e26a70SApple OSS Distributions /* Print a byte array of arbitrary size */
97*a1e26a70SApple OSS Distributions void cc_print(const char *label, size_t count, const uint8_t *s);
98*a1e26a70SApple OSS Distributions 
99*a1e26a70SApple OSS Distributions #endif /* _CORECRYPTO_CCN_DEBUG_H_ */
100