/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.common.crypto;

import org.bitcoinj.core.Utils;

import com.google.common.base.Charsets;

import org.spongycastle.crypto.digests.RIPEMD160Digest;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import java.nio.ByteBuffer;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Hash {

    /**
     * @param data Data as byte array
     * @return Hash of data
     */
    public static byte[] getSha256Hash(byte[] data) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            digest.update(data, 0, data.length);
            return digest.digest();
        } catch (NoSuchAlgorithmException e) {
            log.error("Could not create MessageDigest for hash. " + e.toString());
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * @param message UTF-8 encoded message
     * @return Hash of data
     */
    public static byte[] getSha256Hash(String message) {
        return getSha256Hash(message.getBytes(Charsets.UTF_8));
    }

    /**
     * @param data data as Integer
     * @return Hash of data
     */
    public static byte[] getSha256Hash(Integer data) {
        return getSha256Hash(ByteBuffer.allocate(4).putInt(data).array());
    }

    /**
     * Calculates RIPEMD160(SHA256(data)).
     */
    public static byte[] getSha256Ripemd160hash(byte[] data) {
        return Utils.sha256hash160(data);
    }

    /**
     * Calculates RIPEMD160(data).
     */
    public static byte[] getRipemd160hash(byte[] data) {
        RIPEMD160Digest digest = new RIPEMD160Digest();
        digest.update(data, 0, data.length);
        byte[] out = new byte[20];
        digest.doFinal(out, 0);
        return out;
    }
}


@@ -2446,12 +2446,779 @@
 t;%0A    %7D
+%0A%0A    /**%0A     * @param data Data as byte array%0A     * @return Hash of data%0A     */%0A    public static byte%5B%5D getSha3_256Hash(byte%5B%5D data) %7B%0A        try %7B%0A            MessageDigest digest = MessageDigest.getInstance(%22SHA3-256%22);%0A            digest.update(data, 0, data.length);%0A            return digest.digest();%0A        %7D catch (NoSuchAlgorithmException e) %7B%0A            log.error(%22Could not create MessageDigest for hash. %22 + e.toString());%0A            e.printStackTrace();%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Calculates RIPEMD160(SHA3-256(data)).%0A     */%0A    public static byte%5B%5D getSha3_256Ripemd160hash(byte%5B%5D data) %7B%0A        byte%5B%5D sha3_256Hash = getSha3_256Hash(data);%0A        return getRipemd160hash(sha3_256Hash);%0A    %7D
 %0A%7D%0A%0A

Add SHA3-256 hash function