Skip to content

Commit

Permalink
cleanups, make clang happy
Browse files Browse the repository at this point in the history
  • Loading branch information
cathugger committed Mar 15, 2019
1 parent 9ac54f6 commit 390e8ea
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion base64.h
@@ -1,7 +1,7 @@
// converts src[0:slen] to base64 string
char *base64_to(char *dst,const u8 *src,size_t slen);
// calculates length needed to store data converted to base64
#define BASE64_TO_LEN(l) (((l + 3 - 1) / 3) * 4)
#define BASE64_TO_LEN(l) ((((l) + 2) / 3) * 4)
// converts src string from base64
size_t base64_from(u8 *dst,const char *src,size_t slen);
// calculates length needed to store data converted from base64
Expand Down
2 changes: 1 addition & 1 deletion common.h
Expand Up @@ -10,7 +10,7 @@
#define FORMATTED_PUBLIC_LEN (PKPREFIX_SIZE + PUBLIC_LEN)
#define FORMATTED_SECRET_LEN (SKPREFIX_SIZE + SECRET_LEN)

// full onion address, WITHOUT newline
// full onion address, WITHOUT newline or terminating nil char
#define ONION_LEN 62

extern pthread_mutex_t fout_mutex;
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Expand Up @@ -186,7 +186,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[cstd="$cstd -Wall"],
[AC_MSG_RESULT([no])]
)
CFLAGS="$cstd -Wno-maybe-uninitialized"
# (negative) detection on clang fails without -Werror
CFLAGS="$cstd -Wno-maybe-uninitialized -Werror"
AC_MSG_CHECKING([whether CC supports -Wno-maybe-uninitialized])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])]
Expand Down
2 changes: 1 addition & 1 deletion ed25519/amd64-51-30k/ge25519_base_niels_smalltables.data
Expand Up @@ -765,4 +765,4 @@
{{0x000448327b95d543, 0x0000146681e3a4ba, 0x00038714adc34e0c, 0x0004f26f0e298e30, 0x000272224512c7de}}},
{{{0x000492af49c5342e, 0x0002365cdf5a0357, 0x00032138a7ffbb60, 0x0002a1f7d14646fe, 0x00011b5df18a44cc}},
{{0x0003bb8a42a975fc, 0x0006f2d5b46b17ef, 0x0007b6a9223170e5, 0x000053713fe3b7e6, 0x00019735fd7f6bc2}},
{{0x000390d042c84266, 0x0001efe32a8fdc75, 0x0006925ee7ae1238, 0x0004af9281d0e832, 0x0000fef911191df8}}}
{{0x000390d042c84266, 0x0001efe32a8fdc75, 0x0006925ee7ae1238, 0x0004af9281d0e832, 0x0000fef911191df8}}}
2 changes: 1 addition & 1 deletion ed25519/amd64-51-30k/ge25519_base_slide_multiples.data
Expand Up @@ -93,4 +93,4 @@
{{0x0004d5107f18c781, 0x00064a4fd3a51a5e, 0x0004f4cd0448bb37, 0x000671d38543151e, 0x0001db7778911914}}},
{{{0x000352397c6bc26f, 0x00018a7aa0227bbe, 0x0005e68cc1ea5f8b, 0x0006fe3e3a7a1d5f, 0x00031ad97ad26e2a}},
{{0x00014769dd701ab6, 0x00028339f1b4b667, 0x0004ab214b8ae37b, 0x00025f0aefa0b0fe, 0x0007ae2ca8a017d2}},
{{0x000017ed0920b962, 0x000187e33b53b6fd, 0x00055829907a1463, 0x000641f248e0a792, 0x0001ed1fc53a6622}}}
{{0x000017ed0920b962, 0x000187e33b53b6fd, 0x00055829907a1463, 0x000641f248e0a792, 0x0001ed1fc53a6622}}}
2 changes: 1 addition & 1 deletion ed25519/amd64-64-24k/ge25519_base_niels.data
Expand Up @@ -1533,4 +1533,4 @@
{{0xbd4ea9e10f53c4b6, 0x1673dc5f8ac91a14, 0xa8f81a4e2acc1aba, 0x33a92a7924332a25}}},
{{{0x9dd1f49927996c02, 0x0cb3b058e04d1752, 0x1f7e88967fd02c3e, 0x2f964268cb8b3eb1}},
{{0x7ba95ba0218f2ada, 0xcff42287330fb9ca, 0xdada496d56c6d907, 0x5380c296f4beee54}},
{{0x9d4f270466898d0a, 0x3d0987990aff3f7a, 0xd09ef36267daba45, 0x7761455e7b1c669c}}}
{{0x9d4f270466898d0a, 0x3d0987990aff3f7a, 0xd09ef36267daba45, 0x7761455e7b1c669c}}}
2 changes: 1 addition & 1 deletion ed25519/amd64-64-24k/ge25519_base_niels_smalltables.data
Expand Up @@ -765,4 +765,4 @@
{{0x25d448327b95d543, 0x70d38300a3340f1d, 0xde1c531c60e1c52b, 0x272224512c7de9e4}}},
{{{0x1abc92af49c5342e, 0xffeed811b2e6fad0, 0xefa28c8dfcc84e29, 0x11b5df18a44cc543}},
{{0xbf7bbb8a42a975fc, 0x8c5c397796ada358, 0xe27fc76fcdedaa48, 0x19735fd7f6bc20a6}},
{{0xe3ab90d042c84266, 0xeb848e0f7f19547e, 0x2503a1d065a497b9, 0x0fef911191df895f}}}
{{0xe3ab90d042c84266, 0xeb848e0f7f19547e, 0x2503a1d065a497b9, 0x0fef911191df895f}}}
2 changes: 1 addition & 1 deletion ed25519/amd64-64-24k/ge25519_base_slide_multiples.data
Expand Up @@ -93,4 +93,4 @@
{{0xd2f4d5107f18c781, 0x122ecdf2527e9d28, 0xa70a862a3d3d3341, 0x1db7778911914ce3}}},
{{{0xddf352397c6bc26f, 0x7a97e2cc53d50113, 0x7c74f43abf79a330, 0x31ad97ad26e2adfc}},
{{0xb3394769dd701ab6, 0xe2b8ded419cf8da5, 0x15df4161fd2ac852, 0x7ae2ca8a017d24be}},
{{0xb7e817ed0920b962, 0x1e8518cc3f19da9d, 0xe491c14f25560a64, 0x1ed1fc53a6622c83}}}
{{0xb7e817ed0920b962, 0x1e8518cc3f19da9d, 0xe491c14f25560a64, 0x1ed1fc53a6622c83}}}
2 changes: 2 additions & 0 deletions ed25519/amd64-64-24k/ge25519_scalarmult_base.c
Expand Up @@ -11,8 +11,10 @@ static const ge25519_niels ge25519_base_multiples_niels[] = {
#endif
};

#ifdef SMALLTABLES
/* d */
static const fe25519 ecd = {{0x75EB4DCA135978A3, 0x00700A4D4141D8AB, 0x8CC740797779E898, 0x52036CEE2B6FFE73}};
#endif

void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s)
{
Expand Down
39 changes: 25 additions & 14 deletions test_base64.c
Expand Up @@ -10,15 +10,21 @@
struct texttestcase {
const char *in;
const char *out;
const char *rev;
} tests0[] = {
{"", "", ""},
{"f", "Zg==", "f"},
{"fo", "Zm8=", "fo"},
{"foo", "Zm9v", "foo"},
{"foob", "Zm9vYg==", "foob"},
{"fooba", "Zm9vYmE=", "fooba"},
{"foobar", "Zm9vYmFy", "foobar"},
{ "" ,"" },
{ "f" ,"Zg==" },
{ "fo" ,"Zm8=" },
{ "foo" ,"Zm9v" },
{ "foob" ,"Zm9vYg==" },
{ "fooba" ,"Zm9vYmE=" },
{ "foobar","Zm9vYmFy" },

{ "foobarf" ,"Zm9vYmFyZg==" },
{ "foobarfo" ,"Zm9vYmFyZm8=" },
{ "foobarfoo" ,"Zm9vYmFyZm9v" },
{ "foobarfoob" ,"Zm9vYmFyZm9vYg==" },
{ "foobarfooba" ,"Zm9vYmFyZm9vYmE=" },
{ "foobarfoobar","Zm9vYmFyZm9vYmFy" },
};

int main(void)
Expand All @@ -29,19 +35,24 @@ int main(void)
base64_to(buf, (const u8 *)tests0[i].in, strlen(tests0[i].in));
if (strcmp(buf, tests0[i].out) != 0) {
printf("invalid encoding result: \"%s\" -> encoded as \"%s\", but expected \"%s\".\n",
tests0[i].in, buf, tests0[i].out);
tests0[i].in, buf, tests0[i].out);
return 1;
}
if (strlen(buf) != BASE64_TO_LEN(strlen(tests0[i].in))) {
printf("encoded length mismatch: got %d expected %d\n",
(int) strlen(buf), (int) BASE64_TO_LEN(strlen(tests0[i].in)));
return 1;
}
if (!base64_valid(buf,0)) {
printf("encoded data is considered invalid\n");
return 3;
return 1;
}
r = base64_from((u8 *)buf2, buf, strlen(buf));
buf2[r] = '\0';
if (strcmp(buf2, tests0[i].rev) != 0) {
buf2[r] = '\000';
if (strcmp(buf2, tests0[i].in) != 0) {
printf("invalid decoding result: encoded \"%s\", decoded as \"%s\", but expected \"%s\".\n",
tests0[i].out, buf2, tests0[i].rev);
return 2;
tests0[i].out, buf2, tests0[i].in);
return 1;
}
}
return 0;
Expand Down
20 changes: 8 additions & 12 deletions yaml.c
Expand Up @@ -37,19 +37,13 @@ static const char keys_field_time[] = "time: ";
#define KEYS_FIELD_SECRETKEY_LEN (sizeof(keys_field_secretkey) - NULLTERM_LEN)
#define KEYS_FIELD_TIME_LEN (sizeof(keys_field_time) - NULLTERM_LEN)

