24 lines
No EOL
581 B
C
24 lines
No EOL
581 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <mbedtls/md.h>
|
|
|
|
void show_sha256(char *buf, size_t len) {
|
|
uint8_t output[32];
|
|
memset(output, 0, sizeof(output));
|
|
|
|
mbedtls_md_context_t ctx;
|
|
mbedtls_md_init(&ctx);
|
|
mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 0);
|
|
mbedtls_md_starts(&ctx);
|
|
mbedtls_md_update(&ctx, (const unsigned char *)buf, len);
|
|
mbedtls_md_finish(&ctx, output);
|
|
mbedtls_md_free(&ctx);
|
|
|
|
for (int i = 0; i < sizeof(output); i++) {
|
|
printf("%02x", output[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
return;
|
|
} |