Friday, 20 October 2017
arrow JDiceChecker 5.0.0.1 arrow RandomTest arrow DiscreteFourierTransformTest.java (1)
DiscreteFourierTransformTest.java (1st part) (Discrete Fourier Transform random number test class) 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
 
//
// Creator:    http://www.dicelocksecurity.com
// Version:    vers.5.0.0.1
//
// Copyright 2011 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.
// 
// Environment:
// java version "1.6.0_29"
// Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
// Java HotSpot(TM) Server VM (build 20.4-b02, mixed mode)
// 
 
package com.dicelocksecurity.jdicechecker.RandomTest;
 
import com.dicelocksecurity.jdicechecker.CryptoRandomStream.BaseCryptoRandomStream;
import java.nio.DoubleBuffer;
 
/**
 * Class implementing Discrete Fourier Transform random number test
 * 
 * @author      Angel Ferré @ DiceLock Security
 * @version     5.0.0.1
 * @since       2011-09-30
 */
public class DiscreteFourierTransformTest extends BaseRandomTest {
 
    /// Random Test Class enumerator name
    protected static final RandomTests   TEST = RandomTests.DiscreteFourierTransform;
    /// Random Test Class minimum stream length
    protected static final int       MINIMUMLENGTH = 100;
 
    protected static final int[]   NTRYH = {4,2,3,5};
    protected static final double  TPI = 6.28318530717958647692528676655900577;
    protected static final double  HSQT2 = 0.70710678118654752440084436210485;
 
    protected double   percentile;
    protected double   observedPeaks;
    protected double   expectedPeaks;
    protected double   normalizedDifference;
 
  /**
   * dradf2 method
   * 
   * @param    ido   int 
   * @param    l1    int 
   * @param    cc    double array  
   * @param    ch    double array  
   * @param    wa1    double buffer  
   */ 
    protected void dradf2(int ido, int l1, double[] cc, double[] ch, DoubleBuffer wa1) {
      int i,k;
      int t0,t1,t2,t3,t4,t5,t6;
      
      t1 = 0;
      t2 = l1*ido;
      t0 = t2;
      t3 = ido<<1;
      for (k=0; k<l1; k++) {
        ch[t1<<1] = cc[t1]+cc[t2];
        ch[(t1<<1)+t3-1] = cc[t1]-cc[t2];
        t1 += ido;
        t2 += ido;
      }
      if (ido >= 2) {
        if (ido > 2) {
          t1 = 0;
          t2 = t0;
          for (k=0; k<l1; k++) {
            t3 = t2;
            t4 = (t1<<1)+(ido<<1);
            t5 = t1;
            t6 = 2*t1;
            for (i=0; i< (ido - 2); i+=2) {
              t3 += 2;
              t4 -= 2;
              t5 += 2;
              t6 += 2;
              ch[t6] = cc[t5]+wa1.get(i)*cc[t3]-wa1.get(i+1)*cc[t3-1];                   // INI WA1
              ch[t4] = wa1.get(i)*cc[t3]-wa1.get(i+1)*cc[t3-1]-cc[t5];
              ch[t6-1] = cc[t5-1]+(wa1.get(i)*cc[t3-1]+wa1.get(i+1)*cc[t3]);
              ch[t4-1] = cc[t5-1]-(wa1.get(i)*cc[t3-1]+wa1.get(i+1)*cc[t3]);            // END WA1
            }
            t1 += ido;
            t2 += ido;
          }
          if (ido%2 == 0) {
            t1 = ido;
            t2 = t1-1;
            t3 = t2;
            t2 += t0;
            for (k=0; k<l1; k++) {
              ch[t1] = -cc[t2];
              ch[t1-1] = cc[t3];
              t1 += ido<<1;
              t2 += ido;
              t3 += ido;
            }
          }
        }
      }
    }
 
