Commit 7c4dd3fe authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Make algorithm test programs tolerate whitespace in input files.

parent bdc778a7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@

 Changes between 0.9.7l and 0.9.7m  [xx XXX xxxx]

  *) Make algorithm test programs more tolerant of whitespace.
     [Steve Henson]

  *) Have SSL/TLS server implementation tolerate "mismatched" record
     protocol version while receiving ClientHello even if the
     ClientHello is fragmented.  (The server can't insist on the
+58 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>

#include <openssl/aes.h>
#include <openssl/evp.h>
@@ -622,6 +623,61 @@ int do_mct(char *amode,
    return ret;
    }

/* To avoid extensive changes to test program at this stage just convert
 * the input line into an acceptable form. Keyword lines converted to form
 * "keyword = value\n" no matter what white space present, all other lines
 * just have leading and trailing space removed.
 */

static int tidy_line(char *linebuf, char *olinebuf)
	{
	char *keyword, *value, *p, *q;
	strcpy(linebuf, olinebuf);
	keyword = linebuf;
	/* Skip leading space */
	while (isspace((unsigned char)*keyword))
		keyword++;
	/* Look for = sign */
	p = strchr(linebuf, '=');

	/* If no '=' just chop leading, trailing ws */
	if (!p)
		{
		p = keyword + strlen(keyword) - 1;
		while (*p == '\n' || isspace((unsigned char)*p))
			*p-- = 0;
		strcpy(olinebuf, keyword);
		strcat(olinebuf, "\n");
		return 1;
		}

	q = p - 1;

	/* Remove trailing space */
	while (isspace((unsigned char)*q))
		*q-- = 0;

	*p = 0;
	value = p + 1;

	/* Remove leading space from value */
	while (isspace((unsigned char)*value))
		value++;

	/* Remove trailing space from value */
	p = value + strlen(value) - 1;

	while (*p == '\n' || isspace((unsigned char)*p))
		*p-- = 0;

	strcpy(olinebuf, keyword);
	strcat(olinebuf, " = ");
	strcat(olinebuf, value);
	strcat(olinebuf, "\n");

	return 1;
	}

/*================================================*/
/*----------------------------
  # Config info for v-one
@@ -636,6 +692,7 @@ int proc_file(char *rqfile)
    char afn[256], rfn[256];
    FILE *afp = NULL, *rfp = NULL;
    char ibuf[2048];
    char tbuf[2048];
    int ilen, len, ret = 0;
    char algo[8] = "";
    char amode[8] = "";
@@ -677,6 +734,7 @@ int proc_file(char *rqfile)
	}
    while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
	{
	tidy_line(tbuf, ibuf);
	ilen = strlen(ibuf);
	/*      printf("step=%d ibuf=%s",step,ibuf); */
	switch (step)
+58 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>

#include <openssl/des.h>
#include <openssl/evp.h>
@@ -70,6 +71,61 @@
#include <openssl/err.h>
#include "e_os.h"

/* To avoid extensive changes to test program at this stage just convert
 * the input line into an acceptable form. Keyword lines converted to form
 * "keyword = value\n" no matter what white space present, all other lines
 * just have leading and trailing space removed.
 */

static int tidy_line(char *linebuf, char *olinebuf)
	{
	char *keyword, *value, *p, *q;
	strcpy(linebuf, olinebuf);
	keyword = linebuf;
	/* Skip leading space */
	while (isspace((unsigned char)*keyword))
		keyword++;
	/* Look for = sign */
	p = strchr(linebuf, '=');

	/* If no '=' just chop leading, trailing ws */
	if (!p)
		{
		p = keyword + strlen(keyword) - 1;
		while (*p == '\n' || isspace((unsigned char)*p))
			*p-- = 0;
		strcpy(olinebuf, keyword);
		strcat(olinebuf, "\n");
		return 1;
		}

	q = p - 1;

	/* Remove trailing space */
	while (isspace((unsigned char)*q))
		*q-- = 0;

	*p = 0;
	value = p + 1;

	/* Remove leading space from value */
	while (isspace((unsigned char)*value))
		value++;

	/* Remove trailing space from value */
	p = value + strlen(value) - 1;

	while (*p == '\n' || isspace((unsigned char)*p))
		*p-- = 0;

	strcpy(olinebuf, keyword);
	strcat(olinebuf, " = ");
	strcat(olinebuf, value);
	strcat(olinebuf, "\n");

	return 1;
	}

/*#define AES_BLOCK_SIZE 16*/

#define VERBOSE 0
@@ -414,7 +470,7 @@ int proc_file(char *rqfile)
    {
    char afn[256], rfn[256];
    FILE *afp = NULL, *rfp = NULL;
    char ibuf[2048];
    char ibuf[2048], tbuf[2048];
    int ilen, len, ret = 0;
    char amode[8] = "";
    char atest[100] = "";
@@ -456,6 +512,7 @@ int proc_file(char *rqfile)
	}
    while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
	{
	tidy_line(tbuf, ibuf);
	ilen = strlen(ibuf);
	/*	printf("step=%d ibuf=%s",step,ibuf);*/
	if(step == 3 && !strcmp(amode,"ECB"))
+104 −30
Original line number Diff line number Diff line
@@ -16,6 +16,47 @@ int main()
#include <openssl/err.h>
#include <openssl/fips_sha.h>
#include <string.h>
#include <ctype.h>

static int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf)
	{
	char *keyword, *value, *p, *q;
	strcpy(linebuf, olinebuf);
	keyword = linebuf;
	/* Skip leading space */
	while (isspace((unsigned char)*keyword))
		keyword++;

	/* Look for = sign */
	p = strchr(linebuf, '=');

	/* If no '=' exit */
	if (!p)
		return 0;

	q = p - 1;

	/* Remove trailing space */
	while (isspace((unsigned char)*q))
		*q-- = 0;

	*p = 0;
	value = p + 1;

	/* Remove leading space from value */
	while (isspace((unsigned char)*value))
		value++;

	/* Remove trailing space from value */
	p = value + strlen(value) - 1;

	while (*p == '\n' || isspace((unsigned char)*p))
		*p-- = 0;

	*pkw = keyword;
	*pval = value;
	return 1;
	}

int hex2bin(const char *in, unsigned char *out)
    {
@@ -99,16 +140,20 @@ void pbn(const char *tag,const BIGNUM *val)
void primes()
    {
    char buf[10240];
    char lbuf[10240];
    char *keyword, *value;

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	fputs(buf,stdout);
	if(!strncmp(buf,"Prime= ",7))
	if (!parse_line(&keyword, &value, lbuf, buf))
		continue;
	if(!strcmp(keyword,"Prime"))
	    {
	    BIGNUM *pp;

	    pp=BN_new();
	    BN_hex2bn(&pp,buf+7);
	    BN_hex2bn(&pp,value);
	    printf("result= %c\n",
		   BN_is_prime(pp,20,NULL,NULL,NULL) ? 'P' : 'F');
	    }	    
@@ -118,15 +163,22 @@ void primes()
void pqg()
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    int nmod=0;

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"[mod = ",7))
	    nmod=atoi(buf+7);
	else if(!strncmp(buf,"N = ",4))
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
	    int n=atoi(buf+4);
		fputs(buf,stdout);
		continue;
		}
	if(!strcmp(keyword,"[mod"))
	    nmod=atoi(value);
	else if(!strcmp(keyword,"N"))
	    {
	    int n=atoi(value);

	    printf("[mod = %d]\n\n",nmod);

@@ -155,16 +207,23 @@ void pqg()
void keypair()
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    int nmod=0;

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"[mod = ",7))
	    nmod=atoi(buf+7);
	else if(!strncmp(buf,"N = ",4))
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
		fputs(buf,stdout);
		continue;
		}
	if(!strcmp(keyword,"[mod"))
	    nmod=atoi(value);
	else if(!strcmp(keyword,"N"))
	    {
	    DSA *dsa;
	    int n=atoi(buf+4);
	    int n=atoi(value);

	    printf("[mod = %d]\n\n",nmod);

@@ -189,14 +248,21 @@ void keypair()
void siggen()
    {
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    int nmod=0;
    DSA *dsa=NULL;

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"[mod = ",7))
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
	    nmod=atoi(buf+7);
		fputs(buf,stdout);
		continue;
		}
	if(!strcmp(keyword,"[mod"))
	    {
	    nmod=atoi(value);
	    printf("[mod = %d]\n\n",nmod);

	    dsa=DSA_generate_parameters(nmod,NULL,0,NULL,NULL,NULL,NULL);
@@ -205,14 +271,14 @@ void siggen()
	    pbn("G",dsa->g);
	    putc('\n',stdout);
	    }
	else if(!strncmp(buf,"Msg = ",6))
	else if(!strcmp(keyword,"Msg"))
	    {
	    unsigned char msg[1024];
	    unsigned char hash[20];
	    int n;
	    DSA_SIG *sig;

	    n=hex2bin(buf+6,msg);
	    n=hex2bin(value,msg);
	    pv("Msg",msg,n);

	    DSA_generate_key(dsa);
@@ -231,26 +297,33 @@ void sigver()
    {
    DSA *dsa=NULL;
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    int nmod=0;
    unsigned char hash[20];
    DSA_SIG *sig=DSA_SIG_new();

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"[mod = ",7))
	if (!parse_line(&keyword, &value, lbuf, buf))
		{
		fputs(buf,stdout);
		continue;
		}
	if(!strcmp(keyword,"[mod"))
	    {
	    nmod=atoi(buf+7);
	    nmod=atoi(value);
	    if(dsa)
		DSA_free(dsa);
	    dsa=DSA_new();
	    }
	else if(!strncmp(buf,"P = ",4))
	    dsa->p=hex2bn(buf+4);
	else if(!strncmp(buf,"Q = ",4))
	    dsa->q=hex2bn(buf+4);
	else if(!strncmp(buf,"G = ",4))
	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(buf+4);
	    dsa->g=hex2bn(value);

	    printf("[mod = %d]\n\n",nmod);
	    pbn("P",dsa->p);
@@ -258,22 +331,22 @@ void sigver()
	    pbn("G",dsa->g);
	    putc('\n',stdout);
	    }
	else if(!strncmp(buf,"Msg = ",6))
	else if(!strcmp(keyword,"Msg"))
	    {
	    unsigned char msg[1024];
	    int n;

	    n=hex2bin(buf+6,msg);
	    n=hex2bin(value,msg);
	    pv("Msg",msg,n);
	    SHA1(msg,n,hash);
	    }
	else if(!strncmp(buf,"Y = ",4))
	    dsa->pub_key=hex2bn(buf+4);
	else if(!strncmp(buf,"R = ",4))
	    sig->r=hex2bn(buf+4);
	else if(!strncmp(buf,"S = ",4))
	else if(!strcmp(keyword,"Y"))
	    dsa->pub_key=hex2bn(value);
	else if(!strcmp(keyword,"R"))
	    sig->r=hex2bn(value);
	else if(!strcmp(keyword,"S"))
	    {
	    sig->s=hex2bn(buf+4);
	    sig->s=hex2bn(value);
	
	    pbn("Y",dsa->pub_key);
	    pbn("R",sig->r);
@@ -316,4 +389,5 @@ int main(int argc,char **argv)

    return 0;
    }

#endif
+67 −28
Original line number Diff line number Diff line
@@ -25,6 +25,47 @@ int main()
#include <openssl/rand.h>
#include <openssl/fips_rand.h>
#include <string.h>
#include <ctype.h>

static int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf)
	{
	char *keyword, *value, *p, *q;
	strcpy(linebuf, olinebuf);
	keyword = linebuf;
	/* Skip leading space */
	while (isspace((unsigned char)*keyword))
		keyword++;

	/* Look for = sign */
	p = strchr(linebuf, '=');

	/* If no '=' exit */
	if (!p)
		return 0;

	q = p - 1;

	/* Remove trailing space */
	while (isspace((unsigned char)*q))
		*q-- = 0;

	*p = 0;
	value = p + 1;

	/* Remove leading space from value */
	while (isspace((unsigned char)*value))
		value++;

	/* Remove trailing space from value */
	p = value + strlen(value) - 1;

	while (*p == '\n' || isspace((unsigned char)*p))
		*p-- = 0;

	*pkw = keyword;
	*pval = value;
	return 1;
	}

int hex2bin(const char *in, unsigned char *out)
    {
@@ -99,29 +140,30 @@ void vst()
    unsigned char dt[8];
    unsigned char ret[8];
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    int n;

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"Key1 = ",7))
	fputs(buf,stdout);
	if (!parse_line(&keyword, &value, lbuf, buf))
		continue;
	if(!strcmp(keyword,"Key1"))
	    {
	    n=hex2bin(buf+7,key1);
	    pv("Key1",key1,n);
	    n=hex2bin(value,key1);
	    }
	else if(!strncmp(buf,"Key2 = ",7))
	else if(!strcmp(keyword,"Key2"))
	    {
	    n=hex2bin(buf+7,key2);
	    pv("Key1",key2,n);
	    n=hex2bin(value,key2);
	    }
	else if(!strncmp(buf,"DT = ",5))
	else if(!strcmp(keyword,"DT"))
	    {
	    n=hex2bin(buf+5,dt);
	    pv("DT",dt,n);
	    n=hex2bin(value,dt);
	    }
	else if(!strncmp(buf,"V = ",4))
	else if(!strcmp(keyword,"V"))
	    {
	    n=hex2bin(buf+4,v);
	    pv("V",v,n);
	    n=hex2bin(value,v);

	    FIPS_rand_method()->cleanup();
	    FIPS_set_prng_key(key1,key2);
@@ -137,8 +179,6 @@ void vst()
	    pv("R",ret,8);
	    putc('\n',stdout);
	    }
	else
	    fputs(buf,stdout);
	}
    }

