-
Notifications
You must be signed in to change notification settings - Fork 0
/
FGIntCryptography.h
262 lines (207 loc) · 10.3 KB
/
FGIntCryptography.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
License, info, etc
------------------
This implementation is made by me, Walied Othman, to contact me mail to [email protected], always mention wether it's about
FGInt for Objective-C, preferably in the subject line. My source code is free, but only to other free software,
it's a two-way street, if you use my code in an application from which you won't make any money of (e.g. software for the good of
mankind) then go right ahead, I do demand acknowledgement for my work. However, if you're using my code in a commercial application,
an application from which you'll make money, then yes, I charge a license-fee, as described in the license agreement for commercial
use, see the textfile in this zip-file.
If you're going to use these implementations, let me know, so I can put up a link on my page if desired, I 'm always curious as to
see where my spawn ends up in. If any algorithm is patented in your country, you should acquire a license before using it. Modified
versions of this software must contain an acknowledgement of the original author (=me).
This implementation is available at
http://www.submanifold.be
copyright 2012, Walied Othman
This header may not be removed.
*/
/*
#define rsaKey @"RSA"
#define elgamalKey @"ElGamal"
#define dsaKey @"DSA"
#define gostdsaKey @"GOSTDSA"
*/
#import "FGInt.h"
#import "ECGFp.h"
#define FGIntCryptography_version 20150209
@interface FGIntRSA : NSObject <NSMutableCopying> {
FGInt *modulus, *publicExponent, *privateKey, *pFGInt, *qFGInt, *pInvertedModQ;
}
@property (assign, readwrite) FGInt *modulus;
@property (assign, readwrite) FGInt *publicExponent;
@property (assign, readwrite) FGInt *privateKey;
@property (assign, readwrite) FGInt *pFGInt;
@property (assign, readwrite) FGInt *qFGInt;
@property (assign, readwrite) FGInt *pInvertedModQ;
-(void) dealloc;
-(id) initWithBitLength: (FGIntOverflow) bitLength;
-(id) initWithNSData: (NSData *) dataSeed;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(void) setPublicKeyWithBase64NSString: (NSString *) publicKeyBase64NSString;
-(NSData *) publicKeyToNSData;
-(NSString *) publicKeyToBase64NSString;
-(void) setSecretKeyWithNSData: (NSData *) secretKeyNSData;
-(void) setSecretKeyWithBase64NSString: (NSString *) secretKeyBase64NSString;
-(NSData *) secretKeyToNSData;
-(NSString *) secretKeyToBase64NSString;
-(NSData *) encryptNSString: (NSString *) plainText;
-(NSData *) encryptNSData: (NSData *) plainText;
-(NSData *) decryptNSData: (NSData *) cipherText;
-(NSData *) signNSString: (NSString *) plainText;
-(NSData *) signNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSString: (NSString *) plainText;
@end
@interface FGIntElGamal : NSObject <NSCopying> {
FGInt *primeFGInt, *gFGInt, *secretKey, *yFGInt;
}
@property (assign, readwrite) FGInt *primeFGInt;
@property (assign, readwrite) FGInt *gFGInt;
@property (assign, readwrite) FGInt *secretKey;
@property (assign, readwrite) FGInt *yFGInt;
-(void) setGFGIntAndComputeY: (FGInt *) newG;
-(void) setSecretKeyAndComputeY: (FGInt *) newSecretKey;
-(void) dealloc;
-(id) initWithBitLength: (FGIntOverflow) bitLength;
// -(id) initWithNSData: (NSData *) secretKeyData;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(void) setPublicKeyWithBase64NSString: (NSString *) publicKeyBase64NSString;
-(NSData *) publicKeyToNSData;
-(NSString *) publicKeyToBase64NSString;
-(void) setSecretKeyWithNSData: (NSData *) secretKeyNSData;
-(void) setSecretKeyWithBase64NSString: (NSString *) secretKeyBase64NSString;
-(NSData *) secretKeyToNSData;
-(NSString *) secretKeyToBase64NSString;
-(NSData *) encryptNSString: (NSString *) plainText;
-(NSData *) encryptNSData: (NSData *) plainText;
-(NSData *) decryptNSData: (NSData *) cipherText;
-(NSData *) signNSString: (NSString *) plainText;
-(NSData *) signNSString: (NSString *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSString: (NSString *) plainText;
@end
@interface FGIntDSA : NSObject <NSCopying> {
FGInt *pFGInt, *qFGInt, *gFGInt, *secretKey, *yFGInt;
}
@property (assign, readwrite) FGInt *pFGInt;
@property (assign, readwrite) FGInt *qFGInt;
@property (assign, readwrite) FGInt *gFGInt;
@property (assign, readwrite) FGInt *secretKey;
@property (assign, readwrite) FGInt *yFGInt;
-(void) setGFGIntAndComputeY: (FGInt *) newG;
-(void) setSecretKeyAndComputeY: (FGInt *) newSecretKey;
-(void) dealloc;
-(id) initWithBitLength: (FGIntOverflow) bitLength;
-(id) initWithNSData: (NSData *) secretKeyData;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(void) setPublicKeyWithBase64NSString: (NSString *) publicKeyBase64NSString;
-(NSData *) publicKeyToNSData;
-(NSString *) publicKeyToBase64NSString;
-(void) setSecretKeyWithNSData: (NSData *) secretKeyNSData;
-(void) setSecretKeyWithBase64NSString: (NSString *) secretKeyBase64NSString;
-(NSData *) secretKeyToNSData;
-(NSString *) secretKeyToBase64NSString;
-(NSData *) signNSString: (NSString *) plainText;
-(NSData *) signNSString: (NSString *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSString: (NSString *) plainText;
@end
@interface FGIntGOSTDSA : NSObject <NSCopying> {
FGInt *pFGInt, *qFGInt, *gFGInt, *secretKey, *yFGInt;
}
@property (assign, readwrite) FGInt *pFGInt;
@property (assign, readwrite) FGInt *qFGInt;
@property (assign, readwrite) FGInt *gFGInt;
@property (assign, readwrite) FGInt *secretKey;
@property (assign, readwrite) FGInt *yFGInt;
-(void) setGFGIntAndComputeY: (FGInt *) newG;
-(void) setSecretKeyAndComputeY: (FGInt *) newSecretKey;
-(void) dealloc;
-(id) initWithBitLength: (FGIntOverflow) bitLength;
-(id) initWithNSData: (NSData *) secretKeyData;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(void) setPublicKeyWithBase64NSString: (NSString *) publicKeyBase64NSString;
-(NSData *) publicKeyToNSData;
-(NSString *) publicKeyToBase64NSString;
-(void) setSecretKeyWithNSData: (NSData *) secretKeyNSData;
-(void) setSecretKeyWithBase64NSString: (NSString *) secretKeyBase64NSString;
-(NSData *) secretKeyToNSData;
-(NSString *) secretKeyToBase64NSString;
-(NSData *) signNSString: (NSString *) plainText;
-(NSData *) signNSString: (NSString *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSString: (NSString *) plainText;
@end
@interface ECDSA : NSObject <NSCopying> {
ECPoint *gPoint, *yPoint;
FGInt *secretKey;
}
@property (assign, readwrite) ECPoint *gPoint;
@property (assign, readwrite) FGInt *secretKey;
@property (assign, readwrite) ECPoint *yPoint;
-(void) dealloc;
-(void) setGPointAndComputeYPoint: (ECPoint *) newG;
-(void) setSecretKeyAndComputeYPoint: (FGInt *) newSecretKey;
-(id) initWithBitLength: (FGIntOverflow) bitLength;
-(id) initWithNSData: (NSData *) secretKeyData;
-(void) setSecretKeyWithNSData: (NSData *) secretKeyNSData;
-(void) setSecretKeyWithBase64NSString: (NSString *) secretKeyBase64NSString;
-(NSData *) secretKeyToNSData;
-(NSString *) secretKeyToBase64NSString;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(void) setPublicKeyWithBase64NSString: (NSString *) publicKeyBase64NSString;
-(NSData *) publicKeyToNSData;
-(NSString *) publicKeyToBase64NSString;
-(NSData *) signNSString: (NSString *) plainText;
-(NSData *) signNSString: (NSString *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) signNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSData: (NSData *) plainText;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSString: (NSString *) plainText;
@end
@interface ECElGamal : NSObject <NSCopying> {
ECPoint *gPoint, *yPoint;
FGInt *secretKey;
}
@property (assign, readwrite) ECPoint *gPoint;
@property (assign, readwrite) FGInt *secretKey;
@property (assign, readwrite) ECPoint *yPoint;
-(void) dealloc;
-(void) setGPointAndComputeYPoint: (ECPoint *) newG;
-(void) setSecretKeyAndComputeYPoint: (FGInt *) newSecretKey;
-(id) initWithBitLength: (FGIntOverflow) bitLength;
-(id) initWithNSData: (NSData *) secretKeyData;
-(void) setSecretKeyWithNSData: (NSData *) secretKeyNSData;
-(void) setSecretKeyWithBase64NSString: (NSString *) secretKeyBase64NSString;
-(NSData *) secretKeyToNSData;
-(NSString *) secretKeyToBase64NSString;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(void) setPublicKeyWithBase64NSString: (NSString *) publicKeyBase64NSString;
-(NSData *) publicKeyToNSData;
-(NSString *) publicKeyToBase64NSString;
-(NSData *) encryptNSString: (NSString *) plainText;
-(NSData *) encryptNSString: (NSString *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) encryptNSData: (NSData *) plainText withRandomNSData: (NSData *) kData;
-(NSData *) encryptNSData: (NSData *) plainText;
-(NSData *) decryptNSData: (NSData *) cipherText;
@end
@interface NISTECDSA : ECDSA <NSCopying> {
tag nistPrime;
}
@property (assign, readwrite) tag nistPrime;
-(id) initWithNISTcurve: (tag) nistPrimeTag;
-(void) setGPointAndComputeYPoint: (ECPoint *) newG;
-(void) setSecretKeyAndComputeYPoint: (FGInt *) newSecretKey;
-(void) setPublicKeyWithNSData: (NSData *) publicKeyNSData;
-(NSData *) signNSData: (NSData *) plainText withRandomNSData: (NSData *) kData;
-(BOOL) verifySignature: (NSData *) signature ofPlainTextNSData: (NSData *) plainText;
@end
//@interface FGIntCryptography : NSObject {
//}
//@end