| 1 | #include "randombytes.h" |
| 2 | #include "crypto_nP.h" |
| 3 | #include "fe25519.h" |
| 4 | #include "crypto_uint64_vec8x1.h" |
| 5 | |
| 6 | #define mladder CRYPTO_SHARED_NAMESPACE(mladder) |
| 7 | extern void mladder(crypto_uint64_vec8x1 *,crypto_uint64_vec8x1 *,const unsigned char *); |
| 8 | |
| 9 | void crypto_nP(unsigned char *q, const unsigned char *n, const unsigned char *p) { |
| 10 | |
| 11 | int i; |
| 12 | unsigned char c[32]; |
| 13 | |
| 14 | crypto_uint64_vec8x1 a[10] = {{0}}; |
| 15 | crypto_uint64_vec8x1 b[10] = {{0}}; |
| 16 | fe25519_10l u,v; |
| 17 | fe25519 z[2]; |
| 18 | |
| 19 | for(i=0;i<32;i++) c[i] = n[i]; |
| 20 | c[0] &= 248; c[31] &= 127; c[31] |= 64; |
| 21 | |
| 22 | fe25519_unpack(z,p); |
| 23 | fe25519_to_10l(&u,z); |
| 24 | |
| 25 | a[0][0] = a[0][6] = b[0][4] = 1; |
| 26 | |
| 27 | for (i=0;i<10;i++) {a[i][4] = u.l[i]; b[i][6] = u.l[i];} |
| 28 | |
| 29 | mladder(a,b,c); |
| 30 | |
| 31 | for (i=0;i<10;i++) {u.l[i] = a[i][0]; v.l[i] = a[i][2];} |
| 32 | |
| 33 | fe25519_from_10l(z,&u); |
| 34 | fe25519_from_10l(z+1,&v); |
| 35 | fe25519_invert(z+1,z+1); |
| 36 | fe25519_mul(z,z,z+1); |
| 37 | fe25519_pack(q,z); |
| 38 | } |