blob: 70bd5ad4f469e0c75f44a53a2907a69fa460efc7 [file] [log] [blame]
Jarno Lamsa18987a42019-04-24 15:40:43 +03001/* ecc.h - TinyCrypt interface to common ECC functions */
2
Simon Butcher92c3d1f2019-09-09 17:25:08 +01003/*
4 * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
Jarno Lamsa18987a42019-04-24 15:40:43 +03008/* Copyright (c) 2014, Kenneth MacKay
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * * Redistributions of source code must retain the above copyright notice, this
15 * list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions are met:
39 *
40 * - Redistributions of source code must retain the above copyright notice,
41 * this list of conditions and the following disclaimer.
42 *
43 * - Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 *
47 * - Neither the name of Intel Corporation nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
52 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
55 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 * POSSIBILITY OF SUCH DAMAGE.
62 */
63
64/**
65 * @file
66 * @brief -- Interface to common ECC functions.
67 *
68 * Overview: This software is an implementation of common functions
69 * necessary to elliptic curve cryptography. This implementation uses
70 * curve NIST p-256.
71 *
72 * Security: The curve NIST p-256 provides approximately 128 bits of security.
73 *
74 */
75
Manuel Pégourié-Gonnardafdc1b52019-05-09 11:24:11 +020076#if defined(MBEDTLS_USE_TINYCRYPT)
Jarno Lamsa18987a42019-04-24 15:40:43 +030077#ifndef __TC_UECC_H__
78#define __TC_UECC_H__
79
80#include <stdint.h>
81
82#ifdef __cplusplus
83extern "C" {
84#endif
85
Manuel Pégourié-Gonnardc05f1502019-11-06 10:15:26 +010086/* Return values for functions, chosen with large Hamming distances between
87 * them (especially to SUCESS) to mitigate the impact of fault injection
88 * attacks flipping a low number of bits. */
89#define UECC_SUCCESS 0
90#define UECC_FAILURE 0x75555555
91#define UECC_ATTACK_DETECTED 0x7aaaaaaa
92
Jarno Lamsa18987a42019-04-24 15:40:43 +030093/* Word size (4 bytes considering 32-bits architectures) */
94#define uECC_WORD_SIZE 4
95
96/* setting max number of calls to prng: */
97#ifndef uECC_RNG_MAX_TRIES
98#define uECC_RNG_MAX_TRIES 64
99#endif
100
101/* defining data types to store word and bit counts: */
102typedef int8_t wordcount_t;
103typedef int16_t bitcount_t;
104/* defining data type for comparison result: */
105typedef int8_t cmpresult_t;
106/* defining data type to store ECC coordinate/point in 32bits words: */
107typedef unsigned int uECC_word_t;
108/* defining data type to store an ECC coordinate/point in 64bits words: */
109typedef uint64_t uECC_dword_t;
110
111/* defining masks useful for ecc computations: */
112#define HIGH_BIT_SET 0x80000000
113#define uECC_WORD_BITS 32
114#define uECC_WORD_BITS_SHIFT 5
115#define uECC_WORD_BITS_MASK 0x01F
116
117/* Number of words of 32 bits to represent an element of the the curve p-256: */
118#define NUM_ECC_WORDS 8
119/* Number of bytes to represent an element of the the curve p-256: */
120#define NUM_ECC_BYTES (uECC_WORD_SIZE*NUM_ECC_WORDS)
Manuel Pégourié-Gonnard78a7e352019-11-04 12:31:06 +0100121#define NUM_ECC_BITS 256
Jarno Lamsa18987a42019-04-24 15:40:43 +0300122
123/* structure that represents an elliptic curve (e.g. p256):*/
124struct uECC_Curve_t;
125typedef const struct uECC_Curve_t * uECC_Curve;
126struct uECC_Curve_t {
Jarno Lamsa18987a42019-04-24 15:40:43 +0300127 uECC_word_t b[NUM_ECC_WORDS];
Jarno Lamsa18987a42019-04-24 15:40:43 +0300128};
129
130/*
131 * @brief computes doubling of point ion jacobian coordinates, in place.
132 * @param X1 IN/OUT -- x coordinate
133 * @param Y1 IN/OUT -- y coordinate
134 * @param Z1 IN/OUT -- z coordinate
135 * @param curve IN -- elliptic curve
136 */
137void double_jacobian_default(uECC_word_t * X1, uECC_word_t * Y1,
138 uECC_word_t * Z1, uECC_Curve curve);
139
140/*
Jarno Lamsa18987a42019-04-24 15:40:43 +0300141 * @brief Computes result = product % curve_p
142 * from http://www.nsa.gov/ia/_files/nist-routines.pdf
143 * @param result OUT -- product % curve_p
144 * @param product IN -- value to be reduced mod curve_p
145 */
146void vli_mmod_fast_secp256r1(unsigned int *result, unsigned int *product);
147
148/* Bytes to words ordering: */
149#define BYTES_TO_WORDS_8(a, b, c, d, e, f, g, h) 0x##d##c##b##a, 0x##h##g##f##e
150#define BYTES_TO_WORDS_4(a, b, c, d) 0x##d##c##b##a
151#define BITS_TO_WORDS(num_bits) \
152 ((num_bits + ((uECC_WORD_SIZE * 8) - 1)) / (uECC_WORD_SIZE * 8))
153#define BITS_TO_BYTES(num_bits) ((num_bits + 7) / 8)
154
Manuel Pégourié-Gonnard4d8777c2019-11-21 10:02:58 +0100155extern const uECC_word_t curve_p[NUM_ECC_WORDS];
Manuel Pégourié-Gonnard356d8592019-11-21 10:23:05 +0100156extern const uECC_word_t curve_n[NUM_ECC_WORDS];
Manuel Pégourié-Gonnarda6115082019-11-21 10:29:14 +0100157extern const uECC_word_t curve_G[2 * NUM_ECC_WORDS];
Manuel Pégourié-Gonnard4d8777c2019-11-21 10:02:58 +0100158
Jarno Lamsa18987a42019-04-24 15:40:43 +0300159/* definition of curve NIST p-256: */
160static const struct uECC_Curve_t curve_secp256r1 = {
Manuel Pégourié-Gonnard30833f22019-11-21 09:46:52 +0100161 {
Jarno Lamsa18987a42019-04-24 15:40:43 +0300162 BYTES_TO_WORDS_8(4B, 60, D2, 27, 3E, 3C, CE, 3B),
163 BYTES_TO_WORDS_8(F6, B0, 53, CC, B0, 06, 1D, 65),
164 BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3),
165 BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A)
166 },
Jarno Lamsa18987a42019-04-24 15:40:43 +0300167};
168
169uECC_Curve uECC_secp256r1(void);
170
171/*
172 * @brief Generates a random integer in the range 0 < random < top.
173 * Both random and top have num_words words.
174 * @param random OUT -- random integer in the range 0 < random < top
175 * @param top IN -- upper limit
176 * @param num_words IN -- number of words
177 * @return a random integer in the range 0 < random < top
178 */
179int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top,
180 wordcount_t num_words);
181
182
183/* uECC_RNG_Function type
184 * The RNG function should fill 'size' random bytes into 'dest'. It should
185 * return 1 if 'dest' was filled with random data, or 0 if the random data could
186 * not be generated. The filled-in values should be either truly random, or from
187 * a cryptographically-secure PRNG.
188 *
189 * A correctly functioning RNG function must be set (using uECC_set_rng())
190 * before calling uECC_make_key() or uECC_sign().
191 *
192 * Setting a correctly functioning RNG function improves the resistance to
193 * side-channel attacks for uECC_shared_secret().
194 *
195 * A correct RNG function is set by default. If you are building on another
196 * POSIX-compliant system that supports /dev/random or /dev/urandom, you can
197 * define uECC_POSIX to use the predefined RNG.
198 */
199typedef int(*uECC_RNG_Function)(uint8_t *dest, unsigned int size);
200
201/*
202 * @brief Set the function that will be used to generate random bytes. The RNG
203 * function should return 1 if the random data was generated, or 0 if the random
204 * data could not be generated.
205 *
206 * @note On platforms where there is no predefined RNG function, this must be
207 * called before uECC_make_key() or uECC_sign() are used.
208 *
209 * @param rng_function IN -- function that will be used to generate random bytes
210 */
211void uECC_set_rng(uECC_RNG_Function rng_function);
212
213/*
214 * @brief provides current uECC_RNG_Function.
215 * @return Returns the function that will be used to generate random bytes.
216 */
217uECC_RNG_Function uECC_get_rng(void);
218
219/*
220 * @brief computes the size of a private key for the curve in bytes.
221 * @param curve IN -- elliptic curve
222 * @return size of a private key for the curve in bytes.
223 */
224int uECC_curve_private_key_size(uECC_Curve curve);
225
226/*
227 * @brief computes the size of a public key for the curve in bytes.
228 * @param curve IN -- elliptic curve
229 * @return the size of a public key for the curve in bytes.
230 */
231int uECC_curve_public_key_size(uECC_Curve curve);
232
233/*
234 * @brief Compute the corresponding public key for a private key.
235 * @param private_key IN -- The private key to compute the public key for
236 * @param public_key OUT -- Will be filled in with the corresponding public key
237 * @param curve
238 * @return Returns 1 if key was computed successfully, 0 if an error occurred.
239 */
240int uECC_compute_public_key(const uint8_t *private_key,
241 uint8_t *public_key, uECC_Curve curve);
242
243/*
244 * @brief Compute public-key.
245 * @return corresponding public-key.
246 * @param result OUT -- public-key
247 * @param private_key IN -- private-key
248 * @param curve IN -- elliptic curve
249 */
250uECC_word_t EccPoint_compute_public_key(uECC_word_t *result,
251 uECC_word_t *private_key, uECC_Curve curve);
252
253/*
Manuel Pégourié-Gonnardef238282019-11-04 11:19:30 +0100254 * @brief Point multiplication algorithm using Montgomery's ladder with co-Z
255 * coordinates. See http://eprint.iacr.org/2011/338.pdf.
256 * Uses scalar regularization and coordinate randomization (if a global RNG
257 * function is set) in order to protect against some side channel attacks.
258 * @note Result may overlap point.
259 * @param result OUT -- returns scalar*point
260 * @param point IN -- elliptic curve point
261 * @param scalar IN -- scalar
262 * @param curve IN -- elliptic curve
263 */
264int EccPoint_mult_safer(uECC_word_t * result, const uECC_word_t * point,
265 const uECC_word_t * scalar, uECC_Curve curve);
266
267/*
Jarno Lamsa18987a42019-04-24 15:40:43 +0300268 * @brief Constant-time comparison to zero - secure way to compare long integers
269 * @param vli IN -- very long integer
270 * @param num_words IN -- number of words in the vli
271 * @return 1 if vli == 0, 0 otherwise.
272 */
Manuel Pégourié-Gonnardf3899fc2019-11-04 12:44:43 +0100273uECC_word_t uECC_vli_isZero(const uECC_word_t *vli);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300274
275/*
276 * @brief Check if 'point' is the point at infinity
277 * @param point IN -- elliptic curve point
278 * @param curve IN -- elliptic curve
279 * @return if 'point' is the point at infinity, 0 otherwise.
280 */
281uECC_word_t EccPoint_isZero(const uECC_word_t *point, uECC_Curve curve);
282
283/*
284 * @brief computes the sign of left - right, in constant time.
285 * @param left IN -- left term to be compared
286 * @param right IN -- right term to be compared
287 * @param num_words IN -- number of words
288 * @return the sign of left - right
289 */
Manuel Pégourié-Gonnard2cb3eea2019-11-04 14:43:35 +0100290cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300291
292/*
293 * @brief computes sign of left - right, not in constant time.
294 * @note should not be used if inputs are part of a secret
295 * @param left IN -- left term to be compared
296 * @param right IN -- right term to be compared
297 * @param num_words IN -- number of words
298 * @return the sign of left - right
299 */
Manuel Pégourié-Gonnarda7521912019-11-04 14:31:35 +0100300cmpresult_t uECC_vli_cmp_unsafe(const uECC_word_t *left, const uECC_word_t *right);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300301
302/*
303 * @brief Computes result = (left - right) % mod.
304 * @note Assumes that (left < mod) and (right < mod), and that result does not
305 * overlap mod.
306 * @param result OUT -- (left - right) % mod
307 * @param left IN -- leftright term in modular subtraction
308 * @param right IN -- right term in modular subtraction
309 * @param mod IN -- mod
310 * @param num_words IN -- number of words
311 */
312void uECC_vli_modSub(uECC_word_t *result, const uECC_word_t *left,
Manuel Pégourié-Gonnard1b0875d2019-11-04 14:50:54 +0100313 const uECC_word_t *right, const uECC_word_t *mod);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300314
315/*
316 * @brief Computes P' = (x1', y1', Z3), P + Q = (x3, y3, Z3) or
317 * P => P', Q => P + Q
318 * @note assumes Input P = (x1, y1, Z), Q = (x2, y2, Z)
319 * @param X1 IN -- x coordinate of P
320 * @param Y1 IN -- y coordinate of P
321 * @param X2 IN -- x coordinate of Q
322 * @param Y2 IN -- y coordinate of Q
323 * @param curve IN -- elliptic curve
324 */
325void XYcZ_add(uECC_word_t * X1, uECC_word_t * Y1, uECC_word_t * X2,
326 uECC_word_t * Y2, uECC_Curve curve);
327
328/*
329 * @brief Computes (x1 * z^2, y1 * z^3)
330 * @param X1 IN -- previous x1 coordinate
331 * @param Y1 IN -- previous y1 coordinate
332 * @param Z IN -- z value
333 * @param curve IN -- elliptic curve
334 */
Manuel Pégourié-Gonnardc3ec14c2019-11-04 12:12:00 +0100335void apply_z(uECC_word_t * X1, uECC_word_t * Y1, const uECC_word_t * const Z);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300336
337/*
338 * @brief Check if bit is set.
339 * @return Returns nonzero if bit 'bit' of vli is set.
340 * @warning It is assumed that the value provided in 'bit' is within the
341 * boundaries of the word-array 'vli'.
342 * @note The bit ordering layout assumed for vli is: {31, 30, ..., 0},
343 * {63, 62, ..., 32}, {95, 94, ..., 64}, {127, 126,..., 96} for a vli consisting
344 * of 4 uECC_word_t elements.
345 */
346uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit);
347
348/*
349 * @brief Computes result = product % mod, where product is 2N words long.
350 * @param result OUT -- product % mod
351 * @param mod IN -- module
352 * @param num_words IN -- number of words
353 * @warning Currently only designed to work for curve_p or curve_n.
354 */
355void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product,
Manuel Pégourié-Gonnard10349e42019-11-04 14:57:53 +0100356 const uECC_word_t *mod);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300357
358/*
359 * @brief Computes modular product (using curve->mmod_fast)
360 * @param result OUT -- (left * right) mod % curve_p
361 * @param left IN -- left term in product
362 * @param right IN -- right term in product
363 * @param curve IN -- elliptic curve
364 */
365void uECC_vli_modMult_fast(uECC_word_t *result, const uECC_word_t *left,
Manuel Pégourié-Gonnardc3ec14c2019-11-04 12:12:00 +0100366 const uECC_word_t *right);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300367
368/*
369 * @brief Computes result = left - right.
370 * @note Can modify in place.
371 * @param result OUT -- left - right
372 * @param left IN -- left term in subtraction
373 * @param right IN -- right term in subtraction
374 * @param num_words IN -- number of words
375 * @return borrow
376 */
377uECC_word_t uECC_vli_sub(uECC_word_t *result, const uECC_word_t *left,
Manuel Pégourié-Gonnard129b42e2019-11-04 14:41:45 +0100378 const uECC_word_t *right);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300379
380/*
381 * @brief Constant-time comparison function(secure way to compare long ints)
382 * @param left IN -- left term in comparison
383 * @param right IN -- right term in comparison
384 * @param num_words IN -- number of words
Manuel Pégourié-Gonnard2b6312b2019-11-06 10:42:02 +0100385 * @return Returns 0 if left == right, non-zero otherwise.
Jarno Lamsa18987a42019-04-24 15:40:43 +0300386 */
Manuel Pégourié-Gonnard2eca3d32019-11-04 14:33:09 +0100387uECC_word_t uECC_vli_equal(const uECC_word_t *left, const uECC_word_t *right);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300388
389/*
390 * @brief Computes (left * right) % mod
391 * @param result OUT -- (left * right) % mod
392 * @param left IN -- left term in product
393 * @param right IN -- right term in product
394 * @param mod IN -- mod
395 * @param num_words IN -- number of words
396 */
397void uECC_vli_modMult(uECC_word_t *result, const uECC_word_t *left,
Manuel Pégourié-Gonnard3e20adf2019-11-04 15:00:43 +0100398 const uECC_word_t *right, const uECC_word_t *mod);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300399
400/*
401 * @brief Computes (1 / input) % mod
402 * @note All VLIs are the same size.
403 * @note See "Euclid's GCD to Montgomery Multiplication to the Great Divide"
404 * @param result OUT -- (1 / input) % mod
405 * @param input IN -- value to be modular inverted
406 * @param mod IN -- mod
407 * @param num_words -- number of words
408 */
409void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
Manuel Pégourié-Gonnard91353482019-11-04 15:04:20 +0100410 const uECC_word_t *mod);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300411
412/*
413 * @brief Sets dest = src.
414 * @param dest OUT -- destination buffer
415 * @param src IN -- origin buffer
416 * @param num_words IN -- number of words
417 */
Manuel Pégourié-Gonnardcbbb0f02019-11-04 13:02:04 +0100418void uECC_vli_set(uECC_word_t *dest, const uECC_word_t *src);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300419
420/*
421 * @brief Computes (left + right) % mod.
422 * @note Assumes that (left < mod) and right < mod), and that result does not
423 * overlap mod.
424 * @param result OUT -- (left + right) % mod.
425 * @param left IN -- left term in addition
426 * @param right IN -- right term in addition
427 * @param mod IN -- mod
428 * @param num_words IN -- number of words
429 */
430void uECC_vli_modAdd(uECC_word_t *result, const uECC_word_t *left,
Manuel Pégourié-Gonnard0779be72019-11-04 14:48:22 +0100431 const uECC_word_t *right, const uECC_word_t *mod);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300432
433/*
434 * @brief Counts the number of bits required to represent vli.
435 * @param vli IN -- very long integer
436 * @param max_words IN -- number of words
437 * @return number of bits in given vli
438 */
Manuel Pégourié-Gonnard2bf5a122019-11-04 12:56:59 +0100439bitcount_t uECC_vli_numBits(const uECC_word_t *vli);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300440
441/*
442 * @brief Erases (set to 0) vli
443 * @param vli IN -- very long integer
444 * @param num_words IN -- number of words
445 */
Manuel Pégourié-Gonnard94e48492019-11-04 12:47:28 +0100446void uECC_vli_clear(uECC_word_t *vli);
Jarno Lamsa18987a42019-04-24 15:40:43 +0300447
448/*
449 * @brief check if it is a valid point in the curve
450 * @param point IN -- point to be checked
451 * @param curve IN -- elliptic curve
452 * @return 0 if point is valid
453 * @exception returns -1 if it is a point at infinity
454 * @exception returns -2 if x or y is smaller than p,
455 * @exception returns -3 if y^2 != x^3 + ax + b.
456 */
457int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve);
458
459/*
460 * @brief Check if a public key is valid.
461 * @param public_key IN -- The public key to be checked.
462 * @return returns 0 if the public key is valid
463 * @exception returns -1 if it is a point at infinity
464 * @exception returns -2 if x or y is smaller than p,
465 * @exception returns -3 if y^2 != x^3 + ax + b.
466 * @exception returns -4 if public key is the group generator.
467 *
468 * @note Note that you are not required to check for a valid public key before
469 * using any other uECC functions. However, you may wish to avoid spending CPU
470 * time computing a shared secret or verifying a signature using an invalid
471 * public key.
472 */
473int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve);
474
475 /*
476 * @brief Converts an integer in uECC native format to big-endian bytes.
477 * @param bytes OUT -- bytes representation
478 * @param num_bytes IN -- number of bytes
479 * @param native IN -- uECC native representation
480 */
481void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes,
482 const unsigned int *native);
483
484/*
485 * @brief Converts big-endian bytes to an integer in uECC native format.
486 * @param native OUT -- uECC native representation
487 * @param bytes IN -- bytes representation
488 * @param num_bytes IN -- number of bytes
489 */
490void uECC_vli_bytesToNative(unsigned int *native, const uint8_t *bytes,
491 int num_bytes);
492
493#ifdef __cplusplus
494}
495#endif
496
497#endif /* __TC_UECC_H__ */
Manuel Pégourié-Gonnardafdc1b52019-05-09 11:24:11 +0200498#endif /* MBEDTLS_USE_TINYCRYPT */