gitlab.com/yawning/chacha20.git@v0.0.0-20230427033715-7877545b1b37/internal/api/api.go (about) 1 // Copryright (C) 2019 Yawning Angel 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 // Package api provides the ChaCha20 implementation abstract interface. 17 package api 18 19 const ( 20 // BlockSize is the size of a ChaCha20 block in bytes. 21 BlockSize = 64 22 23 // StateSize is the size of the ChaCha20 state as 32 bit unsigned words. 24 StateSize = 16 25 26 // HashSize is the size of the HChaCha output in bytes. 27 HashSize = 32 28 29 // HNonceSize is the HChaCha20 nonce size in bytes. 30 HNonceSize = 16 31 32 // Sigma0 is the first word of the ChaCha constant. 33 Sigma0 = uint32(0x61707865) 34 35 // Sigma1 is the second word of the ChaCha constant. 36 Sigma1 = uint32(0x3320646e) 37 38 // Sigma2 is the third word of the ChaCha constant. 39 Sigma2 = uint32(0x79622d32) 40 41 // Sigma3 is the fourth word of the ChaCha constant. 42 Sigma3 = uint32(0x6b206574) 43 ) 44 45 // Implementation is a ChaCha20 implementation 46 type Implementation interface { 47 // Name returns the name of the implementation. 48 Name() string 49 50 // Blocks calculates the ChaCha20 blocks. If src is not nil, dst will 51 // be set to the XOR of src with the key stream, otherwise dst will be 52 // set to the key stream. 53 Blocks(x *[StateSize]uint32, dst, src []byte, nrBlocks int) 54 55 // HChaCha calculates the HChaCha20 hash. 56 // 57 // Note: `dst` is guaranteed to be HashSize bytes. 58 HChaCha(key, nonce []byte, dst []byte) 59 }