Skip to content

Commit

Permalink
removed use of byte array output stream as no longer required.
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Sep 15, 2024
1 parent 32ba114 commit 5f87ffc
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.bouncycastle.jcajce.provider.asymmetric.mldsa;

import java.io.ByteArrayOutputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
Expand All @@ -18,15 +17,13 @@
public class SignatureSpi
extends java.security.Signature
{
private ByteArrayOutputStream bOut;
private MLDSASigner signer;
private MLDSAParameters parameters;

protected SignatureSpi(MLDSASigner signer)
{
super("MLDSA");

this.bOut = new ByteArrayOutputStream();
this.signer = signer;
this.parameters = null;
}
Expand All @@ -35,7 +32,6 @@ protected SignatureSpi(MLDSASigner signer, MLDSAParameters parameters)
{
super(MLDSAParameterSpec.fromName(parameters.getName()).getName());

this.bOut = new ByteArrayOutputStream();
this.signer = signer;
this.parameters = parameters;
}
Expand Down Expand Up @@ -109,26 +105,20 @@ protected void engineInitSign(PrivateKey privateKey)
protected void engineUpdate(byte b)
throws SignatureException
{
bOut.write(b);
signer.update(b);
}

protected void engineUpdate(byte[] b, int off, int len)
throws SignatureException
{
bOut.write(b, off, len);
signer.update(b, off, len);
}

protected byte[] engineSign()
throws SignatureException
{
try
{
byte[] message = bOut.toByteArray();

bOut.reset();

signer.update(message, 0, message.length);

return signer.generateSignature();
}
catch (Exception e)
Expand All @@ -140,12 +130,6 @@ protected byte[] engineSign()
protected boolean engineVerify(byte[] sigBytes)
throws SignatureException
{
byte[] message = bOut.toByteArray();

bOut.reset();

signer.update(message, 0, message.length);

return signer.verifySignature(sigBytes);
}

Expand Down

0 comments on commit 5f87ffc

Please sign in to comment.