cl

package
v0.0.0-...-eab8366 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2020 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAttrs

func ParseAttrs(specs map[string]interface{}) ([]CredAttr, *AttrCount, error)

FIXME make nicer Hook to organization?

func ReadGob

func ReadGob(filePath string, object interface{}) error

func WriteGob

func WriteGob(filePath string, object interface{}) error

TODO: where should we put WriteGob and ReadGob?

Types

type AttrCount

type AttrCount struct {
	Known     int
	Committed int
	Hidden    int
}

AttrCount holds the number of known, committed and hidden parameters.

func NewAttrCount

func NewAttrCount(known, committed, hidden int) *AttrCount

func (*AttrCount) String

func (c *AttrCount) String() string

type Attrs

type Attrs struct {
	// attributes that are known to the credential receiver and issuer
	Known []*big.Int
	// attributes which are known only to the credential receiver
	Hidden []*big.Int
	// attributes for which the issuer knows only commitment
	Committed []*big.Int
}

func NewAttrs

func NewAttrs(known, committed, hidden []*big.Int) *Attrs

type Cred

type Cred struct {
	A   *big.Int
	E   *big.Int
	V11 *big.Int
}

Cred represents anonymous credentials.

func NewCred

func NewCred(A, e, v11 *big.Int) *Cred

type CredAttr

type CredAttr interface {
	GetValue() interface{}
	FromInternalValue(*big.Int) (interface{}, error)
	UpdateValue(interface{}) error
	InternalValue() *big.Int
	SetInternalValue() error
	IsKnown() bool
	HasVal() bool
	GetName() string
	String() string
}

CredAttr represents an attribute for the CL scheme.

type CredManager

type CredManager struct {
	Params  *Params
	PubKey  *PubKey
	RawCred *RawCred

	Nym *big.Int

	Attrs              *Attrs
	CommitmentsOfAttrs []*big.Int // commitments of committedAttrs
	// V1 is a random element in credential - it is generated in GetCredRequest and needed when
	// proving the possesion of a credential - this is why it is stored in User and not in UserCredentialReceiver
	V1 *big.Int // v1 is random element in U; U = S^v1 * R_i^m_i where m_i are hidden attributes

	CredReqNonce *big.Int
	// contains filtered or unexported fields
}

CredManager manages a single instance of anonymous credential.

An instance of this struct should be created by a user before she wants a new credential to be issued, or an existing one to be updated or proved.

When a user needs a new credential under a new nym, she also needs a new instance of CredManager.

func NewCredManager

func NewCredManager(params *Params, pubKey *PubKey,
	masterSecret *big.Int, rawCred *RawCred) (*CredManager, error)

func (*CredManager) BuildProof

func (m *CredManager) BuildProof(cred *Cred, revealedKnownAttrsIndices,
	revealedCommitmentsOfAttrsIndices []int, nonceOrg *big.Int) (*Cred,
	*qr.RepresentationProof, error)

BuildProof builds a proof of knowledge for the given credential.

func (*CredManager) FilterAttributes

func (m *CredManager) FilterAttributes(revealedKnownAttrsIndices,
	revealedCommitmentsOfAttrsIndices []int) ([]*big.Int, []*big.Int)

FilterAttributes returns only attributes to be revealed to the verifier.

func (*CredManager) GetCredRequest

func (m *CredManager) GetCredRequest(nonceOrg *big.Int) (*CredRequest, error)

GetCredRequest computes U and returns CredRequest which contains: - proof data for proving that nym was properly generated, - U and proof data that U was properly generated, - proof data for proving the knowledge of opening for commitments of attributes (for those attributes for which the committed value is known).

func (*CredManager) GetProofChallenge

func (m *CredManager) GetProofChallenge(credProofRandomData, nonceOrg *big.Int) *big.Int

func (*CredManager) Update

func (m *CredManager) Update(c *RawCred)

Update updates credential.

func (*CredManager) Verify

func (m *CredManager) Verify(cred *Cred, AProof *qr.RepresentationProof) (bool, error)

Verify verifies anonymous credential cred, returning a boolean indicating success or failure of credential verification. When verification process fails due to misconfiguration, error is returned.

type CredRequest

type CredRequest struct {
	Nym                      *big.Int
	KnownAttrs               []*big.Int
	CommitmentsOfAttrs       []*big.Int
	NymProof                 *schnorr.Proof
	U                        *big.Int
	UProof                   *qr.RepresentationProof
	CommitmentsOfAttrsProofs []*df.OpeningProof
	Nonce                    *big.Int
}

func NewCredRequest

func NewCredRequest(nym *big.Int, knownAttrs, commitmentsOfAttrs []*big.Int, nymProof *schnorr.Proof,
	U *big.Int, UProof *qr.RepresentationProof,
	commitmentsOfAttrsProofs []*df.OpeningProof, nonce *big.Int) *CredRequest

type CredResult

type CredResult struct {
	Cred   *Cred
	AProof *qr.RepresentationProof
	Record *ReceiverRecord
}

type Int64Attr

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

func NewEmptyInt64Attr

func NewEmptyInt64Attr(name string, known bool) *Int64Attr

func NewInt64Attr

func NewInt64Attr(name string, val int64, known bool) (*Int64Attr,
	error)

func (*Int64Attr) FromInternalValue

func (a *Int64Attr) FromInternalValue(val *big.Int) (interface{}, error)

func (Int64Attr) GetName

func (a Int64Attr) GetName() string

func (*Int64Attr) GetValue

func (a *Int64Attr) GetValue() interface{}

func (Int64Attr) HasVal

func (a Int64Attr) HasVal() bool

func (Int64Attr) InternalValue

func (a Int64Attr) InternalValue() *big.Int

func (Int64Attr) IsKnown

func (a Int64Attr) IsKnown() bool

func (*Int64Attr) SetInternalValue

func (a *Int64Attr) SetInternalValue() error

func (*Int64Attr) String

func (a *Int64Attr) String() string

func (*Int64Attr) UpdateValue

func (a *Int64Attr) UpdateValue(n interface{}) error

type KeyPair

type KeyPair struct {
	Sec *SecKey
	Pub *PubKey
}

TODO probably doesn't make much sense if sec is unexported, remove

func GenerateKeyPair

func GenerateKeyPair(p *Params, attrs *AttrCount) (*KeyPair, error)

GenerateKeyPair takes and constructs a keypair containing public and secret key for the CL scheme.

type MockRecordManager

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

MockRecordManager is a mock implementation of the ReceiverRecordManager interface. It stores key-value pairs of nyms and corresponding receiver records in a map.

func NewMockRecordManager

func NewMockRecordManager() *MockRecordManager

NewMockRecordManager initializes the map that will hold the data.

func (*MockRecordManager) Load

func (rm *MockRecordManager) Load(nym *big.Int) (*ReceiverRecord, error)

func (*MockRecordManager) Store

func (rm *MockRecordManager) Store(nym *big.Int, r *ReceiverRecord) error

type Org

type Org struct {
	Params *Params
	Group  *qr.RSASpecial // in this group attributes will be used as exponents (basis is PubKey.Rs...)

	U         *big.Int
	UVerifier *qr.RepresentationVerifier
	Keys      *KeyPair
	// contains filtered or unexported fields
}

func LoadOrg

func LoadOrg(pubKeyPath, secKeyPath string) (*Org, error)

FIXME

func NewOrg

func NewOrg(params *Params, attrCount *AttrCount) (*Org, error)

func NewOrgFromParams

func NewOrgFromParams(params *Params, keys *KeyPair) (*Org, error)

FIXME

func (*Org) GenNonce

func (o *Org) GenNonce() *big.Int

func (*Org) GetCredIssueNonce

func (o *Org) GetCredIssueNonce() *big.Int

func (*Org) GetProveCredNonce

func (o *Org) GetProveCredNonce() *big.Int

func (*Org) IssueCred

func (o *Org) IssueCred(cr *CredRequest) (*CredResult, error)

func (*Org) ProveCred

func (o *Org) ProveCred(A *big.Int, proof *qr.RepresentationProof,
	revealedKnownAttrsIndices, revealedCommitmentsOfAttrsIndices []int,
	revealedKnownAttrs, revealedCommitmentsOfAttrs []*big.Int) (bool, error)

ProveCred proves the possession of a valid credential and reveals only the attributes the user desires to reveal. Which knownAttrs and commitmentsOfAttrs are to be revealed are given by revealedKnownAttrsIndices and revealedCommitmentsOfAttrsIndices parameters. Parameters knownAttrs and commitmentsOfAttrs must contain only known attributes and commitments of attributes (of attributes for which only commitment is known) which are to be revealed to the organization.

func (*Org) UpdateCred

func (o *Org) UpdateCred(nym *big.Int, rec *ReceiverRecord, nonceUser *big.Int, newKnownAttrs []*big.Int) (*CredResult, error)

type Params

type Params struct {
	// There are only a few possibilities for RhoBitLen. 256 implies that the modulus
	// bit length is 2048
	RhoBitLen         int // bit length of order of the commitment group
	NLength           int // bit length of RSA modulus
	KnownAttrsNum     int // number of attributes known to both - credential issuer and receiver
	CommittedAttrsNum int // number of attributes for which the issuer knows only commitments
	HiddenAttrsNum    int // number of attributes known only to the receiver
	AttrBitLen        int // bit length of attribute
	HashBitLen        int // bit length of hash output used for Fiat-Shamir
	SecParam          int // security parameter
	EBitLen           int // size of e values of certificates
	E1BitLen          int // size of the interval the e values are taken from
	VBitLen           int // size of the v values of the certificates
	ChallengeSpace    int // bit length of challenges for DF commitment proofs
}

Params presents parameters that organization (which is issuing credentials) needs to set.

func GetDefaultParamSizes

func GetDefaultParamSizes() *Params

TODO: add method to load params from file or blockchain or wherever they will be stored.

type PubKey

type PubKey struct {
	N              *big.Int
	S              *big.Int
	Z              *big.Int
	RsKnown        []*big.Int // one R corresponds to one attribute - these attributes are known to both - receiver and issuer
	RsCommitted    []*big.Int // issuer knows only commitments of these attributes
	RsHidden       []*big.Int // only receiver knows these attributes
	PedersenParams *pedersen.Params
	// the fields below are for commitments of the (committed) attributes
	N1 *big.Int
	G  *big.Int
	H  *big.Int
}

PubKey is a public key for the CL scheme.

func NewPubKey

func NewPubKey(g *qr.RSASpecial, p *Params,
	attrs *AttrCount, recv *df.Receiver) (*PubKey,
	error)

NewPubKey accepts group g, parameters p and commitment receiver recv, and returns a public key for the CL scheme.

func (*PubKey) GenerateUserMasterSecret

func (k *PubKey) GenerateUserMasterSecret() *big.Int

GenerateUserMasterSecret generates a secret key that needs to be encoded into every user's credential as a sharing prevention mechanism.

func (*PubKey) GetContext

func (k *PubKey) GetContext() *big.Int

GetContext concatenates public parameters and returns a corresponding number.

type RawCred

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

RawCred represents a credential to be used by application that executes the scheme to prove possesion of an anonymous credential.

func NewRawCred

func NewRawCred(c *AttrCount) *RawCred

func (*RawCred) AddEmptyInt64Attr

func (c *RawCred) AddEmptyInt64Attr(name string, known bool) error

func (*RawCred) AddEmptyStrAttr

func (c *RawCred) AddEmptyStrAttr(name string, known bool) error

func (*RawCred) AddInt64Attr

func (c *RawCred) AddInt64Attr(name string, val int64, known bool) error

func (*RawCred) AddStrAttr

func (c *RawCred) AddStrAttr(name, val string, known bool) error

func (*RawCred) GetAttr

