• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright The Mbed TLS Contributors
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * Copyright (c) 2023 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
17  *
18  *****************************************************************************/
19 
20 #ifndef ECP_ALT_H
21 #define ECP_ALT_H
22 
23 #if defined(MBEDTLS_ECP_ALT)
24 
25 typedef struct mbedtls_ecp_group {
26     mbedtls_ecp_group_id id; /*!< An internal group identifier. */
27     mbedtls_mpi P;           /*!< The prime modulus of the base field. */
28     mbedtls_mpi A;           /*!< For Short Weierstrass: \p A in the equation. For
29                                      Montgomery curves: <code>(A + 2) / 4</code>. */
30     mbedtls_mpi B;           /*!< For Short Weierstrass: \p B in the equation.
31                                      For Montgomery curves: unused. */
32     mbedtls_ecp_point G;     /*!< The generator of the subgroup used. */
33     mbedtls_mpi N;           /*!< The order of \p G. */
34     size_t pbits;            /*!< The number of bits in \p P. */
35     size_t nbits;            /*!< For Short Weierstrass: The number of bits in \p P.
36                                      For Montgomery curves: the number of bits in the
37                                      private keys. */
38     /* End of public fields */
39 
40     unsigned int MBEDTLS_PRIVATE(h);             /*!< \internal 1 if the constants are static. */
41     int (*MBEDTLS_PRIVATE(modp))(mbedtls_mpi *); /*!< The function for fast pseudo-reduction mod \p P (see above). */
42     int (*MBEDTLS_PRIVATE(t_pre))(mbedtls_ecp_point *, void *);  /*!< Unused. */
43     int (*MBEDTLS_PRIVATE(t_post))(mbedtls_ecp_point *, void *); /*!< Unused. */
44     void *MBEDTLS_PRIVATE(t_data);                               /*!< Unused. */
45     mbedtls_ecp_point *MBEDTLS_PRIVATE(T);                       /*!< Pre-computed points for ecp_mul_comb(). */
46     size_t MBEDTLS_PRIVATE(T_size); /*!< The number of dynamic allocated pre-computed points. */
47 } mbedtls_ecp_group;
48 
49 /**
50  * \name SECTION: Module settings
51  *
52  * The configuration options you can set for this module are in this section.
53  * Either change them in mbedtls_config.h, or define them using the compiler command line.
54  * \{
55  */
56 
57 #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
58 /*
59  * Maximum "window" size used for point multiplication.
60  * Default: a point where higher memory usage yields disminishing performance
61  *          returns.
62  * Minimum value: 2. Maximum value: 7.
63  *
64  * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
65  * points used for point multiplication. This value is directly tied to EC
66  * peak memory usage, so decreasing it by one should roughly cut memory usage
67  * by two (if large curves are in use).
68  *
69  * Reduction in size may reduce speed, but larger curves are impacted first.
70  * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
71  *      w-size:     6       5       4       3       2
72  *      521       145     141     135     120      97
73  *      384       214     209     198     177     146
74  *      256       320     320     303     262     226
75  *      224       475     475     453     398     342
76  *      192       640     640     633     587     476
77  */
78 #define MBEDTLS_ECP_WINDOW_SIZE 4 /**< The maximum window size used. */
79 #endif                            /* MBEDTLS_ECP_WINDOW_SIZE */
80 
81 #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
82 /*
83  * Trade code size for speed on fixed-point multiplication.
84  *
85  * This speeds up repeated multiplication of the generator (that is, the
86  * multiplication in ECDSA signatures, and half of the multiplications in
87  * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
88  *
89  * For each n-bit Short Weierstrass curve that is enabled, this adds 4n bytes
90  * of code size if n < 384 and 8n otherwise.
91  *
92  * Change this value to 0 to reduce code size.
93  */
94 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */
95 #endif                                  /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
96 
97 /* \} name SECTION: Module settings */
98 
99 #endif /* MBEDTLS_ECP_ALT */
100 
101 #endif /* ecp_alt.h */
102