
1: /* Declarations of functions and data types used for SHA1 sum 2: library functions. 3: Copyright (C) 2007 Free Software Foundation, Inc. 4: 5: This file is part of the GNU Binutils. 6: 7: This program is free software; you can redistribute it and/or modify it 8: under the terms of the GNU General Public License as published by the 9: Free Software Foundation; either version 3, or (at your option) any 10: later version. 11: 12: This program is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with this program; if not, write to the Free Software Foundation, 19: Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 20: 21: #ifndef SHA1_H 22: #define SHA1_H 1 23: 24: #include <stdio.h> 25: #include "bfd_stdint.h" 26: 27: /* Structure to save state of computation between the single steps. */ 28: struct sha1_ctx 29: { 30: uint32_t A; 31: uint32_t B; 32: uint32_t C; 33: uint32_t D; 34: uint32_t E; 35: 36: uint32_t total[2]; 37: uint32_t buflen; 38: uint32_t buffer[32]; 39: }; 40: 41: 42: /* Initialize structure containing state of computation. */ 43: extern void sha1_init_ctx (struct sha1_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! */ 49: extern void sha1_process_block (const void *buffer, size_t len, 50: struct sha1_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. */ 56: extern void sha1_process_bytes (const void *buffer, size_t len, 57: struct sha1_ctx *ctx); 58: 59: /* Process the remaining bytes in the buffer and put result from CTX 60: in first 20 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. 63: 64: IMPORTANT: On some systems it is required that RESBUF be correctly 65: aligned for a 32 bits value. */ 66: extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); 67: 68: /* Put result from CTX in first 20 bytes following RESBUF. The result is 69: always in little endian byte order, so that a byte-wise output yields 70: to the wanted ASCII representation of the message digest. 71: 72: IMPORTANT: On some systems it is required that RESBUF is correctly 73: aligned for a 32 bits value. */ 74: extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); 75: 76: /* Compute SHA1 message digest for bytes read from STREAM. The 77: resulting message digest number will be written into the 20 bytes 78: beginning at RESBLOCK. */ 79: extern int sha1_stream (FILE *stream, void *resblock); 80: 81: /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The 82: result is always in little endian byte order, so that a byte-wise 83: output yields to the wanted ASCII representation of the message 84: digest. */ 85: extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); 86: 87: #endif /* SHA1_H */