8000 GitHub - x13a/go-charm: Charm implementation in Go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

x13a/go-charm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-charm

A tiny, self-contained cryptography library, implementing authenticated encryption and keyed hashing.

This is a port to Go. It has to be fully compatible with the C, Zig and JavaScript (TypeScript) versions.

Install

go get -u "github.com/x13a/go-charm"

Usage

package main

import (
	"crypto/rand"
	"fmt"
	
	"github.com/x13a/go-charm"
)

func randomBytes(buf []byte) error {
	_, err := rand.Read(buf)
	return err
}

func main() {
	msg := []byte("Hello, World!")

	var c *charm.Charm
	var err error
	
	key := make([]byte, charm.KeyLength)
	err = randomBytes(key)
	if err != nil {
		panic(err)
	}

	// Nonce is optional
	nonce := make([]byte, charm.NonceLength)
	err = randomBytes(nonce)
	if err != nil {
		panic(err)
	}
	
	// Encrypt
	c, err = charm.NewCharm(key, nonce)
	if err != nil {
		panic(err)
	}
	tag := c.Encrypt(msg)
	
	// Decrypt
	c, err = charm.NewCharm(key, nonce)
	if err != nil {
		panic(err)
	}
	err = c.Decrypt(msg, tag)
	if err != nil {
		panic(err)
	}

	// Hash
	c, err = charm.NewCharm(key, nonce)
	if err != nil {
		panic(err)
	}
	hash := c.Hash(msg)
	fmt.Printf("%x\n", hash)
}

Other implementations

  • charm original implementation in C
  • zig-charm an implementation of Charm in the Zig language
  • charm.js an implementation of Charm in the JavaScript (TypeScript) language

License

MIT

About

Charm implementation in Go

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Languages

0