Skip to content

Commit

Permalink
Add libsodium on Github Actiions
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Oct 11, 2021
1 parent d93b500 commit 2884118
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Create a file with all the pkgs
run: go list ./... > pkgs.txt
run: go list -tag libsodium ./... > pkgs.txt
- name: Split pkgs into 4 files
run: split -d -n l/4 pkgs.txt pkgs.txt.part.
# cache multiple
Expand All @@ -30,22 +30,32 @@ jobs:
name: "${{ github.sha }}-03"
path: ./pkgs.txt.part.03

build-libsodium:
runs-on: ubuntu-latest
needs: split-test-files
steps:
- run: make libsodium

build-linux:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
libsodium: ["0", "1"]
include:
- goarch: "amd64"
gcc: "gcc"
package: ""
host: ""
- goarch: "arm64"
gcc: "aarch64-linux-gnu-gcc"
package: "g++-aarch64-linux-gnu"
host: "aarch64-linux-gnu"
- goarch: "arm"
gcc: "arm-linux-gnueabi-gcc"
package: "g++-arm-linux-gnueabi"
host: "arm-linux-gnueabi"
timeout-minutes: 5
steps:
- run: sudo apt update && sudo apt install -y ${{ matrix.package }} qemu-user-binfmt
Expand All @@ -61,15 +71,16 @@ jobs:
go.mod
go.sum
- name: install
run: GOOS=linux GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} make build
run: GOOS=linux GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} TARGET_HOST=${{ matrix.host }} LIBSODIUM=${{ matrix.libsodium }} make build
if: "env.GIT_DIFF != ''"

tests:
runs-on: ubuntu-latest
needs: split-test-files
needs: build-libsodium
strategy:
fail-fast: false
matrix:
vrf: ["r2ishiguro", "libsodium"]
part: ["00", "01", "02", "03"]
steps:
- uses: actions/setup-go@v2
Expand All @@ -88,7 +99,7 @@ jobs:
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 10m -race -coverprofile=${{ matrix.part }}profile.out -covermode=atomic
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 10m -race -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tag=${{ matrix.vrf }}
if: env.GIT_DIFF
- uses: actions/upload-artifact@v2
with:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ install_abci:
VRF_ROOT = $(SRCPATH)/crypto/vrf/internal/vrf
LIBSODIUM_ROOT = $(VRF_ROOT)/libsodium
LIBSODIUM_OS = $(VRF_ROOT)/sodium/$(TARGET_OS)_$(TARGET_ARCH)
ifneq ($(TARGET_HOST), "")
LIBSODIUM_HOST = "--host=$(TARGET_HOST)"
endif

libsodium:
@if [ ! -f $(LIBSODIUM_OS)/lib/libsodium.a ]; then \
Expand All @@ -158,7 +161,7 @@ libsodium:
git submodule update --init --recursive && \
cd $(LIBSODIUM_ROOT) && \
./autogen.sh && \
./configure --disable-shared --prefix="$(LIBSODIUM_OS)" && \
./configure --disable-shared --prefix="$(LIBSODIUM_OS)" $(LIBSODIUM_HOST) && \
$(MAKE) && \
$(MAKE) install; \
fi
Expand Down
4 changes: 3 additions & 1 deletion crypto/vrf/keygen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func keyGen_coniks_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.
}

func keyGen_libsodium_ed25519(secret [SEEDBYTES]byte) (ed25519.PrivateKey, ed25519.PublicKey) {
pubKey, privKey := libsodium.KeyPairFromSeed(&secret)
var seed [libsodium.SEEDBYTES]byte
copy(seed[:], secret[:])
pubKey, privKey := libsodium.KeyPairFromSeed(&seed)
privateKey := make([]byte, libsodium.SECRETKEYBYTES)
copy(privateKey, privKey[:])
publicKey := make([]byte, libsodium.PUBLICKEYBYTES)
Expand Down
10 changes: 5 additions & 5 deletions crypto/vrf/vrf_libsodium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestKeyPairCompatibilityLibsodium(t *testing.T) {
secret := [SEEDBYTES]byte{}
secret := [libsodium.SEEDBYTES]byte{}
publicKey, privateKey := libsodium.KeyPairFromSeed(&secret)

privateKey2 := ed25519.PrivateKey(make([]byte, 64))
Expand All @@ -28,7 +28,7 @@ func TestKeyPairCompatibilityLibsodium(t *testing.T) {
}

func TestProveAndVerify_LibsodiumByCryptoED25519(t *testing.T) {
secret := [SEEDBYTES]byte{}
secret := [libsodium.SEEDBYTES]byte{}
privateKey := ed25519.NewKeyFromSeed(secret[:])
publicKey := privateKey.Public().(ed25519.PublicKey)

Expand All @@ -41,7 +41,7 @@ func TestProveAndVerify_LibsodiumByCryptoED25519(t *testing.T) {
}

func TestProveAndVerify_LibsodiumByConiksED25519(t *testing.T) {
secret := [SEEDBYTES]byte{}
secret := [libsodium.SEEDBYTES]byte{}
privateKey, _ := coniks.GenerateKey(bytes.NewReader(secret[:]))
publicKey, _ := privateKey.Public()

Expand All @@ -55,7 +55,7 @@ func TestProveAndVerify_LibsodiumByConiksED25519(t *testing.T) {
}

func TestProveAndVerify_LibsodiumByLibsodiumED25519(t *testing.T) {
secret := [SEEDBYTES]byte{}
secret := [libsodium.SEEDBYTES]byte{}
publicKey, privateKey := libsodium.KeyPairFromSeed(&secret)

verified, err := proveAndVerify(t, privateKey[:], publicKey[:])
Expand All @@ -67,7 +67,7 @@ func TestProveAndVerify_LibsodiumByLibsodiumED25519(t *testing.T) {
}

func TestProveAndVerifyCompatibilityLibsodium(t *testing.T) {
secret := [SEEDBYTES]byte{}
secret := [libsodium.SEEDBYTES]byte{}
message := []byte("hello, world")
privateKey := ed25519.NewKeyFromSeed(secret[:])
publicKey := privateKey.Public().(ed25519.PublicKey)
Expand Down
1 change: 0 additions & 1 deletion crypto/vrf/vrf_r2ishiguro.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// default: r2ishiguro
// +build !libsodium,!coniks

package vrf
Expand Down

0 comments on commit 2884118

Please sign in to comment.