Example usage for org.bouncycastle.crypto.digests Blake2bDigest Blake2bDigest

List of usage examples for org.bouncycastle.crypto.digests Blake2bDigest Blake2bDigest

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.digests Blake2bDigest Blake2bDigest.

Prototype

public Blake2bDigest() 

Source Link

Usage

From source file:cologne.eck.peafactory.crypto.kdf.Catena.java

License:Open Source License

/**
 * Use Catena as key derivation function to
 * derive a cryptographic key with arbitrary length. 
 * /*  w  ww  .j  a va 2s . co  m*/
 * @param pwd         the password
 * @param salt         the salt
 * @param data         the associated data 
 * @param lambda      the depth of the graph
 * @param min_garlic   min. cost parameter
 * @param garlic      the cost parameter
 * @param key_id      the key identifier
 * @param key         the result key, the length 
 *                   of the vector indicates the 
 *                   length of the result key
 */
public void deriveKey(byte[] pwd, byte[] salt, byte[] data, int lambda, int min_garlic, int garlic, int key_id,
        byte[] key) {

    byte[] hash = new byte[H_LEN];
    int keylen = key.length;
    int len = keylen / H_LEN;
    int rest = keylen % H_LEN;
    long i;
    if (digest == null) {
        digest = new Blake2bDigest();
    }
    // default is FULL
    if (reducedDigest == null) {
        fast = false;
        //reducedDigest = digest;
    } else {
        fast = true;
    }
    catena(pwd, salt, data, lambda, min_garlic, garlic, H_LEN, REGULAR, KEY_DERIVATION_MODE, hash);

    for (i = 0; i < len; i++) {

        long tmp = i;
        digest.update((byte) 0);
        update(long2bytesLE(tmp));
        digest.update((byte) key_id);
        update(int2bytesLE(keylen));
        update(hash);
        digest.doFinal(key, (int) i * H_LEN);
        digest.reset();
    }

    if (rest > 0) {

        long tmp = i;// TO_LITTLE_ENDIAN_64(i);
        digest.update((byte) 0);
        update(long2bytesLE(tmp));
        digest.update((byte) key_id);
        update(int2bytesLE(keylen));
        update(hash);
        digest.doFinal(hash, 0);
        digest.reset();
        System.arraycopy(hash, 0, key, len * H_LEN, rest);
    }
}

From source file:cologne.eck.peafactory.crypto.kdf.Catena.java

License:Open Source License

/**
 * Initializes the digests. /*from   w  ww.j a va  2  s  .  c o m*/
 */
private void initDigests() {
    if (digest == null) {
        digest = new Blake2bDigest();
    }
    if (reducedDigest == null) {
        if (fast == true) {
            reducedDigest = new Catena_Blake2b_1();
        } else {
            //
        }
    }
}

From source file:cologne.eck.peafactory.gui.Menu.java

License:Open Source License

