コード例 #1
0
        public override int Read(
            byte[]  buffer,
            int offset,
            int count)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

            if (inCipher == null)
            {
                return(stream.Read(buffer, offset, count));
            }

            int num = 0;

            while (num < count)
            {
                if (mInBuf == null || mInPos >= mInBuf.Length)
                {
                    if (!FillInBuf())
                    {
                        break;
                    }
                }

                int numToCopy = System.Math.Min(count - num, mInBuf.Length - mInPos);
                Array.Copy(mInBuf, mInPos, buffer, offset + num, numToCopy);
                mInPos += numToCopy;
                num    += numToCopy;
            }

            return(num);
        }
コード例 #2
0
        public override void Flush()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

            // Note: outCipher.DoFinal is only called during Close()
            stream.Flush();
        }
コード例 #3
0
        public override void Write(
            byte[]  buffer,
            int offset,
            int count)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

            Debug.Assert(buffer != null);
            Debug.Assert(0 <= offset && offset <= buffer.Length);
            Debug.Assert(count >= 0);

            int end = offset + count;

            Debug.Assert(0 <= end && end <= buffer.Length);

            if (outCipher == null)
            {
                stream.Write(buffer, offset, count);
                return;
            }

            byte[] data = outCipher.ProcessBytes(buffer, offset, count);
            if (data != null)
            {
                stream.Write(data, 0, data.Length);
            }
        }
コード例 #4
0
        public override void Close()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            Platform.Dispose(stream);
            base.Close();
        }
コード例 #5
0
        public override void SetLength(
            long length)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            stream.SetLength(length);
        }
コード例 #6
0
        public override long Seek(
            long offset,
            SeekOrigin origin)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            return(stream.Seek(offset, origin));
        }
コード例 #7
0
ファイル: FipsAes.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IMacFactory <A> CreateMacFactory <A>(A algorithmDetails) where A : IAuthenticationParameters <A, Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service");

                ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm);

                return(((IMacFactoryProvider <A>)prov).CreateMacFactory(algorithmDetails));
            }
コード例 #8
0
ファイル: FipsAes.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IKeyWrapper <A> CreateKeyWrapper <A>(A algorithmDetails) where A : ISymmetricWrapParameters <A, Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service");

                ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm);

                return(((IKeyWrapperProvider <A>)prov).CreateKeyWrapper(algorithmDetails));
            }
コード例 #9
0
ファイル: FipsAes.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IAeadCipherBuilder <A> CreateAeadEncryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service");

                ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm);

                return(((IAeadEncryptorBuilderProvider <A>)prov).CreateAeadEncryptorBuilder(algorithmDetails));
            }
コード例 #10
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

                Platform.Dispose(stream);
            }
            base.Dispose(disposing);
        }
コード例 #11
0
        public ICipherBuilder <A> CreateEncryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm>
        {
            CryptoServicesRegistrar.ApprovedModeCheck(false, "Service");

            if (algorithmDetails is IParametersWithIV <IParameters <GeneralAlgorithm>, GeneralAlgorithm> )
            {
                return(((IEncryptorBuilderProvider <A>)provWithIV).CreateEncryptorBuilder(algorithmDetails));
            }
            return(((IEncryptorBuilderProvider <A>)prov).CreateEncryptorBuilder(algorithmDetails));
        }
コード例 #12
0
        public IMacFactory <A> CreateMacFactory <A>(A algorithmDetails) where A : IAuthenticationParameters <A, Algorithm>
        {
            CryptoServicesRegistrar.ApprovedModeCheck(false, "Service");

            if (algorithmDetails is IAuthenticationParametersWithIV <A, Algorithm> )
            {
                return(((IMacFactoryProvider <A>)provWithIV).CreateMacFactory(algorithmDetails));
            }

            return(((IMacFactoryProvider <A>)prov).CreateMacFactory(algorithmDetails));
        }
コード例 #13
0
        public override void WriteByte(
            byte b)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            if (outDigest != null)
            {
                outDigest.Update(b);
            }
            stream.WriteByte(b);
        }
コード例 #14
0
        public override void Close()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

            if (outCipher != null)
            {
                byte[] data = outCipher.DoFinal();
                stream.Write(data, 0, data.Length);
                stream.Flush();
            }
            Platform.Dispose(stream);
            base.Close();
        }
コード例 #15
0
            public IKeyWrapper <A> CreateKeyWrapper <A>(A algorithmDetails) where A : IParameters <Algorithm>
            {
                Rsa.Pkcs1v15WrapParameters pkcsP = algorithmDetails as Rsa.Pkcs1v15WrapParameters;
                if (pkcsP != null)
                {
                    CryptoServicesRegistrar.ApprovedModeCheck(false, "RSA");
                    General.Utils.ApprovedModeCheck("service", algorithmDetails.Algorithm);

                    return((IKeyWrapper <A>) new Rsa.Pkcs1v15KeyWrapper(pkcsP, publicKey));
                }

                return((IKeyWrapper <A>) new Fips.FipsRsa.RsaKeyWrapper(algorithmDetails as Fips.FipsRsa.OaepWrapParameters, publicKey));
            }
コード例 #16
0
            public ICipherBuilder <A> CreateDecryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service");

                ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm, true);

                if (algorithmDetails is TripleDes.ParametersWithIV)
                {
                    CryptoServicesRegistrar.GeneralModeCheck(approvedOnlyMode, algorithmDetails.Algorithm);

                    return(((IDecryptorBuilderProvider <A>)genProvForIV).CreateDecryptorBuilder(algorithmDetails));
                }
                return(((IDecryptorBuilderProvider <A>)prov).CreateDecryptorBuilder(algorithmDetails));
            }
