microsoft / go-crypto-openssl Goto Github PK
View Code? Open in Web Editor NEWGo crypto backend for Linux using OpenSSL
License: MIT License
Go crypto backend for Linux using OpenSSL
License: MIT License
My code panic when I try to use the library but I don't know how to fix it. Can someone help?
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/thanhpp/go/bin"
GOCACHE="/home/thanhpp/.cache/go-build"
GOENV="/home/thanhpp/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/thanhpp/go/pkg/mod"
GONOPROXY="github.com/KyberNetwork,github.com/nri4nudge"
GONOSUMDB="github.com/KyberNetwork,github.com/nri4nudge"
GOOS="linux"
GOPATH="/home/thanhpp/go"
GOPROXY="proxy.golang.org,sum.golang.org,index.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build820668886=/tmp/go-build -gno-record-gcc-switches"
$ openssl version
OpenSSL 3.1.1 30 May 2023 (Library: OpenSSL 3.1.1 30 May 2023)
package main
import (
"fmt"
"github.com/microsoft/go-crypto-openssl/openssl"
)
func main() {
fmt.Println(openssl.SHA1([]byte("abc")))
}
$ go run .
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]
runtime stack:
runtime.throw({0x4ad78a?, 0xffffffffffffffb8?})
/usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7ffdd49b7500 sp=0x7ffdd49b74d0 pc=0x437f7d
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:825 +0x3e9 fp=0x7ffdd49b7560 sp=0x7ffdd49b7500 pc=0x44ca69
goroutine 1 [syscall]:
runtime.cgocall(0x48a910, 0xc000060ed0)
/usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc000060ea8 sp=0xc000060e70 pc=0x40a15c
github.com/microsoft/go-crypto-openssl/openssl._Cfunc_go_openssl_EVP_sha1()
_cgo_gotypes.go:1519 +0x49 fp=0xc000060ed0 sp=0xc000060ea8 pc=0x4891c9
github.com/microsoft/go-crypto-openssl/openssl.SHA1({0xc000060f49, 0x3, 0x3})
/home/thanhpp/go/pkg/mod/github.com/microsoft/[email protected]/openssl/sha.go:36 +0x38 fp=0xc000060f18 sp=0xc000060ed0 pc=0x489598
main.main()
/home/thanhpp/go/src/test-microsoft-openssl/main.go:10 +0x36 fp=0xc000060f80 sp=0xc000060f18 pc=0x489836
runtime.main()
/usr/local/go/src/runtime/proc.go:250 +0x207 fp=0xc000060fe0 sp=0xc000060f80 pc=0x43a8a7
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000060fe8 sp=0xc000060fe0 pc=0x465141
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000052fb0 sp=0xc000052f90 pc=0x43acd6
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:387
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:305 +0xb0 fp=0xc000052fe0 sp=0xc000052fb0 pc=0x43ab10
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000052fe8 sp=0xc000052fe0 pc=0x465141
created by runtime.init.6
/usr/local/go/src/runtime/proc.go:293 +0x25
goroutine 18 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc00004e780 sp=0xc00004e760 pc=0x43acd6
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:387
runtime.bgsweep(0x0?)
/usr/local/go/src/runtime/mgcsweep.go:278 +0x8e fp=0xc00004e7c8 sp=0xc00004e780 pc=0x42796e
runtime.gcenable.func1()
/usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc00004e7e0 sp=0xc00004e7c8 pc=0x41ce26
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00004e7e8 sp=0xc00004e7e0 pc=0x465141
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:178 +0x6b
goroutine 19 [GC scavenge wait]:
runtime.gopark(0xc000096000?, 0x4c3fd0?, 0x1?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc00004ef70 sp=0xc00004ef50 pc=0x43acd6
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:387
runtime.(*scavengerState).park(0x542bc0)
/usr/local/go/src/runtime/mgcscavenge.go:400 +0x53 fp=0xc00004efa0 sp=0xc00004ef70 pc=0x425893
runtime.bgscavenge(0x0?)
/usr/local/go/src/runtime/mgcscavenge.go:628 +0x45 fp=0xc00004efc8 sp=0xc00004efa0 pc=0x425e65
runtime.gcenable.func2()
/usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc00004efe0 sp=0xc00004efc8 pc=0x41cdc6
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00004efe8 sp=0xc00004efe0 pc=0x465141
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:179 +0xaa
goroutine 20 [finalizer wait]:
runtime.gopark(0x1a0?, 0x543000?, 0x20?, 0xa8?, 0xc000052770?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000052628 sp=0xc000052608 pc=0x43acd6
runtime.runfinq()
/usr/local/go/src/runtime/mfinal.go:193 +0x107 fp=0xc0000527e0 sp=0xc000052628 pc=0x41be67
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000527e8 sp=0xc0000527e0 pc=0x465141
created by runtime.createfing
/usr/local/go/src/runtime/mfinal.go:163 +0x45
exit status 2
openssl provides sha3-384 implementation.
when available please expose sha3-384 implementation.
This is to gain access to a FIPS certified SHA3 implementation instead of golang.org/x/crypto/sha3
ideally as a drop in replacement for golang.org/x/crypto/sha3
The "EVP_PKEY_decrypt/encrypt failed" error is returned on error in cryptEVP and verifyEVP functions. The operation is not encrypt/decrypt, but signature verification.
Similarly, the cryptEVP function returns the same error when called by the evpSign function and fails. The failure is in signature generation, not in encrypt/decrypt.
File: openssl/evpkey.go
Right now, the repo has a v0.1
branch, and v0.1.0
+ v0.1.1
tags.
In my experience, I've only seen v
prefixes before tags, and it's sometimes been a useful way to differentiate tags from branches. It's certainly valid to have v0.1
as a branch, just not something I've seen before.
In .NET land, the norm is e.g. release/6.0
and v6.0.1
. I've also seen a bare version: 0.1
with v0.1.1
tag.
I'm curious if this naming style has history behind it, maybe in the Go ecosystem in particular?
(Figured we might as well discuss this on a GitHub issue for posterity. ๐)
@qmuntal @microsoft/golang-compiler
I am trying to use the library in my project, the folder structure looks roughly like this:
crypto/
โโโ main.go
โโโ go-crypto-openssl
โโโ ....h
โโโ ....c
โโโ ....go
โโโ ...._test.go
When trying to run tests from inside the library package, everything works fine, but when i try to build from inside my project and execute it, it fails with a SIGSEG
.
I tried to see what's going on with gdb, it looks like i am missing the cgo types definitions for some reason:
(r1=<optimized out>) at _cgo_gotypes.go:1018
1018 _cgo_gotypes.go: No such file or directory.
Any idea on how to resolve this? (i am not that familiar with the workings of cgo)
Hi, I have encountered this error: "go list failed to return CompiledGoFiles. This may indicate failure to perform cgo processing; try building at the command line. See https://golang.org/issue/38990." after I installed the package locally.
go env
set GO111MODULE=on
set GOENV=C:\Users\USERNAME\AppData\Roaming\go\env
set GOPATH=C:\Users\USERNAME\go
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOVERSION=go1.19.2
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\USERNAME\go\pkg\mod\github.com\microsoft\[email protected]\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-
go list -json -compiled -e
{
"Dir": "C:\\Users\\USERNAME\\go\\pkg\\mod\\github.com\\microsoft\\[email protected]\\openssl",
"ImportPath": "github.com/microsoft/go-crypto-openssl/openssl",
"Name": "openssl",
"Root": "C:\\Users\\USERNAME\\go\\pkg\\mod\\github.com\\microsoft\\[email protected]",
"Module": {
"Path": "github.com/microsoft/go-crypto-openssl",
"Main": true,
"Dir": "C:\\Users\\USERNAME\\go\\pkg\\mod\\github.com\\microsoft\\[email protected]",
"GoMod": "C:\\Users\\USERNAME\\go\\pkg\\mod\\github.com\\microsoft\\[email protected]\\go.mod",
"GoVersion": "1.16"
},
"Match": [
"."
],
"Stale": true,
"StaleReason": "not installed but available in build cache",
"GoFiles": [
"big.go"
],
"CompiledGoFiles": [
"big.go"
],
"IgnoredGoFiles": [
"aes.go",
"aes_test.go",
"ecdh.go",
"ecdh_test.go",
"ecdsa.go",
"ecdsa_test.go",
"evpkey.go",
"openssl_funcs.h"
]
}
{
// "go.buildFlags": ["-tags=linux,!android"],
"gopls": {
"build.experimentalWorkspaceModule": true,
"build.allowModfileModifications": true
}
}
It seems to ignore those files with C imported, so basically the only file that is successfully compiled is big.go, and this made my code that uses this package not able to recognize functions/identifiers in those cgo files. For example, it can only understand openssl.BigInt
because this is the only thing that is compiled. All other requests, such as openssl.NewAESCipher
, will have error similar to this shown: "undefined: openssl.NewAESCipher" with yellow squiggly lines "NewAESCipher not declared by package openssl (compile)"
Is there something wrong with my gopls settings, or is it an issue with go version (go.mod indicates 1.16 yet go version is 1.19)? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.