From: Niels Möller Date: Tue, 24 Jun 2025 16:40:12 +0000 (+0200) Subject: Update sha-example.c. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa7887c3b027510f2d8f1fb90359b25386872bb3;p=thirdparty%2Fnettle.git Update sha-example.c. --- diff --git a/ChangeLog b/ChangeLog index e4634851..5b84b5f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2025-06-24 Niels Möller + + * sha-example.c (main): Update to use sha256 rather than sha1, and + new use sha256_digest interface. + 2025-06-23 Niels Möller * blowfish-bcrypt.c (ibcrypt): Simplify salt logic, eliminating a diff --git a/sha-example.c b/sha-example.c index dcd889c7..eb024e6d 100644 --- a/sha-example.c +++ b/sha-example.c @@ -1,7 +1,7 @@ #include #include -#include +#include #define BUF_SIZE 1000 @@ -19,23 +19,23 @@ display_hex(unsigned length, uint8_t *data) int main(int argc, char **argv) { - struct sha1_ctx ctx; + struct sha256_ctx ctx; uint8_t buffer[BUF_SIZE]; - uint8_t digest[SHA1_DIGEST_SIZE]; + uint8_t digest[SHA256_DIGEST_SIZE]; - sha1_init(&ctx); + sha256_init(&ctx); for (;;) { int done = fread(buffer, 1, sizeof(buffer), stdin); - sha1_update(&ctx, done, buffer); + sha256_update(&ctx, done, buffer); if (done < sizeof(buffer)) break; } if (ferror(stdin)) return EXIT_FAILURE; - sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest); + sha256_digest(&ctx, digest); - display_hex(SHA1_DIGEST_SIZE, digest); + display_hex(SHA256_DIGEST_SIZE, digest); return EXIT_SUCCESS; }