/
niceSOFT
/
nettle
Обзор
Документация
Войти
/
niceSOFT
/
nettle
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sha-example.c
41 строка
697 B
Niels Möller
Update sha-example.c.
24 июн 2025, 19:40
24 июн 2025, 19:40
fa7887c
Код
Авторство
О чём код?
#include <stdio.h> #include <stdlib.h> #include <nettle/sha2.h> #define BUF_SIZE 1000 static void display_hex(unsigned length, uint8_t *data) { unsigned i; for (i = 0; i<length; i++) printf("%02x ", data[i]); printf("\n"); } int main(int argc, char **argv) { struct sha256_ctx ctx; uint8_t buffer[BUF_SIZE]; uint8_t digest[SHA256_DIGEST_SIZE]; sha256_init(&ctx); for (;;) { int done = fread(buffer, 1, sizeof(buffer), stdin); sha256_update(&ctx, done, buffer); if (done < sizeof(buffer)) break; } if (ferror(stdin)) return EXIT_FAILURE; sha256_digest(&ctx, digest); display_hex(SHA256_DIGEST_SIZE, digest); return EXIT_SUCCESS; }