コード例 #17
0
            public ISignatureFactory <A> CreateSignatureFactory <A>(A algorithmDetails) where A : IParameters <Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "RSA");

                Fips.FipsRsa.PssSignatureParameters pssParams = algorithmDetails as Fips.FipsRsa.PssSignatureParameters;
                if (pssParams != null)
                {
                    return((ISignatureFactory <A>) new SignatureFactory <Fips.FipsRsa.PssSignatureParameters>(pssParams, new Fips.FipsRsa.PssSignerProvider(pssParams, privateKey)));
                }

                Fips.FipsRsa.SignatureParameters sigParams = algorithmDetails as Fips.FipsRsa.SignatureParameters;

                return((ISignatureFactory <A>) new SignatureFactory <Fips.FipsRsa.SignatureParameters>(sigParams, new Fips.FipsRsa.SignerProvider(sigParams, privateKey)));
            }
コード例 #18
0
        public override int ReadByte()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            int b = stream.ReadByte();

            if (inDigest != null)
            {
                if (b >= 0)
                {
                    inDigest.Update((byte)b);
                }
            }
            return(b);
        }
コード例 #19
0
            public ISignatureFactory<A> CreateSignatureFactory<A>(A algorithmDetails) where A : IParameters<Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "EC");

                if (algorithmDetails is Fips.FipsEC.SignatureParameters)
                {
                    return (ISignatureFactory<A>)new SignatureFactory<Fips.FipsEC.SignatureParameters>(algorithmDetails as Fips.FipsEC.SignatureParameters, new Fips.FipsEC.SignerProvider(algorithmDetails as Fips.FipsEC.SignatureParameters, privateKey));
                }
                else
                {
                    General.Utils.ApprovedModeCheck("service", algorithmDetails.Algorithm);

                    return (ISignatureFactory<A>)new SignatureFactory<General.EC.SignatureParameters>(algorithmDetails as General.EC.SignatureParameters, new General.EC.SignerProvider(algorithmDetails as General.EC.SignatureParameters, privateKey));
                }
            }
コード例 #20
0
        public override void Write(
            byte[]  buffer,
            int offset,
            int count)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            if (outDigest != null)
            {
                if (count > 0)
                {
                    outDigest.BlockUpdate(buffer, offset, count);
                }
            }
            stream.Write(buffer, offset, count);
        }
コード例 #21
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

                if (outCipher != null)
                {
                    byte[] data = outCipher.DoFinal();
                    stream.Write(data, 0, data.Length);
                    stream.Flush();
                }
                Platform.Dispose(stream);
            }
            base.Dispose(disposing);
        }
コード例 #22
0
        public override void WriteByte(
            byte b)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

            if (outCipher == null)
            {
                stream.WriteByte(b);
                return;
            }

            byte[] data = outCipher.ProcessByte(b);
            if (data != null)
            {
                stream.Write(data, 0, data.Length);
            }
        }
コード例 #23
0
        public override int Read(
            byte[]  buffer,
            int offset,
            int count)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            int n = stream.Read(buffer, offset, count);

            if (inDigest != null)
            {
                if (n > 0)
                {
                    inDigest.BlockUpdate(buffer, offset, n);
                }
            }
            return(n);
        }
コード例 #24
0
        public override int ReadByte()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "CipherStream");

            if (inCipher == null)
            {
                return(stream.ReadByte());
            }

            if (mInBuf == null || mInPos >= mInBuf.Length)
            {
                if (!FillInBuf())
                {
                    return(-1);
                }
            }

            return(mInBuf[mInPos++]);
        }
コード例 #25
0
ファイル: FipsAes.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IBlockCipherBuilder <A> CreateBlockEncryptorBuilder <A>(A algorithmDetails) where A : IParameters <Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "Service");

                ValidateKeyUse(keyAlg, keyBytes, algorithmDetails.Algorithm);

                try
                {
                    return(((IBlockEncryptorBuilderProvider <A>)prov).CreateBlockEncryptorBuilder(algorithmDetails));
                }
                catch (InvalidCastException e)
                {
                    if (!AlgorithmModeUtils.isBlockCipherMode(algorithmDetails.Algorithm))
                    {
                        throw new NotSupportedException("cannot create a block encryptor from non-block mode", e);
                    }
                    throw e;
                }
            }
コード例 #26
0
            public IKeyWrapper <A> CreateKeyWrapper <A>(A algorithmDetails) where A : IParameters <Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DH");
                General.Utils.ApprovedModeCheck("service", algorithmDetails.Algorithm);

                ElGamal.OaepWrapParameters oaepP = algorithmDetails as ElGamal.OaepWrapParameters;
                if (oaepP != null)
                {
                    return((IKeyWrapper <A>) new ElGamal.OaepKeyWrapper(oaepP, publicKey));
                }

                ElGamal.Pkcs1v15WrapParameters pkcsP = algorithmDetails as ElGamal.Pkcs1v15WrapParameters;
                if (pkcsP != null)
                {
                    return((IKeyWrapper <A>) new ElGamal.Pkcs1v15KeyWrapper(pkcsP, publicKey));
                }

                throw new ArgumentException("unknown algorithm parameters");
            }
コード例 #27
0
        internal virtual IDigest WriteDigest()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            return(outDigest);
        }
コード例 #28
0
            public IAgreementCalculator<A> CreateAgreementCalculator<A>(A algorithmDetails) where A : IParameters<Algorithm>
            {
                CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "EC");

                return (IAgreementCalculator<A>)new FipsEC.AgreementCalculator(algorithmDetails as FipsEC.AgreementParameters, privateKey);
            }
コード例 #29
0
        public override void Flush()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "DigestStream");

            stream.Flush();
        }
コード例 #30
0
        internal virtual ISigner WriteSigner()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, "SignerStream");

            return(outSigner);
        }