This should be CRLF even under *nix.
/* printf("Iteration %d\n", i); */
if (i > 0)
{
- fprintf(rfp,"COUNT = %d\n",i);
+ fprintf(rfp,"COUNT = %d" RESP_EOL ,i);
OutputValue("KEY",key[i],nkeysz,rfp,0);
if (imode != ECB) /* ECB */
OutputValue("IV",iv[i],AES_BLOCK_SIZE,rfp,0);
/* Output Ciphertext | Plaintext */
OutputValue(t_tag[dir],dir ? ctext[j] : ptext[j],len,rfp,
imode == CFB1);
- fprintf(rfp, "\n"); /* add separator */
+ fprintf(rfp, RESP_EOL); /* add separator */
/* Compute next KEY */
if (dir == XENCRYPT)
}
else
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
++ step;
}
}
if (akeysz)
{ /* insert current time & date */
time_t rtim = time(0);
- fprintf(rfp, "# %s", ctime(&rtim));
+ fputs("# ", rfp);
+ copy_line(ctime(&rtim), rfp);
}
else
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (strncmp(pp, "AESVS ", 6) == 0)
{
strcpy(algo, "AES");
case 1: /* [ENCRYPT] | [DECRYPT] */
if (ibuf[0] == '[')
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
++step;
if (fips_strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
dir = 1;
step = 2;
case 2: /* KEY = xxxx */
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if(*ibuf == '\n')
break;
if(!fips_strncasecmp(ibuf,"COUNT = ",8))
break;
case 3: /* IV = xxxx */
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (fips_strncasecmp(ibuf, "IV = ", 5) != 0)
{
printf("Missing IV\n");
break;
case 4: /* PLAINTEXT = xxxx */
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (fips_strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
{
printf("Missing PLAINTEXT\n");
break;
case 5: /* CIPHERTEXT = xxxx */
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (fips_strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
{
printf("Missing KEY\n");
}
else if (strcmp(atest, "MCT") != 0)
{ /* MCT already added terminating nl */
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
}
step = 1;
break;
}
rv = FIPS_cipher(&ctx, NULL, NULL, 0);
if (rv < 0)
- fprintf(out, "FAIL\n");
+ fprintf(out, "FAIL" RESP_EOL);
else
OutputValue("PT", pt, ptlen, out, 0);
if (iv)
{
if (rv == 0)
Payload[0] = 0;
- fputs("Result = Pass\n", out);
+ fputs("Result = Pass" RESP_EOL, out);
OutputValue("Payload", Payload, len, out, 0);
}
else
- fputs("Result = Fail\n", out);
+ fputs("Result = Fail" RESP_EOL, out);
OPENSSL_free(CT);
OPENSSL_free(Payload);
CT = Payload = NULL;
fputs("Mac = ", out);
for (i = 0; i < Tlen; i++)
fprintf(out, "%02x", res[i]);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
rc = 1;
}
CMAC_CTX_free(cmac_ctx);
else
{
if (!memcmp(Mac, res, Maclen))
- fputs("Result = P\n", out);
+ fputs("Result = P" RESP_EOL, out);
else
- fputs("Result = F\n", out);
+ fputs("Result = F" RESP_EOL, out);
}
CMAC_CTX_free(cmac_ctx);
return rc;
EVP_CIPHER_CTX ctx;
FIPS_cipher_ctx_init(&ctx);
- fprintf(rfp,"\nCOUNT = %d\n",i);
+ fprintf(rfp,RESP_EOL "COUNT = %d" RESP_EOL,i);
if(kp == 1)
OutputValue("KEY",akey,8,rfp,0);
else
}
else
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
++ step;
}
}
if(*amode)
{ /* insert current time & date */
time_t rtim = time(0);
- fprintf(rfp, "# %s", ctime(&rtim));
+ fputs("# ", rfp);
+ copy_line(ctime(&rtim), rfp);
}
else
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if(!strncmp(pp,"INVERSE ",8) || !strncmp(pp,"DES ",4)
|| !strncmp(pp,"TDES ",5)
|| !strncmp(pp,"PERMUTATION ",12)
break;
if (ibuf[0] == '[')
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
++step;
if (fips_strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
dir = 1;
case 2: /* KEY = xxxx */
if(*ibuf == '\n')
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
break;
}
if(!fips_strncasecmp(ibuf,"COUNT = ",8))
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
break;
}
if(!fips_strncasecmp(ibuf,"COUNT=",6))
{
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
break;
}
if(!fips_strncasecmp(ibuf,"NumKeys = ",10))
break;
}
if (echo)
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if(!fips_strncasecmp(ibuf,"KEY = ",6))
{
akeysz=64;
case 3: /* IV = xxxx */
if (echo)
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (fips_strncasecmp(ibuf, "IV = ", 5) != 0)
{
printf("Missing IV\n");
case 4: /* PLAINTEXT = xxxx */
if (echo)
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (fips_strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
{
printf("Missing PLAINTEXT\n");
case 5: /* CIPHERTEXT = xxxx */
if (echo)
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
if (fips_strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
{
printf("Missing KEY\n");
}
else if (strcmp(atest, "MCT") != 0)
{ /* MCT already added terminating nl */
- fputs(ibuf, rfp);
+ copy_line(ibuf, rfp);
}
step = 1;
break;
pp=BN_new();
do_hex2bn(&pp,value);
- fprintf(out, "result= %c\n",
+ fprintf(out, "result= %c" RESP_EOL,
BN_is_prime_ex(pp,20,NULL,NULL) ? 'P' : 'F');
}
}
seed, M_EVP_MD_size(md), out, 0);
if (!dsa2)
{
- fprintf(out, "c = %d\n",counter);
- fprintf(out, "H = %lx\n\n",h);
+ fprintf(out, "c = %d" RESP_EOL, counter);
+ fprintf(out, "H = %lx" RESP_EOL RESP_EOL,h);
}
else
{
- fprintf(out, "counter = %d\n",counter);
- fputs("\n", out);
+ fprintf(out, "counter = %d" RESP_EOL RESP_EOL, counter);
}
}
}
if (idx >= 0)
{
if (BN_cmp(dsa->g, g))
- fprintf(out, "Result = F\n");
+ fprintf(out, "Result = F" RESP_EOL);
else
- fprintf(out, "Result = P\n");
+ fprintf(out, "Result = P" RESP_EOL);
}
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");
+ fprintf(out, "Result = F" RESP_EOL);
else
- fprintf(out, "Result = P\n");
+ fprintf(out, "Result = P" RESP_EOL);
BN_free(p);
BN_free(q);
BN_free(g);
paramcheck = -1;
}
if (paramcheck != 1)
- fprintf(out, "Result = F\n");
+ fprintf(out, "Result = F" RESP_EOL);
else
{
if (!BN_mod_exp(Y2, g, X, p, ctx) || BN_cmp(Y2, Y))
- fprintf(out, "Result = F\n");
+ fprintf(out, "Result = F" RESP_EOL);
else
- fprintf(out, "Result = P\n");
+ fprintf(out, "Result = P" RESP_EOL);
}
BN_free(X);
BN_free(Y);
do_bn_print_name(out, "P",dsa->p);
do_bn_print_name(out, "Q",dsa->q);
do_bn_print_name(out, "G",dsa->g);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
while(n--)
{
do_bn_print_name(out, "X",dsa->priv_key);
do_bn_print_name(out, "Y",dsa->pub_key);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
}
}
}
do_bn_print_name(out, "P",dsa->p);
do_bn_print_name(out, "Q",dsa->q);
do_bn_print_name(out, "G",dsa->g);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
}
else if(!strcmp(keyword,"Msg"))
{
do_bn_print_name(out, "R",sig->r);
do_bn_print_name(out, "S",sig->s);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
FIPS_dsa_sig_free(sig);
FIPS_md_ctx_cleanup(&mctx);
}
no_err = 0;
FIPS_md_ctx_cleanup(&mctx);
- fprintf(out, "Result = %c\n\n", r == 1 ? 'P' : 'F');
+ fprintf(out, "Result = %c" RESP_EOL RESP_EOL, r == 1 ? 'P' : 'F');
}
}
}
do_bn_print_name(out, "d", d);
do_bn_print_name(out, "Qx", Qx);
do_bn_print_name(out, "Qy", Qy);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
EC_KEY_free(key);
}
no_err = 1;
rv = EC_KEY_set_public_key_affine_coordinates(key, Qx, Qy);
no_err = 0;
- fprintf(out, "Result = %s\n", rv ? "P":"F");
+ fprintf(out, "Result = %s" RESP_EOL, rv ? "P":"F");
}
}
rv = FIPS_ecdsa_verify_ctx(key, &mctx, sig);
no_err = 0;
- fprintf(out, "Result = %s\n", rv ? "P":"F");
+ fprintf(out, "Result = %s" RESP_EOL, rv ? "P":"F");
}
}
#include <openssl/fips_rand.h>
#include <openssl/objects.h>
+#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);
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);
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);
r = do_bn_print(out, bn);
if (!r)
return 0;
- fputs("\n", out);
+ fputs(RESP_EOL, out);
return 1;
}
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)
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
{
fprintf(rfp, "%s = ", tag);
for (i = 0; i < len; i++)
fprintf(rfp, "%02x", val[i]);
- fputs("\n", rfp);
+ fputs(RESP_EOL, rfp);
}
#if VERBOSE
fputs("Mac = ", out);
for (i = 0; i < Tlen; i++)
fprintf(out, "%02x", md[i]);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
return 1;
}
BN_free(bn_e);
fputs("n = ", out);
do_bn_print(out, rsa->n);
- fputs("\ne = ", out);
+ fputs(RESP_EOL "e = ", out);
do_bn_print(out, rsa->e);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
current_keylen = keylen;
}
for (i = 0; i < siglen; i++)
fprintf(out, "%02X", sigbuf[i]);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
ret = 1;
goto error;
if (r == 0)
- fputs("Result = F\n", out);
+ fputs("Result = F" RESP_EOL, out);
else
- fputs("Result = P\n", out);
+ fputs("Result = P" RESP_EOL, out);
ret = 1;
fputs("MD = ", out);
for (i = 0; i < mdlen; i++)
fprintf(out, "%02x", md[i]);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
return 1;
}
memcpy(m2, Seed, SeedLen);
memcpy(m3, Seed, SeedLen);
- fputs("\n", out);
+ fputs(RESP_EOL, out);
for (j = 0; j < 100; j++)
{
m3 = p;
FIPS_digestfinal(&ctx, m3, &m3len);
}
- fprintf(out, "COUNT = %d\n", j);
+ fprintf(out, "COUNT = %d" RESP_EOL, j);
fputs("MD = ", out);
for (k = 0; k < m3len; k++)
fprintf(out, "%02x", m3[k]);
- fputs("\n\n", out);
+ fputs(RESP_EOL RESP_EOL, out);
memcpy(m1, m3, m3len);
memcpy(m2, m3, m3len);
m1len = m2len = m3len;