  /**
   *  dradf4 method
   *  
   * @param    ido   int 
   * @param    l1    int 
   * @param    cc    double array  
   * @param    ch    double array  
   * @param    wa1    double buffer  
   * @param    wa2    double buffer  
   * @param    wa3    double buffer  
   */ 
    protected void dradf4(int ido, int l1, double[] cc, double[] ch, DoubleBuffer wa1, DoubleBuffer wa2, DoubleBuffer wa3) {
      int i,k,t0,t1,t2,t3,t4,t5,t6;
      double ci2,ci3,ci4,cr2,cr3,cr4;
 
      t0 = l1*ido;
      t1 = t0;
      t4 = t1<<1;
      t2 = t1+(t1<<1);
      t3 = 0;
      for (k=0; k<l1; k++){
        t5 = t3<<2;
        ch[t5] = (cc[t1]+cc[t2])+(cc[t3]+cc[t4]);
        ch[(ido<<2)+t5-1] = (cc[t3]+cc[t4])-(cc[t1]+cc[t2]);
        ch[(t5 += (ido<<1))-1] = cc[t3]-cc[t4];
        ch[t5] = cc[t2]-cc[t1];
        t1 += ido;
        t2 += ido;
        t3 += ido;
        t4 += ido;
      }
      if (ido >= 2) {
        if (ido > 2) {
          t1 = 0;
          for (k=0; k<l1; k++) {
            t2 = t1;
            t4 = t1<<2;
            t6 = ido<<1;
            t5 = t6+t4;
            for (i=0; i< (ido - 2); i+=2) {
              t3 = (t2 += 2);
              t4 += 2;
              t5 -= 2;
              t3 += t0;
              cr2 = wa1.get(i)*cc[t3-1]+wa1.get(i+1)*cc[t3];  // INI WA1
              ci2 = wa1.get(i)*cc[t3]-wa1.get(i+1)*cc[t3-1];  // END WA1
              t3 += t0;
              cr3 = wa2.get(i)*cc[t3-1]+wa2.get(i+1)*cc[t3];  // INI WA2
              ci3 = wa2.get(i)*cc[t3]-wa2.get(i+1)*cc[t3-1];  // END WA2
              t3 += t0;
              cr4 = wa3.get(i)*cc[t3-1]+wa3.get(i+1)*cc[t3];  // INI WA3
              ci4 = wa3.get(i)*cc[t3]-wa3.get(i+1)*cc[t3-1];  // END WA3
              ch[t4-1] = (cr2+cr4)+(cc[t2-1]+cr3);
              ch[t4] = (ci2+ci4)+(cc[t2]+ci3);
              ch[t5-1] = (cc[t2-1]-cr3)-(ci2-ci4);
              ch[t5] = (cr4-cr2)-(cc[t2]-ci3);
              ch[t4+t6-1] = (ci2-ci4)+(cc[t2-1]-cr3);
              ch[t4+t6] = (cr4-cr2)+(cc[t2]-ci3);
              ch[t5+t6-1] = (cc[t2-1]+cr3)-(cr2+cr4);
              ch[t5+t6] = (ci2+ci4)-(cc[t2]+ci3);
            }
            t1 += ido;
          }
          if (ido%2 == 0) {
            t1 = t0+ido-1;
            t2 = t1+(t0<<1);
            t3 = ido<<2;
            t4 = ido;
            t5 = ido<<1;
            t6 = ido;
            for (k=0; k<l1; k++) {
              ch[t4-1] = (DiscreteFourierTransformTest.HSQT2*(cc[t1]-cc[t2]))+cc[t6-1];
              ch[t4+t5-1] = cc[t6-1]-(DiscreteFourierTransformTest.HSQT2*(cc[t1]-cc[t2]));
              ch[t4] = (-DiscreteFourierTransformTest.HSQT2*(cc[t1]+cc[t2]))-cc[t1+t0];
              ch[t4+t5] = (-DiscreteFourierTransformTest.HSQT2*(cc[t1]+cc[t2]))+cc[t1+t0];
              t1 += ido;
              t2 += ido;
              t4 += t3;
              t6 += ido;
            }
          }
        }
      }
    }