Skip to content

Initial implementation of Threefish + Skein #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions core/src/main/java/org/bouncycastle/crypto/digests/SkeinDigest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.bouncycastle.crypto.digests;

import org.bouncycastle.crypto.ExtendedDigest;
import org.bouncycastle.crypto.engines.ThreefishEngine;
import org.bouncycastle.crypto.params.SkeinParameters;
import org.bouncycastle.util.Memoable;

/**
* Implementation of the Skein parameterised hash function in 256, 512 and 1024 bit block sizes,
* based on the {@link ThreefishEngine Threefish} tweakable block cipher.
* <p>
* This is the 1.3 version of Skein defined in the Skein hash function submission to the NIST SHA-3
* competition in October 2010.
* <p>
* Skein was designed by Niels Ferguson - Stefan Lucks - Bruce Schneier - Doug Whiting - Mihir
* Bellare - Tadayoshi Kohno - Jon Callas - Jesse Walker.
* <p>
*
* @see SkeinEngine
* @see SkeinParameters
*/
public class SkeinDigest implements ExtendedDigest, Memoable
{
/** 256 bit block size - Skein-256 */
public static final int SKEIN_256 = SkeinEngine.SKEIN_256;
/** 512 bit block size - Skein-512 */
public static final int SKEIN_512 = SkeinEngine.SKEIN_512;
/** 1024 bit block size - Skein-1024 */
public static final int SKEIN_1024 = SkeinEngine.SKEIN_1024;

private SkeinEngine engine;

/**
* Constructs a Skein digest with an internal state size and output size.
*
* @param stateSizeBits
* the internal state size in bits - one of {@link #SKEIN_256}, {@link #SKEIN_512} or
* {@link #SKEIN_1024}.
* @param digestSizeBits
* the output/digest size to produce in bits, which must be an integral number of
* bytes.
*/
public SkeinDigest(int stateSizeBits, int digestSizeBits)
{
this.engine = new SkeinEngine(stateSizeBits, digestSizeBits);
init(null);
}

public SkeinDigest(SkeinDigest digest)
{
this.engine = new SkeinEngine(digest.engine);
}

public void reset(Memoable other)
{
SkeinDigest d = (SkeinDigest)other;
engine.reset(d.engine);
}

public Memoable copy()
{
return new SkeinDigest(this);
}

public String getAlgorithmName()
{
return "Skein-" + (engine.getBlockSize() * 8) + "-" + (engine.getOutputSize() * 8);
}

public int getDigestSize()
{
return engine.getOutputSize();
}

public int getByteLength()
{
return engine.getBlockSize();
}

/**
* Optionally initialises the Skein digest with the provided parameters.<br>
* See {@link SkeinParameters} for details on the parameterisation of the Skein hash function.
*
* @param params
* the parameters to apply to this engine, or <code>null</code> to use no parameters.
*/
public void init(SkeinParameters params)
{
engine.init(params);
}

public void reset()
{
engine.reset();
}

public void update(byte in)
{
engine.update(in);
}

public void update(byte[] in, int inOff, int len)
{
engine.update(in, inOff, len);
}

public int doFinal(byte[] out, int outOff)
{
return engine.doFinal(out, outOff);
}

}
Loading