2 // MACTripleDES.cs: Handles MAC with TripleDES
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
12 using Mono.Security.Cryptography;
14 namespace System.Security.Cryptography {
17 // a. FIPS PUB 81: DES MODES OF OPERATION
18 // MAC: Appendix F (MACDES not MACTripleDES but close enough ;-)
19 // http://www.itl.nist.gov/fipspubs/fip81.htm
21 // LAMESPEC: MACTripleDES == MAC-CBC using TripleDES (not MAC-CFB).
22 public class MACTripleDES: KeyedHashAlgorithm {
24 private TripleDES tdes;
25 private MACAlgorithm mac;
26 private bool m_disposed;
28 public MACTripleDES ()
30 Setup ("TripleDES", null);
33 public MACTripleDES (byte[] rgbKey)
36 throw new ArgumentNullException ("rgbKey");
37 Setup ("TripleDES", rgbKey);
40 public MACTripleDES (string strTripleDES, byte[] rgbKey)
43 throw new ArgumentNullException ("rgbKey");
44 if (strTripleDES == null)
45 Setup ("TripleDES", rgbKey);
47 Setup (strTripleDES, rgbKey);
50 private void Setup (string strTripleDES, byte[] rgbKey)
52 tdes = TripleDES.Create (strTripleDES);
53 // if rgbKey is null we keep the randomly generated key
55 // this way we get the TripleDES key validation (like weak
56 // and semi-weak keys)
59 HashSizeValue = tdes.BlockSize;
60 // we use Key property to get the additional validations
61 // (from KeyedHashAlgorithm ancestor)
63 mac = new MACAlgorithm (tdes);
72 protected override void Dispose (bool disposing)
75 // note: we ALWAYS zeroize keys (disposing or not)
77 // clear our copy of the secret key
79 Array.Clear (KeyValue, 0, KeyValue.Length);
80 // clear the secret key (inside TripleDES)
85 // disposed managed stuff
90 base.Dispose (disposing);
95 public override void Initialize ()
98 throw new ObjectDisposedException ("MACTripleDES");
100 mac.Initialize (KeyValue);
103 protected override void HashCore (byte[] rgb, int ib, int cb)
106 throw new ObjectDisposedException ("MACTripleDES");
111 mac.Core (rgb, ib, cb);
114 protected override byte[] HashFinal ()
117 throw new ObjectDisposedException ("MACTripleDES");