diff options
| author | tb <> | 2024-01-02 18:21:02 +0000 |
|---|---|---|
| committer | tb <> | 2024-01-02 18:21:02 +0000 |
| commit | dca01f913509b1c404d3ab5b43beecae8386dc4a (patch) | |
| tree | ba3ad19f03f5a5c99d83c908b29a22e8b4f08eb1 /src | |
| parent | 9812b741aad62722b8886907a81243c5c70ae750 (diff) | |
| download | openbsd-dca01f913509b1c404d3ab5b43beecae8386dc4a.tar.gz openbsd-dca01f913509b1c404d3ab5b43beecae8386dc4a.tar.bz2 openbsd-dca01f913509b1c404d3ab5b43beecae8386dc4a.zip | |
Consistently use ctx for an EVP_CIPHER_CTX
Not c (which is most of the time an EVP_CIPHER) or a (?!).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/evp/evp_cipher.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c index 751360cd7b..b9bc15e371 100644 --- a/src/lib/libcrypto/evp/evp_cipher.c +++ b/src/lib/libcrypto/evp/evp_cipher.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: evp_cipher.c,v 1.3 2023/12/29 06:56:38 tb Exp $ */ | 1 | /* $OpenBSD: evp_cipher.c,v 1.4 2024/01/02 18:21:02 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 | * |
| @@ -618,40 +618,40 @@ EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | |||
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | int | 620 | int |
| 621 | EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *a) | 621 | EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) |
| 622 | { | 622 | { |
| 623 | return EVP_CIPHER_CTX_cleanup(a); | 623 | return EVP_CIPHER_CTX_cleanup(ctx); |
| 624 | } | 624 | } |
| 625 | 625 | ||
| 626 | int | 626 | int |
| 627 | EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | 627 | EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx) |
| 628 | { | 628 | { |
| 629 | if (c->cipher != NULL) { | 629 | if (ctx->cipher != NULL) { |
| 630 | /* XXX - Avoid leaks, so ignore return value of cleanup()... */ | 630 | /* XXX - Avoid leaks, so ignore return value of cleanup()... */ |
| 631 | if (c->cipher->cleanup != NULL) | 631 | if (ctx->cipher->cleanup != NULL) |
| 632 | c->cipher->cleanup(c); | 632 | ctx->cipher->cleanup(ctx); |
| 633 | if (c->cipher_data != NULL) | 633 | if (ctx->cipher_data != NULL) |
| 634 | explicit_bzero(c->cipher_data, c->cipher->ctx_size); | 634 | explicit_bzero(ctx->cipher_data, ctx->cipher->ctx_size); |
| 635 | } | 635 | } |
| 636 | 636 | ||
| 637 | /* XXX - store size of cipher_data so we can always freezero(). */ | 637 | /* XXX - store size of cipher_data so we can always freezero(). */ |
| 638 | free(c->cipher_data); | 638 | free(ctx->cipher_data); |
| 639 | 639 | ||
| 640 | explicit_bzero(c, sizeof(EVP_CIPHER_CTX)); | 640 | explicit_bzero(ctx, sizeof(EVP_CIPHER_CTX)); |
| 641 | 641 | ||
| 642 | return 1; | 642 | return 1; |
| 643 | } | 643 | } |
| 644 | 644 | ||
| 645 | int | 645 | int |
| 646 | EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen) | 646 | EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *ctx, int keylen) |
| 647 | { | 647 | { |
| 648 | if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH) | 648 | if (ctx->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH) |
| 649 | return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, | 649 | return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_KEY_LENGTH, |
| 650 | keylen, NULL); | 650 | keylen, NULL); |
| 651 | if (c->key_len == keylen) | 651 | if (ctx->key_len == keylen) |
| 652 | return 1; | 652 | return 1; |
| 653 | if (keylen > 0 && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) { | 653 | if (keylen > 0 && (ctx->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) { |
| 654 | c->key_len = keylen; | 654 | ctx->key_len = keylen; |
| 655 | return 1; | 655 | return 1; |
| 656 | } | 656 | } |
| 657 | EVPerror(EVP_R_INVALID_KEY_LENGTH); | 657 | EVPerror(EVP_R_INVALID_KEY_LENGTH); |
| @@ -740,67 +740,67 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) | |||
| 740 | } | 740 | } |
| 741 | 741 | ||
| 742 | int | 742 | int |
| 743 | EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | 743 | EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) |
| 744 | { | 744 | { |
| 745 | int ret; | 745 | int ret; |
| 746 | 746 | ||
| 747 | if (c->cipher->set_asn1_parameters != NULL) | 747 | if (ctx->cipher->set_asn1_parameters != NULL) |
| 748 | ret = c->cipher->set_asn1_parameters(c, type); | 748 | ret = ctx->cipher->set_asn1_parameters(ctx, type); |
| 749 | else if (c->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) | 749 | else if (ctx->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) |
| 750 | ret = EVP_CIPHER_set_asn1_iv(c, type); | 750 | ret = EVP_CIPHER_set_asn1_iv(ctx, type); |
| 751 | else | 751 | else |
| 752 | ret = -1; | 752 | ret = -1; |
| 753 | return (ret); | 753 | return (ret); |
| 754 | } | 754 | } |
| 755 | 755 | ||
| 756 | int | 756 | int |
| 757 | EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | 757 | EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) |
| 758 | { | 758 | { |
| 759 | int ret; | 759 | int ret; |
| 760 | 760 | ||
| 761 | if (c->cipher->get_asn1_parameters != NULL) | 761 | if (ctx->cipher->get_asn1_parameters != NULL) |
| 762 | ret = c->cipher->get_asn1_parameters(c, type); | 762 | ret = ctx->cipher->get_asn1_parameters(ctx, type); |
| 763 | else if (c->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) | 763 | else if (ctx->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) |
| 764 | ret = EVP_CIPHER_get_asn1_iv(c, type); | 764 | ret = EVP_CIPHER_get_asn1_iv(ctx, type); |
| 765 | else | 765 | else |
| 766 | ret = -1; | 766 | ret = -1; |
| 767 | return (ret); | 767 | return (ret); |
| 768 | } | 768 | } |
| 769 | 769 | ||
| 770 | int | 770 | int |
| 771 | EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | 771 | EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) |
| 772 | { | 772 | { |
| 773 | int i = 0; | 773 | int i = 0; |
| 774 | int l; | 774 | int l; |
| 775 | 775 | ||
| 776 | if (type != NULL) { | 776 | if (type != NULL) { |
| 777 | l = EVP_CIPHER_CTX_iv_length(c); | 777 | l = EVP_CIPHER_CTX_iv_length(ctx); |
| 778 | if (l < 0 || l > sizeof(c->iv)) { | 778 | if (l < 0 || l > sizeof(ctx->iv)) { |
| 779 | EVPerror(EVP_R_IV_TOO_LARGE); | 779 | EVPerror(EVP_R_IV_TOO_LARGE); |
| 780 | return 0; | 780 | return 0; |
| 781 | } | 781 | } |
| 782 | i = ASN1_TYPE_get_octetstring(type, c->oiv, l); | 782 | i = ASN1_TYPE_get_octetstring(type, ctx->oiv, l); |
| 783 | if (i != l) | 783 | if (i != l) |
| 784 | return (-1); | 784 | return (-1); |
| 785 | else if (i > 0) | 785 | else if (i > 0) |
| 786 | memcpy(c->iv, c->oiv, l); | 786 | memcpy(ctx->iv, ctx->oiv, l); |
| 787 | } | 787 | } |
| 788 | return (i); | 788 | return (i); |
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | int | 791 | int |
| 792 | EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | 792 | EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) |
| 793 | { | 793 | { |
| 794 | int i = 0; | 794 | int i = 0; |
| 795 | int j; | 795 | int j; |
| 796 | 796 | ||
| 797 | if (type != NULL) { | 797 | if (type != NULL) { |
| 798 | j = EVP_CIPHER_CTX_iv_length(c); | 798 | j = EVP_CIPHER_CTX_iv_length(ctx); |
| 799 | if (j < 0 || j > sizeof(c->iv)) { | 799 | if (j < 0 || j > sizeof(ctx->iv)) { |
| 800 | EVPerror(EVP_R_IV_TOO_LARGE); | 800 | EVPerror(EVP_R_IV_TOO_LARGE); |
| 801 | return 0; | 801 | return 0; |
| 802 | } | 802 | } |
| 803 | i = ASN1_TYPE_set_octetstring(type, c->oiv, j); | 803 | i = ASN1_TYPE_set_octetstring(type, ctx->oiv, j); |
| 804 | } | 804 | } |
| 805 | return (i); | 805 | return (i); |
| 806 | } | 806 | } |
