* contributed to the OpenSSL project.
*/
-#define OPENSSL_FIPSAPI
+
#include <string.h>
#include "ec_lcl.h"
#include <openssl/err.h>
-#include <string.h>
EC_KEY *EC_KEY_new(void)
{
}
ret->version = 1;
+ ret->flags = 0;
ret->group = NULL;
ret->pub_key = NULL;
ret->priv_key= NULL;
dest->enc_flag = src->enc_flag;
dest->conv_form = src->conv_form;
dest->version = src->version;
+ dest->flags = src->flags;
return dest;
}
return ((i > 1) ? 1 : 0);
}
-#ifdef OPENSSL_FIPS
-
-#include <openssl/evp.h>
-
-static int fips_check_ec(EC_KEY *key)
- {
- EVP_PKEY pk;
- unsigned char tbs[] = "ECDSA Pairwise Check Data";
- pk.type = EVP_PKEY_EC;
- pk.pkey.ec = key;
-
- if (!fips_pkey_signature_test(FIPS_TEST_PAIRWISE,
- &pk, tbs, -1, NULL, 0, NULL, 0, NULL))
- {
- FIPSerr(FIPS_F_FIPS_CHECK_EC,FIPS_R_PAIRWISE_TEST_FAILED);
- fips_set_selftest_fail();
- return 0;
- }
- return 1;
- }
-
-#endif
-
int EC_KEY_generate_key(EC_KEY *eckey)
{
int ok = 0;
eckey->priv_key = priv_key;
eckey->pub_key = pub_key;
-#ifdef OPENSSL_FIPS
- if(!fips_check_ec(eckey))
- {
- eckey->priv_key = NULL;
- eckey->pub_key = NULL;
- goto err;
- }
-#endif
-
ok=1;
err:
goto err;
}
/* testing whether pub_key * order is the point at infinity */
- order = &eckey->group->order;
+ order = eckey->group->order;
if (BN_is_zero(order))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);
tx, ty, ctx))
goto err;
}
- /* Check if retrieved coordinates match originals: if not values
- * are out of range.
+ /* Check if retrieved coordinates match originals and are less than
+ * field order: if not values are out of range.
*/
- if (BN_cmp(x, tx) || BN_cmp(y, ty))
+ if (BN_cmp(x, tx) || BN_cmp(y, ty)
+ || (BN_cmp(x, key->group->field) >= 0)
+ || (BN_cmp(y, key->group->field) >= 0))
{
ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES,
EC_R_COORDINATES_OUT_OF_RANGE);
void *EC_KEY_get_key_method_data(EC_KEY *key,
void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
{
- return EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
+ void *ret;
+
+ CRYPTO_r_lock(CRYPTO_LOCK_EC);
+ ret = EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
+ CRYPTO_r_unlock(CRYPTO_LOCK_EC);
+
+ return ret;
}
-void EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
+void *EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
{
EC_EXTRA_DATA *ex_data;
+
CRYPTO_w_lock(CRYPTO_LOCK_EC);
ex_data = EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
if (ex_data == NULL)
EC_EX_DATA_set_data(&key->method_data, data, dup_func, free_func, clear_free_func);
CRYPTO_w_unlock(CRYPTO_LOCK_EC);
+
+ return ex_data;
}
void EC_KEY_set_asn1_flag(EC_KEY *key, int flag)
return 0;
return EC_GROUP_precompute_mult(key->group, ctx);
}
+
+int EC_KEY_get_flags(const EC_KEY *key)
+ {
+ return key->flags;
+ }
+
+void EC_KEY_set_flags(EC_KEY *key, int flags)
+ {
+ key->flags |= flags;
+ }
+
+void EC_KEY_clear_flags(EC_KEY *key, int flags)
+ {
+ key->flags &= ~flags;
+ }