Skip to content

prongbang/lazyxchacha

Repository files navigation

lazyxchacha

Lazy XChaCha20-Poly1305 in golang base on golang.org/x/crypto.

Go Report Card

"Buy Me A Coffee"

Algorithm details

  • Key exchange: X25519
  • Encryption: XChaCha20
  • Authentication: Poly1305

Install

go get github.com/prongbang/lazyxchacha

Benchmark

BenchmarkEncrypt-10    	 1220955	       984.5 ns/op	     944 B/op	       5 allocs/op
BenchmarkDecrypt-10    	 1717482	       696.1 ns/op	     576 B/op	       4 allocs/op

How to use

  • Generate KeyPair
keyPair := lazyxchacha.NewKeyPair()
  • Key Exchange
// Generate KeyPair
clientKp := lazyxchacha.NewKeyPair()
serverKp := lazyxchacha.NewKeyPair()

serverKx := serverKp.Exchange(clientKp.Pk)
clientKx := clientKp.Exchange(serverKp.Pk)
  • Shared Key
serverSharedKey, _ := serverKx.Secret()
clientSharedKey, _ := clientKx.Secret()
  • Encrypt
lazyXchacha := lazyxchacha.New()
sharedKey, _ := clientKx.Secret()
key, _ := hex.DecodeString(sharedKey)
plaintext := "text"
ciphertext, err := lazyXchacha.Encrypt(plaintext, key)
  • Decrypt
lazyXchacha := lazyxchacha.New()
sharedKey, _ := serverKx.Secret()
key, _ := hex.DecodeString(sharedKey)
ciphertext := "f6a1bd8"
plaintext, err := lazyXchacha.Decrypt(ciphertext, key)