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 Paul Eggert <eggert@cs.ucla.edu>
+ 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.
+
crypto/sha3: Don’t leak if init fails and no free
If the init_ctx functions fail, it’s natural for callers to
immediately fail too. Change the init_ctx functions to not leak
}
int
-afalg_buffer (const char *buffer, size_t len, const char *alg,
- void *resblock, ssize_t hashlen)
+afalg_buffer (char const *restrict buffer, size_t len,
+ char const *restrict alg,
+ void *restrict resblock, ssize_t hashlen)
{
/* On Linux < 4.9, the value for an empty stream is wrong (all zeroes).
See <https://patchwork.kernel.org/patch/9308641/>.
}
int
-afalg_stream (FILE *stream, const char *alg,
- void *resblock, ssize_t hashlen)
+afalg_stream (FILE *restrict stream, char const *restrict alg,
+ void *restrict resblock, ssize_t hashlen)
{
int ofd = alg_socket (alg);
if (ofd < 0)
If successful, fill RESBLOCK and return 0.
Upon failure, return a negated error number. */
int
-afalg_buffer (const char *buffer, size_t len, const char *alg,
- void *resblock, ssize_t hashlen);
+afalg_buffer (char const *restrict buffer, size_t len, char const *restrict alg,
+ void *restrict resblock, ssize_t hashlen);
/* Compute a message digest of data read from STREAM.
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);
+afalg_stream (FILE *restrict stream, char const *restrict alg,
+ void *restrict resblock, ssize_t hashlen);
# else
static inline int
-afalg_buffer (const char *buffer, size_t len, const char *alg,
- void *resblock, ssize_t hashlen)
+afalg_buffer (char const *restrict buffer, size_t len, char const *restrict alg,
+ void *restrict resblock, ssize_t hashlen)
{
return -EAFNOSUPPORT;
}
static inline int
-afalg_stream (FILE *stream, const char *alg,
- void *resblock, ssize_t hashlen)
+afalg_stream (FILE *restrict stream, char const *restrict alg,
+ void *restrict resblock, ssize_t hashlen)
{
return -EAFNOSUPPORT;
}
#include "arcfour.h"
void
-arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf,
+arcfour_stream (arcfour_context *restrict context,
+ char const *restrict inbuf, char *restrict outbuf,
size_t length)
{
uint8_t i = context->idx_i;
}
void
-arcfour_setkey (arcfour_context * context, const char *key, size_t keylen)
+arcfour_setkey (arcfour_context *restrict context,
+ char const *restrict key, size_t keylen)
{
char *sbox = context->sbox;
LENGTH size. CONTEXT must be initialized with arcfour_setkey
before this function is called. */
extern void
-arcfour_stream (arcfour_context * context,
- const char *inbuf, char *restrict outbuf, size_t length);
+arcfour_stream (arcfour_context *restrict context,
+ char const *restrict inbuf, char *restrict outbuf,
+ size_t length);
/* Initialize CONTEXT using encryption KEY of KEYLEN bytes. KEY
should be 40 bits (5 bytes) or longer. The KEY cannot be zero
length. */
extern void
-arcfour_setkey (arcfour_context * context, const char *key, size_t keylen);
+arcfour_setkey (arcfour_context *restrict context,
+ char const *restrict key, size_t keylen);
#ifdef __cplusplus
}
void
-arctwo_encrypt (arctwo_context *context, const char *inbuf,
- char *outbuf, size_t length)
+arctwo_encrypt (arctwo_context *restrict context, char const *restrict inbuf,
+ char *restrict outbuf, size_t length)
{
for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE,
inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
}
void
-arctwo_decrypt (arctwo_context *context, const char *inbuf,
- char *outbuf, size_t length)
+arctwo_decrypt (arctwo_context *restrict context, char const *restrict inbuf,
+ char *restrict outbuf, size_t length)
{
for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE,
inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
}
void
-arctwo_setkey_ekb (arctwo_context *context,
- size_t keylen, const char *key, size_t effective_keylen)
+arctwo_setkey_ekb (arctwo_context *restrict context,
+ size_t keylen, char const *restrict key,
+ size_t effective_keylen)
{
if (keylen < 40 / 8 || effective_keylen > 1024)
return;
only be of EFFECTIVE_KEYLEN bits. Normally, you use
EFFECTIVE_KEYLEN of 0, but see RFC 2268 for more information. */
void
-arctwo_setkey_ekb (arctwo_context *context,
- size_t keylen, const char *key, size_t effective_keylen);
+arctwo_setkey_ekb (arctwo_context *restrict context,
+ size_t keylen, char const *restrict key,
+ size_t effective_keylen);
#define arctwo_setkey(context,keylen,key) \
arctwo_setkey_ekb (context, keylen, key, 8 * (keylen))
and must have been initialized with arctwo_setkey or
arctwo_setkey_ekb. */
extern void
-arctwo_encrypt (arctwo_context *context, const char *inbuf,
+arctwo_encrypt (arctwo_context *restrict context, char const *restrict inbuf,
char *restrict outbuf, size_t length);
/* Decrypt INBUF of size LENGTH into OUTBUF. LENGTH must be a
and must have been initialized with arctwo_setkey or
arctwo_setkey_ekb. */
extern void
-arctwo_decrypt (arctwo_context *context, const char *inbuf,
+arctwo_decrypt (arctwo_context *restrict context, char const *restrict inbuf,
char *restrict outbuf, size_t length);
}
void
-gl_des_setkey (gl_des_ctx *ctx, const char * key)
+gl_des_setkey (gl_des_ctx *restrict ctx, char const *restrict key)
{
des_key_schedule (key, ctx->encrypt_subkeys);
}
bool
-gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen)
+gl_des_makekey (gl_des_ctx *ctx, char const *restrict key, size_t keylen)
{
if (keylen != 8)
return false;
}
void
-gl_des_ecb_crypt (gl_des_ctx *ctx, const char * _from, char * _to, int mode)
+gl_des_ecb_crypt (gl_des_ctx *ctx, char const *restrict _from,
+ char *restrict _to, int mode)
{
const unsigned char *from = (const unsigned char *) _from;
unsigned char *to = (unsigned char *) _to;
}
void
-gl_3des_set2keys (gl_3des_ctx *ctx, const char * key1, const char * key2)
+gl_3des_set2keys (gl_3des_ctx *restrict ctx,
+ char const *restrict key1,
+ char const *restrict key2)
{
des_key_schedule (key1, ctx->encrypt_subkeys);
des_key_schedule (key2, &(ctx->decrypt_subkeys[32]));
}
void
-gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1,
- const char * key2, const char * key3)
+gl_3des_set3keys (gl_3des_ctx *restrict ctx,
+ char const *restrict key1,
+ char const *restrict key2,
+ char const *restrict key3)
{
des_key_schedule (key1, ctx->encrypt_subkeys);
des_key_schedule (key2, &(ctx->decrypt_subkeys[32]));
}
void
-gl_3des_ecb_crypt (gl_3des_ctx *ctx,
- const char * _from,
- char * _to, int mode)
+gl_3des_ecb_crypt (gl_3des_ctx *restrict ctx,
+ char const *restrict _from,
+ char *restrict _to, int mode)
{
const unsigned char *from = (const unsigned char *) _from;
unsigned char *to = (unsigned char *) _to;
}
bool
-gl_3des_makekey (gl_3des_ctx *ctx, const char * key, size_t keylen)
+gl_3des_makekey (gl_3des_ctx *restrict ctx,
+ char const *restrict key, size_t keylen)
{
if (keylen != 24)
return false;
* Does not check parity bits, but simply ignore them. Does not check
* for weak keys. */
extern void
-gl_des_setkey (gl_des_ctx *ctx, const char * key);
+gl_des_setkey (gl_des_ctx *restrict ctx, char const *restrict key);
/* Fill a DES context CTX with subkeys calculated from 64bit KEY, with
* weak key checking. Does not check parity bits, but simply ignore
* them. */
extern bool
-gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen);
+gl_des_makekey (gl_des_ctx *restrict ctx,
+ char const *restrict key, size_t keylen);
/* Electronic Codebook Mode DES encryption/decryption of data
* according to 'mode'. */
extern void
-gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode);
+gl_des_ecb_crypt (gl_des_ctx *restrict ctx, char const *restrict from,
+ char *restrict to, int mode);
#define gl_des_ecb_encrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 0)
#define gl_des_ecb_decrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 1)
* 64bit keys in KEY1 and KEY2. Does not check the parity bits of the
* keys, but simply ignore them. Does not check for weak keys. */
extern void
-gl_3des_set2keys (gl_3des_ctx *ctx,
- const char * key1,
- const char * key2);
+gl_3des_set2keys (gl_3des_ctx *restrict ctx,
+ char const *restrict key1,
+ char const *restrict key2);
/*
* Fill a Triple-DES context CTX with subkeys calculated from three
* of the keys, but simply ignore them. Does not check for weak
* keys. */
extern void
-gl_3des_set3keys (gl_3des_ctx *ctx,
- const char * key1,
- const char * key2,
- const char * key3);
+gl_3des_set3keys (gl_3des_ctx *restrict ctx,
+ char const *restrict key1,
+ char const *restrict key2,
+ char const *restrict key3);
/* Fill a Triple-DES context CTX with subkeys calculated from three
* concatenated 64bit keys in KEY, with weak key checking. Does not
* check the parity bits of the keys, but simply ignore them. */
extern bool
-gl_3des_makekey (gl_3des_ctx *ctx,
- const char * key,
+gl_3des_makekey (gl_3des_ctx *restrict ctx,
+ char const *restrict key,
size_t keylen);
/* Electronic Codebook Mode Triple-DES encryption/decryption of data
* according to 'mode'. Sometimes this mode is named 'EDE' mode
* (Encryption-Decryption-Encryption). */
extern void
-gl_3des_ecb_crypt (gl_3des_ctx *ctx,
- const char * from,
- char * to,
+gl_3des_ecb_crypt (gl_3des_ctx *restrict ctx,
+ char const *restrict from,
+ char *restrict to,
int mode);
#define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0)
}
Gc_rc
-gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
+gc_cipher_setkey (gc_cipher_handle restrict handle, size_t keylen,
+ char const *restrict key)
{
_gc_cipher_ctx *ctx = handle;
}
Gc_rc
-gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
+gc_cipher_setiv (gc_cipher_handle restrict handle, size_t ivlen,
+ char const *restrict iv)
{
_gc_cipher_ctx *ctx = handle;
}
Gc_rc
-gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
+gc_cipher_encrypt_inline (gc_cipher_handle restrict handle,
+ size_t len, char *restrict data)
{
_gc_cipher_ctx *ctx = handle;
}
Gc_rc
-gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
+gc_cipher_decrypt_inline (gc_cipher_handle restrict handle, size_t len,
+ char *restrict data)
{
_gc_cipher_ctx *ctx = handle;
}
Gc_rc
-gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
+gc_hash_clone (gc_hash_handle restrict handle,
+ gc_hash_handle *restrict outhandle)
{
_gc_hash_ctx *in = handle;
_gc_hash_ctx *out = calloc (1, sizeof (*out));
}
void
-gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
+gc_hash_write (gc_hash_handle restrict handle,
+ size_t len, char const *restrict data)
{
_gc_hash_ctx *ctx = handle;
}
Gc_rc
-gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
+gc_hash_buffer (Gc_hash hash, const void *restrict in, size_t inlen,
+ char *restrict resbuf)
{
switch (hash)
{
#if GNULIB_GC_MD2
Gc_rc
-gc_md2 (const void *in, size_t inlen, void *resbuf)
+gc_md2 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
md2_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_MD4
Gc_rc
-gc_md4 (const void *in, size_t inlen, void *resbuf)
+gc_md4 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
md4_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_MD5
Gc_rc
-gc_md5 (const void *in, size_t inlen, void *resbuf)
+gc_md5 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
md5_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_SHA1
Gc_rc
-gc_sha1 (const void *in, size_t inlen, void *resbuf)
+gc_sha1 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
sha1_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_SHA256
Gc_rc
-gc_sha256 (const void *in, size_t inlen, void *resbuf)
+gc_sha256 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
sha256_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_SHA512
Gc_rc
-gc_sha512 (const void *in, size_t inlen, void *resbuf)
+gc_sha512 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
sha512_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_SM3
Gc_rc
-gc_sm3 (const void *in, size_t inlen, void *resbuf)
+gc_sm3 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
sm3_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_HMAC_MD5
Gc_rc
-gc_hmac_md5 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_md5 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
hmac_md5 (key, keylen, in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_HMAC_SHA1
Gc_rc
-gc_hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_sha1 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
hmac_sha1 (key, keylen, in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_HMAC_SHA256
Gc_rc
-gc_hmac_sha256 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_sha256 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
hmac_sha256 (key, keylen, in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_HMAC_SHA512
Gc_rc
-gc_hmac_sha512 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_sha512 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
hmac_sha512 (key, keylen, in, inlen, resbuf);
return GC_OK;
}
Gc_rc
-gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
+gc_cipher_setkey (gc_cipher_handle restrict handle, size_t keylen,
+ char const *restrict key)
{
gcry_error_t err = gcry_cipher_setkey ((gcry_cipher_hd_t) handle, key, keylen);
if (gcry_err_code (err))
}
Gc_rc
-gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
+gc_cipher_setiv (gc_cipher_handle restrict handle,
+ size_t ivlen, char const *restrict iv)
{
gcry_error_t err = gcry_cipher_setiv ((gcry_cipher_hd_t) handle, iv, ivlen);
if (gcry_err_code (err))
}
Gc_rc
-gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
+gc_cipher_encrypt_inline (gc_cipher_handle restrict handle,
+ size_t len, char *restrict data)
{
if (gcry_cipher_encrypt ((gcry_cipher_hd_t) handle,
data, len, NULL, len) != 0)
}
Gc_rc
-gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
+gc_cipher_decrypt_inline (gc_cipher_handle restrict handle,
+ size_t len, char *restrict data)
{
if (gcry_cipher_decrypt ((gcry_cipher_hd_t) handle,
data, len, NULL, len) != 0)
}
Gc_rc
-gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
+gc_hash_clone (gc_hash_handle restrict handle,
+ gc_hash_handle *restrict outhandle)
{
_gc_hash_ctx *in = handle;
_gc_hash_ctx *out = calloc (1, sizeof (*out));
}
void
-gc_hash_hmac_setkey (gc_hash_handle handle, size_t len, const char *key)
+gc_hash_hmac_setkey (gc_hash_handle restrict handle,
+ size_t len, char const *restrict key)
{
_gc_hash_ctx *ctx = handle;
#if GNULIB_GC_MD2
}
void
-gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
+gc_hash_write (gc_hash_handle restrict handle,
+ size_t len, char const *restrict data)
{
_gc_hash_ctx *ctx = handle;
}
Gc_rc
-gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
+gc_hash_buffer (Gc_hash hash, void const *restrict in, size_t inlen,
+ char *restrict resbuf)
{
int gcryalg;
#if GNULIB_GC_MD2
Gc_rc
-gc_md2 (const void *in, size_t inlen, void *resbuf)
+gc_md2 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
md2_buffer (in, inlen, resbuf);
return GC_OK;
#if GNULIB_GC_MD4
Gc_rc
-gc_md4 (const void *in, size_t inlen, void *resbuf)
+gc_md4 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD4);
assert (outlen == GC_MD4_DIGEST_SIZE);
#if GNULIB_GC_MD5
Gc_rc
-gc_md5 (const void *in, size_t inlen, void *resbuf)
+gc_md5 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD5);
assert (outlen == GC_MD5_DIGEST_SIZE);
#if GNULIB_GC_SHA1
Gc_rc
-gc_sha1 (const void *in, size_t inlen, void *resbuf)
+gc_sha1 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
assert (outlen == GC_SHA1_DIGEST_SIZE);
#if GNULIB_GC_SHA256
Gc_rc
-gc_sha256 (const void *in, size_t inlen, void *resbuf)
+gc_sha256 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA256);
assert (outlen == GC_SHA256_DIGEST_SIZE);
#if GNULIB_GC_SHA512
Gc_rc
-gc_sha512 (const void *in, size_t inlen, void *resbuf)
+gc_sha512 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA512);
assert (outlen == GC_SHA512_DIGEST_SIZE);
#if GNULIB_GC_SM3
Gc_rc
-gc_sm3 (const void *in, size_t inlen, void *resbuf)
+gc_sm3 (void const *restrict in, size_t inlen, void *restrict resbuf)
{
# if !LIBGCRYPT_HAS_MD_SM3
sm3_buffer (in, inlen, resbuf);
#if GNULIB_GC_HMAC_MD5
Gc_rc
-gc_hmac_md5 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_md5 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_MD5);
assert (hlen == GC_MD5_DIGEST_SIZE);
#if GNULIB_GC_HMAC_SHA1
Gc_rc
-gc_hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_sha1 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
assert (hlen == GC_SHA1_DIGEST_SIZE);
#if GNULIB_GC_HMAC_SHA256
Gc_rc
-gc_hmac_sha256 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_sha256 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA256);
assert (hlen == GC_SHA256_DIGEST_SIZE);
#if GNULIB_GC_HMAC_SHA512
Gc_rc
-gc_hmac_sha512 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf)
+gc_hmac_sha512 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf)
{
size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA512);
assert (hlen == GC_SHA512_DIGEST_SIZE);
#include <string.h>
Gc_rc
-gc_pbkdf2_sha1 (const char *P, size_t Plen,
- const char *S, size_t Slen,
+gc_pbkdf2_sha1 (char const *restrict P, size_t Plen,
+ char const *restrict S, size_t Slen,
unsigned int c,
- char *DK, size_t dkLen)
+ char *restrict DK, size_t dkLen)
{
return gc_pbkdf2_hmac (GC_SHA1, P, Plen, S, Slen, c, DK, dkLen);
}
#include <stdlib.h>
#include <string.h>
-typedef Gc_rc (*gc_prf_func) (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf);
+typedef Gc_rc (*gc_prf_func) (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen,
+ char *restrict resbuf);
static Gc_rc
gc_pbkdf2_prf (gc_prf_func prf, size_t hLen,
- const char *P, size_t Plen,
- const char *S, size_t Slen,
+ char const *restrict P, size_t Plen,
+ char const *restrict S, size_t Slen,
unsigned int c,
- char *DK, size_t dkLen)
+ char *restrict DK, size_t dkLen)
{
if (c == 0)
return GC_PKCS5_INVALID_ITERATION_COUNT;
Gc_rc
gc_pbkdf2_hmac (Gc_hash hash,
- const char *P, size_t Plen,
- const char *S, size_t Slen,
- unsigned int c, char *DK, size_t dkLen)
+ char const *restrict P, size_t Plen,
+ char const *restrict S, size_t Slen,
+ unsigned int c, char *restrict DK, size_t dkLen)
{
gc_prf_func prf;
size_t hLen;
/* Ciphers. */
extern Gc_rc gc_cipher_open (Gc_cipher cipher, Gc_cipher_mode mode,
gc_cipher_handle *outhandle);
-extern Gc_rc gc_cipher_setkey (gc_cipher_handle handle,
- size_t keylen, const char *key);
-extern Gc_rc gc_cipher_setiv (gc_cipher_handle handle,
- size_t ivlen, const char *iv);
-extern Gc_rc gc_cipher_encrypt_inline (gc_cipher_handle handle,
- size_t len, char *data);
-extern Gc_rc gc_cipher_decrypt_inline (gc_cipher_handle handle,
- size_t len, char *data);
+extern Gc_rc gc_cipher_setkey (gc_cipher_handle restrict handle,
+ size_t keylen, char const *restrict key);
+extern Gc_rc gc_cipher_setiv (gc_cipher_handle restrict handle,
+ size_t ivlen, char const *restrict iv);
+extern Gc_rc gc_cipher_encrypt_inline (gc_cipher_handle restrict handle,
+ size_t len, char *restrict data);
+extern Gc_rc gc_cipher_decrypt_inline (gc_cipher_handle restrict handle,
+ size_t len, char *restrict data);
extern Gc_rc gc_cipher_close (gc_cipher_handle handle);
/* Hashes. */
extern Gc_rc gc_hash_open (Gc_hash hash, Gc_hash_mode mode,
gc_hash_handle *outhandle);
-extern Gc_rc gc_hash_clone (gc_hash_handle handle, gc_hash_handle *outhandle);
+extern Gc_rc gc_hash_clone (gc_hash_handle restrict handle,
+ gc_hash_handle *restrict outhandle);
extern size_t gc_hash_digest_length (Gc_hash hash)
_GL_ATTRIBUTE_CONST;
-extern void gc_hash_hmac_setkey (gc_hash_handle handle,
- size_t len, const char *key);
-extern void gc_hash_write (gc_hash_handle handle,
- size_t len, const char *data);
+extern void gc_hash_hmac_setkey (gc_hash_handle restrict handle,
+ size_t len, char const *restrict key);
+extern void gc_hash_write (gc_hash_handle restrict handle,
+ size_t len, char const *restrict data);
extern const char *gc_hash_read (gc_hash_handle handle);
extern void gc_hash_close (gc_hash_handle handle);
must be 16 bytes. The return value is 0 (GC_OK) on success, or
another Gc_rc error code. */
extern Gc_rc
-gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *out);
+gc_hash_buffer (Gc_hash hash, void const *restrict in, size_t inlen,
+ char *restrict out);
/* One-call interface. */
-extern Gc_rc gc_md2 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_md4 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_md5 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_sha1 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_sha256 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_sha512 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_sm3 (const void *in, size_t inlen, void *resbuf);
-extern Gc_rc gc_hmac_md5 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf);
-extern Gc_rc gc_hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf);
-extern Gc_rc gc_hmac_sha256 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf);
-extern Gc_rc gc_hmac_sha512 (const void *key, size_t keylen,
- const void *in, size_t inlen, char *resbuf);
+extern Gc_rc gc_md2 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_md4 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_md5 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_sha1 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_sha256 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_sha512 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_sm3 (void const *restrict in, size_t inlen, void *restrict resbuf);
+extern Gc_rc gc_hmac_md5 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf);
+extern Gc_rc gc_hmac_sha1 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf);
+extern Gc_rc gc_hmac_sha256 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf);
+extern Gc_rc gc_hmac_sha512 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, char *restrict resbuf);
/* Derive cryptographic keys using PKCS#5 PBKDF2 (RFC 2898) from a
password P of length PLEN, with salt S of length SLEN, placing the
returned on success, otherwise a Gc_rc error code is returned. */
extern Gc_rc
gc_pbkdf2_hmac (Gc_hash hash,
- const char *P, size_t Plen,
- const char *S, size_t Slen,
+ char const *restrict P, size_t Plen,
+ char const *restrict S, size_t Slen,
unsigned int c, char *restrict DK, size_t dkLen);
extern Gc_rc
-gc_pbkdf2_sha1 (const char *P, size_t Plen,
- const char *S, size_t Slen,
+gc_pbkdf2_sha1 (char const *restrict P, size_t Plen,
+ char const *restrict S, size_t Slen,
unsigned int c, char *restrict DK, size_t dkLen);
/*
/* These were never exposed by gnulib. */
#if ! (GL_OPENSSL_NAME == 224 || GL_OPENSSL_NAME == 384)
GL_OPENSSL_INLINE void
-GL_CRYPTO_FN (_process_bytes) (const void *buf, size_t len, struct _gl_ctx *ctx)
+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) (const void *buf, size_t len, struct _gl_ctx *ctx)
+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 *ctx, void *restrict res)
+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) (const char *buf, size_t len, void *restrict res)
+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) (const struct _gl_ctx *ctx, void *restrict res)
+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;
KEYLEN bytes, writing the output to pre-allocated 16 byte minimum
RESBUF buffer. Return 0 on success. */
int
-hmac_md5 (const void *key, size_t keylen,
- const void *buffer, size_t buflen, void *restrict resbuf);
+hmac_md5 (void const *restrict key, size_t keylen,
+ void const *restrict buffer, size_t buflen, void *restrict resbuf);
/* Compute Hashed Message Authentication Code with SHA-1, over BUFFER
data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the
output to pre-allocated 20 byte minimum RESBUF buffer. Return 0 on
success. */
int
-hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen, void *restrict resbuf);
+hmac_sha1 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, void *restrict resbuf);
/* Compute Hashed Message Authentication Code with SHA-256, over BUFFER
data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the
output to pre-allocated 32 byte minimum RESBUF buffer. Return 0 on
success. */
int
-hmac_sha256 (const void *key, size_t keylen,
- const void *in, size_t inlen, void *restrict resbuf);
+hmac_sha256 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, void *restrict resbuf);
/* Compute Hashed Message Authentication Code with SHA-512, over BUFFER
data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the
output to pre-allocated 64 byte minimum RESBUF buffer. Return 0 on
success. */
int
-hmac_sha512 (const void *key, size_t keylen,
- const void *in, size_t inlen, void *restrict resbuf);
+hmac_sha512 (void const *restrict key, size_t keylen,
+ void const *restrict in, size_t inlen, void *restrict resbuf);
#ifdef __cplusplus
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
int
-md2_stream (FILE *stream, void *resblock)
+md2_stream (FILE *restrict stream, void *restrict resblock)
{
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
/* Put result from CTX in first 16 bytes following RESBUF. The result
must be in little endian byte order. */
void *
-md2_read_ctx (const struct md2_ctx *ctx, void *resbuf)
+md2_read_ctx (struct md2_ctx const *restrict ctx, void *restrict resbuf)
{
memcpy (resbuf, ctx->X, 16);
/* Process the remaining bytes in the internal buffer and the usual
prolog according to the standard and write the result to RESBUF. */
void *
-md2_finish_ctx (struct md2_ctx *ctx, void *resbuf)
+md2_finish_ctx (struct md2_ctx *restrict ctx, void *restrict resbuf)
{
/* pad the message */
unsigned long k = 16 - ctx->curlen;
output yields to the wanted ASCII representation of the message
digest. */
void *
-md2_buffer (const char *buffer, size_t len, void *resblock)
+md2_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct md2_ctx ctx;
}
void
-md2_process_bytes (const void *buffer, size_t len, struct md2_ctx *ctx)
+md2_process_bytes (void const *restrict buffer, size_t len,
+ struct md2_ctx *restrict ctx)
{
const char *in = buffer;
/* Process LEN bytes of BUFFER, accumulating context into CTX. */
void
-md2_process_block (const void *buffer, size_t len, struct md2_ctx *ctx)
+md2_process_block (void const *restrict buffer, size_t len,
+ struct md2_ctx *restrict ctx)
{
md2_process_bytes (buffer, len, ctx);
}
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void md2_process_block (const void *buffer, size_t len,
- struct md2_ctx *ctx);
+extern void md2_process_block (void const *restrict buffer, size_t len,
+ struct md2_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void md2_process_bytes (const void *buffer, size_t len,
- struct md2_ctx *ctx);
+extern void md2_process_bytes (void const *restrict buffer, size_t len,
+ struct md2_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX
in first 16 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *md2_finish_ctx (struct md2_ctx *ctx, void *restrict resbuf);
+extern void *md2_finish_ctx (struct md2_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in first 16 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */
-extern void *md2_read_ctx (const struct md2_ctx *ctx, void *restrict resbuf);
+extern void *md2_read_ctx (struct md2_ctx const *restrict ctx,
+ void *restrict resbuf);
/* Compute MD2 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *md2_buffer (const char *buffer, size_t len,
+extern void *md2_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
/* Compute MD2 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
-extern int md2_stream (FILE *stream, void *resblock);
+extern int md2_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
int
-md4_stream (FILE * stream, void *resblock)
+md4_stream (FILE *restrict stream, void *restrict resblock)
{
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
/* Put result from CTX in first 16 bytes following RESBUF. The result
must be in little endian byte order. */
void *
-md4_read_ctx (const struct md4_ctx *ctx, void *resbuf)
+md4_read_ctx (struct md4_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
/* Process the remaining bytes in the internal buffer and the usual
prolog according to the standard and write the result to RESBUF. */
void *
-md4_finish_ctx (struct md4_ctx *ctx, void *resbuf)
+md4_finish_ctx (struct md4_ctx *restrict ctx, void *restrict resbuf)
{
/* Take yet unprocessed bytes into account. */
uint32_t bytes = ctx->buflen;
output yields to the wanted ASCII representation of the message
digest. */
void *
-md4_buffer (const char *buffer, size_t len, void *resblock)
+md4_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct md4_ctx ctx;
}
void
-md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx)
+md4_process_bytes (void const *restrict buffer, size_t len,
+ struct md4_ctx *restrict ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
It is assumed that LEN % 64 == 0. */
void
-md4_process_block (const void *buffer, size_t len, struct md4_ctx *ctx)
+md4_process_block (void const *restrict buffer, size_t len,
+ struct md4_ctx *restrict ctx)
{
const uint32_t *words = buffer;
size_t nwords = len / sizeof (uint32_t);
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
-extern void md4_process_block (const void *buffer, size_t len,
- struct md4_ctx *ctx);
+extern void md4_process_block (void const *restrict buffer, size_t len,
+ struct md4_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void md4_process_bytes (const void *buffer, size_t len,
- struct md4_ctx *ctx);
+extern void md4_process_bytes (void const *restrict buffer, size_t len,
+ struct md4_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX
in first 16 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *md4_finish_ctx (struct md4_ctx *ctx, void *restrict resbuf);
+extern void *md4_finish_ctx (struct md4_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in first 16 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */
-extern void *md4_read_ctx (const struct md4_ctx *ctx, void *restrict resbuf);
+extern void *md4_read_ctx (struct md4_ctx const *restrict ctx,
+ void *restrict resbuf);
/* Compute MD4 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *md4_buffer (const char *buffer, size_t len,
+extern void *md4_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
/* Compute MD4 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
-extern int md4_stream (FILE * stream, void *resblock);
+extern int md4_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
-extern void __md5_process_block (const void *buffer, size_t len,
- struct md5_ctx *ctx) __THROW;
+extern void __md5_process_block (void const *restrict buffer, size_t len,
+ struct md5_ctx *restrict ctx) __THROW;
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void __md5_process_bytes (const void *buffer, size_t len,
- struct md5_ctx *ctx) __THROW;
+extern void __md5_process_bytes (void const *restrict buffer, size_t len,
+ struct md5_ctx *restrict ctx) __THROW;
/* Process the remaining bytes in the buffer and put result from CTX
in first 16 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *restrict resbuf)
+extern void *__md5_finish_ctx (struct md5_ctx *restrict ctx,
+ void *restrict resbuf)
__THROW;
/* Put result from CTX in first 16 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */
-extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *restrict resbuf)
+extern void *__md5_read_ctx (struct md5_ctx const *restrict ctx,
+ void *restrict resbuf)
__THROW;
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *__md5_buffer (const char *buffer, size_t len,
+extern void *__md5_buffer (char const *restrict buffer, size_t len,
void *restrict resblock) __THROW;
# endif
The case that the last operation on STREAM was an 'ungetc' is not supported.
The resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
-extern int __md5_stream (FILE *stream, void *resblock) __THROW;
+extern int __md5_stream (FILE *restrict stream, void *restrict resblock)
+ __THROW;
# ifdef __cplusplus
* @return the number of rounds for the given cipher key size.
*/
int
-rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
- const char cipherKey[], size_t keyBits)
+rijndaelKeySetupEnc (uint32_t rk[restrict /*4*(Nr + 1) */],
+ char const cipherKey[restrict], size_t keyBits)
{
size_t i = 0;
* @return the number of rounds for the given cipher key size.
*/
int
-rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ],
- const char cipherKey[], size_t keyBits)
+rijndaelKeySetupDec (uint32_t rk[restrict /*4*(Nr + 1) */],
+ char const cipherKey[restrict], size_t keyBits)
{
/* expand the cipher key: */
size_t Nr = rijndaelKeySetupEnc (rk, cipherKey, keyBits);
}
void
-rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
- const char pt[16], char ct[16])
+rijndaelEncrypt (uint32_t const rk[restrict /*4*(Nr + 1) */], size_t Nr,
+ char const pt[restrict 16], char ct[restrict 16])
{
uint32_t t0, t1, t2, t3;
}
void
-rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
- const char ct[16], char pt[16])
+rijndaelDecrypt (uint32_t const rk[restrict /*4*(Nr + 1) */], size_t Nr,
+ char const ct[restrict 16], char pt[restrict 16])
{
uint32_t t0, t1, t2, t3;
#define RIJNDAEL_MAXKB (256/8)
#define RIJNDAEL_MAXNR 14
-int rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
- const char cipherKey[], size_t keyBits);
-int rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ],
- const char cipherKey[], size_t keyBits);
-void rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
- const char pt[16], char ct[16]);
-void rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
- const char ct[16], char pt[16]);
+int rijndaelKeySetupEnc (uint32_t rk[restrict /*4*(Nr + 1) */],
+ char const cipherKey[restrict], size_t keyBits);
+int rijndaelKeySetupDec (uint32_t rk[restrict /*4*(Nr + 1) */],
+ char const cipherKey[restrict], size_t keyBits);
+void rijndaelEncrypt (const uint32_t rk[restrict /*4*(Nr + 1) */], size_t Nr,
+ char const pt[restrict 16], char ct[restrict 16]);
+void rijndaelDecrypt (const uint32_t rk[restrict /*4*(Nr + 1) */], size_t Nr,
+ char const ct[restrict 16], char pt[restrict 16]);
#ifdef __cplusplus
#include <string.h>
rijndael_rc
-rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction,
- size_t keyLen, const char *keyMaterial)
+rijndaelMakeKey (rijndaelKeyInstance *restrict key,
+ rijndael_direction direction,
+ size_t keyLen, char const *restrict keyMaterial)
{
if (key == NULL)
{
}
rijndael_rc
-rijndaelCipherInit (rijndaelCipherInstance *cipher, rijndael_mode mode,
- const char *IV)
+rijndaelCipherInit (rijndaelCipherInstance *restrict cipher, rijndael_mode mode,
+ char const *restrict IV)
{
if ((mode == RIJNDAEL_MODE_ECB) || (mode == RIJNDAEL_MODE_CBC)
|| (mode == RIJNDAEL_MODE_CFB1))
}
int
-rijndaelBlockEncrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input,
- size_t inputLen, char *outBuffer)
+rijndaelBlockEncrypt (rijndaelCipherInstance *restrict cipher,
+ rijndaelKeyInstance const *restrict key,
+ char const *restrict input,
+ size_t inputLen, char *restrict outBuffer)
{
if (cipher == NULL || key == NULL || key->direction == RIJNDAEL_DIR_DECRYPT)
{
}
int
-rijndaelPadEncrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input,
- size_t inputOctets, char *outBuffer)
+rijndaelPadEncrypt (rijndaelCipherInstance *restrict cipher,
+ rijndaelKeyInstance const *restrict key,
+ char const *restrict input,
+ size_t inputOctets, char *restrict outBuffer)
{
if (cipher == NULL || key == NULL || key->direction == RIJNDAEL_DIR_DECRYPT)
{
}
int
-rijndaelBlockDecrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input,
- size_t inputLen, char *outBuffer)
+rijndaelBlockDecrypt (rijndaelCipherInstance *restrict cipher,
+ rijndaelKeyInstance const *restrict key,
+ char const *restrict input,
+ size_t inputLen, char *restrict outBuffer)
{
if (cipher == NULL
|| key == NULL
}
int
-rijndaelPadDecrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input,
- size_t inputOctets, char *outBuffer)
+rijndaelPadDecrypt (rijndaelCipherInstance *restrict cipher,
+ rijndaelKeyInstance const *restrict key,
+ char const *restrict input,
+ size_t inputOctets, char *restrict outBuffer)
{
if (cipher == NULL || key == NULL || key->direction == RIJNDAEL_DIR_ENCRYPT)
{
from KEYMATERIAL, a hex string, of KEYLEN size. KEYLEN should be
128, 192 or 256. Returns 0 on success, or an error code. */
extern rijndael_rc
-rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction,
- size_t keyLen, const char *keyMaterial);
+rijndaelMakeKey (rijndaelKeyInstance *restrict key,
+ rijndael_direction direction,
+ size_t keyLen, char const *restrict keyMaterial);
/* Initialize cipher state CIPHER for encryption MODE (e.g.,
RIJNDAEL_MODE_CBC) with initialization vector IV, a hex string of
2*RIJNDAEL_MAX_IV_SIZE length. IV may be NULL for modes that do
not need an IV (i.e., RIJNDAEL_MODE_ECB). */
extern rijndael_rc
-rijndaelCipherInit (rijndaelCipherInstance *cipher,
- rijndael_mode mode, const char *IV);
+rijndaelCipherInit (rijndaelCipherInstance *restrict cipher,
+ rijndael_mode mode, char const *restrict IV);
/* Encrypt data in INPUT, of INPUTLEN/8 bytes length, placing the
output in the pre-allocated OUTBUFFER which must hold at least
calling this function. Return the number of bits written, or a
negative rijndael_rc error code. */
extern int
-rijndaelBlockEncrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input, size_t inputLen,
+rijndaelBlockEncrypt (rijndaelCipherInstance *restrict cipher,
+ const rijndaelKeyInstance *restrict key,
+ char const *restrict input, size_t inputLen,
char *restrict outBuffer);
/* Encrypt data in INPUT, of INPUTOCTETS bytes length, placing the
calling this function. Return the number of bits written, or a
negative rijndael_rc error code. */
extern int
-rijndaelPadEncrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input, size_t inputOctets,
+rijndaelPadEncrypt (rijndaelCipherInstance *restrict cipher,
+ const rijndaelKeyInstance *restrict key,
+ char const *restrict input, size_t inputOctets,
char *restrict outBuffer);
/* Decrypt data in INPUT, of INPUTLEN/8 bytes length, placing the
calling this function. Return the number of bits written, or a
negative rijndael_rc error code. */
extern int
-rijndaelBlockDecrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input, size_t inputLen,
+rijndaelBlockDecrypt (rijndaelCipherInstance *restrict cipher,
+ const rijndaelKeyInstance *restrict key,
+ char const *restrict input, size_t inputLen,
char *restrict outBuffer);
/* Decrypt data in INPUT, of INPUTOCTETS bytes length, placing the
calling this function. Return the number of bits written, or a
negative rijndael_rc error code. */
extern int
-rijndaelPadDecrypt (rijndaelCipherInstance *cipher,
- const rijndaelKeyInstance *key,
- const char *input, size_t inputOctets,
+rijndaelPadDecrypt (rijndaelCipherInstance *restrict cipher,
+ const rijndaelKeyInstance *restrict key,
+ char const *restrict input, size_t inputOctets,
char *restrict outBuffer);
resulting message digest number will be written into the 20 bytes
beginning at RESBLOCK. */
int
-sha1_stream (FILE *stream, void *resblock)
+sha1_stream (FILE *restrict stream, void *restrict resblock)
{
switch (afalg_stream (stream, "sha1", resblock, SHA1_DIGEST_SIZE))
{
/* Put result from CTX in first 20 bytes following RESBUF. The result
must be in little endian byte order. */
void *
-sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
+sha1_read_ctx (struct sha1_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
/* Process the remaining bytes in the internal buffer and the usual
prolog according to the standard and write the result to RESBUF. */
void *
-sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
+sha1_finish_ctx (struct sha1_ctx *restrict ctx, void *restrict resbuf)
{
/* Take yet unprocessed bytes into account. */
uint32_t bytes = ctx->buflen;
output yields to the wanted ASCII representation of the message
digest. */
void *
-sha1_buffer (const char *buffer, size_t len, void *resblock)
+sha1_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct sha1_ctx ctx;
}
void
-sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
+sha1_process_bytes (void const *restrict buffer, size_t len,
+ struct sha1_ctx *restrict ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
Most of this code comes from GnuPG's cipher/sha1.c. */
void
-sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
+sha1_process_block (void const *restrict buffer, size_t len,
+ struct sha1_ctx *restrict ctx)
{
const uint32_t *words = buffer;
size_t nwords = len / sizeof (uint32_t);
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
-extern void sha1_process_block (const void *buffer, size_t len,
- struct sha1_ctx *ctx);
+extern void sha1_process_block (void const *restrict buffer, size_t len,
+ struct sha1_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void sha1_process_bytes (const void *buffer, size_t len,
- struct sha1_ctx *ctx);
+extern void sha1_process_bytes (void const *restrict buffer, size_t len,
+ struct sha1_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX
in first 20 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf);
+extern void *sha1_finish_ctx (struct sha1_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in first 20 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */
-extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf);
+extern void *sha1_read_ctx (struct sha1_ctx const *restrict ctx,
+ void *restrict resbuf);
/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *sha1_buffer (const char *buffer, size_t len,
+extern void *sha1_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
# endif
The case that the last operation on STREAM was an 'ungetc' is not supported.
The resulting message digest number will be written into the 20 bytes
beginning at RESBLOCK. */
-extern int sha1_stream (FILE *stream, void *resblock);
+extern int sha1_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus
The initial and finishing operations are INIT_CTX and FINISH_CTX.
Return zero if and only if successful. */
static int
-shaxxx_stream (FILE *stream, char const *alg, void *resblock,
+shaxxx_stream (FILE *restrict stream, char const *restrict alg,
+ void *restrict resblock,
ssize_t hashlen, void (*init_ctx) (struct sha256_ctx *),
- void *(*finish_ctx) (struct sha256_ctx *, void *))
+ void *(*finish_ctx) (struct sha256_ctx *restrict,
+ void *restrict))
{
switch (afalg_stream (stream, alg, resblock, hashlen))
{
}
int
-sha256_stream (FILE *stream, void *resblock)
+sha256_stream (FILE *restrict stream, void *restrict resblock)
{
return shaxxx_stream (stream, "sha256", resblock, SHA256_DIGEST_SIZE,
sha256_init_ctx, sha256_finish_ctx);
}
int
-sha224_stream (FILE *stream, void *resblock)
+sha224_stream (FILE *restrict stream, void *restrict resblock)
{
return shaxxx_stream (stream, "sha224", resblock, SHA224_DIGEST_SIZE,
sha224_init_ctx, sha224_finish_ctx);
/* Put result from CTX in first 32 bytes following RESBUF.
The result must be in little endian byte order. */
void *
-sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
+sha256_read_ctx (struct sha256_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
}
void *
-sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
+sha224_read_ctx (struct sha256_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
}
void *
-sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
+sha256_finish_ctx (struct sha256_ctx *restrict ctx, void *restrict resbuf)
{
sha256_conclude_ctx (ctx);
return sha256_read_ctx (ctx, resbuf);
}
void *
-sha224_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
+sha224_finish_ctx (struct sha256_ctx *restrict ctx, void *restrict resbuf)
{
sha256_conclude_ctx (ctx);
return sha224_read_ctx (ctx, resbuf);
output yields to the wanted ASCII representation of the message
digest. */
void *
-sha256_buffer (const char *buffer, size_t len, void *resblock)
+sha256_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct sha256_ctx ctx;
}
void *
-sha224_buffer (const char *buffer, size_t len, void *resblock)
+sha224_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct sha256_ctx ctx;
}
void
-sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
+sha256_process_bytes (void const *restrict buffer, size_t len,
+ struct sha256_ctx *restrict ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
Most of this code comes from GnuPG's cipher/sha1.c. */
void
-sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
+sha256_process_block (void const *restrict buffer, size_t len,
+ struct sha256_ctx *restrict ctx)
{
const uint32_t *words = buffer;
size_t nwords = len / sizeof (uint32_t);
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
-extern void sha256_process_block (const void *buffer, size_t len,
- struct sha256_ctx *ctx);
+extern void sha256_process_block (void const *restrict buffer, size_t len,
+ struct sha256_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void sha256_process_bytes (const void *buffer, size_t len,
- struct sha256_ctx *ctx);
+extern void sha256_process_bytes (void const *restrict buffer, size_t len,
+ struct sha256_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX
in first 32 (28) bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *sha256_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf);
-extern void *sha224_finish_ctx (struct sha256_ctx *ctx, void *restrict resbuf);
+extern void *sha256_finish_ctx (struct sha256_ctx *restrict ctx,
+ void *restrict resbuf);
+extern void *sha224_finish_ctx (struct sha256_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in first 32 (28) bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */
-extern void *sha256_read_ctx (const struct sha256_ctx *ctx,
+extern void *sha256_read_ctx (struct sha256_ctx const *restrict ctx,
void *restrict resbuf);
-extern void *sha224_read_ctx (const struct sha256_ctx *ctx,
+extern void *sha224_read_ctx (struct sha256_ctx const *restrict ctx,
void *restrict resbuf);
The result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *sha256_buffer (const char *buffer, size_t len,
+extern void *sha256_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
-extern void *sha224_buffer (const char *buffer, size_t len,
+extern void *sha224_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
# endif
The case that the last operation on STREAM was an 'ungetc' is not supported.
The resulting message digest number will be written into the 32 (28) bytes
beginning at RESBLOCK. */
-extern int sha256_stream (FILE *stream, void *resblock);
-extern int sha224_stream (FILE *stream, void *resblock);
+extern int sha256_stream (FILE *restrict stream, void *restrict resblock);
+extern int sha224_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus
}
int
-sha3_224_stream (FILE *stream, void *resblock)
+sha3_224_stream (FILE *restrict stream, void *restrict resblock)
{
return sha3_xxx_stream (stream, "sha3-224", resblock, SHA3_224_DIGEST_SIZE,
sha3_224_init_ctx);
}
int
-sha3_256_stream (FILE *stream, void *resblock)
+sha3_256_stream (FILE *restrict stream, void *restrict resblock)
{
return sha3_xxx_stream (stream, "sha3-256", resblock, SHA3_256_DIGEST_SIZE,
sha3_256_init_ctx);
}
int
-sha3_384_stream (FILE *stream, void *resblock)
+sha3_384_stream (FILE *restrict stream, void *restrict resblock)
{
return sha3_xxx_stream (stream, "sha3-384", resblock, SHA3_384_DIGEST_SIZE,
sha3_384_init_ctx);
}
int
-sha3_512_stream (FILE *stream, void *resblock)
+sha3_512_stream (FILE *restrict stream, void *restrict resblock)
{
return sha3_xxx_stream (stream, "sha3-512", resblock, SHA3_512_DIGEST_SIZE,
sha3_512_init_ctx);
}
void *
-sha3_read_ctx (const struct sha3_ctx *ctx, void *resbuf)
+sha3_read_ctx (struct sha3_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
size_t words = ctx->digestlen / sizeof *ctx->state;
}
void *
-sha3_finish_ctx (struct sha3_ctx *ctx, void *resbuf)
+sha3_finish_ctx (struct sha3_ctx *restrict ctx, void *restrict resbuf)
{
sha3_conclude_ctx (ctx);
return sha3_read_ctx (ctx, resbuf);
#define DEFINE_SHA3_BUFFER(SIZE) \
void * \
- sha3_##SIZE##_buffer (const char *buffer, size_t len, void *resblock) \
+ sha3_##SIZE##_buffer (char const *restrict buffer, size_t len, \
+ void *restrict resblock) \
{ \
struct sha3_ctx ctx; \
sha3_##SIZE##_init_ctx (&ctx); \
DEFINE_SHA3_BUFFER (512)
bool
-sha3_process_bytes (const void *buffer, size_t len, struct sha3_ctx *ctx)
+sha3_process_bytes (void const *restrict buffer, size_t len,
+ struct sha3_ctx *restrict ctx)
{
char const *buf = buffer;
}
bool
-sha3_process_block (const void *buffer, size_t len, struct sha3_ctx *ctx)
+sha3_process_block (void const *restrict buffer, size_t len,
+ struct sha3_ctx *restrict ctx)
{
u64 *a = ctx->state;
const u64 *words = buffer;
}
void *
-sha3_read_ctx (const struct sha3_ctx *ctx, void *resbuf)
+sha3_read_ctx (struct sha3_ctx const *restrict ctx, void *restrict resbuf)
{
void *result = NULL;
int err = ENOMEM;
}
void *
-sha3_finish_ctx (struct sha3_ctx *ctx, void *resbuf)
+sha3_finish_ctx (struct sha3_ctx *restrict ctx, void *restrict resbuf)
{
int result = EVP_DigestFinal_ex (ctx->evp_ctx, resbuf, NULL);
if (result == 0)
DEFINE_SHA3_BUFFER (512)
bool
-sha3_process_bytes (const void *buffer, size_t len, struct sha3_ctx *ctx)
+sha3_process_bytes (void const *restrict buffer, size_t len,
+ struct sha3_ctx *restrict ctx)
{
int result = EVP_DigestUpdate (ctx->evp_ctx, buffer, len);
if (result == 0)
}
bool
-sha3_process_block (const void *buffer, size_t len, struct sha3_ctx *ctx)
+sha3_process_block (void const *restrict buffer, size_t len,
+ struct sha3_ctx *restrict ctx)
{
return sha3_process_bytes (buffer, len, ctx);
}
starting at BUFFER.
It is necessary that LEN is a multiple of the BLOCKLEN member of CTX!!!
Return false if an OpenSSL function fails. */
-extern bool sha3_process_block (const void *buffer, size_t len,
- struct sha3_ctx *ctx);
+extern bool sha3_process_block (void const *restrict buffer, size_t len,
+ struct sha3_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of the BLOCKLEN member of CTX.
Return false if an OpenSSL function fails. */
-extern bool sha3_process_bytes (const void *buffer, size_t len,
- struct sha3_ctx *ctx);
+extern bool sha3_process_bytes (void const *restrict buffer, size_t len,
+ struct sha3_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX in RESBUF.
The result is always in little endian byte order, so that a byte-wise output
yields to the wanted ASCII representation of the message digest.
Return NULL if an OpenSSL function fails. */
-extern void *sha3_finish_ctx (struct sha3_ctx *ctx, void *restrict resbuf);
+extern void *sha3_finish_ctx (struct sha3_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in RESBUF. The result is always in little endian byte
order, so that a byte-wise output yields to the wanted ASCII representation
of the message digest.
Return NULL if an OpenSSL function fails. */
-extern void *sha3_read_ctx (const struct sha3_ctx *ctx,
+extern void *sha3_read_ctx (struct sha3_ctx const *restrict ctx,
void *restrict resbuf);
/* Compute a SHA-3 message digest for LEN bytes beginning at BUFFER.
output yields to the wanted ASCII representation of the message
digest.
Return NULL if an OpenSSL function fails. */
-extern void *sha3_224_buffer (const char *buffer, size_t len,
+extern void *sha3_224_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
-extern void *sha3_256_buffer (const char *buffer, size_t len,
+extern void *sha3_256_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
-extern void *sha3_384_buffer (const char *buffer, size_t len,
+extern void *sha3_384_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
-extern void *sha3_512_buffer (const char *buffer, size_t len,
+extern void *sha3_512_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
/* Compute SHA-3 message digest for bytes read from STREAM. STREAM is an open
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. The resulting
message digest number will be written into RESBLOCK. */
-extern int sha3_224_stream (FILE *stream, void *resblock);
-extern int sha3_256_stream (FILE *stream, void *resblock);
-extern int sha3_384_stream (FILE *stream, void *resblock);
-extern int sha3_512_stream (FILE *stream, void *resblock);
+extern int sha3_224_stream (FILE *restrict stream, void *restrict resblock);
+extern int sha3_256_stream (FILE *restrict stream, void *restrict resblock);
+extern int sha3_384_stream (FILE *restrict stream, void *restrict resblock);
+extern int sha3_512_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus
}
The initial and finishing operations are INIT_CTX and FINISH_CTX.
Return zero if and only if successful. */
static int
-shaxxx_stream (FILE *stream, char const *alg, void *resblock,
+shaxxx_stream (FILE *restrict stream, char const *restrict alg,
+ void *restrict resblock,
ssize_t hashlen, void (*init_ctx) (struct sha512_ctx *),
- void *(*finish_ctx) (struct sha512_ctx *, void *))
+ void *(*finish_ctx) (struct sha512_ctx *restrict,
+ void *restrict))
{
switch (afalg_stream (stream, alg, resblock, hashlen))
{
}
int
-sha512_stream (FILE *stream, void *resblock)
+sha512_stream (FILE *restrict stream, void *restrict resblock)
{
return shaxxx_stream (stream, "sha512", resblock, SHA512_DIGEST_SIZE,
sha512_init_ctx, sha512_finish_ctx);
}
int
-sha384_stream (FILE *stream, void *resblock)
+sha384_stream (FILE *restrict stream, void *restrict resblock)
{
return shaxxx_stream (stream, "sha384", resblock, SHA384_DIGEST_SIZE,
sha384_init_ctx, sha384_finish_ctx);
/* Put result from CTX in first 64 bytes following RESBUF.
The result must be in little endian byte order. */
void *
-sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf)
+sha512_read_ctx (struct sha512_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
}
void *
-sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf)
+sha384_read_ctx (struct sha512_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
}
void *
-sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf)
+sha512_finish_ctx (struct sha512_ctx *restrict ctx, void *restrict resbuf)
{
sha512_conclude_ctx (ctx);
return sha512_read_ctx (ctx, resbuf);
}
void *
-sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf)
+sha384_finish_ctx (struct sha512_ctx *restrict ctx, void *restrict resbuf)
{
sha512_conclude_ctx (ctx);
return sha384_read_ctx (ctx, resbuf);
output yields to the wanted ASCII representation of the message
digest. */
void *
-sha512_buffer (const char *buffer, size_t len, void *resblock)
+sha512_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct sha512_ctx ctx;
}
void *
-sha384_buffer (const char *buffer, size_t len, void *resblock)
+sha384_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct sha512_ctx ctx;
}
void
-sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx)
+sha512_process_bytes (void const *restrict buffer, size_t len,
+ struct sha512_ctx *restrict ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
Most of this code comes from GnuPG's cipher/sha1.c. */
void
-sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx)
+sha512_process_block (void const *restrict buffer, size_t len,
+ struct sha512_ctx *restrict ctx)
{
u64 const *words = buffer;
u64 const *endp = words + len / sizeof (u64);
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 128!!! */
-extern void sha512_process_block (const void *buffer, size_t len,
- struct sha512_ctx *ctx);
+extern void sha512_process_block (void const *restrict buffer, size_t len,
+ struct sha512_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 128. */
-extern void sha512_process_bytes (const void *buffer, size_t len,
- struct sha512_ctx *ctx);
+extern void sha512_process_bytes (void const *restrict buffer, size_t len,
+ struct sha512_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX
in first 64 (48) bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *restrict resbuf);
-extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *restrict resbuf);
+extern void *sha512_finish_ctx (struct sha512_ctx *restrict ctx,
+ void *restrict resbuf);
+extern void *sha384_finish_ctx (struct sha512_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
-extern void *sha512_read_ctx (const struct sha512_ctx *ctx,
+extern void *sha512_read_ctx (struct sha512_ctx const *restrict ctx,
void *restrict resbuf);
-extern void *sha384_read_ctx (const struct sha512_ctx *ctx,
+extern void *sha384_read_ctx (struct sha512_ctx const *restrict ctx,
void *restrict resbuf);
The result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *sha512_buffer (const char *buffer, size_t len,
+extern void *sha512_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
-extern void *sha384_buffer (const char *buffer, size_t len,
+extern void *sha384_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
# endif
The case that the last operation on STREAM was an 'ungetc' is not supported.
The resulting message digest number will be written into the 64 (48) bytes
beginning at RESBLOCK. */
-extern int sha512_stream (FILE *stream, void *resblock);
-extern int sha384_stream (FILE *stream, void *resblock);
+extern int sha512_stream (FILE *restrict stream, void *restrict resblock);
+extern int sha384_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus
resulting message digest number will be written into the 32 bytes
beginning at RESBLOCK. */
int
-sm3_stream (FILE *stream, void *resblock)
+sm3_stream (FILE *restrict stream, void *restrict resblock)
{
char *buffer = malloc (BLOCKSIZE + 72);
if (!buffer)
/* Put result from CTX in first 32 bytes following RESBUF. The result
must be in little endian byte order. */
void *
-sm3_read_ctx (const struct sm3_ctx *ctx, void *resbuf)
+sm3_read_ctx (struct sm3_ctx const *restrict ctx, void *restrict resbuf)
{
char *r = resbuf;
}
void *
-sm3_finish_ctx (struct sm3_ctx *ctx, void *resbuf)
+sm3_finish_ctx (struct sm3_ctx *restrict ctx, void *restrict resbuf)
{
sm3_conclude_ctx (ctx);
return sm3_read_ctx (ctx, resbuf);
output yields to the wanted ASCII representation of the message
digest. */
void *
-sm3_buffer (const char *buffer, size_t len, void *resblock)
+sm3_buffer (char const *restrict buffer, size_t len, void *restrict resblock)
{
struct sm3_ctx ctx;
}
void
-sm3_process_bytes (const void *buffer, size_t len, struct sm3_ctx *ctx)
+sm3_process_bytes (void const *restrict buffer, size_t len,
+ struct sm3_ctx *restrict ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
Most of this code comes from David Madore's sha256.c. */
void
-sm3_process_block (const void *buffer, size_t len, struct sm3_ctx *ctx)
+sm3_process_block (void const *restrict buffer, size_t len,
+ struct sm3_ctx *restrict ctx)
{
const uint32_t *words = buffer;
size_t nwords = len / sizeof (uint32_t);
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
-extern void sm3_process_block (const void *buffer, size_t len,
- struct sm3_ctx *ctx);
+extern void sm3_process_block (void const *restrict buffer, size_t len,
+ struct sm3_ctx *restrict ctx);
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
-extern void sm3_process_bytes (const void *buffer, size_t len,
- struct sm3_ctx *ctx);
+extern void sm3_process_bytes (void const *restrict buffer, size_t len,
+ struct sm3_ctx *restrict ctx);
/* Process the remaining bytes in the buffer and put result from CTX
in first 32 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */
-extern void *sm3_finish_ctx (struct sm3_ctx *ctx, void *restrict resbuf);
+extern void *sm3_finish_ctx (struct sm3_ctx *restrict ctx,
+ void *restrict resbuf);
/* Put result from CTX in first 32 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */
-extern void *sm3_read_ctx (const struct sm3_ctx *ctx, void *restrict resbuf);
+extern void *sm3_read_ctx (struct sm3_ctx const *restrict ctx,
+ void *restrict resbuf);
/* Compute SM3 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *sm3_buffer (const char *buffer, size_t len,
+extern void *sm3_buffer (char const *restrict buffer, size_t len,
void *restrict resblock);
# endif
/* Compute SM3 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 32 bytes
beginning at RESBLOCK. */
-extern int sm3_stream (FILE *stream, void *resblock);
+extern int sm3_stream (FILE *restrict stream, void *restrict resblock);
# ifdef __cplusplus