exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / sha1.h
blob940163eb528a39ef22cc1c6303e1a2447f9ebbda
1 /* Declarations of functions and data types used for SHA1 sum
2 library functions.
3 Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2024 Free Software
4 Foundation, Inc.
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 This file 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 #ifndef SHA1_H
20 # define SHA1_H 1
22 /* This file uses HAVE_OPENSSL_SHA1. */
23 # if !_GL_CONFIG_H_INCLUDED
24 # error "Please include config.h first."
25 # endif
27 # include <stdio.h>
28 # include <stdint.h>
30 # if HAVE_OPENSSL_SHA1
31 # ifndef OPENSSL_API_COMPAT
32 # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */
33 # endif
34 /* If <openssl/macros.h> would give a compile-time error, don't use OpenSSL. */
35 # include <openssl/opensslv.h>
36 # if OPENSSL_VERSION_MAJOR >= 3
37 # include <openssl/configuration.h>
38 # if (OPENSSL_CONFIGURED_API \
39 < (OPENSSL_API_COMPAT < 0x900000L ? OPENSSL_API_COMPAT : \
40 ((OPENSSL_API_COMPAT >> 28) & 0xF) * 10000 \
41 + ((OPENSSL_API_COMPAT >> 20) & 0xFF) * 100 \
42 + ((OPENSSL_API_COMPAT >> 12) & 0xFF)))
43 # undef HAVE_OPENSSL_SHA1
44 # endif
45 # endif
46 # if HAVE_OPENSSL_SHA1
47 # include <openssl/sha.h>
48 # endif
49 # endif
51 # ifdef __cplusplus
52 extern "C" {
53 # endif
55 # define SHA1_DIGEST_SIZE 20
57 # if HAVE_OPENSSL_SHA1
58 # define GL_OPENSSL_NAME 1
59 # include "gl_openssl.h"
60 # else
61 /* Structure to save state of computation between the single steps. */
62 struct sha1_ctx
64 uint32_t A;
65 uint32_t B;
66 uint32_t C;
67 uint32_t D;
68 uint32_t E;
70 uint32_t total[2];
71 uint32_t buflen; /* ≥ 0, ≤ 128 */
72 uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
75 /* Initialize structure containing state of computation. */
76 extern void sha1_init_ctx (struct sha1_ctx *ctx);
78 /* Starting with the result of former calls of this function (or the
79 initialization function update the context for the next LEN bytes
80 starting at BUFFER.
81 It is necessary that LEN is a multiple of 64!!! */
82 extern void sha1_process_block (const void *buffer, size_t len,
83 struct sha1_ctx *ctx);
85 /* Starting with the result of former calls of this function (or the
86 initialization function update the context for the next LEN bytes
87 starting at BUFFER.
88 It is NOT required that LEN is a multiple of 64. */
89 extern void sha1_process_bytes (const void *buffer, size_t len,
90 struct sha1_ctx *ctx);
92 /* Process the remaining bytes in the buffer and put result from CTX
93 in first 20 bytes following RESBUF. The result is always in little
94 endian byte order, so that a byte-wise output yields to the wanted
95 ASCII representation of the message digest. */
96 extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf);
99 /* Put result from CTX in first 20 bytes following RESBUF. The result is
100 always in little endian byte order, so that a byte-wise output yields
101 to the wanted ASCII representation of the message digest. */
102 extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf);
105 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
106 result is always in little endian byte order, so that a byte-wise
107 output yields to the wanted ASCII representation of the message
108 digest. */
109 extern void *sha1_buffer (const char *buffer, size_t len,
110 void *restrict resblock);
112 # endif
114 /* Compute SHA1 message digest for bytes read from STREAM.
115 STREAM is an open file stream. Regular files are handled more efficiently.
116 The contents of STREAM from its current position to its end will be read.
117 The case that the last operation on STREAM was an 'ungetc' is not supported.
118 The resulting message digest number will be written into the 20 bytes
119 beginning at RESBLOCK. */
120 extern int sha1_stream (FILE *stream, void *resblock);
123 # ifdef __cplusplus
125 # endif
127 #endif
130 * Hey Emacs!
131 * Local Variables:
132 * coding: utf-8
133 * End: