This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow caller to specify Random interface, mostly for J2ME.
- Loading branch information
Showing
11 changed files
with
116 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
common/src/main/java/org/whispersystems/curve25519/SecureRandomProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.whispersystems.curve25519; | ||
|
||
public interface SecureRandomProvider { | ||
public void nextBytes(byte[] output); | ||
} |
18 changes: 5 additions & 13 deletions
18
j2me/src/main/java/org/whispersystems/curve25519/J2meCurve25519Provider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
package org.whispersystems.curve25519; | ||
|
||
import org.whispersystems.curve25519.java.Sha512; | ||
|
||
public class J2meCurve25519Provider extends BaseJavaCurve25519Provider { | ||
|
||
private final BouncyCastleSha512Provider sha512Provider = new BouncyCastleSha512Provider(); | ||
|
||
// @Override | ||
protected Sha512 getSha512() { | ||
return sha512Provider; | ||
protected J2meCurve25519Provider() { | ||
super(new BouncyCastleSha512Provider(), new NullSecureRandomProvider()); | ||
} | ||
|
||
// @Override | ||
public byte[] getRandom(int length) { | ||
byte[] random = new byte[length]; | ||
SecureRandom.getInstance().nextBytes(random); | ||
|
||
return random; | ||
@Override | ||
public boolean isNative() { | ||
return false; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
j2me/src/main/java/org/whispersystems/curve25519/NullSecureRandomProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.whispersystems.curve25519; | ||
|
||
public class NullSecureRandomProvider implements SecureRandomProvider { | ||
@Override | ||
public void nextBytes(byte[] output) { | ||
throw new IllegalArgumentException("No default J2ME Secure Random provider available!"); | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
j2me/src/main/java/org/whispersystems/curve25519/SecureRandom.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
java/src/main/java/org/whispersystems/curve25519/JCESecureRandomProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.whispersystems.curve25519; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
import java.security.SecureRandom; | ||
|
||
public class JCESecureRandomProvider implements SecureRandomProvider { | ||
|
||
@Override | ||
public void nextBytes(byte[] output) { | ||
try { | ||
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); | ||
secureRandom.nextBytes(output); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters