}
*pdsa2 = 1;
*p = 0;
- if (!parse_line(&keyword, &value, lbuf, line))
+ if (!parse_line2(&keyword, &value, lbuf, line, 0))
return 0;
if (strcmp(keyword, "L"))
return 0;
if (!p)
return 0;
*p = 0;
- if (!parse_line(&keyword, &value, lbuf, line))
+ if (!parse_line2(&keyword, &value, lbuf, line, 0))
return 0;
if (strcmp(keyword, "N"))
return 0;
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);
-int dsa_builtin_paramgen2(DSA *ret, size_t bits, size_t qbits,
+int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,
const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
- unsigned char *seed_out,
+ int idx, unsigned char *seed_out,
int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
static void pqg(FILE *in, FILE *out)
char *keyword, *value;
int dsa2, L, N;
const EVP_MD *md = NULL;
+ BIGNUM *p = NULL, *q = NULL;
+ enum pqtype { PQG_NONE, PQG_PQ, PQG_G, PQG_GCANON}
+ pqg_type = PQG_NONE;
+ int seedlen=-1, idxlen, idx = -1;
+ unsigned char seed[1024], idtmp[1024];
while(fgets(buf,sizeof buf,in) != NULL)
{
+ if (buf[0] == '[')
+ {
+ if (strstr(buf, "Probable"))
+ pqg_type = PQG_PQ;
+ else if (strstr(buf, "Unverifiable"))
+ pqg_type = PQG_G;
+ else if (strstr(buf, "Canonical"))
+ pqg_type = PQG_GCANON;
+ }
if (!parse_line(&keyword, &value, lbuf, buf))
{
fputs(buf,out);
continue;
}
+ fputs(buf,out);
if(!strcmp(keyword,"[mod"))
{
- fputs(buf,out);
if (!parse_mod(value, &dsa2, &L, &N, &md))
{
fprintf(stderr, "Mod Parse Error\n");
exit (1);
}
}
- else if(!strcmp(keyword,"N"))
+ else if(!strcmp(keyword,"N")
+ || (!strcmp(keyword, "Num") && pqg_type == PQG_PQ))
{
int n=atoi(value);
while(n--)
{
- unsigned char seed[EVP_MAX_MD_SIZE];
DSA *dsa;
int counter;
unsigned long h;
exit(1);
}
if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md,
- NULL, 0, seed,
+ NULL, 0, -1, seed,
&counter, &h, NULL) <= 0)
{
fprintf(stderr, "Parameter Generation error\n");
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);
+ if (!dsa2)
+ do_bn_print_name(out, "G",dsa->g);
+ OutputValue(dsa2 ? "domain_parameter_seed" : "Seed",
+ seed, M_EVP_MD_size(md), out, 0);
+ if (!dsa2)
+ {
+ fprintf(out, "c = %d\n",counter);
+ fprintf(out, "H = %lx\n\n",h);
+ }
+ else
+ fputs("\n", out);
}
}
- else
- fputs(buf,out);
+ else if(!strcmp(keyword,"P"))
+ p=hex2bn(value);
+ else if(!strcmp(keyword,"Q"))
+ q=hex2bn(value);
+ else if(!strcmp(keyword,"domain_parameter_seed"))
+ seedlen = hex2bin(value, seed);
+ else if(!strcmp(keyword,"index"))
+ {
+ idxlen = hex2bin(value, idtmp);
+ if (idxlen != 1)
+ {
+ fprintf(stderr, "Index value error\n");
+ exit (1);
+ }
+ idx = idtmp[0];
+ }
+ if ((idx >= 0 && pqg_type == PQG_GCANON) || (q && pqg_type == PQG_G))
+ {
+ DSA *dsa;
+ dsa = FIPS_dsa_new();
+ dsa->p = p;
+ dsa->q = q;
+ p = q = NULL;
+ if (dsa_builtin_paramgen2(dsa, L, N, md,
+ seed, seedlen, idx, NULL,
+ NULL, NULL, NULL) <= 0)
+ {
+ fprintf(stderr, "Parameter Generation error\n");
+ exit(1);
+ }
+ do_bn_print_name(out, "G",dsa->g);
+ FIPS_dsa_free(dsa);
+ idx = -1;
+ }
}
}
DSA *dsa=NULL;
int dsa2, L, N, part_test = 0;
const EVP_MD *md = NULL;
- int seedlen=-1;
- unsigned char seed[1024];
+ int seedlen=-1, idxlen, idx = -1;
+ unsigned char seed[1024], idtmp[1024];
while(fgets(buf,sizeof buf,in) != NULL)
{
q=hex2bn(value);
else if(!strcmp(keyword,"G"))
g=hex2bn(value);
- else if(!strcmp(keyword,"Seed"))
+ else if(!strcmp(keyword,"Seed")
+ || !strcmp(keyword,"domain_parameter_seed"))
{
seedlen = hex2bin(value, seed);
if (!dsa2 && seedlen != 20)
fprintf(stderr, "Seed parse length error\n");
exit (1);
}
+ if (idx > 0)
+ part_test = 1;
+ }
+ else if(!strcmp(keyword,"index"))
+ {
+ idxlen = hex2bin(value, idtmp);
+ if (idxlen != 1)
+ {
+ fprintf(stderr, "Index value error\n");
+ exit (1);
+ }
+ idx = idtmp[0];
}
else if(!strcmp(keyword,"c"))
- counter =atoi(buf+4);
+ counter = atoi(buf+4);
partial:
if(!strcmp(keyword,"H") || part_test)
{
exit (1);
}
dsa = FIPS_dsa_new();
+ if (idx >= 0)
+ {
+ dsa->p = BN_dup(p);
+ dsa->q = BN_dup(q);
+ }
if (!dsa2 && !dsa_builtin_paramgen(dsa, L, N, md,
seed, seedlen, NULL,
&counter2, &h2, NULL))
exit(1);
}
if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md,
- seed, seedlen, NULL,
+ seed, seedlen, idx, NULL,
&counter2, &h2, NULL) < 0)
{
fprintf(stderr, "Parameter Generation error\n");
exit(1);
}
- if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) ||
+ if (idx >= 0)
+ {
+ if (BN_cmp(dsa->g, g))
+ fprintf(out, "Result = F\n");
+ else
+ fprintf(out, "Result = P\n");
+ }
+ else if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) ||
(!part_test &&
((BN_cmp(dsa->g, g) || (counter != counter2) || (h != h2)))))
fprintf(out, "Result = F\n");
dsa = NULL;
if (part_test)
{
- fputs(buf,out);
+ if (idx == -1)
+ fputs(buf,out);
part_test = 0;
}
+ idx = -1;
}
}
}
fprintf(stderr, "Parameter Generation error\n");
exit(1);
}
- if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, NULL, NULL, 0,
+ if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, NULL, NULL, 0, -1,
NULL, NULL, NULL, NULL) <= 0)
{
fprintf(stderr, "Parameter Generation error\n");
fprintf(stderr, "Parameter Generation error\n");
exit(1);
}
- if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, NULL, 0,
+ if (dsa2 && dsa_builtin_paramgen2(dsa, L, N, md, NULL, 0, -1,
NULL, NULL, NULL, NULL) <= 0)
{
fprintf(stderr, "Parameter Generation error\n");