Skip to content

Commit 84252ae

Browse files
authored
Merge pull request #44 from onflow/tarak/go1.26-cgo-only
Go 1.26 support
2 parents b566d9b + 28f8bca commit 84252ae

109 files changed

Lines changed: 5978 additions & 11033 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,16 @@ jobs:
3434
cache: true
3535
- name: run Go tidy
3636
run: make go-tidy
37-
- name: Run golangci-lint with cgo
37+
- name: Run golangci-lint
3838
env:
3939
CGO_ENABLED: 1
4040
uses: golangci/golangci-lint-action@v8
4141
with:
4242
version: ${{ env.LINT_VERSION }}
4343
# https://github.com/golangci/golangci-lint-action/issues/244
4444
skip-cache: true
45-
- name: Run golangci-lint without cgo
46-
env:
47-
CGO_ENABLED: 0
48-
uses: golangci/golangci-lint-action@v8
49-
with:
50-
version: ${{ env.LINT_VERSION }}
51-
args: --build-tags no_cgo
52-
# https://github.com/golangci/golangci-lint-action/issues/244
53-
skip-cache: true
5445
- name: Run Go Fix
5546
run: make go-fix
56-
- name: Run incorrect builds
57-
run: |
58-
echo "::remove-matcher owner=go::"
59-
make incorrect_builds
6047

6148
c-code:
6249
strategy:

.golangci.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ linters:
1010
- linters:
1111
- govet
1212
text: "unsafeptr" # disable flagging unsafeptr usage
13-
# ecdsa.go wraps crypto/ecdsa, whose Sign/Verify still consume the raw
14-
# PrivateKey.D and PublicKey.X/Y fields.
15-
# Go 1.26 deprecated direct access to those fields, but the recommended
16-
# replacement API (ecdsa.ParseRawPrivateKey / ParseUncompressedPublicKey /
17-
# (*PrivateKey).Bytes / (*PublicKey).Bytes) supports only the NIST curves and
18-
# rejects secp256k1, which this package supports via btcec's custom
19-
# elliptic.Curve, so the package has to keep using the low-level fields.
20-
- path: (^|/)ecdsa(_test)?\.go$
21-
linters:
22-
- staticcheck
23-
text: "SA1019"
2413
formatters:
2514
exclusions:
2615
paths:

Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,7 @@ go-lint: go-tidy go-fix
9696
test:
9797
# root package
9898
CGO_ENABLED=1 CGO_CFLAGS=$(ADX_FLAG) go test -coverprofile=$(COVER_PROFILE) $(RACE_FLAG) $(if $(JSON_OUTPUT),-json,) $(if $(VERBOSE),-v,)
99-
#root package without cgo
100-
CGO_ENABLED=0 go test -tags=no_cgo -coverprofile=$(COVER_PROFILE) $(RACE_FLAG) $(if $(JSON_OUTPUT),-json,) $(if $(VERBOSE),-v,)
10199
# sub packages
102100
go test -coverprofile=$(COVER_PROFILE) $(RACE_FLAG) $(if $(JSON_OUTPUT),-json,) $(if $(VERBOSE),-v,) ./hash
103101
go test -coverprofile=$(COVER_PROFILE) $(RACE_FLAG) $(if $(JSON_OUTPUT),-json,) $(if $(VERBOSE),-v,) ./random
104102

105-
# test incorrect builds and make sure they fail
106-
.PHONY: incorrect_builds
107-
incorrect_builds:
108-
# both tests should fail
109-
! CGO_ENABLED=0 go test
110-
! CGO_ENABLED=1 CGO_CFLAGS=$(ADX_FLAG) go test -tags=no_cgo

README.md

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ import "github.com/onflow/crypto"
2929

3030
Building your project with Flow crypto and enabling all the supported algorithms requires using cgo to compile the C code underneath.
3131
If cgo isn't enabled by default, the `CGO_ENABLED` environment variable should be set to `1`.
32-
It is also possible to build without cgo (`CGO_ENABLED=0`) but this would disable some primitives (the ones related to BLS).
33-
34-
### Build with cgo
35-
36-
Building with cgo is required to support all the algorithms of the module, including the algorithms based on the BLS12-381 curve.
3732

3833
If the test or target application crashes with a "Caught SIGILL" exception, rebuild with `CGO_CFLAGS` set to `"-O2 -D__BLST_PORTABLE__"` to disable non-portable code.
3934
The runtime error can happen if the CPU doesn't support certain instructions.
@@ -53,19 +48,6 @@ GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 go build
5348

