diff options
author | tb <> | 2024-02-18 16:28:38 +0000 |
---|---|---|
committer | tb <> | 2024-02-18 16:28:38 +0000 |
commit | f3cff8b6438de90dfb152c94ee691fd4b59b0890 (patch) | |
tree | 6a60bd14d56bf5ac3d9034a6b7ba3be4736b59dd | |
parent | babf480e3dc1d1c868511b40c31061c5ee5d75d1 (diff) | |
download | openbsd-f3cff8b6438de90dfb152c94ee691fd4b59b0890.tar.gz openbsd-f3cff8b6438de90dfb152c94ee691fd4b59b0890.tar.bz2 openbsd-f3cff8b6438de90dfb152c94ee691fd4b59b0890.zip |
Add posix_time.h from BoringSSL
This is prepares to expose some internal API as OPENSSL_tm_to_posix() and
OPENSSL_posix_to_tm(). They will be used in libtls and ocspcheck(8) to get
rid of the portability nightmare that is timegm().
Also fix the location of OPENSSL_gmtime() and OPENSSL_timegm() (this API
is not yet exposed). The former is from OpenSSL and surprisingly lives in
crypto.h, not asn1.h, and the latter is BoringSSL API and lives in the new
posix_time.h.
Initial diff from beck, this pulls in further upstream work after review
feedback.
ok jsing
-rw-r--r-- | src/lib/libcrypto/Makefile | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/Symbols.namespace | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/a_time_posix.c | 106 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 7 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_local.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/posix_time.h | 54 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto.h | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/hidden/openssl/posix_time.h | 32 |
8 files changed, 160 insertions, 60 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index 2ac252aabc..0ddf74246c 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.167 2024/01/27 17:14:33 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.168 2024/02/18 16:28:37 tb Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -705,6 +705,7 @@ HDRS=\ | |||
705 | ${LCRYPTO_SRC}/aes/aes.h \ | 705 | ${LCRYPTO_SRC}/aes/aes.h \ |
706 | ${LCRYPTO_SRC}/asn1/asn1.h \ | 706 | ${LCRYPTO_SRC}/asn1/asn1.h \ |
707 | ${LCRYPTO_SRC}/asn1/asn1t.h \ | 707 | ${LCRYPTO_SRC}/asn1/asn1t.h \ |
708 | ${LCRYPTO_SRC}/asn1/posix_time.h \ | ||
708 | ${LCRYPTO_SRC}/bf/blowfish.h \ | 709 | ${LCRYPTO_SRC}/bf/blowfish.h \ |
709 | ${LCRYPTO_SRC}/bio/bio.h \ | 710 | ${LCRYPTO_SRC}/bio/bio.h \ |
710 | ${LCRYPTO_SRC}/bn/bn.h \ | 711 | ${LCRYPTO_SRC}/bn/bn.h \ |
diff --git a/src/lib/libcrypto/Symbols.namespace b/src/lib/libcrypto/Symbols.namespace index 08f070e79c..62d6b5a3ad 100644 --- a/src/lib/libcrypto/Symbols.namespace +++ b/src/lib/libcrypto/Symbols.namespace | |||
@@ -2645,3 +2645,7 @@ _libre_i2d_DHparams | |||
2645 | _libre_DHparams_print_fp | 2645 | _libre_DHparams_print_fp |
2646 | _libre_DHparams_print | 2646 | _libre_DHparams_print |
2647 | _libre_ERR_load_DH_strings | 2647 | _libre_ERR_load_DH_strings |
2648 | _libre_OPENSSL_gmtime | ||
2649 | _libre_OPENSSL_timegm | ||
2650 | _libre_OPENSSL_posix_to_tm | ||
2651 | _libre_OPENSSL_tm_to_posix | ||
diff --git a/src/lib/libcrypto/asn1/a_time_posix.c b/src/lib/libcrypto/asn1/a_time_posix.c index 5d10d21d3c..d4439b4701 100644 --- a/src/lib/libcrypto/asn1/a_time_posix.c +++ b/src/lib/libcrypto/asn1/a_time_posix.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_time_posix.c,v 1.4 2023/11/13 12:46:07 beck Exp $ */ | 1 | /* $OpenBSD: a_time_posix.c,v 1.5 2024/02/18 16:28:38 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2022, Google Inc. | 3 | * Copyright (c) 2022, Google Inc. |
4 | * Copyright (c) 2022, Bob Beck <beck@obtuse.com> | 4 | * Copyright (c) 2022, Bob Beck <beck@obtuse.com> |
@@ -23,10 +23,14 @@ | |||
23 | 23 | ||
24 | #include <inttypes.h> | 24 | #include <inttypes.h> |
25 | #include <limits.h> | 25 | #include <limits.h> |
26 | #include <stdint.h> | ||
26 | #include <string.h> | 27 | #include <string.h> |
27 | #include <time.h> | 28 | #include <time.h> |
28 | 29 | ||
29 | #include <openssl/asn1.h> | 30 | #include <openssl/asn1.h> |
31 | #include <openssl/posix_time.h> | ||
32 | |||
33 | #include "crypto_internal.h" | ||
30 | 34 | ||
31 | #define SECS_PER_HOUR (int64_t)(60 * 60) | 35 | #define SECS_PER_HOUR (int64_t)(60 * 60) |
32 | #define SECS_PER_DAY (int64_t)(24 * SECS_PER_HOUR) | 36 | #define SECS_PER_DAY (int64_t)(24 * SECS_PER_HOUR) |
@@ -36,7 +40,7 @@ | |||
36 | * to 9999? | 40 | * to 9999? |
37 | */ | 41 | */ |
38 | static int | 42 | static int |
39 | is_valid_date(int year, int month, int day) | 43 | is_valid_date(int64_t year, int64_t month, int64_t day) |
40 | { | 44 | { |
41 | int days_in_month; | 45 | int days_in_month; |
42 | if (day < 1 || month < 1 || year < 0 || year > 9999) | 46 | if (day < 1 || month < 1 || year < 0 || year > 9999) |
@@ -80,13 +84,16 @@ is_valid_time(int hours, int minutes, int seconds) | |||
80 | minutes <= 59 && seconds <= 59; | 84 | minutes <= 59 && seconds <= 59; |
81 | } | 85 | } |
82 | 86 | ||
87 | /* 0000-01-01 00:00:00 UTC */ | ||
88 | #define MIN_POSIX_TIME INT64_C(-62167219200) | ||
89 | /* 9999-12-31 23:59:59 UTC */ | ||
90 | #define MAX_POSIX_TIME INT64_C(253402300799) | ||
91 | |||
83 | /* Is a int64 time representing a time within our expected range? */ | 92 | /* Is a int64 time representing a time within our expected range? */ |
84 | static int | 93 | static int |
85 | is_valid_epoch_time(int64_t time) | 94 | is_valid_posix_time(int64_t time) |
86 | { | 95 | { |
87 | /* 0000-01-01 00:00:00 UTC to 9999-12-31 23:59:59 UTC */ | 96 | return MIN_POSIX_TIME <= time && time <= MAX_POSIX_TIME; |
88 | return (int64_t)-62167219200LL <= time && | ||
89 | time <= (int64_t)253402300799LL; | ||
90 | } | 97 | } |
91 | 98 | ||
92 | /* | 99 | /* |
@@ -95,8 +102,8 @@ is_valid_epoch_time(int64_t time) | |||
95 | * (Public Domain) | 102 | * (Public Domain) |
96 | */ | 103 | */ |
97 | static int | 104 | static int |
98 | posix_time_from_utc(int year, int month, int day, int hours, int minutes, | 105 | posix_time_from_utc(int64_t year, int64_t month, int64_t day, int64_t hours, |
99 | int seconds, int64_t *out_time) | 106 | int64_t minutes, int64_t seconds, int64_t *out_time) |
100 | { | 107 | { |
101 | int64_t era, year_of_era, day_of_year, day_of_era, posix_days; | 108 | int64_t era, year_of_era, day_of_year, day_of_era, posix_days; |
102 | 109 | ||
@@ -132,7 +139,7 @@ utc_from_posix_time(int64_t time, int *out_year, int *out_month, int *out_day, | |||
132 | int64_t days, leftover_seconds, era, day_of_era, year_of_era, | 139 | int64_t days, leftover_seconds, era, day_of_era, year_of_era, |
133 | day_of_year, month_of_year; | 140 | day_of_year, month_of_year; |
134 | 141 | ||
135 | if (!is_valid_epoch_time(time)) | 142 | if (!is_valid_posix_time(time)) |
136 | return 0; | 143 | return 0; |
137 | 144 | ||
138 | days = time / SECS_PER_DAY; | 145 | days = time / SECS_PER_DAY; |
@@ -167,40 +174,41 @@ utc_from_posix_time(int64_t time, int *out_year, int *out_month, int *out_day, | |||
167 | return 1; | 174 | return 1; |
168 | } | 175 | } |
169 | 176 | ||
170 | static int | 177 | int |
171 | asn1_time_tm_to_posix(const struct tm *tm, int64_t *out) | 178 | OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) |
172 | { | 179 | { |
173 | /* Ensure additions below do not overflow */ | 180 | return posix_time_from_utc(tm->tm_year + (int64_t)1900, |
174 | if (tm->tm_year > 9999) | 181 | tm->tm_mon + (int64_t)1, tm->tm_mday, tm->tm_hour, tm->tm_min, |
175 | return 0; | 182 | tm->tm_sec, out); |
176 | if (tm->tm_mon > 12) | ||
177 | return 0; | ||
178 | |||
179 | return posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, | ||
180 | tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, out); | ||
181 | } | 183 | } |
184 | LCRYPTO_ALIAS(OPENSSL_tm_to_posix); | ||
182 | 185 | ||
183 | static int | 186 | int |
184 | asn1_time_posix_to_tm(int64_t time, struct tm *out_tm) | 187 | OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) |
185 | { | 188 | { |
186 | memset(out_tm, 0, sizeof(struct tm)); | 189 | struct tm tmp_tm = {0}; |
187 | if (!utc_from_posix_time(time, &out_tm->tm_year, &out_tm->tm_mon, | 190 | |
188 | &out_tm->tm_mday, &out_tm->tm_hour, &out_tm->tm_min, | 191 | memset(out_tm, 0, sizeof(*out_tm)); |
189 | &out_tm->tm_sec)) | 192 | |
193 | if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon, | ||
194 | &tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min, &tmp_tm.tm_sec)) | ||
190 | return 0; | 195 | return 0; |
191 | 196 | ||
192 | out_tm->tm_year -= 1900; | 197 | tmp_tm.tm_year -= 1900; |
193 | out_tm->tm_mon -= 1; | 198 | tmp_tm.tm_mon -= 1; |
199 | |||
200 | *out_tm = tmp_tm; | ||
194 | 201 | ||
195 | return 1; | 202 | return 1; |
196 | } | 203 | } |
204 | LCRYPTO_ALIAS(OPENSSL_posix_to_tm); | ||
197 | 205 | ||
198 | int | 206 | int |
199 | asn1_time_tm_to_time_t(const struct tm *tm, time_t *out) | 207 | asn1_time_tm_to_time_t(const struct tm *tm, time_t *out) |
200 | { | 208 | { |
201 | int64_t posix_time; | 209 | int64_t posix_time; |
202 | 210 | ||
203 | if (!asn1_time_tm_to_posix(tm, &posix_time)) | 211 | if (!OPENSSL_tm_to_posix(tm, &posix_time)) |
204 | return 0; | 212 | return 0; |
205 | 213 | ||
206 | #ifdef SMALL_TIME_T | 214 | #ifdef SMALL_TIME_T |
@@ -219,7 +227,7 @@ asn1_time_time_t_to_tm(const time_t *time, struct tm *out_tm) | |||
219 | { | 227 | { |
220 | int64_t posix_time = *time; | 228 | int64_t posix_time = *time; |
221 | 229 | ||
222 | return asn1_time_posix_to_tm(posix_time, out_tm); | 230 | return OPENSSL_posix_to_tm(posix_time, out_tm); |
223 | } | 231 | } |
224 | 232 | ||
225 | int | 233 | int |
@@ -236,28 +244,29 @@ OPENSSL_gmtime(const time_t *time, struct tm *out_tm) { | |||
236 | } | 244 | } |
237 | LCRYPTO_ALIAS(OPENSSL_gmtime); | 245 | LCRYPTO_ALIAS(OPENSSL_gmtime); |
238 | 246 | ||
247 | /* Public API in OpenSSL. BoringSSL uses int64_t instead of long. */ | ||
239 | int | 248 | int |
240 | OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) | 249 | OPENSSL_gmtime_adj(struct tm *tm, int offset_day, int64_t offset_sec) |
241 | { | 250 | { |
242 | int64_t posix_time; | 251 | int64_t posix_time; |
243 | 252 | ||
244 | /* Ensure additions below do not overflow */ | 253 | if (!OPENSSL_tm_to_posix(tm, &posix_time)) |
245 | if (tm->tm_year > 9999) | ||
246 | return 0; | ||
247 | if (tm->tm_mon > 12) | ||
248 | return 0; | 254 | return 0; |
249 | 255 | ||
250 | if (!posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, | 256 | CTASSERT(INT_MAX <= INT64_MAX / SECS_PER_DAY); |
251 | tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, &posix_time)) | 257 | CTASSERT(MAX_POSIX_TIME <= INT64_MAX - INT_MAX * SECS_PER_DAY); |
252 | return 0; | 258 | CTASSERT(MIN_POSIX_TIME >= INT64_MIN - INT_MIN * SECS_PER_DAY); |
259 | |||
260 | posix_time += offset_day * SECS_PER_DAY; | ||
253 | 261 | ||
254 | if (!utc_from_posix_time(posix_time + off_day * SECS_PER_DAY + | 262 | if (posix_time > 0 && offset_sec > INT64_MAX - posix_time) |
255 | offset_sec, &tm->tm_year, &tm->tm_mon, &tm->tm_mday, &tm->tm_hour, | ||
256 | &tm->tm_min, &tm->tm_sec)) | ||
257 | return 0; | 263 | return 0; |
264 | if (posix_time < 0 && offset_sec < INT64_MIN - posix_time) | ||
265 | return 0; | ||
266 | posix_time += offset_sec; | ||
258 | 267 | ||
259 | tm->tm_year -= 1900; | 268 | if (!OPENSSL_posix_to_tm(posix_time, tm)) |
260 | tm->tm_mon -= 1; | 269 | return 0; |
261 | 270 | ||
262 | return 1; | 271 | return 1; |
263 | } | 272 | } |
@@ -268,20 +277,17 @@ OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from, | |||
268 | { | 277 | { |
269 | int64_t time_to, time_from, timediff, daydiff; | 278 | int64_t time_to, time_from, timediff, daydiff; |
270 | 279 | ||
271 | if (!posix_time_from_utc(to->tm_year + 1900, to->tm_mon + 1, | 280 | if (!OPENSSL_tm_to_posix(to, &time_to) || |
272 | to->tm_mday, to->tm_hour, to->tm_min, to->tm_sec, &time_to)) | 281 | !OPENSSL_tm_to_posix(from, &time_from)) |
273 | return 0; | 282 | return 0; |
274 | 283 | ||
275 | if (!posix_time_from_utc(from->tm_year + 1900, from->tm_mon + 1, | 284 | /* Times are in range, so these calculations cannot overflow. */ |
276 | from->tm_mday, from->tm_hour, from->tm_min, | 285 | CTASSERT(SECS_PER_DAY <= INT_MAX); |
277 | from->tm_sec, &time_from)) | 286 | CTASSERT((MAX_POSIX_TIME - MIN_POSIX_TIME) / SECS_PER_DAY <= INT_MAX); |
278 | return 0; | ||
279 | 287 | ||
280 | timediff = time_to - time_from; | 288 | timediff = time_to - time_from; |
281 | daydiff = timediff / SECS_PER_DAY; | 289 | daydiff = timediff / SECS_PER_DAY; |
282 | timediff %= SECS_PER_DAY; | 290 | timediff %= SECS_PER_DAY; |
283 | if (daydiff > INT_MAX || daydiff < INT_MIN) | ||
284 | return 0; | ||
285 | 291 | ||
286 | *out_secs = timediff; | 292 | *out_secs = timediff; |
287 | *out_days = daydiff; | 293 | *out_days = daydiff; |
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index d876b25b0b..cf288e5060 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1.h,v 1.82 2023/12/16 12:25:02 tb Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.83 2024/02/18 16:28:38 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -915,11 +915,6 @@ int SMIME_text(BIO *in, BIO *out); | |||
915 | 915 | ||
916 | void ERR_load_ASN1_strings(void); | 916 | void ERR_load_ASN1_strings(void); |
917 | 917 | ||
918 | #if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API) | ||
919 | int OPENSSL_timegm(const struct tm *tm, time_t *out); | ||
920 | struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm); | ||
921 | #endif | ||
922 | |||
923 | /* Error codes for the ASN1 functions. */ | 918 | /* Error codes for the ASN1 functions. */ |
924 | 919 | ||
925 | /* Function codes. */ | 920 | /* Function codes. */ |
diff --git a/src/lib/libcrypto/asn1/asn1_local.h b/src/lib/libcrypto/asn1/asn1_local.h index 499e160275..a5478faa0b 100644 --- a/src/lib/libcrypto/asn1/asn1_local.h +++ b/src/lib/libcrypto/asn1/asn1_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_local.h,v 1.7 2024/01/06 20:47:01 tb Exp $ */ | 1 | /* $OpenBSD: asn1_local.h,v 1.8 2024/02/18 16:28:38 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -160,7 +160,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, | |||
160 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp); | 160 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp); |
161 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, | 161 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, |
162 | long length); | 162 | long length); |
163 | int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec); | 163 | int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, int64_t offset_sec); |
164 | int OPENSSL_gmtime_diff(int *pday, int *psec, const struct tm *from, | 164 | int OPENSSL_gmtime_diff(int *pday, int *psec, const struct tm *from, |
165 | const struct tm *to); | 165 | const struct tm *to); |
166 | int asn1_time_time_t_to_tm(const time_t *time, struct tm *out_tm); | 166 | int asn1_time_time_t_to_tm(const time_t *time, struct tm *out_tm); |
diff --git a/src/lib/libcrypto/asn1/posix_time.h b/src/lib/libcrypto/asn1/posix_time.h new file mode 100644 index 0000000000..82b3f30bc2 --- /dev/null +++ b/src/lib/libcrypto/asn1/posix_time.h | |||
@@ -0,0 +1,54 @@ | |||
1 | /* $OpenBSD: posix_time.h,v 1.1 2024/02/18 16:28:38 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2022, Google Inc. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and/or distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
12 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
14 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #ifndef OPENSSL_HEADER_POSIX_TIME_H | ||
19 | #define OPENSSL_HEADER_POSIX_TIME_H | ||
20 | |||
21 | #include <stdint.h> | ||
22 | #include <time.h> | ||
23 | |||
24 | #if defined(__cplusplus) | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | /* | ||
29 | * OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time|, which must | ||
30 | * be in the range of year 0000 to 9999, to a broken out time value in |tm|. It | ||
31 | * returns one on success and zero on error. | ||
32 | */ | ||
33 | int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm); | ||
34 | |||
35 | /* | ||
36 | * OPENSSL_tm_to_posix converts a time value between the years 0 and 9999 in | ||
37 | * |tm| to a POSIX time value in |out|. One is returned on success, zero is | ||
38 | * returned on failure. It is a failure if |tm| contains out of range values. | ||
39 | */ | ||
40 | int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out); | ||
41 | |||
42 | /* | ||
43 | * OPENSSL_timegm converts a time value between the years 0 and 9999 in |tm| to | ||
44 | * a time_t value in |out|. One is returned on success, zero is returned on | ||
45 | * failure. It is a failure if the converted time can not be represented in a | ||
46 | * time_t, or if the tm contains out of range values. | ||
47 | */ | ||
48 | int OPENSSL_timegm(const struct tm *tm, time_t *out); | ||
49 | |||
50 | #if defined(__cplusplus) | ||
51 | } /* extern C */ | ||
52 | #endif | ||
53 | |||
54 | #endif /* OPENSSL_HEADER_POSIX_TIME_H */ | ||
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index 07a55ec1f6..47e7eff37c 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: crypto.h,v 1.63 2023/07/28 10:19:20 tb Exp $ */ | 1 | /* $OpenBSD: crypto.h,v 1.64 2024/02/18 16:28:37 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -522,6 +522,14 @@ int CRYPTO_memcmp(const void *a, const void *b, size_t len); | |||
522 | int OPENSSL_init_crypto(uint64_t opts, const void *settings); | 522 | int OPENSSL_init_crypto(uint64_t opts, const void *settings); |
523 | void OPENSSL_cleanup(void); | 523 | void OPENSSL_cleanup(void); |
524 | 524 | ||
525 | /* | ||
526 | * OpenSSL helpfully put OPENSSL_gmtime() here because all other time related | ||
527 | * functions are in asn1.h. | ||
528 | */ | ||
529 | #if defined(LIBRESSL_INTERNAL) || defined(LIBRESSL_NEXT_API) | ||
530 | struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm); | ||
531 | #endif | ||
532 | |||
525 | void ERR_load_CRYPTO_strings(void); | 533 | void ERR_load_CRYPTO_strings(void); |
526 | 534 | ||
527 | /* Error codes for the CRYPTO functions. */ | 535 | /* Error codes for the CRYPTO functions. */ |
diff --git a/src/lib/libcrypto/hidden/openssl/posix_time.h b/src/lib/libcrypto/hidden/openssl/posix_time.h new file mode 100644 index 0000000000..306d43eae5 --- /dev/null +++ b/src/lib/libcrypto/hidden/openssl/posix_time.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* $OpenBSD: posix_time.h,v 1.1 2024/02/18 16:28:38 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2024 Bob Beck <beck@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #ifndef _LIBCRYPTO_POSIX_TIME_H | ||
19 | #define _LIBCRYPTO_POSIX_TIME_H | ||
20 | |||
21 | #ifndef _MSC_VER | ||
22 | #include_next <openssl/posix_time.h> | ||
23 | #else | ||
24 | #include "../include/openssl/posix_time.h" | ||
25 | #endif | ||
26 | #include "crypto_namespace.h" | ||
27 | |||
28 | LCRYPTO_USED(OPENSSL_posix_to_tm); | ||
29 | LCRYPTO_USED(OPENSSL_tm_to_posix); | ||
30 | LCRYPTO_USED(OPENSSL_timegm); | ||
31 | |||
32 | #endif /* _LIBCRYPTO_POSIX_TIME_H */ | ||