代码

main.c
#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/err.h>
void tDigest(){
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
EVP_MD_CTX *mdctx;
mdctx = EVP_MD_CTX_new();
char msg1[] = "20201303";
char msg2[] = "ZHANGyibo";
EVP_MD_CTX_init(mdctx);
EVP_DigestInit_ex(mdctx, EVP_sm3(), NULL);
EVP_DigestUpdate(mdctx, msg1, strlen(msg1));
EVP_DigestUpdate(mdctx, msg2, strlen(msg2));
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
EVP_MD_CTX_destroy(mdctx);

printf("Debug:Message1%s and Message2%s digest to:\n",msg1, msg2);
for(int i = 0; i<md_len; i++){

printf("0x%02x ", md_value[i]);
}
printf("\n");
}

int main(){

OpenSSL_add_all_algorithms();
tDigest();
return 0;
}
sm3.c
#include<stdio.h>
#include<string.h>
#include<openssl/evp.h>
#include<openssl/err.h>

void tDigest(){
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
EVP_MD_CTX *mdctx;
mdctx = EVP_MD_CTX_new();
char msg1[] = "20211122";
char msg2[] = "TANG_jiahao";

EVP_MD_CTX_init(mdctx);
EVP_DigestInit_ex(mdctx, EVP_sm3(),NULL);
EVP_DigestUpdate(mdctx, msg1, strlen(msg1));
EVP_DigestUpdate(mdctx, msg2, strlen(msg2));
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
EVP_MD_CTX_destroy(mdctx);

printf("Debug:Message1%s and Message2%s digest to:\n",msg1, msg2);
for(int i= 0; i<md_len; i++){

printf("0x%02x ", md_value[i]);
}
printf("\n");
}

int main(){
OpenSSL_add_all_algorithms();
tDigest();
return 0;
}

posted @ 2023-10-19 23:03  天问—九章  阅读(7)  评论(0编辑  收藏  举报