#include "dkcCRC.h"dkcCRC.cのインクルード依存関係図

構成 | |
| union | dkc_local_ptr_offset_union |
| union | dkc_local_offset_union |
マクロ定義 | |
| #define | DKUTIL_C_CRC_C |
型定義 | |
| typedef ULONG | value_type |
| typedef USHORT | value_type16 |
| typedef dkc_local_ptr_offset_union | OFFSET_PTR_UNION |
| typedef dkc_local_offset_union | OFFSET_UNION |
関数 | |
| DKC_INLINE value_type | mask_value (size_t Bits) |
| unsigned char | index (value_type rem, unsigned char x,size_t Bits, BOOL DoReflect) |
| Compare a byte to the remainder's highest byte. | |
| value_type | shift (value_type rem,BOOL DoReflect) |
| Shift out the remainder's highest byte. | |
| value_type | reflector (size_t Bits, value_type x) |
| value_type | reflection (BOOL DoReflect, size_t Bits, value_type x) |
| int | makecrctable32 (ULONG *crctable, size_t Bits, ULONG TruncPoly, BOOL Reflect) |
| CRC table generator 32bit version. | |
| int | makecrctable16 (USHORT *crctable, size_t Bits, ULONG TruncPoly, BOOL Reflect) |
| CRC table generator 16bit version. | |
| USHORT * | get_crc16left () |
| USHORT * | get_crc16right () |
| ULONG * | get_crc32left () |
| ULONG * | get_crc32right () |
| USHORT * | get_crc_ccitt () |
| USHORT * | get_crc_xmodem () |
| size_t WINAPI | dkcCRCGetUseTableSize (size_t Bits) |
| dkcCRCInit()のbufferに渡すバッファサイズを求める。 | |
| DKC_CRC *WINAPI | dkcAllocCRC (size_t Bits, ULONG TruncPoly, ULONG InitRem, ULONG FinalXor, dkctBOOL ReflectIn, dkctBOOL ReflectRem) |
| DKC_CRC *WINAPI | dkcAllocCRC_32left () |
| DKC_CRC *WINAPI | dkcAllocCRC_32right () |
| DKC_CRC *WINAPI | dkcAllocCRC_ansi16left () |
| DKC_CRC *WINAPI | dkcAllocCRC_ansi16right () |
| DKC_CRC *WINAPI | dkcAllocCRC_ccitt_left () |
| DKC_CRC *WINAPI | dkcAllocCRC_ccitt_right () |
| DKC_CRC *WINAPI | dkcAllocCRC_7left () |
| DKC_CRC *WINAPI | dkcAllocCRC_7right () |
| DKC_CRC *WINAPI | dkcAllocCRC_xmodem () |
| int WINAPI | dkcFreeCRC (DKC_CRC **pp) |
| int WINAPI | dkcCRCInit (DKC_CRC *p, void *buffer, size_t Bits, ULONG TruncPoly, ULONG InitRem, ULONG FinalXor, dkctBOOL ReflectIn, dkctBOOL ReflectRem) |
| void WINAPI | dkcCRCLoad (DKC_CRC *p, const BYTE *pBuffer, size_t size) |
| void WINAPI | dkcCRCLoadBlock (DKC_CRC *pobj, const void *bytes_begin, const void *bytes_end) |
| DKC_INLINE ULONG | get_sigbit (size_t Bits) |
| ULONG WINAPI | dkcCRCFinal (DKC_CRC *p) |
| ULONG WINAPI | dkcCRCResult (const DKC_CRC *p) |
dkcCRC.c で定義されています。
|
|
|
|
|
|
|
|
|
|
|
参照元 makecrctable32(), mask_value(), reflection(), reflector(), と shift(). |
|
|
参照元 makecrctable16(). |
|
||||||||||||||||||||||||||||
|
参照先 DKC_CRC, dkcAllocate(), dkcCRCGetUseTableSize(), dkcCRCInit(), dkcFree(), dkctBOOL, と NULL. 参照元 dkcAllocCRC_32left(), dkcAllocCRC_32right(), dkcAllocCRC_7left(), dkcAllocCRC_7right(), dkcAllocCRC_ansi16left(), dkcAllocCRC_ansi16right(), dkcAllocCRC_ccitt_left(), dkcAllocCRC_ccitt_right(), と dkcAllocCRC_xmodem().
00230 {
00231 DKC_CRC *p = (DKC_CRC *)dkcAllocate(sizeof(DKC_CRC));
00232 void *pt;
00233
00234 if(NULL==p){
00235 return NULL;
00236 }
00237 pt = dkcAllocate(dkcCRCGetUseTableSize(Bits));
00238 if(NULL==pt){
00239 goto Error;
00240 }
00241 dkcCRCInit(p,pt,Bits,TruncPoly,InitRem,FinalXor,ReflectIn,ReflectRem);
00242
00243 return p;
00244
00245 Error:
00246 dkcFree((void **)&p);
00247 return NULL;
00248 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と FALSE.
00250 {
00251 return dkcAllocCRC(32, 0xEDB88320, 0xFFFFFFFF, 0xFFFFFFFF, FALSE, FALSE);
00252
00253 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と TRUE.
00255 {
00256 //バグ ... 値を治す
00257 return dkcAllocCRC(32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, TRUE, TRUE);
00258 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と FALSE.
00273 {
00274 return dkcAllocCRC(16, 0x51, 0xFFFF, 0, FALSE,FALSE);
00275 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と TRUE.
00276 {
00277 return dkcAllocCRC(16, 0x8a, 0xFFFF, 0, TRUE,TRUE);
00278 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と TRUE.
00259 {
00260 return dkcAllocCRC(16, 0x8005, 0, 0, TRUE,TRUE);
00261 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と FALSE.
00263 {
00264 return dkcAllocCRC(16, 0xa001, 0, 0, FALSE,FALSE);
00265 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と FALSE.
00267 {
00268 return dkcAllocCRC(16, 0x1021, 0xFFFF, 0, FALSE,FALSE);
00269 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と TRUE.
00270 {
00271 return dkcAllocCRC(16, 0x8005, 0xFFFF, 0, TRUE,TRUE);
00272 }
|
|
|
参照先 DKC_CRC, dkcAllocCRC(), と TRUE.
00280 {
00281 return dkcAllocCRC(16, 0x8408, 0, 0, TRUE,TRUE);
00282 }
|
|
|
参照先 BOOL, DKC_CRC, mask_value(), dkc_CRC::mBits, dkc_CRC::mFinalXor, dkc_CRC::mR, dkc_CRC::mReflectIn, dkc_CRC::mReflectRem, dkc_CRC::mResult, と reflection().
00490 {
00491 BOOL b = (p->mReflectRem != p->mReflectIn);
00492 size_t Bits = p->mBits;
00493 ULONG ult = mask_value(Bits);
00494 //~(0x80000000 >> (Bits ));//( ( 1u ) << ( get_sigbit(Bits) - 1u ) );
00495 //変数の再利用・・・。本当はしたくないのだが・・・。
00496 Bits = ( reflection(b,Bits,p->mR) ^ p->mFinalXor ) & ult;
00497
00498 p->mResult = Bits;
00499
00500 return Bits;
00501
00502
00503 //reflect_out_type::reflect(rem_) ^ get_final_xor_value() )
00504 // & masking_type::sig_bits_fast;
00505 }
|
|
|
dkcCRCInit()のbufferに渡すバッファサイズを求める。
参照元 dkcAllocCRC().
00214 {
00215 //手抜き演算〜〜
00216 size_t t;
00217 if(Bits <= 16){
00218 t = sizeof(USHORT) * 0x100;
00219 }else if(Bits <= 32){
00220 t = sizeof(ULONG) * 0x100;
00221 }else{
00222 t = 0;
00223 }
00224 return t;
00225 }
|
|
||||||||||||||||||||||||||||||||||||
|
参照先 DKC_CRC, dkctBOOL, makecrctable16(), makecrctable32(), dkc_CRC::mBits, dkc_CRC::mFinalXor, dkc_CRC::mInitRem, dkc_CRC::mR, dkc_CRC::mReflectIn, dkc_CRC::mReflectRem, dkc_CRC::mResult, dkc_CRC::mTable, dkc_CRC::mTruncPoly, と reflection(). 参照元 dkcAllocCRC().
00334 {
00335 int r;
00336
00337 //初期値
00338 p->mR = reflection(ReflectIn,Bits,InitRem);
00339 //処理結果
00340 p->mResult = 0;
00341 //テーブルへのポインタ
00342 p->mTable = buffer;
00343
00344 p->mBits = Bits;
00345 p->mTruncPoly = TruncPoly;
00346 p->mInitRem = InitRem;
00347 p->mFinalXor = FinalXor;
00348 p->mReflectIn = ReflectIn;
00349 p->mReflectRem = ReflectRem;
00350
00351
00352
00353 if(Bits <= 16){
00354 r = makecrctable16((USHORT *)buffer,Bits,TruncPoly,ReflectIn);
00355 //p->mLoader = Loader16;
00356 }else if(Bits <= 32){
00357 r = makecrctable32((ULONG *)buffer,Bits,TruncPoly,ReflectIn);
00358 //p->mLoader = Loader32;
00359 }else{
00360 r = edk_FAILED;
00361 }
00362 return r;
00363
00364 }
|
|
||||||||||||||||
|
参照先 BYTE, DKC_CRC, と dkcCRCLoadBlock().
00367 {
00368 unsigned char const * const b = (unsigned char const *)pBuffer;
00369 dkcCRCLoadBlock(p, b, b + size );
00370
00371 }
|
|
||||||||||||||||
|
参照先 BOOL, BYTE, DKC_CRC, dkcmFORCE_NOT_ASSERT, index(), mask_value(), dkc_CRC::mBits, dkc_CRC::mR, dkc_CRC::mReflectIn, dkc_CRC::mTable, と shift(). 参照元 dkcCRCLoad().
00385 {
00386 unsigned char const * p = (unsigned char const *)bytes_begin;
00387
00388 unsigned char byte_index;
00389 //for 32bit
00390 //ULONG *pTable32 = (ULONG *)pobj->mTable;
00391 //for 16bit
00392 //USHORT *pTable16 = (ULONG *)pobj->mTable;
00393
00394
00395
00396 //general purpose
00397 size_t Bits = pobj->mBits;
00398 BOOL DoReflect = pobj->mReflectIn;
00399
00400 USHORT *usp;
00401 ULONG *ulp;
00402 ULONG rem;
00403
00404 ulp = (ULONG *)pobj->mTable;
00405 usp = (USHORT *)ulp;
00406
00407 //もし、おかしな値になったらエンディアン系を疑ってネ^^;
00408 rem = pobj->mR;
00409
00410
00411 if(Bits <= 16)
00412 {//16bit filter
00413 // Recompute the CRC for each byte passed
00414 for (; p < (const BYTE *)bytes_end ; ++p )
00415 {
00416 // Compare the new byte with the remainder's higher bits to
00417 // get the new bits, shift out the remainder's current higher
00418 // bits, and update the remainder with the polynominal division
00419 // of the new bits.
00420 byte_index = index( rem, *p ,Bits,DoReflect);
00421 rem = (USHORT)shift( rem , DoReflect);
00422 rem ^= usp[ byte_index ];
00423 }
00424
00425 pobj->mR = rem & mask_value(Bits);
00426
00427 }else if(Bits <= 32)
00428 {//32bit filter
00429 for (; p < (const BYTE *)bytes_end ; ++p )
00430 {
00431
00432 byte_index = index( rem, *p ,Bits,DoReflect);
00433 rem = shift( rem ,DoReflect);
00434 rem ^= ulp[ byte_index ];
00435 }
00436 pobj->mR = rem;
00437 }else{
00438 dkcmFORCE_NOT_ASSERT("dkcCRCLoadBlock中に32ビット以上の計算を要求された");
00439 }
00440 /*
00441 OFFSET_PTR_UNION uni;
00442 OFFSET_UNION rem;
00443
00444 uni.pt32 = (ULONG *)pobj->mTable;
00445 //もし、おかしな値になったらエンディアン系を疑ってネ^^;
00446 rem.t32 = pobj->mR;
00447
00448
00449 if(Bits <= 16)
00450 {//16bit filter
00451 // Recompute the CRC for each byte passed
00452 for (; p < (const BYTE *)bytes_end ; ++p )
00453 {
00454 // Compare the new byte with the remainder's higher bits to
00455 // get the new bits, shift out the remainder's current higher
00456 // bits, and update the remainder with the polynominal division
00457 // of the new bits.
00458 byte_index = index( rem.t16, *p ,Bits,DoReflect);
00459 rem.t16 = (USHORT)shift( rem.t16 , DoReflect);
00460 rem.t16 ^= uni.pt16[ byte_index ];
00461 }
00462
00463 pobj->mR = rem.t16;
00464
00465 }else if(Bits <= 32)
00466 {//32bit filter
00467 for (; p < (const BYTE *)bytes_end ; ++p )
00468 {
00469
00470 byte_index = index( rem.t32, *p ,Bits,DoReflect);
00471 rem.t32 = shift( rem.t32 ,DoReflect);
00472 rem.t32 ^= uni.pt32[ byte_index ];
00473 }
00474 pobj->mR = rem.t32;
00475 }else{
00476 dkcmFORCE_NOT_ASSERT("dkcCRCLoadBlock中に32ビット以上の計算を要求された");
00477 }
00478 */
00479
00480
00481 // rem.t32 & mask_value(Bits);
00482 }
|
|
|
参照先 DKC_CRC, と dkc_CRC::mResult.
00507 {
00508 return p->mResult;
00509 }
|
|
|
|
|
|
00193 {
00194
00195 }
|
|
|
00197 {
00198
00199 }
|
|
|
00200 {
00201
00202 }
|
|
|
00203 {
00204
00205 }
|
|
|
00207 {
00208
00209 }
|
|
|
00210 {
00211
00212 }
|
|
|
参照先 BYTE.
00485 {
00486 return (( (BYTE)1u ) << ( Bits - 1u )) ;
00487 //return (~( ~( 0ul ) << Bits )) ;
00488 //return (~( ~(least( 0u )) << Bits ))
00489 }
|
|
||||||||||||||||||||
|
Compare a byte to the remainder's highest byte.
参照元 dkcCRCLoadBlock().
00032 {
00033 return (BYTE)(x ^ ( rem >> (DoReflect ? 0u : Bits - CHAR_BIT) ));
00034 }
|
|
||||||||||||||||||||
|
CRC table generator 16bit version.
参照先 BOOL, reflection(), と value_type16. 参照元 dkcCRCInit().
00132 {
00133
00134
00135 // factor-out constants to avoid recalculation
00136 const value_type16 fast_hi_bit = (const value_type16)(1u << ( Bits - 1u ));
00137 unsigned char const byte_hi_bit = 1u << (CHAR_BIT - 1u);
00138
00139 // loop over every possible dividend value
00140 unsigned char dividend = 0;
00141 value_type16 remainder ;
00142 unsigned char mask;
00143
00144 if(Bits > 16){
00145 return edk_FAILED;
00146 }
00147
00148 do
00149 {
00150 remainder = 0;
00151
00152
00153 // go through all the dividend's bits
00154 for ( mask = byte_hi_bit ; mask ; mask >>= 1 )
00155 {
00156 // check if divisor fits
00157 if ( dividend & mask )
00158 {
00159 remainder ^= fast_hi_bit;
00160 }
00161
00162 // do polynominal division
00163 if ( remainder & fast_hi_bit )
00164 {
00165 remainder <<= 1;
00166 remainder ^= TruncPoly;
00167 }
00168 else
00169 {
00170 remainder <<= 1;
00171 }
00172 }
00173
00174 //crctable[ crc_helper<CHAR_BIT, Reflect>::reflect(dividend) ]
00175 // = crc_helper<Bits, Reflect>::reflect( remainder );
00176 crctable[ reflection(Reflect,CHAR_BIT,dividend) ]
00177 = (USHORT)reflection(Reflect,Bits,remainder);
00178 }
00179 while ( ++dividend );
00180
00181 return edk_SUCCEEDED;
00182 }
|
|
||||||||||||||||||||
|
CRC table generator 32bit version.
参照先 BOOL, reflection(), と value_type. 参照元 dkcCRCInit().
00079 {
00080
00081 // factor-out constants to avoid recalculation
00082 const value_type fast_hi_bit = 1ul << ( Bits - 1u );
00083 unsigned char const byte_hi_bit = 1u << (CHAR_BIT - 1u);
00084
00085 // loop over every possible dividend value
00086 unsigned char dividend = 0;
00087 value_type remainder ;
00088 unsigned char mask;
00089
00090 if(Bits > 32){
00091 return edk_FAILED;
00092 }
00093
00094 do
00095 {
00096 remainder = 0;
00097
00098
00099 // go through all the dividend's bits
00100 for ( mask = byte_hi_bit ; mask ; mask >>= 1 )
00101 {
00102 // check if divisor fits
00103 if ( dividend & mask )
00104 {
00105 remainder ^= fast_hi_bit;
00106 }
00107
00108 // do polynominal division
00109 if ( remainder & fast_hi_bit )
00110 {
00111 remainder <<= 1;
00112 remainder ^= TruncPoly;
00113 }
00114 else
00115 {
00116 remainder <<= 1;
00117 }
00118 }
00119
00120 //crctable[ crc_helper<CHAR_BIT, Reflect>::reflect(dividend) ]
00121 // = crc_helper<Bits, Reflect>::reflect( remainder );
00122 crctable[ reflection(Reflect,CHAR_BIT,dividend) ]
00123 = reflection(Reflect,Bits,remainder);
00124 }
00125 while ( ++dividend );
00126
00127 return edk_SUCCEEDED;
00128 }
|
|
|
参照先 value_type. 参照元 dkcCRCFinal(), dkcCRCLoadBlock(), と reflector().
00019 {
00020 //return (~(0x80000000 >> (Bits )) << 1) + 1;
00021 //size_t a = (0x00000001 << Bits);
00022 size_t b = (0xFFFFFFFF >> (32 - Bits));
00023 //size_t result = a & b;
00024 return b;
00025
00026 //return (0x00000001 << Bits) & (0xFFFFFFFF >> (32 - Bits));
00027 }
|
|
||||||||||||||||
|
参照先 BOOL, reflector(), と value_type. 参照元 dkcCRCFinal(), dkcCRCInit(), makecrctable16(), makecrctable32(), と reflector().
00072 {
00073 return DoReflect ? reflector( Bits,x ) : x;
00074
00075 }
|
|
||||||||||||
|
参照先 mask_value(), reflection(), と value_type. 参照元 reflection().
00052 {
00053 value_type reflection = 0;
00054 value_type const one = 1;
00055 size_t i;
00056
00057 for ( i = 0 ; i < Bits ; ++i, x >>= 1 )
00058 {
00059 if ( x & one )
00060 {
00061 reflection |= ( one << (Bits - 1u - i) );
00062 }
00063 }
00064
00065
00066 //return reflection;
00067 //return reflection & (~(0x80000000 >> (Bits )) << 1) + 1;
00068
00069 return reflection & mask_value(Bits);
00070 }
|
|
||||||||||||
|
Shift out the remainder's highest byte.
参照先 BOOL, と value_type. 参照元 dkcCRCLoadBlock().
00038 {
00039 return DoReflect ? rem >> CHAR_BIT : rem << CHAR_BIT;
00040 }
|
1.3.6