kcdsa

package
v1.0.3030 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const NumMRTests = 64

Variables

View Source
var (
	One   = big.NewInt(1)
	Two   = big.NewInt(2)
	Three = big.NewInt(3)
)

Functions

func FermatInverse

func FermatInverse(k, P *big.Int) *big.Int

func GenerateG

func GenerateG(
	G *big.Int,
	P, J, H *big.Int,
) (ok bool)

func GenerateHG

func GenerateHG(
	H, G *big.Int,
	buf []byte,
	rand io.Reader,
	P, J *big.Int,
) (bufOut []byte, err error)

func GenerateJ

func GenerateJ(
	J *big.Int, buf []byte,
	seed []byte,
	h hash.Hash,
	d ParameterSize,
) (bufNew []byte, ok bool)

func GenerateKey

func GenerateKey(priv *PrivateKey, rand io.Reader) error

func GenerateKeyWithSeed

func GenerateKeyWithSeed(priv *PrivateKey, rand io.Reader, xkey, upri []byte, sizes ParameterSizes) (xkeyOut, upriOut []byte, err error)

func GeneratePQ

func GeneratePQ(
	P, Q *big.Int, buf []byte,
	J *big.Int,
	seed []byte,
	h hash.Hash,
	d ParameterSize,
) (bufNew []byte, count int, ok bool)

func GenerateParameters

func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) (err error)

Generate the parameters without Key Generation Parameters (J, Seed, Count)

func GenerateParametersTTAK

func GenerateParametersTTAK(params *Parameters, rand io.Reader, sizes ParameterSizes) (err error)

Generate the parameters using Key Generation Parameters (J, Seed, Count)

func GenerateX

func GenerateX(
	X *big.Int,
	Q *big.Int, upri, xkey []byte, h hash.Hash, d ParameterSize,
)

func GenerateY

func GenerateY(
	Y *big.Int,
	P, Q, G, X *big.Int,
)

func Grow

func Grow(buf []byte, bytes int) []byte

without guarantee of data

func LeftMost

func LeftMost(b []byte, bits int) []byte

[0 0 0 0 0 0]0 0

func MarshalPrivateKey

func MarshalPrivateKey(key *PrivateKey) ([]byte, error)

PKCS8 包装私钥

func MarshalPublicKey

func MarshalPublicKey(pub *PublicKey) ([]byte, error)

PKCS8 包装公钥

func ReadBigInt

func ReadBigInt(dst *big.Int, rand io.Reader, buf []byte, max *big.Int) (bufNew []byte, err error)

ReadBigInt returns a uniform random value in [0, max). It panics if max <= 0.

func ReadBits

func ReadBits(dst []byte, rand io.Reader, bits int) ([]byte, error)

resize dst, ReadFull, cut from right

func ReadBytes

func ReadBytes(dst []byte, rand io.Reader, bytes int) ([]byte, error)

resize dst, ReadFull, cut from right

func RegeneratePQ

func RegeneratePQ(
	ps ParameterSize,
	J *big.Int,
	seed []byte,
	count int,
) (
	P, Q *big.Int,
	ok bool,
)

func RegenerateParameters

func RegenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error

TTAKParameters -> P, Q, G(randomly)

func RightMost

func RightMost(b []byte, bits int) []byte

0 0[0 0 0 0 0 0]

func Sign

func Sign(rand io.Reader, priv *PrivateKey, h Hasher, data []byte) (r, s *big.Int, err error)

func SignASN1

func SignASN1(rand io.Reader, priv *PrivateKey, h Hasher, data []byte) (sig []byte, err error)

Sign data returns the ASN.1 encoded signature.

func SignBytes added in v1.0.3030

func SignBytes(rand io.Reader, priv *PrivateKey, hashFunc Hasher, data []byte) (sig []byte, err error)

Sign data returns the Bytes encoded signature.

func Verify

func Verify(pub *PublicKey, h Hasher, data []byte, r, s *big.Int) bool

func VerifyASN1

func VerifyASN1(pub *PublicKey, h Hasher, data []byte, sig []byte) bool

VerifyASN1 verifies the ASN.1 encoded signature, sig, M, of hash using the public key, pub. Its return value records whether the signature is valid.

func VerifyBytes added in v1.0.3030

func VerifyBytes(pub *PublicKey, hashFunc Hasher, data, sig []byte) bool

Verify verifies the Bytes encoded signature

Types

type GeneratedParameter

type GeneratedParameter struct {
	P     *big.Int
	Q     *big.Int
	G     *big.Int
	J     *big.Int
	Seed  []byte
	Count int
	H     *big.Int
}

func GenerateParametersFast

func GenerateParametersFast(rand io.Reader, d ParameterSize) (generated GeneratedParameter, err error)

type GenerationParameters

type GenerationParameters struct {
	J     *big.Int
	Seed  []byte
	Count int
}

func (*GenerationParameters) Equal

Equal reports whether p, q, g and sizes have the same value.

func (*GenerationParameters) IsValid

func (params *GenerationParameters) IsValid() bool

type Hasher

type Hasher = func() hash.Hash

type PKCS8Key

type PKCS8Key struct{}

*

  • pkcs8 密钥 *
  • @create 2024-8-12
  • @author deatil

func NewPKCS8Key

func NewPKCS8Key() PKCS8Key

构造函数

func (PKCS8Key) MarshalPrivateKey

func (this PKCS8Key) MarshalPrivateKey(key *PrivateKey) ([]byte, error)

PKCS8 包装私钥

func (PKCS8Key) MarshalPublicKey

func (this PKCS8Key) MarshalPublicKey(key *PublicKey) ([]byte, error)

PKCS8 包装公钥

func (PKCS8Key) ParsePrivateKey

func (this PKCS8Key) ParsePrivateKey(der []byte) (key *PrivateKey, err error)

PKCS8 解析私钥

func (PKCS8Key) ParsePublicKey

func (this PKCS8Key) ParsePublicKey(der []byte) (*PublicKey, error)

PKCS8 解析公钥

type ParameterSize

type ParameterSize struct {
	A, B int
	LH   int
	L    int

	NewHash func() hash.Hash
}

func GetSizes

func GetSizes(sizes ParameterSizes) (ParameterSize, bool)

type ParameterSizes

type ParameterSizes int
const (
	A2048B224SHA224 ParameterSizes = 1 + iota
	A2048B224SHA256
	A2048B256SHA256
	A3072B256SHA256
	A1024B160HAS160
)

func (ParameterSizes) Hash

func (ps ParameterSizes) Hash() hash.Hash

type Parameters

type Parameters struct {
	P, Q, G *big.Int

	GenParameters GenerationParameters
}

func (Parameters) Equal

func (params Parameters) Equal(xx Parameters) bool

Equal reports whether p, q, g and sizes have the same value.

type PrivateKey

type PrivateKey struct {
	PublicKey
	X *big.Int
}

PrivateKey represents a KCDSA private key.

func ParsePrivateKey

func ParsePrivateKey(derBytes []byte) (key *PrivateKey, err error)

PKCS8 解析私钥

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

Equal reports whether priv and x have the same value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

Public returns the public key corresponding to priv.

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)

crypto.Signer

type PublicKey

type PublicKey struct {
	Parameters
	Y *big.Int
}

PublicKey represents a KCDSA public key.

func ParsePublicKey

func ParsePublicKey(derBytes []byte) (*PublicKey, error)

PKCS8 解析公钥

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Equal reports whether pub and y have the same value.

func (*PublicKey) Verify

func (pub *PublicKey) Verify(hash, sig []byte, opts crypto.SignerOpts) (bool, error)

type SignerOpts

type SignerOpts struct {
	Hash Hasher
}

SignerOpts contains options for creating and verifying EC-KCDSA signatures.

func (*SignerOpts) GetHash

func (opts *SignerOpts) GetHash() Hasher

GetHash returns func() hash.Hash

func (*SignerOpts) HashFunc

func (opts *SignerOpts) HashFunc() crypto.Hash

HashFunc returns crypto.Hash

Jump to

Keyboard shortcuts

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