eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CRC16Stream':

Home

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

Class: CRC16Stream


Inheritance:

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

Package:
stx:libbasic2
Category:
System-Crypt-Hashing
Version:
rev: 1.10 date: 2019/03/25 13:33:27
user: cg
file: CRC16Stream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


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

    ATTENTION: CRC16Stream is currently BROKEN (in development)

    crc16 is a full zoo of different implementations;
    they differ in the polynom, the initial value and the final xor value.
    Also, some return an MSB, others an LSB first value (i.e. byteswapped).
    Make sure to use the correct one:
    
    newCRC_CCITT:
 Standard CRC method as defined by CCITT with FFFF as start value 
 (ITU-T-T30, ITU-T V42, ITU-T X25, RFC1331, RFC1662, ISO/IEC FCD14443-3).
 This is used in data link protocols such as HDLC, SS7, and ISDN.
    
 The polynomial is
   x^16 + x^12 + x^5 + 1

    newCRC_DNP:
 Standard CRC method as defined by DNP.
 This is used in data link protocols such as HDLC, SS7, and ISDN.
 DNP 3.0, or distributed network protocol is a communication protocol 
 designed for use between substation computers, RTUs remote terminal units, 
 IEDs intelligent electronic devices 
 and master stations for the electric utility industry. 
 It is now also used in familiar industries like waste water treatment, 
 transportation and the oil and gas industry.
 The polynomial is 0x3d65

    newKERMIT:
 CRC as used in kermit protocol

    newMODBUS:
 CRC as used in the modbus protocol
 

    [instance variables:]

    [class variables:]


Related information:

    SHA1Stream
    MD5Stream

Class protocol:

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

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

o  generatorPolynomMSB: anInteger initValue: initValueArg xorOut: xorOut
notice, in literature, the generator polynom is usually specified as an MSB number

o  new
return an instance of the CCITT CRC-16

o  newCCITT
return an instance of the CCITT CRC-16 with FFFF as initial value
x16 + x12 + x5 + 1

o  newCCITT_1D0F
return an instance of the CCITT CRC-16 with 1D0F as initial value
x16 + x12 + x5 + 1

o  newCRC_16
return an instance of the CRC-16
x16 + x15 + x2 + 1

o  newDNP
return an instance of the DNP CRC-16
x16 + x13 + x12 + x11 + x10 + x8 + x6 + x5 + x2 + 1

DNP 3.0, or distributed network protocol is a communication protocol
designed for use between substation computers, RTUs remote terminal units,
IEDs intelligent electronic devices
and master stations for the electric utility industry.
It is now also used in familiar industries like waste water treatment,
transportation and the oil and gas industry.

o  newKERMIT
return an instance of the CRC-16 used by kermit
2r11110101100101
x16 + x13 + x12 + x11 + x10 + x8 + x6 + x5 + x2 + 1

o  newMODBUS
return an instance of the MODBUS CRC-16
x16 + x15 + x2 + 1

o  newXMODEM
return an instance of the XMODEM protocol
x16 + x12 + x5 + 1
1 2r0001000000100001

queries
o  hashSize
return the size of the hashvalue returned by instances of this class (in bytes)


Instance protocol:

initialization
o  byteSwapped

o  byteSwapped: aBoolean

o  generatorPolynom: anLSBInteger
set the generator polynom for this instance,
set start and xorOut to 16rFFFF.
Note: you have to set the bit-reversed value, so the LSB must be first

o  generatorPolynom: anLSBInteger initValue: initValueArg
set the generator polynom for this instance.
set start to initValueArg and xorOut to 16rFFFF.
Note: you have to set the bit-reversed value, so the LSB must be first

queries
o  hashValue
return the computed CRC.
For unknown reasons, the standard crc16 needs byte swapping


Examples:


expect xxx:
  self information:(CRC16Stream hashValueOf:'resume') hexPrintString
expect xxx:
  self information:(CRC16Stream new
                          nextPut:$r;
                          nextPut:$e;
                          nextPut:$s;
                          nextPut:$u;
                          nextPut:$m;
                          nextPut:$e;
                          hashValue) hexPrintString
expect xxx:
  self information:(CRC16Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString
expect xxx:
  self information:((CRC16Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
           16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
           16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
           16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
expect xxx: timing throughput:
  |hashStream n t|

  hashStream := CRC16Stream new.
  n := 1000000.
  t := Time millisecondsToRun:[
          n timesRepeat:[
              hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
          ].
       ].
  t := (t / 1000) asFloat.
  Transcript show:'crc16:'; showCR: hashStream hashValue hexPrintString.
  Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
  Transcript show:(n*50/1024 / t); showCR:' Kb/s'


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 19 Sep 2019 08:47:04 GMT