当前位置: 首页>>代码示例>>Java>>正文


Java ScalarOps类代码示例

本文整理汇总了Java中net.i2p.crypto.eddsa.math.ScalarOps的典型用法代码示例。如果您正苦于以下问题:Java ScalarOps类的具体用法?Java ScalarOps怎么用?Java ScalarOps使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScalarOps类属于net.i2p.crypto.eddsa.math包,在下文中一共展示了ScalarOps类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: EdDSAParameterSpec

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
/**
 * @throws IllegalArgumentException if hash algorithm is unsupported or length is wrong
 */
public EdDSAParameterSpec(Curve curve, String hashAlgo,
                          ScalarOps sc, GroupElement B) {
    try {
        MessageDigest hash = MessageDigest.getInstance(hashAlgo);
        // EdDSA hash function must produce 2b-bit output
        if (curve.getField().getb() / 4 != hash.getDigestLength())
            throw new IllegalArgumentException("Hash output is not 2b-bit");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("Unsupported hash algorithm");
    }

    this.curve = curve;
    this.hashAlgo = hashAlgo;
    this.sc = sc;
    this.B = B;
}
 
开发者ID:ubirch,项目名称:ubirch-scala-utils,代码行数:20,代码来源:EdDSAParameterSpec.java

示例2: EdDSAParameterSpec

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
/**
 * @param curve the curve
 * @param hashAlgo the JCA string for the hash algorithm
 * @param sc the parameter L represented as ScalarOps
 * @param B the parameter B
 * @throws IllegalArgumentException if hash algorithm is unsupported or length is wrong
 */
public EdDSAParameterSpec(Curve curve, String hashAlgo,
        ScalarOps sc, GroupElement B) {
    try {
        MessageDigest hash = MessageDigest.getInstance(hashAlgo);
        // EdDSA hash function must produce 2b-bit output
        if (curve.getField().getb()/4 != hash.getDigestLength())
            throw new IllegalArgumentException("Hash output is not 2b-bit");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("Unsupported hash algorithm");
    }

    this.curve = curve;
    this.hashAlgo = hashAlgo;
    this.sc = sc;
    this.B = B;
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:24,代码来源:EdDSAParameterSpec.java

示例3: EdDSAParameterSpec

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
/**
 *  @throws IllegalArgumentException if hash algorithm is unsupported or length is wrong
 */
public EdDSAParameterSpec(Curve curve, String hashAlgo,
        ScalarOps sc, GroupElement B) {
    try {
        MessageDigest hash = MessageDigest.getInstance(hashAlgo);
        // EdDSA hash function must produce 2b-bit output
        if (curve.getField().getb()/4 != hash.getDigestLength())
            throw new IllegalArgumentException("Hash output is not 2b-bit");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("Unsupported hash algorithm");
    }

    this.curve = curve;
    this.hashAlgo = hashAlgo;
    this.sc = sc;
    this.B = B;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:20,代码来源:EdDSAParameterSpec.java

示例4: testMultiplyAndAdd

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
/**
 * Test method for {@link net.i2p.crypto.eddsa.math.bigint.BigIntegerScalarOps#multiplyAndAdd(byte[], byte[], byte[])}.
 */
@Test
public void testMultiplyAndAdd() {
    ScalarOps sc = new BigIntegerScalarOps(ed25519Field,
            new BigInteger("5"));
    assertThat(sc.multiplyAndAdd(new byte[] {7}, new byte[] {2}, new byte[] {5}),
            is(equalTo(Utils.hexToBytes("0400000000000000000000000000000000000000000000000000000000000000"))));

    ScalarOps sc2 = new BigIntegerScalarOps(ed25519Field,
            new BigInteger("7237005577332262213973186563042994240857116359379907606001950938285454250989"));
    // Example from test case 1
    byte[] h = Utils.hexToBytes("86eabc8e4c96193d290504e7c600df6cf8d8256131ec2c138a3e7e162e525404");
    byte[] a = Utils.hexToBytes("307c83864f2833cb427a2ef1c00a013cfdff2768d980c0a3a520f006904de94f");
    byte[] r = Utils.hexToBytes("f38907308c893deaf244787db4af53682249107418afc2edc58f75ac58a07404");
    byte[] S = Utils.hexToBytes("5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");
    assertThat(sc2.multiplyAndAdd(h, a, r), is(equalTo(S)));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:20,代码来源:BigIntegerScalarOpsTest.java

示例5: engineSign

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
@Override
protected byte[] engineSign() throws SignatureException {
    Curve curve = key.getParams().getCurve();
    ScalarOps sc = key.getParams().getScalarOps();
    byte[] a = ((EdDSAPrivateKey) key).geta();

    byte[] message = baos.toByteArray();
    // r = H(h_b,...,h_2b-1,M)
    byte[] r = digest.digest(message);

    // r mod l
    // Reduces r from 64 bytes to 32 bytes
    r = sc.reduce(r);

    // R = rB
    GroupElement R = key.getParams().getB().scalarMultiply(r);
    byte[] Rbyte = R.toByteArray();

    // S = (r + H(Rbar,Abar,M)*a) mod l
    digest.update(Rbyte);
    digest.update(((EdDSAPrivateKey) key).getAbyte());
    byte[] h = digest.digest(message);
    h = sc.reduce(h);
    byte[] S = sc.multiplyAndAdd(h, a, r);

    // R+S
    int b = curve.getField().getb();
    ByteBuffer out = ByteBuffer.allocate(b/4);
    out.put(Rbyte).put(S);
    return out.array();
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:32,代码来源:EdDSAEngine.java

示例6: testReduce

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
/**
 * Test method for {@link net.i2p.crypto.eddsa.math.bigint.BigIntegerScalarOps#reduce(byte[])}.
 */
@Test
public void testReduce() {
    ScalarOps sc = new BigIntegerScalarOps(ed25519Field,
            new BigInteger("5"));
    assertThat(sc.reduce(new byte[] {7}),
            is(equalTo(Utils.hexToBytes("0200000000000000000000000000000000000000000000000000000000000000"))));

    ScalarOps sc2 = new BigIntegerScalarOps(ed25519Field,
            new BigInteger("7237005577332262213973186563042994240857116359379907606001950938285454250989"));
    // Example from test case 1
    byte[] r = Utils.hexToBytes("b6b19cd8e0426f5983fa112d89a143aa97dab8bc5deb8d5b6253c928b65272f4044098c2a990039cde5b6a4818df0bfb6e40dc5dee54248032962323e701352d");
    assertThat(sc2.reduce(r), is(equalTo(Utils.hexToBytes("f38907308c893deaf244787db4af53682249107418afc2edc58f75ac58a07404"))));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:17,代码来源:BigIntegerScalarOpsTest.java

示例7: EdDSANamedCurveSpec

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
public EdDSANamedCurveSpec(String name, Curve curve,
                           String hashAlgo, ScalarOps sc, GroupElement B) {
    super(curve, hashAlgo, sc, B);
    this.name = name;
}
 
开发者ID:ubirch,项目名称:ubirch-scala-utils,代码行数:6,代码来源:EdDSANamedCurveSpec.java

示例8: getScalarOps

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
public ScalarOps getScalarOps() {
    return sc;
}
 
开发者ID:ubirch,项目名称:ubirch-scala-utils,代码行数:4,代码来源:EdDSAParameterSpec.java

示例9: x_engineSign

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
private byte[] x_engineSign() throws SignatureException {
    Curve curve = key.getParams().getCurve();
    ScalarOps sc = key.getParams().getScalarOps();
    byte[] a = ((EdDSAPrivateKey) key).geta();

    byte[] message;
    int offset, length;
    if (oneShotMode) {
        if (oneShotBytes == null)
            throw new SignatureException("update() not called first");
        message = oneShotBytes;
        offset = oneShotOffset;
        length = oneShotLength;
    } else {
        if (baos == null)
            message = new byte[0];
        else
            message = baos.toByteArray();
        offset = 0;
        length = message.length;
    }
    // r = H(h_b,...,h_2b-1,M)
    digest.update(message, offset, length);
    byte[] r = digest.digest();

    // r mod l
    // Reduces r from 64 bytes to 32 bytes
    r = sc.reduce(r);

    // R = rB
    GroupElement R = key.getParams().getB().scalarMultiply(r);
    byte[] Rbyte = R.toByteArray();

    // S = (r + H(Rbar,Abar,M)*a) mod l
    digest.update(Rbyte);
    digest.update(((EdDSAPrivateKey) key).getAbyte());
    digest.update(message, offset, length);
    byte[] h = digest.digest();
    h = sc.reduce(h);
    byte[] S = sc.multiplyAndAdd(h, a, r);

    // R+S
    int b = curve.getField().getb();
    ByteBuffer out = ByteBuffer.allocate(b / 4);
    out.put(Rbyte).put(S);
    return out.array();
}
 
开发者ID:ubirch,项目名称:ubirch-scala-utils,代码行数:48,代码来源:EdDSAEngine.java

示例10: EdDSANamedCurveSpec

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
public EdDSANamedCurveSpec(String name, Curve curve,
        String hashAlgo, ScalarOps sc, GroupElement B) {
    super(curve, hashAlgo, sc, B);
    this.name = name;
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:6,代码来源:EdDSANamedCurveSpec.java

示例11: x_engineSign

import net.i2p.crypto.eddsa.math.ScalarOps; //导入依赖的package包/类
private byte[] x_engineSign() throws SignatureException {
    Curve curve = key.getParams().getCurve();
    ScalarOps sc = key.getParams().getScalarOps();
    byte[] a = ((EdDSAPrivateKey) key).geta();

    byte[] message;
    int offset, length;
    if (oneShotMode) {
        if (oneShotBytes == null)
            throw new SignatureException("update() not called first");
        message = oneShotBytes;
        offset = oneShotOffset;
        length = oneShotLength;
    } else {
        if (baos == null)
            message = new byte[0];
        else
            message = baos.toByteArray();
        offset = 0;
        length = message.length;
    }
    // r = H(h_b,...,h_2b-1,M)
    digest.update(message, offset, length);
    byte[] r = digest.digest();

    // r mod l
    // Reduces r from 64 bytes to 32 bytes
    r = sc.reduce(r);

    // R = rB
    GroupElement R = key.getParams().getB().scalarMultiply(r);
    byte[] Rbyte = R.toByteArray();

    // S = (r + H(Rbar,Abar,M)*a) mod l
    digest.update(Rbyte);
    digest.update(((EdDSAPrivateKey) key).getAbyte());
    digest.update(message, offset, length);
    byte[] h = digest.digest();
    h = sc.reduce(h);
    byte[] S = sc.multiplyAndAdd(h, a, r);

    // R+S
    int b = curve.getField().getb();
    ByteBuffer out = ByteBuffer.allocate(b/4);
    out.put(Rbyte).put(S);
    return out.array();
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:48,代码来源:EdDSAEngine.java


注:本文中的net.i2p.crypto.eddsa.math.ScalarOps类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。