internal/subtle: simple riscv64

This commit is contained in:
Sun Yimin 2024-09-02 13:13:16 +08:00 committed by GitHub
parent 8a2ba16639
commit 3ede9024a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 86 additions and 22 deletions

View File

@ -14,7 +14,7 @@ jobs:
test: test:
strategy: strategy:
matrix: matrix:
go-version: [1.18.x] go-version: [1.22.x]
arch: [riscv64] arch: [riscv64]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -29,11 +29,8 @@ jobs:
- name: Check out code - name: Check out code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Build
run: go build -v ./internal/bigmod/...
- name: Test - name: Test
run: go test -v -short ./internal/bigmod/... run: go test -v -short ./internal/...
env: env:
GODEBUG: x509sha1=1 GODEBUG: x509sha1=1
GOARCH: ${{ matrix.arch }} GOARCH: ${{ matrix.arch }}

View File

@ -85,10 +85,10 @@ loop:
MOV X16, 2*8(X5) // z[2] MOV X16, 2*8(X5) // z[2]
MOV X19, 3*8(X5) // z[3] MOV X19, 3*8(X5) // z[3]
ADDI $32, X5 ADD $32, X5
ADDI $32, X7 ADD $32, X7
ADDI $-4, X30 SUB $4, X30
BNEZ X30, loop BNEZ X30, loop
done: done:

View File

@ -42,16 +42,6 @@ var testValues = [20]string{
"c79886c5cd9de1f2a0deee1c76cd8c38da7dcd401f59ec4bebbaf815006f2f71", "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) { func p256OrderMulTest(t *testing.T, x, y, n *big.Int) {
var scalar1 [32]byte var scalar1 [32]byte
var scalar2 [32]byte var scalar2 [32]byte

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 package subtle

View File

@ -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)

View File

@ -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

View File

@ -1,7 +1,7 @@
// Copyright 2018 The Go Authors. All rights reserved. // Copyright 2024 Sun Yimin. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//
//go:build !purego //go:build !purego
package subtle package subtle

View File

@ -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 //go:build !purego
#include "textflag.h" #include "textflag.h"