Skip to content

MASTG-DEMO-0013: Use of Hardcoded RSA Private Key in SecKeyCreateWithData with r2

Content in BETA

This content is in beta and still under active development, so it is subject to change any time (e.g. structure, IDs, content, URLs, etc.).

Send Feedback

Sample

  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
import Foundation
import Security

struct MastgTest {
    static func mastgTest(completion: @escaping (String) -> Void) {

    // Step 1: Use a hardcoded RSA private key (in DER format)
    let privateKeyBytes: [UInt8] = [
        0x30, 0x82, 0x02, 0x5b, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xbd, 0xf6, 0x89, 0x8f, 0xbd, 
        0x0c, 0xe6, 0x4f, 0x9a, 0x97, 0xec, 0x30, 0x1a, 0x48, 0x93, 0x4d, 0x2a, 0xbf, 0xdf, 0xf7, 0x08, 
        0x15, 0x4c, 0xdb, 0x87, 0xe5, 0xdf, 0xb1, 0xcf, 0x8d, 0xa2, 0x5e, 0x2a, 0x7d, 0x92, 0xa8, 0xbd, 
        0x30, 0xb9, 0x10, 0xcf, 0x96, 0xda, 0x10, 0x25, 0xd4, 0x67, 0xaf, 0x92, 0x26, 0xfa, 0x43, 0xb7, 
        0x86, 0x83, 0xa2, 0x68, 0xd4, 0x7a, 0x56, 0xce, 0x41, 0x41, 0xed, 0xc0, 0x10, 0x0c, 0x89, 0xa5, 
        0x4e, 0x5f, 0xc4, 0x59, 0xcc, 0x55, 0x09, 0x1f, 0xa1, 0x1f, 0x1f, 0xb7, 0x97, 0x1d, 0x53, 0x1b, 
        0x73, 0x38, 0x4c, 0x3e, 0xe8, 0x28, 0x1d, 0xc1, 0x68, 0x6a, 0x8d, 0x3e, 0xb0, 0xf2, 0x0a, 0xb3, 
        0x74, 0x26, 0xd2, 0xdc, 0xcf, 0xa4, 0xac, 0xf3, 0x5b, 0x26, 0x35, 0xd1, 0x2d, 0xee, 0x91, 0x41, 
        0xa6, 0x93, 0xed, 0x91, 0xfa, 0xd7, 0x43, 0x83, 0x85, 0x53, 0xe5, 0x02, 0x03, 0x01, 0x00, 0x01, 
        0x02, 0x81, 0x80, 0x01, 0xed, 0xbf, 0x79, 0xcd, 0xee, 0x94, 0x32, 0x73, 0x1c, 0x5f, 0x5e, 0x88, 
        0x0f, 0x62, 0x94, 0x48, 0x98, 0x3b, 0x54, 0x80, 0x8f, 0x1b, 0x9a, 0xdc, 0x9a, 0x91, 0x16, 0xaa, 
        0x14, 0x9c, 0xa8, 0x6a, 0xe6, 0x6c, 0xb0, 0xf9, 0x7f, 0x92, 0x8b, 0x0d, 0xc0, 0x84, 0x25, 0x13, 
        0xd3, 0xa6, 0x75, 0xda, 0x16, 0x3a, 0xd3, 0x0f, 0xfc, 0x8f, 0x71, 0xfc, 0x7e, 0x16, 0xfb, 0xe5, 
        0x71, 0x67, 0xc6, 0x8a, 0x4b, 0xfb, 0x12, 0x13, 0x68, 0x45, 0xd6, 0x17, 0xbd, 0xd2, 0x83, 0x69, 
        0x17, 0xc8, 0x44, 0x84, 0xb0, 0x25, 0xe4, 0x49, 0x9e, 0x51, 0x95, 0x05, 0x79, 0xe6, 0x86, 0x4a, 
        0xf6, 0xc4, 0x5e, 0x70, 0x52, 0x18, 0xf0, 0x46, 0x63, 0x42, 0x32, 0x1b, 0x07, 0x52, 0x83, 0xee, 
        0xd0, 0xbc, 0x0b, 0x6e, 0x12, 0xed, 0x27, 0xbb, 0x03, 0x31, 0xbb, 0xa5, 0x24, 0xc7, 0x2e, 0x3b, 
        0xd6, 0xe9, 0x25, 0x02, 0x41, 0x00, 0xcb, 0x78, 0x2f, 0x7f, 0x51, 0x2f, 0x49, 0xf0, 0xf8, 0xdb, 
        0x2f, 0xc3, 0x18, 0xc8, 0x41, 0x62, 0x41, 0x69, 0x4c, 0xc0, 0x78, 0x98, 0x6c, 0xce, 0xdb, 0x86, 
        0x1e, 0x04, 0x99, 0x11, 0x6c, 0x3d, 0x98, 0x8c, 0xa1, 0xcf, 0xb7, 0x48, 0xa2, 0x8b, 0x53, 0x28, 
        0x31, 0xfd, 0x15, 0x5f, 0x56, 0xc0, 0xc4, 0xc1, 0xe6, 0x25, 0x8b, 0x69, 0x83, 0xe8, 0x59, 0xd2, 
        0x2b, 0x3e, 0xe7, 0xc9, 0xbb, 0xfb, 0x02, 0x41, 0x00, 0xef, 0x01, 0xad, 0x4f, 0xdb, 0xa4, 0xb9, 
        0x59, 0x81, 0x23, 0x5e, 0xd1, 0x10, 0xee, 0x0a, 0xa3, 0x51, 0x24, 0x6f, 0x60, 0x45, 0x5c, 0xd5, 
        0x70, 0x5c, 0xa4, 0x4a, 0x32, 0x70, 0x56, 0xa2, 0x6f, 0x64, 0xaf, 0x68, 0xc9, 0x70, 0xd8, 0x93, 
        0x38, 0x86, 0x1a, 0x94, 0xc0, 0xbe, 0xb7, 0xb0, 0x9d, 0x8d, 0xb5, 0x59, 0xf6, 0x3a, 0x3a, 0xed, 
        0xd7, 0x54, 0x77, 0x57, 0x10, 0x9a, 0xad, 0x49, 0x9f, 0x02, 0x40, 0x6c, 0xf3, 0x95, 0x53, 0x72, 
        0x90, 0x84, 0xe2, 0x81, 0x0f, 0x35, 0x7b, 0x1d, 0xc9, 0x15, 0xa1, 0xdc, 0x6e, 0xdb, 0x47, 0x71, 
        0x0c, 0x05, 0xaf, 0x9a, 0xc3, 0x2d, 0x4d, 0xbe, 0xfd, 0x22, 0x5d, 0xb5, 0x53, 0x10, 0xce, 0x5e, 
        0x51, 0x89, 0xa0, 0x5b, 0x4d, 0xf9, 0xbe, 0x90, 0x74, 0x35, 0xcb, 0x11, 0x50, 0xd6, 0xc1, 0x21, 
        0xee, 0xc5, 0x50, 0x64, 0xd0, 0x72, 0x91, 0xc3, 0xa2, 0x35, 0x83, 0x02, 0x40, 0x62, 0xee, 0xd6, 
        0xc6, 0xcf, 0xac, 0x87, 0xec, 0xbc, 0xbf, 0xdf, 0x67, 0xbb, 0x12, 0x4d, 0xe4, 0xfc, 0x99, 0x90, 
        0x60, 0xd1, 0x55, 0x74, 0x24, 0x66, 0xb4, 0xba, 0xe1, 0xd6, 0x0e, 0x86, 0x7e, 0x85, 0xb6, 0xf6, 
        0x31, 0x2c, 0x3c, 0xf9, 0xf3, 0xd3, 0xce, 0xfc, 0xf4, 0x2b, 0xfd, 0xed, 0x65, 0xca, 0x5a, 0xdf, 
        0x3a, 0x45, 0x30, 0x4f, 0x73, 0x6a, 0xcb, 0x5b, 0x86, 0xcc, 0x00, 0x1f, 0x11, 0x02, 0x40, 0x5e, 
        0x6b, 0xae, 0x7c, 0x7d, 0xfc, 0x8a, 0xf5, 0x97, 0xa9, 0x39, 0x37, 0x27, 0x4e, 0xd9, 0xe8, 0xd0, 
        0x8d, 0xa9, 0x32, 0xe4, 0x6b, 0xde, 0x76, 0x0f, 0xee, 0xf1, 0x22, 0x11, 0xc4, 0x1e, 0x4a, 0x01, 
        0x73, 0xc4, 0x34, 0x8c, 0x4d, 0x16, 0xf1, 0x2f, 0x5f, 0xe4, 0xe5, 0x41, 0x3a, 0x3b, 0xf1, 0xb1, 
        0x78, 0x7c, 0x0e, 0x55, 0xf9, 0xf7, 0xcf, 0x64, 0x93, 0xad, 0x77, 0xfd, 0x31, 0x52, 0x87
    ]
    let privateKeyData = Data(privateKeyBytes)

    let keyAttributes: [String: Any] = [
        kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
        kSecAttrKeyClass as String: kSecAttrKeyClassPrivate,
        kSecAttrKeySizeInBits as String: 1024,
        kSecReturnPersistentRef as String: true
    ]

    var error: Unmanaged<CFError>?
    guard let privateKey = SecKeyCreateWithData(privateKeyData as CFData, keyAttributes as CFDictionary, &error) else {
        completion("Failed to create private key: \(String(describing: error))")
        return
    }

        guard let publicKey = SecKeyCopyPublicKey(privateKey) else {
            completion("Failed to generate public key")
            return
        }

        // Convert the public key to data (DER format)
        guard let publicKeyData = SecKeyCopyExternalRepresentation(publicKey, &error) as Data? else {
            completion("Failed to extract public key: \(String(describing: error))")
            return
        }

        // Encode the public key for display
        let publicKeyHex = publicKeyData.map { String(format: "%02hhx", $0) }.joined()

        // Data to sign
        let dataToSign = "This is a sample text".data(using: .utf8)!

        // Step 2: Sign the data with the hardcoded private key
        guard let signature = SecKeyCreateSignature(
            privateKey,
            SecKeyAlgorithm.rsaSignatureMessagePKCS1v15SHA256,
            dataToSign as CFData,
            &error
        ) else {
            completion("Signing failed: \(String(describing: error))")
            return
        }

        // Convert signature to hex string for display
        let signatureHex = (signature as Data).map { String(format: "%02hhx", $0) }.joined()

        // Step 3: Verify the signature with the public key
        let verificationStatus = SecKeyVerifySignature(
            publicKey,
            SecKeyAlgorithm.rsaSignatureMessagePKCS1v15SHA256,
            dataToSign as CFData,
            signature as CFData,
            &error
        )

        let verificationResult = verificationStatus ? "Signature is valid." : "Signature is invalid."

        let value = """
        Original: \(String(data: dataToSign, encoding: .utf8)!)

        Public Key (Hex): \(publicKeyHex)

        Signature (Hex): \(signatureHex)

        Verification: \(verificationResult)
        """

        completion(value)
    }
}
  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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
            ; CALL XREF from sym.func.1000063c8 @ 0x100006400(x)
 2444: sym.func.10000491c (int64_t arg1, int64_t arg2, void *arg3);
           0x10000491c      stp x28, x27, [sp, -0x60]!
           0x100004920      stp x26, x25, [var_10h]
           0x100004924      stp x24, x23, [var_20h]
           0x100004928      stp x22, x21, [var_30h]
           0x10000492c      stp x20, x19, [var_40h]
           0x100004930      stp x29, x30, [var_50h_2]
           0x100004934      add x29, sp, 0x50
           0x100004938      sub sp, sp, 0x1b0
           0x10000493c      mov x19, sp
           0x100004940      str x2, [x19, 0x70]                       ; arg3
           0x100004944      mov x24, x1                               ; arg2
           0x100004948      mov x26, x0                               ; arg1
           0x10000494c      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004950      ldr x8, reloc.__stack_chk_guard           ; 0x10000c408
           0x100004954      ldr x8, [x8]
           0x100004958      stur x8, [x29, -0x60]
           0x10000495c      mov x0, 0
           0x100004960      bl sym Foundation...8EncodingVMa          ; sym.imp.Foundation...8EncodingVMa
           0x100004964      ldur x8, [x0, -8]
           0x100004968      stp x8, x0, [x19, 0x48]
           0x10000496c      ldr x8, [x8, 0x40]
           0x100004970      mov x9, x8
           0x100004974      adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004978      ldr x16, reloc.__chkstk_darwin            ; 0x10000c3f8
           0x10000497c      blr x16
           0x100004980      mov x9, sp
           0x100004984      add x8, x8, 0xf
           0x100004988      and x8, x8, 0xfffffffffffffff0
           0x10000498c      sub x8, x9, x8
           0x100004990      str x8, [x19, 0x58]
           0x100004994      mov sp, x8
           0x100004998      adrp x0, segment.__DATA                   ; 0x100010000
           0x10000499c      add x0, x0, 0x328                         ; int64_t arg1
           0x1000049a0      bl sym.func.1000052a8
           0x1000049a4      adrp x1, segment.__DATA                   ; 0x100010000
           0x1000049a8      add x1, x1, 0xa8
           0x1000049ac      bl sym.imp.swift_initStaticObject
           0x1000049b0      mov x20, x0
           0x1000049b4      adrp x21, segment.__DATA                  ; 0x100010000
           0x1000049b8      add x21, x21, 0x330
           0x1000049bc      mov x0, x21                               ; int64_t arg1
           0x1000049c0      bl sym.func.1000052a8
           0x1000049c4      mov x22, x0
           0x1000049c8      stur x0, [x29, -0x70]
           0x1000049cc      adrp x0, segment.__DATA                   ; 0x100010000
           0x1000049d0      add x0, x0, 0x338                         ; int64_t arg1
           0x1000049d4      adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x1000049d8      ldr x2, reloc.Foundation.ContiguousBytes.UInt8...szlMc ; 0x10000c338 ; int64_t arg3
           0x1000049dc      mov x1, x21                               ; int64_t arg2
           0x1000049e0      bl sym.func.1000053c8
           0x1000049e4      stur x0, [x29, -0x68]
           0x1000049e8      stur x20, [x29, -0x88]
           0x1000049ec      sub x0, x29, 0x88                         ; int64_t arg1
           0x1000049f0      mov x1, x22                               ; int64_t arg2
           0x1000049f4      bl sym.func.10000532c
           0x1000049f8      ldr x8, [x0]
           0x1000049fc      add x0, x8, 0x20                          ; int64_t arg1
           0x100004a00      ldr x8, [x8, 0x10]
           0x100004a04      add x1, x0, x8                            ; int64_t arg2
           0x100004a08      bl sym.func.1000047b8
           0x100004a0c      mov x25, x0
           0x100004a10      mov x28, x1
           0x100004a14      sub x0, x29, 0x88                         ; int64_t arg1
           0x100004a18      bl sym.func.100005350
           0x100004a1c      adrp x0, segment.__DATA                   ; 0x100010000
           0x100004a20      add x0, x0, 0x340                         ; int64_t arg1
           0x100004a24      bl sym.func.1000052a8
           0x100004a28      add x1, x19, 0x98                         ; void *arg1
           0x100004a2c      bl sym.imp.swift_initStackObject          ; void *swift_initStackObject(void *arg0, void *arg1)
           0x100004a30      mov x20, x0
           0x100004a34      adrp x8, 0x100007000
           0x100004a38      ldr q0, [x8, 0xad0]
           0x100004a3c      str q0, [x0, 0x10]
           0x100004a40      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004a44      ldr x8, reloc.kSecAttrKeyType             ; 0x10000c438
           0x100004a48      ldr x0, [x8]
           0x100004a4c      bl sym Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ ; sym.imp.Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ
           0x100004a50      mov x21, x20
           0x100004a54      str x0, [x21, 0x20]!
           0x100004a58      str x1, [x20, 0x28]
           0x100004a5c      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004a60      ldr x8, reloc.kSecAttrKeyTypeRSA          ; 0x10000c440
           0x100004a64      ldr x23, [x8]
           0x100004a68      mov x0, 0
           0x100004a6c      bl sym.func.100005370
           0x100004a70      mov x22, x0
           0x100004a74      str x0, [x20, 0x48]
           0x100004a78      str x23, [x20, 0x30]
           0x100004a7c      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004a80      ldr x8, reloc.kSecAttrKeyClass            ; 0x10000c420
           0x100004a84      ldr x0, [x8]
           0x100004a88      bl sym Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ ; sym.imp.Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ
           0x100004a8c      stp x0, x1, [x20, 0x50]
           0x100004a90      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004a94      ldr x8, reloc.kSecAttrKeyClassPrivate     ; 0x10000c428
           0x100004a98      ldr x27, [x8]
           0x100004a9c      str x22, [x20, 0x78]
           0x100004aa0      mov x22, x28
           0x100004aa4      str x27, [x20, 0x60]
           0x100004aa8      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004aac      ldr x8, reloc.kSecAttrKeySizeInBits       ; 0x10000c430
           0x100004ab0      ldr x0, [x8]
           0x100004ab4      bl sym Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ ; sym.imp.Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ
           0x100004ab8      stp x0, x1, [x20, 0x80]
           0x100004abc      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004ac0      ldr x8, reloc....SiN                      ; 0x10000c350
           0x100004ac4      str x8, [x20, 0xa8]
           0x100004ac8      mov w8, 0x400
           0x100004acc      str x8, [x20, 0x90]
           0x100004ad0      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004ad4      ldr x8, reloc.kSecReturnPersistentRef     ; 0x10000c450
           0x100004ad8      ldr x0, [x8]
           0x100004adc      bl sym Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ ; sym.imp.Foundation...nconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ
           0x100004ae0      stp x0, x1, [x20, 0xb0]
           0x100004ae4      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004ae8      ldr x8, reloc....SbN                      ; 0x10000c348
           0x100004aec      str x8, [x20, 0xd8]
           0x100004af0      mov w8, 1
           0x100004af4      strb w8, [x20, 0xc0]
           0x100004af8      bl sym.imp.objc_retain_x23
           0x100004afc      mov x23, x25
           0x100004b00      bl sym.imp.objc_retain_x27
           0x100004b04      mov x0, x20                               ; int64_t arg1
           0x100004b08      bl sym.func.100004820
           0x100004b0c      mov x25, x0
           0x100004b10      mov x0, x20
           0x100004b14      bl sym.imp.swift_setDeallocating
           0x100004b18      adrp x0, segment.__DATA                   ; 0x100010000
           0x100004b1c      add x0, x0, 0x348                         ; int64_t arg1
           0x100004b20      bl sym.func.1000052a8
           0x100004b24      mov x2, x0
           0x100004b28      mov x0, x21
           0x100004b2c      mov w1, 4
           0x100004b30      bl sym.imp.swift_arrayDestroy
           0x100004b34      str xzr, [x19, 0x90]
           0x100004b38      mov x0, x23
           0x100004b3c      mov x1, x28
           0x100004b40      bl sym Foundation.Data._bridgeToObjectiveC.NSData...F ; sym.imp.Foundation.Data._bridgeToObjectiveC.NSData...F
           0x100004b44      mov x20, x0
           0x100004b48      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004b4c      ldr x8, reloc....ypN                      ; 0x10000c3c8
           0x100004b50      add x2, x8, 8
           0x100004b54      adrp x1, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004b58      ldr x1, reloc....SSN                      ; 0x10000c320
           0x100004b5c      adrp x3, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
           0x100004b60      ldr x3, [x3, 0x328]
           0x100004b64      mov x0, x25
           0x100004b68      bl sym Foundationbool...ridgeToObjectiveCSo12NSDictionaryCyF ; sym.imp.Foundationbool...ridgeToObjectiveCSo12NSDictionaryCyF
           0x100004b6c      mov x21, x0
           0x100004b70      add x2, x19, 0x90
           0x100004b74      mov x0, x20
           0x100004b78      mov x1, x21
           0x100004b7c      bl sym.imp.SecKeyCreateWithData
           0x100004b80      mov x28, x0
           0x100004b84      bl sym.imp.objc_release_x20
           0x100004b88      bl sym.imp.objc_release_x21
       ┌─< 0x100004b8c      cbz x28, 0x100004f68
          0x100004b90      stp x26, x24, [x19, 0x60]
          0x100004b94      mov x0, x28
          0x100004b98      bl sym.imp.SecKeyCopyPublicKey
      ┌──< 0x100004b9c      cbz x0, 0x100005028
      ││   0x100004ba0      str x25, [x19, 0x38]
      ││   0x100004ba4      mov x21, 0x10
      ││   0x100004ba8      movk x21, 0xd000, lsl 48
      ││   0x100004bac      add x1, x19, 0x90
      ││   0x100004bb0      mov x26, x0
      ││   0x100004bb4      bl sym.imp.SecKeyCopyExternalRepresentation
      ││   0x100004bb8      ldp x24, x25, [x19, 0x68]
      ││   0x100004bbc      ldr x27, [x19, 0x60]
     ┌───< 0x100004bc0      cbz x0, 0x100005098
     │││   0x100004bc4      mov x20, x0
     │││   0x100004bc8      stp x22, x26, [x19, 0x28]
     │││   0x100004bcc      str x23, [x19, 0x20]
     │││   0x100004bd0      bl sym Foundation.Data._unconditionallyBridgeFromObjectiveC.NSData...gFZ ; sym.imp.Foundation.Data._unconditionallyBridgeFromObjectiveC.NSData...gFZ
     │││   0x100004bd4      mov x26, x0
     │││   0x100004bd8      mov x24, x1
     │││   0x100004bdc      bl sym.imp.objc_release_x20
     │││   0x100004be0      mov x0, x26                               ; int64_t arg1
     │││   0x100004be4      mov x1, x24                               ; int64_t arg2
     │││   0x100004be8      mov x25, 0x10
     │││   0x100004bec      movk x25, 0xd000, lsl 48
     │││   0x100004bf0      mov x21, 0
     │││   0x100004bf4      bl sym.func.100004000
     │││   0x100004bf8      mov x23, x0
     │││   0x100004bfc      stur x0, [x29, -0x88]
     │││   0x100004c00      adrp x20, segment.__DATA                  ; 0x100010000
     │││   0x100004c04      add x20, x20, 0x360
     │││   0x100004c08      mov x0, x20                               ; int64_t arg1
     │││   0x100004c0c      bl sym.func.1000052a8
     │││   0x100004c10      mov x27, x0
     │││   0x100004c14      adrp x0, segment.__DATA                   ; 0x100010000
     │││   0x100004c18      add x0, x0, 0x368                         ; int64_t arg1
     │││   0x100004c1c      adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
     │││   0x100004c20      ldr x2, reloc....SayxGSKsMc               ; 0x10000c340 ; int64_t arg3
     │││   0x100004c24      mov x1, x20                               ; int64_t arg2
     │││   0x100004c28      bl sym.func.1000053c8
     │││   0x100004c2c      mov x22, x0
     │││   0x100004c30      sub x20, x29, 0x88
     │││   0x100004c34      mov x0, 0
     │││   0x100004c38      mov x1, -0x2000000000000000
     │││   0x100004c3c      str x27, [x19, 0x10]
     │││   0x100004c40      mov x2, x27
     │││   0x100004c44      mov x3, x22
     │││   0x100004c48      bl sym Element...F                        ; sym.imp.Element...F
     │││   0x100004c4c      str x0, [x19, 8]
     │││   0x100004c50      str x1, [x19, 0x18]
     │││   0x100004c54      mov x0, x23                               ; void *arg0
     │││   0x100004c58      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
     │││   0x100004c5c      add x8, x25, 5
     │││   0x100004c60      adrp x9, 0x100008000
     │││   0x100004c64      add x9, x9, 0x540                         ; 0x100008540 ; "This is a sample text"
     │││   0x100004c68      sub x9, x9, 0x20
     │││   0x100004c6c      orr x9, x9, 0x8000000000000000
     │││   0x100004c70      stp x8, x9, [x29, -0x88]
     │││   0x100004c74      ldr x23, [x19, 0x58]
     │││   0x100004c78      mov x8, x23
     │││   0x100004c7c      bl sym Foundation...8EncodingV4utf8ACvgZ  ; sym.imp.Foundation...8EncodingV4utf8ACvgZ
     │││   0x100004c80      bl sym.func.100005408
     │││   0x100004c84      mov x3, x0
     │││   0x100004c88      adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
     │││   0x100004c8c      ldr x2, reloc....SSN                      ; 0x10000c320
     │││   0x100004c90      sub x20, x29, 0x88
     │││   0x100004c94      mov x0, x23
     │││   0x100004c98      mov w1, 0
     │││   0x100004c9c      bl sym Foundation...btF                   ; sym.imp.Foundation...btF
     │││   0x100004ca0      str x0, [x19, 0x40]
     │││   0x100004ca4      mov x20, x1
     │││   0x100004ca8      ldp x8, x1, [x19, 0x48]
     │││   0x100004cac      ldr x8, [x8, 8]
     │││   0x100004cb0      mov x0, x23
     │││   0x100004cb4      blr x8
     │││   0x100004cb8      ldur x0, [x29, -0x80]                     ; void *arg0
     │││   0x100004cbc      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
     │││   0x100004cc0      lsr x8, x20, 0x3c
     │││   0x100004cc4      cmp x8, 0xe
     │││   0x100004cc8      mov x25, 0x10
     │││   0x100004ccc      movk x25, 0xd000, lsl 48
    ┌────< 0x100004cd0      b.hi 0x100005280
    ││││   0x100004cd4      adrp x8, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
    ││││   0x100004cd8      ldr x8, reloc.kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA256 ; 0x10000c448
    ││││   0x100004cdc      ldr x23, [x8]
    ││││   0x100004ce0      ldr x0, [x19, 0x40]
    ││││   0x100004ce4      str x20, [x19, 0x50]
    ││││   0x100004ce8      mov x1, x20
    ││││   0x100004cec      bl sym Foundation.Data._bridgeToObjectiveC.NSData...F ; sym.imp.Foundation.Data._bridgeToObjectiveC.NSData...F
    ││││   0x100004cf0      mov x20, x0
    ││││   0x100004cf4      add x3, x19, 0x90
    ││││   0x100004cf8      mov x0, x28
    ││││   0x100004cfc      mov x1, x23
    ││││   0x100004d00      mov x2, x20
    ││││   0x100004d04      bl sym.imp.SecKeyCreateSignature
    ││││   0x100004d08      mov x27, x0
    ││││   0x100004d0c      bl sym.imp.objc_release_x20
   ┌─────< 0x100004d10      cbz x27, 0x10000515c
   │││││   0x100004d14      str x26, [x19]
   │││││   0x100004d18      str x24, [x19, 0x48]
   │││││   0x100004d1c      mov x0, x27
   │││││   0x100004d20      bl sym Foundation.Data._unconditionallyBridgeFromObjectiveC.NSData...gFZ ; sym.imp.Foundation.Data._unconditionallyBridgeFromObjectiveC.NSData...gFZ
   │││││   0x100004d24      mov x20, x0
   │││││   0x100004d28      mov x26, x1
   │││││   0x100004d2c      bl sym.func.100004000
   │││││   0x100004d30      mov x21, x0
   │││││   0x100004d34      mov x0, x20                               ; void *arg0
   │││││   0x100004d38      mov x1, x26                               ; int64_t arg2
   │││││   0x100004d3c      bl sym.func.100005384
   │││││   0x100004d40      stur x21, [x29, -0x88]
   │││││   0x100004d44      mov x24, -0x2000000000000000
   │││││   0x100004d48      sub x20, x29, 0x88
   │││││   0x100004d4c      mov x0, 0
   │││││   0x100004d50      mov x1, -0x2000000000000000
   │││││   0x100004d54      ldr x2, [x19, 0x10]
   │││││   0x100004d58      mov x3, x22
   │││││   0x100004d5c      bl sym Element...F                        ; sym.imp.Element...F
   │││││   0x100004d60      str x0, [x19, 0x10]
   │││││   0x100004d64      mov x26, x1
   │││││   0x100004d68      mov x0, x21                               ; void *arg0
   │││││   0x100004d6c      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
   │││││   0x100004d70      ldr x25, [x19, 0x40]
   │││││   0x100004d74      mov x0, x25
   │││││   0x100004d78      ldr x21, [x19, 0x50]
   │││││   0x100004d7c      mov x1, x21
   │││││   0x100004d80      bl sym Foundation.Data._bridgeToObjectiveC.NSData...F ; sym.imp.Foundation.Data._bridgeToObjectiveC.NSData...F
   │││││   0x100004d84      mov x20, x0
   │││││   0x100004d88      add x4, x19, 0x90
   │││││   0x100004d8c      ldr x0, [x19, 0x30]
   │││││   0x100004d90      mov x1, x23
   │││││   0x100004d94      mov x2, x20
   │││││   0x100004d98      mov x3, x27
   │││││   0x100004d9c      bl sym.imp.SecKeyVerifySignature
   │││││   0x100004da0      mov x23, x0
   │││││   0x100004da4      bl sym.imp.objc_release_x20
   │││││   0x100004da8      stp xzr, x24, [x29, -0x88]
   │││││   0x100004dac      sub x20, x29, 0x88
   │││││   0x100004db0      mov w0, 0x49                              ; 'I'
   │││││   0x100004db4      bl sym _StringGuts.grow...SiF             ; sym.imp._StringGuts.grow...SiF
   │││││   0x100004db8      ldp x8, x9, [x29, -0x88]
   │││││   0x100004dbc      stp x8, x9, [x29, -0x88]
   │││││   0x100004dc0      sub x20, x29, 0x88
   │││││   0x100004dc4      mov x0, 0x724f                            ; 'Or'
   │││││   0x100004dc8      movk x0, 0x6769, lsl 16                   ; 'ig'
   │││││   0x100004dcc      movk x0, 0x6e69, lsl 32                   ; 'in'
   │││││   0x100004dd0      movk x0, 0x6c61, lsl 48                   ; 'al'
   │││││   0x100004dd4      mov x1, 0x203a                            ; ': '
   │││││   0x100004dd8      movk x1, 0xea00, lsl 48
   │││││   0x100004ddc      bl sym append...ySSF                      ; sym.imp.append...ySSF
   │││││   0x100004de0      ldr x20, [x19, 0x58]
   │││││   0x100004de4      mov x8, x20
   │││││   0x100004de8      bl sym Foundation...8EncodingV4utf8ACvgZ  ; sym.imp.Foundation...8EncodingV4utf8ACvgZ
   │││││   0x100004dec      mov x0, x25
   │││││   0x100004df0      mov x1, x21
   │││││   0x100004df4      mov x2, x20
   │││││   0x100004df8      bl sym Foundation__String...AAE8EncodingVtcfC ; sym.imp.Foundation__String...AAE8EncodingVtcfC
  ┌──────< 0x100004dfc      cbz x1, 0x100005294
  ││││││   0x100004e00      mov x25, x1
  ││││││   0x100004e04      adrp x8, 0x100008000
  ││││││   0x100004e08      add x8, x8, 0x580                         ; 0x100008580 ; "Signature is valid."
  ││││││   0x100004e0c      sub x8, x8, 0x20
  ││││││   0x100004e10      orr x8, x8, 0x8000000000000000
  ││││││   0x100004e14      adrp x9, 0x100008000
  ││││││   0x100004e18      add x9, x9, 0x600                         ; 0x100008600 ; "Signature is invalid."
  ││││││   0x100004e1c      sub x9, x9, 0x20
  ││││││   0x100004e20      orr x9, x9, 0x8000000000000000
  ││││││   0x100004e24      cmp w23, 0
  ││││││   0x100004e28      csel x24, x9, x8, eq
  ││││││   0x100004e2c      mov x22, 0x10
  ││││││   0x100004e30      movk x22, 0xd000, lsl 48
  ││││││   0x100004e34      add x21, x22, 3
  ││││││   0x100004e38      add x8, x22, 5
  ││││││   0x100004e3c      csel x23, x8, x21, eq
  ││││││   0x100004e40      sub x20, x29, 0x88
  ││││││   0x100004e44      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004e48      mov x0, x25                               ; void *arg0
  ││││││   0x100004e4c      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
  ││││││   0x100004e50      add x0, x22, 4
  ││││││   0x100004e54      adrp x8, 0x100008000
  ││││││   0x100004e58      add x8, x8, 0x5a0                         ; 0x1000085a0 ; "\n\nPublic Key (Hex): "
  ││││││   0x100004e5c      sub x8, x8, 0x20
  ││││││   0x100004e60      orr x1, x8, 0x8000000000000000
  ││││││   0x100004e64      sub x20, x29, 0x88
  ││││││   0x100004e68      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004e6c      sub x20, x29, 0x88
  ││││││   0x100004e70      ldr x0, [x19, 8]
  ││││││   0x100004e74      ldr x25, [x19, 0x18]
  ││││││   0x100004e78      mov x1, x25
  ││││││   0x100004e7c      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004e80      adrp x8, 0x100008000
  ││││││   0x100004e84      add x8, x8, 0x5c0                         ; 0x1000085c0 ; "\n\nSignature (Hex): "
  ││││││   0x100004e88      sub x8, x8, 0x20
  ││││││   0x100004e8c      orr x1, x8, 0x8000000000000000
  ││││││   0x100004e90      sub x20, x29, 0x88
  ││││││   0x100004e94      mov x0, x21
  ││││││   0x100004e98      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004e9c      sub x20, x29, 0x88
  ││││││   0x100004ea0      ldr x0, [x19, 0x10]
  ││││││   0x100004ea4      mov x1, x26
  ││││││   0x100004ea8      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004eac      adrp x8, 0x100008000
  ││││││   0x100004eb0      add x8, x8, 0x5e0                         ; 0x1000085e0 ; "\n\nVerification: "
  ││││││   0x100004eb4      sub x8, x8, 0x20
  ││││││   0x100004eb8      orr x1, x8, 0x8000000000000000
  ││││││   0x100004ebc      sub x20, x29, 0x88
  ││││││   0x100004ec0      mov x0, 0x10
  ││││││   0x100004ec4      movk x0, 0xd000, lsl 48
  ││││││   0x100004ec8      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004ecc      sub x20, x29, 0x88
  ││││││   0x100004ed0      mov x0, x23
  ││││││   0x100004ed4      mov x1, x24
  ││││││   0x100004ed8      bl sym append...ySSF                      ; sym.imp.append...ySSF
  ││││││   0x100004edc      ldp x8, x21, [x29, -0x88]
  ││││││   0x100004ee0      ldr x10, [x19, 0x60]
  ││││││   0x100004ee4      ldr x9, [x19, 0x68]
  ││││││   0x100004ee8      stp x10, x9, [x29, -0x88]
  ││││││   0x100004eec      ldr x9, [x19, 0x70]
  ││││││   0x100004ef0      stur x9, [x29, -0x78]
  ││││││   0x100004ef4      stp x8, x21, [x19, 0x80]
  ││││││   0x100004ef8      mov x0, x21                               ; void *arg0
  ││││││   0x100004efc      bl sym.imp.swift_bridgeObjectRetain       ; void *swift_bridgeObjectRetain(void *arg0)
  ││││││   0x100004f00      adrp x0, segment.__DATA                   ; 0x100010000
  ││││││   0x100004f04      add x0, x0, 0x358                         ; int64_t arg1
  ││││││   0x100004f08      bl sym.func.1000052a8
  ││││││   0x100004f0c      mov x1, x0
  ││││││   0x100004f10      add x0, x19, 0x80
  ││││││   0x100004f14      sub x20, x29, 0x88
  ││││││   0x100004f18      bl sym SwiftUI.State.wrappedValue...s     ; sym.imp.SwiftUI.State.wrappedValue...s
  ││││││   0x100004f1c      ldr x0, [x19, 0x38]                       ; void *arg0
  ││││││   0x100004f20      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
  ││││││   0x100004f24      ldp x0, x1, [x19, 0x20]                   ; int64_t arg2
  ││││││   0x100004f28      bl sym.func.100005384
  ││││││   0x100004f2c      mov x0, x26                               ; void *arg0
  ││││││   0x100004f30      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
  ││││││   0x100004f34      mov x0, x24                               ; void *arg0
  ││││││   0x100004f38      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
  ││││││   0x100004f3c      mov x0, x21                               ; void *arg0
  ││││││   0x100004f40      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
  ││││││   0x100004f44      bl sym.imp.objc_release_x27
  ││││││   0x100004f48      ldr x0, [x19, 0x40]                       ; int64_t arg2
  ││││││   0x100004f4c      ldr x1, [x19, 0x50]
  ││││││   0x100004f50      bl sym.func.10000544c
  ││││││   0x100004f54      mov x0, x25                               ; void *arg0
  ││││││   0x100004f58      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
  ││││││   0x100004f5c      ldr x0, [x19]
  ││││││   0x100004f60      ldr x1, [x19, 0x48]
 ┌───────< 0x100004f64      b 0x100005234
 │││││││   ; CODE XREF from sym.func.10000491c @ 0x100004b8c(x)
 ││││││└─> 0x100004f68      mov x8, -0x2000000000000000
 ││││││    0x100004f6c      stp xzr, x8, [x29, -0x88]
 ││││││    0x100004f70      sub x20, x29, 0x88
 ││││││    0x100004f74      mov w0, 0x20
 ││││││    0x100004f78      bl sym _StringGuts.grow...SiF             ; sym.imp._StringGuts.grow...SiF
 ││││││    0x100004f7c      ldur x0, [x29, -0x80]                     ; void *arg0
 ││││││    0x100004f80      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││││    0x100004f84      mov x8, 0x10
 ││││││    0x100004f88      movk x8, 0xd000, lsl 48
 ││││││    0x100004f8c      orr x8, x8, 0xe
 ││││││    0x100004f90      adrp x9, 0x100008000
 ││││││    0x100004f94      add x9, x9, 0x4e0                         ; 0x1000084e0 ; "Failed to create private key: "
 ││││││    0x100004f98      sub x9, x9, 0x20
 ││││││    0x100004f9c      orr x9, x9, 0x8000000000000000
 ││││││    0x100004fa0      stp x8, x9, [x29, -0x88]
 ││││││    0x100004fa4      ldr x8, [x19, 0x90]
 ││││││    0x100004fa8      str x8, [x19, 0x80]
 ││││││    0x100004fac      adrp x0, segment.__DATA                   ; 0x100010000
 ││││││    0x100004fb0      add x0, x0, 0x350                         ; int64_t arg1
 ││││││    0x100004fb4      bl sym.func.1000052a8
 ││││││    0x100004fb8      mov x1, x0
 ││││││    0x100004fbc      add x0, x19, 0x80
 ││││││    0x100004fc0      bl sym describing__String...clufC         ; sym.imp.describing__String...clufC
 ││││││    0x100004fc4      mov x21, x1
 ││││││    0x100004fc8      sub x20, x29, 0x88
 ││││││    0x100004fcc      bl sym append...ySSF                      ; sym.imp.append...ySSF
 ││││││    0x100004fd0      mov x0, x21                               ; void *arg0
 ││││││    0x100004fd4      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││││    0x100004fd8      ldp x8, x21, [x29, -0x88]
 ││││││    0x100004fdc      stp x26, x24, [x29, -0x88]
 ││││││    0x100004fe0      ldr x9, [x19, 0x70]
 ││││││    0x100004fe4      stur x9, [x29, -0x78]
 ││││││    0x100004fe8      stp x8, x21, [x19, 0x80]
 ││││││    0x100004fec      mov x0, x21                               ; void *arg0
 ││││││    0x100004ff0      bl sym.imp.swift_bridgeObjectRetain       ; void *swift_bridgeObjectRetain(void *arg0)
 ││││││    0x100004ff4      adrp x0, segment.__DATA                   ; 0x100010000
 ││││││    0x100004ff8      add x0, x0, 0x358                         ; int64_t arg1
 ││││││    0x100004ffc      bl sym.func.1000052a8
 ││││││    0x100005000      mov x1, x0
 ││││││    0x100005004      add x0, x19, 0x80
 ││││││    0x100005008      sub x20, x29, 0x88
 ││││││    0x10000500c      bl sym SwiftUI.State.wrappedValue...s     ; sym.imp.SwiftUI.State.wrappedValue...s
 ││││││    0x100005010      mov x0, x25                               ; void *arg0
 ││││││    0x100005014      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││││    0x100005018      mov x0, x23                               ; void *arg0
 ││││││    0x10000501c      mov x1, x22                               ; int64_t arg2
 ││││││    0x100005020      bl sym.func.100005384
 ││││││┌─< 0x100005024      b 0x100005150
 │││││││   ; CODE XREF from sym.func.10000491c @ 0x100004b9c(x)
 │││││└──> 0x100005028      ldr x9, [x19, 0x60]
 │││││    0x10000502c      ldr x8, [x19, 0x68]
 │││││    0x100005030      stp x9, x8, [x29, -0x88]
 │││││    0x100005034      ldr x8, [x19, 0x70]
 │││││    0x100005038      stur x8, [x29, -0x78]
 │││││    0x10000503c      mov w8, 0xd
 │││││    0x100005040      mov x9, 0x10
 │││││    0x100005044      movk x9, 0xd000, lsl 48
 │││││    0x100005048      orr x8, x9, x8
 │││││    0x10000504c      adrp x9, 0x100008000
 │││││    0x100005050      add x9, x9, 0x500                         ; 0x100008500 ; "Failed to generate public key"
 │││││    0x100005054      sub x9, x9, 0x20
 │││││    0x100005058      orr x9, x9, 0x8000000000000000
 │││││    0x10000505c      stp x8, x9, [x19, 0x80]
 │││││    0x100005060      adrp x0, segment.__DATA                   ; 0x100010000
 │││││    0x100005064      add x0, x0, 0x358                         ; int64_t arg1
 │││││    0x100005068      bl sym.func.1000052a8
 │││││    0x10000506c      mov x1, x0
 │││││    0x100005070      add x0, x19, 0x80
 │││││    0x100005074      sub x20, x29, 0x88
 │││││    0x100005078      bl sym SwiftUI.State.wrappedValue...s     ; sym.imp.SwiftUI.State.wrappedValue...s
 │││││    0x10000507c      mov x0, x25                               ; void *arg0
 │││││    0x100005080      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 │││││    0x100005084      mov x0, x23                               ; void *arg0
 │││││    0x100005088      mov x1, x22                               ; int64_t arg2
 │││││    0x10000508c      bl sym.func.100005384
 │││││    0x100005090      bl sym.imp.objc_release_x28
 │││││┌──< 0x100005094      b 0x100005244
 │││││││   ; CODE XREF from sym.func.10000491c @ 0x100004bc0(x)
 ││││└───> 0x100005098      mov x8, -0x2000000000000000
 ││││ ││   0x10000509c      stp xzr, x8, [x29, -0x88]
 ││││ ││   0x1000050a0      sub x20, x29, 0x88
 ││││ ││   0x1000050a4      mov w0, 0x20
 ││││ ││   0x1000050a8      bl sym _StringGuts.grow...SiF             ; sym.imp._StringGuts.grow...SiF
 ││││ ││   0x1000050ac      ldur x0, [x29, -0x80]                     ; void *arg0
 ││││ ││   0x1000050b0      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││ ││   0x1000050b4      add x8, x21, 0xe
 ││││ ││   0x1000050b8      adrp x9, 0x100008000
 ││││ ││   0x1000050bc      add x9, x9, 0x520                         ; 0x100008520 ; "Failed to extract public key: "
 ││││ ││   0x1000050c0      sub x9, x9, 0x20
 ││││ ││   0x1000050c4      orr x9, x9, 0x8000000000000000
 ││││ ││   0x1000050c8      stp x8, x9, [x29, -0x88]
 ││││ ││   0x1000050cc      ldr x8, [x19, 0x90]
 ││││ ││   0x1000050d0      str x8, [x19, 0x80]
 ││││ ││   0x1000050d4      adrp x0, segment.__DATA                   ; 0x100010000
 ││││ ││   0x1000050d8      add x0, x0, 0x350                         ; int64_t arg1
 ││││ ││   0x1000050dc      bl sym.func.1000052a8
 ││││ ││   0x1000050e0      mov x1, x0
 ││││ ││   0x1000050e4      add x0, x19, 0x80
 ││││ ││   0x1000050e8      bl sym describing__String...clufC         ; sym.imp.describing__String...clufC
 ││││ ││   0x1000050ec      mov x21, x1
 ││││ ││   0x1000050f0      sub x20, x29, 0x88
 ││││ ││   0x1000050f4      bl sym append...ySSF                      ; sym.imp.append...ySSF
 ││││ ││   0x1000050f8      mov x0, x21                               ; void *arg0
 ││││ ││   0x1000050fc      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││ ││   0x100005100      ldp x8, x21, [x29, -0x88]
 ││││ ││   0x100005104      stp x27, x24, [x29, -0x88]
 ││││ ││   0x100005108      stur x25, [x29, -0x78]
 ││││ ││   0x10000510c      stp x8, x21, [x19, 0x80]
 ││││ ││   0x100005110      mov x0, x21                               ; void *arg0
 ││││ ││   0x100005114      bl sym.imp.swift_bridgeObjectRetain       ; void *swift_bridgeObjectRetain(void *arg0)
 ││││ ││   0x100005118      adrp x0, segment.__DATA                   ; 0x100010000
 ││││ ││   0x10000511c      add x0, x0, 0x358                         ; int64_t arg1
 ││││ ││   0x100005120      bl sym.func.1000052a8
 ││││ ││   0x100005124      mov x1, x0
 ││││ ││   0x100005128      add x0, x19, 0x80
 ││││ ││   0x10000512c      sub x20, x29, 0x88
 ││││ ││   0x100005130      bl sym SwiftUI.State.wrappedValue...s     ; sym.imp.SwiftUI.State.wrappedValue...s
 ││││ ││   0x100005134      ldr x0, [x19, 0x38]                       ; void *arg0
 ││││ ││   0x100005138      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││ ││   0x10000513c      mov x0, x23                               ; void *arg0
 ││││ ││   0x100005140      mov x1, x22                               ; int64_t arg2
 ││││ ││   0x100005144      bl sym.func.100005384
 ││││ ││   0x100005148      bl sym.imp.objc_release_x28
 ││││ ││   0x10000514c      bl sym.imp.objc_release_x26
 ││││ ││   ; CODE XREF from sym.func.10000491c @ 0x100005024(x)
 ││││ │└─> 0x100005150      mov x0, x21                               ; void *arg0
 ││││     0x100005154      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││││ │┌─< 0x100005158      b 0x100005244
 ││││ ││   ; CODE XREF from sym.func.10000491c @ 0x100004d10(x)
 ││└─────> 0x10000515c      mov x8, -0x2000000000000000
 ││  ││   0x100005160      stp xzr, x8, [x29, -0x88]
 ││  ││   0x100005164      sub x20, x29, 0x88
 ││  ││   0x100005168      mov w0, 0x12
 ││  ││   0x10000516c      bl sym _StringGuts.grow...SiF             ; sym.imp._StringGuts.grow...SiF
 ││  ││   0x100005170      ldur x0, [x29, -0x80]                     ; void *arg0
 ││  ││   0x100005174      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││  ││   0x100005178      adrp x8, 0x100008000
 ││  ││   0x10000517c      add x8, x8, 0x560                         ; 0x100008560 ; "Signing failed: "
 ││  ││   0x100005180      sub x8, x8, 0x20
 ││  ││   0x100005184      orr x8, x8, 0x8000000000000000
 ││  ││   0x100005188      stp x25, x8, [x29, -0x88]
 ││  ││   0x10000518c      ldr x8, [x19, 0x90]
 ││  ││   0x100005190      str x8, [x19, 0x80]
 ││  ││   0x100005194      adrp x0, segment.__DATA                   ; 0x100010000
 ││  ││   0x100005198      add x0, x0, 0x350                         ; int64_t arg1
 ││  ││   0x10000519c      bl sym.func.1000052a8
 ││  ││   0x1000051a0      mov x1, x0
 ││  ││   0x1000051a4      add x0, x19, 0x80
 ││  ││   0x1000051a8      bl sym describing__String...clufC         ; sym.imp.describing__String...clufC
 ││  ││   0x1000051ac      mov x21, x1
 ││  ││   0x1000051b0      sub x20, x29, 0x88
 ││  ││   0x1000051b4      bl sym append...ySSF                      ; sym.imp.append...ySSF
 ││  ││   0x1000051b8      mov x0, x21                               ; void *arg0
 ││  ││   0x1000051bc      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││  ││   0x1000051c0      ldp x8, x21, [x29, -0x88]
 ││  ││   0x1000051c4      ldr x10, [x19, 0x60]
 ││  ││   0x1000051c8      ldr x9, [x19, 0x68]
 ││  ││   0x1000051cc      stp x10, x9, [x29, -0x88]
 ││  ││   0x1000051d0      ldr x9, [x19, 0x70]
 ││  ││   0x1000051d4      stur x9, [x29, -0x78]
 ││  ││   0x1000051d8      stp x8, x21, [x19, 0x80]
 ││  ││   0x1000051dc      mov x0, x21                               ; void *arg0
 ││  ││   0x1000051e0      bl sym.imp.swift_bridgeObjectRetain       ; void *swift_bridgeObjectRetain(void *arg0)
 ││  ││   0x1000051e4      adrp x0, segment.__DATA                   ; 0x100010000
 ││  ││   0x1000051e8      add x0, x0, 0x358                         ; int64_t arg1
 ││  ││   0x1000051ec      bl sym.func.1000052a8
 ││  ││   0x1000051f0      mov x1, x0
 ││  ││   0x1000051f4      add x0, x19, 0x80
 ││  ││   0x1000051f8      sub x20, x29, 0x88
 ││  ││   0x1000051fc      bl sym SwiftUI.State.wrappedValue...s     ; sym.imp.SwiftUI.State.wrappedValue...s
 ││  ││   0x100005200      ldr x0, [x19, 0x38]                       ; void *arg0
 ││  ││   0x100005204      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││  ││   0x100005208      ldp x0, x1, [x19, 0x20]                   ; int64_t arg2
 ││  ││   0x10000520c      bl sym.func.100005384
 ││  ││   0x100005210      mov x0, x21                               ; void *arg0
 ││  ││   0x100005214      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││  ││   0x100005218      ldr x0, [x19, 0x40]                       ; int64_t arg2
 ││  ││   0x10000521c      ldr x1, [x19, 0x50]
 ││  ││   0x100005220      bl sym.func.10000544c
 ││  ││   0x100005224      ldr x0, [x19, 0x18]                       ; void *arg0
 ││  ││   0x100005228      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
 ││  ││   0x10000522c      mov x0, x26
 ││  ││   0x100005230      mov x1, x24
 ││  ││   ; CODE XREF from sym.func.10000491c @ 0x100004f64(x)
 └───────> 0x100005234      bl sym.func.100005384
    ││   0x100005238      bl sym.imp.objc_release_x28
    ││   0x10000523c      ldr x8, [x19, 0x30]
    ││   0x100005240      bl sym.imp.objc_release_x8
    ││   ; CODE XREFS from sym.func.10000491c @ 0x100005094(x), 0x100005158(x)
    └└─> 0x100005244      ldur x8, [x29, -0x60]
         0x100005248      adrp x9, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000
         0x10000524c      ldr x9, reloc.__stack_chk_guard           ; 0x10000c408
         0x100005250      ldr x9, [x9]
         0x100005254      cmp x9, x8
     ┌─< 0x100005258      b.ne 0x10000527c
        0x10000525c      sub sp, x29, 0x50
        0x100005260      ldp x29, x30, [var_50h_2]
        0x100005264      ldp x20, x19, [var_40h]
        0x100005268      ldp x22, x21, [var_30h]
        0x10000526c      ldp x24, x23, [var_20h]
        0x100005270      ldp x26, x25, [var_10h]
        0x100005274      ldp x28, x27, [sp], 0x60
        0x100005278      ret
        ; CODE XREF from sym.func.10000491c @ 0x100005258(x)
     └─> 0x10000527c      bl sym.imp.__stack_chk_fail               ; void __stack_chk_fail(void)
         ; CODE XREF from sym.func.10000491c @ 0x100004cd0(x)
   └────> 0x100005280      ldr x0, [x19, 0x68]                       ; void *arg0
          0x100005284      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
          0x100005288      ldr x0, [x19, 0x70]                       ; void *arg0
          0x10000528c      bl sym.imp.swift_release                  ; void swift_release(void *arg0)
          0x100005290      brk 1
          ; CODE XREF from sym.func.10000491c @ 0x100004dfc(x)
  └──────> 0x100005294      ldr x0, [x19, 0x68]                       ; void *arg0
           0x100005298      bl sym.imp.swift_bridgeObjectRelease      ; void swift_bridgeObjectRelease(void *arg0)
           0x10000529c      ldr x0, [x19, 0x70]                       ; void *arg0
           0x1000052a0      bl sym.imp.swift_release                  ; void swift_release(void *arg0)
           0x1000052a4      brk 1
 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
// ✨ Decompiled using OpenAI's ChatGPT o1-review model ✨

import Security

func runCryptoFunction() {
    // Step 1: Load RSA Private Key from Embedded Data
    // The key data is hardcoded and embedded in the binary
    let keyBytes: [UInt8] = [
        // The bytes from the data provided
        0x30, 0x82, 0x02, 0x5b, 0x02, 0x01, 0x00, 0x02,
        0x81, 0x81, 0x00, 0xbd, 0xf6, 0x89, 0x8f, 0xbd,
        0x0c, 0xe6, 0x4f, 0x9a, 0x97, 0xec, 0x30, 0x1a,
        // ...
        // For brevity, the full key data is not shown
    ]
    let keyData = Data(keyBytes)

    // Key attributes for creating the key
    let keyDict: [String: Any] = [
        kSecAttrKeyType as String:            kSecAttrKeyTypeRSA,
        kSecAttrKeyClass as String:           kSecAttrKeyClassPrivate,
        kSecAttrKeySizeInBits as String:      1024,
        kSecReturnPersistentRef as String:    true,
    ]

    var error: Unmanaged<CFError>?

    // Create the private key from the data
    guard let privateKey = SecKeyCreateWithData(keyData as CFData, keyDict as CFDictionary, &error) else {
        let errorMessage = "Failed to create private key: \(error!.takeRetainedValue() as Error)"
        self.output = errorMessage
        return
    }

    // Step 2: Extract Public Key
    guard let publicKey = SecKeyCopyPublicKey(privateKey) else {
        let errorMessage = "Failed to generate public key"
        self.output = errorMessage
        return
    }

    // Step 3: Create Sample Data
    let sampleText = "This is a sample text"
    guard let data = sampleText.data(using: .utf8) else {
        self.output = "Failed to convert text to data"
        return
    }

    // Step 4: Sign the Data
    let algorithm: SecKeyAlgorithm = .rsaSignatureMessagePKCS1v15SHA256
    guard SecKeyIsAlgorithmSupported(privateKey, .sign, algorithm) else {
        self.output = "Algorithm not supported for signing"
        return
    }
    guard let signatureData = SecKeyCreateSignature(privateKey, algorithm, data as CFData, &error) as Data? else {
        let errorMessage = "Signing failed: \(error!.takeRetainedValue() as Error)"
        self.output = errorMessage
        return
    }

    // Step 5: Verify the Signature
    guard SecKeyIsAlgorithmSupported(publicKey, .verify, algorithm) else {
        self.output = "Algorithm not supported for verification"
        return
    }
    let isVerified = SecKeyVerifySignature(publicKey, algorithm, data as CFData, signatureData as CFData, &error)

    // Step 6: Convert Keys and Signature to Hex Strings
    guard let publicKeyData = SecKeyCopyExternalRepresentation(publicKey, &error) as Data? else {
        let errorMessage = "Failed to extract public key: \(error!.takeRetainedValue() as Error)"
        self.output = errorMessage
        return
    }
    let publicKeyHex = publicKeyData.map { String(format: "%02x", $0) }.joined()
    let signatureHex = signatureData.map { String(format: "%02x", $0) }.joined()

    // Step 7: Construct an Output Message
    var outputMessage = "Original: \(sampleText)"
    outputMessage += "\n\nSignature is \(isVerified ? "valid." : "invalid.")"
    outputMessage += "\n\nPublic Key (Hex): \(publicKeyHex)"
    outputMessage += "\n\nSignature (Hex): \(signatureHex)"
    outputMessage += "\n\nVerification: \(isVerified ? "Success" : "Failure")"

    // Step 8: Update SwiftUI State Variable
    self.output = outputMessage
}

