chacha20 - 2023.1 English

Vitis Libraries

Release Date
2023-12-20
Version
2023.1 English
#include "xf_security/chacha20.hpp"
void chacha20 (
    hls::stream <ap_uint <256>>& keyStrm,
    hls::stream <ap_uint <128>>& counterNonceStrm,
    hls::stream <ap_uint <512>>& plainStrm,
    hls::stream <bool>& ePlainStrm,
    hls::stream <ap_uint <512>>& cipherStrm,
    hls::stream <bool>& eCipherStrm
    )

chahcha20 is a basic function for stream ciphering when key is “keylayout-chacha”, its layout in a 256-bit ap_uint<> likes this,

0 - 7 bit: ‘k’ 8 - 15 bit: ‘e’ 16 - 23 bit: ‘y’ 24 - 31 bit: ‘l’ … 232- 239 bit: ‘c’ 240- 247 bit: ‘h’ 248- 255 bit: ‘a’

state matrix: s[0] s[1] s[2] s[3] s[4] s[5] s[6] s[7] s[8] s[9] s[10] s[11] s[12] s[13] s[14] s[15]

128bits counterNonceStrm = counter 32 bits + nonce 96 bits the layout of the data from counteStrm 0-31 bit: counter s[12] 32-63 bit: nonce1 s[13] 64-95 bit: nonce2 s[14] 96-127 bit: nonce3 s[15]

Parameters:

keyStrm initail key
counterNonceStm initial counter and nonce
plainStrm input plain text to be encrypted
ePlainStrm the end flag of plainStrm
cipherStrm output encrypted text
eCipherStrm the end flag of cipherStrm