encode.c 15 KB

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