1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/tsrc/BC/libcrypto/topenssl/src/prime.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,132 @@
1.4 +/* ====================================================================
1.5 + * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
1.6 + *
1.7 + * Redistribution and use in source and binary forms, with or without
1.8 + * modification, are permitted provided that the following conditions
1.9 + * are met:
1.10 + *
1.11 + * 1. Redistributions of source code must retain the above copyright
1.12 + * notice, this list of conditions and the following disclaimer.
1.13 + *
1.14 + * 2. Redistributions in binary form must reproduce the above copyright
1.15 + * notice, this list of conditions and the following disclaimer in
1.16 + * the documentation and/or other materials provided with the
1.17 + * distribution.
1.18 + *
1.19 + * 3. All advertising materials mentioning features or use of this
1.20 + * software must display the following acknowledgment:
1.21 + * "This product includes software developed by the OpenSSL Project
1.22 + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
1.23 + *
1.24 + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
1.25 + * endorse or promote products derived from this software without
1.26 + * prior written permission. For written permission, please contact
1.27 + * openssl-core@openssl.org.
1.28 + *
1.29 + * 5. Products derived from this software may not be called "OpenSSL"
1.30 + * nor may "OpenSSL" appear in their names without prior written
1.31 + * permission of the OpenSSL Project.
1.32 + *
1.33 + * 6. Redistributions of any form whatsoever must retain the following
1.34 + * acknowledgment:
1.35 + * "This product includes software developed by the OpenSSL Project
1.36 + * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
1.37 + *
1.38 + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
1.39 + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.40 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1.41 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
1.42 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1.43 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1.44 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1.45 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.46 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.47 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1.48 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1.49 + * OF THE POSSIBILITY OF SUCH DAMAGE.
1.50 + *
1.51 + */
1.52 +
1.53 +#include <string.h>
1.54 +
1.55 +#include "apps.h"
1.56 +#include <openssl/bn.h>
1.57 +
1.58 +
1.59 +#undef PROG
1.60 +#define PROG prime_main
1.61 +
1.62 +int MAIN(int, char **);
1.63 +
1.64 +int MAIN(int argc, char **argv)
1.65 + {
1.66 + int hex=0;
1.67 + int checks=20;
1.68 + BIGNUM *bn=NULL;
1.69 + BIO *bio_out;
1.70 +
1.71 + apps_startup();
1.72 +
1.73 + if (bio_err == NULL)
1.74 + if ((bio_err=BIO_new(BIO_s_file())) != NULL)
1.75 + BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
1.76 +
1.77 +
1.78 + --argc;
1.79 + ++argv;
1.80 + while (argc >= 1 && **argv == '-')
1.81 + {
1.82 + if(!strcmp(*argv,"-hex"))
1.83 + hex=1;
1.84 + else if(!strcmp(*argv,"-checks"))
1.85 + if(--argc < 1)
1.86 + goto bad;
1.87 + else
1.88 + checks=atoi(*++argv);
1.89 + else
1.90 + {
1.91 + BIO_printf(bio_err,"Unknown option '%s'\n",*argv);
1.92 + goto bad;
1.93 + }
1.94 + --argc;
1.95 + ++argv;
1.96 + }
1.97 +
1.98 + if (argv[0] == NULL)
1.99 + {
1.100 + BIO_printf(bio_err,"No prime specified\n");
1.101 + goto bad;
1.102 + }
1.103 +
1.104 + if ((bio_out=BIO_new(BIO_s_file())) != NULL)
1.105 + {
1.106 + BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
1.107 +
1.108 +#ifdef OPENSSL_SYS_VMS
1.109 + {
1.110 + BIO *tmpbio = BIO_new(BIO_f_linebuffer());
1.111 + bio_out = BIO_push(tmpbio, bio_out);
1.112 + }
1.113 +#endif
1.114 + }
1.115 +
1.116 + if(hex)
1.117 + BN_hex2bn(&bn,argv[0]);
1.118 + else
1.119 + BN_dec2bn(&bn,argv[0]);
1.120 +
1.121 + BN_print(bio_out,bn);
1.122 + BIO_printf(bio_out," is %sprime\n",
1.123 + BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
1.124 +
1.125 + BN_free(bn);
1.126 + BIO_free_all(bio_out);
1.127 +
1.128 + return 0;
1.129 +
1.130 + bad:
1.131 + BIO_printf(bio_err,"options are\n");
1.132 + BIO_printf(bio_err,"%-14s hex\n","-hex");
1.133 + BIO_printf(bio_err,"%-14s number of checks\n","-checks <n>");
1.134 + return 1;
1.135 + }