original files of m241
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#
|
||||
# Copyright (C) 2013 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
# Revision history
|
||||
# -------------------
|
||||
# 01c,31jan13,bbz create this file
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
|
||||
|
||||
OEM=
|
||||
SOFTPORT=$(SRCDIR)/target/usr/h/wrn/wm/util/port/vxworks
|
||||
HARDPORT=
|
||||
SRCDIR=$(WIND_BASE)
|
||||
XCFLAGS=
|
||||
EXTRA_PRODUCTS=
|
||||
WMSNMP_ADDED_OBJS=
|
||||
WMSNMP_ADDED_MIBS=
|
||||
MIBCOMPILER=mibcomp
|
||||
TOUCH=touch
|
||||
MAKEFILENAME=makefile.wmsnmp
|
||||
CLEAN_LIST=
|
||||
ETC_INI_FILES=etc.ini
|
||||
TGT_DIR=$(WIND_BASE)/target
|
||||
WMINC=$(SRCDIR)/target/h
|
||||
MIBCOMPFLAGS=-l $(SRCDIR)/target/src/wrn/wm/snmp/std-mibs -quiet
|
||||
|
||||
PRODUCTH=$(SRCDIR)/target/h/wrn/wm/common
|
||||
|
||||
WIND_BASE := $(subst \,/,$(WIND_BASE))
|
||||
|
||||
ifeq ($(EXTRA_DEFINE),)
|
||||
export EXTRA_DEFINE=
|
||||
endif
|
||||
|
||||
override EXTRA_DEFINE+=-fno-strict-aliasing
|
||||
|
||||
OBJ = o
|
||||
LIBEXT = a
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# These next 3 lines must come before any of the application rules.
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
include $(WIND_USR)/make/defs.default
|
||||
include $(WIND_USR)/tool/$(TOOL_FAMILY)/make.$(CPU)$(TOOL)
|
||||
|
||||
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
WEAKPRNG_OBJS=weakprng.o
|
||||
PRNG_OBJS=
|
||||
MD4_OBJS=
|
||||
MD5_OBJS=snmpMd5.o
|
||||
SHA_OBJS=snmpSha.o
|
||||
HMAC_OBJS=snmpHmac.o
|
||||
DESTESTOBJS=des_test.o
|
||||
|
||||
STRING_OBJS=
|
||||
|
||||
THREAD_OBJS=
|
||||
|
||||
FIXED64_OBJS=fixed64.o
|
||||
|
||||
OBJS=cmn_init.o $(WEAKPRNG_OBJS) $(PRNG_OBJS) $(MD4_OBJS) $(MD5_OBJS) $(SHA_OBJS) $(HMAC_OBJS) $(STRING_OBJS) $(THREAD_OBJS) $(FIXED64_OBJS)
|
||||
|
||||
LIB_BASE_NAME=epcommon
|
||||
|
||||
include $(WIND_USR)/make/rules.library
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/cmn_init.c,v 1.3 2003/01/16 18:18:54 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: cmn_init.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:54 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:50 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:30 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:52 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 2000/02/04 21:46:25 josh
|
||||
* added some prototypes and includes so the vxWorks compiler
|
||||
* is happy
|
||||
*
|
||||
* Revision 1.1 1999/03/06 06:54:36 paul
|
||||
* moved common_init from prng.c to cmn_init.c
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
#include <wrn/wm/common/cmn_init.h>
|
||||
|
||||
#if INSTALL_COMMON_PRNG
|
||||
#include <wrn/wm/common/prng.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
etc_common_init(void)
|
||||
{
|
||||
#if INSTALL_COMMON_PRNG
|
||||
prng_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES test cases from NBS DES certification suite
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/des.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#ifndef PRINTF
|
||||
#define PRINTF printf
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define DES_TEST_CASES 34
|
||||
|
||||
bits8_t keys [DES_TEST_CASES][8] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
|
||||
{ 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
|
||||
{ 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
|
||||
{ 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
|
||||
{ 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
|
||||
{ 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
|
||||
{ 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
|
||||
{ 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
|
||||
{ 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
|
||||
{ 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
|
||||
{ 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
|
||||
{ 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
|
||||
{ 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
|
||||
{ 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
|
||||
{ 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
|
||||
{ 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
|
||||
{ 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
|
||||
{ 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
|
||||
{ 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
|
||||
{ 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
|
||||
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
|
||||
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
|
||||
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
|
||||
};
|
||||
|
||||
bits8_t ptext [DES_TEST_CASES][8] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42 },
|
||||
{ 0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA },
|
||||
{ 0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72 },
|
||||
{ 0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A },
|
||||
{ 0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2 },
|
||||
{ 0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A },
|
||||
{ 0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2 },
|
||||
{ 0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A },
|
||||
{ 0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02 },
|
||||
{ 0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A },
|
||||
{ 0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32 },
|
||||
{ 0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA },
|
||||
{ 0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62 },
|
||||
{ 0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2 },
|
||||
{ 0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA },
|
||||
{ 0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92 },
|
||||
{ 0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A },
|
||||
{ 0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2 },
|
||||
{ 0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
};
|
||||
|
||||
bits8_t ctext [DES_TEST_CASES][8] =
|
||||
{
|
||||
{ 0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7 },
|
||||
{ 0x73, 0x59, 0xB2, 0x16, 0x3E, 0x4E, 0xDC, 0x58 },
|
||||
{ 0x95, 0x8E, 0x6E, 0x62, 0x7A, 0x05, 0x55, 0x7B },
|
||||
{ 0xF4, 0x03, 0x79, 0xAB, 0x9E, 0x0E, 0xC5, 0x33 },
|
||||
{ 0x17, 0x66, 0x8D, 0xFC, 0x72, 0x92, 0x53, 0x2D },
|
||||
{ 0x8A, 0x5A, 0xE1, 0xF8, 0x1A, 0xB8, 0xF2, 0xDD },
|
||||
{ 0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7 },
|
||||
{ 0xED, 0x39, 0xD9, 0x50, 0xFA, 0x74, 0xBC, 0xC4 },
|
||||
{ 0x69, 0x0F, 0x5B, 0x0D, 0x9A, 0x26, 0x93, 0x9B },
|
||||
{ 0x7A, 0x38, 0x9D, 0x10, 0x35, 0x4B, 0xD2, 0x71 },
|
||||
{ 0x86, 0x8E, 0xBB, 0x51, 0xCA, 0xB4, 0x59, 0x9A },
|
||||
{ 0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A },
|
||||
{ 0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95 },
|
||||
{ 0x86, 0xA5, 0x60, 0xF1, 0x0E, 0xC6, 0xD8, 0x5B },
|
||||
{ 0x0C, 0xD3, 0xDA, 0x02, 0x00, 0x21, 0xDC, 0x09 },
|
||||
{ 0xEA, 0x67, 0x6B, 0x2C, 0xB7, 0xDB, 0x2B, 0x7A },
|
||||
{ 0xDF, 0xD6, 0x4A, 0x81, 0x5C, 0xAF, 0x1A, 0x0F },
|
||||
{ 0x5C, 0x51, 0x3C, 0x9C, 0x48, 0x86, 0xC0, 0x88 },
|
||||
{ 0x0A, 0x2A, 0xEE, 0xAE, 0x3F, 0xF4, 0xAB, 0x77 },
|
||||
{ 0xEF, 0x1B, 0xF0, 0x3E, 0x5D, 0xFA, 0x57, 0x5A },
|
||||
{ 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 },
|
||||
{ 0xA1, 0xF9, 0x91, 0x55, 0x41, 0x02, 0x0B, 0x56 },
|
||||
{ 0x6F, 0xBF, 0x1C, 0xAF, 0xCF, 0xFD, 0x05, 0x56 },
|
||||
{ 0x2F, 0x22, 0xE4, 0x9B, 0xAB, 0x7C, 0xA1, 0xAC },
|
||||
{ 0x5A, 0x6B, 0x61, 0x2C, 0xC2, 0x6C, 0xCE, 0x4A },
|
||||
{ 0x5F, 0x4C, 0x03, 0x8E, 0xD1, 0x2B, 0x2E, 0x41 },
|
||||
{ 0x63, 0xFA, 0xC0, 0xD0, 0x34, 0xD9, 0xF7, 0x93 },
|
||||
{ 0x61, 0x7B, 0x3A, 0x0C, 0xE8, 0xF0, 0x71, 0x00 },
|
||||
{ 0xDB, 0x95, 0x86, 0x05, 0xF8, 0xC8, 0xC6, 0x06 },
|
||||
{ 0xED, 0xBF, 0xD1, 0xC6, 0x6C, 0x29, 0xCC, 0xC7 },
|
||||
{ 0x35, 0x55, 0x50, 0xB2, 0x15, 0x0E, 0x24, 0x51 },
|
||||
{ 0xCA, 0xAA, 0xAF, 0x4D, 0xEA, 0xF1, 0xDB, 0xAE },
|
||||
{ 0xD5, 0xD4, 0x4F, 0xF7, 0x20, 0x68, 0x3D, 0x0D },
|
||||
{ 0x2A, 0x2B, 0xB0, 0x08, 0xDF, 0x97, 0xC2, 0xF2 }
|
||||
};
|
||||
|
||||
int main ()
|
||||
{
|
||||
int i;
|
||||
DES_KS k;
|
||||
int err = 0;
|
||||
|
||||
|
||||
for (i = 0 ; i < DES_TEST_CASES ; i++)
|
||||
{ deskey (k, keys [i], 0);
|
||||
des (k, ptext [i], ptext [i]);
|
||||
if (MEMCMP (ptext [i], ctext [i], 8) != 0)
|
||||
{
|
||||
err++;
|
||||
PRINTF("failure on test %d\n", i);
|
||||
}
|
||||
else
|
||||
PRINTF("success on test %d\n", i);
|
||||
}
|
||||
|
||||
return (err != 0);
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/fixed64.c,v 1.3 2003/01/16 18:18:55 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Fixed-point 64-bit math routines, intended primarily for time conversion
|
||||
* between Attache milliseconds and pSOSystem "ticks". These routines
|
||||
* are in the common library because they may be useful for other
|
||||
* applications, but these functions are not a full-fleged 64-bit math
|
||||
* library.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: fixed64.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:55 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:50 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:30 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:53 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1999/03/01 20:08:56 sra
|
||||
* Add fixed-point 64-bit math routines; these are primarily intended for
|
||||
* converting between Attache and pSOSystem clock values, but the
|
||||
* functions themselves aren't specific to that.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/bug.h>
|
||||
#include <wrn/wm/common/fixed64.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
/*
|
||||
* Multiply two-64 bit unsigned fixed-point numbers (32 integer bits, 32
|
||||
* fractional bits) and return the integer part of the result, mod 2**32.
|
||||
*
|
||||
* The algorithm here is from Knuth, volume 2, 2nd edition, page 278.
|
||||
* We're trying to multiply two 2N-bit numbers u and v:
|
||||
*
|
||||
* u = 2**N * u1 + u0
|
||||
* v = 2**N * v1 + v0
|
||||
*
|
||||
* u * v = (2**(2*N) + 2**N ) * (u1 * v1)
|
||||
* + ( 2**N ) * ((u1 - u0) * (v0 - v1))
|
||||
* + ( 2**N + 1) * (u0 * v0)
|
||||
*
|
||||
* We use this algorithm twice, once with N=32, once with N=16.
|
||||
*
|
||||
* The final calculation yields a 128 bit result, but we can drop some
|
||||
* terms because we know they're just going to be outside the range of
|
||||
* the final result anyway. All we really want are the bits of the
|
||||
* result from 2**32 through 2**63, inclusive. So we can throw away
|
||||
* the 2**64 term, and we can use native arithmetic for all the 2**32
|
||||
* terms because we don't care about any high bits in those terms.
|
||||
* However, we have to calculate all 64 bits of the (u0 * v0) product
|
||||
* because of possible carries from the final term (1 * u0 * v0),
|
||||
* so we use this algorithm again, this time with N=16 (that is, using
|
||||
* the low 16 bits of 32-bit integers, so that we don't lose any bits).
|
||||
*
|
||||
* Most of the work here is just calculating the (x0 * y0) product,
|
||||
* and most of that is just the grunt work of summing up the 16-bit
|
||||
* partial products. The only tricky bit is handling the sign of the
|
||||
* "b" term; the multiplication itself comes out correctly, but the
|
||||
* sign bit doesn't propegate correctly through the summation without
|
||||
* some help.
|
||||
*/
|
||||
|
||||
bits32_t fixed64_mul(bits32_t x1, /* high bits of X */
|
||||
bits32_t x0, /* low bits of X */
|
||||
bits32_t y1, /* high bits of Y */
|
||||
bits32_t y0) /* low bits of Y */
|
||||
{
|
||||
bits32_t u1 = x0 >> 16, u0 = x0 & 0xFFFF;
|
||||
bits32_t v1 = y0 >> 16, v0 = y0 & 0xFFFF;
|
||||
bits32_t a = u1 * v1;
|
||||
bits32_t b = (u1 - u0) * (v0 - v1);
|
||||
bits32_t c = u0 * v0;
|
||||
bits32_t p1 = a, p0 = c, w;
|
||||
|
||||
w = p0, p0 += (a << 16), p1 += (a >> 16) + (p0 < w);
|
||||
w = p0, p0 += (c << 16), p1 += (c >> 16) + (p0 < w);
|
||||
|
||||
w = p0;
|
||||
if ((u1 < u0) != (v0 < v1))
|
||||
p0 -= (-b << 16), p1 -= (-b >> 16) + (p0 > w);
|
||||
else
|
||||
p0 += ( b << 16), p1 += ( b >> 16) + (p0 < w);
|
||||
|
||||
return x1 * y1 + (x1 - x0) * (y0 - y1) + p0 + p1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Divide a 32-bit unsigned integer by another 32-bit unsigned integer
|
||||
* to form a 64-bit unsigned fixed point number (32 integer bits, 32
|
||||
* fractional bits).
|
||||
*
|
||||
* We only expect to use this function at boot time, so it's optimized
|
||||
* for small code space and readability rather than speed of the
|
||||
* algorithm. Intended use is to compute things like the conversion
|
||||
* ratios between milliseconds (Attache) and "ticks" (pSOSystem).
|
||||
*/
|
||||
|
||||
void fixed64_div(bits32_t numerator,
|
||||
bits32_t denominator,
|
||||
bits32_t *integer,
|
||||
bits32_t *fractional)
|
||||
{
|
||||
bits32_t dividend;
|
||||
bits32_t remainder;
|
||||
bits32_t overflow;
|
||||
|
||||
BUG_ASSERT(denominator != 0 && integer != 0 && fractional != 0);
|
||||
|
||||
*integer = numerator / denominator;
|
||||
remainder = numerator % denominator;
|
||||
*fractional = 0;
|
||||
|
||||
for (dividend = 0x80000000;
|
||||
dividend && remainder;
|
||||
dividend >>= 1) {
|
||||
overflow = remainder & 0x80000000;
|
||||
remainder <<= 1;
|
||||
if (overflow || remainder >= denominator) {
|
||||
remainder -= denominator;
|
||||
*fractional += dividend;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
#
|
||||
# Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
|
||||
# [clearcase]
|
||||
# modification history
|
||||
# -------------------
|
||||
# 01b,01aug07,jbl filenames change so makefile changes
|
||||
# 01a,20apr05,job update copyright notices
|
||||
#
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
|
||||
$#equate(PRODUCTH $#filepath($(SRCDIR) target h wrn wm common))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
$#equate(WEAKPRNG_OBJS $#objs(weakprng))
|
||||
$#equate(PRNG_OBJS $#if-installed(COMMON_PRNG $#objs(prng)))
|
||||
$#equate(MD4_OBJS $#if-installed(COMMON_MD4 $#objs(md4)))
|
||||
$#equate(MD5_OBJS $#if-installed(COMMON_MD5 $#objs(snmpMd5)))
|
||||
$#equate(SHA_OBJS $#if-installed(COMMON_SHA $#objs(snmpSha)))
|
||||
$#equate(HMAC_OBJS $#if-installed(COMMON_HMAC $#objs(snmpHmac)))
|
||||
$#equate(DESTESTOBJS $#objs(des_test))
|
||||
|
||||
$#equate(STRING_OBJS
|
||||
$#if-installed(COMMON_STRTOL $#objs(strtol))
|
||||
$#if-installed(COMMON_STRTOUL $#objs(strtoul))
|
||||
$#if-installed(COMMON_STRICMP $#objs(stricmp))
|
||||
$#if-installed(COMMON_STRNICMP $#objs(strnicmp))
|
||||
$#if-installed(COMMON_MEMCMP $#objs(memcmp))
|
||||
$#if-installed(COMMON_SNPRINTF $#objs(snprintf))
|
||||
$#if-installed(COMMON_STRNCPY $#objs(strncpy))
|
||||
)
|
||||
|
||||
$#equate(THREAD_OBJS $#if-installed(THREAD_DEBUG $#objs(thd_dbg)))
|
||||
|
||||
$#equate(FIXED64_OBJS $#if-installed(COMMON_FIXED64 $#objs(fixed64)))
|
||||
|
||||
$#equate(OBJS $#objs(cmn_init)
|
||||
$#(WEAKPRNG_OBJS)
|
||||
$#(PRNG_OBJS)
|
||||
$#(MD4_OBJS)
|
||||
$#(MD5_OBJS)
|
||||
$#(SHA_OBJS)
|
||||
$#(HMAC_OBJS)
|
||||
$#(STRING_OBJS)
|
||||
$#(THREAD_OBJS)
|
||||
$#(FIXED64_OBJS))
|
||||
|
||||
all: $#libs(epcommon) $#if-installed(COMMON_DES_TEST $#exes(des_test)) $#dummy()
|
||||
|
||||
##############################################################################
|
||||
# Make the library itself
|
||||
|
||||
$#makelib(epcommon $#(OBJS) $(MAKEFILENAME))
|
||||
|
||||
##############################################################################
|
||||
# Make the des verification program
|
||||
$#makeexe(des_test $#progn($#(DESTESTOBJS)) $#progn($#libs(epcommon) $#libs(epdes)) $(MAKEFILENAME))
|
||||
|
||||
##############################################################################
|
||||
# commands to figure out how big this all compiles to
|
||||
|
||||
sizes: $#dummy()
|
||||
$#makesizehdr(Epilogue Common)
|
||||
$#if-installed(COMMON_PRNG $#makesize(PRNG $(PRNG_OBJS))
|
||||
$#makesizenone(PRNG))
|
||||
$#if-installed(COMMON_MD4 $#makesize(MD4 $(MD4_OBJS))
|
||||
$#makesizenone(MD4))
|
||||
$#if-installed(COMMON_MD5 $#makesize(MD5 $(MD5_OBJS))
|
||||
$#makesizenone(MD5))
|
||||
$#if-installed(COMMON_SHA $#makesize(SHA $(SHA_OBJS))
|
||||
$#makesizenone(SHA))
|
||||
$#if-installed(COMMON_HMAC $#makesize(HMAC $(HMAC_OBJS))
|
||||
$#makesizenone(HMAC))
|
||||
$#makesize(WEAKPRNG $(WEAKPRNG_OBJS))
|
||||
|
||||
clean: $#dummy()
|
||||
-$(RM) $#objs(*)
|
||||
-$(RM) $#libs(epcommon)
|
||||
-$(RM) $#libs(epdes)
|
||||
-$(RM) $#exes(des_test)
|
||||
$#clean()
|
||||
|
||||
##############################################################################
|
||||
# file dependencies
|
||||
|
||||
$#objs(cmn_init) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common cmn_init.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common prng.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
cmn_init.c
|
||||
)
|
||||
$#objs(des_test) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common des.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
des_test.c
|
||||
)
|
||||
$#objs(fixed64) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common bug.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common bugdef.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common fixed64.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
fixed64.c
|
||||
)
|
||||
$#objs(hmac) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common hmac.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
hmac.c
|
||||
)
|
||||
$#objs(md4) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common glue.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common md4.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common snprintf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
md4.c
|
||||
)
|
||||
$#objs(md5) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common md5.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
md5.c
|
||||
)
|
||||
$#objs(memcmp) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
memcmp.c
|
||||
)
|
||||
$#objs(prng) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common md5.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common prng.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
prng.c
|
||||
)
|
||||
$#objs(sha) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common sha.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
sha.c
|
||||
)
|
||||
$#objs(snprintf) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common snprintf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
snprintf.c
|
||||
)
|
||||
$#objs(stricmp) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
stricmp.c
|
||||
)
|
||||
$#objs(strncpy) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strncpy.c
|
||||
)
|
||||
$#objs(strnicmp) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strnicmp.c
|
||||
)
|
||||
$#objs(strtol) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strtol.c
|
||||
)
|
||||
$#objs(strtoul) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strtoul.c
|
||||
)
|
||||
$#objs(thd_dbg) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm attache config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm attache packet.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common bug.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common bugdef.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common thread.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(attache.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
$#port-hdr(thdport.h)
|
||||
thd_dbg.c
|
||||
)
|
||||
$#objs(weakprng) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common glue.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common weakprng.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
weakprng.c
|
||||
)
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* $Log: md4.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:55 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:51 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:54 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1999/09/13 19:23:20 wes
|
||||
* Rename index to idx to squelch compiler warning
|
||||
*
|
||||
* Revision 1.1 1999/08/11 21:18:04 bala
|
||||
* MD4 functions
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
/* Epilogue changes for type names and CVS info only */
|
||||
|
||||
/* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it
|
||||
is identified as the "RSA Data Security, Inc. MD4 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. MD4 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.
|
||||
*/
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
|
||||
#if INSTALL_COMMON_MD4
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif
|
||||
|
||||
#ifndef __MD4_INCLUDE__
|
||||
#include <wrn/wm/common/md4.h>
|
||||
#endif
|
||||
|
||||
/* Constants for MD4Transform routine.
|
||||
*/
|
||||
#define S11 3
|
||||
#define S12 7
|
||||
#define S13 11
|
||||
#define S14 19
|
||||
#define S21 3
|
||||
#define S22 5
|
||||
#define S23 9
|
||||
#define S24 13
|
||||
#define S31 3
|
||||
#define S32 9
|
||||
#define S33 11
|
||||
#define S34 15
|
||||
|
||||
static void MD4Transform __((bits32_t [4], bits8_t [64]));
|
||||
static void Encode __((bits8_t *, bits32_t *, bits32_t));
|
||||
static void Decode __((bits32_t *, bits8_t *, bits32_t));
|
||||
|
||||
static bits8_t 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 and H are basic MD4 functions.
|
||||
*/
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits.
|
||||
*/
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG and HH are transformations for rounds 1, 2 and 3 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
|
||||
#define FF(a, b, c, d, x, s) { \
|
||||
(a) += F ((b), (c), (d)) + (x); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (bits32_t)0x5a827999; \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (bits32_t)0x6ed9eba1; \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
|
||||
/* MD4 initialization. Begins an MD4 operation, writing a new context.
|
||||
*/
|
||||
void MD4Init (context)
|
||||
MD4_CTX *context; /* context */
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/* MD4 block update operation. Continues an MD4 message-digest
|
||||
operation, processing another message block, and updating the
|
||||
context.
|
||||
*/
|
||||
void MD4Update (context, input, inputLen)
|
||||
MD4_CTX *context; /* context */
|
||||
bits8_t *input; /* input block */
|
||||
bits32_t inputLen; /* length of input block */
|
||||
{
|
||||
bits32_t i, idx, partLen;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
idx = (bits32_t)((context->count[0] >> 3) & 0x3F);
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((bits32_t)inputLen << 3))
|
||||
< ((bits32_t)inputLen << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += ((bits32_t)inputLen >> 29);
|
||||
|
||||
partLen = 64 - idx;
|
||||
|
||||
/* Transform as many times as possible.
|
||||
*/
|
||||
if (inputLen >= partLen) {
|
||||
MEMCPY(&context->buffer[idx], input, partLen);
|
||||
MD4Transform (context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD4Transform (context->state, &input[i]);
|
||||
|
||||
idx = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
MEMCPY(&context->buffer[idx], &input[i],
|
||||
inputLen-i);
|
||||
}
|
||||
|
||||
/* MD4 finalization. Ends an MD4 message-digest operation, writing the
|
||||
the message digest and zeroizing the context.
|
||||
*/
|
||||
void MD4Final (digest, context)
|
||||
bits8_t digest[16]; /* message digest */
|
||||
MD4_CTX *context; /* context */
|
||||
{
|
||||
bits8_t bits[8];
|
||||
bits32_t idx, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
Encode (bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64.
|
||||
*/
|
||||
idx = (bits32_t)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (idx < 56) ? (56 - idx) : (120 - idx);
|
||||
MD4Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
MD4Update (context, bits, 8);
|
||||
/* Store state in digest */
|
||||
Encode (digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
*/
|
||||
MEMSET(context, 0, sizeof (*context));
|
||||
}
|
||||
|
||||
/* MD4 basic transformation. Transforms state based on block.
|
||||
*/
|
||||
static void MD4Transform (state, block)
|
||||
bits32_t state[4];
|
||||
bits8_t block[64];
|
||||
{
|
||||
bits32_t 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); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 0], S21); /* 17 */
|
||||
GG (d, a, b, c, x[ 4], S22); /* 18 */
|
||||
GG (c, d, a, b, x[ 8], S23); /* 19 */
|
||||
GG (b, c, d, a, x[12], S24); /* 20 */
|
||||
GG (a, b, c, d, x[ 1], S21); /* 21 */
|
||||
GG (d, a, b, c, x[ 5], S22); /* 22 */
|
||||
GG (c, d, a, b, x[ 9], S23); /* 23 */
|
||||
GG (b, c, d, a, x[13], S24); /* 24 */
|
||||
GG (a, b, c, d, x[ 2], S21); /* 25 */
|
||||
GG (d, a, b, c, x[ 6], S22); /* 26 */
|
||||
GG (c, d, a, b, x[10], S23); /* 27 */
|
||||
GG (b, c, d, a, x[14], S24); /* 28 */
|
||||
GG (a, b, c, d, x[ 3], S21); /* 29 */
|
||||
GG (d, a, b, c, x[ 7], S22); /* 30 */
|
||||
GG (c, d, a, b, x[11], S23); /* 31 */
|
||||
GG (b, c, d, a, x[15], S24); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 0], S31); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32); /* 34 */
|
||||
HH (c, d, a, b, x[ 4], S33); /* 35 */
|
||||
HH (b, c, d, a, x[12], S34); /* 36 */
|
||||
HH (a, b, c, d, x[ 2], S31); /* 37 */
|
||||
HH (d, a, b, c, x[10], S32); /* 38 */
|
||||
HH (c, d, a, b, x[ 6], S33); /* 39 */
|
||||
HH (b, c, d, a, x[14], S34); /* 40 */
|
||||
HH (a, b, c, d, x[ 1], S31); /* 41 */
|
||||
HH (d, a, b, c, x[ 9], S32); /* 42 */
|
||||
HH (c, d, a, b, x[ 5], S33); /* 43 */
|
||||
HH (b, c, d, a, x[13], S34); /* 44 */
|
||||
HH (a, b, c, d, x[ 3], S31); /* 45 */
|
||||
HH (d, a, b, c, x[11], S32); /* 46 */
|
||||
HH (c, d, a, b, x[ 7], S33); /* 47 */
|
||||
HH (b, c, d, a, x[15], S34); /* 48 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
*/
|
||||
MEMSET(x, 0, sizeof (x));
|
||||
}
|
||||
|
||||
/* Encodes input (bits32_t) into output (bits8_t). Assumes len is
|
||||
a multiple of 4.
|
||||
*/
|
||||
static void Encode (output, input, len)
|
||||
bits8_t *output;
|
||||
bits32_t *input;
|
||||
bits32_t len;
|
||||
{
|
||||
bits32_t i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (bits8_t)(input[i] & 0xff);
|
||||
output[j+1] = (bits8_t)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (bits8_t)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (bits8_t)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
/* Decodes input (bits8_t) into output (bits32_t). Assumes len is
|
||||
a multiple of 4.
|
||||
*/
|
||||
static void Decode (output, input, len)
|
||||
|
||||
bits32_t *output;
|
||||
bits8_t *input;
|
||||
bits32_t len;
|
||||
{
|
||||
bits32_t i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((bits32_t)input[j]) | (((bits32_t)input[j+1]) << 8) |
|
||||
(((bits32_t)input[j+2]) << 16) | (((bits32_t)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_MD4 */
|
||||
@@ -0,0 +1,79 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/memcmp.c,v 1.3 2003/01/16 18:18:56 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: memcmp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:52 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:54 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/04/09 20:33:47 wes
|
||||
* re-constify. let's see what, if anything, blows up
|
||||
*
|
||||
* Revision 1.2 1998/07/04 00:29:23 sra
|
||||
* Remove "const" tags, more trouble than they are worth.
|
||||
*
|
||||
* Revision 1.1 1998/07/03 20:19:16 sra
|
||||
* Add etc_memcmp().
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
/*
|
||||
* Portable implementation of ISO C memcmp() function for platforms
|
||||
* that don't have it or have a broken version.
|
||||
*
|
||||
* ISO C clearly states that memcmp() compares unsigned characters
|
||||
* (each byte to be considered in the range 0..255), but a number
|
||||
* of implementations seem to get this wrong, probably for historical
|
||||
* reasons.
|
||||
*/
|
||||
|
||||
int
|
||||
etc_memcmp(const void *v1, const void *v2, size_t len)
|
||||
{
|
||||
unsigned const char *b1 = v1, *b2 = v2;
|
||||
int result = 0;
|
||||
|
||||
while (len-- > 0)
|
||||
if ((result = (*b1++) - (*b2++)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/prng.c,v 1.3 2003/01/16 18:18:56 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998-1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: prng.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:53 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.17 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.16 2000/03/17 00:16:55 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.15 2000/03/13 21:21:47 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.14 1999/04/28 23:53:24 sra
|
||||
* Clean up various minor installation option glitches.
|
||||
*
|
||||
* Revision 1.13 1999/03/06 06:54:36 paul
|
||||
* moved common_init from prng.c to cmn_init.c
|
||||
*
|
||||
* Revision 1.11.2.1 1999/01/04 20:57:58 wes
|
||||
* Shut up purify.
|
||||
*
|
||||
* Revision 1.11 1998/09/11 16:30:41 paul
|
||||
* Auto-initialize common library.
|
||||
*
|
||||
* Revision 1.10 1998/06/25 20:40:06 sra
|
||||
* Fix CAD-UL warning in prng_init().
|
||||
*
|
||||
* Revision 1.9 1998/02/25 04:43:28 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.8 1997/10/30 16:42:34 sra
|
||||
* Fix copyright date.
|
||||
*
|
||||
* Revision 1.7 1997/08/21 17:23:43 sra
|
||||
* Begin moving configuration stuff that's common to all products to common.h
|
||||
* Minor cleanups to common/lib/prng.c. Add pnrg seed function to snarkbsd.
|
||||
*
|
||||
* Revision 1.6 1997/08/19 23:05:54 meister
|
||||
* Made some variables static that were global (and shouldnt have been).
|
||||
* Generated reasonable values for the two magic constants PRNG_MAGIC[12]
|
||||
*
|
||||
* Revision 1.5 1997/08/14 21:42:13 meister
|
||||
* ifdef'd out the linear congruential generator, and added the crypto-strong
|
||||
* one.
|
||||
*
|
||||
* Revision 1.4 1997/08/14 16:04:39 lowell
|
||||
* boilerplate
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_PRNG_H
|
||||
#include <wrn/wm/common/prng.h>
|
||||
#endif
|
||||
|
||||
#ifndef __MD5_INCLUDE__
|
||||
#include <wrn/wm/common/md5.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements a cryptographically strong random number generator.
|
||||
* The algorithm is based on the ANSI X9.17 generator. Keyed MD5 is used
|
||||
* as the basic transform rather than TDES. The DT value is augmented with
|
||||
* a monotonically increasing counter. See [Stallings - Network and
|
||||
* Internetwork Security pp 102-103] or ANSI X9.17 Appendix C.
|
||||
*/
|
||||
|
||||
static void prng_iterate (void);
|
||||
|
||||
/*
|
||||
* these next 2 bits of magic are used to seed the generator with
|
||||
* less than 32 bytes of randomness. If the user hands in N < 32 bytes (call
|
||||
* them "B") we generate MD5 (MAGIC1 "+" B "+" MAGIC1), and
|
||||
* MD5 (MAGIC2 "+" B "+" MAGIC2), and combine them to get our needed 32 bytes.
|
||||
* The actual values here are *not* of any importance, although having a
|
||||
* reasonably "random" bit distribution is useful. These were generated by
|
||||
* running some real-time system statistics through MD5.
|
||||
*/
|
||||
|
||||
static bits8_t PRNG_MAGIC1 [] =
|
||||
{ 0xb4, 0x33, 0x4b, 0xf5, 0x9b, 0x7a, 0x24, 0x19,
|
||||
0x8c, 0x04, 0xa5, 0xd1, 0x1e, 0xab, 0xa2, 0xe9
|
||||
};
|
||||
|
||||
static bits8_t PRNG_MAGIC2 [] =
|
||||
{ 0xaa, 0x9b, 0x49, 0xd4, 0x0f, 0x4c, 0xa7, 0x1b,
|
||||
0x1d, 0x0e, 0x83, 0xd6, 0xe7, 0x9c, 0xab, 0xf8
|
||||
};
|
||||
|
||||
#define PRNG_SEEDBYTES_NEEDED 32
|
||||
|
||||
static MD5_CTX PRNG_MD5_CTX;
|
||||
|
||||
/* new seed buffer for prng_get_seed () */
|
||||
static bits8_t PRNG_SB [PRNG_SEEDBYTES_NEEDED];
|
||||
|
||||
static bits8_t PRNG_MD5_K [16]; /* MD5 keyed hash key */
|
||||
static bits8_t PRNG_SV [16]; /* current seed value */
|
||||
static bits8_t PRNG_R [16]; /* current random pool */
|
||||
static bits32_t PRNG_DT; /* "date+time" value */
|
||||
static bits32_t PRNG_CNT; /* counter; increments with each call */
|
||||
static bits8_t PRNG_N; /* number of "random" bytes currently available */
|
||||
static bits8_t PRNG_INJIDX; /* index of PRNG_SV where prng_inject_random8 will
|
||||
xor next random input into */
|
||||
|
||||
/*
|
||||
* Initialize the prng system. This involves calling out for seed bytes. 32
|
||||
* of them, in fact.
|
||||
*/
|
||||
void prng_init (void)
|
||||
{
|
||||
bits8_t seedvalues [PRNG_SEEDBYTES_NEEDED];
|
||||
bits32_t actual;
|
||||
|
||||
MEMSET(seedvalues, 0, PRNG_SEEDBYTES_NEEDED);
|
||||
|
||||
actual = GLUE_SEED_PRNG(seedvalues, PRNG_SEEDBYTES_NEEDED);
|
||||
|
||||
if (actual < PRNG_SEEDBYTES_NEEDED)
|
||||
{
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC1, 16);
|
||||
if (actual > 0)
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) seedvalues, actual);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC1, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_MD5_K, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC2, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) seedvalues, actual);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC2, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_SV, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
MEMCPY(&PRNG_CNT, seedvalues, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
MEMCPY(PRNG_SV, seedvalues, 16);
|
||||
MEMCPY(PRNG_MD5_K, seedvalues + 16, 16);
|
||||
MEMCPY(&PRNG_CNT, seedvalues, 4);
|
||||
}
|
||||
PRNG_DT = GLUE_NOW();
|
||||
PRNG_N = PRNG_INJIDX = 0;
|
||||
prng_iterate (); /* kick start the PRNG */
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* compute next seed value and state
|
||||
*/
|
||||
|
||||
static void prng_iterate (void)
|
||||
{
|
||||
int i;
|
||||
bits8_t *p, *q;
|
||||
bits8_t digest [16];
|
||||
|
||||
/* step 1. R = MD5_K (MD5_K ((DT concat (++CNT)) XOR SV)) */
|
||||
|
||||
/* digest <-- MD5 ((DT concat (++CNT)) XOR SV */
|
||||
++PRNG_CNT;
|
||||
PRNG_DT = GLUE_NOW();
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) &PRNG_DT, 4);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) &PRNG_CNT, 4);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(digest, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
/* PRNG_SV <-- (PRNG_SV XOR digest) */
|
||||
/* leave digest alone as we'll need it again when we compute new SV */
|
||||
for (i = 0, p = PRNG_SV, q = digest; i < 16 ; i++)
|
||||
*p++ ^= *q++;
|
||||
|
||||
/* PRNG_R <-- MD5 (PRNG_SV) */
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_SV, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_R, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
/*
|
||||
* step 2. SV = MD5_K (MD5_K ((DT concat (++CNT)) XOR R))
|
||||
*
|
||||
* digest is still MD5_K ((DT concat (++CNT)), so we dont need another
|
||||
* MD5 operation
|
||||
*/
|
||||
/* PRNG_SV <-- (PRNG_SV XOR digest) */
|
||||
for (i = 0, p = PRNG_R, q = digest; i < 16 ; i++)
|
||||
*q++ ^= *p++;
|
||||
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) digest, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_SV, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
/* now we have another 16 bytes of usable R */
|
||||
|
||||
PRNG_N = 16;
|
||||
}
|
||||
|
||||
/*
|
||||
* hand back a "random" byte
|
||||
*/
|
||||
|
||||
bits8_t prng_random8 (void)
|
||||
{
|
||||
if (!PRNG_N)
|
||||
prng_iterate ();
|
||||
|
||||
return PRNG_R [--PRNG_N];
|
||||
}
|
||||
|
||||
/*
|
||||
* fill up a buffer with "random" bytes
|
||||
*/
|
||||
|
||||
void prng_random (bits8_t *buf, int N)
|
||||
{
|
||||
while (N--)
|
||||
*buf++ = prng_random8 ();
|
||||
}
|
||||
|
||||
void prng_get_seed(bits8_t **buffer, int * bufsize)
|
||||
{
|
||||
prng_iterate ();
|
||||
|
||||
MEMCPY(PRNG_SB, PRNG_SV, 16);
|
||||
MEMCPY(PRNG_SB + 16, PRNG_R, 16);
|
||||
|
||||
prng_iterate ();
|
||||
|
||||
*buffer = PRNG_SB;
|
||||
*bufsize = PRNG_SEEDBYTES_NEEDED;
|
||||
}
|
||||
|
||||
void prng_inject_random8 (bits8_t in)
|
||||
{
|
||||
PRNG_SV [PRNG_INJIDX & 0xF] ^= in;
|
||||
PRNG_INJIDX++;
|
||||
|
||||
#ifndef PRNG_INJECT_IMMEDIATE_EFFECT
|
||||
prng_iterate ();
|
||||
#else
|
||||
if (!(PRNG_INJIDX & 0xF))
|
||||
prng_iterate ();
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/hmac.c,v 1.3 2003/01/16 18:18:55 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005, 2013 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: hmac.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:55 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:51 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/01/19 22:21:30 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.5 2000/03/17 00:16:53 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.4 1998/09/04 14:02:28 sar
|
||||
* Convert some ints to unsigned ints to make some compliers happier
|
||||
*
|
||||
* Revision 1.3 1998/06/21 21:40:55 sar
|
||||
* More type checking stuff to keep compilers happy
|
||||
*
|
||||
* Revision 1.2 1998/06/18 04:11:23 sar
|
||||
* clean u psome type info, make the lengths be bits32_t
|
||||
*
|
||||
* Revision 1.1 1998/05/22 18:03:07 sar
|
||||
* HMAC functions, this code is arranged so that the user can insert their
|
||||
* own digest functions such as MD5 or SHA
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01d,14may13,bbz correct the VSB building errors(WIND00417424)
|
||||
01c,08may13,bbz clear the high impact warning from prevent.pl(WIND00416598)
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif /* EPILOGUE_INSTALL_H */
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif /* EPILOGUE_TYPES_H */
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif /* COMMON_CONFIG_H */
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif /* COMMON_GLUE_H */
|
||||
|
||||
#include <wrn/wm/common/hmac.h>
|
||||
|
||||
/* initialize an HMAC context */
|
||||
void InitHmacCTX (HMAC_CTX *ctx,
|
||||
hashfcn_init_t init,
|
||||
hashfcn_update_t update,
|
||||
hashfcn_final_t final,
|
||||
bits32_t hashsiz)
|
||||
{
|
||||
ctx->hmac_hashinit = init;
|
||||
ctx->hmac_hashupdate = update;
|
||||
ctx->hmac_hashfinal = final;
|
||||
ctx->hmac_hashlen = hashsiz;
|
||||
}
|
||||
|
||||
void hmac_init (HMAC_CTX *ctx,
|
||||
bits8_t *key,
|
||||
bits32_t keylen)
|
||||
{
|
||||
bits8_t xk [64];
|
||||
unsigned int i;
|
||||
|
||||
/*
|
||||
* if we have more than 64 bytes of key, hash that first using the
|
||||
* given hash algorithm.
|
||||
*/
|
||||
if (keylen > 64)
|
||||
{
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, key, keylen);
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, xk);
|
||||
|
||||
/* K XOR input pad of 0x36's */
|
||||
for (i = 0 ; i < ctx->hmac_hashlen; i++)
|
||||
xk [i] ^= ((bits8_t) 0x36);
|
||||
|
||||
MEMSET (xk + (unsigned int)ctx->hmac_hashlen, 0x36,
|
||||
64 - (unsigned int)ctx->hmac_hashlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* K XOR input pad of 0x36's */
|
||||
for (i = 0 ; i < keylen; i++)
|
||||
xk [i] = key [i] ^ ((bits8_t) 0x36);
|
||||
if (keylen < 64)
|
||||
MEMSET (xk + (unsigned int)keylen, 0x36, 64 - (unsigned int)keylen);
|
||||
|
||||
}
|
||||
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, xk, 64);
|
||||
|
||||
}
|
||||
|
||||
void hmac_update (HMAC_CTX *ctx,
|
||||
bits8_t *data,
|
||||
bits32_t len)
|
||||
{
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, data, len);
|
||||
}
|
||||
|
||||
void hmac_final (HMAC_CTX *ctx,
|
||||
bits8_t *key,
|
||||
bits32_t keylen,
|
||||
bits8_t *output)
|
||||
{
|
||||
|
||||
bits8_t xk [64];
|
||||
unsigned int i;
|
||||
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, ctx->hmac_tmp);
|
||||
|
||||
/*
|
||||
* if we have more than 64 bytes of key, hash that first using the
|
||||
* given hash algorithm.
|
||||
*/
|
||||
if (keylen > 64)
|
||||
{
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, key, keylen);
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, xk);
|
||||
|
||||
/* K XOR output pad of 0x5c's */
|
||||
for (i = 0 ; i < ctx->hmac_hashlen; i++)
|
||||
xk [i] ^= ((bits8_t) 0x5c);
|
||||
|
||||
MEMSET (xk + (unsigned int)ctx->hmac_hashlen, 0x5c,
|
||||
64 - (unsigned int)ctx->hmac_hashlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* K XOR output pad of 0x5c's */
|
||||
for (i = 0 ; i < keylen; i++)
|
||||
xk [i] = key [i] ^ ((bits8_t) 0x5c);
|
||||
if (keylen < 64)
|
||||
MEMSET (xk + (unsigned int)keylen, 0x5c, 64 - (unsigned int)keylen);
|
||||
}
|
||||
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, xk, 64);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, ctx->hmac_tmp,
|
||||
ctx->hmac_hashlen);
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, output);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
/* Wind River changed symbol names to remove conflicts */
|
||||
/* Epilogue changes for type names and CVS info only */
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** md5.c -- the source code for MD5 routines **
|
||||
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
|
||||
** Created: 2/17/90 RLR **
|
||||
** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** Copyright (C) 1990, RSA Data Security, Inc. 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. **
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: md5.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:52 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.7 1998/03/11 23:06:04 meister
|
||||
* fix conversion warnings on lines 193 and 152 (mdi = ...)
|
||||
*
|
||||
* Revision 1.6 1998/02/25 15:21:13 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.5 1998/02/25 01:37:18 sra
|
||||
* Fix up CVS/RCS keywords.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,31aug07,josh fix symbol conflicts
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif /* EPILOGUE_INSTALL_H */
|
||||
|
||||
#if INSTALL_COMMON_MD5
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif /* EPILOGUE_TYPES_H */
|
||||
#include <wrn/wm/common/md5.h>
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** Message-digest routines: **
|
||||
** To form the message digest for a message M **
|
||||
** (1) Initialize a context buffer mdContext using MD5Init **
|
||||
** (2) Call MD5Update on mdContext and M **
|
||||
** (3) Call MD5Final on mdContext **
|
||||
** The message digest is now in mdContext->digest[0...15] **
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/* forward declaration */
|
||||
static void WrsnmpCommonTransform (bits32_t *buf, bits32_t *in);
|
||||
|
||||
static bits8_t WRSNMP_COMMON_PADDING[64] = {
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
/* 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) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) \
|
||||
{(a) += G ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) \
|
||||
{(a) += H ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) \
|
||||
{(a) += I ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
#define UL(x) x##U
|
||||
#else
|
||||
#define UL(x) x
|
||||
#endif
|
||||
|
||||
/* The routine WRSNMP_MD5Init initializes the message-digest context
|
||||
mdContext. All fields are set to zero.
|
||||
*/
|
||||
void WrsnmpCommonMD5Init (mdContext)
|
||||
MD5_CTX *mdContext;
|
||||
{
|
||||
mdContext->i[0] = mdContext->i[1] = (bits32_t)0;
|
||||
|
||||
/* Load magic initialization constants.
|
||||
*/
|
||||
mdContext->buf[0] = (bits32_t)0x67452301L;
|
||||
mdContext->buf[1] = (bits32_t)0xefcdab89L;
|
||||
mdContext->buf[2] = (bits32_t)0x98badcfeL;
|
||||
mdContext->buf[3] = (bits32_t)0x10325476L;
|
||||
}
|
||||
|
||||
/* The routine WRSNMP_MD5Update updates the message-digest context to
|
||||
account for the presence of each of the characters inBuf[0..inLen-1]
|
||||
in the message whose digest is being computed.
|
||||
*/
|
||||
void WrsnmpCommonMD5Update (mdContext, inBuf, inLen)
|
||||
MD5_CTX *mdContext;
|
||||
bits8_t *inBuf;
|
||||
bits32_t inLen;
|
||||
{
|
||||
bits32_t in[16];
|
||||
unsigned int mdi;
|
||||
unsigned int i, ii;
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (unsigned int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* update number of bits */
|
||||
if ((mdContext->i[0] + ((bits32_t)inLen << 3)) < mdContext->i[0])
|
||||
mdContext->i[1]++;
|
||||
mdContext->i[0] += ((bits32_t)inLen << 3);
|
||||
mdContext->i[1] += ((bits32_t)inLen >> 29);
|
||||
|
||||
while (inLen--) {
|
||||
/* add new character to buffer, increment mdi */
|
||||
mdContext->in[mdi++] = *inBuf++;
|
||||
|
||||
/* transform if necessary */
|
||||
if (mdi == 0x40) {
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
in[i] = (((bits32_t)mdContext->in[ii+3]) << 24) |
|
||||
(((bits32_t)mdContext->in[ii+2]) << 16) |
|
||||
(((bits32_t)mdContext->in[ii+1]) << 8) |
|
||||
((bits32_t)mdContext->in[ii]);
|
||||
WrsnmpCommonTransform (mdContext->buf, in);
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The routine WRSNMP_MD5Final terminates the message-digest computation and
|
||||
ends with the desired message digest in mdContext->digest[0...15].
|
||||
*/
|
||||
void WrsnmpCommonMD5Final (mdContext)
|
||||
MD5_CTX *mdContext;
|
||||
{
|
||||
bits32_t in[16];
|
||||
unsigned int mdi;
|
||||
unsigned int i, ii;
|
||||
bits32_t padLen;
|
||||
|
||||
/* save number of bits */
|
||||
in[14] = mdContext->i[0];
|
||||
in[15] = mdContext->i[1];
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (unsigned int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* pad out to 56 mod 64 */
|
||||
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
|
||||
MD5Update (mdContext, WRSNMP_COMMON_PADDING, padLen);
|
||||
|
||||
/* append length in bits and transform */
|
||||
for (i = 0, ii = 0; i < 14; i++, ii += 4)
|
||||
in[i] = (((bits32_t)mdContext->in[ii+3]) << 24) |
|
||||
(((bits32_t)mdContext->in[ii+2]) << 16) |
|
||||
(((bits32_t)mdContext->in[ii+1]) << 8) |
|
||||
((bits32_t)mdContext->in[ii]);
|
||||
WrsnmpCommonTransform (mdContext->buf, in);
|
||||
|
||||
/* store buffer in digest */
|
||||
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
|
||||
mdContext->digest[ii] = (bits8_t)(mdContext->buf[i] & 0xFF);
|
||||
mdContext->digest[ii+1] =
|
||||
(bits8_t)((mdContext->buf[i] >> 8) & 0xFF);
|
||||
mdContext->digest[ii+2] =
|
||||
(bits8_t)((mdContext->buf[i] >> 16) & 0xFF);
|
||||
mdContext->digest[ii+3] =
|
||||
(bits8_t)((mdContext->buf[i] >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
/* Basic MD5 step. Transforms buf based on in.
|
||||
*/
|
||||
static void WrsnmpCommonTransform (bits32_t *buf, bits32_t *in)
|
||||
{
|
||||
bits32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
/* Round 1 */
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
FF ( a, b, c, d, in[ 0], S11, UL(3614090360L)); /* 1 */
|
||||
FF ( d, a, b, c, in[ 1], S12, UL(3905402710L)); /* 2 */
|
||||
FF ( c, d, a, b, in[ 2], S13, UL( 606105819L)); /* 3 */
|
||||
FF ( b, c, d, a, in[ 3], S14, UL(3250441966L)); /* 4 */
|
||||
FF ( a, b, c, d, in[ 4], S11, UL(4118548399L)); /* 5 */
|
||||
FF ( d, a, b, c, in[ 5], S12, UL(1200080426L)); /* 6 */
|
||||
FF ( c, d, a, b, in[ 6], S13, UL(2821735955L)); /* 7 */
|
||||
FF ( b, c, d, a, in[ 7], S14, UL(4249261313L)); /* 8 */
|
||||
FF ( a, b, c, d, in[ 8], S11, UL(1770035416L)); /* 9 */
|
||||
FF ( d, a, b, c, in[ 9], S12, UL(2336552879L)); /* 10 */
|
||||
FF ( c, d, a, b, in[10], S13, UL(4294925233L)); /* 11 */
|
||||
FF ( b, c, d, a, in[11], S14, UL(2304563134L)); /* 12 */
|
||||
FF ( a, b, c, d, in[12], S11, UL(1804603682L)); /* 13 */
|
||||
FF ( d, a, b, c, in[13], S12, UL(4254626195L)); /* 14 */
|
||||
FF ( c, d, a, b, in[14], S13, UL(2792965006L)); /* 15 */
|
||||
FF ( b, c, d, a, in[15], S14, UL(1236535329L)); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
GG ( a, b, c, d, in[ 1], S21, UL(4129170786L)); /* 17 */
|
||||
GG ( d, a, b, c, in[ 6], S22, UL(3225465664L)); /* 18 */
|
||||
GG ( c, d, a, b, in[11], S23, UL( 643717713L)); /* 19 */
|
||||
GG ( b, c, d, a, in[ 0], S24, UL(3921069994L)); /* 20 */
|
||||
GG ( a, b, c, d, in[ 5], S21, UL(3593408605L)); /* 21 */
|
||||
GG ( d, a, b, c, in[10], S22, UL( 38016083L)); /* 22 */
|
||||
GG ( c, d, a, b, in[15], S23, UL(3634488961L)); /* 23 */
|
||||
GG ( b, c, d, a, in[ 4], S24, UL(3889429448L)); /* 24 */
|
||||
GG ( a, b, c, d, in[ 9], S21, UL( 568446438L)); /* 25 */
|
||||
GG ( d, a, b, c, in[14], S22, UL(3275163606L)); /* 26 */
|
||||
GG ( c, d, a, b, in[ 3], S23, UL(4107603335L)); /* 27 */
|
||||
GG ( b, c, d, a, in[ 8], S24, UL(1163531501L)); /* 28 */
|
||||
GG ( a, b, c, d, in[13], S21, UL(2850285829L)); /* 29 */
|
||||
GG ( d, a, b, c, in[ 2], S22, UL(4243563512L)); /* 30 */
|
||||
GG ( c, d, a, b, in[ 7], S23, UL(1735328473L)); /* 31 */
|
||||
GG ( b, c, d, a, in[12], S24, UL(2368359562L)); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
HH ( a, b, c, d, in[ 5], S31, UL(4294588738L)); /* 33 */
|
||||
HH ( d, a, b, c, in[ 8], S32, UL(2272392833L)); /* 34 */
|
||||
HH ( c, d, a, b, in[11], S33, UL(1839030562L)); /* 35 */
|
||||
HH ( b, c, d, a, in[14], S34, UL(4259657740L)); /* 36 */
|
||||
HH ( a, b, c, d, in[ 1], S31, UL(2763975236L)); /* 37 */
|
||||
HH ( d, a, b, c, in[ 4], S32, UL(1272893353L)); /* 38 */
|
||||
HH ( c, d, a, b, in[ 7], S33, UL(4139469664L)); /* 39 */
|
||||
HH ( b, c, d, a, in[10], S34, UL(3200236656L)); /* 40 */
|
||||
HH ( a, b, c, d, in[13], S31, UL( 681279174L)); /* 41 */
|
||||
HH ( d, a, b, c, in[ 0], S32, UL(3936430074L)); /* 42 */
|
||||
HH ( c, d, a, b, in[ 3], S33, UL(3572445317L)); /* 43 */
|
||||
HH ( b, c, d, a, in[ 6], S34, UL( 76029189L)); /* 44 */
|
||||
HH ( a, b, c, d, in[ 9], S31, UL(3654602809L)); /* 45 */
|
||||
HH ( d, a, b, c, in[12], S32, UL(3873151461L)); /* 46 */
|
||||
HH ( c, d, a, b, in[15], S33, UL( 530742520L)); /* 47 */
|
||||
HH ( b, c, d, a, in[ 2], S34, UL(3299628645L)); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
II ( a, b, c, d, in[ 0], S41, UL(4096336452L)); /* 49 */
|
||||
II ( d, a, b, c, in[ 7], S42, UL(1126891415L)); /* 50 */
|
||||
II ( c, d, a, b, in[14], S43, UL(2878612391L)); /* 51 */
|
||||
II ( b, c, d, a, in[ 5], S44, UL(4237533241L)); /* 52 */
|
||||
II ( a, b, c, d, in[12], S41, UL(1700485571L)); /* 53 */
|
||||
II ( d, a, b, c, in[ 3], S42, UL(2399980690L)); /* 54 */
|
||||
II ( c, d, a, b, in[10], S43, UL(4293915773L)); /* 55 */
|
||||
II ( b, c, d, a, in[ 1], S44, UL(2240044497L)); /* 56 */
|
||||
II ( a, b, c, d, in[ 8], S41, UL(1873313359L)); /* 57 */
|
||||
II ( d, a, b, c, in[15], S42, UL(4264355552L)); /* 58 */
|
||||
II ( c, d, a, b, in[ 6], S43, UL(2734768916L)); /* 59 */
|
||||
II ( b, c, d, a, in[13], S44, UL(1309151649L)); /* 60 */
|
||||
II ( a, b, c, d, in[ 4], S41, UL(4149444226L)); /* 61 */
|
||||
II ( d, a, b, c, in[11], S42, UL(3174756917L)); /* 62 */
|
||||
II ( c, d, a, b, in[ 2], S43, UL( 718787259L)); /* 63 */
|
||||
II ( b, c, d, a, in[ 9], S44, UL(3951481745L)); /* 64 */
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** End of md5.c **
|
||||
******************************** (cut) ********************************
|
||||
*/
|
||||
|
||||
#endif /* INSTALL_COMMON_MD5 */
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* $Log: sha.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:53 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:56 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/06/16 05:12:26 sar
|
||||
* Clean up some type questions
|
||||
*
|
||||
* Revision 1.1 1998/05/22 18:03:35 sar
|
||||
* SHA digest functions
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
/* NIST Secure Hash Algorithm */
|
||||
/* heavily modified by Uwe Hollerbach <uh@alumni.caltech edu> */
|
||||
/* from Peter C. Gutmann's implementation as found in */
|
||||
/* Applied Cryptography by Bruce Schneier */
|
||||
/* Further modifications to include the "UNRAVEL" stuff, below */
|
||||
|
||||
/* This code is in the public domain */
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <wrn/wm/common/sha.h>
|
||||
|
||||
|
||||
/* Always use version 1, but leave the code around in case
|
||||
somebody wants to know that the difference is */
|
||||
#define SHA_VERSION 1
|
||||
|
||||
/* SHA f()-functions */
|
||||
|
||||
#define f1(x,y,z) ((x & y) | (~x & z))
|
||||
#define f2(x,y,z) (x ^ y ^ z)
|
||||
#define f3(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define f4(x,y,z) (x ^ y ^ z)
|
||||
|
||||
/* SHA constants */
|
||||
|
||||
#define CONST1 0x5a827999L
|
||||
#define CONST2 0x6ed9eba1L
|
||||
#define CONST3 0x8f1bbcdcL
|
||||
#define CONST4 0xca62c1d6L
|
||||
|
||||
/* 32-bit rotate */
|
||||
|
||||
#define R32(x,n) ((x << n) | (x >> (32 - n)))
|
||||
|
||||
#define FG(n) \
|
||||
T = R32(A,5) + f##n(B,C,D) + E + *WP++ + CONST##n; \
|
||||
E = D; D = C; C = R32(B,30); B = A; A = T
|
||||
|
||||
/* do SHA transformation */
|
||||
|
||||
static void sha_transform (SHA_CTX *sha_info)
|
||||
{
|
||||
int i;
|
||||
bits8_t *dp;
|
||||
bits32_t T, A, B, C, D, E, W[80], *WP;
|
||||
|
||||
dp = sha_info->data;
|
||||
|
||||
#if (INSTALL_ON_LITTLE_ENDIAN)
|
||||
for (i = 0; i < 16; ++i)
|
||||
{
|
||||
T = *((bits32_t *) dp);
|
||||
dp += 4;
|
||||
W[i] = ((T << 24) & 0xff000000L) | ((T << 8) & 0x00ff0000L) |
|
||||
((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
|
||||
}
|
||||
#endif /* #if (INSTALL_ON_LITTLE_ENDIAN) */
|
||||
|
||||
#if (INSTALL_ON_BIG_ENDIAN)
|
||||
for (i = 0; i < 16; ++i)
|
||||
{
|
||||
T = *((bits32_t *) dp);
|
||||
dp += 4;
|
||||
W[i] = T;
|
||||
}
|
||||
#endif /* #if (INSTALL_ON_BIG_ENDIAN) **/
|
||||
|
||||
for (i = 16; i < 80; ++i)
|
||||
{
|
||||
W[i] = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16];
|
||||
#if (SHA_VERSION == 1)
|
||||
W[i] = R32(W[i], 1);
|
||||
#endif /* SHA_VERSION */
|
||||
}
|
||||
|
||||
A = sha_info->buf[0];
|
||||
B = sha_info->buf[1];
|
||||
C = sha_info->buf[2];
|
||||
D = sha_info->buf[3];
|
||||
E = sha_info->buf[4];
|
||||
WP = W;
|
||||
|
||||
for (i = 0; i < 20; ++i) { FG(1); }
|
||||
for (i = 20; i < 40; ++i) { FG(2); }
|
||||
for (i = 40; i < 60; ++i) { FG(3); }
|
||||
for (i = 60; i < 80; ++i) { FG(4); }
|
||||
|
||||
sha_info->buf[0] += A;
|
||||
sha_info->buf[1] += B;
|
||||
sha_info->buf[2] += C;
|
||||
sha_info->buf[3] += D;
|
||||
sha_info->buf[4] += E;
|
||||
|
||||
}
|
||||
|
||||
/* initialize the SHA digest */
|
||||
|
||||
void sha_init(SHA_CTX *sha_info)
|
||||
{
|
||||
sha_info->buf[0] = 0x67452301L;
|
||||
sha_info->buf[1] = 0xefcdab89L;
|
||||
sha_info->buf[2] = 0x98badcfeL;
|
||||
sha_info->buf[3] = 0x10325476L;
|
||||
sha_info->buf[4] = 0xc3d2e1f0L;
|
||||
sha_info->count_lo = 0L;
|
||||
sha_info->count_hi = 0L;
|
||||
sha_info->local = 0;
|
||||
}
|
||||
|
||||
/* update the SHA digest */
|
||||
|
||||
void sha_update(SHA_CTX *sha_info,
|
||||
bits8_t *buffer,
|
||||
bits32_t count)
|
||||
{
|
||||
bits32_t clo;
|
||||
size_t i;
|
||||
|
||||
clo = sha_info->count_lo + ((bits32_t) count << 3);
|
||||
if (clo < sha_info->count_lo) {
|
||||
++sha_info->count_hi;
|
||||
}
|
||||
sha_info->count_lo = clo;
|
||||
sha_info->count_hi += (bits32_t) count >> 29;
|
||||
if (sha_info->local)
|
||||
{
|
||||
i = SHA_BLOCKSIZE - sha_info->local;
|
||||
if (i > count)
|
||||
i = (size_t)count;
|
||||
|
||||
MEMCPY(sha_info->data + sha_info->local, buffer, i);
|
||||
count -= i;
|
||||
buffer += i;
|
||||
sha_info->local += i;
|
||||
if (sha_info->local == SHA_BLOCKSIZE)
|
||||
sha_transform(sha_info);
|
||||
else
|
||||
return;
|
||||
}
|
||||
while (count >= SHA_BLOCKSIZE)
|
||||
{ MEMCPY (sha_info->data, buffer, SHA_BLOCKSIZE);
|
||||
buffer += SHA_BLOCKSIZE;
|
||||
count -= SHA_BLOCKSIZE;
|
||||
sha_transform (sha_info);
|
||||
}
|
||||
if (count) {
|
||||
MEMCPY (sha_info->data, buffer, (size_t)count);
|
||||
}
|
||||
sha_info->local = (size_t)count;
|
||||
|
||||
}
|
||||
|
||||
/* finish computing the SHA digest */
|
||||
|
||||
void sha_final (SHA_CTX *sha_info)
|
||||
{
|
||||
int count, i, ii;
|
||||
bits32_t lo_bit_count, hi_bit_count;
|
||||
|
||||
lo_bit_count = sha_info->count_lo;
|
||||
hi_bit_count = sha_info->count_hi;
|
||||
count = (int) ((lo_bit_count >> 3) & 0x3f);
|
||||
((bits8_t *) sha_info->data)[count++] = 0x80;
|
||||
if (count > SHA_BLOCKSIZE - 8) {
|
||||
MEMSET(sha_info->data + count, 0, SHA_BLOCKSIZE - count);
|
||||
sha_transform(sha_info);
|
||||
MEMSET(sha_info->data, 0, SHA_BLOCKSIZE - 8);
|
||||
} else {
|
||||
MEMSET(sha_info->data + count, 0, SHA_BLOCKSIZE - 8 - count);
|
||||
}
|
||||
sha_info->data[56] = (bits8_t) ((hi_bit_count >> 24) & 0xffL);
|
||||
sha_info->data[57] = (bits8_t) ((hi_bit_count >> 16) & 0xffL);
|
||||
sha_info->data[58] = (bits8_t) ((hi_bit_count >> 8) & 0xffL);
|
||||
sha_info->data[59] = (bits8_t) ((hi_bit_count ) & 0xffL);
|
||||
sha_info->data[60] = (bits8_t) ((lo_bit_count >> 24) & 0xffL);
|
||||
sha_info->data[61] = (bits8_t) ((lo_bit_count >> 16) & 0xffL);
|
||||
sha_info->data[62] = (bits8_t) ((lo_bit_count >> 8) & 0xffL);
|
||||
sha_info->data[63] = (bits8_t) ((lo_bit_count ) & 0xffL);
|
||||
|
||||
sha_transform(sha_info);
|
||||
|
||||
/* store buffer in digest */
|
||||
for(i = 0, ii = 0; i < 5; i++, ii += 4) {
|
||||
sha_info->digest[ii] = (bits8_t)((sha_info->buf[i] >> 24) & 0xFF);
|
||||
sha_info->digest[ii+1] = (bits8_t)((sha_info->buf[i] >> 16) & 0xFF);
|
||||
sha_info->digest[ii+2] = (bits8_t)((sha_info->buf[i] >> 8) & 0xFF);
|
||||
sha_info->digest[ii+3] = (bits8_t)((sha_info->buf[i]) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,496 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/snprintf.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Portable implementation of snprintf() and vsnprintf(). This is
|
||||
* derived from publicly-available code, modified to fit Epilogue
|
||||
* coding conventions and strip out the floating point support (which
|
||||
* we don't need).
|
||||
*
|
||||
* Original author's copyright notice:
|
||||
*
|
||||
* Copyright Patrick Powell 1995
|
||||
* This code is based on code written by Patrick Powell (papowell@astart.com)
|
||||
* It may be used for any purpose as long as this notice remains intact
|
||||
* on all source code distributions
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: snprintf.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:53 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:56 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/05/21 16:43:51 sra
|
||||
* Minor tweaks to debugging code.
|
||||
*
|
||||
* Revision 1.2 1999/05/20 22:15:12 wes
|
||||
* Call etc_vsnprintf from etc_snprintf
|
||||
*
|
||||
* Revision 1.1 1999/05/20 20:28:17 sra
|
||||
* Add etc_snprintf() and etc_vsnprintf().
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/snprintf.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static void dopr (char *buffer, size_t maxlen, const char *format,
|
||||
va_list args);
|
||||
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max);
|
||||
static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags);
|
||||
static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
|
||||
|
||||
/*
|
||||
* dopr(): poor man's version of doprintf
|
||||
*/
|
||||
|
||||
/* format read states */
|
||||
#define DP_S_DEFAULT 0
|
||||
#define DP_S_FLAGS 1
|
||||
#define DP_S_MIN 2
|
||||
#define DP_S_DOT 3
|
||||
#define DP_S_MAX 4
|
||||
#define DP_S_MOD 5
|
||||
#define DP_S_CONV 6
|
||||
#define DP_S_DONE 7
|
||||
|
||||
/* format flags - Bits */
|
||||
#define DP_F_MINUS (1 << 0)
|
||||
#define DP_F_PLUS (1 << 1)
|
||||
#define DP_F_SPACE (1 << 2)
|
||||
#define DP_F_NUM (1 << 3)
|
||||
#define DP_F_ZERO (1 << 4)
|
||||
#define DP_F_UP (1 << 5)
|
||||
#define DP_F_UNSIGNED (1 << 6)
|
||||
|
||||
/* Conversion Flags */
|
||||
#define DP_C_SHORT 1
|
||||
#define DP_C_LONG 2
|
||||
|
||||
#define char_to_int(p) (p - '0')
|
||||
#define MAX(p,q) ((p >= q) ? p : q)
|
||||
|
||||
static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
|
||||
{
|
||||
char ch;
|
||||
long value;
|
||||
char *strvalue;
|
||||
int min;
|
||||
int max;
|
||||
int state;
|
||||
int flags;
|
||||
int cflags;
|
||||
size_t currlen;
|
||||
|
||||
state = DP_S_DEFAULT;
|
||||
currlen = flags = cflags = min = 0;
|
||||
max = -1;
|
||||
ch = *format++;
|
||||
|
||||
while (state != DP_S_DONE) {
|
||||
if ((ch == '\0') || (currlen >= maxlen))
|
||||
state = DP_S_DONE;
|
||||
|
||||
switch(state) {
|
||||
case DP_S_DEFAULT:
|
||||
if (ch == '%')
|
||||
state = DP_S_FLAGS;
|
||||
else
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
ch = *format++;
|
||||
break;
|
||||
case DP_S_FLAGS:
|
||||
switch (ch) {
|
||||
case '-':
|
||||
flags |= DP_F_MINUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '+':
|
||||
flags |= DP_F_PLUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= DP_F_SPACE;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '#':
|
||||
flags |= DP_F_NUM;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '0':
|
||||
flags |= DP_F_ZERO;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
state = DP_S_MIN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DP_S_MIN:
|
||||
if (isdigit((int) ch)) {
|
||||
min = 10*min + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
min = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_DOT;
|
||||
} else {
|
||||
state = DP_S_DOT;
|
||||
}
|
||||
break;
|
||||
case DP_S_DOT:
|
||||
if (ch == '.') {
|
||||
state = DP_S_MAX;
|
||||
ch = *format++;
|
||||
} else {
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
break;
|
||||
case DP_S_MAX:
|
||||
if (isdigit((int) ch)) {
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
max = 10*max + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
max = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_MOD;
|
||||
} else {
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
break;
|
||||
case DP_S_MOD:
|
||||
/* Currently, we don't support Long Long, bummer */
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
cflags = DP_C_SHORT;
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'l':
|
||||
cflags = DP_C_LONG;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
state = DP_S_CONV;
|
||||
break;
|
||||
case DP_S_CONV:
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, long int);
|
||||
else
|
||||
value = va_arg (args, int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'o':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, unsigned long int);
|
||||
else
|
||||
value = va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
|
||||
break;
|
||||
case 'u':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, unsigned long int);
|
||||
else
|
||||
value = va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'X':
|
||||
flags |= DP_F_UP;
|
||||
case 'x':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, unsigned long int);
|
||||
else
|
||||
value = va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
|
||||
break;
|
||||
case 'c':
|
||||
dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
|
||||
break;
|
||||
case 's':
|
||||
strvalue = va_arg (args, char *);
|
||||
if (max < 0)
|
||||
max = maxlen; /* ie, no max */
|
||||
fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
|
||||
break;
|
||||
case 'p':
|
||||
strvalue = va_arg (args, void *);
|
||||
fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
|
||||
break;
|
||||
case 'n':
|
||||
if (cflags == DP_C_SHORT) {
|
||||
short int *num;
|
||||
num = va_arg (args, short int *);
|
||||
*num = currlen;
|
||||
} else if (cflags == DP_C_LONG) {
|
||||
long int *num;
|
||||
num = va_arg (args, long int *);
|
||||
*num = currlen;
|
||||
} else {
|
||||
int *num;
|
||||
num = va_arg (args, int *);
|
||||
*num = currlen;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
break;
|
||||
case 'w':
|
||||
/* not supported yet, treat as next char */
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
/* Unknown, skip */
|
||||
break;
|
||||
}
|
||||
ch = *format++;
|
||||
state = DP_S_DEFAULT;
|
||||
flags = cflags = min = 0;
|
||||
max = -1;
|
||||
break;
|
||||
case DP_S_DONE:
|
||||
break;
|
||||
default: /* hmm? */
|
||||
break; /* some picky compilers need this */
|
||||
}
|
||||
}
|
||||
if (currlen < maxlen - 1)
|
||||
buffer[currlen] = '\0';
|
||||
else
|
||||
buffer[maxlen - 1] = '\0';
|
||||
}
|
||||
|
||||
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max)
|
||||
{
|
||||
int padlen; /* amount to pad */
|
||||
int cnt = 0;
|
||||
|
||||
if (value == 0)
|
||||
value = "<NULL>";
|
||||
|
||||
padlen = min - STRLEN(value);
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justify */
|
||||
|
||||
while ((padlen > 0) && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
++cnt;
|
||||
}
|
||||
while (*value && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, *value++);
|
||||
++cnt;
|
||||
}
|
||||
while ((padlen < 0) && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
|
||||
|
||||
static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags)
|
||||
{
|
||||
int signvalue = 0;
|
||||
unsigned long uvalue;
|
||||
char convert[20];
|
||||
int place = 0;
|
||||
int spadlen = 0; /* amount to space pad */
|
||||
int zpadlen = 0; /* amount to zero pad */
|
||||
char *chars = ((flags & DP_F_UP)
|
||||
? "0123456789ABCDEF"
|
||||
: "0123456789abcdef");
|
||||
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
|
||||
uvalue = value;
|
||||
|
||||
if (!(flags & DP_F_UNSIGNED)) {
|
||||
if (value < 0) {
|
||||
signvalue = '-';
|
||||
uvalue = -value;
|
||||
} else if (flags & DP_F_PLUS) { /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
} else if (flags & DP_F_SPACE) {
|
||||
signvalue = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
convert[place++] = chars[uvalue % (unsigned) base];
|
||||
uvalue = (uvalue / (unsigned)base );
|
||||
} while(uvalue && (place < 20));
|
||||
if (place == 20)
|
||||
place--;
|
||||
convert[place] = 0;
|
||||
|
||||
zpadlen = max - place;
|
||||
spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
|
||||
if (zpadlen < 0)
|
||||
zpadlen = 0;
|
||||
if (spadlen < 0)
|
||||
spadlen = 0;
|
||||
if (flags & DP_F_ZERO) {
|
||||
zpadlen = MAX(zpadlen, spadlen);
|
||||
spadlen = 0;
|
||||
}
|
||||
if (flags & DP_F_MINUS)
|
||||
spadlen = -spadlen; /* Left Justifty */
|
||||
|
||||
/* Spaces */
|
||||
while (spadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--spadlen;
|
||||
}
|
||||
|
||||
/* Sign */
|
||||
if (signvalue)
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
|
||||
/* Zeros */
|
||||
if (zpadlen > 0) {
|
||||
while (zpadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
}
|
||||
|
||||
/* Digits */
|
||||
while (place > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, convert[--place]);
|
||||
|
||||
/* Left Justified spaces */
|
||||
while (spadlen < 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++spadlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
|
||||
{
|
||||
if (*currlen < maxlen)
|
||||
buffer[(*currlen)++] = c;
|
||||
}
|
||||
|
||||
int etc_vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
||||
{
|
||||
str[0] = 0;
|
||||
dopr(str, count, fmt, args);
|
||||
return(STRLEN(str));
|
||||
}
|
||||
|
||||
int etc_snprintf (char *str, size_t count, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
etc_vsnprintf(str, count, fmt, ap);
|
||||
va_end(ap);
|
||||
return(STRLEN(str));
|
||||
}
|
||||
|
||||
#ifndef INSTALL_ETC_SNPRINTF_TEST
|
||||
#define INSTALL_ETC_SNPRINTF_TEST defined(ETC_SNPRINTF_TEST_OUTPUT)
|
||||
#endif
|
||||
|
||||
#if INSTALL_ETC_SNPRINTF_TEST
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char buf1[1024];
|
||||
char buf2[1024];
|
||||
char *int_fmt[] = { "%-1.5d", "%1.5d", "%123.9d", "%5.5d", "%10.5d",
|
||||
"% 10.5d", "%+22.33d", "%01.3d", "%4d", 0 };
|
||||
long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
|
||||
int x, y;
|
||||
int fail = 0;
|
||||
int num = 0;
|
||||
|
||||
ETC_SNPRINTF_TEST_OUTPUT("Testing etc_snprintf() against sprintf()...");
|
||||
|
||||
for (x = 0; int_fmt[x] != 0; x++) {
|
||||
for (y = 0; int_nums[y] != 0 ; y++) {
|
||||
etc_snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
|
||||
sprintf (buf2, int_fmt[x], int_nums[y]);
|
||||
if (STRCMP (buf1, buf2)) {
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\netc_snprintf() doesn't match format: ");
|
||||
ETC_SNPRINTF_TEST_OUTPUT(int_fmt[x]);
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n\tetc_snprintf() = ");
|
||||
ETC_SNPRINTF_TEST_OUTPUT(buf1);
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n\tsprintf() = ");
|
||||
ETC_SNPRINTF_TEST_OUTPUT(buf2);
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n");
|
||||
fail++;
|
||||
} else {
|
||||
ETC_SNPRINTF_TEST_OUTPUT(".");
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n");
|
||||
return fail;
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ETC_SNPRINTF_TEST */
|
||||
@@ -0,0 +1,102 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/stricmp.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: stricmp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:54 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/05/24 20:32:30 paul
|
||||
* CAD-UL compiler is picky.
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:57 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/04/09 20:33:48 wes
|
||||
* re-constify. let's see what, if anything, blows up
|
||||
*
|
||||
* Revision 1.2 1998/06/17 18:28:33 meister
|
||||
* This function returned -1 for both cases of non-matching strings. Fixed
|
||||
* to return 1 or -1 as appropriate.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:51 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
int
|
||||
etc_stricmp(register const char *s,
|
||||
register const char *t)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
while (*s && *t) {
|
||||
a = (int)*s; b = (int)*t;
|
||||
|
||||
/* we only call tolower() if we're sure we need to because
|
||||
* on some systems, calling tolower() on something other
|
||||
* than an uppercase character will break the character.
|
||||
*/
|
||||
if (isupper(a))
|
||||
a = tolower(a);
|
||||
if (isupper(b))
|
||||
b = tolower(b);
|
||||
if (a != b)
|
||||
return (a > b ? 1 : -1);
|
||||
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
|
||||
if (*s != *t)
|
||||
return (*s > *t ? 1 : -1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strncpy.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strncpy.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:54 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/02/09 21:23:58 paul
|
||||
* Return dst (duh).
|
||||
*
|
||||
* Revision 1.2 2001/02/09 20:16:42 paul
|
||||
* Fixed Header line.
|
||||
*
|
||||
* Revision 1.1 2001/02/09 20:13:42 paul
|
||||
* Our own version of strncpy(), just in case the user doesn't have one.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
char *
|
||||
etc_strncpy(char *dst, const char *src, size_t n)
|
||||
{
|
||||
char *ret = dst;
|
||||
|
||||
for ( ; (n > 0) && ((*dst++ = *src++) != '\0'); --n) {
|
||||
}
|
||||
for ( ; n > 0; --n) {
|
||||
*dst++ = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strnicmp.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strnicmp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:55 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/05/24 20:32:30 paul
|
||||
* CAD-UL compiler is picky.
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:57 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/04/09 20:33:48 wes
|
||||
* re-constify. let's see what, if anything, blows up
|
||||
*
|
||||
* Revision 1.2 1998/06/17 18:25:54 meister
|
||||
* This function only returned 0 or -1, now fixed to return 0, 1, or -1
|
||||
* as appropriate.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:51 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
int
|
||||
etc_strnicmp(register const char *s,
|
||||
register const char *t,
|
||||
size_t len)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
while (*s && *t && len) {
|
||||
len--;
|
||||
a = (int)*s; b = (int)*t;
|
||||
if (isupper(a))
|
||||
a = tolower(a);
|
||||
if (isupper(b))
|
||||
b = tolower(b);
|
||||
if (a != b)
|
||||
return (a > b ? 1 : -1);
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
|
||||
/* if we're here because len is zero, don't do the final compare,
|
||||
* which verifies that both strings are null terminated, cause
|
||||
* chances are, they're not.
|
||||
*/
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
if (*s != *t) {
|
||||
return (*s > *t ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strtol.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strtol.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:55 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:58 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/10/14 13:03:20 sar
|
||||
* Removed setting of errno on errors as it isn't portable enough.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:52 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
/* This doesn't accept 0x if the radix is 16. The overflow code assumes
|
||||
* a 2's complement architecture */
|
||||
long
|
||||
etc_strtol(char *string,
|
||||
char **endptr,
|
||||
int radix)
|
||||
{
|
||||
char *s;
|
||||
long value;
|
||||
long new_value;
|
||||
int sign;
|
||||
int increment;
|
||||
|
||||
value = 0;
|
||||
sign = 1;
|
||||
s = string;
|
||||
|
||||
if ((radix == 1) || (radix > 36) || (radix < 0)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* skip whitespace */
|
||||
while ((*s == ' ') || (*s == '\t') || (*s == '\n') || (*s == '\r'))
|
||||
s++;
|
||||
|
||||
if (*s == '-') {
|
||||
sign = -1; s++;
|
||||
}
|
||||
else if (*s == '+')
|
||||
s++;
|
||||
|
||||
if (radix == 0) {
|
||||
if (*s == '0') {
|
||||
s++;
|
||||
if ((*s == 'x') || (*s == 'X')) {
|
||||
s++;
|
||||
radix = 16;
|
||||
}
|
||||
else
|
||||
radix = 8;
|
||||
}
|
||||
else
|
||||
radix = 10;
|
||||
}
|
||||
|
||||
/* read number */
|
||||
while (1) {
|
||||
if ((*s >= '0') && (*s <= '9'))
|
||||
increment = *s - '0';
|
||||
else if ((*s >= 'a') && (*s <= 'z'))
|
||||
increment = *s - 'a' + 10;
|
||||
else if ((*s >= 'A') && (*s <= 'Z'))
|
||||
increment = *s - 'A' + 10;
|
||||
else
|
||||
break;
|
||||
|
||||
if (increment >= radix)
|
||||
break;
|
||||
|
||||
new_value = value * radix + increment;
|
||||
/* detect overflow */
|
||||
if ((new_value - increment)/radix != value) {
|
||||
s = string;
|
||||
value = -1 >> 1;
|
||||
if (sign < 0)
|
||||
value += 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
value = new_value;
|
||||
s++;
|
||||
}
|
||||
|
||||
done:
|
||||
if (endptr)
|
||||
*endptr = s;
|
||||
return value*sign;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strtoul.c,v 1.3 2003/01/16 18:18:58 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strtoul.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:58 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:55 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:59 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/10/14 13:03:20 sar
|
||||
* Removed setting of errno on errors as it isn't portable enough.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:52 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
/* This doesn't accept 0x if the radix is 16. The overflow code assumes
|
||||
* a 2's complement architecture */
|
||||
unsigned long
|
||||
etc_strtoul(char *string,
|
||||
char **endptr,
|
||||
int radix)
|
||||
{
|
||||
char *s;
|
||||
unsigned long value;
|
||||
unsigned long new_value;
|
||||
int sign;
|
||||
int increment;
|
||||
|
||||
value = 0;
|
||||
sign = 1;
|
||||
s = string;
|
||||
|
||||
if ((radix == 1) || (radix > 36) || (radix < 0)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* skip whitespace */
|
||||
while ((*s == ' ') || (*s == '\t') || (*s == '\n') || (*s == '\r'))
|
||||
s++;
|
||||
|
||||
if (*s == '-') {
|
||||
sign = -1; s++;
|
||||
}
|
||||
else if (*s == '+')
|
||||
s++;
|
||||
|
||||
if (radix == 0) {
|
||||
if (*s == '0') {
|
||||
s++;
|
||||
if ((*s == 'x') || (*s == 'X')) {
|
||||
s++;
|
||||
radix = 16;
|
||||
}
|
||||
else
|
||||
radix = 8;
|
||||
}
|
||||
else
|
||||
radix = 10;
|
||||
}
|
||||
|
||||
/* read number */
|
||||
while (1) {
|
||||
if ((*s >= '0') && (*s <= '9'))
|
||||
increment = *s - '0';
|
||||
else if ((*s >= 'a') && (*s <= 'z'))
|
||||
increment = *s - 'a' + 10;
|
||||
else if ((*s >= 'A') && (*s <= 'Z'))
|
||||
increment = *s - 'A' + 10;
|
||||
else
|
||||
break;
|
||||
|
||||
if (increment >= radix)
|
||||
break;
|
||||
|
||||
new_value = value * radix + increment;
|
||||
/* detect overflow */
|
||||
if ((new_value - increment)/radix != value) {
|
||||
s = string;
|
||||
value = -1 >> 1;
|
||||
if (sign < 0)
|
||||
value += 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
value = new_value;
|
||||
s++;
|
||||
}
|
||||
|
||||
done:
|
||||
if (endptr)
|
||||
*endptr = s;
|
||||
return value*sign;
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/thd_dbg.c,v 1.3 2003/01/16 18:18:58 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998-1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: thd_dbg.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:58 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:56 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.12 2001/06/12 08:06:07 paul
|
||||
* Mutex priorities are unsigned.
|
||||
* Added debugging to condition variable routines.
|
||||
*
|
||||
* Revision 1.11 2001/03/22 16:54:08 paul
|
||||
* Mutex and condition variable functions now return errors.
|
||||
*
|
||||
* Revision 1.10 2001/03/20 17:11:38 paul
|
||||
* Removed unused local variable.
|
||||
*
|
||||
* Revision 1.9 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.8 2000/10/16 19:22:06 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.6 2000/03/17 00:16:59 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.5 1999/09/02 20:58:18 wes
|
||||
* Create a new memory pool for thread debug state, and use it instead of
|
||||
* using malloc/free.
|
||||
*
|
||||
* Revision 1.4 1999/05/20 19:44:32 wes
|
||||
* Print out more info for thread assertion failures
|
||||
*
|
||||
* Revision 1.3 1999/05/19 21:27:33 wes
|
||||
* Fix signed vs unsigned comparison glitch
|
||||
*
|
||||
* Revision 1.2 1999/04/21 20:05:18 wes
|
||||
* Silence DIAB compiler warnings
|
||||
*
|
||||
* Revision 1.1 1999/02/18 17:45:57 wes
|
||||
* 8.3ize thread_debug.c to thd_dbg.c
|
||||
*
|
||||
* Revision 1.2 1999/02/18 04:41:23 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 1.1.6.10 1999/02/05 18:33:57 paul
|
||||
* Changed the way we identify the thread for trace statements, due to
|
||||
* differences between various pthreads implementations.
|
||||
*
|
||||
* Revision 1.1.6.9 1999/01/22 19:49:15 paul
|
||||
* Added this_thread() to allow other parts of the code to print the
|
||||
* current thread.
|
||||
* Added copyright notice.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/thread.h>
|
||||
#include <wrn/attache/config.h> /* !!!??? */
|
||||
#include <wrn/attache/glue.h> /* !!!??? */
|
||||
#include <wrn/wm/common/bug.h>
|
||||
|
||||
#define ASSERT1(cond, lock, file, line) \
|
||||
do {if (!(cond)) { thread_preabort(file, line, lock); \
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_FATAL, 0, \
|
||||
(BUG_OUT, "Lock assertion \"%s\" failed, file %s, line %d", \
|
||||
#cond, file, line)); } } while (0)
|
||||
|
||||
glue_mutex_t etc_meta_mutex;
|
||||
|
||||
enum thread_debug_state {
|
||||
THREAD_DEBUG_RUNNABLE,
|
||||
THREAD_DEBUG_MUTEX_WAIT,
|
||||
THREAD_DEBUG_COND_WAIT
|
||||
};
|
||||
|
||||
typedef struct _tdit thread_debug_info_t;
|
||||
|
||||
struct _tdit {
|
||||
thread_debug_info_t *next_thread;
|
||||
char *thread_name;
|
||||
enum thread_debug_state thread_state;
|
||||
etc_mutex_t *thread_held_locks;
|
||||
etc_mutex_t *thread_wanted_lock;
|
||||
etc_cond_t *thread_wanted_cond;
|
||||
glue_thread_t tid;
|
||||
};
|
||||
|
||||
size_t thd_debug_size = sizeof(thread_debug_info_t);
|
||||
|
||||
void debug_state_free(void *debug)
|
||||
{
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "Freeing thread state %p", debug));
|
||||
GLUE_FREE_TO_POOL(debug, MEMPOOL_THD_DBG);
|
||||
}
|
||||
|
||||
|
||||
void common_thread_init(void)
|
||||
{
|
||||
GLUE_THREAD_INIT();
|
||||
GLUE_MUTEX_INIT_MAGIC(&etc_meta_mutex);
|
||||
|
||||
GLUE_THD_COOKIE_INIT(debug_state_free);
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "Threading!"));
|
||||
}
|
||||
|
||||
thread_debug_info_t *thread_debug_state(void)
|
||||
{
|
||||
thread_debug_info_t *dip;
|
||||
|
||||
GLUE_THD_COOKIE_GET(&dip);
|
||||
|
||||
if (dip == NULL) {
|
||||
dip = GLUE_ALLOC_FROM_POOL(sizeof(*dip), MEMPOOL_THD_DBG);
|
||||
BUG_ASSERT(dip != NULL);
|
||||
|
||||
dip->tid = GLUE_THD_SELF();
|
||||
dip->next_thread = NULL;
|
||||
dip->thread_name = NULL;
|
||||
dip->thread_state = THREAD_DEBUG_RUNNABLE;
|
||||
dip->thread_held_locks = NULL;
|
||||
dip->thread_wanted_lock = NULL;
|
||||
dip->thread_wanted_cond = NULL;
|
||||
GLUE_THD_COOKIE_SET(dip);
|
||||
}
|
||||
return dip;
|
||||
}
|
||||
|
||||
static unsigned compute_lock_prio(thread_debug_info_t *tdi)
|
||||
{
|
||||
unsigned prio = 0;
|
||||
etc_mutex_t *lock;
|
||||
|
||||
for (lock = tdi->thread_held_locks; lock != NULL; lock = lock->next_lock)
|
||||
{
|
||||
if (lock->lock_prio > prio)
|
||||
prio = lock->lock_prio;
|
||||
}
|
||||
|
||||
return prio;
|
||||
}
|
||||
|
||||
#if INSTALL_BUG
|
||||
static char *indent_string(int level)
|
||||
{
|
||||
static char indentfu[10]="\t\t\t\t\t\t\t\t\t\t";
|
||||
if (level < 0) level=0;
|
||||
if (level > (int)sizeof(indentfu)) level = sizeof(indentfu);
|
||||
|
||||
return &indentfu[sizeof(indentfu) - level];
|
||||
}
|
||||
#endif
|
||||
|
||||
void print_proc (int level, char *tag, thread_debug_info_t *tdi)
|
||||
{
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%s%s: %p", indent_string(level), tag, tdi));
|
||||
}
|
||||
|
||||
void print_lock(int level, char *tag, etc_mutex_t *lock)
|
||||
{
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%s%s: %s (%p) (pri %u)", indent_string(level),
|
||||
tag, lock->lock_name, lock, lock->lock_prio));
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%slock last locked in %s, line %d",
|
||||
indent_string(level+1), lock->last_lock_file, lock->last_lock_line));
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%slock last unlocked in %s, line %d",
|
||||
indent_string(level+1), lock->last_unlock_file,
|
||||
lock->last_unlock_line));
|
||||
if (lock->lock_owner != NULL) {
|
||||
print_proc(level+1, "Held by", lock->lock_owner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void thread_preabort(char *file, int line, etc_mutex_t *errlock)
|
||||
{
|
||||
thread_debug_info_t *tdi = thread_debug_state();
|
||||
etc_mutex_t *lock;
|
||||
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "locking error detected on lock %p at %s, line %d",
|
||||
errlock,
|
||||
file, line));
|
||||
|
||||
print_lock(0, "bad lock", errlock);
|
||||
|
||||
if (tdi->thread_wanted_lock == NULL) {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "No locks wanted"));
|
||||
} else {
|
||||
print_lock(0, "waiting for", tdi->thread_wanted_lock);
|
||||
}
|
||||
if (tdi->thread_held_locks == NULL) {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "No locks held"));
|
||||
} else {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "Held locks:"));
|
||||
for (lock = tdi->thread_held_locks; lock != NULL; lock = lock->next_lock) {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "\t%s (%p) (pri %u)", lock->lock_name, lock, lock->lock_prio));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int etc_mutex_lock_debug (etc_mutex_t *lock, unsigned prio,
|
||||
char *file, int line)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
unsigned curlockprio = compute_lock_prio(us);
|
||||
int ret;
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
|
||||
us->thread_state = THREAD_DEBUG_MUTEX_WAIT;
|
||||
us->thread_wanted_lock = lock;
|
||||
|
||||
ASSERT1((lock->lock_owner != us), lock, file, line);
|
||||
ASSERT1((lock->lock_prio > curlockprio), lock, file, line);
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "waiting to lock %s (%p) at %s, line %d",
|
||||
lock->lock_name, lock, file, line));
|
||||
|
||||
if (GLUE_MUTEX_TRYLOCK(&(lock)->m, prio)) {
|
||||
ETC_META_UNLOCK();
|
||||
ret = (int)GLUE_MUTEX_LOCK(&(lock)->m, prio);
|
||||
ETC_META_LOCK();
|
||||
if (ret) {
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "!!failed to lock %s (%p) at %s, line %d", lock->lock_name,
|
||||
lock, file, line));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "locked %s (%p) at %s, line %d", lock->lock_name,
|
||||
lock, file, line));
|
||||
|
||||
us->thread_state = THREAD_DEBUG_RUNNABLE;
|
||||
us->thread_wanted_lock = NULL;
|
||||
|
||||
ASSERT1((lock->lock_prio == prio), lock, file, line);
|
||||
ASSERT1((lock->lock_owner == NULL), lock, file, line);
|
||||
|
||||
lock->last_lock_file = file;
|
||||
lock->last_lock_line = line;
|
||||
lock->lock_owner = us;
|
||||
lock->next_lock = us->thread_held_locks;
|
||||
us->thread_held_locks = lock;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int etc_mutex_unlock_debug (etc_mutex_t *lock, unsigned prio,
|
||||
char *file, int line)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
|
||||
ASSERT1((lock->lock_owner == us), lock, file, line);
|
||||
ASSERT1((lock->lock_prio == prio), lock, file, line);
|
||||
lock->lock_owner = NULL;
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "unlocking %s (%p) at %s, line %d",
|
||||
lock->lock_name, lock, file, line));
|
||||
|
||||
if (lock == us->thread_held_locks) {
|
||||
us->thread_held_locks = lock->next_lock;
|
||||
lock->next_lock = NULL;
|
||||
} else {
|
||||
etc_mutex_t *l1;
|
||||
|
||||
for (l1 = us->thread_held_locks; l1 != NULL; l1 = l1->next_lock) {
|
||||
if (l1->next_lock == lock) {
|
||||
l1->next_lock = lock->next_lock;
|
||||
lock->next_lock = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT1((lock->next_lock == NULL), lock, file, line);
|
||||
|
||||
lock->last_unlock_file = file;
|
||||
lock->last_unlock_line = line;
|
||||
|
||||
return (int)GLUE_MUTEX_UNLOCK(&(lock)->m, prio);
|
||||
}
|
||||
|
||||
|
||||
void etc_mutex_lock_assert (etc_mutex_t *lock, unsigned prio,
|
||||
char *file, int line)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
|
||||
ETC_META_LOCK();
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
|
||||
ASSERT1((lock->lock_owner == us), lock, file, line);
|
||||
ASSERT1((lock->lock_prio == prio), lock, file, line);
|
||||
|
||||
ETC_META_UNLOCK();
|
||||
}
|
||||
|
||||
int etc_mutex_destroy (etc_mutex_t *lock, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "destroying mutex %s (%p)",
|
||||
lock->lock_name, lock));
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
ret = (int)GLUE_MUTEX_DESTROY(&(lock)->m);
|
||||
(lock)->magic = ~ETC_LOCK_MAGIC;
|
||||
lock->last_unlock_file = file;
|
||||
lock->last_unlock_line = line;
|
||||
|
||||
ETC_META_UNLOCK();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *this_thread(void)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
|
||||
return (void *)us;
|
||||
}
|
||||
|
||||
int etc_mutex_init(etc_mutex_t *lock, unsigned prio, char *name)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
lock->magic = ETC_LOCK_MAGIC;
|
||||
lock->lock_owner = NULL;
|
||||
lock->lock_name = name;
|
||||
lock->lock_prio = prio;
|
||||
lock->next_lock = NULL;
|
||||
ret = (int)GLUE_MUTEX_INIT(&lock->m, prio);
|
||||
ETC_META_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_mutex_lock(etc_mutex_t *lock, unsigned prio, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = etc_mutex_lock_debug(lock, prio, file, line);
|
||||
ETC_META_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_mutex_unlock(etc_mutex_t *lock, unsigned prio, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = etc_mutex_unlock_debug(lock, prio, file, line);
|
||||
ETC_META_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_init(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
cond->m = mutex;
|
||||
ret = (int)GLUE_COND_INIT(&cond->c, &mutex->m);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_init() and cv_create() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "GLUE_COND_INIT returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_wait(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
etc_mutex_unlock_debug(mutex, mutex->lock_prio, file, line);
|
||||
ret = (int)GLUE_COND_WAIT(&cond->c, &etc_meta_mutex);
|
||||
etc_mutex_lock_debug(mutex, mutex->lock_prio, file, line);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_wait() and cv_wait() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_WAIT returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_wakeup(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = (int)GLUE_COND_WAKEUP(&cond->c, mutex);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_signal() and cv_signal() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_WAKEUP returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_broadcast(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = (int)GLUE_COND_BROADCAST(&cond->c, mutex);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_broadcast() and cv_broadcast() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_BROADCAST returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_destroy(etc_cond_t *cond, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = (int)GLUE_COND_DESTROY(&cond->c);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_destroy() and cv_delete() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_DESTROY returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/weakprng.c,v 1.3 2003/01/16 18:18:58 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: weakprng.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:58 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:56 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.9 2001/01/19 22:21:33 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.8 2000/03/17 00:17:00 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.7 1998/03/06 20:30:45 sra
|
||||
* Fiddle seeding algorithm per Phil's recommendation.
|
||||
*
|
||||
* Revision 1.6 1998/02/25 22:08:28 mrf
|
||||
* Correct copyright dates.
|
||||
*
|
||||
* Revision 1.5 1998/02/25 15:17:07 mrf
|
||||
* Fix msvc5 compiler warnings.
|
||||
*
|
||||
* Revision 1.4 1998/02/25 04:43:28 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.3 1998/02/21 23:38:34 sra
|
||||
* Minor changes to WeakPRNG module.
|
||||
*
|
||||
* Revision 1.1 1998/02/21 22:05:36 mrf
|
||||
* Added weak random number generator.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_WEAKPRNG_H
|
||||
#include <wrn/wm/common/weakprng.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements a cryptographically WEAK random number generator
|
||||
* suitable only for dithering protocol responses to avoid collisions or
|
||||
* other situations where the purpose of the "random" number is to avoid
|
||||
* simultaneity or repeated use of the same values. For any cryptographic
|
||||
* purposes, the cryptographically strong random number generator (found
|
||||
* in common/lib/prng.c) should be used instead.
|
||||
*
|
||||
* This weak generator is useful for dithering for those protocols which
|
||||
* require it (such as DHCP, RIP, IGMP, Router Discovery and IPv6 Neighbor
|
||||
* Discovery). It has relatively low processing overhead (compared to the
|
||||
* strong random number generator), and it is seeded automatically by
|
||||
* Attache.
|
||||
*
|
||||
* It is the purpose of this weak random number generator, not to produce
|
||||
* truly random numbers, but to produce numbers which are likely to be
|
||||
* different for different hosts on a given link. In order to obtain
|
||||
* this result, it is important that different hosts use different seeds.
|
||||
* Attache seeds (and re-seeds) the generator in several places with values
|
||||
* that are likely to be unique for this host. Seeds include the GLUE_NOW()
|
||||
* value at the end of the attache_init() call, the hardware address or
|
||||
* IPv6 address token provided in the net_if structure during each if_attach()
|
||||
* call, if any, and the IP addresses provided to route_add_address() each
|
||||
* time it is called. Successive seeds do not reset the generator. If a
|
||||
* customer has additional seed information that may help to improve the
|
||||
* uniqueness of the generated values for a particular host (e.g. a box
|
||||
* serial number), he can also input those seeds using the seed call below.
|
||||
*/
|
||||
|
||||
static bits32_t ep_weak_prng_value;
|
||||
|
||||
/* ep_seed_weak_prng --
|
||||
* Seeds the weak random number generator with (hopefully unique
|
||||
* for this host) seed data. Data is provided as a buffer of
|
||||
* unsigned bytes and a length (in bytes). We run the generator
|
||||
* as part of the seeding process to reduce the chance of losing
|
||||
* this seed if the generator is seeded again before it is used.
|
||||
*/
|
||||
void
|
||||
ep_seed_weak_prng(bits8_t *seed_string, size_t len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int) len; i++) {
|
||||
ep_weak_prng_value ^= ((bits32_t) (seed_string[i])) << (8 * (i & 3));
|
||||
if ((i & 3) == 3)
|
||||
ep_weak_prng(0xFFFFFFFFL);
|
||||
}
|
||||
ep_weak_prng(0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
/* ep_weak_prng --
|
||||
* Returns a "random" 32_bit integer less than or equal to 'max'.
|
||||
*
|
||||
* The algorithm is a linear congruential random number generator,
|
||||
* equivilent to the ANSI C rand() function but with constants that
|
||||
* provide better results than those used in the BSD rand() function.
|
||||
*
|
||||
* These constants are from Knuth, chap 3, pp 102 & 170. Don't change
|
||||
* them unless you really understand the underlying math.
|
||||
*/
|
||||
bits32_t
|
||||
ep_weak_prng(bits32_t max)
|
||||
{
|
||||
ep_weak_prng_value = (ep_weak_prng_value + 1) * 16664525L;
|
||||
|
||||
return ++max ? ep_weak_prng_value % max : ep_weak_prng_value;
|
||||
}
|
||||
Reference in New Issue
Block a user