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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneCrypto Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _CURVE25519_H
30 #define _CURVE25519_H
31 
32 //Dependencies
33 #include "core/crypto.h"
34 
35 //Length of the elliptic curve
36 #define CURVE25519_BIT_LEN 255
37 #define CURVE25519_BYTE_LEN 32
38 #define CURVE25519_WORD_LEN 8
39 
40 //A24 constant
41 #define CURVE25519_A24 121666
42 
43 //C++ guard
44 #ifdef __cplusplus
45  extern "C" {
46 #endif
47 
48 //Curve25519 related functions
49 void curve25519SetInt(uint32_t *a, uint32_t b);
50 void curve25519Add(uint32_t *r, const uint32_t *a, const uint32_t *b);
51 void curve25519AddInt(uint32_t *r, const uint32_t *a, uint32_t b);
52 void curve25519Sub(uint32_t *r, const uint32_t *a, const uint32_t *b);
53 void curve25519SubInt(uint32_t *r, const uint32_t *a, uint32_t b);
54 void curve25519Mul(uint32_t *r, const uint32_t *a, const uint32_t *b);
55 void curve25519MulInt(uint32_t *r, const uint32_t *a, uint32_t b);
56 void curve25519Red(uint32_t *r, const uint32_t *a);
57 void curve25519Sqr(uint32_t *r, const uint32_t *a);
58 void curve25519Pwr2(uint32_t *r, const uint32_t *a, uint_t n);
59 void curve25519Inv(uint32_t *r, const uint32_t *a);
60 
61 uint32_t curve25519Sqrt(uint32_t *r, const uint32_t *a, const uint32_t *b);
62 
63 void curve25519Copy(uint32_t *a, const uint32_t *b);
64 void curve25519Swap(uint32_t *a, uint32_t *b, uint32_t c);
65 
66 void curve25519Select(uint32_t *r, const uint32_t *a, const uint32_t *b,
67  uint32_t c);
68 
69 uint32_t curve25519Comp(const uint32_t *a, const uint32_t *b);
70 
71 void curve25519Import(uint32_t *a, const uint8_t *data);
72 void curve25519Export(uint32_t *a, uint8_t *data);
73 
74 //C++ guard
75 #ifdef __cplusplus
76  }
77 #endif
78 
79 #endif
void curve25519Mul(uint32_t *r, const uint32_t *a, const uint32_t *b)
Modular multiplication.
Definition: curve25519.c:189
uint32_t curve25519Comp(const uint32_t *a, const uint32_t *b)
Compare integers.
Definition: curve25519.c:585
uint8_t c
Definition: ndp.h:510
void curve25519Add(uint32_t *r, const uint32_t *a, const uint32_t *b)
Modular addition.
Definition: curve25519.c:77
void curve25519Inv(uint32_t *r, const uint32_t *a)
Modular multiplicative inverse.
Definition: curve25519.c:378
General definitions for cryptographic algorithms.
void curve25519Export(uint32_t *a, uint8_t *data)
Export an octet string.
Definition: curve25519.c:632
void curve25519Sqr(uint32_t *r, const uint32_t *a)
Modular squaring.
Definition: curve25519.c:315
uint8_t a
Definition: ndp.h:407
void curve25519Import(uint32_t *a, const uint8_t *data)
Import an octet string.
Definition: curve25519.c:611
void curve25519MulInt(uint32_t *r, const uint32_t *a, uint32_t b)
Modular multiplication.
Definition: curve25519.c:275
void curve25519Pwr2(uint32_t *r, const uint32_t *a, uint_t n)
Raise an integer to power 2^n.
Definition: curve25519.c:329
void curve25519Select(uint32_t *r, const uint32_t *a, const uint32_t *b, uint32_t c)
Select an integer.
Definition: curve25519.c:560
void curve25519SubInt(uint32_t *r, const uint32_t *a, uint32_t b)
Modular subtraction.
Definition: curve25519.c:157
void curve25519Copy(uint32_t *a, const uint32_t *b)
Copy an integer.
Definition: curve25519.c:513
void curve25519SetInt(uint32_t *a, uint32_t b)
Set integer value.
Definition: curve25519.c:55
void curve25519Red(uint32_t *r, const uint32_t *a)
Modular reduction.
Definition: curve25519.c:350
void curve25519Swap(uint32_t *a, uint32_t *b, uint32_t c)
Conditional swap.
Definition: curve25519.c:532
unsigned int uint_t
Definition: compiler_port.h:43
void curve25519Sub(uint32_t *r, const uint32_t *a, const uint32_t *b)
Modular subtraction.
Definition: curve25519.c:128
uint8_t data[]
Definition: dtls_misc.h:167
uint32_t r
Definition: ndp.h:342
void curve25519AddInt(uint32_t *r, const uint32_t *a, uint32_t b)
Modular addition.
Definition: curve25519.c:103
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:428
uint8_t n
uint8_t b[6]
Definition: dtls_misc.h:130