All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.digests.AsconXof128 Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.

The newest version!
package org.bouncycastle.crypto.digests;

import org.bouncycastle.crypto.Xof;
import org.bouncycastle.util.Pack;

/**
 * Ascon-XOF128 was introduced in NIST Special Publication (SP) 800-232
 * (Initial Public Draft).
 * 

* Additional details and the specification can be found in: * NIST SP 800-232 (Initial Public Draft). * For reference source code and implementation details, please see: * Reference, highly optimized, masked C and * ASM implementations of Ascon (NIST SP 800-232). *

*/ public class AsconXof128 extends AsconBaseDigest implements Xof { private boolean m_squeezing = false; public AsconXof128() { reset(); } protected long pad(int i) { return 0x01L << (i << 3); } protected long loadBytes(final byte[] bytes, int inOff) { return Pack.littleEndianToLong(bytes, inOff); } protected long loadBytes(final byte[] bytes, int inOff, int n) { return Pack.littleEndianToLong(bytes, inOff, n); } protected void setBytes(long w, byte[] bytes, int inOff) { Pack.longToLittleEndian(w, bytes, inOff); } protected void setBytes(long w, byte[] bytes, int inOff, int n) { Pack.longToLittleEndian(w, bytes, inOff, n); } protected void padAndAbsorb() { m_squeezing = true; super.padAndAbsorb(); } public String getAlgorithmName() { return "Ascon-XOF-128"; } public void update(byte in) { if (m_squeezing) { throw new IllegalArgumentException("attempt to absorb while squeezing"); } super.update(in); } public void update(byte[] input, int inOff, int len) { if (m_squeezing) { throw new IllegalArgumentException("attempt to absorb while squeezing"); } super.update(input, inOff, len); } public int doOutput(byte[] output, int outOff, int outLen) { return hash(output, outOff, outLen); } public int doFinal(byte[] output, int outOff, int outLen) { int rlt = doOutput(output, outOff, outLen); reset(); return rlt; } public int getByteLength() { return 8; } public void reset() { m_squeezing = false; super.reset(); /* initialize */ x0 = -2701369817892108309L; x1 = -3711838248891385495L; x2 = -1778763697082575311L; x3 = 1072114354614917324L; x4 = -2282070310009238562L; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy