Skip to content

Commit

Permalink
Refactor and extract ring signature functionality to gotrax
Browse files Browse the repository at this point in the history
  • Loading branch information
olabini committed Aug 22, 2018
1 parent eaeb9f7 commit 2c98947
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@ var kdfPrefix = []byte("OTRv4")
const (
usageFingerprint = byte(0x00)
usageBraceKey = byte(0x02)
usageAuth = byte(0x11)
)

var basePointBytesDup = []byte{
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00,
}

var primeOrderBytesDup = []byte{
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x7c, 0xca, 0x23, 0xe9, 0xc4, 0x4e, 0xdb, 0x49,
0xae, 0xd6, 0x36, 0x90, 0x21, 0x6c, 0xc2, 0x72, 0x8d, 0xc5, 0x8f, 0x55,
0x23, 0x78, 0xc2, 0x92, 0xab, 0x58, 0x44, 0xf3,
}
2 changes: 2 additions & 0 deletions kdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gotrax

import "golang.org/x/crypto/sha3"

type KdfFunc func(uint8, uint16, ...[]byte) []byte

func KdfPrekeyServer(usageID uint8, size uint16, values ...[]byte) []byte {
buf := make([]byte, size)
KdfxPrekeyServer(usageID, buf, values...)
Expand Down
10 changes: 10 additions & 0 deletions keys_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func DeserializePoint(buf []byte) ([]byte, ed448.Point, bool) {
return buf[57:], tp, true
}

func DeserializeScalar(buf []byte) ([]byte, ed448.Scalar, bool) {
if len(buf) < 56 {
return nil, nil, false
}
ts := ed448.NewScalar()
ts.Decode(buf[0:56])
return buf[56:], ts, true

}

func (p *PublicKey) Deserialize(buf []byte) ([]byte, bool) {
var ok bool
pubKeyType := uint16(0)
Expand Down
16 changes: 16 additions & 0 deletions keys_serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ func (s *GotraxSuite) Test_EddsaSignature_deserializesCorrectly(c *C) {
c.Assert(r, DeepEquals, []byte{0x42})
}

func (s *GotraxSuite) Test_DeserializeScalar_failsOnShortBuffer(c *C) {
ser := []byte{
0x12, 0x34, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}

b, _, ok := DeserializeScalar(ser)
c.Assert(b, IsNil)
c.Assert(ok, Equals, false)
}

func (s *GotraxSuite) Test_EddsaSignature_failsOnShortDeserialize(c *C) {
ser := []byte{
0x12, 0x34, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0,
Expand Down

0 comments on commit 2c98947

Please sign in to comment.