Пример #1
0
        protected virtual ISigner MakeSigner(SignatureAndHashAlgorithm algorithm, bool raw, bool forSigning,
                                             ICipherParameters cp)
        {
            if ((algorithm != null) != TlsUtilities.IsTlsV12(mContext))
            {
                throw new InvalidOperationException();
            }
            if (algorithm != null && algorithm.Signature != SignatureAlgorithm.rsa)
            {
                throw new InvalidOperationException();
            }

            IDigest d;

            if (raw)
            {
                d = new NullDigest();
            }
            else if (algorithm == null)
            {
                d = new CombinedHash();
            }
            else
            {
                d = TlsUtilities.CreateHash(algorithm.Hash);
            }

            ISigner s;

            if (algorithm != null)
            {
                /*
                 * RFC 5246 4.7. In RSA signing, the opaque vector contains the signature generated
                 * using the RSASSA-PKCS1-v1_5 signature scheme defined in [PKCS1].
                 */
                s = new RsaDigestSigner(d, TlsUtilities.GetOidForHashAlgorithm(algorithm.Hash));
            }
            else
            {
                /*
                 * RFC 5246 4.7. Note that earlier versions of TLS used a different RSA signature scheme
                 * that did not include a DigestInfo encoding.
                 */
                s = new GenericSigner(CreateRsaImpl(), d);
            }
            s.Init(forSigning, cp);
            return(s);
        }
Пример #2
0
        public virtual TlsHandshakeHash NotifyPrfDetermined()
        {
            int prfAlgorithm = mContext.SecurityParameters.PrfAlgorithm;

            if (prfAlgorithm == PrfAlgorithm.tls_prf_legacy)
            {
                CombinedHash legacyHash = new CombinedHash();
                legacyHash.Init(mContext);
                mBuf.UpdateDigest(legacyHash);
                return(legacyHash.NotifyPrfDetermined());
            }

            this.mPrfHashAlgorithm = TlsUtilities.GetHashAlgorithmForPrfAlgorithm(prfAlgorithm);

            CheckTrackingHash((byte)mPrfHashAlgorithm);

            return(this);
        }
Пример #3
0
 internal CombinedHash(CombinedHash t)
 {
     this.mContext = t.mContext;
     this.mMd5     = TlsUtilities.CloneHash(HashAlgorithm.md5, t.mMd5);
     this.mSha1    = TlsUtilities.CloneHash(HashAlgorithm.sha1, t.mSha1);
 }