Mercurial > gnulib
annotate lib/md5.h @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 1acf7ebb5dab |
children |
rev | line source |
---|---|
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
1 /* Declaration of functions and data types used for MD5 sum computing |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
2 library functions. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19623
diff
changeset
|
3 Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2019 Free Software |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
4 Foundation, Inc. |
6381
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
5 This file is part of the GNU C Library. |
464 | 6 |
771 | 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 2, or (at your option) any | |
10 later version. | |
464 | 11 |
771 | 12 This program is distributed in the hope that it will be useful, |
755 | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
771 | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | |
464 | 16 |
771 | 17 You should have received a copy of the GNU General Public License |
19190 | 18 along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
464 | 19 |
20 #ifndef _MD5_H | |
745 | 21 #define _MD5_H 1 |
464 | 22 |
23 #include <stdio.h> | |
6381
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
24 #include <stdint.h> |
464 | 25 |
17554
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
26 # if HAVE_OPENSSL_MD5 |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
27 # include <openssl/md5.h> |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
28 # endif |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
29 |
6381
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
30 #define MD5_DIGEST_SIZE 16 |
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
31 #define MD5_BLOCK_SIZE 64 |
5159 | 32 |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
33 #ifndef __GNUC_PREREQ |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
34 # if defined __GNUC__ && defined __GNUC_MINOR__ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11749
diff
changeset
|
35 # define __GNUC_PREREQ(maj, min) \ |
6381
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
36 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
37 # else |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
38 # define __GNUC_PREREQ(maj, min) 0 |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
39 # endif |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
40 #endif |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
41 |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
42 #ifndef __THROW |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
43 # if defined __cplusplus && __GNUC_PREREQ (2,8) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11749
diff
changeset
|
44 # define __THROW throw () |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
45 # else |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
46 # define __THROW |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
47 # endif |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
48 #endif |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
49 |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
50 #ifndef _LIBC |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
51 # define __md5_buffer md5_buffer |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
52 # define __md5_finish_ctx md5_finish_ctx |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
53 # define __md5_init_ctx md5_init_ctx |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
54 # define __md5_process_block md5_process_block |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
55 # define __md5_process_bytes md5_process_bytes |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
56 # define __md5_read_ctx md5_read_ctx |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
57 # define __md5_stream md5_stream |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
58 #endif |
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
59 |
11731
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
60 # ifdef __cplusplus |
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
61 extern "C" { |
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
62 # endif |
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
63 |
17554
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
64 # if HAVE_OPENSSL_MD5 |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
65 # define GL_OPENSSL_NAME 5 |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
66 # include "gl_openssl.h" |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
67 # else |
464 | 68 /* Structure to save state of computation between the single steps. */ |
69 struct md5_ctx | |
70 { | |
6381
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
71 uint32_t A; |
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
72 uint32_t B; |
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
73 uint32_t C; |
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
74 uint32_t D; |
745 | 75 |
6381
865e2ea2dde4
Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents:
6335
diff
changeset
|
76 uint32_t total[2]; |
18756
34f03a221ea4
md5, sha1, sha256, sha512: Add comments regarding correctness.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
77 uint32_t buflen; /* ≥ 0, ≤ 128 */ |
34f03a221ea4
md5, sha1, sha256, sha512: Add comments regarding correctness.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
78 uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */ |
464 | 79 }; |
80 | |
81 /* | |
82 * The following three functions are build up the low level used in | |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
83 * the functions 'md5_stream' and 'md5_buffer'. |
464 | 84 */ |
85 | |
86 /* Initialize structure containing state of computation. | |
87 (RFC 1321, 3.3: Step 3) */ | |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
88 extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW; |
745 | 89 |
90 /* Starting with the result of former calls of this function (or the | |
91 initialization function update the context for the next LEN bytes | |
92 starting at BUFFER. | |
93 It is necessary that LEN is a multiple of 64!!! */ | |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
94 extern void __md5_process_block (const void *buffer, size_t len, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11749
diff
changeset
|
95 struct md5_ctx *ctx) __THROW; |
464 | 96 |
97 /* Starting with the result of former calls of this function (or the | |
745 | 98 initialization function update the context for the next LEN bytes |
464 | 99 starting at BUFFER. |
745 | 100 It is NOT required that LEN is a multiple of 64. */ |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
101 extern void __md5_process_bytes (const void *buffer, size_t len, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11749
diff
changeset
|
102 struct md5_ctx *ctx) __THROW; |
745 | 103 |
104 /* Process the remaining bytes in the buffer and put result from CTX | |
105 in first 16 bytes following RESBUF. The result is always in little | |
106 endian byte order, so that a byte-wise output yields to the wanted | |
9657
267c66b59eec
md5: adapt alignment constraint fix from sha1.
Simon Josefsson <simon@josefsson.org>
parents:
6553
diff
changeset
|
107 ASCII representation of the message digest. */ |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
108 extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW; |
745 | 109 |
464 | 110 |
111 /* Put result from CTX in first 16 bytes following RESBUF. The result is | |
112 always in little endian byte order, so that a byte-wise output yields | |
9657
267c66b59eec
md5: adapt alignment constraint fix from sha1.
Simon Josefsson <simon@josefsson.org>
parents:
6553
diff
changeset
|
113 to the wanted ASCII representation of the message digest. */ |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
114 extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW; |
464 | 115 |
116 | |
117 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The | |
118 result is always in little endian byte order, so that a byte-wise | |
119 output yields to the wanted ASCII representation of the message | |
120 digest. */ | |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
121 extern void *__md5_buffer (const char *buffer, size_t len, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11749
diff
changeset
|
122 void *resblock) __THROW; |
464 | 123 |
17554
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
124 # endif |
19623
1acf7ebb5dab
af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents:
19496
diff
changeset
|
125 /* Compute MD5 message digest for bytes read from STREAM. |
1acf7ebb5dab
af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents:
19496
diff
changeset
|
126 STREAM is an open file stream. Regular files are handled more efficiently. |
1acf7ebb5dab
af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents:
19496
diff
changeset
|
127 The contents of STREAM from its current position to its end will be read. |
1acf7ebb5dab
af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents:
19496
diff
changeset
|
128 The case that the last operation on STREAM was an 'ungetc' is not supported. |
1acf7ebb5dab
af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents:
19496
diff
changeset
|
129 The resulting message digest number will be written into the 16 bytes |
17554
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
130 beginning at RESBLOCK. */ |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
131 extern int __md5_stream (FILE *stream, void *resblock) __THROW; |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
132 |
0c8459454095
md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents:
17249
diff
changeset
|
133 |
11731
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
134 # ifdef __cplusplus |
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
135 } |
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
136 # endif |
2ddd55967fe9
C++: wrap md2,md5,sha1,etc. function declarations in extern "C" scope
Peter Simons <simons@cryp.to>
parents:
9657
diff
changeset
|
137 |
6222
3bdede13630a
Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
138 #endif /* md5.h */ |
19496
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
139 |
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
140 /* |
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
141 * Hey Emacs! |
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
142 * Local Variables: |
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
143 * coding: utf-8 |
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
144 * End: |
33ee5e90be64
maint: Add encoding marker for Emacs to non-ASCII sources.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
145 */ |