public override void WriteByte( byte b) { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestStream"); digest.Update(b); }
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)))); } } }
internal DigestFactory(TParams parameters, IEngineProvider <IDigest> digestProvider, int digestSize) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.parameters = parameters; this.digestProvider = digestProvider; this.digestSize = digestSize; }
public override void WriteByte( byte b) { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "SignatureStream"); signer.Update(b); }
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() }); } }
public int Collect(byte[] destination, int offset) { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestResult"); digest.DoFinal(destination, offset); return(digest.GetDigestSize()); }
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); }
/// <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)); }
public override void Write( byte[] buffer, int offset, int count) { CryptoServicesRegistrar.ApprovedModeCheck(approvedOnlyMode, "DigestStream"); if (count > 0) { digest.BlockUpdate(buffer, offset, count); } }
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()); }
internal CipherBuilderImpl(TParams parameters, IBufferedCipher cipher) { this.isApprovedModeOnly = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.parameters = parameters; this.cipher = cipher; }
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())); }
internal XofCalculator(IXof xof) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.xof = xof; this.stream = new DigestBucket(xof); }
/// <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); }
public ICipher BuildCipher(Stream stream) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, parameters.Algorithm.Name); return(new CipherImpl(cipher, new CipherStream(stream, cipher))); }
public SignatureBucket( ISigner signer) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.signer = signer; }
internal DigestCalculator(IDigest digest) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.digest = digest; this.stream = new DigestBucket(digest); }
public ICipher BuildCipher(Stream stream) { CryptoServicesRegistrar.ApprovedModeCheck(isApprovedModeOnly, parameters.Algorithm.Name); return(new AeadCipherImpl(parameters.MacSizeInBits, cipher, new CipherStream(stream, new BufferedAeadBlockCipher(cipher)))); }
public DigestBucket( IDigest digest) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.digest = digest; }
internal DigestResult(IDigest digest) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.digest = digest; }
/// <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))); }
internal XofFactory(TParams parameters, IEngineProvider <IXof> xofProvider) { this.approvedOnlyMode = CryptoServicesRegistrar.IsInApprovedOnlyMode(); this.parameters = parameters; this.xofProvider = xofProvider; }
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; }
/// <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))); }
/// <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; }