1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-04-28 06:33:36 +00:00
Files
gnulib/lib/gl_openssl.h
Paul Eggert 8765694360 crypto: add ‘restrict’ to .h files
Use ‘restrict’ on pointer args when appropriate.
It suffices to do this in .h files, as .c files inherit it.
For style, prefer qualifiers after types, to be consistent with
putting ‘restrict’ after types.
* lib/af_alg.h (afalg_buffer, afalg_stream):
* lib/arcfour.h (arcfour_stream, arcfour_setkey):
* lib/arctwo.h (arctwo_setkey_ekb, arctwo_encrypt, arctwo_decrypt):
* lib/des.h (gl_des_setkey, gl_des_makekey, gl_des_ecb_crypt)
(gl_3des_set2keys, gl_3des_set3keys, gl_3des_makekey)
(gl_3des_ecb_crypt):
* lib/gc.h (gc_cipher_setkey, gc_cipher_setiv)
(gc_cipher_encrypt_inline, gc_cipher_decrypt_inline, gc_hash_clone)
(gc_hash_hmac_setkey, gc_hash_write, gc_hash_buffer, gc_md2)
(gc_md4, gc_md5, gc_sha1, gc_sha256, gc_sha512, gc_sm3)
(gc_hmac_md5, gc_hmac_sha1, gc_hmac_sha256, gc_hmac_sha512)
(gc_pbkdf2_hmac, gc_pbkdf2_sha1):
* lib/gl_openssl.h (GL_CRYPTO_FN (_process_bytes))
(GL_CRYPTO_FN (_process_block), GL_CRYPTO_FN (_finish_ctx))
(GL_CRYPTO_FN (_buffer), GL_CRYPTO_FN (_read_ctx)):
* lib/hmac.h (hmac_md5, hmac_sha1, hmac_sha256, hmac_sha512):
* lib/md2.h (md2_process_block, md2_process_bytes, md2_finish_ctx)
(md2_read_ctx, md2_buffer, md2_stream):
* lib/md4.h (md4_process_block, md4_process_bytes, md4_finish_ctx)
(md4_read_ctx, md4_buffer, md4_stream):
* lib/md5.h (__md5_process_block, __md5_process_bytes, __md5_finish_ctx)
(__md5_read_ctx, __md5_buffer, __md5_stream):
* lib/rijndael-alg-fst.h (rijndaelKeySetupEnc)
(rijndaelKeySetupDec, rijndaelEncrypt, rijndaelDecrypt):
* lib/rijndael-api-fst.h (rijndaelMakeKey, rijndaelCipherInit)
(rijndaelBlockEncrypt, rijndaelPadEncrypt, rijndaelBlockDecrypt)
(rijndaelPadDecrypt):
* lib/sha1.h (sha1_process_block, sha1_process_bytes)
(sha1_finish_ctx, sha1_read_ctx, sha1_buffer, sha1_stream):
* lib/sha256.h (sha256_process_block, sha256_process_bytes)
(sha256_finish_ctx, sha224_finish_ctx, sha256_read_ctx)
(sha224_read_ctx, sha256_buffer, sha224_buffer, sha256_stream)
(sha224_stream):
* lib/sha3.h (sha3_process_block, sha3_process_bytes)
(sha3_finish_ctx, sha3_read_ctx, sha3_224_buffer, sha3_256_buffer)
(sha3_384_buffer, sha3_512_buffer, sha3_224_stream)
(sha3_256_stream, sha3_384_stream, sha3_512_stream):
* lib/sha512.h (sha512_process_block, sha512_process_bytes)
(sha512_finish_ctx, sha384_finish_ctx, sha512_read_ctx)
(sha384_read_ctx, sha512_buffer, sha384_buffer, sha512_stream)
(sha384_stream):
* lib/sm3.h (sm3_process_block, sm3_process_bytes, sm3_finish_ctx)
(sm3_read_ctx, sm3_buffer, sm3_stream):
Add ‘restrict’ to pointer args.  All implementations changed.
2026-02-22 16:18:31 -08:00

123 lines
4.0 KiB
C

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