-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy path0002-Vendor-crypto-backends.patch
15174 lines (15166 loc) · 509 KB
/
0002-Vendor-crypto-backends.patch
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
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
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
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Quim Muntal <[email protected]>
Date: Mon, 23 May 2022 12:59:36 +0000
Subject: [PATCH] Vendor crypto backends
To reproduce changes in 'src/vendor', run 'go mod vendor' in 'src'.
Use a 'go' that was recently built by the current branch to ensure stable results.
---
src/crypto/internal/backend/deps_ignore.go | 22 +
src/go.mod | 6 +
src/go.sum | 6 +
src/go/build/deps_test.go | 17 +-
src/go/build/vendor_test.go | 3 +
.../golang-fips/openssl/v2/.gitignore | 1 +
.../golang-fips/openssl/v2/.gitleaks.toml | 9 +
.../github.com/golang-fips/openssl/v2/LICENSE | 20 +
.../golang-fips/openssl/v2/README.md | 66 ++
.../github.com/golang-fips/openssl/v2/aes.go | 147 ++++
.../golang-fips/openssl/v2/bbig/big.go | 37 +
.../github.com/golang-fips/openssl/v2/big.go | 11 +
.../golang-fips/openssl/v2/cgo_go124.go | 18 +
.../golang-fips/openssl/v2/cipher.go | 569 ++++++++++++++
.../github.com/golang-fips/openssl/v2/des.go | 114 +++
.../github.com/golang-fips/openssl/v2/dsa.go | 323 ++++++++
.../github.com/golang-fips/openssl/v2/ec.go | 68 ++
.../github.com/golang-fips/openssl/v2/ecdh.go | 303 ++++++++
.../golang-fips/openssl/v2/ecdsa.go | 208 +++++
.../golang-fips/openssl/v2/ed25519.go | 228 ++++++
.../github.com/golang-fips/openssl/v2/evp.go | 580 ++++++++++++++
.../golang-fips/openssl/v2/goopenssl.c | 248 ++++++
.../golang-fips/openssl/v2/goopenssl.h | 261 +++++++
.../github.com/golang-fips/openssl/v2/hash.go | 714 ++++++++++++++++++
.../github.com/golang-fips/openssl/v2/hkdf.go | 322 ++++++++
.../github.com/golang-fips/openssl/v2/hmac.go | 274 +++++++
.../github.com/golang-fips/openssl/v2/init.go | 64 ++
.../golang-fips/openssl/v2/init_unix.go | 31 +
.../golang-fips/openssl/v2/init_windows.go | 36 +
.../golang-fips/openssl/v2/openssl.go | 506 +++++++++++++
.../golang-fips/openssl/v2/params.go | 210 ++++++
.../golang-fips/openssl/v2/pbkdf2.go | 62 ++
.../golang-fips/openssl/v2/port_dsa.c | 85 +++
.../github.com/golang-fips/openssl/v2/rand.go | 20 +
.../github.com/golang-fips/openssl/v2/rc4.go | 66 ++
.../github.com/golang-fips/openssl/v2/rsa.go | 408 ++++++++++
.../github.com/golang-fips/openssl/v2/shims.h | 413 ++++++++++
.../golang-fips/openssl/v2/thread_setup.go | 14 +
.../golang-fips/openssl/v2/thread_setup.h | 4 +
.../openssl/v2/thread_setup_unix.c | 64 ++
.../openssl/v2/thread_setup_windows.c | 64 ++
.../golang-fips/openssl/v2/tls1prf.go | 160 ++++
.../github.com/golang-fips/openssl/v2/zaes.go | 86 +++
.../microsoft/go-crypto-darwin/LICENSE | 21 +
.../microsoft/go-crypto-darwin/bbig/big.go | 31 +
.../internal/cryptokit/CryptoKit.o | Bin 0 -> 100952 bytes
.../internal/cryptokit/cryptokit.go | 34 +
.../internal/cryptokit/cryptokit.h | 43 ++
.../internal/cryptokit/ed25519.go | 72 ++
.../internal/cryptokit/gcm.go | 36 +
.../internal/cryptokit/hkdf.go | 77 ++
.../microsoft/go-crypto-darwin/xcrypto/aes.go | 306 ++++++++
.../microsoft/go-crypto-darwin/xcrypto/big.go | 16 +
.../go-crypto-darwin/xcrypto/cgo_go124.go | 21 +
.../go-crypto-darwin/xcrypto/cipher.go | 122 +++
.../microsoft/go-crypto-darwin/xcrypto/des.go | 117 +++
.../microsoft/go-crypto-darwin/xcrypto/ec.go | 32 +
.../go-crypto-darwin/xcrypto/ecdh.go | 135 ++++
.../go-crypto-darwin/xcrypto/ecdsa.go | 181 +++++
.../go-crypto-darwin/xcrypto/ed25519.go | 100 +++
.../microsoft/go-crypto-darwin/xcrypto/evp.go | 338 +++++++++
.../go-crypto-darwin/xcrypto/hash.go | 403 ++++++++++
.../go-crypto-darwin/xcrypto/hkdf.go | 66 ++
.../go-crypto-darwin/xcrypto/hmac.go | 113 +++
.../go-crypto-darwin/xcrypto/pbkdf2.go | 65 ++
.../go-crypto-darwin/xcrypto/rand.go | 26 +
.../microsoft/go-crypto-darwin/xcrypto/rc4.go | 83 ++
.../microsoft/go-crypto-darwin/xcrypto/rsa.go | 194 +++++
.../go-crypto-darwin/xcrypto/xcrypto.go | 59 ++
.../microsoft/go-crypto-winnative/LICENSE | 21 +
.../microsoft/go-crypto-winnative/cng/aes.go | 393 ++++++++++
.../go-crypto-winnative/cng/bbig/big.go | 31 +
.../microsoft/go-crypto-winnative/cng/big.go | 30 +
.../go-crypto-winnative/cng/cipher.go | 52 ++
.../microsoft/go-crypto-winnative/cng/cng.go | 131 ++++
.../microsoft/go-crypto-winnative/cng/des.go | 106 +++
.../microsoft/go-crypto-winnative/cng/dsa.go | 465 ++++++++++++
.../microsoft/go-crypto-winnative/cng/ecdh.go | 255 +++++++
.../go-crypto-winnative/cng/ecdsa.go | 169 +++++
.../microsoft/go-crypto-winnative/cng/hash.go | 325 ++++++++
.../microsoft/go-crypto-winnative/cng/hkdf.go | 124 +++
.../microsoft/go-crypto-winnative/cng/hmac.go | 35 +
.../microsoft/go-crypto-winnative/cng/keys.go | 220 ++++++
.../go-crypto-winnative/cng/pbkdf2.go | 70 ++
.../microsoft/go-crypto-winnative/cng/rand.go | 28 +
.../microsoft/go-crypto-winnative/cng/rc4.go | 65 ++
.../microsoft/go-crypto-winnative/cng/rsa.go | 396 ++++++++++
.../microsoft/go-crypto-winnative/cng/sha3.go | 311 ++++++++
.../go-crypto-winnative/cng/tls1prf.go | 88 +++
.../internal/bcrypt/bcrypt_windows.go | 368 +++++++++
.../internal/bcrypt/ntstatus_windows.go | 45 ++
.../internal/bcrypt/zsyscall_windows.go | 412 ++++++++++
.../internal/subtle/aliasing.go | 32 +
.../internal/sysdll/sys_windows.go | 55 ++
src/vendor/modules.txt | 16 +
95 files changed, 13799 insertions(+), 3 deletions(-)
create mode 100644 src/crypto/internal/backend/deps_ignore.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/.gitignore
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/.gitleaks.toml
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/LICENSE
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/README.md
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/aes.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/bbig/big.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/big.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/cgo_go124.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/cipher.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/des.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/dsa.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/ec.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/ecdh.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/ecdsa.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/ed25519.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/evp.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/goopenssl.c
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/goopenssl.h
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/hash.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/hkdf.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/hmac.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/init.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/init_unix.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/init_windows.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/openssl.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/params.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/pbkdf2.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/port_dsa.c
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/rand.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/rc4.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/rsa.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/shims.h
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/thread_setup.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/thread_setup.h
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/thread_setup_unix.c
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/thread_setup_windows.c
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/tls1prf.go
create mode 100644 src/vendor/github.com/golang-fips/openssl/v2/zaes.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/LICENSE
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/bbig/big.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/internal/cryptokit/CryptoKit.o
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/internal/cryptokit/cryptokit.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/internal/cryptokit/cryptokit.h
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/internal/cryptokit/ed25519.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/internal/cryptokit/gcm.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/internal/cryptokit/hkdf.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/aes.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/big.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/cgo_go124.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/cipher.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/des.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/ec.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/ecdh.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/ecdsa.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/ed25519.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/evp.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/hash.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/hkdf.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/hmac.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/pbkdf2.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/rand.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/rc4.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/rsa.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-darwin/xcrypto/xcrypto.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/LICENSE
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/aes.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/bbig/big.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/big.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/cipher.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/cng.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/des.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/dsa.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/ecdh.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/ecdsa.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/hash.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/hkdf.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/hmac.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/keys.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/pbkdf2.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/rand.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/rc4.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/rsa.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/sha3.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/cng/tls1prf.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/internal/bcrypt/bcrypt_windows.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/internal/bcrypt/ntstatus_windows.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/internal/bcrypt/zsyscall_windows.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/internal/subtle/aliasing.go
create mode 100644 src/vendor/github.com/microsoft/go-crypto-winnative/internal/sysdll/sys_windows.go
diff --git a/src/crypto/internal/backend/deps_ignore.go b/src/crypto/internal/backend/deps_ignore.go
new file mode 100644
index 00000000000000..ae4055d2d71303
--- /dev/null
+++ b/src/crypto/internal/backend/deps_ignore.go
@@ -0,0 +1,22 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ms_ignore_backend_deps
+
+package main
+
+import (
+ _ "github.com/golang-fips/openssl/v2"
+ _ "github.com/golang-fips/openssl/v2/bbig"
+
+ _ "github.com/microsoft/go-crypto-darwin/bbig"
+ _ "github.com/microsoft/go-crypto-darwin/xcrypto"
+
+ _ "github.com/microsoft/go-crypto-winnative/cng"
+ _ "github.com/microsoft/go-crypto-winnative/cng/bbig"
+)
+
+// This file is here just to declare the external dependencies
+// that are used by the backend package. This allows to track
+// their versions in a single patch file.
diff --git a/src/go.mod b/src/go.mod
index 7a1318dcac32ba..a59c5f120e7dfb 100644
--- a/src/go.mod
+++ b/src/go.mod
@@ -11,3 +11,9 @@ require (
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
)
+
+require (
+ github.com/golang-fips/openssl/v2 v2.0.4-0.20250115103809-bf655f6d08d6
+ github.com/microsoft/go-crypto-darwin v0.0.2-0.20250116101429-467bd63a2d67
+ github.com/microsoft/go-crypto-winnative v0.0.0-20250110072644-50d2dfac4b70
+)
diff --git a/src/go.sum b/src/go.sum
index 9e661352f16e0b..b4273d691cbe36 100644
--- a/src/go.sum
+++ b/src/go.sum
@@ -1,3 +1,9 @@
+github.com/golang-fips/openssl/v2 v2.0.4-0.20250115103809-bf655f6d08d6 h1:FFp7Q2AwYX+IQhhQt3ljQDdWtG5ZbRu0u3ohWQdFow8=
+github.com/golang-fips/openssl/v2 v2.0.4-0.20250115103809-bf655f6d08d6/go.mod h1:OYUBsoxLpFu8OFyhZHxfpN8lgcsw8JhTC3BQK7+XUc0=
+github.com/microsoft/go-crypto-darwin v0.0.2-0.20250116101429-467bd63a2d67 h1:SI0IFiHducwfamZR7pv6jb92oc5o/z5tn66wynS6ADE=
+github.com/microsoft/go-crypto-darwin v0.0.2-0.20250116101429-467bd63a2d67/go.mod h1:LyP4oZ0QcysEJdqUTOk9ngNFArRFK94YRImkoJ8julQ=
+github.com/microsoft/go-crypto-winnative v0.0.0-20250110072644-50d2dfac4b70 h1:97wOagHu7OExwU929NjuPIlUEUaFIQtffQMaVj0mR5E=
+github.com/microsoft/go-crypto-winnative v0.0.0-20250110072644-50d2dfac4b70/go.mod h1:JkxQeL8dGcyCuKjn1Etz4NmQrOMImMy4BA9hptEfVFA=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.32.1-0.20241206180132-552d8ac903a1 h1:+Yk1FZ5E+/ewA0nOO/HRYs9E4yeqpGOShuSAdzCNNoQ=
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
index e3e01077c18b17..e017efb1562379 100644
--- a/src/go/build/deps_test.go
+++ b/src/go/build/deps_test.go
@@ -503,7 +503,7 @@ var depsRules = `
NONE < crypto/internal/boring/sig, crypto/internal/boring/syso;
sync/atomic < crypto/internal/boring/bcache;
- FIPS, internal/godebug, hash, embed,
+ FIPS, internal/godebug, hash, embed, encoding/binary,
crypto/internal/boring/sig,
crypto/internal/boring/syso,
crypto/internal/boring/bcache
@@ -513,6 +513,14 @@ var depsRules = `
< crypto/sha3
< crypto/internal/fips140hash
< crypto/cipher
+ < github.com/golang-fips/openssl/v2/internal/subtle
+ < github.com/golang-fips/openssl/v2
+ < github.com/microsoft/go-crypto-darwin/internal/cryptokit
+ < github.com/microsoft/go-crypto-darwin/xcrypto
+ < github.com/microsoft/go-crypto-winnative/internal/subtle
+ < github.com/microsoft/go-crypto-winnative/internal/sysdll
+ < github.com/microsoft/go-crypto-winnative/internal/bcrypt
+ < github.com/microsoft/go-crypto-winnative/cng
< crypto/internal/boring
< crypto/boring
< crypto/aes,
@@ -534,6 +542,9 @@ var depsRules = `
# CRYPTO-MATH is crypto that exposes math/big APIs - no cgo, net; fmt now ok.
CRYPTO, FMT, math/big
+ < github.com/golang-fips/openssl/v2/bbig
+ < github.com/microsoft/go-crypto-darwin/bbig
+ < github.com/microsoft/go-crypto-winnative/cng/bbig
< crypto/internal/boring/bbig
< crypto/rand
< crypto/ed25519 # depends on crypto/rand.Reader
@@ -837,7 +848,7 @@ var buildIgnore = []byte("\n//go:build ignore")
func findImports(pkg string) ([]string, error) {
vpkg := pkg
- if strings.HasPrefix(pkg, "golang.org") {
+ if strings.HasPrefix(pkg, "golang.org") || strings.HasPrefix(pkg, "github.com") {
vpkg = "vendor/" + pkg
}
dir := filepath.Join(Default.GOROOT, "src", vpkg)
@@ -847,7 +858,7 @@ func findImports(pkg string) ([]string, error) {
}
var imports []string
var haveImport = map[string]bool{}
- if pkg == "crypto/internal/boring" {
+ if pkg == "crypto/internal/boring" || pkg == "github.com/golang-fips/openssl/v2" || strings.HasPrefix(pkg, "github.com/microsoft/go-crypto-darwin") {
haveImport["C"] = true // kludge: prevent C from appearing in crypto/internal/boring imports
}
fset := token.NewFileSet()
diff --git a/src/go/build/vendor_test.go b/src/go/build/vendor_test.go
index 7f6237ffd59c11..6092c93d4c5b26 100644
--- a/src/go/build/vendor_test.go
+++ b/src/go/build/vendor_test.go
@@ -22,6 +22,9 @@ var allowedPackagePrefixes = []string{
"github.com/google/pprof",
"github.com/ianlancetaylor/demangle",
"rsc.io/markdown",
+ "github.com/golang-fips/openssl",
+ "github.com/microsoft/go-crypto-winnative",
+ "github.com/microsoft/go-crypto-darwin",
}
// Verify that the vendor directories contain only packages matching the list above.
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/.gitignore b/src/vendor/github.com/golang-fips/openssl/v2/.gitignore
new file mode 100644
index 00000000000000..79b5594df7fa29
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/.gitignore
@@ -0,0 +1 @@
+**/.DS_Store
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/.gitleaks.toml b/src/vendor/github.com/golang-fips/openssl/v2/.gitleaks.toml
new file mode 100644
index 00000000000000..aed2e22df2d555
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/.gitleaks.toml
@@ -0,0 +1,9 @@
+#
+# GitLeaks Repo Specific Configuration
+#
+# This allowlist is used to ignore false positives during secret scans.
+
+[allowlist]
+paths = [
+ 'ecdh_test.go',
+]
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/LICENSE b/src/vendor/github.com/golang-fips/openssl/v2/LICENSE
new file mode 100644
index 00000000000000..97e85154015761
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2022 The Golang FIPS Authors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/README.md b/src/vendor/github.com/golang-fips/openssl/v2/README.md
new file mode 100644
index 00000000000000..1bfbaf60f4dd58
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/README.md
@@ -0,0 +1,66 @@
+# Go OpenSSL bindings for FIPS compliance
+
+[![Go Reference](https://pkg.go.dev/badge/github.com/golang-fips/openssl.svg)](https://pkg.go.dev/github.com/golang-fips/openssl)
+
+The `openssl` package implements Go crypto primitives using OpenSSL shared libraries and cgo. When configured correctly, OpenSSL can be executed in FIPS mode, making the `openssl` package FIPS compliant.
+
+The `openssl` package is designed to be used as a drop-in replacement for the [boring](https://pkg.go.dev/crypto/internal/boring) package in order to facilitate integrating `openssl` inside a forked Go toolchain.
+
+## Disclaimer
+
+A program directly or indirectly using this package in FIPS mode can claim it is using a FIPS-certified cryptographic module (OpenSSL), but it can't claim the program as a whole is FIPS certified without passing the certification process, nor claim it is FIPS compliant without ensuring all crypto APIs and workflows are implemented in a FIPS-compliant manner.
+
+## Background
+
+FIPS 140-2 is a U.S. government computer security standard used to approve cryptographic modules. FIPS compliance may come up when working with U.S. government and other regulated industries.
+
+### Go FIPS compliance
+
+The Go `crypto` package is not FIPS certified, and the Go team has stated that it won't be, e.g. in [golang/go/issues/21734](https://github.com/golang/go/issues/21734#issuecomment-326980213) Adam Langley says:
+
+> The status of FIPS 140 for Go itself remains "no plans, basically zero chance".
+
+On the other hand, Google maintains a branch that uses cgo and BoringSSL to implement various crypto primitives: https://github.com/golang/go/blob/dev.boringcrypto/README.boringcrypto.md. As BoringSSL is FIPS 140-2 certified, an application using that branch is more likely to be FIPS 140-2 compliant, yet Google does not provide any liability about the suitability of this code in relation to the FIPS 140-2 standard.
+
+## Features
+
+### Multiple OpenSSL versions supported
+
+The `openssl` package has support for multiple OpenSSL versions, namely 1.0.2, 1.1.0, 1.1.1 and 3.x.
+
+All supported OpenSSL versions pass a small set of automatic tests that ensure they can be built and that there are no major regressions.
+These tests do not validate the cryptographic correctness of the `openssl` package.
+
+On top of that, the [golang-fips Go fork](https://github.com/golang-fips/go) -maintained by Red Hat- and the [Microsoft Go fork](https://github.com/microsoft/go), tests a subset of the supported OpenSSL versions when integrated with the Go `crypto` package.
+These tests are much more exhaustive and validate a specific OpenSSL version can produce working applications.
+
+### Building without OpenSSL headers
+
+The `openssl` package does not use any symbol from the OpenSSL headers. There is no need that have them installed to build an application which imports this library.
+
+The CI tests in this repository verify that all the functions and constants defined in our headers match the ones in the OpenSSL headers for every supported OpenSSL version.
+
+### Portable OpenSSL
+
+The OpenSSL bindings are implemented in such a way that the OpenSSL version available when building a program does not have to match with the OpenSSL version used when running it.
+In fact, OpenSSL doesn't need to be present on the builder.
+For example, using the `openssl` package and `go build .` on a Windows host with `GOOS=linux` can produce a program that successfully runs on Linux and uses OpenSSL.
+
+This feature does not require any additional configuration, but it only works with OpenSSL versions known and supported by the Go toolchain that integrates the `openssl` package.
+
+## Limitations
+
+- Only Unix, Unix-like and Windows platforms are supported.
+- The build must set `CGO_ENABLED=1`.
+
+## Acknowledgements
+
+The work done to support FIPS compatibility mode leverages code and ideas from other open-source projects:
+
+- All crypto stubs are a mirror of Google's [dev.boringcrypto branch](https://github.com/golang/go/tree/dev.boringcrypto) and the release branch ports of that branch.
+- The mapping between BoringSSL and OpenSSL APIs is taken from the former [Red Hat Go fork](https://pagure.io/go).
+- The portable OpenSSL implementation is ported from Microsoft's [.NET runtime](https://github.com/dotnet/runtime) cryptography module.
+
+## Code of Conduct
+
+This project adopts the Go code of conduct: https://go.dev/conduct.
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/aes.go b/src/vendor/github.com/golang-fips/openssl/v2/aes.go
new file mode 100644
index 00000000000000..18bb070a2e5bda
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/aes.go
@@ -0,0 +1,147 @@
+//go:build !cmd_go_bootstrap
+
+package openssl
+
+// #include "goopenssl.h"
+import "C"
+import (
+ "crypto/cipher"
+ "errors"
+)
+
+//go:generate go run github.com/golang-fips/openssl/v2/cmd/genaesmodes -in aes.go -modes CBC,CTR,GCM -out zaes.go
+//go:generate go run github.com/golang-fips/openssl/v2/cmd/gentestvectors -out vectors_test.go
+
+// Steps to support a new AES mode, e.g. `FOO`:
+// 1. Add `FOO` to the list of modes in the `genaesmodes` command.
+// 2. Run `go generate` to update the generated code.
+// 3. Implement the necessary interfaces for the new struct, which will be named `cipherWithFOO`.
+
+// NewAESCipher creates and returns a new AES cipher.Block.
+// The key argument should be the AES key, either 16, 24, or 32 bytes to select
+// AES-128, AES-192, or AES-256.
+// The returned cipher.Block implements the CBC, CTR, and/or GCM modes if
+// the underlying OpenSSL library supports them.
+func NewAESCipher(key []byte) (cipher.Block, error) {
+ var kind cipherKind
+ switch len(key) * 8 {
+ case 128:
+ kind = cipherAES128
+ case 192:
+ kind = cipherAES192
+ case 256:
+ kind = cipherAES256
+ default:
+ return nil, errors.New("crypto/aes: invalid key size")
+ }
+ c, err := newEVPCipher(key, kind)
+ if err != nil {
+ return nil, err
+ }
+ return newAESBlock(c, kind), nil
+}
+
+// NewGCMTLS returns a GCM cipher specific to TLS
+// and should not be used for non-TLS purposes.
+func NewGCMTLS(c cipher.Block) (cipher.AEAD, error) {
+ if c, ok := c.(interface {
+ NewGCMTLS() (cipher.AEAD, error)
+ }); ok {
+ return c.NewGCMTLS()
+ }
+ return nil, errors.New("GCM not supported")
+}
+
+// NewGCMTLS13 returns a GCM cipher specific to TLS 1.3 and should not be used
+// for non-TLS purposes.
+func NewGCMTLS13(c cipher.Block) (cipher.AEAD, error) {
+ if c, ok := c.(interface {
+ NewGCMTLS13() (cipher.AEAD, error)
+ }); ok {
+ return c.NewGCMTLS13()
+ }
+ return nil, errors.New("GCM not supported")
+}
+
+// aesCipher implements the cipher.Block interface.
+type aesCipher struct {
+ cipher *evpCipher
+}
+
+func (c aesCipher) BlockSize() int {
+ return c.cipher.blockSize
+}
+
+func (c aesCipher) Encrypt(dst, src []byte) {
+ if err := c.cipher.encrypt(dst, src); err != nil {
+ // crypto/aes expects that the panic message starts with "crypto/aes: ".
+ panic("crypto/aes: " + err.Error())
+ }
+}
+
+func (c aesCipher) Decrypt(dst, src []byte) {
+ if err := c.cipher.decrypt(dst, src); err != nil {
+ // crypto/aes expects that the panic message starts with "crypto/aes: ".
+ panic("crypto/aes: " + err.Error())
+ }
+}
+
+// Implement optional interfaces for AES modes.
+
+func (c cipherWithCBC) NewCBCEncrypter(iv []byte) cipher.BlockMode {
+ return c.cipher.newCBC(iv, cipherOpEncrypt)
+}
+
+func (c cipherWithCBC) NewCBCDecrypter(iv []byte) cipher.BlockMode {
+ return c.cipher.newCBC(iv, cipherOpDecrypt)
+}
+
+func (c cipherWithCTR) NewCTR(iv []byte) cipher.Stream {
+ return c.cipher.newCTR(iv)
+}
+
+func (c cipherWithGCM) NewGCM(nonceSize, tagSize int) (cipher.AEAD, error) {
+ return c.cipher.newGCMChecked(nonceSize, tagSize)
+}
+
+func (c cipherWithGCM) NewGCMTLS() (cipher.AEAD, error) {
+ return c.cipher.newGCM(cipherGCMTLS12)
+}
+
+func (c cipherWithGCM) NewGCMTLS13() (cipher.AEAD, error) {
+ return c.cipher.newGCM(cipherGCMTLS13)
+}
+
+// The following interfaces have been copied out of crypto/aes/modes.go.
+
+type gcmAble interface {
+ NewGCM(nonceSize, tagSize int) (cipher.AEAD, error)
+}
+
+type cbcEncAble interface {
+ NewCBCEncrypter(iv []byte) cipher.BlockMode
+}
+
+type cbcDecAble interface {
+ NewCBCDecrypter(iv []byte) cipher.BlockMode
+}
+
+type ctrAble interface {
+ NewCTR(iv []byte) cipher.Stream
+}
+
+// Test that the interfaces are implemented.
+
+var (
+ _ cipher.Block = (*aesCipher)(nil)
+
+ _ cipher.Block = (*cipherWithCBC)(nil)
+ _ cbcEncAble = (*cipherWithCBC)(nil)
+ _ cbcDecAble = (*cipherWithCBC)(nil)
+
+ _ cipher.Block = (*cipherWithCTR)(nil)
+ _ ctrAble = (*cipherWithCTR)(nil)
+
+ _ cipher.Block = (*cipherWithGCM)(nil)
+ _ gcmAble = (*cipherWithGCM)(nil)
+)
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/bbig/big.go b/src/vendor/github.com/golang-fips/openssl/v2/bbig/big.go
new file mode 100644
index 00000000000000..a81cbdbef93148
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/bbig/big.go
@@ -0,0 +1,37 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This is a mirror of
+// https://github.com/golang/go/blob/36b87f273cc43e21685179dc1664ebb5493d26ae/src/crypto/internal/boring/bbig/big.go.
+
+package bbig
+
+import (
+ "math/big"
+ "unsafe"
+
+ "github.com/golang-fips/openssl/v2"
+)
+
+func Enc(b *big.Int) openssl.BigInt {
+ if b == nil {
+ return nil
+ }
+ x := b.Bits()
+ if len(x) == 0 {
+ return openssl.BigInt{}
+ }
+ return unsafe.Slice((*uint)(&x[0]), len(x))
+}
+
+func Dec(b openssl.BigInt) *big.Int {
+ if b == nil {
+ return nil
+ }
+ if len(b) == 0 {
+ return new(big.Int)
+ }
+ x := unsafe.Slice((*big.Word)(&b[0]), len(b))
+ return new(big.Int).SetBits(x)
+}
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/big.go b/src/vendor/github.com/golang-fips/openssl/v2/big.go
new file mode 100644
index 00000000000000..6461f241f863fc
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/big.go
@@ -0,0 +1,11 @@
+package openssl
+
+// This file does not have build constraints to
+// facilitate using BigInt in Go crypto.
+// Go crypto references BigInt unconditionally,
+// even if it is not finally used.
+
+// A BigInt is the raw words from a BigInt.
+// This definition allows us to avoid importing math/big.
+// Conversion between BigInt and *big.Int is in openssl/bbig.
+type BigInt []uint
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/cgo_go124.go b/src/vendor/github.com/golang-fips/openssl/v2/cgo_go124.go
new file mode 100644
index 00000000000000..933a751873dd05
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/cgo_go124.go
@@ -0,0 +1,18 @@
+//go:build go1.24 && !cmd_go_bootstrap
+
+package openssl
+
+// The following noescape and nocallback directives are used to prevent the Go
+// compiler from allocating function parameters on the heap. See
+// https://github.com/golang/go/blob/0733682e5ff4cd294f5eccb31cbe87a543147bc6/src/cmd/cgo/doc.go#L439-L461
+//
+// If possible, write a C wrapper function to optimize a call rather than using
+// this feature so the optimization will work for all supported Go versions.
+//
+// This is just a performance optimization. Only add functions that have been
+// observed to benefit from these directives, not every function that is merely
+// expected to meet the noescape/nocallback criteria.
+
+// #cgo noescape go_openssl_RAND_bytes
+// #cgo nocallback go_openssl_RAND_bytes
+import "C"
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/cipher.go b/src/vendor/github.com/golang-fips/openssl/v2/cipher.go
new file mode 100644
index 00000000000000..72f7aebfc130e7
--- /dev/null
+++ b/src/vendor/github.com/golang-fips/openssl/v2/cipher.go
@@ -0,0 +1,569 @@
+//go:build !cmd_go_bootstrap
+
+package openssl
+
+// #include "goopenssl.h"
+import "C"
+
+import (
+ "crypto/cipher"
+ "encoding/binary"
+ "errors"
+ "runtime"
+ "strconv"
+ "sync"
+ "unsafe"
+)
+
+type cipherKind int8
+
+const (
+ cipherAES128 cipherKind = iota
+ cipherAES192
+ cipherAES256
+ cipherDES
+ cipherDES3
+ cipherRC4
+)
+
+func (c cipherKind) String() string {
+ switch c {
+ case cipherAES128:
+ return "AES-128"
+ case cipherAES192:
+ return "AES-192"
+ case cipherAES256:
+ return "AES-256"
+ case cipherDES:
+ return "DES"
+ case cipherDES3:
+ return "DES3"
+ case cipherRC4:
+ return "RC4"
+ default:
+ panic("unknown cipher kind: " + strconv.Itoa(int(c)))
+ }
+}
+
+type cipherMode int8
+
+const (
+ cipherModeNone cipherMode = -1
+ cipherModeECB cipherMode = iota
+ cipherModeCBC
+ cipherModeCTR
+ cipherModeGCM
+)
+
+// cipherOp is the allowed operations for a cipher,
+// as documented in [EVP_CipherInit_ex].
+//
+// [EVP_CipherInit_ex]: https://www.openssl.org/docs/man3.0/man3/EVP_CipherInit_ex.html
+type cipherOp int8
+
+const (
+ cipherOpNone cipherOp = -1 // leaves the value of the previous call, if any.
+ cipherOpDecrypt cipherOp = 0
+ cipherOpEncrypt cipherOp = 1
+)
+
+// cacheCipher is a cache of cipherKind to GO_EVP_CIPHER_PTR.
+var cacheCipher sync.Map
+
+type cacheCipherKey struct {
+ kind cipherKind
+ mode cipherMode
+}
+
+// loadCipher returns a cipher object for the given k.
+func loadCipher(k cipherKind, mode cipherMode) (cipher C.GO_EVP_CIPHER_PTR) {
+ if v, ok := cacheCipher.Load(cacheCipherKey{k, mode}); ok {
+ return v.(C.GO_EVP_CIPHER_PTR)
+ }
+ defer func() {
+ if cipher != nil && vMajor == 3 {
+ // On OpenSSL 3, directly operating on a EVP_CIPHER object
+ // not created by EVP_CIPHER has negative performance
+ // implications, as cipher operations will have
+ // to fetch it on every call. Better to just fetch it once here.
+ cipher = C.go_openssl_EVP_CIPHER_fetch(nil, C.go_openssl_EVP_CIPHER_get0_name(cipher), nil)
+ }
+ cacheCipher.Store(cacheCipherKey{k, mode}, cipher)
+ }()
+ switch k {
+ case cipherAES128:
+ switch mode {
+ case cipherModeECB:
+ cipher = C.go_openssl_EVP_aes_128_ecb()
+ case cipherModeCBC:
+ cipher = C.go_openssl_EVP_aes_128_cbc()
+ case cipherModeCTR:
+ cipher = C.go_openssl_EVP_aes_128_ctr()
+ case cipherModeGCM:
+ cipher = C.go_openssl_EVP_aes_128_gcm()
+ }
+ case cipherAES192:
+ switch mode {
+ case cipherModeECB:
+ cipher = C.go_openssl_EVP_aes_192_ecb()
+ case cipherModeCBC:
+ cipher = C.go_openssl_EVP_aes_192_cbc()
+ case cipherModeCTR:
+ cipher = C.go_openssl_EVP_aes_192_ctr()
+ case cipherModeGCM:
+ cipher = C.go_openssl_EVP_aes_192_gcm()
+ }
+ case cipherAES256:
+ switch mode {
+ case cipherModeECB:
+ cipher = C.go_openssl_EVP_aes_256_ecb()
+ case cipherModeCBC:
+ cipher = C.go_openssl_EVP_aes_256_cbc()
+ case cipherModeCTR:
+ cipher = C.go_openssl_EVP_aes_256_ctr()
+ case cipherModeGCM:
+ cipher = C.go_openssl_EVP_aes_256_gcm()
+ }
+ case cipherDES:
+ switch mode {
+ case cipherModeECB:
+ cipher = C.go_openssl_EVP_des_ecb()
+ case cipherModeCBC:
+ cipher = C.go_openssl_EVP_des_cbc()
+ }
+ case cipherDES3:
+ switch mode {
+ case cipherModeECB:
+ cipher = C.go_openssl_EVP_des_ede3_ecb()
+ case cipherModeCBC:
+ cipher = C.go_openssl_EVP_des_ede3_cbc()
+ }
+ case cipherRC4:
+ cipher = C.go_openssl_EVP_rc4()
+ }
+ return cipher
+}
+
+type evpCipher struct {
+ key []byte
+ kind cipherKind
+ blockSize int
+}
+
+func newEVPCipher(key []byte, kind cipherKind) (*evpCipher, error) {
+ cipher := loadCipher(kind, cipherModeECB)
+ if cipher == nil {
+ return nil, errors.New("crypto/cipher: unsupported cipher: " + kind.String())
+ }
+ c := &evpCipher{key: make([]byte, len(key)), kind: kind}
+ copy(c.key, key)
+ c.blockSize = int(C.go_openssl_EVP_CIPHER_get_block_size(cipher))
+ return c, nil
+}
+
+func (c *evpCipher) encrypt(dst, src []byte) error {
+ if len(src) < c.blockSize {
+ return errors.New("input not full block")
+ }
+ if len(dst) < c.blockSize {
+ return errors.New("output not full block")
+ }
+ // Only check for overlap between the parts of src and dst that will actually be used.
+ // This matches Go standard library behavior.
+ if inexactOverlap(dst[:c.blockSize], src[:c.blockSize]) {
+ return errors.New("invalid buffer overlap")
+ }
+ enc_ctx, err := newCipherCtx(c.kind, cipherModeECB, cipherOpEncrypt, c.key, nil)
+ if err != nil {
+ return err
+ }
+ defer C.go_openssl_EVP_CIPHER_CTX_free(enc_ctx)
+
+ if C.go_openssl_EVP_EncryptUpdate_wrapper(enc_ctx, base(dst), base(src), C.int(c.blockSize)) != 1 {
+ return errors.New("EncryptUpdate failed")
+ }
+ runtime.KeepAlive(c)
+ return nil
+}
+
+func (c *evpCipher) decrypt(dst, src []byte) error {
+ if len(src) < c.blockSize {
+ return errors.New("input not full block")
+ }
+ if len(dst) < c.blockSize {
+ return errors.New("output not full block")
+ }
+ // Only check for overlap between the parts of src and dst that will actually be used.
+ // This matches Go standard library behavior.
+ if inexactOverlap(dst[:c.blockSize], src[:c.blockSize]) {
+ return errors.New("invalid buffer overlap")
+ }
+ dec_ctx, err := newCipherCtx(c.kind, cipherModeECB, cipherOpDecrypt, c.key, nil)
+ if err != nil {
+ return err
+ }
+ defer C.go_openssl_EVP_CIPHER_CTX_free(dec_ctx)
+
+ if C.go_openssl_EVP_CIPHER_CTX_set_padding(dec_ctx, 0) != 1 {
+ return errors.New("could not disable cipher padding")
+ }
+
+ C.go_openssl_EVP_DecryptUpdate_wrapper(dec_ctx, base(dst), base(src), C.int(c.blockSize))
+ runtime.KeepAlive(c)
+ return nil
+}
+
+type cipherCBC struct {
+ ctx C.GO_EVP_CIPHER_CTX_PTR
+ blockSize int
+}
+
+func (c *cipherCBC) finalize() {
+ C.go_openssl_EVP_CIPHER_CTX_free(c.ctx)
+}
+
+func (x *cipherCBC) BlockSize() int { return x.blockSize }
+
+func (x *cipherCBC) CryptBlocks(dst, src []byte) {
+ if inexactOverlap(dst, src) {
+ panic("crypto/cipher: invalid buffer overlap")
+ }
+ if len(src)%x.blockSize != 0 {
+ panic("crypto/cipher: input not full blocks")
+ }
+ if len(dst) < len(src) {
+ panic("crypto/cipher: output smaller than input")
+ }
+ if len(src) > 0 {
+ if C.go_openssl_EVP_CipherUpdate_wrapper(x.ctx, base(dst), base(src), C.int(len(src))) != 1 {
+ panic("crypto/cipher: CipherUpdate failed")
+ }
+ runtime.KeepAlive(x)
+ }
+}
+
+func (x *cipherCBC) SetIV(iv []byte) {
+ if len(iv) != x.blockSize {
+ panic("cipher: incorrect length IV")
+ }
+ if C.go_openssl_EVP_CipherInit_ex(x.ctx, nil, nil, nil, base(iv), C.int(cipherOpNone)) != 1 {
+ panic("cipher: unable to initialize EVP cipher ctx")
+ }
+}
+
+func (c *evpCipher) newCBC(iv []byte, op cipherOp) cipher.BlockMode {
+ ctx, err := newCipherCtx(c.kind, cipherModeCBC, op, c.key, iv)
+ if err != nil {
+ panic(err)
+ }
+ x := &cipherCBC{ctx: ctx, blockSize: c.blockSize}
+ runtime.SetFinalizer(x, (*cipherCBC).finalize)
+ if C.go_openssl_EVP_CIPHER_CTX_set_padding(x.ctx, 0) != 1 {
+ panic("cipher: unable to set padding")
+ }
+ return x
+}
+
+type cipherCTR struct {
+ ctx C.GO_EVP_CIPHER_CTX_PTR
+}
+
+func (x *cipherCTR) XORKeyStream(dst, src []byte) {
+ if inexactOverlap(dst, src) {
+ panic("crypto/cipher: invalid buffer overlap")
+ }
+ if len(dst) < len(src) {
+ panic("crypto/cipher: output smaller than input")
+ }
+ if len(src) == 0 {
+ return
+ }
+ if C.go_openssl_EVP_EncryptUpdate_wrapper(x.ctx, base(dst), base(src), C.int(len(src))) != 1 {
+ panic("crypto/cipher: EncryptUpdate failed")
+ }
+ runtime.KeepAlive(x)
+}
+
+func (c *evpCipher) newCTR(iv []byte) cipher.Stream {
+ ctx, err := newCipherCtx(c.kind, cipherModeCTR, cipherOpEncrypt, c.key, iv)
+ if err != nil {
+ panic(err)
+ }
+ x := &cipherCTR{ctx: ctx}
+ runtime.SetFinalizer(x, (*cipherCTR).finalize)
+ return x
+}
+
+func (c *cipherCTR) finalize() {
+ C.go_openssl_EVP_CIPHER_CTX_free(c.ctx)
+}
+
+type cipherGCMTLS uint8
+
+const (
+ cipherGCMTLSNone cipherGCMTLS = iota
+ cipherGCMTLS12
+ cipherGCMTLS13
+)
+
+type cipherGCM struct {
+ c *evpCipher
+ tls cipherGCMTLS
+ // minNextNonce is the minimum value that the next nonce can be, enforced by
+ // all TLS modes.
+ minNextNonce uint64
+ // mask is the nonce mask used in TLS 1.3 mode.