static const char hostname_example[] = "xxxxxvsjzke274nisktdqcl3eqm5ve3m6iur6vwme7m5p6kxivrvjnyd.onion";
static const char pubkey_example[] = "PT0gZWQyNTUxOXYxLXB1YmxpYzogdHlwZTAgPT0AAAC973vWScqJr/GokqY4CXskGdqTbPIpH1bMJ9nX+VdFYw==";
static const char seckey_example[] = "PT0gZWQyNTUxOXYxLXNlY3JldDogdHlwZTAgPT0AAACwCPMr6rvBRtkW7ZzZ8P7Ne4acRZrhPrN/EF6AETRraFGvdrkW5es4WXB2UxrbuUf8zPoIKkXK5cpdakYdUeM3";
static const char time_example[] = "2018-07-04 21:31:20 Z";

#define HOSTNAME_LEN (sizeof(hostname_example) - NULLTERM_LEN)
#define B64_PUBKEY_LEN (sizeof(pubkey_example) - NULLTERM_LEN)
#define B64_SECKEY_LEN (sizeof(seckey_example) - NULLTERM_LEN)
#define TIME_LEN (sizeof(time_example) - NULLTERM_LEN)
#define B64_PUBKEY_LEN (BASE64_TO_LEN(FORMATTED_PUBLIC_LEN))
#define B64_SECKEY_LEN (BASE64_TO_LEN(FORMATTED_SECRET_LEN))
#define TIME_LEN (21 * sizeof(char)) // strlen("2018-07-04 21:31:20 Z")

#define KEYS_LEN ( \
KEYS_FIELD_GENERATED_LEN + LINEFEED_LEN + \
KEYS_FIELD_HOSTNAME_LEN + HOSTNAME_LEN + LINEFEED_LEN + \
KEYS_FIELD_HOSTNAME_LEN + ONION_LEN + LINEFEED_LEN + \
KEYS_FIELD_PUBLICKEY_LEN + B64_PUBKEY_LEN + LINEFEED_LEN + \
KEYS_FIELD_SECRETKEY_LEN + B64_SECKEY_LEN + LINEFEED_LEN + \
KEYS_FIELD_TIME_LEN + TIME_LEN + LINEFEED_LEN \
Expand Down Expand Up @@ -206,8 +200,10 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
len = strlen(p);
switch (keyt) {
case HOST:
if (len != ONION_LEN || base32_valid(p,&cnt) || cnt != BASE32_TO_LEN(PUBONION_LEN) ||
strcmp(&p[cnt],&hostname_example[cnt]) != 0)
if (len != ONION_LEN ||
base32_valid(p,&cnt) ||
cnt != BASE32_TO_LEN(PUBONION_LEN) ||
strcmp(&p[cnt],".onion") != 0)
{
fprintf(stderr,"ERROR: invalid hostname syntax\n");
return 1;
Expand Down

0 comments on commit 390e8ea

Please sign in to comment.