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

Use sodium_init to optimize and ensure thread safety

parent 5bb13a1a
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.
*/
int sodium_init();
......@@ -39,6 +39,7 @@ from nacl.c.crypto_sign import (
crypto_sign, crypto_sign_open,
)
from nacl.c.randombytes import randombytes
from nacl.c.sodium_core import sodium_init
__all__ = [
......@@ -84,4 +85,9 @@ __all__ = [
"crypto_sign_open",
"randombytes",
"sodium_init",
]
# Initialize Sodium
sodium_init()
# 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._lib import lib
from nacl.exceptions import CryptoError
def sodium_init():
"""
Initializes sodium, picking the best implementations available for this
machine.
"""
if lib.sodium_init() != 0:
raise CryptoError("Could not initialize sodium")
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