mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-04-02 02:26:58 +02:00
Remove curve parameter from public functions
This commit is contained in:
@@ -116,15 +116,13 @@ uECC_RNG_Function uECC_get_rng(void)
|
||||
return g_rng_function;
|
||||
}
|
||||
|
||||
int uECC_curve_private_key_size(uECC_Curve curve)
|
||||
int uECC_curve_private_key_size(void)
|
||||
{
|
||||
(void) curve;
|
||||
return BITS_TO_BYTES(NUM_ECC_BITS);
|
||||
}
|
||||
|
||||
int uECC_curve_public_key_size(uECC_Curve curve)
|
||||
int uECC_curve_public_key_size(void)
|
||||
{
|
||||
(void) curve;
|
||||
return 2 * NUM_ECC_BYTES;
|
||||
}
|
||||
|
||||
@@ -672,11 +670,6 @@ static void x_side_default(uECC_word_t *result,
|
||||
uECC_vli_modAdd(result, result, curve_b, curve_p);
|
||||
}
|
||||
|
||||
uECC_Curve uECC_secp256r1(void)
|
||||
{
|
||||
return curve_secp256r1;
|
||||
}
|
||||
|
||||
void vli_mmod_fast_secp256r1(unsigned int *result, unsigned int*product)
|
||||
{
|
||||
unsigned int tmp[NUM_ECC_WORDS];
|
||||
@@ -952,7 +945,7 @@ static uECC_word_t regularize_k(const uECC_word_t * const k, uECC_word_t *k0,
|
||||
}
|
||||
|
||||
int EccPoint_mult_safer(uECC_word_t * result, const uECC_word_t * point,
|
||||
const uECC_word_t * scalar, uECC_Curve curve)
|
||||
const uECC_word_t * scalar)
|
||||
{
|
||||
uECC_word_t tmp[NUM_ECC_WORDS];
|
||||
uECC_word_t s[NUM_ECC_WORDS];
|
||||
@@ -962,9 +955,6 @@ int EccPoint_mult_safer(uECC_word_t * result, const uECC_word_t * point,
|
||||
uECC_word_t *initial_Z = 0;
|
||||
int r;
|
||||
|
||||
if (curve != uECC_secp256r1())
|
||||
return 0;
|
||||
|
||||
/* Protects against invalid curves attacks */
|
||||
if (uECC_valid_point(point) != 0 ) {
|
||||
return 0;
|
||||
@@ -1005,10 +995,9 @@ clear_and_out:
|
||||
}
|
||||
|
||||
uECC_word_t EccPoint_compute_public_key(uECC_word_t *result,
|
||||
uECC_word_t *private_key,
|
||||
uECC_Curve curve)
|
||||
uECC_word_t *private_key)
|
||||
{
|
||||
return EccPoint_mult_safer(result, curve_G, private_key, curve);
|
||||
return EccPoint_mult_safer(result, curve_G, private_key);
|
||||
}
|
||||
|
||||
/* Converts an integer in uECC native format to big-endian bytes. */
|
||||
@@ -1106,8 +1095,7 @@ int uECC_valid_public_key(const uint8_t *public_key)
|
||||
return uECC_valid_point(_public);
|
||||
}
|
||||
|
||||
int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key,
|
||||
uECC_Curve curve)
|
||||
int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key)
|
||||
{
|
||||
|
||||
uECC_word_t _private[NUM_ECC_WORDS];
|
||||
@@ -1128,7 +1116,7 @@ int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key,
|
||||
}
|
||||
|
||||
/* Compute public key. */
|
||||
if (!EccPoint_compute_public_key(_public, _private, curve)) {
|
||||
if (!EccPoint_compute_public_key(_public, _private)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
|
||||
unsigned int *d, uECC_Curve curve)
|
||||
unsigned int *d)
|
||||
{
|
||||
|
||||
uECC_word_t _private[NUM_ECC_WORDS];
|
||||
@@ -85,7 +85,7 @@ int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
|
||||
mbedtls_platform_memcpy (_private, d, NUM_ECC_BYTES);
|
||||
|
||||
/* Computing public-key from private: */
|
||||
if (EccPoint_compute_public_key(_public, _private, curve)) {
|
||||
if (EccPoint_compute_public_key(_public, _private)) {
|
||||
|
||||
/* Converting buffers to correct bit order: */
|
||||
uECC_vli_nativeToBytes(private_key,
|
||||
@@ -106,7 +106,7 @@ int uECC_make_key_with_d(uint8_t *public_key, uint8_t *private_key,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
|
||||
int uECC_make_key(uint8_t *public_key, uint8_t *private_key)
|
||||
{
|
||||
|
||||
uECC_word_t _random[NUM_ECC_WORDS * 2];
|
||||
@@ -126,7 +126,7 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
|
||||
uECC_vli_mmod(_private, _random, curve_n);
|
||||
|
||||
/* Computing public-key from private: */
|
||||
if (EccPoint_compute_public_key(_public, _private, curve)) {
|
||||
if (EccPoint_compute_public_key(_public, _private)) {
|
||||
|
||||
/* Converting buffers to correct bit order: */
|
||||
uECC_vli_nativeToBytes(private_key,
|
||||
@@ -149,7 +149,7 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve)
|
||||
}
|
||||
|
||||
int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
|
||||
uint8_t *secret, uECC_Curve curve)
|
||||
uint8_t *secret)
|
||||
{
|
||||
|
||||
uECC_word_t _public[NUM_ECC_WORDS * 2];
|
||||
@@ -169,7 +169,7 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
|
||||
public_key + num_bytes,
|
||||
num_bytes);
|
||||
|
||||
r = EccPoint_mult_safer(_public, _public, _private, curve);
|
||||
r = EccPoint_mult_safer(_public, _public, _private);
|
||||
uECC_vli_nativeToBytes(secret, num_bytes, _public);
|
||||
|
||||
/* erasing temporary buffer used to store secret: */
|
||||
|
||||
@@ -76,7 +76,7 @@ static uECC_RNG_Function g_rng_function = 0;
|
||||
#endif
|
||||
|
||||
static void bits2int(uECC_word_t *native, const uint8_t *bits,
|
||||
unsigned bits_size, uECC_Curve curve)
|
||||
unsigned bits_size)
|
||||
{
|
||||
unsigned num_n_bytes = BITS_TO_BYTES(NUM_ECC_BITS);
|
||||
unsigned num_n_words = BITS_TO_WORDS(NUM_ECC_BITS);
|
||||
@@ -84,8 +84,6 @@ static void bits2int(uECC_word_t *native, const uint8_t *bits,
|
||||
uECC_word_t carry;
|
||||
uECC_word_t *ptr;
|
||||
|
||||
(void) curve;
|
||||
|
||||
if (bits_size > num_n_bytes) {
|
||||
bits_size = num_n_bytes;
|
||||
}
|
||||
@@ -111,8 +109,7 @@ static void bits2int(uECC_word_t *native, const uint8_t *bits,
|
||||
}
|
||||
|
||||
int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
unsigned hash_size, uECC_word_t *k, uint8_t *signature,
|
||||
uECC_Curve curve)
|
||||
unsigned hash_size, uECC_word_t *k, uint8_t *signature)
|
||||
{
|
||||
|
||||
uECC_word_t tmp[NUM_ECC_WORDS];
|
||||
@@ -128,7 +125,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = EccPoint_mult_safer(p, curve_G, k, curve);
|
||||
r = EccPoint_mult_safer(p, curve_G, k);
|
||||
if (r == 0 || uECC_vli_isZero(p)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -158,7 +155,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
uECC_vli_set(s, p);
|
||||
uECC_vli_modMult(s, tmp, s, curve_n); /* s = r*d */
|
||||
|
||||
bits2int(tmp, message_hash, hash_size, curve);
|
||||
bits2int(tmp, message_hash, hash_size);
|
||||
uECC_vli_modAdd(s, tmp, s, curve_n); /* s = e + r*d */
|
||||
uECC_vli_modMult(s, s, k, curve_n); /* s = (e + r*d) / k */
|
||||
if (uECC_vli_numBits(s) > (bitcount_t)NUM_ECC_BYTES * 8) {
|
||||
@@ -170,7 +167,7 @@ int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
}
|
||||
|
||||
int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
unsigned hash_size, uint8_t *signature, uECC_Curve curve)
|
||||
unsigned hash_size, uint8_t *signature)
|
||||
{
|
||||
uECC_word_t _random[2*NUM_ECC_WORDS];
|
||||
uECC_word_t k[NUM_ECC_WORDS];
|
||||
@@ -187,8 +184,7 @@ int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash,
|
||||
// computing k as modular reduction of _random (see FIPS 186.4 B.5.1):
|
||||
uECC_vli_mmod(k, _random, curve_n);
|
||||
|
||||
if (uECC_sign_with_k(private_key, message_hash, hash_size, k, signature,
|
||||
curve)) {
|
||||
if (uECC_sign_with_k(private_key, message_hash, hash_size, k, signature)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -201,8 +197,7 @@ static bitcount_t smax(bitcount_t a, bitcount_t b)
|
||||
}
|
||||
|
||||
int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
|
||||
unsigned hash_size, const uint8_t *signature,
|
||||
uECC_Curve curve)
|
||||
unsigned hash_size, const uint8_t *signature)
|
||||
{
|
||||
|
||||
uECC_word_t u1[NUM_ECC_WORDS], u2[NUM_ECC_WORDS];
|
||||
@@ -224,9 +219,6 @@ int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
|
||||
wordcount_t num_words = NUM_ECC_WORDS;
|
||||
wordcount_t num_n_words = BITS_TO_WORDS(NUM_ECC_BITS);
|
||||
|
||||
if (curve != uECC_secp256r1())
|
||||
return 0;
|
||||
|
||||
rx[num_n_words - 1] = 0;
|
||||
r[num_n_words - 1] = 0;
|
||||
s[num_n_words - 1] = 0;
|
||||
@@ -251,7 +243,7 @@ int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
|
||||
/* Calculate u1 and u2. */
|
||||
uECC_vli_modInv(z, s, curve_n); /* z = 1/s */
|
||||
u1[num_n_words - 1] = 0;
|
||||
bits2int(u1, message_hash, hash_size, curve);
|
||||
bits2int(u1, message_hash, hash_size);
|
||||
uECC_vli_modMult(u1, u1, z, curve_n); /* u1 = e/s */
|
||||
uECC_vli_modMult(u2, r, z, curve_n); /* u2 = r/s */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user