source: trunk/CrypPlugins/PKCS5/PKCS5Settings.cs @ 138

Last change on this file since 138 was 138, checked in by Gerhard Junker, 13 years ago

TIGER Hash implementes under SSCext
ToDo Tiger Plugin

  • Property svn:keywords set to URL Author Date Rev Id
File size: 5.0 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////////////////////
2// CrypTool V2
3// © 2008 - Gerhard Junker
4// Apache License see http://www.apache.org/licenses/
5//
6// $HeadURL: trunk/CrypPlugins/PKCS5/PKCS5Settings.cs $
7//////////////////////////////////////////////////////////////////////////////////////////////////
8// $Revision:: 138                                                                            $://
9// $Author:: junker                                                                           $://
10// $Date:: 2008-12-10 09:53:31 +0000 (Wed, 10 Dec 2008)                                       $://
11//////////////////////////////////////////////////////////////////////////////////////////////////
12
13using System;
14using System.Collections.Generic;
15using System.Text;
16
17using Cryptool.PluginBase;
18using Cryptool.PluginBase.Cryptography;
19using Cryptool.PluginBase.IO;
20
21using System.Security.Cryptography;
22
23using System.ComponentModel;
24using System.Runtime.InteropServices;
25
26using System.Windows.Controls;
27
28namespace PKCS5
29{
30  /// <summary>
31  /// Settings for PKCS#5 v2
32  /// </summary>
33  public class PKCS5Settings : ISettings
34  {
35    private bool hasChanges = false;
36
37    #region ISettings Member
38
39
40    /// <summary>
41    /// selected internal hash HMAC function
42    /// </summary>
43    private PKCS5MaskGenerationMethod.ShaFunction selectedShaFunction
44                                        = PKCS5MaskGenerationMethod.ShaFunction.SHA256;
45
46    [ContextMenu("SHA Function",
47      "Select the hash function (MD5, SHA1 or one out of the SHA2 family)", 0,
48      DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null,
49      new string[] { "MD5", "SHA1", "SHA256", "SHA384", "SHA512" })]
50    [TaskPane("Select hash function",
51      "Select the hash function (MD2, SHA1 or one out of the SHA2 family)", "", 0, true,
52      DisplayLevel.Beginner, ControlType.ComboBox,
53      new string[] { "MD5", "SHA1", "SHA256", "SHA384", "SHA512" })]
54    public int SHAFunction
55    {
56      get
57      {
58        return (int)this.selectedShaFunction;
59      }
60      set
61      {
62        this.selectedShaFunction = (PKCS5MaskGenerationMethod.ShaFunction)value;
63        //CheckLength();
64        // set to max hash length
65        length = PKCS5MaskGenerationMethod.GetHashLength(selectedShaFunction) * 8;
66        hasChanges = true;
67        OnPropertyChanged("SHAFunction");
68        OnPropertyChanged("Length");
69      }
70    }
71
72    /// <summary>
73    /// count of hash loops
74    /// </summary>
75    private int count = 1000;
76    [TaskPane("Number of iterations (counter)",
77      "The counter determines how often the hash function is applied." +
78      " A value bigger than 1000 is recommended.", "", 1, false,
79      DisplayLevel.Beginner, ControlType.TextBox, ValidationType.RangeInteger, 1, 9999)]
80    public int Count
81    {
82      get
83      {
84        return count;
85      }
86      set
87      {
88        count = value;
89        if (count == 0)
90          count = 1000;
91        hasChanges = true;
92        OnPropertyChanged("Count");
93      }
94    }
95
96    /// <summary>
97    /// length of calculated hash in bits
98    /// </summary>
99    private int length = 256;
100    [TaskPane("Length of output key",
101      "The length of the output in bits must be a multiple of 8.", "", 2, false,
102      DisplayLevel.Beginner, ControlType.TextBox, ValidationType.RangeInteger, -64, 2048)]
103    public int Length
104    {
105      get
106      {
107        return length;
108      }
109      set
110      {
111        length = value;
112        if (length < 0) // change from bytes to bits [hack]
113          length *= -8;
114
115        while ((length & 0x07) != 0) // go to the next multiple of 8
116          length++;
117
118        //CheckLength();
119
120        hasChanges = true;
121        OnPropertyChanged("Length");
122      }
123    }
124
125    /// <summary>
126    /// Checks the length.
127    /// </summary>
128    private void CheckLength()
129    {
130      // get max length of this hash
131      int newlen = PKCS5MaskGenerationMethod.GetHashLength(selectedShaFunction) * 8;
132      if (newlen < length)
133      {
134        length = newlen; // reduce it to max length
135        hasChanges = true;
136      }
137    }
138
139    /// <summary>
140    /// Gets or sets a value indicating whether this instance has changes.
141    /// </summary>
142    /// <value>
143    ///         <c>true</c> if this instance has changes; otherwise, <c>false</c>.
144    /// </value>
145    public bool HasChanges
146    {
147      get
148      {
149        return hasChanges;
150      }
151      set
152      {
153        hasChanges = value;
154      }
155    }
156
157    #endregion
158
159    #region INotifyPropertyChanged Member
160
161    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
162
163    /// <summary>
164    /// Called when [property changed].
165    /// </summary>
166    /// <param name="name">The name.</param>
167    protected void OnPropertyChanged(string name)
168    {
169      if (PropertyChanged != null)
170      {
171        PropertyChanged(this, new PropertyChangedEventArgs(name));
172      }
173      hasChanges = true;
174    }
175
176    #endregion
177  }
178}
Note: See TracBrowser for help on using the repository browser.