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/des.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

131 lines
3.9 KiB
C

/* des.h --- DES cipher implementation.
* Copyright (C) 2005, 2007, 2009-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/>.
*
*/
/* Adapted for gnulib by Simon Josefsson, based on Libgcrypt. */
#ifndef DES_H
#define DES_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Encryption/Decryption context of DES
*/
typedef struct
{
uint32_t encrypt_subkeys[32];
uint32_t decrypt_subkeys[32];
} gl_des_ctx;
/*
* Encryption/Decryption context of Triple-DES
*/
typedef struct
{
uint32_t encrypt_subkeys[96];
uint32_t decrypt_subkeys[96];
} gl_3des_ctx;
/* Check whether the 8 byte key is weak. Does not check the parity
* bits of the key but simple ignore them. */
extern bool
gl_des_is_weak_key (const char * key);
/*
* DES
* ---
*/
/* Fill a DES context CTX with subkeys calculated from 64bit KEY.
* Does not check parity bits, but simply ignore them. Does not check
* for weak keys. */
extern void
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 *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 *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)
/* Triple-DES
* ----------
*/
/* Fill a Triple-DES context CTX with subkeys calculated from two
* 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 *restrict ctx,
char const *restrict key1,
char const *restrict key2);
/*
* Fill a Triple-DES context CTX with subkeys calculated from three
* 64bit keys in KEY1, KEY2 and KEY3. Does not check the parity bits
* of the keys, but simply ignore them. Does not check for weak
* keys. */
extern void
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 *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 *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)
#define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1)
#ifdef __cplusplus
}
#endif
#endif /* DES_H */