|
Class: CRCStream
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
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
initialization
-
crcTableFor: generatorPolynomInteger
-
construct the polynom-specific lookup table
usage example(s):
CRC8Stream crcTableFor:(16r1D bitReversed8)
|
-
flushCrcTables
-
CRC16Stream flushCrcTables
CRC32Stream flushCrcTables
instance creation
-
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
|
-
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
|
-
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
|
accessing
-
generatorPolynom
-
answer the generator polynom (LSB)
-
initValue
-
answer the init value
-
xorOut
-
answer the xorOut value
initialization
-
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
-
reset
-
reset the current crc value
queries
-
hashValue
-
return the computed CRC
writing
-
nextPutBytes: count from: anObject startingAt: start
-
add the hash of anObject to the computed hash so far.
|