x25519

package module
v0.0.0-...-1171696 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 2 Imported by: 0

README

Easy X25519

Go

A simple way to do x25519 key agreements.

Why this?

  • Easy to use
  • Use curve25519.X25519 for multiplication and not other deprecated methods.
  • Small code base
  • Use slices of byte instead of [32]byte

Installing

go get github.com/HirbodBehnam/EasyX25519

Usage

This library has three functions.

  1. NewX25519: Creates a fresh key pair for x25519 key exchange algorithm.
  2. NewX25519FromPrivateKey: Creates a key pair from private key
  3. (*KeyPair) GenerateSharedSecret: Pass the other recipient's public key to this command to generate a shared secret
Documentation

https://pkg.go.dev/github.com/HirbodBehnam/EasyX25519

Example

Here is a small example from test file:

package main

import (
	"github.com/HirbodBehnam/EasyX25519"
	"log"
)

func main() {
	// generate keys
	alice, err := x25519.NewX25519()
	if err != nil{
		log.Fatalf("could not genearte key for alice: %s",err.Error())
	}
	log.Printf("Alice public key %x",alice.PublicKey)
	bob, err := x25519.NewX25519()
	if err != nil{
		log.Fatalf("could not genearte key for bob: %s",err.Error())
	}
	log.Printf("Bob public key %x",bob.PublicKey)
	// calculate secret
	s1, err := alice.GenerateSharedSecret(bob.PublicKey)
	if err != nil{
		log.Fatalf("could not get secret for alice: %s",err.Error())
	}
	s2, err := bob.GenerateSharedSecret(alice.PublicKey)
	if err != nil{
		log.Fatalf("could not get secret for bob: %s",err.Error())
	}
	// check if they match
	log.Printf("Alice secret %x",s1)
	log.Printf("Bob secret %x",s2)
}

Documentation

Overview

A small helper library to make X25519 key agreement algorithm easier

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyPair

type KeyPair struct {
	PublicKey []byte // share this value with anyone you like!
	SecretKey []byte // keep this one secret
}

The structure that holds public key and secret key. Share public key to perform key agreement. Do not share the secret key

func NewX25519

func NewX25519() (*KeyPair, error)

Generates a public key and a secret for key agreement

func NewX25519FromPrivateKey

func NewX25519FromPrivateKey(privateKey []byte) (*KeyPair, error)

Generate a key pair (public key) from private key

func (*KeyPair) GenerateSharedSecret

func (key *KeyPair) GenerateSharedSecret(otherPublicKey []byte) ([]byte, error)

Calculates a shared secret given with the other user's public key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL