mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Require a label for hashing
* Add a string label argument to CryptoComponent#hash() * Convert DoubleDigest from implementing MessageDigest to implementing org.spongycastle.crypto.Digest (we need to keep DoubleDigest for FortunaGenerator) * Convert all other uses of MessageDigest to CryptoComponent#hash() * Remove CryptoComponent#getMessageDigest(), MessageDigest and DigestWrapper
This commit is contained in:
@@ -10,8 +10,6 @@ public interface CryptoComponent {
|
||||
|
||||
SecretKey generateSecretKey();
|
||||
|
||||
MessageDigest getMessageDigest();
|
||||
|
||||
PseudoRandom getPseudoRandom(int seed1, int seed2);
|
||||
|
||||
SecureRandom getSecureRandom();
|
||||
@@ -164,8 +162,17 @@ public interface CryptoComponent {
|
||||
/**
|
||||
* Returns the hash of the given inputs. The inputs are unambiguously
|
||||
* combined by prefixing each input with its length.
|
||||
*
|
||||
* @param label A label specific to this hash to ensure that hashes
|
||||
* calculated for distinct purposes don't collide.
|
||||
*/
|
||||
byte[] hash(byte[]... inputs);
|
||||
byte[] hash(String label, byte[]... inputs);
|
||||
|
||||
/**
|
||||
* Returns the length of hashes produced by
|
||||
* the {@link CryptoComponent#hash(String, byte[]...)} method.
|
||||
*/
|
||||
int getHashLength();
|
||||
|
||||
/**
|
||||
* Returns a message authentication code with the given key over the
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package org.briarproject.bramble.api.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface MessageDigest {
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#digest()}
|
||||
*/
|
||||
byte[] digest();
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#digest(byte[])}
|
||||
*/
|
||||
byte[] digest(byte[] input);
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#digest(byte[], int, int)}
|
||||
*/
|
||||
int digest(byte[] buf, int offset, int len);
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#getDigestLength()}
|
||||
*/
|
||||
int getDigestLength();
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#reset()}
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#update(byte)}
|
||||
*/
|
||||
void update(byte input);
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#update(byte[])}
|
||||
*/
|
||||
void update(byte[] input);
|
||||
|
||||
/**
|
||||
* @see {@link java.security.MessageDigest#update(byte[], int, int)}
|
||||
*/
|
||||
void update(byte[] input, int offset, int len);
|
||||
}
|
||||
@@ -3,8 +3,6 @@ package org.briarproject.bramble.api.identity;
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
@@ -18,8 +16,7 @@ public class AuthorId extends UniqueId {
|
||||
/**
|
||||
* Label for hashing authors to calculate their identities.
|
||||
*/
|
||||
public static final byte[] LABEL =
|
||||
"AUTHOR_ID".getBytes(Charset.forName("US-ASCII"));
|
||||
public static final String LABEL = "org.briarproject.bramble.AUTHOR_ID";
|
||||
|
||||
public AuthorId(byte[] id) {
|
||||
super(id);
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.briarproject.bramble.api.sync;
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
@@ -17,8 +15,7 @@ public class GroupId extends UniqueId {
|
||||
/**
|
||||
* Label for hashing groups to calculate their identifiers.
|
||||
*/
|
||||
public static final byte[] LABEL =
|
||||
"GROUP_ID".getBytes(Charset.forName("US-ASCII"));
|
||||
public static final String LABEL = "org.briarproject.bramble.GROUP_ID";
|
||||
|
||||
public GroupId(byte[] id) {
|
||||
super(id);
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.briarproject.bramble.api.sync;
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
@@ -18,8 +16,7 @@ public class MessageId extends UniqueId {
|
||||
/**
|
||||
* Label for hashing messages to calculate their identifiers.
|
||||
*/
|
||||
public static final byte[] LABEL =
|
||||
"MESSAGE_ID".getBytes(Charset.forName("US-ASCII"));
|
||||
public static final String LABEL = "org.briarproject.bramble.MESSAGE_ID";
|
||||
|
||||
public MessageId(byte[] id) {
|
||||
super(id);
|
||||
|
||||
Reference in New Issue
Block a user