From 4cc2bbab6758b73e005d69cb454cb9ba269859df Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 1 Oct 2011 20:42:52 +0000 Subject: Make fips algorithm test utilities use RESP_EOL for end of line character(s). This should be CRLF even under *nix. --- fips/fips_utl.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'fips/fips_utl.h') diff --git a/fips/fips_utl.h b/fips/fips_utl.h index 899422f438..c0ce613f47 100644 --- a/fips/fips_utl.h +++ b/fips/fips_utl.h @@ -52,6 +52,12 @@ #include #include +#ifdef OPENSSL_SYS_WIN32 +#define RESP_EOL "\n" +#else +#define RESP_EOL "\r\n" +#endif + int hex2bin(const char *in, unsigned char *out); unsigned char *hex2bin_m(const char *in, long *plen); int do_hex2bn(BIGNUM **pr, const char *in); @@ -61,6 +67,7 @@ int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf); int parse_line2(char **pkw, char **pval, char *linebuf, char *olinebuf, int eol); BIGNUM *hex2bn(const char *in); int tidy_line(char *linebuf, char *olinebuf); +int copy_line(const char *in, FILE *ofp); int bint2bin(const char *in, int len, unsigned char *out); int bin2bint(const unsigned char *in,int len,char *out); void PrintValue(char *tag, unsigned char *val, int len); @@ -74,9 +81,9 @@ static int no_err; static void put_err_cb(int lib, int func,int reason,const char *file,int line) { - if (no_err) - return; - fprintf(stderr, "ERROR:%08lX:lib=%d,func=%d,reason=%d" + if (no_err) + return; + fprintf(stderr, "ERROR:%08lX:lib=%d,func=%d,reason=%d" ":file=%s:line=%d\n", ERR_PACK(lib, func, reason), lib, func, reason, file, line); @@ -257,7 +264,7 @@ int do_bn_print_name(FILE *out, const char *name, const BIGNUM *bn) r = do_bn_print(out, bn); if (!r) return 0; - fputs("\n", out); + fputs(RESP_EOL, out); return 1; } @@ -373,6 +380,20 @@ int tidy_line(char *linebuf, char *olinebuf) return 1; } +/* Copy supplied line to ofp replacing \n with \r\n */ +int copy_line(const char *in, FILE *ofp) + { + const char *p; + p = strchr(in, '\n'); + if (p) + { + fwrite(in, 1, (size_t)(p - in), ofp); + fputs(RESP_EOL, ofp); + } + else + fputs(in, ofp); + return 1; + } /* NB: this return the number of _bits_ read */ int bint2bin(const char *in, int len, unsigned char *out) @@ -412,7 +433,7 @@ void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode) if(bitmode) { olen=bin2bint(val,len,obuf); - fprintf(rfp, "%s = %.*s\n", tag, olen, obuf); + fprintf(rfp, "%s = %.*s" RESP_EOL, tag, olen, obuf); } else { @@ -420,7 +441,7 @@ void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode) fprintf(rfp, "%s = ", tag); for (i = 0; i < len; i++) fprintf(rfp, "%02x", val[i]); - fputs("\n", rfp); + fputs(RESP_EOL, rfp); } #if VERBOSE -- cgit v1.2.3