@@ -151,6 +191,8 @@ void mct()
    unsigned char dt[8];
    unsigned char ret[8];
    char buf[1024];
    char lbuf[1024];
    char *keyword, *value;
    int n;

    BIGNUM *bn;
@@ -159,26 +201,25 @@ void mct()

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"Key1 = ",7))
	fputs(buf,stdout);
	if (!parse_line(&keyword, &value, lbuf, buf))
		continue;
	if(!strcmp(keyword,"Key1"))
	    {
	    n=hex2bin(buf+7,key1);
	    pv("Key1",key1,n);
	    n=hex2bin(value,key1);
	    }
	else if(!strncmp(buf,"Key2 = ",7))
	else if(!strcmp(keyword,"Key2"))
	    {
	    n=hex2bin(buf+7,key2);
	    pv("Key1",key2,n);
	    n=hex2bin(value,key2);
	    }
	else if(!strncmp(buf,"DT = ",5))
	else if(!strcmp(keyword,"DT"))
	    {
	    n=hex2bin(buf+5,dt);
	    pv("DT",dt,n);
	    n=hex2bin(value,dt);
	    }
	else if(!strncmp(buf,"V = ",4))
	else if(!strcmp(keyword,"V"))
	    {
	    int iter;
	    n=hex2bin(buf+4,v);
	    pv("V",v,n);
	    n=hex2bin(value,v);

	    FIPS_rand_method()->cleanup();
	    FIPS_set_prng_key(key1,key2);
@@ -200,8 +241,6 @@ void mct()
	    pv("R",ret,8);
	    putc('\n',stdout);
	    }
	else
	    fputs(buf,stdout);
	}
    BN_free(bn);
    }
Loading