Skip to content

Commit 313d368

Browse files
committed
rolled back accidental commit.
1 parent 521bb63 commit 313d368

File tree

7 files changed

+40
-96
lines changed

7 files changed

+40
-96
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private byte[] getEncodedPublicKey(
132132
return keyBytes;
133133
}
134134

135-
protected void getAttributesHash(PGPUserAttributeSubpacketVector userAttributes)
135+
protected void getAttriubtesHash(PGPUserAttributeSubpacketVector userAttributes)
136136
throws PGPException
137137
{
138138
//

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ boolean doVerifyCertification(
220220
{
221221
updateWithPublicKey(key);
222222

223-
getAttributesHash(userAttributes);
223+
getAttriubtesHash(userAttributes);
224224

225225
addTrailer();
226226

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public PGPSignature generateCertification(
240240
{
241241
updateWithPublicKey(pubKey);
242242

243-
getAttributesHash(userAttributes);
243+
getAttriubtesHash(userAttributes);
244244

245245
return this.generate();
246246
}

pg/src/main/java/org/bouncycastle/openpgp/operator/PBEKeyEncryptionMethodGenerator.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
import org.bouncycastle.bcpg.S2K;
88
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
99
import org.bouncycastle.bcpg.SymmetricKeyEncSessionPacket;
10+
import org.bouncycastle.bcpg.SymmetricKeyUtils;
11+
import org.bouncycastle.crypto.InvalidCipherTextException;
12+
import org.bouncycastle.crypto.digests.SHA256Digest;
13+
import org.bouncycastle.crypto.generators.HKDFBytesGenerator;
14+
import org.bouncycastle.crypto.modes.AEADCipher;
15+
import org.bouncycastle.crypto.params.AEADParameters;
16+
import org.bouncycastle.crypto.params.HKDFParameters;
17+
import org.bouncycastle.crypto.params.KeyParameter;
1018
import org.bouncycastle.openpgp.PGPException;
19+
import org.bouncycastle.openpgp.operator.bc.BcAEADUtil;
1120
import org.bouncycastle.util.Arrays;
1221

1322
/**
@@ -211,7 +220,12 @@ private ContainedPacket generateV6ESK(int kekAlgorithm, int aeadAlgorithm, byte[
211220
(byte) kekAlgorithm,
212221
(byte) aeadAlgorithm
213222
};
214-
byte[] kek = generateV6KEK(kekAlgorithm, ikm, info);
223+
HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA256Digest());
224+
hkdf.init(new HKDFParameters(ikm, null, info));
225+
226+
int kekLen = SymmetricKeyUtils.getKeyLengthInOctets(kekAlgorithm);
227+
byte[] kek = new byte[kekLen];
228+
hkdf.generateBytes(kek, 0, kek.length);
215229

216230
byte[] iv = new byte[AEADUtils.getIVLength(aeadAlgorithm)];
217231
random.nextBytes(iv);
@@ -224,6 +238,27 @@ private ContainedPacket generateV6ESK(int kekAlgorithm, int aeadAlgorithm, byte[
224238
return SymmetricKeyEncSessionPacket.createV6Packet(kekAlgorithm, aeadAlgorithm, iv, s2k, esk, tag);
225239
}
226240

241+
private byte[] getEskAndTag(int kekAlgorithm, int aeadAlgorithm, byte[] sessionInfo, byte[] key, byte[] iv, byte[] info)
242+
throws PGPException
243+
{
244+
byte[] sessionKey = new byte[sessionInfo.length - 3];
245+
System.arraycopy(sessionInfo, 1, sessionKey, 0, sessionKey.length);
246+
247+
AEADCipher aeadCipher = BcAEADUtil.createAEADCipher(kekAlgorithm, aeadAlgorithm);
248+
aeadCipher.init(true, new AEADParameters(new KeyParameter(key), 128, iv, info));
249+
int outLen = aeadCipher.getOutputSize(sessionKey.length);
250+
byte[] eskAndTag = new byte[outLen];
251+
int len = aeadCipher.processBytes(sessionKey, 0, sessionKey.length, eskAndTag, 0);
252+
try
253+
{
254+
len += aeadCipher.doFinal(eskAndTag, len);
255+
}
256+
catch (InvalidCipherTextException e)
257+
{
258+
throw new PGPException("cannot encrypt session info", e);
259+
}
260+
return eskAndTag;
261+
}
227262
/**
228263
* Generate a V4 SKESK packet.
229264
*
@@ -253,10 +288,4 @@ public ContainedPacket generate(int encAlgorithm, byte[] sessionInfo)
253288

254289
abstract protected byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] sessionInfo)
255290
throws PGPException;
256-
257-
abstract protected byte[] getEskAndTag(int kekAlgorithm, int aeadAlgorithm, byte[] sessionInfo, byte[] key, byte[] iv, byte[] info)
258-
throws PGPException;
259-
260-
abstract protected byte[] generateV6KEK(int kekAlgorithm, byte[] ikm, byte[] info)
261-
throws PGPException;
262291
}

pg/src/main/java/org/bouncycastle/openpgp/operator/bc/BcPBEKeyEncryptionMethodGenerator.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
import java.security.SecureRandom;
44

55
import org.bouncycastle.bcpg.S2K;
6-
import org.bouncycastle.bcpg.SymmetricKeyUtils;
76
import org.bouncycastle.crypto.BlockCipher;
87
import org.bouncycastle.crypto.BufferedBlockCipher;
98
import org.bouncycastle.crypto.InvalidCipherTextException;
10-
import org.bouncycastle.crypto.digests.SHA256Digest;
11-
import org.bouncycastle.crypto.engines.CamelliaEngine;
12-
import org.bouncycastle.crypto.generators.HKDFBytesGenerator;
13-
import org.bouncycastle.crypto.modes.AEADCipher;
14-
import org.bouncycastle.crypto.params.AEADParameters;
15-
import org.bouncycastle.crypto.params.HKDFParameters;
16-
import org.bouncycastle.crypto.params.KeyParameter;
179
import org.bouncycastle.openpgp.PGPException;
1810
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
1911
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
@@ -111,38 +103,4 @@ protected byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] session
111103
throw new PGPException("encryption failed: " + e.getMessage(), e);
112104
}
113105
}
114-
115-
protected byte[] generateV6KEK(int kekAlgorithm, byte[] ikm, byte[] info)
116-
throws PGPException
117-
{
118-
HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA256Digest());
119-
hkdf.init(new HKDFParameters(ikm, null, info));
120-
121-
int kekLen = SymmetricKeyUtils.getKeyLengthInOctets(kekAlgorithm);
122-
byte[] kek = new byte[kekLen];
123-
hkdf.generateBytes(kek, 0, kek.length);
124-
return kek;
125-
}
126-
127-
protected byte[] getEskAndTag(int kekAlgorithm, int aeadAlgorithm, byte[] sessionInfo, byte[] key, byte[] iv, byte[] info)
128-
throws PGPException
129-
{
130-
byte[] sessionKey = new byte[sessionInfo.length - 3];
131-
System.arraycopy(sessionInfo, 1, sessionKey, 0, sessionKey.length);
132-
133-
AEADCipher aeadCipher = BcAEADUtil.createAEADCipher(kekAlgorithm, aeadAlgorithm);
134-
aeadCipher.init(true, new AEADParameters(new KeyParameter(key), 128, iv, info));
135-
int outLen = aeadCipher.getOutputSize(sessionKey.length);
136-
byte[] eskAndTag = new byte[outLen];
137-
int len = aeadCipher.processBytes(sessionKey, 0, sessionKey.length, eskAndTag, 0);
138-
try
139-
{
140-
len += aeadCipher.doFinal(eskAndTag, len);
141-
}
142-
catch (InvalidCipherTextException e)
143-
{
144-
throw new PGPException("cannot encrypt session info", e);
145-
}
146-
return eskAndTag;
147-
}
148106
}

pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcePBEKeyEncryptionMethodGenerator.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,13 @@
1313
import javax.crypto.spec.SecretKeySpec;
1414

1515
import org.bouncycastle.bcpg.S2K;
16-
import org.bouncycastle.bcpg.SymmetricKeyUtils;
17-
import org.bouncycastle.crypto.InvalidCipherTextException;
18-
import org.bouncycastle.crypto.digests.SHA256Digest;
19-
import org.bouncycastle.crypto.generators.HKDFBytesGenerator;
20-
import org.bouncycastle.crypto.modes.AEADCipher;
21-
import org.bouncycastle.crypto.params.AEADParameters;
22-
import org.bouncycastle.crypto.params.HKDFParameters;
23-
import org.bouncycastle.crypto.params.KeyParameter;
2416
import org.bouncycastle.jcajce.util.DefaultJcaJceHelper;
2517
import org.bouncycastle.jcajce.util.NamedJcaJceHelper;
2618
import org.bouncycastle.jcajce.util.ProviderJcaJceHelper;
2719
import org.bouncycastle.openpgp.PGPException;
2820
import org.bouncycastle.openpgp.PGPUtil;
2921
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
3022
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
31-
import org.bouncycastle.openpgp.operator.bc.BcAEADUtil;
3223

3324
/**
3425
* JCE based generator for password based encryption (PBE) data protection methods.
@@ -148,38 +139,4 @@ protected byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] session
148139
throw new PGPException("key invalid: " + e.getMessage(), e);
149140
}
150141
}
151-
152-
protected byte[] generateV6KEK(int kekAlgorithm, byte[] ikm, byte[] info)
153-
throws PGPException
154-
{
155-
HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA256Digest());
156-
hkdf.init(new HKDFParameters(ikm, null, info));
157-
158-
int kekLen = SymmetricKeyUtils.getKeyLengthInOctets(kekAlgorithm);
159-
byte[] kek = new byte[kekLen];
160-
hkdf.generateBytes(kek, 0, kek.length);
161-
return kek;
162-
}
163-
164-
protected byte[] getEskAndTag(int kekAlgorithm, int aeadAlgorithm, byte[] sessionInfo, byte[] key, byte[] iv, byte[] info)
165-
throws PGPException
166-
{
167-
byte[] sessionKey = new byte[sessionInfo.length - 3];
168-
System.arraycopy(sessionInfo, 1, sessionKey, 0, sessionKey.length);
169-
170-
AEADCipher aeadCipher = BcAEADUtil.createAEADCipher(kekAlgorithm, aeadAlgorithm);
171-
aeadCipher.init(true, new AEADParameters(new KeyParameter(key), 128, iv, info));
172-
int outLen = aeadCipher.getOutputSize(sessionKey.length);
173-
byte[] eskAndTag = new byte[outLen];
174-
int len = aeadCipher.processBytes(sessionKey, 0, sessionKey.length, eskAndTag, 0);
175-
try
176-
{
177-
len += aeadCipher.doFinal(eskAndTag, len);
178-
}
179-
catch (InvalidCipherTextException e)
180-
{
181-
throw new PGPException("cannot encrypt session info", e);
182-
}
183-
return eskAndTag;
184-
}
185142
}

pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcePublicKeyDataDecryptorFactoryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private byte[] decryptSessionData(JcaPGPKeyConverter converter, PGPPrivateKey pr
260260
if (ecKey.getCurveOID().equals(CryptlibObjectIdentifiers.curvey25519))
261261
{
262262
agreementName = RFC6637Utils.getXDHAlgorithm(pubKeyData);
263-
if (pEnc.length != (1 + X25519PublicBCPGKey.LENGTH) || 0x40 != pEnc[0])
263+
if (pEnc.length != (1 + X25519PublicKeyParameters.KEY_SIZE) || 0x40 != pEnc[0])
264264
{
265265
throw new IllegalArgumentException("Invalid Curve25519 public key");
266266
}

0 commit comments

Comments
 (0)