Esempio n. 1
0
        public override void WriteByte(
            byte b)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestStream");

            digest.Update(b);
        }
Esempio n. 2
0
        public ICipher BuildPaddedCipher(Stream stream, IBlockCipherPadding padding)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, parameters.Algorithm.Name);

            if (forEncryption)
            {
                if (stream.CanWrite)
                {
                    return(new CipherImpl(cipher, new PaddingStream(forEncryption, padding, BlockSize, new CipherStream(stream, cipher))));
                }
                else
                {
                    return(new CipherImpl(cipher, new CipherStream(new PaddingStream(forEncryption, padding, BlockSize, stream), cipher)));
                }
            }
            else
            {
                if (stream.CanWrite)
                {
                    return(new CipherImpl(cipher, new CipherStream(new PaddingStream(forEncryption, padding, BlockSize, stream), cipher)));
                }
                else
                {
                    return(new CipherImpl(cipher, new PaddingStream(forEncryption, padding, BlockSize, new CipherStream(stream, cipher))));
                }
            }
        }
Esempio n. 3
0
 internal DigestFactory(TParams parameters, IEngineProvider <IDigest> digestProvider, int digestSize)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.parameters       = parameters;
     this.digestProvider   = digestProvider;
     this.digestSize       = digestSize;
 }
Esempio n. 4
0
        public override void WriteByte(
            byte b)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "SignatureStream");

            signer.Update(b);
        }
Esempio n. 5
0
 internal AeadCipherBuilderImpl(bool forEncryption, TParams parameters, IAeadBlockCipher cipher)
 {
     this.isApprovedModeOnly = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.forEncryption      = forEncryption;
     this.parameters         = parameters;
     this.cipher             = cipher;
 }
        public byte[][] DeriveKeyAndIV(TargetKeyType keyType, int keySizeInBytes, int ivSizeInBytes)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "PasswordBasedDeriver");

            if (approvedOnlyMode)
            {
                if (keySizeInBytes < 14)
                {
                    throw new CryptoUnapprovedOperationError("keySizeInBytes must be at least 14");
                }
            }

            if (keyType == TargetKeyType.MAC)
            {
                ParametersWithIV paramWithIv = (ParametersWithIV)generator.GenerateDerivedMacParameters(keySizeInBytes * 8, ivSizeInBytes * 8);

                return(new byte[][] { ((KeyParameter)paramWithIv.Parameters).GetKey(), paramWithIv.GetIV() });
            }
            else
            {
                ParametersWithIV paramWithIv = (ParametersWithIV)generator.GenerateDerivedParameters(keySizeInBytes * 8, ivSizeInBytes * 8);

                return(new byte[][] { ((KeyParameter)paramWithIv.Parameters).GetKey(), paramWithIv.GetIV() });
            }
        }
Esempio n. 7
0
        public int Collect(byte[] destination, int offset)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestResult");

            digest.DoFinal(destination, offset);
            return(digest.GetDigestSize());
        }
Esempio n. 8
0
        public override void WriteByte(
            byte b)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "AAD");

            aeadCipher.ProcessAadByte(b);
        }
        /// <summary>
        /// Store the final result of the operation by copying it into the destination array.
        /// </summary>
        /// <returns>The number of bytes copied into destination.</returns>
        /// <param name="destination">The byte array to copy the result into.</param>
        /// <param name="offset">The offset into destination to start copying the result at.</param>
        public int Collect(byte[] destination, int offset)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "SimpleBlockResult");

            Array.Copy(result, 0, destination, offset, result.Length);

            return(result.Length);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the result.
        /// </summary>
        /// <returns>The result.</returns>
        /// <param name="outputLength">The length (in bytes) of the output wanted from the XOF.</param>
        public IBlockResult GetResult(int outputLength)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "XofResult");

            byte[] rv = new byte[outputLength];

            xof.DoOutput(rv, 0, outputLength);

            return(new SimpleBlockResult(rv));
        }
Esempio n. 11
0
        public override void Write(
            byte[]  buffer,
            int offset,
            int count)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestStream");

            if (count > 0)
            {
                digest.BlockUpdate(buffer, offset, count);
            }
        }
Esempio n. 12
0
        public override void Write(
            byte[]  buffer,
            int offset,
            int count)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "AAD");

            if (count > 0)
            {
                aeadCipher.ProcessAadBytes(buffer, offset, count);
            }
        }
        public byte[] DeriveKey(TargetKeyType keyType, int keySizeInBytes)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "PasswordBasedDeriver");

            if (approvedOnlyMode)
            {
                if (keySizeInBytes < 14)
                {
                    throw new CryptoUnapprovedOperationError("keySizeInBytes must be at least 14");
                }
            }

            if (keyType == TargetKeyType.MAC)
            {
                return(((KeyParameter)generator.GenerateDerivedMacParameters(keySizeInBytes * 8)).GetKey());
            }

            return(((KeyParameter)generator.GenerateDerivedParameters(keySizeInBytes * 8)).GetKey());
        }
Esempio n. 14
0
 internal CipherBuilderImpl(TParams parameters, IBufferedCipher cipher)
 {
     this.isApprovedModeOnly = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.parameters         = parameters;
     this.cipher             = cipher;
 }
Esempio n. 15
0
 public AADBucket(
     IAeadBlockCipher aeadCipher)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.aeadCipher       = aeadCipher;
 }
 public static A CreateGenerator <A>(IGenerationServiceType <A> type)
 {
     return(ThreadSecurityContext.CreateGenerator(type, CryptoServicesRegistrar.GetSecureRandom()));
 }
Esempio n. 17
0
 internal XofCalculator(IXof xof)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.xof    = xof;
     this.stream = new DigestBucket(xof);
 }
Esempio n. 18
0
        /// <summary>
        /// Return the final result of the operation.
        /// </summary>
        /// <returns>A block of bytes, representing the result of an operation.</returns>
        public byte[] Collect()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "SimpleBlockResult");

            return(result);
        }
Esempio n. 19
0
        public ICipher BuildCipher(Stream stream)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, parameters.Algorithm.Name);

            return(new CipherImpl(cipher, new CipherStream(stream, cipher)));
        }
Esempio n. 20
0
 public SignatureBucket(
     ISigner signer)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.signer           = signer;
 }
Esempio n. 21
0
 internal DigestCalculator(IDigest digest)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.digest           = digest;
     this.stream           = new DigestBucket(digest);
 }
Esempio n. 22
0
        public ICipher BuildCipher(Stream stream)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, parameters.Algorithm.Name);

            return(new AeadCipherImpl(parameters.MacSizeInBits, cipher, new CipherStream(stream, new BufferedAeadBlockCipher(cipher))));
        }
Esempio n. 23
0
 public DigestBucket(
     IDigest digest)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.digest           = digest;
 }
Esempio n. 24
0
 internal DigestResult(IDigest digest)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.digest           = digest;
 }
Esempio n. 25
0
        /// <summary>
        /// Create a stream calculator for the digest algorithm associated with this factory. The stream
        /// calculator is used for the actual operation of entering the data to be digested
        /// and producing the digest block.
        /// </summary>
        /// <returns>A calculator producing an IBlockResult with the final digest in it.</returns>
        public IStreamCalculator <IBlockResult> CreateCalculator()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestFactory");

            return(new DigestCalculator(digestProvider.CreateEngine(EngineUsage.GENERAL)));
        }
Esempio n. 26
0
 internal XofFactory(TParams parameters, IEngineProvider <IXof> xofProvider)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.parameters       = parameters;
     this.xofProvider      = xofProvider;
 }
Esempio n. 27
0
        public IBlockResult GetResult()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestStream");

            return(new DigestResult(digest));
        }
 public PasswordBasedDeriver(A algorithmDetails, PbeParametersGenerator generator)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.algorithmDetails = algorithmDetails;
     this.generator        = generator;
 }
Esempio n. 29
0
        /// <summary>
        /// Create a stream calculator for the XOF associated with this factory. The stream
        /// calculator is used for the actual operation of entering the data to be processed
        /// and producing the XOF output.
        /// </summary>
        /// <returns>A calculator producing an StreamResult which can be used to read the output from the XOF.</returns>
        public IVariableStreamCalculator <IBlockResult> CreateCalculator()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "XofFactory");

            return(new XofCalculator(xofProvider.CreateEngine(EngineUsage.GENERAL)));
        }
Esempio n. 30
0
 /// <summary>
 /// Base constructor - a wrapper for the passed in byte array.
 /// </summary>
 /// <param name="result">The byte array to be wrapped.</param>
 public SimpleBlockResult(byte[] result)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.result           = result;
 }