OpenSSL:EVP_DigestFinal_ex 的输出大小是否可以大于摘要大小?

OpenSSL: can output size of EVP_DigestFinal_ex be greater than the digest size?

OpenSSL EVP_DigestFinal_ex 具有以下文档:

"EVP_DigestFinal_ex() retrieves the digest value from ctx and places it in md. If the s parameter is not NULL then the number of bytes of data written (i.e. the length of the digest) will be written to the integer at s, at most EVP_MAX_MD_SIZE bytes will be written."

签名:

int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);

是否存在摘要长度大于摘要输出大小但小于 EVP_MAX_MD_SIZE 的情况。即对于 SHA-1 摘要,我得到一个大于 20 字节的输出?

来自 OpenSSL 的相关源代码crypto/evp/digest.c:

    OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
    ret = ctx->digest->final(ctx, md);
    if (size != NULL)
       *size = ctx->digest->md_size;

其中 size 是您想要的输出摘要大小,digest 是一个 const 结构如果 SHA1 在 crypto/evp/m_sha1.c:

中定义
static const EVP_MD sha1_md = {
     NID_sha1,
     NID_sha1WithRSAEncryption,
     SHA_DIGEST_LENGTH

md_size 是这个结构的第三个成员,所以它总是 SHA_DIGEST_LENGTHequal to 20