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文に使用できます。
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) 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