fips_dssvs.c 13.4 KB
Newer Older
1 2

#define OPENSSL_FIPSAPI
D
Dr. Stephen Henson 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <openssl/opensslconf.h>

#ifndef OPENSSL_FIPS
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("No FIPS DSA support\n");
    return(0);
}
#else

#include <openssl/bn.h>
#include <openssl/dsa.h>
#include <openssl/fips.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <string.h>
#include <ctype.h>

#include "fips_utl.h"

25 26 27 28 29 30 31 32 33 34 35 36 37
static int parse_mod(char *line, int *pdsa2, int *pL, int *pN,
				const EVP_MD **pmd)
	{
	char lbuf[10240];
	char *keyword, *value;

	char *p;
	p = strchr(line, ',');
	if (!p)
		{
		*pL = atoi(line);
		*pdsa2 = 0;
		*pN = 160;
38 39
		if (pmd)
			*pmd = EVP_sha1();
40 41 42 43 44 45 46 47 48 49
		return 1;
		}
	*pdsa2 = 1;
	*p = 0;
	if (!parse_line(&keyword, &value, lbuf, line))
		return 0;
	if (strcmp(keyword, "L"))
		return 0;
	*pL = atoi(value);
	strcpy(line, p + 1);
50 51 52 53
	if (pmd)
		p = strchr(line, ',');
	else
		p = strchr(line, ']');
54 55 56 57 58 59 60 61
	if (!p)
		return 0;
	*p = 0;
	if (!parse_line(&keyword, &value, lbuf, line))
		return 0;
	if (strcmp(keyword, "N"))
		return 0;
	*pN = atoi(value);
62 63
	if (!pmd)
		return 1;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	strcpy(line, p + 1);
	p = strchr(line, ']');
	if (!p)
		return 0;
	*p = 0;
	p = line;
	while(isspace(*p))
		p++;
	if (!strcmp(p, "SHA-1"))
		*pmd = EVP_sha1();
	else if (!strcmp(p, "SHA-224"))
		*pmd = EVP_sha224();
	else if (!strcmp(p, "SHA-256"))
		*pmd = EVP_sha256();
	else if (!strcmp(p, "SHA-384"))
		*pmd = EVP_sha384();
	else if (!strcmp(p, "SHA-512"))
		*pmd = EVP_sha512();
	else
		return 0;
	return 1;
	}

87
static void primes(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
88 89 90 91 92
    {
    char buf[10240];
    char lbuf[10240];
    char *keyword, *value;

93
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
94
	{
95
	fputs(buf,out);
D
Dr. Stephen Henson 已提交
96 97 98 99 100 101 102 103
	if (!parse_line(&keyword, &value, lbuf, buf))
		continue;
	if(!strcmp(keyword,"Prime"))
	    {
	    BIGNUM *pp;

	    pp=BN_new();
	    do_hex2bn(&pp,value);
104
	    fprintf(out, "result= %c\n",
D
Dr. Stephen Henson 已提交
105 106 107 108 109 110 111 112 113
		   BN_is_prime_ex(pp,20,NULL,NULL) ? 'P' : 'F');
	    }	    
	}
    }

int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
	const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
	unsigned char *seed_out,
	int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
114 115 116 117
int dsa_builtin_paramgen2(DSA *ret, size_t bits, size_t qbits,
	const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
	unsigned char *seed_out,
	int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
D
Dr. Stephen Henson 已提交
118

119
static void pqg(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
120 121 122 123
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
D
Dr. Stephen Henson 已提交
124 125
    int dsa2, L, N;
    const EVP_MD *md = NULL;
D
Dr. Stephen Henson 已提交
126

127
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
128 129 130
	{
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
131
		fputs(buf,out);
D
Dr. Stephen Henson 已提交
132 133 134
		continue;
		}
	if(!strcmp(keyword,"[mod"))
135
	    {
136
	    fputs(buf,out);
D
Dr. Stephen Henson 已提交
137 138 139 140 141
	    if (!parse_mod(value, &dsa2, &L, &N, &md))
		{
		fprintf(stderr, "Mod Parse Error\n");
		exit (1);
		}
142
	    }
D
Dr. Stephen Henson 已提交
143 144 145 146 147 148 149 150 151 152 153 154
	else if(!strcmp(keyword,"N"))
	    {
	    int n=atoi(value);

	    while(n--)
		{
		unsigned char seed[EVP_MAX_MD_SIZE];
		DSA *dsa;
		int counter;
		unsigned long h;
		dsa = FIPS_dsa_new();

D
Dr. Stephen Henson 已提交
155 156 157 158 159 160 161 162 163 164 165 166
		if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md,
						NULL, 0, seed,
						&counter, &h, NULL))
			{
			fprintf(stderr, "Parameter Generation error\n");
			exit(1);
			}
		if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md,
						NULL, 0, seed,
						&counter, &h, NULL) <= 0)
			{
			fprintf(stderr, "Parameter Generation error\n");
D
Dr. Stephen Henson 已提交
167
			exit(1);
D
Dr. Stephen Henson 已提交
168 169
			}
 
170 171 172 173 174 175
		do_bn_print_name(out, "P",dsa->p);
		do_bn_print_name(out, "Q",dsa->q);
		do_bn_print_name(out, "G",dsa->g);
		OutputValue("Seed",seed, M_EVP_MD_size(md), out, 0);
		fprintf(out, "c = %d\n",counter);
		fprintf(out, "H = %lx\n\n",h);
D
Dr. Stephen Henson 已提交
176 177 178
		}
	    }
	else
179
	    fputs(buf,out);
D
Dr. Stephen Henson 已提交
180 181 182
	}
    }

183
static void pqgver(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
184 185 186 187 188
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    BIGNUM *p = NULL, *q = NULL, *g = NULL;
D
Dr. Stephen Henson 已提交
189
    int counter=-1, counter2;
D
Dr. Stephen Henson 已提交
190
    unsigned long h=0, h2;
D
Dr. Stephen Henson 已提交
191
    DSA *dsa=NULL;
192
    int dsa2, L, N, part_test = 0;
193
    const EVP_MD *md = NULL;
D
Dr. Stephen Henson 已提交
194
    int seedlen=-1;
D
Dr. Stephen Henson 已提交
195 196
    unsigned char seed[1024];

197
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
198 199 200
	{
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
201 202 203 204 205
		if (p && q)
			{
			part_test = 1;
			goto partial;
			}
206
		fputs(buf,out);
D
Dr. Stephen Henson 已提交
207 208
		continue;
		}
209
	fputs(buf, out);
D
Dr. Stephen Henson 已提交
210
	if(!strcmp(keyword,"[mod"))
211 212 213 214 215 216 217
	    {
	    if (!parse_mod(value, &dsa2, &L, &N, &md))
		{
		fprintf(stderr, "Mod Parse Error\n");
		exit (1);
		}
	    }
D
Dr. Stephen Henson 已提交
218 219 220 221 222 223 224 225
	else if(!strcmp(keyword,"P"))
	    p=hex2bn(value);
	else if(!strcmp(keyword,"Q"))
	    q=hex2bn(value);
	else if(!strcmp(keyword,"G"))
	    g=hex2bn(value);
	else if(!strcmp(keyword,"Seed"))
	    {
226 227
	    seedlen = hex2bin(value, seed);
	    if (!dsa2 && seedlen != 20)
D
Dr. Stephen Henson 已提交
228 229 230 231 232 233 234
		{
		fprintf(stderr, "Seed parse length error\n");
		exit (1);
		}
	    }
	else if(!strcmp(keyword,"c"))
	    counter =atoi(buf+4);
235 236
	partial:
	if(!strcmp(keyword,"H") || part_test)
D
Dr. Stephen Henson 已提交
237
	    {
238 239 240
	    if (!part_test)
	    	h = atoi(value);
	    if (!p || !q || (!g && !part_test))
D
Dr. Stephen Henson 已提交
241 242 243 244 245
		{
		fprintf(stderr, "Parse Error\n");
		exit (1);
		}
	    dsa = FIPS_dsa_new();
246 247 248 249 250 251 252 253 254 255 256 257
	    if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md,
					seed, seedlen, NULL,
					&counter2, &h2, NULL))
			{
			fprintf(stderr, "Parameter Generation error\n");
			exit(1);
			}
	    if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md,
					seed, seedlen, NULL,
					&counter2, &h2, NULL) < 0)
			{
			fprintf(stderr, "Parameter Generation error\n");
D
Dr. Stephen Henson 已提交
258
			exit(1);
259
			}
260 261 262
            if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) || 
		(!part_test &&
		((BN_cmp(dsa->g, g) || (counter != counter2) || (h != h2)))))
263
	    	fprintf(out, "Result = F\n");
D
Dr. Stephen Henson 已提交
264
	    else
265
	    	fprintf(out, "Result = P\n");
D
Dr. Stephen Henson 已提交
266 267 268 269 270 271 272 273
	    BN_free(p);
	    BN_free(q);
	    BN_free(g);
	    p = NULL;
	    q = NULL;
	    g = NULL;
	    FIPS_dsa_free(dsa);
	    dsa = NULL;
274 275
	    if (part_test)
		{
276
		fputs(buf,out);
277 278
		part_test = 0;
		}
D
Dr. Stephen Henson 已提交
279 280 281 282 283 284 285 286 287
	    }
	}
    }

/* Keypair verification routine. NB: this isn't part of the standard FIPS140-2
 * algorithm tests. It is an additional test to perform sanity checks on the
 * output of the KeyPair test.
 */

288
static int dss_paramcheck(int L, int N, BIGNUM *p, BIGNUM *q, BIGNUM *g,
D
Dr. Stephen Henson 已提交
289 290 291
							BN_CTX *ctx)
    {
    BIGNUM *rem = NULL;
292
    if (BN_num_bits(p) != L)
D
Dr. Stephen Henson 已提交
293
	return 0;
294
    if (BN_num_bits(q) != N)
D
Dr. Stephen Henson 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
	return 0;
    if (BN_is_prime_ex(p, BN_prime_checks, ctx, NULL) != 1)
	return 0;
    if (BN_is_prime_ex(q, BN_prime_checks, ctx, NULL) != 1)
	return 0;
    rem = BN_new();
    if (!BN_mod(rem, p, q, ctx) || !BN_is_one(rem)
    	|| (BN_cmp(g, BN_value_one()) <= 0)
	|| !BN_mod_exp(rem, g, q, p, ctx) || !BN_is_one(rem))
	{
	BN_free(rem);
	return 0;
	}
    /* Todo: check g */
    BN_free(rem);
    return 1;
    }

313
static void keyver(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
314 315 316 317 318 319 320
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    BIGNUM *p = NULL, *q = NULL, *g = NULL, *X = NULL, *Y = NULL;
    BIGNUM *Y2;
    BN_CTX *ctx = NULL;
321 322
    int dsa2, L, N;
    int paramcheck = 0;
D
Dr. Stephen Henson 已提交
323 324 325 326

    ctx = BN_CTX_new();
    Y2 = BN_new();

327
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
328 329 330
	{
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
331
		fputs(buf,out);
D
Dr. Stephen Henson 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345
		continue;
		}
	if(!strcmp(keyword,"[mod"))
	    {
	    if (p)
		BN_free(p);
	    p = NULL;
	    if (q)
		BN_free(q);
	    q = NULL;
	    if (g)
		BN_free(g);
	    g = NULL;
	    paramcheck = 0;
346 347 348 349 350
	    if (!parse_mod(value, &dsa2, &L, &N, NULL))
		{
		fprintf(stderr, "Mod Parse Error\n");
		exit (1);
		}
D
Dr. Stephen Henson 已提交
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
	    }
	else if(!strcmp(keyword,"P"))
	    p=hex2bn(value);
	else if(!strcmp(keyword,"Q"))
	    q=hex2bn(value);
	else if(!strcmp(keyword,"G"))
	    g=hex2bn(value);
	else if(!strcmp(keyword,"X"))
	    X=hex2bn(value);
	else if(!strcmp(keyword,"Y"))
	    {
	    Y=hex2bn(value);
	    if (!p || !q || !g || !X || !Y)
		{
		fprintf(stderr, "Parse Error\n");
		exit (1);
		}
368 369 370 371 372
	    do_bn_print_name(out, "P",p);
	    do_bn_print_name(out, "Q",q);
	    do_bn_print_name(out, "G",g);
	    do_bn_print_name(out, "X",X);
	    do_bn_print_name(out, "Y",Y);
D
Dr. Stephen Henson 已提交
373 374
	    if (!paramcheck)
		{
375
		if (dss_paramcheck(L, N, p, q, g, ctx))
D
Dr. Stephen Henson 已提交
376 377 378 379 380
			paramcheck = 1;
		else
			paramcheck = -1;
		}
	    if (paramcheck != 1)
381
	   	fprintf(out, "Result = F\n");
D
Dr. Stephen Henson 已提交
382 383 384
	    else
		{
		if (!BN_mod_exp(Y2, g, X, p, ctx) || BN_cmp(Y2, Y))
385
	    		fprintf(out, "Result = F\n");
D
Dr. Stephen Henson 已提交
386
	        else
387
	    		fprintf(out, "Result = P\n");
D
Dr. Stephen Henson 已提交
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
		}
	    BN_free(X);
	    BN_free(Y);
	    X = NULL;
	    Y = NULL;
	    }
	}
	if (p)
	    BN_free(p);
	if (q)
	    BN_free(q);
	if (g)
	    BN_free(g);
	if (Y2)
	    BN_free(Y2);
    }

405
static void keypair(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
406 407 408 409
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
410
    int dsa2, L, N;
D
Dr. Stephen Henson 已提交
411

412
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
413 414 415 416 417 418
	{
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
		continue;
		}
	if(!strcmp(keyword,"[mod"))
419 420 421 422 423 424
	    {
	    if (!parse_mod(value, &dsa2, &L, &N, NULL))
		{
		fprintf(stderr, "Mod Parse Error\n");
		exit (1);
		}
425
	    fputs(buf,out);
426
	    }
D
Dr. Stephen Henson 已提交
427 428 429 430 431 432
	else if(!strcmp(keyword,"N"))
	    {
	    DSA *dsa;
	    int n=atoi(value);

	    dsa = FIPS_dsa_new();
433 434 435 436 437 438 439 440 441 442 443 444
	    if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, NULL, NULL, 0,
						NULL, NULL, NULL, NULL))
			{
			fprintf(stderr, "Parameter Generation error\n");
			exit(1);
			}
	    if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, NULL, NULL, 0,
						NULL, NULL, NULL, NULL) <= 0)
			{
			fprintf(stderr, "Parameter Generation error\n");
			exit(1);
			}
445 446 447 448
	    do_bn_print_name(out, "P",dsa->p);
	    do_bn_print_name(out, "Q",dsa->q);
	    do_bn_print_name(out, "G",dsa->g);
	    fputs("\n", out);
D
Dr. Stephen Henson 已提交
449 450 451 452 453 454

	    while(n--)
		{
		if (!DSA_generate_key(dsa))
			exit(1);

455 456 457
		do_bn_print_name(out, "X",dsa->priv_key);
		do_bn_print_name(out, "Y",dsa->pub_key);
	    	fputs("\n", out);
D
Dr. Stephen Henson 已提交
458 459 460 461 462
		}
	    }
	}
    }

463
static void siggen(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
464 465 466 467
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
D
Dr. Stephen Henson 已提交
468 469
    int dsa2, L, N;
    const EVP_MD *md = NULL;
D
Dr. Stephen Henson 已提交
470 471
    DSA *dsa=NULL;

472
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
473 474 475
	{
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
476
		fputs(buf,out);
D
Dr. Stephen Henson 已提交
477 478
		continue;
		}
479
	fputs(buf,out);
D
Dr. Stephen Henson 已提交
480 481
	if(!strcmp(keyword,"[mod"))
	    {
D
Dr. Stephen Henson 已提交
482 483 484 485 486
	    if (!parse_mod(value, &dsa2, &L, &N, &md))
		{
		fprintf(stderr, "Mod Parse Error\n");
		exit (1);
		}
D
Dr. Stephen Henson 已提交
487 488 489
	    if (dsa)
		FIPS_dsa_free(dsa);
	    dsa = FIPS_dsa_new();
D
Dr. Stephen Henson 已提交
490 491 492 493 494 495 496 497 498 499 500 501
	    if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md, NULL, 0,
						NULL, NULL, NULL, NULL))
			{
			fprintf(stderr, "Parameter Generation error\n");
			exit(1);
			}
	    if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, NULL, 0,
						NULL, NULL, NULL, NULL) <= 0)
			{
			fprintf(stderr, "Parameter Generation error\n");
			exit(1);
			}
502 503 504 505
	    do_bn_print_name(out, "P",dsa->p);
	    do_bn_print_name(out, "Q",dsa->q);
	    do_bn_print_name(out, "G",dsa->g);
	    fputs("\n", out);
D
Dr. Stephen Henson 已提交
506 507 508 509 510 511 512
	    }
	else if(!strcmp(keyword,"Msg"))
	    {
	    unsigned char msg[1024];
	    int n;
	    EVP_MD_CTX mctx;
	    DSA_SIG *sig;
513
	    FIPS_md_ctx_init(&mctx);
D
Dr. Stephen Henson 已提交
514 515 516 517 518

	    n=hex2bin(value,msg);

	    if (!DSA_generate_key(dsa))
		exit(1);
519
	    do_bn_print_name(out, "Y",dsa->pub_key);
D
Dr. Stephen Henson 已提交
520

521 522
	    FIPS_digestinit(&mctx, md);
	    FIPS_digestupdate(&mctx, msg, n);
D
Dr. Stephen Henson 已提交
523 524
	    sig = FIPS_dsa_sign_ctx(dsa, &mctx);

525 526 527
	    do_bn_print_name(out, "R",sig->r);
	    do_bn_print_name(out, "S",sig->s);
	    fputs("\n", out);
528
	    FIPS_dsa_sig_free(sig);
529
	    FIPS_md_ctx_cleanup(&mctx);
D
Dr. Stephen Henson 已提交
530 531 532 533 534 535
	    }
	}
	if (dsa)
		FIPS_dsa_free(dsa);
    }

