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