keys

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 12 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeFMPPrivateKey

func EncodeFMPPrivateKey(priv *FMPPrivateKey) string

EncodeFMPPrivateKey marshalls an RSA private key using FMP types into a string.

func EncodeFMPPublicKey

func EncodeFMPPublicKey(pub *FMPPublicKey) string

EncodeFMPPublicKey marshalls an RSA public key using FMP types into a string.

func FMPtoBigPrivateKey

func FMPtoBigPrivateKey(key *FMPPrivateKey) *x509big.BigPrivateKey

FMPtoBigPrivateKey takes a FMPPrivateKey and returns an x509big.PrivateKey using native go big Int types.

func FMPtoBigPublicKey

func FMPtoBigPublicKey(key *FMPPublicKey) *x509big.BigPublicKey

FMPtoBigPublicKey takes a FMPPublicKey and returns an x509big.PublicKey using native go big Int types.

Types

type CRTValue

type CRTValue struct {
	Exp   *fmp.Fmpz // D mod (prime-1).
	Coeff *fmp.Fmpz // R·Coeff ≡ 1 mod Prime.
	R     *fmp.Fmpz // product of primes prior to this (inc p and q).
}

CRTValue contains the precomputed Chinese remainder theorem values.

type FMPPrivateKey

type FMPPrivateKey struct {
	PublicKey *FMPPublicKey
	D         *fmp.Fmpz
	Primes    []*fmp.Fmpz
	N         *fmp.Fmpz

	Precomputed *PrecomputedValues
}

FMPPrivateKey represents a RSA private key using FMP data structures.

func BigtoFMPPrivateKey

func BigtoFMPPrivateKey(key *x509big.BigPrivateKey) FMPPrivateKey

BigtoFMPPrivateKey takes a x509big.BigPrivateKey and returns a FMPPrivateKey that uses fmp.Fmpz types

func PrivateFromPublic

func PrivateFromPublic(key *FMPPublicKey) *FMPPrivateKey

PrivateFromPublic takes a Public Key and return a Private Key with the public components packed.

type FMPPublicKey

type FMPPublicKey struct {
	N *fmp.Fmpz
	E *fmp.Fmpz
}

FMPPublicKey represents a RSA public key using FMP data structures.

type PrecomputedValues

type PrecomputedValues struct {
	Dp, Dq *fmp.Fmpz // D mod (P-1) (or mod Q-1)
	Qinv   *fmp.Fmpz // Q^-1 mod P

	// CRTValues is used for the 3rd and subsequent primes. Due to a
	// historical accident, the CRT for the first two primes is handled
	// differently in PKCS#1 and interoperability is sufficiently
	// important that we mirror this.
	CRTValues []CRTValue
}

PrecomputedValues contains precomputed values that speed up private operations, if available.

type RSA

type RSA struct {
	Key               FMPPrivateKey
	CipherText        []byte
	PlainText         []byte
	KnownPlainText    []byte
	DLSB              []byte
	OracleCiphertexts map[int]*fmp.Fmpz
	Hints             []*fmp.Fmpz
	BruteMax          int64
	KeyFilename       string
	PastPrimesFile    string
	NumPrimes         int
	Verbose           bool
	Log               *log.Logger
}

RSA wraps FMPPrivateKey and adds a field for cipher and plaintexts as well as other fields needed for various attacks.

func ImportIntegerList

func ImportIntegerList(kb []byte) (*RSA, error)

ImportIntegerList attempts to parse the key (and optionally ciphertext) data as if it was a list of integers N, and e and c.

func ImportKey

func ImportKey(kb []byte) (*RSA, error)

ImportKey imports a PEM key file and returns a RSA object or error.

func NewRSA

func NewRSA(key *FMPPrivateKey, c []byte, m []byte, pf string, v bool) (*RSA, error)

NewRSA constructs an RSA object or returns an error.

func (*RSA) DumpKey

func (t *RSA) DumpKey()

DumpKey prints the key components in a string format.

func (*RSA) PackGivenD

func (t *RSA) PackGivenD(d *fmp.Fmpz)

PackGivenD takes d and packs it into the key, solving for any ciphertext on the way.

func (*RSA) PackGivenP

func (t *RSA) PackGivenP(p *fmp.Fmpz)

PackGivenP takes one prime p and packs the Key member of the RSA struct with the private key values, p, q & d as well as the Plaintext if a Ciphertext was given.

func (*RSA) PackMultiPrime

func (t *RSA) PackMultiPrime(primes []*fmp.Fmpz) error

PackMultiPrime takes many primes and packs the RSA struct with the private key values, []*Primes & d.

func (*RSA) String

func (t *RSA) String() string

String returns the key components in a string format.

Jump to

Keyboard shortcuts

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