diff options
| author | tb <> | 2023-06-15 13:44:38 +0000 |
|---|---|---|
| committer | tb <> | 2023-06-15 13:44:38 +0000 |
| commit | 9df878af0c73c86a47253280c64c30e5087aa3ec (patch) | |
| tree | 81d74136a78908e89ad6cb40d450ea331e6f3c89 | |
| parent | be4d851ec5fb784684c4cb3bc82f3f4079381ebf (diff) | |
| download | openbsd-9df878af0c73c86a47253280c64c30e5087aa3ec.tar.gz openbsd-9df878af0c73c86a47253280c64c30e5087aa3ec.tar.bz2 openbsd-9df878af0c73c86a47253280c64c30e5087aa3ec.zip | |
Rename a few variables and other cosmetics
Rename buf_in into in, buf_out into out, use in_len and out_len for their
lengths, drop a couple of silly casts and remove some empty lines.
ok jsing
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_item.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_item.c b/src/lib/libcrypto/asn1/asn1_item.c index b441ca8f33..fcf45a0fee 100644 --- a/src/lib/libcrypto/asn1/asn1_item.c +++ b/src/lib/libcrypto/asn1/asn1_item.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1_item.c,v 1.11 2023/06/15 13:32:18 tb Exp $ */ | 1 | /* $OpenBSD: asn1_item.c,v 1.12 2023/06/15 13:44:38 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 | * |
| @@ -233,8 +233,8 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 233 | { | 233 | { |
| 234 | const EVP_MD *type; | 234 | const EVP_MD *type; |
| 235 | EVP_PKEY *pkey; | 235 | EVP_PKEY *pkey; |
| 236 | unsigned char *buf_in = NULL, *buf_out = NULL; | 236 | unsigned char *in = NULL, *out = NULL; |
| 237 | size_t buf_out_len = 0; | 237 | size_t out_len = 0; |
| 238 | int in_len = 0; | 238 | int in_len = 0; |
| 239 | int signid, paramtype; | 239 | int signid, paramtype; |
| 240 | int rv = 2; | 240 | int rv = 2; |
| @@ -254,7 +254,7 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 254 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, | 254 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, |
| 255 | signature); | 255 | signature); |
| 256 | if (rv == 1) { | 256 | if (rv == 1) { |
| 257 | buf_out_len = signature->length; | 257 | out_len = signature->length; |
| 258 | goto done; | 258 | goto done; |
| 259 | } | 259 | } |
| 260 | /* Return value meanings: | 260 | /* Return value meanings: |
| @@ -295,33 +295,31 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 295 | 295 | ||
| 296 | } | 296 | } |
| 297 | 297 | ||
| 298 | if ((in_len = ASN1_item_i2d(asn, &buf_in, it)) <= 0) { | 298 | if ((in_len = ASN1_item_i2d(asn, &in, it)) <= 0) { |
| 299 | in_len = 0; | 299 | in_len = 0; |
| 300 | goto err; | 300 | goto err; |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | if (!EVP_DigestSign(ctx, NULL, &buf_out_len, buf_in, in_len)) { | 303 | if (!EVP_DigestSign(ctx, NULL, &out_len, in, in_len)) { |
| 304 | ASN1error(ERR_R_EVP_LIB); | 304 | ASN1error(ERR_R_EVP_LIB); |
| 305 | goto err; | 305 | goto err; |
| 306 | } | 306 | } |
| 307 | 307 | if ((out = calloc(1, out_len)) == NULL) { | |
| 308 | if ((buf_out = calloc(1, buf_out_len)) == NULL) { | ||
| 309 | ASN1error(ERR_R_MALLOC_FAILURE); | 308 | ASN1error(ERR_R_MALLOC_FAILURE); |
| 310 | goto err; | 309 | goto err; |
| 311 | } | 310 | } |
| 312 | 311 | if (!EVP_DigestSign(ctx, out, &out_len, in, in_len)) { | |
| 313 | if (!EVP_DigestSign(ctx, buf_out, &buf_out_len, buf_in, in_len)) { | ||
| 314 | ASN1error(ERR_R_EVP_LIB); | 312 | ASN1error(ERR_R_EVP_LIB); |
| 315 | goto err; | 313 | goto err; |
| 316 | } | 314 | } |
| 317 | 315 | ||
| 318 | if (buf_out_len > INT_MAX) { | 316 | if (out_len > INT_MAX) { |
| 319 | ASN1error(ASN1_R_TOO_LONG); | 317 | ASN1error(ASN1_R_TOO_LONG); |
| 320 | goto err; | 318 | goto err; |
| 321 | } | 319 | } |
| 322 | 320 | ||
| 323 | ASN1_STRING_set0(signature, buf_out, (int)buf_out_len); | 321 | ASN1_STRING_set0(signature, out, out_len); |
| 324 | buf_out = NULL; | 322 | out = NULL; |
| 325 | 323 | ||
| 326 | if (!asn1_abs_set_unused_bits(signature, 0)) { | 324 | if (!asn1_abs_set_unused_bits(signature, 0)) { |
| 327 | ASN1error(ERR_R_ASN1_LIB); | 325 | ASN1error(ERR_R_ASN1_LIB); |
| @@ -329,11 +327,11 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 329 | } | 327 | } |
| 330 | 328 | ||
| 331 | done: | 329 | done: |
| 332 | ret = (int)buf_out_len; | 330 | ret = out_len; |
| 333 | err: | 331 | err: |
| 334 | EVP_MD_CTX_cleanup(ctx); | 332 | EVP_MD_CTX_cleanup(ctx); |
| 335 | freezero(buf_in, in_len); | 333 | freezero(in, in_len); |
| 336 | freezero(buf_out, buf_out_len); | 334 | freezero(out, out_len); |
| 337 | 335 | ||
| 338 | return ret; | 336 | return ret; |
| 339 | } | 337 | } |
| @@ -343,10 +341,10 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 343 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) | 341 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey) |
| 344 | { | 342 | { |
| 345 | EVP_MD_CTX ctx; | 343 | EVP_MD_CTX ctx; |
| 346 | unsigned char *buf_in = NULL; | 344 | unsigned char *in = NULL; |
| 347 | int ret = -1, inl; | ||
| 348 | |||
| 349 | int mdnid, pknid; | 345 | int mdnid, pknid; |
| 346 | int in_len = 0; | ||
| 347 | int ret = -1; | ||
| 350 | 348 | ||
| 351 | if (!pkey) { | 349 | if (!pkey) { |
| 352 | ASN1error(ERR_R_PASSED_NULL_PARAMETER); | 350 | ASN1error(ERR_R_PASSED_NULL_PARAMETER); |
| @@ -402,20 +400,20 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, | |||
| 402 | 400 | ||
| 403 | } | 401 | } |
| 404 | 402 | ||
| 405 | inl = ASN1_item_i2d(asn, &buf_in, it); | 403 | in_len = ASN1_item_i2d(asn, &in, it); |
| 406 | 404 | ||
| 407 | if (buf_in == NULL) { | 405 | if (in == NULL) { |
| 408 | ASN1error(ERR_R_MALLOC_FAILURE); | 406 | ASN1error(ERR_R_MALLOC_FAILURE); |
| 409 | goto err; | 407 | goto err; |
| 410 | } | 408 | } |
| 411 | 409 | ||
| 412 | if (!EVP_DigestVerifyUpdate(&ctx, buf_in, inl)) { | 410 | if (!EVP_DigestVerifyUpdate(&ctx, in, in_len)) { |
| 413 | ASN1error(ERR_R_EVP_LIB); | 411 | ASN1error(ERR_R_EVP_LIB); |
| 414 | ret = 0; | 412 | ret = 0; |
| 415 | goto err; | 413 | goto err; |
| 416 | } | 414 | } |
| 417 | 415 | ||
| 418 | freezero(buf_in, (unsigned int)inl); | 416 | freezero(in, (unsigned int)in_len); |
| 419 | 417 | ||
| 420 | if (EVP_DigestVerifyFinal(&ctx, signature->data, | 418 | if (EVP_DigestVerifyFinal(&ctx, signature->data, |
| 421 | (size_t)signature->length) <= 0) { | 419 | (size_t)signature->length) <= 0) { |