func (c *RawCred) GetAttr(name string) (CredAttr, error)

func (*RawCred) GetAttrInternalIndex

func (c *RawCred) GetAttrInternalIndex(attrName string) (int, error)

func (*RawCred) GetAttrs

func (c *RawCred) GetAttrs() map[int]CredAttr

func (*RawCred) GetCommittedVals

func (c *RawCred) GetCommittedVals() []*big.Int

GetCommittedVals returns *big.Int values of committed attributes. The returned elements are ordered by attribute's index.

func (*RawCred) GetKnownVals

func (c *RawCred) GetKnownVals() []*big.Int

GetKnownVals returns *big.Int values of known attributes. The returned elements are ordered by attribute's index.

type ReceiverRecord

type ReceiverRecord struct {
	KnownAttrs         []*big.Int
	CommitmentsOfAttrs []*big.Int
	Q                  *big.Int
	V11                *big.Int
	Context            *big.Int
}

func NewReceiverRecord

func NewReceiverRecord(knownAttrs, commitmentsOfAttrs []*big.Int, Q, v11, context *big.Int) *ReceiverRecord

Returns ReceiverRecord which contains user data needed when updating the credential for this user.

func (*ReceiverRecord) MarshalBinary

func (r *ReceiverRecord) MarshalBinary() ([]byte, error)

func (*ReceiverRecord) UnmarshalBinary

func (r *ReceiverRecord) UnmarshalBinary(data []byte) error

type ReceiverRecordManager

type ReceiverRecordManager interface {
	// Store stores the nym and the corresponding ReceiverRecord,
	// returning error in case the data was not successfully stored.
	Store(*big.Int, *ReceiverRecord) error

	// Load loads the ReceiverRecord associated with the given
	// nym, returning an error in case no record was found, or
	// in case of error in the interaction with the
	// storage backend.
	Load(*big.Int) (*ReceiverRecord, error)
}

ReceiverRecordManager manages receiver records tied to particular nyms.

type RedisClient

type RedisClient struct {
	*redis.Client
}

RedisClient wraps a redis client in order to interact with the redis database for management of receiver records.

func NewRedisClient

func NewRedisClient(c *redis.Client) *RedisClient

NewRedisClient accepts an instance of redis.Client and returns an instance of RedisClient.

func (*RedisClient) Load

func (m *RedisClient) Load(nym *big.Int) (*ReceiverRecord, error)

func (*RedisClient) Store

func (m *RedisClient) Store(nym *big.Int, r *ReceiverRecord) error

type SecKey

type SecKey struct {
	RsaPrimes                  *qr.RSASpecialPrimes
	AttributesSpecialRSAPrimes *qr.RSASpecialPrimes
}

SecKey is a secret key for the CL scheme.

func NewSecKey

func NewSecKey(g *qr.RSASpecial, cr *df.Receiver) *SecKey

NewSecKey accepts group g and commitment receiver cr, and returns new secret key for the CL scheme.

type StrAttr

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

func NewEmptyStrAttr

func NewEmptyStrAttr(name string, known bool) *StrAttr

func NewStrAttr

func NewStrAttr(name, val string, known bool) (*StrAttr,
	error)

func (*StrAttr) FromInternalValue

func (a *StrAttr) FromInternalValue(val *big.Int) (interface{}, error)

func (StrAttr) GetName

func (a StrAttr) GetName() string

func (*StrAttr) GetValue

func (a *StrAttr) GetValue() interface{}

func (StrAttr) HasVal

func (a StrAttr) HasVal() bool

func (StrAttr) InternalValue

func (a StrAttr) InternalValue() *big.Int

func (StrAttr) IsKnown

func (a StrAttr) IsKnown() bool

func (*StrAttr) SetInternalValue

func (a *StrAttr) SetInternalValue() error

func (*StrAttr) String

func (a *StrAttr) String() string

func (*StrAttr) UpdateValue

func (a *StrAttr) UpdateValue(s interface{}) error

Jump to

Keyboard shortcuts

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