diff --git a/docs/secret.rst b/docs/secret.rst index dd20c4296d0a510ab1f958c5b1b3d0fd6ee5099d..3a431bc22d56b8c5750346ad81011e8c2138afee 100644 --- a/docs/secret.rst +++ b/docs/secret.rst @@ -15,11 +15,11 @@ Example .. code:: python - import nacl.random import nacl.secret + import nacl.utils # This must be kept secret, this is the combination to your safe - key = nacl.random.random(nacl.secret.SecretBox.KEY_SIZE) + key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE) # This is your safe, you can use it to encrypt or decrypt messages box = nacl.secret.SecretBox(key) @@ -31,7 +31,7 @@ Example # This is a nonce, it *MUST* only be used once, but it is not considered # secret and can be transmitted or stored alongside the ciphertext. A # good source of nonce is just 24 random bytes. - nonce = nacl.random.random(nacl.secret.SecretBox.NONCE_SIZE) + nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE) # Encrypt our message, it will be exactly 16 bytes longer than the original # message as it stores authentication information alongside it. @@ -76,11 +76,11 @@ is not enough to simply use a random value and hope that it's not being reused One good method of generating nonces is for each person to pick a unique prefix, for example ``b"p1"`` and ``b"p2"``. When each person generates a nonce they -prefix it, so instead of ``nacl.random.random(24)`` you'd do ``b"p1" + nacl.random.random(22)``. -This prefix serves as a guarantee that no two messages from different people -will inadvertently overlap nonces while in transit. They should still record -every nonce they've personally used and every nonce they've received to prevent -reuse or replays. +prefix it, so instead of ``nacl.utils.random(24)`` you'd do +``b"p1" + nacl.utils.random(22)``. This prefix serves as a guarantee that no +two messages from different people will inadvertently overlap nonces while in +transit. They should still record every nonce they've personally used and every +nonce they've received to prevent reuse or replays. Reference diff --git a/nacl/signing.py b/nacl/signing.py index c1067cb0fb26bc613f4ff629b443a0a98d30c03d..01efafa778951d493ff44fea5ab29a9830f0260e 100644 --- a/nacl/signing.py +++ b/nacl/signing.py @@ -5,7 +5,7 @@ from . import six from . import nacl, encoding from .exceptions import CryptoError -from .random import random +from .utils import random class BadSignatureError(CryptoError): diff --git a/nacl/random.py b/nacl/utils.py similarity index 100% rename from nacl/random.py rename to nacl/utils.py diff --git a/tests/test_random.py b/tests/test_random.py deleted file mode 100644 index 4ec3817b5114dc7a7b90054e2ad04eb0e009b9c6..0000000000000000000000000000000000000000 --- a/tests/test_random.py +++ /dev/null @@ -1,9 +0,0 @@ -import nacl.random - - -def test_random_bytes_produces(): - assert len(nacl.random.random(16)) == 16 - - -def test_random_bytes_produces_different_bytes(): - assert nacl.random.random(16) != nacl.random.random(16) diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..83dbee05cafdc32cfa27a2a85c541d6c3b1c26b7 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,9 @@ +import nacl.utils + + +def test_random_bytes_produces(): + assert len(nacl.utils.random(16)) == 16 + + +def test_random_bytes_produces_different_bytes(): + assert nacl.utils.random(16) != nacl.utils.random(16)