Skip to content

ChaCha20 implementation for encryption#207

Open
logicog wants to merge 1 commit into
mainfrom
chacha20
Open

ChaCha20 implementation for encryption#207
logicog wants to merge 1 commit into
mainfrom
chacha20

Conversation

@logicog
Copy link
Copy Markdown
Owner

@logicog logicog commented Apr 26, 2026

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.

ChaCha20 can be used together with Poly1305 in the Authenticated Encryption with Associated Data (AEAD) implementation CHACHA20POLY1305, which is used e.g. in Wireguard and in TLS, which both Firefox and Chrome support it. In a next step, Poly1305 will be implemented, an 8-bit implementation exists. The final step for use in Wireguard/TLS, will require an implementation for DiffieHellman key exchange using Curve25519, for which an 8-bit microcontroller implementation also exists.

To test, call chacha20_test() in rtlplayground.c

The output will be:

>
Encrypting...
Cypertext:
6e 2e 35 9a 25 68 f9 80 41 ba 07 28 dd 0d 69 81 e9 7e 7a ec 1d 43 60 c2 0a 27 af cc fd 9f ae 0b f9 1b 65 c5 52 47 33 ab 8f 59 3d ab cd 62 b3 57 16 39 d6 24 e6 51 52 ab 8f 53 0c 35 9f 08 61 d8 07 ca 0d bf 50 0d 6a 61 56 a3 8e 08 8a 22 b6 5e 52 bc 51 4d 16 cc f8 06 81 8c e9 1a b7 79 37 36 5a f9 0b bf 74 a3 5b e6 b4 0b 8e ed f2 78 5e 42 87 4d 

Currently, no applications are provided, but the code could be used to encrypt e.g. the password.

@logicog logicog requested review from feelfree69, ranma and vDorst April 26, 2026 08:27
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant