• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IntegerPolynomial类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: signHash

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
private byte[] signHash(byte[] msgHash, NTRUSigningPrivateKeyParameters kp)
{
    int r = 0;
    IntegerPolynomial s;
    IntegerPolynomial i;

    NTRUSigningPublicKeyParameters kPub = kp.getPublicKey();
    do
    {
        r++;
        if (r > params.signFailTolerance)
        {
            throw new IllegalStateException("Signing failed: too many retries (max=" + params.signFailTolerance + ")");
        }
        i = createMsgRep(msgHash, r);
        s = sign(i, kp);
    }
    while (!verify(i, s, kPub.h));

    byte[] rawSig = s.toBinary(params.q);
    ByteBuffer sbuf = ByteBuffer.allocate(rawSig.length + 4);
    sbuf.put(rawSig);
    sbuf.putInt(r);
    return sbuf.array();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:NTRUSigner.java


示例2: encode

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
/**
 * Writes the basis to an output stream
 *
 * @param os        an output stream
 * @param include_h whether to write the polynomial <code>h</code> (<code>true</code>) or only <code>f</code> and <code>f'</code> (<code>false</code>)
 * @throws IOException
 */
void encode(OutputStream os, boolean include_h)
    throws IOException
{
    int q = params.q;

    os.write(getEncoded(f));
    if (params.basisType == NTRUSigningKeyGenerationParameters.BASIS_TYPE_STANDARD)
    {
        IntegerPolynomial fPrimeInt = fPrime.toIntegerPolynomial();
        for (int i = 0; i < fPrimeInt.coeffs.length; i++)
        {
            fPrimeInt.coeffs[i] += q / 2;
        }
        os.write(fPrimeInt.toBinary(q));
    }
    else
    {
        os.write(getEncoded(fPrime));
    }
    if (include_h)
    {
        os.write(h.toBinary(q));
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:32,代码来源:NTRUSigningPrivateKeyParameters.java


示例3: NTRUEncryptionPrivateKeyParameters

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
/**
 * Reads a polynomial <code>f</code> from an input stream and constructs a new private key
 *
 * @param is     an input stream
 * @param params the NtruEncrypt parameters to use
 * @see #writeTo(OutputStream)
 */
public NTRUEncryptionPrivateKeyParameters(InputStream is, NTRUEncryptionParameters params)
    throws IOException
{
    super(true, params);

    if (params.polyType == NTRUParameters.TERNARY_POLYNOMIAL_TYPE_PRODUCT)
    {
        int N = params.N;
        int df1 = params.df1;
        int df2 = params.df2;
        int df3Ones = params.df3;
        int df3NegOnes = params.fastFp ? params.df3 : params.df3 - 1;
        h = IntegerPolynomial.fromBinary(is, params.N, params.q);
        t = ProductFormPolynomial.fromBinary(is, N, df1, df2, df3Ones, df3NegOnes);
    }
    else
    {
        h = IntegerPolynomial.fromBinary(is, params.N, params.q);
        IntegerPolynomial fInt = IntegerPolynomial.fromBinary3Tight(is, params.N);
        t = params.sparse ? new SparseTernaryPolynomial(fInt) : new DenseTernaryPolynomial(fInt);
    }

    init();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:32,代码来源:NTRUEncryptionPrivateKeyParameters.java


示例4: decrypt

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
/**
 * @param e
 * @param priv_t  a polynomial such that if <code>fastFp=true</code>, <code>f=1+3*priv_t</code>; otherwise, <code>f=priv_t</code>
 * @param priv_fp
 * @return
 */
protected IntegerPolynomial decrypt(IntegerPolynomial e, Polynomial priv_t, IntegerPolynomial priv_fp)
{
    IntegerPolynomial a;
    if (params.fastFp)
    {
        a = priv_t.mult(e, params.q);
        a.mult(3);
        a.add(e);
    }
    else
    {
        a = priv_t.mult(e, params.q);
    }
    a.center0(params.q);
    a.mod3();

    IntegerPolynomial c = params.fastFp ? a : new DenseTernaryPolynomial(a).mult(priv_fp, 3);
    c.center0(3);
    return c;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:NTRUEngine.java


示例5: decrypt

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
/**
 * @param e
 * @param priv_t  a polynomial such that if <code>fastFp=true</code>, <code>f=1+3*priv_t</code>; otherwise, <code>f=priv_t</code>
 * @param priv_fp
 * @return an IntegerPolynomial representing the output.
 */
protected IntegerPolynomial decrypt(IntegerPolynomial e, Polynomial priv_t, IntegerPolynomial priv_fp)
{
    IntegerPolynomial a;
    if (params.fastFp)
    {
        a = priv_t.mult(e, params.q);
        a.mult(3);
        a.add(e);
    }
    else
    {
        a = priv_t.mult(e, params.q);
    }
    a.center0(params.q);
    a.mod3();

    IntegerPolynomial c = params.fastFp ? a : new DenseTernaryPolynomial(a).mult(priv_fp, 3);
    c.center0(3);
    return c;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:27,代码来源:NTRUEngine.java


示例6: testMult

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
public void testMult()
{
    IntegerPolynomial i1 = new IntegerPolynomial(new int[]{1368, 2047, 672, 871, 1662, 1352, 1099, 1608});
    IntegerPolynomial i2 = new IntegerPolynomial(new int[]{1729, 1924, 806, 179, 1530, 1381, 1695, 60});
    LongPolynomial2 a = new LongPolynomial2(i1);
    LongPolynomial2 b = new LongPolynomial2(i2);
    IntegerPolynomial c1 = i1.mult(i2, 2048);
    IntegerPolynomial c2 = a.mult(b).toIntegerPolynomial();
    assertTrue(Arrays.areEqual(c1.coeffs, c2.coeffs));

    // test 10 random polynomials
    Random rng = new Random();
    for (int i = 0; i < 10; i++)
    {
        int N = 2 + rng.nextInt(2000);
        i1 = PolynomialGenerator.generateRandom(N, 2048);
        i2 = PolynomialGenerator.generateRandom(N, 2048);
        a = new LongPolynomial2(i1);
        b = new LongPolynomial2(i2);
        c1 = i1.mult(i2);
        c1.modPositive(2048);
        c2 = a.mult(b).toIntegerPolynomial();
        assertTrue(Arrays.areEqual(c1.coeffs, c2.coeffs));
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:LongPolynomial2Test.java


示例7: verifyResultant

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
private void verifyResultant(IntegerPolynomial a, Resultant r)
{
    BigIntPolynomial b = new BigIntPolynomial(a).mult(r.rho);
    BigInteger[]     bCoeffs = b.getCoeffs();

    for (int j = 1; j < bCoeffs.length - 1; j++)
    {
        assertEquals(BigInteger.ZERO, bCoeffs[j]);
    }
    if (r.res.equals(BigInteger.ZERO))
    {
        assertEquals(BigInteger.ZERO, bCoeffs[0].subtract(bCoeffs[bCoeffs.length - 1]));
    }
    else
    {
        assertEquals(BigInteger.ZERO, (bCoeffs[0].subtract(bCoeffs[bCoeffs.length - 1]).mod(r.res)));
    }
    assertEquals(bCoeffs[0].subtract(r.res), bCoeffs[bCoeffs.length - 1].negate());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:20,代码来源:IntegerPolynomialTest.java


示例8: testMult

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
/**
 * tests mult(IntegerPolynomial) and mult(BigIntPolynomial)
 */
public void testMult()
{
    SecureRandom random = new SecureRandom();
    SparseTernaryPolynomial p1 = SparseTernaryPolynomial.generateRandom(1000, 500, 500, random);
    IntegerPolynomial p2 = DenseTernaryPolynomial.generateRandom(1000, random);

    IntegerPolynomial prod1 = p1.mult(p2);
    IntegerPolynomial prod2 = p1.mult(p2);
    assertEquals(prod1, prod2);

    BigIntPolynomial p3 = new BigIntPolynomial(p2);
    BigIntPolynomial prod3 = p1.mult(p3);

    assertEquals(new BigIntPolynomial(prod1), prod3);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:19,代码来源:SparseTernaryPolynomialTest.java


示例9: testInvalidEncoding

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
private void testInvalidEncoding(NTRUEngine ntru, AsymmetricCipherKeyPair kp, NTRUEncryptionKeyGenerationParameters params)
{
    try
    {
        byte[] plainText = "secret encrypted text".getBytes();
        ntru.init(true, kp.getPublic());

        byte[] encrypted = ntru.processBlock(plainText, 0, plainText.length);

        NTRUEncryptionPrivateKeyParameters orig = (NTRUEncryptionPrivateKeyParameters)kp.getPrivate();
        IntegerPolynomial h = (IntegerPolynomial)((NTRUEncryptionPublicKeyParameters)kp.getPublic()).h.clone();
        h.coeffs[0] = (h.coeffs[0] + 111) % params.q;   // alter h
        NTRUEncryptionPrivateKeyParameters privKey = new NTRUEncryptionPrivateKeyParameters(h, orig.t, orig.fp, params.getEncryptionParameters());

        ntru.init(false, privKey);

        ntru.processBlock(encrypted, 0, encrypted.length);

        fail("An exception should have been thrown!");
    }
    catch (InvalidCipherTextException ex)
    {
        assertEquals("Invalid message encoding", ex.getMessage());
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:NTRUEncryptTest.java


示例10: testCreateMsgRep

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
private void testCreateMsgRep(NTRUSigningKeyGenerationParameters params)
{
    VisibleNTRUSigner ntru = new VisibleNTRUSigner(params.getSigningParameters());
    byte[] msgHash = "adfsadfsdfs23234234".getBytes();

    // verify that the message representative is reproducible
    IntegerPolynomial i1 = ntru.createMsgRep(msgHash, 1);
    IntegerPolynomial i2 = ntru.createMsgRep(msgHash, 1);
    assertTrue(Arrays.areEqual(i1.coeffs, i2.coeffs));
    i1 = ntru.createMsgRep(msgHash, 5);
    i2 = ntru.createMsgRep(msgHash, 5);
    assertTrue(Arrays.areEqual(i1.coeffs, i2.coeffs));

    i1 = ntru.createMsgRep(msgHash, 2);
    i2 = ntru.createMsgRep(msgHash, 3);
    assertFalse(Arrays.areEqual(i1.coeffs, i2.coeffs));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:NTRUSignerTest.java


示例11: verifyHash

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
private boolean verifyHash(byte[] msgHash, byte[] sig, NTRUSigningPublicKeyParameters pub)
{
    ByteBuffer sbuf = ByteBuffer.wrap(sig);
    byte[] rawSig = new byte[sig.length - 4];
    sbuf.get(rawSig);
    IntegerPolynomial s = IntegerPolynomial.fromBinary(rawSig, params.N, params.q);
    int r = sbuf.getInt();
    return verify(createMsgRep(msgHash, r), s, pub.h);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:NTRUSigner.java


示例12: verify

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
private boolean verify(IntegerPolynomial i, IntegerPolynomial s, IntegerPolynomial h)
{
    int q = params.q;
    double normBoundSq = params.normBoundSq;
    double betaSq = params.betaSq;

    IntegerPolynomial t = h.mult(s, q);
    t.sub(i);
    long centeredNormSq = (long)(s.centeredNormSq(q) + betaSq * t.centeredNormSq(q));
    return centeredNormSq <= normBoundSq;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:12,代码来源:NTRUSigner.java


示例13: createMsgRep

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
protected IntegerPolynomial createMsgRep(byte[] msgHash, int r)
{
    int N = params.N;
    int q = params.q;

    int c = 31 - Integer.numberOfLeadingZeros(q);
    int B = (c + 7) / 8;
    IntegerPolynomial i = new IntegerPolynomial(N);

    ByteBuffer cbuf = ByteBuffer.allocate(msgHash.length + 4);
    cbuf.put(msgHash);
    cbuf.putInt(r);
    NTRUSignerPrng prng = new NTRUSignerPrng(cbuf.array(), params.hashAlg);

    for (int t = 0; t < N; t++)
    {
        byte[] o = prng.nextBytes(B);
        int hi = o[o.length - 1];
        hi >>= 8 * B - c;
        hi <<= 8 * B - c;
        o[o.length - 1] = (byte)hi;

        ByteBuffer obuf = ByteBuffer.allocate(4);
        obuf.put(o);
        obuf.rewind();
        // reverse byte order so it matches the endianness of java ints
        i.coeffs[t] = Integer.reverseBytes(obuf.getInt());
    }
    return i;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:31,代码来源:NTRUSigner.java


示例14: NTRUEncryptionPublicKeyParameters

import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial; //导入依赖的package包/类
/**
 * Constructs a new public key from a polynomial
 *
 * @param h      the polynomial <code>h</code> which determines the key
 * @param params the NtruEncrypt parameters to use
 */
public NTRUEncryptionPublicKeyParameters(IntegerPolynomial h, NTRUEncryptionParameters params)
{
    super(false, params);

    this.h = h;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:NTRUEncryptionPublicKeyParameters.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AopConfigException类代码示例发布时间:2022-05-22
下一篇:
Java Sampling类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap