ed448.h
Go to the documentation of this file.
1 /**
2  * @file ed448.h
3  * @brief Ed448 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 _ED448_H
30 #define _ED448_H
31 
32 //Dependencies
33 #include "core/crypto.h"
34 #include "xof/shake256.h"
35 
36 //Length of EdDSA private keys
37 #define ED448_PRIVATE_KEY_LEN 57
38 //Length of EdDSA public keys
39 #define ED448_PUBLIC_KEY_LEN 57
40 //Length of EdDSA signatures
41 #define ED448_SIGNATURE_LEN 114
42 
43 //Ed448ph flag
44 #define ED448_PH_FLAG 1
45 //Prehash function output size
46 #define ED448_PH_SIZE 64
47 
48 //C++ guard
49 #ifdef __cplusplus
50  extern "C" {
51 #endif
52 
53 
54 /**
55  * @brief Projective point representation
56  **/
57 
58 typedef struct
59 {
60  uint32_t x[14];
61  uint32_t y[14];
62  uint32_t z[14];
63 } Ed448Point;
64 
65 
66 /**
67  * @brief Ed448 working state
68  **/
69 
70 typedef struct
71 {
73  uint8_t k[114];
74  uint8_t p[57];
75  uint8_t r[57];
76  uint8_t s[57];
77  uint8_t t[57];
83  uint32_t a[14];
84  uint32_t b[14];
85  uint32_t c[14];
86  uint32_t d[14];
87  uint32_t e[14];
88  uint32_t f[14];
89  uint32_t g[14];
90 } Ed448State;
91 
92 
93 //Ed448 related functions
94 error_t ed448GenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext,
95  uint8_t *privateKey, uint8_t *publicKey);
96 
97 error_t ed448GenerateSignature(const uint8_t *privateKey,
98  const uint8_t *publicKey, const void *message, size_t messageLen,
99  const void *context, uint8_t contextLen, uint8_t flag, uint8_t *signature);
100 
101 error_t ed448VerifySignature(const uint8_t *publicKey, const void *message,
102  size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag,
103  const uint8_t *signature);
104 
105 void ed448Mul(Ed448State *state, Ed448Point *r, const uint8_t *k,
106  const Ed448Point *p);
107 
108 void ed448Add(Ed448State *state, Ed448Point *r, const Ed448Point *p,
109  const Ed448Point *q);
110 
111 void ed448Double(Ed448State *state, Ed448Point *r, const Ed448Point *p);
112 
113 void ed448Encode(Ed448Point *p, uint8_t *data);
114 uint32_t ed448Decode(Ed448Point *p, const uint8_t *data);
115 
116 void ed448RedInt(uint8_t *r, const uint8_t *a);
117 
118 void ed448AddInt(uint8_t *r, const uint8_t *a, const uint8_t *b, uint_t n);
119 uint8_t ed448SubInt(uint8_t *r, const uint8_t *a, const uint8_t *b, uint_t n);
120 
121 void ed448MulInt(uint8_t *rl, uint8_t *rh, const uint8_t *a,
122  const uint8_t *b, uint_t n);
123 
124 void ed448CopyInt(uint8_t *a, const uint8_t *b, uint_t n);
125 
126 void ed448SelectInt(uint8_t *r, const uint8_t *a, const uint8_t *b,
127  uint8_t c, uint_t n);
128 
129 uint8_t ed448CompInt(const uint8_t *a, const uint8_t *b, uint_t n);
130 
131 //C++ guard
132 #ifdef __cplusplus
133  }
134 #endif
135 
136 #endif
void ed448Add(Ed448State *state, Ed448Point *r, const Ed448Point *p, const Ed448Point *q)
Point addition.
Definition: ed448.c:404
void ed448Mul(Ed448State *state, Ed448Point *r, const uint8_t *k, const Ed448Point *p)
Scalar multiplication on Ed448 curve.
Definition: ed448.c:361
error_t ed448GenerateSignature(const uint8_t *privateKey, const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, uint8_t *signature)
EdDSA signature generation.
Definition: ed448.c:168
uint8_t ed448CompInt(const uint8_t *a, const uint8_t *b, uint_t n)
Compare integers.
Definition: ed448.c:779
void ed448MulInt(uint8_t *rl, uint8_t *rh, const uint8_t *a, const uint8_t *b, uint_t n)
Multiplication of two integers.
Definition: ed448.c:668
uint8_t c
Definition: ndp.h:510
uint32_t ed448Decode(Ed448Point *p, const uint8_t *data)
Point decoding.
Definition: ed448.c:505
uint8_t p
Definition: ndp.h:295
uint8_t message[]
Definition: chap.h:150
General definitions for cryptographic algorithms.
Shake256Context shake256Context
Definition: ed448.h:72
uint16_t z
Definition: dns_common.h:173
Ed448Point u
Definition: ed448.h:81
uint8_t a
Definition: ndp.h:407
void ed448Encode(Ed448Point *p, uint8_t *data)
Point encoding.
Definition: ed448.c:480
uint8_t ed448SubInt(uint8_t *r, const uint8_t *a, const uint8_t *b, uint_t n)
Subtraction of two integers.
Definition: ed448.c:640
Keccak context.
Definition: keccak.h:105
void ed448AddInt(uint8_t *r, const uint8_t *a, const uint8_t *b, uint_t n)
Addition of two integers.
Definition: ed448.c:615
Ed448Point sb
Definition: ed448.h:80
error_t ed448GenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *privateKey, uint8_t *publicKey)
EdDSA key pair generation.
Definition: ed448.c:101
uint8_t signature
Definition: tls.h:1364
void ed448RedInt(uint8_t *r, const uint8_t *a)
Reduce an integer modulo L.
Definition: ed448.c:580
uint8_t s
void ed448SelectInt(uint8_t *r, const uint8_t *a, const uint8_t *b, uint8_t c, uint_t n)
Select an integer.
Definition: ed448.c:753
error_t
Error codes.
Definition: error.h:40
Ed448 working state.
Definition: ed448.h:70
unsigned int uint_t
Definition: compiler_port.h:43
void ed448Double(Ed448State *state, Ed448Point *r, const Ed448Point *p)
Point doubling.
Definition: ed448.c:447
uint8_t data[]
Definition: dtls_misc.h:167
Common interface for pseudo-random number generators.
Definition: crypto.h:1091
uint32_t r
Definition: ndp.h:342
Ed448Point v
Definition: ed448.h:82
Ed448Point rb
Definition: ed448.h:79
SHAKE256 extendable-output function (XOF)
void ed448CopyInt(uint8_t *a, const uint8_t *b, uint_t n)
Copy an integer.
Definition: ed448.c:732
uint8_t n
Projective point representation.
Definition: ed448.h:58
Ed448Point ka
Definition: ed448.h:78
error_t ed448VerifySignature(const uint8_t *publicKey, const void *message, size_t messageLen, const void *context, uint8_t contextLen, uint8_t flag, const uint8_t *signature)
EdDSA signature verification.
Definition: ed448.c:282
uint8_t b[6]
Definition: dtls_misc.h:130