curve25519.h
Go to the documentation of this file.
1 /**
2  * @file curve25519.h
3  * @brief Curve25519 elliptic curve (constant-time implementation)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.0
29  **/
30 
31 #ifndef _CURVE25519_H
32 #define _CURVE25519_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Speed optimization level
38 #ifndef CURVE25519_SPEED_OPTIMIZATION_LEVEL
39  #define CURVE25519_SPEED_OPTIMIZATION_LEVEL 2
40 #elif (CURVE25519_SPEED_OPTIMIZATION_LEVEL < 0)
41  #error CURVE25519_SPEED_OPTIMIZATION_LEVEL parameter is not valid
42 #endif
43 
44 //Length of the elliptic curve
45 #define CURVE25519_BIT_LEN 255
46 #define CURVE25519_BYTE_LEN 32
47 #define CURVE25519_WORD_LEN 8
48 
49 //A24 constant
50 #define CURVE25519_A24 121666
51 
52 //C++ guard
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 //Curve25519 related functions
58 void curve25519SetInt(int32_t *a, int32_t b);
59 
60 void curve25519Add(int32_t *r, const int32_t *a, const int32_t *b);
61 void curve25519AddInt(int32_t *r, const int32_t *a, int32_t b);
62 
63 void curve25519Sub(int32_t *r, const int32_t *a, const int32_t *b);
64 void curve25519SubInt(int32_t *r, const int32_t *a, int32_t b);
65 
66 void curve25519Mul(int32_t *r, const int32_t *a, const int32_t *b);
67 void curve25519MulInt(int32_t *r, const int32_t *a, int32_t b);
68 void curve25519Sqr(int32_t *r, const int32_t *a);
69 void curve25519Pwr2(int32_t *r, const int32_t *a, uint_t n);
70 
71 void curve25519Inv(int32_t *r, const int32_t *a);
72 
73 uint32_t curve25519Sqrt(int32_t *r, const int32_t *a, const int32_t *b);
74 
75 void curve25519Canonicalize(int32_t *r, const int32_t *a);
76 
77 void curve25519Copy(int32_t *a, const int32_t *b);
78 void curve25519Swap(int32_t *a, int32_t *b, uint32_t c);
79 
80 void curve25519Select(int32_t *r, const int32_t *a, const int32_t *b,
81  uint32_t c);
82 
83 uint32_t curve25519Comp(const int32_t *a, const int32_t *b);
84 
85 void curve25519Import(int32_t *a, const uint8_t *data);
86 void curve25519Export(int32_t *a, uint8_t *data);
87 
88 //C++ guard
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif
uint8_t b
Definition: nbns_common.h:104
void curve25519Import(int32_t *a, const uint8_t *data)
Import an octet string.
Definition: curve25519.c:896
uint8_t a
Definition: ndp.h:411
void curve25519Export(int32_t *a, uint8_t *data)
Export an octet string.
Definition: curve25519.c:917
uint8_t data[]
Definition: ethernet.h:222
void curve25519Sqr(int32_t *r, const int32_t *a)
Modular squaring.
Definition: curve25519.c:571
void curve25519Mul(int32_t *r, const int32_t *a, const int32_t *b)
Modular multiplication.
Definition: curve25519.c:267
void curve25519Add(int32_t *r, const int32_t *a, const int32_t *b)
Modular addition.
Definition: curve25519.c:79
uint8_t r
Definition: ndp.h:346
void curve25519Canonicalize(int32_t *r, const int32_t *a)
Reduce non-canonical value.
Definition: curve25519.c:749
void curve25519Pwr2(int32_t *r, const int32_t *a, uint_t n)
Raise an integer to power 2^n.
Definition: curve25519.c:585
General definitions for cryptographic algorithms.
uint32_t curve25519Sqrt(int32_t *r, const int32_t *a, const int32_t *b)
Compute the square root of (A / B) modulo p.
Definition: curve25519.c:656
void curve25519Copy(int32_t *a, const int32_t *b)
Copy an integer.
Definition: curve25519.c:798
void curve25519Sub(int32_t *r, const int32_t *a, const int32_t *b)
Modular subtraction.
Definition: curve25519.c:173
void curve25519SubInt(int32_t *r, const int32_t *a, int32_t b)
Modular subtraction.
Definition: curve25519.c:238
void curve25519AddInt(int32_t *r, const int32_t *a, int32_t b)
Modular addition.
Definition: curve25519.c:144
uint8_t n
void curve25519MulInt(int32_t *r, const int32_t *a, int32_t b)
Modular multiplication.
Definition: curve25519.c:499
void curve25519SetInt(int32_t *a, int32_t b)
Set integer value.
Definition: curve25519.c:57
void curve25519Inv(int32_t *r, const int32_t *a)
Modular multiplicative inverse.
Definition: curve25519.c:606
void curve25519Swap(int32_t *a, int32_t *b, uint32_t c)
Conditional swap.
Definition: curve25519.c:817
unsigned int uint_t
Definition: compiler_port.h:57
void curve25519Select(int32_t *r, const int32_t *a, const int32_t *b, uint32_t c)
Select an integer.
Definition: curve25519.c:845
uint32_t curve25519Comp(const int32_t *a, const int32_t *b)
Compare integers.
Definition: curve25519.c:870
uint8_t c
Definition: ndp.h:514