challengebypassristrettoffi

package module
v0.0.0-...-3e22c06 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MPL-2.0 Imports: 4 Imported by: 4

README

challenge-bypass-ristretto-ffi Build Status

A FFI crate, C++ and Golang wrappers to expose functionality from challenge-bypass-ristretto

The challenge-bypass-ristretto crate implements a form of blinded tokens using a VOPRF protocol in rust. This crate exposes C FFI functions and is configured to produce a static library so that the functionality can be used in other languages.

Currently there are bindings for C++ and Golang.

Notes

The FFI crate handles all allocation of blinded token structures, returning a pointer to the underlying memory using Box::into_raw(Box::new(...)). Correspondingly, there are destructor functions to free the memory for each structure. The higher level bindings take care to ensure that these destructors are automatically called, any new bindings added should take care to do the same.

No direct introspection / modification of the Rust allocated objects from external bindings is allowed. The C header exposes only an opaque pointer to the Rust allocated objects.

Other than the destructor no FFI functions exposed mutate or take ownership of the passed structures.

Error handling at the C FFI layer is done via a thread local variable LAST_ERROR which is set when an error occurs. For most functions, a NULL return is indicative of an error. For verification functions that would normally return a bool, an int is returned instead. In these cases -1 indicates an error.

Convenience functions are included to handle encoding / decoding structures to / from base64.

UTF-8 strings are expected in all places strings are passed. These bindings do not attempt to address cross-platform string differences such as UTF-16 on windows.

Cbindgen was used to generate the C header file.

This crate instantiates challenge-bypass-ristretto with Sha512 as the hash and rand::OsRng as the cryptographically secure random number generator.

The C++ bindings can optionally be built with exceptions turned off. This is intended for interoperability with Chromium which by default does not use exceptions. If exceptions are turned off, instead of being thrown exceptions are assigned to a thread local variable. The exception_occured() function must be called after every function call and if an error occurred the get_last_exception() function can be called to retrieve and clear the exception.

Development

Working on this repository requires having Rust, Go 1.11, g++, musl and valgrind to be installed. Alternatively - Rust, g++ / valgrind and Docker can be used as there is a Dockerfile for building and testing the Golang bindings.

Testing

There are end to end test binaries for the C++ and Golang bindings, when run under valgrind we can ensure memory is being properly freed.

C++

Running e2e test
make examples/cpp.out
valgrind --leak-check=yes --error-exitcode=1 ./examples/cpp.out

Golang

Running e2e test
make examples/golang.dyn.out
valgrind --suppressions=.valgrind.supp --run-libc-freeres=no --leak-check=yes --undef-value-errors=no --error-exitcode=1 examples/golang.dyn.out
Running e2e test with Docker
make go-docker-test

Regenerating the C header

cbindgen -o src/lib.h

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchDLEQProof

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

BatchDLEQProof shows many points were signed by the same signing key as a particular PublicKey

func NewBatchDLEQProof

func NewBatchDLEQProof(blindedTokens []*BlindedToken, signedTokens []*SignedToken, key *SigningKey) (*BatchDLEQProof, error)

NewBatchDLEQProof showing each SignedToken is the result of signing the corresponding BlindedToken with the given SigningKey

func (*BatchDLEQProof) MarshalText

func (proof *BatchDLEQProof) MarshalText() ([]byte, error)

MarshalText marshalls the verification signature into text.

func (*BatchDLEQProof) UnmarshalText

func (proof *BatchDLEQProof) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the unblinded token from text.

func (*BatchDLEQProof) Verify

func (proof *BatchDLEQProof) Verify(blindedTokens []*BlindedToken, signedTokens []*SignedToken, publicKey *PublicKey) (bool, error)

Verify that the BatchDLEQProof shows each SignedToken is a BlindedToken signed by the same SigningKey as PublicKey

func (*BatchDLEQProof) VerifyAndUnblind

func (proof *BatchDLEQProof) VerifyAndUnblind(tokens []*Token, blindedTokens []*BlindedToken, signedTokens []*SignedToken, publicKey *PublicKey) ([]*UnblindedToken, error)

VerifyAndUnblind each SignedToken if the BatchDLEQProof is valid

type BlindedToken

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

BlindedToken is sent to the server for signing.

func (*BlindedToken) MarshalText

func (t *BlindedToken) MarshalText() ([]byte, error)

MarshalText marshalls the blinded token into text.

func (*BlindedToken) UnmarshalText

func (t *BlindedToken) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the blinded token from text.

type DLEQProof

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

DLEQProof shows a point was signed by the same signing key as a particular PublicKey

func NewDLEQProof

func NewDLEQProof(blindedToken *BlindedToken, signedToken *SignedToken, key *SigningKey) (*DLEQProof, error)

