コンテンツにスキップ

巡回冗長検査

出典: フリー百科事典『ウィキペディア(Wikipedia)』

: Cyclic Redundancy Check, CRC使使

HDLCCSMA/CD使

W1961[1]CRC-32IEEE 802.3CRC1975ZIPPNG使[2]

[]


CRC 使使

CRCn CRC  CRC-n CRC-n XXX CRC

CRC使使CRC2GF(2)使

CRC使nCRCn[]n1 1-2-n CRC便

CRC211

CRC[]


CRC11100CRCCRCCRCCRC

CRCCRCHMAC

CRC[]


n2CRCCRC (n+1) 3CRC
11010011101100 <--- 入力
1011           <--- 除数 (4 Bits)
--------------
01100011101100 <--- 結果

011XOR11
00000000001110 <--- それまでの計算結果
          1011 <--- 除数
--------------
00000000000101 <--- 余り (3 bits)

0n1CRCCRC

CRC[]


x GF(2) 使

CRC[]


CRC

(1)



9 (CRC-8)

17 (CRC-16)

33 (CRC-32)

65 (CRC-64)

n CRCn  CRCn CRCn CRCn n + 1(n + 1)n CRC CRC-n-XXX 

CRC(+CRC)CRCCRC1 + x1 + x



CRC1

kCRC22k-1

kCRCkkk) k1

x + 1 CRC

CRC[]


CRC

CRC0CRC0

n0nCRCCRCn0CRC0

XOR

: CRC

: CRC16CRCCRC2

: nCRC (n+1) 1n

CRC[]


 CRC-12 3使[3]CRC-16 使8CRC-32 3[4]使19932004Koopman  Castagnoli 16[5]2432[6][7]調[7]iSCSI

使CRC-32IEEE V.42FDDIZIPPNG 使使[2]iSCSI使 Castagnoli CRC-32C [7]

使CRCXOR

: CRC
名称 多項式 (用途) 標準 / 反転 (相反多項式の反転)
CRC-1 x + 1 (各種ハードウェア。パリティビット 0x1 / 0x1 (0x1)
CRC-4-ITU x4 + x + 1 (ITU G.704, p. 12) 0x3 / 0xC (0x9)
CRC-5-ITU x5 + x4 + x2 + 1 (ITU G.704, p. 9) 0x15 / 0x15 (0x1A)
CRC-5-USB x5 + x2 + 1USBトークンパケット) 0x05 / 0x14 (0x12)
CRC-6-ITU x6 + x + 1 (ITU G.704, p. 3) 0x03 / 0x30 (0x21)
CRC-7 x7 + x3 + 1 (通信系、MMCSD 0x09 / 0x48 (0x44)
CRC-8-ATM x8 + x2 + x + 1 (ATM Header Error Correction) 0x07 / 0xE0 (0x83)
CRC-8-CCITT x8 + x7 + x3 + x2 + 11-Wire バス 0x8D / 0xB1 (0xC6)
CRC-8-Dallas/Maxim x8 + x5 + x4 + 11-Wire バス 0x31 / 0x8C (0x98)
CRC-8 x8 + x7 + x6 + x4 + x2 + 1 0xD5 / 0xAB (0xEA [5])
CRC-8-SAE J1850 x8 + x4 + x3 + x2 + 1 0x1D / 0xB8 (0x8E)
CRC-10 x10 + x9 + x5 + x4 + x + 1 0x233 / 0x331 (0x319)
CRC-11 x11 + x9 + x8 + x7 + x2 + 1 (FlexRay) 0x385 / 0x50E (0x5C2)
CRC-12 x12 + x11 + x3 + x2 + x + 1 (通信系、[8][9] ) 0x80F / 0xF01 (0xC07)
CRC-15-CAN x15 + x14 + x10 + x8 + x7 + x4 + x3 + 1 0x4599 / 0x4CD1 (0x62CC)
CRC-16-Fletcher CRCではない。フレッチャーのチェックサム Adler-32 A & B CRC で使用
CRC-16-CCITT x16 + x12 + x5 + 1X.25V.41CDMABluetoothXMODEMHDLCPPPIrDABACnet; CRC-CCITTとも) 0x1021 / 0x8408 (0x8810 [5])
CRC-16-IBM x16 + x15 + x2 + 1SDLCUSB、その他; CRC-16とも) 0x8005 / 0xA001 (0xC002)
CRC-24-Radix-64 x24 + x23 + x18 + x17 + x14 + x11 + x10 + x7 + x6 + x5 + x4 + x3 + x + 1 (FlexRay) 0x864CFB / 0xDF3261 (0xC3267D)
CRC-30 x30 + x29 + x21 + x20 + x15 + x13 + x12 + x11 + x8 + x7 + x6 + x2 + x + 1 (CDMA) 0x2030B9C7 / 0x38E74301 (0x30185CE3)
CRC-32-Adler CRCではない; Adler-32 Adler-32参照
CRC-32 x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
(V.42, MPEG-2, zlib, PNG [10])
0x04C11DB7 / 0xEDB88320 (0x82608EDB [7])
CRC-32C (Castagnoli) x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1 (iSCSI, Btrfs, VHDX) 0x1EDC6F41 / 0x82F63B78 (0x8F6E37A0 [7])
CRC-32K (Koopman) x32 + x30 + x29 + x28 + x26 + x20 + x19 + x17 + x16 + x15 + x11 + x10 + x7 + x6 + x4 + x2 + x + 1 0x741B8CD7 / 0xEB31D82E (0xBA0DC66B [7])
CRC-64-ISO x64 + x4 + x3 + x + 1 (HDLC — ISO 3309) 0x000000000000001B / 0xD800000000000000 (0x800000000000000D)
CRC-64-ECMA-182 x64 + x62 + x57 + x55 + x54 + x53 + x52 + x47 + x46 + x45 + x40 + x39 + x38 + x37 + x35 + x33 + x32 + x31 + x29 + x27 + x24 + x23 + x22 + x21 + x19 + x17 + x13 + x12 + x10 + x9 + x7 + x4 + x + 1 (ECMA-182 p.63) 0x42F0E1EBA9EA3693 / 0xC96C5795D7870F42 (0xA17870F5D4F51B49)

使

CRC-128 (IEEE)

CRC-256 (IEEE)

[]

CRC-32[]


CRFC 1952 (gzip)  RFC 2083 (PNG) zlib 
uint32_t crc_table[256];

void make_crc_table(void) {
    for (uint32_t i = 0; i < 256; i++) {
        uint32_t c = i;
        for (int j = 0; j < 8; j++) {
            c = (c & 1) ? (0xEDB88320 ^ (c >> 1)) : (c >> 1);
        }
        crc_table[i] = c;
    }
}

uint32_t crc32(uint8_t *buf, size_t len) {
    uint32_t c = 0xFFFFFFFF;
    for (size_t i = 0; i < len; i++) {
        c = crc_table[(c ^ buf[i]) & 0xFF] ^ (c >> 8);
    }
    return c ^ 0xFFFFFFFF;
}

int main(void)
{
    make_crc_table();
    uint32_t crc = crc32();
    
    return 0;
}

生成多項式を反転させない場合の実装例。

uint32_t crc_table[256];

/* 事前にこの関数を実行しておくこと */
void make_crc_table(void){
    for(uint32_t i=0; i<256; i++){
        uint32_t c = i << 24;
        for( int j=0; j<8; j++){
            c = ( c << 1) ^ ( ( c & 0x80000000) ? 0x04C11DB7 : 0);
        }
        crc_table[i] = c;
    }
}

uint32_t crc32(uint8_t *buf, int len){
    uint32_t c = 0xffffffff;
    for (int i = 0; i < len; i++)    {
        c = (c << 8) ^ crc_table[((c >> 24) ^ buf[i]) & 0xff];
    }
    return c;
}

関連項目[編集]

脚注[編集]



(一)^ Peterson, W. W. and Brown, D. T. (1961-1). Cyclic Codes for Error Detection. Proceedings of the IRE 49: 228. doi:10.1109/JRPROC.1961.287814. ISSN 0096-8390. 

(二)^ abBrayer, K; Hammond, J L Jr. (1975). "Evaluation of error detection polynomial performance on the AUTOVON channel". Conference Record. National Telecommunications Conference, New Orleans, La. Vol. 1. New York: Institute of Electrical and Electronics Engineers. pp. 8-21 to 8-25.

(三)^ (slib) Cyclic Checksum. 200846

(四)^ Greg Cook (200899). Catalogue of parameterised CRC algorithms. 200899

(五)^ abcKoopman, Philip; Chakravarty, Tridib (2004), Cyclic Redundancy Code (CRC) Polynomial Selection For Embedded Networks, http://www.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf 

(六)^ Castagnoli, G. and Braeuer, S. and Herrman, M. (1993-6). Optimization of Cyclic Redundancy-Check Codes with 24 and 32 Parity Bits. IEEE Transactions on Communications 41 (6): 883. doi:10.1109/26.231911. ISSN 0090-6778.  - Castagnoli's et al. CRC

(七)^ abcdefKoopman, P. (2002-6). 32-Bit Cyclic Redundancy Codes for Internet Applications. The International Conference on Dependable Systems and Networks: 459. doi:10.1109/DSN.2002.1028931. http://citeseer.ist.psu.edu/koopman02bit.html.  - Castagnoli 

(八)^ Perez, A.; Wismer & Becker (1983). Byte-Wise CRC Calculations. IEEE Micro 3 (3): 4050. doi:10.1109/MM.1983.291120. ISSN 0272-1732. 

(九)^ Ramabadran, T.V.; Gaitonde, S.S. (1988). A tutorial on CRC computations. IEEE Micro 8 (4): 62-75. doi:10.1109/40.7773. ISSN 0272-1732. 

(十)^ Thomas Boutell, Glenn Randers-Pehrson, et al. (1998714). PNG (Portable Network Graphics) Specification, Version 1.2. 2008428

外部リンク[編集]


 CRC32  C++ 

Free CRC Source Code from the Boost C++ Libraries

The CRC Pitstop

Williams, R. (1993-09) A Painless Guide to CRC Error Detection Algorithms

Black, R. (1994-02) Fast CRC32 in Software; Linux4

Kounavis, M. and Berry, F. (2005). A Systematic Approach to Building High Performance, Software-based, CRC generators, Slicing-by-4  slicing-by-8 

CRC32: Generating a checksum for a file, C++  by Brian Friesen

CRC16 to CRC64 collision research

Reversing CRC - Theory and Practice.

'CRC-Analysis with Bitfilters'.

JFileRecovery CRC

MathPages - Cyclic Redundancy Checks

ACRC calculation utility and C source code generator written in Python. (MIT licence)

CRC Encoding - C#  by Marcel de Wijs

Cyclic Redundancy Check: CRC-32Henry S. Warren, Jr.  Hacker's Delight 

[]


Free CRC Verilog Circuit generator

CRC CRC32/CRC32B

CRC(8/16/31/64)

CRC

CRC

CRC Tool: Generator of synthesizable CRC functions

TRANSLATOR, BINARY ASCII162Base64CRC

Online CRC Calculator