メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkcSHA384.c

説明を見る。

    00001
    00007 #define DKUTIL_C_SHA384_C
    00008 #include "dkcSHA384.h"
    00009 #include "dkcStdio.h"
    00010
    00011
    00012
    00013 DKC_SHA384 *WINAPI dkcAllocSHA384(){
    00014     DKC_SHA384 *p = dkcAllocate(sizeof(DKC_SHA384));
    00015     if(NULL==p){
    00016         return NULL;
    00017     }
    00018     dkcSHA384Init(p);
    00019     return p;
    00020 }
    00021
    00022 void WINAPI dkcSHA384Init(DKC_SHA384 *p){
    00023
    00024     p->m_qwH[0] = 0xcbbb9d5dc1059ed8;
    00025   p->m_qwH[1] = 0x629a292a367cd507;
    00026   p->m_qwH[2] = 0x9159015a3070dd17;
    00027   p->m_qwH[3] = 0x152fecd8f70e5939;
    00028   p->m_qwH[4] = 0x67332667ffc00b31;
    00029   p->m_qwH[5] = 0x8eb44a8768581511;
    00030   p->m_qwH[6] = 0xdb0c2e0d64f98fa7;
    00031   p->m_qwH[7] = 0x47b5481dbefa4fa4;
    00032     p->m_qwLNumBits = 0;
    00033     p->m_qwHNumBits = 0;
    00034     p->m_nNumChr = 0;
    00035
    00036     p->mFinalized = FALSE;
    00037 }
    00038
    00039 void WINAPI dkcSHA384Load(DKC_SHA384 *p,const BYTE *pBuffer,DWORD dwSize){
    00040     dkcSHA512Load(p,pBuffer,dwSize);
    00041 }
    00042
    00043 void WINAPI dkcSHA384Final(DKC_SHA384 *p){
    00044     dkcSHA512Final(p);
    00045     /*BYTE cZero = 0x00;
    00046     BYTE cOne  = 0x80;
    00047     DWORD dwHNumBits;
    00048     DWORD dwLNumBits;
    00049     if(p->mFinalized){
    00050         return ;
    00051     }
    00052
    00053     dwHNumBits = ReverseEndian(p->m_dwHNumBits);
    00054     dwLNumBits = ReverseEndian(p->m_dwLNumBits);
    00055
    00056     dkcSHA384Load(p,&cOne, 1);
    00057     while(p->m_nNumChr != SHA_BUFFER_SIZE - 8) dkcSHA384Load(p,&cZero, 1);
    00058
    00059     dkcSHA384Load(p,(BYTE *)&dwHNumBits, 4);
    00060     dkcSHA384Load(p,(BYTE *)&dwLNumBits, 4);
    00061
    00062     //ファイナル処理した。
    00063     p->mFinalized = TRUE;
    00064     */
    00065
    00066 }
    00067
    00068 int WINAPI dkcSHA384DigestStr(DKC_SHA384 *p,char *buff,size_t size){
    00069
    00070     //char s[SHA_HASH * 8 + 1];
    00071     char s[SHA384_STR_BUFFER_SIZE];
    00072     //BYTE *tb;
    00073     int i;
    00074     //s[SHA_HASH * 8]='\0';
    00075     s[SHA384_STR_BUFFER_SIZE]='\0';
    00076
    00077     if(SHA384_STR_BUFFER_SIZE > size){
    00078         return edk_BufferOverFlow;
    00079     }
    00080     if(FALSE==p->mFinalized){
    00081         //まだFinalやってないっつーの
    00082         return edk_LogicError;
    00083     }
    00084
    00085     /*for( i = 0; i < SHA384_HASH; i++){
    00086         sprintf(s + i * 12,     "%06x", (DWORD)(p->m_qwH[i] >> 32));
    00087         sprintf(s + i * 12 + 6, "%06x", (DWORD)(p->m_qwH[i] & 0x00000000ffffffff));
    00088     }*/
    00089     //tb = (BYTE *)p->m_qwH;
    00090     for( i=0;i<SHA384_BIN_BUFFER_SIZE;i++){
    00091         //sprintf(&s[SHA384_HASH * i],"%0x",p->m_qwH[i]);
    00092
    00093         //sprintf(s + i * 12,     "%0x", (DWORD)(p->m_qwH[i] >> 32));
    00094         //sprintf(s + i * 12 + 6, "%0x", (DWORD)(p->m_qwH[i] & 0x00000000ffffffff));
    00095         sprintf(s + i * 2,     "%02x",  (BYTE)(p->m_qwH[i >> 3] >> (8 * (~i & 7))));
    00096         //sprintf(s + i * 16 + 8, "%08x", (DWORD)(p->m_qwH[i] & 0x00000000ffffffff));
    00097     }
    00098
    00099     //std::string strDigest = s;
    00100     //return strDigest;
    00101     return dkc_strcpy(buff,size,s,strlen(s));
    00102 }
    00103
    00104
    00105 int WINAPI dkcSHA384FinalDigestStr(DKC_SHA384 *p,char *buff,size_t size){
    00106     dkcSHA384Final(p);
    00107     return dkcSHA384DigestStr(p,buff,size);
    00108 }
    00109
    00110 int WINAPI dkcSHA384Digest(DKC_SHA384 *p,BYTE *buff,size_t size){
    00111     ULONG i = 0;
    00112     //DWORD *dwp = (DWORD *)buff;
    00113     //char s[SHA384_STR_BUFFER_SIZE];
    00114     //s[SHA384_STR_BUFFER_SIZE]='\0';
    00115
    00116     if(SHA384_BIN_BUFFER_SIZE > size){
    00117         return edk_BufferOverFlow;
    00118     }
    00119     if(FALSE==p->mFinalized){
    00120         //まだFinalやってないっつーの
    00121         return edk_LogicError;
    00122     }
    00123     /*
    00124     for( i = 0; i < SHA_HASH; i++){
    00125         sprintf(s + i * 8, "%08x", p->m_dwH[i]);
    00126         dwp[i] = atoi(s + i * 8);
    00127     }*/
    00128     for(i = 0; i < SHA384_BIN_BUFFER_SIZE; ++i){
    00129         //buff[i] = (BYTE)(p->m_dwH[i >> 2] >> (8 * (~i & 3)));
    00130         buff[i] = (BYTE)(p->m_qwH[i >> 3] >> (8 * (~i & 7)));
    00131     }
    00132     return edk_SUCCEEDED;
    00133     //ナにバカやってんだ私。
    00134     //return dkc_memcpy(buff,size,(const void *)p->m_dwH,sizeof(p->m_dwH));
    00135 }
    00136
    00137
    00138 int WINAPI dkcSHA384FinalDigest(DKC_SHA384 *p,BYTE *buff,size_t size){
    00139     dkcSHA384Final(p);
    00140     return dkcSHA384Digest(p,buff,size);
    00141 }
    00142
    00143 int WINAPI dkcFreeSHA384(DKC_SHA384 **p){
    00144     if(NULL==p){
    00145         return edk_FAILED;
    00146     }
    00147     return dkcFree((void **)p);
    00148 }