s2k

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package s2k implements the various OpenPGP string-to-key transforms as specified in RFC 4800 section 3.7.1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashIdToHash

func HashIdToHash(id byte) (h crypto.Hash, ok bool)

HashIdToHash returns a crypto.Hash which corresponds to the given OpenPGP hash id.

func HashIdToString

func HashIdToString(id byte) (name string, ok bool)

HashIdToString returns the name of the hash function corresponding to the given OpenPGP hash id.

func HashToHashId

func HashToHashId(h crypto.Hash) (id byte, ok bool)

HashIdToHash returns an OpenPGP hash id which corresponds the given Hash.

func Iterated

func Iterated(out []byte, h hash.Hash, in []byte, salt []byte, count int)

Iterated writes to out the result of computing the Iterated and Salted S2K function (RFC 4880, section 3.7.1.3) using the given hash, input passphrase, salt and iteration count.

func Parse

func Parse(r io.Reader) (f func(out, in []byte), err error)

Parse reads a binary specification for a string-to-key transformation from r and returns a function which performs that transform. If the S2K is a special GNU extension that indicates that the private key is missing, then the error returned is errors.ErrDummyPrivateKey.

func Salted

func Salted(out []byte, h hash.Hash, in []byte, salt []byte)

Salted writes to out the result of computing the Salted S2K function (RFC 4880, section 3.7.1.2) using the given hash, input passphrase and salt.

func Serialize

func Serialize(w io.Writer, key []byte, rand io.Reader, passphrase []byte, c *Config) error

Serialize salts and stretches the given passphrase and writes the resulting key into key. It also serializes an S2K descriptor to w. The key stretching can be configured with c, which may be nil. In that case, sensible defaults will be used.

func Simple

func Simple(out []byte, h hash.Hash, in []byte)

Simple writes to out the result of computing the Simple S2K function (RFC 4880, section 3.7.1.1) using the given hash and input passphrase.

Types

type Config

type Config struct {
	// S2KMode is the mode of s2k function.
	// It can be 0 (simple), 1(salted), 3(iterated)
	// 2(reserved) 100-110(private/experimental).
	S2KMode uint8
	// Hash is the default hash function to be used. If
	// nil, SHA256 is used.
	Hash crypto.Hash
	// S2KCount is only used for symmetric encryption. It
	// determines the strength of the passphrase stretching when
	// the said passphrase is hashed to produce a key. S2KCount
	// should be between 65536 and 65011712, inclusive. If Config
	// is nil or S2KCount is 0, the value 16777216 used. Not all
	// values in the above range can be represented. S2KCount will
	// be rounded up to the next representable value if it cannot
	// be encoded exactly. See RFC 4880 Section 3.7.1.3.
	S2KCount int
}

Config collects configuration parameters for s2k key-stretching transformations. A nil *Config is valid and results in all default values. Currently, Config is used only by the Serialize function in this package.

func (*Config) EncodedCount

func (c *Config) EncodedCount() uint8

EncodedCount get encoded count

type Params

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

Params contains all the parameters of the s2k packet

func Generate

func Generate(rand io.Reader, c *Config) (*Params, error)

Generate generates valid parameters from given configuration. It will enforce salted + hashed s2k method

func ParseIntoParams

func ParseIntoParams(r io.Reader) (params *Params, err error)

ParseIntoParams reads a binary specification for a string-to-key transformation from r and returns a struct describing the s2k parameters.

func (*Params) Dummy

func (params *Params) Dummy() bool

func (*Params) Function

func (params *Params) Function() (f func(out, in []byte), err error)

func (*Params) Serialize

func (params *Params) Serialize(w io.Writer) (err error)

Jump to

Keyboard shortcuts

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