Chacha20 is a cipher stream. Its input includes a 256-bit key, a 32-bit counter, a 96-bit nonce and plain text. Its initial state is a 4*4 matrix of 32-bit words. The first row is a constant string “expand 32-byte k,” which is cut into 4*32-bit words. The second and the third are filled with 256-bit key. The first word in the last row are 32-bit counter and the others are 96-bit nonce. It generates 512-bit keystream in each iteration to encrypt a 512-bit block of plain text. When the rest of plain text is less 512 bits after several encryptions, do padding to the left with 0s(MSB) in the last input data and remove the same bits of non-useful data from the last output data. Its encryption and decryption are same as long as input same initial key, counter and nonce.
XChacha20 is a variant of original Chacha20 to support Longer nonce of 192bits. Its implementation is similar to Chacha20.