Blame lib/gl_openssl.h

Packit Service a2489d
/* Wrap openssl crypto hash routines in gnulib interface.  -*- coding: utf-8 -*-
Packit Service a2489d
Packit Service a2489d
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit Service a2489d
Packit Service a2489d
   This program is free software: you can redistribute it and/or modify
Packit Service a2489d
   it under the terms of the GNU General Public License as published by
Packit Service a2489d
   the Free Software Foundation; either version 3 of the License, or
Packit Service a2489d
   (at your option) any 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 Pádraig Brady */
Packit Service a2489d
Packit Service a2489d
#ifndef GL_OPENSSL_NAME
Packit Service a2489d
# error "Please define GL_OPENSSL_NAME to 1,5,256 etc."
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
#ifndef _GL_INLINE_HEADER_BEGIN
Packit Service a2489d
# error "Please include config.h first."
Packit Service a2489d
#endif
Packit Service a2489d
_GL_INLINE_HEADER_BEGIN
Packit Service a2489d
#ifndef GL_OPENSSL_INLINE
Packit Service a2489d
# define GL_OPENSSL_INLINE _GL_INLINE
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
/* Concatenate two preprocessor tokens.  */
Packit Service a2489d
#define _GLCRYPTO_CONCAT_(prefix, suffix) prefix##suffix
Packit Service a2489d
#define _GLCRYPTO_CONCAT(prefix, suffix) _GLCRYPTO_CONCAT_ (prefix, suffix)
Packit Service a2489d
Packit Service a2489d
#if GL_OPENSSL_NAME == 5
Packit Service a2489d
# define OPENSSL_ALG md5
Packit Service a2489d
#else
Packit Service a2489d
# define OPENSSL_ALG _GLCRYPTO_CONCAT (sha, GL_OPENSSL_NAME)
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
/* Context type mappings.  */
Packit Service a2489d
#if BASE_OPENSSL_TYPE != GL_OPENSSL_NAME
Packit Service a2489d
# undef BASE_OPENSSL_TYPE
Packit Service a2489d
# if GL_OPENSSL_NAME == 224
Packit Service a2489d
#  define BASE_OPENSSL_TYPE 256
Packit Service a2489d
# elif GL_OPENSSL_NAME == 384
Packit Service a2489d
#  define BASE_OPENSSL_TYPE 512
Packit Service a2489d
# endif
Packit Service a2489d
# define md5_CTX MD5_CTX
Packit Service a2489d
# define sha1_CTX SHA_CTX
Packit Service a2489d
# define sha224_CTX SHA256_CTX
Packit Service a2489d
# define sha224_ctx sha256_ctx
Packit Service a2489d
# define sha256_CTX SHA256_CTX
Packit Service a2489d
# define sha384_CTX SHA512_CTX
Packit Service a2489d
# define sha384_ctx sha512_ctx
Packit Service a2489d
# define sha512_CTX SHA512_CTX
Packit Service a2489d
# undef _gl_CTX
Packit Service a2489d
# undef _gl_ctx
Packit Service a2489d
# define _gl_CTX _GLCRYPTO_CONCAT (OPENSSL_ALG, _CTX) /* openssl type.  */
Packit Service a2489d
# define _gl_ctx _GLCRYPTO_CONCAT (OPENSSL_ALG, _ctx) /* gnulib type.  */
Packit Service a2489d
Packit Service a2489d
struct _gl_ctx { _gl_CTX CTX; };
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
/* Function name mappings.  */
Packit Service a2489d
#define md5_prefix MD5
Packit Service a2489d
#define sha1_prefix SHA1
Packit Service a2489d
#define sha224_prefix SHA224
Packit Service a2489d
#define sha256_prefix SHA256
Packit Service a2489d
#define sha384_prefix SHA384
Packit Service a2489d
#define sha512_prefix SHA512
Packit Service a2489d
#define _GLCRYPTO_PREFIX _GLCRYPTO_CONCAT (OPENSSL_ALG, _prefix)
Packit Service a2489d
#define OPENSSL_FN(suffix) _GLCRYPTO_CONCAT (_GLCRYPTO_PREFIX, suffix)
Packit Service a2489d
#define GL_CRYPTO_FN(suffix) _GLCRYPTO_CONCAT (OPENSSL_ALG, suffix)
Packit Service a2489d
Packit Service a2489d
GL_OPENSSL_INLINE void
Packit Service a2489d
GL_CRYPTO_FN (_init_ctx) (struct _gl_ctx *ctx)
Packit Service a2489d
{ (void) OPENSSL_FN (_Init) ((_gl_CTX *) ctx); }
Packit Service a2489d
Packit Service a2489d
/* These were never exposed by gnulib.  */
Packit Service a2489d
#if ! (GL_OPENSSL_NAME == 224 || GL_OPENSSL_NAME == 384)
Packit Service a2489d
GL_OPENSSL_INLINE void
Packit Service a2489d
GL_CRYPTO_FN (_process_bytes) (const void *buf, size_t len, struct _gl_ctx *ctx)
Packit Service a2489d
{ OPENSSL_FN (_Update) ((_gl_CTX *) ctx, buf, len); }
Packit Service a2489d
Packit Service a2489d
GL_OPENSSL_INLINE void
Packit Service a2489d
GL_CRYPTO_FN (_process_block) (const void *buf, size_t len, struct _gl_ctx *ctx)
Packit Service a2489d
{ GL_CRYPTO_FN (_process_bytes) (buf, len, ctx); }
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
GL_OPENSSL_INLINE void *
Packit Service a2489d
GL_CRYPTO_FN (_finish_ctx) (struct _gl_ctx *ctx, void *res)
Packit Service a2489d
{ OPENSSL_FN (_Final) ((unsigned char *) res, (_gl_CTX *) ctx); return res; }
Packit Service a2489d
Packit Service a2489d
GL_OPENSSL_INLINE void *
Packit Service a2489d
GL_CRYPTO_FN (_buffer) (const char *buf, size_t len, void *res)
Packit Service a2489d
{ return OPENSSL_FN () ((const unsigned char *) buf, len, (unsigned char *) res); }
Packit Service a2489d
Packit Service a2489d
GL_OPENSSL_INLINE void *
Packit Service a2489d
GL_CRYPTO_FN (_read_ctx) (const struct _gl_ctx *ctx, void *res)
Packit Service a2489d
{
Packit Service a2489d
  /* Assume any unprocessed bytes in ctx are not to be ignored.  */
Packit Service a2489d
  _gl_CTX tmp_ctx = *(_gl_CTX *) ctx;
Packit Service a2489d
  OPENSSL_FN (_Final) ((unsigned char *) res, &tmp_ctx);
Packit Service a2489d
  return res;
Packit Service a2489d
}
Packit Service a2489d
Packit Service a2489d
/* Undef so we can include multiple times.  */
Packit Service a2489d
#undef GL_CRYPTO_FN
Packit Service a2489d
#undef OPENSSL_FN
Packit Service a2489d
#undef _GLCRYPTO_PREFIX
Packit Service a2489d
#undef OPENSSL_ALG
Packit Service a2489d
#undef GL_OPENSSL_NAME
Packit Service a2489d
Packit Service a2489d
_GL_INLINE_HEADER_END