Browse Source

Some KNF

OPENBSD_3_6
millert 20 years ago
parent
commit
224ee4053e
1 changed files with 25 additions and 25 deletions
  1. +25
    -25
      src/lib/libc/hash/helper.c

+ 25
- 25
src/lib/libc/hash/helper.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: helper.c,v 1.1 2004/04/26 19:38:12 millert Exp $ */
/* $OpenBSD: helper.c,v 1.2 2004/04/29 02:39:32 millert Exp $ */
/*
* ----------------------------------------------------------------------------
@ -10,7 +10,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$OpenBSD: helper.c,v 1.1 2004/04/26 19:38:12 millert Exp $";
static const char rcsid[] = "$OpenBSD: helper.c,v 1.2 2004/04/29 02:39:32 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -28,21 +28,21 @@ static const char rcsid[] = "$OpenBSD: helper.c,v 1.1 2004/04/26 19:38:12 miller
char *
HASHEnd(HASH_CTX *ctx, char buf[HASH_DIGEST_STRING_LENGTH])
{
int i;
u_char digest[HASH_DIGEST_LENGTH];
static const char hex[] = "0123456789abcdef";
int i;
u_int8_t digest[HASH_DIGEST_LENGTH];
static const char hex[] = "0123456789abcdef";
if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL)
return(NULL);
if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL)
return(NULL);
HASHFinal(digest,ctx);
for (i = 0; i < HASH_DIGEST_LENGTH; i++) {
buf[i + i] = hex[digest[i] >> 4];
buf[i + i + 1] = hex[digest[i] & 0x0f];
}
buf[i + i] = '\0';
memset(digest, 0, sizeof(digest));
return(buf);
HASHFinal(digest,ctx);
for (i = 0; i < HASH_DIGEST_LENGTH; i++) {
buf[i + i] = hex[digest[i] >> 4];
buf[i + i + 1] = hex[digest[i] & 0x0f];
}
buf[i + i] = '\0';
memset(digest, 0, sizeof(digest));
return (buf);
}
char *
@ -50,28 +50,28 @@ HASHFile(char *filename, char buf[HASH_DIGEST_STRING_LENGTH])
{
u_char buffer[BUFSIZ];
HASH_CTX ctx;
int fd, num, oerrno;
int fd, num, save_errno;
HASHInit(&ctx);
if ((fd = open(filename, O_RDONLY)) < 0)
return(0);
return(NULL);
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
HASHUpdate(&ctx, buffer, num);
HASHUpdate(&ctx, buffer, num);
oerrno = errno;
save_errno = errno;
close(fd);
errno = oerrno;
return(num < 0 ? 0 : HASHEnd(&ctx, buf));
errno = save_errno;
return (num < 0 ? NULL : HASHEnd(&ctx, buf));
}
char *
HASHData(const u_char *data, size_t len, char buf[HASH_DIGEST_STRING_LENGTH])
{
HASH_CTX ctx;
HASH_CTX ctx;
HASHInit(&ctx);
HASHUpdate(&ctx, data, len);
return(HASHEnd(&ctx, buf));
HASHInit(&ctx);
HASHUpdate(&ctx, data, len);
return (HASHEnd(&ctx, buf));
}

Loading…
Cancel
Save