1/* 2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL license (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 <openssl/cipher.h> 11 12#include <assert.h> 13#include <limits.h> 14#include <string.h> 15 16#include <openssl/err.h> 17#include <openssl/mem.h> 18#include <openssl/nid.h> 19 20#include "../../internal.h" 21#include "../service_indicator/internal.h" 22#include "internal.h" 23 24 25void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) { 26 OPENSSL_memset(ctx, 0, sizeof(EVP_CIPHER_CTX)); 27} 28 29EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) { 30 EVP_CIPHER_CTX *ctx = reinterpret_cast<EVP_CIPHER_CTX *>( 31 OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))); 32 if (ctx) { 33 EVP_CIPHER_CTX_init(ctx); 34 } 35 return ctx; 36} 37 38int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) { 39 if (c->cipher != NULL && c->cipher->cleanup) { 40 c->cipher->cleanup(c); 41 } 42 OPENSSL_free(c->cipher_data); 43 44 OPENSSL_memset(c, 0, sizeof(EVP_CIPHER_CTX)); 45 return 1; 46} 47 48void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) { 49 if (ctx) { 50 EVP_CIPHER_CTX_cleanup(ctx); 51 OPENSSL_free(ctx); 52 } 53} 54 55int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) { 56 if (in == NULL || in->cipher == NULL) { 57 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INPUT_NOT_INITIALIZED); 58 return 0; 59 } 60 61 if (in->poisoned) { 62 OPENSSL_PUT_ERROR(CIPHER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 63 return 0; 64 } 65 66 EVP_CIPHER_CTX_cleanup(out); 67 OPENSSL_memcpy(out, in, sizeof(EVP_CIPHER_CTX)); 68 69 if (in->cipher_data && in->cipher->ctx_size) { 70 out->cipher_data = OPENSSL_memdup(in->cipher_data, in->cipher->ctx_size); 71 if (!out->cipher_data) { 72 out->cipher = NULL; 73 return 0; 74 } 75 } 76 77 if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) { 78 if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out)) { 79 out->cipher = NULL; 80 return 0; 81 } 82 } 83 84 return 1; 85} 86 87int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) { 88 EVP_CIPHER_CTX_cleanup(ctx); 89 EVP_CIPHER_CTX_init(ctx); 90 return 1; 91} 92 93int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 94 ENGINE *engine, const uint8_t *key, const uint8_t *iv, 95 int enc) { 96 if (enc == -1) { 97 enc = ctx->encrypt; 98 } else { 99 if (enc) { 100 enc = 1; 101 } 102 ctx->encrypt = enc; 103 } 104 105 if (cipher) { 106 // Ensure a context left from last time is cleared (the previous check 107 // attempted to avoid this if the same ENGINE and EVP_CIPHER could be 108 // used). 109 if (ctx->cipher) { 110 EVP_CIPHER_CTX_cleanup(ctx); 111 // Restore encrypt and flags 112 ctx->encrypt = enc; 113 } 114 115 ctx->cipher = cipher; 116 if (ctx->cipher->ctx_size) { 117 ctx->cipher_data = OPENSSL_malloc(ctx->cipher->ctx_size); 118 if (!ctx->cipher_data) { 119 ctx->cipher = NULL; 120 return 0; 121 } 122 } else { 123 ctx->cipher_data = NULL; 124 } 125 126 ctx->key_len = cipher->key_len; 127 ctx->flags = 0; 128 129 if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) { 130 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) { 131 ctx->cipher = NULL; 132 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INITIALIZATION_ERROR); 133 return 0; 134 } 135 } 136 } else if (!ctx->cipher) { 137 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_NO_CIPHER_SET); 138 return 0; 139 } 140 141 // we assume block size is a power of 2 in *cryptUpdate 142 assert(ctx->cipher->block_size == 1 || ctx->cipher->block_size == 8 || 143 ctx->cipher->block_size == 16); 144 145 if (!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { 146 switch (EVP_CIPHER_CTX_mode(ctx)) { 147 case EVP_CIPH_STREAM_CIPHER: 148 case EVP_CIPH_ECB_MODE: 149 break; 150 151 case EVP_CIPH_CFB_MODE: 152 ctx->num = 0; 153 [[fallthrough]]; 154 155 case EVP_CIPH_CBC_MODE: 156 assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof(ctx->iv)); 157 if (iv) { 158 OPENSSL_memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); 159 } 160 OPENSSL_memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); 161 break; 162 163 case EVP_CIPH_CTR_MODE: 164 case EVP_CIPH_OFB_MODE: 165 ctx->num = 0; 166 // Don't reuse IV for CTR mode 167 if (iv) { 168 OPENSSL_memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx)); 169 } 170 break; 171 172 default: 173 return 0; 174 } 175 } 176 177 if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) { 178 if (!ctx->cipher->init(ctx, key, iv, enc)) { 179 return 0; 180 } 181 } 182 183 ctx->buf_len = 0; 184 ctx->final_used = 0; 185 // Clear the poisoned flag to permit re-use of a CTX that previously had a 186 // failed operation. 187 ctx->poisoned = 0; 188 return 1; 189} 190 191int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 192 ENGINE *impl, const uint8_t *key, const uint8_t *iv) { 193 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1); 194} 195 196int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 197 ENGINE *impl, const uint8_t *key, const uint8_t *iv) { 198 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0); 199} 200 201// block_remainder returns the number of bytes to remove from |len| to get a 202// multiple of |ctx|'s block size. 203static int block_remainder(const EVP_CIPHER_CTX *ctx, int len) { 204 // |block_size| must be a power of two. 205 assert(ctx->cipher->block_size != 0); 206 assert((ctx->cipher->block_size & (ctx->cipher->block_size - 1)) == 0); 207 return len & (ctx->cipher->block_size - 1); 208} 209 210int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len, 211 const uint8_t *in, int in_len) { 212 if (ctx->poisoned) { 213 OPENSSL_PUT_ERROR(CIPHER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 214 return 0; 215 } 216 // If the first call to |cipher| succeeds and the second fails, |ctx| may be 217 // left in an indeterminate state. We set a poison flag on failure to ensure 218 // callers do not continue to use the object in that case. 219 ctx->poisoned = 1; 220 221 // Ciphers that use blocks may write up to |bl| extra bytes. Ensure the output 222 // does not overflow |*out_len|. 223 int bl = ctx->cipher->block_size; 224 if (bl > 1 && in_len > INT_MAX - bl) { 225 OPENSSL_PUT_ERROR(CIPHER, ERR_R_OVERFLOW); 226 return 0; 227 } 228 229 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { 230 int ret = ctx->cipher->cipher(ctx, out, in, in_len); 231 if (ret < 0) { 232 return 0; 233 } else { 234 *out_len = ret; 235 } 236 ctx->poisoned = 0; 237 return 1; 238 } 239 240 if (in_len <= 0) { 241 *out_len = 0; 242 if (in_len == 0) { 243 ctx->poisoned = 0; 244 return 1; 245 } 246 return 0; 247 } 248 249 if (ctx->buf_len == 0 && block_remainder(ctx, in_len) == 0) { 250 if (ctx->cipher->cipher(ctx, out, in, in_len)) { 251 *out_len = in_len; 252 ctx->poisoned = 0; 253 return 1; 254 } else { 255 *out_len = 0; 256 return 0; 257 } 258 } 259 260 int i = ctx->buf_len; 261 assert(bl <= (int)sizeof(ctx->buf)); 262 if (i != 0) { 263 if (bl - i > in_len) { 264 OPENSSL_memcpy(&ctx->buf[i], in, in_len); 265 ctx->buf_len += in_len; 266 *out_len = 0; 267 ctx->poisoned = 0; 268 return 1; 269 } else { 270 int j = bl - i; 271 OPENSSL_memcpy(&ctx->buf[i], in, j); 272 if (!ctx->cipher->cipher(ctx, out, ctx->buf, bl)) { 273 return 0; 274 } 275 in_len -= j; 276 in += j; 277 out += bl; 278 *out_len = bl; 279 } 280 } else { 281 *out_len = 0; 282 } 283 284 i = block_remainder(ctx, in_len); 285 in_len -= i; 286 if (in_len > 0) { 287 if (!ctx->cipher->cipher(ctx, out, in, in_len)) { 288 return 0; 289 } 290 *out_len += in_len; 291 } 292 293 if (i != 0) { 294 OPENSSL_memcpy(ctx->buf, &in[in_len], i); 295 } 296 ctx->buf_len = i; 297 ctx->poisoned = 0; 298 return 1; 299} 300 301int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) { 302 int n; 303 unsigned int i, b, bl; 304 305 if (ctx->poisoned) { 306 OPENSSL_PUT_ERROR(CIPHER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 307 return 0; 308 } 309 310 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { 311 // When EVP_CIPH_FLAG_CUSTOM_CIPHER is set, the return value of |cipher| is 312 // the number of bytes written, or -1 on error. Otherwise the return value 313 // is one on success and zero on error. 314 const int num_bytes = ctx->cipher->cipher(ctx, out, NULL, 0); 315 if (num_bytes < 0) { 316 return 0; 317 } 318 *out_len = num_bytes; 319 goto out; 320 } 321 322 b = ctx->cipher->block_size; 323 assert(b <= sizeof(ctx->buf)); 324 if (b == 1) { 325 *out_len = 0; 326 goto out; 327 } 328 329 bl = ctx->buf_len; 330 if (ctx->flags & EVP_CIPH_NO_PADDING) { 331 if (bl) { 332 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); 333 return 0; 334 } 335 *out_len = 0; 336 goto out; 337 } 338 339 n = b - bl; 340 for (i = bl; i < b; i++) { 341 ctx->buf[i] = n; 342 } 343 if (!ctx->cipher->cipher(ctx, out, ctx->buf, b)) { 344 return 0; 345 } 346 *out_len = b; 347 348out: 349 EVP_Cipher_verify_service_indicator(ctx); 350 return 1; 351} 352 353int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len, 354 const uint8_t *in, int in_len) { 355 if (ctx->poisoned) { 356 OPENSSL_PUT_ERROR(CIPHER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 357 return 0; 358 } 359 360 // Ciphers that use blocks may write up to |bl| extra bytes. Ensure the output 361 // does not overflow |*out_len|. 362 unsigned int b = ctx->cipher->block_size; 363 if (b > 1 && in_len > INT_MAX - (int)b) { 364 OPENSSL_PUT_ERROR(CIPHER, ERR_R_OVERFLOW); 365 return 0; 366 } 367 368 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { 369 int r = ctx->cipher->cipher(ctx, out, in, in_len); 370 if (r < 0) { 371 *out_len = 0; 372 return 0; 373 } else { 374 *out_len = r; 375 } 376 return 1; 377 } 378 379 if (in_len <= 0) { 380 *out_len = 0; 381 return in_len == 0; 382 } 383 384 if (ctx->flags & EVP_CIPH_NO_PADDING) { 385 return EVP_EncryptUpdate(ctx, out, out_len, in, in_len); 386 } 387 388 assert(b <= sizeof(ctx->final)); 389 int fix_len = 0; 390 if (ctx->final_used) { 391 OPENSSL_memcpy(out, ctx->final, b); 392 out += b; 393 fix_len = 1; 394 } 395 396 if (!EVP_EncryptUpdate(ctx, out, out_len, in, in_len)) { 397 return 0; 398 } 399 400 // if we have 'decrypted' a multiple of block size, make sure 401 // we have a copy of this last block 402 if (b > 1 && !ctx->buf_len) { 403 *out_len -= b; 404 ctx->final_used = 1; 405 OPENSSL_memcpy(ctx->final, &out[*out_len], b); 406 } else { 407 ctx->final_used = 0; 408 } 409 410 if (fix_len) { 411 *out_len += b; 412 } 413 414 return 1; 415} 416 417int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *out_len) { 418 int i, n; 419 unsigned int b; 420 *out_len = 0; 421 422 if (ctx->poisoned) { 423 OPENSSL_PUT_ERROR(CIPHER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 424 return 0; 425 } 426 427 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { 428 i = ctx->cipher->cipher(ctx, out, NULL, 0); 429 if (i < 0) { 430 return 0; 431 } else { 432 *out_len = i; 433 } 434 goto out; 435 } 436 437 b = ctx->cipher->block_size; 438 if (ctx->flags & EVP_CIPH_NO_PADDING) { 439 if (ctx->buf_len) { 440 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); 441 return 0; 442 } 443 *out_len = 0; 444 goto out; 445 } 446 447 if (b > 1) { 448 if (ctx->buf_len || !ctx->final_used) { 449 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_WRONG_FINAL_BLOCK_LENGTH); 450 return 0; 451 } 452 assert(b <= sizeof(ctx->final)); 453 454 // The following assumes that the ciphertext has been authenticated. 455 // Otherwise it provides a padding oracle. 456 n = ctx->final[b - 1]; 457 if (n == 0 || n > (int)b) { 458 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT); 459 return 0; 460 } 461 462 for (i = 0; i < n; i++) { 463 if (ctx->final[--b] != n) { 464 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT); 465 return 0; 466 } 467 } 468 469 n = ctx->cipher->block_size - n; 470 for (i = 0; i < n; i++) { 471 out[i] = ctx->final[i]; 472 } 473 *out_len = n; 474 } else { 475 *out_len = 0; 476 } 477 478out: 479 EVP_Cipher_verify_service_indicator(ctx); 480 return 1; 481} 482 483int EVP_Cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in, 484 size_t in_len) { 485 const int ret = ctx->cipher->cipher(ctx, out, in, in_len); 486 487 // |EVP_CIPH_FLAG_CUSTOM_CIPHER| never sets the FIPS indicator via 488 // |EVP_Cipher| because it's complicated whether the operation has completed 489 // or not. E.g. AES-GCM with a non-NULL |in| argument hasn't completed an 490 // operation. Callers should use the |EVP_AEAD| API or, at least, 491 // |EVP_CipherUpdate| etc. 492 // 493 // This call can't be pushed into |EVP_Cipher_verify_service_indicator| 494 // because whether |ret| indicates success or not depends on whether 495 // |EVP_CIPH_FLAG_CUSTOM_CIPHER| is set. (This unreasonable, but matches 496 // OpenSSL.) 497 if (!(ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) && ret) { 498 EVP_Cipher_verify_service_indicator(ctx); 499 } 500 501 return ret; 502} 503 504int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len, 505 const uint8_t *in, int in_len) { 506 if (ctx->encrypt) { 507 return EVP_EncryptUpdate(ctx, out, out_len, in, in_len); 508 } else { 509 return EVP_DecryptUpdate(ctx, out, out_len, in, in_len); 510 } 511} 512 513int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) { 514 if (ctx->encrypt) { 515 return EVP_EncryptFinal_ex(ctx, out, out_len); 516 } else { 517 return EVP_DecryptFinal_ex(ctx, out, out_len); 518 } 519} 520 521const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) { 522 return ctx->cipher; 523} 524 525int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) { return ctx->cipher->nid; } 526 527int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx) { 528 return ctx->encrypt; 529} 530 531unsigned EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) { 532 return ctx->cipher->block_size; 533} 534 535unsigned EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) { 536 return ctx->key_len; 537} 538 539unsigned EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) { 540 if (EVP_CIPHER_mode(ctx->cipher) == EVP_CIPH_GCM_MODE) { 541 int length; 542 int res = EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0, 543 &length); 544 // EVP_CIPHER_CTX_ctrl returning an error should be impossible under this 545 // circumstance. If it somehow did, fallback to the static cipher iv_len. 546 if (res == 1) { 547 return length; 548 } 549 } 550 return ctx->cipher->iv_len; 551} 552 553void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx) { 554 return ctx->app_data; 555} 556 557void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data) { 558 ctx->app_data = data; 559} 560 561uint32_t EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) { 562 return ctx->cipher->flags & ~EVP_CIPH_MODE_MASK; 563} 564 565uint32_t EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *ctx) { 566 return ctx->cipher->flags & EVP_CIPH_MODE_MASK; 567} 568 569int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int command, int arg, void *ptr) { 570 int ret; 571 if (!ctx->cipher) { 572 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_NO_CIPHER_SET); 573 return 0; 574 } 575 576 if (!ctx->cipher->ctrl) { 577 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_CTRL_NOT_IMPLEMENTED); 578 return 0; 579 } 580 581 ret = ctx->cipher->ctrl(ctx, command, arg, ptr); 582 if (ret == -1) { 583 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_CTRL_OPERATION_NOT_IMPLEMENTED); 584 return 0; 585 } 586 587 return ret; 588} 589 590int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad) { 591 if (pad) { 592 ctx->flags &= ~EVP_CIPH_NO_PADDING; 593 } else { 594 ctx->flags |= EVP_CIPH_NO_PADDING; 595 } 596 return 1; 597} 598 599int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, unsigned key_len) { 600 if (c->key_len == key_len) { 601 return 1; 602 } 603 604 if (key_len == 0 || !(c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) { 605 OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_KEY_LENGTH); 606 return 0; 607 } 608 609 c->key_len = key_len; 610 return 1; 611} 612 613int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { return cipher->nid; } 614 615unsigned EVP_CIPHER_block_size(const EVP_CIPHER *cipher) { 616 return cipher->block_size; 617} 618 619unsigned EVP_CIPHER_key_length(const EVP_CIPHER *cipher) { 620 return cipher->key_len; 621} 622 623unsigned EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) { 624 return cipher->iv_len; 625} 626 627uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) { 628 return cipher->flags & ~EVP_CIPH_MODE_MASK; 629} 630 631uint32_t EVP_CIPHER_mode(const EVP_CIPHER *cipher) { 632 return cipher->flags & EVP_CIPH_MODE_MASK; 633} 634 635int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 636 const uint8_t *key, const uint8_t *iv, int enc) { 637 if (cipher) { 638 EVP_CIPHER_CTX_init(ctx); 639 } 640 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc); 641} 642 643int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 644 const uint8_t *key, const uint8_t *iv) { 645 return EVP_CipherInit(ctx, cipher, key, iv, 1); 646} 647 648int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 649 const uint8_t *key, const uint8_t *iv) { 650 return EVP_CipherInit(ctx, cipher, key, iv, 0); 651} 652 653int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) { 654 return EVP_CipherFinal_ex(ctx, out, out_len); 655} 656 657int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) { 658 return EVP_EncryptFinal_ex(ctx, out, out_len); 659} 660 661int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) { 662 return EVP_DecryptFinal_ex(ctx, out, out_len); 663} 664 665int EVP_add_cipher_alias(const char *a, const char *b) { return 1; } 666 667void EVP_CIPHER_CTX_set_flags(const EVP_CIPHER_CTX *ctx, uint32_t flags) {} 668