Run through indent

This commit is contained in:
Glenn L McGrath 2003-06-07 14:54:24 +00:00
parent 233b170a85
commit 7aa62cf173

View File

@ -77,8 +77,7 @@
typedef u_int32_t md5_uint32;
/* Structure to save state of computation between the single steps. */
struct md5_ctx
{
struct md5_ctx {
md5_uint32 A;
md5_uint32 B;
md5_uint32 C;
@ -96,21 +95,21 @@ struct md5_ctx
/* Initialize structure containing state of computation.
(RFC 1321, 3.3: Step 3) */
static void md5_init_ctx __P ((struct md5_ctx *ctx));
static void md5_init_ctx __P((struct md5_ctx * ctx));
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
static void md5_process_block __P ((const void *buffer, size_t len,
struct md5_ctx *ctx));
static void md5_process_block __P((const void *buffer, size_t len,
struct md5_ctx * ctx));
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
static void md5_process_bytes __P ((const void *buffer, size_t len,
struct md5_ctx *ctx));
static void md5_process_bytes __P((const void *buffer, size_t len,
struct md5_ctx * ctx));
/* Process the remaining bytes in the buffer and put result from CTX
in first 16 bytes following RESBUF. The result is always in little
@ -119,7 +118,7 @@ static void md5_process_bytes __P ((const void *buffer, size_t len,
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
static void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
static void *md5_finish_ctx __P((struct md5_ctx * ctx, void *resbuf));
@ -127,13 +126,13 @@ static void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
static int md5_stream __P ((FILE *stream, void *resblock));
static int md5_stream __P((FILE * stream, void *resblock));
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
static void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
static void *md5_buffer __P((const char *buffer, size_t len, void *resblock));
//----------------------------------------------------------------------------
//--------end of md5.h
@ -141,9 +140,9 @@ static void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
/* Handle endian-ness */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define SWAP(n) (n)
#define SWAP(n) (n)
#else
#define SWAP(n) ((n << 24) | ((n&65280)<<8) | ((n&16711680)>>8) | (n>>24))
#define SWAP(n) ((n << 24) | ((n&65280)<<8) | ((n&16711680)>>8) | (n>>24))
#endif
@ -194,7 +193,7 @@ static void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf)
/* Put the 64-bit file length in *bits* at the end of the buffer. */
*(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3);
*(md5_uint32 *) & ctx->buffer[bytes + pad + 4] =
SWAP( ((ctx->total[1] << 3) | (ctx->total[0] >> 29)) );
SWAP(((ctx->total[1] << 3) | (ctx->total[0] >> 29)));
/* Process last bytes. */
md5_process_block(ctx->buffer, bytes + pad + 8, ctx);
@ -216,10 +215,10 @@ static void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf)
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
static int md5_stream(FILE *stream, void *resblock)
static int md5_stream(FILE * stream, void *resblock)
{
/* Important: BLOCKSIZE must be a multiple of 64. */
static const int BLOCKSIZE = 4096;
static const int BLOCKSIZE = 4096;
struct md5_ctx ctx;
char buffer[BLOCKSIZE + 72];
size_t sum;
@ -233,6 +232,7 @@ static const int BLOCKSIZE = 4096;
computation function processes the whole buffer so that with the
next round of the loop another block can be read. */
size_t n;
sum = 0;
/* Read block. Take care for partial reads. */
@ -282,7 +282,8 @@ static void *md5_buffer(const char *buffer, size_t len, void *resblock)
return md5_finish_ctx(&ctx, resblock);
}
static void md5_process_bytes(const void *buffer, size_t len, struct md5_ctx *ctx)
static void md5_process_bytes(const void *buffer, size_t len,
struct md5_ctx *ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
@ -330,12 +331,14 @@ static void md5_process_bytes(const void *buffer, size_t len, struct md5_ctx *ct
/* Process LEN bytes of BUFFER, accumulating context into CTX.
It is assumed that LEN % 64 == 0. */
static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
static void md5_process_block(const void *buffer, size_t len,
struct md5_ctx *ctx)
{
md5_uint32 correct_words[16];
const md5_uint32 *words = buffer;
size_t nwords = len / sizeof(md5_uint32);
const md5_uint32 *endp = words + nwords;
#if MD5SUM_SIZE_VS_SPEED > 0
static const md5_uint32 C_array[] = {
/* round 1 */
@ -409,65 +412,85 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
int i;
md5_uint32 temp;
for ( i=0 ; i < 16 ; i++ ) {
for (i = 0; i < 16; i++) {
cwp[i] = SWAP(words[i]);
}
words += 16;
#if MD5SUM_SIZE_VS_SPEED > 2
pc = C_array; pp = P_array; ps = S_array - 4;
pc = C_array;
pp = P_array;
ps = S_array - 4;
for ( i = 0 ; i < 64 ; i++ ) {
if ((i&0x0f) == 0) ps += 4;
for (i = 0; i < 64; i++) {
if ((i & 0x0f) == 0)
ps += 4;
temp = A;
switch (i>>4) {
switch (i >> 4) {
case 0:
temp += FF(B,C,D);
temp += FF(B, C, D);
break;
case 1:
temp += FG(B,C,D);
temp += FG(B, C, D);
break;
case 2:
temp += FH(B,C,D);
temp += FH(B, C, D);
break;
case 3:
temp += FI(B,C,D);
temp += FI(B, C, D);
}
temp += cwp[(int)(*pp++)] + *pc++;
CYCLIC (temp, ps[i&3]);
temp += cwp[(int) (*pp++)] + *pc++;
CYCLIC(temp, ps[i & 3]);
temp += B;
A = D; D = C; C = B; B = temp;
A = D;
D = C;
C = B;
B = temp;
}
#else
pc = C_array; pp = P_array; ps = S_array;
pc = C_array;
pp = P_array;
ps = S_array;
for ( i = 0 ; i < 16 ; i++ ) {
temp = A + FF(B,C,D) + cwp[(int)(*pp++)] + *pc++;
CYCLIC (temp, ps[i&3]);
for (i = 0; i < 16; i++) {
temp = A + FF(B, C, D) + cwp[(int) (*pp++)] + *pc++;
CYCLIC(temp, ps[i & 3]);
temp += B;
A = D; D = C; C = B; B = temp;
A = D;
D = C;
C = B;
B = temp;
}
ps += 4;
for ( i = 0 ; i < 16 ; i++ ) {
temp = A + FG(B,C,D) + cwp[(int)(*pp++)] + *pc++;
CYCLIC (temp, ps[i&3]);
for (i = 0; i < 16; i++) {
temp = A + FG(B, C, D) + cwp[(int) (*pp++)] + *pc++;
CYCLIC(temp, ps[i & 3]);
temp += B;
A = D; D = C; C = B; B = temp;
A = D;
D = C;
C = B;
B = temp;
}
ps += 4;
for ( i = 0 ; i < 16 ; i++ ) {
temp = A + FH(B,C,D) + cwp[(int)(*pp++)] + *pc++;
CYCLIC (temp, ps[i&3]);
for (i = 0; i < 16; i++) {
temp = A + FH(B, C, D) + cwp[(int) (*pp++)] + *pc++;
CYCLIC(temp, ps[i & 3]);
temp += B;
A = D; D = C; C = B; B = temp;
A = D;
D = C;
C = B;
B = temp;
}
ps += 4;
for ( i = 0 ; i < 16 ; i++ ) {
temp = A + FI(B,C,D) + cwp[(int)(*pp++)] + *pc++;
CYCLIC (temp, ps[i&3]);
for (i = 0; i < 16; i++) {
temp = A + FI(B, C, D) + cwp[(int) (*pp++)] + *pc++;
CYCLIC(temp, ps[i & 3]);
temp += B;
A = D; D = C; C = B; B = temp;
A = D;
D = C;
C = B;
B = temp;
}
#endif
@ -509,7 +532,7 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
/* Round 1. */
#if MD5SUM_SIZE_VS_SPEED == 1
pc = C_array;
for ( i=0 ; i < 4 ; i++ ) {
for (i = 0; i < 4; i++) {
OP(A, B, C, D, 7, *pc++);
OP(D, A, B, C, 12, *pc++);
OP(C, D, A, B, 17, *pc++);
@ -550,11 +573,11 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
/* Round 2. */
#if MD5SUM_SIZE_VS_SPEED == 1
pp = P_array;
for ( i=0 ; i < 4 ; i++ ) {
OP(FG, A, B, C, D, (int)(*pp++), 5, *pc++);
OP(FG, D, A, B, C, (int)(*pp++), 9, *pc++);
OP(FG, C, D, A, B, (int)(*pp++), 14, *pc++);
OP(FG, B, C, D, A, (int)(*pp++), 20, *pc++);
for (i = 0; i < 4; i++) {
OP(FG, A, B, C, D, (int) (*pp++), 5, *pc++);
OP(FG, D, A, B, C, (int) (*pp++), 9, *pc++);
OP(FG, C, D, A, B, (int) (*pp++), 14, *pc++);
OP(FG, B, C, D, A, (int) (*pp++), 20, *pc++);
}
#else
OP(FG, A, B, C, D, 1, 5, 0xf61e2562);
@ -577,11 +600,11 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
/* Round 3. */
#if MD5SUM_SIZE_VS_SPEED == 1
for ( i=0 ; i < 4 ; i++ ) {
OP(FH, A, B, C, D, (int)(*pp++), 4, *pc++);
OP(FH, D, A, B, C, (int)(*pp++), 11, *pc++);
OP(FH, C, D, A, B, (int)(*pp++), 16, *pc++);
OP(FH, B, C, D, A, (int)(*pp++), 23, *pc++);
for (i = 0; i < 4; i++) {
OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++);
OP(FH, D, A, B, C, (int) (*pp++), 11, *pc++);
OP(FH, C, D, A, B, (int) (*pp++), 16, *pc++);
OP(FH, B, C, D, A, (int) (*pp++), 23, *pc++);
}
#else
OP(FH, A, B, C, D, 5, 4, 0xfffa3942);
@ -604,11 +627,11 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
/* Round 4. */
#if MD5SUM_SIZE_VS_SPEED == 1
for ( i=0 ; i < 4 ; i++ ) {
OP(FI, A, B, C, D, (int)(*pp++), 6, *pc++);
OP(FI, D, A, B, C, (int)(*pp++), 10, *pc++);
OP(FI, C, D, A, B, (int)(*pp++), 15, *pc++);
OP(FI, B, C, D, A, (int)(*pp++), 21, *pc++);
for (i = 0; i < 4; i++) {
OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++);
OP(FI, D, A, B, C, (int) (*pp++), 10, *pc++);
OP(FI, C, D, A, B, (int) (*pp++), 15, *pc++);
OP(FI, B, C, D, A, (int) (*pp++), 21, *pc++);
}
#else
OP(FI, A, B, C, D, 0, 6, 0xf4292244);
@ -666,10 +689,7 @@ static int status_only = 0; /* With -c, don't generate any output.
static int warn = 0; /* With -w, print a message to standard error warning
about each improperly formatted MD5 checksum line */
static int split_3(char *s,
size_t s_len,
unsigned char **u,
char **w)
static int split_3(char *s, size_t s_len, unsigned char **u, char **w)
{
size_t i = 0;
int escaped_filename = 0;
@ -761,8 +781,7 @@ static inline int hex_digits(unsigned char const *s)
/* An interface to md5_stream. Operate on FILENAME (it may be "-") and
put the result in *MD5_RESULT. Return non-zero upon failure, zero
to indicate success. */
static int md5_file(const char *filename,
unsigned char *md5_result)
static int md5_file(const char *filename, unsigned char *md5_result)
{
FILE *fp;
@ -819,10 +838,10 @@ static int md5_check(const char *checkfile_name)
++line_number;
fgets(line, BUFSIZ-1, checkfile_stream);
fgets(line, BUFSIZ - 1, checkfile_stream);
line_length = strlen(line);
if (line_length <= 0 || line==NULL)
if (line_length <= 0 || line == NULL)
break;
/* Ignore comment lines, which begin with a '#' character. */
@ -836,7 +855,8 @@ static int md5_check(const char *checkfile_name)
if (split_3(line, line_length, &md5num, &filename)
|| !hex_digits(md5num)) {
if (warn) {
bb_error_msg("%s: %lu: improperly formatted MD5 checksum line",
bb_error_msg
("%s: %lu: improperly formatted MD5 checksum line",
checkfile_name, (unsigned long) line_number);
}
} else {
@ -857,6 +877,7 @@ static int md5_check(const char *checkfile_name)
}
} else {
size_t cnt;
/* Compare generated binary number with text representation
in check file. Ignore case of hex digits. */
for (cnt = 0; cnt < 16; ++cnt) {
@ -901,13 +922,15 @@ static int md5_check(const char *checkfile_name)
- n_open_or_read_failures);
if (n_open_or_read_failures > 0) {
bb_error_msg("WARNING: %d of %d listed files could not be read",
bb_error_msg
("WARNING: %d of %d listed files could not be read",
n_open_or_read_failures, n_properly_formated_lines);
return FALSE;
}
if (n_mismatched_checksums > 0) {
bb_error_msg("WARNING: %d of %d computed checksums did NOT match",
bb_error_msg
("WARNING: %d of %d computed checksums did NOT match",
n_mismatched_checksums, n_computed_checkums);
return FALSE;
}
@ -918,8 +941,7 @@ static int md5_check(const char *checkfile_name)
&& n_open_or_read_failures == 0) ? 0 : 1);
}
int md5sum_main(int argc,
char **argv)
int md5sum_main(int argc, char **argv)
{
unsigned char md5buffer[16];
int do_check = 0;
@ -932,9 +954,9 @@ int md5sum_main(int argc,
while ((opt = getopt(argc, argv, "g:bcstw")) != -1) {
switch (opt) {
case 'g': { /* read a string */
case 'g':{ /* read a string */
if (string == NULL)
string = (char **) xmalloc ((argc - 1) * sizeof (char *));
string = (char **) xmalloc((argc - 1) * sizeof(char *));
string[n_strings++] = optarg;
break;
@ -970,7 +992,8 @@ int md5sum_main(int argc,
}
if (file_type_specified && do_check) {
bb_error_msg_and_die("the -b and -t options are meaningless when verifying checksums");
bb_error_msg_and_die
("the -b and -t options are meaningless when verifying checksums");
}
if (n_strings > 0 && do_check) {
@ -978,11 +1001,13 @@ int md5sum_main(int argc,
}
if (status_only && !do_check) {
bb_error_msg_and_die("the -s option is meaningful only when verifying checksums");
bb_error_msg_and_die
("the -s option is meaningful only when verifying checksums");
}
if (warn && !do_check) {
bb_error_msg_and_die("the -w option is meaningful only when verifying checksums");
bb_error_msg_and_die
("the -w option is meaningful only when verifying checksums");
}
if (n_strings > 0) {
@ -993,19 +1018,20 @@ int md5sum_main(int argc,
}
for (i = 0; i < n_strings; ++i) {
size_t cnt;
md5_buffer (string[i], strlen (string[i]), md5buffer);
md5_buffer(string[i], strlen(string[i]), md5buffer);
for (cnt = 0; cnt < 16; ++cnt)
printf ("%02x", md5buffer[cnt]);
printf("%02x", md5buffer[cnt]);
printf (" \"%s\"\n", string[i]);
printf(" \"%s\"\n", string[i]);
}
} else if (do_check) {
if (optind + 1 < argc) {
bb_error_msg("only one argument may be specified when using -c");
}
err = md5_check ((optind == argc) ? "-" : argv[optind]);
err = md5_check((optind == argc) ? "-" : argv[optind]);
} else {
if (optind == argc)
argv[argc++] = "-";
@ -1014,56 +1040,58 @@ int md5sum_main(int argc,
int fail;
char *file = argv[optind];
fail = md5_file (file, md5buffer);
fail = md5_file(file, md5buffer);
err |= fail;
if (!fail && file[0]=='-' && file[1] == '\0') {
if (!fail && file[0] == '-' && file[1] == '\0') {
size_t i;
for (i = 0; i < 16; ++i)
printf ("%02x", md5buffer[i]);
putchar ('\n');
printf("%02x", md5buffer[i]);
putchar('\n');
} else if (!fail) {
size_t i;
/* Output a leading backslash if the file name contains
a newline or backslash. */
if (strchr (file, '\n') || strchr (file, '\\'))
putchar ('\\');
if (strchr(file, '\n') || strchr(file, '\\'))
putchar('\\');
for (i = 0; i < 16; ++i)
printf ("%02x", md5buffer[i]);
printf("%02x", md5buffer[i]);
putchar (' ');
putchar(' ');
if (binary)
putchar ('*');
putchar('*');
else
putchar (' ');
putchar(' ');
/* Translate each NEWLINE byte to the string, "\\n",
and each backslash to "\\\\". */
for (i = 0; i < strlen (file); ++i) {
for (i = 0; i < strlen(file); ++i) {
switch (file[i]) {
case '\n':
fputs ("\\n", stdout);
fputs("\\n", stdout);
break;
case '\\':
fputs ("\\\\", stdout);
fputs("\\\\", stdout);
break;
default:
putchar (file[i]);
putchar(file[i]);
break;
}
}
putchar ('\n');
putchar('\n');
}
}
}
if (fclose (stdout) == EOF) {
if (fclose(stdout) == EOF) {
bb_error_msg_and_die("write error");
}
if (have_read_stdin && fclose (stdin) == EOF) {
if (have_read_stdin && fclose(stdin) == EOF) {
bb_error_msg_and_die(bb_msg_standard_input);
}