Move & split opensslconf.h.in
[openssl.git] / crypto / include / internal / ct_int.h
1 /* crypto/ct/ct_locl.h */
2 /*
3  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4  * 2015.
5  */
6 /* ====================================================================
7  * Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in
18  *    the documentation and/or other materials provided with the
19  *    distribution.
20  *
21  * 3. All advertising materials mentioning features or use of this
22  *    software must display the following acknowledgment:
23  *    "This product includes software developed by the OpenSSL Project
24  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25  *
26  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27  *    endorse or promote products derived from this software without
28  *    prior written permission. For written permission, please contact
29  *    licensing@OpenSSL.org.
30  *
31  * 5. Products derived from this software may not be called "OpenSSL"
32  *    nor may "OpenSSL" appear in their names without prior written
33  *    permission of the OpenSSL Project.
34  *
35  * 6. Redistributions of any form whatsoever must retain the following
36  *    acknowledgment:
37  *    "This product includes software developed by the OpenSSL Project
38  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51  * OF THE POSSIBILITY OF SUCH DAMAGE.
52  * ====================================================================
53  *
54  */
55 #ifndef HEADER_CT_LOCL_H
56 # define HEADER_CT_LOCL_H
57
58 # ifdef __cplusplus
59 extern "C" {
60 # endif
61
62 # ifndef OPENSSL_NO_CT
63
64 /* All hashes are currently SHA256 */
65 #  define SCT_V1_HASHLEN  32
66 /* Minimum RSA key size, from RFC6962 */
67 #  define SCT_MIN_RSA_BITS 2048
68
69 /*
70  * From RFC6962: opaque SerializedSCT<1..2^16-1>; struct { SerializedSCT
71  * sct_list <1..2^16-1>; } SignedCertificateTimestampList;
72  */
73
74 #  define MAX_SCT_SIZE            65535
75 #  define MAX_SCT_LIST_SIZE       MAX_SCT_SIZE
76
77 typedef enum {
78     UNSET_ENTRY = -1,
79     X509_ENTRY = 0,
80     PRECERT_ENTRY = 1
81 } log_entry_type_t;
82
83 typedef enum {
84     UNSET_VERSION = -1,
85     SCT_V1 = 0
86 } sct_version_t;
87
88 typedef struct {
89     sct_version_t version;
90     /* If version is not SCT_V1 this contains the encoded SCT */
91     unsigned char *sct;
92     size_t sct_len;
93     /*
94      * If version is SCT_V1, fields below contain components of the SCT.
95      * "log_id", "ext" and "sig" point to buffers allocated with
96      * OPENSSL_malloc().
97      */
98     unsigned char *log_id;
99     size_t log_id_len;
100
101     /*
102      * Note, we cannot distinguish between an unset timestamp, and one
103      * that is set to 0.  However since CT didn't exist in 1970, no real
104      * SCT should ever be set as such.
105      */
106     uint64_t timestamp;
107     unsigned char *ext;
108     size_t ext_len;
109     unsigned char hash_alg;
110     unsigned char sig_alg;
111     unsigned char *sig;
112     size_t sig_len;
113     /* Log entry type */
114     log_entry_type_t entry_type;
115 } SCT;
116
117 DEFINE_STACK_OF(SCT)
118
119 /*
120  * Allocate new SCT.
121  * Caller is responsible for calling SCT_free when done.
122  */
123 SCT *SCT_new(void);
124
125 /*
126  * Free SCT and underlying datastructures.
127  */
128 void SCT_free(SCT *sct);
129
130 /*
131  * Set the version of an SCT.
132  * Returns 1 on success, 0 if the version is unrecognized.
133  */
134 int SCT_set_version(SCT *sct, sct_version_t version);
135
136 /*
137  * Set the log entry type of an SCT.
138  * Returns 1 on success.
139  */
140 int SCT_set_log_entry_type(SCT *sct, log_entry_type_t entry_type);
141
142 /*
143  * Set the log id of an SCT to point directly to the *log_id specified.
144  * The SCT takes ownership of the specified pointer.
145  * Returns 1 on success.
146  */
147 int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len);
148
149 /*
150  * Set the timestamp of an SCT.
151  */
152 void SCT_set_timestamp(SCT *sct, uint64_t timestamp);
153
154 /*
155  * Set the signature type of an SCT
156  * Currently NID_sha256WithRSAEncryption or NID_ecdsa_with_SHA256.
157  * Returns 1 on success.
158  */
159 int SCT_set_signature_nid(SCT *sct, int nid);
160
161 /*
162  * Set the extensions of an SCT to point directly to the *ext specified.
163  * The SCT takes ownership of the specified pointer.
164  */
165 void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len);
166
167 /*
168  * Set the signature of an SCT to point directly to the *sig specified.
169  * The SCT takes ownership of the specified pointer.
170  */
171 void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len);
172
173 /*
174  * Returns the version of the SCT.
175  */
176 sct_version_t SCT_get_version(const SCT *sct);
177
178 /*
179  * Returns the log entry type of the SCT.
180  */
181 log_entry_type_t SCT_get_log_entry_type(const SCT *sct);
182
183 /*
184  * Set *log_id to point to the log id for the SCT. log_id must not be NULL.
185  * The SCT retains ownership of this pointer.
186  * Returns length of the data pointed to.
187  */
188 size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id);
189
190 /*
191  * Returns the timestamp for the SCT.
192  */
193 uint64_t SCT_get_timestamp(const SCT *sct);
194
195 /*
196  * Return the nid for the signature used by the SCT.
197  * Currently NID_sha256WithRSAEncryption or NID_ecdsa_with_SHA256
198  * (or NID_undef).
199  */
200 int SCT_get_signature_nid(const SCT *sct);
201
202 /*
203  * Set *ext to point to the extension data for the SCT. ext must not be NULL.
204  * The SCT retains ownership of this pointer.
205  * Returns length of the data pointed to.
206  */
207 size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext);
208
209 /*
210  * Set *sig to point to the signature for the SCT. sig must not be NULL.
211  * The SCT retains ownership of this pointer.
212  * Returns length of the data pointed to.
213  */
214 size_t SCT_get0_signature(const SCT *sct, unsigned char **sig);
215
216
217 # endif
218
219 /* BEGIN ERROR CODES */
220 /*
221  * The following lines are auto generated by the script mkerr.pl. Any changes
222  * made after this point may be overwritten when the script is next run.
223  */
224 void ERR_load_CT_strings(void);
225
226 /* Error codes for the CT functions. */
227
228 /* Function codes. */
229 # define CT_F_SCT_NEW                                     100
230 # define CT_F_SCT_SET0_LOG_ID                             101
231 # define CT_F_SCT_SET_LOG_ENTRY_TYPE                      102
232 # define CT_F_SCT_SET_SIGNATURE_NID                       103
233 # define CT_F_SCT_SET_VERSION                             104
234
235 /* Reason codes. */
236 # define CT_R_INVALID_LOG_ID_LENGTH                       100
237 # define CT_R_UNRECOGNIZED_SIGNATURE_NID                  101
238 # define CT_R_UNSUPPORTED_ENTRY_TYPE                      102
239 # define CT_R_UNSUPPORTED_VERSION                         103
240
241 #ifdef  __cplusplus
242 }
243 #endif
244 #endif