3 * The SHA256 hash function
5 * (c) 2020 Mark Wooding
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Runlisp, a tool for invoking Common Lisp scripts.
12 * Runlisp is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 3 of the License, or (at your
15 * option) any later version.
17 * Runlisp is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License
23 * along with Runlisp. If not, see <https://www.gnu.org/licenses/>.
33 /*----- Header files ------------------------------------------------------*/
37 /*----- Data types --------------------------------------------------------*/
39 /* Select a suitable type for 32-bit words. */
40 #if UINT_MAX >= 0xffffffff
43 typedef unsigned long u32;
46 #define SHA256_BLKSZ 64 /* input block size in bytes */
47 #define SHA256_HASHSZ 32 /* output hash size in bytes */
50 unsigned n; /* number of live bytes in buffer */
51 size_t nblk; /* number of blocks hashed so far */
52 u32 a[8]; /* hash state */
53 unsigned char buf[SHA256_BLKSZ]; /* input buffer */
56 /*----- Functions provided ------------------------------------------------*/
58 extern void sha256_init(struct sha256_state */**/);
59 /* Initialize the hash state S. */
61 extern void sha256_hash(struct sha256_state */*s*/,
62 const void */*m*/, size_t /*sz*/);
63 /* Append SZ bytes of data starting at M to the hash state S. */
65 extern void sha256_done(struct sha256_state */*s*/, unsigned char */*h*/);
66 /* Write the final hash of state S to buffer H. */
68 /*----- That's all, folks -------------------------------------------------*/