Пример #1
0
    def test_crcmod_32(self):
        data = 0x414243
        dataSize = 24
        inputPoly = 0x104c11db7
        regInit = 0x0
        xorOut = 0x00
        crcSize = 32

        #         print "XXX {:X} {:X}".format( data, data2)

        #         barray1 = bytearray.fromhex('{:x}'.format(data))
        #         barray2 = bytearray.fromhex('{:x}'.format(data2))

        #         crc32_func = crcmod.mkCrcFun(0x104c11db7, initCrc=regInit, xorOut=xorOut)
        crc32_func = crcmod.mkCrcFun(0x104c11db7,
                                     rev=False,
                                     initCrc=regInit,
                                     xorOut=xorOut)
        crcLib = crc32_func(intToASCII(data))

        crcProc = ModCRC()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)
        crc = crcProc.calculate2(data, dataSize, inputPoly, crcSize)

        #         print "crc: {:X} {:X}".format( crcLib, crc )
        self.assertEqual(crc, crcLib)
Пример #2
0
    def test_crcmod_8_random(self):
        data = NumberMask(random.randint(1, 0xFFFFFFFFFFFFFFFF), 64)
        crcSize = 8
        crcMax = 2**crcSize - 1
        inputPoly = NumberMask((0x1 << crcSize) | random.randint(1, crcMax),
                               crcSize)
        #         regInit = random.randint(0, crcMax)
        #         xorOut = random.randint(0, crcMax)
        regInit = 0x0
        xorOut = 0x0
        reverse = bool(random.randint(0, 1))

        crc_func = crcmod.mkCrcFun(inputPoly.masterData(),
                                   rev=reverse,
                                   initCrc=regInit,
                                   xorOut=xorOut)
        crcLib = crc_func(data.toASCII())
        #         print "crc: {:X} {:X}".format( crc, crc2 )

        crcProc = ModCRC()
        crcProc.setReversed(reverse)
        crcProc.setXorOutValue(xorOut)
        crcProc.setInitCRC(regInit, crcSize)

        crc = crcProc.calculate3(data, inputPoly)

        self.assertEqual(crc, crcLib)
Пример #3
0
    def test_crcmod_8rohc(self):
        data = NumberMask(0xF00F, 16)
        inputPoly = NumberMask(0x107, 8)
        regInit = 0xFF
        xorOut = 0x0

        crc_func = crcmod.predefined.mkCrcFun('crc-8-rohc')  ## rev
        crcLib = crc_func(data.toASCII())

        crcProc = ModCRC()
        crcProc.setReversed()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)

        crc = crcProc.calculate3(data, inputPoly)

        #         print "crcx: {:b} {:b}".format( crcLib, crc )

        self.assertEqual(crc, crcLib)
Пример #4
0
    def test_crcmod_8rev_init(self):
        data = NumberMask(0xFF0F, 16)
        inputPoly = NumberMask(0x181, 8)
        regInit = 0x0F
        xorOut = 0x0

        crc_func = crcmod.mkCrcFun(inputPoly.masterData(),
                                   initCrc=regInit,
                                   rev=True,
                                   xorOut=xorOut)
        crcLib = crc_func(data.toASCII())

        crcProc = ModCRC()
        crcProc.setReversed()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)

        crc = crcProc.calculate3(data, inputPoly)
        #         print "crcx: {:b} {:b}".format( crc, crcLib )
        self.assertEqual(crc, crcLib)
Пример #5
0
    def test_crcmod_8darc(self):
        data = NumberMask(0x01, 8)
        inputPoly = NumberMask(0x139, 8)
        regInit = 0x0
        xorOut = 0x0

        crc_func = crcmod.predefined.mkCrcFun('crc-8-darc')
        crcLib = crc_func(data.toASCII())

        crcProc = ModCRC()
        crcProc.setReversed()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)

        revData = data.reorderedBytes()

        crc = crcProc.calculate3(revData, inputPoly)

        #         print "crcx: {:b} {:b}".format( crc, crcLib )

        self.assertEqual(crc, crcLib)
Пример #6
0
    def test_crcmod_8_xorOut(self):
        data = 0xF0
        dataSize = 8
        inputPoly = 0x100
        crcSize = 8
        regInit = 0x0F
        xorOut = 0xF0

        crc_func = crcmod.mkCrcFun(inputPoly,
                                   initCrc=regInit,
                                   rev=False,
                                   xorOut=xorOut)
        crcLib = crc_func(intToASCII(data))

        crcProc = ModCRC()
        crcProc.setXorOutValue(xorOut)
        crcProc.setInitCRC(regInit, crcSize)

        crc = crcProc.calculate2(data, dataSize, inputPoly, crcSize)
        #         print "crc: 0x{0:X}[0b{0:b}] 0x{1:X}[0b{1:b}]".format( crc, crcLib )
        self.assertEqual(crc, crcLib)
Пример #7
0
    def test_crcmod_8_data(self):
        data = 0xF0FF
        dataSize = 16
        inputPoly = 0x181  ## leave symmetric
        crcSize = 8
        regInit = 0x0
        xorOut = 0x0

        crc_func = crcmod.mkCrcFun(inputPoly,
                                   initCrc=regInit,
                                   rev=False,
                                   xorOut=xorOut)
        crcLib = crc_func(intToASCII(data))

        crcProc = ModCRC()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)
        crc = crcProc.calculate2(data, dataSize, inputPoly, crcSize)

        #         print "crc: {:b} {:b}".format( crcLib, crc )

        self.assertEqual(crc, crcLib)
Пример #8
0
    def test_crcmod_8rev_symm(self):
        data = NumberMask(0xFF, 8)
        inputPoly = NumberMask(0x181, 8)  ## leave symmetric
        regInit = 0x0
        xorOut = 0x0

        crc_func = crcmod.mkCrcFun(inputPoly.masterData(),
                                   initCrc=regInit,
                                   rev=True,
                                   xorOut=xorOut)
        crcLib = crc_func(data.toASCII())

        crcProc = ModCRC()
        crcProc.setReversed()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)

        revData = data.reorderedBytes()
        revPoly = inputPoly.reversed()

        crc = crcProc.calculate3(revData, revPoly)
        #         print "crcx: {:b} {:b}".format( crc, crcLib )
        self.assertEqual(crc, crcLib)