mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Added interfaces for reading and writing packets and recognising which
contact originated an incoming connection, and an implementation of the PacketWriter interface.
This commit is contained in:
@@ -8,6 +8,10 @@ import java.security.NoSuchProviderException;
|
||||
import java.security.Security;
|
||||
import java.security.Signature;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.crypto.KeyParser;
|
||||
|
||||
@@ -18,11 +22,15 @@ class CryptoComponentImpl implements CryptoComponent {
|
||||
private static final String PROVIDER = "BC";
|
||||
private static final String DIGEST_ALGO = "SHA-256";
|
||||
private static final String KEY_PAIR_ALGO = "ECDSA";
|
||||
private static final int KEY_PAIR_KEYSIZE = 256;
|
||||
private static final int KEY_PAIR_KEYSIZE = 256; // Bits
|
||||
private static final String MAC_ALGO = "HMacSHA256";
|
||||
private static final String SECRET_KEY_ALGO = "AES";
|
||||
private static final int SECRET_KEY_KEYSIZE = 256; // Bits
|
||||
private static final String SIGNATURE_ALGO = "ECDSA";
|
||||
|
||||
private final KeyParser keyParser;
|
||||
private final KeyPairGenerator keyPairGenerator;
|
||||
private final KeyGenerator keyGenerator;
|
||||
|
||||
CryptoComponentImpl() {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
@@ -31,6 +39,9 @@ class CryptoComponentImpl implements CryptoComponent {
|
||||
keyPairGenerator = KeyPairGenerator.getInstance(KEY_PAIR_ALGO,
|
||||
PROVIDER);
|
||||
keyPairGenerator.initialize(KEY_PAIR_KEYSIZE);
|
||||
keyGenerator = KeyGenerator.getInstance(SECRET_KEY_ALGO,
|
||||
PROVIDER);
|
||||
keyGenerator.init(SECRET_KEY_KEYSIZE);
|
||||
} catch(NoSuchAlgorithmException impossible) {
|
||||
throw new RuntimeException(impossible);
|
||||
} catch(NoSuchProviderException impossible) {
|
||||
@@ -42,10 +53,24 @@ class CryptoComponentImpl implements CryptoComponent {
|
||||
return keyPairGenerator.generateKeyPair();
|
||||
}
|
||||
|
||||
public SecretKey generateSecretKey() {
|
||||
return keyGenerator.generateKey();
|
||||
}
|
||||
|
||||
public KeyParser getKeyParser() {
|
||||
return keyParser;
|
||||
}
|
||||
|
||||
public Mac getMac() {
|
||||
try {
|
||||
return Mac.getInstance(MAC_ALGO, PROVIDER);
|
||||
} catch(NoSuchAlgorithmException impossible) {
|
||||
throw new RuntimeException(impossible);
|
||||
} catch(NoSuchProviderException impossible) {
|
||||
throw new RuntimeException(impossible);
|
||||
}
|
||||
}
|
||||
|
||||
public MessageDigest getMessageDigest() {
|
||||
try {
|
||||
return MessageDigest.getInstance(DIGEST_ALGO, PROVIDER);
|
||||
|
||||
Reference in New Issue
Block a user