crypto

package
v2.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeySign returns a signing key (GetKeyFromIdentity)
	KeySign = iota
	// KeyEncrypt returns a encryption key (GetKeyFromIdentity)
	KeyEncrypt
	// KeyAuth returns an authorization key (GetKeyFromIdentity)
	KeyAuth
)

Variables

This section is empty.

Functions

func GetArmoredPublicKey

func GetArmoredPublicKey(ent *openpgp.Entity) ([]byte, error)

GetArmoredPublicKey returns an armored public key for entity.

func GetKeyFromIdentity

func GetKeyFromIdentity(ent *openpgp.Entity, mode int) *openpgp.Key

GetKeyFromIdentity returns a suitable subkey from entity for the given operation.

func GetPublicKey

func GetPublicKey(buf []byte) (*packet.PublicKey, error)

GetPublicKey converts an ASCII-armored public key representation into an OpenPGP key.

func Reconstruct

func Reconstruct(shares []Share) *math.Int

Reconstruct secrets from number of shares: if not sufficient shares are available, the resulting secret is "random"

Types

type Counter

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

Counter is a cryptographic counter (encrypted value)

func NewCounter

func NewCounter(k *PaillierPublicKey) (c *Counter, err error)

NewCounter creates a new Counter instance for given public key.

func (*Counter) Get

func (c *Counter) Get() *math.Int

Get the encrypted counter value.

func (*Counter) Increment

func (c *Counter) Increment(step *math.Int) error

Increment counter: usually called with step values of "0" (don't change counter, but change representation) and "1" (increment by one step).

type FieldP

type FieldP struct {
	P *math.Int
}

FieldP is a prime field

func (*FieldP) Add

func (f *FieldP) Add(a, b *math.Int) *math.Int

Add field values

func (*FieldP) Div

func (f *FieldP) Div(a, b *math.Int) *math.Int

Div divides field values

func (*FieldP) Mul

func (f *FieldP) Mul(a, b *math.Int) *math.Int

Mul multiplies field values

func (*FieldP) Neg

func (f *FieldP) Neg(a *math.Int) *math.Int

Neg negates a field value

func (*FieldP) Random

func (f *FieldP) Random() *math.Int

Random generates a random field value

func (*FieldP) Sub

func (f *FieldP) Sub(a, b *math.Int) *math.Int

Sub subtracts field values

type PaillierPrivateKey

type PaillierPrivateKey struct {
	*PaillierPublicKey
	L, U *math.Int
	P, Q *math.Int
}

PaillierPrivateKey data structure

func NewPaillierPrivateKey

func NewPaillierPrivateKey(bits int) (key *PaillierPrivateKey, err error)

NewPaillierPrivateKey generates a new Paillier private key (key pair).

The key used in the Paillier crypto system consists of four integer values. The public key has two parameters; the private key has three parameters (one parameter is shared between the keys). As in RSA it starts with two random primes 'p' and 'q'; the public key parameter are computed as:

n := p * q
g := random number from interval [0,n^2[

The private key parameters are computed as:

n := p * q
l := lcm (p-1,q-1)
u := (((g^l mod n^2)-1)/n) ^-1 mod n

N.B. The division by n is integer based and rounds toward zero!

func (*PaillierPrivateKey) Decrypt

func (p *PaillierPrivateKey) Decrypt(c *math.Int) (m *math.Int, err error)

Decrypt message with private key.

The decryption function in the Paillier crypto scheme is:

m = D(c) = ((((c^l mod n^2)-1)/n) * u) mod n

N.B. As in the key generation process the division by n is integer

based and rounds toward zero!

func (*PaillierPrivateKey) GetPublicKey

func (p *PaillierPrivateKey) GetPublicKey() *PaillierPublicKey

GetPublicKey returns the corresponding public key from a private key.

type PaillierPublicKey

type PaillierPublicKey struct {
	N, G *math.Int
}

PaillierPublicKey data structure

func (*PaillierPublicKey) Encrypt

func (p *PaillierPublicKey) Encrypt(m *math.Int) (c *math.Int, err error)

Encrypt message with public key.

The encryption function in the Paillier crypto scheme is:

c = E(m) = (g^m * r^n) mod n^2

where 'r' is a random number from the interval [0,n[. This encryption allows different encryption results for the same message, based on the actual value of 'r'.

type Share

type Share struct {
	X, Y, P *math.Int
}

Share is a data structure for a partial secret.

func Split

func Split(secret, p *math.Int, n, k int) []Share

Split a 'secret' into 'n' shares, where a 'k' shares are sufficient to reconstruct 'secret'.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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