1 package org.bouncycastle.jce.spec;
2 
3 import java.security.spec.AlgorithmParameterSpec;
4 
5 import org.bouncycastle.util.Arrays;
6 
7 /**
8  * Parameter spec for an integrated encryptor, as in IEEE P1363a
9  */
10 public class IESParameterSpec
11     implements AlgorithmParameterSpec
12 {
13     private byte[] derivation;
14     private byte[] encoding;
15     private int macKeySize;
16     private int cipherKeySize;
17     private byte[] nonce;
18     private boolean usePointCompression;
19 
20 
21     /**
22      * Set the IES engine parameters.
23      *
24      * @param derivation the optional derivation vector for the KDF.
25      * @param encoding   the optional encoding vector for the KDF.
26      * @param macKeySize the key size (in bits) for the MAC.
27      */
IESParameterSpec( byte[] derivation, byte[] encoding, int macKeySize)28     public IESParameterSpec(
29         byte[] derivation,
30         byte[] encoding,
31         int macKeySize)
32     {
33         this(derivation, encoding, macKeySize, -1, null, false);
34     }
35 
36     /**
37      * Set the IES engine parameters.
38      *
39      * @param derivation    the optional derivation vector for the KDF.
40      * @param encoding      the optional encoding vector for the KDF.
41      * @param macKeySize    the key size (in bits) for the MAC.
42      * @param cipherKeySize the key size (in bits) for the block cipher.
43      * @param nonce         an IV to use initialising the block cipher.
44      */
IESParameterSpec( byte[] derivation, byte[] encoding, int macKeySize, int cipherKeySize, byte[] nonce)45     public IESParameterSpec(
46         byte[] derivation,
47         byte[] encoding,
48         int macKeySize,
49         int cipherKeySize,
50         byte[] nonce)
51     {
52         this(derivation, encoding, macKeySize, cipherKeySize, nonce, false);
53     }
54 
55     /**
56      * Set the IES engine parameters.
57      *
58      * @param derivation    the optional derivation vector for the KDF.
59      * @param encoding      the optional encoding vector for the KDF.
60      * @param macKeySize    the key size (in bits) for the MAC.
61      * @param cipherKeySize the key size (in bits) for the block cipher.
62      * @param nonce         an IV to use initialising the block cipher.
63      * @param usePointCompression whether to use EC point compression or not (false by default)
64      */
IESParameterSpec( byte[] derivation, byte[] encoding, int macKeySize, int cipherKeySize, byte[] nonce, boolean usePointCompression)65     public IESParameterSpec(
66         byte[] derivation,
67         byte[] encoding,
68         int macKeySize,
69         int cipherKeySize,
70         byte[] nonce,
71         boolean usePointCompression)
72     {
73         if (derivation != null)
74         {
75             this.derivation = new byte[derivation.length];
76             System.arraycopy(derivation, 0, this.derivation, 0, derivation.length);
77         }
78         else
79         {
80             this.derivation = null;
81         }
82 
83         if (encoding != null)
84         {
85             this.encoding = new byte[encoding.length];
86             System.arraycopy(encoding, 0, this.encoding, 0, encoding.length);
87         }
88         else
89         {
90             this.encoding = null;
91         }
92 
93         this.macKeySize = macKeySize;
94         this.cipherKeySize = cipherKeySize;
95         this.nonce = Arrays.clone(nonce);
96         this.usePointCompression = usePointCompression;
97     }
98 
99     /**
100      * return the derivation vector.
101      */
getDerivationV()102     public byte[] getDerivationV()
103     {
104         return Arrays.clone(derivation);
105     }
106 
107     /**
108      * return the encoding vector.
109      */
getEncodingV()110     public byte[] getEncodingV()
111     {
112         return Arrays.clone(encoding);
113     }
114 
115     /**
116      * return the key size in bits for the MAC used with the message
117      */
getMacKeySize()118     public int getMacKeySize()
119     {
120         return macKeySize;
121     }
122 
123     /**
124      * return the key size in bits for the block cipher used with the message
125      */
getCipherKeySize()126     public int getCipherKeySize()
127     {
128         return cipherKeySize;
129     }
130 
131     /**
132      * Return the nonce (IV) value to be associated with message.
133      *
134      * @return block cipher IV for message.
135      */
getNonce()136     public byte[] getNonce()
137     {
138         return Arrays.clone(nonce);
139     }
140 
141     /**
142      * Set the 'point compression' flag.
143      */
setPointCompression(boolean usePointCompression)144     public void setPointCompression(boolean usePointCompression)
145     {
146         this.usePointCompression = usePointCompression;
147     }
148 
149     /**
150      * Return the 'point compression' flag.
151      *
152      * @return the point compression flag
153      */
getPointCompression()154     public boolean getPointCompression()
155     {
156         return usePointCompression;
157     }
158 }