diff --git a/Makefile b/Makefile index 409ed6e..deef854 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -CFLAGS += -Wall -g -O2 +CFLAGS += -m64 -std=c99 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual \ + -Wstrict-prototypes -Wmissing-prototypes -g -O2 SRCS = hazmat.c randombytes.c sss.c tweetnacl.c OBJS := ${SRCS:.c=.o} diff --git a/sss.c b/sss.c index 4b5e284..763c579 100644 --- a/sss.c +++ b/sss.c @@ -38,23 +38,41 @@ static const unsigned char nonce[crypto_secretbox_NONCEBYTES] = { 0 }; /* - * Return a pointer to the ciphertext part of this Share + * Return a mutable pointer to the ciphertext part of this Share */ -static uint8_t* get_ciphertext(const sss_Share *share) +static uint8_t* get_ciphertext(sss_Share *share) { - return (uint8_t*) &(*share)[sss_KEYSHARE_LEN]; + return &((uint8_t*) share)[sss_KEYSHARE_LEN]; } /* - * Return a pointer to the Keyshare part of this Share + * Return a mutable pointer to the Keyshare part of this Share */ -static sss_Keyshare* get_keyshare(const sss_Share *share) +static sss_Keyshare* get_keyshare(sss_Share *share) { return (sss_Keyshare*) &share[0]; } +/* + * Return a const pointer to the ciphertext part of this Share + */ +static const uint8_t* get_ciphertext_const(const sss_Share *share) +{ + return &((const uint8_t*) share)[sss_KEYSHARE_LEN]; +} + + +/* + * Return a const pointer to the Keyshare part of this Share + */ +static const sss_Keyshare* get_keyshare_const(const sss_Share *share) +{ + return (const sss_Keyshare*) &share[0]; +} + + /* * Create `n` shares with theshold `k` and write them to `out` */ @@ -82,9 +100,9 @@ void sss_create_shares(sss_Share *out, const unsigned char *data, /* Build regular shares */ for (idx = 0; idx < n; idx++) { - memcpy(get_keyshare((const sss_Share*) &out[idx]), &keyshares[idx][0], + memcpy(get_keyshare((sss_Share*) &out[idx]), &keyshares[idx][0], sss_KEYSHARE_LEN); - memcpy(get_ciphertext((const sss_Share*) &out[idx]), + memcpy(get_ciphertext((sss_Share*) &out[idx]), &c[crypto_secretbox_BOXZEROBYTES], sss_CLEN); } } @@ -110,15 +128,15 @@ int sss_combine_shares(uint8_t *data, const sss_Share *shares, uint8_t k) /* Check if all ciphertexts are the same */ if (k < 1) return -1; for (idx = 1; idx < k; idx++) { - if (memcmp(get_ciphertext(&shares[0]), - get_ciphertext(&shares[idx]), sss_CLEN) != 0) { + if (memcmp(get_ciphertext_const(&shares[0]), + get_ciphertext_const(&shares[idx]), sss_CLEN) != 0) { return -1; } } /* Restore the key */ for (idx = 0; idx < k; idx++) { - memcpy(&keyshares[idx], get_keyshare(&shares[idx]), + memcpy(&keyshares[idx], get_keyshare_const(&shares[idx]), sss_KEYSHARE_LEN); } sss_combine_keyshares(key, (const sss_Keyshare*) keyshares, k); diff --git a/test_hazmat.c b/test_hazmat.c index f9bc97a..e2141e1 100644 --- a/test_hazmat.c +++ b/test_hazmat.c @@ -3,7 +3,7 @@ #include -static void test_key_shares() +static void test_key_shares(void) { uint8_t key[32], restored[32]; sss_Keyshare key_shares[256]; @@ -31,7 +31,7 @@ static void test_key_shares() } -int main() +int main(void) { test_key_shares(); return 0; diff --git a/test_sss.c b/test_sss.c index 04d2fed..9435f57 100644 --- a/test_sss.c +++ b/test_sss.c @@ -2,7 +2,7 @@ #include #include -int main() +int main(void) { unsigned char data[sss_MLEN] = { 42 }, restored[sss_MLEN]; sss_Share shares[256];