1 /*
2  * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #pragma once
7 
8 #include <stdint.h>
9 #include <stdbool.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #define P256_LEN        (256/8)
16 #define P192_LEN        (192/8)
17 
18 /* Note: x & y are stored in little endian order (same as CPU byte order, and order used internally by most libraries).
19 
20    This is the same order used in hardware
21 
22    Note this is opposite to most byte string formats used to represent keys, which are often big endian
23 */
24 typedef struct {
25     uint8_t x[P256_LEN]; /* Little endian order */
26     uint8_t y[P256_LEN]; /* Little endian order */
27     unsigned len;        /* P192_LEN or P256_LEN */
28 } ecc_point_t;
29 
30 /**
31  * @brief Perform ECC point multiplication (R = K * (Px, Py))
32  *
33  * @param point ECC point (multiplicand)
34  * @param scalar Integer represented in byte array format (multiplier)
35  * @param result Result of the multiplication
36  * @param verify_first Verify that the point is on the curve before performing multiplication
37  *
38  * @return - 0 if the multiplication was successful
39  *         - -1 otherwise
40  *
41  * @note 'scalar' is expected as a byte array in little endian order.
42  *        Most byte string formats used to represent keys are in big endian order.
43  */
44 int esp_ecc_point_multiply(const ecc_point_t *point, const uint8_t *scalar, ecc_point_t *result, bool verify_first);
45 
46 /**
47  * @brief Perform ECC point verification,
48  *        i.e check whether the point (Px, Py) lies on the curve
49  *
50  * @param point ECC point that needs to be verified
51  *
52  * @return - 1, if point lies on the curve
53  *         - 0, otherwise
54  *
55  */
56 int esp_ecc_point_verify(const ecc_point_t *point);
57 
58 #ifdef __cplusplus
59 }
60 #endif
61