Blame lib/gl_openssl.h

Packit 8f70b4
/* Wrap openssl crypto hash routines in gnulib interface.  -*- coding: utf-8 -*-
Packit 8f70b4
Packit 8f70b4
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit 8f70b4
Packit 8f70b4
   This program is free software: you can redistribute it and/or modify
Packit 8f70b4
   it under the terms of the GNU General Public License as published by
Packit 8f70b4
   the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
   (at your option) any later version.
Packit 8f70b4
Packit 8f70b4
   This program is distributed in the hope that it will be useful,
Packit 8f70b4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
   GNU General Public License for more details.
Packit 8f70b4
Packit 8f70b4
   You should have received a copy of the GNU General Public License
Packit 8f70b4
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit 8f70b4
Packit 8f70b4
/* Written by Pádraig Brady */
Packit 8f70b4
Packit 8f70b4
#ifndef GL_OPENSSL_NAME
Packit 8f70b4
# error "Please define GL_OPENSSL_NAME to 1,5,256 etc."
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifndef _GL_INLINE_HEADER_BEGIN
Packit 8f70b4
# error "Please include config.h first."
Packit 8f70b4
#endif
Packit 8f70b4
_GL_INLINE_HEADER_BEGIN
Packit 8f70b4
#ifndef GL_OPENSSL_INLINE
Packit 8f70b4
# define GL_OPENSSL_INLINE _GL_INLINE
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Concatenate two preprocessor tokens.  */
Packit 8f70b4
#define _GLCRYPTO_CONCAT_(prefix, suffix) prefix##suffix
Packit 8f70b4
#define _GLCRYPTO_CONCAT(prefix, suffix) _GLCRYPTO_CONCAT_ (prefix, suffix)
Packit 8f70b4
Packit 8f70b4
#if GL_OPENSSL_NAME == 5
Packit 8f70b4
# define OPENSSL_ALG md5
Packit 8f70b4
#else
Packit 8f70b4
# define OPENSSL_ALG _GLCRYPTO_CONCAT (sha, GL_OPENSSL_NAME)
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Context type mappings.  */
Packit 8f70b4
#if BASE_OPENSSL_TYPE != GL_OPENSSL_NAME
Packit 8f70b4
# undef BASE_OPENSSL_TYPE
Packit 8f70b4
# if GL_OPENSSL_NAME == 224
Packit 8f70b4
#  define BASE_OPENSSL_TYPE 256
Packit 8f70b4
# elif GL_OPENSSL_NAME == 384
Packit 8f70b4
#  define BASE_OPENSSL_TYPE 512
Packit 8f70b4
# endif
Packit 8f70b4
# define md5_CTX MD5_CTX
Packit 8f70b4
# define sha1_CTX SHA_CTX
Packit 8f70b4
# define sha224_CTX SHA256_CTX
Packit 8f70b4
# define sha224_ctx sha256_ctx
Packit 8f70b4
# define sha256_CTX SHA256_CTX
Packit 8f70b4
# define sha384_CTX SHA512_CTX
Packit 8f70b4
# define sha384_ctx sha512_ctx
Packit 8f70b4
# define sha512_CTX SHA512_CTX
Packit 8f70b4
# undef _gl_CTX
Packit 8f70b4
# undef _gl_ctx
Packit 8f70b4
# define _gl_CTX _GLCRYPTO_CONCAT (OPENSSL_ALG, _CTX) /* openssl type.  */
Packit 8f70b4
# define _gl_ctx _GLCRYPTO_CONCAT (OPENSSL_ALG, _ctx) /* gnulib type.  */
Packit 8f70b4
Packit 8f70b4
struct _gl_ctx { _gl_CTX CTX; };
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Function name mappings.  */
Packit 8f70b4
#define md5_prefix MD5
Packit 8f70b4
#define sha1_prefix SHA1
Packit 8f70b4
#define sha224_prefix SHA224
Packit 8f70b4
#define sha256_prefix SHA256
Packit 8f70b4
#define sha384_prefix SHA384
Packit 8f70b4
#define sha512_prefix SHA512
Packit 8f70b4
#define _GLCRYPTO_PREFIX _GLCRYPTO_CONCAT (OPENSSL_ALG, _prefix)
Packit 8f70b4
#define OPENSSL_FN(suffix) _GLCRYPTO_CONCAT (_GLCRYPTO_PREFIX, suffix)
Packit 8f70b4
#define GL_CRYPTO_FN(suffix) _GLCRYPTO_CONCAT (OPENSSL_ALG, suffix)
Packit 8f70b4
Packit 8f70b4
GL_OPENSSL_INLINE void
Packit 8f70b4
GL_CRYPTO_FN (_init_ctx) (struct _gl_ctx *ctx)
Packit 8f70b4
{ (void) OPENSSL_FN (_Init) ((_gl_CTX *) ctx); }
Packit 8f70b4
Packit 8f70b4
/* These were never exposed by gnulib.  */
Packit 8f70b4
#if ! (GL_OPENSSL_NAME == 224 || GL_OPENSSL_NAME == 384)
Packit 8f70b4
GL_OPENSSL_INLINE void
Packit 8f70b4
GL_CRYPTO_FN (_process_bytes) (const void *buf, size_t len, struct _gl_ctx *ctx)
Packit 8f70b4
{ OPENSSL_FN (_Update) ((_gl_CTX *) ctx, buf, len); }
Packit 8f70b4
Packit 8f70b4
GL_OPENSSL_INLINE void
Packit 8f70b4
GL_CRYPTO_FN (_process_block) (const void *buf, size_t len, struct _gl_ctx *ctx)
Packit 8f70b4
{ GL_CRYPTO_FN (_process_bytes) (buf, len, ctx); }
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
GL_OPENSSL_INLINE void *
Packit 8f70b4
GL_CRYPTO_FN (_finish_ctx) (struct _gl_ctx *ctx, void *res)
Packit 8f70b4
{ OPENSSL_FN (_Final) ((unsigned char *) res, (_gl_CTX *) ctx); return res; }
Packit 8f70b4
Packit 8f70b4
GL_OPENSSL_INLINE void *
Packit 8f70b4
GL_CRYPTO_FN (_buffer) (const char *buf, size_t len, void *res)
Packit 8f70b4
{ return OPENSSL_FN () ((const unsigned char *) buf, len, (unsigned char *) res); }
Packit 8f70b4
Packit 8f70b4
GL_OPENSSL_INLINE void *
Packit 8f70b4
GL_CRYPTO_FN (_read_ctx) (const struct _gl_ctx *ctx, void *res)
Packit 8f70b4
{
Packit 8f70b4
  /* Assume any unprocessed bytes in ctx are not to be ignored.  */
Packit 8f70b4
  _gl_CTX tmp_ctx = *(_gl_CTX *) ctx;
Packit 8f70b4
  OPENSSL_FN (_Final) ((unsigned char *) res, &tmp_ctx);
Packit 8f70b4
  return res;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
/* Undef so we can include multiple times.  */
Packit 8f70b4
#undef GL_CRYPTO_FN
Packit 8f70b4
#undef OPENSSL_FN
Packit 8f70b4
#undef _GLCRYPTO_PREFIX
Packit 8f70b4
#undef OPENSSL_ALG
Packit 8f70b4
#undef GL_OPENSSL_NAME
Packit 8f70b4
Packit 8f70b4
_GL_INLINE_HEADER_END