1/* Declarations of functions and data types used for SHA256 and SHA224 sum 2 library functions. 3 Copyright (C) 2005, 2006, 2008, 2009, 2010 Free Software Foundation, Inc. 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18#ifndef SHA256_H 19# define SHA256_H 1 20 21# include <stdio.h> 22# include <stdint.h> 23 24# ifdef __cplusplus 25extern "C" { 26# endif 27 28/* Structure to save state of computation between the single steps. */ 29struct sha256_ctx 30{ 31 uint32_t state[8]; 32 33 uint32_t total[2]; 34 size_t buflen; 35 uint32_t buffer[32]; 36}; 37 38enum { SHA224_DIGEST_SIZE = 224 / 8 }; 39enum { SHA256_DIGEST_SIZE = 256 / 8 }; 40 41/* Initialize structure containing state of computation. */ 42extern void sha256_init_ctx (struct sha256_ctx *ctx); 43extern void sha224_init_ctx (struct sha256_ctx *ctx); 44 45/* Starting with the result of former calls of this function (or the 46 initialization function update the context for the next LEN bytes 47 starting at BUFFER. 48 It is necessary that LEN is a multiple of 64!!! */ 49extern void sha256_process_block (const void *buffer, size_t len, 50 struct sha256_ctx *ctx); 51 52/* Starting with the result of former calls of this function (or the 53 initialization function update the context for the next LEN bytes 54 starting at BUFFER. 55 It is NOT required that LEN is a multiple of 64. */ 56extern void sha256_process_bytes (const void *buffer, size_t len, 57 struct sha256_ctx *ctx); 58 59/* Process the remaining bytes in the buffer and put result from CTX 60 in first 32 (28) bytes following RESBUF. The result is always in little 61 endian byte order, so that a byte-wise output yields to the wanted 62 ASCII representation of the message digest. */ 63extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf); 64extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf); 65 66 67/* Put result from CTX in first 32 (28) bytes following RESBUF. The result is 68 always in little endian byte order, so that a byte-wise output yields 69 to the wanted ASCII representation of the message digest. */ 70extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf); 71extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf); 72 73 74/* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The 75 resulting message digest number will be written into the 32 (28) bytes 76 beginning at RESBLOCK. */ 77extern int sha256_stream (FILE *stream, void *resblock); 78extern int sha224_stream (FILE *stream, void *resblock); 79 80/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The 81 result is always in little endian byte order, so that a byte-wise 82 output yields to the wanted ASCII representation of the message 83 digest. */ 84extern void *sha256_buffer (const char *buffer, size_t len, void *resblock); 85extern void *sha224_buffer (const char *buffer, size_t len, void *resblock); 86 87# ifdef __cplusplus 88} 89# endif 90 91#endif 92