Migrate Bluetooth protocol to BQP's master secret derivation

This commit is contained in:
str4d
2016-02-02 02:31:30 +00:00
parent 77e4ec381a
commit c822623677
4 changed files with 25 additions and 33 deletions

View File

@@ -205,28 +205,6 @@ class CryptoComponentImpl implements CryptoComponent {
return ByteUtils.readUint(random, CODE_BITS);
}
public SecretKey deriveBTMasterSecret(byte[] theirPublicKey,
KeyPair ourKeyPair, boolean alice) throws GeneralSecurityException {
MessageDigest messageDigest = getMessageDigest();
byte[] ourPublicKey = ourKeyPair.getPublic().getEncoded();
byte[] ourHash = messageDigest.digest(ourPublicKey);
byte[] theirHash = messageDigest.digest(theirPublicKey);
byte[] aliceInfo, bobInfo;
if (alice) {
aliceInfo = ourHash;
bobInfo = theirHash;
} else {
aliceInfo = theirHash;
bobInfo = ourHash;
}
PrivateKey ourPriv = ourKeyPair.getPrivate();
PublicKey theirPub = agreementKeyParser.parsePublicKey(theirPublicKey);
// The raw secret comes from the key agreement algorithm
byte[] raw = performRawKeyAgreement(ourPriv, theirPub);
// Derive the master secret from the raw secret using the hash KDF
return new SecretKey(hashKdf(raw, BT_MASTER, aliceInfo, bobInfo));
}
public int deriveBTConfirmationCode(SecretKey master, boolean alice) {
byte[] b = macKdf(master, alice ? BT_A_CONFIRM : BT_B_CONFIRM);
return ByteUtils.readUint(b, CODE_BITS);
@@ -290,6 +268,12 @@ class CryptoComponentImpl implements CryptoComponent {
return new SecretKey(macKdf(sharedSecret, MASTER_KEY));
}
public SecretKey deriveMasterSecret(byte[] theirPublicKey,
KeyPair ourKeyPair, boolean alice) throws GeneralSecurityException {
return deriveMasterSecret(deriveSharedSecret(
theirPublicKey,ourKeyPair, alice));
}
public TransportKeys deriveTransportKeys(TransportId t,
SecretKey master, long rotationPeriod, boolean alice) {
// Keys for the previous period are derived from the master secret

View File

@@ -146,7 +146,7 @@ abstract class Connector extends Thread {
// Derive the master secret
if (LOG.isLoggable(INFO))
LOG.info(pluginName + " deriving master secret");
return crypto.deriveBTMasterSecret(key, keyPair, alice);
return crypto.deriveMasterSecret(key, keyPair, alice);
}
protected void sendConfirmation(BdfWriter w, boolean confirmed)