1
0
mirror of https://github.com/henrydcase/nobs.git synced 2024-11-22 15:18:57 +00:00

x448: Export shared secret size (#3)

Changes x448Bytes variable to SharedSecretSize
This commit is contained in:
Henry Case 2018-08-03 14:36:45 +01:00 committed by GitHub
parent fc932264c3
commit c88bbf0f75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 25 deletions

View File

@ -28,7 +28,7 @@
package x448
const (
x448Bytes = 56
SharedSecretSize = 56
edwardsD = -39081
)
@ -55,7 +55,7 @@ func ScalarMult(out, scalar, base *[56]byte) int {
// Scalar conditioning.
if t/8 == 0 {
sb &= 0xFC
} else if t/8 == x448Bytes-1 {
} else if t/8 == SharedSecretSize-1 {
sb |= 0x80
}

View File

@ -742,14 +742,14 @@ func (a *gf) canon() {
}
// deser deserializes into the limb representation.
func (s *gf) deser(ser *[x448Bytes]byte) {
func (s *gf) deser(ser *[SharedSecretSize]byte) {
var buf uint64
bits := uint(0)
k := 0
for i, v := range ser {
buf |= (uint64)(v) << bits
for bits += 8; (bits >= lBits || i == x448Bytes-1) && k < x448Limbs; bits, buf = bits-lBits, buf>>lBits {
for bits += 8; (bits >= lBits || i == SharedSecretSize-1) && k < x448Limbs; bits, buf = bits-lBits, buf>>lBits {
s.limb[k] = (uint32)(buf & lMask)
k++
}
@ -757,14 +757,14 @@ func (s *gf) deser(ser *[x448Bytes]byte) {
}
// ser serializes into byte representation.
func (a *gf) ser(ser *[x448Bytes]byte) {
func (a *gf) ser(ser *[SharedSecretSize]byte) {
a.canon()
k := 0
bits := uint(0)
var buf uint64
for i, v := range a.limb {
buf |= (uint64)(v) << bits
for bits += lBits; (bits >= 8 || i == x448Limbs-1) && k < x448Bytes; bits, buf = bits-8, buf>>8 {
for bits += lBits; (bits >= 8 || i == x448Limbs-1) && k < SharedSecretSize; bits, buf = bits-8, buf>>8 {
ser[k] = (byte)(buf)
k++
}

View File

@ -38,14 +38,14 @@ var reallyRunSlowTest = false
func TestX448(t *testing.T) {
type KATVectors struct {
scalar [x448Bytes]byte
base [x448Bytes]byte
answer [x448Bytes]byte
scalar [SharedSecretSize]byte
base [SharedSecretSize]byte
answer [SharedSecretSize]byte
}
vectors := []KATVectors{
{
[x448Bytes]byte{
[SharedSecretSize]byte{
0x3d, 0x26, 0x2f, 0xdd, 0xf9, 0xec, 0x8e, 0x88,
0x49, 0x52, 0x66, 0xfe, 0xa1, 0x9a, 0x34, 0xd2,
0x88, 0x82, 0xac, 0xef, 0x04, 0x51, 0x04, 0xd0,
@ -54,7 +54,7 @@ func TestX448(t *testing.T) {
0xf4, 0x49, 0x43, 0xeb, 0xa3, 0x68, 0xf5, 0x4b,
0x29, 0x25, 0x9a, 0x4f, 0x1c, 0x60, 0x0a, 0xd3,
},
[x448Bytes]byte{
[SharedSecretSize]byte{
0x06, 0xfc, 0xe6, 0x40, 0xfa, 0x34, 0x87, 0xbf,
0xda, 0x5f, 0x6c, 0xf2, 0xd5, 0x26, 0x3f, 0x8a,
0xad, 0x88, 0x33, 0x4c, 0xbd, 0x07, 0x43, 0x7f,
@ -63,7 +63,7 @@ func TestX448(t *testing.T) {
0x83, 0xfa, 0x54, 0x29, 0xdb, 0x94, 0xad, 0xa1,
0x8a, 0xa7, 0xa7, 0xfb, 0x4e, 0xf8, 0xa0, 0x86,
},
[x448Bytes]byte{
[SharedSecretSize]byte{
0xce, 0x3e, 0x4f, 0xf9, 0x5a, 0x60, 0xdc, 0x66,
0x97, 0xda, 0x1d, 0xb1, 0xd8, 0x5e, 0x6a, 0xfb,
0xdf, 0x79, 0xb5, 0x0a, 0x24, 0x12, 0xd7, 0x54,
@ -74,7 +74,7 @@ func TestX448(t *testing.T) {
},
},
{
[x448Bytes]byte{
[SharedSecretSize]byte{
0x20, 0x3d, 0x49, 0x44, 0x28, 0xb8, 0x39, 0x93,
0x52, 0x66, 0x5d, 0xdc, 0xa4, 0x2f, 0x9d, 0xe8,
0xfe, 0xf6, 0x00, 0x90, 0x8e, 0x0d, 0x46, 0x1c,
@ -83,7 +83,7 @@ func TestX448(t *testing.T) {
0x31, 0x5c, 0x44, 0xe0, 0xa5, 0xb4, 0x37, 0x12,
0x82, 0xdd, 0x2c, 0x8d, 0x5b, 0xe3, 0x09, 0x5f,
},
[x448Bytes]byte{
[SharedSecretSize]byte{
0x0f, 0xbc, 0xc2, 0xf9, 0x93, 0xcd, 0x56, 0xd3,
0x30, 0x5b, 0x0b, 0x7d, 0x9e, 0x55, 0xd4, 0xc1,
0xa8, 0xfb, 0x5d, 0xbb, 0x52, 0xf8, 0xe9, 0xa1,
@ -92,7 +92,7 @@ func TestX448(t *testing.T) {
0x2f, 0xe2, 0x05, 0xe2, 0x8a, 0x78, 0xb9, 0x1c,
0xdf, 0xbd, 0xe7, 0x1c, 0xe8, 0xd1, 0x57, 0xdb,
},
[x448Bytes]byte{
[SharedSecretSize]byte{
0x88, 0x4a, 0x02, 0x57, 0x62, 0x39, 0xff, 0x7a,
0x2f, 0x2f, 0x63, 0xb2, 0xdb, 0x6a, 0x9f, 0xf3,
0x70, 0x47, 0xac, 0x13, 0x56, 0x8e, 0x1e, 0x30,
@ -104,7 +104,7 @@ func TestX448(t *testing.T) {
},
}
var out [x448Bytes]byte
var out [SharedSecretSize]byte
for i, vec := range vectors {
ret := ScalarMult(&out, &vec.scalar, &vec.base)
if ret != 0 {
@ -126,7 +126,7 @@ func TestX448IETFDraft(t *testing.T) {
// refuse to run the full 1 million iterations, and the `go test`
// timeout will need to be increased (`go test -timeout 30m`).
var k, u, out [x448Bytes]byte
var k, u, out [SharedSecretSize]byte
copy(k[:], basePoint[:])
copy(u[:], basePoint[:])
@ -160,7 +160,7 @@ func TestX448IETFDraft(t *testing.T) {
}
func TestCurve448(t *testing.T) {
alicePriv := [x448Bytes]byte{
alicePriv := [SharedSecretSize]byte{
0x9a, 0x8f, 0x49, 0x25, 0xd1, 0x51, 0x9f, 0x57,
0x75, 0xcf, 0x46, 0xb0, 0x4b, 0x58, 0x00, 0xd4,
0xee, 0x9e, 0xe8, 0xba, 0xe8, 0xbc, 0x55, 0x65,
@ -170,7 +170,7 @@ func TestCurve448(t *testing.T) {
0x9a, 0xc2, 0xd8, 0xc0, 0xa5, 0x98, 0x72, 0x6b,
}
alicePub := [x448Bytes]byte{
alicePub := [SharedSecretSize]byte{
0x9b, 0x08, 0xf7, 0xcc, 0x31, 0xb7, 0xe3, 0xe6,
0x7d, 0x22, 0xd5, 0xae, 0xa1, 0x21, 0x07, 0x4a,
0x27, 0x3b, 0xd2, 0xb8, 0x3d, 0xe0, 0x9c, 0x63,
@ -180,7 +180,7 @@ func TestCurve448(t *testing.T) {
0x17, 0x7f, 0x80, 0xe5, 0x32, 0xc4, 0x1f, 0xa0,
}
bobPriv := [x448Bytes]byte{
bobPriv := [SharedSecretSize]byte{
0x1c, 0x30, 0x6a, 0x7a, 0xc2, 0xa0, 0xe2, 0xe0,
0x99, 0x0b, 0x29, 0x44, 0x70, 0xcb, 0xa3, 0x39,
0xe6, 0x45, 0x37, 0x72, 0xb0, 0x75, 0x81, 0x1d,
@ -190,7 +190,7 @@ func TestCurve448(t *testing.T) {
0x36, 0x6f, 0x10, 0xb6, 0x51, 0x73, 0x99, 0x2d,
}
bobPub := [x448Bytes]byte{
bobPub := [SharedSecretSize]byte{
0x3e, 0xb7, 0xa8, 0x29, 0xb0, 0xcd, 0x20, 0xf5,
0xbc, 0xfc, 0x0b, 0x59, 0x9b, 0x6f, 0xec, 0xcf,
0x6d, 0xa4, 0x62, 0x71, 0x07, 0xbd, 0xb0, 0xd4,
@ -200,7 +200,7 @@ func TestCurve448(t *testing.T) {
0x07, 0xbd, 0xc1, 0xc6, 0x7b, 0xf3, 0x36, 0x09,
}
aliceBob := [x448Bytes]byte{
aliceBob := [SharedSecretSize]byte{
0x07, 0xff, 0xf4, 0x18, 0x1a, 0xc6, 0xcc, 0x95,
0xec, 0x1c, 0x16, 0xa9, 0x4a, 0x0f, 0x74, 0xd1,
0x2d, 0xa2, 0x32, 0xce, 0x40, 0xa7, 0x75, 0x52,
@ -210,7 +210,7 @@ func TestCurve448(t *testing.T) {
0x44, 0x9a, 0x50, 0x37, 0x51, 0x4a, 0x87, 0x9d,
}
var out [x448Bytes]byte
var out [SharedSecretSize]byte
ret := ScalarBaseMult(&out, &alicePriv)
if ret != 0 {
t.Error("Alice: ScalarBaseMult failed")
@ -242,7 +242,7 @@ func TestCurve448(t *testing.T) {
}
func BenchmarkECDH(b *testing.B) {
var sa, sb, pa, pb, ab, ba [x448Bytes]byte
var sa, sb, pa, pb, ab, ba [SharedSecretSize]byte
ret := 0
rand.Read(sa[:])