Migrate io/ioutil uses to new APIs.

ioutil has been deprecated since Go 1.16. The functions were moved to
some combination of io and os. See https://pkg.go.dev/io/ioutil.

(File-related functions went to os. Generic things went to io. Names
were kept the same except TempDir and TempFile are os.MkdirTemp and
os.CreateTemp, respectively.)

Change-Id: I031306f69e70424841df08f64fa9d90f31780928
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55186
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
diff --git a/crypto/fipsmodule/bn/bn_test_to_fuzzer.go b/crypto/fipsmodule/bn/bn_test_to_fuzzer.go
index d1ee734..13cff26 100644
--- a/crypto/fipsmodule/bn/bn_test_to_fuzzer.go
+++ b/crypto/fipsmodule/bn/bn_test_to_fuzzer.go
@@ -21,7 +21,6 @@
 	"errors"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"math/big"
 	"os"
 	"path/filepath"
@@ -221,8 +220,8 @@
 
 		if len(fuzzer) != 0 {
 			hash := sha1.Sum(b)
-			path := filepath.Join(fuzzerDir, fuzzer + "_corpus", hex.EncodeToString(hash[:]))
-			if err := ioutil.WriteFile(path, b, 0666); err != nil {
+			path := filepath.Join(fuzzerDir, fuzzer+"_corpus", hex.EncodeToString(hash[:]))
+			if err := os.WriteFile(path, b, 0666); err != nil {
 				fmt.Fprintf(os.Stderr, "Error writing to %s: %s.\n", path, err)
 				os.Exit(1)
 			}
diff --git a/crypto/obj/objects.go b/crypto/obj/objects.go
index 361cdfe..1b9ded3 100644
--- a/crypto/obj/objects.go
+++ b/crypto/obj/objects.go
@@ -19,7 +19,6 @@
 	"bytes"
 	"errors"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"sort"
@@ -518,7 +517,7 @@
 		return err
 	}
 
-	return ioutil.WriteFile(path, []byte(formatted), 0666)
+	return os.WriteFile(path, []byte(formatted), 0666)
 }
 
 // TODO(davidben): Replace this with sort.Slice once Go 1.8 is sufficiently
@@ -710,7 +709,7 @@
 		return err
 	}
 
-	return ioutil.WriteFile(path, []byte(formatted), 0666)
+	return os.WriteFile(path, []byte(formatted), 0666)
 }
 
 func main() {
diff --git a/crypto/x509/test/make_basic_constraints.go b/crypto/x509/test/make_basic_constraints.go
index 23158b5..6524799 100644
--- a/crypto/x509/test/make_basic_constraints.go
+++ b/crypto/x509/test/make_basic_constraints.go
@@ -23,8 +23,8 @@
 	"crypto/x509/pkix"
 	"encoding/pem"
 	"fmt"
-	"io/ioutil"
 	"math/big"
+	"os"
 	"time"
 )
 
@@ -75,7 +75,7 @@
 		}
 
 		certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes})
-		if err := ioutil.WriteFile(fmt.Sprintf("basic_constraints_%s.pem", cert.name), certPEM, 0666); err != nil {
+		if err := os.WriteFile(fmt.Sprintf("basic_constraints_%s.pem", cert.name), certPEM, 0666); err != nil {
 			panic(err)
 		}
 	}
diff --git a/ssl/test/runner/hpke/hpke_test.go b/ssl/test/runner/hpke/hpke_test.go
index eec16e9..35503be 100644
--- a/ssl/test/runner/hpke/hpke_test.go
+++ b/ssl/test/runner/hpke/hpke_test.go
@@ -23,7 +23,7 @@
 	"errors"
 	"flag"
 	"fmt"
-	"io/ioutil"
+	"os"
 	"path/filepath"
 	"testing"
 )
