annotate lib/af_alg.h @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents f63c4e7dfb31
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19636
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
1 /* af_alg.h - Compute message digests from file streams and buffers.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19636
diff changeset
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
19598
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
3
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
5 under the terms of the GNU General Public License as published by the
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
6 Free Software Foundation; either version 2, or (at your option) any
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
7 later version.
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
8
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
12 GNU General Public License for more details.
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
13
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
16
19607
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
17 /* Written by Matteo Croce <mcroce@redhat.com>, 2018.
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
18 Documentation by Bruno Haible <bruno@clisp.org>, 2018. */
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
19
19618
00d4a0f20c8b af_alg: Improve comments.
Paul Eggert <eggert@cs.ucla.edu>
parents: 19616
diff changeset
20 /* Declare specific functions for computing message digests
19607
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
21 using the Linux kernel crypto API, if available. This kernel API gives
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
22 access to specialized crypto instructions (that would also be available
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
23 in user space) or to crypto devices (not directly available in user space).
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
24
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
25 For a more complete set of facilities that use the Linux kernel crypto API,
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
26 look at libkcapi. */
19598
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
27
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
28 #ifndef AF_ALG_H
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
29 # define AF_ALG_H 1
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
30
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
31 # include <stdio.h>
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
32 # include <errno.h>
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
33
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
34 # ifdef __cplusplus
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
35 extern "C" {
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
36 # endif
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
37
19621
3475ec8fca53 af_alg: Add configure option to enable/disable use of Linux crypto API.
Bruno Haible <bruno@clisp.org>
parents: 19618
diff changeset
38 # if USE_LINUX_CRYPTO_API
19598
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
39
19627
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
40 /* Compute a message digest of a memory region.
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
41
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
42 The memory region starts at BUFFER and is LEN bytes long.
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
43
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
44 ALG is the message digest algorithm; see the file /proc/crypto.
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
45
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
46 RESBLOCK points to a block of HASHLEN bytes, for the result.
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
47 HASHLEN must be the length of the message digest, in bytes, in particular:
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
48
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
49 alg | hashlen
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
50 -------+--------
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
51 md5 | 16
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
52 sha1 | 20
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
53 sha224 | 28
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
54 sha256 | 32
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
55 sha384 | 48
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
56 sha512 | 64
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
57
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
58 If successful, fill RESBLOCK and return 0.
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
59 Upon failure, return a negated error number. */
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
60 int
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
61 afalg_buffer (const char *buffer, size_t len, const char *alg,
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
62 void *resblock, ssize_t hashlen);
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
63
19636
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
64 /* Compute a message digest of data read from STREAM.
19623
1acf7ebb5dab af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents: 19621
diff changeset
65
19636
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
66 STREAM is an open file stream. The last operation on STREAM should
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
67 not be 'ungetc', and if STREAM is also open for writing it should
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
68 have been fflushed since its last write. Read from the current
40100
f63c4e7dfb31 Fix typos found by codespell.
Tim Rühsen <tim.ruehsen@gmx.de>
parents: 40057
diff changeset
69 position to the end of STREAM. Handle regular files efficiently.
19623
1acf7ebb5dab af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents: 19621
diff changeset
70
19618
00d4a0f20c8b af_alg: Improve comments.
Paul Eggert <eggert@cs.ucla.edu>
parents: 19616
diff changeset
71 ALG is the message digest algorithm; see the file /proc/crypto.
19623
1acf7ebb5dab af_alg: Fix bug with streams that are not at position 0.
Bruno Haible <bruno@clisp.org>
parents: 19621
diff changeset
72
19618
00d4a0f20c8b af_alg: Improve comments.
Paul Eggert <eggert@cs.ucla.edu>
parents: 19616
diff changeset
73 RESBLOCK points to a block of HASHLEN bytes, for the result.
00d4a0f20c8b af_alg: Improve comments.
Paul Eggert <eggert@cs.ucla.edu>
parents: 19616
diff changeset
74 HASHLEN must be the length of the message digest, in bytes, in particular:
19607
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
75
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
76 alg | hashlen
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
77 -------+--------
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
78 md5 | 16
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
79 sha1 | 20
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
80 sha224 | 28
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
81 sha256 | 32
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
82 sha384 | 48
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
83 sha512 | 64
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
84
19618
00d4a0f20c8b af_alg: Improve comments.
Paul Eggert <eggert@cs.ucla.edu>
parents: 19616
diff changeset
85 If successful, fill RESBLOCK and return 0.
19636
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
86 Upon failure, return a negated error number.
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
87 Unless returning 0 or -EIO, restore STREAM's file position so that
b9a17c2eedf8 af_alg: recover better from crypto failures
Paul Eggert <eggert@cs.ucla.edu>
parents: 19627
diff changeset
88 the caller can fall back on some other method. */
19598
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
89 int
19627
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
90 afalg_stream (FILE *stream, const char *alg,
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
91 void *resblock, ssize_t hashlen);
19598
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
92
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
93 # else
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
94
19626
0fe92d74b6d9 af_alg: Avoid warnings.
Bruno Haible <bruno@clisp.org>
parents: 19623
diff changeset
95 static inline int
19627
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
96 afalg_buffer (const char *buffer, size_t len, const char *alg,
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
97 void *resblock, ssize_t hashlen)
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
98 {
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
99 return -EAFNOSUPPORT;
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
100 }
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
101
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
102 static inline int
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
103 afalg_stream (FILE *stream, const char *alg,
25b7564e3876 af_alg: Add ability to use Linux kernel crypto API on data in memory.
Bruno Haible <bruno@clisp.org>
parents: 19626
diff changeset
104 void *resblock, ssize_t hashlen)
19598
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
105 {
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
106 return -EAFNOSUPPORT;
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
107 }
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
108
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
109 # endif
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
110
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
111 # ifdef __cplusplus
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
112 }
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
113 # endif
e5aa8f083cad sha1sum: use AF_ALG when available
Matteo Croce <mcroce@redhat.com>
parents:
diff changeset
114
19607
eca9d8b783a2 af_alg: Add documentation.
Bruno Haible <bruno@clisp.org>
parents: 19598
diff changeset
115 #endif /* AF_ALG_H */