crypto

package
v0.0.0-...-3192b2a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxX509CertificateLength = 600

	P256FELength                 = 32
	P256ECDSASignatureLengthRaw  = 2 * P256FELength
	P256PointLength              = 2*P256FELength + 1
	Sha256HashLength             = 32
	Sha1HashLength               = 20
	SubjectKeyIdentifierLength   = Sha1HashLength
	AuthorityKeyIdentifierLength = Sha1HashLength

	GroupSizeBytes     = P256FELength
	PublicKeySizeBytes = P256PointLength

	AEADMicLengthBytes      = 16
	SymmetricKeyLengthBytes = 16 //对称密钥长度

	ECDHSecretLength     = P256FELength
	ECDSASignatureLength = P256ECDSASignatureLengthRaw

	MaxFELength    = P256FELength
	MaxPointLength = P256PointLength
	MaxHashLength  = Sha256HashLength

	MaxCSRLength = 255

	HashLenBytes = Sha256HashLength

	Spake2pMinPBKDFSaltLength = 16
	Spake2pMaxPBKDFSaltLength = 32
	Spake2pMinPBKDFIterations = 1000
	Spake2pMaxPBKDFIterations = 100000

	P256PrivateKeyLength = GroupSizeBytes
	P256PublicKeyLength  = PublicKeySizeBytes

	AESCCM128KeyLength   = 128 / 8
	AESCCM128BlockLength = AESCCM128KeyLength
	AESCCM128NonceLength = 13
	AESCCM128TagLength   = 16

	MaxSpake2pContextSize     = 1024
	MaxP256keypairContextSize = 512

	EmitDerIntegerWithoutTagOverhead = 1 // 1 sign stuffer
	EmitDerIntegerOverhead           = 3 // NextTag + Length byte + 1 sign stuffer

	MaxHashSha256ContextSize = config.Sha256ContextSize

	Spake2pWSLength                 = P256FELength + 8
	Spake2pVerifierSerializedLength = P256FELength + P256PointLength

	VIDPrefixForCNEncoding  = "Mvid:"
	PIDPrefixForCNEncoding  = "Mpid:"
	VIDAndPIDHexLength      = 2 * 2
	MaxCommonNameAttrLength = 64
)

Variables

This section is empty.

Functions

func AES128CCMDecrypt

func AES128CCMDecrypt(cipherText, key, nonce, addData []byte, tagSize int) (plainText []byte, err error)

func AES128CCMEncrypt

func AES128CCMEncrypt(plainText, key, nonce, aad []byte, tagSize int) (cipherTag []byte, err error)

AES128CCMEncrypt 使用输入加密明文 输出的密文长度 = len(plainText) + tagSize

func ComputeWS

func ComputeWS(iterationCount, setupCode uint32, salt []byte) ([]byte, error)

func EccSign

func EccSign(plainText []byte, priKey []byte) (sign []byte, err error)

EccSign 对数据进行Ecc签名, sha256

func EccVerify

func EccVerify(plainText, rText, sTest []byte, publicKeyFile string) (b bool, err error)

EccVerify Ecc签名认证, sha256

func GenerateEccKey

func GenerateEccKey(privateKeyFile, publicKeyFile string) error

GenerateEccKey 生成Ecc秘钥对,P256

func HKDFSha256

func HKDFSha256(mSharedSecret, salt, kKDFSR2Info []byte) []byte

Types

type GroupOperationalCredentials

type GroupOperationalCredentials struct {
	StateTime     time.Time
	Hash          uint16
	EncryptionKey []byte
	PrivacyKey    []byte
}

type OperationalKeystore

type OperationalKeystore interface {
	Init(persistentStorage store.PersistentStorageDelegate) error
	HasPendingOpKeypair() bool
	HasOpKeypairForFabric(fabricIndex lib.FabricIndex) bool
	NewOpKeypairForFabric(fabricIndex lib.FabricIndex) ([]byte, error)
	ActivateOpKeypairForFabric(fabricIndex lib.FabricIndex, key crypto.PublicKey) error
	CommitOpKeypairForFabric(fabricIndex lib.FabricIndex) error
	RemoveOpKeypairForFabric(fabricIndex lib.FabricIndex) error
	RevertPendingKeypair()
	SignWithOpKeypair(fabricIndex lib.FabricIndex, message []byte) ([]byte, error)
	AllocateEphemeralKeypairForCASE() *P256Keypair
	ReleaseEphemeralKeypair(key *P256Keypair)
}

type OperationalKeystoreImpl

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

func NewOperationalKeystoreImpl

func NewOperationalKeystoreImpl() *OperationalKeystoreImpl

func (*OperationalKeystoreImpl) ActivateOpKeypairForFabric

func (p *OperationalKeystoreImpl) ActivateOpKeypairForFabric(fabricIndex lib.FabricIndex, key crypto.PublicKey) error

func (*OperationalKeystoreImpl) AllocateEphemeralKeypairForCASE

func (p *OperationalKeystoreImpl) AllocateEphemeralKeypairForCASE() *P256Keypair

func (*OperationalKeystoreImpl) CommitOpKeypairForFabric

func (p *OperationalKeystoreImpl) CommitOpKeypairForFabric(fabricIndex lib.FabricIndex) error

func (*OperationalKeystoreImpl) HasOpKeypairForFabric

func (p *OperationalKeystoreImpl) HasOpKeypairForFabric(fabricIndex lib.FabricIndex) bool

func (*OperationalKeystoreImpl) HasPendingOpKeypair

func (p *OperationalKeystoreImpl) HasPendingOpKeypair() bool

func (*OperationalKeystoreImpl) Init

func (p *OperationalKeystoreImpl) Init(persistentStorage store.PersistentStorageDelegate) error

func (*OperationalKeystoreImpl) NewOpKeypairForFabric

func (p *OperationalKeystoreImpl) NewOpKeypairForFabric(fabricIndex lib.FabricIndex) ([]byte, error)

func (*OperationalKeystoreImpl) ReleaseEphemeralKeypair

func (p *OperationalKeystoreImpl) ReleaseEphemeralKeypair(key *P256Keypair)

func (*OperationalKeystoreImpl) RemoveOpKeypairForFabric

func (p *OperationalKeystoreImpl) RemoveOpKeypairForFabric(fabricIndex lib.FabricIndex) error

func (*OperationalKeystoreImpl) RevertPendingKeypair

func (p *OperationalKeystoreImpl) RevertPendingKeypair()

func (*OperationalKeystoreImpl) SignWithOpKeypair

func (p *OperationalKeystoreImpl) SignWithOpKeypair(fabricIndex lib.FabricIndex, message []byte) ([]byte, error)

type P256ECDHDerivedSecret

type P256ECDHDerivedSecret struct {
}

type P256ECDSASignature

type P256ECDSASignature []byte

func SignP256ECDSASignature

func SignP256ECDSASignature(plainTex, privateKeyFile []byte) (P256ECDSASignature, error)

func (*P256ECDSASignature) Bytes

func (s *P256ECDSASignature) Bytes() []byte

type P256Keypair

type P256Keypair ecdh.PrivateKey

func GenericP256Keypair

func GenericP256Keypair() *P256Keypair

func (*P256Keypair) ECDHDeriveSecret

func (k *P256Keypair) ECDHDeriveSecret(key *P256PublicKey) ([]byte, error)

func (*P256Keypair) ECDSASignMsg

func (k *P256Keypair) ECDSASignMsg(msg []byte) ([]byte, error)

func (*P256Keypair) PrivateKey

func (k *P256Keypair) PrivateKey() *ecdh.PrivateKey

func (*P256Keypair) PubBytes

func (k *P256Keypair) PubBytes() []byte

type P256PublicKey

type P256PublicKey ecdh.PublicKey

func UnmarshalPublicKey

func UnmarshalPublicKey(data []byte) (*P256PublicKey, error)

UnmarshalPublicKey 接收到的字节序列化成公钥

func (*P256PublicKey) PublicKey

func (k *P256PublicKey) PublicKey() *ecdh.PublicKey

type P256Sha256HkdfHmac

type P256Sha256HkdfHmac struct {
	Spake2p
}

func (P256Sha256HkdfHmac) BeginProver

func (p P256Sha256HkdfHmac) BeginProver(ws []byte) error

func (P256Sha256HkdfHmac) BeginVerifier

func (p P256Sha256HkdfHmac) BeginVerifier(t interface{}, i int, t2 interface{}, i2 int, w0 []byte, ml []byte) error

func (P256Sha256HkdfHmac) Clear

func (p P256Sha256HkdfHmac) Clear()

func (P256Sha256HkdfHmac) ComputeRoundOne

func (p P256Sha256HkdfHmac) ComputeRoundOne(in, out []byte) error

func (P256Sha256HkdfHmac) ComputeRoundTwo

func (p P256Sha256HkdfHmac) ComputeRoundTwo(x []byte, out []byte) error

func (P256Sha256HkdfHmac) GetKeys

func (p P256Sha256HkdfHmac) GetKeys(out []byte) error

func (P256Sha256HkdfHmac) Init

func (p P256Sha256HkdfHmac) Init(context []byte) error

func (P256Sha256HkdfHmac) KeyConfirm

func (p P256Sha256HkdfHmac) KeyConfirm(verifier []byte) error

type PersistentStorageOperationalKeystore

type PersistentStorageOperationalKeystore interface {
	OperationalKeystore
}

type PersistentStorageOperationalKeystoreImpl

type PersistentStorageOperationalKeystoreImpl struct {
	*OperationalKeystoreImpl
}

func NewPersistentStorageOperationalKeystoreImpl

func NewPersistentStorageOperationalKeystoreImpl() *PersistentStorageOperationalKeystoreImpl

func (*PersistentStorageOperationalKeystoreImpl) ActivateOpKeypairForFabric

func (p *PersistentStorageOperationalKeystoreImpl) ActivateOpKeypairForFabric(fabricIndex lib.FabricIndex, key crypto.PublicKey) error

func (*PersistentStorageOperationalKeystoreImpl) AllocateEphemeralKeypairForCASE

func (p *PersistentStorageOperationalKeystoreImpl) AllocateEphemeralKeypairForCASE() *P256Keypair

func (*PersistentStorageOperationalKeystoreImpl) CommitOpKeypairForFabric

func (p *PersistentStorageOperationalKeystoreImpl) CommitOpKeypairForFabric(fabricIndex lib.FabricIndex) error

func (*PersistentStorageOperationalKeystoreImpl) HasOpKeypairForFabric

func (p *PersistentStorageOperationalKeystoreImpl) HasOpKeypairForFabric(fabricIndex lib.FabricIndex) bool

func (*PersistentStorageOperationalKeystoreImpl) HasPendingOpKeypair

func (p *PersistentStorageOperationalKeystoreImpl) HasPendingOpKeypair() bool

func (*PersistentStorageOperationalKeystoreImpl) NewOpKeypairForFabric

func (p *PersistentStorageOperationalKeystoreImpl) NewOpKeypairForFabric(fabricIndex lib.FabricIndex) ([]byte, error)

func (*PersistentStorageOperationalKeystoreImpl) ReleaseEphemeralKeypair

func (p *PersistentStorageOperationalKeystoreImpl) ReleaseEphemeralKeypair(key *P256Keypair)

func (*PersistentStorageOperationalKeystoreImpl) RemoveOpKeypairForFabric

func (p *PersistentStorageOperationalKeystoreImpl) RemoveOpKeypairForFabric(fabricIndex lib.FabricIndex) error

func (*PersistentStorageOperationalKeystoreImpl) RevertPendingKeypair

func (p *PersistentStorageOperationalKeystoreImpl) RevertPendingKeypair()

func (*PersistentStorageOperationalKeystoreImpl) SignWithOpKeypair

func (p *PersistentStorageOperationalKeystoreImpl) SignWithOpKeypair(fabricIndex lib.FabricIndex, message []byte) ([]byte, error)

type Spake2p

type Spake2p struct {
}

type Spake2pVerifier

type Spake2pVerifier struct {
	W0 []byte
	ML []byte
}

func (Spake2pVerifier) Deserialize

func (v Spake2pVerifier) Deserialize(verifier []byte) error

func (Spake2pVerifier) Generate

func (v Spake2pVerifier) Generate(count uint32, span []byte, passcode uint32) error

func (Spake2pVerifier) Serialize

func (v Spake2pVerifier) Serialize() ([]byte, error)

type SymmetricKeyContextBase

type SymmetricKeyContextBase interface {
	KeyHash() uint16
	Release()
	MessageEncrypt(plaintext, nonce, addData []byte, tagSize int) (cipherText []byte, err error)
}

Jump to

Keyboard shortcuts

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