![JAR search and dependency download from the Maven repository](/logo.png)
org.bouncycastle.crypto.fips.Ed448Signer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bc-fips-debug Show documentation
Show all versions of bc-fips-debug Show documentation
The FIPS 140-2 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-2 level 1. This jar contains the debug version JCE provider and low-level API for the BC-FJA version 1.0.2.3, FIPS Certificate #3514. Please note the debug jar is not certified.
package org.bouncycastle.crypto.fips;
import org.bouncycastle.crypto.internal.CipherParameters;
import org.bouncycastle.crypto.internal.Signer;
import org.bouncycastle.crypto.internal.Xof;
import org.bouncycastle.math.ec.rfc8032.Ed448;
import org.bouncycastle.util.Arrays;
import java.io.ByteArrayOutputStream;
class Ed448Signer
implements Signer
{
private final Buffer buffer = new Buffer();
private final byte[] context;
private boolean forSigning;
private Ed448PrivateKeyParameters privateKey;
private Ed448PublicKeyParameters publicKey;
public Ed448Signer(byte[] context)
{
this.context = Arrays.clone(context);
}
public void init(boolean forSigning, CipherParameters parameters)
{
this.forSigning = forSigning;
if (forSigning)
{
this.privateKey = (Ed448PrivateKeyParameters)parameters;
this.publicKey = null;
}
else
{
this.privateKey = null;
this.publicKey = (Ed448PublicKeyParameters)parameters;
}
reset();
}
public void update(byte b)
{
buffer.write(b);
}
public void update(byte[] buf, int off, int len)
{
buffer.write(buf, off, len);
}
public byte[] generateSignature()
{
if (!forSigning || null == privateKey)
{
throw new IllegalStateException("Ed448Signer not initialised for signature generation.");
}
return buffer.generateSignature(privateKey, context);
}
public boolean verifySignature(byte[] signature)
{
if (forSigning || null == publicKey)
{
throw new IllegalStateException("Ed448Signer not initialised for verification");
}
return buffer.verifySignature(publicKey, context, signature);
}
public void reset()
{
buffer.reset();
}
private static class Buffer
extends ByteArrayOutputStream
{
private final Ed448 ed448 = new Ed448()
{
@Override
protected Xof createXof()
{
return (Xof) FipsSHS.createDigest(FipsSHS.Algorithm.SHAKE256);
}
};
synchronized byte[] generateSignature(Ed448PrivateKeyParameters privateKey, byte[] ctx)
{
byte[] signature = new byte[Ed448PrivateKeyParameters.SIGNATURE_SIZE];
privateKey.sign(Ed448.Algorithm.Ed448, ctx, buf, 0, count, signature, 0);
reset();
return signature;
}
synchronized boolean verifySignature(Ed448PublicKeyParameters publicKey, byte[] ctx, byte[] signature)
{
if (Ed448.SIGNATURE_SIZE != signature.length)
{
reset();
return false;
}
byte[] pk = publicKey.getEncoded();
boolean result = ed448.verify(signature, 0, pk, 0, ctx, buf, 0, count);
reset();
return result;
}
public synchronized void reset()
{
Arrays.fill(buf, 0, count, (byte)0);
this.count = 0;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy