mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-01-09 11:07:19 -03:00
cleanups, make clang happy
This commit is contained in:
parent
9ac54f6db3
commit
390e8ea9de
11 changed files with 44 additions and 34 deletions
2
base64.h
2
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
|
||||
|
|
2
common.h
2
common.h
|
@ -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;
|
||||
|
|
|
@ -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])]
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
@ -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;
|
||||
|
|
20
yaml.c
20
yaml.c
|
@ -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 \
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue