-2

For security, I need to use 256 bits input as the rand seed, but it seems there is no satisfied API or functions, for example, in Golang std library, the seed should be int64, or 64 bits integer.

// Seed uses the provided seed value to initialize the default Source to a
// deterministic state. If Seed is not called, the generator behaves as
// if seeded by Seed(1). Seed values that have the same remainder when
// divided by 2³¹-1 generate the same pseudo-random sequence.
// Seed, unlike the Rand.Seed method, is safe for concurrent use.
func Seed(seed int64) { globalRand.Seed(seed) }

above code is just an inappropriate example, you can ignore it, crypto/rand is much safer, as we can see in the std library doc.

Is there a way to use 256 bits rand seeds in Golang?

THANKS A LOT !!!

Edgar
  • 89
  • 2
  • 9
  • 2
    Assuming your using [`math/rand`](https://pkg.go.dev/math/rand) keep in mind that those prngs are not intended to be used for security-sensitive stuff: *Package rand implements pseudo-random number generators **unsuitable for security-sensitive work**.* . If you need truly random bytes for security-sensitive stuff there's [`crypto/rand`](https://pkg.go.dev/crypto/rand) for that. – Turtlefight Feb 18 '22 at 04:31
  • Please stay away from anything security relevant. – Volker Feb 18 '22 at 05:27
  • @Turtlefight, thanks, but I can not set seed in crypto/rand . – Edgar Feb 18 '22 at 05:33

1 Answers1

0

Is there a way to use 256 bits rand seeds in [math/rand] Go[]?

No, for obvious reasons.

Volker
  • 40,468
  • 7
  • 81
  • 87
  • But put security aside, why there is no 256 bits rand seed ? Thanks! – Edgar Feb 18 '22 at 05:43
  • @Edgar For the same reason there are no 96 bits seed, no 512 bits seed and no 2048 bits seed an no 71 bit seed. This is a pseudo random number generator and while the size of the internal configuration space does matter the generated sequence doesn't become "better" (for any metric!) if you use more bits in seeding. – Volker Feb 18 '22 at 05:59