Seperated headers from sources and add a install option
This commit is contained in:
parent
29064b05eb
commit
fb6cfb7633
@ -1,4 +1,5 @@
|
|||||||
project(ed25519)
|
project(ed25519)
|
||||||
|
cmake_minimum_required(VERSION 3.9)
|
||||||
|
|
||||||
set(SOURCE
|
set(SOURCE
|
||||||
src/add_scalar.c
|
src/add_scalar.c
|
||||||
@ -17,3 +18,9 @@ add_library(ed25519 STATIC ${SOURCE})
|
|||||||
|
|
||||||
add_executable(ed25519_test test.c)
|
add_executable(ed25519_test test.c)
|
||||||
target_link_libraries(ed25519_test ed25519)
|
target_link_libraries(ed25519_test ed25519)
|
||||||
|
|
||||||
|
INSTALL(DIRECTORY include/ DESTINATION include/ed25519)
|
||||||
|
INSTALL(TARGETS ed25519
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
)
|
@ -1,7 +1,7 @@
|
|||||||
#include "ed25519.h"
|
#include "../include/ed25519.h"
|
||||||
#include "ge.h"
|
#include "../include/ge.h"
|
||||||
#include "sc.h"
|
#include "../include/sc.h"
|
||||||
#include "sha512.h"
|
#include "../include/sha512.h"
|
||||||
|
|
||||||
|
|
||||||
/* see http://crypto.stackexchange.com/a/6215/4697 */
|
/* see http://crypto.stackexchange.com/a/6215/4697 */
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
#ifndef ED25519_H
|
|
||||||
#define ED25519_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#if defined(ED25519_BUILD_DLL)
|
|
||||||
#define ED25519_DECLSPEC __declspec(dllexport)
|
|
||||||
#elif defined(ED25519_DLL)
|
|
||||||
#define ED25519_DECLSPEC __declspec(dllimport)
|
|
||||||
#else
|
|
||||||
#define ED25519_DECLSPEC
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define ED25519_DECLSPEC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef ED25519_NO_SEED
|
|
||||||
int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
|
|
||||||
void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
|
|
||||||
int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
|
|
||||||
void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
|
|
||||||
void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
4
src/fe.c
4
src/fe.c
@ -1,5 +1,5 @@
|
|||||||
#include "fixedint.h"
|
#include "../include/fixedint.h"
|
||||||
#include "fe.h"
|
#include "../include/fe.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
41
src/fe.h
41
src/fe.h
@ -1,41 +0,0 @@
|
|||||||
#ifndef FE_H
|
|
||||||
#define FE_H
|
|
||||||
|
|
||||||
#include "fixedint.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
fe means field element.
|
|
||||||
Here the field is \Z/(2^255-19).
|
|
||||||
An element t, entries t[0]...t[9], represents the integer
|
|
||||||
t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9].
|
|
||||||
Bounds on each t[i] vary depending on context.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
typedef int32_t fe[10];
|
|
||||||
|
|
||||||
|
|
||||||
void fe_0(fe h);
|
|
||||||
void fe_1(fe h);
|
|
||||||
|
|
||||||
void fe_frombytes(fe h, const unsigned char *s);
|
|
||||||
void fe_tobytes(unsigned char *s, const fe h);
|
|
||||||
|
|
||||||
void fe_copy(fe h, const fe f);
|
|
||||||
int fe_isnegative(const fe f);
|
|
||||||
int fe_isnonzero(const fe f);
|
|
||||||
void fe_cmov(fe f, const fe g, unsigned int b);
|
|
||||||
void fe_cswap(fe f, fe g, unsigned int b);
|
|
||||||
|
|
||||||
void fe_neg(fe h, const fe f);
|
|
||||||
void fe_add(fe h, const fe f, const fe g);
|
|
||||||
void fe_invert(fe out, const fe z);
|
|
||||||
void fe_sq(fe h, const fe f);
|
|
||||||
void fe_sq2(fe h, const fe f);
|
|
||||||
void fe_mul(fe h, const fe f, const fe g);
|
|
||||||
void fe_mul121666(fe h, fe f);
|
|
||||||
void fe_pow22523(fe out, const fe z);
|
|
||||||
void fe_sub(fe h, const fe f, const fe g);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
Portable header to provide the 32 and 64 bits type.
|
|
||||||
|
|
||||||
Not a compatible replacement for <stdint.h>, do not blindly use it as such.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED)
|
|
||||||
#include <stdint.h>
|
|
||||||
#define FIXEDINT_H_INCLUDED
|
|
||||||
|
|
||||||
#if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C)
|
|
||||||
#include <limits.h>
|
|
||||||
#define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef FIXEDINT_H_INCLUDED
|
|
||||||
#define FIXEDINT_H_INCLUDED
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
/* (u)int32_t */
|
|
||||||
#ifndef uint32_t
|
|
||||||
#if (ULONG_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned long uint32_t;
|
|
||||||
#elif (UINT_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned int uint32_t;
|
|
||||||
#elif (USHRT_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned short uint32_t;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef int32_t
|
|
||||||
#if (LONG_MAX == 0x7fffffffL)
|
|
||||||
typedef signed long int32_t;
|
|
||||||
#elif (INT_MAX == 0x7fffffffL)
|
|
||||||
typedef signed int int32_t;
|
|
||||||
#elif (SHRT_MAX == 0x7fffffffL)
|
|
||||||
typedef signed short int32_t;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* (u)int64_t */
|
|
||||||
#if (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && __STDC_VERSION__ >= 199901L)
|
|
||||||
typedef long long int64_t;
|
|
||||||
typedef unsigned long long uint64_t;
|
|
||||||
|
|
||||||
#define UINT64_C(v) v ##ULL
|
|
||||||
#define INT64_C(v) v ##LL
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
__extension__ typedef long long int64_t;
|
|
||||||
__extension__ typedef unsigned long long uint64_t;
|
|
||||||
|
|
||||||
#define UINT64_C(v) v ##ULL
|
|
||||||
#define INT64_C(v) v ##LL
|
|
||||||
#elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC)
|
|
||||||
typedef long long int64_t;
|
|
||||||
typedef unsigned long long uint64_t;
|
|
||||||
|
|
||||||
#define UINT64_C(v) v ##ULL
|
|
||||||
#define INT64_C(v) v ##LL
|
|
||||||
#elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || defined(__DECC)
|
|
||||||
typedef __int64 int64_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
|
|
||||||
#define UINT64_C(v) v ##UI64
|
|
||||||
#define INT64_C(v) v ##I64
|
|
||||||
#endif
|
|
||||||
#endif
|
|
4
src/ge.c
4
src/ge.c
@ -1,5 +1,5 @@
|
|||||||
#include "ge.h"
|
#include "../include/ge.h"
|
||||||
#include "precomp_data.h"
|
#include "../include/precomp_data.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
74
src/ge.h
74
src/ge.h
@ -1,74 +0,0 @@
|
|||||||
#ifndef GE_H
|
|
||||||
#define GE_H
|
|
||||||
|
|
||||||
#include "fe.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
ge means group element.
|
|
||||||
|
|
||||||
Here the group is the set of pairs (x,y) of field elements (see fe.h)
|
|
||||||
satisfying -x^2 + y^2 = 1 + d x^2y^2
|
|
||||||
where d = -121665/121666.
|
|
||||||
|
|
||||||
Representations:
|
|
||||||
ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
|
|
||||||
ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
|
|
||||||
ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
|
|
||||||
ge_precomp (Duif): (y+x,y-x,2dxy)
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
fe X;
|
|
||||||
fe Y;
|
|
||||||
fe Z;
|
|
||||||
} ge_p2;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
fe X;
|
|
||||||
fe Y;
|
|
||||||
fe Z;
|
|
||||||
fe T;
|
|
||||||
} ge_p3;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
fe X;
|
|
||||||
fe Y;
|
|
||||||
fe Z;
|
|
||||||
fe T;
|
|
||||||
} ge_p1p1;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
fe yplusx;
|
|
||||||
fe yminusx;
|
|
||||||
fe xy2d;
|
|
||||||
} ge_precomp;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
fe YplusX;
|
|
||||||
fe YminusX;
|
|
||||||
fe Z;
|
|
||||||
fe T2d;
|
|
||||||
} ge_cached;
|
|
||||||
|
|
||||||
void ge_p3_tobytes(unsigned char *s, const ge_p3 *h);
|
|
||||||
void ge_tobytes(unsigned char *s, const ge_p2 *h);
|
|
||||||
int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s);
|
|
||||||
|
|
||||||
void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
|
|
||||||
void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
|
|
||||||
void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b);
|
|
||||||
void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q);
|
|
||||||
void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q);
|
|
||||||
void ge_scalarmult_base(ge_p3 *h, const unsigned char *a);
|
|
||||||
|
|
||||||
void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
|
|
||||||
void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
|
|
||||||
void ge_p2_0(ge_p2 *h);
|
|
||||||
void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p);
|
|
||||||
void ge_p3_0(ge_p3 *h);
|
|
||||||
void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p);
|
|
||||||
void ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
|
|
||||||
void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||||||
#include "ed25519.h"
|
#include "../include/ed25519.h"
|
||||||
#include "fe.h"
|
#include "../include/fe.h"
|
||||||
|
|
||||||
void ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key) {
|
void ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key) {
|
||||||
unsigned char e[32];
|
unsigned char e[32];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "ed25519.h"
|
#include "../include/ed25519.h"
|
||||||
#include "sha512.h"
|
#include "../include/sha512.h"
|
||||||
#include "ge.h"
|
#include "../include/ge.h"
|
||||||
|
|
||||||
|
|
||||||
void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed) {
|
void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed) {
|
||||||
|
1391
src/precomp_data.h
1391
src/precomp_data.h
File diff suppressed because it is too large
Load Diff
4
src/sc.c
4
src/sc.c
@ -1,5 +1,5 @@
|
|||||||
#include "fixedint.h"
|
#include "../include/fixedint.h"
|
||||||
#include "sc.h"
|
#include "../include/sc.h"
|
||||||
|
|
||||||
static uint64_t load_3(const unsigned char *in) {
|
static uint64_t load_3(const unsigned char *in) {
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
|
12
src/sc.h
12
src/sc.h
@ -1,12 +0,0 @@
|
|||||||
#ifndef SC_H
|
|
||||||
#define SC_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
The set of scalars is \Z/l
|
|
||||||
where l = 2^252 + 27742317777372353535851937790883648493.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void sc_reduce(unsigned char *s);
|
|
||||||
void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "ed25519.h"
|
#include "../include/ed25519.h"
|
||||||
|
|
||||||
#ifndef ED25519_NO_SEED
|
#ifndef ED25519_NO_SEED
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "fixedint.h"
|
#include "../include/fixedint.h"
|
||||||
#include "sha512.h"
|
#include "../include/sha512.h"
|
||||||
|
|
||||||
/* the K array */
|
/* the K array */
|
||||||
static const uint64_t K[80] = {
|
static const uint64_t K[80] = {
|
||||||
|
20
src/sha512.h
20
src/sha512.h
@ -1,20 +0,0 @@
|
|||||||
#ifndef SHA512_H
|
|
||||||
#define SHA512_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include "fixedint.h"
|
|
||||||
|
|
||||||
/* state */
|
|
||||||
typedef struct sha512_context_ {
|
|
||||||
uint64_t length, state[8];
|
|
||||||
size_t curlen;
|
|
||||||
unsigned char buf[128];
|
|
||||||
} sha512_context;
|
|
||||||
|
|
||||||
|
|
||||||
int sha512_final(sha512_context * md, unsigned char *out);
|
|
||||||
int sha512_update(sha512_context * md, const unsigned char *in, size_t inlen);
|
|
||||||
int sha512(const unsigned char *message, size_t message_len, unsigned char *out);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||||||
#include "ed25519.h"
|
#include "../include/ed25519.h"
|
||||||
#include "sha512.h"
|
#include "../include/sha512.h"
|
||||||
#include "ge.h"
|
#include "../include/ge.h"
|
||||||
#include "sc.h"
|
#include "../include/sc.h"
|
||||||
|
|
||||||
|
|
||||||
void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) {
|
void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "ed25519.h"
|
#include "../include/ed25519.h"
|
||||||
#include "sha512.h"
|
#include "../include/sha512.h"
|
||||||
#include "ge.h"
|
#include "../include/ge.h"
|
||||||
#include "sc.h"
|
#include "../include/sc.h"
|
||||||
|
|
||||||
static int consttime_equal(const unsigned char *x, const unsigned char *y) {
|
static int consttime_equal(const unsigned char *x, const unsigned char *y) {
|
||||||
unsigned char r = 0;
|
unsigned char r = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user