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
#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <ctype.h>
#include <openssl/aes.h>
#include <openssl/evp.h>
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
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] = "";
}
while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
{
+ tidy_line(tbuf, ibuf);
ilen = strlen(ibuf);
/* printf("step=%d ibuf=%s",step,ibuf); */
switch (step)
#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <ctype.h>
#include <openssl/des.h>
#include <openssl/evp.h>
#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
{
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] = "";
}
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"))
#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)
{
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');
}
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))
+ {
+ fputs(buf,stdout);
+ continue;
+ }
+ if(!strcmp(keyword,"[mod"))
+ nmod=atoi(value);
+ else if(!strcmp(keyword,"N"))
{
- int n=atoi(buf+4);
+ int n=atoi(value);
printf("[mod = %d]\n\n",nmod);
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);
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))
+ {
+ fputs(buf,stdout);
+ continue;
+ }
+ if(!strcmp(keyword,"[mod"))
{
- nmod=atoi(buf+7);
+ nmod=atoi(value);
printf("[mod = %d]\n\n",nmod);
dsa=DSA_generate_parameters(nmod,NULL,0,NULL,NULL,NULL,NULL);
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);
{
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);
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);
return 0;
}
+
#endif
#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)
{
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);
pv("R",ret,8);
putc('\n',stdout);
}
- else
- fputs(buf,stdout);
}
}
unsigned char dt[8];
unsigned char ret[8];
char buf[1024];
+ char lbuf[1024];
+ char *keyword, *value;
int n;
BIGNUM *bn;
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);
pv("R",ret,8);
putc('\n',stdout);
}
- else
- fputs(buf,stdout);
}
BN_free(bn);
}
while (isspace((unsigned char)*q))
*q-- = 0;
-
+ *p = 0;
value = p + 1;
/* Remove leading space from value */
while (isspace((unsigned char)*q))
*q-- = 0;
-
+ *p = 0;
value = p + 1;
/* Remove leading space from value */
while (isspace((unsigned char)*q))
*q-- = 0;
-
+ *p = 0;
value = p + 1;
/* Remove leading space from value */
}
#define SHA_TEST_MAX_BITS 102400
-#define SHA_TEST_MAXLINELEN (((SHA_TEST_MAX_BITS >> 3) * 2) + 10)
+#define SHA_TEST_MAXLINELEN (((SHA_TEST_MAX_BITS >> 3) * 2) + 100)
int dgst_test(BIO *err, BIO *out, BIO *in)
{
/* Remove trailing space from value */
p = value + strlen(value) - 1;
-
while (*p == '\n' || isspace((unsigned char)*p))
*p-- = 0;