【发布时间】:2018-07-13 04:58:14
【问题描述】:
我正在开发一个基于 cryptonight 算法的 Java 加密货币矿工应用程序。
我正在尝试基于此文档实现哈希函数:https://cryptonote.org/cns/cns008.txt
我的代码:
public byte[] mine(String hash) {
byte[] out = hash.getBytes();
out = doKeccak(out);
//Make key
byte[] key = new byte[32];
System.arraycopy(out, 0, key, 0, 32);
//Make blocks
byte[][] blocks = new byte[8][];
for (int i = 0; i < 8; ++i)
System.arraycopy(out, 64 + 16 * i, blocks[i], 0, 16);
byte[][] keys = new byte[11][];
keys[0]=key;
for (int i = 0; i < 10; ++i) {
keys[i+1]=new byte[32];
Rijndael.expandKey(keys[i], keys[i+1], 0, 32, 32);
}
//byte[] pad = new byte[2097152];
//Encrypt blocks
for (int bid = 0; bid < 8; ++bid) {
for (int i = 0; i < 10; ++i) {
blocks[bid] = AES.encrypt(blocks[i], keys[i+1]);
}
}
return Utils.byteToHex(out);
}
Rijndael.expandKey 方法的用法如下:public static void expandKey(byte[] key, byte[] out, int offset, int keySize, int expKeySize)
我应该在扩展密钥大小中输入什么数字?我在文档中看不到,这就是我在这里问的原因。
【问题讨论】:
标签: java algorithm hash cryptography aes