Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: filter/dscache/support.go

Issue 2354303002: dscache: Use math/rand's Read for nonce. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « filter/dscache/dscache.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filter/dscache/support.go
diff --git a/filter/dscache/support.go b/filter/dscache/support.go
index aa17fede6040ccd6ef191e14511c0c3a7adf48ee..6de7c1bf96e33026b831d07803f4cf63091eff26 100644
--- a/filter/dscache/support.go
+++ b/filter/dscache/support.go
@@ -83,26 +83,6 @@ func (s *supportContext) mkAllKeys(keys []*ds.Key) []string {
return ret
}
-// crappyNonce creates a really crappy nonce using math/rand. This is generally
-// unacceptable for cryptographic purposes, but since mathrand is the only
-// mocked randomness source, we use that.
-//
-// The random values here are controlled entriely by the application, will never
-// be shown to, or provided by, the user, so this should be fine.
-//
-// Do not use this function for anything other than mkRandLockItems or your hair
-// will fall out. You've been warned.
-func (s *supportContext) crappyNonce() []byte {
- ret := make([]byte, NonceUint32s*4)
- for w := uint(0); w < NonceUint32s; w++ {
- word := s.mr.Uint32()
- for i := uint(0); i < 4; i++ {
- ret[(w*4)+i] = byte(word >> (8 * i))
- }
- }
- return ret
-}
-
func (s *supportContext) mutation(keys []*ds.Key, f func() error) error {
lockItems, lockKeys := s.mkAllLockItems(keys)
if lockItems == nil {
@@ -130,7 +110,7 @@ func (s *supportContext) mkRandLockItems(keys []*ds.Key, metas ds.MultiMetaGette
if len(mcKeys) == 0 {
return nil, nil
}
- nonce := s.crappyNonce()
+ nonce := generateNonce()
ret := make([]mc.Item, len(mcKeys))
for i, k := range mcKeys {
if k == "" {
@@ -157,3 +137,14 @@ func (s *supportContext) mkAllLockItems(keys []*ds.Key) ([]mc.Item, []string) {
}
return ret, mcKeys
}
+
+// generateNonce creates a pseudo-random sequence of bytes for use as a nonce
+// usingthe non-cryptographic PRNG in "math/rand".
+//
+// The random values here are controlled entriely by the application, will never
+// be shown to, or provided by, the user, so this should be fine.
+func generateNonce() []byte {
+ nonce := make([]byte, NonceBytes)
+ _, _ = rand.Read(nonce) // This Read will always return len(nonce), nil.
+ return nonce
+}
« no previous file with comments | « filter/dscache/dscache.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698