Makefile: add a lot of $(CC) warnings

See also: dsprenkels/randombytes@fb97f5b4b4
This commit is contained in:
Daan Sprenkels
2017-10-30 12:18:19 +01:00
parent 0de9c12308
commit 95c75d4d50
4 changed files with 33 additions and 14 deletions

View File

@@ -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 SRCS = hazmat.c randombytes.c sss.c tweetnacl.c
OBJS := ${SRCS:.c=.o} OBJS := ${SRCS:.c=.o}

38
sss.c
View File

@@ -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 (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` * 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 */ /* Build regular shares */
for (idx = 0; idx < n; idx++) { 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); sss_KEYSHARE_LEN);
memcpy(get_ciphertext((const sss_Share*) &out[idx]), memcpy(get_ciphertext((sss_Share*) &out[idx]),
&c[crypto_secretbox_BOXZEROBYTES], sss_CLEN); &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 */ /* Check if all ciphertexts are the same */
if (k < 1) return -1; if (k < 1) return -1;
for (idx = 1; idx < k; idx++) { for (idx = 1; idx < k; idx++) {
if (memcmp(get_ciphertext(&shares[0]), if (memcmp(get_ciphertext_const(&shares[0]),
get_ciphertext(&shares[idx]), sss_CLEN) != 0) { get_ciphertext_const(&shares[idx]), sss_CLEN) != 0) {
return -1; return -1;
} }
} }
/* Restore the key */ /* Restore the key */
for (idx = 0; idx < k; idx++) { 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_KEYSHARE_LEN);
} }
sss_combine_keyshares(key, (const sss_Keyshare*) keyshares, k); sss_combine_keyshares(key, (const sss_Keyshare*) keyshares, k);

View File

@@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
static void test_key_shares() static void test_key_shares(void)
{ {
uint8_t key[32], restored[32]; uint8_t key[32], restored[32];
sss_Keyshare key_shares[256]; sss_Keyshare key_shares[256];
@@ -31,7 +31,7 @@ static void test_key_shares()
} }
int main() int main(void)
{ {
test_key_shares(); test_key_shares();
return 0; return 0;

View File

@@ -2,7 +2,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
int main() int main(void)
{ {
unsigned char data[sss_MLEN] = { 42 }, restored[sss_MLEN]; unsigned char data[sss_MLEN] = { 42 }, restored[sss_MLEN];
sss_Share shares[256]; sss_Share shares[256];