multicastRSA

package
v0.0.6 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, BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDecryption = errors.New("xx_network/crypto/multicastRSA: " +
	"decryption error")

ErrDecryption represents a failure to decrypt a message. It is deliberately vague to avoid adaptive attacks.

View Source
var ErrMessageTooLong = errors.New("xx_network/crypto/multicastRSA: " +
	"message too long for RSA public key size")

ErrMessageTooLong is returned when attempting to encrypt a message which is too large for the size of the public key.

View Source
var ErrVerification = errors.New("xx_network/crypto/multicastRSA: " +
	"verification error")

ErrVerification represents a failure to verify a signature. It is deliberately vague to avoid adaptive attacks.

Functions

func DecryptOAEP

func DecryptOAEP(hash hash.Hash, pub PublicKey,
	ciphertext []byte, label []byte) ([]byte, error)

DecryptOAEP decrypts ciphertext using RSA-OAEP using an RSA Public Key for multicast RSA.

OAEP is parameterised by a hash function that is used as a random oracle. Encryption and decryption of a given message must use the same hash function and sha256.New() is a reasonable choice.

The label parameter must match the value given when encrypting. See EncryptOAEP for details.

func EncryptOAEP

func EncryptOAEP(hash hash.Hash, random io.Reader, priv PrivateKey,
	msg []byte, label []byte) ([]byte, error)

EncryptOAEP encrypts the given message with RSA-OAEP using a Private Key for multicast RSA.

OAEP is parameterised by a hash function that is used as a random oracle. Encryption and decryption of a given message must use the same hash function and sha256.New() is a reasonable choice.

The random parameter is used as a source of entropy to ensure that encrypting the same message twice doesn't result in the same ciphertext.

The label parameter may contain arbitrary data that will not be encrypted, but which gives important context to the message. For example, if a given public key is used to encrypt two types of messages then distinct label values could be used to ensure that a ciphertext for one purpose cannot be used for another by an attacker. If not required it can be empty.

The message must be no longer than the length of the public modulus minus twice the hash length, minus a further 2.

func GetMaxPayloadSize

func GetMaxPayloadSize(hash hash.Hash, key PublicKey) int

GetMaxPayloadSize returns the maximum size of a multicastRSA broadcast message The message must be no longer than the length of the public modulus minus twice the hash length, minus a further 2.

Types

type PrivateKey

type PrivateKey interface {
	// Private implements the same interface as public, but with
	// more functions.
	PublicKey

	// GetPrimes returns the prime factors of N, which has >= 2 elements
	GetPrimes() []*large.Int

	// GetD returns the private exponent of the RSA Private Key as
	// a large.Int
	GetD() *large.Int

	// GetDp returns D mod (P - 1), or nil if unavailable
	GetDp() *large.Int

	// GetDq returns D mod (Q - 1), or nil if unavailable
	GetDq() *large.Int
}

type PublicKey

type PublicKey interface {
	// GetN returns the RSA Public Key modulus
	GetN() *large.Int

	// GetE returns the RSA Public Key exponent
	GetE() int

	// Size returns the modulus size in bytes. Raw signatures and
	// ciphertexts for or by this public key will have the same
	// size.
	Size() int
}

Jump to

Keyboard shortcuts

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