summaryrefslogtreecommitdiff
path: root/lib/af_alg.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-05-09 18:07:29 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2018-05-09 18:08:58 -0700
commitcb17397cd405b533f8106064324ce52278f94a7a (patch)
tree9072276178b1b0752ec24298b006cbe0072b48ad /lib/af_alg.h
parenta03d9294699894f9a0c1406458917eebfae533e8 (diff)
downloadgnulib-cb17397cd405b533f8106064324ce52278f94a7a.tar.gz
af_alg: recover better from crypto failures
* lib/af_alg.c (afalg_stream): Recover from crypto failures if the input stream is seekable, by repositioning the stream back to where it was, possibly by just calling sendfile with an offset arg. This lets us return -EAFNOSUPPORT instead of -EIO in some cases, which lets our callers try again with user-mode code. * modules/crypto/af_alg (Depends-on): Depend on fseeko and ftello instead of on fflush and lseek.
Diffstat (limited to 'lib/af_alg.h')
-rw-r--r--lib/af_alg.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/af_alg.h b/lib/af_alg.h
index 018fa221a0..429ec210d6 100644
--- a/lib/af_alg.h
+++ b/lib/af_alg.h
@@ -1,4 +1,4 @@
-/* af_alg.h - Compute message digests from file streams.
+/* af_alg.h - Compute message digests from file streams and buffers.
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -61,11 +61,12 @@ int
afalg_buffer (const char *buffer, size_t len, const char *alg,
void *resblock, ssize_t hashlen);
-/* Compute a message digest of the contents of a file.
+/* Compute a message digest of data read from STREAM.
- STREAM is an open file stream. Regular files are handled more efficiently.
- The contents of STREAM from its current position to its end will be read.
- The case that the last operation on STREAM was an 'ungetc' is not supported.
+ STREAM is an open file stream. The last operation on STREAM should
+ not be 'ungetc', and if STREAM is also open for writing it should
+ have been fflushed since its last write. Read from the current
+ position to the end of STREAM. Handle regular files efficently.
ALG is the message digest algorithm; see the file /proc/crypto.
@@ -82,7 +83,9 @@ afalg_buffer (const char *buffer, size_t len, const char *alg,
sha512 | 64
If successful, fill RESBLOCK and return 0.
- Upon failure, return a negated error number. */
+ Upon failure, return a negated error number.
+ Unless returning 0 or -EIO, restore STREAM's file position so that
+ the caller can fall back on some other method. */
int
afalg_stream (FILE *stream, const char *alg,
void *resblock, ssize_t hashlen);