Code Monkey home page Code Monkey logo

go's Introduction

eciesgo

Go GoDoc Widget Go Report

Elliptic Curve Integrated Encryption Scheme for secp256k1, written in Go with minimal dependencies.

This is the Go version of ecies/py with a built-in class-like secp256k1 API, you may go there for detailed documentation of the mechanism under the hood.

Install

go get github.com/ecies/go/v2

Go 1.13 is required cause fmt.Errorf is used to wrap errors.

โš ๏ธ Please use version 2.0.3 and later. It's much faster and safer.

Quick Start

package main

import (
	ecies "github.com/ecies/go/v2"
	"log"
)

func main() {
	k, err := ecies.GenerateKey()
	if err != nil {
		panic(err)
	}
	log.Println("key pair has been generated")

	ciphertext, err := ecies.Encrypt(k.PublicKey, []byte("THIS IS THE TEST"))
	if err != nil {
		panic(err)
	}
	log.Printf("plaintext encrypted: %v\n", ciphertext)

	plaintext, err := ecies.Decrypt(k, ciphertext)
	if err != nil {
		panic(err)
	}
	log.Printf("ciphertext decrypted: %s\n", string(plaintext))
}

Benchmarks

With CGO:

goos: linux
goarch: amd64
pkg: github.com/ecies/go/v2
cpu: AMD Ryzen 7 5700G with Radeon Graphics         
BenchmarkEncrypt-16        12250             98122 ns/op            5185 B/op         61 allocs/op
BenchmarkDecrypt-16        23934             50046 ns/op            4097 B/op         46 allocs/op

Without CGO:

goos: linux
goarch: amd64
pkg: github.com/ecies/go/v2
cpu: AMD Ryzen 7 5700G with Radeon Graphics         
BenchmarkEncrypt-16        10000            112632 ns/op            5655 B/op         68 allocs/op
BenchmarkDecrypt-16        14038             85641 ns/op            4725 B/op         56 allocs/op

go's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gmaiainc avatar kigawas avatar ostcar avatar savely-krasovsky avatar vilunov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go's Issues

checksum mismatch when go get

go get github.com/ecies/go/v2
go: downloading github.com/ecies/go/v2 v2.0.3
go: github.com/ecies/go/[email protected]: verifying module: checksum mismatch
downloaded: h1:gosZ7+G8LFo0NHPGR7//Lcj7r5gzVRthWl/De3QVay8=
sum.golang.org: h1:rtz3x6uw+if+lt4a39JnCi7M/B35l1JShCXTOBe3LPw=

SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.

For more information, see 'go help module-auth'.

Support for X25519 key exchange and XChacha20 encryption

@kigawas as far as I understand you are preparing this support for py/js/rs libraries. Currently Golang has new crypto/ecdh standard library, but it lacks of rich configuration, I could only add some basic support for x25519 and xchacha20, otherwise I would need to fork stdlib, which will require more maintance.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

go: gopkg.in/[email protected]: invalid version: git fetch -f https://gopkg.in/check.v1 refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /opt/go/gopath/pkg/mod/cache/vcs/9241c28341fcedca6a799ab7a465dd6924dc5d94044cbfabb75778817250adfc: exit status 128:
	error: RPC failed; curl 18 transfer closed with outstanding read data remaining
	fatal: The remote end hung up unexpectedly
	fatal: early EOF
	fatal: index-pack failed

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Random production of corrupt ciphertext

The package appears to have a bug where it will randomly produce a ciphertext it cannot decipher. This is easily reproducible with the following Go program, largely based on the example in the Readme:

package main

import (
	"log"

	ecies "github.com/ecies/go/v2"
)

func main() {
	k, err := ecies.GenerateKey()
	if err != nil {
		panic(err)
	}
	log.Println("key pair has been generated")

	for {
		ciphertext, err := ecies.Encrypt(k.PublicKey, []byte("THIS IS THE TEST"))
		if err != nil {
			panic(err)
		}

		_, err = ecies.Decrypt(k, ciphertext)
		if err != nil {
			panic(err)
		}
	}
}

The expectation is that this program loops forever, however, what actually happens is that after a certain number of iterations (usually in the order of a few thousand), Decrypt will fail with an error: "invalid public key". This is because the Encrypt function is rarely producing a ciphertext that does not appear to be valid.

How to load key generate by openssl?

Hello, I'm using github.com/ecies/go/v2 v2.0.7, try to load a public key by openssl , and got the follow error:

panic: cannot parse public key                       
                                                     
goroutine 1 [running]:                               
main.main()               

the ecc public key is generate by the follow:

openssl version
OpenSSL 1.1.1n  15 Mar 2022

 openssl ecparam -genkey -name secp256k1 -out ecc_private_key.pem
 openssl ec -in ecc_private_key.pem -pubout -out ecc_public_key.pem

test go file:

package main

import (
	"encoding/pem"
	ecies "github.com/ecies/go/v2"
	"log"
)

func main() {
	pubStr := `
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEvO6PRdLyD0EaRkFkfCeptcpey/P3ziHS
cbLbD96xg22JOvC3YYVtzyp4nVEyz+a07tonu3/pfEMstSiil1mEiw==
-----END PUBLIC KEY-----
	`
	block, _ := pem.Decode([]byte(pubStr))

	pub, err := ecies.NewPublicKeyFromBytes(block.Bytes)
	if err != nil {
		panic(err)
	}
	log.Println(pub)

}

Testing ECIES interoperability

Hi guys,

Just sharing one thing you might enjoy, I hope. ๐Ÿ˜„
I am doing simplistic testing for ECIES encrypt/decrypt among some Go implementations.
So far, it seems each implementation only interoperates with itself. See below.
"ecies_go" is package github.com/ecies/go.

go test | grep good
    main_test.go:96: key=key1(secp256r1) text=text1 src= ethereum dst= ethereum good
    main_test.go:96: key=key1(secp256r1) text=text1 src= ethereum dst= obscuren good
    main_test.go:96: key=key1(secp256r1) text=text1 src=    havir dst=    havir good
    main_test.go:96: key=key1(secp256r1) text=text1 src= obscuren dst= ethereum good
    main_test.go:96: key=key1(secp256r1) text=text1 src= obscuren dst= obscuren good
    main_test.go:96: key=key2(secp256k1) text=text1 src=  bitcoin dst=  bitcoin good
    main_test.go:96: key=key2(secp256k1) text=text1 src=sghcrypto dst=sghcrypto good
    main_test.go:96: key=key2(secp256k1) text=text1 src= ecies_go dst= ecies_go good
    main_test.go:96: key=key2(secp256k1) text=text1 src=    btcec dst=    btcec good

If you want, you can find full test code here: https://github.com/udhos/ecies-go-test/blob/master/main_test.go

My cryptographic knowledge is close to zero, so please bear with me.
Are distinct ECIES implementations supposed to talk to each other?
What do you think?

Thanks,
Everton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.