Skip to content

Commit b1b1b3a

Browse files
committed
PGPOnePassSignature: check salt size
1 parent 204cb7c commit b1b1b3a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPOnePassSignature.java

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.bouncycastle.bcpg.BCPGInputStream;
88
import org.bouncycastle.bcpg.BCPGOutputStream;
9+
import org.bouncycastle.bcpg.HashUtils;
910
import org.bouncycastle.bcpg.OnePassSignaturePacket;
1011
import org.bouncycastle.bcpg.Packet;
1112
import org.bouncycastle.bcpg.SignaturePacket;
@@ -65,9 +66,26 @@ public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPP
6566
lastb = 0;
6667
sigOut = verifier.getOutputStream();
6768

69+
checkSaltSize();
6870
updateWithSalt();
6971
}
7072

73+
private void checkSaltSize()
74+
throws PGPException
75+
{
76+
if (getVersion() != SignaturePacket.VERSION_6)
77+
{
78+
return;
79+
}
80+
81+
int expectedSaltSize = HashUtils.getV6SignatureSaltSizeInBytes(getHashAlgorithm());
82+
if (expectedSaltSize != getSalt().length)
83+
{
84+
throw new PGPException("RFC9580 defines the salt size for " + PGPUtil.getDigestName(getHashAlgorithm()) +
85+
" as " + expectedSaltSize + " octets, but signature has " + getSalt().length + " octets.");
86+
}
87+
}
88+
7189
private void updateWithSalt()
7290
throws PGPException
7391
{

0 commit comments

Comments
 (0)