Documentation ¶
Index ¶
- Constants
- func Decrypt(privateKey *PrivateKey, ephemeralPublicKey *PublicKey, ciphertext []byte) (encodedSessionKey []byte, err error)
- func EncodeFields(writer io.Writer, ephemeralPublicKey *PublicKey, encryptedSessionKey []byte, ...) (err error)
- func EncodedFieldsLength(encryptedSessionKey []byte, v6 bool) int
- func Validate(pk *PrivateKey) (err error)
- type PrivateKey
- type PublicKey
Constants ¶
const ( // The size of a public or private key in bytes. KeySize = x25519lib.Size )
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
func Decrypt(privateKey *PrivateKey, ephemeralPublicKey *PublicKey, ciphertext []byte) (encodedSessionKey []byte, err error)
Decrypt decrypts a session key stored in ciphertext with the provided x25519 private key and ephemeral public key.
func EncodeFields ¶
func EncodeFields(writer io.Writer, ephemeralPublicKey *PublicKey, encryptedSessionKey []byte, cipherFunction byte, v6 bool) (err error)
EncodeField encodes x25519 session key encryption fields as ephemeral x25519 public key | follow byte length | cipherFunction (v3 only) | encryptedSessionKey and writes it to writer.
func EncodedFieldsLength ¶
EncodeFieldsLength returns the length of the ciphertext encoding given the encrypted session key.
func Validate ¶
func Validate(pk *PrivateKey) (err error)
Validate validates that the provided public key matches the private key.
Types ¶
type PrivateKey ¶
type PrivateKey struct { PublicKey // Secret represents the secret of the private key. Secret []byte }
func GenerateKey ¶
func GenerateKey(rand io.Reader) (*PrivateKey, error)
GenerateKey generates a new x25519 key pair.
func NewPrivateKey ¶
func NewPrivateKey(key PublicKey) *PrivateKey
NewPrivateKey creates a new empty private key including the public key.
type PublicKey ¶
type PublicKey struct { // Point represents the encoded elliptic curve point of the public key. Point []byte }
func DecodeFields ¶
func DecodeFields(reader io.Reader, v6 bool) (ephemeralPublicKey *PublicKey, encryptedSessionKey []byte, cipherFunction byte, err error)
DecodeField decodes a x25519 session key encryption as ephemeral x25519 public key | follow byte length | cipherFunction (v3 only) | encryptedSessionKey.
func Encrypt ¶
func Encrypt(rand io.Reader, publicKey *PublicKey, sessionKey []byte) (ephemeralPublicKey *PublicKey, encryptedSessionKey []byte, err error)
Encrypt encrypts a sessionKey with x25519 according to the OpenPGP crypto refresh specification section 5.1.6. The function assumes that the sessionKey has the correct format and padding according to the specification.