| 1 | /* Declarations of functions and data types used for SHA1 sum |
| 2 | library functions. |
| 3 | Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2013 Free Software |
| 4 | Foundation, Inc. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 3, or (at your option) any |
| 9 | later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef SHA1_H |
| 20 | # define SHA1_H 1 |
| 21 | |
| 22 | # include <stdio.h> |
| 23 | # include <stdint.h> |
| 24 | |
| 25 | # ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | # endif |
| 28 | |
| 29 | #define SHA1_DIGEST_SIZE 20 |
| 30 | |
| 31 | /* Structure to save state of computation between the single steps. */ |
| 32 | struct sha1_ctx |
| 33 | { |
| 34 | uint32_t A; |
| 35 | uint32_t B; |
| 36 | uint32_t C; |
| 37 | uint32_t D; |
| 38 | uint32_t E; |
| 39 | |
| 40 | uint32_t total[2]; |
| 41 | uint32_t buflen; |
| 42 | uint32_t buffer[32]; |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | /* Initialize structure containing state of computation. */ |
| 47 | extern void sha1_init_ctx (struct sha1_ctx *ctx); |
| 48 | |
| 49 | /* Starting with the result of former calls of this function (or the |
| 50 | initialization function update the context for the next LEN bytes |
| 51 | starting at BUFFER. |
| 52 | It is necessary that LEN is a multiple of 64!!! */ |
| 53 | extern void sha1_process_block (const void *buffer, size_t len, |
| 54 | struct sha1_ctx *ctx); |
| 55 | |
| 56 | /* Starting with the result of former calls of this function (or the |
| 57 | initialization function update the context for the next LEN bytes |
| 58 | starting at BUFFER. |
| 59 | It is NOT required that LEN is a multiple of 64. */ |
| 60 | extern void sha1_process_bytes (const void *buffer, size_t len, |
| 61 | struct sha1_ctx *ctx); |
| 62 | |
| 63 | /* Process the remaining bytes in the buffer and put result from CTX |
| 64 | in first 20 bytes following RESBUF. The result is always in little |
| 65 | endian byte order, so that a byte-wise output yields to the wanted |
| 66 | ASCII representation of the message digest. */ |
| 67 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); |
| 68 | |
| 69 | |
| 70 | /* Put result from CTX in first 20 bytes following RESBUF. The result is |
| 71 | always in little endian byte order, so that a byte-wise output yields |
| 72 | to the wanted ASCII representation of the message digest. */ |
| 73 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); |
| 74 | |
| 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 | # ifdef __cplusplus |
| 88 | } |
| 89 | # endif |
| 90 | |
| 91 | #endif |