![JAR search and dependency download from the Maven repository](/logo.png)
com.unbound.provider.UBSchnorrSignature Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.unbound.provider;
import com.unbound.client.Client;
import com.unbound.client.Partition;
import com.unbound.client.SignatureMode;
import com.unbound.client.SignatureOper;
import com.unbound.client.pkcs11.PKCS11Partition;
import com.unbound.client.pkcs11.PKCS11SignatureOper;
import com.unbound.common.crypto.EC;
import java.security.*;
import java.security.interfaces.ECPublicKey;
public class UBSchnorrSignature extends SignatureSpi
{
private final SignatureOper oper = Client.getInstance().newSignatureOperation();
private ECPublicKey pubKey = null;
UBSchnorrSignature()
{
oper.mode = SignatureMode.Schnorr;
}
@Override
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException
{
if (!(publicKey instanceof ECPublicKey)) throw new InvalidKeyException("Invalid key type");
if (EC.getCurve((ECPublicKey)publicKey)!=EC.P256k) throw new InvalidKeyException("Invalid curve");
pubKey = (ECPublicKey)publicKey;
oper.reset();
}
@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException
{
if (!(privateKey instanceof UBECPrivateKey)) throw new InvalidKeyException("Invalid key type");
if (EC.getCurve((UBECPrivateKey)privateKey)!=EC.P256k) throw new InvalidKeyException("Invalid curve");
oper.keyObject = ((UBECPrivateKey)privateKey).object;
}
@Override
protected void engineUpdate(byte b) throws SignatureException
{
oper.update(b);
}
@Override
protected void engineUpdate(byte[] in, int inOffset, int inLen) throws SignatureException
{
oper.update(in, inOffset, inLen);
}
@Override
protected byte[] engineSign() throws SignatureException
{
return oper.finalSign();
}
@Override
protected boolean engineVerify(byte[] sigBytes) throws SignatureException
{
return ((PKCS11SignatureOper)oper).verifySchnorr((PKCS11Partition)Partition.getDefault(), pubKey, sigBytes);
}
@Override
protected void engineSetParameter(String param, Object value) throws InvalidParameterException
{
throw new UnsupportedOperationException("setParameter() not supported");
}
@Override
protected Object engineGetParameter(String param) throws InvalidParameterException
{
throw new UnsupportedOperationException("getParameter() not supported");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy