aboutsummaryrefslogtreecommitdiff
path: root/openssl/apps/prime.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-03-29 17:08:02 +0000
committermarha <marha@users.sourceforge.net>2010-03-29 17:08:02 +0000
commit15272ab4ed1e6250412fccd48200ed9eae59608f (patch)
treea5996ea67966a778a16565f19dfc2e7c7f49b376 /openssl/apps/prime.c
parent3827301b2ea5a45ac009c3bf9f08586ff40b8506 (diff)
downloadvcxsrv-15272ab4ed1e6250412fccd48200ed9eae59608f.tar.gz
vcxsrv-15272ab4ed1e6250412fccd48200ed9eae59608f.tar.bz2
vcxsrv-15272ab4ed1e6250412fccd48200ed9eae59608f.zip
Updated to openssl 1.0.0
Diffstat (limited to 'openssl/apps/prime.c')
-rw-r--r--openssl/apps/prime.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/openssl/apps/prime.c b/openssl/apps/prime.c
index af2fed15a..f1aaef872 100644
--- a/openssl/apps/prime.c
+++ b/openssl/apps/prime.c
@@ -62,6 +62,9 @@ int MAIN(int argc, char **argv)
{
int hex=0;
int checks=20;
+ int generate=0;
+ int bits=0;
+ int safe=0;
BIGNUM *bn=NULL;
BIO *bio_out;
@@ -77,6 +80,15 @@ int MAIN(int argc, char **argv)
{
if(!strcmp(*argv,"-hex"))
hex=1;
+ else if(!strcmp(*argv,"-generate"))
+ generate=1;
+ else if(!strcmp(*argv,"-bits"))
+ if(--argc < 1)
+ goto bad;
+ else
+ bits=atoi(*++argv);
+ else if(!strcmp(*argv,"-safe"))
+ safe=1;
else if(!strcmp(*argv,"-checks"))
if(--argc < 1)
goto bad;
@@ -91,13 +103,13 @@ int MAIN(int argc, char **argv)
++argv;
}
- if (argv[0] == NULL)
+ if (argv[0] == NULL && !generate)
{
BIO_printf(bio_err,"No prime specified\n");
goto bad;
}
- if ((bio_out=BIO_new(BIO_s_file())) != NULL)
+ if ((bio_out=BIO_new(BIO_s_file())) != NULL)
{
BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
@@ -108,14 +120,32 @@ int MAIN(int argc, char **argv)
#endif
}
- if(hex)
- BN_hex2bn(&bn,argv[0]);
+ if(generate)
+ {
+ char *s;
+
+ if(!bits)
+ {
+ BIO_printf(bio_err,"Specifiy the number of bits.\n");
+ return 1;
+ }
+ bn=BN_new();
+ BN_generate_prime_ex(bn,bits,safe,NULL,NULL,NULL);
+ s=hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
+ BIO_printf(bio_out,"%s\n",s);
+ OPENSSL_free(s);
+ }
else
- BN_dec2bn(&bn,argv[0]);
+ {
+ if(hex)
+ BN_hex2bn(&bn,argv[0]);
+ else
+ BN_dec2bn(&bn,argv[0]);
- BN_print(bio_out,bn);
- BIO_printf(bio_out," is %sprime\n",
- BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
+ BN_print(bio_out,bn);
+ BIO_printf(bio_out," is %sprime\n",
+ BN_is_prime_ex(bn,checks,NULL,NULL) ? "" : "not ");
+ }
BN_free(bn);
BIO_free_all(bio_out);