mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Remove method that just wraps a MAC call.
This commit is contained in:
@@ -32,18 +32,6 @@ public interface CryptoComponent {
|
|||||||
*/
|
*/
|
||||||
SecretKey deriveKey(String label, SecretKey k, byte[]... inputs);
|
SecretKey deriveKey(String label, SecretKey k, byte[]... inputs);
|
||||||
|
|
||||||
/**
|
|
||||||
* Derives a nonce from the given secret key that can be used for key
|
|
||||||
* binding.
|
|
||||||
*
|
|
||||||
* TODO: This just calls mac(), remove it
|
|
||||||
*
|
|
||||||
* @param label a namespaced label indicating the purpose of this nonce,
|
|
||||||
* to prevent it from being repurposed or colliding with a nonce derived
|
|
||||||
* for another purpose
|
|
||||||
*/
|
|
||||||
byte[] deriveKeyBindingNonce(String label, SecretKey k);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derives a common shared secret from two public keys and one of the
|
* Derives a common shared secret from two public keys and one of the
|
||||||
* corresponding private keys.
|
* corresponding private keys.
|
||||||
|
|||||||
@@ -157,10 +157,8 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
|||||||
BdfWriter w = bdfWriterFactory.createWriter(streamWriter);
|
BdfWriter w = bdfWriterFactory.createWriter(streamWriter);
|
||||||
|
|
||||||
// Derive the nonces to be signed
|
// Derive the nonces to be signed
|
||||||
byte[] aliceNonce = crypto.deriveKeyBindingNonce(ALICE_NONCE_LABEL,
|
byte[] aliceNonce = crypto.mac(ALICE_NONCE_LABEL, masterSecret);
|
||||||
masterSecret);
|
byte[] bobNonce = crypto.mac(BOB_NONCE_LABEL, masterSecret);
|
||||||
byte[] bobNonce = crypto.deriveKeyBindingNonce(BOB_NONCE_LABEL,
|
|
||||||
masterSecret);
|
|
||||||
|
|
||||||
// Exchange pseudonyms, signed nonces, and timestamps
|
// Exchange pseudonyms, signed nonces, and timestamps
|
||||||
long localTimestamp = clock.currentTimeMillis();
|
long localTimestamp = clock.currentTimeMillis();
|
||||||
|
|||||||
@@ -220,12 +220,9 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SecretKey deriveKey(String label, SecretKey k, byte[]... inputs) {
|
public SecretKey deriveKey(String label, SecretKey k, byte[]... inputs) {
|
||||||
return new SecretKey(mac(label, k, inputs));
|
byte[] mac = mac(label, k, inputs);
|
||||||
}
|
if (mac.length != SecretKey.LENGTH) throw new IllegalStateException();
|
||||||
|
return new SecretKey(mac);
|
||||||
@Override
|
|
||||||
public byte[] deriveKeyBindingNonce(String label, SecretKey k) {
|
|
||||||
return mac(label, k);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -451,15 +451,16 @@ class IntroduceeManager {
|
|||||||
private void deriveMacKeysAndNonces(BdfDictionary localState,
|
private void deriveMacKeysAndNonces(BdfDictionary localState,
|
||||||
LocalAuthor author, SecretKey secretKey, boolean alice)
|
LocalAuthor author, SecretKey secretKey, boolean alice)
|
||||||
throws FormatException, GeneralSecurityException {
|
throws FormatException, GeneralSecurityException {
|
||||||
// Derive two nonces and MAC keys from the shared secret key
|
// Derive two nonces and two MAC keys from the shared secret key
|
||||||
byte[] ourNonce = cryptoComponent.deriveKeyBindingNonce(
|
String ourNonceLabel = alice ? ALICE_NONCE_LABEL : BOB_NONCE_LABEL;
|
||||||
alice ? ALICE_NONCE_LABEL : BOB_NONCE_LABEL, secretKey);
|
String theirNonceLabel = alice ? BOB_NONCE_LABEL : ALICE_NONCE_LABEL;
|
||||||
byte[] theirNonce = cryptoComponent.deriveKeyBindingNonce(
|
byte[] ourNonce = cryptoComponent.mac(ourNonceLabel, secretKey);
|
||||||
alice ? BOB_NONCE_LABEL : ALICE_NONCE_LABEL, secretKey);
|
byte[] theirNonce = cryptoComponent.mac(theirNonceLabel, secretKey);
|
||||||
SecretKey ourMacKey = cryptoComponent.deriveKey(
|
String ourKeyLabel = alice ? ALICE_MAC_KEY_LABEL : BOB_MAC_KEY_LABEL;
|
||||||
alice ? ALICE_MAC_KEY_LABEL : BOB_MAC_KEY_LABEL, secretKey);
|
String theirKeyLabel = alice ? BOB_MAC_KEY_LABEL : ALICE_MAC_KEY_LABEL;
|
||||||
SecretKey theirMacKey = cryptoComponent.deriveKey(
|
SecretKey ourMacKey = cryptoComponent.deriveKey(ourKeyLabel, secretKey);
|
||||||
alice ? BOB_MAC_KEY_LABEL : ALICE_MAC_KEY_LABEL, secretKey);
|
SecretKey theirMacKey =
|
||||||
|
cryptoComponent.deriveKey(theirKeyLabel, secretKey);
|
||||||
|
|
||||||
// Save the other nonce and MAC key for the verification
|
// Save the other nonce and MAC key for the verification
|
||||||
localState.put(NONCE, theirNonce);
|
localState.put(NONCE, theirNonce);
|
||||||
|
|||||||
@@ -755,8 +755,7 @@ public class IntroductionIntegrationTest
|
|||||||
// Nonce 1
|
// Nonce 1
|
||||||
SecretKey sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
SecretKey sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
eKeyPair2.getPublic(), eKeyPair1, true);
|
eKeyPair2.getPublic(), eKeyPair1, true);
|
||||||
byte[] nonce1 = crypto.deriveKeyBindingNonce(ALICE_NONCE_LABEL,
|
byte[] nonce1 = crypto.mac(ALICE_NONCE_LABEL, sharedSecret);
|
||||||
sharedSecret);
|
|
||||||
|
|
||||||
// Signature 1
|
// Signature 1
|
||||||
byte[] sig1 = crypto.sign(SIGNING_LABEL, nonce1,
|
byte[] sig1 = crypto.sign(SIGNING_LABEL, nonce1,
|
||||||
@@ -791,7 +790,7 @@ public class IntroductionIntegrationTest
|
|||||||
byte[] ePublicKeyBytes1f = eKeyPair1f.getPublic().getEncoded();
|
byte[] ePublicKeyBytes1f = eKeyPair1f.getPublic().getEncoded();
|
||||||
sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
eKeyPair2.getPublic(), eKeyPair1f, true);
|
eKeyPair2.getPublic(), eKeyPair1f, true);
|
||||||
nonce1 = crypto.deriveKeyBindingNonce(ALICE_NONCE_LABEL, sharedSecret);
|
nonce1 = crypto.mac(ALICE_NONCE_LABEL, sharedSecret);
|
||||||
|
|
||||||
// recalculate MAC
|
// recalculate MAC
|
||||||
macKey1 = crypto.deriveKey(ALICE_MAC_KEY_LABEL, sharedSecret);
|
macKey1 = crypto.deriveKey(ALICE_MAC_KEY_LABEL, sharedSecret);
|
||||||
|
|||||||
Reference in New Issue
Block a user