?? arithmetic.h
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: target.h
** Last modified Date: 2005-11-14
** Last Version: 1.0
** Descriptions: header file of the specific codes for LPC2200 target boards
** Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#ifndef __ARITHMETIC_H
#define __ARITHMETIC_H
#ifdef __cplusplus
extern "C" {
#endif
/* MD5算法寄存器. */
typedef struct
{
uint32 state[4];
uint32 count[2];
uint8 buffer[64];
} MD5_CTX;
#ifndef _SHA_enum_
#define _SHA_enum_
enum
{
shaSuccess = 0,
shaNull, /* Null pointer parameter */
shaInputTooLong, /* input data too long */
shaStateError /* called Input after Result */
};
#endif
#define SHA1HashSize 20
/* SHA-1算法寄存器. */
typedef struct SHA1Context
{
uint32 Intermediate_Hash[SHA1HashSize / 4]; /* Message Digest */
uint32 Length_Low; /* Message length in bits */
uint32 Length_High; /* Message length in bits */
/* Index into message block array */
int16 Message_Block_Index;
uint8 Message_Block[64]; /* 512-bit message blocks */
int Computed; /* Is the digest computed? */
int Corrupted; /* Is the message digest corrupted? */
} SHA1Context;
/*********************************************************************************************************
** Function name: crc8
** Descriptions: 計算crc8,表達式為x^8 + X^5 + X^4 + x^0
** input parameters: Fcs : 初始crcr值,一般為0x0。
** cp : 數(shù)據(jù)
** n : 數(shù)據(jù)長度
** Returned value: crc值
********************************************************************************************************/
extern uint8 crc8(uint8 Fcs, uint8 *p, unsigned int n);
/*********************************************************************************************************
** Function name: crc16
** Descriptions: 計算crc16,表達式為x^16 + x^12 + x^5 + x^0
** input parameters: Fcs : 初始crcr值,反碼表示,一般為0xffff。
** cp : 數(shù)據(jù)
** Length : 數(shù)據(jù)長度
** Returned value: crc結(jié)果,反碼表示
********************************************************************************************************/
extern uint16 crc16(uint16 Fcs, uint8 *cp, int16 Length);
/*********************************************************************************************************
** Function name: CalculateEcc
** Descriptions: 計算ecc校驗,最大512字節(jié)
** input parameters: Ecc : 保存計算結(jié)果(4字節(jié))
** Buf : 數(shù)據(jù)Buf
** len : 數(shù)據(jù)長度
** Returned value: none
********************************************************************************************************/
extern void CalculateEcc(const uint8 *Buf, unsigned int len, uint8 *Ecc);
/*********************************************************************************************************
** Function name: CorrectData
** Descriptions: 通過ecc校驗校正數(shù)據(jù)
** input parameters: Ecc : 保存計算結(jié)果(4字節(jié))
** Buf : 數(shù)據(jù)Buf
** EccRead: 含讀到的ecc
** Returned value: 0 : 數(shù)據(jù)正確
** 1 : 糾正數(shù)據(jù)
** 2 : 糾正ecc
** -1 : 錯誤數(shù)據(jù)超過1位
********************************************************************************************************/
extern int CorrectData(uint8 *Buf, uint8 *EccRead , const uint8 *Ecc);
/*********************************************************************************************************
** Function name: MD5Init
** Descriptions: 初始化MD5算法寄存器
** input parameters: context : MD5算法寄存器
** Returned value: 無
********************************************************************************************************/
extern void MD5Init(MD5_CTX *context);
/*********************************************************************************************************
** Function name: MD5Update
** Descriptions: MD5 分組更新操作. 繼續(xù)一個MD5操作,處理另一個消息
** 分組并更新MD5算法寄存器.
** input parameters: context : MD5算法寄存器
** input : 輸入分組
** inputLen : 輸入的分組的長度
** Returned value: 無
********************************************************************************************************/
extern void MD5Update(MD5_CTX *context, const uint8 *input, unsigned int inputLen);
/*********************************************************************************************************
** Function name: MD5Final
** Descriptions: MD5 最終結(jié)果. 以一個 MD5 報文摘要操作結(jié)束, 寫下
** 報文摘要值
** input parameters: digest : 報文摘要
** context : MD5算法寄存器
** Returned value: 無
********************************************************************************************************/
extern void MD5Final(uint8 digest[16], MD5_CTX *context);
/*********************************************************************************************************
** Function name: SHA1Init
** Descriptions: 初始化SHA-1算法寄存器
** input parameters: context : SHA-1算法寄存器
** Returned value: shaSuccess : 成功
** shaNull : context為空
********************************************************************************************************/
extern int SHA1Init(SHA1Context *context);
/*********************************************************************************************************
** Function name: SHA1Update
** Descriptions: 執(zhí)行一次SHA-1算法
** input parameters: context : SHA-1算法寄存器
** input : 輸入分組
** inputLen : 輸入的分組的長度
** Returned value: shaSuccess : 成功
** shaNull : context為空
** shaInputTooLong : 輸入數(shù)據(jù)超長
** shaStateError : 獲得結(jié)果后調(diào)用了函數(shù)SHA1Update()
********************************************************************************************************/
extern int SHA1Update(SHA1Context *context, const uint8 *input, unsigned int inputLen);
/*********************************************************************************************************
** Function name: SHA1Final
** Descriptions: SHA-1最終結(jié)果. 以一個SHA-1報文摘要操作結(jié)束, 寫下
** 報文摘要值
** input parameters: digest : 報文摘要
** context : SHA-1算法寄存器
** Returned value: shaSuccess : 成功
** shaNull : context為空
** shaInputTooLong : 輸入數(shù)據(jù)超長
** shaStateError : 獲得結(jié)果后調(diào)用了函數(shù)SHA1Update()
********************************************************************************************************/
extern int SHA1Final(uint8 digest[SHA1HashSize], SHA1Context *context);
#ifdef __cplusplus
}
#endif
#endif
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -