author | Nikita Kozlov <nikita@mbdsys.com> |
Tue, 07 Dec 2010 22:57:56 +0100 | |
changeset 815 | ca323cff3ac9 |
parent 810 | 0ff0059f2ec3 |
permissions | -rw-r--r-- |
810
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
1 |
/* |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
2 |
* otr4j, the open source java otr library. |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
3 |
* |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
4 |
* Distributable under LGPL license. |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
5 |
* See terms of license at gnu.org. |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
6 |
*/ |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
7 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
8 |
package net.java.otr4j.crypto; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
9 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
10 |
import java.math.BigInteger; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
11 |
import java.security.KeyPair; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
12 |
import java.security.PrivateKey; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
13 |
import java.security.PublicKey; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
14 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
15 |
import javax.crypto.interfaces.DHPublicKey; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
16 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
17 |
/** |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
18 |
* |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
19 |
* @author George Politis |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
20 |
* |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
21 |
*/ |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
22 |
public interface OtrCryptoEngine { |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
23 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
24 |
public static final String MODULUS_TEXT = "00FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF"; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
25 |
public static final BigInteger MODULUS = new BigInteger(MODULUS_TEXT, 16); |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
26 |
public static final BigInteger BIGINTEGER_TWO = BigInteger.valueOf(2); |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
27 |
public static final BigInteger MODULUS_MINUS_TWO = MODULUS |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
28 |
.subtract(BIGINTEGER_TWO); |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
29 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
30 |
public static String GENERATOR_TEXT = "2"; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
31 |
public static BigInteger GENERATOR = new BigInteger(GENERATOR_TEXT, 10); |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
32 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
33 |
public static final int AES_KEY_BYTE_LENGTH = 16; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
34 |
public static final int SHA256_HMAC_KEY_BYTE_LENGTH = 32; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
35 |
public static final int DH_PRIVATE_KEY_MINIMUM_BIT_LENGTH = 320; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
36 |
public static final byte[] ZERO_CTR = new byte[] { 0x00, 0x00, 0x00, 0x00, |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
37 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
38 |
0x00 }; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
39 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
40 |
public static final int DSA_PUB_TYPE = 0; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
41 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
42 |
public abstract KeyPair generateDHKeyPair() throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
43 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
44 |
public abstract DHPublicKey getDHPublicKey(byte[] mpiBytes) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
45 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
46 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
47 |
public abstract DHPublicKey getDHPublicKey(BigInteger mpi) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
48 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
49 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
50 |
public abstract byte[] sha256Hmac(byte[] b, byte[] key) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
51 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
52 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
53 |
public abstract byte[] sha256Hmac(byte[] b, byte[] key, int length) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
54 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
55 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
56 |
public abstract byte[] sha1Hmac(byte[] b, byte[] key, int length) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
57 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
58 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
59 |
public abstract byte[] sha256Hmac160(byte[] b, byte[] key) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
60 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
61 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
62 |
public abstract byte[] sha256Hash(byte[] b) throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
63 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
64 |
public abstract byte[] sha1Hash(byte[] b) throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
65 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
66 |
public abstract byte[] aesDecrypt(byte[] key, byte[] ctr, byte[] b) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
67 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
68 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
69 |
public abstract byte[] aesEncrypt(byte[] key, byte[] ctr, byte[] b) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
70 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
71 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
72 |
public abstract BigInteger generateSecret(PrivateKey privKey, |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
73 |
PublicKey pubKey) throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
74 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
75 |
public abstract byte[] sign(byte[] b, PrivateKey privatekey) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
76 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
77 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
78 |
public abstract boolean verify(byte[] b, PublicKey pubKey, byte[] rs) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
79 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
80 |
|
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
81 |
public abstract String getFingerprint(PublicKey pubKey) |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
82 |
throws OtrCryptoException; |
0ff0059f2ec3
initial commit adding otr to beem, it's based on http://bitbucket.org/romanzadov/beem, with a better beem integration
Nikita Kozlov <nikita@mbdsys.com>
parents:
diff
changeset
|
83 |
} |