1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef X25519_ASM_H 17 #define X25519_ASM_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_CRYPTO_X25519 21 22 #include "curve25519_local.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * Function description: out = f * g (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 30 * Function prototype: void Fp51Mul(Fp51 *out, const Fp51 *f, const Fp51 *g); 31 * Input register: rdi: out; rsi: f; rdx: g; fp51 is an array of [u64; 5]. 32 * rdi: out, array pointer of output parameter fp51. 33 * rsi: pointer f of the input source data fp51 array. 34 * rdx: pointer g of the input source data fp51 array. 35 * Modify the register as follows: rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15. 36 * Output register: None 37 * Function/Macro Call: None 38 */ 39 void Fp51Mul(Fp51 *out, const Fp51 *f, const Fp51 *g); 40 41 /** 42 * Function description: out = f ^ 2 (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 43 * Function prototype: void Fp51Square(Fp51 *out, const Fp51 *f); 44 * Input register: rdi: out; rsi: f; fp51 is an array of [u64; 5] 45 * rdi: out, array pointer of output parameter fp51. 46 * rsi: pointer f of the input source data fp51 array. 47 * Modify the register as follows: rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15. 48 * Output register: None 49 * Function/Macro Call: None 50 */ 51 void Fp51Square(Fp51 *out, const Fp51 *f); 52 53 /** 54 * Function description: out = f * 121666 (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 55 * Function prototype: void Fp51MulScalar(Fp51 *out, const Fp51 *f, const uint32_t scalar); 56 * Input register: rdi: out; rsi: f; fp51 is an array of [u64; 5] 57 * rdi: out, array pointer of output parameter fp51. 58 * rsi: pointer f of the input source data fp51 array. 59 * Modify the register as follows: rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15. 60 * Output register: None 61 * Function/Macro Call: None 62 */ 63 void Fp51MulScalar(Fp51 *out, const Fp51 *in); 64 65 #ifdef HITLS_CRYPTO_X25519_X8664 66 67 typedef uint64_t Fp64[4]; 68 69 /** 70 * Function description: out = f * g (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 71 * Function prototype: void Fp64Mul(Fp64 h, const Fp64 f, const Fp64 g); 72 * Input register: rdi: out; rsi: f; rdx: g; Fp64 is an array of [u64; 4]. 73 * rdi: out, array pointer of output parameter Fp64. 74 * rsi: pointer f of the input source data Fp64 array. 75 * rdx: pointer g of the input source data Fp64 array. 76 * Modify the register as follows: rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15. 77 * Output register: None 78 * Function/Macro Call: None 79 */ 80 void Fp64Mul(Fp64 out, const Fp64 f, const Fp64 g); 81 82 /** 83 * Function description: out = f ^ 2 (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 84 * Function prototype: void Fp64Sqr(Fp64 h, const Fp64 f); 85 * Input register: rdi: out; rsi: f; Fp64 is an array of [u64; 4] 86 * rdi: out, array pointer of output parameter Fp64. 87 * rsi: pointer f of the input source data Fp64 array. 88 * Modify the register as follows: rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15. 89 * Output register: None 90 * Function/Macro Call: None 91 */ 92 void Fp64Sqr(Fp64 out, const Fp64 f); 93 94 /** 95 * Function description: out = f * 121666 (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 96 * Function prototype: void Fp64MulScalar(Fp64 h, Fp64 f); 97 * Input register: rdi: out; rsi: f; Fp64 is an array of [u64; 4] 98 * rdi: out, array pointer of output parameter Fp64. 99 * rsi: pointer f of the input source data Fp64 array. 100 * Modify the register as follows: rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15. 101 * Output register: None 102 * Function/Macro Call: None 103 */ 104 void Fp64MulScalar(Fp64 out, Fp64 f); 105 106 /** 107 * Function description: out = f + g (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 108 * Function prototype: void Fp64Add(Fp64 h, const Fp64 f, const Fp64 g); 109 * Input register: rdi: out; rsi: f; Fp64 is an array of [u64; 4] 110 * rdi: out, array pointer of output parameter Fp64. 111 * rsi: pointer f of the input source data Fp64 array. 112 * rdx: pointer g of the input source data Fp64 array. 113 * Modify the register as follows: rax, rcx, r8-r11. 114 * Output register: None 115 * Function/Macro Call: None 116 */ 117 void Fp64Add(Fp64 out, const Fp64 f, const Fp64 g); 118 119 /** 120 * Function description: out = f - g (mod p), p = 2 ^ 255 - 19, which is the modulus of curve25519 field. 121 * Function prototype: void Fp64Sub(Fp64 h, const Fp64 f, const Fp64 g); 122 * Input register: rdi: out; rsi: f; Fp64 is an array of [u64; 4] 123 * rdi: out, array pointer of output parameter Fp64. 124 * rsi: pointer f of the input source data Fp64 array. 125 * rdx: pointer g of the input source data Fp64 array. 126 * Modify the register as follows: rax, rcx, r8-r11. 127 * Output register: None 128 * Function/Macro Call: None 129 */ 130 void Fp64Sub(Fp64 out, const Fp64 f, const Fp64 g); 131 132 /** 133 * Function description: data conversion. 134 * Function prototype: void Fp64PolyToData(uint8_t *out, const Fp64 f); 135 * Input register: rdi: out; rsi: f; Fp64 is an array of [u64; 4] 136 * rdi: out, array pointer of output parameter Fp64. 137 * rsi: pointer f of the input source data Fp64 array. 138 * Modify the register as follows: rax, rcx, r8-r11. 139 * Output register: None 140 * Function/Macro Call: None 141 */ 142 void Fp64PolyToData(uint8_t *out, const Fp64 f); 143 144 #endif 145 146 #ifdef __cplusplus 147 } 148 #endif 149 150 #endif /* HITLS_CRYPTO_X25519 */ 151 152 #endif // X25519_ASM_H 153