Blame lib/af_alg.h

Packit Service a2489d
/* af_alg.h - Compute message digests from file streams and buffers.
Packit Service a2489d
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit Service a2489d
Packit Service a2489d
   This program is free software; you can redistribute it and/or modify it
Packit Service a2489d
   under the terms of the GNU General Public License as published by the
Packit Service a2489d
   Free Software Foundation; either version 3, or (at your option) any
Packit Service a2489d
   later version.
Packit Service a2489d
Packit Service a2489d
   This program is distributed in the hope that it will be useful,
Packit Service a2489d
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2489d
   GNU General Public License for more details.
Packit Service a2489d
Packit Service a2489d
   You should have received a copy of the GNU General Public License
Packit Service a2489d
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit Service a2489d
Packit Service a2489d
/* Written by Matteo Croce <mcroce@redhat.com>, 2018.
Packit Service a2489d
   Documentation by Bruno Haible <bruno@clisp.org>, 2018.  */
Packit Service a2489d
Packit Service a2489d
/* Declare specific functions for computing message digests
Packit Service a2489d
   using the Linux kernel crypto API, if available.  This kernel API gives
Packit Service a2489d
   access to specialized crypto instructions (that would also be available
Packit Service a2489d
   in user space) or to crypto devices (not directly available in user space).
Packit Service a2489d
Packit Service a2489d
   For a more complete set of facilities that use the Linux kernel crypto API,
Packit Service a2489d
   look at libkcapi.  */
Packit Service a2489d
Packit Service a2489d
#ifndef AF_ALG_H
Packit Service a2489d
# define AF_ALG_H 1
Packit Service a2489d
Packit Service a2489d
# include <stdio.h>
Packit Service a2489d
# include <errno.h>
Packit Service a2489d
Packit Service a2489d
# ifdef __cplusplus
Packit Service a2489d
extern "C" {
Packit Service a2489d
# endif
Packit Service a2489d
Packit Service a2489d
# if USE_LINUX_CRYPTO_API
Packit Service a2489d
Packit Service a2489d
/* Compute a message digest of a memory region.
Packit Service a2489d
Packit Service a2489d
   The memory region starts at BUFFER and is LEN bytes long.
Packit Service a2489d
Packit Service a2489d
   ALG is the message digest algorithm; see the file /proc/crypto.
Packit Service a2489d
Packit Service a2489d
   RESBLOCK points to a block of HASHLEN bytes, for the result.
Packit Service a2489d
   HASHLEN must be the length of the message digest, in bytes, in particular:
Packit Service a2489d
Packit Service a2489d
      alg    | hashlen
Packit Service a2489d
      -------+--------
Packit Service a2489d
      md5    | 16
Packit Service a2489d
      sha1   | 20
Packit Service a2489d
      sha224 | 28
Packit Service a2489d
      sha256 | 32
Packit Service a2489d
      sha384 | 48
Packit Service a2489d
      sha512 | 64
Packit Service a2489d
Packit Service a2489d
   If successful, fill RESBLOCK and return 0.
Packit Service a2489d
   Upon failure, return a negated error number.  */
Packit Service a2489d
int
Packit Service a2489d
afalg_buffer (const char *buffer, size_t len, const char *alg,
Packit Service a2489d
              void *resblock, ssize_t hashlen);
Packit Service a2489d
Packit Service a2489d
/* Compute a message digest of data read from STREAM.
Packit Service a2489d
Packit Service a2489d
   STREAM is an open file stream.  The last operation on STREAM should
Packit Service a2489d
   not be 'ungetc', and if STREAM is also open for writing it should
Packit Service a2489d
   have been fflushed since its last write.  Read from the current
Packit Service a2489d
   position to the end of STREAM.  Handle regular files efficently.
Packit Service a2489d
Packit Service a2489d
   ALG is the message digest algorithm; see the file /proc/crypto.
Packit Service a2489d
Packit Service a2489d
   RESBLOCK points to a block of HASHLEN bytes, for the result.
Packit Service a2489d
   HASHLEN must be the length of the message digest, in bytes, in particular:
Packit Service a2489d
Packit Service a2489d
      alg    | hashlen
Packit Service a2489d
      -------+--------
Packit Service a2489d
      md5    | 16
Packit Service a2489d
      sha1   | 20
Packit Service a2489d
      sha224 | 28
Packit Service a2489d
      sha256 | 32
Packit Service a2489d
      sha384 | 48
Packit Service a2489d
      sha512 | 64
Packit Service a2489d
Packit Service a2489d
   If successful, fill RESBLOCK and return 0.
Packit Service a2489d
   Upon failure, return a negated error number.
Packit Service a2489d
   Unless returning 0 or -EIO, restore STREAM's file position so that
Packit Service a2489d
   the caller can fall back on some other method.  */
Packit Service a2489d
int
Packit Service a2489d
afalg_stream (FILE *stream, const char *alg,
Packit Service a2489d
              void *resblock, ssize_t hashlen);
Packit Service a2489d
Packit Service a2489d
# else
Packit Service a2489d
Packit Service a2489d
static inline int
Packit Service a2489d
afalg_buffer (const char *buffer, size_t len, const char *alg,
Packit Service a2489d
              void *resblock, ssize_t hashlen)
Packit Service a2489d
{
Packit Service a2489d
  return -EAFNOSUPPORT;
Packit Service a2489d
}
Packit Service a2489d
Packit Service a2489d
static inline int
Packit Service a2489d
afalg_stream (FILE *stream, const char *alg,
Packit Service a2489d
              void *resblock, ssize_t hashlen)
Packit Service a2489d
{
Packit Service a2489d
  return -EAFNOSUPPORT;
Packit Service a2489d
}
Packit Service a2489d
Packit Service a2489d
# endif
Packit Service a2489d
Packit Service a2489d
# ifdef __cplusplus
Packit Service a2489d
}
Packit Service a2489d
# endif
Packit Service a2489d
Packit Service a2489d
#endif /* AF_ALG_H */