Shuffle headers

Make whitespace, sections and layouts consistent. Increase entropy.
This commit is contained in:
Lucas Gabriel Vuotto 2024-06-27 12:29:39 +00:00
parent ac13dbe9cf
commit 546649da1d
2 changed files with 84 additions and 80 deletions

View File

@ -24,14 +24,16 @@
* CONSTANTS
*/
/* Authentitcation. */
/* Authentitcation */
#define HMAC_BLOCKLEN_MAX LC_SHA512_BLOCKLEN
#define HMAC_HASHLEN_MAX LC_SHA512_HASHLEN
#define POLY1305_TAGLEN_WORDS (LC_POLY1305_TAGLEN / sizeof(uint32_t))
/* Ciphers. */
/* Ciphers */
#define CHACHA20_BLOCKLEN_WORDS (LC_CHACHA20_BLOCKLEN / sizeof(uint32_t))
#define CHACHA20_CTRMAX 4294967295 /* 2^32 - 1 */
@ -39,7 +41,8 @@
#define CHACHA20_NONCE_WORDS 4
#define CHACHA20_ROUNDS 10
/* Hashes. */
/* Hashes */
#define SHA256_BLOCKLEN_WORDS (LC_SHA256_BLOCKLEN / sizeof(uint32_t))
#define SHA256_ROUNDS 64
@ -152,11 +155,13 @@ struct lc_hash_ctx {
void *arg;
};
/*
* *_state holds the internal state of the cryptographic algorithms.
*/
/* AEAD. */
/* AEAD */
struct chacha20_poly1305_state {
struct lc_auth_ctx *auth;
@ -166,7 +171,8 @@ struct chacha20_poly1305_state {
int aaddone;
};
/* Authentication. */
/* Authentication */
struct hmac_state {
struct lc_hash_ctx *hash;
@ -183,7 +189,7 @@ struct poly1305_state {
};
/* Ciphers. */
/* Ciphers */
struct chacha20_state {
uint32_t s[CHACHA20_BLOCKLEN_WORDS];
@ -194,7 +200,7 @@ struct chacha20_state {
};
/* Hashes. */
/* Hashes */
struct sha256_state {
uint32_t h0, h1, h2, h3, h4, h5, h6, h7;
@ -211,25 +217,25 @@ struct sha512_state {
};
/*
* PROTOTYPES
*/
/* Authentitcation. */
/* Authentitcation */
void poly1305_block(struct poly1305_state *, uint32_t);
void poly1305_reduce(struct poly1305_state *,
uint32_t [POLY1305_TAGLEN_WORDS]);
/* Ciphers. */
/* Ciphers */
void chacha20_block(struct chacha20_state *);
void hchacha20_block(struct chacha20_state *);
/* Hashes. */
/* Hashes */
void sha256_block(struct sha256_state *);

View File

@ -23,10 +23,29 @@
/*
* Constants.
* CONSTANTS
*/
/* Hashes. */
/* Authentitcation */
#define LC_POLY1305_BLOCKLEN 16
#define LC_POLY1305_KEYLEN 32
#define LC_POLY1305_TAGLEN 16
/* Ciphers */
#define LC_CHACHA20_BLOCKLEN 64
#define LC_CHACHA20_KEYLEN 32
#define LC_CHACHA20_NONCELEN 12
#define LC_XCHACHA20_BLOCKLEN 64
#define LC_XCHACHA20_KEYLEN 32
#define LC_XCHACHA20_NONCELEN 24
/* Hashes */
#define LC_SHA224_BLOCKLEN 64
#define LC_SHA224_HASHLEN 28
#define LC_SHA256_BLOCKLEN 64
@ -40,24 +59,12 @@
#define LC_SHA512_256_BLOCKLEN 128
#define LC_SHA512_256_HASHLEN 32
/* Authentitcation. */
#define LC_POLY1305_BLOCKLEN 16
#define LC_POLY1305_KEYLEN 32
#define LC_POLY1305_TAGLEN 16
/* Ciphers. */
#define LC_CHACHA20_BLOCKLEN 64
#define LC_CHACHA20_KEYLEN 32
#define LC_CHACHA20_NONCELEN 12
#define LC_XCHACHA20_BLOCKLEN 64
#define LC_XCHACHA20_KEYLEN 32
#define LC_XCHACHA20_NONCELEN 24
/*
* Structs.
* STRUCTS
*/
struct lc_aead_ctx;
struct lc_aead_impl;
@ -72,37 +79,8 @@ struct lc_hash_impl;
struct lc_kdf_impl;
/*
* Parameters.
*/
/* Authentication. */
struct lc_hmac_params {
struct lc_hash_ctx *hash;
size_t keylen;
uint8_t *key;
};
struct lc_poly1305_params {
uint8_t key[LC_POLY1305_KEYLEN];
};
/* Ciphers. */
struct lc_chacha20_params {
uint8_t key[LC_CHACHA20_KEYLEN];
uint8_t nonce[LC_CHACHA20_NONCELEN];
uint32_t counter;
};
struct lc_xchacha20_params {
uint8_t key[LC_XCHACHA20_KEYLEN];
uint8_t nonce[LC_XCHACHA20_NONCELEN];
uint32_t counter;
};
/* AEAD. */
/* AEAD parameters */
struct lc_chacha20_poly1305_params {
struct lc_auth_ctx *auth;
@ -118,7 +96,36 @@ struct lc_xchacha20_poly1305_params {
uint8_t nonce[LC_XCHACHA20_NONCELEN];
};
/* KDF. */
/* Authentication parameters */
struct lc_hmac_params {
struct lc_hash_ctx *hash;
size_t keylen;
uint8_t *key;
};
struct lc_poly1305_params {
uint8_t key[LC_POLY1305_KEYLEN];
};
/* Ciphers parameters */
struct lc_chacha20_params {
uint8_t key[LC_CHACHA20_KEYLEN];
uint8_t nonce[LC_CHACHA20_NONCELEN];
uint32_t counter;
};
struct lc_xchacha20_params {
uint8_t key[LC_XCHACHA20_KEYLEN];
uint8_t nonce[LC_XCHACHA20_NONCELEN];
uint32_t counter;
};
/* KDF parameters */
struct lc_hkdf_params {
struct lc_hash_ctx *hash;
@ -133,16 +140,17 @@ struct lc_hkdf_params {
/*
* Constant-time operations.
* PROTOTYPES
*/
/* Constant-time operations */
uint32_t lc_ct_cmp(const uint8_t *, const uint8_t *, size_t);
uint32_t lc_ct_mask32(uint32_t);
/*
* Hashes.
*/
/* Hashes */
int lc_hash_init(struct lc_hash_ctx *);
int lc_hash_update(struct lc_hash_ctx *, const uint8_t *, size_t);
@ -161,9 +169,7 @@ const struct lc_hash_impl *lc_hash_impl_sha512_224(void);
const struct lc_hash_impl *lc_hash_impl_sha512_256(void);
/*
* Authentication.
*/
/* Authentication */
int lc_auth_init(struct lc_auth_ctx *, void *);
int lc_auth_update(struct lc_auth_ctx *, const uint8_t *, size_t);
@ -178,9 +184,7 @@ const struct lc_auth_impl *lc_auth_impl_hmac(void);
const struct lc_auth_impl *lc_auth_impl_poly1305(void);
/*
* Ciphers.
*/
/* Ciphers */
int lc_cipher_encrypt_init(struct lc_cipher_ctx *, void *);
int lc_cipher_encrypt_update(struct lc_cipher_ctx *, uint8_t *, size_t *,
@ -202,16 +206,13 @@ const struct lc_cipher_impl *lc_cipher_impl_chacha20(void);
const struct lc_cipher_impl *lc_cipher_impl_xchacha20(void);
/*
* Authenticated encryption with additional data.
*/
/* Authenticated encryption with additional data */
int lc_aead_seal_init(struct lc_aead_ctx *, void *);
int lc_aead_seal_update(struct lc_aead_ctx *, uint8_t *, size_t *,
const uint8_t *, size_t, const uint8_t *, size_t);
int lc_aead_seal_final(struct lc_aead_ctx *, uint8_t *, size_t *, uint8_t *,
size_t *);
int lc_aead_seal_final(struct lc_aead_ctx *, uint8_t *, size_t *,
uint8_t *, size_t *);
int lc_aead_seal(const struct lc_aead_impl *, uint8_t *, size_t *,
uint8_t *, size_t *, void *, const uint8_t *, size_t,
const uint8_t *, size_t);
@ -231,9 +232,7 @@ const struct lc_aead_impl *lc_aead_impl_chacha20_poly1305(void);
const struct lc_aead_impl *lc_aead_impl_xchacha20_poly1305(void);
/*
* Key derivation functions.
*/
/* Key derivation functions */
int lc_kdf(const struct lc_kdf_impl *, uint8_t *, size_t *, void *,
size_t);
@ -241,11 +240,10 @@ int lc_kdf(const struct lc_kdf_impl *, uint8_t *, size_t *, void *,
const struct lc_kdf_impl *lc_kdf_impl_hkdf(void);
/*
* Utilities.
*/
/* Utilities */
int lc_hexdump_fp(FILE *, const void *, size_t);
void lc_scrub(void *, size_t);
#endif /* LILCRYPTO_H */