Friday, 20 October 2017
arrow JDiceChecker 5.0.0.1 arrow RandomTest arrow RandomTestSuite.java (3)
RandomTestSuite.java (3rd part) (Random Test Suite class for all random number tests) Print E-mail
Get C++ DiceLock cipher architecture source code packages of DiceLock for Microsoft Visual Studio 2013 and DiceLock-x for Linux with Test Driver Programs and Response Test Vector files to verify that both them work as expected.
DiceLock for Windows and Linux
DiceLock Security governing software licenses are Free/Libre Source Code License and Educational and Research License
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
 
    // CHECKING RANDOMNESS
 
  /**
   * Tests the BaseCryptoRandomStream untill an error is found with all instantiated random tests and returns the boolean random value
   * 
   * @param     stream      bit stream to be checked for randomness properties
   * @return    boolean:    boolean indicating if "stream" tested presents random properties
   *            true:       "stream" is a randomized bit stream
   *            false:      "stream" is not a randomized bit stream
   */ 
    public boolean IsRandom(BaseCryptoRandomStream stream) {
      int i;
      
      this.random = true;
      i = this.GetFirstTest().ordinal();
      while ((i < this.GetMaximumNumberOfTests().ordinal()) && (this.random)) {
        if (this.suite[i] != null) {
          this.random &= this.suite[i].IsRandom(stream);
          nonRandomTest = this.suite[i].GetType();
          if (this.suite[i].GetError() != RandomTestErrors.NoError) {
            errorTest = this.suite[i].GetType();
            this.numberOfErrors = 1;
          }
        }
        i++;
      }
      return this.random;
    }
 
  /**
   * Tests the BaseCryptoRandomStream with all instantiated random tests and returns the random value
   * 
   * @param     stream      bit stream to be checked for randomness properties
   * @return    boolean:    boolean indicating if "stream" tested presents random properties
   *            true:       "stream" is a randomized bit stream
   *            false:      "stream" is not a randomized bit stream
   */ 
    public boolean TestRandom(BaseCryptoRandomStream stream) {
      int i;
      
      this.random = true;
      for ( i = this.GetFirstTest().ordinal(); i < this.GetMaximumNumberOfTests().ordinal(); i++ ) {
        if (this.suite[i] != null) {
          this.random &= this.suite[i].IsRandom(stream);
          if (!(this.suite[i].IsRandom())) {
            if (this.suite[i].GetError() != RandomTestErrors.NoError) {
              if (this.error == RandomTestErrors.NoError)
                this.error = this.suite[i].GetError();
              else 
                if (this.error != this.suite[i].GetError())
                  this.error = RandomTestErrors.MultipleErrors;
              numberOfErrors++;
            }
          }
        }
      }
      return this.random;
    }
 
    // INITIALIZE SUITE
    
  /**
   * Initializes all random tests in the suite
   * 
   */ 
    public void Initialize() {
      int i;
      
      for ( i = this.GetFirstTest().ordinal(); i < this.GetMaximumNumberOfTests().ordinal(); i++ ) {
        if (this.suite[i] != null) {
          this.suite[i].Initialize();
        }
      }
      this.random = false;
      this.error = RandomTestErrors.NoError;
      this.numberOfErrors = 0;
      this.errorTest = RandomTests.NotDefined;
    }
 
  /**
   * Sets Alpha all random tests in the suite
   * 
   * @param     alpha     "alpha" confidence parameter to verify randomness 
   */ 
    public void SetAlpha(double alpha) {
      int i;
 
      for (i = 0; i < RandomTests.NumberOfTests.ordinal(); i++)
        if (this.suite[i] != null)
          this.suite[i].SetAlpha(alpha);
    }
 
    // GETTING SUITE RESULTS
 
  /**
   * Gets the RandomTestSuite random state of the last executed BaseCryptoRandomStream
   * 
   * @return    boolean:      returns randomness of last verified bit stream
   */ 
    public boolean IsRandom() {
          
      return this.random;
    }
 
  /**
   * Gets the number of Random Tests that contains the suite
   * 
   * @return    int:    number of random number tests instantiated in the suite
   */ 
    public int GetInstantiatedTests() {
          
        return this.instantiatedTests;
    }
 
  /**
   * Gets the minimum random stream length in bits corresponding
   * to random number test with higher random stream length
   * 
   * @return    int:    length in bits of the shorter bit stream that can be verified with random number tests instantiated in the suite
   */ 
    public int GetMinimumLength() {
      int minimumMax;
 
      minimumMax = 0;
      for(RandomTests test : RandomTests.values()) {
        if ( this.Exist(test) ) {
          if ( this.GetRandomTest(test).GetMinimumLength() > minimumMax ) {
            minimumMax = this.GetRandomTest(test).GetMinimumLength();
          }
        }
      }
      return minimumMax;
    }
 
  /**
   * Gets the corresponding random number test 
   * with higher minimum random stream length in bits 
   * 
   * @return    RandomTests:    enumeration value of the random number test with higher minimum random stream length in bits 
   */ 
    public RandomTests GetMinimumLengthRandomTest() {
      int minimumMax;
      RandomTests randomTest;
 
      minimumMax = 0;
      randomTest = RandomTests.NotDefined;
      for(RandomTests test : RandomTests.values()) {
        if ( this.Exist(test) ) {
          if ( this.GetRandomTest(test).GetMinimumLength() > minimumMax ) {
            minimumMax = this.GetRandomTest(test).GetMinimumLength();
            randomTest = test;
          }
        }
      }
      return randomTest;
    }
 
  /**
   * Gets the random test in the RandomTestSuite that does not verify last bit stream as randomized
   * 
   * @return    RandomTests     enumeration value pointing the failed random test of last verified bit stream
   */ 
    public RandomTests GetNonRandomTest() {
          
      return this.nonRandomTest;
    }
 
  /**
   * Gets the RandomTestError error of the last executed bit stream
   * 
   * @return    RandomTestErrors    error of the last verified bit stream
   */ 
    public RandomTestErrors GetError() {
          
        return this.error;
    }
 
  /**
   * Gets the RandomTest that produced the error of last executed bit stream
   * 
   * @return    RandomTests    enumeration value pointing random number test that produced the error of last executed bit stream
   */ 
    public RandomTests GetErrorTest() {
          
      return this.errorTest;
    }
 
  /**
   * Indicates if a random test object exists in the suite
   * 
   * @param     test        RandomTests enumeration value to verify if it has been instantiated in the suite
   * @return    boolean:    indicates if random test is instantiated in the suite
   *            true:       random test instantiated
   *            false:      random test not instantiated
   */ 
    public boolean Exist(RandomTests test) {
          
      return (this.suite[test.ordinal()] != null);
    }
 
}