]> git.saurik.com Git - apple/security.git/blob - OSX/shared_regressions/si-44-seckey-ies.m
Security-58286.31.2.tar.gz
[apple/security.git] / OSX / shared_regressions / si-44-seckey-ies.m
1 /*
2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 #import <Foundation/Foundation.h>
26 #import <Security/SecItemPriv.h>
27
28 #import <corecrypto/ccrng.h>
29 #import <corecrypto/ccsha1.h>
30 #import <corecrypto/ccsha2.h>
31 #import <corecrypto/ccec.h>
32 #import <corecrypto/ccecies.h>
33
34 #include "shared_regressions.h"
35
36 static void test_ies_run(id privateKey, SecKeyAlgorithm algorithm) {
37 NSError *error = nil;
38 id publicKey = CFBridgingRelease(SecKeyCopyPublicKey((SecKeyRef)privateKey));
39 ok(publicKey, "public key retrieved");
40
41 ok(SecKeyIsAlgorithmSupported((SecKeyRef)privateKey, kSecKeyOperationTypeDecrypt, algorithm),
42 "%@ supported for decryption", algorithm);
43 ok(SecKeyIsAlgorithmSupported((SecKeyRef)publicKey, kSecKeyOperationTypeEncrypt, algorithm),
44 "%@ supported for encryption", algorithm);
45 ok(!SecKeyIsAlgorithmSupported((SecKeyRef)publicKey, kSecKeyOperationTypeDecrypt, algorithm),
46 "%@ not supported for decryption - pubkey", algorithm);
47 ok(!SecKeyIsAlgorithmSupported((SecKeyRef)privateKey, kSecKeyOperationTypeEncrypt, algorithm),
48 "%@ not supported for encryption - privKey", algorithm);
49
50 NSData *message = [NSData dataWithBytes:"hello" length:5];
51 error = nil;
52 NSData *encrypted = CFBridgingRelease(SecKeyCreateEncryptedData((SecKeyRef)publicKey, algorithm, (CFDataRef)message, (void *)&error));
53 ok(encrypted, "message encrypted");
54
55 error = nil;
56 NSData *decrypted = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privateKey, algorithm, (CFDataRef)encrypted, (void *)&error));
57 ok(decrypted, "encrypted message decrypted");
58 ok([decrypted isEqual:message], "decrypted message is equal as original one (original:%@ decrypted:%@)", message, decrypted);
59
60 // Modify encrypted message and verify that it cannot be decrypted.
61 NSMutableData *badEncrypted = [NSMutableData dataWithData:encrypted];
62 UInt8 *badEncryptedBuffer = badEncrypted.mutableBytes;
63 badEncryptedBuffer[badEncrypted.length - 8] ^= 0xff;
64
65 error = nil;
66 decrypted = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privateKey, algorithm, (CFDataRef)badEncrypted, (void *)&error));
67 ok(decrypted == nil, "broken encrypted message failed to decrypt (tag breakage)");
68
69 badEncrypted = [NSMutableData dataWithData:encrypted];
70 badEncryptedBuffer = badEncrypted.mutableBytes;
71 badEncryptedBuffer[badEncrypted.length - 20] ^= 0xff;
72
73 error = nil;
74 decrypted = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privateKey, algorithm, (CFDataRef)badEncrypted, (void *)&error));
75 ok(decrypted == nil, "broken encrypted message failed to decrypt (ciphertext breakage)");
76
77 badEncrypted = [NSMutableData dataWithData:encrypted];
78 badEncryptedBuffer = badEncrypted.mutableBytes;
79 badEncryptedBuffer[0] ^= 0xff;
80
81 error = nil;
82 decrypted = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privateKey, algorithm, (CFDataRef)badEncrypted, (void *)&error));
83 ok(decrypted == nil, "broken encrypted message failed to decrypt (pubkey intro breakage)");
84
85 badEncrypted = [NSMutableData dataWithData:encrypted];
86 badEncryptedBuffer = badEncrypted.mutableBytes;
87 badEncryptedBuffer[1] ^= 0xff;
88
89 error = nil;
90 decrypted = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privateKey, algorithm, (CFDataRef)badEncrypted, (void *)&error));
91 ok(decrypted == nil, "broken encrypted message failed to decrypt (pubkey data breakage)");
92 }
93 static const int TestCountIESRun = 12;
94
95 static void test_ecies() {
96 NSError *error;
97 id privateKey;
98
99 privateKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)@{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @192}, (void *)&error));
100 ok(privateKey, "key generation error %@", error);
101 error = nil;
102 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM);
103 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM);
104 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM);
105 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM);
106 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM);
107
108 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
109 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
110 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
111 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
112
113 privateKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)@{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @256}, (void *)&error));
114 ok(privateKey, "key generation error %@", error);
115 error = nil;
116 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA1AESGCM);
117 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA224AESGCM);
118 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM);
119 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM);
120 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM);
121
122 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
123 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
124 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
125 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
126
127 privateKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)@{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @521}, (void *)&error));
128 ok(privateKey, "key generation error %@", error);
129 error = nil;
130 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM);
131 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM);
132 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM);
133 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM);
134 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM);
135
136 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
137 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
138 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
139 test_ies_run(privateKey, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
140 }
141 static const int TestCountECIES = TestCountIESRun * 9 * 3 + 3;
142
143 static void test_rsawrap() {
144 NSError *error;
145 id privateKey;
146
147 privateKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)@{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA, (id)kSecAttrKeySizeInBits: @1024}, (void *)&error));
148 ok(privateKey, "key generation error %@", error);
149 error = nil;
150 test_ies_run(privateKey, kSecKeyAlgorithmRSAEncryptionOAEPSHA1AESGCM);
151 test_ies_run(privateKey, kSecKeyAlgorithmRSAEncryptionOAEPSHA224AESGCM);
152 test_ies_run(privateKey, kSecKeyAlgorithmRSAEncryptionOAEPSHA256AESGCM);
153 test_ies_run(privateKey, kSecKeyAlgorithmRSAEncryptionOAEPSHA384AESGCM);
154
155 privateKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)@{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA, (id)kSecAttrKeySizeInBits: @4096}, (void *)&error));
156 ok(privateKey, "key generation error %@", error);
157 error = nil;
158 test_ies_run(privateKey, kSecKeyAlgorithmRSAEncryptionOAEPSHA512AESGCM);
159 }
160 static const int TestCountRSAWRAP = TestCountIESRun * 5 + 2;
161
162 static void test_ies_against_corecrypto(id privKey, ccec_const_cp_t cp, const struct ccdigest_info *di, uint32_t ccKeySize, bool secureIV, SecKeyAlgorithm algorithm) {
163 // Generate SecKey and import it as corecrypto fullkey.
164 NSError *error;
165 NSData *privKeyData = CFBridgingRelease(SecKeyCopyExternalRepresentation((SecKeyRef)privKey, (void *)&error));
166 ok(privKeyData != nil, "export key (error %@)", error);
167 ccec_full_ctx_decl_cp(cp, fullkey);
168 ok(ccec_x963_import_priv(cp, privKeyData.length, privKeyData.bytes, fullkey) == 0, "error importing cc ec key");
169
170 // SecKey encrypt -> cc decrypt.
171 static const UInt8 knownPlaintext[] = "KNOWN PLAINTEXT";
172 NSData *plaintext = [NSData dataWithBytes:knownPlaintext length:sizeof(knownPlaintext)];
173 error = nil;
174 id publicKey = CFBridgingRelease(SecKeyCopyPublicKey((SecKeyRef)privKey));
175 NSData *ciphertext = CFBridgingRelease(SecKeyCreateEncryptedData((SecKeyRef)publicKey, algorithm, (CFDataRef)plaintext, (void *)&error));
176 ok(ciphertext != nil, "encrypt data with SecKey (error %@)", error);
177 struct ccecies_gcm ecies_dec;
178 ccecies_decrypt_gcm_setup(&ecies_dec, di, ccaes_gcm_decrypt_mode(), ccKeySize, 16,
179 ECIES_EPH_PUBKEY_IN_SHAREDINFO1 | ECIES_EXPORT_PUB_STANDARD | (secureIV ? 0 : ECIES_LEGACY_IV));
180 size_t decryptedLength = plaintext.length;
181 NSMutableData *decrypted = [NSMutableData dataWithLength:decryptedLength];
182 if (ciphertext != nil) {
183 ok(ccecies_decrypt_gcm(fullkey, &ecies_dec, ciphertext.length, ciphertext.bytes, 0, NULL, 0, NULL,
184 &decryptedLength, decrypted.mutableBytes) == 0, "decrypt data with cc failed");
185 }
186 ok(decryptedLength = plaintext.length);
187 ok([plaintext isEqualToData:decrypted], "cc decrypted data are the same");
188
189 // cc encrypt -> SecKey decrypt
190 struct ccecies_gcm ecies_enc;
191 ccecies_encrypt_gcm_setup(&ecies_enc, di, ccrng(NULL), ccaes_gcm_encrypt_mode(), ccKeySize, 16,
192 ECIES_EPH_PUBKEY_IN_SHAREDINFO1 | ECIES_EXPORT_PUB_STANDARD | (secureIV ? 0 : ECIES_LEGACY_IV));
193 size_t encryptedLength = ccecies_encrypt_gcm_ciphertext_size(ccec_ctx_pub(fullkey), &ecies_enc, sizeof(knownPlaintext));
194 NSMutableData *encrypted = [NSMutableData dataWithLength:encryptedLength];
195 ok(ccecies_encrypt_gcm(ccec_ctx_pub(fullkey), &ecies_enc, sizeof(knownPlaintext), knownPlaintext, 0, NULL, 0, NULL, &encryptedLength, encrypted.mutableBytes) == 0, "encrypt data with cc failed");
196 error = nil;
197 NSData *decryptedPlaintext = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privKey, algorithm, (CFDataRef)encrypted, (void *)&error));
198 ok(decryptedPlaintext != nil, "decrypt data with SecKey (error %@)", error);
199 ok([plaintext isEqualToData:decryptedPlaintext], "SecKey decrypted data are the same");
200 }
201 static const int TestCountIESAgainstCoreCryptoRun = 9;
202
203 static void test_against_corecrypto() {
204 id privKey;
205 NSDictionary *params;
206 NSError *error;
207
208 params = @{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @192, (id)kSecAttrNoLegacy: @YES};
209 privKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)params, (void *)&error));
210 ok(privKey != nil, "create key (error %@)", error);
211 error = nil;
212 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha1_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM);
213 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha224_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM);
214 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha256_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM);
215 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha384_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM);
216 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha512_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM);
217
218 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha224_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
219 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha256_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
220 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha384_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
221 test_ies_against_corecrypto(privKey, ccec_cp_192(), ccsha512_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
222
223 params = @{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @256, (id)kSecAttrNoLegacy: @YES};
224 privKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)params, (void *)&error));
225 ok(privKey != nil, "create key (error %@)", error);
226 error = nil;
227 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha1_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM);
228 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha224_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM);
229 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha256_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM);
230 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha384_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM);
231 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha512_di(), 16, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM);
232
233 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha224_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
234 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha256_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
235 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha384_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
236 test_ies_against_corecrypto(privKey, ccec_cp_256(), ccsha512_di(), 16, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
237
238 params = @{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @384, (id)kSecAttrNoLegacy: @YES};
239 privKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)params, (void *)&error));
240 ok(privKey != nil, "create key (error %@)", error);
241 error = nil;
242 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha1_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM);
243 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha224_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM);
244 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha256_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM);
245 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha384_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM);
246 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha512_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM);
247
248 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha224_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
249 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha256_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
250 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha384_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
251 test_ies_against_corecrypto(privKey, ccec_cp_384(), ccsha512_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
252
253 params = @{(id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom, (id)kSecAttrKeySizeInBits: @521, (id)kSecAttrNoLegacy: @YES};
254 privKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)params, (void *)&error));
255 ok(privKey != nil, "create key (error %@)", error);
256 error = nil;
257 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha1_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM);
258 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha224_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM);
259 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha256_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM);
260 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha384_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM);
261 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha512_di(), 32, false, kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM);
262
263 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha224_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM);
264 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha256_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM);
265 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha384_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM);
266 test_ies_against_corecrypto(privKey, ccec_cp_521(), ccsha512_di(), 32, true, kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM);
267 }
268 static const int TestCountAgainstCoreCrypto = TestCountIESAgainstCoreCryptoRun * 36 + 4;
269
270 static void test_ies_known_ciphertext(CFStringRef keyType, id keySize, SecKeyAlgorithm algorithm, NSString *privKeyData, NSString *ciphertext) {
271 #define GENERATE_VECTORS 0
272
273 NSError *error = nil;
274 #if GENERATE_VECTORS
275 NSDictionary *params = @{(id)kSecAttrKeyType: (__bridge id)keyType, (id)kSecAttrKeySizeInBits: keySize, (id)kSecAttrNoLegacy: @YES};
276 id privKey = CFBridgingRelease(SecKeyCreateRandomKey((CFDictionaryRef)params, (void *)&error));
277 ok(privKey != nil, "generate key (error %@)", error);
278 #else
279 NSDictionary *params = @{(id)kSecAttrKeyType: (__bridge id)keyType, (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate};
280 id privKey = CFBridgingRelease(SecKeyCreateWithData((CFDataRef)[[NSData alloc] initWithBase64EncodedString:privKeyData options:0], (CFDictionaryRef)params, (void *)&error));
281 ok(privKey != nil, "import key (error %@)", error);
282 #endif
283
284 static const UInt8 knownPlaintext[] = "KNOWN PLAINTEXT";
285 NSData *plaintext = [NSData dataWithBytes:knownPlaintext length:sizeof(knownPlaintext)];
286 error = nil;
287 #if GENERATE_VECTORS
288 id publicKey = CFBridgingRelease(SecKeyCopyPublicKey((SecKeyRef)privKey));
289 NSData *ciphertextData = CFBridgingRelease(SecKeyCreateEncryptedData((SecKeyRef)publicKey, algorithm, (CFDataRef)plaintext, (void *)&error));
290 error = nil;
291 NSData *keyData = CFBridgingRelease(SecKeyCopyExternalRepresentation((SecKeyRef)privKey, (void *)&error));
292 printf("\n@\"%s\", @\"%s\");\n",
293 [keyData base64EncodedStringWithOptions:0].UTF8String,
294 [ciphertextData base64EncodedStringWithOptions:0].UTF8String);
295 #else
296 NSData *ciphertextData = [[NSData alloc] initWithBase64EncodedString:ciphertext options:0];
297 NSData *decrypted = CFBridgingRelease(SecKeyCreateDecryptedData((SecKeyRef)privKey, algorithm, (CFDataRef)ciphertextData, (void *)&error));
298 ok(decrypted != nil, "decrypt known ciphertext (error %@)", error);
299 ok([decrypted isEqual:plaintext], "known ciphertext decrypts to known plaintext (%@: %@)", plaintext, decrypted);
300 #endif
301 }
302 static const int TestCountTestIESKnownCipherText = 3;
303
304 static void test_known_ciphertext() {
305 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(192), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA1AESGCM, @"BJID1fgBoH7L1eHwBcJmZcP4oeuV0xDkeEEO3RdodExpqy5UQWf64FIfRRRbZKSA9cATBLVT0HIl2HXcDMYoX0kE9l8fA/G18w==", @"BMUM+ykbSAfK3zVjoqMpruH00UJWvtC05GITlPuqByGu7loVSl3LdOw8bmkHQB+yx6CdBuq2LGao1BqGP7rNYQRiVDrdA/klICsCm/HADu6a");
306 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(192), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA224AESGCM, @"BGvXnhpVlguy834KfbQUn/HHJVz1mE2q1TOI/c5VdryxFdTSIHzO1OntV7rHVqoKhMXvgmtE88aKr0E6dDESlTmGUXlXvD7AoQ==", @"BL8xaAaQBe3+4GR8e6BO+wupb4dNAr6NgjdqH7C1p55LKhJyEP2QQJo1YHXadXpqdSvh9wWBWiz4NDgMeQx8F5Vst6FWKDuzgQKY1QS8Zp0z");
307 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(192), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM, @"BPyRwvWxZr+tJsxRigfSQflyr1sq+CqUsh68E2JqNK33ud5J34OdI0dGSWe7/i4JF7l0a8piYVr4pkH2pTIPtYmwFAOGGtrzyA==", @"BAPIogml3kN6qJ7Lqdmah+C9LtxnGQ+npz1dj1wqf8UmCRScyjvB3Ir87vGLpOJTWNb7fWth+9FieyAyn9AtK9uRE+JH9x2mu2dmfVq+q48z");
308 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(192), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM, @"BBXZUianpQozaYCBT4DzWfhg/+UqvW1BS4i17RIVvXZuYhXhfuYpCdgwfVc7NqJretuT/Bti6noQ6g1P+yj7BJF+i9pPwSnj5Q==", @"BEPRcNwrzSQ8fGzdQlhKaLmfUcuosUkZGfdta/cwTOpoREIrn/ax4BoNpNibuGVhgUMdWNMIg9Z519o0v/VZFKtRk++9cFQSDjE1SIw3NyOy");
309 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(192), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM, @"BETnUivZ4Qg+x7F8mQZaAyh7rmb15O49EKwBIxodfx1BykjVXWBqC64odYkWcOUc3w2LZ/9/klr0VGvF9UC+5w9fKufyMVQdvg==", @"BEj8oriYbbcfX+y/RW+aHp47LMSChJy3TY5GU2Ld4vMP6M8y4AyB7mIZTLJLYQPOoMam/CGqpEAUhtJlhYxugQMzqJHr9ySEsgp89vsgM/X+");
310
311 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(256), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA1AESGCM, @"BOAqiwAFzjxO7xaYE/6+ywCRap/xxiBCxuUj4A0kzSQtu+0BJ0R71djlM+wtYPwff3+g7e52a8cQSioBciTrMjWCTZuTbhHqsMOdqsmKN/pLEwK9uI3FA6grFbSODA1u0g==", @"BIqvCZdbwbSmS4+hB8vbDdIDJxaUGBmcaOPoRpaTY8MWofTlcqc/OGB0AjbuzpJ7cqODphJ+B6LlsrK0SPogUyj7zT01PA9gwWau/BXb8/1JQa7zTeIJ1vsF7gSrTcMWxA==");
312 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(256), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA224AESGCM, @"BPYROmZkeW3Zc9Qc8TzTZ27YO9+IGHjj78DNmZ3gwNjZtEW+knhI3Z3G/UNwaI3jCgezA3ZyPgIfizUTOqe4fYRIwy867Zn8BHpSxjzEG7Sk3zu/CgA7ObNVJQ6dJWu4PQ==", @"BCiu9fyMXqWXojfd0XWynB9CQwUSNedfdn1AC7OlrZaqH9IyUrgcyajdFaRCksBWt6lmUQx4Ypv48mOqvBcPXpX1TAr4NHkHK4cWXbBzaxesrYn3zOlUhZYvzB5WnWTorg==");
313 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(256), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM, @"BINzTFiGIp6G4fpmFCP/KHot+ek+PUYvYp69iT8lHdJNwRbJir1Zr4i73A0vdKoKMn3jdp/8oQ5WnSE+PsFruYahsHI2tFyhPjGYEhUmFrwaA/2WQynh77dAqSiKhg0l3w==", @"BE7IWFWccaIl7n7Kffg5Q+vkJMJFVsHP8C5C/APzW6gjUQynJGRoG4Vw4UEsFTi/yfUQYTSV7Vv18CXE/3IecGAILuLpcDaSxSwzFqrwmqCcSqSRbYSat+8HuaKq19Cq4A==");
314 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(256), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM, @"BE73i2R6RS7M83M2JGD+JKCR1Z8AST87PFRNLLIfIXoKhH6BFsVgUmuOhz+o450teB4rig57yn9nzDkBRTTn+QAp3g6zGzIE1CBuxSSWVcJNiUD8APCb6kJj7Y/95ekTHg==", @"BKl/2vl0v3BqnLYTMvjszf2hB48GwIrSqqBQU01p/RsAPk3zPb1QG1nq0/bL5mFyIbsQUq8jhAvx8YbXDG47e6qv44Q2nalZqvry55daTUyVvrHvZ+xM6qceFzLFUHYGLw==");
315
316 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(256), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM, @"BMnc5IlDIZJKns6G8ALvQqnaprPuhMkNy04G7rZmOD5w7O2OlViw+aDZr667+xIoQ/zqpMBLIA8ujun6mMQdgx2Wvtj3LPhvfbnHQnuTM60RDfA2BQ+Xj4WCQ4KzcaUElw==", @"BP997mVpTGiPFJp+2CKm2cWgAg/bUToX9UcJlGuasGxFdDqb6a3WZ0HYyujiwxihdSUOEcAdExU3RJdWTfFHDeXDAB7Qdf4WdjiWfyPO29kSWAWbJnHaC9JKC4UdTjTPBA==");
317
318
319 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(521), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA1AESGCM, @"BAD3+GLa92qTtnxZjAYCnkX+LqlwrDKD+jMvq8JYYNFk3rYBT7QKs8ddleTb1ScK732C/NtNTS6yBuqh1/GLLIH0+QCE4D+B3tk+gpgx7yc0Yy+RMTxPpdfX8h4holqwo81TlvLaYpriEmD+8fSFNJuOzc30COFJhpEa70aRkBOtXJbd0AFbq3fvwbC1epWVeTq5d73ZEuiFv5CJ6NIxBsdBFy0RvFm0I+hgqUXyk4gILgsNP6WdWQc1SFqHh6PvbmXO5f6Jzw==", @"BABKMqx3GstC3HtOo2FyOJ1TP0/v+CxRcKawwESkC2SQ7bvhkJGClfPpO57ZIUBULNzY04d+ZmrZ6JX9mp/qB2DtSAA9WGEm/dAawdzOrwwPbD55fi/BaUhP7HF/2x/5ST4WyU5oFTGc3c2vvTnHLLEKKUk13d9ybl8inWPWlNZolb5NNna7MrzX45H8IcRljg6xWntSVqzeglzB4BkRrmjqVbeJ");
320 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(521), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA224AESGCM, @"BAAKStHnPj7CcT+M0wIAsCR89AzaD5h5Mvn8fMPgdqyWZjPuHOL1QaInfSytINx/w88AXLmdEVZucY/R1QB8Gj+5KQFvVYcxFH6rfyHiel00khFdiV0hiNKDQIgGOj3EtkMW2SBnawj2E9ku3m6AhR6p9XcnrwiORhqujH5VQsohJkWMCABNScNDTe19wGskuup11oTKnDNIucSrpggRJsldGymnyV4O74vFsl+8Kq3kfxpVKClU39tqAtC9hxduBRolHwfscg==", @"BAEPiWaky7NoDWFoNRot4xVsxxWP64hbwLM9xyIvYDWyQjXRXHaP4weUYV0n8Cw5aUzvDyON4ik9ouRlLId0SX8SYQCGvopjiBWyA9ieu0LKLxYvMYJCrZUshXmmpHdB25gVZ8vv9sZyE5ggA0IXVl7IxMJTLirbIcfO8EvMPAao/3z0rAx09Yht2iITOoNupE/gSbg/UY3ijuhccFd0bBaLlj9u");
321 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(521), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM, @"BAHaS9E1bgFRlYB555Or19pwj9wOdMP1ETONjgS8MQ4NiOmkOaus4HMcqpiTfCruIAIjBJ0jfuM8j2TdTR8GdPEg3QHHXOav+tPlhfj8y+E/6dNAz0jLHO16wjcGjpq0MJcDMlHS7SKPh8j/GD2KwNya9LefD+VAM62yqRuaFFJihpBV5QHbLDN1AIjqhQO0nm2fRgW0Hff7EcFJXNHkl7ULby2sViPZx1+qN+LcAt4BoZVayiQVxIWX+p2l6nesBcChF+2Fvw==", @"BAFJqyEg7XOScWdtbgVTvmzsYbunFKhiDMJINwPp5tq0QSOiSkh7Cz91+SkUrlCN7Um6bPJmpRjksd9ThR2GlWiiPACFnhhcLmSlLkS1vG3H6kutOJLISBvru05qzXqhDAoda4lDh6jrqppAGUkOgk6lwSJq9w023fmxCxpPtth41Vfq7U2hxik8N81ZdeqiYALerJdXhGVmv8YVaZis2hdzGHLc");
322 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(521), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM, @"BAHR8zVCUzKJi3yc7QJCpxIdsVUJ+N2tB9P0CnMWZ9gVt6bO+UCrGsS6pon0f+nERY+RlPfTyTlrBBGp24a2wWhs2wFaZf2Ng1eKcRFaXPgJozAdz+vOGy1UVK3PxhDkhusdDGyDu6d72UNAicyESa6OCl+f9uicZA5ANaDb0djGr2o67AHQNb41IMcZ+CQKW7XdoMBHT+tLCSZCw+7ZQ1mnHD9NaJbnaxI0qgI03RxXKFj4mqNKjxxzugl9rUfFF0HYJ1KANA==", @"BAFQj+wieG249oNkP5kzC0xTdgtQkd0tTwNmVxYarD05WIjWeaE9VgyfqPVHNyntNA7fEfpLjWy6d5WQGBdFwXxxiAHAqDXeNyNLL0MSzKPmyQNy4TAGjUmGXt/Nq2LafQgKSiWLagSvyaICgk7BBa2z9NvVr4ZcvpreUDzLTrl/+J1WRfR9/78vM3uLfFyTEJwKg6MH3fQRr8RWxcza9AQXspbD");
323 test_ies_known_ciphertext(kSecAttrKeyTypeECSECPrimeRandom, @(521), kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM, @"BAD56NOl02CAXGSBYKT9JMmMQNtYkaRjw/DP29GWe8X70zTNzTBRgQQzqtCmT2c10VRNxzR5bCAM47fR8HyK4OsV4wEes8IDR68JQC7+epF7cdx+m+EGhaHlB2N99MCEZx9NQni6/5LBMItVY7LSQUskKjqslG90vlIZZxn87EzbJ9MvHgFFgeZeUj9SXcbCu6/+ysgXAtldaGyFwXwzI6CrN84Pd72TR/6me1GZjm8pamJ0p507ntdISB5SBFcAQpNieDYxbg==", @"BAABJeJ2D+Yy0aA1/FKoUF4eBR5kr3JnM8iXDEjIZ47EWixF1nde4ehg7iZpbihxv/rDl7jdJYOW9LqXdqoF/2JO7gCrNSbqSkveG6UdsgfalnAd/tAYvz26Ct6vQiGSJJLvHcnss8thgQrOVQaf/NAoxgxIM0dxUmJE3B2EJxb5sKedzCje0XttQQWvEW1t3Ni606AVAhZ3Psiud23qf/qgtJxK");
324
325 test_ies_known_ciphertext(kSecAttrKeyTypeRSA, @(1024), kSecKeyAlgorithmRSAEncryptionOAEPSHA1AESGCM, @"MIICXQIBAAKBgQC0QZAuyNFNspGakQvFdgwkswN+eG6y2IKefIGbcrhGRvs4LJUp0Z+AjTR5ir6Mm7KeRaFMlwybz1eW0HXEJX86jtCGkB4T9iKW06HOevMqp5p/gOSMroGkX374UMdX5WIsI/qPXxHSp0OdoUC1vsAO99UYGitiYuiyzVm/XONKBQIDAQABAoGAFEkUlXnwDr27zm3oVI6BC1hCBRI/PaKeqytOgqnvEamcoqkRwvpePYn75SRiEVIsUHd8PDGmL5qukWs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Lf9nUBXccoaL7sHjZTPO/tCv13SZWYt1S+DaEl4GqdJ3OPRmYh2YPTObmIJ6vhZ2TgOwWxNjx9DBmh4Xxnf6EcuDvDpHlY0gQYWL9uKGNVCBwMi6jQv5BRsMeiUf6WwZCud7M6EsuaqVaj9JOQQgUScXIPx/b2OzmIRjJpGIMDghN7lnlHuIKz9ED5WoK5Gn9Ypp48PfnBgL6y538pn919VPfTCQ0afGEWsSoFfwl8PcMUkBGhNRRA8SY0LnJuF7raC3eOyQHld+C5Yvg/WW+cePKJjeDWot28ltBRobtQ5EgXOUatjjNMj+1lLZoFNm8eKdE1NKoA0nXCghX5g5Pt/J4mGNEp25T8TCM0Aoqou30sMN/a2NQHFCOvIBJeLP/0hD31Zig6FZZyiFQ3BAURlsqgbGP4O6y6Z98dFsf7eqXAOxSACj/GWad8pfQ3p9tPjADU8Q==");
330 }
331 static const int TestCountKnownCipherText = TestCountTestIESKnownCipherText * 5 * 4;
332
333 static const int TestCount = TestCountECIES + TestCountRSAWRAP + TestCountAgainstCoreCrypto + TestCountKnownCipherText;
334
335 int si_44_seckey_ies(int argc, char *const *argv) {
336 plan_tests(TestCount);
337
338 @autoreleasepool {
339 test_ecies();
340 test_rsawrap();
341 test_against_corecrypto();
342 test_known_ciphertext();
343 }
344
345 return 0;
346 }