Skip to content

Commit

Permalink
all: fix sizeof, spurious spaces before/after brackets
Browse files Browse the repository at this point in the history
Automated find and replace in-place with:

* perl -pi -e 's/ \)/\)/' *
* perl -pi -e 's/\( /\(/' *

to make for more consistent code to improve
readability.

Also made consistent of invoking
    sizeof(expr)

instead of

    sizeof expr

Fixes #12
  • Loading branch information
odeke-em authored and diagprov committed Jan 9, 2020
1 parent 9e661c3 commit 679372c
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 226 deletions.
8 changes: 4 additions & 4 deletions include/e4/pstdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ extern "C" {
* do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
*/

#if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
#if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)))) && !defined (_PSTDINT_H_INCLUDED)
#include <stdint.h>
#define _PSTDINT_H_INCLUDED
# if defined(__GNUC__) && (defined(__x86_64__) || defined(__ppc64__)) && !(defined(__APPLE__) && defined(__MACH__))
Expand Down Expand Up @@ -787,7 +787,7 @@ typedef uint_least32_t uint_fast32_t;
# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
# endif
typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
typedef stdint_intptr_glue3(int,stdint_intptr_bits,_t) intptr_t;
# else
/* TODO -- This following is likely wrong for some platforms, and does
nothing for the definition of uintptr_t. */
Expand All @@ -801,7 +801,7 @@ typedef uint_least32_t uint_fast32_t;
*/

#ifndef SIG_ATOMIC_MAX
# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof(sig_atomic_t)*CHAR_BIT-1)) - 1)
#endif

#endif
Expand Down Expand Up @@ -894,7 +894,7 @@ int main () {
#endif

#define STR(v) #v
#define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof (v));
#define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof(v));
if (err_n) {
printf ("pstdint.h is not correct. Please use sizes below to correct it:\n");
}
Expand Down
2 changes: 1 addition & 1 deletion include/e4/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
#define ZERO(X) \
do \
{ \
zeroize(&X, sizeof X); \
zeroize(&X, sizeof(X)); \
} while (0)
#endif

Expand Down
6 changes: 3 additions & 3 deletions mk/pubkey/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $(TESTDIR)/util: $(TESTOBJDIR)/util.$O
$(TESTDIR)/crypto: $(TESTOBJDIR)/crypto.$O
$(CC) $(TESTLDFLAGS) $< $(LIB) -o $@

$(TESTDIR)/siv_kats_the_musical: $(TESTOBJDIR)/siv.$O
$(TESTDIR)/siv_kat: $(TESTOBJDIR)/siv.$O
$(CC) $(TESTLDFLAGS) $< $(LIB) -o $@

$(TESTDIR)/pubkey_file: $(TESTOBJDIR)/pubkey_file.$O
Expand All @@ -54,7 +54,7 @@ $(TESTDIR)/ed25519_test: $(TESTOBJDIR)/ed25519_test.$O
PUBKEY_TESTS = \
$(TESTDIR)/util \
$(TESTDIR)/crypto \
$(TESTDIR)/siv_kats_the_musical \
$(TESTDIR)/siv_kat \
$(TESTDIR)/pubkey_file \
$(TESTDIR)/pubkey_e4cmd \
$(TESTDIR)/pubkey_e4topicmsg \
Expand All @@ -65,7 +65,7 @@ E4TESTS += $(PUBKEY_TESTS)
testexec_pk:
./$(TESTDIR)/util
./$(TESTDIR)/crypto
./$(TESTDIR)/siv_kats_the_musical
./$(TESTDIR)/siv_kat
./$(TESTDIR)/pubkey_file
./$(TESTDIR)/pubkey_e4cmd
./$(TESTDIR)/pubkey_e4topicmsg
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/curve25519/curve25519-donna.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ swap_conditional(limb a[19], limb b[19], limb iswap) {
const s32 swap = (s32) -iswap;

for (i = 0; i < 10; ++i) {
const s32 x = swap & ( ((s32)a[i]) ^ ((s32)b[i]) );
const s32 x = swap & (((s32)a[i]) ^ ((s32)b[i]));
a[i] = ((s32)a[i]) ^ x;
b[i] = ((s32)b[i]) ^ x;
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/ed25519/fixedint.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Not a compatible replacement for <stdint.h>, do not blindly use it as such.
*/

#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED)
#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)))) && !defined(FIXEDINT_H_INCLUDED)
#include <stdint.h>
#define FIXEDINT_H_INCLUDED

Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static const uint64_t K[80] = {
/* Various logical functions */

#define ROR64c(x, y) \
( ((((x)&UINT64_C(0xFFFFFFFFFFFFFFFF))>>((uint64_t)(y)&UINT64_C(63))) | \
(((((x)&UINT64_C(0xFFFFFFFFFFFFFFFF))>>((uint64_t)(y)&UINT64_C(63))) | \
((x)<<((uint64_t)(64-((y)&UINT64_C(63)))))) & UINT64_C(0xFFFFFFFFFFFFFFFF))

#define STORE64H(x, y) \
Expand All @@ -84,7 +84,7 @@ static const uint64_t K[80] = {
#define Gamma0(x) (S(x, 1) ^ S(x, 8) ^ R(x, 7))
#define Gamma1(x) (S(x, 19) ^ S(x, 61) ^ R(x, 6))
#ifndef MIN
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
#define MIN(x, y) (((x)<(y))?(x):(y))
#endif

/* compress 1024-bits */
Expand Down
72 changes: 36 additions & 36 deletions src/e4c_pk_store_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ int e4c_load(e4storage *store, const char *path)
return E4_ERROR_PERSISTENCE_ERROR;
}

memset(mbuf, 0, sizeof mbuf);
rlen = read(fd, mbuf, sizeof E4V2_MAGIC);
if (rlen != sizeof E4V2_MAGIC)
memset(mbuf, 0, sizeof(mbuf));
rlen = read(fd, mbuf, sizeof(E4V2_MAGIC));
if (rlen != sizeof(E4V2_MAGIC))
{
goto err;
}
if (memcmp(mbuf, E4V2_MAGIC, sizeof E4V2_MAGIC) != 0)
if (memcmp(mbuf, E4V2_MAGIC, sizeof(E4V2_MAGIC)) != 0)
{
goto err;
}

rlen = read(fd, store->id, sizeof store->id);
if (rlen != sizeof store->id)
rlen = read(fd, store->id, sizeof(store->id));
if (rlen != sizeof(store->id))
{
goto err;
}
Expand All @@ -104,25 +104,25 @@ int e4c_load(e4storage *store, const char *path)
e4c_derive_topichash(store->ctrltopic, E4_TOPICHASH_LEN, controltopic);

/* read in key material */
rlen = read(fd, store->privkey, sizeof store->privkey);
if (rlen != sizeof store->privkey)
rlen = read(fd, store->privkey, sizeof(store->privkey));
if (rlen != sizeof(store->privkey))
{
goto err;
}
rlen = read(fd, store->pubkey, sizeof store->pubkey);
if (rlen != sizeof store->pubkey)
rlen = read(fd, store->pubkey, sizeof(store->pubkey));
if (rlen != sizeof(store->pubkey))
{
goto err;
}

rlen = read(fd, store->c2key, sizeof store->c2key);
if (rlen != sizeof store->c2key)
rlen = read(fd, store->c2key, sizeof(store->c2key));
if (rlen != sizeof(store->c2key))
{
goto err;
}

rlen = read(fd, &store->topiccount, sizeof store->topiccount);
if (rlen != sizeof store->topiccount)
rlen = read(fd, &store->topiccount, sizeof(store->topiccount));
if (rlen != sizeof(store->topiccount))
{
goto err;
}
Expand All @@ -145,8 +145,8 @@ int e4c_load(e4storage *store, const char *path)
}
}

rlen = read(fd, &store->devicecount, sizeof store->devicecount);
if (rlen != sizeof store->devicecount)
rlen = read(fd, &store->devicecount, sizeof(store->devicecount));
if (rlen != sizeof(store->devicecount))
{
goto err;
}
Expand Down Expand Up @@ -195,28 +195,28 @@ int e4c_sync(e4storage *store)
return E4_ERROR_PERSISTENCE_ERROR;
}

write(fd, E4V2_MAGIC, sizeof E4V2_MAGIC);
write(fd, store->id, sizeof store->id);
write(fd, store->privkey, sizeof store->privkey);
write(fd, store->pubkey, sizeof store->pubkey);
write(fd, store->c2key, sizeof store->c2key);
write(fd, &store->topiccount, sizeof store->topiccount);
write(fd, E4V2_MAGIC, sizeof(E4V2_MAGIC));
write(fd, store->id, sizeof(store->id));
write(fd, store->privkey, sizeof(store->privkey));
write(fd, store->pubkey, sizeof(store->pubkey));
write(fd, store->c2key, sizeof(store->c2key));
write(fd, &store->topiccount, sizeof(store->topiccount));

for (i = 0; i < store->topiccount; i++)
{
topic_key *t = &(store->topics[0]) + i;

write(fd, t->topic, sizeof t->topic);
write(fd, t->key, sizeof t->key);
write(fd, t->topic, sizeof(t->topic));
write(fd, t->key, sizeof(t->key));
}
write(fd, &store->devicecount, sizeof store->devicecount);
write(fd, &store->devicecount, sizeof(store->devicecount));

for (i = 0; i < store->devicecount; i++)
{
device_key *d = &(store->devices[0]) + i;

write(fd, d->id, sizeof d->id);
write(fd, d->pubkey, sizeof d->pubkey);
write(fd, d->id, sizeof(d->id));
write(fd, d->pubkey, sizeof(d->pubkey));
}
close(fd);

Expand All @@ -230,33 +230,33 @@ int e4c_set_id(e4storage *store, const uint8_t *id)
ZERO(controltopic);

r = e4c_derive_control_topic(controltopic, E4_CTRLTOPIC_LEN + 1, id);
if ( r != E4_RESULT_OK ) goto exit;
if (r != E4_RESULT_OK) goto exit;

r = e4c_derive_topichash(store->ctrltopic, E4_TOPICHASH_LEN, controltopic);
if ( r != E4_RESULT_OK ) {
if (r != E4_RESULT_OK) {
ZERO(store->ctrltopic);
goto exit;
}

memmove(store->id, id, sizeof store->id);
memmove(store->id, id, sizeof(store->id));
r = E4_RESULT_OK;
exit:
return r;
}
int e4c_set_idseckey(e4storage *store, const uint8_t *key)
{
memmove(store->privkey, key, sizeof store->privkey);
memmove(store->privkey, key, sizeof(store->privkey));
e4c_sync(store);
return E4_RESULT_OK;
}

int e4c_get_idseckey(e4storage* store, uint8_t *key) {
memcpy(key, store->privkey, sizeof store->privkey);
memcpy(key, store->privkey, sizeof(store->privkey));
return 0;
}

int e4c_get_idpubkey(e4storage* store, uint8_t *key) {
memcpy(key, store->pubkey, sizeof store->pubkey);
memcpy(key, store->pubkey, sizeof(store->pubkey));
return 0;
}

Expand Down Expand Up @@ -362,7 +362,7 @@ int e4c_reset_topics(e4storage *store)
{
store->topiccount = 0;
}
for ( i=0 ; i < E4_TOPICS_MAX ; i++ ) {
for (i=0 ; i < E4_TOPICS_MAX ; i++) {
ZERO(store->topics[i]);
}

Expand All @@ -371,7 +371,7 @@ int e4c_reset_topics(e4storage *store)
}

int e4c_set_idpubkey(e4storage *store, const uint8_t *pubkey) {
memmove(store->pubkey, pubkey, sizeof store->pubkey);
memmove(store->pubkey, pubkey, sizeof(store->pubkey));
e4c_sync(store);
return E4_RESULT_OK;
}
Expand Down Expand Up @@ -460,7 +460,7 @@ int e4c_reset_devices(e4storage* store)
store->devicecount = 0;
}
/* Attempt to zero memory. This may not work depending on the platform */
for ( i=0 ; i < E4_DEVICES_MAX ; i++ ) {
for (i=0 ; i < E4_DEVICES_MAX ; i++) {
ZERO(store->devices[i]);
}

Expand Down
18 changes: 9 additions & 9 deletions src/e4c_pk_store_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,34 @@ int e4c_set_id(e4storage *store, const uint8_t *id)
ZERO(controltopic);

r = e4c_derive_control_topic(controltopic, E4_CTRLTOPIC_LEN + 1, id);
if ( r != E4_RESULT_OK ) goto exit;
if (r != E4_RESULT_OK) goto exit;

r = e4c_derive_topichash(store->ctrltopic, E4_TOPICHASH_LEN, controltopic);
if ( r != E4_RESULT_OK ) {
if (r != E4_RESULT_OK) {
ZERO(store->ctrltopic);
goto exit;
}

memmove(store->id, id, sizeof store->id);
memmove(store->id, id, sizeof(store->id));
r = E4_RESULT_OK;
exit:
return r;
}

int e4c_set_idseckey(e4storage *store, const uint8_t *key)
{
memmove(store->privkey, key, sizeof store->privkey);
memmove(store->privkey, key, sizeof(store->privkey));
e4c_sync(store);
return E4_RESULT_OK;
}

int e4c_get_idseckey(e4storage* store, uint8_t *key) {
memcpy(key, store->privkey, sizeof store->privkey);
memcpy(key, store->privkey, sizeof(store->privkey));
return 0;
}

int e4c_get_idpubkey(e4storage* store, uint8_t *key) {
memcpy(key, store->pubkey, sizeof store->pubkey);
memcpy(key, store->pubkey, sizeof(store->pubkey));
return 0;
}

Expand Down Expand Up @@ -192,7 +192,7 @@ int e4c_reset_topics(e4storage *store)
{
store->topiccount = 0;
}
for ( i=0 ; i < E4_TOPICS_MAX ; i++ ) {
for (i=0 ; i < E4_TOPICS_MAX ; i++) {
ZERO(store->topics[i]);
}

Expand All @@ -201,7 +201,7 @@ int e4c_reset_topics(e4storage *store)
}

int e4c_set_idpubkey(e4storage *store, const uint8_t *pubkey) {
memmove(store->pubkey, pubkey, sizeof store->pubkey);
memmove(store->pubkey, pubkey, sizeof(store->pubkey));
e4c_sync(store);
return E4_RESULT_OK;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ int e4c_reset_devices(e4storage* store)
store->devicecount = 0;
}
/* Attempt to zero memory. This may not work depending on the platform */
for ( i=0 ; i < E4_DEVICES_MAX ; i++ ) {
for (i=0 ; i < E4_DEVICES_MAX ; i++) {
ZERO(store->devices[i]);
}

Expand Down
Loading

0 comments on commit 679372c

Please sign in to comment.