前言
上一篇结尾说到效率问题,针对EVP的实现,我们来研究下具体优劣情况
一、EVP-sha256实现
仔细看看下面的代码就会发现一个规律,这种使用API接口的模式在整个openssl都能看到很多影子。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#define LEN 1024*1024
/* 做个数组是正确的abc字串sha256 hash,用于下面的验证 */
unsigned char app_b1[SHA256_DIGEST_LENGTH] = {
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
};</