1 /* 2 * Copyright (c) 2024, The TrustedFirmware-M Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __CC3XX_EC_WEIERSTRASS_H__ 9 #define __CC3XX_EC_WEIERSTRASS_H__ 10 11 #include <stdint.h> 12 #include <stddef.h> 13 14 #include "cc3xx_pka.h" 15 #include "cc3xx_ec.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * @brief Validate an affine point. 23 * 24 * @param[in] curve A pointer to an initialized weierstrass curve 25 * object 26 * @param[in] p A pointer to the affine point to validate. 27 * 28 * @return true if the affine point a valid point on 29 * the curve, false if it isn't. 30 */ 31 bool cc3xx_lowlevel_ec_weierstrass_validate_point(cc3xx_ec_curve_t *curve, 32 cc3xx_ec_point_affine *p); 33 34 /** 35 * @brief Add two affine points 36 * 37 * @param[in] curve A pointer to an initialized weierstrass curve 38 * object 39 * @param[in] p A pointer to the first affine point object to 40 * add. 41 * @param[in] q A pointer to the secnd affine point object to 42 * add. 43 * @param[out] res A pointer to the affine point object which the 44 * result will be written to. 45 * 46 * @return CC3XX_ERR_SUCCESS on success, another 47 * cc3xx_err_t on error. 48 */ 49 cc3xx_err_t cc3xx_lowlevel_ec_weierstrass_add_points(cc3xx_ec_curve_t *curve, 50 cc3xx_ec_point_affine *p, 51 cc3xx_ec_point_affine *q, 52 cc3xx_ec_point_affine *res); 53 54 /** 55 * @brief Double an affine point 56 * 57 * @param[in] curve A pointer to an initialized weierstrass curve 58 * object. 59 * @param[in] p A pointer to the affine point object to double. 60 * @param[out] res A pointer to the affine point object which the 61 * result will be written to. 62 * 63 * @return CC3XX_ERR_SUCCESS on success, another 64 * cc3xx_err_t on error. 65 */ 66 cc3xx_err_t cc3xx_lowlevel_ec_weierstrass_double_point(cc3xx_ec_curve_t *curve, 67 cc3xx_ec_point_affine *p, 68 cc3xx_ec_point_affine *res); 69 70 /** 71 * @brief Negate an affine point 72 * 73 * @param[in] p A pointer to the affine point object to negate. 74 * @param[out] res A pointer to the affine point object which the 75 * result will be written to. 76 */ 77 void cc3xx_lowlevel_ec_weierstrass_negate_point(cc3xx_ec_point_affine *p, 78 cc3xx_ec_point_affine *res); 79 80 /** 81 * @brief Multiply an affine point by a scalar value 82 * 83 * @note This function is side-channel protected and 84 * may be used on secret values. By default it is 85 * protected against timing attacks, further 86 * mitigations can be enabled by config. 87 * 88 * @param[in] curve A pointer to an initialized weierstrass curve 89 * object. 90 * @param[in] p A pointer to the affine point object to 91 * multiply. 92 * @param[in] scalar The scalar value to multiply the point by. 93 * @param[out] res A pointer to the affine point object which the 94 * result will be written to. 95 * 96 * @return CC3XX_ERR_SUCCESS on success, another 97 * cc3xx_err_t on error. 98 */ 99 cc3xx_err_t cc3xx_lowlevel_ec_weierstrass_multipy_point_by_scalar( 100 cc3xx_ec_curve_t *curve, 101 cc3xx_ec_point_affine *p, 102 cc3xx_pka_reg_id_t scalar, 103 cc3xx_ec_point_affine *res); 104 105 /** 106 * @brief Multiply two scalar by two separate affine 107 * values, and then add the points. This function 108 * may use the Shamir trick, if it is enabled by 109 * config. 110 * 111 * @note This function must _not_ be used on secret 112 * values, in case the Shamir trick is used which 113 * is not side-channel protected. 114 * 115 * @param[in] curve A pointer to an initialized weierstrass curve 116 * object 117 * @param[in] p1 A pointer to the first affine point object to 118 * multiply. 119 * @param[in] scalar1 The scalar value to multiply the first point 120 * by. 121 * @param[in] p2 A pointer to the second affine point object to 122 * multiply. 123 * @param[in] scalar2 The scalar value to multiply the second point 124 * by. 125 * @param[out] res A pointer to the affine point object which the 126 * result will be written to. 127 * 128 * @return CC3XX_ERR_SUCCESS on success, another 129 * cc3xx_err_t on error. 130 */ 131 cc3xx_err_t cc3xx_lowlevel_ec_weierstrass_shamir_multiply_points_by_scalars_and_add( 132 cc3xx_ec_curve_t *curve, 133 cc3xx_ec_point_affine *p1, 134 cc3xx_pka_reg_id_t scalar1, 135 cc3xx_ec_point_affine *p2, 136 cc3xx_pka_reg_id_t scalar2, 137 cc3xx_ec_point_affine *res); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* __CC3XX_EC_WEIERSTRASS_H__ */ 144