Steps

  1. Unzip the app package and locate the main binary file ( Exploring the App Package), which in this case is ./Payload/MASTestApp.app/MASTestApp.
  2. Open the app binary with radare2 for iOS with the -i option to run this script.
sec_hardcoded_rsa.r2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
e asm.bytes=false
e scr.color=false
e asm.var=false

?e Uses of SecKeyCreateWithData:
afl~SecKeyCreateWithData

?e

?e xrefs to SecKeyCreateWithData:
axt @ 0x100007904

?e

pdf @ sym.func.10000491c > function.asm

px 607 @ 0x1000100c8 > key.asm
run.sh
1
2
#!/bin/bash
r2 -q -i sec_hardcoded_rsa.r2 -A MASTestApp > output.asm

Observation

The output reveals a call to SecKeyCreateWithData as well as the hardcoded RSA private key within the DATA section of the binary.

1
2
3
4
5
Uses of SecKeyCreateWithData:
0x100007904    1     12 sym.imp.SecKeyCreateWithData

xrefs to SecKeyCreateWithData:
sym.func.10000491c 0x100004b7c [CALL:--x] bl sym.imp.SecKeyCreateWithData
 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
- offset -   C8C9 CACB CCCD CECF D0D1 D2D3 D4D5 D6D7  89ABCDEF01234567
0x1000100c8  3082 025b 0201 0002 8181 00bd f689 8fbd  0..[............
0x1000100d8  0ce6 4f9a 97ec 301a 4893 4d2a bfdf f708  ..O...0.H.M*....
0x1000100e8  154c db87 e5df b1cf 8da2 5e2a 7d92 a8bd  .L........^*}...
0x1000100f8  30b9 10cf 96da 1025 d467 af92 26fa 43b7  0......%.g..&.C.
0x100010108  8683 a268 d47a 56ce 4141 edc0 100c 89a5  ...h.zV.AA......
0x100010118  4e5f c459 cc55 091f a11f 1fb7 971d 531b  N_.Y.U........S.
0x100010128  7338 4c3e e828 1dc1 686a 8d3e b0f2 0ab3  s8L>.(..hj.>....
0x100010138  7426 d2dc cfa4 acf3 5b26 35d1 2dee 9141  t&......[&5.-..A
0x100010148  a693 ed91 fad7 4383 8553 e502 0301 0001  ......C..S......
0x100010158  0281 8001 edbf 79cd ee94 3273 1c5f 5e88  ......y...2s._^.
0x100010168  0f62 9448 983b 5480 8f1b 9adc 9a91 16aa  .b.H.;T.........
0x100010178  149c a86a e66c b0f9 7f92 8b0d c084 2513  ...j.l........%.
0x100010188  d3a6 75da 163a d30f fc8f 71fc 7e16 fbe5  ..u..:....q.~...
0x100010198  7167 c68a 4bfb 1213 6845 d617 bdd2 8369  qg..K...hE.....i
0x1000101a8  17c8 4484 b025 e449 9e51 9505 79e6 864a  ..D..%.I.Q..y..J
0x1000101b8  f6c4 5e70 5218 f046 6342 321b 0752 83ee  ..^pR..FcB2..R..
0x1000101c8  d0bc 0b6e 12ed 27bb 0331 bba5 24c7 2e3b  ...n..'..1..$..;
0x1000101d8  d6e9 2502 4100 cb78 2f7f 512f 49f0 f8db  ..%.A..x/.Q/I...
0x1000101e8  2fc3 18c8 4162 4169 4cc0 7898 6cce db86  /...AbAiL.x.l...
0x1000101f8  1e04 9911 6c3d 988c a1cf b748 a28b 5328  ....l=.....H..S(
0x100010208  31fd 155f 56c0 c4c1 e625 8b69 83e8 59d2  1.._V....%.i..Y.
0x100010218  2b3e e7c9 bbfb 0241 00ef 01ad 4fdb a4b9  +>.....A....O...
0x100010228  5981 235e d110 ee0a a351 246f 6045 5cd5  Y.#^.....Q$o`E\.
0x100010238  705c a44a 3270 56a2 6f64 af68 c970 d893  p\.J2pV.od.h.p..
0x100010248  3886 1a94 c0be b7b0 9d8d b559 f63a 3aed  8..........Y.::.
0x100010258  d754 7757 109a ad49 9f02 406c f395 5372  [email protected]
0x100010268  9084 e281 0f35 7b1d c915 a1dc 6edb 4771  .....5{.....n.Gq
0x100010278  0c05 af9a c32d 4dbe fd22 5db5 5310 ce5e  .....-M.."].S..^
0x100010288  5189 a05b 4df9 be90 7435 cb11 50d6 c121  Q..[M...t5..P..!
0x100010298  eec5 5064 d072 91c3 a235 8302 4062 eed6  ..Pd.r...5..@b..
0x1000102a8  c6cf ac87 ecbc bfdf 67bb 124d e4fc 9990  ........g..M....
0x1000102b8  60d1 5574 2466 b4ba e1d6 0e86 7e85 b6f6  `.Ut$f......~...
0x1000102c8  312c 3cf9 f3d3 cefc f42b fded 65ca 5adf  1,<......+..e.Z.
0x1000102d8  3a45 304f 736a cb5b 86cc 001f 1102 405e  :E0Osj.[......@^
0x1000102e8  6bae 7c7d fc8a f597 a939 3727 4ed9 e8d0  k.|}.....97'N...
0x1000102f8  8da9 32e4 6bde 760f eef1 2211 c41e 4a01  ..2.k.v..."...J.
0x100010308  73c4 348c 4d16 f12f 5fe4 e541 3a3b f1b1  s.4.M../_..A:;..
0x100010318  787c 0e55 f9f7 cf64 93ad 77fd 3152 87    x|.U...d..w.1R.

Evaluation

The test fails because a hardcoded RSA private key was found in the code.

Note: Using artificial intelligence we're able to decompile the disassembled code and review it. The output is a human-readable version of the assembly code. The AI decompiled code may not perfect and might contain errors but, in this case, it clearly shows the use of SecKeyCreateWithData and the associated private key.