95dfe4db53d4ef06f17f476bc442ca4f499ac3ed
[mono.git] / mcs / class / corlib / System.Security.Cryptography / RC2.cs
1 //
2 // System.Security.Cryptography.RC2.cs
3 //
4 // Authors: 
5 //      Andrew Birkett (andy@nobugs.org)
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //          
8
9 using System;
10
11 namespace System.Security.Cryptography {
12
13         public abstract class RC2 : SymmetricAlgorithm {
14
15                 public static new RC2 Create () 
16                 {
17                         return Create ("System.Security.Cryptography.RC2");
18                 }
19                 
20                 public static new RC2 Create (string algName) 
21                 {
22                         return (RC2) CryptoConfig.CreateFromName (algName);
23                 }
24
25                 protected int EffectiveKeySizeValue;
26
27                 public virtual int EffectiveKeySize {
28                         get {
29                                 if (EffectiveKeySizeValue == 0)
30                                         return KeySizeValue;
31                                 else
32                                         return EffectiveKeySizeValue;
33                         }
34                         set { 
35                                 if (!KeySizes.IsLegalKeySize (LegalKeySizesValue, value))
36                                         throw new CryptographicException ("key size not supported by algorithm");
37                                 EffectiveKeySizeValue = value; 
38                         }
39                 }
40
41                 // Overridden, which makes me suspect it changes effective keysize too?
42                 public override int KeySize {
43                         get { return KeySizeValue; }
44                         set { KeySizeValue = value; }
45                 }
46                                 
47                 public RC2 () 
48                 {
49                         KeySizeValue = 128;
50                         BlockSizeValue = 64;
51                         FeedbackSizeValue = 64;
52
53                         // The RFC allows keys of 1 to 128 bytes, but MS impl only supports
54                         // 40 to 128 bits, sigh.
55                         LegalKeySizesValue = new KeySizes[1];
56                         LegalKeySizesValue[0] = new KeySizes(40, 128, 8);
57
58                         LegalBlockSizesValue = new KeySizes[1];
59                         LegalBlockSizesValue[0] = new KeySizes(64, 64, 0);
60                 }
61         }
62 }