https://github.com/prongbang/lazychacha
Lazy ChaCha20-Poly1305 in golang.
https://github.com/prongbang/lazychacha
chacha20 chacha20-poly1305 lazychacha
Last synced: 6 months ago
JSON representation
Lazy ChaCha20-Poly1305 in golang.
- Host: GitHub
- URL: https://github.com/prongbang/lazychacha
- Owner: prongbang
- License: mit
- Created: 2024-04-18T04:03:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-19T09:53:36.000Z (over 1 year ago)
- Last Synced: 2025-03-25T22:52:06.110Z (7 months ago)
- Topics: chacha20, chacha20-poly1305, lazychacha
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lazychacha
Lazy ChaCha20-Poly1305 in golang on [golang.org/x/crypto](golang.org/x/crypto).
[](https://goreportcard.com/report/github.com/prongbang/lazychacha)
[](https://www.buymeacoffee.com/prongbang)
### Algorithm details
- Key exchange: X25519
- Encryption: ChaCha20
- Authentication: Poly1305### Install
```
go get github.com/prongbang/lazychacha
```### Benchmark
```shell
BenchmarkEncrypt-10 1347146 872.2 ns/op 864 B/op 5 allocs/op
BenchmarkDecrypt-10 2088066 577.9 ns/op 544 B/op 4 allocs/op
```### How to use
- Generate KeyPair
```go
keyPair := lazychacha.NewKeyPair()
```- Key Exchange
```go
clientKp := lazychacha.NewKeyPair()
serverKp := lazychacha.NewKeyPair()serverKx := serverKp.Exchange(clientKp.Pk)
clientKx := clientKp.Exchange(serverKp.Pk)
```- Shared Key
```go
serverSharedKey, _ := serverKx.Secret()
clientSharedKey, _ := clientKx.Secret()
```- Encrypt
```go
lazyChacha := lazychacha.New()
sharedKey, _ := clientKx.Secret()
key, _ := hex.DecodeString(sharedKey)
plaintext := "text"
ciphertext, err := lazyChacha.Encrypt(plaintext, key)
```- Decrypt
```go
lazyChacha := lazychacha.New()
sharedKey, _ := serverKx.Secret()
key, _ := hex.DecodeString(sharedKey)
ciphertext := "f6a1bd8"
plaintext, err := lazyChacha.Decrypt(ciphertext, key)
```