random123

Counter-based Random Number Generators
git clone git://git.meso-star.com/random123.git
Log | Files | Refs | README | LICENSE

ut_ars.c (3053B)


      1 /*
      2 Copyright 2010-2011, D. E. Shaw Research.
      3 All rights reserved.
      4 
      5 Redistribution and use in source and binary forms, with or without
      6 modification, are permitted provided that the following conditions are
      7 met:
      8 
      9 * Redistributions of source code must retain the above copyright
     10   notice, this list of conditions, and the following disclaimer.
     11 
     12 * Redistributions in binary form must reproduce the above copyright
     13   notice, this list of conditions, and the following disclaimer in the
     14   documentation and/or other materials provided with the distribution.
     15 
     16 * Neither the name of D. E. Shaw Research nor the names of its
     17   contributors may be used to endorse or promote products derived from
     18   this software without specific prior written permission.
     19 
     20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31 */
     32 #include <Random123/ars.h>
     33 #include <stdlib.h>
     34 #include <stdio.h>
     35 #include <string.h>
     36 
     37 #if !R123_USE_SSE
     38 int main(int argc, char **argv){
     39     (void)argc; (void)argv; /* unused */
     40     printf("No SSE support.  This test is not compiled\n");
     41     return 0;
     42 }
     43 #else
     44 #include "util_m128.h"
     45 
     46 int
     47 main(int argc, char **argv)
     48 {
     49 #if R123_USE_AES_NI
     50     struct r123array1xm128i c, k, ret;
     51     char m128str[M128_STR_SIZE], *kat;
     52 
     53     if (haveAESNI()) {
     54 	c.v[0].m = m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
     55 	k.v[0].m = m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
     56 	ret = ars1xm128i_R(7, c, k);
     57 	kat = "2b1623350cd214dc 7740187993411872";
     58 	if (strcmp(m128i_to_charbuf(ret.v[0].m, m128str), kat) != 0) {
     59 	    fprintf(stderr, "%s: error, expected %s, got %s\n", argv[0], kat, m128str);
     60 	    exit(1);
     61 	}
     62 	printf("%s: OK, got %s\n", argv[0], kat);
     63 	c.v[0].m = m128i_from_charbuf("00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
     64 	k.v[0].m = m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
     65 	ret = ars1xm128i_R(7, c, k);
     66 	kat = "2de6b66fa461b668 f380126f32b9cd22";
     67 	if (strcmp(m128i_to_charbuf(ret.v[0].m, m128str), kat) != 0) {
     68 	    fprintf(stderr, "%s: error, expected %s, got %s\n", argv[0], kat, m128str);
     69 	    exit(1);
     70 	}
     71 	printf("%s: OK, got %s\n", argv[0], kat);
     72     } else {
     73 	printf("%s: no AES-NI on this machine\n", argv[0]);
     74     }
     75 #else
     76     printf("%s: no AES-NI compiled into this program\n", argv[0]);
     77 #endif
     78     (void)argc; (void)argv; /* unused */
     79     return 0;
     80 }
     81 
     82 #endif