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