xmss

package module
v0.0.0-...-6c701c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2018 License: MIT Imports: 12 Imported by: 0

README

Build Status GoDoc GitHub license Coverage Status

XMSS (eXtended Merkle Signature Scheme)

Overview

This library is for creating keys, signing messages and verifing the signature by XMSS and XMSS^MT in Go.

This code implements XMSS-SHA2_*_256 and XMSSMT-SHA2_*/*_256 described on XMSS: eXtended Merkle Signature Scheme (RFC 8391). This code should be much faster than the XMSS reference code. by using SSE extention and block level optimizations in SHA256 with multi threadings.

Requirements

  • git
  • go 1.9+

are required to compile.

Install

$ go get -u github.com/AidosKuneen/xmss

Usage

	import "github.com/AidosKuneen/xmss"
	import	"github.com/vmihailenco/msgpack"

	seed := []byte{0x01,0x02...}
	mer := xmss.NewMerkle(10, seed)
	msg := []byte("This is a test for XMSS.")
	sig := mer.Sign(msg)
	pub := mer.PublicKey()
	if !xmss.Verify(sig, msg, pub) {
		log.Println("signature is invalid")
	}
	//output Merkle contents to json
	dat, err := json.Marshal(mer)
	//convert json to Merkle
	var mer2 xmss.Merkle
	err = json.Unmarshal(dat, &mer2)

	//output Merkle contents to msgpack format
	mdat, err := msgpack.Marshal(mer)
	//convert msgapck bin to Merkle
	var mmer xmss.Merkle
	err = msgpack.Unmarshal(mdat, &mmer)

	mt, err := xmss.NewPrivKeyMT(seed, 40, 4)
	sig := mt.Sign(msg)
	if !VerifyMT(sig, msg, mt.PublicKey(), 40, 4) {
		...
	}

Performance

Using the following test environment...

* Compiler: go version go1.10 linux/amd64
* Kernel: Linux WS777 4.13.5-1-ARCH #1 SMP PREEMPT Fri Oct 6 09:58:47 CEST 2017 x86_64 GNU/Linux
* CPU:  Celeron(R) CPU G1840 @ 2.80GHz 
* Memory: 8 GB

For XMSS-SHA2_10_256, it takes

  • about 760 mS to generating a keypair,
  • about 6.3 mS to sign a message,
  • about 490 uS to verify a signature.

For XMSS-SHA2_16_256, it takes

  • about 46 seconds to generating a keypair,
  • about 7.3 mS to sign a message,
  • about 500 uS to verify a signature.

For XMSS-SHA2_20_256, it takes about 14 minutes to generating a keypair,

BenchmarkXMSS10-2                      2         759714114 ns/op
BenchmarkXMSS10Sign-2                300           6281026 ns/op
BenchmarkXMSS10Veri-2               3000            487012 ns/op
enchmarkXMSS16-2                      1        45571294167 ns/op
BenchmarkXMSS16Sign-2                300           7299528 ns/op
BenchmarkXMSS16Veri-2               3000            504971 ns/op
BenchmarkXMSS20-2                      1        820250400243 ns/op

On DIGNO M KYL22(Android Smartphone):

* Compiler: go version go1.10 linux/arm
* OS: 	Android 4.2.2
* CPU:	Qualcomm Snapdragon 800 MSM8974 2.2GHz (quad core)
* Memory: 2 GB

For XMSS-SHA2_10_256, it takes

  • about 2.9 seconds to generating a keypair,
  • about 34 mS to sign a message,
  • about 4.5 mS to verify a signature.
BenchmarkXMSS10                1        2906321328 ns/op
BenchmarkXMSS10Sign          100          34440405 ns/op
BenchmarkXMSS10Veri          300           4496049 ns/op

On a cloud server:

* Compiler: go version go1.8.1 linux/amd64
* Kernel: Linux 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
* CPU:  CAMD Ryzen 7 1700X Eight-Core Processor @ 2.20GHz (16 cores)
* Memory: 64 GB

For XMSS-SHA2_10_256, it takes

  • about 190 mS to generating a keypair,
  • about 4.9 mS to sign a message,
  • about 410 uS to verify a signature.

For XMSS-SHA2_16_256, it takes

  • about 9.0 seconds to generating a keypair,
  • about 5.3 mS to sign a message,
  • about 420 uS to verify a signature.

For XMSS-SHA2_20_256, it takes about 3.1 minutes to generating a keypair,

BenchmarkXMSS10-16        	      10	 180479693 ns/op
BenchmarkXMSS10Sign-16    	     300	   4939994 ns/op
BenchmarkXMSS10Veri-16    	    5000	    411160 ns/op
BenchmarkXMSS16-16        	       1	9032432802 ns/op
BenchmarkXMSS16Sign-16    	     300	   5364563 ns/op
BenchmarkXMSS16Veri-16    	    3000	    419544 ns/op
BenchmarkXMSS20-16        	       1  187203367087 ns/op

Dependencies and Licenses

This software includes the work that is distributed in the Apache License 2.0.

github.com/AidosKuneen/xmss           MIT License 
github.com/AidosKuneen/sha256-simd    Apache License 2.0
github.com/vmihailenco/msgpack/codes  BSD 2-clause "Simplified" License
Golang Standard Library               BSD 3-clause License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexFromSig

func IndexFromSig(bsig []byte) (uint32, error)

IndexFromSig returns index of merkle from the signature bsig.

func PublickeyMTHeader

func PublickeyMTHeader(h, d uint32) (byte, error)

PublickeyMTHeader returns first 1 byte of public key of XMSS^MT

func Verify

func Verify(bsig, msg, bpk []byte) bool

Verify verifies msg by XMSS.

func VerifyMT

func VerifyMT(bsig, msg, bpk []byte) bool

VerifyMT verifies msg by XMSS^MT.

Types

type Merkle

type Merkle struct {
	//Leaf is the number of unused leaf.
	Leaf   uint32
	Height uint32
	// contains filtered or unexported fields
}

Merkle represents MerkleTree for XMSS.

func NewMerkle

func NewMerkle(h byte, seed []byte) *Merkle

NewMerkle makes Merkle struct from height and private seed.

func (*Merkle) DecodeMsgpack

func (m *Merkle) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack unmarshals JSON to Merkle.

func (*Merkle) EncodeMsgpack

func (m *Merkle) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack marshals Merkle into valid JSON.

func (*Merkle) LeafNo

func (m *Merkle) LeafNo() uint64

LeafNo returns the leaf no in merkle.

func (*Merkle) MarshalJSON

func (m *Merkle) MarshalJSON() ([]byte, error)

MarshalJSON marshals Merkle into valid JSON.

func (*Merkle) PublicKey

func (m *Merkle) PublicKey() []byte

PublicKey returns public key (merkle root) of XMSS

func (*Merkle) SetLeafNo

func (m *Merkle) SetLeafNo(n uint64) error

SetLeafNo sets the leaf no in merkle and refresh authes..

func (*Merkle) Sign

func (m *Merkle) Sign(msg []byte) []byte

Sign signs by XMSS with MerkleTree.

func (*Merkle) Traverse

func (m *Merkle) Traverse()

Traverse refreshes auth and stacks and increment leafe number.

func (*Merkle) UnmarshalJSON

func (m *Merkle) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON to Merkle.

type NH

type NH struct {
	// contains filtered or unexported fields
}

NH represents a node in a merkle tree.

func (*NH) DecodeMsgpack

func (nn *NH) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack unmarshals NH.

func (*NH) EncodeMsgpack

func (nn *NH) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack marshals NH into valid msgpack.

func (*NH) MarshalJSON

func (nn *NH) MarshalJSON() ([]byte, error)

MarshalJSON marshals NH into valid JSON.

func (*NH) UnmarshalJSON

func (nn *NH) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals NH .

type PrivKey

type PrivKey struct {
	// contains filtered or unexported fields
}

PrivKey is a private key of XMSS.

func (*PrivKey) DecodeMsgpack

func (x *PrivKey) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack unmarshals msgpack to PrivKey.

func (*PrivKey) EncodeMsgpack

func (x *PrivKey) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack marshals PrivKey into valid msgpack.

func (*PrivKey) MarshalJSON

func (x *PrivKey) MarshalJSON() ([]byte, error)

MarshalJSON marshals PrivKey into valid JSON.

func (*PrivKey) UnmarshalJSON

func (x *PrivKey) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON to PrivKey.

type PrivKeyMT

type PrivKeyMT struct {
	// contains filtered or unexported fields
}

PrivKeyMT is a private key of XMSS^MT.

func NewPrivKeyMT

func NewPrivKeyMT(seed []byte, h, d uint32) (*PrivKeyMT, error)

NewPrivKeyMT returns XMSS^MT private key.

func (*PrivKeyMT) DecodeMsgpack

func (p *PrivKeyMT) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack unmarshals msgpack to PrivKey.

func (*PrivKeyMT) EncodeMsgpack

func (p *PrivKeyMT) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack marshals PrivKeyMT into valid msgpack.

func (*PrivKeyMT) LeafNo

func (p *PrivKeyMT) LeafNo() uint64

LeafNo returns the leaf no in xmss^mt.

func (*PrivKeyMT) MarshalJSON

func (p *PrivKeyMT) MarshalJSON() ([]byte, error)

MarshalJSON marshals PrivKeyMT into valid JSON.

func (*PrivKeyMT) PublicKey

func (p *PrivKeyMT) PublicKey() []byte

PublicKey returns public key (merkle root) of XMSS^MT

func (*PrivKeyMT) SetLeafNo

func (p *PrivKeyMT) SetLeafNo(n uint64) error

SetLeafNo sets the leaf no in merkle and refresh authes..

func (*PrivKeyMT) Sign

func (p *PrivKeyMT) Sign(msg []byte) []byte

Sign signs by XMSS with XMSS^MT.

func (*PrivKeyMT) UnmarshalJSON

func (p *PrivKeyMT) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON to PrivKeyMT.

type PublicKey

type PublicKey struct {
	Height byte
	Root   []byte
	Seed   []byte
}

PublicKey for xmss

func DeserializePK

func DeserializePK(key []byte) (*PublicKey, error)

DeserializePK deserialized bytes to XMSS PublicKey.

func (*PublicKey) Serialize

func (p *PublicKey) Serialize() []byte

Serialize returns serialized bytes of XMSS PublicKey.

type PublicKeyMT

type PublicKeyMT struct {
	H    uint32
	D    uint32
	Root []byte
	Seed []byte
}

PublicKeyMT for xmss^MT

func DeserializeMT

func DeserializeMT(key []byte) (*PublicKeyMT, error)

DeserializeMT deserialized bytes to XMSS^MT PublicKey.

func (*PublicKeyMT) Serialize

func (p *PublicKeyMT) Serialize() ([]byte, error)

Serialize returns serialized bytes of XMSS^MT PublicKey.

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack is a stack to use in merkle traversing.

func (*Stack) DecodeMsgpack

func (s *Stack) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack unmarshals Stack to msgpack.

func (*Stack) EncodeMsgpack

func (s *Stack) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack marshals Stack into valid msgpack.

func (*Stack) MarshalJSON

func (s *Stack) MarshalJSON() ([]byte, error)

MarshalJSON marshals Stack into valid JSON.

func (*Stack) UnmarshalJSON

func (s *Stack) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals Stack to JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL