eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CRCStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: CRCStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--HashStream
         |
         +--CRCStream
            |
            +--CRC16Stream
            |
            +--CRC32Stream
            |
            +--CRC8Stream

Package:
stx:libbasic2
Category:
System-Crypt-Hashing
Version:
rev: 1.13 date: 2019/06/06 21:17:07
user: cg
file: CRCStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


abstract superclass of crc streams;
refactored from original crc32 stream.
For details, see https://en.wikipedia.org/wiki/Cyclic_redundancy_check

Only use CRC to protect against communication errors;
DO NOT use CRC for cryptography, authentication, security, etc.
- use secure hashes for those instead.

[parameters:] 
    polynomials:
        CRC_POLY_16             0xA001
        CRC_POLY_32             0xEDB88320L
        CRC_POLY_CCITT          0x1021
        CRC_POLY_DNP            0xA6BC
        CRC_POLY_KERMIT         0x8408

    start values:
        CRC_START_8             0x00
        CRC_START_16            0x0000
        CRC_START_MODBUS        0xFFFF
        CRC_START_XMODEM        0x0000
        CRC_START_CCITT_1D0F    0x1D0F
        CRC_START_CCITT_FFFF    0xFFFF
        CRC_START_KERMIT        0x0000
        CRC_START_SICK          0x0000
        CRC_START_DNP           0x0000
        CRC_START_32            0xFFFFFFFF


Class protocol:

initialization
o  crcTableFor: generatorPolynomInteger
construct the polynom-specific lookup table

usage example(s):

CRC8Stream crcTableFor:(16r1D bitReversed8)

o  flushCrcTables
CRC16Stream flushCrcTables
CRC32Stream flushCrcTables

instance creation
o  generatorPolynom: anLSBInteger
notice, in literature, the generator polynom is usually specified as an MSB number

usage example(s):

       self assert:((self generatorPolynom:16r82F63B78)
                                nextPut:'123456789';
                                hashValue)    = 16rE3069283

o  generatorPolynom: anLSBInteger initValue: initValue
notice, in literature, the generator polynom is usually specified as an MSB number

usage example(s):

       self assert:((self generatorPolynom:16r82F63B78)
                                nextPut:'123456789';
                                hashValue)    = 16rE3069283

o  generatorPolynom: anLSBInteger initValue: initValue xorOut: xorOut
notice, in literature, the generator polynom is usually specified as an MSB number

usage example(s):

       self assert:((self generatorPolynom:16r82F63B78)
                                nextPut:'123456789';
                                hashValue)    = 16rE3069283


Instance protocol:

accessing
o  generatorPolynom
answer the generator polynom (LSB)

o  initValue
answer the init value

o  xorOut
answer the xorOut value

initialization
o  generatorPolynom: polyLSB initValue: initValueArg xorOut: xorOutArg
set the generator polynom for this instance.
And set start and xorOut.
Computes the crcTable for this polynom.
Notice the bit order is LSB

o  reset
reset the current crc value

queries
o  hashValue
return the computed CRC

writing
o  nextPutBytes: count from: anObject startingAt: start
add the hash of anObject to the computed hash so far.



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 20 Sep 2019 03:42:37 GMT