]> git.saurik.com Git - apple/security.git/blob - libsecurity_cryptkit/lib/feeDebug.h
Security-55178.0.1.tar.gz
[apple/security.git] / libsecurity_cryptkit / lib / feeDebug.h
1 /*
2 File: feeDebug.h
3
4 Contains: Debug macros.
5
6 Written by: Doug Mitchell
7
8 Copyright: Copyright 1998 by Apple Computer, Inc.
9 All rights reserved.
10
11 Change History (most recent first):
12
13 <9> 10/06/98 ap Changed to compile with C++.
14
15 To Do:
16 */
17
18 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
19 *
20 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
21 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
22 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE COMPUTER, INC. AND THE
23 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE COMPUTER,
24 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
25 * EXPOSE YOU TO LIABILITY.
26 ***************************************************************************
27 */
28
29 #ifndef _CK_FEEDEBUG_H_
30 #define _CK_FEEDEBUG_H_
31
32 #include "giantIntegers.h"
33 #include "elliptic.h"
34 #include "curveParams.h"
35 #include <stdio.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #ifdef NDEBUG
42 #define FEE_DEBUG 0
43 #else
44 #define FEE_DEBUG 1
45 #endif
46
47 /*
48 * In utilities.c...
49 */
50 extern void printGiant(const giant x);
51 extern void printGiantHex(const giant x);
52 extern void printGiantExp(const giant x);
53 extern void printKey(const key k);
54 extern void printCurveParams(const curveParams *p);
55
56 #if FEE_DEBUG
57
58 #define dbgLog(x) printf x
59
60
61 #else /* FEE_DEBUG */
62
63 #define dbgLog(x)
64
65 #endif /* FEE_DEBUG */
66
67 /*
68 * Profiling.
69 */
70 #define FEE_PROFILE 0 /* general purpose profile */
71 #define ELL_PROFILE 0 /* ell_even/ell_odd only */
72
73 #if (FEE_PROFILE || ELL_PROFILE)
74 #include <kern/time_stamp.h>
75 #endif /* (FEE_PROFILE || ELL_PROFILE) */
76
77 /*
78 * Place this macro after the last local and before any code in a routine
79 * to profile.
80 */
81 #define CPROF_START \
82 struct tsval _profStartTime; \
83 struct tsval _profEndTime; \
84 kern_timestamp(&_profStartTime);
85
86 /*
87 * This one goes at the end of the routine, just before the (only) return.
88 * There must be a static accumulator (an unsigned int) on a per-routine basis.
89 */
90 #define CPROF_END(accum) \
91 kern_timestamp(&_profEndTime); \
92 accum += (_profEndTime.low_val - _profStartTime.low_val);
93
94 /*
95 * Increment a profiling counter.
96 */
97 #define CPROF_INCR(ctr) ctr++
98
99 #if FEE_PROFILE
100
101 #define PROF_START CPROF_START
102 #define PROF_END(a) CPROF_END(a)
103 #define PROF_INCR(ctr) CPROF_INCR(ctr)
104
105 /*
106 * As of 14 Apr 1998, we no longer time mulg or gsquare calls with this
107 * mechanism; the time overhead is the same magnitude as the mulg. Instead
108 * we'll just count the mulgs and gsquares.
109 */
110 #define PROF_TIME_MULGS 0
111
112
113 /*
114 * Fundamental ops
115 */
116 extern unsigned ellAddTime;
117 extern unsigned whichCurveTime;
118 extern unsigned ellipticTime;
119 extern unsigned sigCompTime;
120
121 /*
122 * low-level primitives
123 */
124 extern unsigned numerDoubleTime;
125 extern unsigned numerPlusTime;
126 extern unsigned numerTimesTime;
127 extern unsigned denomDoubleTime;
128 extern unsigned denomTimesTime;
129 extern unsigned powerModTime;
130 extern unsigned modgTime;
131 extern unsigned binvauxTime;
132
133 /*
134 * Counters for calculating microseconds per {mulg, feemod, ...}
135 */
136 extern unsigned numMulg;
137 extern unsigned numFeemod;
138 extern unsigned numGsquare;
139 extern unsigned numBorrows;
140
141 extern void clearProfile();
142
143 #else /* FEE_PROFILE */
144 #define PROF_START
145 #define PROF_END(a)
146 #define PROF_INCR(ctr)
147 #endif /* FEE_PROFILE */
148
149 #if ELL_PROFILE
150 extern unsigned ellOddTime;
151 extern unsigned ellEvenTime;
152 extern unsigned numEllOdds;
153 extern unsigned numEllEvens;
154 extern void clearEllProfile();
155
156 #define EPROF_START CPROF_START
157 #define EPROF_END(a) CPROF_END(a)
158 #define EPROF_INCR(ctr) CPROF_INCR(ctr)
159
160 #else /* ELL_PROFILE */
161 #define EPROF_START
162 #define EPROF_END(a)
163 #define EPROF_INCR(ctr)
164 #endif /* ELL_PROFILE */
165
166 /*
167 * NULL gets defined externally if FEE_DEBUG is true..
168 */
169 #if !FEE_DEBUG
170 #ifndef NULL
171 #define NULL ((void *)0)
172 #endif /* NULL */
173 #endif /* !FEE_DEBUG */
174
175 #if FEE_DEBUG
176
177 #include "platform.h"
178
179 #define CKASSERT(expression) \
180 ((expression) ? (void)0 : \
181 (printf ("Assertion failed: " #expression \
182 ", file " __FILE__ ", line %d.\n", __LINE__), \
183 CKRaise("Assertion Failure")))
184
185 #else /* FEE_DEBUG */
186
187 #define CKASSERT(expression)
188
189 #endif /* FEE_DEBUG */
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif /* _CK_FEEDEBUG_H_ */