curve25519.h
Go to the documentation of this file.
1 /**
2  * @file curve25519.h
3  * @brief Curve25519 elliptic curve
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.6
29  **/
30 
31 #ifndef _CURVE25519_H
32 #define _CURVE25519_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Length of the elliptic curve
38 #define CURVE25519_BIT_LEN 255
39 #define CURVE25519_BYTE_LEN 32
40 #define CURVE25519_WORD_LEN 8
41 
42 //A24 constant
43 #define CURVE25519_A24 121666
44 
45 //C++ guard
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 //Curve25519 related functions
51 void curve25519SetInt(int32_t *a, int32_t b);
52 
53 void curve25519Add(int32_t *r, const int32_t *a, const int32_t *b);
54 void curve25519AddInt(int32_t *r, const int32_t *a, int32_t b);
55 
56 void curve25519Sub(int32_t *r, const int32_t *a, const int32_t *b);
57 void curve25519SubInt(int32_t *r, const int32_t *a, int32_t b);
58 
59 void curve25519Mul(int32_t *r, const int32_t *a, const int32_t *b);
60 void curve25519MulInt(int32_t *r, const int32_t *a, int32_t b);
61 void curve25519Sqr(int32_t *r, const int32_t *a);
62 void curve25519Pwr2(int32_t *r, const int32_t *a, uint_t n);
63 
64 void curve25519Inv(int32_t *r, const int32_t *a);
65 
66 uint32_t curve25519Sqrt(int32_t *r, const int32_t *a, const int32_t *b);
67 
68 void curve25519Canonicalize(int32_t *r, const int32_t *a);
69 
70 void curve25519Copy(int32_t *a, const int32_t *b);
71 void curve25519Swap(int32_t *a, int32_t *b, uint32_t c);
72 
73 void curve25519Select(int32_t *r, const int32_t *a, const int32_t *b,
74  uint32_t c);
75 
76 uint32_t curve25519Comp(const int32_t *a, const int32_t *b);
77 
78 void curve25519Import(int32_t *a, const uint8_t *data);
79 void curve25519Export(int32_t *a, uint8_t *data);
80 
81 //C++ guard
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif
uint8_t b
Definition: nbns_common.h:122
void curve25519Import(int32_t *a, const uint8_t *data)
Import an octet string.
Definition: curve25519.c:777
uint8_t a
Definition: ndp.h:411
void curve25519Export(int32_t *a, uint8_t *data)
Export an octet string.
Definition: curve25519.c:798
uint8_t data[]
Definition: ethernet.h:224
void curve25519Sqr(int32_t *r, const int32_t *a)
Modular squaring.
Definition: curve25519.c:452
void curve25519Mul(int32_t *r, const int32_t *a, const int32_t *b)
Modular multiplication.
Definition: curve25519.c:227
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:630
void curve25519Pwr2(int32_t *r, const int32_t *a, uint_t n)
Raise an integer to power 2^n.
Definition: curve25519.c:466
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:537
void curve25519Copy(int32_t *a, const int32_t *b)
Copy an integer.
Definition: curve25519.c:679
void curve25519Sub(int32_t *r, const int32_t *a, const int32_t *b)
Modular subtraction.
Definition: curve25519.c:153
void curve25519SubInt(int32_t *r, const int32_t *a, int32_t b)
Modular subtraction.
Definition: curve25519.c:198
void curve25519AddInt(int32_t *r, const int32_t *a, int32_t b)
Modular addition.
Definition: curve25519.c:124
uint8_t n
void curve25519MulInt(int32_t *r, const int32_t *a, int32_t b)
Modular multiplication.
Definition: curve25519.c:404
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:487
void curve25519Swap(int32_t *a, int32_t *b, uint32_t c)
Conditional swap.
Definition: curve25519.c:698
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:726
uint32_t curve25519Comp(const int32_t *a, const int32_t *b)
Compare integers.
Definition: curve25519.c:751
uint8_t c
Definition: ndp.h:514