1
- diff --git a/api/go1.19.txt b/api/go1.19.txt
2
- index f31d633af9..e078f4aee1 100644
3
- --- a/api/go1.19.txt
4
- +++ b/api/go1.19.txt
5
- @@ -290,6 +290,8 @@ pkg sync/atomic, type Uint64 struct #50860
6
- pkg sync/atomic, type Uintptr struct #50860
7
- pkg time, method (Duration) Abs() Duration #51414
8
- pkg time, method (Time) ZoneBounds() (Time, Time) #50062
9
- + pkg crypto/ecdsa, func HashSign(io.Reader, *PrivateKey, []uint8, crypto.Hash) (*big.Int, *big.Int, error) #000000
10
- + pkg crypto/ecdsa, func HashVerify(*PublicKey, []uint8, *big.Int, *big.Int, crypto.Hash) bool #000000
11
- pkg crypto/x509, func ParseCRL //deprecated #50674
12
- pkg crypto/x509, func ParseDERCRL //deprecated #50674
13
- pkg crypto/x509, method (*Certificate) CheckCRLSignature //deprecated #50674
14
1
diff --git a/src/cmd/go/testdata/script/gopath_std_vendor.txt b/src/cmd/go/testdata/script/gopath_std_vendor.txt
15
2
index 4aaf46b5d0..c231e299d9 100644
16
3
--- a/src/cmd/go/testdata/script/gopath_std_vendor.txt
@@ -51,105 +38,6 @@ index 10da95afbb..af6bcd86f4 100644
51
38
if testing.Short() {
52
39
t.Skip("test requires running 'go build'")
53
40
}
54
- diff --git a/src/crypto/ecdsa/ecdsa_hashsignverify.go b/src/crypto/ecdsa/ecdsa_hashsignverify.go
55
- new file mode 100644
56
- index 0000000000..37f3a18223
57
- --- /dev/null
58
- +++ b/src/crypto/ecdsa/ecdsa_hashsignverify.go
59
- @@ -0,0 +1,45 @@
60
- + package ecdsa
61
- +
62
- + import (
63
- + "crypto"
64
- + "crypto/internal/boring"
65
- + "crypto/internal/randutil"
66
- + "math/big"
67
- + "io"
68
- + )
69
- +
70
- + func HashSign(rand io.Reader, priv *PrivateKey, msg []byte, h crypto.Hash) (*big.Int, *big.Int, error) {
71
- + randutil.MaybeReadByte(rand)
72
- +
73
- + if boring.Enabled {
74
- + b, err := boringPrivateKey(priv)
75
- + if err != nil {
76
- + return nil, nil, err
77
- + }
78
- + return boring.HashSignECDSA(b, msg, h)
79
- + }
80
- + boring.UnreachableExceptTests()
81
- +
82
- + hash := h.New()
83
- + hash.Write(msg)
84
- + d := hash.Sum(nil)
85
- +
86
- + return Sign(rand, priv, d)
87
- + }
88
- +
89
- + func HashVerify(pub *PublicKey, msg []byte, r, s *big.Int, h crypto.Hash) bool {
90
- + if boring.Enabled {
91
- + bpk, err := boringPublicKey(pub)
92
- + if err != nil {
93
- + return false
94
- + }
95
- + return boring.HashVerifyECDSA(bpk, msg, r, s, h)
96
- + }
97
- + boring.UnreachableExceptTests()
98
- +
99
- + hash := h.New()
100
- + hash.Write(msg)
101
- + d := hash.Sum(nil)
102
- +
103
- + return Verify(pub, d, r, s)
104
- + }
105
- diff --git a/src/crypto/ecdsa/ecdsa_hashsignverify_test.go b/src/crypto/ecdsa/ecdsa_hashsignverify_test.go
106
- new file mode 100644
107
- index 0000000000..d12ba2f441
108
- --- /dev/null
109
- +++ b/src/crypto/ecdsa/ecdsa_hashsignverify_test.go
110
- @@ -0,0 +1,42 @@
111
- + package ecdsa
112
- +
113
- + import (
114
- + "crypto"
115
- + "crypto/internal/boring"
116
- + "crypto/elliptic"
117
- + "crypto/rand"
118
- + "testing"
119
- + )
120
- +
121
- + func testHashSignAndHashVerify(t *testing.T, c elliptic.Curve, tag string) {
122
- + priv, err := GenerateKey(c, rand.Reader)
123
- + if priv == nil {
124
- + t.Fatal(err)
125
- + }
126
- +
127
- + msg := []byte("testing")
128
- + h := crypto.SHA256
129
- + r, s, err := HashSign(rand.Reader, priv, msg, h)
130
- + if err != nil {
131
- + t.Errorf("%s: error signing: %s", tag, err)
132
- + return
133
- + }
134
- +
135
- + if !HashVerify(&priv.PublicKey, msg, r, s, h) {
136
- + t.Errorf("%s: Verify failed", tag)
137
- + }
138
- +
139
- + msg[0] ^= 0xff
140
- + if HashVerify(&priv.PublicKey, msg, r, s, h) {
141
- + t.Errorf("%s: Verify should not have succeeded", tag)
142
- + }
143
- + }
144
- + func TestHashSignAndHashVerify(t *testing.T) {
145
- + testHashSignAndHashVerify(t, elliptic.P256(), "p256")
146
- +
147
- + if testing.Short() && !boring.Enabled {
148
- + return
149
- + }
150
- + testHashSignAndHashVerify(t, elliptic.P384(), "p384")
151
- + testHashSignAndHashVerify(t, elliptic.P521(), "p521")
152
- + }
153
41
diff --git a/src/crypto/ecdsa/ecdsa_test.go b/src/crypto/ecdsa/ecdsa_test.go
154
42
index 08a0903eb1..61a4662036 100644
155
43
--- a/src/crypto/ecdsa/ecdsa_test.go
@@ -247,50 +135,6 @@ index f933f2800a..223ce04340 100644
247
135
testenv.MustHaveExternalNetwork(t)
248
136
249
137
// Create a temp dir and modcache subdir.
250
- diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
251
- new file mode 100644
252
- index 0000000000..c0800df578
253
- --- /dev/null
254
- +++ b/src/crypto/internal/backend/bbig/big.go
255
- @@ -0,0 +1,38 @@
256
- + // Copyright 2022 The Go Authors. All rights reserved.
257
- + // Use of this source code is governed by a BSD-style
258
- + // license that can be found in the LICENSE file.
259
- +
260
- + // This is a mirror of crypto/internal/boring/bbig/big.go.
261
- +
262
- + package bbig
263
- +
264
- + import (
265
- + "math/big"
266
- + "unsafe"
267
- +
268
- + "github.com/golang-fips/openssl-fips/openssl"
269
- + )
270
- +
271
- + func Enc(b *big.Int) openssl.BigInt {
272
- + if b == nil {
273
- + return nil
274
- + }
275
- + x := b.Bits()
276
- + if len(x) == 0 {
277
- + return openssl.BigInt{}
278
- + }
279
- + // TODO: Use unsafe.Slice((*uint)(&x[0]), len(x)) once go1.16 is no longer supported.
280
- + return (*(*[]uint)(unsafe.Pointer(&x)))[:len(x)]
281
- + }
282
- +
283
- + func Dec(b openssl.BigInt) *big.Int {
284
- + if b == nil {
285
- + return nil
286
- + }
287
- + if len(b) == 0 {
288
- + return new(big.Int)
289
- + }
290
- + // TODO: Use unsafe.Slice((*uint)(&b[0]), len(b)) once go1.16 is no longer supported.
291
- + x := (*(*[]big.Word)(unsafe.Pointer(&b)))[:len(b)]
292
- + return new(big.Int).SetBits(x)
293
- + }
294
138
diff --git a/src/crypto/internal/backend/boringtest/config.go b/src/crypto/internal/backend/boringtest/config.go
295
139
new file mode 100644
296
140
index 0000000000..6c8c00d11e
@@ -366,7 +210,7 @@ index 0000000000..15c1ee8cbe
366
210
+ "crypto/cipher"
367
211
+ "crypto/internal/boring/sig"
368
212
+ "math/big"
369
- + "github.com/golang-fips/openssl-fips/openssl "
213
+ + bbig "crypto/internal/boring "
370
214
+ "hash"
371
215
+ "io"
372
216
+ )
@@ -419,16 +263,16 @@ index 0000000000..15c1ee8cbe
419
263
+ func NewGCMTLS(c cipher.Block) (cipher.AEAD, error) {
420
264
+ panic("boringcrypto: not available")
421
265
+ }
422
- + func GenerateKeyECDSA(curve string) (X, Y, D openssl .BigInt, err error) {
266
+ + func GenerateKeyECDSA(curve string) (X, Y, D bbig .BigInt, err error) {
423
267
+ panic("boringcrypto: not available")
424
268
+ }
425
- + func NewPrivateKeyECDSA(curve string, X, Y, D openssl .BigInt) (*PrivateKeyECDSA, error) {
269
+ + func NewPrivateKeyECDSA(curve string, X, Y, D bbig .BigInt) (*PrivateKeyECDSA, error) {
426
270
+ panic("boringcrypto: not available")
427
271
+ }
428
- + func NewPublicKeyECDSA(curve string, X, Y openssl .BigInt) (*PublicKeyECDSA, error) {
272
+ + func NewPublicKeyECDSA(curve string, X, Y bbig .BigInt) (*PublicKeyECDSA, error) {
429
273
+ panic("boringcrypto: not available")
430
274
+ }
431
- + func SignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (r, s openssl .BigInt, err error) {
275
+ + func SignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (r, s bbig .BigInt, err error) {
432
276
+ panic("boringcrypto: not available")
433
277
+ }
434
278
+ func SignMarshalECDSA(priv *PrivateKeyECDSA, hash []byte) ([]byte, error) {
@@ -462,7 +306,7 @@ index 0000000000..15c1ee8cbe
462
306
+ type PublicKeyRSA struct{ _ int }
463
307
+ type PrivateKeyRSA struct{ _ int }
464
308
+
465
- + func DecryptRSAOAEP(h hash.Hash, priv *PrivateKeyRSA, ciphertext, label []byte) ([]byte, error) {
309
+ + func DecryptRSAOAEP(h, h2 hash.Hash, priv *PrivateKeyRSA, ciphertext, label []byte) ([]byte, error) {
466
310
+ panic("boringcrypto: not available")
467
311
+ }
468
312
+ func DecryptRSAPKCS1(priv *PrivateKeyRSA, ciphertext []byte) ([]byte, error) {
@@ -471,7 +315,7 @@ index 0000000000..15c1ee8cbe
471
315
+ func DecryptRSANoPadding(priv *PrivateKeyRSA, ciphertext []byte) ([]byte, error) {
472
316
+ panic("boringcrypto: not available")
473
317
+ }
474
- + func EncryptRSAOAEP(h hash.Hash, pub *PublicKeyRSA, msg, label []byte) ([]byte, error) {
318
+ + func EncryptRSAOAEP(h, h2 hash.Hash, pub *PublicKeyRSA, msg, label []byte) ([]byte, error) {
475
319
+ panic("boringcrypto: not available")
476
320
+ }
477
321
+ func EncryptRSAPKCS1(pub *PublicKeyRSA, msg []byte) ([]byte, error) {
@@ -480,20 +324,20 @@ index 0000000000..15c1ee8cbe
480
324
+ func EncryptRSANoPadding(pub *PublicKeyRSA, msg []byte) ([]byte, error) {
481
325
+ panic("boringcrypto: not available")
482
326
+ }
483
- + func GenerateKeyRSA(bits int) (N, E, D, P, Q, Dp, Dq, Qinv openssl .BigInt, err error) {
327
+ + func GenerateKeyRSA(bits int) (N, E, D, P, Q, Dp, Dq, Qinv bbig .BigInt, err error) {
484
328
+ panic("boringcrypto: not available")
485
329
+ }
486
- + func NewPrivateKeyRSA(N, E, D, P, Q, Dp, Dq, Qinv openssl .BigInt) (*PrivateKeyRSA, error) {
330
+ + func NewPrivateKeyRSA(N, E, D, P, Q, Dp, Dq, Qinv bbig .BigInt) (*PrivateKeyRSA, error) {
487
331
+ panic("boringcrypto: not available")
488
332
+ }
489
- + func NewPublicKeyRSA(N, E openssl .BigInt) (*PublicKeyRSA, error) { panic("boringcrypto: not available") }
490
- + func SignRSAPKCS1v15(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, msgHashed bool ) ([]byte, error) {
333
+ + func NewPublicKeyRSA(N, E bbig .BigInt) (*PublicKeyRSA, error) { panic("boringcrypto: not available") }
334
+ + func SignRSAPKCS1v15(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte) ([]byte, error) {
491
335
+ panic("boringcrypto: not available")
492
336
+ }
493
337
+ func SignRSAPSS(priv *PrivateKeyRSA, h crypto.Hash, hashed []byte, saltLen int) ([]byte, error) {
494
338
+ panic("boringcrypto: not available")
495
339
+ }
496
- + func VerifyRSAPKCS1v15(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, msgHashed bool ) error {
340
+ + func VerifyRSAPKCS1v15(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte) error {
497
341
+ panic("boringcrypto: not available")
498
342
+ }
499
343
+ func VerifyRSAPSS(pub *PublicKeyRSA, h crypto.Hash, hashed, sig []byte, saltLen int) error {
@@ -520,7 +364,7 @@ new file mode 100644
520
364
index 0000000000..2087c555a4
521
365
--- /dev/null
522
366
+++ b/src/crypto/internal/backend/openssl.go
523
- @@ -0,0 +1,106 @@
367
+ @@ -0,0 +1,122 @@
524
368
+ // Copyright 2017 The Go Authors. All rights reserved.
525
369
+ // Use of this source code is governed by a BSD-style
526
370
+ // license that can be found in the LICENSE file.
@@ -534,11 +378,20 @@ index 0000000000..2087c555a4
534
378
+ package backend
535
379
+
536
380
+ import (
537
- + "github.com/golang-fips/openssl-fips/openssl"
381
+ + "os"
382
+ + "github.com/golang-fips/openssl/v2"
538
383
+ )
539
384
+
540
385
+ // Enabled controls whether FIPS crypto is enabled.
541
- + var Enabled = openssl.Enabled
386
+ + var enabled bool
387
+ +
388
+ + func init() {
389
+ + enabled = openssl.FIPS()
390
+ + }
391
+ +
392
+ + func Enabled() bool {
393
+ + return enabled
394
+ + }
542
395
+
543
396
+ // Unreachable marks code that should be unreachable
544
397
+ // when OpenSSLCrypto is in use. It panics only when
@@ -549,6 +402,13 @@ index 0000000000..2087c555a4
549
402
+ }
550
403
+ }
551
404
+
405
+ + // ExecutingTest returns a boolean indicating if we're
406
+ + // executing under a test binary or not.
407
+ + func ExecutingTest() bool {
408
+ + name := os.Args[0]
409
+ + return hasSuffix(name, "_test") || hasSuffix(name, ".test")
410
+ + }
411
+ +
552
412
+ // Provided by runtime.crypto_backend_runtime_arg0 to avoid os import.
553
413
+ func runtime_arg0() string
554
414
+
@@ -567,7 +427,7 @@ index 0000000000..2087c555a4
567
427
+ }
568
428
+ }
569
429
+
570
- + var ExecutingTest = openssl.ExecutingTest
430
+ +
571
431
+
572
432
+ const RandReader = openssl.RandReader
573
433
+
@@ -627,6 +487,27 @@ index 0000000000..2087c555a4
627
487
+ var ExtractHKDF = openssl.ExtractHKDF
628
488
+ var ExpandHKDF = openssl.ExpandHKDF
629
489
+ var SupportsHKDF = openssl.SupportsHKDF
490
+ diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
491
+ new file mode 100644
492
+ index 0000000000..7fac1ec7e1
493
+ --- /dev/null
494
+ +++ b/src/crypto/internal/backend/bbig/big.go
495
+ @@ -0,0 +1,15 @@
496
+ + // Copyright 2022 The Go Authors. All rights reserved.
497
+ + // Use of this source code is governed by a BSD-style
498
+ + // license that can be found in the LICENSE file.
499
+ +
500
+ + // This is a mirror of
501
+ + // https://github.com/golang/go/blob/36b87f273cc43e21685179dc1664ebb5493d26ae/src/crypto/internal/boring/bbig/big.go.
502
+ +
503
+ + package bbig
504
+ +
505
+ + import (
506
+ + "github.com/golang-fips/openssl/v2/bbig"
507
+ + )
508
+ +
509
+ + var Enc = bbig.Enc
510
+ + var Dec = bbig.Dec
630
511
diff --git a/src/crypto/rsa/pkcs1v15_test.go b/src/crypto/rsa/pkcs1v15_test.go
631
512
index dfa1eddc88..39a4fc184a 100644
632
513
--- a/src/crypto/rsa/pkcs1v15_test.go
@@ -862,7 +743,7 @@ index 63bc8dad1a..ab56ccd1ed 100644
862
743
return nil, err
863
744
}
864
745
- return boring.EncryptRSAOAEP(hash, hash, bkey, msg, label)
865
- + return boring.EncryptRSAOAEP(hash, bkey, msg, label)
746
+ + return boring.EncryptRSAOAEP(hash, hash, bkey, msg, label)
866
747
}
867
748
boring.UnreachableExceptTests()
868
749
@@ -871,7 +752,7 @@ index 63bc8dad1a..ab56ccd1ed 100644
871
752
return nil, err
872
753
}
873
754
- out, err := boring.DecryptRSAOAEP(hash, mgfHash, bkey, ciphertext, label)
874
- + out, err := boring.DecryptRSAOAEP(hash, bkey, ciphertext, label)
755
+ + out, err := boring.DecryptRSAOAEP(hash, mgfHash, bkey, ciphertext, label)
875
756
if err != nil {
876
757
return nil, ErrDecryption
877
758
}
@@ -1577,7 +1458,7 @@ index 08452c7b1d..0732db0662 100644
1577
1458
+ fmt, crypto/cipher,
1578
1459
crypto/internal/boring/bcache
1579
1460
< crypto/internal/boring
1580
- + < github.com/golang-fips/openssl-fips/openssl
1461
+ + < github.com/golang-fips/openssl/v2
1581
1462
+ < crypto/internal/backend
1582
1463
< crypto/boring;
1583
1464
@@ -1591,7 +1472,7 @@ index 08452c7b1d..0732db0662 100644
1591
1472
1592
1473
# CRYPTO-MATH is core bignum-based crypto - no cgo, net; fmt now ok.
1593
1474
CRYPTO, FMT, math/big
1594
- + < github.com/golang-fips/openssl-fips/openssl /bbig
1475
+ + < github.com/golang-fips/openssl/v2 /bbig
1595
1476
< crypto/internal/boring/bbig
1596
1477
+ < crypto/internal/backend/bbig
1597
1478
< crypto/rand
@@ -1601,7 +1482,7 @@ index 08452c7b1d..0732db0662 100644
1601
1482
}
1602
1483
1603
1484
func TestDependencies(t *testing.T) {
1604
- + t.Skip("openssl-fips based toolchain has different dependencies than upstream")
1485
+ + t.Skip("openssl based toolchain has different dependencies than upstream")
1605
1486
if !testenv.HasSrc() {
1606
1487
// Tests run in a limited file system and we do not
1607
1488
// provide access to every source file.
@@ -1619,7 +1500,7 @@ index 08452c7b1d..0732db0662 100644
1619
1500
var imports []string
1620
1501
var haveImport = map[string]bool{}
1621
1502
- if pkg == "crypto/internal/boring" {
1622
- + if pkg == "crypto/internal/boring" || pkg == "github.com/golang-fips/openssl-fips/openssl " {
1503
+ + if pkg == "crypto/internal/boring" || pkg == "github.com/golang-fips/openssl/v2 " {
1623
1504
haveImport["C"] = true // kludge: prevent C from appearing in crypto/internal/boring imports
1624
1505
}
1625
1506
fset := token.NewFileSet()
0 commit comments