mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 14:55:40 +01:00
Clean up ECP abstraction layer code
This commit fixes several style issues and fixes in the documentation of the Elliptic Curve Point arithmetic abstraction layer.
This commit is contained in:
parent
b069753313
commit
372697b6b7
@ -1,9 +1,10 @@
|
||||
/**
|
||||
* \file alt_func_internal.h
|
||||
* \file ecp_function_alt.h
|
||||
*
|
||||
* \brief Function declarations for alternate implementation.
|
||||
* \brief Function declarations for alternative implementation of elliptic curve
|
||||
* point arithmetic.
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* Copyright (C) 2016, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@ -38,22 +39,23 @@ void ecp_alt_deinit( const mbedtls_ecp_group *grp );
|
||||
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
|
||||
int ecp_randomize_jac_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
|
||||
int ecp_add_mixed_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
|
||||
const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
|
||||
int ecp_double_jac_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_ecp_point *P );
|
||||
const mbedtls_ecp_point *P );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
|
||||
int ecp_normalize_jac_many_alt( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *T[], size_t t_len );
|
||||
mbedtls_ecp_point *T[], size_t t_len );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
|
||||
@ -62,21 +64,22 @@ int ecp_normalize_jac_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt )
|
||||
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
|
||||
int ecp_double_add_mxz_alt( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *R, mbedtls_ecp_point *S,
|
||||
const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q,
|
||||
const mbedtls_mpi *d );
|
||||
mbedtls_ecp_point *R, mbedtls_ecp_point *S,
|
||||
const mbedtls_ecp_point *P,
|
||||
const mbedtls_ecp_point *Q, const mbedtls_mpi *d );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
|
||||
int ecp_randomize_mxz_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
|
||||
int ecp_normalize_mxz_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P );
|
||||
#endif
|
||||
|
||||
#endif // MBEDTLS_ECP_FUNCTION_ALT
|
||||
#endif /* MBEDTLS_ECP_FUNCTION_ALT */
|
||||
|
||||
#endif /* ecp_function_alt.h */
|
||||
|
||||
|
@ -297,24 +297,24 @@
|
||||
* \def MBEDTLS_ECP_FUNCTION_ALT
|
||||
*
|
||||
* MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your
|
||||
* alternate core implementation of elliptic curve arithmetic. Keep in mind that
|
||||
* function prototypes should remain the same.
|
||||
* alternative core implementation of elliptic curve arithmetic. Keep in mind
|
||||
* that function prototypes should remain the same.
|
||||
*
|
||||
* This partially replaces one function. The header file from mbed TLS is still
|
||||
* used, in contrast to the MBEDTLS_ECP_ALT flag. The original implementation
|
||||
* is still present and it is used for group structures not supported by the
|
||||
* alternative.
|
||||
*
|
||||
* Any of these options become available by turning MBEDTLS_ECP_FUNCTION_ALT and
|
||||
* implementing the following function:
|
||||
* Any of these options become available by defining MBEDTLS_ECP_FUNCTION_ALT
|
||||
* and implementing the following function:
|
||||
* unsigned char ecp_alt_grp_capable( const mbedtls_ecp_group *grp )
|
||||
* This should return 1 if the replacement functions implement arithmetic for
|
||||
* the given group and 0 otherwise.
|
||||
*
|
||||
* The functions
|
||||
* int ecp_alt_init( const mbedtls_ecp_group *grp )
|
||||
* void ecp_alt_deinit( const mbedtls_ecp_group *grp )
|
||||
* can be turned on by MBEDTLS_ECP_ALT_INIT and MBEDTLS_ECP_ALT_DEINIT.
|
||||
* The functions:
|
||||
* int ecp_alt_init( const mbedtls_ecp_group *grp )
|
||||
* void ecp_alt_deinit( const mbedtls_ecp_group *grp )
|
||||
* can be enabled by MBEDTLS_ECP_ALT_INIT and MBEDTLS_ECP_ALT_DEINIT.
|
||||
* They are called before and after each point operation and provide an
|
||||
* opportunity to implement optimized set up and tear down instructions.
|
||||
*
|
||||
|
@ -38,8 +38,11 @@
|
||||
#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< Signature is valid but shorter than the user-supplied length. */
|
||||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
// Regular implementation
|
||||
// default mbed TLS elliptic curve arithmetic implementation
|
||||
//
|
||||
// (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
|
||||
// alternative implementation for the whole module and it will replace this
|
||||
// one.)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -666,7 +669,7 @@ int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ec
|
||||
*/
|
||||
int mbedtls_ecp_self_test( int verbose );
|
||||
|
||||
#endif // MBEDTLS_SELF_TEST
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -757,7 +757,7 @@ static int ecp_normalize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *p
|
||||
{
|
||||
return ecp_normalize_jac_alt( grp, pt );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) */
|
||||
#endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */
|
||||
mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi );
|
||||
|
||||
/*
|
||||
@ -934,7 +934,7 @@ static int ecp_double_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
{
|
||||
return ecp_double_jac_alt( grp, R, P );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) */
|
||||
#endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */
|
||||
|
||||
mbedtls_mpi_init( &M ); mbedtls_mpi_init( &S ); mbedtls_mpi_init( &T ); mbedtls_mpi_init( &U );
|
||||
|
||||
@ -1032,7 +1032,7 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
{
|
||||
return ecp_add_mixed_alt( grp, R, P, Q );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) */
|
||||
#endif /* MBEDTLS_ECP_ADD_MIXED_ALT */
|
||||
|
||||
/*
|
||||
* Trivial cases: P == 0 or Q == 0 (case 1)
|
||||
@ -1119,7 +1119,7 @@ static int ecp_randomize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *p
|
||||
{
|
||||
return ecp_randomize_jac_alt( grp, pt, f_rng, p_rng );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) */
|
||||
#endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */
|
||||
|
||||
p_size = ( grp->pbits + 7 ) / 8;
|
||||
mbedtls_mpi_init( &l ); mbedtls_mpi_init( &ll );
|
||||
@ -1487,7 +1487,7 @@ static int ecp_normalize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P
|
||||
{
|
||||
return ecp_normalize_mxz_alt( grp, P );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) */
|
||||
#endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &P->Z, &P->Z, &grp->P ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &P->X, &P->X, &P->Z ) ); MOD_MUL( P->X );
|
||||
@ -1518,7 +1518,7 @@ static int ecp_randomize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P
|
||||
{
|
||||
return ecp_randomize_mxz_alt( grp, P, f_rng, p_rng );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) */
|
||||
#endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */
|
||||
|
||||
p_size = ( grp->pbits + 7 ) / 8;
|
||||
mbedtls_mpi_init( &l );
|
||||
@ -1573,7 +1573,7 @@ static int ecp_double_add_mxz( const mbedtls_ecp_group *grp,
|
||||
{
|
||||
return ecp_double_add_mxz_alt( grp, R, S, P, Q, d );
|
||||
}
|
||||
#endif /* #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) */
|
||||
#endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */
|
||||
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &AA ); mbedtls_mpi_init( &B );
|
||||
mbedtls_mpi_init( &BB ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &C );
|
||||
|
Loading…
Reference in New Issue
Block a user