Commit 86f40a2e authored by bill_ofarrell's avatar bill_ofarrell Committed by Brad Fitzpatrick

crypto/ecdsa: fix buffer size on s390x for ecdsa

I used too small a size for buffers, which can cause a panic in some testing.
The new buffer size is generous and sufficient for all purposes.

Fixes #34927
Fixes #34928

Change-Id: Icdbbfed5da87fe3757be40dfd23182b37ec62d58
Reviewed-on: https://go-review.googlesource.com/c/go/+/201317Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c4817f5d
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
// s390x accelerated signatures // s390x accelerated signatures
//go:noescape //go:noescape
func kdsaSig(fc uint64, block *[1720]byte) (errn uint64) func kdsaSig(fc uint64, block *[4096]byte) (errn uint64)
type signverify int type signverify int
...@@ -109,7 +109,7 @@ func zeroExtendAndCopy(dst, src []byte, size int) { ...@@ -109,7 +109,7 @@ func zeroExtendAndCopy(dst, src []byte, size int) {
func sign(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, e *big.Int) (r, s *big.Int, err error) { func sign(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, e *big.Int) (r, s *big.Int, err error) {
var bo bufferOffsets var bo bufferOffsets
if canUseKDSA(signing, c, &bo) && e.Sign() != 0 { if canUseKDSA(signing, c, &bo) && e.Sign() != 0 {
var buffer [1720]byte var buffer [4096]byte
for { for {
var k *big.Int var k *big.Int
k, err = randFieldElement(c, csprng) k, err = randFieldElement(c, csprng)
...@@ -140,7 +140,7 @@ func sign(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, e *bi ...@@ -140,7 +140,7 @@ func sign(priv *PrivateKey, csprng *cipher.StreamReader, c elliptic.Curve, e *bi
func verify(pub *PublicKey, c elliptic.Curve, e, r, s *big.Int) bool { func verify(pub *PublicKey, c elliptic.Curve, e, r, s *big.Int) bool {
var bo bufferOffsets var bo bufferOffsets
if canUseKDSA(verifying, c, &bo) && e.Sign() != 0 { if canUseKDSA(verifying, c, &bo) && e.Sign() != 0 {
var buffer [1720]byte var buffer [4096]byte
zeroExtendAndCopy(buffer[bo.offsetR:], r.Bytes(), bo.baseSize) zeroExtendAndCopy(buffer[bo.offsetR:], r.Bytes(), bo.baseSize)
zeroExtendAndCopy(buffer[bo.offsetS:], s.Bytes(), bo.baseSize) zeroExtendAndCopy(buffer[bo.offsetS:], s.Bytes(), bo.baseSize)
zeroExtendAndCopy(buffer[bo.offsetHash:], e.Bytes(), bo.hashSize) zeroExtendAndCopy(buffer[bo.offsetHash:], e.Bytes(), bo.hashSize)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "textflag.h" #include "textflag.h"
// func kdsaSig(fc uint64, block *[1720]byte) (errn uint64) // func kdsaSig(fc uint64, block *[4096]byte) (errn uint64)
TEXT ·kdsaSig(SB), NOSPLIT|NOFRAME, $0-24 TEXT ·kdsaSig(SB), NOSPLIT|NOFRAME, $0-24
MOVD fc+0(FP), R0 // function code MOVD fc+0(FP), R0 // function code
MOVD block+8(FP), R1 // address parameter block MOVD block+8(FP), R1 // address parameter block
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment