rename -lutil to -lminixutil
. in preparation for netbsd -lutil
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
# Makefile for libutil
|
||||
|
||||
LIB= util
|
||||
|
||||
.if (${NBSD_LIBC} != "no")
|
||||
# SHA and MD5 functions already in libc
|
||||
SRCS= openpty.c efun.c
|
||||
.else
|
||||
SRCS= openpty.c sha2.c efun.c \
|
||||
sha1.c sha1hl.c sha2.c sha2hl.c md5c.c md5hl.c
|
||||
.endif
|
||||
.include <bsd.lib.mk>
|
||||
@@ -1,161 +0,0 @@
|
||||
/* $NetBSD: efun.c,v 1.6 2008/04/28 20:23:02 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: efun.c,v 1.6 2008/04/28 20:23:02 martin Exp $");
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <err.h>
|
||||
#include <util.h>
|
||||
|
||||
static void (*efunc)(int, const char *, ...) = err;
|
||||
|
||||
void (*
|
||||
esetfunc(void (*ef)(int, const char *, ...)))(int, const char *, ...)
|
||||
{
|
||||
void (*of)(int, const char *, ...) = efunc;
|
||||
efunc = ef == NULL ? (void (*)(int, const char *, ...))exit : ef;
|
||||
return of;
|
||||
}
|
||||
|
||||
size_t
|
||||
estrlcpy(char *dst, const char *src, size_t len)
|
||||
{
|
||||
size_t rv;
|
||||
if ((rv = strlcpy(dst, src, len)) >= len) {
|
||||
errno = ENAMETOOLONG;
|
||||
(*efunc)(1,
|
||||
"Cannot copy string; %zu chars needed %zu provided",
|
||||
rv, len);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
size_t
|
||||
estrlcat(char *dst, const char *src, size_t len)
|
||||
{
|
||||
size_t rv;
|
||||
if ((rv = strlcat(dst, src, len)) >= len) {
|
||||
errno = ENAMETOOLONG;
|
||||
(*efunc)(1,
|
||||
"Cannot append to string; %zu chars needed %zu provided",
|
||||
rv, len);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *
|
||||
estrdup(const char *s)
|
||||
{
|
||||
char *d = strdup(s);
|
||||
if (d == NULL)
|
||||
(*efunc)(1, "Cannot copy string");
|
||||
return d;
|
||||
}
|
||||
|
||||
#ifndef __minix
|
||||
char *
|
||||
estrndup(const char *s, size_t len)
|
||||
{
|
||||
char *d = strndup(s, len);
|
||||
if (d == NULL)
|
||||
(*efunc)(1, "Cannot copy string");
|
||||
return d;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *
|
||||
emalloc(size_t n)
|
||||
{
|
||||
void *p = malloc(n);
|
||||
if (p == NULL)
|
||||
(*efunc)(1, "Cannot allocate %zu bytes", n);
|
||||
return p;
|
||||
}
|
||||
|
||||
void *
|
||||
ecalloc(size_t n, size_t s)
|
||||
{
|
||||
void *p = calloc(n, s);
|
||||
if (p == NULL)
|
||||
(*efunc)(1, "Cannot allocate %zu bytes", n);
|
||||
return p;
|
||||
}
|
||||
|
||||
void *
|
||||
erealloc(void *p, size_t n)
|
||||
{
|
||||
void *q = realloc(p, n);
|
||||
if (q == NULL)
|
||||
(*efunc)(1, "Cannot re-allocate %zu bytes", n);
|
||||
return q;
|
||||
}
|
||||
|
||||
FILE *
|
||||
efopen(const char *p, const char *m)
|
||||
{
|
||||
FILE *fp = fopen(p, m);
|
||||
if (fp == NULL)
|
||||
(*efunc)(1, "Cannot open `%s'", p);
|
||||
return fp;
|
||||
}
|
||||
|
||||
int
|
||||
easprintf(char ** __restrict ret, const char * __restrict format, ...)
|
||||
{
|
||||
int rv;
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
if ((rv = vasprintf(ret, format, ap)) == -1)
|
||||
(*efunc)(1, "Cannot format string");
|
||||
va_end(ap);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
evasprintf(char ** __restrict ret, const char * __restrict format, va_list ap)
|
||||
{
|
||||
int rv;
|
||||
if ((rv = vasprintf(ret, format, ap)) == -1)
|
||||
(*efunc)(1, "Cannot format string");
|
||||
return rv;
|
||||
}
|
||||
@@ -1,379 +0,0 @@
|
||||
/* $NetBSD: md5c.c,v 1.7 2008/10/06 12:36:20 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* This file is derived from the RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm and has been modified by Jason R. Thorpe <thorpej@NetBSD.org>
|
||||
* for portability and formatting.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
* rights reserved.
|
||||
*
|
||||
* License to copy and use this software is granted provided that it
|
||||
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm" in all material mentioning or referencing this software
|
||||
* or this function.
|
||||
*
|
||||
* License is also granted to make and use derivative works provided
|
||||
* that such works are identified as "derived from the RSA Data
|
||||
* Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
* mentioning or referencing the derived work.
|
||||
*
|
||||
* RSA Data Security, Inc. makes no representations concerning either
|
||||
* the merchantability of this software or the suitability of this
|
||||
* software for any particular purpose. It is provided "as is"
|
||||
* without express or implied warranty of any kind.
|
||||
*
|
||||
* These notices must be retained in any copies of any part of this
|
||||
* documentation and/or software.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
#include <lib/libkern/libkern.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/md5.h>
|
||||
#define _DIAGASSERT(x) (void)0
|
||||
#else
|
||||
#if 0
|
||||
#include "namespace.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <minix/md5.h>
|
||||
#endif /* _KERNEL || _STANDALONE */
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef __minix
|
||||
#if defined(HAVE_MEMSET)
|
||||
#define ZEROIZE(d, l) memset((d), 0, (l))
|
||||
#else
|
||||
# if defined(HAVE_BZERO)
|
||||
#define ZEROIZE(d, l) bzero((d), (l))
|
||||
# else
|
||||
#error You need either memset or bzero
|
||||
# endif
|
||||
#endif
|
||||
#else
|
||||
#define ZEROIZE(d, l) memset((d), 0, (l))
|
||||
#endif
|
||||
|
||||
#define _DIAGASSERT assert
|
||||
|
||||
typedef unsigned char *POINTER;
|
||||
typedef uint16_t UINT2;
|
||||
typedef uint32_t UINT4;
|
||||
|
||||
/*
|
||||
* Constants for MD5Transform routine.
|
||||
*/
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
#if 0
|
||||
#if !defined(_KERNEL) && !defined(_STANDALONE) && defined(__weak_alias)
|
||||
__weak_alias(MD5Init,_MD5Init)
|
||||
__weak_alias(MD5Update,_MD5Update)
|
||||
__weak_alias(MD5Final,_MD5Final)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void MD5Transform __P((UINT4 [4], const unsigned char [64]));
|
||||
|
||||
static void Encode __P((unsigned char *, UINT4 *, unsigned int));
|
||||
static void Decode __P((UINT4 *, const unsigned char *, unsigned int));
|
||||
|
||||
/*
|
||||
* Encodes input (UINT4) into output (unsigned char). Assumes len is
|
||||
* a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
Encode (output, input, len)
|
||||
unsigned char *output;
|
||||
UINT4 *input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (unsigned char)(input[i] & 0xff);
|
||||
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Decodes input (unsigned char) into output (UINT4). Assumes len is
|
||||
* a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
Decode (output, input, len)
|
||||
UINT4 *output;
|
||||
const unsigned char *input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
|
||||
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
static const unsigned char PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* F, G, H and I are basic MD5 functions.
|
||||
*/
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/*
|
||||
* ROTATE_LEFT rotates x left n bits.
|
||||
*/
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/*
|
||||
* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
* Rotation is separate from addition to prevent recomputation.
|
||||
*/
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 initialization. Begins an MD5 operation, writing a new context.
|
||||
*/
|
||||
void
|
||||
MD5Init(context)
|
||||
MD5_CTX *context; /* context */
|
||||
{
|
||||
|
||||
_DIAGASSERT(context != 0);
|
||||
|
||||
context->count[0] = context->count[1] = 0;
|
||||
|
||||
/* Load magic initialization constants. */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 block update operation. Continues an MD5 message-digest
|
||||
* operation, processing another message block, and updating the
|
||||
* context.
|
||||
*/
|
||||
void
|
||||
MD5Update(context, input, inputLen)
|
||||
MD5_CTX *context; /* context */
|
||||
const unsigned char *input; /* input block */
|
||||
unsigned int inputLen; /* length of input block */
|
||||
{
|
||||
unsigned int i, idx, partLen;
|
||||
|
||||
_DIAGASSERT(context != 0);
|
||||
_DIAGASSERT(input != 0);
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((UINT4)inputLen << 3))
|
||||
< ((UINT4)inputLen << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += ((UINT4)inputLen >> 29);
|
||||
|
||||
partLen = 64 - idx;
|
||||
|
||||
/* Transform as many times as possible. */
|
||||
if (inputLen >= partLen) {
|
||||
/* LINTED const castaway ok */
|
||||
memcpy((POINTER)&context->buffer[idx],
|
||||
(POINTER)input, partLen);
|
||||
MD5Transform(context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD5Transform(context->state, &input[i]);
|
||||
|
||||
idx = 0;
|
||||
} else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
/* LINTED const castaway ok */
|
||||
memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i],
|
||||
inputLen - i);
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 finalization. Ends an MD5 message-digest operation, writing the
|
||||
* message digest and zeroing the context.
|
||||
*/
|
||||
void
|
||||
MD5Final(digest, context)
|
||||
unsigned char digest[16]; /* message digest */
|
||||
MD5_CTX *context; /* context */
|
||||
{
|
||||
unsigned char bits[8];
|
||||
unsigned int idx, padLen;
|
||||
|
||||
_DIAGASSERT(digest != 0);
|
||||
_DIAGASSERT(context != 0);
|
||||
|
||||
/* Save number of bits */
|
||||
Encode(bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64. */
|
||||
idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (idx < 56) ? (56 - idx) : (120 - idx);
|
||||
MD5Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
MD5Update(context, bits, 8);
|
||||
|
||||
/* Store state in digest */
|
||||
Encode(digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
ZEROIZE((POINTER)(void *)context, sizeof(*context));
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 basic transformation. Transforms state based on block.
|
||||
*/
|
||||
static void
|
||||
MD5Transform(state, block)
|
||||
UINT4 state[4];
|
||||
const unsigned char block[64];
|
||||
{
|
||||
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode(x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
ZEROIZE((POINTER)(void *)x, sizeof (x));
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/* $NetBSD: mdXhl.c,v 1.2 2008/10/06 12:36:20 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* from FreeBSD Id: mdXhl.c,v 1.8 1996/10/25 06:48:12 bde Exp
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modifed April 29, 1997 by Jason R. Thorpe <thorpej@NetBSD.org>
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <minix/md5.h>
|
||||
|
||||
#define MDALGORITHM MD5
|
||||
#define CONCAT(x,y) __CONCAT(x,y)
|
||||
#define MDNAME(x) CONCAT(MDALGORITHM,x)
|
||||
|
||||
#define _DIAGASSERT assert
|
||||
|
||||
char *
|
||||
MDNAME(End)(ctx, buf)
|
||||
MDNAME(_CTX) *ctx;
|
||||
char *buf;
|
||||
{
|
||||
int i;
|
||||
unsigned char digest[16];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
_DIAGASSERT(ctx != 0);
|
||||
|
||||
if (buf == NULL)
|
||||
buf = malloc(33);
|
||||
if (buf == NULL)
|
||||
return (NULL);
|
||||
|
||||
MDNAME(Final)(digest, ctx);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
buf[i+i] = hex[(uint32_t)digest[i] >> 4];
|
||||
buf[i+i+1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
|
||||
buf[i+i] = '\0';
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
MDNAME(File)(filename, buf)
|
||||
const char *filename;
|
||||
char *buf;
|
||||
{
|
||||
unsigned char buffer[BUFSIZ];
|
||||
MDNAME(_CTX) ctx;
|
||||
int f, i, j;
|
||||
|
||||
_DIAGASSERT(filename != 0);
|
||||
/* buf may be NULL */
|
||||
|
||||
MDNAME(Init)(&ctx);
|
||||
f = open(filename, O_RDONLY, 0666);
|
||||
if (f < 0)
|
||||
return NULL;
|
||||
|
||||
while ((i = read(f, buffer, sizeof(buffer))) > 0)
|
||||
MDNAME(Update)(&ctx, buffer, (unsigned int)i);
|
||||
|
||||
j = errno;
|
||||
close(f);
|
||||
errno = j;
|
||||
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
|
||||
return (MDNAME(End)(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
MDNAME(Data)(data, len, buf)
|
||||
const unsigned char *data;
|
||||
unsigned int len;
|
||||
char *buf;
|
||||
{
|
||||
MDNAME(_CTX) ctx;
|
||||
|
||||
_DIAGASSERT(data != 0);
|
||||
|
||||
MDNAME(Init)(&ctx);
|
||||
MDNAME(Update)(&ctx, data, len);
|
||||
return (MDNAME(End)(&ctx, buf));
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* openpty() tries to open a pty; applications won't have to
|
||||
* duplicate this code all the time (or change it if the system
|
||||
* pty interface changes).
|
||||
*
|
||||
* First version by Ben Gras <beng@few.vu.nl>,
|
||||
* Initially heavily based on telnetd/pty.c
|
||||
* by Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>.
|
||||
*
|
||||
*/
|
||||
#include <libutil.h>
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioc_tty.h>
|
||||
|
||||
#define DEV_DIR "/dev"
|
||||
|
||||
/*
|
||||
* Allocate a PTY, by trying to open one repeatedly.
|
||||
*/
|
||||
int openpty(int *amaster, int *aslave, char *name,
|
||||
struct termios *termp, struct winsize *winp)
|
||||
{
|
||||
char buff[128];
|
||||
register int i, j;
|
||||
static char tty_name[128];
|
||||
struct group *ttygroup;
|
||||
gid_t tty_gid = 0;
|
||||
|
||||
if(!amaster || !aslave) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 'p'; i < 'w'; i++) {
|
||||
j = 0;
|
||||
do {
|
||||
sprintf(buff, "%s/pty%c%c",
|
||||
DEV_DIR, i, (j < 10) ? j + '0' : j + 'a' - 10);
|
||||
|
||||
if((*amaster = open(buff, O_RDWR)) >= 0) {
|
||||
sprintf(tty_name, "%s/tty%c%c", DEV_DIR,
|
||||
i, (j < 10) ? j + '0' : j + 'a' - 10);
|
||||
if((*aslave = open(tty_name, O_RDWR)) >= 0)
|
||||
break;
|
||||
}
|
||||
close(*amaster);
|
||||
|
||||
j++;
|
||||
if (j == 16) break;
|
||||
} while(1);
|
||||
|
||||
/* Did we find one? */
|
||||
if (j < 16) break;
|
||||
}
|
||||
if (*amaster < 0) { errno = ENOENT; return(-1); }
|
||||
|
||||
setgrent();
|
||||
ttygroup = getgrnam("tty");
|
||||
endgrent();
|
||||
if(ttygroup) tty_gid = ttygroup->gr_gid;
|
||||
|
||||
if(name) strcpy(name, tty_name);
|
||||
|
||||
/* Ignore errors on these. */
|
||||
chown(tty_name, getuid(), tty_gid);
|
||||
chmod(tty_name, 0620); /* -rw--w---- */
|
||||
if(termp) tcsetattr(*aslave, TCSAFLUSH, termp);
|
||||
if(winp) ioctl(*aslave, TIOCSWINSZ, winp);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -1,295 +0,0 @@
|
||||
/* $NetBSD: sha1.c,v 1.8 2008/10/06 12:36:20 joerg Exp $ */
|
||||
/* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */
|
||||
|
||||
/*
|
||||
* SHA-1 in C
|
||||
* By Steve Reid <steve@edmweb.com>
|
||||
* 100% Public Domain
|
||||
*
|
||||
* Test Vectors (from FIPS PUB 180-1)
|
||||
* "abc"
|
||||
* A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
* "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
* 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
* A million repetitions of "a"
|
||||
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
#define SHA1HANDSOFF /* Copies data before messing with it. */
|
||||
|
||||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
#include <sys/param.h>
|
||||
#include <sys/sha1.h>
|
||||
#include <sys/systm.h>
|
||||
#define _DIAGASSERT(x) (void)0
|
||||
#else
|
||||
#if 0
|
||||
#include "namespace.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <minix/sha1.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
#define _DIAGASSERT assert
|
||||
|
||||
/*
|
||||
* XXX Kludge until there is resolution regarding mem*() functions
|
||||
* XXX in the kernel.
|
||||
*/
|
||||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
#define memcpy(s, d, l) bcopy((d), (s), (l))
|
||||
#endif
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
/*
|
||||
* blk0() and blk() perform the initial expand.
|
||||
* I got the idea of expanding during the round function from SSLeay
|
||||
*/
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|
||||
|(rol(block->l[i],8)&0x00FF00FF))
|
||||
#else
|
||||
# define blk0(i) block->l[i]
|
||||
#endif
|
||||
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
||||
^block->l[(i+2)&15]^block->l[i&15],1))
|
||||
|
||||
/*
|
||||
* (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
|
||||
*/
|
||||
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
|
||||
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
|
||||
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
|
||||
|
||||
|
||||
#if 0
|
||||
#if !defined(_KERNEL) && defined(__weak_alias)
|
||||
__weak_alias(SHA1Transform,_SHA1Transform)
|
||||
__weak_alias(SHA1Init,_SHA1Init)
|
||||
__weak_alias(SHA1Update,_SHA1Update)
|
||||
__weak_alias(SHA1Final,_SHA1Final)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
unsigned char c[64];
|
||||
unsigned int l[16];
|
||||
} CHAR64LONG16;
|
||||
|
||||
/* old sparc64 gcc could not compile this */
|
||||
#undef SPARC64_GCC_WORKAROUND
|
||||
#if defined(__sparc64__) && defined(__GNUC__) && __GNUC__ < 3
|
||||
#define SPARC64_GCC_WORKAROUND
|
||||
#endif
|
||||
|
||||
#ifdef SPARC64_GCC_WORKAROUND
|
||||
void do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *);
|
||||
void do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *);
|
||||
void do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *);
|
||||
void do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *);
|
||||
|
||||
#define nR0(v,w,x,y,z,i) R0(*v,*w,*x,*y,*z,i)
|
||||
#define nR1(v,w,x,y,z,i) R1(*v,*w,*x,*y,*z,i)
|
||||
#define nR2(v,w,x,y,z,i) R2(*v,*w,*x,*y,*z,i)
|
||||
#define nR3(v,w,x,y,z,i) R3(*v,*w,*x,*y,*z,i)
|
||||
#define nR4(v,w,x,y,z,i) R4(*v,*w,*x,*y,*z,i)
|
||||
|
||||
void
|
||||
do_R01(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
|
||||
{
|
||||
nR0(a,b,c,d,e, 0); nR0(e,a,b,c,d, 1); nR0(d,e,a,b,c, 2); nR0(c,d,e,a,b, 3);
|
||||
nR0(b,c,d,e,a, 4); nR0(a,b,c,d,e, 5); nR0(e,a,b,c,d, 6); nR0(d,e,a,b,c, 7);
|
||||
nR0(c,d,e,a,b, 8); nR0(b,c,d,e,a, 9); nR0(a,b,c,d,e,10); nR0(e,a,b,c,d,11);
|
||||
nR0(d,e,a,b,c,12); nR0(c,d,e,a,b,13); nR0(b,c,d,e,a,14); nR0(a,b,c,d,e,15);
|
||||
nR1(e,a,b,c,d,16); nR1(d,e,a,b,c,17); nR1(c,d,e,a,b,18); nR1(b,c,d,e,a,19);
|
||||
}
|
||||
|
||||
void
|
||||
do_R2(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
|
||||
{
|
||||
nR2(a,b,c,d,e,20); nR2(e,a,b,c,d,21); nR2(d,e,a,b,c,22); nR2(c,d,e,a,b,23);
|
||||
nR2(b,c,d,e,a,24); nR2(a,b,c,d,e,25); nR2(e,a,b,c,d,26); nR2(d,e,a,b,c,27);
|
||||
nR2(c,d,e,a,b,28); nR2(b,c,d,e,a,29); nR2(a,b,c,d,e,30); nR2(e,a,b,c,d,31);
|
||||
nR2(d,e,a,b,c,32); nR2(c,d,e,a,b,33); nR2(b,c,d,e,a,34); nR2(a,b,c,d,e,35);
|
||||
nR2(e,a,b,c,d,36); nR2(d,e,a,b,c,37); nR2(c,d,e,a,b,38); nR2(b,c,d,e,a,39);
|
||||
}
|
||||
|
||||
void
|
||||
do_R3(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
|
||||
{
|
||||
nR3(a,b,c,d,e,40); nR3(e,a,b,c,d,41); nR3(d,e,a,b,c,42); nR3(c,d,e,a,b,43);
|
||||
nR3(b,c,d,e,a,44); nR3(a,b,c,d,e,45); nR3(e,a,b,c,d,46); nR3(d,e,a,b,c,47);
|
||||
nR3(c,d,e,a,b,48); nR3(b,c,d,e,a,49); nR3(a,b,c,d,e,50); nR3(e,a,b,c,d,51);
|
||||
nR3(d,e,a,b,c,52); nR3(c,d,e,a,b,53); nR3(b,c,d,e,a,54); nR3(a,b,c,d,e,55);
|
||||
nR3(e,a,b,c,d,56); nR3(d,e,a,b,c,57); nR3(c,d,e,a,b,58); nR3(b,c,d,e,a,59);
|
||||
}
|
||||
|
||||
void
|
||||
do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LONG16 *block)
|
||||
{
|
||||
nR4(a,b,c,d,e,60); nR4(e,a,b,c,d,61); nR4(d,e,a,b,c,62); nR4(c,d,e,a,b,63);
|
||||
nR4(b,c,d,e,a,64); nR4(a,b,c,d,e,65); nR4(e,a,b,c,d,66); nR4(d,e,a,b,c,67);
|
||||
nR4(c,d,e,a,b,68); nR4(b,c,d,e,a,69); nR4(a,b,c,d,e,70); nR4(e,a,b,c,d,71);
|
||||
nR4(d,e,a,b,c,72); nR4(c,d,e,a,b,73); nR4(b,c,d,e,a,74); nR4(a,b,c,d,e,75);
|
||||
nR4(e,a,b,c,d,76); nR4(d,e,a,b,c,77); nR4(c,d,e,a,b,78); nR4(b,c,d,e,a,79);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hash a single 512-bit block. This is the core of the algorithm.
|
||||
*/
|
||||
void SHA1Transform(state, buffer)
|
||||
uint32_t state[5];
|
||||
const unsigned char buffer[64];
|
||||
{
|
||||
uint32_t a, b, c, d, e;
|
||||
CHAR64LONG16 *block;
|
||||
|
||||
#ifdef SHA1HANDSOFF
|
||||
CHAR64LONG16 workspace;
|
||||
#endif
|
||||
|
||||
_DIAGASSERT(buffer != 0);
|
||||
_DIAGASSERT(state != 0);
|
||||
|
||||
#ifdef SHA1HANDSOFF
|
||||
block = &workspace;
|
||||
(void)memcpy(block, buffer, 64);
|
||||
#else
|
||||
block = (CHAR64LONG16 *)(void *)buffer;
|
||||
#endif
|
||||
|
||||
/* Copy context->state[] to working vars */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
|
||||
#ifdef SPARC64_GCC_WORKAROUND
|
||||
do_R01(&a, &b, &c, &d, &e, block);
|
||||
do_R2(&a, &b, &c, &d, &e, block);
|
||||
do_R3(&a, &b, &c, &d, &e, block);
|
||||
do_R4(&a, &b, &c, &d, &e, block);
|
||||
#else
|
||||
/* 4 rounds of 20 operations each. Loop unrolled. */
|
||||
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
||||
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
||||
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
||||
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
||||
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
||||
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
||||
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
||||
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
||||
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
||||
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
||||
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
||||
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
||||
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
||||
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
||||
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
||||
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
||||
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
||||
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
||||
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
||||
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
||||
#endif
|
||||
|
||||
/* Add the working vars back into context.state[] */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
|
||||
/* Wipe variables */
|
||||
a = b = c = d = e = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SHA1Init - Initialize new context
|
||||
*/
|
||||
void SHA1Init(context)
|
||||
SHA1_CTX *context;
|
||||
{
|
||||
|
||||
_DIAGASSERT(context != 0);
|
||||
|
||||
/* SHA1 initialization constants */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xEFCDAB89;
|
||||
context->state[2] = 0x98BADCFE;
|
||||
context->state[3] = 0x10325476;
|
||||
context->state[4] = 0xC3D2E1F0;
|
||||
context->count[0] = context->count[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Run your data through this.
|
||||
*/
|
||||
void SHA1Update(context, data, len)
|
||||
SHA1_CTX *context;
|
||||
const unsigned char *data;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
_DIAGASSERT(context != 0);
|
||||
_DIAGASSERT(data != 0);
|
||||
|
||||
j = context->count[0];
|
||||
if ((context->count[0] += len << 3) < j)
|
||||
context->count[1] += (len>>29)+1;
|
||||
j = (j >> 3) & 63;
|
||||
if ((j + len) > 63) {
|
||||
(void)memcpy(&context->buffer[j], data, (i = 64-j));
|
||||
SHA1Transform(context->state, context->buffer);
|
||||
for ( ; i + 63 < len; i += 64)
|
||||
SHA1Transform(context->state, &data[i]);
|
||||
j = 0;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
(void)memcpy(&context->buffer[j], &data[i], len - i);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add padding and return the message digest.
|
||||
*/
|
||||
void SHA1Final(digest, context)
|
||||
unsigned char digest[20];
|
||||
SHA1_CTX* context;
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char finalcount[8];
|
||||
|
||||
_DIAGASSERT(digest != 0);
|
||||
_DIAGASSERT(context != 0);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
|
||||
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
||||
}
|
||||
SHA1Update(context, (unsigned char *)"\200", 1);
|
||||
while ((context->count[0] & 504) != 448)
|
||||
SHA1Update(context, (unsigned char *)"\0", 1);
|
||||
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
||||
|
||||
if (digest) {
|
||||
for (i = 0; i < 20; i++)
|
||||
digest[i] = (unsigned char)
|
||||
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
/* $NetBSD: sha1hl.c,v 1.8 2008/10/06 12:36:20 joerg Exp $ */
|
||||
|
||||
/* sha1hl.c
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include "namespace.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <minix/sha1.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define _DIAGASSERT assert
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: sha1hl.c,v 1.8 2008/10/06 12:36:20 joerg Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#if 0
|
||||
#if defined(__weak_alias)
|
||||
__weak_alias(SHA1End,_SHA1End)
|
||||
__weak_alias(SHA1File,_SHA1File)
|
||||
__weak_alias(SHA1Data,_SHA1Data)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ARGSUSED */
|
||||
char *
|
||||
SHA1End(ctx, buf)
|
||||
SHA1_CTX *ctx;
|
||||
char *buf;
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
unsigned char digest[20];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
_DIAGASSERT(ctx != NULL);
|
||||
/* buf may be NULL */
|
||||
|
||||
if (p == NULL && (p = malloc(41)) == NULL)
|
||||
return 0;
|
||||
|
||||
SHA1Final(digest,ctx);
|
||||
for (i = 0; i < 20; i++) {
|
||||
p[i + i] = hex[((uint32_t)digest[i]) >> 4];
|
||||
p[i + i + 1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
p[i + i] = '\0';
|
||||
return(p);
|
||||
}
|
||||
|
||||
char *
|
||||
SHA1File (filename, buf)
|
||||
char *filename;
|
||||
char *buf;
|
||||
{
|
||||
unsigned char buffer[BUFSIZ];
|
||||
SHA1_CTX ctx;
|
||||
int fd, num, oerrno;
|
||||
|
||||
_DIAGASSERT(filename != NULL);
|
||||
/* XXX: buf may be NULL ? */
|
||||
|
||||
SHA1Init(&ctx);
|
||||
|
||||
if ((fd = open(filename,O_RDONLY)) < 0)
|
||||
return(0);
|
||||
|
||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
|
||||
SHA1Update(&ctx, buffer, (size_t)num);
|
||||
|
||||
oerrno = errno;
|
||||
close(fd);
|
||||
errno = oerrno;
|
||||
return(num < 0 ? 0 : SHA1End(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
SHA1Data (data, len, buf)
|
||||
const unsigned char *data;
|
||||
size_t len;
|
||||
char *buf;
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
|
||||
_DIAGASSERT(data != NULL);
|
||||
/* XXX: buf may be NULL ? */
|
||||
|
||||
SHA1Init(&ctx);
|
||||
SHA1Update(&ctx, data, len);
|
||||
return(SHA1End(&ctx, buf));
|
||||
}
|
||||
1165
lib/libutil/sha2.c
1165
lib/libutil/sha2.c
File diff suppressed because it is too large
Load Diff
@@ -1,246 +0,0 @@
|
||||
/* $NetBSD: sha2hl.c,v 1.7 2007/07/31 13:17:34 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* sha2hl.c
|
||||
* This code includes some functions taken from sha2.c, hence the
|
||||
* following licence reproduction.
|
||||
*
|
||||
* This code is not a verbatim copy, since some routines have been added,
|
||||
* and some bugs have been fixed.
|
||||
*
|
||||
* Version 1.0.0beta1
|
||||
*
|
||||
* Written by Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
* Copyright 2000 Aaron D. Gifford. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <minix/sha2.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef _DIAGASSERT
|
||||
#define _DIAGASSERT(cond) assert(cond)
|
||||
#endif
|
||||
|
||||
#ifndef MEMSET_BZERO
|
||||
#define MEMSET_BZERO(p,l) memset((p), 0, (l))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constant used by SHA256/384/512_End() functions for converting the
|
||||
* digest to a readable hexadecimal character string:
|
||||
*/
|
||||
static const char sha2_hex_digits[] = "0123456789abcdef";
|
||||
|
||||
char *
|
||||
SHA256_File(char *filename, char *buf)
|
||||
{
|
||||
unsigned char buffer[SHA256_DIGEST_STRING_LENGTH];
|
||||
SHA256_CTX ctx;
|
||||
int fd, num, oerrno;
|
||||
|
||||
_DIAGASSERT(filename != NULL);
|
||||
/* XXX: buf may be NULL ? */
|
||||
|
||||
SHA256_Init(&ctx);
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
return (0);
|
||||
|
||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
|
||||
SHA256_Update(&ctx, buffer, (size_t) num);
|
||||
|
||||
oerrno = errno;
|
||||
close(fd);
|
||||
errno = oerrno;
|
||||
return (num < 0 ? 0 : SHA256_End(&ctx, buf));
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
SHA256_End(SHA256_CTX *ctx, char buffer[SHA256_DIGEST_STRING_LENGTH])
|
||||
{
|
||||
unsigned char digest[SHA256_DIGEST_LENGTH], *d = digest;
|
||||
unsigned char *ret;
|
||||
int i;
|
||||
|
||||
/* Sanity check: */
|
||||
assert(ctx != NULL);
|
||||
|
||||
if ((ret = (unsigned char *)buffer) != NULL) {
|
||||
SHA256_Final(digest, ctx);
|
||||
|
||||
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
|
||||
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
|
||||
*buffer++ = sha2_hex_digits[*d & 0x0f];
|
||||
d++;
|
||||
}
|
||||
*buffer = (char) 0;
|
||||
} else {
|
||||
(void) MEMSET_BZERO(ctx, sizeof(SHA256_CTX));
|
||||
}
|
||||
(void) MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
|
||||
return (char *)ret;
|
||||
}
|
||||
|
||||
char *
|
||||
SHA256_Data(const uint8_t * data, size_t len, unsigned char digest[SHA256_DIGEST_STRING_LENGTH])
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, data, len);
|
||||
return SHA256_End(&ctx, (char *)digest);
|
||||
}
|
||||
|
||||
char *
|
||||
SHA384_File(char *filename, char *buf)
|
||||
{
|
||||
SHA384_CTX ctx;
|
||||
unsigned char buffer[SHA384_DIGEST_STRING_LENGTH];
|
||||
int fd, num, oerrno;
|
||||
|
||||
_DIAGASSERT(filename != NULL);
|
||||
/* XXX: buf may be NULL ? */
|
||||
|
||||
SHA384_Init(&ctx);
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
return (0);
|
||||
|
||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
|
||||
SHA384_Update(&ctx, buffer, (size_t) num);
|
||||
|
||||
oerrno = errno;
|
||||
close(fd);
|
||||
errno = oerrno;
|
||||
return (num < 0 ? 0 : SHA384_End(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
SHA384_End(SHA384_CTX * ctx, char buffer[SHA384_DIGEST_STRING_LENGTH])
|
||||
{
|
||||
unsigned char digest[SHA384_DIGEST_LENGTH], *d = digest;
|
||||
unsigned char *ret;
|
||||
int i;
|
||||
|
||||
/* Sanity check: */
|
||||
assert(ctx != NULL);
|
||||
|
||||
if ((ret = (unsigned char *)buffer) != NULL) {
|
||||
SHA384_Final(digest, ctx);
|
||||
|
||||
for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
|
||||
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
|
||||
*buffer++ = sha2_hex_digits[*d & 0x0f];
|
||||
d++;
|
||||
}
|
||||
*buffer = (char) 0;
|
||||
} else {
|
||||
(void) MEMSET_BZERO(ctx, sizeof(SHA384_CTX));
|
||||
}
|
||||
(void) MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
|
||||
return (char *)ret;
|
||||
}
|
||||
|
||||
char *
|
||||
SHA384_Data(const uint8_t* data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH])
|
||||
{
|
||||
SHA384_CTX ctx;
|
||||
|
||||
SHA384_Init(&ctx);
|
||||
SHA384_Update(&ctx, data, len);
|
||||
return SHA384_End(&ctx, digest);
|
||||
}
|
||||
|
||||
char *
|
||||
SHA512_File(char *filename, char *buf)
|
||||
{
|
||||
SHA512_CTX ctx;
|
||||
unsigned char buffer[SHA512_DIGEST_STRING_LENGTH];
|
||||
int fd, num, oerrno;
|
||||
|
||||
_DIAGASSERT(filename != NULL);
|
||||
/* XXX: buf may be NULL ? */
|
||||
|
||||
SHA512_Init(&ctx);
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
return (0);
|
||||
|
||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
|
||||
SHA512_Update(&ctx, buffer, (size_t) num);
|
||||
|
||||
oerrno = errno;
|
||||
close(fd);
|
||||
errno = oerrno;
|
||||
return (num < 0 ? 0 : SHA512_End(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
SHA512_End(SHA512_CTX * ctx, char buffer[SHA512_DIGEST_STRING_LENGTH])
|
||||
{
|
||||
unsigned char digest[SHA512_DIGEST_LENGTH], *d = digest;
|
||||
unsigned char *ret;
|
||||
int i;
|
||||
|
||||
/* Sanity check: */
|
||||
assert(ctx != NULL);
|
||||
|
||||
if ((ret = (unsigned char *)buffer) != NULL) {
|
||||
SHA512_Final(digest, ctx);
|
||||
|
||||
for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
|
||||
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
|
||||
*buffer++ = sha2_hex_digits[*d & 0x0f];
|
||||
d++;
|
||||
}
|
||||
*buffer = (char) 0;
|
||||
} else {
|
||||
(void) MEMSET_BZERO(ctx, sizeof(SHA512_CTX));
|
||||
}
|
||||
(void) MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
|
||||
return (char *)ret;
|
||||
}
|
||||
|
||||
char *
|
||||
SHA512_Data(const uint8_t * data, size_t len, char *digest)
|
||||
{
|
||||
SHA512_CTX ctx;
|
||||
|
||||
SHA512_Init(&ctx);
|
||||
SHA512_Update(&ctx, data, len);
|
||||
return SHA512_End(&ctx, digest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user