Fix many memory leaks in algorithm test utilities.
}
}
}
-
+ FIPS_cipher_ctx_cleanup(&ctx);
return ret;
}
fclose(rfp);
if (afp)
fclose(afp);
+ FIPS_cipher_ctx_cleanup(&ctx);
return err;
}
iv = aad = ct = pt = key = tag = NULL;
}
}
+ FIPS_cipher_ctx_cleanup(&ctx);
}
static void xtstest(FILE *in, FILE *out)
iv = key = inbuf = outbuf = NULL;
}
}
+ FIPS_cipher_ctx_cleanup(&ctx);
}
static void ccmtest(FILE *in, FILE *out)
}
else if (!strcmp(keyword,"Adata"))
{
+ if (Adata)
+ OPENSSL_free(Adata);
Adata = hex2bin_m(value, &l);
if (Alen && l != Alen)
{
OPENSSL_free(Key);
if (Nonce)
OPENSSL_free(Nonce);
+ if (Adata)
+ OPENSSL_free(Adata);
FIPS_cipher_ctx_cleanup(&ctx);
}
if(imode == TOFB)
for(n=0 ; n < 8 ; ++n)
text[n]=text0[n]^old_iv[n];
+ FIPS_cipher_ctx_cleanup(&ctx);
}
return 1;
}
fclose(rfp);
if (afp)
fclose(afp);
+ FIPS_cipher_ctx_cleanup(&ctx);
return err;
}
{
fprintf(out, "counter = %d" RESP_EOL RESP_EOL, counter);
}
+ FIPS_dsa_free(dsa);
}
}
else if(!strcmp(keyword,"P"))
BN_free(g);
if (Y2)
BN_free(Y2);
+ if (ctx)
+ BN_CTX_free(ctx);
}
static void keypair(FILE *in, FILE *out)
do_bn_print_name(out, "Y",dsa->pub_key);
fputs(RESP_EOL, out);
}
+ if (dsa)
+ FIPS_dsa_free(dsa);
}
}
}
FIPS_md_ctx_cleanup(&mctx);
}
}
- if (dsa)
- FIPS_dsa_free(dsa);
+ if (dsa)
+ FIPS_dsa_free(dsa);
}
static void sigver(FILE *in, FILE *out)
dsa = FIPS_dsa_new();
}
else if(!strcmp(keyword,"P"))
- dsa->p=hex2bn(value);
+ do_hex2bn(&dsa->p, value);
else if(!strcmp(keyword,"Q"))
- dsa->q=hex2bn(value);
+ do_hex2bn(&dsa->q, value);
else if(!strcmp(keyword,"G"))
- dsa->g=hex2bn(value);
+ do_hex2bn(&dsa->g, value);
else if(!strcmp(keyword,"Msg"))
n=hex2bin(value,msg);
else if(!strcmp(keyword,"Y"))
- dsa->pub_key=hex2bn(value);
+ do_hex2bn(&dsa->pub_key, value);
else if(!strcmp(keyword,"R"))
sig->r=hex2bn(value);
else if(!strcmp(keyword,"S"))
r = FIPS_dsa_verify_ctx(dsa, &mctx, sig);
no_err = 0;
FIPS_md_ctx_cleanup(&mctx);
+ if (sig->s)
+ {
+ BN_free(sig->s);
+ sig->s = NULL;
+ }
+ if (sig->r)
+ {
+ BN_free(sig->r);
+ sig->r = NULL;
+ }
fprintf(out, "Result = %c" RESP_EOL RESP_EOL, r == 1 ? 'P' : 'F');
}
}
+ if (dsa)
+ FIPS_dsa_free(dsa);
}
#ifdef FIPS_ALGVS
EC_GROUP *group = NULL;
char *keyword = NULL, *value = NULL;
int do_verify = -1, exout = 0;
+ int rv = 1;
int curve_nids[5] = {0,0,0,0,0};
int param_set = -1;
md, rhash, rhashlen);
}
}
- return 0;
+ rv = 0;
parse_error:
- fprintf(stderr, "Error Parsing request file\n");
- exit(1);
+ if (id)
+ BN_free(id);
+ if (ix)
+ BN_free(ix);
+ if (iy)
+ BN_free(iy);
+ if (cx)
+ BN_free(cx);
+ if (cy)
+ BN_free(cy);
+ if (group)
+ EC_GROUP_free(group);
+ if (rv)
+ fprintf(stderr, "Error Parsing request file\n");
+ return rv;
}
#endif
no_err = 1;
rv = EC_KEY_set_public_key_affine_coordinates(key, Qx, Qy);
no_err = 0;
+ EC_KEY_free(key);
fprintf(out, "Result = %s" RESP_EOL, rv ? "P":"F");
}
}
+ BN_free(Qx);
+ BN_free(Qy);
return 1;
}
do_bn_print_name(out, "S", sig->s);
EC_KEY_free(key);
-
+ OPENSSL_free(msg);
FIPS_ecdsa_sig_free(sig);
}
FIPS_digestupdate(&mctx, msg, mlen);
no_err = 1;
rv = FIPS_ecdsa_verify_ctx(key, &mctx, sig);
+ EC_KEY_free(key);
+ if (msg)
+ OPENSSL_free(msg);
no_err = 0;
fprintf(out, "Result = %s" RESP_EOL, rv ? "P":"F");
}
}
+ if (sig->r)
+ BN_free(sig->r);
+ if (sig->s)
+ BN_free(sig->s);
+ if (Qx)
+ BN_free(Qx);
+ if (Qy)
+ BN_free(Qy);
+ EVP_MD_CTX_cleanup(&mctx);
return 1;
}
#ifdef FIPS_ALGVS
for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
printf("\n");
+ FIPS_rsa_free(key);
+
return 1;
}
}
rv = 1;
err:
- FIPS_drbg_uninstantiate(dctx);
+ FIPS_drbg_free(dctx);
return rv;
}
error:
+ if (sigbuf)
+ OPENSSL_free(sigbuf);
+
return ret;
}
#endif
char **xargv;
int lineno = 0, badarg = 0;
int nerr = 0, quiet = 0, verbose = 0;
+ int rv;
FILE *in = NULL;
+#ifdef FIPS_ALGVS_MEMCHECK
+ CRYPTO_malloc_debug_init();
+ OPENSSL_init();
+ CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+#endif
+
if (*args && *args[0] != '-')
- return run_prg(argc - 1, args);
+ {
+ rv = run_prg(argc - 1, args);
+#ifdef FIPS_ALGVS_MEMCHECK
+ CRYPTO_mem_leaks_fp(stderr);
+#endif
+ return rv;
+ }
while (!badarg && *args && *args[0] == '-')
{
if (!strcmp(*args, "-script"))
fprintf(stderr, "Error processing line %d\n", lineno);
else
{
- int rv;
if (!quiet)
{
int i;
if (!quiet)
printf("Completed with %d errors\n", nerr);
+ if (arg.data)
+ OPENSSL_free(arg.data);
+
fclose(in);
+#ifdef FIPS_ALGVS_MEMCHECK
+ CRYPTO_mem_leaks_fp(stderr);
+#endif
if (nerr == 0)
return 0;
return 1;
}
-
#endif