Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/crypto/asn1/a_time.c
Line
Count
Source
1
/*
2
 * Copyright 1999-2025 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/*-
11
 * This is an implementation of the ASN1 Time structure which is:
12
 *    Time ::= CHOICE {
13
 *      utcTime        UTCTime,
14
 *      generalTime    GeneralizedTime }
15
 */
16
17
#include <stdio.h>
18
#include <time.h>
19
#include "crypto/asn1.h"
20
#include "crypto/ctype.h"
21
#include "internal/cryptlib.h"
22
#include <openssl/asn1t.h>
23
#include "asn1_local.h"
24
25
9.74M
IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
26
27
IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
28
IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_TIME)
29
30
static int is_utc(const int year)
31
21.6k
{
32
21.6k
    if (50 <= year && year <= 149)
33
21.6k
        return 1;
34
0
    return 0;
35
21.6k
}
36
37
static int leap_year(const int year)
38
263k
{
39
263k
    if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
40
62.1k
        return 1;
41
201k
    return 0;
42
263k
}
43
44
/*
45
 * Compute the day of the week and the day of the year from the year, month
46
 * and day.  The day of the year is straightforward, the day of the week uses
47
 * a form of Zeller's congruence.  For this months start with March and are
48
 * numbered 4 through 15.
49
 */
50
static void determine_days(struct tm *tm)
51
361k
{
52
361k
    static const int ydays[12] = {
53
361k
        0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
54
361k
    };
55
361k
    int y = tm->tm_year + 1900;
56
361k
    int m = tm->tm_mon;
57
361k
    int d = tm->tm_mday;
58
361k
    int c;
59
60
361k
    tm->tm_yday = ydays[m] + d - 1;
61
361k
    if (m >= 2) {
62
        /* March and onwards can be one day further into the year */
63
212k
        tm->tm_yday += leap_year(y);
64
212k
        m += 2;
65
212k
    } else {
66
        /* Treat January and February as part of the previous year */
67
148k
        m += 14;
68
148k
        y--;
69
148k
    }
70
361k
    c = y / 100;
71
361k
    y %= 100;
72
    /* Zeller's congruence */
73
361k
    tm->tm_wday = (d + (13 * m) / 5 + y + y / 4 + c / 4 + 5 * c + 6) % 7;
74
361k
}
75
76
int ossl_asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d)
77
467k
{
78
467k
    static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };
79
467k
    static const int max[9] = { 99, 99, 12, 31, 23, 59, 59, 12, 59 };
80
467k
    static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
81
467k
    char *a;
82
467k
    int n, i, i2, l, o, min_l, strict = 0, end = 6, btz = 5, md;
83
467k
    struct tm tmp;
84
#if defined(CHARSET_EBCDIC)
85
    const char upper_z = 0x5A, num_zero = 0x30, period = 0x2E, minus = 0x2D, plus = 0x2B;
86
#else
87
467k
    const char upper_z = 'Z', num_zero = '0', period = '.', minus = '-', plus = '+';
88
467k
#endif
89
    /*
90
     * ASN1_STRING_FLAG_X509_TIME is used to enforce RFC 5280
91
     * time string format, in which:
92
     *
93
     * 1. "seconds" is a 'MUST'
94
     * 2. "Zulu" timezone is a 'MUST'
95
     * 3. "+|-" is not allowed to indicate a timezone
96
     */
97
467k
    if (d->type == V_ASN1_UTCTIME) {
98
245k
        min_l = 13;
99
245k
        if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
100
0
            strict = 1;
101
0
        }
102
245k
    } else if (d->type == V_ASN1_GENERALIZEDTIME) {
103
222k
        end = 7;
104
222k
        btz = 6;
105
222k
        min_l = 15;
106
222k
        if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
107
0
            strict = 1;
108
0
        }
109
222k
    } else {
110
0
        return 0;
111
0
    }
112
113
467k
    l = d->length;
114
467k
    a = (char *)d->data;
115
467k
    o = 0;
116
467k
    memset(&tmp, 0, sizeof(tmp));
117
118
    /*
119
     * GENERALIZEDTIME is similar to UTCTIME except the year is represented
120
     * as YYYY. This stuff treats everything as a two digit field so make
121
     * first two fields 00 to 99
122
     */
123
124
467k
    if (l < min_l)
125
32.0k
        goto err;
126
2.41M
    for (i = 0; i < end; i++) {
127
2.19M
        if (!strict && (i == btz) && ((a[o] == upper_z) || (a[o] == plus) || (a[o] == minus))) {
128
55.7k
            i++;
129
55.7k
            break;
130
55.7k
        }
131
2.13M
        if (!ossl_ascii_isdigit(a[o]))
132
70.7k
            goto err;
133
2.06M
        n = a[o] - num_zero;
134
        /* incomplete 2-digital number */
135
2.06M
        if (++o == l)
136
0
            goto err;
137
138
2.06M
        if (!ossl_ascii_isdigit(a[o]))
139
50.6k
            goto err;
140
2.01M
        n = (n * 10) + a[o] - num_zero;
141
        /* no more bytes to read, but we haven't seen time-zone yet */
142
2.01M
        if (++o == l)
143
0
            goto err;
144
145
2.01M
        i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
146
147
2.01M
        if ((n < min[i2]) || (n > max[i2]))
148
33.1k
            goto err;
149
1.98M
        switch (i2) {
150
173k
        case 0:
151
            /* UTC will never be here */
152
173k
            tmp.tm_year = n * 100 - 1900;
153
173k
            break;
154
369k
        case 1:
155
369k
            if (d->type == V_ASN1_UTCTIME)
156
203k
                tmp.tm_year = n < 50 ? n + 100 : n;
157
165k
            else
158
165k
                tmp.tm_year += n;
159
369k
            break;
160
328k
        case 2:
161
328k
            tmp.tm_mon = n - 1;
162
328k
            break;
163
312k
        case 3:
164
            /* check if tm_mday is valid in tm_mon */
165
312k
            if (tmp.tm_mon == 1) {
166
                /* it's February */
167
42.0k
                md = mdays[1] + leap_year(tmp.tm_year + 1900);
168
270k
            } else {
169
270k
                md = mdays[tmp.tm_mon];
170
270k
            }
171
312k
            if (n > md)
172
3.02k
                goto err;
173
309k
            tmp.tm_mday = n;
174
309k
            determine_days(&tmp);
175
309k
            break;
176
293k
        case 4:
177
293k
            tmp.tm_hour = n;
178
293k
            break;
179
283k
        case 5:
180
283k
            tmp.tm_min = n;
181
283k
            break;
182
222k
        case 6:
183
222k
            tmp.tm_sec = n;
184
222k
            break;
185
1.98M
        }
186
1.98M
    }
187
188
    /*
189
     * Optional fractional seconds: decimal point followed by one or more
190
     * digits.
191
     */
192
277k
    if (d->type == V_ASN1_GENERALIZEDTIME && a[o] == period) {
193
95.9k
        if (strict)
194
            /* RFC 5280 forbids fractional seconds */
195
0
            goto err;
196
95.9k
        if (++o == l)
197
3.28k
            goto err;
198
92.6k
        i = o;
199
398k
        while ((o < l) && ossl_ascii_isdigit(a[o]))
200
306k
            o++;
201
        /* Must have at least one digit after decimal point */
202
92.6k
        if (i == o)
203
1.48k
            goto err;
204
        /* no more bytes to read, but we haven't seen time-zone yet */
205
91.1k
        if (o == l)
206
185
            goto err;
207
91.1k
    }
208
209
    /*
210
     * 'o' will never point to '\0' at this point, the only chance
211
     * 'o' can point to '\0' is either the subsequent if or the first
212
     * else if is true.
213
     */
214
272k
    if (a[o] == upper_z) {
215
203k
        o++;
216
203k
    } else if (!strict && ((a[o] == plus) || (a[o] == minus))) {
217
62.7k
        int offsign = a[o] == minus ? 1 : -1;
218
62.7k
        int offset = 0;
219
220
62.7k
        o++;
221
        /*
222
         * if not equal, no need to do subsequent checks
223
         * since the following for-loop will add 'o' by 4
224
         * and the final return statement will check if 'l'
225
         * and 'o' are equal.
226
         */
227
62.7k
        if (o + 4 != l)
228
9.70k
            goto err;
229
129k
        for (i = end; i < end + 2; i++) {
230
97.9k
            if (!ossl_ascii_isdigit(a[o]))
231
5.18k
                goto err;
232
92.7k
            n = a[o] - num_zero;
233
92.7k
            o++;
234
92.7k
            if (!ossl_ascii_isdigit(a[o]))
235
10.5k
                goto err;
236
82.2k
            n = (n * 10) + a[o] - num_zero;
237
82.2k
            i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
238
82.2k
            if ((n < min[i2]) || (n > max[i2]))
239
6.18k
                goto err;
240
            /* if tm is NULL, no need to adjust */
241
76.0k
            if (tm != NULL) {
242
76.0k
                if (i == end)
243
44.9k
                    offset = n * 3600;
244
31.1k
                else if (i == end + 1)
245
31.1k
                    offset += n * 60;
246
76.0k
            }
247
76.0k
            o++;
248
76.0k
        }
249
31.1k
        if (offset && !OPENSSL_gmtime_adj(&tmp, 0, offset * offsign))
250
379
            goto err;
251
31.1k
    } else {
252
        /* not Z, or not +/- in non-strict mode */
253
6.81k
        goto err;
254
6.81k
    }
