1# Copyright 2013-2019 Donald Stufft and individual contributors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from __future__ import absolute_import, division, print_function 16 17from nacl.bindings.crypto_aead import ( 18 crypto_aead_chacha20poly1305_ABYTES, 19 crypto_aead_chacha20poly1305_KEYBYTES, 20 crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX, 21 crypto_aead_chacha20poly1305_NPUBBYTES, 22 crypto_aead_chacha20poly1305_NSECBYTES, 23 crypto_aead_chacha20poly1305_decrypt, 24 crypto_aead_chacha20poly1305_encrypt, 25 crypto_aead_chacha20poly1305_ietf_ABYTES, 26 crypto_aead_chacha20poly1305_ietf_KEYBYTES, 27 crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX, 28 crypto_aead_chacha20poly1305_ietf_NPUBBYTES, 29 crypto_aead_chacha20poly1305_ietf_NSECBYTES, 30 crypto_aead_chacha20poly1305_ietf_decrypt, 31 crypto_aead_chacha20poly1305_ietf_encrypt, 32 crypto_aead_xchacha20poly1305_ietf_ABYTES, 33 crypto_aead_xchacha20poly1305_ietf_KEYBYTES, 34 crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX, 35 crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, 36 crypto_aead_xchacha20poly1305_ietf_NSECBYTES, 37 crypto_aead_xchacha20poly1305_ietf_decrypt, 38 crypto_aead_xchacha20poly1305_ietf_encrypt, 39) 40from nacl.bindings.crypto_box import ( 41 crypto_box, crypto_box_BEFORENMBYTES, crypto_box_BOXZEROBYTES, 42 crypto_box_NONCEBYTES, crypto_box_PUBLICKEYBYTES, crypto_box_SEALBYTES, 43 crypto_box_SECRETKEYBYTES, crypto_box_SEEDBYTES, crypto_box_ZEROBYTES, 44 crypto_box_afternm, crypto_box_beforenm, crypto_box_keypair, 45 crypto_box_open, crypto_box_open_afternm, crypto_box_seal, 46 crypto_box_seal_open, crypto_box_seed_keypair, 47) 48from nacl.bindings.crypto_core import ( 49 crypto_core_ed25519_BYTES, crypto_core_ed25519_NONREDUCEDSCALARBYTES, 50 crypto_core_ed25519_SCALARBYTES, crypto_core_ed25519_add, 51 crypto_core_ed25519_is_valid_point, crypto_core_ed25519_scalar_add, 52 crypto_core_ed25519_scalar_complement, crypto_core_ed25519_scalar_invert, 53 crypto_core_ed25519_scalar_mul, crypto_core_ed25519_scalar_negate, 54 crypto_core_ed25519_scalar_reduce, crypto_core_ed25519_scalar_sub, 55 crypto_core_ed25519_sub, has_crypto_core_ed25519 56) 57from nacl.bindings.crypto_generichash import ( 58 crypto_generichash_BYTES, crypto_generichash_BYTES_MAX, 59 crypto_generichash_BYTES_MIN, crypto_generichash_KEYBYTES, 60 crypto_generichash_KEYBYTES_MAX, crypto_generichash_KEYBYTES_MIN, 61 crypto_generichash_PERSONALBYTES, crypto_generichash_SALTBYTES, 62 crypto_generichash_STATEBYTES, 63 generichash_blake2b_final as crypto_generichash_blake2b_final, 64 generichash_blake2b_init as crypto_generichash_blake2b_init, 65 generichash_blake2b_salt_personal as 66 crypto_generichash_blake2b_salt_personal, 67 generichash_blake2b_update as crypto_generichash_blake2b_update 68) 69from nacl.bindings.crypto_hash import ( 70 crypto_hash, crypto_hash_BYTES, crypto_hash_sha256, 71 crypto_hash_sha256_BYTES, crypto_hash_sha512, crypto_hash_sha512_BYTES, 72) 73from nacl.bindings.crypto_kx import ( 74 crypto_kx_PUBLIC_KEY_BYTES, 75 crypto_kx_SECRET_KEY_BYTES, 76 crypto_kx_SEED_BYTES, 77 crypto_kx_SESSION_KEY_BYTES, 78 crypto_kx_client_session_keys, 79 crypto_kx_keypair, 80 crypto_kx_seed_keypair, 81 crypto_kx_server_session_keys, 82) 83from nacl.bindings.crypto_pwhash import ( 84 crypto_pwhash_ALG_ARGON2I13, 85 crypto_pwhash_ALG_ARGON2ID13, 86 crypto_pwhash_ALG_DEFAULT, 87 crypto_pwhash_BYTES_MAX, 88 crypto_pwhash_BYTES_MIN, 89 crypto_pwhash_PASSWD_MAX, 90 crypto_pwhash_PASSWD_MIN, 91 crypto_pwhash_SALTBYTES, 92 crypto_pwhash_STRBYTES, 93 crypto_pwhash_alg, 94 crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE, 95 crypto_pwhash_argon2i_MEMLIMIT_MAX, 96 crypto_pwhash_argon2i_MEMLIMIT_MIN, 97 crypto_pwhash_argon2i_MEMLIMIT_MODERATE, 98 crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE, 99 crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE, 100 crypto_pwhash_argon2i_OPSLIMIT_MAX, 101 crypto_pwhash_argon2i_OPSLIMIT_MIN, 102 crypto_pwhash_argon2i_OPSLIMIT_MODERATE, 103 crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE, 104 crypto_pwhash_argon2i_STRPREFIX, 105 crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE, 106 crypto_pwhash_argon2id_MEMLIMIT_MAX, 107 crypto_pwhash_argon2id_MEMLIMIT_MIN, 108 crypto_pwhash_argon2id_MEMLIMIT_MODERATE, 109 crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE, 110 crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE, 111 crypto_pwhash_argon2id_OPSLIMIT_MAX, 112 crypto_pwhash_argon2id_OPSLIMIT_MIN, 113 crypto_pwhash_argon2id_OPSLIMIT_MODERATE, 114 crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE, 115 crypto_pwhash_argon2id_STRPREFIX, 116 crypto_pwhash_scryptsalsa208sha256_BYTES_MAX, 117 crypto_pwhash_scryptsalsa208sha256_BYTES_MIN, 118 crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE, 119 crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX, 120 crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN, 121 crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE, 122 crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE, 123 crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX, 124 crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN, 125 crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE, 126 crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX, 127 crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN, 128 crypto_pwhash_scryptsalsa208sha256_SALTBYTES, 129 crypto_pwhash_scryptsalsa208sha256_STRBYTES, 130 crypto_pwhash_scryptsalsa208sha256_STRPREFIX, 131 crypto_pwhash_scryptsalsa208sha256_ll, 132 crypto_pwhash_scryptsalsa208sha256_str, 133 crypto_pwhash_scryptsalsa208sha256_str_verify, 134 crypto_pwhash_str_alg, 135 crypto_pwhash_str_verify, 136 has_crypto_pwhash_scryptsalsa208sha256, 137 nacl_bindings_pick_scrypt_params, 138) 139from nacl.bindings.crypto_scalarmult import ( 140 crypto_scalarmult, crypto_scalarmult_BYTES, crypto_scalarmult_SCALARBYTES, 141 crypto_scalarmult_base, crypto_scalarmult_ed25519, 142 crypto_scalarmult_ed25519_BYTES, crypto_scalarmult_ed25519_SCALARBYTES, 143 crypto_scalarmult_ed25519_base, crypto_scalarmult_ed25519_base_noclamp, 144 crypto_scalarmult_ed25519_noclamp, has_crypto_scalarmult_ed25519 145) 146from nacl.bindings.crypto_secretbox import ( 147 crypto_secretbox, crypto_secretbox_BOXZEROBYTES, crypto_secretbox_KEYBYTES, 148 crypto_secretbox_MACBYTES, crypto_secretbox_MESSAGEBYTES_MAX, 149 crypto_secretbox_NONCEBYTES, crypto_secretbox_ZEROBYTES, 150 crypto_secretbox_open 151) 152from nacl.bindings.crypto_secretstream import ( 153 crypto_secretstream_xchacha20poly1305_ABYTES, 154 crypto_secretstream_xchacha20poly1305_HEADERBYTES, 155 crypto_secretstream_xchacha20poly1305_KEYBYTES, 156 crypto_secretstream_xchacha20poly1305_STATEBYTES, 157 crypto_secretstream_xchacha20poly1305_TAG_FINAL, 158 crypto_secretstream_xchacha20poly1305_TAG_MESSAGE, 159 crypto_secretstream_xchacha20poly1305_TAG_PUSH, 160 crypto_secretstream_xchacha20poly1305_TAG_REKEY, 161 crypto_secretstream_xchacha20poly1305_init_pull, 162 crypto_secretstream_xchacha20poly1305_init_push, 163 crypto_secretstream_xchacha20poly1305_keygen, 164 crypto_secretstream_xchacha20poly1305_pull, 165 crypto_secretstream_xchacha20poly1305_push, 166 crypto_secretstream_xchacha20poly1305_rekey, 167 crypto_secretstream_xchacha20poly1305_state, 168) 169from nacl.bindings.crypto_shorthash import ( 170 BYTES as crypto_shorthash_siphash24_BYTES, 171 KEYBYTES as crypto_shorthash_siphash24_KEYBYTES, 172 XBYTES as crypto_shorthash_siphashx24_BYTES, 173 XKEYBYTES as crypto_shorthash_siphashx24_KEYBYTES, 174 crypto_shorthash_siphash24, 175 crypto_shorthash_siphashx24, 176 has_crypto_shorthash_siphashx24 177) 178from nacl.bindings.crypto_sign import ( 179 crypto_sign, crypto_sign_BYTES, crypto_sign_PUBLICKEYBYTES, 180 crypto_sign_SECRETKEYBYTES, crypto_sign_SEEDBYTES, 181 crypto_sign_ed25519_pk_to_curve25519, crypto_sign_ed25519_sk_to_curve25519, 182 crypto_sign_ed25519_sk_to_pk, crypto_sign_ed25519_sk_to_seed, 183 crypto_sign_ed25519ph_STATEBYTES, crypto_sign_ed25519ph_final_create, 184 crypto_sign_ed25519ph_final_verify, crypto_sign_ed25519ph_state, 185 crypto_sign_ed25519ph_update, crypto_sign_keypair, crypto_sign_open, 186 crypto_sign_seed_keypair, 187) 188from nacl.bindings.randombytes import ( 189 randombytes, 190 randombytes_buf_deterministic 191) 192from nacl.bindings.sodium_core import sodium_init 193from nacl.bindings.utils import ( 194 sodium_add, sodium_increment, sodium_memcmp, sodium_pad, sodium_unpad, 195) 196 197 198__all__ = [ 199 "crypto_aead_chacha20poly1305_ABYTES", 200 "crypto_aead_chacha20poly1305_KEYBYTES", 201 "crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX", 202 "crypto_aead_chacha20poly1305_NPUBBYTES", 203 "crypto_aead_chacha20poly1305_NSECBYTES", 204 "crypto_aead_chacha20poly1305_decrypt", 205 "crypto_aead_chacha20poly1305_encrypt", 206 "crypto_aead_chacha20poly1305_ietf_ABYTES", 207 "crypto_aead_chacha20poly1305_ietf_KEYBYTES", 208 "crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX", 209 "crypto_aead_chacha20poly1305_ietf_NPUBBYTES", 210 "crypto_aead_chacha20poly1305_ietf_NSECBYTES", 211 "crypto_aead_chacha20poly1305_ietf_decrypt", 212 "crypto_aead_chacha20poly1305_ietf_encrypt", 213 "crypto_aead_xchacha20poly1305_ietf_ABYTES", 214 "crypto_aead_xchacha20poly1305_ietf_KEYBYTES", 215 "crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX", 216 "crypto_aead_xchacha20poly1305_ietf_NPUBBYTES", 217 "crypto_aead_xchacha20poly1305_ietf_NSECBYTES", 218 "crypto_aead_xchacha20poly1305_ietf_decrypt", 219 "crypto_aead_xchacha20poly1305_ietf_encrypt", 220 221 "crypto_box_SECRETKEYBYTES", 222 "crypto_box_PUBLICKEYBYTES", 223 "crypto_box_SEEDBYTES", 224 "crypto_box_NONCEBYTES", 225 "crypto_box_ZEROBYTES", 226 "crypto_box_BOXZEROBYTES", 227 "crypto_box_BEFORENMBYTES", 228 "crypto_box_SEALBYTES", 229 "crypto_box_keypair", 230 "crypto_box", 231 "crypto_box_open", 232 "crypto_box_beforenm", 233 "crypto_box_afternm", 234 "crypto_box_open_afternm", 235 "crypto_box_seal", 236 "crypto_box_seal_open", 237 "crypto_box_seed_keypair", 238 239 "has_crypto_core_ed25519", 240 "crypto_core_ed25519_BYTES", 241 "crypto_core_ed25519_UNIFORMBYTES", 242 "crypto_core_ed25519_SCALARBYTES", 243 "crypto_core_ed25519_NONREDUCEDSCALARBYTES", 244 "crypto_core_ed25519_add", 245 "crypto_core_ed25519_from_uniform", 246 "crypto_core_ed25519_is_valid_point", 247 "crypto_core_ed25519_sub", 248 "crypto_core_ed25519_scalar_invert", 249 "crypto_core_ed25519_scalar_negate", 250 "crypto_core_ed25519_scalar_complement", 251 "crypto_core_ed25519_scalar_add", 252 "crypto_core_ed25519_scalar_sub", 253 "crypto_core_ed25519_scalar_mul", 254 "crypto_core_ed25519_scalar_reduce", 255 256 "crypto_hash_BYTES", 257 "crypto_hash_sha256_BYTES", 258 "crypto_hash_sha512_BYTES", 259 "crypto_hash", 260 "crypto_hash_sha256", 261 "crypto_hash_sha512", 262 263 "crypto_generichash_BYTES", 264 "crypto_generichash_BYTES_MIN", 265 "crypto_generichash_BYTES_MAX", 266 "crypto_generichash_KEYBYTES", 267 "crypto_generichash_KEYBYTES_MIN", 268 "crypto_generichash_KEYBYTES_MAX", 269 "crypto_generichash_SALTBYTES", 270 "crypto_generichash_PERSONALBYTES", 271 "crypto_generichash_STATEBYTES", 272 "crypto_generichash_blake2b_salt_personal", 273 "crypto_generichash_blake2b_init", 274 "crypto_generichash_blake2b_update", 275 "crypto_generichash_blake2b_final", 276 277 "crypto_kx_keypair", 278 "crypto_kx_seed_keypair", 279 "crypto_kx_client_session_keys", 280 "crypto_kx_server_session_keys", 281 "crypto_kx_PUBLIC_KEY_BYTES", 282 "crypto_kx_SECRET_KEY_BYTES", 283 "crypto_kx_SEED_BYTES", 284 "crypto_kx_SESSION_KEY_BYTES", 285 286 "has_crypto_scalarmult_ed25519", 287 "crypto_scalarmult_BYTES", 288 "crypto_scalarmult_SCALARBYTES", 289 "crypto_scalarmult", 290 "crypto_scalarmult_base", 291 "crypto_scalarmult_ed25519_BYTES", 292 "crypto_scalarmult_ed25519_SCALARBYTES", 293 "crypto_scalarmult_ed25519", 294 "crypto_scalarmult_ed25519_base", 295 "crypto_scalarmult_ed25519_noclamp", 296 "crypto_scalarmult_ed25519_base_noclamp", 297 298 "crypto_secretbox_KEYBYTES", 299 "crypto_secretbox_NONCEBYTES", 300 "crypto_secretbox_ZEROBYTES", 301 "crypto_secretbox_BOXZEROBYTES", 302 "crypto_secretbox_MACBYTES", 303 "crypto_secretbox_MESSAGEBYTES_MAX", 304 "crypto_secretbox", 305 "crypto_secretbox_open", 306 307 "crypto_secretstream_xchacha20poly1305_ABYTES", 308 "crypto_secretstream_xchacha20poly1305_HEADERBYTES", 309 "crypto_secretstream_xchacha20poly1305_KEYBYTES", 310 "crypto_secretstream_xchacha20poly1305_STATEBYTES", 311 "crypto_secretstream_xchacha20poly1305_TAG_FINAL", 312 "crypto_secretstream_xchacha20poly1305_TAG_MESSAGE", 313 "crypto_secretstream_xchacha20poly1305_TAG_PUSH", 314 "crypto_secretstream_xchacha20poly1305_TAG_REKEY", 315 "crypto_secretstream_xchacha20poly1305_init_pull", 316 "crypto_secretstream_xchacha20poly1305_init_push", 317 "crypto_secretstream_xchacha20poly1305_keygen", 318 "crypto_secretstream_xchacha20poly1305_pull", 319 "crypto_secretstream_xchacha20poly1305_push", 320 "crypto_secretstream_xchacha20poly1305_rekey", 321 "crypto_secretstream_xchacha20poly1305_state", 322 323 "has_crypto_shorthash_siphashx24", 324 "crypto_shorthash_siphash24_BYTES", 325 "crypto_shorthash_siphash24_KEYBYTES", 326 "crypto_shorthash_siphash24", 327 "crypto_shorthash_siphashx24_BYTES", 328 "crypto_shorthash_siphashx24_KEYBYTES", 329 "crypto_shorthash_siphashx24", 330 331 "crypto_sign_BYTES", 332 "crypto_sign_SEEDBYTES", 333 "crypto_sign_PUBLICKEYBYTES", 334 "crypto_sign_SECRETKEYBYTES", 335 "crypto_sign_keypair", 336 "crypto_sign_seed_keypair", 337 "crypto_sign", 338 "crypto_sign_open", 339 "crypto_sign_ed25519_pk_to_curve25519", 340 "crypto_sign_ed25519_sk_to_curve25519", 341 "crypto_sign_ed25519_sk_to_pk", 342 "crypto_sign_ed25519_sk_to_seed", 343 "crypto_sign_ed25519ph_STATEBYTES", 344 "crypto_sign_ed25519ph_final_create", 345 "crypto_sign_ed25519ph_final_verify", 346 "crypto_sign_ed25519ph_state", 347 "crypto_sign_ed25519ph_update", 348 349 "crypto_pwhash_ALG_ARGON2I13", 350 "crypto_pwhash_ALG_ARGON2ID13", 351 "crypto_pwhash_ALG_DEFAULT", 352 "crypto_pwhash_BYTES_MAX", 353 "crypto_pwhash_BYTES_MIN", 354 "crypto_pwhash_PASSWD_MAX", 355 "crypto_pwhash_PASSWD_MIN", 356 "crypto_pwhash_SALTBYTES", 357 "crypto_pwhash_STRBYTES", 358 359 "crypto_pwhash_alg", 360 "crypto_pwhash_argon2i_MEMLIMIT_MIN", 361 "crypto_pwhash_argon2i_MEMLIMIT_MAX", 362 "crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE", 363 "crypto_pwhash_argon2i_MEMLIMIT_MODERATE", 364 "crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE", 365 "crypto_pwhash_argon2i_OPSLIMIT_MIN", 366 "crypto_pwhash_argon2i_OPSLIMIT_MAX", 367 "crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE", 368 "crypto_pwhash_argon2i_OPSLIMIT_MODERATE", 369 "crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE", 370 "crypto_pwhash_argon2i_STRPREFIX", 371 372 "crypto_pwhash_argon2id_MEMLIMIT_MIN", 373 "crypto_pwhash_argon2id_MEMLIMIT_MAX", 374 "crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE", 375 "crypto_pwhash_argon2id_MEMLIMIT_MODERATE", 376 "crypto_pwhash_argon2id_OPSLIMIT_MIN", 377 "crypto_pwhash_argon2id_OPSLIMIT_MAX", 378 "crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE", 379 "crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE", 380 "crypto_pwhash_argon2id_OPSLIMIT_MODERATE", 381 "crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE", 382 "crypto_pwhash_argon2id_STRPREFIX", 383 384 "crypto_pwhash_str_alg", 385 "crypto_pwhash_str_verify", 386 387 "has_crypto_pwhash_scryptsalsa208sha256", 388 "crypto_pwhash_scryptsalsa208sha256_BYTES_MAX", 389 "crypto_pwhash_scryptsalsa208sha256_BYTES_MIN", 390 "crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE", 391 "crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX", 392 "crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN", 393 "crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE", 394 "crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE", 395 "crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX", 396 "crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN", 397 "crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE", 398 "crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX", 399 "crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN", 400 "crypto_pwhash_scryptsalsa208sha256_SALTBYTES", 401 "crypto_pwhash_scryptsalsa208sha256_STRBYTES", 402 "crypto_pwhash_scryptsalsa208sha256_STRPREFIX", 403 "crypto_pwhash_scryptsalsa208sha256_ll", 404 "crypto_pwhash_scryptsalsa208sha256_str", 405 "crypto_pwhash_scryptsalsa208sha256_str_verify", 406 "nacl_bindings_pick_scrypt_params", 407 408 "randombytes", 409 "randombytes_buf_deterministic", 410 411 "sodium_init", 412 413 "sodium_add", 414 "sodium_increment", 415 416 "sodium_memcmp", 417 "sodium_pad", 418 "sodium_unpad", 419] 420 421 422# Initialize Sodium 423sodium_init() 424