Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid C namespace pollution by keeping implementations static #36

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <cpuid.h>
#include <stdint.h>

int aesni_available = -1;
EXPORT int aesni_available = -1;

int aesni_check_available(void)
EXPORT int aesni_check_available(void)
{
unsigned int eax, ebx, ecx, edx;
if(__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
Expand Down Expand Up @@ -224,7 +224,7 @@ static void * align16(void * p)
return (void *) n;
}

int aesniKeySetupEnc(unsigned char * ckey,
EXPORT int aesniKeySetupEnc(unsigned char * ckey,
const unsigned char * key,
int keylength)
{
Expand All @@ -239,7 +239,7 @@ int aesniKeySetupEnc(unsigned char * ckey,
return nrounds;
}

int aesniKeySetupDec(unsigned char * ckey,
EXPORT int aesniKeySetupDec(unsigned char * ckey,
const unsigned char * key,
int keylength)
{
Expand All @@ -257,7 +257,7 @@ int aesniKeySetupDec(unsigned char * ckey,
return nrounds;
}

void aesniEncrypt(const unsigned char * key, int nrounds,
EXPORT void aesniEncrypt(const unsigned char * key, int nrounds,
const unsigned char * in,
unsigned char * out)
{
Expand All @@ -278,7 +278,7 @@ void aesniEncrypt(const unsigned char * key, int nrounds,
_mm_storeu_si128 ((__m128i*) out, t);
}

void aesniDecrypt(const unsigned char * key, int nrounds,
EXPORT void aesniDecrypt(const unsigned char * key, int nrounds,
const unsigned char * in,
unsigned char * out)
{
Expand All @@ -303,24 +303,24 @@ void aesniDecrypt(const unsigned char * key, int nrounds,

int aesni_available = 0;

int aesni_check_available(void) { return 0; }
EXPORT int aesni_check_available(void) { return 0; }

int aesniKeySetupEnc(unsigned char * ckey,
EXPORT int aesniKeySetupEnc(unsigned char * ckey,
const unsigned char * key,
int keylength)
{ abort(); }

int aesniKeySetupDec(unsigned char * ckey,
EXPORT int aesniKeySetupDec(unsigned char * ckey,
const unsigned char * key,
int keylength)
{ abort(); }

void aesniEncrypt(const unsigned char * key, int nrounds,
EXPORT void aesniEncrypt(const unsigned char * key, int nrounds,
const unsigned char * in,
unsigned char * out)
{ abort(); }

void aesniDecrypt(const unsigned char * key, int nrounds,
EXPORT void aesniDecrypt(const unsigned char * key, int nrounds,
const unsigned char * in,
unsigned char * out)
{ abort(); }
Expand Down
12 changes: 6 additions & 6 deletions src/aesni.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@

/* Hardware-accelerated implementation of AES */

extern int aesni_available;
EXPORT int aesni_available;
/* -1: unknown, call aesni_check_available() to determine
0: not available
1: available
*/

extern int aesni_check_available(void);
EXPORT int aesni_check_available(void);

extern int aesniKeySetupEnc(unsigned char * ckey,
EXPORT int aesniKeySetupEnc(unsigned char * ckey,
const unsigned char * key,
int keylength);

extern int aesniKeySetupDec(unsigned char * ckey,
EXPORT int aesniKeySetupDec(unsigned char * ckey,
const unsigned char * key,
int keylength);

extern void aesniEncrypt(const unsigned char * key, int nrounds,
EXPORT void aesniEncrypt(const unsigned char * key, int nrounds,
const unsigned char * in,
unsigned char * out);

extern void aesniDecrypt(const unsigned char * key, int nrounds,
EXPORT void aesniDecrypt(const unsigned char * key, int nrounds,
const unsigned char * in,
unsigned char * out);

Expand Down
6 changes: 2 additions & 4 deletions src/arcfour.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
/* */
/***********************************************************************/

/* $Id$ */

#include "arcfour.h"

void arcfour_cook_key(struct arcfour_key * key,
EXPORT void arcfour_cook_key(struct arcfour_key * key,
unsigned char * key_data,
int key_data_len)
{
Expand All @@ -37,7 +35,7 @@ void arcfour_cook_key(struct arcfour_key * key,
}
}

void arcfour_encrypt(struct arcfour_key * key,
EXPORT void arcfour_encrypt(struct arcfour_key * key,
char * src, char * dst, long len)
{
int x, y, kx, ky;
Expand Down
4 changes: 2 additions & 2 deletions src/arcfour.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ struct arcfour_key
unsigned char x, y;
};

extern void arcfour_cook_key(struct arcfour_key * key,
EXPORT void arcfour_cook_key(struct arcfour_key * key,
unsigned char * key_data,
int key_data_len);

extern void arcfour_encrypt(struct arcfour_key * key,
EXPORT void arcfour_encrypt(struct arcfour_key * key,
char * src, char * dst, long len);

12 changes: 6 additions & 6 deletions src/blake2.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void blake2b_compress(struct blake2b * s, unsigned char * data,
s->h[6] ^= v6 ^ v14; s->h[7] ^= v7 ^ v15;
}

void blake2b_init(struct blake2b * s,
EXPORT void blake2b_init(struct blake2b * s,
int hashlen, int keylen, unsigned char * key)
{
int i;
Expand All @@ -134,7 +134,7 @@ void blake2b_init(struct blake2b * s,
}
}

void blake2b_add_data(struct blake2b * s,
EXPORT void blake2b_add_data(struct blake2b * s,
unsigned char * data, size_t len)
{
int n;
Expand All @@ -161,7 +161,7 @@ void blake2b_add_data(struct blake2b * s,
s->numbytes = len;
}

void blake2b_final(struct blake2b * s, int hashlen, unsigned char * hash)
EXPORT void blake2b_final(struct blake2b * s, int hashlen, unsigned char * hash)
{
unsigned int i;
assert (0 < hashlen && hashlen <= 64);
Expand Down Expand Up @@ -255,7 +255,7 @@ static void blake2s_compress(struct blake2s * s, unsigned char * data,
s->h[6] ^= v6 ^ v14; s->h[7] ^= v7 ^ v15;
}

void blake2s_init(struct blake2s * s,
EXPORT void blake2s_init(struct blake2s * s,
int hashlen, int keylen, unsigned char * key)
{
int i;
Expand All @@ -273,7 +273,7 @@ void blake2s_init(struct blake2s * s,
}
}

void blake2s_add_data(struct blake2s * s,
EXPORT void blake2s_add_data(struct blake2s * s,
unsigned char * data, size_t len)
{
int n;
Expand All @@ -300,7 +300,7 @@ void blake2s_add_data(struct blake2s * s,
s->numbytes = len;
}

void blake2s_final(struct blake2s * s, int hashlen, unsigned char * hash)
EXPORT void blake2s_final(struct blake2s * s, int hashlen, unsigned char * hash)
{
unsigned int i;
assert (0 < hashlen && hashlen <= 32);
Expand Down
12 changes: 6 additions & 6 deletions src/blake2.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ struct blake2b {
unsigned char buffer[BLAKE2b_BLOCKSIZE];
};

extern void blake2b_init(struct blake2b * s,
EXPORT void blake2b_init(struct blake2b * s,
int hashlen, int keylen, unsigned char * key);
extern void blake2b_add_data(struct blake2b * s,
EXPORT void blake2b_add_data(struct blake2b * s,
unsigned char * data, size_t len);
extern void blake2b_final(struct blake2b * s,
EXPORT void blake2b_final(struct blake2b * s,
int hashlen, unsigned char * hash);

#define BLAKE2s_BLOCKSIZE 64
Expand All @@ -38,10 +38,10 @@ struct blake2s {
unsigned char buffer[BLAKE2s_BLOCKSIZE];
};

extern void blake2s_init(struct blake2s * s,
EXPORT void blake2s_init(struct blake2s * s,
int hashlen, int keylen, unsigned char * key);
extern void blake2s_add_data(struct blake2s * s,
EXPORT void blake2s_add_data(struct blake2s * s,
unsigned char * data, size_t len);
extern void blake2s_final(struct blake2s * s,
EXPORT void blake2s_final(struct blake2s * s,
int hashlen, unsigned char * hash);

18 changes: 9 additions & 9 deletions src/blake3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "blake3.h"
#include "blake3_impl.h"

const char *blake3_version(void) { return BLAKE3_VERSION_STRING; }
EXPORT const char *blake3_version(void) { return BLAKE3_VERSION_STRING; }

INLINE void chunk_state_init(blake3_chunk_state *self, const uint32_t key[8],
uint8_t flags) {
Expand Down Expand Up @@ -366,16 +366,16 @@ INLINE void hasher_init_base(blake3_hasher *self, const uint32_t key[8],
self->cv_stack_len = 0;
}

void blake3_hasher_init(blake3_hasher *self) { hasher_init_base(self, IV, 0); }
EXPORT void blake3_hasher_init(blake3_hasher *self) { hasher_init_base(self, IV, 0); }

void blake3_hasher_init_keyed(blake3_hasher *self,
EXPORT void blake3_hasher_init_keyed(blake3_hasher *self,
const uint8_t key[BLAKE3_KEY_LEN]) {
uint32_t key_words[8];
load_key_words(key, key_words);
hasher_init_base(self, key_words, KEYED_HASH);
}

void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
EXPORT void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
size_t context_len) {
blake3_hasher context_hasher;
hasher_init_base(&context_hasher, IV, DERIVE_KEY_CONTEXT);
Expand All @@ -387,7 +387,7 @@ void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
hasher_init_base(self, context_key_words, DERIVE_KEY_MATERIAL);
}

void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context) {
EXPORT void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context) {
blake3_hasher_init_derive_key_raw(self, context, strlen(context));
}

Expand Down Expand Up @@ -452,7 +452,7 @@ INLINE void hasher_push_cv(blake3_hasher *self, uint8_t new_cv[BLAKE3_OUT_LEN],
self->cv_stack_len += 1;
}

void blake3_hasher_update(blake3_hasher *self, const void *input,
EXPORT void blake3_hasher_update(blake3_hasher *self, const void *input,
size_t input_len) {
// Explicitly checking for zero avoids causing UB by passing a null pointer
// to memcpy. This comes up in practice with things like:
Expand Down Expand Up @@ -561,12 +561,12 @@ void blake3_hasher_update(blake3_hasher *self, const void *input,
}
}

void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
EXPORT void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
size_t out_len) {
blake3_hasher_finalize_seek(self, 0, out, out_len);
}

void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
EXPORT void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
uint8_t *out, size_t out_len) {
// Explicitly checking for zero avoids causing UB by passing a null pointer
// to memcpy. This comes up in practice with things like:
Expand Down Expand Up @@ -610,7 +610,7 @@ void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
output_root_bytes(&output, seek, out, out_len);
}

void blake3_hasher_reset(blake3_hasher *self) {
EXPORT void blake3_hasher_reset(blake3_hasher *self) {
chunk_state_reset(&self->chunk, self->key, 0);
self->cv_stack_len = 0;
}
30 changes: 15 additions & 15 deletions src/blake3.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
EXPORT "C" {
#endif

#define BLAKE3_VERSION_STRING "1.3.1"
Expand Down Expand Up @@ -38,20 +38,20 @@ typedef struct {
uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
} blake3_hasher;

const char *blake3_version(void);
void blake3_hasher_init(blake3_hasher *self);
void blake3_hasher_init_keyed(blake3_hasher *self,
const uint8_t key[BLAKE3_KEY_LEN]);
void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context);
void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
size_t context_len);
void blake3_hasher_update(blake3_hasher *self, const void *input,
size_t input_len);
void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
size_t out_len);
void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
uint8_t *out, size_t out_len);
void blake3_hasher_reset(blake3_hasher *self);
EXPORT const char *blake3_version(void);
EXPORT void blake3_hasher_init(blake3_hasher *self);
EXPORT void blake3_hasher_init_keyed(blake3_hasher *self,
const uint8_t key[BLAKE3_KEY_LEN]);
EXPORT void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context);
EXPORT void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
size_t context_len);
EXPORT void blake3_hasher_update(blake3_hasher *self, const void *input,
size_t input_len);
EXPORT void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
size_t out_len);
EXPORT void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
uint8_t *out, size_t out_len);
EXPORT void blake3_hasher_reset(blake3_hasher *self);

#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions src/blake3_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static
}
}

void blake3_compress_in_place(uint32_t cv[8],
EXPORT void blake3_compress_in_place(uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len, uint64_t counter,
uint8_t flags) {
Expand Down Expand Up @@ -162,7 +162,7 @@ void blake3_compress_in_place(uint32_t cv[8],
blake3_compress_in_place_portable(cv, block, block_len, counter, flags);
}

void blake3_compress_xof(const uint32_t cv[8],
EXPORT void blake3_compress_xof(const uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len, uint64_t counter, uint8_t flags,
uint8_t out[64]) {
Expand Down Expand Up @@ -191,7 +191,7 @@ void blake3_compress_xof(const uint32_t cv[8],
blake3_compress_xof_portable(cv, block, block_len, counter, flags, out);
}

void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs,
EXPORT void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs,
size_t blocks, const uint32_t key[8], uint64_t counter,
bool increment_counter, uint8_t flags,
uint8_t flags_start, uint8_t flags_end, uint8_t *out) {
Expand Down Expand Up @@ -244,7 +244,7 @@ void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs,
}

// The dynamically detected SIMD degree of the current platform.
size_t blake3_simd_degree(void) {
EXPORT size_t blake3_simd_degree(void) {
#if defined(IS_X86)
const enum cpu_feature features = get_cpu_features();
MAYBE_UNUSED(features);
Expand Down
Loading