@@ -98,7 +98,7 @@
 
 // TestVectors checks all relevant test vectors in test-vectors.json.
 func TestVectors(t *testing.T) {
-	jsonStr, err := ioutil.ReadFile(filepath.Join(*testDataDir, "test-vectors.json"))
+	jsonStr, err := os.ReadFile(filepath.Join(*testDataDir, "test-vectors.json"))
 	if err != nil {
 		t.Errorf("error reading test vectors: %s", err)
 		return
diff --git a/ssl/test/runner/runner.go b/ssl/test/runner/runner.go
index 5c6ef4f..8c756a6 100644
--- a/ssl/test/runner/runner.go
+++ b/ssl/test/runner/runner.go
@@ -32,7 +32,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"math/big"
 	"net"
 	"os"
@@ -234,7 +233,7 @@
 		*testCerts[i].cert = cert
 	}
 
-	channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
+	channelIDPEMBlock, err := os.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
 	if err != nil {
 		panic(err)
 	}
@@ -294,7 +293,7 @@
 
 func loadRSAPrivateKey(filename string) (priv *rsa.PrivateKey, privPKCS8 []byte, err error) {
 	pemPath := path.Join(*resourceDir, filename)
-	pemBytes, err := ioutil.ReadFile(pemPath)
+	pemBytes, err := os.ReadFile(pemPath)
 	if err != nil {
 		return nil, nil, err
 	}
@@ -712,7 +711,7 @@
 		return nil
 	}
 
-	settings, err := ioutil.ReadFile(path)
+	settings, err := os.ReadFile(path)
 	if err != nil {
 		if !os.IsNotExist(err) {
 			return err
@@ -723,7 +722,7 @@
 	}
 
 	settings = append(settings, data...)
-	return ioutil.WriteFile(path, settings, 0644)
+	return os.WriteFile(path, settings, 0644)
 }
 
 // A timeoutConn implements an idle timeout on each Read and Write operation.
@@ -822,7 +821,7 @@
 				bb := newByteBuilder()
 				bb.addU24LengthPrefixed().addBytes(encodedInner)
 				bb.addBytes(outer)
-				return ioutil.WriteFile(filepath.Join(dir, name), bb.finish(), 0644)
+				return os.WriteFile(filepath.Join(dir, name), bb.finish(), 0644)
 			}
 		}
 
@@ -1091,7 +1090,7 @@
 			return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
 		}
 		// Read until EOF.
