Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
KeyDerivationFunction | 34 | 0 | - | 0 | 0 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.crypto.password; | |
21 | ||
22 | import java.io.IOException; | |
23 | ||
24 | import org.xwiki.crypto.params.cipher.symmetric.KeyParameter; | |
25 | import org.xwiki.crypto.params.cipher.symmetric.KeyWithIVParameters; | |
26 | import org.xwiki.crypto.password.params.KeyDerivationFunctionParameters; | |
27 | ||
28 | /** | |
29 | * Key derivation function from password interface. | |
30 | * | |
31 | * @version $Id: 21052e0bf378847b87a8df3abfd3465164685c67 $ | |
32 | * @since 5.4M1 | |
33 | */ | |
34 | public interface KeyDerivationFunction | |
35 | { | |
36 | /** | |
37 | * @return the current requested key size in bytes. | |
38 | */ | |
39 | int getKeySize(); | |
40 | ||
41 | /** | |
42 | * Override the key size receive from the factory. | |
43 | * | |
44 | * This is mainly useful internally when the key size from parameter is negative | |
45 | * (see {@link org.xwiki.crypto.password.params.KeyDerivationFunctionParameters}) to set the effective key size that | |
46 | * should be produced by the derivation function. This value will not be encoded with the function, which means | |
47 | * that the recipient of the encoded form will also have to overwrite the key size to be able to use this function. | |
48 | * | |
49 | * @param keySize the length of the key to generate. A negative or null value means use the one from parameters. | |
50 | */ | |
51 | void overrideKeySize(int keySize); | |
52 | ||
53 | /** | |
54 | * @return true if the key size has been overwritten. | |
55 | */ | |
56 | boolean isKeySizeOverwritten(); | |
57 | ||
58 | /** | |
59 | * @return the parameters used by this key derivation function. | |
60 | */ | |
61 | KeyDerivationFunctionParameters getParameters(); | |
62 | ||
63 | /** | |
64 | * Derive a key from the provided password. | |
65 | * | |
66 | * @param password the password already converted properly to a byte array. | |
67 | * See ({@link PasswordToByteConverter}) for converting password properly. | |
68 | * @return a key parameters with the generated key. | |
69 | */ | |
70 | KeyParameter derive(byte[] password); | |
71 | ||
72 | /** | |
73 | * Derive a key and an initialization vector of the requested size from the provided password. | |
74 | * | |
75 | * Security note: Deriving the initialization vector and the key from the same password is not recommended since | |
76 | * it partially defeat the purpose of the initialization vector which is to salt the resulting encrypted data. | |
77 | * | |
78 | * @param password the password already converted properly to a byte array. | |
79 | * See ({@link PasswordToByteConverter}) for converting password properly. | |
80 | * @param ivSize the initialization vector size in byte. | |
81 | * @return a key with iv parameters. | |
82 | */ | |
83 | KeyWithIVParameters derive(byte[] password, int ivSize); | |
84 | ||
85 | /** | |
86 | * Serialize the definition of this key derivation function. | |
87 | * | |
88 | * This serialization could be provided to an appropriate factory (like the one that have been used to create this | |
89 | * function) to produce an equivalent function. The serialization contains the key algorithm and the key parameters. | |
90 | * For best interoperability, the recommended encoding is ASN.1 in DER format. | |
91 | * | |
92 | * @return an encoded definition of this derivation function. | |
93 | * @throws IOException on error | |
94 | */ | |
95 | byte[] getEncoded() throws IOException; | |
96 | } |