From b866f41052d19d2b45523347985d17284bed41b1 Mon Sep 17 00:00:00 2001 From: Daniel Bourdrez <3641580+bytemare@users.noreply.github.com> Date: Sat, 11 Feb 2023 13:12:12 +0100 Subject: [PATCH] Use int instead of uint (#32) * use Montgomery ladder for scalar pow Signed-off-by: bytemare <3641580+bytemare@users.noreply.github.com> * update deps and use int instead of uint Signed-off-by: bytemare <3641580+bytemare@users.noreply.github.com> --------- Signed-off-by: bytemare <3641580+bytemare@users.noreply.github.com> --- README.md | 4 ++-- go.mod | 4 ++-- go.sum | 14 ++++---------- groups.go | 4 ++-- internal/edwards25519/group.go | 4 ++-- internal/group.go | 4 ++-- internal/nist/group.go | 8 ++++---- internal/ristretto/ristretto.go | 4 ++-- 8 files changed, 20 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 009ef77..866cbc4 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ type Group interface { HashToGroup(input, dst []byte) Element EncodeToGroup(input, dst []byte) Element Ciphersuite() string - ScalarLength() uint - ElementLength() uint + ScalarLength() int + ElementLength() int Order() string } ``` diff --git a/go.mod b/go.mod index c0c36c4..65153ca 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,6 @@ require ( require ( github.com/bytemare/hash v0.1.3 // indirect - golang.org/x/crypto v0.5.0 // indirect - golang.org/x/sys v0.4.0 // indirect + golang.org/x/crypto v0.6.0 // indirect + golang.org/x/sys v0.5.0 // indirect ) diff --git a/go.sum b/go.sum index 2846f67..828af56 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= -filippo.io/nistec v0.0.0-20220513155737-c4b6d02e738c h1:x4epP2lA8b5UYoIFjcVpN+MfJQeX5M5Yilmc1VH0YDw= -filippo.io/nistec v0.0.0-20220513155737-c4b6d02e738c/go.mod h1:84fxC9mi+MhC2AERXI4LSa8cmSVOzrFikg6hZ4IfCyw= filippo.io/nistec v0.0.0-20220825075812-a82cab4ea6f0 h1:infQBtlEPAdRCqMIoddLS8K27zaaz05FLnrXskk0TtE= filippo.io/nistec v0.0.0-20220825075812-a82cab4ea6f0/go.mod h1:84fxC9mi+MhC2AERXI4LSa8cmSVOzrFikg6hZ4IfCyw= github.com/bytemare/hash v0.1.3 h1:E2v/+gqvLTjaR8W2JdhqaB2L9161yFBlSXDnYEyMt94= @@ -10,11 +8,7 @@ github.com/bytemare/hash2curve v0.1.2 h1:V/TSdU/WsfYS3Bk73ap+odLCOOm2/B02rKE8lb9 github.com/bytemare/hash2curve v0.1.2/go.mod h1:S+OcM3nIREThTmjkFa+nX6vqGH11nEzefaIYq7MVAp4= github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 h1:Y7NOhdqIOU8kYI7BxsgL38d0ot0raxvcW+EMQU2QrT4= -golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/groups.go b/groups.go index 6e2b6df..085c75f 100644 --- a/groups.go +++ b/groups.go @@ -131,12 +131,12 @@ func (g Group) EncodeToGroup(input, dst []byte) *Element { } // ScalarLength returns the byte size of an encoded scalar. -func (g Group) ScalarLength() uint { +func (g Group) ScalarLength() int { return g.get().ScalarLength() } // ElementLength returns the byte size of an encoded element. -func (g Group) ElementLength() uint { +func (g Group) ElementLength() int { return g.get().ElementLength() } diff --git a/internal/edwards25519/group.go b/internal/edwards25519/group.go index 66d4251..4ba9cf3 100644 --- a/internal/edwards25519/group.go +++ b/internal/edwards25519/group.go @@ -67,12 +67,12 @@ func (g Group) Ciphersuite() string { } // ScalarLength returns the byte size of an encoded element. -func (g Group) ScalarLength() uint { +func (g Group) ScalarLength() int { return canonicalEncodingLength } // ElementLength returns the byte size of an encoded element. -func (g Group) ElementLength() uint { +func (g Group) ElementLength() int { return canonicalEncodingLength } diff --git a/internal/group.go b/internal/group.go index 2a796fb..4851746 100644 --- a/internal/group.go +++ b/internal/group.go @@ -36,10 +36,10 @@ type Group interface { Ciphersuite() string // ScalarLength returns the byte size of an encoded scalar. - ScalarLength() uint + ScalarLength() int // ElementLength returns the byte size of an encoded element. - ElementLength() uint + ElementLength() int // Order returns the order of the canonical group of scalars. Order() string diff --git a/internal/nist/group.go b/internal/nist/group.go index 989ca4e..66ff636 100644 --- a/internal/nist/group.go +++ b/internal/nist/group.go @@ -133,15 +133,15 @@ func (g Group[P]) Ciphersuite() string { } // ScalarLength returns the byte size of an encoded element. -func (g Group[P]) ScalarLength() uint { +func (g Group[P]) ScalarLength() int { byteLen := (g.scalarField.bitLen() + 7) / 8 - return uint(byteLen) + return byteLen } // ElementLength returns the byte size of an encoded element. -func (g Group[P]) ElementLength() uint { +func (g Group[P]) ElementLength() int { byteLen := (g.curve.field.bitLen() + 7) / 8 - return uint(1 + byteLen) + return 1 + byteLen } // Order returns the order of the canonical group of scalars. diff --git a/internal/ristretto/ristretto.go b/internal/ristretto/ristretto.go index 3ab4bc3..d9b4d6e 100644 --- a/internal/ristretto/ristretto.go +++ b/internal/ristretto/ristretto.go @@ -81,12 +81,12 @@ func (g Group) Ciphersuite() string { } // ScalarLength returns the byte size of an encoded element. -func (g Group) ScalarLength() uint { +func (g Group) ScalarLength() int { return canonicalEncodingLength } // ElementLength returns the byte size of an encoded element. -func (g Group) ElementLength() uint { +func (g Group) ElementLength() int { return canonicalEncodingLength }