urs

package module
v0.0.0-...-10a99cf Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 18 Imported by: 0

README

Unique Ring Signatures (URS)

URS can be used to sign plaintext or binaries anonymously (among a group of known users). That is a user can sign a message, hiding among a group of known/registered users, that prevents the verifier from revealing the signer's identity other than knowing that it is in the set of registered users. The size of the set of registered users is flexible. Increasing this number slows down signing and verifying linearly, and also increases the size of the signatures linearly.

Bitcoin public and private keys are used to generate the signatures. You may generate your own keypairs with the set-generate function described below. Bitcoin addresses are also generated.

When in default (unique) mode, signatures are generated with the prefix '1' and contain immutable Hx, Hy values as the first two bigints in the signature. These are immutable per message and private key. That is, any single message signed with the same private key and keyring will always generate the same Hx, Hy values, so for this single message you can identify if multiple members of the keyring have signed (but not which one).

Signature blinding has also been implemented. Blind signatures are prefixed with '2'. While blind signatures lose their Hx, Hy uniqueness, they use an ephemeral key to generate that signature that is afterwards discarded. This will prevents someone in the future from being able to identify which member of the ring signaturesigned the message, even if all private keys for the public keys in the keyring are later revealed.

For more information on signature blinding, refer to this link.

Requirements

Go 1.11 or newer.

Usage

import "github.com/Cealgull/urs"

Acknowledgements

Original Repo

Documentation

Overview

Package urs implements Unique Ring Signatures, as defined in short version: http://csiflabs.cs.ucdavis.edu/~hbzhang/romring.pdf full version: http://eprint.iacr.org/2012/577.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base582Hex

func Base582Hex(b string) []byte

convert base58 to hex bytes

func BlindVerify

func BlindVerify(R *PublicKeyRing, m []byte, rs *BlindRingSign) bool

BlindVerify verifies the signature in rs of m using the public key ring, R. Its return value records whether the signature is valid.

func CmpPubKey

func CmpPubKey(i, j *ecdsa.PublicKey) bool

CmpPubKey compares two pubkeys and returns true if they are the same, else false. WARNING: Assumes the curves are equivalent!

func GenerateKey

func GenerateKey(c elliptic.Curve, rand io.Reader) (priv *ecdsa.PrivateKey, err error)

GenerateKey generates a public and private key pair.

func GetBinaryFileData

func GetBinaryFileData(filename string) ([]byte, error)

GetBinaryFileData retrieves the []byte encoding of a binary file from a path. It hashes the data it obtains sequentially to compress the file.

func GetSigFileData

func GetSigFileData(filename string) ([]byte, error)

GetSigFileData retrieves the []byte encoding of a signature file from a path.

func GetTextFileData

func GetTextFileData(filename string) ([]byte, error)

GetTextFileData retrieves the []byte encoding of a text file from a path.

func Hex2Base58Str

func Hex2Base58Str(val []byte) string

func Hex2Base58String

func Hex2Base58String(val []byte) string

func Hex2Big

func Hex2Big(b []byte) *big.Int

func PubKeyToString

func PubKeyToString(k ecdsa.PublicKey) string

func ReadKeyPair

func ReadKeyPair(filename string) (*ecdsa.PrivateKey, error)

ReadKeyPair reads an ECDSA keypair a file in JSON object format. Example JSON input:

{
  "privkey": "..."
}

It also checks if a pubkey is in the keyring and, if not, appends it to the keyring.

func String2Hex

func String2Hex(s string) []byte

func StripTextFile

func StripTextFile(b []byte) []byte

StripTextFile removes line breaks from a text file to ensure that signatures of text files function correctly cross platform.

func TestBase58

func TestBase58()

TODO: do and test everything

func Verify

func Verify(R *PublicKeyRing, m []byte, rs *RingSign) bool

Verify verifies the signature in rs of m using the public key ring, R. Its return value records whether the signature is valid.

Types

type Base58

type Base58 string

type to hold the Base58 string

func Big2Base58

func Big2Base58(val *big.Int) Base58

encodes big.Int to base58 string

func Hex2Base58

func Hex2Base58(val []byte) Base58

encodes hex bytes into base58

func Int2Base58

func Int2Base58(val int) Base58

encodes int to base58 string

func Str2Hex58

