crypto

package
v0.0.0-...-3eefbbf Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Ed25519        KeyType = "Ed25519"
	X25519         KeyType = "X25519"
	SECP256k1      KeyType = "secp256k1"
	SECP256k1ECDSA KeyType = "secp256k1-ECDSA"
	P224           KeyType = "P-224"
	P256           KeyType = "P-256"
	P384           KeyType = "P-384"
	P521           KeyType = "P-521"
	RSA            KeyType = "RSA"
	BLS12381G1     KeyType = "BLS12381G1"
	BLS12381G2     KeyType = "BLS12381G2"
	Dilithium2     KeyType = "Dilithium2"
	Dilithium3     KeyType = "Dilithium3"
	Dilithium5     KeyType = "Dilithium5"

	RSAKeySize int = 2048
)

Variables

View Source
var (
	ECDSAMarshalCompressed = Option{Name: "ecdsa-compressed", Value: true}
)

Functions

func BytesToPrivKey

func BytesToPrivKey(keyBytes []byte, kt KeyType) (crypto.PrivateKey, error)

BytesToPrivKey reconstructs a private key given some bytes and a target key type It is assumed the key was turned into byte form using the sibling method `PrivKeyToBytes`

func BytesToPubKey

func BytesToPubKey(keyBytes []byte, kt KeyType) (crypto.PublicKey, error)

BytesToPubKey reconstructs a public key given some bytes and a target key type It is assumed the key was turned into byte form using the sibling method `PubKeyToBytes`

func GenerateBBSKeyPair

func GenerateBBSKeyPair() (*bbsg2.PublicKey, *bbsg2.PrivateKey, error)

GenerateBBSKeyPair https://w3c-ccg.github.io/ldp-bbs2020

func GenerateDilithiumKeyPair

func GenerateDilithiumKeyPair(m dilithium.Mode) (dilithium.PublicKey, dilithium.PrivateKey, error)

GenerateDilithiumKeyPair generates a new Dilithium key pair for the given mode

func GenerateEd25519Key

func GenerateEd25519Key() (ed25519.PublicKey, ed25519.PrivateKey, error)

func GenerateKeyByKeyType

func GenerateKeyByKeyType(kt KeyType) (crypto.PublicKey, crypto.PrivateKey, error)

GenerateKeyByKeyType creates a brand-new key, returning the public and private key for the given key type

func GenerateP224Key

func GenerateP224Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateP256Key

func GenerateP256Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateP384Key

func GenerateP384Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateP521Key

func GenerateP521Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateRSA2048Key

func GenerateRSA2048Key() (rsa.PublicKey, rsa.PrivateKey, error)

func GenerateSECP256k1Key

func GenerateSECP256k1Key() (secp.PublicKey, secp.PrivateKey, error)

func GenerateX25519Key

func GenerateX25519Key() (x25519.PublicKey, x25519.PrivateKey, error)

func GetModeFromDilithiumPrivateKey

func GetModeFromDilithiumPrivateKey(privKey dilithium.PrivateKey) (dilithium.Mode, error)

GetModeFromDilithiumPrivateKey returns the DilithiumMode from a dilithium.PrivateKey, validating the key is a valid private key

func GetModeFromDilithiumPublicKey

func GetModeFromDilithiumPublicKey(pubKey dilithium.PublicKey) (dilithium.Mode, error)

GetModeFromDilithiumPublicKey returns the DilithiumMode from a dilithium.PublicKey, validating the key is a valid public key

func IsSupportedKeyType

func IsSupportedKeyType(kt KeyType) bool

IsSupportedKeyType returns true if the key type is supported

func IsSupportedSignatureAlg

func IsSupportedSignatureAlg(sa SignatureAlgorithm) bool

IsSupportedSignatureAlg returns true if the signature algorithm is supported

func PrivKeyToBytes

func PrivKeyToBytes(key crypto.PrivateKey) ([]byte, error)

PrivKeyToBytes constructs a byte representation of a private key, for a set number of supported key types

func PubKeyToBytes

func PubKeyToBytes(key crypto.PublicKey, opts ...Option) ([]byte, error)

PubKeyToBytes constructs a byte representation of a public key, for a set number of supported key types

func SignBBSMessage

func SignBBSMessage(privKey *bbsg2.PrivateKey, messages ...[]byte) ([]byte, error)

