Changed the root package from net.sf.briar to org.briarproject.

This commit is contained in:
akwizgran
2014-01-08 16:18:30 +00:00
parent dce70f487c
commit 832476412c
427 changed files with 2507 additions and 2507 deletions

View File

@@ -0,0 +1,24 @@
package org.briarproject.api.crypto;
import java.security.GeneralSecurityException;
/** An authenticated cipher that support additional authenticated data. */
public interface AuthenticatedCipher {
/**
* Initializes this cipher with a key, an initialisation vector (IV) and
* additional authenticated data (AAD).
*/
void init(int opmode, SecretKey key, byte[] iv, byte[] aad)
throws GeneralSecurityException;
/** Encrypts or decrypts data in a single-part operation. */
int doFinal(byte[] input, int inputOff, int len, byte[] output,
int outputOff) throws GeneralSecurityException;
/** Returns the length of the message authenticated code (MAC) in bytes. */
int getMacLength();
/** Returns the block size of the cipher in bytes. */
int getBlockSize();
}

View File

@@ -0,0 +1,105 @@
package org.briarproject.api.crypto;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
public interface CryptoComponent {
SecretKey generateSecretKey();
MessageDigest getMessageDigest();
PseudoRandom getPseudoRandom(int seed1, int seed2);
SecureRandom getSecureRandom();
Signature getSignature();
KeyPair generateAgreementKeyPair();
KeyParser getAgreementKeyParser();
KeyPair generateSignatureKeyPair();
KeyParser getSignatureKeyParser();
/** Generates a random invitation code. */
int generateInvitationCode();
/**
* Derives two confirmation codes from the given master secret. The first
* code is for Alice to give to Bob; the second is for Bob to give to
* Alice.
*/
int[] deriveConfirmationCodes(byte[] secret);
/**
* Derives two nonces from the given master secret. The first nonce is for
* Alice to sign; the second is for Bob to sign.
*/
byte[][] deriveInvitationNonces(byte[] secret);
/**
* Derives a shared master secret from two public keys and one of the
* corresponding private keys.
* @param alice indicates whether the private key belongs to Alice or Bob.
*/
byte[] deriveMasterSecret(byte[] theirPublicKey, KeyPair ourKeyPair,
boolean alice) throws GeneralSecurityException;
/** Derives a group salt from the given master secret. */
byte[] deriveGroupSalt(byte[] secret);
/**
* Derives an initial secret for the given transport from the given master
* secret.
*/
byte[] deriveInitialSecret(byte[] secret, int transportIndex);
/**
* Derives a temporary secret for the given period from the given secret,
* which is either the initial shared secret or the previous period's
* temporary secret.
*/
byte[] deriveNextSecret(byte[] secret, long period);
/**
* Derives a tag key from the given temporary secret.
* @param alice indicates whether the key is for connections initiated by
* Alice or Bob.
*/
SecretKey deriveTagKey(byte[] secret, boolean alice);
/**
* Derives a frame key from the given temporary secret and connection
* number.
* @param alice indicates whether the key is for a connection initiated by
* Alice or Bob.
* @param initiator indicates whether the key is for the initiator's or the
* responder's side of the connection.
*/
SecretKey deriveFrameKey(byte[] secret, long connection, boolean alice,
boolean initiator);
/** Returns a cipher for encrypting and authenticating connections. */
AuthenticatedCipher getFrameCipher();
/** Encodes the pseudo-random tag that is used to recognise a connection. */
void encodeTag(byte[] tag, SecretKey tagKey, long connection);
/**
* Encrypts and authenticates the given plaintext so it can be written to
* storage. The encryption and authentication keys are derived from the
* given password. The ciphertext will be decryptable using the same
* password after the app restarts.
*/
byte[] encryptWithPassword(byte[] plaintext, char[] password);
/**
* Decrypts and authenticates the given ciphertext that has been read from
* storage. The encryption and authentication keys are derived from the
* given password. Returns null if the ciphertext cannot be decrypted and
* authenticated (for example, if the password is wrong).
*/
byte[] decryptWithPassword(byte[] ciphertext, char[] password);
}

View File

