1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
6 #include "curve25519.h"
12 #ifndef __BYTE_ORDER__
13 #include <sys/param.h>
14 #if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN) || !defined(LITTLE_ENDIAN)
15 #error "Unable to determine endianness."
17 #define __BYTE_ORDER__ BYTE_ORDER
18 #define __ORDER_BIG_ENDIAN__ BIG_ENDIAN
19 #define __ORDER_LITTLE_ENDIAN__ LITTLE_ENDIAN
23 #include <linux/types.h>
29 typedef uint64_t u64
, __le64
;
30 typedef uint32_t u32
, __le32
;
35 #define __unused __attribute__((unused))
37 #ifndef __always_inline
38 #define __always_inline __inline __attribute__((__always_inline__))
41 #define noinline __attribute__((noinline))
44 #define __aligned(x) __attribute__((aligned(x)))
50 static __always_inline __unused
void put_unaligned_le64(u64 s
, u8
*d
)
52 __le64 l
= cpu_to_le64(s
);
53 __builtin_memcpy(d
, &l
, sizeof(l
));
56 static noinline
void memzero_explicit(void *s
, size_t count
)
59 asm volatile("": :"r"(s
) : "memory");
62 #ifdef __SIZEOF_INT128__
63 #include "curve25519-hacl64.h"
65 #include "curve25519-fiat32.h"
68 void curve25519_generate_public(uint8_t pub
[static CURVE25519_KEY_SIZE
], const uint8_t secret
[static CURVE25519_KEY_SIZE
])
70 static const uint8_t basepoint
[CURVE25519_KEY_SIZE
] __aligned(sizeof(uintptr_t)) = { 9 };
72 curve25519(pub
, secret
, basepoint
);
75 void curve25519(uint8_t mypublic
[static CURVE25519_KEY_SIZE
], const uint8_t secret
[static CURVE25519_KEY_SIZE
], const uint8_t basepoint
[static CURVE25519_KEY_SIZE
])
77 curve25519_generic(mypublic
, secret
, basepoint
);