#define OPENSSL_FIPSAPI
#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"
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;
if (pmd)
*pmd = EVP_sha1();
return 1;
}
*pdsa2 = 1;
*p = 0;
if (!parse_line2(&keyword, &value, lbuf, line, 0))
return 0;
if (strcmp(keyword, "L"))
return 0;
*pL = atoi(value);
strcpy(lbuf, p + 1);
strcpy(line, lbuf);
if (pmd)
p = strchr(line, ',');
else
p = strchr(line, ']');
if (!p)
return 0;
*p = 0;
if (!parse_line2(&keyword, &value, lbuf, line, 0))
return 0;
if (strcmp(keyword, "N"))
return 0;
*pN = atoi(value);
if (!pmd)
return 1;
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;
}
static void primes(FILE *in, FILE *out)
{
char buf[10240];
char lbuf[10240];
char *keyword, *value;
while(fgets(buf,sizeof buf,in) != NULL)
{
fputs(buf,out);
if (!parse_line(&keyword, &value, lbuf, buf))
continue;
if(!strcmp(keyword,"Prime"))
{
BIGNUM *pp;
pp=BN_new();
do_hex2bn(&pp,value);
fprintf(out, "result= %c" RESP_EOL,
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);
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,
int idx, unsigned char *seed_out,
int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
int dsa_paramgen_check_g(DSA *dsa);
static void pqg(FILE *in, FILE *out)
{
char buf[1024];
char lbuf[1024];
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, "