oprf

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package oprf implements the Elliptic Curve Oblivious Pseudorandom Function (EC-OPRF) from https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-16.html

Example (Oprf)
suite := SuiteP256Sha256
//   Server(sk, pk, info*)
private, err := GenerateKey(suite)
if err != nil {
	log.Fatalln(err)
}

server, err := NewServer(suite, private)
if err != nil {
	log.Fatalln(err)
}

//   Client(info*)
client, err := NewClient(suite)
if err != nil {
	log.Fatalln(err)
}
//   =================================================================
//   finData, evalReq = Blind(input)
inputs := [][]byte{[]byte("first input"), []byte("second input")}

finData, evalReq, err := client.Blind(inputs)
if err != nil {
	log.Fatalln(err)
}
//
//                               evalReq
//                             ---------->
//
//                               evaluation = Evaluate(evalReq, info*)
evaluation, err := server.BlindEvaluate(evalReq)
if err != nil {
	log.Fatalln(err)
}
//
//                              evaluation
//                             <----------
//
//   output = Finalize(finData, evaluation, info*)
outputs, err := client.Finalize(finData, evaluation)
fmt.Print(err == nil && len(inputs) == len(outputs))
Output:

true

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSuite indicates that given oprf suite is not supported
	ErrInvalidSuite = errors.New("oprf: invalid suite")
	// ErrInvalidMode indicates that given oprf mode is not supported
	ErrInvalidMode = errors.New("oprf: invalid mode")
	// ErrDeriveKeyError indicates that key derivation operation failed
	ErrDeriveKeyError = errors.New("oprf: key derivation failed")
	// ErrInvalidInput indicates that given input value produces identity element
	ErrInvalidInput = errors.New("oprf: blind input produces an invalid output element")
	// ErrVerify indicates that proof verification failed
	ErrVerify = errors.New("oprf: verifiable OPRF proof verification failed")
	// ErrInputValidation indicates that given inputs are not suitable
	ErrInputValidation = errors.New("oprf: validation of inputs failed")
	// ErrEmptyKey indicates that given key is nil or empty
	ErrEmptyKey = errors.New("oprf: empty key")
)

Functions

This section is empty.

Types

type Client

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

Client is oprf client instance with mode ModeOPRF

func NewClient

func NewClient(s Suite) (*Client, error)

NewClient returns new instance of oprf client with mode ModeOPRF

func (*Client) Blind

func (c *Client) Blind(inputs [][]byte) (*FinalizeData, *EvaluationRequest, error)

Blind function blinding given inputs, returns FinalizeData for Finaliza function and EvaluationRequest to send server

func (*Client) DeterministicBlind

func (c *Client) DeterministicBlind(inputs [][]byte, blinds []*eccgroup.Scalar) (*FinalizeData, *EvaluationRequest, error)

DeterministicBlind is doing same thing with Blind but with given blinds

func (*Client) Finalize

func (c *Client) Finalize(finData *FinalizeData, evalRes *EvaluationResponse) ([][]byte, error)

Finalize function implements the final step of OPRF evaluation

type EvaluationRequest

type EvaluationRequest struct {
	BlindedElements []*eccgroup.Element
}

EvaluationRequest identify the message send from client to server for Evaluation operation

type EvaluationResponse

type EvaluationResponse struct {
	Proof             []byte
	EvaluatedElements []*eccgroup.Element
}

EvaluationResponse identify the message send from server to client as evaluation operation response

type FinalizeData

type FinalizeData struct {
	EvalRequest *EvaluationRequest
	Inputs      [][]byte
	Blinds      []*eccgroup.Scalar
}

FinalizeData identify the state to keep on client

type ModeType

type ModeType uint8

ModeType is type identifier for OPRF Modes constants https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-12.html#name-configuration

const (
	ModeOPRF  ModeType = 0x00 //nolint:revive //no need
	ModeVOPRF ModeType = 0x01 //nolint:revive //no need
	ModePOPRF ModeType = 0x02 //nolint:revive //no need
)

type PartialObliviousClient

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

PartialObliviousClient is oprf client instance with mode ModePOPRF

func NewPartialObliviousClient

func NewPartialObliviousClient(s Suite, sPub *PublicKey) (*PartialObliviousClient, error)

NewPartialObliviousClient returns new instance of oprf client with mode ModePOPRF

func (*PartialObliviousClient) Blind

func (c *PartialObliviousClient) Blind(inputs [][]byte, info []byte) (*FinalizeData, *EvaluationRequest, error)

Blind function blinding given inputs, returns FinalizeData for Finaliza function and EvaluationRequest to send server

func (*PartialObliviousClient) DeterministicBlind

func (c *PartialObliviousClient) DeterministicBlind(inputs [][]byte, blinds []*eccgroup.Scalar, info []byte) (*FinalizeData, *EvaluationRequest, error)

DeterministicBlind is doing same thing with Blind but with given blinds

func (*PartialObliviousClient) Finalize

func (c *PartialObliviousClient) Finalize(finData *FinalizeData, evalRes *EvaluationResponse, info []byte) ([][]byte, error)

Finalize function implements the final step of POPRF evaluation

type PartialObliviousServer

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

PartialObliviousServer is oprf server instance with mode ModePOPRF

func NewPartialObliviousServer

func NewPartialObliviousServer(s Suite, privKey *PrivateKey) (*PartialObliviousServer, error)

NewPartialObliviousServer returns new instance of oprf server with mode ModePOPRF

func (*PartialObliviousServer) BlindEvaluate

func (s *PartialObliviousServer) BlindEvaluate(evalReq *EvaluationRequest, info []byte) (*EvaluationResponse, error)

BlindEvaluate evaluates blinded elements

func (*PartialObliviousServer) FinalEvaluate

func (s *PartialObliviousServer) FinalEvaluate(input, info []byte) ([]byte, error)

FinalEvaluate is generating expected finalize output

func (PartialObliviousServer) PublicKey

func (s PartialObliviousServer) PublicKey() *PublicKey

func (*PartialObliviousServer) VerifyFinalize

func (s *PartialObliviousServer) VerifyFinalize(input, info, exptectedOutput []byte) bool

VerifyFinalize verifies finalize output is expected or not

type PrivateKey

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

PrivateKey identify the private key according to group

func DeriveKey

func DeriveKey(s Suite, mode ModeType, seed, info []byte) (*PrivateKey, error)

DeriveKey generates a private key from a given seed and optional info string.

func GenerateKey

func GenerateKey(s Suite) (*PrivateKey, error)

GenerateKey generates a private key compatible with the suite.

func (*PrivateKey) MarshalBinary

func (priv *PrivateKey) MarshalBinary() ([]byte, error)

MarshalBinary marshals the private key to bytes

func (*PrivateKey) MarshalText

func (priv *PrivateKey) MarshalText() ([]byte, error)

MarshalText marshals the private key to base64 encoded bytes

func (*PrivateKey) Public

func (priv *PrivateKey) Public() *PublicKey

Public returns corresponding public key

func (*PrivateKey) UnmarshalBinary

func (priv *PrivateKey) UnmarshalBinary(s Suite, data []byte) error

UnmarshalBinary unmarshals given data to PrivateKey struct according to given suite

func (*PrivateKey) UnmarshalText

func (priv *PrivateKey) UnmarshalText(s Suite, text []byte) error

UnmarshalText unmarshals given data to PrivateKey struct according to given suite

type PublicKey

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

PublicKey identify the public key according to group

func (*PublicKey) MarshalBinary

func (pub *PublicKey) MarshalBinary() ([]byte, error)

MarshalBinary marshals the public key to bytes

func (*PublicKey) MarshalText

func (pub *PublicKey) MarshalText() ([]byte, error)

MarshalText marshals the public key to base64 encoded bytes

func (*PublicKey) UnmarshalBinary

func (pub *PublicKey) UnmarshalBinary(s Suite, data []byte) error

UnmarshalBinary unmarshals given data to PublicKey struct according to given suite

func (*PublicKey) UnmarshalText

func (pub *PublicKey) UnmarshalText(s Suite, text []byte) error

UnmarshalText unmarshals given data to PublicKey struct according to given suite

type Server

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

Server is oprf server instance with mode ModeOPRF

func NewServer

func NewServer(s Suite, privKey *PrivateKey) (*Server, error)

NewServer returns new instance of oprf server with mode ModeOPRF

func (*Server) BlindEvaluate