@@ -0,0 +1,17 @@
package org.briarproject.api.crypto;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import com.google.inject.BindingAnnotation;
/** Annotation for injecting the executor for long-running crypto tasks. */
@BindingAnnotation
@Target({ FIELD, METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface CryptoExecutor {}

View File

@@ -0,0 +1,23 @@
package org.briarproject.api.crypto;
import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.transport.ConnectionContext;
import org.briarproject.api.transport.Endpoint;
public interface KeyManager extends Service {
/**
* Returns a connection context for connecting to the given contact over
* the given transport, or null if an error occurs or the contact does not
* support the transport.
*/
ConnectionContext getConnectionContext(ContactId c, TransportId t);
/**
* Called whenever an endpoint has been added. The initial secret
* is erased before returning.
*/
void endpointAdded(Endpoint ep, long maxLatency, byte[] initialSecret);
}

View File

@@ -0,0 +1,21 @@
package org.briarproject.api.crypto;
/** A key pair consisting of a {@link PublicKey} and a {@link PrivateKey). */
public class KeyPair {
private final PublicKey publicKey;
private final PrivateKey privateKey;
public KeyPair(PublicKey publicKey, PrivateKey privateKey) {
this.publicKey = publicKey;
this.privateKey = privateKey;
}
public PublicKey getPublic() {
return publicKey;
}
public PrivateKey getPrivate() {
return privateKey;
}
}

View File

@@ -0,0 +1,11 @@
package org.briarproject.api.crypto;
import java.security.GeneralSecurityException;
public interface KeyParser {
PublicKey parsePublicKey(byte[] encodedKey) throws GeneralSecurityException;
PrivateKey parsePrivateKey(byte[] encodedKey)
throws GeneralSecurityException;
}

View File

@@ -0,0 +1,28 @@
package org.briarproject.api.crypto;
public interface MessageDigest {
/** @see {@link java.security.MessageDigest#digest()} */
byte[] digest();
/** @see {@link java.security.MessageDigest#digest(byte[])} */
byte[] digest(byte[] input);
/** @see {@link java.security.MessageDigest#digest(byte[], int, int)} */
int digest(byte[] buf, int offset, int len);
/** @see {@link java.security.MessageDigest#getDigestLength()} */
int getDigestLength();
/** @see {@link java.security.MessageDigest#reset()} */
void reset();
/** @see {@link java.security.MessageDigest#update(byte)} */
void update(byte input);
/** @see {@link java.security.MessageDigest#update(byte[])} */
void update(byte[] input);
/** @see {@link java.security.MessageDigest#update(byte[], int, int)} */
void update(byte[] input, int offset, int len);
}

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.crypto;
/** The private half of a public/private {@link KeyPair}. */
public interface PrivateKey {
/** Returns the encoded representation of this key. */
byte[] getEncoded();
}

View File

@@ -0,0 +1,7 @@
package org.briarproject.api.crypto;
/** A deterministic PRNG. */
public interface PseudoRandom {
byte[] nextBytes(int bytes);
}

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.crypto;
/** The public half of a public/private {@link KeyPair}. */
public interface PublicKey {
/** Returns the encoded representation of this key. */
byte[] getEncoded();
}

View File

@@ -0,0 +1,21 @@
package org.briarproject.api.crypto;
/** A secret key used for encryption and/or authentication. */
public interface SecretKey {
/** Returns the encoded representation of this key. */
byte[] getEncoded();
/**
* Returns a copy of this key - erasing this key will erase the copy and
* vice versa.
*/
SecretKey copy();
/**
* Erases this key from memory. Any copies derived from this key via the
* {@link #copy()} method, and any keys from which this key was derived via
* the {@link #copy()} method, are also erased.
*/
void erase();
}

View File

@@ -0,0 +1,31 @@
package org.briarproject.api.crypto;
import java.security.GeneralSecurityException;
public interface Signature {
/**
* @see {@link java.security.Signature#initSign(java.security.PrivateKey)}
*/
void initSign(PrivateKey k) throws GeneralSecurityException;
/**
* @see {@link java.security.Signature#initVafiry(java.security.PublicKey)}
*/
void initVerify(PublicKey k) throws GeneralSecurityException;
/** @see {@link java.security.Signature#update(byte)} */
void update(byte b);
/** @see {@link java.security.Signature#update(byte[])} */
void update(byte[] b);
/** @see {@link java.security.Signature#update(byte[], int, int)} */
void update(byte[] b, int off, int len);
/** @see {@link java.security.Signature#sign()} */
byte[] sign();
/** @see {@link java.security.Signature#verify(byte[])} */
boolean verify(byte[] signature);
}