Replace crypto/rand with internal rand package

PiperOrigin-RevId: 200784607
Change-Id: I39aa6ee632936dcbb00fc298adccffa606e9f4c0
This commit is contained in:
Michael Pratt
2018-06-15 15:36:00 -07:00
committed by Shentubot
parent 437890dc4b
commit bd2d1aaa16
16 changed files with 67 additions and 10 deletions
+1
View File
@@ -11,6 +11,7 @@ go_library(
],
importpath = "gvisor.googlesource.com/gvisor/pkg/dhcp",
deps = [
"//pkg/rand",
"//pkg/tcpip",
"//pkg/tcpip/network/ipv4",
"//pkg/tcpip/stack",
+1 -1
View File
@@ -7,12 +7,12 @@ package dhcp
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"log"
"sync"
"time"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/tcpip"
"gvisor.googlesource.com/gvisor/pkg/tcpip/network/ipv4"
"gvisor.googlesource.com/gvisor/pkg/tcpip/stack"
+11
View File
@@ -0,0 +1,11 @@
package(licenses = ["notice"]) # Apache 2.0
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "rand",
srcs = ["rand.go"],
importpath = "gvisor.googlesource.com/gvisor/pkg/rand",
visibility = ["//:sandbox"],
deps = ["@org_golang_x_sys//unix:go_default_library"],
)
+39
View File
@@ -0,0 +1,39 @@
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package rand implements a cryptographically secure pseudorandom number
// generator.
package rand
import (
"io"
"golang.org/x/sys/unix"
)
// reader implements an io.Reader that returns pseudorandom bytes.
type reader struct{}
// Read implements io.Reader.Read.
func (reader) Read(p []byte) (int, error) {
return unix.Getrandom(p, 0)
}
// Reader is the default reader.
var Reader io.Reader = reader{}
// Read reads from the default reader.
func Read(b []byte) (int, error) {
return io.ReadFull(Reader, b)
}
+1
View File
@@ -33,6 +33,7 @@ go_library(
"//pkg/abi/linux",
"//pkg/amutex",
"//pkg/log",
"//pkg/rand",
"//pkg/sentry/context",
"//pkg/sentry/device",
"//pkg/sentry/fs",
+1 -2
View File
@@ -15,9 +15,8 @@
package dev
import (
"crypto/rand"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs/ramfs"
+1
View File
@@ -39,6 +39,7 @@ go_library(
"//pkg/binary",
"//pkg/cpuid",
"//pkg/log",
"//pkg/rand",
"//pkg/refs",
"//pkg/sentry/arch",
"//pkg/sentry/context",
+1 -1
View File
@@ -17,13 +17,13 @@ package loader
import (
"bytes"
"crypto/rand"
"io"
"path"
"gvisor.googlesource.com/gvisor/pkg/abi"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/cpuid"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/sentry/arch"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
+1
View File
@@ -70,6 +70,7 @@ go_library(
"//pkg/eventchannel",
"//pkg/log",
"//pkg/metric",
"//pkg/rand",
"//pkg/sentry/arch",
"//pkg/sentry/context",
"//pkg/sentry/fs",
+1 -1
View File
@@ -15,10 +15,10 @@
package linux
import (
"crypto/rand"
"io"
"math"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/sentry/arch"
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel"
"gvisor.googlesource.com/gvisor/pkg/sentry/safemem"
+4 -1
View File
@@ -7,5 +7,8 @@ go_library(
srcs = ["hash.go"],
importpath = "gvisor.googlesource.com/gvisor/pkg/tcpip/network/hash",
visibility = ["//visibility:public"],
deps = ["//pkg/tcpip/header"],
deps = [
"//pkg/rand",
"//pkg/tcpip/header",
],
)
+1 -1
View File
@@ -6,9 +6,9 @@
package hash
import (
"crypto/rand"
"encoding/binary"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/tcpip/header"
)
+1
View File
@@ -51,6 +51,7 @@ go_library(
importpath = "gvisor.googlesource.com/gvisor/pkg/tcpip/transport/tcp",
visibility = ["//visibility:public"],
deps = [
"//pkg/rand",
"//pkg/sleep",
"//pkg/state",
"//pkg/tcpip",
+1 -1
View File
@@ -5,7 +5,6 @@
package tcp
import (
"crypto/rand"
"crypto/sha1"
"encoding/binary"
"hash"
@@ -13,6 +12,7 @@ import (
"sync"
"time"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/sleep"
"gvisor.googlesource.com/gvisor/pkg/tcpip"
"gvisor.googlesource.com/gvisor/pkg/tcpip/header"
+1 -1
View File
@@ -5,11 +5,11 @@
package tcp
import (
"crypto/rand"
"sync"
"sync/atomic"
"time"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/sleep"
"gvisor.googlesource.com/gvisor/pkg/tcpip"
"gvisor.googlesource.com/gvisor/pkg/tcpip/buffer"
+1 -1
View File
@@ -5,12 +5,12 @@
package tcp
import (
"crypto/rand"
"math"
"sync"
"sync/atomic"
"time"
"gvisor.googlesource.com/gvisor/pkg/rand"
"gvisor.googlesource.com/gvisor/pkg/sleep"
"gvisor.googlesource.com/gvisor/pkg/tcpip"
"gvisor.googlesource.com/gvisor/pkg/tcpip/buffer"