536
static void sigver(FILE *in, FILE *out)
D
Dr. Stephen Henson 已提交
537 538 539 540 541 542
    {
    DSA *dsa=NULL;
    char buf[1024];
    char lbuf[1024];
    unsigned char msg[1024];
    char *keyword, *value;
543 544 545
    int n=0;
    int dsa2, L, N;
    const EVP_MD *md = NULL;
D
Dr. Stephen Henson 已提交
546 547 548 549 550
    DSA_SIG sg, *sig = &sg;

    sig->r = NULL;
    sig->s = NULL;

551
    while(fgets(buf,sizeof buf,in) != NULL)
D
Dr. Stephen Henson 已提交
552 553 554
	{
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
555
		fputs(buf,out);
D
Dr. Stephen Henson 已提交
556 557
		continue;
		}
558
	fputs(buf,out);
D
Dr. Stephen Henson 已提交
559 560
	if(!strcmp(keyword,"[mod"))
	    {
561 562 563 564 565 566
	    if (!parse_mod(value, &dsa2, &L, &N, &md))
		{
		fprintf(stderr, "Mod Parse Error\n");
		exit (1);
		}
	    if (dsa)
D
Dr. Stephen Henson 已提交
567
		FIPS_dsa_free(dsa);
568
	    dsa = FIPS_dsa_new();
D
Dr. Stephen Henson 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
	    }
	else if(!strcmp(keyword,"P"))
	    dsa->p=hex2bn(value);
	else if(!strcmp(keyword,"Q"))
	    dsa->q=hex2bn(value);
	else if(!strcmp(keyword,"G"))
	    dsa->g=hex2bn(value);
	else if(!strcmp(keyword,"Msg"))
	    n=hex2bin(value,msg);
	else if(!strcmp(keyword,"Y"))
	    dsa->pub_key=hex2bn(value);
	else if(!strcmp(keyword,"R"))
	    sig->r=hex2bn(value);
	else if(!strcmp(keyword,"S"))
	    {
	    EVP_MD_CTX mctx;
	    int r;
586
	    FIPS_md_ctx_init(&mctx);
D
Dr. Stephen Henson 已提交
587
	    sig->s=hex2bn(value);
D
Dr. Stephen Henson 已提交
588

589 590
	    FIPS_digestinit(&mctx, md);
	    FIPS_digestupdate(&mctx, msg, n);
D
Dr. Stephen Henson 已提交
591 592 593
	    no_err = 1;
	    r = FIPS_dsa_verify_ctx(dsa, &mctx, sig);
	    no_err = 0;
594
	    FIPS_md_ctx_cleanup(&mctx);
D
Dr. Stephen Henson 已提交
595
	
596
	    fprintf(out, "Result = %c\n\n", r == 1 ? 'P' : 'F');
D
Dr. Stephen Henson 已提交
597 598 599 600 601 602
	    }
	}
    }

int main(int argc,char **argv)
    {
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
    FILE *in, *out;
    if (argc == 4)
	{
	in = fopen(argv[2], "r");
	if (!in)
		{
		fprintf(stderr, "Error opening input file\n");
		exit(1);
		}
	out = fopen(argv[3], "w");
	if (!out)
		{
		fprintf(stderr, "Error opening output file\n");
		exit(1);
		}
	}
    else if (argc == 2)
	{
	in = stdin;
	out = stdout;
	}
    else
D
Dr. Stephen Henson 已提交
625
	{
626
	fprintf(stderr,"%s [prime|pqg|pqgver|keypair|keyver|siggen|sigver]\n",argv[0]);
D
Dr. Stephen Henson 已提交
627 628
	exit(1);
	}
629
    fips_algtest_init();
D
Dr. Stephen Henson 已提交
630
    if(!strcmp(argv[1],"prime"))
631
	primes(in, out);
D
Dr. Stephen Henson 已提交
632
    else if(!strcmp(argv[1],"pqg"))
633
	pqg(in, out);
D
Dr. Stephen Henson 已提交
634
    else if(!strcmp(argv[1],"pqgver"))
635
	pqgver(in, out);
D
Dr. Stephen Henson 已提交
636
    else if(!strcmp(argv[1],"keypair"))
637
	keypair(in, out);
D
Dr. Stephen Henson 已提交
638
    else if(!strcmp(argv[1],"keyver"))
639
	keyver(in, out);
D
Dr. Stephen Henson 已提交
640
    else if(!strcmp(argv[1],"siggen"))
641
	siggen(in, out);
D
Dr. Stephen Henson 已提交
642
    else if(!strcmp(argv[1],"sigver"))
643
	sigver(in, out);
D
Dr. Stephen Henson 已提交
644 645 646 647 648 649
    else
	{
	fprintf(stderr,"Don't know how to %s.\n",argv[1]);
	exit(1);
	}

650 651 652 653 654 655
    if (argc == 4)
	{
	fclose(in);
	fclose(out);
	}

D
Dr. Stephen Henson 已提交
656 657 658 659
    return 0;
    }

#endif