af_alg: Improve comments.
[gnulib.git] / lib / af_alg.h
blob2545ec6ec213fd794dbb51c3650d0d8f7796de7e
1 /* af_alg.h - Compute message digests from file streams.
2 Copyright (C) 2018 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Matteo Croce <mcroce@redhat.com>, 2018.
18 Documentation by Bruno Haible <bruno@clisp.org>, 2018. */
20 /* Declare specific functions for computing message digests
21 using the Linux kernel crypto API, if available. This kernel API gives
22 access to specialized crypto instructions (that would also be available
23 in user space) or to crypto devices (not directly available in user space).
25 For a more complete set of facilities that use the Linux kernel crypto API,
26 look at libkcapi. */
28 #ifndef AF_ALG_H
29 # define AF_ALG_H 1
31 # include <stdio.h>
32 # include <errno.h>
34 # ifdef __cplusplus
35 extern "C" {
36 # endif
38 # if HAVE_LINUX_IF_ALG_H
40 /* Compute a message digest of the contents of a file.
41 STREAM is an open file stream. Regular files are handled more efficiently.
42 ALG is the message digest algorithm; see the file /proc/crypto.
43 RESBLOCK points to a block of HASHLEN bytes, for the result.
44 HASHLEN must be the length of the message digest, in bytes, in particular:
46 alg | hashlen
47 -------+--------
48 md5 | 16
49 sha1 | 20
50 sha224 | 28
51 sha256 | 32
52 sha384 | 48
53 sha512 | 64
55 If successful, fill RESBLOCK and return 0.
56 Upon failure, return a negated error number. */
57 int
58 afalg_stream (FILE *stream, const char *alg, void *resblock, ssize_t hashlen);
60 # else
62 static int
63 afalg_stream (FILE *stream, const char *alg, void *resblock, ssize_t hashlen)
65 return -EAFNOSUPPORT;
68 # endif
70 # ifdef __cplusplus
72 # endif
74 #endif /* AF_ALG_H */