Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChaCha20 public domain encryption and decryption in Go

Public domain chacha20.go implements the ChaCha20 encryption and decryption algorithm by D. J. Bernstein. chacha20.go is derived from Bernstein's public domain ref implementation. chacha20.go implements crypto/cipher.Stream and io.Read interfaces. chacha20.go and chacha20_test.go are in the public domain and may be used for any purpose.

This version uses goroutines, yielding 8.7X the speed on a 3.504 GHz 12-processor Mac Studio with M2 Max w/12 processors.

ChaCha20 has been widely adopted.

Example use:

import "github.com/charltoncr/chacha20"
import "crypto/rand"
// ...
var m = []byte("This is a test.") // use a real message here
c := make([]byte, len(m))
key := make([]byte, 32) // 16 is acceptable; 32 is recommended
rand.Read(key)          // use a real key here
iv := make([]byte, 8)   // must be 8  
rand.Read(iv)           // use a real initialization vector here
ctx := chacha20.New(key, iv) // create a chacha20 context
ctx.Encrypt(m, c)       // encrypt m into c
// ...
ctx = chacha20.New(key, iv) // must use same key/iv as encrypt to decrypt
ctx.Decrypt(c, m) // decrypt c back into m
// ...

chacha20.go can also perform as ChaCha8 and ChaCha12 by using SetRounds(8) or SetRounds(12).

About

Public domain ChaCha20 encryption/decryption in Go.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages