crypto

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 23 Imported by: 4

Documentation

Overview

ECDH , inspired by go-ethereum

Index

Constants

This section is empty.

Variables

View Source
var (
	ECIES_AES128_SHA256 = ECIESParams{
		Hash: sha256.New,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    16,
		// contains filtered or unexported fields
	}

	ECIES_AES256_SHA256 = ECIESParams{
		Hash: sha256.New,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
		// contains filtered or unexported fields
	}

	ECIES_AES256_SHA384 = ECIESParams{
		Hash: sha512.New384,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
		// contains filtered or unexported fields
	}

	ECIES_AES256_SHA512 = ECIESParams{
		Hash: sha512.New,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
		// contains filtered or unexported fields
	}
)
View Source
var AttributeTypeNames = map[string]string{
	"2.5.4.6":  "C",
	"2.5.4.10": "O",
	"2.5.4.11": "OU",
	"2.5.4.3":  "CN",
	"2.5.4.5":  "SERIALNUMBER",
	"2.5.4.7":  "L",
	"2.5.4.8":  "ST",
	"2.5.4.9":  "STREET",
	"2.5.4.17": "POSTALCODE",
}

Functions

func CheckHMAC

func CheckHMAC(h func() hash.Hash, message, messageMAC, key []byte) bool

func GetDN

func GetDN(name pkix.Name) string

Get the DN (distinguished name) associated with a pkix.Name. NOTE: This code is almost a direct copy of the String() function in https://go-review.googlesource.com/c/go/+/67270/1/src/crypto/x509/pkix/pkix.go#26 which returns a DN as defined by RFC 2253.

func HashSha256

func HashSha256(data []byte) []byte

func HashSha512

func HashSha512(data []byte) []byte

func NewHMAC

func NewHMAC(h func() hash.Hash, message, key []byte) []byte

func ParseCertPem

func ParseCertPem(pemBytes []byte) *x509.Certificate

Types

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

func (ECDSASignature) Marshal

func (t ECDSASignature) Marshal() []byte

func (ECDSASignature) Unmarshal

func (ECDSASignature) Unmarshal(signature []byte) (ecdsaSignature ECDSASignature)

type ECIESParams

type ECIESParams struct {
	Hash func() hash.Hash // hash function

	Cipher    func([]byte) (cipher.Block, error) // symmetric cipher
	BlockSize int                                // block size of symmetric cipher
	KeyLen    int                                // length of symmetric key
	// contains filtered or unexported fields
}

func ParamsFromCurve

func ParamsFromCurve(curve elliptic.Curve) (params ECIESParams)

ParamsFromCurve selects parameters optimal for the selected elliptic curve. Only the curves P256, P384, and P512 are supported.

func (ECIESParams) SymDecrypt

func (params ECIESParams) SymDecrypt(key, cipherText []byte) (m []byte)

symDecrypt carries out CTR decryption using the block cipher specified in the parameters

func (ECIESParams) SymEncrypt

func (params ECIESParams) SymEncrypt(rand io.Reader, key, m []byte) (cipherText []byte)

symEncrypt carries out CTR encryption using the block cipher specified in the parameters.

type ECPriv

type ECPriv struct {
	*ecdsa.PrivateKey
}

Used for both ECDSA and ECDH

func (ECPriv) Decrypt

func (prv ECPriv) Decrypt(c []byte) []byte

Decrypt decrypts an ECIES ciphertext.

func (ECPriv) GenerateShared

func (prv ECPriv) GenerateShared(pub ECPub, skLen, macLen int) (sk []byte)

ECDH key agreement method used to establish secret keys for encryption.

func (ECPriv) LoadPem

func (ECPriv) LoadPem(pemBytes []byte) ECPriv

func (ECPriv) New

func (ECPriv) New(curve elliptic.Curve) ECPriv

generate an EC private key (default to use P256 curve)

func (ECPriv) Sign

func (t ECPriv) Sign(digest []byte) []byte

func (ECPriv) ToPem

func (t ECPriv) ToPem() []byte

type ECPub

type ECPub struct {
	*ecdsa.PublicKey
}

PublicKey is a representation of an elliptic curve public key.

func (ECPub) Encrypt

func (pub ECPub) Encrypt(rand io.Reader, m []byte) (ct []byte)

func (ECPub) LoadCert

func (ECPub) LoadCert(pemBytes []byte) ECPub

func (ECPub) Verify

func (t ECPub) Verify(digest []byte, signature []byte) bool

type PKCS8

type PKCS8 struct {
	pem.Block
	Key interface{}
	reflect.Type
}

default in nodejs sdk

func (PKCS8) FormatECDSA

func (t PKCS8) FormatECDSA() *ecdsa.PrivateKey

func (PKCS8) LoadPem

func (PKCS8) LoadPem(pemBytes []byte) PKCS8

func (PKCS8) ToPem

func (t PKCS8) ToPem() []byte

Jump to

Keyboard shortcuts

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