/* Provenance: openssl/openssl X509_issuer_and_serial_hash (fixed). * repo: openssl/openssl * commit: 122a19ab48091c657f7cb1fb3af9fc07bd557bbf * parent: c8c6e7438c03b2fc24e7ead460feeaef04911fb4 * commit_url: https://github.com/openssl/openssl/commit/122a19ab48091c657f7cb1fb3af9fc07bd557bbf * cve: CVE-2021-23841 * license: OpenSSL License * function: X509_issuer_and_serial_hash * relpath: crypto/x509/x509_cmp.c */ unsigned long X509_issuer_and_serial_hash(X509 *a) { unsigned long ret = 0; EVP_MD_CTX *ctx = EVP_MD_CTX_new(); unsigned char md[16]; char *f; if (ctx == NULL) goto err; f = X509_NAME_oneline(a->cert_info.issuer, NULL, 0); if (f == NULL) goto err; if (!EVP_DigestInit_ex(ctx, EVP_md5(), NULL)) goto err; if (!EVP_DigestUpdate(ctx, (unsigned char *)f, strlen(f))) goto err; OPENSSL_free(f); if (!EVP_DigestUpdate (ctx, (unsigned char *)a->cert_info.serialNumber.data, (unsigned long)a->cert_info.serialNumber.length)) goto err; if (!EVP_DigestFinal_ex(ctx, &(md[0]), NULL)) goto err; ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) | ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L) ) & 0xffffffffL; err: EVP_MD_CTX_free(ctx); return ret; }