curve25519.h File Reference

Curve25519 elliptic curve (constant-time implementation) More...

#include "core/crypto.h"

Go to the source code of this file.

Macros

#define CURVE25519_BIT_LEN   255
 
#define CURVE25519_BYTE_LEN   32
 
#define CURVE25519_WORD_LEN   8
 
#define CURVE25519_A24   121666
 

Functions

void curve25519SetInt (uint32_t *a, uint32_t b)
 Set integer value. More...
 
void curve25519Add (uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular addition. More...
 
void curve25519AddInt (uint32_t *r, const uint32_t *a, uint32_t b)
 Modular addition. More...
 
void curve25519Sub (uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular subtraction. More...
 
void curve25519SubInt (uint32_t *r, const uint32_t *a, uint32_t b)
 Modular subtraction. More...
 
void curve25519Mul (uint32_t *r, const uint32_t *a, const uint32_t *b)
 Modular multiplication. More...
 
void curve25519MulInt (uint32_t *r, const uint32_t *a, uint32_t b)
 Modular multiplication. More...
 
void curve25519Red (uint32_t *r, const uint32_t *a)
 Modular reduction. More...
 
void curve25519Sqr (uint32_t *r, const uint32_t *a)
 Modular squaring. More...
 
void curve25519Pwr2 (uint32_t *r, const uint32_t *a, uint_t n)
 Raise an integer to power 2^n. More...
 
void curve25519Inv (uint32_t *r, const uint32_t *a)
 Modular multiplicative inverse. More...
 
uint32_t curve25519Sqrt (uint32_t *r, const uint32_t *a, const uint32_t *b)
 Compute the square root of (A / B) modulo p. More...
 
void curve25519Copy (uint32_t *a, const uint32_t *b)
 Copy an integer. More...
 
void curve25519Swap (uint32_t *a, uint32_t *b, uint32_t c)
 Conditional swap. More...
 
void curve25519Select (uint32_t *r, const uint32_t *a, const uint32_t *b, uint32_t c)
 Select an integer. More...
 
uint32_t curve25519Comp (const uint32_t *a, const uint32_t *b)
 Compare integers. More...
 
void curve25519Import (uint32_t *a, const uint8_t *data)
 Import an octet string. More...
 
void curve25519Export (uint32_t *a, uint8_t *data)
 Export an octet string. More...
 

Detailed Description

Curve25519 elliptic curve (constant-time implementation)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCrypto Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file curve25519.h.

Macro Definition Documentation

◆ CURVE25519_A24

#define CURVE25519_A24   121666

Definition at line 41 of file curve25519.h.

◆ CURVE25519_BIT_LEN

#define CURVE25519_BIT_LEN   255

Definition at line 36 of file curve25519.h.

◆ CURVE25519_BYTE_LEN

#define CURVE25519_BYTE_LEN   32

Definition at line 37 of file curve25519.h.

◆ CURVE25519_WORD_LEN

#define CURVE25519_WORD_LEN   8

Definition at line 38 of file curve25519.h.

Function Documentation

◆ curve25519Add()

void curve25519Add ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular addition.

Parameters
[out]rResulting integer R = (A + B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < p

Definition at line 77 of file curve25519.c.

◆ curve25519AddInt()

void curve25519AddInt ( uint32_t *  r,
const uint32_t *  a,
uint32_t  b 
)

Modular addition.

Parameters
[out]rResulting integer R = (A + B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < (2^32 - 1)

Definition at line 103 of file curve25519.c.

◆ curve25519Comp()

uint32_t curve25519Comp ( const uint32_t *  a,
const uint32_t *  b 
)

Compare integers.

Parameters
[in]aPointer to the first integer
[in]bPointer to the second integer
Returns
The function returns 0 if the A = B, else 1

Definition at line 585 of file curve25519.c.

◆ curve25519Copy()

void curve25519Copy ( uint32_t *  a,
const uint32_t *  b 
)

Copy an integer.

Parameters
[out]aPointer to the destination integer
[in]bPointer to the source integer

Definition at line 513 of file curve25519.c.

◆ curve25519Export()

void curve25519Export ( uint32_t *  a,
uint8_t *  data 
)

Export an octet string.

Parameters
[in]aPointer to the integer to be exported
[out]dataOctet string resulting from the conversion

Definition at line 632 of file curve25519.c.

◆ curve25519Import()

void curve25519Import ( uint32_t *  a,
const uint8_t *  data 
)

Import an octet string.

Parameters
[out]aPointer to resulting integer
[in]dataOctet string to be converted

Definition at line 611 of file curve25519.c.

◆ curve25519Inv()

void curve25519Inv ( uint32_t *  r,
const uint32_t *  a 
)

Modular multiplicative inverse.

Parameters
[out]rResulting integer R = A^-1 mod p
[in]aAn integer such as 0 <= A < p

Definition at line 378 of file curve25519.c.

◆ curve25519Mul()

void curve25519Mul ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular multiplication.

Parameters
[out]rResulting integer R = (A * B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < p

Definition at line 189 of file curve25519.c.

◆ curve25519MulInt()

void curve25519MulInt ( uint32_t *  r,
const uint32_t *  a,
uint32_t  b 
)

Modular multiplication.

Parameters
[out]rResulting integer R = (A * B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < (2^32 - 1)

Definition at line 275 of file curve25519.c.

◆ curve25519Pwr2()

void curve25519Pwr2 ( uint32_t *  r,
const uint32_t *  a,
uint_t  n 
)

Raise an integer to power 2^n.

Parameters
[out]rResulting integer R = (A ^ (2^n)) mod p
[in]aAn integer such as 0 <= A < p
[in]nAn integer such as n >= 1

Definition at line 329 of file curve25519.c.

◆ curve25519Red()

void curve25519Red ( uint32_t *  r,
const uint32_t *  a 
)

Modular reduction.

Parameters
[out]rResulting integer R = A mod p
[in]aAn integer such as 0 <= A < (2 * p)

Definition at line 350 of file curve25519.c.

◆ curve25519Select()

void curve25519Select ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b,
uint32_t  c 
)

Select an integer.

Parameters
[out]rPointer to the destination integer
[in]aPointer to the first source integer
[in]bPointer to the second source integer
[in]cCondition variable

Definition at line 560 of file curve25519.c.

◆ curve25519SetInt()

void curve25519SetInt ( uint32_t *  a,
uint32_t  b 
)

Set integer value.

Parameters
[out]aPointer to the integer to be initialized
[in]bInitial value

Definition at line 55 of file curve25519.c.

◆ curve25519Sqr()

void curve25519Sqr ( uint32_t *  r,
const uint32_t *  a 
)

Modular squaring.

Parameters
[out]rResulting integer R = (A ^ 2) mod p
[in]aAn integer such as 0 <= A < p

Definition at line 315 of file curve25519.c.

◆ curve25519Sqrt()

uint32_t curve25519Sqrt ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Compute the square root of (A / B) modulo p.

Parameters
[out]rResulting integer R = (A / B)^(1 / 2) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 < B < p
Returns
The function returns 0 if the square root exists, else 1

Definition at line 428 of file curve25519.c.

◆ curve25519Sub()

void curve25519Sub ( uint32_t *  r,
const uint32_t *  a,
const uint32_t *  b 
)

Modular subtraction.

Parameters
[out]rResulting integer R = (A - B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < p

Definition at line 128 of file curve25519.c.

◆ curve25519SubInt()

void curve25519SubInt ( uint32_t *  r,
const uint32_t *  a,
uint32_t  b 
)

Modular subtraction.

Parameters
[out]rResulting integer R = (A - B) mod p
[in]aAn integer such as 0 <= A < p
[in]bAn integer such as 0 <= B < (2^32 - 1)

Definition at line 157 of file curve25519.c.

◆ curve25519Swap()

void curve25519Swap ( uint32_t *  a,
uint32_t *  b,
uint32_t  c 
)

Conditional swap.

Parameters
[in,out]aPointer to the first integer
[in,out]bPointer to the second integer
[in]cCondition variable

Definition at line 532 of file curve25519.c.