]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/feeTypes.h
87db4052db2eb912083639c3bb2cee3d6f779254
[apple/security.git] / OSX / libsecurity_cryptkit / lib / feeTypes.h
1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
2 *
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
10 *
11 * feeTypes.h - general purpose FEE typedefs and constants
12 *
13 * Revision History
14 * ----------------
15 * 23 Mar 98 at Apple
16 * Added FR_BadKeyBlob.
17 * 20 Jan 98 at Apple
18 * New PT_GENERAL depth values.
19 * 09 Jan 98 at Apple
20 * Removed obsolete FEE_DEPTH_* values.
21 * 20 Aug 96 at NeXT
22 * Created.
23 */
24
25 #ifndef _CK_FEETYPES_H_
26 #define _CK_FEETYPES_H_
27
28 /*
29 * Opaque public key object.
30 */
31 typedef void *feePubKey;
32
33 /*
34 * Standard return codes.
35 * Remember to update frtnStrings[] in utilities.c when adding new items.
36 */
37 typedef enum {
38 FR_Success = 0,
39 FR_BadPubKey,
40 FR_BadPubKeyString,
41 FR_IncompatibleKey, /* incompatible key */
42 FR_IllegalDepth,
43 FR_BadUsageName, /* bad usageName */
44 FR_BadSignatureFormat, /* signature corrupted */
45 FR_InvalidSignature, /* signature intact, but not valid */
46 FR_IllegalArg, /* illegal argument */
47 FR_BadCipherText, /* malformed ciphertext */
48 FR_Unimplemented, /* unimplemented function */
49 FR_BadCipherFile,
50 FR_BadEnc64, /* bad enc64() format */
51 FR_WrongSignatureType, /* ElGamal vs. ECDSA */
52 FR_BadKeyBlob,
53 FR_IllegalCurve, /* e.g., ECDSA with Montgomery curve */
54 FR_Internal, /* internal library error */
55 FR_Memory, /* out of memory */
56 FR_ShortPrivData /* insufficient privData for creating
57 * private key */
58 /* etc. */
59 } feeReturn;
60
61 typedef enum {
62 FSF_Default, /* default */
63 FSF_DER, /* DER */
64 FSF_RAW, /* RAW (for ECDSA, first half is r, second half is s */
65 } feeSigFormat;
66
67 /*
68 * The feeDepth parameter defines one of 'n' known curves. From a user's
69 * perspective, the most interesting parameter indicated by feeDepth is
70 * the size (in bits) of the key.
71 */
72 typedef unsigned feeDepth;
73
74 /*
75 * Prime and curve description parameters.
76 */
77 typedef enum {
78 FPT_Default, /* default per key size */
79 FPT_Mersenne, /* (2 ** q) - 1 */
80 FPT_FEE, /* (2 ** q) - k */
81 FPT_General /* random prime */
82 } feePrimeType;
83
84 typedef enum {
85 FCT_Default, /* default per key size */
86 FCT_Montgomery, /* a==1, b==0 */
87 FCT_Weierstrass, /* c==0. IEEE P1363 compliant. */
88 FCT_ANSI, /* ANSI X9.62/Certicom, also FCT_Weierstrass */
89 FCT_General /* Other */
90 } feeCurveType;
91
92 /*
93 * Some commonly used feeDepth values. In these definitions, q and k are
94 * from the expression (2^q - k), the base modulus of the curve. The case
95 * k=1 implies a Mersenne prime as the modulus.
96 */
97 #define FEE_PROTOTYPE_CURVES 0
98
99 #if FEE_PROTOTYPE_CURVES
100
101 /* q k a b c */
102 /* ---- ---- ---- ---- ---- */
103 #define FEE_DEPTH_31_1_W 0 /* 31 1 7 1 0 */
104 #define FEE_DEPTH_31_1_M 1 /* 31 1 1 0 666 */
105 #define FEE_DEPTH_31_1_P 2 /* 31 1 5824692 2067311435 0 */
106 #define FEE_DEPTH_40_213 3 /* 40 213 1627500953 523907505 0 */
107 #define FEE_DEPTH_127_1 4 /* 127 1 1 0 666 */
108 #define FEE_DEPTH_127_1W 5 /* 127 1 666 1 0 */
109 #define FEE_DEPTH_160_57 6 /* 160 57 0 3 0 */
110 #define FEE_DEPTH_192_1425 7 /* 192 1425 0 -11 0 */
111 #define FEE_DEPTH_192_M529891 8 /* 192 -529891 -152 722 0 */
112
113 /*
114 * The remaining curves are implemented as PT_GENERAL curves; modulo
115 * arithmetic does not utilize any FEE or Mersenne optimizations. These
116 * are here for performance measurements and DVT.
117 */
118 #define FEE_DEPTH_127_GEN 9 /* 127 1 1 0 666 */
119 #define FEE_DEPTH_160_GEN 10 /* 160 57 0 3 0 */
120 #define FEE_DEPTH_161_GEN 11 /* 161 .. -152 722 0 */
121
122 /*
123 * The default depth.
124 */
125 #define FEE_DEPTH_DEFAULT FEE_DEPTH_160_57
126
127 /*
128 * Last enumerated depth.
129 */
130 #define FEE_DEPTH_MAX FEE_DEPTH_161_GEN
131
132 #else /* FEE_PROTOTYPE_CURVES */
133
134 /*
135 * The real curves as of 4/9/2001.
136 * Note that ECDSA signatures can only be performed with curve of
137 * curveType FCT_Weierstrass.
138 *
139 * Default curveType for curves with same prime size is FCT_Weierstrass.
140 */
141 #define FEE_DEPTH_31M 0 /* size=31 FPT_Mersenne FCT_Montgomery */
142 #define FEE_DEPTH_31W 1 /* size=31 FPT_Mersenne FCT_Weierstrass */
143 #define FEE_DEPTH_127M 2 /* size=127 FPT_Mersenne FCT_Montgomery */
144 #define FEE_DEPTH_128W 3 /* size=128 FPT_FEE FCT_Weierstrass */
145 #define FEE_DEPTH_161W 4 /* size=161 FPT_FEE FCT_Weierstrass */
146 #define FEE_DEPTH_161G 5 /* size=161 FPT_General FCT_Weierstrass */
147 #define FEE_DEPTH_192G 6 /* size=192 FPT_General FCT_Weierstrass */
148
149 /* ANSI X9.62/Certicom curves */
150 #define FEE_DEPTH_secp192r1 7 /* size=192 FPT_General FCT_ANSI */
151 #define FEE_DEPTH_secp256r1 8 /* size=256 FPT_General FCT_ANSI */
152 #define FEE_DEPTH_secp384r1 9 /* size=384 FPT_General FCT_ANSI */
153 #define FEE_DEPTH_secp521r1 10 /* size=521 FPT_General FCT_ANSI */
154 /*
155 * The default depth.
156 */
157 #define FEE_DEPTH_DEFAULT FEE_DEPTH_161W
158
159 /*
160 * Last enumerated depth.
161 */
162 #define FEE_DEPTH_MAX FEE_DEPTH_secp521r1
163
164 #endif /* FEE_PROTOTYPE_CURVES */
165
166 /*
167 * Random number generator callback function.
168 */
169 typedef feeReturn (*feeRandFcn)(
170 void *ref,
171 unsigned char *bytes, /* must be alloc'd by caller */
172 unsigned numBytes);
173
174 #endif /* _CK_FEETYPES_H_ */