diff --git a/src/nacl/_lib/sodium_core.h b/src/nacl/_lib/sodium_core.h new file mode 100644 index 0000000000000000000000000000000000000000..b0059d5efc3874cae07b27a1241e460af86eee62 --- /dev/null +++ b/src/nacl/_lib/sodium_core.h @@ -0,0 +1,16 @@ +/* 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(); diff --git a/src/nacl/c/__init__.py b/src/nacl/c/__init__.py index 7499bbd6447ff0c253bf967dbf6cbd6ca7a6a559..af60eb57eaa854ffe89359b89e31275ca326089c 100644 --- a/src/nacl/c/__init__.py +++ b/src/nacl/c/__init__.py @@ -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() diff --git a/src/nacl/c/sodium_core.py b/src/nacl/c/sodium_core.py new file mode 100644 index 0000000000000000000000000000000000000000..51d3a8f63e4b9a266426a841c5cc2dbc378d3449 --- /dev/null +++ b/src/nacl/c/sodium_core.py @@ -0,0 +1,26 @@ +# 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")