Remove CRs from files.
authorDr. Stephen Henson <steve@openssl.org>
Fri, 10 Jun 2005 00:41:25 +0000 (00:41 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 10 Jun 2005 00:41:25 +0000 (00:41 +0000)
fips/fipshashes.c
fips/rand/fips_rand_selftest.c
fips/rand/fips_rngvs.c

index 1b122ca8e16da824133cb55326aa9fdd99e67640..0c7710d5dd12bf189f8a8d0cb89eb3e55c088cee 100644 (file)
@@ -20,7 +20,7 @@ const char * const FIPS_source_hashes[] = {
 "HMAC-SHA1(dsa/fips_dsa_selftest.c)= 7c2ba8d82feda2aadc8b769a3b6c4c25a6356e01",
 "HMAC-SHA1(rand/fips_rand.c)= 7e3964447a81cfe4e75df981827d14a5fe0c2923",
 "HMAC-SHA1(rand/fips_rand.h)= bf009ea8963e79b1e414442ede9ae7010a03160b",
-"HMAC-SHA1(rand/fips_rand_selftest.c)= d9c8985e08feecefafe667ad0119d444b42f807c",
+"HMAC-SHA1(rand/fips_rand_selftest.c)= 5661f383decf0708d0230409fe1564223e834a3b",
 "HMAC-SHA1(rsa/fips_rsa_eay.c)= 2512f849a220daa083f346b10effdb2ee96d4395",
 "HMAC-SHA1(rsa/fips_rsa_gen.c)= 577466931c054d99caf4ac2aefff0e35efd94024",
 "HMAC-SHA1(rsa/fips_rsa_selftest.c)= a9dc47bd1001f795d1565111d26433c300101e06",
index 36346774d87abdcc651ca34df073509123d015ff..691b929d71c2c444737e8218e5a4d0726819d4ad 100644 (file)
-/* ====================================================================\r
- * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer. \r
- *\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in\r
- *    the documentation and/or other materials provided with the\r
- *    distribution.\r
- *\r
- * 3. All advertising materials mentioning features or use of this\r
- *    software must display the following acknowledgment:\r
- *    "This product includes software developed by the OpenSSL Project\r
- *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
- *\r
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
- *    endorse or promote products derived from this software without\r
- *    prior written permission. For written permission, please contact\r
- *    openssl-core@openssl.org.\r
- *\r
- * 5. Products derived from this software may not be called "OpenSSL"\r
- *    nor may "OpenSSL" appear in their names without prior written\r
- *    permission of the OpenSSL Project.\r
- *\r
- * 6. Redistributions of any form whatsoever must retain the following\r
- *    acknowledgment:\r
- *    "This product includes software developed by the OpenSSL Project\r
- *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
- * OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- */\r
-\r
-#include <string.h>\r
-#include <openssl/err.h>\r
-#include <openssl/fips.h>\r
-#include <openssl/rand.h>\r
-#include <openssl/fips_rand.h>\r
-\r
-#ifdef OPENSSL_FIPS\r
-static struct\r
-    {\r
-    unsigned char key1[8];\r
-    unsigned char key2[8];\r
-    unsigned char seed[8];\r
-    unsigned char dt[8];\r
-    } init_iv[] =\r
-    {\r
-    { \r
-    { 0x75, 0xc7, 0x1a, 0xe5, 0xa1, 0x1a, 0x23, 0x2c },\r
-    { 0x40, 0x25, 0x6d, 0xcd, 0x94, 0xf7, 0x67, 0xb0 },\r
-    { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },\r
-    { 0xc8, 0x9a, 0x1d, 0x88, 0x8e, 0xd1, 0x2f, 0x3c },\r
-    },\r
-    {\r
-    { 0x75, 0xc7, 0x1a, 0xe5, 0xa1, 0x1a, 0x23, 0x2c },\r
-    { 0x40, 0x25, 0x6d, 0xcd, 0x94, 0xf7, 0x67, 0xb0 },\r
-    { 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },\r
-    { 0xc8, 0x9a, 0x1d, 0x88, 0x8e, 0xd1, 0x2f, 0x40 },\r
-    },\r
-    {\r
-    { 0x75, 0xc7, 0x1a, 0xe5, 0xa1, 0x1a, 0x23, 0x2c },\r
-    { 0x40, 0x25, 0x6d, 0xcd, 0x94, 0xf7, 0x67, 0xb0 },\r
-    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },\r
-    { 0xc8, 0x9a, 0x1d, 0x88, 0x8e, 0xd1, 0x2f, 0x7b },\r
-    },\r
-    };\r
-\r
-static const unsigned char expected_ret[][8]=\r
-    {\r
-    { 0x94, 0x4d, 0xc7, 0x21, 0x0d, 0x6d, 0x7f, 0xd7 },\r
-    { 0x02, 0x43, 0x3c, 0x94, 0x17, 0xa3, 0x32, 0x6f },\r
-    { 0xe7, 0xe2, 0xb2, 0x96, 0x4f, 0x36, 0xed, 0x41 },\r
-    };\r
-\r
-void FIPS_corrupt_rng()\r
-    {\r
-    init_iv[0].dt[0]++;\r
-    }\r
-\r
-int FIPS_selftest_rng()\r
-    {\r
-    int n;\r
-\r
-    for(n=0 ; n < 3 ; ++n)\r
-       {\r
-       unsigned char actual_ret[8];\r
-\r
-       FIPS_rand_method()->cleanup();\r
-       FIPS_set_prng_key(init_iv[n].key1,init_iv[n].key2); \r
-       FIPS_rand_seed(init_iv[n].seed,8);\r
-       FIPS_test_mode(1,init_iv[n].dt);\r
-       if ((FIPS_rand_method()->bytes(actual_ret, 8) <=0) || (memcmp(actual_ret,expected_ret[n],sizeof actual_ret)))\r
-           {\r
-           FIPS_test_mode(0,NULL);\r
-           FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);\r
-           return 0;\r
-           }\r
-       }\r
-    FIPS_test_mode(0,NULL);\r
-    return 1;\r
-    }\r
-\r
-#endif\r
+/* ====================================================================
+ * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``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 OpenSSL PROJECT OR
+ * ITS 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.
+ *
+ */
+
+#include <string.h>
+#include <openssl/err.h>
+#include <openssl/fips.h>
+#include <openssl/rand.h>
+#include <openssl/fips_rand.h>
+
+#ifdef OPENSSL_FIPS
+static struct
+    {
+    unsigned char key1[8];
+    unsigned char key2[8];
+    unsigned char seed[8];
+    unsigned char dt[8];
+    } init_iv[] =
+    {
+    { 
+    { 0x75, 0xc7, 0x1a, 0xe5, 0xa1, 0x1a, 0x23, 0x2c },
+    { 0x40, 0x25, 0x6d, 0xcd, 0x94, 0xf7, 0x67, 0xb0 },
+    { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    { 0xc8, 0x9a, 0x1d, 0x88, 0x8e, 0xd1, 0x2f, 0x3c },
+    },
+    {
+    { 0x75, 0xc7, 0x1a, 0xe5, 0xa1, 0x1a, 0x23, 0x2c },
+    { 0x40, 0x25, 0x6d, 0xcd, 0x94, 0xf7, 0x67, 0xb0 },
+    { 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+    { 0xc8, 0x9a, 0x1d, 0x88, 0x8e, 0xd1, 0x2f, 0x40 },
+    },
+    {
+    { 0x75, 0xc7, 0x1a, 0xe5, 0xa1, 0x1a, 0x23, 0x2c },
+    { 0x40, 0x25, 0x6d, 0xcd, 0x94, 0xf7, 0x67, 0xb0 },
+    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
+    { 0xc8, 0x9a, 0x1d, 0x88, 0x8e, 0xd1, 0x2f, 0x7b },
+    },
+    };
+
+static const unsigned char expected_ret[][8]=
+    {
+    { 0x94, 0x4d, 0xc7, 0x21, 0x0d, 0x6d, 0x7f, 0xd7 },
+    { 0x02, 0x43, 0x3c, 0x94, 0x17, 0xa3, 0x32, 0x6f },
+    { 0xe7, 0xe2, 0xb2, 0x96, 0x4f, 0x36, 0xed, 0x41 },
+    };
+
+void FIPS_corrupt_rng()
+    {
+    init_iv[0].dt[0]++;
+    }
+
+int FIPS_selftest_rng()
+    {
+    int n;
+
+    for(n=0 ; n < 3 ; ++n)
+       {
+       unsigned char actual_ret[8];
+
+       FIPS_rand_method()->cleanup();
+       FIPS_set_prng_key(init_iv[n].key1,init_iv[n].key2); 
+       FIPS_rand_seed(init_iv[n].seed,8);
+       FIPS_test_mode(1,init_iv[n].dt);
+       if ((FIPS_rand_method()->bytes(actual_ret, 8) <=0) || (memcmp(actual_ret,expected_ret[n],sizeof actual_ret)))
+           {
+           FIPS_test_mode(0,NULL);
+           FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);
+           return 0;
+           }
+       }
+    FIPS_test_mode(0,NULL);
+    return 1;
+    }
+
+#endif
index a50bfe4bcedf20f5daae2fe0e4d9378b84864ec5..aebba3a72aaefe464ebb857ca3b9c12343debd70 100644 (file)
-/*\r
- * Crude test driver for processing the VST and MCT testvector files\r
- * generated by the CMVP RNGVS product.\r
- *\r
- * Note the input files are assumed to have a _very_ specific format\r
- * as described in the NIST document "The Random Number Generator\r
- * Validation System (RNGVS)", May 25, 2004.\r
- *\r
- */\r
-#include <openssl/opensslconf.h>\r
-\r
-#ifndef OPENSSL_FIPS\r
-#include <stdio.h>\r
-int main()\r
-{\r
-    printf("No FIPS RNG support\n");\r
-    return 0;\r
-}\r
-#else\r
-\r
-#include <openssl/bn.h>\r
-#include <openssl/dsa.h>\r
-#include <openssl/fips.h>\r
-#include <openssl/err.h>\r
-#include <openssl/rand.h>\r
-#include <openssl/fips_rand.h>\r
-#include <string.h>\r
-\r
-int hex2bin(const char *in, unsigned char *out)\r
-    {\r
-    int n1, n2;\r
-    unsigned char ch;\r
-\r
-    for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; )\r
-       { /* first byte */\r
-       if ((in[n1] >= '0') && (in[n1] <= '9'))\r
-           ch = in[n1++] - '0';\r
-       else if ((in[n1] >= 'A') && (in[n1] <= 'F'))\r
-           ch = in[n1++] - 'A' + 10;\r
-       else if ((in[n1] >= 'a') && (in[n1] <= 'f'))\r
-           ch = in[n1++] - 'a' + 10;\r
-       else\r
-           return -1;\r
-       if(!in[n1])\r
-           {\r
-           out[n2++]=ch;\r
-           break;\r
-           }\r
-       out[n2] = ch << 4;\r
-       /* second byte */\r
-       if ((in[n1] >= '0') && (in[n1] <= '9'))\r
-           ch = in[n1++] - '0';\r
-       else if ((in[n1] >= 'A') && (in[n1] <= 'F'))\r
-           ch = in[n1++] - 'A' + 10;\r
-       else if ((in[n1] >= 'a') && (in[n1] <= 'f'))\r
-           ch = in[n1++] - 'a' + 10;\r
-       else\r
-           return -1;\r
-       out[n2++] |= ch;\r
-       }\r
-    return n2;\r
-    }\r
-\r
-int bin2hex(const unsigned char *in,int len,char *out)\r
-    {\r
-    int n1, n2;\r
-    unsigned char ch;\r
-\r
-    for (n1=0,n2=0 ; n1 < len ; ++n1)\r
-       {\r
-       ch=in[n1] >> 4;\r
-       if (ch <= 0x09)\r
-           out[n2++]=ch+'0';\r
-       else\r
-           out[n2++]=ch-10+'a';\r
-       ch=in[n1] & 0x0f;\r
-       if(ch <= 0x09)\r
-           out[n2++]=ch+'0';\r
-       else\r
-           out[n2++]=ch-10+'a';\r
-       }\r
-    out[n2]='\0';\r
-    return n2;\r
-    }\r
-\r
-void pv(const char *tag,const unsigned char *val,int len)\r
-    {\r
-    char obuf[2048];\r
-\r
-    bin2hex(val,len,obuf);\r
-    printf("%s = %s\n",tag,obuf);\r
-    }\r
-\r
-void vst()\r
-    {\r
-    unsigned char key1[8];\r
-    unsigned char key2[8];\r
-    unsigned char v[8];\r
-    unsigned char dt[8];\r
-    unsigned char ret[8];\r
-    char buf[1024];\r
-    int n;\r
-\r
-    while(fgets(buf,sizeof buf,stdin) != NULL)\r
-       {\r
-       if(!strncmp(buf,"Key1 = ",7))\r
-           {\r
-           n=hex2bin(buf+7,key1);\r
-           pv("Key1",key1,n);\r
-           }\r
-       else if(!strncmp(buf,"Key2 = ",7))\r
-           {\r
-           n=hex2bin(buf+7,key2);\r
-           pv("Key1",key2,n);\r
-           }\r
-       else if(!strncmp(buf,"DT = ",5))\r
-           {\r
-           n=hex2bin(buf+5,dt);\r
-           pv("DT",dt,n);\r
-           }\r
-       else if(!strncmp(buf,"V = ",4))\r
-           {\r
-           n=hex2bin(buf+4,v);\r
-           pv("V",v,n);\r
-\r
-           FIPS_rand_method()->cleanup();\r
-           FIPS_set_prng_key(key1,key2);\r
-           FIPS_rand_seed(v,8);\r
-           FIPS_test_mode(1,dt);\r
-           if (FIPS_rand_method()->bytes(ret,8) <= 0)\r
-               {\r
-               FIPS_test_mode(0,NULL);\r
-               FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);\r
-               return;\r
-               }\r
-\r
-           pv("R",ret,8);\r
-           putc('\n',stdout);\r
-           }\r
-       else\r
-           fputs(buf,stdout);\r
-       }\r
-    }\r
-\r
-\r
-void mct()\r
-    {\r
-    unsigned char key1[8];\r
-    unsigned char key2[8];\r
-    unsigned char v[8];\r
-    unsigned char dt[8];\r
-    unsigned char ret[8];\r
-    char buf[1024];\r
-    int n;\r
-\r
-    BIGNUM *bn;\r
-    BIGNUM *pbn;\r
-    bn = BN_new();\r
-\r
-    while(fgets(buf,sizeof buf,stdin) != NULL)\r
-       {\r
-       if(!strncmp(buf,"Key1 = ",7))\r
-           {\r
-           n=hex2bin(buf+7,key1);\r
-           pv("Key1",key1,n);\r
-           }\r
-       else if(!strncmp(buf,"Key2 = ",7))\r
-           {\r
-           n=hex2bin(buf+7,key2);\r
-           pv("Key1",key2,n);\r
-           }\r
-       else if(!strncmp(buf,"DT = ",5))\r
-           {\r
-           n=hex2bin(buf+5,dt);\r
-           pv("DT",dt,n);\r
-           }\r
-       else if(!strncmp(buf,"V = ",4))\r
-           {\r
-           int iter;\r
-           n=hex2bin(buf+4,v);\r
-           pv("V",v,n);\r
-\r
-           FIPS_rand_method()->cleanup();\r
-           FIPS_set_prng_key(key1,key2);\r
-           FIPS_rand_seed(v,8);\r
-           for (iter=0; iter < 10000; ++iter)\r
-               {\r
-               FIPS_test_mode(1,dt);\r
-               if (FIPS_rand_method()->bytes(ret,8) <= 0)\r
-                   {\r
-                   FIPS_test_mode(0,NULL);\r
-                   FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);\r
-                   return;\r
-                   }\r
-               pbn = BN_bin2bn(dt,8,bn);\r
-               n = BN_add(bn,bn,BN_value_one());\r
-               n = BN_bn2bin(bn,dt);\r
-               }\r
-\r
-           pv("R",ret,8);\r
-           putc('\n',stdout);\r
-           }\r
-       else\r
-           fputs(buf,stdout);\r
-       }\r
-    BN_free(bn);\r
-    }\r
-\r
-int main(int argc,char **argv)\r
-    {\r
-    if(argc != 2)\r
-       {\r
-       fprintf(stderr,"%s [mct|vst]\n",argv[0]);\r
-       exit(1);\r
-       }\r
-    if(!FIPS_mode_set(1,argv[0]))\r
-       {\r
-       ERR_load_crypto_strings();\r
-       ERR_print_errors(BIO_new_fp(stderr,BIO_NOCLOSE));\r
-       exit(1);\r
-       }\r
-    if(!strcmp(argv[1],"mct"))\r
-       mct();\r
-    else if(!strcmp(argv[1],"vst"))\r
-       vst();\r
-    else\r
-       {\r
-       fprintf(stderr,"Don't know how to %s.\n",argv[1]);\r
-       exit(1);\r
-       }\r
-\r
-    return 0;\r
-    }\r
-#endif\r
+/*
+ * Crude test driver for processing the VST and MCT testvector files
+ * generated by the CMVP RNGVS product.
+ *
+ * Note the input files are assumed to have a _very_ specific format
+ * as described in the NIST document "The Random Number Generator
+ * Validation System (RNGVS)", May 25, 2004.
+ *
+ */
+#include <openssl/opensslconf.h>
+
+#ifndef OPENSSL_FIPS
+#include <stdio.h>
+int main()
+{
+    printf("No FIPS RNG support\n");
+    return 0;
+}
+#else
+
+#include <openssl/bn.h>
+#include <openssl/dsa.h>
+#include <openssl/fips.h>
+#include <openssl/err.h>
+#include <openssl/rand.h>
+#include <openssl/fips_rand.h>
+#include <string.h>
+
+int hex2bin(const char *in, unsigned char *out)
+    {
+    int n1, n2;
+    unsigned char ch;
+
+    for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; )
+       { /* first byte */
+       if ((in[n1] >= '0') && (in[n1] <= '9'))
+           ch = in[n1++] - '0';
+       else if ((in[n1] >= 'A') && (in[n1] <= 'F'))
+           ch = in[n1++] - 'A' + 10;
+       else if ((in[n1] >= 'a') && (in[n1] <= 'f'))
+           ch = in[n1++] - 'a' + 10;
+       else
+           return -1;
+       if(!in[n1])
+           {
+           out[n2++]=ch;
+           break;
+           }
+       out[n2] = ch << 4;
+       /* second byte */
+       if ((in[n1] >= '0') && (in[n1] <= '9'))
+           ch = in[n1++] - '0';
+       else if ((in[n1] >= 'A') && (in[n1] <= 'F'))
+           ch = in[n1++] - 'A' + 10;
+       else if ((in[n1] >= 'a') && (in[n1] <= 'f'))
+           ch = in[n1++] - 'a' + 10;
+       else
+           return -1;
+       out[n2++] |= ch;
+       }
+    return n2;
+    }
+
+int bin2hex(const unsigned char *in,int len,char *out)
+    {
+    int n1, n2;
+    unsigned char ch;
+
+    for (n1=0,n2=0 ; n1 < len ; ++n1)
+       {
+       ch=in[n1] >> 4;
+       if (ch <= 0x09)
+           out[n2++]=ch+'0';
+       else
+           out[n2++]=ch-10+'a';
+       ch=in[n1] & 0x0f;
+       if(ch <= 0x09)
+           out[n2++]=ch+'0';
+       else
+           out[n2++]=ch-10+'a';
+       }
+    out[n2]='\0';
+    return n2;
+    }
+
+void pv(const char *tag,const unsigned char *val,int len)
+    {
+    char obuf[2048];
+
+    bin2hex(val,len,obuf);
+    printf("%s = %s\n",tag,obuf);
+    }
+
+void vst()
+    {
+    unsigned char key1[8];
+    unsigned char key2[8];
+    unsigned char v[8];
+    unsigned char dt[8];
+    unsigned char ret[8];
+    char buf[1024];
+    int n;
+
+    while(fgets(buf,sizeof buf,stdin) != NULL)
+       {
+       if(!strncmp(buf,"Key1 = ",7))
+           {
+           n=hex2bin(buf+7,key1);
+           pv("Key1",key1,n);
+           }
+       else if(!strncmp(buf,"Key2 = ",7))
+           {
+           n=hex2bin(buf+7,key2);
+           pv("Key1",key2,n);
+           }
+       else if(!strncmp(buf,"DT = ",5))
+           {
+           n=hex2bin(buf+5,dt);
+           pv("DT",dt,n);
+           }
+       else if(!strncmp(buf,"V = ",4))
+           {
+           n=hex2bin(buf+4,v);
+           pv("V",v,n);
+
+           FIPS_rand_method()->cleanup();
+           FIPS_set_prng_key(key1,key2);
+           FIPS_rand_seed(v,8);
+           FIPS_test_mode(1,dt);
+           if (FIPS_rand_method()->bytes(ret,8) <= 0)
+               {
+               FIPS_test_mode(0,NULL);
+               FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);
+               return;
+               }
+
+           pv("R",ret,8);
+           putc('\n',stdout);
+           }
+       else
+           fputs(buf,stdout);
+       }
+    }
+
+
+void mct()
+    {
+    unsigned char key1[8];
+    unsigned char key2[8];
+    unsigned char v[8];
+    unsigned char dt[8];
+    unsigned char ret[8];
+    char buf[1024];
+    int n;
+
+    BIGNUM *bn;
+    BIGNUM *pbn;
+    bn = BN_new();
+
+    while(fgets(buf,sizeof buf,stdin) != NULL)
+       {
+       if(!strncmp(buf,"Key1 = ",7))
+           {
+           n=hex2bin(buf+7,key1);
+           pv("Key1",key1,n);
+           }
+       else if(!strncmp(buf,"Key2 = ",7))
+           {
+           n=hex2bin(buf+7,key2);
+           pv("Key1",key2,n);
+           }
+       else if(!strncmp(buf,"DT = ",5))
+           {
+           n=hex2bin(buf+5,dt);
+           pv("DT",dt,n);
+           }
+       else if(!strncmp(buf,"V = ",4))
+           {
+           int iter;
+           n=hex2bin(buf+4,v);
+           pv("V",v,n);
+
+           FIPS_rand_method()->cleanup();
+           FIPS_set_prng_key(key1,key2);
+           FIPS_rand_seed(v,8);
+           for (iter=0; iter < 10000; ++iter)
+               {
+               FIPS_test_mode(1,dt);
+               if (FIPS_rand_method()->bytes(ret,8) <= 0)
+                   {
+                   FIPS_test_mode(0,NULL);
+                   FIPSerr(FIPS_F_FIPS_SELFTEST_RNG,FIPS_R_SELFTEST_FAILED);
+                   return;
+                   }
+               pbn = BN_bin2bn(dt,8,bn);
+               n = BN_add(bn,bn,BN_value_one());
+               n = BN_bn2bin(bn,dt);
+               }
+
+           pv("R",ret,8);
+           putc('\n',stdout);
+           }
+       else
+           fputs(buf,stdout);
+       }
+    BN_free(bn);
+    }
+
+int main(int argc,char **argv)
+    {
+    if(argc != 2)
+       {
+       fprintf(stderr,"%s [mct|vst]\n",argv[0]);
+       exit(1);
+       }
+    if(!FIPS_mode_set(1,argv[0]))
+       {
+       ERR_load_crypto_strings();
+       ERR_print_errors(BIO_new_fp(stderr,BIO_NOCLOSE));
+       exit(1);
+       }
+    if(!strcmp(argv[1],"mct"))
+       mct();
+    else if(!strcmp(argv[1],"vst"))
+       vst();
+    else
+       {
+       fprintf(stderr,"Don't know how to %s.\n",argv[1]);
+       exit(1);
+       }
+
+    return 0;
+    }
+#endif