5449
When using the `go mod vendor` command in your project, [a known issue](https://github.com/golang/go/issues/26366) with the Go vendoring tool prevents cgo dependencies from being copied into your vendor directory. This results in build errors related to the Flow crypto package. External vendoring tools that do copy the entire package files can be used instead of the Go command to resolve the issue.
5550

56-
57-
### Build without cgo
58-
59-
It is possible to build without cgo but this requires disabling all primitives based on the BLS12-381 curve (BLS signature, BLS threshold signature, BLS-based DKG, BLS-based SPoCK).
60-
Refer to [algorithms](#algorithms) and [protocols](#protocols) to check the supported features.
61-
Calling any of the non-supported primitives would panic.
62-
In order to avoid accidental builds that result in unwanted crashes, disabling cgo must be confirmed with the `no_cgo` build tag.
63-
64-
```
65-
CGO_ENABLED=0 go build -tags=no_cgo
66-
```
67-
68-
6951
## Algorithms
7052

7153
### Hashing and MAC:
@@ -83,10 +65,10 @@ All signature schemes use the generic interfaces of `PrivateKey` and `PublicKey`
8365

8466
* ECDSA
8567
* public keys are compressed or uncompressed.
86-
* ephemeral key is derived from the private key, hash and the system entropy (based on https://golang.org/pkg/crypto/ecdsa/).
8768
* supports NIST P-256 (secp256r1) and secp256k1 curves.
69+
* For NIST P-256, ephemeral key is derived from the private key, hash and the system entropy (based on https://golang.org/pkg/crypto/ecdsa/). For secp256k1, ephemeral key is deterministically formed following RFC 6979 (based on github.com/ethereum/go-ethereum/crypto/secp256k1)
8870

89-
* BLS (requires cgo)
71+
* BLS
9072
* supports [BLS12-381](https://electriccoin.co/blog/new-snark-curve/) curve.
9173
* is implementing the minimal-signature-size variant:
9274
signatures in G1 and public keys in G2.
@@ -114,7 +96,7 @@ All signature schemes use the generic interfaces of `PrivateKey` and `PublicKey`
11496

11597
### Threshold Signature
11698

117-
* BLS-based threshold signature (requires cgo)
99+
* BLS-based threshold signature
118100
* [non interactive](https://www.iacr.org/archive/pkc2003/25670031/25670031.pdf) threshold signature reconstruction.
119101
* supports only BLS 12-381 curve with the same features above.
120102
* (t+1) signatures are required to reconstruct the threshold signature.
@@ -126,16 +108,16 @@ All signature schemes use the generic interfaces of `PrivateKey` and `PublicKey`
126108

127109
All supported Distributed Key Generation protocols are [discrete log based](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.50.2737&rep=rep1&type=pdf) and are implemented for the same BLS setup on the BLS 12-381 curve. The protocols generate key sets for the BLS-based threshold signature.
128110

129-
* Feldman VSS (requires cgo)
111+
* Feldman VSS
130112
* simple verifiable secret sharing with a single dealer.
131113
* the library does not implement the communication channels between participants. The caller should implement the methods `PrivateSend` (1-to-1 messaging) and `Broadcast` (1-to-n messaging)
132114
* 1-to-1 messaging must be a private channel, the caller must make sure the channel preserves confidentialiy and authenticates the sender.
133115
* 1-to-n broadcasting is a reliable broadcast, where honest senders are able to reach all honest receivers, and where all honest receivers end up with the same received messages. The channel should also authenticate the broadcaster.
134116
* It is recommended that both communication channels are unique per protocol instance. This could be achieved by prepending the messages to send/broadcast by a unique protocol instance ID.
135-
* Feldman VSS Qual (requires cgo)
117+
* Feldman VSS Qual
136118
* an extension of the simple Feldman VSS.
137119
* implements a complaint mechanism to qualify/disqualify the dealer.
138-
* Joint Feldman (Pedersen) (requires cgo)
120+
* Joint Feldman (Pedersen)
139121
* distributed generation.
140122
* based on parallel instances of Feldman VSS Qual, each with a different dealer.
141123
* same assumptions about the communication channels as in Feldman VSS.

bls.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo && !no_cgo
2-
31
/*
42
* Flow Crypto
53
*

bls12381_utils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo && !no_cgo
2-
31
/*
42
* Flow Crypto
53
*
@@ -117,6 +115,10 @@ func initBLS12381() {
117115
// set a global point to infinity
118116
C.E2_set_infty((*C.E2)(&g2PublicKey.point))
119117
g2PublicKey.isIdentity = true
118+
119+
blsInstance = &blsBLS12381Algo{
120+
algo: BLSBLS12381,
121+
}
120122
}
121123

122124
// String returns a hex-encoded representation of the scalar.

bls12381_utils_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo && !no_cgo
2-
31
/*
42
* Flow Crypto
53
*

bls_crossBLST_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo && !no_cgo
2-
31
/*
42
* Flow Crypto
53
*

bls_multisig.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo && !no_cgo
2-
31
/*
42
* Flow Crypto
53
*

bls_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo && !no_cgo
2-
31
/*
42
* Flow Crypto
53
*

0 commit comments

Comments
 (0)