func (s *Server) BlindEvaluate(evalReq *EvaluationRequest) (*EvaluationResponse, error)

BlindEvaluate evaluates blinded elements

func (*Server) FinalEvaluate

func (s *Server) FinalEvaluate(input []byte) ([]byte, error)

FinalEvaluate is generating expected finalize output

func (Server) PublicKey

func (s Server) PublicKey() *PublicKey

func (*Server) VerifyFinalize

func (s *Server) VerifyFinalize(input, exptectedOutput []byte) bool

VerifyFinalize verifies finalize output is expected or not

type Suite

type Suite interface {
	String() string
	SuiteID() int
	Group() eccgroup.Group
	Hash() hash.Hashing
	// contains filtered or unexported methods
}

Suite is an interface that identify underlying prime-order curve and hash

var (
	// SuiteRistretto255Sha512 suite identify the OPRF with Ristretto255 and SHA512.
	// See https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-12.html#name-oprfristretto255-sha-512
	SuiteRistretto255Sha512 Suite = &suite{suiteID: 0x0001, group: eccgroup.Ristretto255Sha512, hash: hash.SHA512, strRep: "OPRF(ristretto255, SHA-512)"}

	// SuiteP256Sha256 suite identify the OPRF with P256 and SHA256.
	// See https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-12.html#name-oprfp-256-sha-256
	SuiteP256Sha256 Suite = &suite{suiteID: 0x0003, group: eccgroup.P256Sha256, hash: hash.SHA256, strRep: "OPRF(P-256, SHA-256)"}

	// SuiteP384Sha384 suite identify the OPRF with P384 and SHA384.
	// https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-12.html#name-oprfp-384-sha-384
	SuiteP384Sha384 Suite = &suite{suiteID: 0x0004, group: eccgroup.P384Sha384, hash: hash.SHA384, strRep: "OPRF(P-384, SHA-384)"}

	// SuiteP521Sha512 suite identify the OPRF with P521 and SHA512.
	// See https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-12.html#name-oprfp-521-sha-512
	SuiteP521Sha512 Suite = &suite{suiteID: 0x0005, group: eccgroup.P521Sha512, hash: hash.SHA512, strRep: "OPRF(P-521, SHA-512)"}
)

type VerifiableClient

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

VerifiableClient is oprf client instance with mode ModeVOPRF

func NewVerifiableClient

func NewVerifiableClient(s Suite, sPub *PublicKey) (*VerifiableClient, error)

NewVerifiableClient returns new instance of oprf client with mode ModeVOPRF

func (*VerifiableClient) Blind

func (c *VerifiableClient) Blind(inputs [][]byte) (*FinalizeData, *EvaluationRequest, error)

Blind function blinding given inputs, returns FinalizeData for Finaliza function and EvaluationRequest to send server

func (*VerifiableClient) DeterministicBlind

func (c *VerifiableClient) DeterministicBlind(inputs [][]byte, blinds []*eccgroup.Scalar) (*FinalizeData, *EvaluationRequest, error)

DeterministicBlind is doing same thing with Blind but with given blinds

func (*VerifiableClient) Finalize

func (c *VerifiableClient) Finalize(finData *FinalizeData, evalRes *EvaluationResponse) ([][]byte, error)

Finalize function implements the final step of VOPRF evaluation

type VerifiableServer

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

VerifiableServer is oprf server instance with mode ModeVOPRF

func NewVerifiableServer

func NewVerifiableServer(s Suite, privKey *PrivateKey) (*VerifiableServer, error)

NewVerifiableServer returns new instance of oprf server with mode ModeVOPRF

func (*VerifiableServer) BlindEvaluate

func (s *VerifiableServer) BlindEvaluate(evalReq *EvaluationRequest) (*EvaluationResponse, error)

BlindEvaluate evaluates blinded elements

func (*VerifiableServer) FinalEvaluate

func (s *VerifiableServer) FinalEvaluate(input []byte) ([]byte, error)

FinalEvaluate is generating expected finalize output

func (VerifiableServer) PublicKey

func (s VerifiableServer) PublicKey() *PublicKey

func (*VerifiableServer) VerifyFinalize

func (s *VerifiableServer) VerifyFinalize(input, exptectedOutput []byte) bool

VerifyFinalize verifies finalize output is expected or not

Jump to

Keyboard shortcuts

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