cryptutils

package
v0.0.0-...-c4bf151 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: BSD-3-Clause Imports: 6 Imported by: 4

Documentation

Overview

Package cryptutils implements functionality that may be useful to users of the other packages in this library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashToZp

func HashToZp(result *big.Int, buffer []byte) *big.Int

HashToZp hashes the contents of the specified buffer to Zp and stores it in the provided big.Int. The provided big.Int is then returned.

func RandomZp

func RandomZp(result *big.Int) *big.Int

RandomZp samples a random element of Zp and stores it in the provided big.Int. The provided big.Int is then returned.

Types

type Encryptable

type Encryptable struct {
	bls12381.GT
}

Encryptable represents a message that can be encrypted with WKD-IBE. The intended usage is to choose a random message, encrypt that message, and then hash the message to obtain a symmetric key.

func GenerateKey

func GenerateKey(sk []byte) ([]byte, *Encryptable)

GenerateKey generates a random key, and an Encryptable that hashes to that key. The key is written to the provided slice, and that same slice is returned. Note that, while the slice can be of any length, there are only 32 bytes of entropy in the Encryptable

func (*Encryptable) Bytes

func (m *Encryptable) Bytes() []byte

Bytes returns a slice of bytes representing the value of the message. It is a copy of the underlying C memory, so it can be safely mutated. It can be passed to a hash function to hash the message to a symmetric key.

func (*Encryptable) HashToSymmetricKey

func (m *Encryptable) HashToSymmetricKey(sk []byte) []byte

HashToSymmetricKey hashes the encryptable to get a symmetric key. The symmetric key fills the provided slice (which can be of any length, but remember that there are only 32 bytes of entropy in the underlying group element). Returns sthe provided slice.

func (*Encryptable) Marshal

func (m *Encryptable) Marshal() []byte

Marshal does the same thing as Bytes.

func (*Encryptable) Random

func (m *Encryptable) Random() *Encryptable

Random sets the message to a random valid message and returns a pointer to the message on which it was invoked.

func (*Encryptable) Set

func (m *Encryptable) Set(data []byte) bool

Set sets the value of an encryptable to the provided byte slice.

func (*Encryptable) Unmarshal

func (m *Encryptable) Unmarshal(marshalled []byte) bool

Unmarshal does the same thing as Set.

type Signable

type Signable struct {
	Data C.embedded_pairing_core_bigint_256_t
}

Signable represents a message that is signable with WKD-IBE. The intended usage is to hash the message to sign to a Signable, and then pass the Signable to the Sign function.

func (*Signable) Hash

func (m *Signable) Hash(data []byte) *Signable

Hash assigns the value of this Signable to a cryptographic hash of the provided data. The cryptographic hash used is sha256.

func (*Signable) Set

func (m *Signable) Set(data []byte) *Signable

Set sets the value of this signable to the specified byte slice, which must be 32 bytes long. It will automatically "reduce" itself if the specified byte slice represents a value greater than bls12381.GroupOrder.

Jump to

Keyboard shortcuts

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