Skip to content

Commit

Permalink
Rename crypto.Util to crypto.Digest
Browse files Browse the repository at this point in the history
  • Loading branch information
masomel committed Aug 20, 2016
1 parent 9e10deb commit de26d1e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
package org.coniks.coniks_server;

// coniks-java imports
import org.coniks.crypto.Util;
import org.coniks.crypto.Digest;
import org.coniks.util.Logging;
import org.coniks.coniks_common.MsgType;
import org.coniks.coniks_common.C2SProtos.Registration;
Expand Down Expand Up @@ -208,7 +208,7 @@ else if (opMode.equalsIgnoreCase("test")) {

// init the history
if (!ServerHistory.initHistory(initRoot, initEpoch, 0,
new byte[Util.HASH_SIZE_BYTES])) {
new byte[Digest.HASH_SIZE_BYTES])) {
printStatusMsg(true, "Error initializing the history");
System.exit(-1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
import org.javatuples.*;

// coniks-java imports
import org.coniks.crypto.Util;
import org.coniks.crypto.Digest;
import org.coniks.util.Logging;
import org.coniks.coniks_common.*;
import org.coniks.coniks_common.C2SProtos.*;
Expand Down Expand Up @@ -174,15 +174,15 @@ private static synchronized Commitment buildCommitmentMsg(SignedTreeRoot str){
byte[] rootHashBytes = null;

try {
rootHashBytes = Util.digest(rootBytes);
rootHashBytes = Digest.digest(rootBytes);
}
catch(NoSuchAlgorithmException e) {
Logging.error("[ServerMessagging] "+e.getMessage());
return null;
}

Hash.Builder rootHash = Hash.newBuilder();
if(rootHashBytes.length != Util.HASH_SIZE_BYTES){
if(rootHashBytes.length != Digest.HASH_SIZE_BYTES){
Logging.error("Bad length of root hash: "+rootHashBytes.length);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public class ServerUtils{
/** The size of the Merkle tree hashes in bits.
* Current hashing algorithm: SHA-256
*
*@deprecated Moved to {@link org.coniks.crypto.Util}.
*@deprecated Moved to {@link org.coniks.crypto.Digest}.
*/
@Deprecated
public static final int HASH_SIZE_BITS = 256;

/** The size of the Merkle tree hashes in bytes.
* Current hashing algorithm: SHA-256
*
*@deprecated Moved to {@link org.coniks.crypto.Util}.
*@deprecated Moved to {@link org.coniks.crypto.Digest}.
*/
@Deprecated
public static final int HASH_SIZE_BYTES = HASH_SIZE_BITS/8;
Expand Down Expand Up @@ -124,7 +124,7 @@ public static void printStatusMsg (boolean isErr, String msg) {
* Current hashing algorithm: SHA-256.
*
*@return The hash as a {@code byte[]} or null in case of an error.
*@deprecated Replaced with {@link org.coniks.crypto.Util#digest(byte[])}
*@deprecated Replaced with {@link org.coniks.crypto.Digest#digest(byte[])}
*/
@Deprecated
public static byte[] hash(byte[] input){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

// coniks-java imports
import org.coniks.crypto.Signing;
import org.coniks.crypto.Util;
import org.coniks.crypto.Digest;
import org.coniks.util.Convert;
import org.coniks.util.Logging;
import org.coniks.coniks_common.C2SProtos.AuthPath;
Expand Down Expand Up @@ -105,7 +105,7 @@ public static synchronized SignedTreeRoot generateNextSTR(RootNode root, long ep
byte[] prevStrHash = null;

try {
prevStrHash = Util.digest(ServerUtils.getSTRBytes(ServerHistory.getCurSTR()));
prevStrHash = Digest.digest(ServerUtils.getSTRBytes(ServerHistory.getCurSTR()));
}
catch(NoSuchAlgorithmException e) {
Logging.error("[TransparencyOps] "+e.getMessage());
Expand Down Expand Up @@ -186,7 +186,7 @@ public static AuthPath generateAuthPathProto(UserLeafNode uln, RootNode root){
// true = right
boolean direction = Convert.getNthBit(lookupIndex, curOffset);

byte[] prunedChildHash = new byte[Util.HASH_SIZE_BYTES];
byte[] prunedChildHash = new byte[Digest.HASH_SIZE_BYTES];

if (runner == null){
Logging.error("Null runner" + curOffset);
Expand All @@ -210,7 +210,7 @@ public static AuthPath generateAuthPathProto(UserLeafNode uln, RootNode root){
}

Hash.Builder subtree = Hash.newBuilder();
if(prunedChildHash.length != Util.HASH_SIZE_BYTES){
if(prunedChildHash.length != Digest.HASH_SIZE_BYTES){
Logging.error("Bad length of pruned child hash: "+prunedChildHash.length);
return null;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ public static AuthPath generateAuthPathProto(UserLeafNode uln, RootNode root){
runner = curNodeI.getRight();
}
Hash.Builder subtree = Hash.newBuilder();
if(prunedChildHash.length != Util.HASH_SIZE_BYTES){
if(prunedChildHash.length != Digest.HASH_SIZE_BYTES){
Logging.error("Bad length of pruned child hash: "+prunedChildHash.length);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
import java.security.interfaces.RSAPublicKey;

// coniks-java imports
import org.coniks.crypto.Util;
import org.coniks.crypto.Digest;
import org.coniks.util.Convert;
import org.coniks.util.Logging;

Expand Down Expand Up @@ -200,7 +200,7 @@ private static void computeHashes(RootNode root)
private static byte[] innerComputeHash(TreeNode curNode)
throws NoSuchAlgorithmException {
if(curNode == null) {
return Util.digest(new byte[Util.HASH_SIZE_BYTES]);
return Digest.digest(new byte[Digest.HASH_SIZE_BYTES]);
}

if(curNode instanceof InteriorNode){
Expand All @@ -214,12 +214,12 @@ private static byte[] innerComputeHash(TreeNode curNode)
curNodeI.rightHash = innerComputeHash(curNode.right);
}

return Util.digest(ServerUtils.getInteriorNodeBytes(curNodeI));
return Digest.digest(ServerUtils.getInteriorNodeBytes(curNodeI));
}
else{
// assertion: must be user leaf node.
UserLeafNode curNodeU = (UserLeafNode) curNode;
return Util.digest(ServerUtils.getUserLeafNodeBytes(curNodeU));
return Digest.digest(ServerUtils.getUserLeafNodeBytes(curNodeU));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public class ClientUtils{
/** The size of the Merkle tree hashes in bits.
* Current hashing algorithm: SHA-256
*
*@deprecated Moved to {@link org.coniks.crypto.Util}.
*@deprecated Moved to {@link org.coniks.crypto.Digest}.
*/
@Deprecated
public static final int HASH_SIZE_BITS = 256;

/** The size of the Merkle tree hashes in bytes.
* Current hashing algorithm: SHA-256
*
*@deprecated Moved to {@link org.coniks.crypto.Util}.
*@deprecated Moved to {@link org.coniks.crypto.Digest}.
*/
@Deprecated
public static final int HASH_SIZE_BYTES = HASH_SIZE_BITS/8;
Expand Down Expand Up @@ -115,7 +115,7 @@ public class ClientUtils{
* Current hashing algorithm: SHA-256.
*
*@return The hash as a {@code byte[]} or null in case of an error.
*@deprecated Replaced with {@link org.coniks.crypto.Util#digest(byte[])}
*@deprecated Replaced with {@link org.coniks.crypto.Digest#digest(byte[])}
*/
@Deprecated
public static byte[] hash(byte[] input){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
import org.javatuples.*;

// coniks-java imports
import org.coniks.crypto.Util;
import org.coniks.crypto.Digest;
import org.coniks.util.Logging;
import org.coniks.coniks_common.ServerErr;
import org.coniks.coniks_common.C2SProtos.RegistrationResp;
Expand Down Expand Up @@ -104,15 +104,15 @@ private static byte[] recomputeAuthPathRootProto(AuthPath authPath)
ByteString index = apUln.getLookupIndex();

// verify the input: expect the index to be the size of the hash
if(index.size() != Util.HASH_SIZE_BYTES){
if(index.size() != Digest.HASH_SIZE_BYTES){
Logging.error("Bad index length");
return null;
}

byte[] lookupIndex = index.toByteArray();
int numInteriors = apUln.getIntlevels();

byte[] ulnHash = Util.digest(ClientUtils.ulnProtoToBytes(apUln));
byte[] ulnHash = Digest.digest(ClientUtils.ulnProtoToBytes(apUln));

ArrayList<AuthPath.InteriorNode> inList =
new ArrayList<AuthPath.InteriorNode>(authPath.getInteriorList());
Expand Down Expand Up @@ -173,7 +173,7 @@ public static int verifyMappingProto (AuthPath authPath,
// compute the hash of the recomputed root
byte[] recomputedRootHash = null;
try {
recomputedRootHash = Util.digest(recomputedRoot);
recomputedRootHash = Digest.digest(recomputedRoot);
}
catch(NoSuchAlgorithmException e) {
return ClientUtils.INTERNAL_CLIENT_ERR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*@author Marcela S. Melara (melara@cs.princeton.edu)
*@author Michael Rochlin
*/
public class Util {
public class Digest {

/** The size of a SHA-256 hash in bits.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
import java.util.Arrays;

/**
* Unit tests for Util.
* Unit tests for Digest.
*/
public class UtilTest
public class DigestTest
{

@Test
Expand All @@ -55,16 +55,16 @@ public void testDigest()

byte[] msg = "message".getBytes();

byte[] hash = Util.digest(msg);
byte[] hash = Digest.digest(msg);

if(hash.length != Util.HASH_SIZE_BYTES) {
if(hash.length != Digest.HASH_SIZE_BYTES) {
fail("Computation of hash failed - wrong length.");
}

assertNotNull("Computation of hash failed - null", hash);

assertFalse("Computation of hash failed - hash is all zeros",
Arrays.equals(hash, new byte[Util.HASH_SIZE_BYTES]));
Arrays.equals(hash, new byte[Digest.HASH_SIZE_BYTES]));

}
}

0 comments on commit de26d1e

Please sign in to comment.