diff options
Diffstat (limited to 'gl/sha1.h')
-rw-r--r-- | gl/sha1.h | 66 |
1 files changed, 45 insertions, 21 deletions
@@ -1,20 +1,20 @@ | |||
1 | /* Declarations of functions and data types used for SHA1 sum | 1 | /* Declarations of functions and data types used for SHA1 sum |
2 | library functions. | 2 | library functions. |
3 | Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2013 Free Software | 3 | Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2022 Free Software |
4 | Foundation, Inc. | 4 | Foundation, Inc. |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify it | 6 | This file is free software: you can redistribute it and/or modify |
7 | under the terms of the GNU General Public License as published by the | 7 | it under the terms of the GNU Lesser General Public License as |
8 | Free Software Foundation; either version 3, or (at your option) any | 8 | published by the Free Software Foundation; either version 2.1 of the |
9 | later version. | 9 | License, or (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This file is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU Lesser General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU Lesser General Public License |
17 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | 17 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
18 | 18 | ||
19 | #ifndef SHA1_H | 19 | #ifndef SHA1_H |
20 | # define SHA1_H 1 | 20 | # define SHA1_H 1 |
@@ -22,12 +22,23 @@ | |||
22 | # include <stdio.h> | 22 | # include <stdio.h> |
23 | # include <stdint.h> | 23 | # include <stdint.h> |
24 | 24 | ||
25 | # if HAVE_OPENSSL_SHA1 | ||
26 | # ifndef OPENSSL_API_COMPAT | ||
27 | # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ | ||
28 | # endif | ||
29 | # include <openssl/sha.h> | ||
30 | # endif | ||
31 | |||
25 | # ifdef __cplusplus | 32 | # ifdef __cplusplus |
26 | extern "C" { | 33 | extern "C" { |
27 | # endif | 34 | # endif |
28 | 35 | ||
29 | #define SHA1_DIGEST_SIZE 20 | 36 | # define SHA1_DIGEST_SIZE 20 |
30 | 37 | ||
38 | # if HAVE_OPENSSL_SHA1 | ||
39 | # define GL_OPENSSL_NAME 1 | ||
40 | # include "gl_openssl.h" | ||
41 | # else | ||
31 | /* Structure to save state of computation between the single steps. */ | 42 | /* Structure to save state of computation between the single steps. */ |
32 | struct sha1_ctx | 43 | struct sha1_ctx |
33 | { | 44 | { |
@@ -38,11 +49,10 @@ struct sha1_ctx | |||
38 | uint32_t E; | 49 | uint32_t E; |
39 | 50 | ||
40 | uint32_t total[2]; | 51 | uint32_t total[2]; |
41 | uint32_t buflen; | 52 | uint32_t buflen; /* ≥ 0, ≤ 128 */ |
42 | uint32_t buffer[32]; | 53 | uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */ |
43 | }; | 54 | }; |
44 | 55 | ||
45 | |||
46 | /* Initialize structure containing state of computation. */ | 56 | /* Initialize structure containing state of computation. */ |
47 | extern void sha1_init_ctx (struct sha1_ctx *ctx); | 57 | extern void sha1_init_ctx (struct sha1_ctx *ctx); |
48 | 58 | ||
@@ -64,28 +74,42 @@ extern void sha1_process_bytes (const void *buffer, size_t len, | |||
64 | in first 20 bytes following RESBUF. The result is always in little | 74 | 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 | 75 | endian byte order, so that a byte-wise output yields to the wanted |
66 | ASCII representation of the message digest. */ | 76 | ASCII representation of the message digest. */ |
67 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); | 77 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf); |
68 | 78 | ||
69 | 79 | ||
70 | /* Put result from CTX in first 20 bytes following RESBUF. The result is | 80 | /* 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 | 81 | always in little endian byte order, so that a byte-wise output yields |
72 | to the wanted ASCII representation of the message digest. */ | 82 | to the wanted ASCII representation of the message digest. */ |
73 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); | 83 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf); |
74 | 84 | ||
75 | 85 | ||
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 | 86 | /* 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 | 87 | result is always in little endian byte order, so that a byte-wise |
83 | output yields to the wanted ASCII representation of the message | 88 | output yields to the wanted ASCII representation of the message |
84 | digest. */ | 89 | digest. */ |
85 | extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); | 90 | extern void *sha1_buffer (const char *buffer, size_t len, |
91 | void *restrict resblock); | ||
92 | |||
93 | # endif | ||
94 | |||
95 | /* Compute SHA1 message digest for bytes read from STREAM. | ||
96 | STREAM is an open file stream. Regular files are handled more efficiently. | ||
97 | The contents of STREAM from its current position to its end will be read. | ||
98 | The case that the last operation on STREAM was an 'ungetc' is not supported. | ||
99 | The resulting message digest number will be written into the 20 bytes | ||
100 | beginning at RESBLOCK. */ | ||
101 | extern int sha1_stream (FILE *stream, void *resblock); | ||
102 | |||
86 | 103 | ||
87 | # ifdef __cplusplus | 104 | # ifdef __cplusplus |
88 | } | 105 | } |
89 | # endif | 106 | # endif |
90 | 107 | ||
91 | #endif | 108 | #endif |
109 | |||
110 | /* | ||
111 | * Hey Emacs! | ||
112 | * Local Variables: | ||
113 | * coding: utf-8 | ||
114 | * End: | ||
115 | */ | ||