#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    51
    Rep Power
    56

    HBSC - Hash Based Stream Cipher Algorithm


    Below you can find a short description of a fast cipher algorithm based
    on a secure hash function, in this case on md5.

    The algorithm has a huge internal state, which might prevent it from a
    use on FPGA, but in software it's quite easy to implement.

    It make use of fast, reliable, existing secure hash and key derivation
    functions, which are already part of any good OS.

    It is fast, easy to memorise, easy to understand and should minimise any
    implementation error.

    The keystream output can be 128 bit, 256 bit, 384 bit or any other
    desired bit size by simply changing the hash function from md5 to
    sha256 for example.

    Below some obligatory test results (of course *NO* indication about the
    security of the algorithm).

    A full functional quick and dirty Python source code hack can be found
    here http://www.freecx.co.uk/HBSC/HBSC_md5_STDIO.py

    Cheers,
    Karl-Uwe



    Code:
    HBSC (Hash Based Stream Cipher) 
    ===============================
    
    aH[]        256 * 128 Bit Array of Hash Values
    
    counter     32 or 64 Bit integer value
    
    seq_idx     1 Byte sequential index pointer
    
    rnd_idx     1 Byte pseudo-random index pointer
    
    KDF_Rounds  PBKDF2 Iteration Count
    
    dkLen       Derived Key Length in Byte
     
    Keystream   128 Bit Return Value from PRGA
    
    ||          Concatenating Strings
    
    
    
    KSA (Key Schedule Algorithm)
      aH[0] = PBKDF2_md5(Keyword, IV, KDF_Rounds, dkLen)
      for i=1 to 255
        aH[i] = HMAC_md5(Keyword, IV || aH[i-1])
      next
    
    
    PRGA (Pseudo Random Generation Algorithm)
      counter     = counter +1
      seq_idx     = seq_idx +1 mod256
      rnd_idx     = first Byte of aH[seq_idx]
      Keystream   = md5(aH[seq_idx] || md5(aH[rnd_idx] || counter))
      aH[seq_idx] = md5(aH[seq_idx] || aH[rnd_idx])
      return Keystream



    #################################################


    dd if=/dev/zero bs=1024 count=10240 | pypy HBSC_md5_STDIO.py 13a775db820bac43e01fe6557ccbe3cd 7d0ef66789aca2cfa6c76db7560554 | ./ent

    Entropy = 7.999983 bits per byte.

    Optimum compression would reduce the size
    of this 10485760 byte file by 0 percent.

    Chi square distribution for 10485760 samples is 253.99, and randomly
    would exceed this value 50.60 percent of the times.

    Arithmetic mean value of data bytes is 127.5144 (127.5 = random).
    Monte Carlo value for Pi is 3.140358406 (error 0.04 percent).
    Serial correlation coefficient is 0.000004 (totally uncorrelated = 0.0).


    dd if=/dev/zero bs=1024 count=10240 | pypy HBSC_md5_STDIO.py 7d0ef66789aca2cfa6c76db7560554 358b4eff55cfe21051d2f03afaeccb19 | ./ent

    Entropy = 7.999983 bits per byte.

    Optimum compression would reduce the size
    of this 10485760 byte file by 0 percent.

    Chi square distribution for 10485760 samples is 248.71, and randomly
    would exceed this value 59.93 percent of the times.

    Arithmetic mean value of data bytes is 127.4999 (127.5 = random).
    Monte Carlo value for Pi is 3.143381936 (error 0.06 percent).
    Serial correlation coefficient is -0.000163 (totally uncorrelated = 0.0).



    dd if=/dev/zero bs=1024 count=102400 | pypy HBSC_md5_STDIO.py 13a775db820bac43e01fe6557ccbe3cd 7d0ef66789aca2cfa6c76db7560554 | ./ent
    102400+0 records in
    102400+0 records out
    104857600 bytes transferred in 118.016843 secs (888497 bytes/sec)
    Entropy = 7.999998 bits per byte.

    Optimum compression would reduce the size
    of this 104857600 byte file by 0 percent.

    Chi square distribution for 104857600 samples is 280.42, and randomly
    would exceed this value 13.15 percent of the times.

    Arithmetic mean value of data bytes is 127.5111 (127.5 = random).
    Monte Carlo value for Pi is 3.141039854 (error 0.02 percent).
    Serial correlation coefficient is 0.000131 (totally uncorrelated = 0.0).


    EDIT: "i" against "KDF_Rounds" at the KSA description
    Last edited by Karl-Uwe Frank; August 23rd, 2013 at 04:30 PM.

IMN logo majestic logo threadwatch logo seochat tools logo