All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.whispersystems.curve25519.java.scalarmult Maven / Gradle / Ivy

The newest version!
package org.whispersystems.curve25519.java;

public class scalarmult {

//CONVERT #include "crypto_scalarmult.h"
//CONVERT #include "fe.h"

    public static int crypto_scalarmult(byte[] q,
                                        byte[] n,
                                        byte[] p) {
        byte[] e = new byte[32];
        int i;
        int[] x1 = new int[10];
        int[] x2 = new int[10];
        int[] z2 = new int[10];
        int[] x3 = new int[10];
        int[] z3 = new int[10];
        int[] tmp0 = new int[10];
        int[] tmp1 = new int[10];
        int pos;
        int swap;
        int b;

        for (i = 0; i < 32; ++i) e[i] = n[i];
//  e[0] &= 248;
//  e[31] &= 127;
//  e[31] |= 64;
        fe_frombytes.fe_frombytes(x1, p);
        fe_1.fe_1(x2);
        fe_0.fe_0(z2);
        fe_copy.fe_copy(x3, x1);
        fe_1.fe_1(z3);

        swap = 0;
        for (pos = 254; pos >= 0; --pos) {
            b = e[pos / 8] >>> (pos & 7);
            b &= 1;
            swap ^= b;
            fe_cswap.fe_cswap(x2, x3, swap);
            fe_cswap.fe_cswap(z2, z3, swap);
            swap = b;
//CONVERT #include "montgomery.h"

            /* qhasm: fe X2 */

            /* qhasm: fe Z2 */

            /* qhasm: fe X3 */

            /* qhasm: fe Z3 */

            /* qhasm: fe X4 */

            /* qhasm: fe Z4 */

            /* qhasm: fe X5 */

            /* qhasm: fe Z5 */

            /* qhasm: fe A */

            /* qhasm: fe B */

            /* qhasm: fe C */

            /* qhasm: fe D */

            /* qhasm: fe E */

            /* qhasm: fe AA */

            /* qhasm: fe BB */

            /* qhasm: fe DA */

            /* qhasm: fe CB */

            /* qhasm: fe t0 */

            /* qhasm: fe t1 */

            /* qhasm: fe t2 */

            /* qhasm: fe t3 */

            /* qhasm: fe t4 */

            /* qhasm: enter ladder */

            /* qhasm: D = X3-Z3 */
            /* asm 1: fe_sub.fe_sub(>D=fe#5,D=tmp0,B=fe#6,B=tmp1,A=fe#1,A=x2,C=fe#2,C=z2,DA=fe#4,DA=z3,CB=fe#2,CB=z2,BB=fe#5,BB=tmp0,AA=fe#6,AA=tmp1,t0=fe#3,t0=x3,t1=fe#2,t1=z2,X4=fe#1,X4=x2,E=fe#6,E=tmp1,t2=fe#2,t2=z2,t3=fe#4,t3=z3,X5=fe#3,X5=x3,t4=fe#5,t4=tmp0,Z5=fe#4,x1,Z5=z3,x1,Z4=fe#2,Z4=z2,




© 2015 - 2025 Weber Informatics LLC | Privacy Policy