Skip to content
Snippets Groups Projects
Commit 2a35b6b3 authored by Donald Stufft's avatar Donald Stufft
Browse files

Move the random implementation over to the new layout

parent a5a57dec
No related branches found
No related tags found
No related merge requests found
/* Copyright 2013 Donald Stufft and individual contributors
*
* 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.
*/
void randombytes(unsigned char * const buf, const unsigned long long buf_len);
...@@ -23,6 +23,7 @@ from nacl.c.crypto_scalarmult import ( ...@@ -23,6 +23,7 @@ from nacl.c.crypto_scalarmult import (
crypto_scalarmult_BYTES, crypto_scalarmult_SCALARBYTES, crypto_scalarmult_BYTES, crypto_scalarmult_SCALARBYTES,
crypto_scalarmult_base, crypto_scalarmult_base,
) )
from nacl.c.randombytes import randombytes
__all__ = [ __all__ = [
...@@ -42,4 +43,6 @@ __all__ = [ ...@@ -42,4 +43,6 @@ __all__ = [
"crypto_scalarmult_BYTES", "crypto_scalarmult_BYTES",
"crypto_scalarmult_SCALARBYTES", "crypto_scalarmult_SCALARBYTES",
"crypto_scalarmult_base", "crypto_scalarmult_base",
"randombytes",
] ]
# Copyright 2013 Donald Stufft and individual contributors
#
# 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.
from __future__ import absolute_import, division, print_function
from nacl import _lib as lib
def randombytes(size):
"""
Returns ``size`` number of random bytes from a cryptographically secure
random source.
:param size: int
:rtype: bytes
"""
buf = lib.ffi.new("unsigned char[]", size)
lib.randombytes(buf, size)
return lib.ffi.buffer(buf, size)[:]
...@@ -16,7 +16,7 @@ from __future__ import division ...@@ -16,7 +16,7 @@ from __future__ import division
import six import six
from .c import _lib as nacl import nacl.c
class EncryptedMessage(six.binary_type): class EncryptedMessage(six.binary_type):
...@@ -57,6 +57,4 @@ class StringFixer(object): ...@@ -57,6 +57,4 @@ class StringFixer(object):
def random(size=32): def random(size=32):
data = nacl.ffi.new("unsigned char[]", size) return nacl.c.randombytes(size)
nacl.lib.randombytes(data, size)
return nacl.ffi.buffer(data, size)[:]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment