コード例 #1
0
ファイル: ed25519.cs プロジェクト: zjmit/go2cs
            // Any methods implemented on PublicKey might need to also be implemented on
            // PrivateKey, as the latter embeds the former and will expose its methods.

            // Equal reports whether pub and x have the same value.
            public static bool Equal(this PublicKey pub, crypto.PublicKey x)
            {
                PublicKey(xx, ok) = x._ <PublicKey>();
                if (!ok)
                {
                    return(false);
                }

                return(bytes.Equal(pub, xx));
            }
コード例 #2
0
ファイル: auth.cs プロジェクト: zjmit/go2cs
            // verifyHandshakeSignature verifies a signature against pre-hashed
            // (if required) handshake contents.
            private static error verifyHandshakeSignature(byte sigType, crypto.PublicKey pubkey, crypto.Hash hashFunc, slice <byte> signed, slice <byte> sig)
            {
                if (sigType == signatureECDSA)
                {
                    ptr <ecdsa.PublicKey> (pubKey, ok) = pubkey._ <ptr <ecdsa.PublicKey> >();
                }
                if (!ok)
                {
                    return(error.As(fmt.Errorf("expected an ECDSA public key, got %T", pubkey)) !);
                }
                if (!ecdsa.VerifyASN1(pubKey, signed, sig))
                {
                    return(error.As(errors.New("ECDSA verification failure")) !);
                }
                else if (sigType == signatureEd25519)
                {
                    (pubKey, ok) = pubkey._ <ed25519.PublicKey>();
                }
                if (!ok)
                {
                    return(error.As(fmt.Errorf("expected an Ed25519 public key, got %T", pubkey)) !);
                }
                if (!ed25519.Verify(pubKey, signed, sig))
                {
                    return(error.As(errors.New("Ed25519 verification failure")) !);
                }
                else if (sigType == signaturePKCS1v15)
                {
                    (pubKey, ok) = pubkey._ <ptr <rsa.PublicKey> >();
                }
                if (!ok)
                {
                    return(error.As(fmt.Errorf("expected an RSA public key, got %T", pubkey)) !);
                }
                {
                    var err__prev1 = err;

                    var err = rsa.VerifyPKCS1v15(pubKey, hashFunc, signed, sig);

                    if (err != null)
                    {
                        return(error.As(err) !);
                    }
                    err = err__prev1;
                }
コード例 #3
0
ファイル: ecdsa.cs プロジェクト: zjmit/go2cs
            // Any methods implemented on PublicKey might need to also be implemented on
            // PrivateKey, as the latter embeds the former and will expose its methods.

            // Equal reports whether pub and x have the same value.
            //
            // Two keys are only considered to have the same value if they have the same Curve value.
            // Note that for example elliptic.P256() and elliptic.P256().Params() are different
            // values, as the latter is a generic not constant time implementation.
            private static bool Equal(this ptr <PublicKey> _addr_pub, crypto.PublicKey x)
            {
                ref PublicKey pub = ref _addr_pub.val;