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