Sunday, 22 October 2017

DiceLockSecurity Knowledge

DicelockSecurity (version 9.X)

Windows - Source Code

DiceLock 9.0.0.1
DiceChecker 6.0.0.1
HashDigester 6.0.0.1
DiceLockTime 4.0.0.1
Previous Versions
DiceLock 8.0.0.1
serialTest.cpp (Serial random number test C++ source code file) 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

DiceLock is protected by US patent 7508945 and European Patent 1182777 where applicable.

DiceLock and DiceLock logo are trademarks or registered trademarks in the EC, USA and others.

License information can be obtained at our corporate web site




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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 
//
// Creator:    http://www.dicelocksecurity.com
// Version:    vers.8.0.0.1
//
// Copyright (C) 2008-2012 DiceLock Security, LLC. All rights reserved.
//
//                               DISCLAIMER
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 
// DICELOCK IS A REGISTERED TRADEMARK OR TRADEMARK OF THE OWNERS.
// 
 
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include "serialTest.h"
 
 
namespace DiceLockSecurity {
  
  namespace RandomTest {
 
  // Random Test Class enumerator name
  const RandomTests SerialTest::test = Serial;
  // Random Test Class minimum stream length
  const unsigned long int  SerialTest::minimumLength = 128;
 
  // Constructor, default 
  SerialTest::SerialTest() {
 
    this->blockLength = 16;
    this->pvalue2 = 0.0;        
    this->psim = 0.0; 
    this->psim1 = 0.0; 
    this->psim2 = 0.0; 
    this->delta1 = 0.0; 
    this->delta2 = 0.0;
  }
 
 
  // Constructor with a MathematicalFunctions object instantiated 
  SerialTest::SerialTest(MathematicalFunctions* mathFuncObj) {
 
    this->blockLength = 16;
    this->pvalue2 = 0.0;        
    this->psim = 0.0; 
    this->psim1 = 0.0; 
    this->psim2 = 0.0; 
    this->delta1 = 0.0; 
    this->delta2 = 0.0;
  }
 
  // Destructor
  SerialTest::~SerialTest() {
 
    this->blockLength = 0;
    this->pvalue2 = 0.0;        
    this->psim = 0.0; 
    this->psim1 = 0.0; 
    this->psim2 = 0.0; 
    this->delta1 = 0.0; 
    this->delta2 = 0.0;
  }
 
  // Psi2 function 
  double SerialTest::psi2(signed long int m, BaseCryptoRandomStream* bitStream) {
    signed long int i, j, k, powLen;
    double  sum, numOfBlocks;
    unsigned long int*  P;
  
    if ((m == 0) || (m == -1)) 
      return 0.0;
    numOfBlocks = bitStream->GetBitLength();
    powLen = (int)pow((long double)2,(int)m+1)-1;
    P = (unsigned long int*)calloc(powLen,sizeof(unsigned long int));
    if (P == NULL) {
      this->error = InsufficientMemory;
      return 0.0;
    }
    for(i = 1; i < powLen-1; i++) 
      P[i] = 0;
    for(i = 0; i < numOfBlocks; i++) {     
      k = 1;
      for(j = 0; j < (int)m; j++) {
        if (bitStream->GetBitPosition((i+j)%bitStream->GetBitLength()) == 0)
          k *= 2;
        else if (bitStream->GetBitPosition((i+j)%bitStream->GetBitLength()) == 1)
          k = 2*k+1;
      }
      P[k-1]++;
    }
    sum = 0.0;
    for(i = (int)pow((long double)2,(int)m)-1; i < (int)pow((long double)2,(int)m+1)-1; i++)
      sum += pow((long double)P[i],2);
    sum = (sum * pow((long double)2,(int)m)/(double)bitStream->GetBitLength()) - (double)bitStream->GetBitLength();
    free(P);
    return sum;
  }
 
  // Gets the BaseRandomTest random state of the last executed BaseCryptoRandomStream
  bool SerialTest::IsRandom(void) {
 
    return BaseRandomTest::IsRandom();
  }
 
  // Tests randomness of the BaseCryptoRandomStream and returns the random value
  bool SerialTest::IsRandom(BaseCryptoRandomStream* bitStream) {
 
    if (bitStream->GetBitLength() < (unsigned long int)this->GetMinimumLength()) {
      this->error = InsufficientNumberOfBits;
      this->random = false;
      return this->random;
    }
    this->error = NoError;
    this->psim = psi2(this->blockLength, bitStream);
    this->psim1 = psi2(this->blockLength-1, bitStream);
    this->psim2 = psi2(this->blockLength-2, bitStream);
    this->delta1 = this->psim - this->psim1;
    this->delta2 = this->psim - 2.0*this->psim1 + this->psim2;
    this->pValue = this->mathFuncs->IGammaC(pow((long double)2,(int)(this->blockLength-1))/2,this->delta1/2.0);
    if (_isnan(this->pValue)) {
      this->pValue = 0;
      this->error = MathematicianNAN;
      this->random = false;
      return this->random;
    }
    this->pvalue2 = this->mathFuncs->IGammaC(pow((long double)2,(int)(this->blockLength-2))/2,this->delta2/2.0);
    if (_isnan(this->pvalue2)) {
      this->pvalue2 = 0;
      this->error = MathematicianNAN;
      this->random = false;
      return this->random;
    }
    if (this->pValue < this->alpha) {
      this->random = false;
    }
    else {
      this->random = true;
    }
    if (this->pvalue2 < this->alpha) {
      this->random = false;
    }
    return this->random;
  }
 
  // Initializes the object
  void SerialTest::Initialize(void) {
 
    BaseRandomTest::Initialize();
    this->pvalue2 = 0.0;        
    this->psim = 0.0; 
    this->psim1 = 0.0; 
    this->psim2 = 0.0; 
    this->delta1 = 0.0; 
    this->delta2 = 0.0;
  }
 
  // Gets the type of the object
  RandomTests SerialTest::GetType(void) {
 
    return this->test;
  }
 
  // Gets the minimum random stream length
  unsigned long int SerialTest::GetMinimumLength(void) {
 
    return this->minimumLength;
  }
 
  // Sets the "blockLength" parameter 
  void SerialTest::SetBlockLength(unsigned long int param) {
 
    this->blockLength = param;
  }
 
  // Gets the "blockLength" parameter 
  unsigned long int SerialTest::GetBlockLength(void) {
 
    return this->blockLength;
  }
 
  // Gets the "pvalue2" result  
  double SerialTest::GetPValue2(void) {
 
    return this->pvalue2;
  }
 
  // Gets the "psim" result  
  double SerialTest::GetPsim(void) {
 
    return this->psim;
  }
 
  // Gets the "psim1" result  
  double SerialTest::GetPsim1(void) {
 
    return this->psim1;
  }
 
  // Gets the "psim2" result  
  double SerialTest::GetPsim2(void) {
 
    return this->psim2;
  }
 
  // Gets the "delta1" result  
  double SerialTest::GetDelta1(void) {
 
    return this->delta1;
  }
 
  // Gets the "delta2" result  
  double SerialTest::GetDelta2(void) {
 
    return this->delta2;
  }
 
  // Gets the "BlockSizeRecommended" for the indicated stream length
  unsigned long int SerialTest::MaximumBlockSizeRecommended(unsigned long int length) {
 
    return MAX(1,(int)(log((long double)length)/log((long double)2)-2));
  }
  }
}