elgamal

package
v0.0.0-...-2e526cf Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyGen

func KeyGen(pBits int, qBits int, t int, n int) (PublicKey, PrivateKey, []PrivateKeyShare, error)

KeyGen implements key generation for a distributed ElGamal cryptosystem. It is to be executed by a trusted dealer, who can then send out the individual key shares.

Secret sharing is based on polynomials over a finite field.

Parameters: - pBits: Bit length of modulus p of multiplicative group of integers modulo p - qBits: Bit length of prime order of subgroup G over which ElGamal operates - t: Number of secret shares which should be able to reconstruct private key - n: Number of total secret shares to generate

func RandomBits

func RandomBits(bits int) ([]byte, error)

RandomBits returns bits random bits suitable for cryptographic usage.

Bits must be > 2. If bits is not a multiple of 8, the leading bits of the first byte (at index 0) will be forced to 0.

It is also ensured that the two most significant bit are 1. This costs two bits of randomness, but helps with multiplying such numbers together. As such it is not suitable for use with low bit counts.

func Recover

func Recover(pub PublicKey, decryptionShares []DecryptionShare, ctxt Ciphertext) ([]byte, error)

Recover decrypts a ciphertext using t decryption shares.

Types

type Ciphertext

type Ciphertext struct {
	// R = g^x mod p
	R *big.Int
	// C = H(y^r) XOR m
	C []byte
}

Ciphertext represents a ciphertext of the hashed ElGamal cryptosystem.

func Enc

func Enc(pub PublicKey, message []byte) (Ciphertext, error)

Enc encrypts a message using hashed ElGamal.

Parameters: - pub: Public key to use for encryption - message: Message to encrypt. Must be of length hashByteSize

An error is returned if encryption fails.

type DecryptionShare

type DecryptionShare secretshare.Share

DecryptionShare represents a single party's decryption share.

func Dec

func Dec(pub PublicKey, keyShare PrivateKeyShare, ctxt Ciphertext) (DecryptionShare, error)

Dec creates a single decryption share of a ciphertext based on the passed share of the private key.

t of these can be passed to Recover() to decrypt the ciphertext.

type PrivateKey

type PrivateKey struct {
	// Private exponent from (Z / qZ)
	X *big.Int
}

PrivateKey represents a private key of the ElGamal cryptosystem.

type PrivateKeyShare

type PrivateKeyShare secretshare.Share

PrivateKeyShare represents a private key share of the distributed ElGamal cryptosystem.

type PublicKey

type PublicKey struct {
	SchnorrGroup

	// Public key y = g^x mod p
	Y *big.Int
}

PublicKey represents a public key of the ElGamal cryptosystem.

func (*PublicKey) Zp

func (pk *PublicKey) Zp() (gf.GF, error)

Zp returns the finite field (Z / pZ), which G - over which the ElGamal cryptosystem is defined - is a subgroup of.

func (*PublicKey) Zq

func (pk *PublicKey) Zq() (gf.GF, error)

Zq returns the finite field (Z / qZ), which is used in the secret sharing scheme.

type SchnorrGroup

type SchnorrGroup struct {
	// Prime modulus of multiplicative group of integers modulo p, (Z/pZ)*
	P *big.Int
	// Prime order of subgroup G of (Z/pZ)*
	Q *big.Int
	// Generator of subgroup G
	G *big.Int
}

SchnorrGroup represents a q-order subgroup of the multiplicative group of integers modulo p.

func GenerateSchnorrGroup

func GenerateSchnorrGroup(pBits int, qBits int) (SchnorrGroup, error)

GenerateSchnorrGroup generates a Schnorr subgroup of prime order Q, with q of length qBits, within the multiplicative group of integers modulo P, with p of length pBits.

qBits must be strictly less than pBits, otherwise an error is returned. An error may also be returned if sourcing of cryptographically secure randomness fails.

Jump to

Keyboard shortcuts

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