Frank Denis
7 years ago
20 changed files with 152 additions and 2 deletions
@ -0,0 +1,44 @@ |
|||||
|
|
||||
|
#include "crypto_core_ed25519.h" |
||||
|
#include "private/common.h" |
||||
|
#include "private/ed25519_ref10.h" |
||||
|
|
||||
|
int |
||||
|
crypto_core_ed25519_add(unsigned char *r, |
||||
|
const unsigned char *p, const unsigned char *q) |
||||
|
{ |
||||
|
ge25519_p3 p_p3, q_p3, r_p3; |
||||
|
ge25519_p1p1 r_p1p1; |
||||
|
ge25519_cached q_cached; |
||||
|
|
||||
|
if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 || |
||||
|
ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) { |
||||
|
return -1; |
||||
|
} |
||||
|
ge25519_p3_to_cached(&q_cached, &q_p3); |
||||
|
ge25519_add(&r_p1p1, &p_p3, &q_cached); |
||||
|
ge25519_p1p1_to_p3(&r_p3, &r_p1p1); |
||||
|
ge25519_p3_tobytes(r, &r_p3); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
crypto_core_ed25519_sub(unsigned char *r, |
||||
|
const unsigned char *p, const unsigned char *q) |
||||
|
{ |
||||
|
ge25519_p3 p_p3, q_p3, r_p3; |
||||
|
ge25519_p1p1 r_p1p1; |
||||
|
ge25519_cached q_cached; |
||||
|
|
||||
|
if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 || |
||||
|
ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) { |
||||
|
return -1; |
||||
|
} |
||||
|
ge25519_p3_to_cached(&q_cached, &q_p3); |
||||
|
ge25519_sub(&r_p1p1, &p_p3, &q_cached); |
||||
|
ge25519_p1p1_to_p3(&r_p3, &r_p1p1); |
||||
|
ge25519_p3_tobytes(r, &r_p3); |
||||
|
|
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
#ifndef crypto_core_ed25519_H |
||||
|
#define crypto_core_ed25519_H |
||||
|
|
||||
|
#include <stddef.h> |
||||
|
#include "export.h" |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
SODIUM_EXPORT |
||||
|
int crypto_core_ed25519_add(unsigned char *r, |
||||
|
const unsigned char *p, const unsigned char *q); |
||||
|
|
||||
|
SODIUM_EXPORT |
||||
|
int crypto_core_ed25519_sub(unsigned char *r, |
||||
|
const unsigned char *p, const unsigned char *q); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
|
Loading…
Reference in new issue