255
233k
    if (o == l) {
256
        /* success, check if tm should be filled */
257
231k
        if (tm != NULL)
258
187k
            *tm = tmp;
259
231k
        return 1;
260
231k
    }
261
236k
err:
262
236k
    return 0;
263
233k
}
264
265
ASN1_TIME *ossl_asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type)
266
97.0k
{
267
97.0k
    char *p;
268
97.0k
    ASN1_TIME *tmps = NULL;
269
97.0k
    const size_t len = 20;
270
271
97.0k
    if (type == V_ASN1_UNDEF) {
272
18.5k
        if (is_utc(ts->tm_year))
273
18.5k
            type = V_ASN1_UTCTIME;
274
0
        else
275
0
            type = V_ASN1_GENERALIZEDTIME;
276
78.5k
    } else if (type == V_ASN1_UTCTIME) {
277
0
        if (!is_utc(ts->tm_year))
278
0
            goto err;
279
78.5k
    } else if (type != V_ASN1_GENERALIZEDTIME) {
280
0
        goto err;
281
0
    }
282
283
97.0k
    if (s == NULL)
284
18.5k
        tmps = ASN1_STRING_new();
285
78.5k
    else
286
78.5k
        tmps = s;
287
97.0k
    if (tmps == NULL)
288
0
        return NULL;
289
290
97.0k
    if (!ASN1_STRING_set(tmps, NULL, len))
291
0
        goto err;
292
293
97.0k
    tmps->type = type;
294
97.0k
    p = (char *)tmps->data;
295
296
97.0k
    if (ts->tm_mon > INT_MAX - 1)
297
0
        goto err;
298
299
97.0k
    if (type == V_ASN1_GENERALIZEDTIME) {
300
78.5k
        if (ts->tm_year > INT_MAX - 1900)
301
0
            goto err;
302
78.5k
        tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ",
303
78.5k
            ts->tm_year + 1900, ts->tm_mon + 1,
304
78.5k
            ts->tm_mday, ts->tm_hour, ts->tm_min,
305
78.5k
            ts->tm_sec);
306
78.5k
    } else {
307
18.5k
        tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ",
308
18.5k
            ts->tm_year % 100, ts->tm_mon + 1,
309
18.5k
            ts->tm_mday, ts->tm_hour, ts->tm_min,
310
18.5k
            ts->tm_sec);
311
18.5k
    }
312
313
#ifdef CHARSET_EBCDIC
314
    ebcdic2ascii(tmps->data, tmps->data, tmps->length);
315
#endif
316
97.0k
    return tmps;
317
0
err:
318
0
    if (tmps != s)
319
0
        ASN1_STRING_free(tmps);
320
0
    return NULL;
321
97.0k
}
322
323
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
324
0
{
325
0
    return ASN1_TIME_adj(s, t, 0, 0);
326
0
}
327
328
ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
329
    int offset_day, long offset_sec)
330
21.6k
{
331
21.6k
    struct tm *ts;
332
21.6k
    struct tm data;
333
334
21.6k
    ts = OPENSSL_gmtime(&t, &data);
335
21.6k
    if (ts == NULL) {
336
0
        ERR_raise(ERR_LIB_ASN1, ASN1_R_ERROR_GETTING_TIME);
337
0
        return NULL;
338
0
    }
339
21.6k
    if (offset_day || offset_sec) {
340
0
        if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
341
0
            return NULL;
342
0
    }
343
21.6k
    return ossl_asn1_time_from_tm(s, ts, V_ASN1_UNDEF);
344
21.6k
}
345
346
int ASN1_TIME_check(const ASN1_TIME *t)
347
0
{
348
0
    if (t->type == V_ASN1_GENERALIZEDTIME)
349
0
        return ASN1_GENERALIZEDTIME_check(t);
350
0
    else if (t->type == V_ASN1_UTCTIME)
351
0
        return ASN1_UTCTIME_check(t);
352
0
    return 0;
353
0
}
354
355
/* Convert an ASN1_TIME structure to GeneralizedTime */
356
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
357
    ASN1_GENERALIZEDTIME **out)
358
0
{
359
0
    ASN1_GENERALIZEDTIME *ret = NULL;
360
0
    struct tm tm;
361
362
0
    if (!ASN1_TIME_to_tm(t, &tm))
363
0
        return NULL;
364
365
0
    if (out != NULL)
366
0
        ret = *out;
367
368
0
    ret = ossl_asn1_time_from_tm(ret, &tm, V_ASN1_GENERALIZEDTIME);
369
370
0
    if (out != NULL && ret != NULL)
371
0
        *out = ret;
372
373
0
    return ret;
374
0
}
375
376
int ASN1_TIME_set_string(ASN1_TIME *s, const char *str)
377
0
{
378
    /* Try UTC, if that fails, try GENERALIZED */
379
0
    if (ASN1_UTCTIME_set_string(s, str))
380
0
        return 1;
381
0
    return ASN1_GENERALIZEDTIME_set_string(s, str);
382
0
}
383
384
int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str)
385
0
{
386
0
    ASN1_TIME t;
387
0
    struct tm tm;
388
0
    int rv = 0;
389
390
0
    t.length = strlen(str);
391
0
    t.data = (unsigned char *)str;
392
0
    t.flags = ASN1_STRING_FLAG_X509_TIME;
393
394
0
    t.type = V_ASN1_UTCTIME;
395
396
0
    if (!ASN1_TIME_check(&t)) {
397
0
        t.type = V_ASN1_GENERALIZEDTIME;
398
0
        if (!ASN1_TIME_check(&t))
399
0
            goto out;
400
0
    }
401
402
    /*
403
     * Per RFC 5280 (section 4.1.2.5.), the valid input time
404
     * strings should be encoded with the following rules:
405
     *
406
     * 1. UTC: YYMMDDHHMMSSZ, if YY < 50 (20YY) --> UTC: YYMMDDHHMMSSZ
407
     * 2. UTC: YYMMDDHHMMSSZ, if YY >= 50 (19YY) --> UTC: YYMMDDHHMMSSZ
408
     * 3. G'd: YYYYMMDDHHMMSSZ, if YYYY >= 2050 --> G'd: YYYYMMDDHHMMSSZ
409
     * 4. G'd: YYYYMMDDHHMMSSZ, if YYYY < 2050 --> UTC: YYMMDDHHMMSSZ
410
     *
411
     * Only strings of the 4th rule should be reformatted, but since a
412
     * UTC can only present [1950, 2050), so if the given time string
413
     * is less than 1950 (e.g. 19230419000000Z), we do nothing...
414
     */
415
416
0
    if (s != NULL && t.type == V_ASN1_GENERALIZEDTIME) {
417
0
        if (!ossl_asn1_time_to_tm(&tm, &t))
418
0
            goto out;
419
0
        if (is_utc(tm.tm_year)) {
420
0
            t.length -= 2;
421
            /*
422
             * it's OK to let original t.data go since that's assigned
423
             * to a piece of memory allocated outside of this function.
424
             * new t.data would be freed after ASN1_STRING_copy is done.
425
             */
426
0
            t.data = OPENSSL_zalloc(t.length + 1);
427
0
            if (t.data == NULL)
428
0
                goto out;
429
0
            memcpy(t.data, str + 2, t.length);
430
0
            t.type = V_ASN1_UTCTIME;
431
0
        }
432
0
    }
433
434
0
    if (s == NULL || ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))
435
0
        rv = 1;
436
437
0
    if (t.data != (unsigned char *)str)
438
0
        OPENSSL_free(t.data);
439
0
out:
440
0
    return rv;
441
0
}
442
443
int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm)
444
43.6k
{
445
43.6k
    if (s == NULL) {
446
0
        time_t now_t;
447
448
0
        time(&now_t);
449
0
        memset(tm, 0, sizeof(*tm));
450
0
        if (OPENSSL_gmtime(&now_t, tm) != NULL)
451
0
            return 1;
452
0
        return 0;
453
0
    }
454
455
43.6k
    return ossl_asn1_time_to_tm(tm, s);
456
43.6k
}
457
458
int ASN1_TIME_diff(int *pday, int *psec,
459
    const ASN1_TIME *from, const ASN1_TIME *to)
460
22.0k
{
461
22.0k
    struct tm tm_from, tm_to;
462
463
22.0k
    if (!ASN1_TIME_to_tm(from, &tm_from))
464
4.39k
        return 0;
465
17.6k
    if (!ASN1_TIME_to_tm(to, &tm_to))
466
69
        return 0;
467
17.5k
    return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to);
468
17.6k
}
469
470
static const char _asn1_mon[12][4] = {
471
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
472
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
473
};
474
475
/* prints the time with the default date format (RFC 822) */
476
int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
477
338k
{
478
338k
    return ASN1_TIME_print_ex(bp, tm, ASN1_DTFLGS_RFC822);
479
338k
}
480
481
/* returns 1 on success, 0 on BIO write error or parse failure */
482
int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags)
483
338k
{
484
338k
    return ossl_asn1_time_print_ex(bp, tm, flags) > 0;
485
338k
}
486
487
/* prints the time with the date format of ISO 8601 */
488
/* returns 0 on BIO write error, else -1 in case of parse failure, else 1 */
489
int ossl_asn1_time_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags)
490
425k
{
491
425k
    char *v;
492
425k
    int l;
493
425k
    struct tm stm;
494
425k
    const char period = 0x2E;
495
496
    /* ossl_asn1_time_to_tm will check the time type */
497
425k
    if (!ossl_asn1_time_to_tm(&stm, tm))
498
248k
        return BIO_write(bp, "Bad time value", 14) ? -1 : 0;
499
500
177k
    l = tm->length;
501
177k
    v = (char *)tm->data;
502
503
177k
    if (tm->type == V_ASN1_GENERALIZEDTIME) {
504
94.2k
        char *f = NULL;
505
94.2k
        int f_len = 0;
506
507
        /*
508
         * Try to parse fractional seconds. '14' is the place of
509
         * 'fraction point' in a GeneralizedTime string.
510
         */
511
94.2k
        if (tm->length > 15 && v[14] == period) {
512
            /* exclude the . itself */
513
57.8k
            f = &v[15];
514
57.8k
            f_len = 0;
515
267k
            while (15 + f_len < l && ossl_ascii_isdigit(f[f_len]))
516
209k
                ++f_len;
517
57.8k
        }
518
519
94.2k
        if (f_len > 0) {
520
57.8k
            if ((flags & ASN1_DTFLGS_TYPE_MASK) == ASN1_DTFLGS_ISO8601) {
521
0
                return BIO_printf(bp, "%4d-%02d-%02d %02d:%02d:%02d.%.*sZ",
522
0
                           stm.tm_year + 1900, stm.tm_mon + 1,
523
0
                           stm.tm_mday, stm.tm_hour,
524
0
                           stm.tm_min, stm.tm_sec, f_len, f)
525
0
                    > 0;
526
57.8k
            } else {
527
57.8k
                return BIO_printf(bp, "%s %2d %02d:%02d:%02d.%.*s %d GMT",
528
57.8k
                           _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour,
529
57.8k
                           stm.tm_min, stm.tm_sec, f_len, f,
530
57.8k
                           stm.tm_year + 1900)
531
57.8k
                    > 0;
532
57.8k
            }
533
57.8k
        }
534
94.2k
    }
535
119k
    if ((flags & ASN1_DTFLGS_TYPE_MASK) == ASN1_DTFLGS_ISO8601) {
536
0
        return BIO_printf(bp, "%4d-%02d-%02d %02d:%02d:%02dZ",
537
0
                   stm.tm_year + 1900, stm.tm_mon + 1,
538
0
                   stm.tm_mday, stm.tm_hour,
539
0
                   stm.tm_min, stm.tm_sec)
540
0
            > 0;
541
119k
    } else {
542
119k
        return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d GMT",
543
119k
                   _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour,
544
119k
                   stm.tm_min, stm.tm_sec, stm.tm_year + 1900)
545
119k
            > 0;
546
119k
    }
547
119k
}
548
549
int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t)
550
0
{
551
0
    struct tm stm, ttm;
552
0
    int day, sec;
553
554
0
    if (!ASN1_TIME_to_tm(s, &stm))
555
0
        return -2;
556
557
0
    if (!OPENSSL_gmtime(&t, &ttm))
558
0
        return -2;
559
560
0
    if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
561
0
        return -2;
562
563
0
    if (day > 0 || sec > 0)
564
0
        return 1;
565
0
    if (day < 0 || sec < 0)
566
0
        return -1;
567
0
    return 0;
568
0
}
569
570
int ASN1_TIME_normalize(ASN1_TIME *t)
571
0
{
572
0
    struct tm tm;
573
574
0
    if (t == NULL || !ASN1_TIME_to_tm(t, &tm))
575
0
        return 0;
576
577
0
    return ossl_asn1_time_from_tm(t, &tm, V_ASN1_UNDEF) != NULL;
578
0
}
579
580
int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)
581
404
{
582
404
    int day, sec;
583
584
404
    if (!ASN1_TIME_diff(&day, &sec, b, a))
585
213
        return -2;
586
191
    if (day > 0 || sec > 0)
587
42
        return 1;
588
149
    if (day < 0 || sec < 0)
589
143
        return -1;
590
6
    return 0;
591
149
}