Skip to content

Commit 6460860

Browse files
authored
Implement crypto/hkdf with the OpenSSL/CNG backends (#1449)
1 parent f331d62 commit 6460860

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

Diff for: patches/0002-Add-crypto-backend-foundation.patch

+48-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Subject: [PATCH] Add crypto backend foundation
2323
src/crypto/ed25519/boring.go | 71 ++++++
2424
src/crypto/ed25519/ed25519.go | 73 ++++++
2525
src/crypto/ed25519/notboring.go | 16 ++
26+
src/crypto/hkdf/hkdf.go | 14 ++
2627
src/crypto/hkdf/hkdf_test.go | 2 +-
2728
src/crypto/hmac/hmac.go | 2 +-
2829
src/crypto/hmac/hmac_test.go | 2 +-
@@ -74,7 +75,7 @@ Subject: [PATCH] Add crypto backend foundation
7475
src/hash/notboring_test.go | 9 +
7576
src/net/smtp/smtp_test.go | 72 ++++--
7677
src/runtime/runtime_boring.go | 5 +
77-
70 files changed, 1145 insertions(+), 80 deletions(-)
78+
71 files changed, 1159 insertions(+), 80 deletions(-)
7879
create mode 100644 src/crypto/dsa/boring.go
7980
create mode 100644 src/crypto/dsa/notboring.go
8081
create mode 100644 src/crypto/ed25519/boring.go
@@ -811,6 +812,52 @@ index 00000000000000..b0cdd44d81c753
811812
+func boringPrivateKey(PrivateKey) (*boring.PrivateKeyEd25519, error) {
812813
+ panic("boringcrypto: not available")
813814
+}
815+
diff --git a/src/crypto/hkdf/hkdf.go b/src/crypto/hkdf/hkdf.go
816+
index 7cfbe2c60de356..78139ed6170da5 100644
817+
--- a/src/crypto/hkdf/hkdf.go
818+
+++ b/src/crypto/hkdf/hkdf.go
819+
@@ -11,6 +11,7 @@
820+
package hkdf
821+
822+
import (
823+
+ boring "crypto/internal/backend"
824+
"crypto/internal/fips140/hkdf"
825+
"crypto/internal/fips140only"
826+
"errors"
827+
@@ -27,6 +28,9 @@ func Extract[H hash.Hash](h func() H, secret, salt []byte) ([]byte, error) {
828+
if err := checkFIPS140Only(h, secret); err != nil {
829+
return nil, err
830+
}
831+
+ if boring.Enabled && boring.SupportsHKDF() {
832+
+ return boring.ExtractHKDF(func() hash.Hash { return h() }, secret, salt)
833+
+ }
834+
return hkdf.Extract(h, secret, salt), nil
835+
}
836+
837+
@@ -47,6 +51,9 @@ func Expand[H hash.Hash](h func() H, pseudorandomKey []byte, info string, keyLen
838+
return nil, errors.New("hkdf: requested key length too large")
839+
}
840+
841+
+ if boring.Enabled && boring.SupportsHKDF() {
842+
+ return boring.ExpandHKDF(func() hash.Hash { return h() }, pseudorandomKey, []byte(info), keyLength)
843+
+ }
844+
return hkdf.Expand(h, pseudorandomKey, info, keyLength), nil
845+
}
846+
847+
@@ -63,6 +70,13 @@ func Key[Hash hash.Hash](h func() Hash, secret, salt []byte, info string, keyLen
848+
return nil, errors.New("hkdf: requested key length too large")
849+
}
850+
851+
+ if boring.Enabled && boring.SupportsHKDF() {
852+
+ pseudorandomKey, err := boring.ExtractHKDF(func() hash.Hash { return h() }, secret, salt)
853+
+ if err != nil {
854+
+ return nil, err
855+
+ }
856+
+ return boring.ExpandHKDF(func() hash.Hash { return h() }, pseudorandomKey, []byte(info), keyLength)
857+
+ }
858+
return hkdf.Key(h, secret, salt, info, keyLength), nil
859+
}
860+
814861
diff --git a/src/crypto/hkdf/hkdf_test.go b/src/crypto/hkdf/hkdf_test.go
815862
index 201b440289bb2d..4ed4960ff35b66 100644
816863
--- a/src/crypto/hkdf/hkdf_test.go

0 commit comments

Comments
 (0)