-		_, err := io.Copy(ioutil.Discard, tlsConn)
+		_, err := io.Copy(io.Discard, tlsConn)
 		return err
 	}
 	if messageLen == 0 {
@@ -16389,7 +16388,7 @@
 
 func addDelegatedCredentialTests() {
 	certPath := path.Join(*resourceDir, rsaCertificateFile)
-	pemBytes, err := ioutil.ReadFile(certPath)
+	pemBytes, err := os.ReadFile(certPath)
 	if err != nil {
 		panic(err)
 	}
@@ -19553,7 +19552,7 @@
 	initCertificates()
 
 	if len(*shimConfigFile) != 0 {
-		encoded, err := ioutil.ReadFile(*shimConfigFile)
+		encoded, err := os.ReadFile(*shimConfigFile)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
 			os.Exit(1)
diff --git a/ssl/test/runner/sharding.go b/ssl/test/runner/sharding.go
index 5061a6f..b10973a 100644
--- a/ssl/test/runner/sharding.go
+++ b/ssl/test/runner/sharding.go
@@ -16,7 +16,6 @@
 
 import (
 	"fmt"
-	"io/ioutil"
 	"os"
 	"strconv"
 )
@@ -68,7 +67,7 @@
 	}
 
 	if len(statusFile) > 0 {
-		if err := ioutil.WriteFile(statusFile, nil, 0664); err != nil {
+		if err := os.WriteFile(statusFile, nil, 0664); err != nil {
 			return 0, 0, err
 		}
 	}
diff --git a/ssl/test/runner/tls.go b/ssl/test/runner/tls.go
index af3fa3a..6e57d18 100644
--- a/ssl/test/runner/tls.go
+++ b/ssl/test/runner/tls.go
@@ -14,8 +14,8 @@
 	"crypto/x509"
 	"encoding/pem"
 	"errors"
-	"io/ioutil"
 	"net"
+	"os"
 	"strings"
 	"time"
 )
@@ -174,11 +174,11 @@
 // LoadX509KeyPair reads and parses a public/private key pair from a pair of
 // files. The files must contain PEM encoded data.
 func LoadX509KeyPair(certFile, keyFile string) (cert Certificate, err error) {
-	certPEMBlock, err := ioutil.ReadFile(certFile)
+	certPEMBlock, err := os.ReadFile(certFile)
 	if err != nil {
 		return
 	}
-	keyPEMBlock, err := ioutil.ReadFile(keyFile)
+	keyPEMBlock, err := os.ReadFile(keyFile)
 	if err != nil {
 		return
 	}
diff --git a/util/ar/ar_test.go b/util/ar/ar_test.go
index ef37d79..fac0e26 100644
--- a/util/ar/ar_test.go
+++ b/util/ar/ar_test.go
@@ -17,7 +17,6 @@
 import (
 	"bytes"
 	"flag"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 	"testing"
@@ -52,7 +51,7 @@
 		"linux",
 		"libsample.a",
 		map[string]string{
-			"foo.c.o": "foo.c.o",
+			"foo.c.o":  "foo.c.o",
 			"bar.cc.o": "bar.cc.o",
 		},
 		false,
@@ -61,7 +60,7 @@
 		"mac",
 		"libsample.a",
 		map[string]string{
-			"foo.c.o": "foo.c.o",
+			"foo.c.o":  "foo.c.o",
 			"bar.cc.o": "bar.cc.o",
 		},
 		true,
@@ -70,7 +69,7 @@
 		"windows",
 		"sample.lib",
 		map[string]string{
-			"CMakeFiles\\sample.dir\\foo.c.obj": "foo.c.obj",
+			"CMakeFiles\\sample.dir\\foo.c.obj":  "foo.c.obj",
 			"CMakeFiles\\sample.dir\\bar.cc.obj": "bar.cc.obj",
 		},
 		false,
@@ -92,7 +91,7 @@
 			}
 
 			for file, contentsPath := range test.out {
-				expected, err := ioutil.ReadFile(test.Path(contentsPath))
+				expected, err := os.ReadFile(test.Path(contentsPath))
 				if err != nil {
 					t.Fatalf("error reading %s: %s", contentsPath, err)
 				}
diff --git a/util/compare_benchmarks.go b/util/compare_benchmarks.go
index fd7fdfb..0c79d63 100644
--- a/util/compare_benchmarks.go
+++ b/util/compare_benchmarks.go
@@ -20,7 +20,6 @@
 	"encoding/json"
 	"flag"
 	"fmt"
-	"io/ioutil"
 	"os"
 )
 
@@ -63,7 +62,7 @@
 }
 
 func readResults(path string) ([]Result, error) {
-	data, err := ioutil.ReadFile(path)
+	data, err := os.ReadFile(path)
 	if err != nil {
 		return nil, err
 	}
diff --git a/util/convert_comments.go b/util/convert_comments.go
index afd070f..917f29c 100644
--- a/util/convert_comments.go
+++ b/util/convert_comments.go
@@ -17,7 +17,6 @@
 import (
 	"bytes"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"strings"
 )
@@ -270,11 +269,11 @@
 
 func main() {
 	for _, arg := range os.Args[1:] {
-		in, err := ioutil.ReadFile(arg)
+		in, err := os.ReadFile(arg)
 		if err != nil {
 			panic(err)
 		}
-		if err := ioutil.WriteFile(arg, convertComments(arg, in), 0666); err != nil {
+		if err := os.WriteFile(arg, convertComments(arg, in), 0666); err != nil {
 			panic(err)
 		}
 	}
diff --git a/util/convert_wycheproof.go b/util/convert_wycheproof.go
index 0e9f81b..f81771e 100644
--- a/util/convert_wycheproof.go
+++ b/util/convert_wycheproof.go
@@ -20,7 +20,6 @@
 	"encoding/json"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"sort"
 	"strings"
@@ -122,7 +121,7 @@
 }
 
 func convertWycheproof(f io.Writer, jsonPath string) error {
-	jsonData, err := ioutil.ReadFile(jsonPath)
+	jsonData, err := os.ReadFile(jsonPath)
 	if err != nil {
 		return err
 	}
diff --git a/util/doc.go b/util/doc.go
index 651998e..0460890 100644
--- a/util/doc.go
+++ b/util/doc.go
@@ -14,7 +14,6 @@
 	"flag"
 	"fmt"
 	"html/template"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 	"regexp"
@@ -746,11 +745,11 @@
 }
 
 func copyFile(outPath string, inFilePath string) error {
-	bytes, err := ioutil.ReadFile(inFilePath)
+	bytes, err := os.ReadFile(inFilePath)
 	if err != nil {
 		return err
 	}
-	return ioutil.WriteFile(filepath.Join(outPath, filepath.Base(inFilePath)), bytes, 0666)
+	return os.WriteFile(filepath.Join(outPath, filepath.Base(inFilePath)), bytes, 0666)
 }
 
 func main() {
@@ -772,7 +771,7 @@
 		os.Exit(1)
 	}
 
-	configBytes, err := ioutil.ReadFile(*configFlag)
+	configBytes, err := os.ReadFile(*configFlag)
 	if err != nil {
 		fmt.Printf("Failed to open config file: %s\n", err)
 		os.Exit(1)
diff --git a/util/embed_test_data.go b/util/embed_test_data.go
index 9fd7de1..266f296 100644
--- a/util/embed_test_data.go
+++ b/util/embed_test_data.go
@@ -20,7 +20,6 @@
 	"bytes"
 	"flag"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"strings"
 )
@@ -77,7 +76,7 @@
 
 	var files []string
 	if len(*fileList) != 0 {
-		data, err := ioutil.ReadFile(*fileList)
+		data, err := os.ReadFile(*fileList)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", *fileList, err)
 			os.Exit(1)
@@ -127,7 +126,7 @@
 	const chunkSize = 8192
 
 	for i, arg := range files {
-		data, err := ioutil.ReadFile(arg)
+		data, err := os.ReadFile(arg)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", arg, err)
 			os.Exit(1)
diff --git a/util/fetch_ech_config_list.go b/util/fetch_ech_config_list.go
index badaae2..8f09e66 100644
--- a/util/fetch_ech_config_list.go
+++ b/util/fetch_ech_config_list.go
@@ -18,7 +18,6 @@
 	"errors"
 	"flag"
 	"fmt"
-	"io/ioutil"
 	"log"
 	"net"
 	"os"
@@ -379,7 +378,7 @@
 		}
 
 		outFile := path.Join(*outDir, fmt.Sprintf("ech-config-list-%d", echConfigListCount))
-		if err = ioutil.WriteFile(outFile, record.ech, 0644); err != nil {
+		if err = os.WriteFile(outFile, record.ech, 0644); err != nil {
 			log.Printf("Failed to write file: %s\n", err)
 			os.Exit(1)
 		}
diff --git a/util/fipstools/acvp/acvptool/acvp.go b/util/fipstools/acvp/acvptool/acvp.go
index 033b7c7..723d29e 100644
--- a/util/fipstools/acvp/acvptool/acvp.go
+++ b/util/fipstools/acvp/acvptool/acvp.go
@@ -29,7 +29,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"log"
 	"net/http"
 	neturl "net/url"
@@ -157,7 +156,7 @@
 			continue
 		}
 		path := filepath.Join(cachePath, name)
-		contents, err := ioutil.ReadFile(path)
+		contents, err := os.ReadFile(path)
 		if err != nil {
 			return fmt.Errorf("Failed to read session token cache entry %q: %s", path, err)
 		}
@@ -199,7 +198,7 @@
 // processFile reads a file containing vector sets, at least in the format
 // preferred by our lab, and writes the results to stdout.
 func processFile(filename string, supportedAlgos []map[string]interface{}, middle Middle) error {
-	jsonBytes, err := ioutil.ReadFile(filename)
+	jsonBytes, err := os.ReadFile(filename)
 	if err != nil {
 		return err
 	}
@@ -386,7 +385,7 @@
 	if len(config.CertPEMFile) == 0 {
 		log.Fatal("Config file missing CertPEMFile")
 	}
-	certPEM, err := ioutil.ReadFile(config.CertPEMFile)
+	certPEM, err := os.ReadFile(config.CertPEMFile)
 	if err != nil {
 		log.Fatalf("failed to read certificate from %q: %s", config.CertPEMFile, err)
 	}
@@ -404,7 +403,7 @@
 		privateKeyFile = config.PrivateKeyFile
 	}
 
-	keyBytes, err := ioutil.ReadFile(privateKeyFile)
+	keyBytes, err := os.ReadFile(privateKeyFile)
 	if err != nil {
 		log.Fatalf("failed to read private key from %q: %s", privateKeyFile, err)
 	}
@@ -538,7 +537,7 @@
 	if token := result.AccessToken; len(token) > 0 {
 		server.PrefixTokens[url] = token
 		if len(sessionTokensCacheDir) > 0 {
-			ioutil.WriteFile(filepath.Join(sessionTokensCacheDir, neturl.PathEscape(url))+".token", []byte(token), 0600)
+			os.WriteFile(filepath.Join(sessionTokensCacheDir, neturl.PathEscape(url))+".token", []byte(token), 0600)
 		}
 	}
 
diff --git a/util/fipstools/acvp/acvptool/acvp/acvp.go b/util/fipstools/acvp/acvptool/acvp/acvp.go
index d70f98c..b5a01f0 100644
--- a/util/fipstools/acvp/acvptool/acvp/acvp.go
+++ b/util/fipstools/acvp/acvptool/acvp/acvp.go
@@ -23,7 +23,6 @@
 	"errors"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"net"
 	"net/http"
 	"net/url"
@@ -168,12 +167,12 @@
 		return nil, err
 	}
 
-	buf, err := ioutil.ReadAll(decoder.Buffered())
+	buf, err := io.ReadAll(decoder.Buffered())
 	if err != nil {
 		return nil, err
 	}
 
-	rest, err := ioutil.ReadAll(in)
+	rest, err := io.ReadAll(in)
 	if err != nil {
 		return nil, err
 	}
diff --git a/util/fipstools/acvp/acvptool/interactive.go b/util/fipstools/acvp/acvptool/interactive.go
index ee992f1..384206c 100644
--- a/util/fipstools/acvp/acvptool/interactive.go
+++ b/util/fipstools/acvp/acvptool/interactive.go
@@ -23,7 +23,6 @@
 	"errors"
 	"fmt"
 	"io"
-	"io/ioutil"
 	neturl "net/url"
 	"os"
 	"os/exec"
@@ -159,7 +158,7 @@
 						}
 						set.env.server.PrefixTokens[url] = token
 						if len(set.env.config.SessionTokensCache) > 0 {
-							ioutil.WriteFile(filepath.Join(set.env.config.SessionTokensCache, neturl.PathEscape(url))+".token", []byte(token), 0600)
+							os.WriteFile(filepath.Join(set.env.config.SessionTokensCache, neturl.PathEscape(url))+".token", []byte(token), 0600)
 						}
 					}
 				}
@@ -205,7 +204,7 @@
 }
 
 func edit(initialContents string) ([]byte, error) {
-	tmp, err := ioutil.TempFile("", "acvp*.json")
+	tmp, err := os.CreateTemp("", "acvp*.json")
 	if err != nil {
 		return nil, err
 	}
@@ -231,7 +230,7 @@
 		return nil, err
 	}
 
