|
| 1 | +/* |
| 2 | + * JBoss, Home of Professional Open Source. |
| 3 | + * Copyright Red Hat, Inc., and individual contributors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#import <Foundation/Foundation.h> |
| 19 | + |
| 20 | +// constants used by PBKDF2 algorithm. |
| 21 | +extern const NSInteger AGPBKDF2Iterations; |
| 22 | +extern const NSInteger AGPBKDF2MinimumIterations; |
| 23 | +extern const NSInteger AGPBKDF2DerivedKeyLength; |
| 24 | +extern const NSInteger AGPBKDF2MinimumSaltLength; |
| 25 | + |
| 26 | +/** |
| 27 | + * Class that derives a key from a text password/passphrase using |
| 28 | + * the PBKDF2 algorithm provided by CommonCrypto. |
| 29 | + * (see http://en.wikipedia.org/wiki/PBKDF2) |
| 30 | + */ |
| 31 | +@interface AGPBKDF2 : NSObject |
| 32 | + |
| 33 | +/** |
| 34 | + * Derive a key from text password/passphrase. |
| 35 | + * |
| 36 | + * @param password The password/passphrase to use for key derivation. |
| 37 | + * |
| 38 | + * @return an NSData object containing the derived key. |
| 39 | + */ |
| 40 | +- (NSData *)deriveKey:(NSString *)password; |
| 41 | + |
| 42 | +/** |
| 43 | + * Derive a key from text password/passphrase. |
| 44 | + * |
| 45 | + * @param password The password/passphrase to use for key derivation. |
| 46 | + * @param salt A randomly choosen value used used during key derivation. |
| 47 | + * |
| 48 | + * @return an NSData object containing the derived key. |
| 49 | + */ |
| 50 | +- (NSData *)deriveKey:(NSString *)password salt:(NSData *)salt; |
| 51 | + |
| 52 | +/** |
| 53 | + * Derive a key from text password/passphrase. |
| 54 | + * |
| 55 | + * @param password The password/passphrase to use for key derivation. |
| 56 | + * @param salt A randomly choosen value used used during key derivation. |
| 57 | + * @param iterations The number of iterations against the cryptographic hash. |
| 58 | + * |
| 59 | + * @return an NSData object containing the derived key. |
| 60 | + */ |
| 61 | +- (NSData *)deriveKey:(NSString *)password salt:(NSData *)salt iterations:(NSInteger)iterations; |
| 62 | + |
| 63 | +- (BOOL)validate:(NSString *)password encryptedPassword:(NSData *)encryptedPassword salt:(NSData *)salt; |
| 64 | + |
| 65 | +/** |
| 66 | + * Returns the salt used for the key derivation |
| 67 | + * |
| 68 | + * @return an NSData object containing the salt |
| 69 | + */ |
| 70 | +- (NSData *)salt; |
| 71 | + |
| 72 | +@end |
0 commit comments