Skip to content

Commit dfcb16b

Browse files
authored
config: update openssl backend (#201)
Co-authored-by: Derek Parker <[email protected]>
1 parent 0cce198 commit dfcb16b

File tree

2 files changed

+43
-56
lines changed

2 files changed

+43
-56
lines changed

config/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"github.com/golang-fips/go": "main",
3-
"github.com/golang-fips/openssl": "85d31d0d257ce842c8a1e63c4d230ae850348136",
3+
"github.com/golang-fips/openssl": "61a53ab338d5f1657c6fe5d856d24528bfdd731d",
44
"github.com/golang/go": "go1.22.3"
55
}

patches/001-initial-openssl-for-fips.patch

+42-55
Original file line numberDiff line numberDiff line change
@@ -3719,24 +3719,24 @@ index 3c592e1136..a594823783 100644
37193719
} else {
37203720
testCurve = elliptic.P384()
37213721
diff --git a/src/go.mod b/src/go.mod
3722-
index 737d78da5d..eafc127352 100644
3722+
index 737d78da5d..a1610087fe 100644
37233723
--- a/src/go.mod
37243724
+++ b/src/go.mod
37253725
@@ -3,6 +3,7 @@ module std
37263726
go 1.22
37273727

37283728
require (
3729-
+ github.com/golang-fips/openssl/v2 v2.0.1
3729+
+ github.com/golang-fips/openssl/v2 v2.0.3
37303730
golang.org/x/crypto v0.16.1-0.20231129163542-152cdb1503eb
37313731
golang.org/x/net v0.19.1-0.20240412193750-db050b07227e
37323732
)
37333733
diff --git a/src/go.sum b/src/go.sum
3734-
index 86d173c9e6..51fbaeecdf 100644
3734+
index 86d173c9e6..c7def15f16 100644
37353735
--- a/src/go.sum
37363736
+++ b/src/go.sum
37373737
@@ -1,3 +1,5 @@
3738-
+github.com/golang-fips/openssl/v2 v2.0.1 h1:oNIu7tARUHmSIY7Gqn5lbSCnHSduvkFJoM2FRq294lA=
3739-
+github.com/golang-fips/openssl/v2 v2.0.1/go.mod h1:7tuBqX2Zov8Yq5mJ2yzlKhpnxOnWyEzi38AzeWRuQdg=
3738+
+github.com/golang-fips/openssl/v2 v2.0.3 h1:9+J2R0BQio6Jz8+dPZf/0ylISByl0gZWjTEKm+J+y7Y=
3739+
+github.com/golang-fips/openssl/v2 v2.0.3/go.mod h1:7tuBqX2Zov8Yq5mJ2yzlKhpnxOnWyEzi38AzeWRuQdg=
37403740
golang.org/x/crypto v0.16.1-0.20231129163542-152cdb1503eb h1:1ceSY7sk6sJuiDREHpfyrqDnDljsLfEP2GuTClhBBfI=
37413741
golang.org/x/crypto v0.16.1-0.20231129163542-152cdb1503eb/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
37423742
golang.org/x/net v0.19.1-0.20240412193750-db050b07227e h1:oDnvqaqHo3ho8OChMtkQbQAyp9eqnm3J7JRtt0+Cabc=
@@ -3784,7 +3784,7 @@ index 0000000000..97e8515401
37843784
\ No newline at end of file
37853785
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/README.md b/src/vendor/github.com/golang-fips/openssl/v2/README.md
37863786
new file mode 100644
3787-
index 0000000000..ba6289ecff
3787+
index 0000000000..1bfbaf60f4
37883788
--- /dev/null
37893789
+++ b/src/vendor/github.com/golang-fips/openssl/v2/README.md
37903790
@@ -0,0 +1,66 @@
@@ -3816,7 +3816,7 @@ index 0000000000..ba6289ecff
38163816
+
38173817
+### Multiple OpenSSL versions supported
38183818
+
3819-
+The `openssl` package has support for multiple OpenSSL versions, namely 1.0.2, 1.1.0, 1.1.1 and 3.0.x.
3819+
+The `openssl` package has support for multiple OpenSSL versions, namely 1.0.2, 1.1.0, 1.1.1 and 3.x.
38203820
+
38213821
+All supported OpenSSL versions pass a small set of automatic tests that ensure they can be built and that there are no major regressions.
38223822
+These tests do not validate the cryptographic correctness of the `openssl` package.
@@ -4022,16 +4022,17 @@ index 0000000000..6461f241f8
40224022
+type BigInt []uint
40234023
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/cipher.go b/src/vendor/github.com/golang-fips/openssl/v2/cipher.go
40244024
new file mode 100644
4025-
index 0000000000..2b983c5411
4025+
index 0000000000..72f7aebfc1
40264026
--- /dev/null
40274027
+++ b/src/vendor/github.com/golang-fips/openssl/v2/cipher.go
4028-
@@ -0,0 +1,582 @@
4028+
@@ -0,0 +1,569 @@
40294029
+//go:build !cmd_go_bootstrap
40304030
+
40314031
+package openssl
40324032
+
40334033
+// #include "goopenssl.h"
40344034
+import "C"
4035+
+
40354036
+import (
40364037
+ "crypto/cipher"
40374038
+ "encoding/binary"
@@ -4173,8 +4174,6 @@ index 0000000000..2b983c5411
41734174
+
41744175
+type evpCipher struct {
41754176
+ key []byte
4176-
+ enc_ctx C.GO_EVP_CIPHER_CTX_PTR
4177-
+ dec_ctx C.GO_EVP_CIPHER_CTX_PTR
41784177
+ kind cipherKind
41794178
+ blockSize int
41804179
+}
@@ -4187,19 +4186,9 @@ index 0000000000..2b983c5411
41874186
+ c := &evpCipher{key: make([]byte, len(key)), kind: kind}
41884187
+ copy(c.key, key)
41894188
+ c.blockSize = int(C.go_openssl_EVP_CIPHER_get_block_size(cipher))
4190-
+ runtime.SetFinalizer(c, (*evpCipher).finalize)
41914189
+ return c, nil
41924190
+}
41934191
+
4194-
+func (c *evpCipher) finalize() {
4195-
+ if c.enc_ctx != nil {
4196-
+ C.go_openssl_EVP_CIPHER_CTX_free(c.enc_ctx)
4197-
+ }
4198-
+ if c.dec_ctx != nil {
4199-
+ C.go_openssl_EVP_CIPHER_CTX_free(c.dec_ctx)
4200-
+ }
4201-
+}
4202-
+
42034192
+func (c *evpCipher) encrypt(dst, src []byte) error {
42044193
+ if len(src) < c.blockSize {
42054194
+ return errors.New("input not full block")
@@ -4212,15 +4201,13 @@ index 0000000000..2b983c5411
42124201
+ if inexactOverlap(dst[:c.blockSize], src[:c.blockSize]) {
42134202
+ return errors.New("invalid buffer overlap")
42144203
+ }
4215-
+ if c.enc_ctx == nil {
4216-
+ var err error
4217-
+ c.enc_ctx, err = newCipherCtx(c.kind, cipherModeECB, cipherOpEncrypt, c.key, nil)
4218-
+ if err != nil {
4219-
+ return err
4220-
+ }
4204+
+ enc_ctx, err := newCipherCtx(c.kind, cipherModeECB, cipherOpEncrypt, c.key, nil)
4205+
+ if err != nil {
4206+
+ return err
42214207
+ }
4208+
+ defer C.go_openssl_EVP_CIPHER_CTX_free(enc_ctx)
42224209
+
4223-
+ if C.go_openssl_EVP_EncryptUpdate_wrapper(c.enc_ctx, base(dst), base(src), C.int(c.blockSize)) != 1 {
4210+
+ if C.go_openssl_EVP_EncryptUpdate_wrapper(enc_ctx, base(dst), base(src), C.int(c.blockSize)) != 1 {
42244211
+ return errors.New("EncryptUpdate failed")
42254212
+ }
42264213
+ runtime.KeepAlive(c)
@@ -4239,18 +4226,17 @@ index 0000000000..2b983c5411
42394226
+ if inexactOverlap(dst[:c.blockSize], src[:c.blockSize]) {
42404227
+ return errors.New("invalid buffer overlap")
42414228
+ }
4242-
+ if c.dec_ctx == nil {
4243-
+ var err error
4244-
+ c.dec_ctx, err = newCipherCtx(c.kind, cipherModeECB, cipherOpDecrypt, c.key, nil)
4245-
+ if err != nil {
4246-
+ return err
4247-
+ }
4248-
+ if C.go_openssl_EVP_CIPHER_CTX_set_padding(c.dec_ctx, 0) != 1 {
4249-
+ return errors.New("could not disable cipher padding")
4250-
+ }
4229+
+ dec_ctx, err := newCipherCtx(c.kind, cipherModeECB, cipherOpDecrypt, c.key, nil)
4230+
+ if err != nil {
4231+
+ return err
4232+
+ }
4233+
+ defer C.go_openssl_EVP_CIPHER_CTX_free(dec_ctx)
4234+
+
4235+
+ if C.go_openssl_EVP_CIPHER_CTX_set_padding(dec_ctx, 0) != 1 {
4236+
+ return errors.New("could not disable cipher padding")
42514237
+ }
42524238
+
4253-
+ C.go_openssl_EVP_DecryptUpdate_wrapper(c.dec_ctx, base(dst), base(src), C.int(c.blockSize))
4239+
+ C.go_openssl_EVP_DecryptUpdate_wrapper(dec_ctx, base(dst), base(src), C.int(c.blockSize))
42544240
+ runtime.KeepAlive(c)
42554241
+ return nil
42564242
+}
@@ -4349,7 +4335,7 @@ index 0000000000..2b983c5411
43494335
+)
43504336
+
43514337
+type cipherGCM struct {
4352-
+ ctx C.GO_EVP_CIPHER_CTX_PTR
4338+
+ c *evpCipher
43534339
+ tls cipherGCMTLS
43544340
+ // minNextNonce is the minimum value that the next nonce can be, enforced by
43554341
+ // all TLS modes.
@@ -4407,19 +4393,10 @@ index 0000000000..2b983c5411
44074393
+}
44084394
+
44094395
+func (c *evpCipher) newGCM(tls cipherGCMTLS) (cipher.AEAD, error) {
4410-
+ ctx, err := newCipherCtx(c.kind, cipherModeGCM, cipherOpNone, c.key, nil)
4411-
+ if err != nil {
4412-
+ return nil, err
4413-
+ }
4414-
+ g := &cipherGCM{ctx: ctx, tls: tls, blockSize: c.blockSize}
4415-
+ runtime.SetFinalizer(g, (*cipherGCM).finalize)
4396+
+ g := &cipherGCM{c: c, tls: tls, blockSize: c.blockSize}
44164397
+ return g, nil
44174398
+}
44184399
+
4419-
+func (g *cipherGCM) finalize() {
4420-
+ C.go_openssl_EVP_CIPHER_CTX_free(g.ctx)
4421-
+}
4422-
+
44234400
+func (g *cipherGCM) NonceSize() int {
44244401
+ return gcmStandardNonceSize
44254402
+}
@@ -4492,14 +4469,19 @@ index 0000000000..2b983c5411
44924469
+ panic("cipher: invalid buffer overlap")
44934470
+ }
44944471
+
4472+
+ ctx, err := newCipherCtx(g.c.kind, cipherModeGCM, cipherOpNone, g.c.key, nil)
4473+
+ if err != nil {
4474+
+ panic(err)
4475+
+ }
4476+
+ defer C.go_openssl_EVP_CIPHER_CTX_free(ctx)
44954477
+ // Encrypt additional data.
44964478
+ // When sealing a TLS payload, OpenSSL app sets the additional data using
44974479
+ // 'EVP_CIPHER_CTX_ctrl(g.ctx, C.EVP_CTRL_AEAD_TLS1_AAD, C.EVP_AEAD_TLS1_AAD_LEN, base(additionalData))'.
44984480
+ // This makes the explicit nonce component to monotonically increase on every Seal operation without
44994481
+ // relying in the explicit nonce being securely set externally,
45004482
+ // and it also gives some interesting speed gains.
45014483
+ // Unfortunately we can't use it because Go expects AEAD.Seal to honor the provided nonce.
4502-
+ if C.go_openssl_EVP_CIPHER_CTX_seal_wrapper(g.ctx, base(out), base(nonce),
4484+
+ if C.go_openssl_EVP_CIPHER_CTX_seal_wrapper(ctx, base(out), base(nonce),
45034485
+ base(plaintext), C.int(len(plaintext)),
45044486
+ base(additionalData), C.int(len(additionalData))) != 1 {
45054487
+
@@ -4534,8 +4516,13 @@ index 0000000000..2b983c5411
45344516
+ panic("cipher: invalid buffer overlap")
45354517
+ }
45364518
+
4519+
+ ctx, err := newCipherCtx(g.c.kind, cipherModeGCM, cipherOpNone, g.c.key, nil)
4520+
+ if err != nil {
4521+
+ return nil, err
4522+
+ }
4523+
+ defer C.go_openssl_EVP_CIPHER_CTX_free(ctx)
45374524
+ ok := C.go_openssl_EVP_CIPHER_CTX_open_wrapper(
4538-
+ g.ctx, base(out), base(nonce),
4525+
+ ctx, base(out), base(nonce),
45394526
+ base(ciphertext), C.int(len(ciphertext)),
45404527
+ base(additionalData), C.int(len(additionalData)), base(tag))
45414528
+ runtime.KeepAlive(g)
@@ -7826,15 +7813,15 @@ index 0000000000..a14663298b
78267813
+}
78277814
diff --git a/src/vendor/github.com/golang-fips/openssl/v2/init_unix.go b/src/vendor/github.com/golang-fips/openssl/v2/init_unix.go
78287815
new file mode 100644
7829-
index 0000000000..dbf5ac448f
7816+
index 0000000000..5c09da86ee
78307817
--- /dev/null
78317818
+++ b/src/vendor/github.com/golang-fips/openssl/v2/init_unix.go
78327819
@@ -0,0 +1,31 @@
78337820
+//go:build unix && !cmd_go_bootstrap
78347821
+
78357822
+package openssl
78367823
+
7837-
+// #cgo LDFLAGS: -ldl
7824+
+// #cgo LDFLAGS: -ldl -pthread
78387825
+// #include <stdlib.h>
78397826
+// #include <dlfcn.h>
78407827
+import "C"
@@ -9688,11 +9675,11 @@ index 0000000000..5de62f95a7
96889675
+ return nil
96899676
+}
96909677
diff --git a/src/vendor/modules.txt b/src/vendor/modules.txt
9691-
index 9a234e59b1..f65e24f457 100644
9678+
index 9a234e59b1..a2dc68599f 100644
96929679
--- a/src/vendor/modules.txt
96939680
+++ b/src/vendor/modules.txt
96949681
@@ -1,3 +1,7 @@
9695-
+# github.com/golang-fips/openssl/v2 v2.0.1
9682+
+# github.com/golang-fips/openssl/v2 v2.0.3
96969683
+## explicit; go 1.20
96979684
+github.com/golang-fips/openssl/v2
96989685
+github.com/golang-fips/openssl/v2/bbig

0 commit comments

Comments
 (0)