crypto: guard #defines with #ifndef

This commit is contained in:
Michael Scire 2019-04-04 10:46:29 -07:00 committed by fincs
parent c3a94f5bce
commit 16f8255fd5
4 changed files with 35 additions and 0 deletions

View File

@ -6,16 +6,36 @@
#pragma once
#include "../types.h"
#ifndef AES_BLOCK_SIZE
#define AES_BLOCK_SIZE 0x10
#endif
#ifndef AES_128_KEY_SIZE
#define AES_128_KEY_SIZE 0x10
#endif
#ifndef AES_128_U32_PER_KEY
#define AES_128_U32_PER_KEY (AES_128_KEY_SIZE / sizeof(u32))
#endif
#ifndef AES_128_NUM_ROUNDS
#define AES_128_NUM_ROUNDS 10
#endif
#ifndef AES_192_KEY_SIZE
#define AES_192_KEY_SIZE 0x18
#endif
#ifndef AES_192_U32_PER_KEY
#define AES_192_U32_PER_KEY (AES_192_KEY_SIZE / sizeof(u32))
#endif
#ifndef AES_192_NUM_ROUNDS
#define AES_192_NUM_ROUNDS 12
#endif
#ifndef AES_256_KEY_SIZE
#define AES_256_KEY_SIZE 0x20
#endif
#ifndef AES_256_U32_PER_KEY
#define AES_256_U32_PER_KEY (AES_256_KEY_SIZE / sizeof(u32))
#endif
#ifndef AES_256_NUM_ROUNDS
#define AES_256_NUM_ROUNDS 14
#endif
/// Context for AES-128 operations.
typedef struct {

View File

@ -23,8 +23,12 @@ typedef struct {
bool finalized;
} HmacSha256Context;
#ifndef HMAC_SHA1_KEY_MAX
#define HMAC_SHA1_KEY_MAX (sizeof(((HmacSha1Context *)NULL)->key))
#endif
#ifndef HMAC_SHA256_KEY_MAX
#define HMAC_SHA256_KEY_MAX (sizeof(((HmacSha256Context *)NULL)->key))
#endif
/// Initialize a HMAC-SHA256 context.
void hmacSha256ContextCreate(HmacSha256Context *out, const void *key, size_t key_size);

View File

@ -6,8 +6,13 @@
#pragma once
#include "../types.h"
#ifndef SHA1_HASH_SIZE
#define SHA1_HASH_SIZE 0x14
#endif
#ifndef SHA1_BLOCK_SIZE
#define SHA1_BLOCK_SIZE 0x40
#endif
/// Context for SHA1 operations.
typedef struct {

View File

@ -6,8 +6,14 @@
#pragma once
#include "../types.h"
#ifndef SHA256_HASH_SIZE
#define SHA256_HASH_SIZE 0x20
#endif
#ifndef SHA256_BLOCK_SIZE
#define SHA256_BLOCK_SIZE 0x40
#endif
/// Context for SHA256 operations.
typedef struct {