diff --git a/.github/workflows/test_riscv64.yaml b/.github/workflows/test_riscv64.yaml index 5024177..fc56d0f 100644 --- a/.github/workflows/test_riscv64.yaml +++ b/.github/workflows/test_riscv64.yaml @@ -14,7 +14,7 @@ jobs: test: strategy: matrix: - go-version: [1.18.x] + go-version: [1.22.x] arch: [riscv64] runs-on: ubuntu-latest steps: @@ -29,11 +29,8 @@ jobs: - name: Check out code uses: actions/checkout@v4 - - name: Build - run: go build -v ./internal/bigmod/... - - name: Test - run: go test -v -short ./internal/bigmod/... + run: go test -v -short ./internal/... env: GODEBUG: x509sha1=1 GOARCH: ${{ matrix.arch }} diff --git a/internal/bigmod/nat_riscv64.s b/internal/bigmod/nat_riscv64.s index e105ec0..91dfb22 100644 --- a/internal/bigmod/nat_riscv64.s +++ b/internal/bigmod/nat_riscv64.s @@ -85,10 +85,10 @@ loop: MOV X16, 2*8(X5) // z[2] MOV X19, 3*8(X5) // z[3] - ADDI $32, X5 - ADDI $32, X7 + ADD $32, X5 + ADD $32, X7 - ADDI $-4, X30 + SUB $4, X30 BNEZ X30, loop done: diff --git a/internal/sm2ec/fiat/sm2p256scalar_test.go b/internal/sm2ec/fiat/sm2p256scalar_test.go index 1e44e82..80a427a 100644 --- a/internal/sm2ec/fiat/sm2p256scalar_test.go +++ b/internal/sm2ec/fiat/sm2p256scalar_test.go @@ -42,16 +42,6 @@ var testValues = [20]string{ "c79886c5cd9de1f2a0deee1c76cd8c38da7dcd401f59ec4bebbaf815006f2f71", } -func TestGenerateValues(t *testing.T) { - p, _ := new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16) - for i := 0; i < 20; i++ { - k, _ := rand.Int(rand.Reader, p) - if k.Sign() > 0 { - fmt.Printf("%v\n", hex.EncodeToString(k.Bytes())) - } - } -} - func p256OrderMulTest(t *testing.T, x, y, n *big.Int) { var scalar1 [32]byte var scalar2 [32]byte diff --git a/internal/subtle/xor_generic.go b/internal/subtle/xor_generic.go index c515f53..118244e 100644 --- a/internal/subtle/xor_generic.go +++ b/internal/subtle/xor_generic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // -//go:build purego || !(amd64 || arm64 || s390x || ppc64 || ppc64le) +//go:build purego || !(amd64 || arm64 || s390x || ppc64 || ppc64le || riscv64) package subtle diff --git a/internal/subtle/xor_riscv64.go b/internal/subtle/xor_riscv64.go new file mode 100644 index 0000000..ea8dd38 --- /dev/null +++ b/internal/subtle/xor_riscv64.go @@ -0,0 +1,10 @@ +// Copyright 2024 Sun Yimin. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +//go:build !purego + +package subtle + +//go:noescape +func xorBytes(dst, a, b *byte, n int) diff --git a/internal/subtle/xor_riscv64.s b/internal/subtle/xor_riscv64.s new file mode 100644 index 0000000..bdf38cb --- /dev/null +++ b/internal/subtle/xor_riscv64.s @@ -0,0 +1,63 @@ +// Copyright 2024 Sun Yimin. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +//go:build !purego + +#include "textflag.h" + +// func xorBytes(dst, a, b *byte, n int) +TEXT ·xorBytes(SB), NOSPLIT|NOFRAME, $0 + MOV dst+0(FP), X5 + MOV a+8(FP), X6 + MOV b+16(FP), X7 + MOV n+24(FP), X8 + + MOV $8, X9 + BLTU X8, X9, tail + +loop: + MOV (X6), X10 + MOV (X7), X11 + XOR X10, X11, X10 + MOV X10, (X5) + ADD $8, X5 + ADD $8, X6 + ADD $8, X7 + SUB $8, X8 + BGEU X8, X9, loop + +tail: + BEQZ X8, done + MOV $4, X9 + BLTU X8, X9, less_than4 + MOVWU (X6), X10 + MOVWU (X7), X11 + XOR X10, X11, X10 + MOVW X10, (X5) + ADD $4, X5 + ADD $4, X6 + ADD $4, X7 + SUB $4, X8 + +less_than4: + MOV $2, X9 + BLTU X8, X9, less_than2 + MOVHU (X6), X10 + MOVHU (X7), X11 + XOR X10, X11, X10 + MOVHU X10, (X5) + ADD $2, X5 + ADD $2, X6 + ADD $2, X7 + SUB $2, X8 + +less_than2: + BEQZ X8, done + MOVBU (X6), X10 + MOVBU (X7), X11 + XOR X10, X11, X10 + MOVBU X10, (X5) + +done: + RET diff --git a/internal/subtle/xor_s390x.go b/internal/subtle/xor_s390x.go index 6fbacf9..ea8dd38 100644 --- a/internal/subtle/xor_s390x.go +++ b/internal/subtle/xor_s390x.go @@ -1,7 +1,7 @@ -// Copyright 2018 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style +// Copyright 2024 Sun Yimin. All rights reserved. +// Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -// + //go:build !purego package subtle diff --git a/internal/subtle/xor_s390x.s b/internal/subtle/xor_s390x.s index 834385e..a5ad498 100644 --- a/internal/subtle/xor_s390x.s +++ b/internal/subtle/xor_s390x.s @@ -1,3 +1,7 @@ +// Copyright 2024 Sun Yimin. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + //go:build !purego #include "textflag.h"