ecdh

package
v1.21.8 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

パッケージecdhはNIST曲線とCurve25519上での楕円曲線ディフィー・ヘルマンを実装します。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Curve

type Curve interface {
	// GenerateKey generates a random PrivateKey.
	//
	// Most applications should use [crypto/rand.Reader] as rand. Note that the
	// returned key does not depend deterministically on the bytes read from rand,
	// and may change between calls and/or between versions.
	GenerateKey(rand io.Reader) (*PrivateKey, error)

	// NewPrivateKey checks that key is valid and returns a PrivateKey.
	//
	// For NIST curves, this follows SEC 1, Version 2.0, Section 2.3.6, which
	// amounts to decoding the bytes as a fixed length big endian integer and
	// checking that the result is lower than the order of the curve. The zero
	// private key is also rejected, as the encoding of the corresponding public
	// key would be irregular.
	//
	// For X25519, this only checks the scalar length.
	NewPrivateKey(key []byte) (*PrivateKey, error)

	// NewPublicKey checks that key is valid and returns a PublicKey.
	//
	// For NIST curves, this decodes an uncompressed point according to SEC 1,
	// Version 2.0, Section 2.3.4. Compressed encodings and the point at
	// infinity are rejected.
	//
	// For X25519, this only checks the u-coordinate length. Adversarially
	// selected public keys can cause ECDH to return an error.
	NewPublicKey(key []byte) (*PublicKey, error)
	// contains filtered or unexported methods
}

func P256

func P256() Curve

P256は、NIST P-256 (FIPS 186-3, セクション D.2.3)、またはsecp256r1またはprime256v1としても知られる曲線を実装するCurveを返します。

この関数の複数の呼び出しは、等値チェックやスイッチ文に使用できる同じ値を返します。

func P384

func P384() Curve

P384は、NIST P-384(FIPS 186-3、セクション D.2.4)またはsecp384r1としても知られる のカーブを実装したものを返します。

この関数の複数回呼び出しでは、同じ値が返され、等価性のチェックやswitch文に使用できます。

func P521

func P521() Curve

P521は、NIST P-521(FIPS 186-3、セクションD.2.5)で定義されている、secp521r1としても知られる曲線を実装するCurveを返します。

この関数の複数の呼び出しは、同じ値を返します。これは、等値比較やスイッチ文で使用することができます。

func X25519

func X25519() Curve

X25519はCurve25519上でX25519関数を実装するCurveを返します (RFC 7748、セクション5)。

この関数の複数の呼び出しは同じ値を返すため、等価性チェックやスイッチ文に使用できます。

type PrivateKey

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

PrivateKeyは通常秘密に保持されるECDHの秘密鍵です。

これらの鍵は[crypto/x509.ParsePKCS8PrivateKey]でパースでき、crypto/x509.MarshalPKCS8PrivateKey でエンコードすることができます。NIST曲線の場合、パース後に[crypto/ecdsa.PrivateKey.ECDH]で変換する必要があります。

func (*PrivateKey) Bytes

func (k *PrivateKey) Bytes() []byte

Bytesは、プライベートキーのエンコーディングのコピーを返します。

func (*PrivateKey) Curve

func (k *PrivateKey) Curve() Curve

func (*PrivateKey) ECDH

func (k *PrivateKey) ECDH(remote *PublicKey) ([]byte, error)

ECDHはECDH交換を実行し、共有シークレットを返します。PrivateKeyとPublicKeyは同じ曲線を使用する必要があります。

NIST曲線の場合、これはSEC 1バージョン2.0セクション3.3.1で指定されたようにECDHを実行し、SEC 1バージョン2.0セクション2.3.5に従ってエンコードされたx座標を返します。結果は決して無限遠点ではありません。

X25519の場合、これはRFC 7748セクション6.1で指定されたようにECDHを実行します。結果が全て0値の場合、ECDHはエラーを返します。

func (*PrivateKey) Equal

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

Equalは、xがkと同じ秘密鍵を表しているかどうかを返します。

ただし、異なるエンコーディングを持つ等価な秘密鍵が存在する場合があることに注意してください。 この場合、このチェックではfalseが返されますが、ECDHの入力としては同じように機能します。

このチェックは、キーのタイプと曲線が一致している限り、一定の時間で実行されます。

func (*PrivateKey) Public

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

Publicは、すべての標準ライブラリの非公開キーの暗黙のインターフェースを実装します。crypto.PrivateKeyのドキュメントを参照してください。

func (*PrivateKey) PublicKey

func (k *PrivateKey) PublicKey() *PublicKey

type PublicKey

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

PublicKeyは通常、ワイヤ経由で送信されるECDHの共有キーです。

これらのキーは[crypto/x509.ParsePKIXPublicKey]で解析可能であり、 [crypto/x509.MarshalPKIXPublicKey]を使用してエンコードすることもできます。 NIST曲線の場合、解析後に[crypto/ecdsa.PublicKey.ECDH]で変換する必要があります。

func (*PublicKey) Bytes

func (k *PublicKey) Bytes() []byte

Bytesは公開鍵のエンコードのコピーを返します。

func (*PublicKey) Curve

func (k *PublicKey) Curve() Curve

func (*PublicKey) Equal

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

Equalは、xがkと同じ公開鍵を表すかどうかを返します。

注意:異なるエンコーディングを持つ同等の公開鍵があり、このチェックではfalseを返しますが、ECDHの入力として同じ結果を示す可能性があります。

キーのタイプとその曲線が一致している限り、このチェックは一定時間で実行されます。

Jump to

Keyboard shortcuts

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