Skip to content

wedkarz02/chacha20

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChaCha20

Go Reference Go Report Card GitHub release (with filter) GitHub

Go implementation of the ChaCha20 cipher algorithm.
It was coded referencing RFC8439 and tested with it's test vectors.
Current release provides access to unverified encryption and decryption only. AEAD implemented with the Poly1305 MAC algorithm is planned for future releases.

As always, I do not recommend using this package for anything that needs actual security.

Requirements

Quick Setup

If you haven't created a go module for your project, you can do that with the go mod command:

$ go mod init [project name]

To include this package in your project use the go get command:

$ go get -u github.com/wedkarz02/chacha20

Example

// main.go
package main

import (
    "fmt"
    "log"

    "github.com/wedkarz02/chacha20"
)

func main() {
    key := []byte("Super secret key")
    message := []byte("ChaCha20 encryption is really cool and also fast!")

    // Cipher object initialization.
    cipher, err := chacha20.NewCipher(key)

    // It is strongly recommended to wipe the key from memory at the end.
    defer cipher.ClearKey()

    // Make sure to check for any errors.
    if err != nil {
        log.Fatalf("Cipher init error: %v\n", err)
    }

    // Encrypting the plainText.
    cipherText, err := cipher.Encrypt(message)

    // Make sure to check for any errors.
    if err != nil {
        log.Fatalf("Encryption error: %v\n", err)
    }

    // Printing the cipherText as bytes.
    for _, b := range cipherText {
        fmt.Printf("0x%02x ", b)
    }
}

You might also need to use the go mod tidy command to fetch necessary dependencies:

$ go mod tidy

For more examples, see chacha20/examples.

Testing

To test this package use the go test command from the root directory:

$ go test -v

Documentation

For more documentation, see pkg.go.dev.

License

chacha20 is available under the MIT license. See the LICENSE file for more info.

About

Go package for ChaCha20 encryption and decryption.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages