Back to index

nagios-plugins  1.4.16
sha1.h
Go to the documentation of this file.
00001 /* Declarations of functions and data types used for SHA1 sum
00002    library functions.
00003    Copyright (C) 2000, 2001, 2003, 2005, 2006, 2008, 2009, 2010 Free Software
00004    Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published by the
00008    Free Software Foundation; either version 3, or (at your option) any
00009    later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software Foundation,
00018    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00019 
00020 #ifndef SHA1_H
00021 # define SHA1_H 1
00022 
00023 # include <stdio.h>
00024 # include <stdint.h>
00025 
00026 # ifdef __cplusplus
00027 extern "C" {
00028 # endif
00029 
00030 #define SHA1_DIGEST_SIZE 20
00031 
00032 /* Structure to save state of computation between the single steps.  */
00033 struct sha1_ctx
00034 {
00035   uint32_t A;
00036   uint32_t B;
00037   uint32_t C;
00038   uint32_t D;
00039   uint32_t E;
00040 
00041   uint32_t total[2];
00042   uint32_t buflen;
00043   uint32_t buffer[32];
00044 };
00045 
00046 
00047 /* Initialize structure containing state of computation. */
00048 extern void sha1_init_ctx (struct sha1_ctx *ctx);
00049 
00050 /* Starting with the result of former calls of this function (or the
00051    initialization function update the context for the next LEN bytes
00052    starting at BUFFER.
00053    It is necessary that LEN is a multiple of 64!!! */
00054 extern void sha1_process_block (const void *buffer, size_t len,
00055                                 struct sha1_ctx *ctx);
00056 
00057 /* Starting with the result of former calls of this function (or the
00058    initialization function update the context for the next LEN bytes
00059    starting at BUFFER.
00060    It is NOT required that LEN is a multiple of 64.  */
00061 extern void sha1_process_bytes (const void *buffer, size_t len,
00062                                 struct sha1_ctx *ctx);
00063 
00064 /* Process the remaining bytes in the buffer and put result from CTX
00065    in first 20 bytes following RESBUF.  The result is always in little
00066    endian byte order, so that a byte-wise output yields to the wanted
00067    ASCII representation of the message digest.  */
00068 extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
00069 
00070 
00071 /* Put result from CTX in first 20 bytes following RESBUF.  The result is
00072    always in little endian byte order, so that a byte-wise output yields
00073    to the wanted ASCII representation of the message digest.  */
00074 extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
00075 
00076 
00077 /* Compute SHA1 message digest for bytes read from STREAM.  The
00078    resulting message digest number will be written into the 20 bytes
00079    beginning at RESBLOCK.  */
00080 extern int sha1_stream (FILE *stream, void *resblock);
00081 
00082 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
00083    result is always in little endian byte order, so that a byte-wise
00084    output yields to the wanted ASCII representation of the message
00085    digest.  */
00086 extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
00087 
00088 # ifdef __cplusplus
00089 }
00090 # endif
00091 
00092 #endif