- 首页
-
- 问答
-
-
-
-
-
-
-
-
匿名
1、补充了两个个宏定义: #define SHL1(x,s,w) ((RC5_WORD)((x)<<((w)-((s)&ROT_MASK)))) #define ROTR(x,s,w) ((RC5_WORD)(SHR1((x),(s))|SHL1((x),(s),(w))))2、解密函数定义如下: void RC5_Block_Decrypt (RC5_WORD *S,int R,char *in,char *out) { int i; RC5_WORD A,B; A = in[0] & 0xFF; A += (in[1] & 0xFF) << 8; A += (in[2] & 0xFF) << 16; A += (in[3] & 0xFF) << 24; B = in[4] & 0xFF; B += (in[5] & 0xFF) << 8; B += (in[6] & 0xFF) << 16; B += (in[7] & 0xFF) << 24; for(i=R;i>=1;i--){ B=ROTR((B-S[2*i+1]),A,W); B=B^A; A=ROTR((A-S[2*i]),B,W); A=A^B; } B=B-S[1]; A=A-S[0]; out[0] = (A >> 0) & 0xFF; out[1] = (A >> 8) & 0xFF; out[2] = (A >> 16) & 0xFF; out[3] = (A >> 24) & 0xFF; out[4] = (B >> 0) & 0xFF; out[5] = (B >> 8) & 0xFF; out[6] = (B >> 16) & 0xFF; out[7] = (B >> 24) & 0xFF; return; }/*End of RC5_Block_Decrypt */ int RC5_CBC_Decrypt_Init (pAlg, pKey) rc5CBCAlg *pAlg; rc5UserKey *pKey; { if ((pAlg == ((rc5CBCAlg *) 0)) || (pKey == ((rc5UserKey *) 0))) return (0); RC5_Key_Expand (pKey->keyLength, pKey->keyBytes,pAlg->R, pAlg->S); return (RC5_CBC_SetIV(pAlg, pAlg->I)); } int RC5_CBC_Decrypt_Update(rc5CBCAlg *pAlg,int N,char *C,int *plainLen,char *P) { int plainIndex,cipherIndex,j; plainIndex=cipherIndex=0; for(j=0;j<BB;j++) { P[plainIndex]=pAlg->chainBlock[j]; plainIndex++; } plainIndex=0; while(cipherIndex<N) { if(pAlg->inputBlockIndex<BB) { pAlg->inputBlock[pAlg->inputBlockIndex]=C[cipherIndex]; pAlg->inputBlockIndex++; cipherIndex++; } if(pAlg->inputBlockIndex==BB) { pAlg->inputBlockIndex=0; RC5_Block_Decrypt (pAlg->S,pAlg->R,pAlg->inputBlock,pAlg->chainBlock); for(j=0;j<BB;j++) { if(plainIndex<BB) P[plainIndex]^=pAlg->chainBlock[j]; else P[plainIndex]=C[cipherIndex-16+j]^pAlg->chainBlock[j]; plainIndex++; } } } *plainLen=plainIndex; return (1); }/*End of RC5_CBC_Decrypt_Update*/
-
-
求购