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


Java Poly1305KeyGenerator.clamp方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.generators.Poly1305KeyGenerator.clamp方法的典型用法代码示例。如果您正苦于以下问题:Java Poly1305KeyGenerator.clamp方法的具体用法?Java Poly1305KeyGenerator.clamp怎么用?Java Poly1305KeyGenerator.clamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.generators.Poly1305KeyGenerator的用法示例。


在下文中一共展示了Poly1305KeyGenerator.clamp方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initRecordMAC

import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; //导入方法依赖的package包/类
protected KeyParameter initRecordMAC(ChaChaEngine cipher, boolean forEncryption, long seqNo)
{
    byte[] nonce = new byte[8];
    TlsUtils.writeUint64(seqNo, nonce, 0);

    cipher.init(forEncryption, new ParametersWithIV(null, nonce));

    byte[] firstBlock = new byte[64];
    cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0);

    // NOTE: The BC implementation puts 'r' after 'k'
    System.arraycopy(firstBlock, 0, firstBlock, 32, 16);
    KeyParameter macKey = new KeyParameter(firstBlock, 16, 32);
    Poly1305KeyGenerator.clamp(macKey.getKey());
    return macKey;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:Chacha20Poly1305.java

示例2: TestCase

import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; //导入方法依赖的package包/类
public TestCase(String key, String nonce, String message, String expectedMac)
{
    this.key = Hex.decode(key);
    // nacl test case keys are not pre-clamped
    Poly1305KeyGenerator.clamp(this.key);
    this.nonce = (nonce == null) ? null : Hex.decode(nonce);
    this.message = Hex.decode(message);
    this.expectedMac = Hex.decode(expectedMac);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:10,代码来源:Poly1305Test.java

示例3: initRecordMAC

import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; //导入方法依赖的package包/类
private KeyParameter initRecordMAC(ChaChaEngine cipher)
{
    byte[] firstBlock = new byte[64];
    cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0);

    // NOTE: The BC implementation puts 'r' after 'k'
    System.arraycopy(firstBlock, 0, firstBlock, 32, 16);
    KeyParameter macKey = new KeyParameter(firstBlock, 16, 32);
    Poly1305KeyGenerator.clamp(macKey.getKey());
    return macKey;
}
 
开发者ID:beowulfe,项目名称:HAP-Java,代码行数:12,代码来源:ChachaDecoder.java

示例4: computeMAC

import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; //导入方法依赖的package包/类
/**
 * Computes the MAC of the specified length for the given share with the given key.
 *
 * @param data the data to create the MAC for
 * @param key the key to use for computing the MAC
 * @return the message authentication code (tag or MAC) for this share
 * @throws InvalidKeyException thrown if an InvalidKeyException occurred
 */
@Override
public byte[] computeMAC(byte[] data, byte[] key) throws InvalidKeyException {

    byte[] result = new byte[mac.getMacSize()];

    Poly1305KeyGenerator.clamp(key);

    mac.init(new KeyParameter(key));
    mac.update(data, 0, data.length);
    mac.doFinal(result, 0);
    return result;
}
 
开发者ID:Archistar,项目名称:archistar-smc,代码行数:21,代码来源:BCPoly1305MacHelper.java

示例5: verifyMAC

import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; //导入方法依赖的package包/类
/**
 * Verifies the given MAC.<br>
 * (recomputes the tag from share and key and compares it with the given tag)
 *
 * @param data the data to verify the MAC for
 * @param tag the tag to verify
 * @param key the key to use for verification
 * @return true if verification was successful (the tags matched); false otherwise
 */
@Override
public boolean verifyMAC(byte[] data, byte[] tag, byte[] key) {
    boolean valid = false;

    Poly1305KeyGenerator.clamp(key);

    try {
        byte[] newTag = computeMAC(data, key); // compute tag for the given parameters
        valid = Arrays.equals(tag, newTag); // compare with original tag
    } catch (InvalidKeyException e) {
    }

    return valid;
}
 
开发者ID:Archistar,项目名称:archistar-smc,代码行数:24,代码来源:BCPoly1305MacHelper.java

示例6: testSequential

import org.bouncycastle.crypto.generators.Poly1305KeyGenerator; //导入方法依赖的package包/类
private void testSequential()
{
    // Sequential test, adapted from test-poly1305aes
    int len;
    byte[] kr = new byte[32];
    byte[] m = new byte[MAXLEN];
    byte[] n = new byte[16];
    byte[] out = new byte[16];

    int c = 0;
    final Mac mac = new Poly1305(new AESFastEngine());
    for (int loop = 0; loop < 13; loop++)
    {
        len = 0;
        for (;;)
        {
            c++;
            mac.init(new ParametersWithIV(new KeyParameter(kr), n));
            mac.update(m, 0, len);
            mac.doFinal(out, 0);

            // if (c == 678)
            // {
            // TestCase tc = CASES[0];
            //
            // if (!Arrays.areEqual(tc.key, kr))
            // {
            // System.err.println("Key bad");
            // System.err.println(new String(Hex.encode(tc.key)));
            // System.err.println(new String(Hex.encode(kr)));
            // System.exit(1);
            // }
            // if (!Arrays.areEqual(tc.nonce, n))
            // {
            // System.err.println("Nonce bad");
            // System.exit(1);
            // }
            // System.out.printf("[%d] m: %s\n", c, new String(Hex.encode(m, 0, len)));
            // System.out.printf("[%d] K: %s\n", c, new String(Hex.encodje(kr)));
            // System.out.printf("[%d] N: %s\n", c, new String(Hex.encode(n)));
            // System.out.printf("[%d] M: ", c);
            // }
            // System.out.printf("%d/%s\n", c, new String(Hex.encode(out)));

            if (len >= MAXLEN)
                break;
            n[0] ^= loop;
            for (int i = 0; i < 16; ++i)
                n[i] ^= out[i];
            if (len % 2 != 0)
                for (int i = 0; i < 16; ++i)
                    kr[i] ^= out[i];
            if (len % 3 != 0)
                for (int i = 0; i < 16; ++i)
                    kr[i + 16] ^= out[i];
            Poly1305KeyGenerator.clamp(kr);
            m[len++] ^= out[0];
        }
    }
    // Output after 13 loops as generated by poly1305 ref
    if (c != 13013 || !Arrays.areEqual(out, Hex.decode("c96f60a23701a5b0fd2016f58cbe4f7e")))
    {
        fail("Sequential Poly1305 " + c, "c96f60a23701a5b0fd2016f58cbe4f7e", new String(Hex.encode(out)));
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:66,代码来源:Poly1305Test.java


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