mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Note that this is only the generator part of Fortuna, not the accumulator. The generator requires a seed, which is provided by a platform-specific implementation of SeedProvider. On Linux the implementation reads the seed from /dev/urandom.
27 lines
945 B
Java
27 lines
945 B
Java
package org.briarproject.crypto;
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
import org.briarproject.BriarTestCase;
|
|
import org.briarproject.TestSeedProvider;
|
|
import org.briarproject.api.crypto.CryptoComponent;
|
|
import org.briarproject.api.crypto.KeyPair;
|
|
import org.briarproject.api.crypto.SeedProvider;
|
|
import org.junit.Test;
|
|
|
|
public class KeyAgreementTest extends BriarTestCase {
|
|
|
|
@Test
|
|
public void testKeyAgreement() throws Exception {
|
|
SeedProvider seedProvider = new TestSeedProvider();
|
|
CryptoComponent crypto = new CryptoComponentImpl(seedProvider);
|
|
KeyPair aPair = crypto.generateAgreementKeyPair();
|
|
byte[] aPub = aPair.getPublic().getEncoded();
|
|
KeyPair bPair = crypto.generateAgreementKeyPair();
|
|
byte[] bPub = bPair.getPublic().getEncoded();
|
|
byte[] aSecret = crypto.deriveMasterSecret(aPub, bPair, true);
|
|
byte[] bSecret = crypto.deriveMasterSecret(bPub, aPair, false);
|
|
assertArrayEquals(aSecret, bSecret);
|
|
}
|
|
}
|