mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 04:06:18 +08:00
internal/subtle: simple riscv64
This commit is contained in:
parent
8a2ba16639
commit
3ede9024a5
7
.github/workflows/test_riscv64.yaml
vendored
7
.github/workflows/test_riscv64.yaml
vendored
@ -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 }}
|
||||||
|
@ -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:
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
10
internal/subtle/xor_riscv64.go
Normal file
10
internal/subtle/xor_riscv64.go
Normal 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)
|
63
internal/subtle/xor_riscv64.s
Normal file
63
internal/subtle/xor_riscv64.s
Normal 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
|
@ -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
|
||||||
|
@ -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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user