版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、SHA1算法源代碼2009-10-16 17336951Sha1.h=#ifndef _SHA1_H_#define _SHA1_H_/* * */* sha1 . h */#ifndef _SHA_enum_#define _SHA_enum_Enum。ShaSuccess=0,Shanull、/* */* null pointerparameter */Shainputtoolong,/* */* inputdata too long */shastateerror/* */* called input after result */#endif# define sha1 hasshsiz
2、e 20Typedef struct SHA1Context。dword intermediate _ hashsha1 hashsize/4;/Message DigestDWORD Length _ Low/Message length in bitsDWORD Length _ High/Message length in bitsInt Message _ Block _ Index/Index into message block arrayunsigned char Message _ Block64;/512-bit message blocksInt Computed/Is t
3、he digest computed?Int Corrupted/Is the message digest corrupted? SHA1Context/function protoypesc string get sha1 string(c string s source);int sha 1 reset(sha 1 context *);Int sha1 input (sha1 context *、const unsigned char *、unsigned int);Int sha1 result (sha1context *,unsigned char message _ diges
4、tsha1 hasized);cstring sha1 to base 32(const unsigned char *);#endif=# include“sha1 . h”/define the sha1 circular left shift macro# define sha1 circularshift (bits,word)(word)(bits)|(word)(32-(bits)/local function prototales */void sha1 pad message(sha1 context *);void sha1 process message block(sha
5、1 context *);Int SHA1Reset(SHA1Context *c)。If(!c)Return shaNullc-Length _ Low=0;c-Length _ High=0;c-Message _ Block _ Index=0;c-Intermediate _ Hash0=0x;c-intermediate _ hash1=0 xefc dab 89;c-intermediate _ hash2=0x 98 badcfe;c-Intermediate _ Hash3=0x;c-intermediate _ hash4=0x c3d 2 E1 f 0;c-Computed
6、=0;c-Corrupted=0;Return shaSuccessInt sha1 result (sha1context * c,unsigned char message _ digestsha1 hasshsize)。int I;If(!C |!Message_Digest)Return shaNullc-Corrupted(if)return c-Corrupted;If(!C-已計(jì)算)。sha1 pad message(c);for(I=0);I64C-Message_Block i=0)c-Length _ Low=0;/* * */*和clear length */c-Leng
7、th _ High=0;c-Computed=1;for(I=0);I SHA1HashSizeI)message _ digestI=c-intermediate _ hashI28 *(3-(I0x 03);Return shaSuccessint sha1 input(sha1 context * context,const unsigned char * message _ array,unsigned length)。If(!長度)Return shaSuccessIf(!Context |!Message_array)Return shaNull內(nèi)容計(jì)算(If)。context-c
8、orrupted=shastate error;Return shaStateError內(nèi)容已修正(If)return context-Corrupted;While(length -!Context-Corrupted)。context-message _ blockcontext-message _ block _ index=(* message _ array0x ff);context-Length _ Low=8;If (context-Length_Low=0)。context-Length _ High;If (context-Length_High=0)。/* * */* M
9、essage is too long */context-Corrupted=1;if(context-message _ block _ index=64)sha1 processmessageblock(context);Message _ arrayReturn shaSuccessvoid sha1 process message block(sha1 context * context)。Const dword k =.0x5a,0x6ed 9e1,0x8x1bbcdc,0 xca 62 C1 D6 ;int t;DWORD tempDWORD W80;DWORD A、B、C、D、E
10、;/* */* initialize the first 16 words in the array w*/for(t=0);T 16t)。wt=context-message _ blockt * 424;wt|=context-message _ blockt * 4 116;wt|=context-message _ blockt * 4 28;wt|=context-message _ blockt * 4 3;for(t=16);T 80t)W t=sha1 circularshift (1,wt-3wt-8wt-14wt-16);a=context-Intermediate _ H
11、ash0;b=context-Intermediate _ Hash1;c=context-Intermediate _ Hash2;d=context-Intermediate _ Hash3;e=context-Intermediate _ Hash4;for(t=0);T 20t)。Temp=SHA1CircularShift(5,A)(b c)|( b)d)e wtk0;e=D;d=C;C=SHA1CircularShift(30,B);b=A;A=tempfor(t=20);T 40t)。Temp=sha1 circularshift (5,a)(b c d)e wtk1;e=D;d
12、=C;C=SHA1CircularShift(30,B);b=A;A=tempfor(t=40);T 60t).Temp=SHA1CircularShift(5,A)(B C)|(B D)|(C D)E WtK2;e=D;d=C;C=SHA1CircularShift(30,B);b=A;A=tempfor(t=60);T 80t).Temp=sha1 circularshift (5,a)(b c d)e wtk3;e=D;d=C;C=SHA1CircularShift(30,B);b=A;A=tempcontext-Intermediate _ Hash0=A;context-Interm
13、ediate _ Hash1=B;context-Intermediate _ Hash2=C;context-Intermediate _ Hash3=D;context-Intermediate _ Hash4=E;context-Message _ Block _ Index=0;void sha1 pad message(sha1 context * context)。if(context-message _ block _ index 55)。context-message _ blockcontext-message _ block _ index=0x 80;while(cont
14、ext-message _ block _ index 64)context-message _ blockcontext-message _ block _ index=0;sha1 processmessageblock(context);while(context-message _ block _ index 56)context-message _ blockcontext-message _ block _ index=0;Else.context-message _ blockcontext-message _ block _ index=0x 80;while(context-message _ block _ index 56)context-message _ blockcontext-message _ block _ index=0;/* */* store the message length as the last 8 octets*/context-message _ block56=context-length _ high 24;context-message _ block57=context-length _ high 16;context-message _ block58=context-length _ h
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 巧妙運(yùn)用閱讀策略提高學(xué)生的英語閱讀能力
- 嬰兒護(hù)理培訓(xùn)課件
- 養(yǎng)老院老人生活照料技能培訓(xùn)制度
- 養(yǎng)老院老人康復(fù)理療服務(wù)質(zhì)量管理制度
- 養(yǎng)老院老人健康監(jiān)測人員管理制度
- 養(yǎng)老院安全管理與應(yīng)急預(yù)案制度
- 養(yǎng)老院信息化建設(shè)及管理規(guī)范制度
- 攝影技術(shù)知識培訓(xùn)課件
- 2026年國有企業(yè)市場營銷崗位面試題含答案
- 2026年健康管理師健康教育考題含答案
- 農(nóng)業(yè)銀行房貸合同范本
- 早教師培訓(xùn)課件-04第二章早期教育基礎(chǔ)知識第二節(jié)早教的方法與內(nèi)容
- 前置胎盤護(hù)理查房課件
- 企業(yè)競爭圖譜:2024年運(yùn)動戶外
- 肺癌中西醫(yī)結(jié)合診療指南
- 高壓氣瓶固定支耳加工工藝設(shè)計(jì)
- 寵物服裝采購合同
- 攜程推廣模式方案
- JGT138-2010 建筑玻璃點(diǎn)支承裝置
- 垃圾清運(yùn)服務(wù)投標(biāo)方案(技術(shù)方案)
- 光速測量實(shí)驗(yàn)講義
評論
0/150
提交評論