Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl36/crypto/evp/encode.c
Line
Count
Source
1
/*
2
 * Copyright 1995-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
#include <stdio.h>
11
#include <limits.h>
12
#include "internal/cryptlib.h"
13
#include <openssl/evp.h>
14
#include "crypto/evp.h"
15
#include "evp_local.h"
16
17
static unsigned char conv_ascii2bin(unsigned char a,
18
    const unsigned char *table);
19
static int evp_encodeblock_int(EVP_ENCODE_CTX *ctx, unsigned char *t,
20
    const unsigned char *f, int dlen);
21
static int evp_decodeblock_int(EVP_ENCODE_CTX *ctx, unsigned char *t,
22
    const unsigned char *f, int n, int eof);
23
24
#ifndef CHARSET_EBCDIC
25
12.3k
#define conv_bin2ascii(a, table) ((table)[(a) & 0x3f])
26
#else
27
/*
28
 * We assume that PEM encoded files are EBCDIC files (i.e., printable text
29
 * files). Convert them here while decoding. When encoding, output is EBCDIC
30
 * (text) format again. (No need for conversion in the conv_bin2ascii macro,
31
 * as the underlying textstring data_bin2ascii[] is already EBCDIC)
32
 */
33
#define conv_bin2ascii(a, table) ((table)[(a) & 0x3f])
34
#endif
35
36
/*-
37
 * 64 char lines
38
 * pad input with 0
39
 * left over chars are set to =
40
 * 1 byte  => xx==
41
 * 2 bytes => xxx=
42
 * 3 bytes => xxxx
43
 */
44
#define BIN_PER_LINE (64 / 4 * 3)
45
#define CHUNKS_PER_LINE (64 / 4)
46
#define CHAR_PER_LINE (64 + 1)
47
48
static const unsigned char data_bin2ascii[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
49
50
/* SRP uses a different base64 alphabet */
51
static const unsigned char srpdata_bin2ascii[65] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
52
53
/*-
54
 * 0xF0 is a EOLN
55
 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
56
 * 0xF2 is EOF
57
 * 0xE0 is ignore at start of line.
58
 * 0xFF is error
59
 */
60
61
#define B64_EOLN 0xF0
62
#define B64_CR 0xF1
63
187M
#define B64_EOF 0xF2
64
2.88M
#define B64_WS 0xE0
65
188M
#define B64_ERROR 0xFF
66
194M
#define B64_NOT_BASE64(a) (((a) | 0x13) == 0xF3)
67
191M
#define B64_BASE64(a) (!B64_NOT_BASE64(a))
68
69
static const unsigned char data_ascii2bin[128] = {
70
    0xFF,
71
    0xFF,
72
    0xFF,
73
    0xFF,
74
    0xFF,
75
    0xFF,
76
    0xFF,
77
    0xFF,
78
    0xFF,
79
    0xE0,
80
    0xF0,
81
    0xFF,
82
    0xFF,
83
    0xF1,
84
    0xFF,
85
    0xFF,
86
    0xFF,
87
    0xFF,
88
    0xFF,
89
    0xFF,
90
    0xFF,
91
    0xFF,
92
    0xFF,
93
    0xFF,
94
    0xFF,
95
    0xFF,
96
    0xFF,
97
    0xFF,
98
    0xFF,
99
    0xFF,
100
    0xFF,
101
    0xFF,
102
    0xE0,
103
    0xFF,
104
    0xFF,
105
    0xFF,
106
    0xFF,
107
    0xFF,
108
    0xFF,
109
    0xFF,
110
    0xFF,
111
    0xFF,
112
    0xFF,
113
    0x3E,
114
    0xFF,
115
    0xF2,
116
    0xFF,
117
    0x3F,
118
    0x34,
119
    0x35,
120
    0x36,
121
    0x37,
122
    0x38,
123
    0x39,
124
    0x3A,
125
    0x3B,
126
    0x3C,
127
    0x3D,
128
    0xFF,
129
    0xFF,
130
    0xFF,
131
    0x00,
132
    0xFF,
133
    0xFF,
134
    0xFF,
135
    0x00,
136
    0x01,
137
    0x02,
138
    0x03,
139
    0x04,
140
    0x05,
141
    0x06,
142
    0x07,
143
    0x08,
144
    0x09,
145
    0x0A,
146
    0x0B,
147
    0x0C,
148
    0x0D,
149
    0x0E,
150
    0x0F,
151
    0x10,
152
    0x11,
153
    0x12,
154
    0x13,
155
    0x14,
156
    0x15,
157
    0x16,
158
    0x17,
159
    0x18,
160
    0x19,
161
    0xFF,
162
    0xFF,
163
    0xFF,
164
    0xFF,
165
    0xFF,
166
    0xFF,
167
    0x1A,
168
    0x1B,
169
    0x1C,
170
    0x1D,
171
    0x1E,
172
    0x1F,
173
    0x20,
174
    0x21,
175
    0x22,
176
    0x23,
177
    0x24,
178
    0x25,
179
    0x26,
180
    0x27,
181
    0x28,
182
    0x29,
183
    0x2A,
184
    0x2B,
185
    0x2C,
186
    0x2D,
187
    0x2E,
188
    0x2F,
189
    0x30,
190
    0x31,
191
    0x32,
192
    0x33,
193
    0xFF,
194
    0xFF,
195
    0xFF,
196
    0xFF,
197
    0xFF,
198
};
199
200
static const unsigned char srpdata_ascii2bin[128] = {
201
    0xFF,
202
    0xFF,
203
    0xFF,
204
    0xFF,
205
    0xFF,
206
    0xFF,
207
    0xFF,
208
    0xFF,
209
    0xFF,
210
    0xE0,
211
    0xF0,
212
    0xFF,
213
    0xFF,
214
    0xF1,
215
    0xFF,
216
    0xFF,
217
    0xFF,
218
    0xFF,
219
    0xFF,
220
    0xFF,
221
    0xFF,
222
    0xFF,
223
    0xFF,
224
    0xFF,
225
    0xFF,
226
    0xFF,
227
    0xFF,
228
    0xFF,
229
    0xFF,
230
    0xFF,
231
    0xFF,
232
    0xFF,
233
    0xE0,
234
    0xFF,
235
    0xFF,
236
    0xFF,
237
    0xFF,
238
    0xFF,
239
    0xFF,
240
    0xFF,
241
    0xFF,
242
    0xFF,
243
    0xFF,
244
    0xFF,
245
    0xFF,
246
    0xF2,
247
    0x3E,
248
    0x3F,
249
    0x00,
250
    0x01,
251
    0x02,
252
    0x03,
253
    0x04,
254
    0x05,
255
    0x06,
256
    0x07,
257
    0x08,
258
    0x09,
259
    0xFF,
260
    0xFF,
261
    0xFF,
262
    0x00,
263
    0xFF,
264
    0xFF,
265
    0xFF,
266
    0x0A,
267
    0x0B,
268
    0x0C,
269
    0x0D,
270
    0x0E,
271
    0x0F,
272
    0x10,
273
    0x11,
274
    0x12,
275
    0x13,
276
    0x14,
277
    0x15,
278
    0x16,
279
    0x17,
280
    0x18,
281
    0x19,
282
    0x1A,
283
    0x1B,
284
    0x1C,
285
    0x1D,
286
    0x1E,
287
    0x1F,
288
    0x20,
289
    0x21,
290
    0x22,
291
    0x23,
292
    0xFF,
293
    0xFF,
294
    0xFF,
295
    0xFF,
296
    0xFF,
297
    0xFF,
298
    0x24,
299
    0x25,
300
    0x26,
301
    0x27,
302
    0x28,
303
    0x29,
304
    0x2A,
305
    0x2B,
306
    0x2C,
307
    0x2D,
308
    0x2E,
309
    0x2F,
310
    0x30,
311
    0x31,
312
    0x32,
313
    0x33,
314
    0x34,
315
    0x35,
316
    0x36,
317
    0x37,
318
    0x38,
319
    0x39,
320
    0x3A,
321
    0x3B,
322
    0x3C,
323
    0x3D,
324
    0xFF,
325
    0xFF,
326
    0xFF,
327
    0xFF,
328
    0xFF,
329
};
330
331
#ifndef CHARSET_EBCDIC
332
static unsigned char conv_ascii2bin(unsigned char a, const unsigned char *table)
333
683M
{
334
683M
    if (a & 0x80)
335
4.30k
        return B64_ERROR;
336
683M
    return table[a];
337
683M
}
338
#else
339
static unsigned char conv_ascii2bin(unsigned char a, const unsigned char *table)
340
{
341
    a = os_toascii[a];
342
    if (a & 0x80)
343
        return B64_ERROR;
344
    return table[a];
345
}
346
#endif
347
348
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void)
349
264k
{
350
264k
    return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
351
264k
}
352
353
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx)
354
307k
{
355
307k
    OPENSSL_free(ctx);
356
307k
}
357
358
int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, const EVP_ENCODE_CTX *sctx)
359
0
{
360
0
    memcpy(dctx, sctx, sizeof(EVP_ENCODE_CTX));
361
362
0
    return 1;
363
0
}
364
365
int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx)
366
12.9k
{
367
12.9k
    return ctx->num;
368
12.9k
}
369
370
void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags)
371
0
{
372
0
    ctx->flags = flags;
373
0
}
374
375
void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
376
5.92k
{
377
5.92k
    ctx->length = 48;
378
5.92k
    ctx->num = 0;
379
5.92k
    ctx->line_num = 0;
380
5.92k
    ctx->flags = 0;
381
5.92k
}
382
383
int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
384
    const unsigned char *in, int inl)
385
0
{
386
0
    int i, j;
387
0
    size_t total = 0;
388
389
0
    *outl = 0;
390
0
    if (inl <= 0)
391
0
        return 0;
392
0
    OPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));
393
0
    if (ctx->length - ctx->num > inl) {
394
0
        memcpy(&(ctx->enc_data[ctx->num]), in, inl);
395
0
        ctx->num += inl;
396
0
        return 1;
397
0
    }
398
0
    if (ctx->num != 0) {
399
0
        i = ctx->length - ctx->num;
400
0
        memcpy(&(ctx->enc_data[ctx->num]), in, i);
401
0
        in += i;
402
0
        inl -= i;
403
0
        j = evp_encodeblock_int(ctx, out, ctx->enc_data, ctx->length);
404
0
        ctx->num = 0;
405
0
        out += j;
406
0
        total = j;
407
0
        if ((ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) == 0) {
408
0
            *(out++) = '\n';
409
0
            total++;
410
0
        }
411
0
        *out = '\0';
412
0
    }
413
0
    while (inl >= ctx->length && total <= INT_MAX) {
414
0
        j = evp_encodeblock_int(ctx, out, in, ctx->length);
415
0
        in += ctx->length;
416
0
        inl -= ctx->length;
417
0
        out += j;
418
0
        total += j;
419
0
        if ((ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) == 0) {
420
0
            *(out++) = '\n';
421
0
            total++;
422
0
        }
423
0
        *out = '\0';
424
0
    }
425
0
    if (total > INT_MAX) {
426
        /* Too much output data! */
427
0
        *outl = 0;
428
0
        return 0;
429
0
    }
430
0
    if (inl != 0)
431
0
        memcpy(&(ctx->enc_data[0]), in, inl);
432
0
    ctx->num = inl;
433
0
    *outl = (int)total;
434
435
0
    return 1;
436
0
}
437
438
void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
439
573
{
440
573
    unsigned int ret = 0;
441
442
573
    if (ctx->num != 0) {
443
573
        ret = evp_encodeblock_int(ctx, out, ctx->enc_data, ctx->num);
444
573
        if ((ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) == 0)
445
573
            out[ret++] = '\n';
446
573
        out[ret] = '\0';
447
573
        ctx->num = 0;
448
573
    }
449
573
    *outl = ret;
450
573
}
451
452
static int evp_encodeblock_int(EVP_ENCODE_CTX *ctx, unsigned char *t,
453
    const unsigned char *f, int dlen)
454
573
{
455
573
    int i, ret = 0;
456
573
    unsigned long l;
457
573
    const unsigned char *table;
458
459
573
    if (ctx != NULL && (ctx->flags & EVP_ENCODE_CTX_USE_SRP_ALPHABET) != 0)
460
0
        table = srpdata_bin2ascii;
461
573
    else
462
573
        table = data_bin2ascii;
463
464
3.73k
    for (i = dlen; i > 0; i -= 3) {
465
3.15k
        if (i >= 3) {
466
2.70k
            l = (((unsigned long)f[0]) << 16L) | (((unsigned long)f[1]) << 8L) | f[2];
467
2.70k
            *(t++) = conv_bin2ascii(l >> 18L, table);
468
2.70k
            *(t++) = conv_bin2ascii(l >> 12L, table);
469
2.70k
            *(t++) = conv_bin2ascii(l >> 6L, table);
470
2.70k
            *(t++) = conv_bin2ascii(l, table);
471
2.70k
        } else {
472
451
            l = ((unsigned long)f[0]) << 16L;
473
451
            if (i == 2)
474
185
                l |= ((unsigned long)f[1] << 8L);
475
476
451
            *(t++) = conv_bin2ascii(l >> 18L, table);
477
451
            *(t++) = conv_bin2ascii(l >> 12L, table);
478
451
            *(t++) = (i == 1) ? '=' : conv_bin2ascii(l >> 6L, table);
479
451
            *(t++) = '=';
480
451
        }
481
3.15k
        ret += 4;
482
3.15k
        f += 3;
483
3.15k
    }
484
485
573
    *t = '\0';
486
573
    return ret;
487
573
}
488
489
int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
490
0
{
491
0
    return evp_encodeblock_int(NULL, t, f, dlen);
492
0
}
493
494
void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
495
607k
{
496
    /* Only ctx->num and ctx->flags are used during decoding. */
497
607k
    ctx->num = 0;
498
607k
    ctx->length = 0;
499
607k
    ctx->line_num = 0;
500
607k
    ctx->flags = 0;
501
607k
}
502
503
/*-
504
 * -1 for error
505
 *  0 for last line
506
 *  1 for full line
507
 *
508
 * Note: even though EVP_DecodeUpdate attempts to detect and report end of
509
 * content, the context doesn't currently remember it and will accept more data
510
 * in the next call. Therefore, the caller is responsible for checking and
511
 * rejecting a 0 return value in the middle of content.
512
 *
513
 * Note: even though EVP_DecodeUpdate has historically tried to detect end of
514
 * content based on line length, this has never worked properly. Therefore,
515
 * we now return 0 when one of the following is true:
516
 *   - Padding or B64_EOF was detected and the last block is complete.
517
 *   - Input has zero-length.
518
 * -1 is returned if:
519
 *   - Invalid characters are detected.
520
 *   - There is extra trailing padding, or data after padding.
521
 *   - B64_EOF is detected after an incomplete base64 block.
522
 */
523
int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
524
    const unsigned char *in, int inl)
525
465k
{
526
465k
    int seof = 0, eof = 0, rv = -1, ret = 0, i, v, tmp, n, decoded_len;
527
465k
    unsigned char *d;
528
465k
    const unsigned char *table;
529
530
465k
    n = ctx->num;
531
465k
    d = ctx->enc_data;
532
533
465k
    if (n > 0 && d[n - 1] == '=') {
534
3.40k
        eof++;
535
3.40k
        if (n > 1 && d[n - 2] == '=')
536
1.12k
            eof++;
537
3.40k
    }
538
539
    /* Legacy behaviour: an empty input chunk signals end of input. */
540
465k
    if (inl == 0) {
541
0
        rv = 0;
542
0
        goto end;
543
0
    }
544
545
465k
    if ((ctx->flags & EVP_ENCODE_CTX_USE_SRP_ALPHABET) != 0)
546
0
        table = srpdata_ascii2bin;
547
465k
    else
548
465k
        table = data_ascii2bin;
549
550
188M
    for (i = 0; i < inl; i++) {
551
188M
        tmp = *(in++);
552
188M
        v = conv_ascii2bin(tmp, table);
553
188M
        if (v == B64_ERROR) {
554
225k
            rv = -1;
555
225k
            goto end;
556
225k
        }
557
558
187M
        if (tmp == '=') {
559
184k
            eof++;
560
187M
        } else if (eof > 0 && B64_BASE64(v)) {
561
            /* More data after padding. */
562
702
            rv = -1;
563
702
            goto end;
564
702
        }
565
566
187M
        if (eof > 2) {
567
853
            rv = -1;
568
853
            goto end;
569
853
        }
570
571
187M
        if (v == B64_EOF) {
572
3.61k
            seof = 1;
573
3.61k
            goto tail;
574
3.61k
        }
575
576
        /* Only save valid base64 characters. */
577
187M
        if (B64_BASE64(v)) {
578
178M
            if (n >= 64) {
579
                /*
580
                 * We increment n once per loop, and empty the buffer as soon as
581
                 * we reach 64 characters, so this can only happen if someone's
582
                 * manually messed with the ctx. Refuse to write any more data.
583
                 */
584
0
                rv = -1;
585
0
                goto end;
586
0
            }
587
178M
            OPENSSL_assert(n < (int)sizeof(ctx->enc_data));
588
178M
            d[n++] = tmp;
589
178M
        }
590
591
187M
        if (n == 64) {
592
2.73M
            decoded_len = evp_decodeblock_int(ctx, out, d, n, eof);
593
2.73M
            n = 0;
594
2.73M
            if (decoded_len < 0 || (decoded_len == 0 && eof > 0)) {
595
0
                rv = -1;
596
0
                goto end;
597
0
            }
598
2.73M
            ret += decoded_len;
599
2.73M
            out += decoded_len;
600
2.73M
        }
601
187M
    }
602
603
    /*
604
     * Legacy behaviour: if the current line is a full base64-block (i.e., has
605
     * 0 mod 4 base64 characters), it is processed immediately. We keep this
606
     * behaviour as applications may not be calling EVP_DecodeFinal properly.
607
     */
608
238k
tail:
609
238k
    if (n > 0) {
610
207k
        if ((n & 3) == 0) {
611
148k
            decoded_len = evp_decodeblock_int(ctx, out, d, n, eof);
612
148k
            n = 0;
613
148k
            if (decoded_len < 0 || (decoded_len == 0 && eof > 0)) {
614
0
                rv = -1;
615
0
                goto end;
616
0
            }
617
148k
            ret += decoded_len;
618
148k
        } else if (seof) {
619
            /* EOF in the middle of a base64 block. */
620
1.22k
            rv = -1;
621
1.22k
            goto end;
622
1.22k
        }
623
207k
    }
624
625
237k
    rv = seof || (n == 0 && eof) ? 0 : 1;
626
465k
end:
627
    /* Legacy behaviour. This should probably rather be zeroed on error. */
628
465k
    *outl = ret;
629
465k
    ctx->num = n;
630
465k
    return rv;
631
237k
}
632
633
static int evp_decodeblock_int(EVP_ENCODE_CTX *ctx, unsigned char *t,
634
    const unsigned char *f, int n,
635
    int eof)
636
2.88M
{
637
2.88M
    int i, ret = 0, a, b, c, d;
638
2.88M
    unsigned long l;
639
2.88M
    const unsigned char *table;
640
641
2.88M
    if (eof < -1 || eof > 2)
642
0
        return -1;
643
644
2.88M
    if (ctx != NULL && (ctx->flags & EVP_ENCODE_CTX_USE_SRP_ALPHABET) != 0)
645
0
        table = srpdata_ascii2bin;
646
2.88M
    else
647
2.88M
        table = data_ascii2bin;
648
649
    /* trim whitespace from the start of the line. */
650
2.88M
    while ((n > 0) && (conv_ascii2bin(*f, table) == B64_WS)) {
651
0
        f++;
652
0
        n--;
653
0
    }
654
655
    /*
656
     * strip off stuff at the end of the line ascii2bin values B64_WS,
657
     * B64_EOLN, B64_EOLN and B64_EOF
658
     */
659
2.88M
    while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n - 1], table))))
660
0
        n--;
661
662
2.88M
    if (n % 4 != 0)
663
563
        return -1;
664
2.88M
    if (n == 0)
665
0
        return 0;
666
667
    /* all 4-byte blocks except the last one do not have padding. */
668
44.7M
    for (i = 0; i < n - 4; i += 4) {
669
41.8M
        a = conv_ascii2bin(*(f++), table);
670
41.8M
        b = conv_ascii2bin(*(f++), table);
671
41.8M
        c = conv_ascii2bin(*(f++), table);
672
41.8M
        d = conv_ascii2bin(*(f++), table);
673
41.8M
        if ((a | b | c | d) & 0x80)
674
0
            return -1;
675
41.8M
        l = ((((unsigned long)a) << 18L) | (((unsigned long)b) << 12L) | (((unsigned long)c) << 6L) | (((unsigned long)d)));
676
41.8M
        *(t++) = (unsigned char)(l >> 16L) & 0xff;
677
41.8M
        *(t++) = (unsigned char)(l >> 8L) & 0xff;
678
41.8M
        *(t++) = (unsigned char)(l) & 0xff;
679
41.8M
        ret += 3;
680
41.8M
    }
681
682
    /* process the last block that may have padding. */
683
2.88M
    a = conv_ascii2bin(*(f++), table);
684
2.88M
    b = conv_ascii2bin(*(f++), table);
685
2.88M
    c = conv_ascii2bin(*(f++), table);
686
2.88M
    d = conv_ascii2bin(*(f++), table);
687
2.88M
    if ((a | b | c | d) & 0x80)
688
0
        return -1;
689
2.88M
    l = ((((unsigned long)a) << 18L) | (((unsigned long)b) << 12L) | (((unsigned long)c) << 6L) | (((unsigned long)d)));
690
691
2.88M
    if (eof == -1)
692
0
        eof = (f[2] == '=') + (f[3] == '=');
693
694
2.88M
    switch (eof) {
695
83.2k
    case 2:
696
83.2k
        *(t++) = (unsigned char)(l >> 16L) & 0xff;
697
83.2k
        break;
698
13.6k
    case 1:
699
13.6k
        *(t++) = (unsigned char)(l >> 16L) & 0xff;
700
13.6k
        *(t++) = (unsigned char)(l >> 8L) & 0xff;
701
13.6k
        break;
702
2.78M
    case 0:
703
2.78M
        *(t++) = (unsigned char)(l >> 16L) & 0xff;
704
2.78M
        *(t++) = (unsigned char)(l >> 8L) & 0xff;
705
2.78M
        *(t++) = (unsigned char)(l) & 0xff;
706
2.78M
        break;
707
2.88M
    }
708
2.88M
    ret += 3 - eof;
709
710
2.88M
    return ret;
711
2.88M
}
712
713
int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
714
0
{
715
0
    return evp_decodeblock_int(NULL, t, f, n, 0);
716
0
}
717
718
int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
719
254k
{
720
254k
    int i;
721
722
254k
    *outl = 0;
723
254k
    if (ctx->num != 0) {
724
815
        i = evp_decodeblock_int(ctx, out, ctx->enc_data, ctx->num, -1);
725
815
        if (i < 0)
726
815
            return -1;
727
0
        ctx->num = 0;
728
0
        *outl = i;
729
0
        return 1;
730
815
    } else
731
253k
        return 1;
732
254k
}