Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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)