@Override
public void actionPerformed(ActionEvent ape) {

    //JComponent source = (JComponent) ape.getSource();
    String command = ape.getActionCommand();

    //Menu//w  w  w .java 2s. c  om
    if (command.equals("newProject")) {
        ProjectSelection proj = new ProjectSelection();
        Point p = MainView.getFrameLocation();
        proj.setLocation((int) p.getX() + 100, (int) p.getY() + 60);
        proj.setVisible(true);
    } else if (command.equals("randomPassword")) {
        PasswordGeneratorDialog pg = new PasswordGeneratorDialog(PeaFactory.getFrame());
        pg.setVisible(true);
    } else if (command.equals("keyboard")) {
        int input = JOptionPane.showConfirmDialog(PeaFactory.getFrame(),
                languageBundle.getString("add_keyboard"), " ", JOptionPane.YES_NO_OPTION);
        if (input == 0) {
            FileModifier.setSetKeyboard(true);
        } else {
            FileModifier.setSetKeyboard(false);
        }
    } else if (command.equals("psw_generator")) {
        int input = JOptionPane.showConfirmDialog(PeaFactory.getFrame(),
                languageBundle.getString("add_psw_generator"), " ", JOptionPane.YES_NO_OPTION);
        if (input == 0) {
            FileModifier.setPswGenerator(true);
        } else {
            FileModifier.setPswGenerator(false);
        }
    } else if (command.equals("quit")) {
        System.exit(0);

    } else if (command.equals("generalPeaSettings")) {

        @SuppressWarnings("unused")
        GeneralPeaSettings imageSetting = new GeneralPeaSettings();

    } else if (command.equals("setThoughtless")) {
        securityLevel = 1;
        setSecurityLevel(1);
    } else if (command.equals("setLow")) {
        securityLevel = 2;
        setSecurityLevel(2);
    } else if (command.equals("setStandard")) {
        securityLevel = 3;
        setSecurityLevel(3);
    } else if (command.equals("setHigh")) {
        securityLevel = 4;
        setSecurityLevel(4);
    } else if (command.equals("setParanoid")) {
        securityLevel = 5;
        setSecurityLevel(5);

    } else if (command.equals("setBcrypt")) {
        setSecurityLevel(securityLevel);
        KeyDerivation.setKdf(new BcryptKDF());
    } else if (command.equals("setScrypt")) {
        setSecurityLevel(securityLevel);
        KeyDerivation.setKdf(new ScryptKDF());
    } else if (command.equals("setDragonfly")) {
        setSecurityLevel(securityLevel);
        CatenaKDF.setVersionID("Dragonfly-Full");
        KeyDerivation.setKdf(new CatenaKDF());
    } else if (command.equals("setButterfly")) {
        setSecurityLevel(securityLevel);
        CatenaKDF.setVersionID("Butterfly-Full");
        KeyDerivation.setKdf(new CatenaKDF());
    } else if (command.equals("setPomelo")) {
        setSecurityLevel(securityLevel);
        KeyDerivation.setKdf(new PomeloKDF());

    } else if (command.equals("setBcryptParameters")) {

        @SuppressWarnings("unused")
        BcryptSetting bcryptSetting = new BcryptSetting();

    } else if (command.equals("setPomeloParameters")) {

        @SuppressWarnings("unused")
        PomeloSetting pomeloSetting = new PomeloSetting();

    } else if (command.equals("setScryptParameters")) {

        @SuppressWarnings("unused")
        ScryptSetting scryptSetting = new ScryptSetting();

    } else if (command.equals("setCatenaParameters")) {

        @SuppressWarnings("unused")
        CatenaSetting catenaSetting = new CatenaSetting();

    } else if (command.equals("setImageParameters")) {

        @SuppressWarnings("unused")
        ImageSetting imageSetting = new ImageSetting();

    } else if (command.equals("setShacal2")) {
        CipherStuff.setCipherAlgo(new Shacal2Engine());
    } else if (command.equals("setThreefish256")) {
        CipherStuff.setCipherAlgo(new ThreefishEngine(256));
    } else if (command.equals("setThreefish512")) {
        CipherStuff.setCipherAlgo(new ThreefishEngine(512));
    } else if (command.equals("setThreefish1024")) {
        CipherStuff.setCipherAlgo(new ThreefishEngine(1024));
    } else if (command.equals("setTwofish")) {
        CipherStuff.setCipherAlgo(new TwofishEngine());
    } else if (command.equals("setSerpent")) {
        CipherStuff.setCipherAlgo(new SerpentEngine());
    } else if (command.equals("setAES")) {
        CipherStuff.setCipherAlgo(new AESEngine());
    } else if (command.equals("setAESFast")) {
        CipherStuff.setCipherAlgo(new AESFastEngine());

        // hash function:
    } else if (command.equals("setWhirlpool")) {
        HashStuff.setHashAlgo(new WhirlpoolDigest());
    } else if (command.equals("setKeccak")) {
        HashStuff.setHashAlgo(new SHA3Digest());
    } else if (command.equals("setSha512")) {
        HashStuff.setHashAlgo(new SHA512Digest());
    } else if (command.equals("setSha384")) {
        HashStuff.setHashAlgo(new SHA384Digest());
    } else if (command.equals("setSkein512")) {
        HashStuff.setHashAlgo(new SkeinDigest(512, 512));
    } else if (command.equals("setBlake512")) {
        HashStuff.setHashAlgo(new Blake2bDigest());
        //      } else if (command.equals("setRipemd256")) {
        //         HashStuff.setHashAlgo( new RIPEMD256Digest() );          
    } else if (command.equals("setRipemd320")) {
        HashStuff.setHashAlgo(new RIPEMD320Digest());

    } else if (command.equals("setDE")) {
        PeaFactory.setI18n("de");
    } else if (command.equals("setEN")) {
        PeaFactory.setI18n("en");

    } else if (command.equals("notes")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("notes_description"), null, "notes");
    } else if (command.equals("editor")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("editor_description"), null, "editor");
    } else if (command.equals("image")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("image_description"), null, "image");
    } else if (command.equals("keyboard_info")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog("Onscreen Keyboard", null, "keyboard");
    } else if (command.equals("file")) {
        @SuppressWarnings("unused")
        InfoDialog info = new InfoDialog(languageBundle.getString("file_description"), null, "file");

    } else if (command.equals("problemHelp")) {
        JOptionPane pane = new JOptionPane(languageBundle.getString("problem_help_dialog"),
                JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION, null, null);//new ImageIcon(PswDialogView.getImage()), null);
        pane.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
        //pane.setIconImage(PswDialogView.getImage());
        pane.setVisible(true);
        //pane.showMessageDialog(null, languageBundle.getString("problem_help_dialog"), null, JOptionPane.PLAIN_MESSAGE);
    } else if (command.equals("howToUse")) {
        JOptionPane.showMessageDialog(PeaFactory.getFrame(), languageBundle.getString("how_to_use_dialog"),
                null, JOptionPane.PLAIN_MESSAGE);
    } else if (command.equals("aboutLicense")) {
        JOptionPane.showMessageDialog(PeaFactory.getFrame(), languageBundle.getString("about_license_dialog"),
                null, JOptionPane.PLAIN_MESSAGE);
    }
}