我想知道如何动态获取所有支持的摘要算法的EVP_MD*
列表。
目前我正在使用静态数组
const EVP_MD* aHashAlgos[] = { EVP_sha512(), EVP_sha384(), EVP_sha256() ... }
谢谢!
答案 0 :(得分:4)
以下将列出所有已注册的摘要方法。
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <stdio.h>
void my_callback(const OBJ_NAME *obj, void *arg)
{
printf("Digest: %s\n", obj->name);
}
int main(int argc, char *argv)
{
void *my_arg;
OpenSSL_add_all_digests(); //make sure they're loaded
my_arg = NULL;
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, my_callback, my_arg);
}
回调接收OBJ_NAME类型的对象:
typedef struct obj_name_st {
int type;
int alias;
const char *name;
const char *data;
} OBJ_NAME;
您可以通过EVP_MD*
查找关联的EVP_get_digestbyname()
。
这种方法可以找到许多你可能不想要的东西:
$ ./a.out
Digest: ripemd160WithRSA
Digest: ssl2-md5
Digest: sha384
Digest: sha224
Digest: SHA224
Digest: md4
Digest: sha512
Digest: RSA-SHA256
Digest: DSA-SHA
Digest: sha1WithRSAEncryption
Digest: MD5
Digest: MD4
Digest: ssl3-sha1
Digest: ripemd160
Digest: sha
Digest: SHA384
Digest: SHA1
Digest: ssl3-md5
Digest: sha256
Digest: sha384WithRSAEncryption
Digest: SHA512
Digest: DSA-SHA1-old
Digest: dsaWithSHA1
Digest: ecdsa-with-SHA1
Digest: whirlpool
Digest: RSA-RIPEMD160
Digest: rmd160
Digest: RIPEMD160
Digest: RSA-SHA1-2
Digest: RSA-SHA1
Digest: dsaWithSHA
Digest: md5WithRSAEncryption
Digest: DSS1
Digest: RSA-MD5
Digest: dsaEncryption
Digest: ripemd
Digest: md4WithRSAEncryption
Digest: DSA
Digest: sha512WithRSAEncryption
Digest: SHA
Digest: dss1
Digest: RSA-SHA224
Digest: RSA-SHA512
Digest: SHA256
Digest: md5
Digest: RSA-SHA384
Digest: sha1
Digest: sha224WithRSAEncryption
Digest: RSA-SHA
Digest: shaWithRSAEncryption
Digest: sha256WithRSAEncryption
Digest: DSA-SHA1
Digest: RSA-MD4