| 1 | // Copyright (c) 2020, The Monero Project |
| 2 | // |
| 3 | // All rights reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without modification, are |
| 6 | // permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of |
| 9 | // conditions and the following disclaimer. |
| 10 | // |
| 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 | // of conditions and the following disclaimer in the documentation and/or other |
| 13 | // materials provided with the distribution. |
| 14 | // |
| 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 16 | // used to endorse or promote products derived from this software without specific |
| 17 | // prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Parts of this file from bench.cr.yp.to/supercop.html (2017-07-25): |
| 30 | // Daniel J. Bernstein |
| 31 | // Niels Duif |
| 32 | // Tanja Lange |
| 33 | // lead: Peter Schwabe |
| 34 | // Bo-Yin Yang |
| 35 | |
| 36 | #include <stddef.h> |
| 37 | #include "fe25519.h" |
| 38 | #include "ge25519.h" |
| 39 | |
| 40 | /* constants below can be found in various fles in ed25519/amd64-64-24k */ |
| 41 | |
| 42 | /* d */ |
| 43 | static const fe25519 ecd = {{0x75EB4DCA135978A3, 0x00700A4D4141D8AB, 0x8CC740797779E898, 0x52036CEE2B6FFE73}}; |
| 44 | /* 2*d */ |
| 45 | static const fe25519 ec2d = {{0xEBD69B9426B2F146, 0x00E0149A8283B156, 0x198E80F2EEF3D130, 0xA406D9DC56DFFCE7}}; |
| 46 | /* sqrt(-1) */ |
| 47 | static const fe25519 sqrtm1 = {{0xC4EE1B274A0EA0B0, 0x2F431806AD2FE478, 0x2B4D00993DFBD7A7, 0x2B8324804FC1DF0B}}; |
| 48 | |
| 49 | /* taken from loop in ed25519/amd64-64-24k/ge25519_double_scalarmult.c */ |
| 50 | static void ge25519_p1p1_to_pniels(ge25519_pniels* out, ge25519_p1p1 const* in) |
| 51 | { |
| 52 | ge25519_p1p1_to_p3((ge25519_p3*)out, in); |
| 53 | const fe25519 d = out->ysubx; |
| 54 | fe25519_sub(&(out->ysubx), &(out->xaddy), &(out->ysubx)); |
| 55 | fe25519_add(&(out->xaddy), &(out->xaddy), &d); |
| 56 | fe25519_mul(&(out->t2d), &(out->t2d), &ec2d); |
| 57 | } |
| 58 | |
| 59 | #define choose_tp crypto_sign_ed25519_amd64_64_choose_tp |
| 60 | #include "amd64.c.inc" |
| 61 | |
| 62 | int monero_crypto_amd64_64_24k_ge25519_scalarmult(char* out, char const* pub, char const* sec) |
| 63 | { |
| 64 | return scalarmult(out, pub, sec); |
| 65 | } |
| 66 | |
| 67 | int monero_crypto_amd64_64_24k_generate_key_derivation(char* out, char const* tx_pub, char const* view_sec) |
| 68 | { |
| 69 | return generate_key_derivation(out, tx_pub, view_sec); |
| 70 | } |
| 71 | |
| 72 | int monero_crypto_amd64_64_24k_generate_subaddress_public_key(char* out, char const* output_pub, char const* special_sec) |
| 73 | { |
| 74 | return generate_subaddress_public_key(out, output_pub, special_sec); |
| 75 | } |
| 76 |