Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libsodium test on Github Actions #327

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ jobs:
name: "${{ github.sha }}-03"
path: ./pkgs.txt.part.03

build-libsodium:
name: Build libsodium
runs-on: ubuntu-latest
needs: split-test-files
steps:
- uses: actions/checkout@v2
- run: make libsodium
- uses: actions/upload-artifact@v2
with:
name: libsodium
path: crypto/vrf/internal/vrf/sodium

build-linux:
name: Build
runs-on: ubuntu-latest
Expand All @@ -40,12 +52,15 @@ jobs:
- 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 @@ -60,16 +75,20 @@ jobs:
**/**.go
go.mod
go.sum
- name: install
run: GOOS=linux GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} make build
- name: Build Linux
run: GOOS=linux GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} TARGET_HOST=${{ matrix.host }} make build
if: "env.GIT_DIFF != ''"
- name: Build Linux with Libsodium
run: GOOS=linux GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} TARGET_HOST=${{ matrix.host }} LIBSODIUM=1 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 @@ -86,9 +105,13 @@ jobs:
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
with:
name: libsodium
path: crypto/vrf/internal/vrf/sodium
- 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 -tags ${{ 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