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

            digest.Update(b);
        }
Ejemplo 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))));
                }
            }
        }
Ejemplo 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;
 }
Ejemplo n.º 4
0
        public override void WriteByte(
            byte b)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "SignatureStream");

            signer.Update(b);
        }
Ejemplo n.º 5
0
 internal AeadCipherBuilderImpl(bool forEncryption, TParams parameters, IAeadBlockCipher cipher)
 {
     this.isApprovedModeOnly = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.forEncryption      = forEncryption;
     this.parameters         = parameters;
     this.cipher             = cipher;
 }
Ejemplo n.º 6
0
        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() });
            }
        }
Ejemplo n.º 7
0
        public int Collect(byte[] destination, int offset)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestResult");

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

            aeadCipher.ProcessAadByte(b);
        }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo 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));
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 13
0
        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());
        }
Ejemplo n.º 14
0
 internal CipherBuilderImpl(TParams parameters, IBufferedCipher cipher)
 {
     this.isApprovedModeOnly = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.parameters         = parameters;
     this.cipher             = cipher;
 }
Ejemplo 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()));
 }
Ejemplo n.º 17
0
 internal XofCalculator(IXof xof)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.xof    = xof;
     this.stream = new DigestBucket(xof);
 }
Ejemplo 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);
        }
Ejemplo n.º 19
0
        public ICipher BuildCipher(Stream stream)
        {
            CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, parameters.Algorithm.Name);

            return(new CipherImpl(cipher, new CipherStream(stream, cipher)));
        }
Ejemplo n.º 20
0
 public SignatureBucket(
     ISigner signer)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.signer           = signer;
 }
Ejemplo n.º 21
0
 internal DigestCalculator(IDigest digest)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.digest           = digest;
     this.stream           = new DigestBucket(digest);
 }
Ejemplo 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))));
        }
Ejemplo n.º 23
0
 public DigestBucket(
     IDigest digest)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.digest           = digest;
 }
Ejemplo n.º 24
0
 internal DigestResult(IDigest digest)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.digest           = digest;
 }
Ejemplo 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)));
        }
Ejemplo n.º 26
0
 internal XofFactory(TParams parameters, IEngineProvider <IXof> xofProvider)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.parameters       = parameters;
     this.xofProvider      = xofProvider;
 }
Ejemplo n.º 27
0
        public IBlockResult GetResult()
        {
            CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestStream");

            return(new DigestResult(digest));
        }
Ejemplo n.º 28
0
 public PasswordBasedDeriver(A algorithmDetails, PbeParametersGenerator generator)
 {
     this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode();
     this.algorithmDetails = algorithmDetails;
     this.generator        = generator;
 }
Ejemplo 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)));
        }
Ejemplo 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;
 }