Unify coding style

@sjaeckel integrated clang-format with formal coding style. Run his
script and commit changes.

There are pros and cons of this commit.

Mixed coding style is a "broken window". A good single style simplifies
reading and writing code.

On the other hand, this is a big change which will lead to conflicts.
This commit is contained in:
Dmitry Podgorny
2020-01-03 22:02:22 +02:00
parent eef07cef36
commit 562a06425b
62 changed files with 3972 additions and 3746 deletions

View File

@@ -12,25 +12,23 @@
/* Test Vectors (from FIPS PUB 180-1) */
static char *test_data[] = {
"abc",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"A million repetitions of 'a'",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};
static char *test_results[] = {
"A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D",
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1",
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F",
"AD5B3FDB CB526778 C2839D2F 151EA753 995E26A0"};
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};
static char *test_results[] = {"A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D",
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1",
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F",
"AD5B3FDB CB526778 C2839D2F 151EA753 995E26A0"};
static void digest_to_hex(const uint8_t *digest, char *output)
{
int i,j;
int i, j;
char *c = output;
for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) {
for (i = 0; i < SHA1_DIGEST_SIZE / 4; i++) {
for (j = 0; j < 4; j++) {
sprintf(c,"%02X", digest[i*4+j]);
sprintf(c, "%02X", digest[i * 4 + j]);
c += 2;
}
sprintf(c, " ");
@@ -39,7 +37,7 @@ static void digest_to_hex(const uint8_t *digest, char *output)
*(c - 1) = '\0';
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
size_t k;
SHA1_CTX context;
@@ -49,23 +47,23 @@ int main(int argc, char** argv)
fprintf(stdout, "verifying SHA-1 implementation... ");
for (k = 0; k < ARRAY_SIZE(test_data); k++){
for (k = 0; k < ARRAY_SIZE(test_data); k++) {
if (k == 2) {
/* this case will be checked below */
continue;
}
copy = strdup(test_data[k]);
crypto_SHA1_Init(&context);
crypto_SHA1_Update(&context, (uint8_t*)test_data[k],
crypto_SHA1_Update(&context, (uint8_t *)test_data[k],
strlen(test_data[k]));
crypto_SHA1_Final(&context, digest);
digest_to_hex(digest, output);
if (strcmp(output, test_results[k])) {
fprintf(stdout, "FAIL\n");
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[k]);
fprintf(stderr,"\t%s returned\n", output);
fprintf(stderr,"\t%s is correct\n", test_results[k]);
fprintf(stderr, "* hash of \"%s\" incorrect:\n", test_data[k]);
fprintf(stderr, "\t%s returned\n", output);
fprintf(stderr, "\t%s is correct\n", test_results[k]);
return (1);
}
if (strcmp(copy, test_data[k])) {
@@ -78,18 +76,18 @@ int main(int argc, char** argv)
/* million 'a' vector we feed separately */
crypto_SHA1_Init(&context);
for (k = 0; k < 1000000; k++)
crypto_SHA1_Update(&context, (uint8_t*)"a", 1);
crypto_SHA1_Update(&context, (uint8_t *)"a", 1);
crypto_SHA1_Final(&context, digest);
digest_to_hex(digest, output);
if (strcmp(output, test_results[2])) {
fprintf(stdout, "FAIL\n");
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[2]);
fprintf(stderr,"\t%s returned\n", output);
fprintf(stderr,"\t%s is correct\n", test_results[2]);
fprintf(stderr, "* hash of \"%s\" incorrect:\n", test_data[2]);
fprintf(stderr, "\t%s returned\n", output);
fprintf(stderr, "\t%s is correct\n", test_results[2]);
return (1);
}
/* success */
fprintf(stdout, "ok\n");
return(0);
return (0);
}