Skip to content

Commit

Permalink
feat: Add some parameter checks
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Jan 9, 2024
1 parent 7645152 commit c27c0f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public Bls12381G1_BBSPlus_PrivateKeySigner(KeyPair privateKey) {
@Override
public byte[] sign(byte[] content) throws GeneralSecurityException {

if (Bbs.getSecretKeySize() != this.getPrivateKey().secretKey.length) throw new IllegalArgumentException("Secret key size is not " + Bbs.getSecretKeySize() + ": " + this.getPrivateKey().secretKey.length);
if (Bbs.getBls12381G1PublicKeySize() != this.getPrivateKey().publicKey.length) throw new IllegalArgumentException("Public key size is not " + Bbs.getBls12381G1PublicKeySize() + ": " + this.getPrivateKey().publicKey.length);

try {

return Bbs.blsSign(this.getPrivateKey().secretKey, this.getPrivateKey().publicKey, new byte[][] { content });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public Bls12381G1_BBSPlus_PublicKeyVerifier(KeyPair publicKey) {
@Override
public boolean verify(byte[] content, byte[] signature) throws GeneralSecurityException {

if (Bbs.getBls12381G1PublicKeySize() != this.getPublicKey().publicKey.length) throw new IllegalArgumentException("Public key size is not " + Bbs.getBls12381G1PublicKeySize() + ": " + this.getPublicKey().publicKey.length);
if (Bbs.getSignatureSize() != signature.length) throw new IllegalArgumentException("Signature size is not " + Bbs.getSignatureSize() + ": " + signature.length);

try {

return Bbs.blsVerify(this.getPublicKey().publicKey, signature, new byte[][] { content });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public Bls12381G2_BBSPlus_PrivateKeySigner(KeyPair privateKey) {
@Override
public byte[] sign(byte[] content) throws GeneralSecurityException {

if (Bbs.getSecretKeySize() != this.getPrivateKey().secretKey.length) throw new IllegalArgumentException("Secret key size is not " + Bbs.getSecretKeySize() + ": " + this.getPrivateKey().secretKey.length);
if (Bbs.getBls12381G2PublicKeySize() != this.getPrivateKey().publicKey.length) throw new IllegalArgumentException("Public key size is not " + Bbs.getBls12381G2PublicKeySize() + ": " + this.getPrivateKey().publicKey.length);

try {

return Bbs.blsSign(this.getPrivateKey().secretKey, this.getPrivateKey().publicKey, new byte[][] { content });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public Bls12381G2_BBSPlus_PublicKeyVerifier(KeyPair publicKey) {
@Override
public boolean verify(byte[] content, byte[] signature) throws GeneralSecurityException {

if (Bbs.getBls12381G2PublicKeySize() != this.getPublicKey().publicKey.length) throw new IllegalArgumentException("Public key size is not " + Bbs.getBls12381G2PublicKeySize() + ": " + this.getPublicKey().publicKey.length);
if (Bbs.getSignatureSize() != signature.length) throw new IllegalArgumentException("Signature size is not " + Bbs.getSignatureSize() + ": " + signature.length);

try {

return Bbs.blsVerify(this.getPublicKey().publicKey, signature, new byte[][] { content });
Expand Down

0 comments on commit c27c0f9

Please sign in to comment.