… | |
… | |
34 | #include <cstring> |
34 | #include <cstring> |
35 | #include <openssl/rand.h> |
35 | #include <openssl/rand.h> |
36 | |
36 | |
37 | #include "util.h" |
37 | #include "util.h" |
38 | #include "curve25519.h" |
38 | #include "curve25519.h" |
|
|
39 | |
|
|
40 | #if __GNUC__ >= 4 && __SIZEOF_LONG__ == 8 |
|
|
41 | #include "curve25519-donna-c64.c" |
|
|
42 | #else |
39 | #include "curve25519-donna.c" |
43 | #include "curve25519-donna.c" |
|
|
44 | #endif |
40 | |
45 | |
41 | static void |
46 | static void |
42 | curve25519_derive (const curve25519_key &a, curve25519_key &b) |
47 | curve25519_derive (const curve25519_key &a, curve25519_key &b) |
43 | { |
48 | { |
44 | static const curve25519_key basepoint = { 9 }; |
49 | static const curve25519_key basepoint = { 9 }; |
45 | curve25519_donna (b, a, basepoint); |
50 | curve25519_donna (b, a, basepoint); |
46 | } |
51 | } |
47 | |
52 | |
48 | void curve25519_generate (curve25519_key &a, curve25519_key &b) |
53 | void curve25519_generate (curve25519_key &a, curve25519_key &b) |
49 | { |
54 | { |
50 | RAND_bytes (a, sizeof a); |
55 | rand_fill (a); |
51 | |
56 | |
|
|
57 | #if 0 |
52 | a [ 0] &= 0xf8; |
58 | a [ 0] &= 0xf8; |
53 | a [31] &= 0x7f; |
59 | a [31] &= 0x7f; |
54 | a [31] |= 0x40; |
60 | a [31] |= 0x40; |
|
|
61 | #endif |
55 | |
62 | |
56 | curve25519_derive (a, b); |
63 | curve25519_derive (a, b); |
57 | } |
64 | } |
58 | |
65 | |
59 | void curve25519_combine (const curve25519_key &a, const curve25519_key &b, curve25519_key &s) |
66 | void curve25519_combine (const curve25519_key &a, const curve25519_key &b, curve25519_key &s) |