crypto

package
v1.0.0-pre1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Apache-2.0, MIT Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash uint
const (
	// From "crypto"
	MD4         Hash = 1 + iota // import golang.org/x/crypto/md4
	MD5                         // import crypto/md5
	SHA1                        // import crypto/sha1
	SHA224                      // import crypto/sha256
	SHA256                      // import crypto/sha256
	SHA384                      // import crypto/sha512
	SHA512                      // import crypto/sha512
	MD5SHA1                     // no implementation; MD5+SHA1 used for TLS RSA
	RIPEMD160                   // import golang.org/x/crypto/ripemd160
	SHA3_224                    // import golang.org/x/crypto/sha3
	SHA3_256                    // import golang.org/x/crypto/sha3
	SHA3_384                    // import golang.org/x/crypto/sha3
	SHA3_512                    // import golang.org/x/crypto/sha3
	SHA512_224                  // import crypto/sha512
	SHA512_256                  // import crypto/sha512
	BLAKE2s_256                 // import golang.org/x/crypto/blake2s
	BLAKE2b_256                 // import golang.org/x/crypto/blake2b
	BLAKE2b_384                 // import golang.org/x/crypto/blake2b
	BLAKE2b_512                 // import golang.org/x/crypto/blake2b

	// Extensions
	KECCAK_256
	KECCAK_512
)

func FromVarsigHash

func FromVarsigHash(h varsig.Hash) Hash

func (Hash) HashFunc

func (h Hash) HashFunc() Hash

HashFunc simply returns the value of h so that Hash implements [SignerOpts].

func (Hash) New

func (h Hash) New() hash.Hash

New returns a new hash.Hash calculating the given hash function. New panics if the hash function is not linked into the binary.

func (Hash) String

func (h Hash) String() string

func (Hash) ToVarsigHash

func (h Hash) ToVarsigHash() varsig.Hash

type PrivateKey

type PrivateKey interface {
	// Equal returns true if other is the same PrivateKey
	Equal(other PrivateKey) bool

	// Public returns the matching PublicKey.
	Public() PublicKey

	// ToPKCS8DER serializes the PrivateKey into the PKCS#8 DER (binary) format.
	ToPKCS8DER() []byte

	// ToPKCS8PEM serializes the PrivateKey into the PKCS#8 PEM (string) format.
	ToPKCS8PEM() string
}

type PrivateKeyKeyExchange

type PrivateKeyKeyExchange interface {
	PrivateKey

	// PublicKeyIsCompatible checks that the given PublicKey is compatible to perform key exchange.
	PublicKeyIsCompatible(remote PublicKey) bool

	// KeyExchange computes the shared key using the given PublicKey.
	KeyExchange(remote PublicKey) ([]byte, error)
}

type PrivateKeySigningASN1

type PrivateKeySigningASN1 interface {
	PrivateKey

	// Varsig returns the varsig.Varsig corresponding to the given parameters and private key.
	Varsig(opts ...SigningOption) varsig.Varsig

	// SignToASN1 creates a signature in the ASN.1 format.
	SignToASN1(message []byte, opts ...SigningOption) ([]byte, error)
}

type PrivateKeySigningBytes

type PrivateKeySigningBytes interface {
	PrivateKey

	// Varsig returns the varsig.Varsig corresponding to the given parameters and private key.
	Varsig(opts ...SigningOption) varsig.Varsig

	// SignToBytes creates a signature in the "raw bytes" format.
	// This format can make some assumptions and may not be what you expect.
	// Ideally, this format is defined by the same specification as the underlying crypto scheme.
	SignToBytes(message []byte, opts ...SigningOption) ([]byte, error)
}

type PrivateKeyToBytes

type PrivateKeyToBytes interface {
	PrivateKey

	// ToBytes serializes the PrivateKey into "raw bytes", without metadata or structure.
	// This format can make some assumptions and may not be what you expect.
	// Ideally, this format is defined by the same specification as the underlying crypto scheme.
	ToBytes() []byte
}

type PublicKey

type PublicKey interface {
	// Equal returns true if other is the same PublicKey
	Equal(other PublicKey) bool

	// ToPublicKeyMultibase format the PublicKey into a string compatible with a PublicKeyMultibase field
	// in a DID Document.
	ToPublicKeyMultibase() string

	// ToX509DER serializes the PublicKey into the X.509 DER (binary) format.
	ToX509DER() []byte

	// ToX509PEM serializes the PublicKey into the X.509 PEM (string) format.
	ToX509PEM() string
}

type PublicKeySigningASN1

type PublicKeySigningASN1 interface {
	PublicKey

	// VerifyASN1 checks a signature in the ASN.1 format.
	VerifyASN1(message, signature []byte, opts ...SigningOption) bool
}

type PublicKeySigningBytes

type PublicKeySigningBytes interface {
	PublicKey

	// VerifyBytes checks a signature in the "raw bytes" format.
	// This format can make some assumptions and may not be what you expect.
	// Ideally, this format is defined by the same specification as the underlying crypto scheme.
	VerifyBytes(message, signature []byte, opts ...SigningOption) bool
}

type PublicKeyToBytes

type PublicKeyToBytes interface {
	PublicKey

	// ToBytes serializes the PublicKey into "raw bytes", without metadata or structure.
	// This format can make some assumptions and may not be what you expect.
	// Ideally, this format is defined by the same specification as the underlying crypto scheme.
	ToBytes() []byte
}

type SigningOption

type SigningOption func(opts *SigningOpts)

func WithPayloadEncoding

func WithPayloadEncoding(encoding varsig.PayloadEncoding) SigningOption

WithPayloadEncoding specify the encoding that was used on the message before signing it. This will be included in the resulting varsig.

func WithSigningHash

func WithSigningHash(hash Hash) SigningOption

WithSigningHash specify the hash algorithm to be used for signatures

func WithVarsig

func WithVarsig(vsig varsig.Varsig) SigningOption

WithVarsig configure the signing or verification parameters from a varsig. If you use WithVarsig, you should NOT use other options.

type SigningOpts

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

func CollectSigningOptions

func CollectSigningOptions(opts []SigningOption) SigningOpts

func (SigningOpts) HashOrDefault

func (opts SigningOpts) HashOrDefault(_default Hash) Hash

func (SigningOpts) PayloadEncoding

func (opts SigningOpts) PayloadEncoding() varsig.PayloadEncoding

func (SigningOpts) VarsigMatch

func (opts SigningOpts) VarsigMatch(algo varsig.Algorithm, curve uint64, keyLength uint64) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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