mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 18:41:37 +00:00
Support rngd on arm64
Although it does not do anything, as there is no CPU rng on arm64 at present. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
d7caf92708
commit
8b2327b0e2
@ -1,5 +1,4 @@
|
|||||||
IMAGE=rngd
|
IMAGE=rngd
|
||||||
DEPS:=$(wildcard cmd/rngd/*.go) $(shell find cmd/rngd/vendor)
|
DEPS:=$(wildcard cmd/rngd/*.go) $(shell find cmd/rngd/vendor)
|
||||||
ARCHES=x86_64
|
|
||||||
|
|
||||||
include ../package.mk
|
include ../package.mk
|
||||||
|
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// int rndaddentropy;
|
||||||
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@ -69,3 +73,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type randInfo struct {
|
||||||
|
entropyCount int
|
||||||
|
size int
|
||||||
|
buf uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeEntropy(random *os.File) (int, error) {
|
||||||
|
r, err := rand()
|
||||||
|
if err != nil {
|
||||||
|
// assume can fail occasionally
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
const entropy = 64 // they are good random numbers, Brent
|
||||||
|
info := randInfo{entropy, 8, r}
|
||||||
|
ret, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(random.Fd()), uintptr(C.rndaddentropy), uintptr(unsafe.Pointer(&info)))
|
||||||
|
if ret == 0 {
|
||||||
|
return 8, nil
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
@ -37,10 +37,6 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var disableRdrand = flag.Bool("disable-rdrand", false, "Disable use of RDRAND")
|
var disableRdrand = flag.Bool("disable-rdrand", false, "Disable use of RDRAND")
|
||||||
@ -48,12 +44,6 @@ var disableRdseed = flag.Bool("disable-rdseed", false, "Disable use of RDSEED")
|
|||||||
|
|
||||||
var hasRdrand, hasRdseed bool
|
var hasRdrand, hasRdseed bool
|
||||||
|
|
||||||
type randInfo struct {
|
|
||||||
entropyCount int
|
|
||||||
size int
|
|
||||||
buf uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
func initRand() bool {
|
func initRand() bool {
|
||||||
hasRdrand = C.hasrdrand() == 1 && !*disableRdrand
|
hasRdrand = C.hasrdrand() == 1 && !*disableRdrand
|
||||||
hasRdseed = C.hasrdseed() == 1 && !*disableRdseed
|
hasRdseed = C.hasrdseed() == 1 && !*disableRdseed
|
||||||
@ -72,18 +62,3 @@ func rand() (uint64, error) {
|
|||||||
}
|
}
|
||||||
return 0, errors.New("No randomness available")
|
return 0, errors.New("No randomness available")
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeEntropy(random *os.File) (int, error) {
|
|
||||||
r, err := rand()
|
|
||||||
if err != nil {
|
|
||||||
// assume can fail occasionally
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
const entropy = 64 // they are good random numbers, Brent
|
|
||||||
info := randInfo{entropy, 8, r}
|
|
||||||
ret, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(random.Fd()), uintptr(C.rndaddentropy), uintptr(unsafe.Pointer(&info)))
|
|
||||||
if ret == 0 {
|
|
||||||
return 8, nil
|
|
||||||
}
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
21
pkg/rngd/cmd/rngd/rng_linux_arm64.go
Normal file
21
pkg/rngd/cmd/rngd/rng_linux_arm64.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// #include <linux/random.h>
|
||||||
|
//
|
||||||
|
// int rndaddentropy = RNDADDENTROPY;
|
||||||
|
//
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// No standard RNG on arm64
|
||||||
|
|
||||||
|
func initRand() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func rand() (uint64, error) {
|
||||||
|
return 0, errors.New("No randomness available")
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
// +build !linux !amd64
|
// +build !linux !amd64,!arm64
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user