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-2020 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 1.9.8
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(uint32_t *a, uint32_t b);
52 void curve25519Add(uint32_t *r, const uint32_t *a, const uint32_t *b);
53 void curve25519AddInt(uint32_t *r, const uint32_t *a, uint32_t b);
54 void curve25519Sub(uint32_t *r, const uint32_t *a, const uint32_t *b);
55 void curve25519SubInt(uint32_t *r, const uint32_t *a, uint32_t b);
56 void curve25519Mul(uint32_t *r, const uint32_t *a, const uint32_t *b);
57 void curve25519MulInt(uint32_t *r, const uint32_t *a, uint32_t b);
58 void curve25519Red(uint32_t *r, const uint32_t *a);
59 void curve25519Sqr(uint32_t *r, const uint32_t *a);
60 void curve25519Pwr2(uint32_t *r, const uint32_t *a, uint_t n);
61 void curve25519Inv(uint32_t *r, const uint32_t *a);
62 
63 uint32_t curve25519Sqrt(uint32_t *r, const uint32_t *a, const uint32_t *b);
64 
65 void curve25519Copy(uint32_t *a, const uint32_t *b);
66 void curve25519Swap(uint32_t *a, uint32_t *b, uint32_t c);
67 
68 void curve25519Select(uint32_t *r, const uint32_t *a, const uint32_t *b,
69  uint32_t c);
70 
71 uint32_t curve25519Comp(const uint32_t *a, const uint32_t *b);
72 
73 void curve25519Import(uint32_t *a, const uint8_t *data);
74 void curve25519Export(uint32_t *a, uint8_t *data);
75 
76 //C++ guard
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif
void curve25519Sub(uint32_t *r, const uint32_t *a, const uint32_t *b)
Modular subtraction.
Definition: curve25519.c:130
uint8_t a
Definition: ndp.h:410
uint8_t data[]
Definition: ethernet.h:209
void curve25519Mul(uint32_t *r, const uint32_t *a, const uint32_t *b)
Modular multiplication.
Definition: curve25519.c:191
void curve25519Inv(uint32_t *r, const uint32_t *a)
Modular multiplicative inverse.
Definition: curve25519.c:380
void curve25519Select(uint32_t *r, const uint32_t *a, const uint32_t *b, uint32_t c)
Select an integer.
Definition: curve25519.c:562
uint32_t r
Definition: ndp.h:345
uint32_t curve25519Sqrt(uint32_t *r, const uint32_t *a, const uint32_t *b)
Compute the square root of (A / B) modulo p.
Definition: curve25519.c:430
void curve25519Export(uint32_t *a, uint8_t *data)
Export an octet string.
Definition: curve25519.c:634
General definitions for cryptographic algorithms.
void curve25519Import(uint32_t *a, const uint8_t *data)
Import an octet string.
Definition: curve25519.c:613
void curve25519Red(uint32_t *r, const uint32_t *a)
Modular reduction.
Definition: curve25519.c:352
uint8_t b[6]
Definition: ethernet.h:179
void curve25519Pwr2(uint32_t *r, const uint32_t *a, uint_t n)
Raise an integer to power 2^n.
Definition: curve25519.c:331
void curve25519Add(uint32_t *r, const uint32_t *a, const uint32_t *b)
Modular addition.
Definition: curve25519.c:79
uint8_t n
void curve25519Swap(uint32_t *a, uint32_t *b, uint32_t c)
Conditional swap.
Definition: curve25519.c:534
void curve25519SubInt(uint32_t *r, const uint32_t *a, uint32_t b)
Modular subtraction.
Definition: curve25519.c:159
void curve25519SetInt(uint32_t *a, uint32_t b)
Set integer value.
Definition: curve25519.c:57
void curve25519AddInt(uint32_t *r, const uint32_t *a, uint32_t b)
Modular addition.
Definition: curve25519.c:105
unsigned int uint_t
Definition: compiler_port.h:45
void curve25519Copy(uint32_t *a, const uint32_t *b)
Copy an integer.
Definition: curve25519.c:515
void curve25519MulInt(uint32_t *r, const uint32_t *a, uint32_t b)
Modular multiplication.
Definition: curve25519.c:277
uint32_t curve25519Comp(const uint32_t *a, const uint32_t *b)
Compare integers.
Definition: curve25519.c:587
uint8_t c
Definition: ndp.h:513
void curve25519Sqr(uint32_t *r, const uint32_t *a)
Modular squaring.
Definition: curve25519.c:317