return ret;
}
+static int rsa_ex_idx = -1;
+
static int (*orig_rsa_priv_enc)(int, const unsigned char *, unsigned char *, RSA *, int);
static int tst_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to,
RSA *rsa, int padding)
{
+ if (strcmp(RSA_get_ex_data(rsa, rsa_ex_idx), "test") != 0)
+ return 0;
sign_hits++;
return orig_rsa_priv_enc(flen, from, to, rsa, padding);
}
if (!TEST_ptr(e) || !TEST_ptr(method))
goto err;
+ rsa_ex_idx = RSA_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+
if (!TEST_true(BN_set_word(e, RSA_F4)))
goto err;
rsa = RSA_new();
if (!TEST_ptr(rsa))
goto err;
+ if (!TEST_true(RSA_set_ex_data(rsa, rsa_ex_idx, (void *)"test")))
+ goto err;
if (!TEST_true(RSA_generate_key_ex(rsa, 1024, e, NULL)))
goto err;
}
#ifndef OPENSSL_NO_DSA
+static int dsa_ex_idx = -1;
+
static DSA_SIG *(*orig_dsa_sign)(const unsigned char *, int, DSA *);
static DSA_SIG *tst_dsa_sign(const unsigned char *buf, int len, DSA *dsa)
{
+ if (strcmp(DSA_get_ex_data(dsa, dsa_ex_idx), "test") != 0)
+ return 0;
sign_hits++;
return orig_dsa_sign(buf, len, dsa);
}
if (!TEST_ptr(method))
goto err;
+ dsa_ex_idx = DSA_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+
dsa = load_dsa_params();
if (!TEST_ptr(dsa))
goto err;
+ if (!TEST_true(DSA_set_ex_data(dsa, dsa_ex_idx, (void *)"test")))
+ goto err;
if (!TEST_true(DSA_generate_key(dsa)))
goto err;
#endif /* OPENSSL_NO_DSA */
#ifndef OPENSSL_NO_EC
+static int ec_ex_idx = -1;
+
static int (*orig_ec_sign)(int type, const unsigned char *dgst,
int dlen, unsigned char *sig,
unsigned int *siglen,
const BIGNUM *kinv, const BIGNUM *r,
EC_KEY *eckey)
{
+ if (strcmp(EC_KEY_get_ex_data(eckey, ec_ex_idx), "test") != 0)
+ return 0;
sign_hits++;
return orig_ec_sign(type, dgst, dlen, sig, siglen, kinv, r, eckey);
}
if (!TEST_ptr(method))
goto err;
+ ec_ex_idx = EC_KEY_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+
if (!TEST_ptr(ec = EC_KEY_new_by_curve_name_ex(NULL, NULL, NID_X9_62_prime256v1)))
goto err;
+ if (!TEST_true(EC_KEY_set_ex_data(ec, ec_ex_idx, (void *)"test")))
+ goto err;
if (!TEST_true(EC_KEY_generate_key(ec)))
goto err;
#endif /* OPENSSL_NO_EC */
#ifndef OPENSSL_NO_DH
+static int dh_ex_idx = -1;
static int compute_key_hits = 0;
static int tst_dh_compute_key(unsigned char *key, const BIGNUM *pub_key,
DH *dh)
{
+ if (strcmp(DH_get_ex_data(dh, dh_ex_idx), "test") != 0)
+ return 0;
compute_key_hits++;
return orig_dh_compute_key(key, pub_key, dh);
}
if (!TEST_ptr(method))
goto err;
+ dh_ex_idx = DH_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+
pkey = get_dh512(NULL);
if (!TEST_ptr(pkey))
goto err;
dh = DH_new();
if (!TEST_ptr(dh))
goto err;
+ if (!TEST_true(DH_set_ex_data(dh, dh_ex_idx, (void *)"test")))
+ goto err;
orig_dh_compute_key = DH_meth_get_compute_key(def);
if (!TEST_true(DH_meth_set_compute_key(method, tst_dh_compute_key)))