/*1* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the OpenSSL license (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/* From include/crypto/chacha.h */1011#ifndef OSSL_CRYPTO_CHACHA_H12#define OSSL_CRYPTO_CHACHA_H1314/*15* ChaCha20_ctr32 encrypts |len| bytes from |inp| with the given key and16* nonce and writes the result to |out|, which may be equal to |inp|.17* The |key| is not 32 bytes of verbatim key material though, but the18* said material collected into 8 32-bit elements array in host byte19* order. Same approach applies to nonce: the |counter| argument is20* pointer to concatenated nonce and counter values collected into 421* 32-bit elements. This, passing crypto material collected into 32-bit22* elements as opposite to passing verbatim byte vectors, is chosen for23* efficiency in multi-call scenarios.24*/25void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp,26size_t len, const unsigned int key[8],27const unsigned int counter[4]);28/*29* You can notice that there is no key setup procedure. Because it's30* as trivial as collecting bytes into 32-bit elements, it's reckoned31* that below macro is sufficient.32*/33#define CHACHA_U8TOU32(p) ( \34((unsigned int)(p)[0]) | ((unsigned int)(p)[1]<<8) | \35((unsigned int)(p)[2]<<16) | ((unsigned int)(p)[3]<<24) )3637#define CHACHA_KEY_SIZE 3238#define CHACHA_CTR_SIZE 1639#define CHACHA_BLK_SIZE 644041#endif424344