Example #1
0
File: auth.cs Project: 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;
                }
Example #2
0
            // 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));
            }