Skip to content

Commit b012713

Browse files
committed
1.4 compatibility.
1 parent e70fc92 commit b012713

File tree

5 files changed

+117
-24
lines changed

5 files changed

+117
-24
lines changed

core/src/main/java/org/bouncycastle/pqc/crypto/falcon/FalconConversions.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ byte[] int_to_bytes(int x)
2020
int bytes_to_int(byte[] src, int pos)
2121
{
2222
int acc = 0;
23-
acc = Byte.toUnsignedInt(src[pos + 0]) << 0 |
24-
Byte.toUnsignedInt(src[pos + 1]) << 8 |
25-
Byte.toUnsignedInt(src[pos + 2]) << 16 |
26-
Byte.toUnsignedInt(src[pos + 3]) << 24;
23+
acc = toUnsignedInt(src[pos + 0]) << 0 |
24+
toUnsignedInt(src[pos + 1]) << 8 |
25+
toUnsignedInt(src[pos + 2]) << 16 |
26+
toUnsignedInt(src[pos + 3]) << 24;
2727
return acc;
2828
}
2929

@@ -54,14 +54,24 @@ byte[] long_to_bytes(long x)
5454
long bytes_to_long(byte[] src, int pos)
5555
{
5656
long acc = 0;
57-
acc = Byte.toUnsignedLong(src[pos + 0]) << 0 |
58-
Byte.toUnsignedLong(src[pos + 1]) << 8 |
59-
Byte.toUnsignedLong(src[pos + 2]) << 16 |
60-
Byte.toUnsignedLong(src[pos + 3]) << 24 |
61-
Byte.toUnsignedLong(src[pos + 4]) << 32 |
62-
Byte.toUnsignedLong(src[pos + 5]) << 40 |
63-
Byte.toUnsignedLong(src[pos + 6]) << 48 |
64-
Byte.toUnsignedLong(src[pos + 7]) << 56;
57+
acc = toUnsignedLong(src[pos + 0]) << 0 |
58+
toUnsignedLong(src[pos + 1]) << 8 |
59+
toUnsignedLong(src[pos + 2]) << 16 |
60+
toUnsignedLong(src[pos + 3]) << 24 |
61+
toUnsignedLong(src[pos + 4]) << 32 |
62+
toUnsignedLong(src[pos + 5]) << 40 |
63+
toUnsignedLong(src[pos + 6]) << 48 |
64+
toUnsignedLong(src[pos + 7]) << 56;
6565
return acc;
6666
}
67+
68+
private int toUnsignedInt(byte b)
69+
{
70+
return b & 0xff;
71+
}
72+
73+
private long toUnsignedLong(byte b)
74+
{
75+
return b & 0xffL;
76+
}
6777
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.bouncycastle.crypto;
2+
3+
public final class CryptoServicePurpose
4+
{
5+
public static final CryptoServicePurpose AGREEMENT = new CryptoServicePurpose(0);
6+
public static final CryptoServicePurpose ENCRYPTION = new CryptoServicePurpose(1);
7+
public static final CryptoServicePurpose DECRYPTION = new CryptoServicePurpose(2);
8+
public static final CryptoServicePurpose KEYGEN = new CryptoServicePurpose(3);
9+
public static final CryptoServicePurpose SIGNING = new CryptoServicePurpose(4);
10+
public static final CryptoServicePurpose VERIFYING = new CryptoServicePurpose(5);
11+
public static final CryptoServicePurpose PRF = new CryptoServicePurpose(6);
12+
public static final CryptoServicePurpose ANY = new CryptoServicePurpose(7);
13+
14+
private final int ord;
15+
16+
private CryptoServicePurpose(int ord)
17+
{
18+
this.ord = ord;
19+
}
20+
}

core/src/main/jdk1.4/org/bouncycastle/crypto/CryptoServicesRegistrar.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public final class CryptoServicesRegistrar
3131
private static final Object cacheLock = new Object();
3232
private static SecureRandomProvider defaultSecureRandomProvider;
3333

34+
private static final CryptoServicesConstraints noConstraintsImpl = new CryptoServicesConstraints()
35+
{
36+
public void check(CryptoServiceProperties service)
37+
{
38+
// anything goes.
39+
}
40+
};
41+
42+
private static final boolean preconfiguredConstraints;
43+
private static CryptoServicesConstraints servicesConstraints = noConstraintsImpl;
44+
3445
static
3546
{
3647
// default domain parameters for DSA and Diffie-Hellman
@@ -93,6 +104,9 @@ public final class CryptoServicesRegistrar
93104

94105
localSetGlobalProperty(Property.DSA_DEFAULT_PARAMS, new Object[] { def512Params, def768Params, def1024Params, def2048Params });
95106
localSetGlobalProperty(Property.DH_DEFAULT_PARAMS, new Object[] { toDH(def512Params), toDH(def768Params), toDH(def1024Params), toDH(def2048Params) });
107+
108+
servicesConstraints.set(getDefaultConstraints());
109+
preconfiguredConstraints = (servicesConstraints != noConstraintsImpl);
96110
}
97111

98112
private CryptoServicesRegistrar()
@@ -185,6 +199,54 @@ public static void setSecureRandomProvider(SecureRandomProvider secureRandomProv
185199
defaultSecureRandomProvider = secureRandomProvider;
186200
}
187201

202+
/**
203+
* Return the current algorithm/services constraints.
204+
*
205+
* @return the algorithm/services constraints.
206+
*/
207+
public static CryptoServicesConstraints getServicesConstraints()
208+
{
209+
return servicesConstraints;
210+
}
211+
212+
/**
213+
* Check a service to make sure it meets the current constraints.
214+
*
215+
* @param cryptoService the service to be checked.
216+
* @throws CryptoServiceConstraintsException if the service violates the current constraints.
217+
*/
218+
public static void checkConstraints(CryptoServiceProperties cryptoService)
219+
{
220+
servicesConstraints.check(cryptoService);
221+
}
222+
223+
/**
224+
* Set the current algorithm constraints.
225+
*/
226+
public static void setServicesConstraints(CryptoServicesConstraints constraints)
227+
{
228+
checkPermission(CanSetConstraints);
229+
230+
CryptoServicesConstraints newConstraints = (constraints == null) ? noConstraintsImpl : constraints;
231+
232+
if (preconfiguredConstraints)
233+
{
234+
if (Properties.isOverrideSet("org.bouncycastle.constraints.allow_override"))
235+
{
236+
servicesConstraints = newConstraints;
237+
}
238+
else
239+
{
240+
LOG.warning("attempt to override pre-configured constraints ignored");
241+
}
242+
}
243+
else
244+
{
245+
// TODO: should this only be allowed once?
246+
servicesConstraints = newConstraints;
247+
}
248+
}
249+
188250
/**
189251
* Return the default value for a particular property if one exists. The look up is done on the thread's local
190252
* configuration first and then on the global configuration in no local configuration exists.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bouncycastle.bcpg;
22

3-
public interface UserDataPacket {
3+
public interface UserDataPacket
4+
{
45

56
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static List<PGPSecretKey> checkKeys(List<PGPSecretKey> keys)
4646

4747
for (int i = 0; i != keys.size(); i++)
4848
{
49-
PGPSecretKey k = keys.get(i);
49+
PGPSecretKey k = (PGPSecretKey)keys.get(i);
5050

5151
if (i == 0)
5252
{
@@ -281,7 +281,7 @@ public Iterator<PGPPublicKey> getPublicKeys()
281281

282282
for (Iterator<PGPSecretKey> it = getSecretKeys(); it.hasNext(); )
283283
{
284-
PGPPublicKey key = it.next().getPublicKey();
284+
PGPPublicKey key = ((PGPSecretKey)it.next()).getPublicKey();
285285
pubKeys.add(key);
286286
}
287287

@@ -297,7 +297,7 @@ public Iterator<PGPPublicKey> getPublicKeys()
297297
*/
298298
public PGPSecretKey getSecretKey()
299299
{
300-
return keys.get(0);
300+
return (PGPSecretKey)keys.get(0);
301301
}
302302

303303
/**
@@ -322,7 +322,7 @@ public PGPSecretKey getSecretKey(
322322
{
323323
for (int i = 0; i != keys.size(); i++)
324324
{
325-
PGPSecretKey k = keys.get(i);
325+
PGPSecretKey k = (PGPSecretKey)keys.get(i);
326326

327327
if (keyID == k.getKeyID())
328328
{
@@ -344,7 +344,7 @@ public PGPSecretKey getSecretKey(byte[] fingerprint)
344344
{
345345
for (int i = 0; i != keys.size(); i++)
346346
{
347-
PGPSecretKey k = keys.get(i);
347+
PGPSecretKey k = (PGPSecretKey)keys.get(i);
348348

349349
if (Arrays.areEqual(fingerprint, k.getPublicKey().getFingerprint()))
350350
{
@@ -383,7 +383,7 @@ public void encode(
383383
{
384384
for (int i = 0; i != keys.size(); i++)
385385
{
386-
PGPSecretKey k = keys.get(i);
386+
PGPSecretKey k = (PGPSecretKey)keys.get(i);
387387

388388
k.encode(outStream);
389389
}
@@ -415,7 +415,7 @@ public static PGPSecretKeyRing replacePublicKeys(PGPSecretKeyRing secretRing, PG
415415

416416
for (Iterator<PGPSecretKey> it = secretRing.keys.iterator(); it.hasNext(); )
417417
{
418-
PGPSecretKey sk = it.next();
418+
PGPSecretKey sk = (PGPSecretKey)it.next();
419419
PGPPublicKey pk = publicRing.getPublicKey(sk.getKeyID());
420420

421421
newList.add(PGPSecretKey.replacePublicKey(sk, pk));
@@ -442,7 +442,7 @@ public static PGPSecretKeyRing insertOrReplacePublicKey(PGPSecretKeyRing secretR
442442
List<PGPSecretKey> newList = new ArrayList<>(secretRing.keys.size());
443443
for (Iterator<PGPSecretKey> it = secretRing.getSecretKeys(); it.hasNext(); )
444444
{
445-
PGPSecretKey sk = it.next();
445+
PGPSecretKey sk = (PGPSecretKey)it.next();
446446
if (sk.getKeyID() == publicKey.getKeyID())
447447
{
448448
sk = PGPSecretKey.replacePublicKey(secretKey, publicKey);
@@ -499,7 +499,7 @@ public static PGPSecretKeyRing copyWithNewPassword(
499499

500500
for (Iterator<PGPSecretKey> keys = ring.getSecretKeys(); keys.hasNext(); )
501501
{
502-
PGPSecretKey key = keys.next();
502+
PGPSecretKey key = (PGPSecretKey)keys.next();
503503

504504
if (key.isPrivateKeyEmpty())
505505
{
@@ -532,7 +532,7 @@ public static PGPSecretKeyRing insertSecretKey(
532532

533533
for (int i = 0; i != keys.size(); i++)
534534
{
535-
PGPSecretKey key = keys.get(i);
535+
PGPSecretKey key = (PGPSecretKey)keys.get(i);
536536

537537
if (key.getKeyID() == secKey.getKeyID())
538538
{
@@ -585,7 +585,7 @@ public static PGPSecretKeyRing removeSecretKey(
585585

586586
for (int i = 0; i < count; ++i)
587587
{
588-
PGPSecretKey key = secRing.keys.get(i);
588+
PGPSecretKey key = (PGPSecretKey)secRing.keys.get(i);
589589

590590
if (key.getKeyID() == keyID)
591591
{

0 commit comments

Comments
 (0)