func VerifyBBSMessage

func VerifyBBSMessage(pubKey *bbsg2.PublicKey, signature, message []byte) error

func VerifyDerivedBBSMessage

func VerifyDerivedBBSMessage(pubKey *bbsg2.PublicKey, signature, message, nonce []byte) error

Types

type BBSPlusSigner

type BBSPlusSigner struct {
	*bbsg2.PrivateKey
	*bbsg2.PublicKey
	*BBSPlusVerifier
	// contains filtered or unexported fields
}

func NewBBSPlusSigner

func NewBBSPlusSigner(kid string, privKey *bbsg2.PrivateKey) *BBSPlusSigner

func (*BBSPlusSigner) GetKeyID

func (s *BBSPlusSigner) GetKeyID() string

func (*BBSPlusSigner) GetVerifier

func (s *BBSPlusSigner) GetVerifier() *BBSPlusVerifier

func (*BBSPlusSigner) Sign

func (s *BBSPlusSigner) Sign(message []byte) ([]byte, error)

func (*BBSPlusSigner) SignMultiple

func (s *BBSPlusSigner) SignMultiple(messages ...[]byte) ([]byte, error)

type BBSPlusVerifier

type BBSPlusVerifier struct {
	KID string
	*bbsg2.PublicKey
}

func NewBBSPlusVerifier

func NewBBSPlusVerifier(kid string, pubKey *bbsg2.PublicKey) *BBSPlusVerifier

func (*BBSPlusVerifier) DeriveProof

func (v *BBSPlusVerifier) DeriveProof(messages [][]byte, sigBytes, nonce []byte, revealedIndexes []int) ([]byte, error)

func (*BBSPlusVerifier) GetKeyID

func (v *BBSPlusVerifier) GetKeyID() string

func (*BBSPlusVerifier) Verify

func (v *BBSPlusVerifier) Verify(message, signature []byte) error

func (*BBSPlusVerifier) VerifyDerived

func (v *BBSPlusVerifier) VerifyDerived(message, signature, nonce []byte) error

VerifyDerived verifies a derived proof, or a selective disclosure proof that has been derived from a BBSPlusSignature signed object.

func (*BBSPlusVerifier) VerifyMultiple

func (v *BBSPlusVerifier) VerifyMultiple(signature []byte, messages ...[]byte) error

type HashType

type HashType string
const (
	SHA256 HashType = "SHA256"
)

type KeyType

type KeyType string

func GetExperimentalKeyTypes

func GetExperimentalKeyTypes() []KeyType

GetExperimentalKeyTypes returns a list of experimental key types

func GetKeyTypeFromPrivateKey

func GetKeyTypeFromPrivateKey(key crypto.PrivateKey) (KeyType, error)

GetKeyTypeFromPrivateKey returns the key type for a private key for known key types

func GetSupportedKeyTypes

func GetSupportedKeyTypes() []KeyType

GetSupportedKeyTypes returns a list of supported key types

func (KeyType) String

func (kt KeyType) String() string

type Option

type Option struct {
	Name  string
	Value any
}

type Proof

type Proof any

type SignatureAlgorithm

type SignatureAlgorithm string
const (
	// EdDSA uses an ed25519 key
	EdDSA SignatureAlgorithm = "EdDSA"
	// ES256K uses a secp256k1 key
	ES256K SignatureAlgorithm = "ES256K"
	// ES256 uses a p-256 curve key
	ES256 SignatureAlgorithm = "ES256"
	// ES384 uses a p-384 curve key
	ES384 SignatureAlgorithm = "ES384"
	// PS256 uses a 2048-bit RSA key
	PS256 SignatureAlgorithm = "PS256"

	Dilithium2Sig SignatureAlgorithm = "Dilithium2"
	Dilithium3Sig SignatureAlgorithm = "Dilithium3"
	Dilithium5Sig SignatureAlgorithm = "Dilithium5"
)

func GetExperimentalSignatureAlgs

func GetExperimentalSignatureAlgs() []SignatureAlgorithm

GetExperimentalSignatureAlgs returns a list of experimental signature algorithms

func GetSupportedSignatureAlgs

func GetSupportedSignatureAlgs() []SignatureAlgorithm

GetSupportedSignatureAlgs returns a list of supported signature algorithms

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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