// 
// Decompiled by Procyon v0.6.0
// 

package com.google.crypto.tink.subtle;

import com.google.crypto.tink.internal.Field25519;
import com.google.crypto.tink.internal.Curve25519;
import java.util.Arrays;
import java.security.InvalidKeyException;
import com.google.crypto.tink.annotations.Alpha;

@Alpha
public final class X25519
{
    public static byte[] generatePrivateKey() {
        final byte[] randBytes;
        final byte[] privateKey = randBytes = Random.randBytes(32);
        final int n = 0;
        randBytes[n] |= 0x7;
        final byte[] array = privateKey;
        final int n2 = 31;
        array[n2] &= 0x3F;
        final byte[] array2 = privateKey;
        final int n3 = 31;
        array2[n3] |= (byte)128;
        return privateKey;
    }
    
    public static byte[] computeSharedSecret(final byte[] privateKey, final byte[] peersPublicValue) throws InvalidKeyException {
        if (privateKey.length != 32) {
            throw new InvalidKeyException("Private key must have 32 bytes.");
        }
        final long[] x = new long[11];
        final byte[] copy;
        final byte[] e = copy = Arrays.copyOf(privateKey, 32);
        final int n = 0;
        copy[n] &= (byte)248;
        final byte[] array = e;
        final int n2 = 31;
        array[n2] &= 0x7F;
        final byte[] array2 = e;
        final int n3 = 31;
        array2[n3] |= 0x40;
        Curve25519.curveMult(x, e, peersPublicValue);
        return Field25519.contract(x);
    }
    
    public static byte[] publicFromPrivate(final byte[] privateKey) throws InvalidKeyException {
        if (privateKey.length != 32) {
            throw new InvalidKeyException("Private key must have 32 bytes.");
        }
        final byte[] base = new byte[32];
        base[0] = 9;
        return computeSharedSecret(privateKey, base);
    }
    
    private X25519() {
    }
}
