bloomfilter

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMetadataLen = errors.Errorf("Metadata size is incorrect, " +
	"does not match passed size")
View Source
var ErrInvalidSealedLen = errors.Errorf("Sealed data size is incorrect, " +
	"does not match the expected size")
View Source
var ErrKeySize = errors.Errorf("key size must be %d", chacha20.KeySize)
View Source
var ErrNonceSize = errors.Errorf("nonce size must be %d", chacha20.NonceSizeX)

Functions

This section is empty.

Types

type Sealed

type Sealed interface {
	// Seal encrypts the filter in order to hide metadata, specifically
	// the hamming weight of the filter. it returns the encrypted filter
	// with the appended metadata inside the encrypted payload.
	// Note: the length of the metadata must be the same as
	// the passed size on initialization otherwise an error will
	// be returned
	Seal(metadata []byte) ([]byte, error)

	// Unseal decrypted the sealed filter and stored it in the filter, returning
	// the appended metadata.
	// Will error if the passed in ciphertext is not the correct length of the
	// filter+metadataSize. The size can be retrieved using sealed.SealedSize()
	// Note: the length of the metadata must be the same as
	// the passed size on initialization otherwise an error will
	// be returned
	Unseal(ciphertext []byte) ([]byte, error)

	// Add adds the data to the ring of the bloom filter.
	Add(data []byte)

	// Returns the size of the bloom filter.
	GetSize() uint64

	// Returns the number the hash operations
	GetHashOpCount() uint64

	// Reset clears the ring in the bloom filter.
	Reset()

	// Test returns a bool if the data is in the ring. True
	// indicates that the data may be in the ring, while false
	// indicates that the data is not in the ring.
	Test(data []byte) bool

	// Merge merges the sent Bloom into itself.
	Merge(m Sealed) error

	// Bloom Return the underlying, unencrypted bloom filter.
	Bloom() *bloomfilter.Bloom

	// SealedSize returns the size in bytes of a sealed payload this
	// filter is expecting/ will return
	SealedSize() int
}

func Init

func Init(key, nonce []byte, elements int,
	falsePositive float64, metadataSize uint) (Sealed, error)

Init initializes and returns a new sealed bloom filter, or an error. Given a number of elements, it accurately states if data is not added. Within a falsePositive rate, it will indicate if the data has been added. metadataSize is the size of optional data appended to the bloomfilter which is inside the seal and will be returned on unsealing. It must be known a-priori by both sides

WARNING: the (key, nonce) must never been repeated between bloom filters, otherwise the seal can be trivially decrypted.

func InitByParameters

func InitByParameters(key, nonce []byte, size,
	hashFunctions uint64, metadataSize uint) (Sealed, error)

InitByParameters initializes a sealed bloom filter allowing the user to explicitly set the size of the bit array and the amount of hash functions metadataSize is the size of optional data appended to the bloomfilter which is inside the seal and will be returned on unsealing. It must be known a-priori by both sides

WARNING: the (key, nonce) must never been repeated between bloom filters, otherwise the seal can be trivially decrypted.

Jump to

Keyboard shortcuts

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