sdf

package
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Overview

nolint

nolint

Index

Constants

View Source
const (
	BLOCK_MODE_ECB = "ECB"
	BLOCK_MODE_CTR = "CTR"
)

Variables

This section is empty.

Functions

func CCharArrToGoSlice

func CCharArrToGoSlice(buf []C.uchar) []byte

util funcs

func NewPrivateKey

func NewPrivateKey(sdf *SDFHandle, keyId string, keyPwd []byte, tp bccrypto.KeyType) (bccrypto.PrivateKey, error)

NewPrivateKey returns a sdf ec or sm2 private key

func NewSecretKey

func NewSecretKey(sdf *SDFHandle, keyId string, keyPwd []byte, tp bccrypto.KeyType) (bccrypto.SymmetricKey, error)

Types

type ECCSignature

type ECCSignature struct {
	R *big.Int
	S *big.Int
}

ECCSignature represents a ecc signature

type SDFHandle

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

SDFHandle represents a sdf handle

func New

func New(lib string, sessionCacheSize int) (*SDFHandle, error)

New returns a HSM SDFHandle to provide go-sdf functionalities.

func (*SDFHandle) Close

func (h *SDFHandle) Close() error

Close used to close sdf sessions

func (*SDFHandle) Decrypt

func (h *SDFHandle) Decrypt(key SDFKey, cipher []byte) ([]byte, error)

Decrypt decrypt a cipher with a given mechanism.

func (*SDFHandle) ECCInternalSign

func (h *SDFHandle) ECCInternalSign(key SDFKey, msg []byte) ([]byte, error)

ECCInternalSign signs the input with a given mechanism.

func (*SDFHandle) Encrypt

func (h *SDFHandle) Encrypt(key SDFKey, plain []byte) ([]byte, error)

Encrypt encrypts a plaintext with a given mechanism.

func (*SDFHandle) ExportECDSAPublicKey

func (h *SDFHandle) ExportECDSAPublicKey(key SDFKey) (interface{}, error)

ExportECDSAPublicKey export a ecdsa/sm2 public key of pkcs11 ecdsa/sm2 private key

func (*SDFHandle) GenKeyPair

func (h *SDFHandle) GenKeyPair() (pri *base.ECCrefPrivateKey, pub *base.ECCrefPublicKey, err error)

GenKeyPair returns asym keypair

func (*SDFHandle) GenerateKey

func (h *SDFHandle) GenerateKey(length int) ([]byte, error)

GenerateKey returns sym key

func (*SDFHandle) GenerateRandom

func (h *SDFHandle) GenerateRandom(length int) ([]byte, error)

GenerateRandom return a random bytes with fixed length

func (*SDFHandle) SymDecrypt

func (h *SDFHandle) SymDecrypt(keyHandle base.SessionHandle, mode uint, iv []byte, cipher []byte) ([]byte, error)

SymDecrypt decrypt a cipher with a given mechanism.

func (*SDFHandle) SymEncrypt

func (h *SDFHandle) SymEncrypt(keyHandle base.SessionHandle, mode uint, iv []byte, plain []byte) ([]byte, error)

SymEncrypt encrypts a plaintext with a given mechanism.

func (*SDFHandle) Verify

func (h *SDFHandle) Verify(key SDFKey, msg []byte, sig base.ECCSignature) error

Verify verifies a signature over a message with a given mechanism.

type SDFKey

type SDFKey struct {
	KeyId   uint
	KeyPwd  []byte
	KeyType SDFKeyType
}

SDFKey represents a sdf key

type SDFKeyType

type SDFKeyType string

SDFKeyType defines sdf key type

const (
	RSA   SDFKeyType = "RSA"
	ECDSA SDFKeyType = "ECDSA"
	SM2   SDFKeyType = "SM2"

	AES SDFKeyType = "AES"
	SM4 SDFKeyType = "SM4"

	UNKNOWN SDFKeyType = "UNKNOWN"
)

Directories

Path Synopsis
nolint
nolint

Jump to

Keyboard shortcuts

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