1
10
13
14
20
21
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
103
104
105
109
110
111
115
116
120
121
122
123
124
125
126
127
128
129
130
131
135
136
137
141
142
143
147
148
149
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
185
186
187
188
192
193
194
203
204
205
206
207
208
209
210
219
220
221
222
223
224
225
226
227
228
229
230
236
243
244
245
246
247
248
252
253
254
255
256
257
258
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
335
336
337
341
342
343
347
348
349
358
367
368
369
370
371
372
373
374
375
376
377
378
379
380
384
385
386
392
393
397
398
399
400
404
405
406
407
411
412
413
414
418
419
420
424
425
429
430
434
435
436
440
441
442
446
447
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
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
542
543
544
548
549
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
706
707
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
731
732
733
734
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
757
758
759
760
761
762
763
764
765
766
767
768
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
788
794
798
799
800
801
802
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
846
847
848
852
853
854
855
856
857
858
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
896
897
898
...
...
...
#include "nx_crypto_ecdsa.h"
...
...
NX_CRYPTO_KEEP UINT _nx_crypto_ecdsa_sign(NX_CRYPTO_EC *curve, UCHAR *hash, UINT hash_length,
UCHAR *private_key, UINT private_key_length,
UCHAR *signature, ULONG signature_length,
ULONG *actual_signature_length, HN_UBASE *scratch)
{
UINT status;
NX_CRYPTO_HUGE_NUMBER privkey;
NX_CRYPTO_HUGE_NUMBER z;
NX_CRYPTO_HUGE_NUMBER k;
NX_CRYPTO_HUGE_NUMBER ik;
NX_CRYPTO_HUGE_NUMBER temp;
NX_CRYPTO_EC_POINT pt;
UINT buffer_size = curve -> nx_crypto_ec_n.nx_crypto_huge_buffer_size;
UINT i;
UINT curve_size;
UINT r_size;
UINT s_size;
UCHAR pad_zero_r;
UCHAR pad_zero_s;
UINT sequence_size;
UCHAR *signature_r;
UCHAR *signature_s;
/* ... */
curve_size = curve -> nx_crypto_ec_bits >> 3;
if (curve -> nx_crypto_ec_bits & 7)
{
curve_size++;
}if (curve -> nx_crypto_ec_bits & 7) { ... }
if (signature_length < ((curve_size << 1) + 9))
{
return(NX_CRYPTO_SIZE_ERROR);
}if (signature_length < ((curve_size << 1) + 9)) { ... }
if (private_key_length > buffer_size)
{
return(NX_CRYPTO_SIZE_ERROR);
}if (private_key_length > buffer_size) { ... }
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&privkey, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&z, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&k, scratch, buffer_size + 8);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&ik, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&temp, scratch, buffer_size * 2);
NX_CRYPTO_EC_POINT_INITIALIZE(&pt, NX_CRYPTO_EC_POINT_AFFINE, scratch, buffer_size);
status = _nx_crypto_huge_number_setup(&privkey, private_key, private_key_length);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
if (hash_length > buffer_size)
{
hash_length = buffer_size;
}if (hash_length > buffer_size) { ... }
status = _nx_crypto_huge_number_setup(&z, hash, hash_length);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
if (curve -> nx_crypto_ec_bits < hash_length << 3)
{
_nx_crypto_huge_number_shift_right(&z, (hash_length << 3) - curve -> nx_crypto_ec_bits);
}if (curve -> nx_crypto_ec_bits < hash_length << 3) { ... }
do
{
do
{
_nx_crypto_ec_key_pair_generation_extra(curve, &curve -> nx_crypto_ec_g, &k, &pt,
scratch);
_nx_crypto_huge_number_modulus(&pt.nx_crypto_ec_point_x, &curve -> nx_crypto_ec_n);
...} while (_nx_crypto_huge_number_is_zero(&pt.nx_crypto_ec_point_x));
_nx_crypto_huge_number_inverse_modulus(&k, &curve -> nx_crypto_ec_n, &ik, scratch);
_nx_crypto_huge_number_multiply(&pt.nx_crypto_ec_point_x, &privkey, &temp);
_nx_crypto_huge_number_add_unsigned(&temp, &z);
_nx_crypto_huge_number_modulus(&temp, &curve -> nx_crypto_ec_n);
NX_CRYPTO_HUGE_NUMBER_COPY(&k, &temp);
_nx_crypto_huge_number_multiply(&ik, &k, &temp);
_nx_crypto_huge_number_modulus(&temp, &curve -> nx_crypto_ec_n);
...} while (_nx_crypto_huge_number_is_zero(&temp));
signature_r = signature + 3;
status = _nx_crypto_huge_number_extract(&pt.nx_crypto_ec_point_x, signature_r, (curve_size + 3), &r_size);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
signature_s = signature + (curve_size + 6);
status = _nx_crypto_huge_number_extract(&temp, signature_s, (curve_size + 3), &s_size);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
for (i = 0; i < r_size; i++)
{
if (signature_r[i])
{
break;
}if (signature_r[i]) { ... }
}for (i = 0; i < r_size; i++) { ... }
signature_r += i;
r_size -= i;
pad_zero_r = (signature_r[0] & 0x80) ? 1 : 0;
for (i = 0; i < s_size; i++)
{
if (signature_s[i])
{
break;
}if (signature_s[i]) { ... }
}for (i = 0; i < s_size; i++) { ... }
signature_s += i;
s_size -= i;
pad_zero_s = (signature_s[0] & 0x80) ? 1 : 0;
sequence_size = r_size + pad_zero_r + s_size + pad_zero_s + 4;
signature[0] = 0x30;
if (sequence_size < 0x80)
{
signature[1] = (UCHAR)sequence_size;
signature += 2;
*actual_signature_length = sequence_size + 2;
}if (sequence_size < 0x80) { ... }
else
{
signature[1] = 0x81;
signature[2] = (UCHAR)sequence_size;
signature += 3;
*actual_signature_length = sequence_size + 3;
}else { ... }
NX_CRYPTO_MEMMOVE(&signature[2 + pad_zero_r], signature_r, r_size);
signature[0] = 0x02;
signature[1] = (UCHAR)(r_size + pad_zero_r);
if (pad_zero_r)
{
signature[2] = 0;
}if (pad_zero_r) { ... }
signature += (2u + pad_zero_r + r_size);
NX_CRYPTO_MEMMOVE(&signature[2 + pad_zero_s], signature_s, s_size);
signature[0] = 0x02;
signature[1] = (UCHAR)(s_size + pad_zero_s);
if (pad_zero_s)
{
signature[2] = 0;
}if (pad_zero_s) { ... }
return NX_CRYPTO_SUCCESS;
}{ ... }
...
...
NX_CRYPTO_KEEP UINT _nx_crypto_ecdsa_verify(NX_CRYPTO_EC *curve, UCHAR *hash, UINT hash_length,
UCHAR *public_key, UINT public_key_length,
UCHAR *signature, UINT signature_length, HN_UBASE *scratch)
{
UINT status;
NX_CRYPTO_HUGE_NUMBER r;
NX_CRYPTO_HUGE_NUMBER s;
NX_CRYPTO_HUGE_NUMBER z;
NX_CRYPTO_HUGE_NUMBER w;
NX_CRYPTO_HUGE_NUMBER u1;
NX_CRYPTO_HUGE_NUMBER u2;
NX_CRYPTO_EC_POINT pubkey;
NX_CRYPTO_EC_POINT pt;
NX_CRYPTO_EC_POINT pt2;
UINT buffer_size = curve -> nx_crypto_ec_n.nx_crypto_huge_buffer_size;
/* ... */
if (public_key_length > 1 + (buffer_size << 1))
{
return(NX_CRYPTO_SIZE_ERROR);
}if (public_key_length > 1 + (buffer_size << 1)) { ... }
if (signature[0] != 0x30)
{
return(NX_CRYPTO_AUTHENTICATION_FAILED);
}if (signature[0] != 0x30) { ... }
if (signature[1] & 0x80)
{
if (signature_length < (signature[2] + 3u))
{
return(NX_CRYPTO_SIZE_ERROR);
}if (signature_length < (signature[2] + 3u)) { ... }
signature_length = signature[2];
signature += 3;
}if (signature[1] & 0x80) { ... }
else
{
if (signature_length < (signature[1] + 2u))
{
return(NX_CRYPTO_SIZE_ERROR);
}if (signature_length < (signature[1] + 2u)) { ... }
signature_length = signature[1];
signature += 2;
}else { ... }
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&r, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&s, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&z, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&w, scratch, buffer_size);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&u1, scratch, buffer_size << 1);
NX_CRYPTO_HUGE_NUMBER_INITIALIZE(&u2, scratch, buffer_size << 1);
NX_CRYPTO_EC_POINT_INITIALIZE(&pubkey, NX_CRYPTO_EC_POINT_AFFINE, scratch, buffer_size);
NX_CRYPTO_EC_POINT_INITIALIZE(&pt, NX_CRYPTO_EC_POINT_AFFINE, scratch, buffer_size);
NX_CRYPTO_EC_POINT_INITIALIZE(&pt2, NX_CRYPTO_EC_POINT_AFFINE, scratch, buffer_size);
status = _nx_crypto_ec_point_setup(&pubkey, public_key, public_key_length);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
#ifndef NX_CRYPTO_ECC_DISABLE_KEY_VALIDATION
status = _nx_crypto_ec_validate_public_key(&pubkey, curve, NX_CRYPTO_FALSE, scratch);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
/* ... */#endif
if (signature_length < (signature[1] + 2u))
{
return(NX_CRYPTO_SIZE_ERROR);
}if (signature_length < (signature[1] + 2u)) { ... }
status = _nx_crypto_huge_number_setup(&r, &signature[2], signature[1]);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
signature_length -= (signature[1] + 2u);
signature += signature[1] + 2;
if (signature_length < (signature[1] + 2u))
{
return(NX_CRYPTO_SIZE_ERROR);
}if (signature_length < (signature[1] + 2u)) { ... }
status = _nx_crypto_huge_number_setup(&s, &signature[2], signature[1]);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
if(_nx_crypto_huge_number_is_zero(&r) || _nx_crypto_huge_number_is_zero(&s))
{
return(NX_CRYPTO_NOT_SUCCESSFUL);
}if (_nx_crypto_huge_number_is_zero(&r) || _nx_crypto_huge_number_is_zero(&s)) { ... }
if(NX_CRYPTO_HUGE_NUMBER_LESS != _nx_crypto_huge_number_compare_unsigned(&r, &curve -> nx_crypto_ec_n))
{
return(NX_CRYPTO_NOT_SUCCESSFUL);
}if (NX_CRYPTO_HUGE_NUMBER_LESS != _nx_crypto_huge_number_compare_unsigned(&r, &curve -> nx_crypto_ec_n)) { ... }
if(NX_CRYPTO_HUGE_NUMBER_LESS != _nx_crypto_huge_number_compare_unsigned(&s, &curve -> nx_crypto_ec_n))
{
return(NX_CRYPTO_NOT_SUCCESSFUL);
}if (NX_CRYPTO_HUGE_NUMBER_LESS != _nx_crypto_huge_number_compare_unsigned(&s, &curve -> nx_crypto_ec_n)) { ... }
if (hash_length > buffer_size)
{
hash_length = buffer_size;
}if (hash_length > buffer_size) { ... }
status = _nx_crypto_huge_number_setup(&z, hash, hash_length);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
if (curve -> nx_crypto_ec_bits < hash_length << 3)
{
_nx_crypto_huge_number_shift_right(&z, (hash_length << 3) - curve -> nx_crypto_ec_bits);
}if (curve -> nx_crypto_ec_bits < hash_length << 3) { ... }
_nx_crypto_huge_number_inverse_modulus(&s, &curve -> nx_crypto_ec_n, &w, scratch);
_nx_crypto_huge_number_multiply(&z, &w, &u1);
_nx_crypto_huge_number_modulus(&u1, &curve -> nx_crypto_ec_n);
_nx_crypto_huge_number_multiply(&r, &w, &u2);
_nx_crypto_huge_number_modulus(&u2, &curve -> nx_crypto_ec_n);
curve -> nx_crypto_ec_multiple(curve, &curve -> nx_crypto_ec_g, &u1, &pt, scratch);
curve -> nx_crypto_ec_multiple(curve, &pubkey, &u2, &pt2, scratch);
curve -> nx_crypto_ec_add(curve, &pt, &pt2, scratch);
_nx_crypto_huge_number_modulus(&pt.nx_crypto_ec_point_x, &curve -> nx_crypto_ec_n);
if (NX_CRYPTO_HUGE_NUMBER_EQUAL != _nx_crypto_huge_number_compare_unsigned(&pt.nx_crypto_ec_point_x, &r))
{
return NX_CRYPTO_NOT_SUCCESSFUL;
}if (NX_CRYPTO_HUGE_NUMBER_EQUAL != _nx_crypto_huge_number_compare_unsigned(&pt.nx_crypto_ec_point_x, &r)) { ... }
return NX_CRYPTO_SUCCESS;
}{ ... }
...
...
NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_init(struct NX_CRYPTO_METHOD_STRUCT *method,
UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
VOID **handle,
VOID *crypto_metadata,
ULONG crypto_metadata_size)
{
NX_CRYPTO_ECDSA *ecdsa;
NX_CRYPTO_PARAMETER_NOT_USED(key);
NX_CRYPTO_PARAMETER_NOT_USED(key_size_in_bits);
NX_CRYPTO_PARAMETER_NOT_USED(handle);
NX_CRYPTO_STATE_CHECK
if ((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL))
{
return(NX_CRYPTO_PTR_ERROR);
}if ((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL)) { ... }
if((((ULONG)crypto_metadata) & 0x3) != 0)
{
return(NX_CRYPTO_PTR_ERROR);
}if ((((ULONG)crypto_metadata) & 0x3) != 0) { ... }
if(crypto_metadata_size < sizeof(NX_CRYPTO_ECDSA))
{
return(NX_CRYPTO_PTR_ERROR);
}if (crypto_metadata_size < sizeof(NX_CRYPTO_ECDSA)) { ... }
ecdsa = (NX_CRYPTO_ECDSA *)crypto_metadata;
ecdsa -> nx_crypto_ecdsa_curve = NX_CRYPTO_NULL;
ecdsa -> nx_crypto_ecdsa_hash_method = NX_CRYPTO_NULL;
return(NX_CRYPTO_SUCCESS);
}{ ... }
...
...
NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_cleanup(VOID *crypto_metadata)
{
NX_CRYPTO_STATE_CHECK
#ifdef NX_SECURE_KEY_CLEAR
if (!crypto_metadata)
return (NX_CRYPTO_SUCCESS);
NX_CRYPTO_MEMSET(crypto_metadata, 0, sizeof(NX_CRYPTO_ECDSA));/* ... */
#else
NX_CRYPTO_PARAMETER_NOT_USED(crypto_metadata);
#endif
return(NX_CRYPTO_SUCCESS);
}{ ... }
...
...
NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_operation(UINT op,
VOID *handle,
struct NX_CRYPTO_METHOD_STRUCT *method,
UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
UCHAR *input, ULONG input_length_in_byte,
UCHAR *iv_ptr,
UCHAR *output, ULONG output_length_in_byte,
VOID *crypto_metadata, ULONG crypto_metadata_size,
VOID *packet_ptr,
VOID (*nx_crypto_hw_process_callback)(VOID *, UINT))
{
NX_CRYPTO_ECDSA *ecdsa;
UINT status = NX_CRYPTO_SUCCESS;
NX_CRYPTO_EXTENDED_OUTPUT
*extended_output;
NX_CRYPTO_METHOD *hash_method;
VOID *hash_handler = NX_CRYPTO_NULL;
UCHAR *hash_output = NX_CRYPTO_NULL;
NX_CRYPTO_PARAMETER_NOT_USED(handle);
NX_CRYPTO_PARAMETER_NOT_USED(iv_ptr);
NX_CRYPTO_PARAMETER_NOT_USED(packet_ptr);
NX_CRYPTO_PARAMETER_NOT_USED(nx_crypto_hw_process_callback);
NX_CRYPTO_STATE_CHECK
if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0))
{
return(NX_CRYPTO_PTR_ERROR);
}if ((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { ... }
if(crypto_metadata_size < sizeof(NX_CRYPTO_ECDSA))
{
return(NX_CRYPTO_PTR_ERROR);
}if (crypto_metadata_size < sizeof(NX_CRYPTO_ECDSA)) { ... }
ecdsa = (NX_CRYPTO_ECDSA *)crypto_metadata;
if (op == NX_CRYPTO_EC_CURVE_SET)
{
status = ((NX_CRYPTO_METHOD *)input) -> nx_crypto_operation(NX_CRYPTO_EC_CURVE_GET,
NX_CRYPTO_NULL,
(NX_CRYPTO_METHOD *)input,
NX_CRYPTO_NULL, 0,
NX_CRYPTO_NULL, 0,
NX_CRYPTO_NULL,
(UCHAR *)&ecdsa -> nx_crypto_ecdsa_curve,
sizeof(NX_CRYPTO_METHOD *),
NX_CRYPTO_NULL, 0,
NX_CRYPTO_NULL, NX_CRYPTO_NULL);
if (status)
{
return(status);
}if (status) { ... }
}if (op == NX_CRYPTO_EC_CURVE_SET) { ... }
else if (op == NX_CRYPTO_AUTHENTICATE)
{
if ((key == NX_CRYPTO_NULL) || (ecdsa -> nx_crypto_ecdsa_curve == NX_CRYPTO_NULL))
{
return(NX_CRYPTO_PTR_ERROR);
}if ((key == NX_CRYPTO_NULL) || (ecdsa -> nx_crypto_ecdsa_curve == NX_CRYPTO_NULL)) { ... }
extended_output = (NX_CRYPTO_EXTENDED_OUTPUT *)output;
status = _nx_crypto_ecdsa_sign(ecdsa -> nx_crypto_ecdsa_curve,
input,
input_length_in_byte,
key,
key_size_in_bits >> 3,
extended_output -> nx_crypto_extended_output_data,
extended_output -> nx_crypto_extended_output_length_in_byte,
&extended_output -> nx_crypto_extended_output_actual_size,
ecdsa -> nx_crypto_ecdsa_scratch_buffer);
}else if (op == NX_CRYPTO_AUTHENTICATE) { ... }
else if (op == NX_CRYPTO_VERIFY)
{
if (key == NX_CRYPTO_NULL)
{
return(NX_CRYPTO_PTR_ERROR);
}if (key == NX_CRYPTO_NULL) { ... }
status = _nx_crypto_ecdsa_verify(ecdsa->nx_crypto_ecdsa_curve,
input,
input_length_in_byte,
key,
key_size_in_bits >> 3,
output, output_length_in_byte,
ecdsa -> nx_crypto_ecdsa_scratch_buffer);
}else if (op == NX_CRYPTO_VERIFY) { ... }
else if (op == NX_CRYPTO_EC_KEY_PAIR_GENERATE)
{
if (ecdsa->nx_crypto_ecdsa_curve == NX_CRYPTO_NULL)
{
return(NX_CRYPTO_PTR_ERROR);
}if (ecdsa->nx_crypto_ecdsa_curve == NX_CRYPTO_NULL) { ... }
extended_output = (NX_CRYPTO_EXTENDED_OUTPUT *)output;
status = _nx_crypto_ec_key_pair_stream_generate(ecdsa->nx_crypto_ecdsa_curve,
extended_output -> nx_crypto_extended_output_data,
extended_output -> nx_crypto_extended_output_length_in_byte,
&extended_output -> nx_crypto_extended_output_actual_size,
ecdsa -> nx_crypto_ecdsa_scratch_buffer);
}else if (op == NX_CRYPTO_EC_KEY_PAIR_GENERATE) { ... }
else if (op == NX_CRYPTO_HASH_METHOD_SET)
{
hash_method = (NX_CRYPTO_METHOD *)input;
/* ... */
if ((hash_method -> nx_crypto_metadata_area_size +
(hash_method -> nx_crypto_ICV_size_in_bits >> 3)) >
sizeof(ecdsa -> nx_crypto_ecdsa_scratch_buffer))
{
status = NX_CRYPTO_SIZE_ERROR;
}if ((hash_method -> nx_crypto_metadata_area_size + (hash_method -> nx_crypto_ICV_size_in_bits >> 3)) > sizeof(ecdsa -> nx_crypto_ecdsa_scratch_buffer)) { ... }
else
{
ecdsa -> nx_crypto_ecdsa_hash_method = hash_method;
}else { ... }
}else if (op == NX_CRYPTO_HASH_METHOD_SET) { ... }
else if ((op == NX_CRYPTO_SIGNATURE_GENERATE) || (op == NX_CRYPTO_SIGNATURE_VERIFY))
{
hash_method = ecdsa -> nx_crypto_ecdsa_hash_method;
if (hash_method == NX_CRYPTO_NULL)
{
status = NX_CRYPTO_PTR_ERROR;
}if (hash_method == NX_CRYPTO_NULL) { ... }
else
{
hash_output = (UCHAR *)(ecdsa -> nx_crypto_ecdsa_scratch_buffer) +
(sizeof(ecdsa -> nx_crypto_ecdsa_scratch_buffer) - (hash_method -> nx_crypto_ICV_size_in_bits >> 3));
if (hash_method -> nx_crypto_init)
{
status = hash_method -> nx_crypto_init(hash_method,
NX_CRYPTO_NULL,
0,
&hash_handler,
ecdsa -> nx_crypto_ecdsa_scratch_buffer,
hash_method -> nx_crypto_metadata_area_size);
}if (hash_method -> nx_crypto_init) { ... }
if (status == NX_CRYPTO_SUCCESS)
{
status = hash_method -> nx_crypto_operation(NX_CRYPTO_AUTHENTICATE,
NX_CRYPTO_NULL,
hash_method,
NX_CRYPTO_NULL,
0,
input,
input_length_in_byte,
NX_CRYPTO_NULL,
hash_output,
(hash_method -> nx_crypto_ICV_size_in_bits >> 3),
ecdsa -> nx_crypto_ecdsa_scratch_buffer,
hash_method -> nx_crypto_metadata_area_size,
NX_CRYPTO_NULL, NX_CRYPTO_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}if (status == NX_CRYPTO_SUCCESS) { ... }
if (hash_method -> nx_crypto_cleanup)
{
status = hash_method -> nx_crypto_cleanup(ecdsa -> nx_crypto_ecdsa_scratch_buffer);
}if (hash_method -> nx_crypto_cleanup) { ... }
}else { ... }
if (status == NX_CRYPTO_SUCCESS)
{
if ((key == NX_CRYPTO_NULL) || (ecdsa -> nx_crypto_ecdsa_curve == NX_CRYPTO_NULL))
{
status = NX_CRYPTO_PTR_ERROR;
}if ((key == NX_CRYPTO_NULL) || (ecdsa -> nx_crypto_ecdsa_curve == NX_CRYPTO_NULL)) { ... }
else if (op == NX_CRYPTO_SIGNATURE_GENERATE)
{
extended_output = (NX_CRYPTO_EXTENDED_OUTPUT *)output;
status = _nx_crypto_ecdsa_sign(ecdsa -> nx_crypto_ecdsa_curve,
hash_output,
(hash_method -> nx_crypto_ICV_size_in_bits >> 3),
key,
key_size_in_bits >> 3,
extended_output -> nx_crypto_extended_output_data,
extended_output -> nx_crypto_extended_output_length_in_byte,
&extended_output -> nx_crypto_extended_output_actual_size,
ecdsa -> nx_crypto_ecdsa_scratch_buffer);
}else if (op == NX_CRYPTO_SIGNATURE_GENERATE) { ... }
else
{
status = _nx_crypto_ecdsa_verify(ecdsa->nx_crypto_ecdsa_curve,
hash_output,
(hash_method -> nx_crypto_ICV_size_in_bits >> 3),
key,
key_size_in_bits >> 3,
output, output_length_in_byte,
ecdsa -> nx_crypto_ecdsa_scratch_buffer);
}else { ... }
}if (status == NX_CRYPTO_SUCCESS) { ... }
}else if ((op == NX_CRYPTO_SIGNATURE_GENERATE) || (op == NX_CRYPTO_SIGNATURE_VERIFY)) { ... }
else
{
status = NX_CRYPTO_NOT_SUCCESSFUL;
}else { ... }
return(status);
}{ ... }