1 /* NSData+Crypto.h - this file is part of SOGo
2  *
3  * Copyright (C) 2012 Nicolas Höft
4  * Copyright (C) 2012-2020 Inverse inc.
5  *
6  * Author: Nicolas Höft
7  *         Inverse inc.
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * This file is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; see the file COPYING.  If not, write to
21  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24 
25 #ifndef NSDATA_CRYPTO_H
26 #define NSDATA_CRYPTO_H
27 
28 #import <Foundation/NSData.h>
29 
30 @class NSObject;
31 
32 @interface NSData (SOGoCryptoExtension)
33 
34 - (NSData *) asCryptedPassUsingScheme: (NSString *) passwordScheme
35                              withSalt: (NSData *) theSalt
36                               keyPath: (NSString *) theKeyPath;
37 
38 - (BOOL) verifyUsingScheme: (NSString *) passwordScheme
39                 withPassword: (NSData *) thePassword
40                      keyPath: (NSString *) theKeyPath;
41 
42 - (NSData *) asLM;
43 - (NSData *) asMD4;
44 - (NSData *) asMD5;
45 - (NSData *) asSMD5UsingSalt: (NSData *) theSalt;
46 - (NSData *) asSHA1;
47 - (NSData *) asSSHAUsingSalt: (NSData *) theSalt;
48 - (NSData *) asSHA256;
49 - (NSData *) asSSHA256UsingSalt: (NSData *) theSalt;
50 - (NSData *) asSHA512;
51 - (NSData *) asSSHA512UsingSalt: (NSData *) theSalt;
52 - (NSData *) asSHA256CryptUsingSalt: (NSData *) theSalt;
53 - (NSData *) asSHA512CryptUsingSalt: (NSData *) theSalt;
54 - (NSData *) asSymAES128CBCUsingIV: (NSString *) theIV
55                            keyPath: (NSString *) theKeyPath;
56 - (NSData *) asCramMD5;
57 - (NSData *) asPBKDF2SHA1UsingSalt: (NSData *) theSalt;
58 - (NSData *) asCryptUsingSalt: (NSData *) theSalt;
59 - (NSData *) asMD5CryptUsingSalt: (NSData *) theSalt;
60 - (NSData *) asBlowfishCryptUsingSalt: (NSData *) theSalt;
61 #ifdef HAVE_SODIUM
62 - (NSData *) asArgon2iUsingSalt: (NSData *) theSalt;
63 # ifdef crypto_pwhash_ALG_ARGON2ID13
64 - (NSData *) asArgon2idUsingSalt: (NSData *) theSalt;
65 #endif /* crypto_pwhash_ALG_ARGON2ID13 */
66 #endif /* HAVE_SODIUM */
67 
68 - (NSData *) extractSalt: (NSString *) theScheme;
69 
70 + (NSData *) generateSaltForLength: (unsigned int) theLength
71                         withPrintable: (BOOL) doPrintable;
72 + (NSData *) generateSaltForLength: (unsigned int) theLength;
73 
74 + (NSString *) encodeDataAsHexString: (NSData *) theData;
75 + (NSData *) decodeDataFromHexString: (NSString *) theString;
76 
77 @end
78 
79 #endif /* NSDATA_CRYPTO_H */
80