-/* $OpenBSD: asn1_item.c,v 1.11 2023/06/15 13:32:18 tb Exp $ */
+/* $OpenBSD: asn1_item.c,v 1.12 2023/06/15 13:44:38 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
{
const EVP_MD *type;
EVP_PKEY *pkey;
- unsigned char *buf_in = NULL, *buf_out = NULL;
- size_t buf_out_len = 0;
+ unsigned char *in = NULL, *out = NULL;
+ size_t out_len = 0;
int in_len = 0;
int signid, paramtype;
int rv = 2;
rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2,
signature);
if (rv == 1) {
- buf_out_len = signature->length;
+ out_len = signature->length;
goto done;
}
/* Return value meanings:
}
- if ((in_len = ASN1_item_i2d(asn, &buf_in, it)) <= 0) {
+ if ((in_len = ASN1_item_i2d(asn, &in, it)) <= 0) {
in_len = 0;
goto err;
}
- if (!EVP_DigestSign(ctx, NULL, &buf_out_len, buf_in, in_len)) {
+ if (!EVP_DigestSign(ctx, NULL, &out_len, in, in_len)) {
ASN1error(ERR_R_EVP_LIB);
goto err;
}
-
- if ((buf_out = calloc(1, buf_out_len)) == NULL) {
+ if ((out = calloc(1, out_len)) == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
-
- if (!EVP_DigestSign(ctx, buf_out, &buf_out_len, buf_in, in_len)) {
+ if (!EVP_DigestSign(ctx, out, &out_len, in, in_len)) {
ASN1error(ERR_R_EVP_LIB);
goto err;
}
- if (buf_out_len > INT_MAX) {
+ if (out_len > INT_MAX) {
ASN1error(ASN1_R_TOO_LONG);
goto err;
}
- ASN1_STRING_set0(signature, buf_out, (int)buf_out_len);
- buf_out = NULL;
+ ASN1_STRING_set0(signature, out, out_len);
+ out = NULL;
if (!asn1_abs_set_unused_bits(signature, 0)) {
ASN1error(ERR_R_ASN1_LIB);
}
done:
- ret = (int)buf_out_len;
+ ret = out_len;
err:
EVP_MD_CTX_cleanup(ctx);
- freezero(buf_in, in_len);
- freezero(buf_out, buf_out_len);
+ freezero(in, in_len);
+ freezero(out, out_len);
return ret;
}
ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
- unsigned char *buf_in = NULL;
- int ret = -1, inl;
-
+ unsigned char *in = NULL;
int mdnid, pknid;
+ int in_len = 0;
+ int ret = -1;
if (!pkey) {
ASN1error(ERR_R_PASSED_NULL_PARAMETER);
}
- inl = ASN1_item_i2d(asn, &buf_in, it);
+ in_len = ASN1_item_i2d(asn, &in, it);
- if (buf_in == NULL) {
+ if (in == NULL) {
ASN1error(ERR_R_MALLOC_FAILURE);
goto err;
}
- if (!EVP_DigestVerifyUpdate(&ctx, buf_in, inl)) {
+ if (!EVP_DigestVerifyUpdate(&ctx, in, in_len)) {
ASN1error(ERR_R_EVP_LIB);
ret = 0;
goto err;
}
- freezero(buf_in, (unsigned int)inl);
+ freezero(in, (unsigned int)in_len);
if (EVP_DigestVerifyFinal(&ctx, signature->data,
(size_t)signature->length) <= 0) {