kerneltest/e32utils/nistsecurerng/include/generators.h
branchRCL_3
changeset 294 039a3e647356
parent 268 345b1ca54e88
child 295 5460f47b94ad
equal deleted inserted replaced
268:345b1ca54e88 294:039a3e647356
     1 /*
       
     2 * Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * The original NIST Statistical Test Suite code is placed in public domain.
       
    16 * (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) 
       
    17 * 
       
    18 * This software was developed at the National Institute of Standards and Technology by 
       
    19 * employees of the Federal Government in the course of their official duties. Pursuant
       
    20 * to title 17 Section 105 of the United States Code this software is not subject to 
       
    21 * copyright protection and is in the public domain. The NIST Statistical Test Suite is
       
    22 * an experimental system. NIST assumes no responsibility whatsoever for its use by other 
       
    23 * parties, and makes no guarantees, expressed or implied, about its quality, reliability, 
       
    24 * or any other characteristic. We would appreciate acknowledgment if the software is used.
       
    25 */
       
    26 
       
    27 #ifndef _GENERATORS_H_
       
    28 #define _GENERATORS_H_
       
    29 //#include	"../include/sha.h"
       
    30 
       
    31 void	lcg();
       
    32 double	lcg_rand(int, double, double*, int);
       
    33 void	quadRes1();
       
    34 void	quadRes2();
       
    35 void	cubicRes();
       
    36 void	exclusiveOR();
       
    37 void	modExp();
       
    38 void	bbs();
       
    39 void	micali_schnorr();
       
    40 void	SHA1();
       
    41 void    HASH_DRBG();
       
    42 
       
    43 /* The circular shifts. */
       
    44 #define CS1(x) ((((ULONG)x)<<1)|(((ULONG)x)>>31))
       
    45 #define CS5(x)  ((((ULONG)x)<<5)|(((ULONG)x)>>27))
       
    46 #define CS30(x)  ((((ULONG)x)<<30)|(((ULONG)x)>>2))
       
    47 
       
    48 /* K constants */
       
    49 
       
    50 #define K0  0x5a827999L
       
    51 #define K1  0x6ed9eba1L
       
    52 #define K2  0x8f1bbcdcL
       
    53 #define K3  0xca62c1d6L
       
    54 
       
    55 #define f1(x,y,z)   ( (x & (y ^ z)) ^ z )
       
    56 
       
    57 #define f3(x,y,z)   ( (x & ( y ^ z )) ^ (z & y) )
       
    58 
       
    59 #define f2(x,y,z)   ( x ^ y ^ z )                           /* Rounds 20-39 */
       
    60 
       
    61 #define  expand(x)  Wbuff[x%16] = CS1(Wbuff[(x - 3)%16 ] ^ Wbuff[(x - 8)%16 ] ^ Wbuff[(x - 14)%16] ^ Wbuff[x%16])
       
    62 
       
    63 #define sub1Round1(count)      { \
       
    64 	 temp = CS5(A) + f1(B, C, D) + E + Wbuff[count] + K0; \
       
    65 	 E = D; \
       
    66 	 D = C; \
       
    67 	 C = CS30( B ); \
       
    68 	 B = A; \
       
    69 	 A = temp; \
       
    70 	 } \
       
    71 
       
    72 #define sub2Round1(count)   \
       
    73 	 { \
       
    74 	 expand(count); \
       
    75 	 temp = CS5(A) + f1(B, C, D) + E + Wbuff[count%16] + K0; \
       
    76 	 E = D; \
       
    77 	 D = C; \
       
    78 	 C = CS30( B ); \
       
    79 	 B = A; \
       
    80 	 A = temp; \
       
    81 	} \
       
    82 
       
    83 #define Round2(count)     \
       
    84 	 { \
       
    85 	 expand(count); \
       
    86 	 temp = CS5( A ) + f2( B, C, D ) + E + Wbuff[count%16] + K1;  \
       
    87 	 E = D; \
       
    88 	 D = C; \
       
    89 	 C = CS30( B ); \
       
    90 	 B = A; \
       
    91 	 A = temp;  \
       
    92 	 } \
       
    93 
       
    94 #define Round3(count)    \
       
    95 	 { \
       
    96 	 expand(count); \
       
    97 	 temp = CS5( A ) + f3( B, C, D ) + E + Wbuff[count%16] + K2; \
       
    98 	 E = D; \
       
    99 	 D = C; \
       
   100 	 C = CS30( B ); \
       
   101 	 B = A; \
       
   102 	 A = temp; \
       
   103 	 }
       
   104 
       
   105 #define Round4(count)    \
       
   106 	 { \
       
   107 	 expand(count); \
       
   108 	 temp = CS5( A ) + f2( B, C, D ) + E + Wbuff[count%16] + K3; \
       
   109 	 E = D; \
       
   110 	 D = C; \
       
   111 	 C = CS30( B ); \
       
   112 	 B = A; \
       
   113 	 A = temp; \
       
   114 	 }
       
   115 
       
   116 #endif