100 lines
1.8 KiB
C#
100 lines
1.8 KiB
C#
using System;
|
|
using System.Threading;
|
|
namespace sharp.hashing.SHA3
|
|
{
|
|
public class Keccak : HashBase
|
|
{
|
|
struct keccak_1600_std {
|
|
public readonly int output_size;
|
|
public readonly int r, c;
|
|
|
|
public keccak_1600_std(int output_size,int r,int c){
|
|
this.output_size = output_size;
|
|
this.r = r;
|
|
this.c = c;
|
|
}
|
|
};
|
|
|
|
keccak_1600_std[] std1600 = {
|
|
new keccak_1600_std(224,1152,448),
|
|
new keccak_1600_std(256,1088,512),
|
|
new keccak_1600_std(384,832,768),
|
|
new keccak_1600_std(512,576,1024)
|
|
};
|
|
|
|
private int output_size,r, c;
|
|
|
|
|
|
public Keccak(int size)
|
|
{
|
|
foreach (keccak_1600_std std in std1600){
|
|
if (std.output_size == size){
|
|
this.r = std.r;
|
|
this.c = std.c;
|
|
this.output_size = std.output_size;
|
|
}
|
|
}
|
|
|
|
if (this.output_size != size){
|
|
throw new ArgumentException("No Standard Parameters for that Output Size defined!");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public override byte[] compute(byte[] data)
|
|
{
|
|
byte[] result = null;
|
|
|
|
Monitor.Enter(this);
|
|
|
|
|
|
|
|
Monitor.Exit(this);
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private UInt64[] RC = {
|
|
0x0000000000000001,
|
|
0x0000000000008082,
|
|
0x800000000000808A,
|
|
0x8000000080008000,
|
|
0x000000000000808B,
|
|
0x0000000080000001,
|
|
0x8000000080008081,
|
|
0x8000000000008009,
|
|
0x000000000000008A,
|
|
0x0000000000000088,
|
|
0x0000000080008009,
|
|
0x000000008000000A,
|
|
0x000000008000808B,
|
|
0x800000000000008B,
|
|
0x8000000000008089,
|
|
0x8000000000008003,
|
|
0x8000000000008002,
|
|
0x8000000000000080,
|
|
0x000000000000800A,
|
|
0x800000008000000A,
|
|
0x8000000080008081,
|
|
0x8000000000008080,
|
|
0x0000000080000001,
|
|
0x8000000080008008
|
|
};
|
|
|
|
// RO[y][x]
|
|
private int[][] RO = {
|
|
new int[]{03,10,43,25,39},
|
|
new int[]{36,44,06,55,20},
|
|
new int[]{00,01,62,28,27},
|
|
new int[]{18,02,61,56,14},
|
|
new int[]{41,45,15,21,08}
|
|
};
|
|
|
|
}
|
|
}
|