Search in sources :

Example 1 with EdDSANamedCurveSpec

use of net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec in project i2p.i2p by i2p.

the class PrecomputationTestVectors method getPrecomputation.

public static GroupElement[][] getPrecomputation(String fileName) {
    EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
    Curve curve = ed25519.getCurve();
    Field field = curve.getField();
    GroupElement[][] precmp = new GroupElement[32][8];
    BufferedReader file = null;
    int row = 0, col = 0;
    try {
        InputStream is = PrecomputationTestVectors.class.getResourceAsStream(fileName);
        if (is == null)
            throw new IOException("Resource not found: " + fileName);
        file = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = file.readLine()) != null) {
            if (line.equals(" },"))
                col += 1;
            else if (line.equals("},")) {
                col = 0;
                row += 1;
            } else if (line.startsWith("  { ")) {
                String ypxStr = line.substring(4, line.lastIndexOf(' '));
                FieldElement ypx = field.fromByteArray(Utils.hexToBytes(ypxStr));
                line = file.readLine();
                String ymxStr = line.substring(4, line.lastIndexOf(' '));
                FieldElement ymx = field.fromByteArray(Utils.hexToBytes(ymxStr));
                line = file.readLine();
                String xy2dStr = line.substring(4, line.lastIndexOf(' '));
                FieldElement xy2d = field.fromByteArray(Utils.hexToBytes(xy2dStr));
                precmp[row][col] = GroupElement.precomp(curve, ypx, ymx, xy2d);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (IOException e) {
            }
    }
    return precmp;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) EdDSANamedCurveSpec(net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec)

Example 2 with EdDSANamedCurveSpec

use of net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec in project i2p.i2p by i2p.

the class PrecomputationTestVectors method getDoublePrecomputation.

public static GroupElement[] getDoublePrecomputation(String fileName) {
    EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
    Curve curve = ed25519.getCurve();
    Field field = curve.getField();
    GroupElement[] dblPrecmp = new GroupElement[8];
    BufferedReader file = null;
    int row = 0;
    try {
        InputStream is = PrecomputationTestVectors.class.getResourceAsStream(fileName);
        if (is == null)
            throw new IOException("Resource not found: " + fileName);
        file = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = file.readLine()) != null) {
            if (line.equals(" },")) {
                row += 1;
            } else if (line.startsWith("  { ")) {
                String ypxStr = line.substring(4, line.lastIndexOf(' '));
                FieldElement ypx = field.fromByteArray(Utils.hexToBytes(ypxStr));
                line = file.readLine();
                String ymxStr = line.substring(4, line.lastIndexOf(' '));
                FieldElement ymx = field.fromByteArray(Utils.hexToBytes(ymxStr));
                line = file.readLine();
                String xy2dStr = line.substring(4, line.lastIndexOf(' '));
                FieldElement xy2d = field.fromByteArray(Utils.hexToBytes(xy2dStr));
                dblPrecmp[row] = GroupElement.precomp(curve, ypx, ymx, xy2d);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (IOException e) {
            }
    }
    return dblPrecmp;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) EdDSANamedCurveSpec(net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec)

Example 3 with EdDSANamedCurveSpec

use of net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec in project agileway by fangjinuo.

the class Eddsa25519PublicKeyCodec method decode.

@Override
public PublicKey decode(byte[] bytes) {
    try {
        Buffer buf = new Buffer.PlainBuffer(bytes);
        final int keyLen = buf.readUInt32AsInt();
        final byte[] p = new byte[keyLen];
        buf.readRawBytes(p);
        if (logger.isDebugEnabled()) {
            logger.debug("Key algo: {}, Key curve: 25519, Key Len: {}\np: {}", getName(), keyLen, Arrays.toString(p));
        }
        EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName("Ed25519");
        EdDSAPublicKeySpec publicSpec = new EdDSAPublicKeySpec(p, ed25519);
        return new Ed25519PublicKey(publicSpec);
    } catch (Buffer.BufferException be) {
        throw new SshException(be);
    }
}
Also used : Buffer(com.jn.agileway.ssh.client.utils.Buffer) EdDSAPublicKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec) SshException(com.jn.agileway.ssh.client.SshException) EdDSANamedCurveSpec(net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec)

Aggregations

EdDSANamedCurveSpec (net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 SshException (com.jn.agileway.ssh.client.SshException)1 Buffer (com.jn.agileway.ssh.client.utils.Buffer)1 EdDSAPublicKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec)1