diff --git a/meerkat-common/src/main/java/meerkat/crypto/Digest.java b/meerkat-common/src/main/java/meerkat/crypto/Digest.java index a715b26..06b012c 100644 --- a/meerkat-common/src/main/java/meerkat/crypto/Digest.java +++ b/meerkat-common/src/main/java/meerkat/crypto/Digest.java @@ -8,13 +8,6 @@ import java.security.MessageDigest; * Created by talm on 11/9/15. */ public interface Digest { - - /** - * Marker between messages - */ - public static final byte[] CONCAT_MARKER = {(byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef, - (byte) 0xba, (byte) 0x1d, (byte) 0xfa, (byte) 0xce}; - /** * Completes the hash computation by performing final operations such as padding. * (copied from {@link MessageDigest#digest()}) @@ -25,9 +18,7 @@ public interface Digest { /** * Updates the digest using the specified message (in serialized wire form) * - * Includes a special message concatenation marker (the 64 bit message {@link #CONCAT_MARKER}) in the digest (digesting a single message - * will give a different result than the same message split into two messages). - * Messages must not contain the {@link #CONCAT_MARKER}) marker. + * Each message is (automatically) prepended with its length as a 32-bit big-endian unsigned integer. * @param msg * @return */ diff --git a/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java b/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java index eda41a2..1abad8f 100644 --- a/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java +++ b/meerkat-common/src/main/java/meerkat/crypto/DigitalSignature.java @@ -41,8 +41,8 @@ public interface DigitalSignature { /** - * Add msg to the content stream to be verified / signed. Each message is always (automatically) - * prepended with its length as a 32-bit unsigned integer in network byte order. + * Add msg to the content stream to be verified / signed. Each message is (automatically) + * prepended with its length as a 32-bit big-endian unsigned integer. * * @param msg * @throws SignatureException diff --git a/meerkat-common/src/main/java/meerkat/crypto/concrete/ECDSASignature.java b/meerkat-common/src/main/java/meerkat/crypto/concrete/ECDSASignature.java index 360ea53..1a5683f 100644 --- a/meerkat-common/src/main/java/meerkat/crypto/concrete/ECDSASignature.java +++ b/meerkat-common/src/main/java/meerkat/crypto/concrete/ECDSASignature.java @@ -2,13 +2,13 @@ package meerkat.crypto.concrete; import java.io.IOException; import java.io.InputStream; +import java.nio.ByteBuffer; import java.security.*; import java.security.cert.*; import java.security.cert.Certificate; import java.util.*; import com.google.protobuf.ByteString; -import meerkat.crypto.Digest; import meerkat.protobuf.Crypto; import meerkat.util.Hex; import org.slf4j.Logger; @@ -27,7 +27,7 @@ import javax.security.auth.callback.UnsupportedCallbackException; /** * Sign and verify digital signatures. - *
+ * * This class is not thread-safe (each thread should have its own instance). */ public class ECDSASignature extends GlobalCryptoSetup implements DigitalSignature { @@ -38,6 +38,12 @@ public class ECDSASignature extends GlobalCryptoSetup implements DigitalSignatur SHA256Digest digest = new SHA256Digest(); + /** + * Buffer used to hold length in for hash update + */ + ByteBuffer lenBuf = ByteBuffer.allocate(4); + + Map