diff options
author | tb <> | 2024-01-07 15:21:04 +0000 |
---|---|---|
committer | tb <> | 2024-01-07 15:21:04 +0000 |
commit | 8cb170b1f4aa3af43ce874bfe6b6516969e9d657 (patch) | |
tree | 3be49c5032c18bd9edf4a0103766bcfe0ce295a7 /src | |
parent | e76a414f8808d66dcbcfa39c77bedc8c8f469d5b (diff) | |
download | openbsd-8cb170b1f4aa3af43ce874bfe6b6516969e9d657.tar.gz openbsd-8cb170b1f4aa3af43ce874bfe6b6516969e9d657.tar.bz2 openbsd-8cb170b1f4aa3af43ce874bfe6b6516969e9d657.zip |
Improve EVP_CIPHER_{get,set}_asn1_iv()
Use iv_len for the variables storing the IV length, formerly l and j.
Remove use of the unnecessary variable i and unindent the whole mess.
Some return values are fishy. That will be addressed in subsequent
commits.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/evp/evp_cipher.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c index 81e3f637f5..51bbf70654 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.15 2024/01/04 09:47:54 tb Exp $ */ | 1 | /* $OpenBSD: evp_cipher.c,v 1.16 2024/01/07 15:21:04 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 | * |
@@ -902,22 +902,23 @@ EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) | |||
902 | int | 902 | int |
903 | EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) | 903 | EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) |
904 | { | 904 | { |
905 | int i = 0; | 905 | int iv_len; |
906 | int l; | ||
907 | 906 | ||
908 | if (type != NULL) { | 907 | if (type == NULL) |
909 | l = EVP_CIPHER_CTX_iv_length(ctx); | 908 | return 0; |
910 | if (l < 0 || l > sizeof(ctx->oiv) || l > sizeof(ctx->iv)) { | 909 | |
911 | EVPerror(EVP_R_IV_TOO_LARGE); | 910 | iv_len = EVP_CIPHER_CTX_iv_length(ctx); |
912 | return 0; | 911 | if (iv_len < 0 || iv_len > sizeof(ctx->oiv) || iv_len > sizeof(ctx->iv)) { |
913 | } | 912 | EVPerror(EVP_R_IV_TOO_LARGE); |
914 | i = ASN1_TYPE_get_octetstring(type, ctx->oiv, l); | 913 | return 0; /* XXX */ |
915 | if (i != l) | ||
916 | return (-1); | ||
917 | else if (i > 0) | ||
918 | memcpy(ctx->iv, ctx->oiv, l); | ||
919 | } | 914 | } |
920 | return (i); | 915 | if (ASN1_TYPE_get_octetstring(type, ctx->oiv, iv_len) != iv_len) |
916 | return -1; | ||
917 | |||
918 | if (iv_len > 0) | ||
919 | memcpy(ctx->iv, ctx->oiv, iv_len); | ||
920 | |||
921 | return iv_len; | ||
921 | } | 922 | } |
922 | 923 | ||
923 | int | 924 | int |
@@ -935,18 +936,18 @@ EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) | |||
935 | int | 936 | int |
936 | EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) | 937 | EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) |
937 | { | 938 | { |
938 | int i = 0; | 939 | int iv_len; |
939 | int j; | ||
940 | 940 | ||
941 | if (type != NULL) { | 941 | if (type == NULL) |
942 | j = EVP_CIPHER_CTX_iv_length(ctx); | 942 | return 0; |
943 | if (j < 0 || j > sizeof(ctx->oiv)) { | 943 | |
944 | EVPerror(EVP_R_IV_TOO_LARGE); | 944 | iv_len = EVP_CIPHER_CTX_iv_length(ctx); |
945 | return 0; | 945 | if (iv_len < 0 || iv_len > sizeof(ctx->oiv)) { |
946 | } | 946 | EVPerror(EVP_R_IV_TOO_LARGE); |
947 | i = ASN1_TYPE_set_octetstring(type, ctx->oiv, j); | 947 | return 0; |
948 | } | 948 | } |
949 | return (i); | 949 | |
950 | return ASN1_TYPE_set_octetstring(type, ctx->oiv, iv_len); | ||
950 | } | 951 | } |
951 | 952 | ||
952 | int | 953 | int |