Contiki-NG
ecc-driver.h
Go to the documentation of this file.
1 /*
2  * Original file:
3  * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
4  * All rights reserved.
5  *
6  * Port to Contiki:
7  * Copyright (c) 2014 Andreas Dröscher <contiki@anticat.ch>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /**
36  * \addtogroup cc2538-pka
37  * @{
38  *
39  * \defgroup cc2538-ecc cc2538 ECC driver
40  *
41  * Driver for the cc2538 ECC mode of the PKC engine
42  * @{
43  *
44  * \file
45  * Header file for the cc2538 ECC driver
46  */
47 #ifndef ECC_DRIVER_H_
48 #define ECC_DRIVER_H_
49 
50 #include "contiki.h"
51 #include "dev/pka.h"
52 
53 #include <stdint.h>
54 /*---------------------------------------------------------------------------*/
55 /** \name ECC structures
56  * @{
57  */
58 typedef struct {
59  const char *name; /**< Name of the curve. */
60  const uint8_t size; /**< Size of the curve in 32-bit word. */
61  const uint32_t *prime; /**< The prime that defines the field of the curve. */
62  const uint32_t *n; /**< Order of the curve. */
63  const uint32_t *a; /**< Co-efficient a of the equation. */
64  const uint32_t *b; /**< co-efficient b of the equation. */
65  const uint32_t *x; /**< x co-ordinate value of the generator point. */
66  const uint32_t *y; /**< y co-ordinate value of the generator point. */
67 } ecc_curve_info_t;
68 
69 typedef struct {
70  uint32_t x[12]; /**< Pointer to value of the x co-ordinate. */
71  uint32_t y[12]; /**< Pointer to value of the y co-ordinate. */
72 } ec_point_t;
73 
74 /** @} */
75 /*---------------------------------------------------------------------------*/
76 /** \name ECC functions
77  * \note Not all sequencer functions are implemented in this driver
78  * look at the CC2538 manual for a complete list.
79  * @{
80  */
81 
82 /** \brief Starts ECC Multiplication.
83  *
84  * \param scalar Pointer to the buffer containing the scalar
85  * value to be multiplied.
86  * \param ec_point Pointer to the structure containing the
87  * elliptic curve point to be multiplied. The point should be
88  * on the given curve.
89  * \param curve Pointer to the structure containing the curve
90  * info.
91  * \param result_vector Pointer to the result vector location
92  * which will be set by this function.
93  * \param process Process to be polled upon completion of the
94  * operation, or \c NULL
95  *
96  * This function starts the Elliptical curve cryptography (ECC) point
97  * multiplication operation on the EC point and the scalar value.
98  *
99  * \retval PKA_STATUS_SUCCESS if successful in starting the operation.
100  * \retval PKA_STATUS_OPERATION_INPRG if the PKA hw module is busy doing
101  * some other operation.
102  */
103 uint8_t ecc_mul_start(uint32_t *scalar,
104  ec_point_t *ec_point,
105  ecc_curve_info_t *curve,
106  uint32_t *result_vector,
107  struct process *process);
108 
109 /** \brief Gets the result of ECC Multiplication
110  *
111  * \param ec_point Pointer to the structure where the resultant EC
112  * point will be stored. The callee is responsible to allocate the
113  * space for the ec point structure and the x and y co-ordinate as well.
114  * \param result_vector Address of the result location which
115  * was provided by the start function \sa PKAECCMultiplyStart().
116  *
117  * This function gets the result of ecc point multiplication operation on the
118  * ec point and the scalar value, previously started using the function
119  * \sa PKAECCMultiplyStart().
120  *
121  * \retval PKA_STATUS_SUCCESS if the operation is successful.
122  * \retval PKA_STATUS_OPERATION_INPRG if the PKA hw module is busy performing
123  * the operation.
124  * \retval PKA_STATUS_RESULT_0 if the result is all zeroes.
125  * \retval PKA_STATUS_FAILURE if the operation is not successful.
126  */
127 uint8_t ecc_mul_get_result(ec_point_t *ec_point,
128  uint32_t result_vector);
129 
130 /** \brief Starts the ECC Multiplication with Generator point.
131  *
132  * \param scalar Pointer to the buffer containing the
133  * scalar value.
134  * \param curve Pointer to the structure containing the curve
135  * info.
136  * \param result_vector Pointer to the result vector location
137  * which will be set by this function.
138  * \param process Process to be polled upon completion of the
139  * operation, or \c NULL
140  *
141  * This function starts the ecc point multiplication operation of the
142  * scalar value with the well known generator point of the given curve.
143  *
144  * \retval PKA_STATUS_SUCCESS if successful in starting the operation.
145  * \retval PKA_STATUS_OPERATION_INPRG if the PKA hw module is busy doing
146  * some other operation.
147  */
148 uint8_t ecc_mul_gen_pt_start(uint32_t *scalar,
149  ecc_curve_info_t *curve,
150  uint32_t *result_vector,
151  struct process *process);
152 
153 /** \brief Gets the result of ECC Multiplication with Generator point.
154  *
155  * \param ec_point Pointer to the structure where the resultant EC
156  * point will be stored. The callee is responsible to allocate the
157  * space for the ec point structure and the x and y co-ordinate as well.
158  * \param result_vector Address of the result location which
159  * was provided by the start function \sa PKAECCMultGenPtStart().
160  *
161  * This function gets the result of ecc point multiplication operation on the
162  * scalar point and the known generator point on the curve, previously started
163  * using the function \sa PKAECCMultGenPtStart().
164  *
165  * \retval PKA_STATUS_SUCCESS if the operation is successful.
166  * \retval PKA_STATUS_OPERATION_INPRG if the PKA hw module is busy performing
167  * the operation.
168  * \retval PKA_STATUS_RESULT_0 if the result is all zeroes.
169  * \retval PKA_STATUS_FAILURE if the operation is not successful.
170  */
171 uint8_t ecc_mul_gen_pt_get_result(ec_point_t *ec_point,
172  uint32_t result_vector);
173 
174 /** \brief Starts the ECC Addition.
175  *
176  * \param ec_point1 Pointer to the structure containing the first
177  * ecc point.
178  * \param ec_point2 Pointer to the structure containing the
179  * second ecc point.
180  * \param curve Pointer to the structure containing the curve
181  * info.
182  * \param result_vector Pointer to the result vector location
183  * which will be set by this function.
184  * \param process Process to be polled upon completion of the
185  * operation, or \c NULL
186  *
187  * This function starts the ecc point addition operation on the
188  * two given ec points and generates the resultant ecc point.
189  *
190  * \retval PKA_STATUS_SUCCESS if successful in starting the operation.
191  * \retval PKA_STATUS_OPERATION_INPRG if the PKA hw module is busy doing
192  * some other operation.
193  */
194 uint8_t ecc_add_start(ec_point_t *ec_point1, ec_point_t *ec_point2,
195  ecc_curve_info_t *curve,
196  uint32_t *result_vector,
197  struct process *process);
198 
199 /** \brief Gets the result of the ECC Addition
200  *
201  * \param ptOutEcPt Pointer to the structure where the resultant
202  * point will be stored. The callee is responsible to allocate memory,
203  * for the ec point structure including the memory for x and y
204  * co-ordinate values.
205  * \param ui32ResultLoc Address of the result location which
206  * was provided by the function \sa PKAECCAddStart().
207  *
208  * This function gets the result of ecc point addition operation on the
209  * on the two given ec points, previously started using the function \sa
210  * PKAECCAddStart().
211  *
212  * \retval PKA_STATUS_SUCCESS if the operation is successful.
213  * \retval PKA_STATUS_OPERATION_INPRG if the PKA hw module is busy performing
214  * the operation.
215  * \retval PKA_STATUS_RESULT_0 if the result is all zeroes.
216  * \retval PKA_STATUS_FAILURE if the operation is not successful.
217  */
218 uint8_t ecc_add_get_result(ec_point_t *ptOutEcPt, uint32_t ui32ResultLoc);
219 
220 /** @} */
221 
222 #endif /* ECC_DRIVER_H_ */
223 
224 /**
225  * @}
226  * @}
227  */
uint8_t ecc_mul_get_result(ec_point_t *ec_point, uint32_t result_vector)
Gets the result of ECC Multiplication.
Definition: ecc-driver.c:163
uint8_t ecc_mul_gen_pt_start(uint32_t *scalar, ecc_curve_info_t *curve, uint32_t *result_vector, struct process *process)
Starts the ECC Multiplication with Generator point.
Definition: ecc-driver.c:223
uint8_t ecc_add_get_result(ec_point_t *ec_point, uint32_t result_vector)
Gets the result of the ECC Addition.
Definition: ecc-driver.c:503
uint8_t ecc_mul_start(uint32_t *scalar, ec_point_t *ec_point, ecc_curve_info_t *curve, uint32_t *result_vector, struct process *process)
Starts ECC Multiplication.
Definition: ecc-driver.c:50
uint8_t ecc_mul_gen_pt_get_result(ec_point_t *ec_point, uint32_t result_vector)
Gets the result of ECC Multiplication with Generator point.
Definition: ecc-driver.c:330
Header file for the cc2538 PKA engine driver.
uint8_t ecc_add_start(ec_point_t *ec_point1, ec_point_t *ec_point2, ecc_curve_info_t *curve, uint32_t *result_vector, struct process *process)
Starts the ECC Addition.
Definition: ecc-driver.c:391