func Str2Hex58(val string) Base58

func StrHex2Base58

func StrHex2Base58(val string) Base58

func String2Base58

func String2Base58(val string) Base58

func StringHex2Base58

func StringHex2Base58(val string) Base58

encodes string stored hex bytes into base58

func (Base58) Base582Big

func (b Base58) Base582Big() *big.Int

func (Base58) Base582Int

func (b Base58) Base582Int() int

convert base58 to int

func (Base58) BitHex

func (b Base58) BitHex() []byte

convert base58 to hexes used by Bitcoins (keeping the zeroes on the front, 25 bytes long)

func (Base58) ToBig

func (b Base58) ToBig() *big.Int

Convert base58 to big.Int

func (Base58) ToHex

func (b Base58) ToHex() []byte

convert base58 to hex bytes

func (Base58) ToInt

func (b Base58) ToInt() int

convert base58 to int

type BlindRingSign

type BlindRingSign struct {
	KX, KY *big.Int

	X, Y *big.Int
	C, T []*big.Int
	// contains filtered or unexported fields
}

func BlindSign

func BlindSign(rand io.Reader,
	priv *ecdsa.PrivateKey,
	R *PublicKeyRing,
	m []byte) (rs *BlindRingSign, err error)

BlindSign signs an arbitrary length message (which should NOT be the hash of a larger message) using the private key, priv and the public key ring, R. It returns the signature as a struct of type RingSign. The security of the private key depends on the entropy of rand. The public keys in the ring must all be using the same curve.

func (*BlindRingSign) FromBase58

func (k *BlindRingSign) FromBase58(sig string) error

FromBase58 returns a ring signature from a Base58 string, to the RingSign struct.

func (*BlindRingSign) ToBase58

func (k *BlindRingSign) ToBase58() string

ToBase58 returns a ring signature as a Base58 string.

type PublicKeyRing

type PublicKeyRing struct {
	Ring []ecdsa.PublicKey
}

PublicKeyRing is a list of public keys.

func NewPublicKeyRing

func NewPublicKeyRing(cap uint) *PublicKeyRing

NewPublicKeyRing creates a new public key ring. All keys added to the ring must use the same curve.

func ReadKeyRing

func ReadKeyRing(filename string, kp *ecdsa.PrivateKey) (*PublicKeyRing, error)

ReadKeyRing reads a key ring of public keys from a file in JSON object format, and also inserts the pubkey of a keypair if it's not already present (handles bug in URS implementation).

func (*PublicKeyRing) Add

func (r *PublicKeyRing) Add(pub ecdsa.PublicKey)

Add adds a public key, pub to the ring. All keys added to the ring must use the same curve.

func (*PublicKeyRing) Bytes

func (r *PublicKeyRing) Bytes() (b []byte)

Bytes returns the public key ring as a byte slice.

func (*PublicKeyRing) Len

func (r *PublicKeyRing) Len() int

Len returns the length of ring.

func (*PublicKeyRing) Less

func (r *PublicKeyRing) Less(i, j int) bool

Less determines which of two []ecdsa.PublicKey X values is smaller; if they are the same, evaluate the Y values instead.

func (*PublicKeyRing) Swap

func (r *PublicKeyRing) Swap(i, j int)

Swap swaps two []ecdsa.PublicKey values.

type RingSign

type RingSign struct {
	X, Y *big.Int
	C, T []*big.Int
}

func Sign

func Sign(rand io.Reader,
	priv *ecdsa.PrivateKey,
	R *PublicKeyRing,
	m []byte) (rs *RingSign, err error)

Sign signs an arbitrary length message (which should NOT be the hash of a larger message) using the private key, priv and the public key ring, R. It returns the signature as a struct of type RingSign. The security of the private key depends on the entropy of rand. The public keys in the ring must all be using the same curve.

func (*RingSign) FromBase58

func (k *RingSign) FromBase58(sig string) error

FromBase58 returns a ring signature from a Base58 string, to the RingSign struct.

func (*RingSign) String

func (k *RingSign) String() string

this is just for debugging; we probably don't want this for anything else

func (*RingSign) ToBase58

func (k *RingSign) ToBase58() string

ToBase58 returns a ring signature as a Base58 string.

Jump to

Keyboard shortcuts

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