mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-11-01 18:04:12 +08:00
ChaCha20 implementation for encryption
Add an implementation in 8051 assembler for the generation of a ChaCha20 keystream and an encryption function using the keystream in C. A test function using the example from RFC7539 is provided in chacha20_test. Keys, nonce, and block counter and the pointers to the input plaintext, its length and the output pointer are provided via a struct chacha20, which also holds the working state of the ChaCha20 algorithm
This commit is contained in:
1 parent
3b90e85593
commit
bd84a542ff
4 files changed
+595
-2
No files matched your search
@@ -0,0 +1,28 @@
|
||||
#ifndef _CHACHA_H_
|
||||
#define _CHACHA_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// In order to test, CHACHA20_TEST needs to be defined
|
||||
// #define CHACHA20_TEST
|
||||
|
||||
struct chacha20_t {
|
||||
uint8_t wstate[64]; // 64 bytes written here
|
||||
uint8_t constant[16]; // 128 bit constant (4 Big-Endian u32)
|
||||
uint8_t key[32]; // 256-bit secret key (8 Big-Endian u32)
|
||||
uint8_t cnt[4]; // 32-bit block counter 1, 2.. Big Endian!
|
||||
uint8_t nonce[12]; // 96-bit nonce (3 Big-Endian u32)
|
||||
__xdata uint8_t *plaintext;
|
||||
uint16_t length;
|
||||
__xdata uint8_t *cyphertext;
|
||||
};
|
||||
|
||||
// Encrypt a plaintext with ChaCha20 as per RFC7539
|
||||
void chacha20_encrypt(void) __banked;
|
||||
|
||||
#ifdef CHACHA20_TEST
|
||||
// Test ChaCha20 using the example from RFC7539
|
||||
void chacha20_test(void) __banked;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user