Example usage for org.bouncycastle.crypto.generators Poly1305KeyGenerator clamp

List of usage examples for org.bouncycastle.crypto.generators Poly1305KeyGenerator clamp

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.generators Poly1305KeyGenerator clamp.

Prototype

public static void clamp(byte[] key) 

Source Link

Document

Modifies an existing 32 byte key value to comply with the requirements of the Poly1305 key by clearing required bits in the r (second 16 bytes) portion of the key.
Specifically:
  • r[3], r[7], r[11], r[15] have top four bits clear (i.e., are {0, 1, .

    Usage

    From source file:ch.lamacrypt.internal.crypto.CPCipher.java

    License:Open Source License

    /**
     * Initializes Poly1305 with the given instance of ChaCha20Engine
     *
     * @param cipher//from   w  w w.j a  va2s  .  c o m
     */
    private void initMAC(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());
        mac.init(macKey);
    }