-	return ioutil.ReadFile(path)
+	return os.ReadFile(path)
 }
 
 func (obj ServerObject) Action(action string, args []string) error {
diff --git a/util/fipstools/acvp/acvptool/test/check_expected.go b/util/fipstools/acvp/acvptool/test/check_expected.go
index 8a12021..ccc8038 100644
--- a/util/fipstools/acvp/acvptool/test/check_expected.go
+++ b/util/fipstools/acvp/acvptool/test/check_expected.go
@@ -21,7 +21,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"log"
 	"os"
 	"os/exec"
@@ -138,7 +137,7 @@
 	}
 	defer input.Close()
 
-	tempFile, err := ioutil.TempFile("", "boringssl-check_expected-")
+	tempFile, err := os.CreateTemp("", "boringssl-check_expected-")
 	if err != nil {
 		return fmt.Errorf("Failed to create temp file: %s", err)
 	}
@@ -190,7 +189,7 @@
 }
 
 func writeUpdate(path string, contents []byte) {
-	if err := ioutil.WriteFile(path, contents, 0644); err != nil {
+	if err := os.WriteFile(path, contents, 0644); err != nil {
 		log.Printf("Failed to create missing file %q: %s", path, err)
 	} else {
 		log.Printf("Wrote %q", path)
diff --git a/util/fipstools/break-hash.go b/util/fipstools/break-hash.go
index 8c817d8..9893716 100644
--- a/util/fipstools/break-hash.go
+++ b/util/fipstools/break-hash.go
@@ -24,12 +24,11 @@
 	"encoding/hex"
 	"errors"
 	"fmt"
-	"io/ioutil"
 	"os"
 )
 
 func do(outPath, inPath string) error {
-	objectBytes, err := ioutil.ReadFile(inPath)
+	objectBytes, err := os.ReadFile(inPath)
 	if err != nil {
 		return err
 	}
@@ -131,7 +130,7 @@
 	fmt.Printf("\nHash of module was:          %x\n", hashWas)
 	fmt.Printf("Hash of corrupted module is: %x\n", newHash)
 
-	return ioutil.WriteFile(outPath, objectBytes, 0755)
+	return os.WriteFile(outPath, objectBytes, 0755)
 }
 
 func main() {
diff --git a/util/fipstools/break-kat.go b/util/fipstools/break-kat.go
index 621791d..6eace5b 100644
--- a/util/fipstools/break-kat.go
+++ b/util/fipstools/break-kat.go
@@ -8,7 +8,6 @@
 	"encoding/hex"
 	"flag"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"sort"
 )
@@ -63,7 +62,7 @@
 		panic("invalid kat data: " + err.Error())
 	}
 
-	binaryContents, err := ioutil.ReadFile(inPath)
+	binaryContents, err := os.ReadFile(inPath)
 	if err != nil {
 		fmt.Fprintln(os.Stderr, err)
 		os.Exit(2)
diff --git a/util/fipstools/delocate/delocate.go b/util/fipstools/delocate/delocate.go
index 84508aa..9c4df04 100644
--- a/util/fipstools/delocate/delocate.go
+++ b/util/fipstools/delocate/delocate.go
@@ -20,7 +20,6 @@
 	"errors"
 	"flag"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"sort"
 	"strconv"
@@ -1980,7 +1979,7 @@
 				contents = string(c)
 			}
 		} else {
-			inBytes, err := ioutil.ReadFile(input.path)
+			inBytes, err := os.ReadFile(input.path)
 			if err != nil {
 				return err
 			}
diff --git a/util/fipstools/delocate/delocate_test.go b/util/fipstools/delocate/delocate_test.go
index 43b3ff1..5176c3c 100644
--- a/util/fipstools/delocate/delocate_test.go
+++ b/util/fipstools/delocate/delocate_test.go
@@ -17,7 +17,7 @@
 import (
 	"bytes"
 	"flag"
-	"io/ioutil"
+	"os"
 	"path/filepath"
 	"testing"
 )
@@ -75,9 +75,9 @@
 			}
 
 			if *update {
-				ioutil.WriteFile(test.Path(test.out), buf.Bytes(), 0666)
+				os.WriteFile(test.Path(test.out), buf.Bytes(), 0666)
 			} else {
-				expected, err := ioutil.ReadFile(test.Path(test.out))
+				expected, err := os.ReadFile(test.Path(test.out))
 				if err != nil {
 					t.Fatalf("could not read %q: %s", test.Path(test.out), err)
 				}
diff --git a/util/fipstools/inject_hash/inject_hash.go b/util/fipstools/inject_hash/inject_hash.go
index 6f14982..3680cfd 100644
--- a/util/fipstools/inject_hash/inject_hash.go
+++ b/util/fipstools/inject_hash/inject_hash.go
@@ -27,7 +27,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"strings"
 
@@ -78,7 +77,7 @@
 		}
 		perm = fi.Mode()
 
-		if objectBytes, err = ioutil.ReadFile(oInput); err != nil {
+		if objectBytes, err = os.ReadFile(oInput); err != nil {
 			return err
 		}
 		isStatic = strings.HasSuffix(oInput, ".o")
@@ -245,7 +244,7 @@
 
 	copy(objectBytes[offset:], calculated)
 
-	return ioutil.WriteFile(outPath, objectBytes, perm & 0777)
+	return os.WriteFile(outPath, objectBytes, perm&0777)
 }
 
 func main() {
diff --git a/util/run_android_tests.go b/util/run_android_tests.go
index 5eae742..51b2017 100644
--- a/util/run_android_tests.go
+++ b/util/run_android_tests.go
@@ -21,7 +21,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -293,7 +292,7 @@
 	}
 
 	// Stage everything in a temporary directory.
-	tmpDir, err := ioutil.TempDir("", "boringssl-android")
+	tmpDir, err := os.MkdirTemp("", "boringssl-android")
 	if err != nil {
 		fmt.Printf("Error making temporary directory: %s\n", err)
 		os.Exit(1)