NewDLEQProof showing SignedToken is the result of signing BlindedToken with the given SigningKey

func (*DLEQProof) MarshalText

func (proof *DLEQProof) MarshalText() ([]byte, error)

MarshalText marshalls the verification signature into text.

func (*DLEQProof) UnmarshalText

func (proof *DLEQProof) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the unblinded token from text.

func (*DLEQProof) Verify

func (proof *DLEQProof) Verify(blindedToken *BlindedToken, signedToken *SignedToken, publicKey *PublicKey) (bool, error)

Verify that the DLEQProof shows the SignedToken is BlindedToken signed by the same SigningKey as PublicKey

type PublicKey

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

PublicKey is a committment by the server to a particular SigningKey.

func (*PublicKey) MarshalText

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

MarshalText marshalls the verification signature into text.

func (*PublicKey) UnmarshalText

func (t *PublicKey) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the unblinded token from text.

type SignedToken

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

SignedToken is the result of signing a BlindedToken.

func (*SignedToken) MarshalText

func (t *SignedToken) MarshalText() ([]byte, error)

MarshalText marshalls the signed token into text.

func (*SignedToken) UnmarshalText

func (t *SignedToken) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the signed token from text.

type SigningKey

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

SigningKey is used to sign a BlindedToken and verify an UnblindedToken.

This is a server secret and should NEVER be revealed to the client.

func RandomSigningKey

func RandomSigningKey() (*SigningKey, error)

RandomSigningKey generates a new random `SigningKey` using the os random number generator.

func (*SigningKey) MarshalText

func (k *SigningKey) MarshalText() ([]byte, error)

MarshalText marshalls the signing key into text.

func (*SigningKey) PublicKey

func (k *SigningKey) PublicKey() *PublicKey

PublicKey returns the public key associated with this SigningKey

func (*SigningKey) RederiveUnblindedToken

func (k *SigningKey) RederiveUnblindedToken(t *TokenPreimage) *UnblindedToken

RederiveUnblindedToken via the token preimage of the provided UnblindedToken

func (*SigningKey) Sign

func (k *SigningKey) Sign(t *BlindedToken) (*SignedToken, error)

Sign the provided BlindedToken.

func (*SigningKey) UnmarshalText

func (k *SigningKey) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the signing key from text.

type Token

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

Token consists of a randomly chosen preimage and blinding factor.

func RandomToken

func RandomToken() (*Token, error)

RandomToken generates a new random `Token` using the os random number generator.

func (*Token) Blind

func (t *Token) Blind() *BlindedToken

Blind the Token, returning a BlindedToken to be sent to the server.

func (*Token) MarshalText

func (t *Token) MarshalText() ([]byte, error)

MarshalText marshalls the token into text.

func (*Token) UnmarshalText

func (t *Token) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the token from text.

type TokenPreimage

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

TokenPreimage is a slice of bytes which can be hashed to a `RistrettoPoint`.

func (*TokenPreimage) MarshalText

func (t *TokenPreimage) MarshalText() ([]byte, error)

MarshalText marshalls the token preimage into text.

func (*TokenPreimage) UnmarshalText

func (t *TokenPreimage) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the token preimage from text.

type UnblindedToken

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

UnblindedToken is the result of unblinding a SignedToken.

func (*UnblindedToken) DeriveVerificationKey

func (t *UnblindedToken) DeriveVerificationKey() *VerificationKey

DeriveVerificationKey for this particular UnblindedToken

func (*UnblindedToken) MarshalText

func (t *UnblindedToken) MarshalText() ([]byte, error)

MarshalText marshalls the unblinded token into text.

func (*UnblindedToken) Preimage

func (t *UnblindedToken) Preimage() *TokenPreimage

Preimage returns the TokenPreimage for this particular UnblindedToken

func (*UnblindedToken) UnmarshalText

func (t *UnblindedToken) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the unblinded token from text.

type VerificationKey

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

VerificationKey is the shared key for proving / verifying the validity of an UnblindedToken.

func (*VerificationKey) Sign

func (k *VerificationKey) Sign(message string) (*VerificationSignature, error)

Sign a message, producing a VerificationSignature

func (*VerificationKey) Verify

func (k *VerificationKey) Verify(sig *VerificationSignature, message string) (bool, error)

Verify that the signature of a message matches the provided `VerificationSignature`

type VerificationSignature

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

VerificationSignature which can be verified given the VerificationKey and message

func (*VerificationSignature) MarshalText

func (t *VerificationSignature) MarshalText() ([]byte, error)

MarshalText marshalls the verification signature into text.

func (*VerificationSignature) UnmarshalText

func (t *VerificationSignature) UnmarshalText(bytes []byte) error

UnmarshalText unmarshalls the unblinded token from text.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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