sl@0
|
1 |
/* ====================================================================
|
sl@0
|
2 |
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
5 |
* modification, are permitted provided that the following conditions
|
sl@0
|
6 |
* are met:
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
9 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
12 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
13 |
* the documentation and/or other materials provided with the
|
sl@0
|
14 |
* distribution.
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
17 |
* software must display the following acknowledgment:
|
sl@0
|
18 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
19 |
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
sl@0
|
20 |
*
|
sl@0
|
21 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
22 |
* endorse or promote products derived from this software without
|
sl@0
|
23 |
* prior written permission. For written permission, please contact
|
sl@0
|
24 |
* openssl-core@openssl.org.
|
sl@0
|
25 |
*
|
sl@0
|
26 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
27 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
28 |
* permission of the OpenSSL Project.
|
sl@0
|
29 |
*
|
sl@0
|
30 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
31 |
* acknowledgment:
|
sl@0
|
32 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
33 |
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
sl@0
|
34 |
*
|
sl@0
|
35 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
36 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
37 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
38 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
39 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
40 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
41 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
42 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
43 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
44 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
45 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
46 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
47 |
*
|
sl@0
|
48 |
*/
|
sl@0
|
49 |
|
sl@0
|
50 |
#include <string.h>
|
sl@0
|
51 |
|
sl@0
|
52 |
#include "apps.h"
|
sl@0
|
53 |
#include <openssl/bn.h>
|
sl@0
|
54 |
|
sl@0
|
55 |
|
sl@0
|
56 |
#undef PROG
|
sl@0
|
57 |
#define PROG prime_main
|
sl@0
|
58 |
|
sl@0
|
59 |
int MAIN(int, char **);
|
sl@0
|
60 |
|
sl@0
|
61 |
int MAIN(int argc, char **argv)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
int hex=0;
|
sl@0
|
64 |
int checks=20;
|
sl@0
|
65 |
BIGNUM *bn=NULL;
|
sl@0
|
66 |
BIO *bio_out;
|
sl@0
|
67 |
|
sl@0
|
68 |
apps_startup();
|
sl@0
|
69 |
|
sl@0
|
70 |
if (bio_err == NULL)
|
sl@0
|
71 |
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
|
sl@0
|
72 |
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
|
sl@0
|
73 |
|
sl@0
|
74 |
|
sl@0
|
75 |
--argc;
|
sl@0
|
76 |
++argv;
|
sl@0
|
77 |
while (argc >= 1 && **argv == '-')
|
sl@0
|
78 |
{
|
sl@0
|
79 |
if(!strcmp(*argv,"-hex"))
|
sl@0
|
80 |
hex=1;
|
sl@0
|
81 |
else if(!strcmp(*argv,"-checks"))
|
sl@0
|
82 |
if(--argc < 1)
|
sl@0
|
83 |
goto bad;
|
sl@0
|
84 |
else
|
sl@0
|
85 |
checks=atoi(*++argv);
|
sl@0
|
86 |
else
|
sl@0
|
87 |
{
|
sl@0
|
88 |
BIO_printf(bio_err,"Unknown option '%s'\n",*argv);
|
sl@0
|
89 |
goto bad;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
--argc;
|
sl@0
|
92 |
++argv;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
if (argv[0] == NULL)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
BIO_printf(bio_err,"No prime specified\n");
|
sl@0
|
98 |
goto bad;
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
if ((bio_out=BIO_new(BIO_s_file())) != NULL)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
|
sl@0
|
104 |
|
sl@0
|
105 |
#ifdef OPENSSL_SYS_VMS
|
sl@0
|
106 |
{
|
sl@0
|
107 |
BIO *tmpbio = BIO_new(BIO_f_linebuffer());
|
sl@0
|
108 |
bio_out = BIO_push(tmpbio, bio_out);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
#endif
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
if(hex)
|
sl@0
|
114 |
BN_hex2bn(&bn,argv[0]);
|
sl@0
|
115 |
else
|
sl@0
|
116 |
BN_dec2bn(&bn,argv[0]);
|
sl@0
|
117 |
|
sl@0
|
118 |
BN_print(bio_out,bn);
|
sl@0
|
119 |
BIO_printf(bio_out," is %sprime\n",
|
sl@0
|
120 |
BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
|
sl@0
|
121 |
|
sl@0
|
122 |
BN_free(bn);
|
sl@0
|
123 |
BIO_free_all(bio_out);
|
sl@0
|
124 |
|
sl@0
|
125 |
return 0;
|
sl@0
|
126 |
|
sl@0
|
127 |
bad:
|
sl@0
|
128 |
BIO_printf(bio_err,"options are\n");
|
sl@0
|
129 |
BIO_printf(bio_err,"%-14s hex\n","-hex");
|
sl@0
|
130 |
BIO_printf(bio_err,"%-14s number of checks\n","-checks <n>");
|
sl@0
|
131 |
return 1;
|
sl@0
|
132 |
}
|