Skip to content

Commit

Permalink
Fix return type for randombytes_random and _uniform (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ugljesa Jovanovic authored Oct 5, 2020
1 parent 6aa5903 commit ea27165
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/goterl/lazycode/lazysodium/LazySodium.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private static byte[] hexToBytes(String s) {
//// -------------------------------------------|

@Override
public byte randomBytesRandom() {
public long randomBytesRandom() {
return getSodium().randombytes_random();
}

Expand All @@ -164,7 +164,7 @@ public byte[] nonce(int size) {
}

@Override
public byte randomBytesUniform(int upperBound) {
public long randomBytesUniform(int upperBound) {
return getSodium().randombytes_uniform(upperBound);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/goterl/lazycode/lazysodium/Sodium.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public native int sodium_base642bin(byte[] bin,
//// RANDOM
//// -------------------------------------------|

public native byte randombytes_random();
public native long randombytes_random();

public native byte randombytes_uniform(int upperBound);
public native long randombytes_uniform(int upperBound);

public native void randombytes_buf(byte[] buffer, int size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
public interface Random {

/**
* Return a random byte 0 and 0xffffffff included.
* Return a unsigned int byte 0 and 0xffffffff included.
* @return A random byte.
*/
byte randomBytesRandom();
long randomBytesRandom();

/**
* Returns an unpredictable value between 0 and upperBound (excluded).
* Unlike randombytes_random() % upper_bound, it guarantees a uniform distribution
* of the possible output values even when upper_bound is not a power of 2. Note
* that an upper_bound less than 2 leaves only a single element to be chosen, namely 0.
* @param upperBound
* @return A uniformally random bytes.
* @return A uniformly random unsigned int.
*/
byte randomBytesUniform(int upperBound);
long randomBytesUniform(int upperBound);

/**
* Get a random number of bytes.
Expand Down

0 comments on commit ea27165

Please sign in to comment.