├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── Pipfile ├── Practical_Cryptography_Engineering.pdf ├── README.md ├── aes_gcm.c ├── aes_gcm_cryptography.py ├── aesgcm_file.c ├── aesgcm_file.py ├── ecdh.c ├── ecdh.py ├── ecdh_read_server_pub_write_client_pub.c ├── ecdh_write_server_pub.py ├── kdf.c ├── kdf.py ├── mbedtls ├── .gitignore ├── CMakeLists.txt ├── Makefile ├── aes.c ├── aes.h ├── aesni.c ├── aesni.h ├── arc4.c ├── arc4.h ├── asn1.h ├── asn1parse.c ├── asn1write.c ├── asn1write.h ├── base64.c ├── base64.h ├── bignum.c ├── bignum.h ├── blowfish.c ├── blowfish.h ├── bn_mul.h ├── camellia.c ├── camellia.h ├── ccm.c ├── ccm.h ├── certs.c ├── certs.h ├── check_config.h ├── cipher.c ├── cipher.h ├── cipher_internal.h ├── cipher_wrap.c ├── cmac.c ├── cmac.h ├── compat-1.3.h ├── config.h ├── ctr_drbg.c ├── ctr_drbg.h ├── debug.c ├── debug.h ├── des.c ├── des.h ├── dhm.c ├── dhm.h ├── ecdh.c ├── ecdh.h ├── ecdsa.c ├── ecdsa.h ├── ecjpake.c ├── ecjpake.h ├── ecp.c ├── ecp.h ├── ecp_curves.c ├── ecp_internal.h ├── entropy.c ├── entropy.h ├── entropy_poll.c ├── entropy_poll.h ├── error.c ├── error.h ├── gcm.c ├── gcm.h ├── havege.c ├── havege.h ├── hmac_drbg.c ├── hmac_drbg.h ├── md.c ├── md.h ├── md2.c ├── md2.h ├── md4.c ├── md4.h ├── md5.c ├── md5.h ├── md_internal.h ├── md_wrap.c ├── memory_buffer_alloc.c ├── memory_buffer_alloc.h ├── net.h ├── net_sockets.c ├── net_sockets.h ├── oid.c ├── oid.h ├── padlock.c ├── padlock.h ├── pem.c ├── pem.h ├── pk.c ├── pk.h ├── pk_internal.h ├── pk_wrap.c ├── pkcs11.c ├── pkcs11.h ├── pkcs12.c ├── pkcs12.h ├── pkcs5.c ├── pkcs5.h ├── pkparse.c ├── pkwrite.c ├── platform.c ├── platform.h ├── platform_time.h ├── ripemd160.c ├── ripemd160.h ├── rsa.c ├── rsa.h ├── sha1.c ├── sha1.h ├── sha256.c ├── sha256.h ├── sha512.c ├── sha512.h ├── ssl.h ├── ssl_cache.c ├── ssl_cache.h ├── ssl_ciphersuites.c ├── ssl_ciphersuites.h ├── ssl_cli.c ├── ssl_cookie.c ├── ssl_cookie.h ├── ssl_internal.h ├── ssl_srv.c ├── ssl_ticket.c ├── ssl_ticket.h ├── ssl_tls.c ├── threading.c ├── threading.h ├── timing.c ├── timing.h ├── version.c ├── version.h ├── version_features.c ├── x509.c ├── x509.h ├── x509_create.c ├── x509_crl.c ├── x509_crl.h ├── x509_crt.c ├── x509_crt.h ├── x509_csr.c ├── x509_csr.h ├── x509write_crt.c ├── x509write_csr.c ├── xtea.c └── xtea.h ├── nacl_genkey.py ├── nacl_sign.py ├── nacl_symmetric_gen.py ├── nacl_verify.py ├── rsa_sign.c ├── rsa_sign.py ├── rsa_verify.c ├── rsa_verify.py └── sodium ├── CMakeLists.txt ├── Readme.md ├── cmake └── Findsodium.cmake ├── ed25519_sodium_pynacl.c ├── hello_sodium.c ├── include ├── sodium.h └── sodium │ ├── core.h │ ├── crypto_aead_aes256gcm.h │ ├── crypto_aead_chacha20poly1305.h │ ├── crypto_aead_xchacha20poly1305.h │ ├── crypto_auth.h │ ├── crypto_auth_hmacsha256.h │ ├── crypto_auth_hmacsha512.h │ ├── crypto_auth_hmacsha512256.h │ ├── crypto_box.h │ ├── crypto_box_curve25519xchacha20poly1305.h │ ├── crypto_box_curve25519xsalsa20poly1305.h │ ├── crypto_core_hchacha20.h │ ├── crypto_core_hsalsa20.h │ ├── crypto_core_salsa20.h │ ├── crypto_core_salsa2012.h │ ├── crypto_core_salsa208.h │ ├── crypto_generichash.h │ ├── crypto_generichash_blake2b.h │ ├── crypto_hash.h │ ├── crypto_hash_sha256.h │ ├── crypto_hash_sha512.h │ ├── crypto_kdf.h │ ├── crypto_kdf_blake2b.h │ ├── crypto_kx.h │ ├── crypto_onetimeauth.h │ ├── crypto_onetimeauth_poly1305.h │ ├── crypto_pwhash.h │ ├── crypto_pwhash_argon2i.h │ ├── crypto_pwhash_argon2id.h │ ├── crypto_pwhash_scryptsalsa208sha256.h │ ├── crypto_scalarmult.h │ ├── crypto_scalarmult_curve25519.h │ ├── crypto_secretbox.h │ ├── crypto_secretbox_xchacha20poly1305.h │ ├── crypto_secretbox_xsalsa20poly1305.h │ ├── crypto_secretstream_xchacha20poly1305.h │ ├── crypto_shorthash.h │ ├── crypto_shorthash_siphash24.h │ ├── crypto_sign.h │ ├── crypto_sign_ed25519.h │ ├── crypto_sign_edwards25519sha512batch.h │ ├── crypto_stream.h │ ├── crypto_stream_chacha20.h │ ├── crypto_stream_salsa20.h │ ├── crypto_stream_salsa2012.h │ ├── crypto_stream_salsa208.h │ ├── crypto_stream_xchacha20.h │ ├── crypto_stream_xsalsa20.h │ ├── crypto_verify_16.h │ ├── crypto_verify_32.h │ ├── crypto_verify_64.h │ ├── export.h │ ├── private │ ├── common.h │ ├── curve25519_ref10.h │ ├── implementations.h │ ├── mutex.h │ └── sse2_64_32.h │ ├── randombytes.h │ ├── randombytes_nativeclient.h │ ├── randombytes_salsa20_random.h │ ├── randombytes_sysrandom.h │ ├── runtime.h │ ├── utils.h │ ├── version.h │ └── version.h.in ├── nacl_decrypt_file.c ├── nacl_ed25519.c ├── nacl_encrypt_file.c ├── nacl_genkey.c ├── nacl_sign.c ├── nacl_symmetric_gen.c └── nacl_verify.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # Python 55 | __pycache__ 56 | *.pyc 57 | .venv 58 | Pipfile.lock 59 | 60 | * CLion and/or PyCharm IDEs 61 | .idea 62 | cmake-build-debug 63 | 64 | # CMake 65 | build 66 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | project("mbed_AES" C) 3 | 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall") 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O2 -Wall") 6 | 7 | set(MBED_DIR mbedtls) 8 | 9 | include_directories(. ${MBED_DIR}) 10 | 11 | # Files to build for mbedTLS crypto routines (not including all of the SSL stuff) 12 | set(MBED_CRYPTO 13 | ${MBED_DIR}/aes.c 14 | ${MBED_DIR}/aesni.c 15 | ${MBED_DIR}/arc4.c 16 | ${MBED_DIR}/asn1parse.c 17 | ${MBED_DIR}/asn1write.c 18 | ${MBED_DIR}/base64.c 19 | ${MBED_DIR}/bignum.c 20 | ${MBED_DIR}/blowfish.c 21 | ${MBED_DIR}/camellia.c 22 | ${MBED_DIR}/ccm.c 23 | ${MBED_DIR}/cipher.c 24 | ${MBED_DIR}/cipher_wrap.c 25 | ${MBED_DIR}/cmac.c 26 | ${MBED_DIR}/ctr_drbg.c 27 | ${MBED_DIR}/des.c 28 | ${MBED_DIR}/dhm.c 29 | ${MBED_DIR}/ecdh.c 30 | ${MBED_DIR}/ecdsa.c 31 | ${MBED_DIR}/ecjpake.c 32 | ${MBED_DIR}/ecp.c 33 | ${MBED_DIR}/ecp_curves.c 34 | ${MBED_DIR}/entropy.c 35 | ${MBED_DIR}/entropy_poll.c 36 | ${MBED_DIR}/error.c 37 | ${MBED_DIR}/gcm.c 38 | ${MBED_DIR}/havege.c 39 | ${MBED_DIR}/hmac_drbg.c 40 | ${MBED_DIR}/md.c 41 | ${MBED_DIR}/md2.c 42 | ${MBED_DIR}/md4.c 43 | ${MBED_DIR}/md5.c 44 | ${MBED_DIR}/md_wrap.c 45 | ${MBED_DIR}/memory_buffer_alloc.c 46 | ${MBED_DIR}/oid.c 47 | ${MBED_DIR}/padlock.c 48 | ${MBED_DIR}/pem.c 49 | ${MBED_DIR}/pk.c 50 | ${MBED_DIR}/pk_wrap.c 51 | ${MBED_DIR}/pkcs12.c 52 | ${MBED_DIR}/pkcs5.c 53 | ${MBED_DIR}/pkparse.c 54 | ${MBED_DIR}/pkwrite.c 55 | ${MBED_DIR}/platform.c 56 | ${MBED_DIR}/ripemd160.c 57 | ${MBED_DIR}/rsa.c 58 | ${MBED_DIR}/sha1.c 59 | ${MBED_DIR}/sha256.c 60 | ${MBED_DIR}/sha512.c 61 | ${MBED_DIR}/threading.c 62 | ${MBED_DIR}/timing.c 63 | ${MBED_DIR}/version.c 64 | ${MBED_DIR}/version_features.c 65 | ${MBED_DIR}/xtea.c 66 | ) 67 | 68 | # Files to build for each executable 69 | set(AES_GCM aes_gcm.c) 70 | set(AESGCM_FILE aesgcm_file.c) 71 | set(ECDH ecdh.c) 72 | set(KDF kdf.c) 73 | set(RSA_SIGN rsa_sign.c) 74 | set(RSA_VERIFY rsa_verify.c) 75 | 76 | 77 | # Library type to build (uncomment one of the following lines to choose either a static or dynamic (shared) library type 78 | set(LIB_TYPE STATIC) 79 | #set(LIB_TYPE SHARED) 80 | 81 | # Build mbedTLS crypto code as a library so it only builds once 82 | set(MBED_LIB mbed_crypto) 83 | add_library(${MBED_LIB} ${LIB_TYPE} ${MBED_CRYPTO}) 84 | set_property(TARGET mbed_crypto PROPERTY C_STANDARD 99) 85 | 86 | 87 | # Executables to build 88 | set(AES_TGT aes_gcm) 89 | add_executable(${AES_TGT} ${AES_GCM}) 90 | set_property(TARGET ${AES_TGT} PROPERTY C_STANDARD 99) 91 | target_link_libraries(${AES_TGT} ${MBED_LIB}) 92 | 93 | set(AES_FILE_TGT aesgcm_file) 94 | add_executable(${AES_FILE_TGT} ${AESGCM_FILE}) 95 | set_property(TARGET ${AES_FILE_TGT} PROPERTY C_STANDARD 99) 96 | target_link_libraries(${AES_FILE_TGT} ${MBED_LIB}) 97 | 98 | set(ECDH_TGT ecdh) 99 | add_executable(${ECDH_TGT} ${ECDH}) 100 | set_property(TARGET ${ECDH_TGT} PROPERTY C_STANDARD 99) 101 | target_link_libraries(${ECDH_TGT} ${MBED_LIB}) 102 | 103 | set(KDF_TGT kdf) 104 | add_executable(${KDF_TGT} ${KDF}) 105 | set_property(TARGET ${KDF_TGT} PROPERTY C_STANDARD 99) 106 | target_link_libraries(${KDF_TGT} ${MBED_LIB}) 107 | 108 | set(RSA_SIG_TGT rsa_sign) 109 | add_executable(${RSA_SIG_TGT} ${RSA_SIGN}) 110 | set_property(TARGET ${RSA_SIG_TGT} PROPERTY C_STANDARD 99) 111 | target_link_libraries(${RSA_SIG_TGT} ${MBED_LIB}) 112 | 113 | set(RSA_VER_TGT rsa_verify) 114 | add_executable(${RSA_VER_TGT} ${RSA_VERIFY}) 115 | set_property(TARGET ${RSA_VER_TGT} PROPERTY C_STANDARD 99) 116 | target_link_libraries(${RSA_VER_TGT} ${MBED_LIB}) 117 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | ipython = "*" 8 | 9 | [packages] 10 | cryptography = "*" 11 | colorama = "*" 12 | pynacl = "*" 13 | -------------------------------------------------------------------------------- /Practical_Cryptography_Engineering.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tleonhardt/practical_cryptography_engineering/736c515d13682353c67de5f0ce92c630869af612/Practical_Cryptography_Engineering.pdf -------------------------------------------------------------------------------- /aes_gcm_cryptography.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | This is a simple example of using the cryptography module to securely encrypt and decrypt data with 5 | AES in GCM mode. 6 | 7 | GCM (Galois Counter Mode) is a mode of operation for block ciphers. An AEAD (authenticated 8 | encryption with additional data) mode is a type of block cipher mode that simultaneously encrypts 9 | the message as awell as authenticating it. Additional unencrypted data may also be authenticated. 10 | Additional means of verifying integrity such as HMAC are not necessary. 11 | 12 | NOTE: There is a better way to do AES-GCM in Cryptography version 2.0 or newer using the AES-GCM construction which is 13 | composed of the AES block cipher utilizing GCM mode. This version is intended to be compatible with version 1.7 14 | or newer of the Cryptography module. 15 | """ 16 | import os 17 | 18 | from cryptography.hazmat.backends import default_backend 19 | from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes 20 | 21 | 22 | def encrypt(key: bytes, iv: bytes, plaintext: bytes, associated_data: bytes) -> (bytes, bytes): 23 | # Construct an AES-GCM Cipher object with the given key and a randomly generated nonce. 24 | encryptor = Cipher(algorithms.AES(key), modes.GCM(iv), backend=default_backend()).encryptor() 25 | 26 | # associated_data will be authenticated but not encrypted, it must also be passed in on decryption. 27 | encryptor.authenticate_additional_data(associated_data) 28 | 29 | # Encrypt the plaintext and get the associated ciphertext. GCM does not require padding. 30 | ciphertext = encryptor.update(plaintext) + encryptor.finalize() 31 | 32 | # Cryptography will generate a 128-bit tag when finalizing encryption. This tag is authenticated when decrypting. 33 | return ciphertext, encryptor.tag 34 | 35 | 36 | def decrypt(key: bytes, iv: bytes, ciphertext: bytes, associated_data: bytes, tag: bytes) -> bytes: 37 | # Construct a Cipher object, with the key, iv, and additionally the GCM tag used for authenticating the message. 38 | decryptor = Cipher(algorithms.AES(key), modes.GCM(iv, tag), backend=default_backend()).decryptor() 39 | 40 | # We put associated_data back in or the tag will fail to verify when we finalize the decryptor. 41 | decryptor.authenticate_additional_data(associated_data) 42 | 43 | # Decryption gets us the authenticated plaintext. If the tag does not match an InvalidTag exception will be raised. 44 | return decryptor.update(ciphertext) + decryptor.finalize() 45 | 46 | 47 | if __name__ == '__main__': 48 | # The message we which to transmit in a secret fashion 49 | data = b"a secret message!" 50 | 51 | # Associated data which will be authenticated but not encrypted (must be passed into both encrypt and decrypt) 52 | aad = b"authenticated but not encrypted payload" 53 | 54 | # Generate a random 256-bit key which must be kept secret 55 | key = os.urandom(32) 56 | 57 | # Generate a random 96-bit nonce. NIST recommends a 96-bit IV length for performance, but can be up to 2^64 - 1 bits 58 | nonce = os.urandom(12) 59 | 60 | # Encrypt a secret message 61 | cipher_text, tag = encrypt(key, nonce, data, aad) 62 | 63 | # Decrypt the secret message - if GCM fails to authenticate, an InvalidTag exception is raised 64 | decrypted = decrypt(key, nonce, cipher_text, aad, tag) 65 | 66 | # So the nonce, add, and tag all get sent unencrypted along with the encrypted ciphertext. 67 | 68 | print('plain text: {!r}'.format(data)) 69 | print('ciphertext: {!r}'.format(cipher_text)) 70 | print('decrypted : {!r}'.format(decrypted)) 71 | -------------------------------------------------------------------------------- /ecdh_write_server_pub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | This is a simple example of doing an elliptic curve Diffie-Hellman ECDH) key exchange. 5 | 6 | It allows two parties to jointly agree on a shared secret using an insecure channel. 7 | 8 | NOTE: Cryptography version 2.0 in combination with very new versions of OpenSSL support a simpler 9 | interface to use Curve25519 via from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey 10 | """ 11 | import colorama 12 | from colorama import Fore 13 | from cryptography.hazmat.backends import default_backend 14 | from cryptography.hazmat.primitives.asymmetric import ec 15 | from cryptography.hazmat.primitives import serialization 16 | 17 | # Choose a particular Elliptic Curve. In a DH handshake both peers must agree on a common set of parameters. For 18 | # ECDH, this is equivalent to choosing the same curve. Curves with a size of less than 224 bits should not be used. 19 | # Generally the NIST prime filed ("P") curves are significantly faster than other types. 20 | CURVE = ec.SECP521R1() 21 | 22 | 23 | if __name__ == '__main__': 24 | colorama.init(autoreset=True) 25 | 26 | # Elliptic Curve common parameters 27 | curve = CURVE 28 | backend = default_backend() 29 | 30 | # Filenames to serialize the public and private keys to 31 | server_public_filename = 'server_public.xy' 32 | server_private_filename = 'server_private.der' 33 | 34 | # Serialization encoding, format, and encryption for the private key 35 | pri_encoding = serialization.Encoding.DER 36 | pri_format = serialization.PrivateFormat.PKCS8 37 | pri_encrypt = serialization.NoEncryption() 38 | 39 | print(Fore.CYAN + 'ECDH using Elliptic Curve {!r} with {}-bit key size and {} encoding\n'.format(curve.name, 40 | curve.key_size, 41 | pri_encoding.name)) 42 | 43 | # Generate server's private key 44 | # NOTE: Private keys can be loaded from serialized format using functions like serialization.load_pem_private_key() 45 | server_private = ec.generate_private_key(curve, backend) 46 | 47 | # Get server's public key to pass to client 48 | server_public = server_private.public_key() 49 | 50 | # Encode the elliptic curve point (public key) to a byte string (X followed by Y, each big endian) 51 | server_pub_serialized = server_public.public_numbers().encode_point()[1:] 52 | 53 | # Serialize server's private key to DER format 54 | server_pri_serialized = server_private.private_bytes(pri_encoding, pri_format, pri_encrypt) 55 | 56 | # Print out the server private key 57 | print(Fore.LIGHTMAGENTA_EX + 'Server private key ({} bytes):\n{}\n'.format(len(server_pri_serialized), 58 | server_pri_serialized.hex().upper())) 59 | 60 | # Print out the server public key 61 | print(Fore.LIGHTGREEN_EX + 'Server public key ({} bytes):\n{}\n'.format(len(server_pub_serialized), 62 | server_pub_serialized.hex().upper())) 63 | 64 | # Save data to files 65 | print('Saving server private key to {!r}'.format(server_private_filename)) 66 | with open(server_private_filename, 'wb') as server_private_file: 67 | server_private_file.write(server_pri_serialized) 68 | 69 | print('Saving server public key to {!r}'.format(server_public_filename)) 70 | with open(server_public_filename, 'wb') as server_public_file: 71 | server_public_file.write(server_pub_serialized) 72 | -------------------------------------------------------------------------------- /mbedtls/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | libmbed* 3 | *.sln 4 | *.vcxproj 5 | -------------------------------------------------------------------------------- /mbedtls/aesni.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file aesni.h 3 | * 4 | * \brief AES-NI for hardware AES acceleration on some Intel processors 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_AESNI_H 24 | #define MBEDTLS_AESNI_H 25 | 26 | #include "aes.h" 27 | 28 | #define MBEDTLS_AESNI_AES 0x02000000u 29 | #define MBEDTLS_AESNI_CLMUL 0x00000002u 30 | 31 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \ 32 | ( defined(__amd64__) || defined(__x86_64__) ) && \ 33 | ! defined(MBEDTLS_HAVE_X86_64) 34 | #define MBEDTLS_HAVE_X86_64 35 | #endif 36 | 37 | #if defined(MBEDTLS_HAVE_X86_64) 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief AES-NI features detection routine 45 | * 46 | * \param what The feature to detect 47 | * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL) 48 | * 49 | * \return 1 if CPU has support for the feature, 0 otherwise 50 | */ 51 | int mbedtls_aesni_has_support( unsigned int what ); 52 | 53 | /** 54 | * \brief AES-NI AES-ECB block en(de)cryption 55 | * 56 | * \param ctx AES context 57 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 58 | * \param input 16-byte input block 59 | * \param output 16-byte output block 60 | * 61 | * \return 0 on success (cannot fail) 62 | */ 63 | int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx, 64 | int mode, 65 | const unsigned char input[16], 66 | unsigned char output[16] ); 67 | 68 | /** 69 | * \brief GCM multiplication: c = a * b in GF(2^128) 70 | * 71 | * \param c Result 72 | * \param a First operand 73 | * \param b Second operand 74 | * 75 | * \note Both operands and result are bit strings interpreted as 76 | * elements of GF(2^128) as per the GCM spec. 77 | */ 78 | void mbedtls_aesni_gcm_mult( unsigned char c[16], 79 | const unsigned char a[16], 80 | const unsigned char b[16] ); 81 | 82 | /** 83 | * \brief Compute decryption round keys from encryption round keys 84 | * 85 | * \param invkey Round keys for the equivalent inverse cipher 86 | * \param fwdkey Original round keys (for encryption) 87 | * \param nr Number of rounds (that is, number of round keys minus one) 88 | */ 89 | void mbedtls_aesni_inverse_key( unsigned char *invkey, 90 | const unsigned char *fwdkey, int nr ); 91 | 92 | /** 93 | * \brief Perform key expansion (for encryption) 94 | * 95 | * \param rk Destination buffer where the round keys are written 96 | * \param key Encryption key 97 | * \param bits Key size in bits (must be 128, 192 or 256) 98 | * 99 | * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH 100 | */ 101 | int mbedtls_aesni_setkey_enc( unsigned char *rk, 102 | const unsigned char *key, 103 | size_t bits ); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* MBEDTLS_HAVE_X86_64 */ 110 | 111 | #endif /* MBEDTLS_AESNI_H */ 112 | -------------------------------------------------------------------------------- /mbedtls/arc4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file arc4.h 3 | * 4 | * \brief The ARCFOUR stream cipher 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ARC4_H 24 | #define MBEDTLS_ARC4_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #if !defined(MBEDTLS_ARC4_ALT) 35 | // Regular implementation 36 | // 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief ARC4 context structure 44 | */ 45 | typedef struct 46 | { 47 | int x; /*!< permutation index */ 48 | int y; /*!< permutation index */ 49 | unsigned char m[256]; /*!< permutation table */ 50 | } 51 | mbedtls_arc4_context; 52 | 53 | /** 54 | * \brief Initialize ARC4 context 55 | * 56 | * \param ctx ARC4 context to be initialized 57 | */ 58 | void mbedtls_arc4_init( mbedtls_arc4_context *ctx ); 59 | 60 | /** 61 | * \brief Clear ARC4 context 62 | * 63 | * \param ctx ARC4 context to be cleared 64 | */ 65 | void mbedtls_arc4_free( mbedtls_arc4_context *ctx ); 66 | 67 | /** 68 | * \brief ARC4 key schedule 69 | * 70 | * \param ctx ARC4 context to be setup 71 | * \param key the secret key 72 | * \param keylen length of the key, in bytes 73 | */ 74 | void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key, 75 | unsigned int keylen ); 76 | 77 | /** 78 | * \brief ARC4 cipher function 79 | * 80 | * \param ctx ARC4 context 81 | * \param length length of the input data 82 | * \param input buffer holding the input data 83 | * \param output buffer for the output data 84 | * 85 | * \return 0 if successful 86 | */ 87 | int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input, 88 | unsigned char *output ); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #else /* MBEDTLS_ARC4_ALT */ 95 | #include "arc4_alt.h" 96 | #endif /* MBEDTLS_ARC4_ALT */ 97 | 98 | #ifdef __cplusplus 99 | extern "C" { 100 | #endif 101 | 102 | /** 103 | * \brief Checkup routine 104 | * 105 | * \return 0 if successful, or 1 if the test failed 106 | */ 107 | int mbedtls_arc4_self_test( int verbose ); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* arc4.h */ 114 | -------------------------------------------------------------------------------- /mbedtls/base64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file base64.h 3 | * 4 | * \brief RFC 1521 base64 encoding/decoding 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_BASE64_H 24 | #define MBEDTLS_BASE64_H 25 | 26 | #include 27 | 28 | #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ 29 | #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /** 36 | * \brief Encode a buffer into base64 format 37 | * 38 | * \param dst destination buffer 39 | * \param dlen size of the destination buffer 40 | * \param olen number of bytes written 41 | * \param src source buffer 42 | * \param slen amount of data to be encoded 43 | * 44 | * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL. 45 | * *olen is always updated to reflect the amount 46 | * of data that has (or would have) been written. 47 | * If that length cannot be represented, then no data is 48 | * written to the buffer and *olen is set to the maximum 49 | * length representable as a size_t. 50 | * 51 | * \note Call this function with dlen = 0 to obtain the 52 | * required buffer size in *olen 53 | */ 54 | int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, 55 | const unsigned char *src, size_t slen ); 56 | 57 | /** 58 | * \brief Decode a base64-formatted buffer 59 | * 60 | * \param dst destination buffer (can be NULL for checking size) 61 | * \param dlen size of the destination buffer 62 | * \param olen number of bytes written 63 | * \param src source buffer 64 | * \param slen amount of data to be decoded 65 | * 66 | * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or 67 | * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is 68 | * not correct. *olen is always updated to reflect the amount 69 | * of data that has (or would have) been written. 70 | * 71 | * \note Call this function with *dst = NULL or dlen = 0 to obtain 72 | * the required buffer size in *olen 73 | */ 74 | int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, 75 | const unsigned char *src, size_t slen ); 76 | 77 | /** 78 | * \brief Checkup routine 79 | * 80 | * \return 0 if successful, or 1 if the test failed 81 | */ 82 | int mbedtls_base64_self_test( int verbose ); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* base64.h */ 89 | -------------------------------------------------------------------------------- /mbedtls/certs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file certs.h 3 | * 4 | * \brief Sample certificates and DHM parameters for testing 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_CERTS_H 24 | #define MBEDTLS_CERTS_H 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #if defined(MBEDTLS_PEM_PARSE_C) 33 | /* Concatenation of all CA certificates in PEM format if available */ 34 | extern const char mbedtls_test_cas_pem[]; 35 | extern const size_t mbedtls_test_cas_pem_len; 36 | #endif 37 | 38 | /* List of all CA certificates, terminated by NULL */ 39 | extern const char * mbedtls_test_cas[]; 40 | extern const size_t mbedtls_test_cas_len[]; 41 | 42 | /* 43 | * Convenience for users who just want a certificate: 44 | * RSA by default, or ECDSA if RSA is not available 45 | */ 46 | extern const char * mbedtls_test_ca_crt; 47 | extern const size_t mbedtls_test_ca_crt_len; 48 | extern const char * mbedtls_test_ca_key; 49 | extern const size_t mbedtls_test_ca_key_len; 50 | extern const char * mbedtls_test_ca_pwd; 51 | extern const size_t mbedtls_test_ca_pwd_len; 52 | extern const char * mbedtls_test_srv_crt; 53 | extern const size_t mbedtls_test_srv_crt_len; 54 | extern const char * mbedtls_test_srv_key; 55 | extern const size_t mbedtls_test_srv_key_len; 56 | extern const char * mbedtls_test_cli_crt; 57 | extern const size_t mbedtls_test_cli_crt_len; 58 | extern const char * mbedtls_test_cli_key; 59 | extern const size_t mbedtls_test_cli_key_len; 60 | 61 | #if defined(MBEDTLS_ECDSA_C) 62 | extern const char mbedtls_test_ca_crt_ec[]; 63 | extern const size_t mbedtls_test_ca_crt_ec_len; 64 | extern const char mbedtls_test_ca_key_ec[]; 65 | extern const size_t mbedtls_test_ca_key_ec_len; 66 | extern const char mbedtls_test_ca_pwd_ec[]; 67 | extern const size_t mbedtls_test_ca_pwd_ec_len; 68 | extern const char mbedtls_test_srv_crt_ec[]; 69 | extern const size_t mbedtls_test_srv_crt_ec_len; 70 | extern const char mbedtls_test_srv_key_ec[]; 71 | extern const size_t mbedtls_test_srv_key_ec_len; 72 | extern const char mbedtls_test_cli_crt_ec[]; 73 | extern const size_t mbedtls_test_cli_crt_ec_len; 74 | extern const char mbedtls_test_cli_key_ec[]; 75 | extern const size_t mbedtls_test_cli_key_ec_len; 76 | #endif 77 | 78 | #if defined(MBEDTLS_RSA_C) 79 | extern const char mbedtls_test_ca_crt_rsa[]; 80 | extern const size_t mbedtls_test_ca_crt_rsa_len; 81 | extern const char mbedtls_test_ca_key_rsa[]; 82 | extern const size_t mbedtls_test_ca_key_rsa_len; 83 | extern const char mbedtls_test_ca_pwd_rsa[]; 84 | extern const size_t mbedtls_test_ca_pwd_rsa_len; 85 | extern const char mbedtls_test_srv_crt_rsa[]; 86 | extern const size_t mbedtls_test_srv_crt_rsa_len; 87 | extern const char mbedtls_test_srv_key_rsa[]; 88 | extern const size_t mbedtls_test_srv_key_rsa_len; 89 | extern const char mbedtls_test_cli_crt_rsa[]; 90 | extern const size_t mbedtls_test_cli_crt_rsa_len; 91 | extern const char mbedtls_test_cli_key_rsa[]; 92 | extern const size_t mbedtls_test_cli_key_rsa_len; 93 | #endif 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* certs.h */ 100 | -------------------------------------------------------------------------------- /mbedtls/cipher_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file cipher_internal.h 3 | * 4 | * \brief Cipher wrappers. 5 | * 6 | * \author Adriaan de Jong 7 | * 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * This file is part of mbed TLS (https://tls.mbed.org) 24 | */ 25 | #ifndef MBEDTLS_CIPHER_WRAP_H 26 | #define MBEDTLS_CIPHER_WRAP_H 27 | 28 | #if !defined(MBEDTLS_CONFIG_FILE) 29 | #include "config.h" 30 | #else 31 | #include MBEDTLS_CONFIG_FILE 32 | #endif 33 | 34 | #include "cipher.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * Base cipher information. The non-mode specific functions and values. 42 | */ 43 | struct mbedtls_cipher_base_t 44 | { 45 | /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */ 46 | mbedtls_cipher_id_t cipher; 47 | 48 | /** Encrypt using ECB */ 49 | int (*ecb_func)( void *ctx, mbedtls_operation_t mode, 50 | const unsigned char *input, unsigned char *output ); 51 | 52 | #if defined(MBEDTLS_CIPHER_MODE_CBC) 53 | /** Encrypt using CBC */ 54 | int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length, 55 | unsigned char *iv, const unsigned char *input, 56 | unsigned char *output ); 57 | #endif 58 | 59 | #if defined(MBEDTLS_CIPHER_MODE_CFB) 60 | /** Encrypt using CFB (Full length) */ 61 | int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off, 62 | unsigned char *iv, const unsigned char *input, 63 | unsigned char *output ); 64 | #endif 65 | 66 | #if defined(MBEDTLS_CIPHER_MODE_CTR) 67 | /** Encrypt using CTR */ 68 | int (*ctr_func)( void *ctx, size_t length, size_t *nc_off, 69 | unsigned char *nonce_counter, unsigned char *stream_block, 70 | const unsigned char *input, unsigned char *output ); 71 | #endif 72 | 73 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) 74 | /** Encrypt using STREAM */ 75 | int (*stream_func)( void *ctx, size_t length, 76 | const unsigned char *input, unsigned char *output ); 77 | #endif 78 | 79 | /** Set key for encryption purposes */ 80 | int (*setkey_enc_func)( void *ctx, const unsigned char *key, 81 | unsigned int key_bitlen ); 82 | 83 | /** Set key for decryption purposes */ 84 | int (*setkey_dec_func)( void *ctx, const unsigned char *key, 85 | unsigned int key_bitlen); 86 | 87 | /** Allocate a new context */ 88 | void * (*ctx_alloc_func)( void ); 89 | 90 | /** Free the given context */ 91 | void (*ctx_free_func)( void *ctx ); 92 | 93 | }; 94 | 95 | typedef struct 96 | { 97 | mbedtls_cipher_type_t type; 98 | const mbedtls_cipher_info_t *info; 99 | } mbedtls_cipher_definition_t; 100 | 101 | extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[]; 102 | 103 | extern int mbedtls_cipher_supported[]; 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* MBEDTLS_CIPHER_WRAP_H */ 110 | -------------------------------------------------------------------------------- /mbedtls/entropy_poll.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file entropy_poll.h 3 | * 4 | * \brief Platform-specific and custom entropy polling functions 5 | * 6 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ENTROPY_POLL_H 24 | #define MBEDTLS_ENTROPY_POLL_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /* 39 | * Default thresholds for built-in sources, in bytes 40 | */ 41 | #define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */ 42 | #define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */ 43 | #define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */ 44 | #if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE) 45 | #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */ 46 | #endif 47 | 48 | /** 49 | * \brief Entropy poll callback that provides 0 entropy. 50 | */ 51 | #if defined(MBEDTLS_TEST_NULL_ENTROPY) 52 | int mbedtls_null_entropy_poll( void *data, 53 | unsigned char *output, size_t len, size_t *olen ); 54 | #endif 55 | 56 | #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) 57 | /** 58 | * \brief Platform-specific entropy poll callback 59 | */ 60 | int mbedtls_platform_entropy_poll( void *data, 61 | unsigned char *output, size_t len, size_t *olen ); 62 | #endif 63 | 64 | #if defined(MBEDTLS_HAVEGE_C) 65 | /** 66 | * \brief HAVEGE based entropy poll callback 67 | * 68 | * Requires an HAVEGE state as its data pointer. 69 | */ 70 | int mbedtls_havege_poll( void *data, 71 | unsigned char *output, size_t len, size_t *olen ); 72 | #endif 73 | 74 | #if defined(MBEDTLS_TIMING_C) 75 | /** 76 | * \brief mbedtls_timing_hardclock-based entropy poll callback 77 | */ 78 | int mbedtls_hardclock_poll( void *data, 79 | unsigned char *output, size_t len, size_t *olen ); 80 | #endif 81 | 82 | #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) 83 | /** 84 | * \brief Entropy poll callback for a hardware source 85 | * 86 | * \warning This is not provided by mbed TLS! 87 | * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h. 88 | * 89 | * \note This must accept NULL as its first argument. 90 | */ 91 | int mbedtls_hardware_poll( void *data, 92 | unsigned char *output, size_t len, size_t *olen ); 93 | #endif 94 | 95 | #if defined(MBEDTLS_ENTROPY_NV_SEED) 96 | /** 97 | * \brief Entropy poll callback for a non-volatile seed file 98 | * 99 | * \note This must accept NULL as its first argument. 100 | */ 101 | int mbedtls_nv_seed_poll( void *data, 102 | unsigned char *output, size_t len, size_t *olen ); 103 | #endif 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* entropy_poll.h */ 110 | -------------------------------------------------------------------------------- /mbedtls/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file error.h 3 | * 4 | * \brief Error to string translation 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_ERROR_H 24 | #define MBEDTLS_ERROR_H 25 | 26 | #include 27 | 28 | /** 29 | * Error code layout. 30 | * 31 | * Currently we try to keep all error codes within the negative space of 16 32 | * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In 33 | * addition we'd like to give two layers of information on the error if 34 | * possible. 35 | * 36 | * For that purpose the error codes are segmented in the following manner: 37 | * 38 | * 16 bit error code bit-segmentation 39 | * 40 | * 1 bit - Unused (sign bit) 41 | * 3 bits - High level module ID 42 | * 5 bits - Module-dependent error code 43 | * 7 bits - Low level module errors 44 | * 45 | * For historical reasons, low-level error codes are divided in even and odd, 46 | * even codes were assigned first, and -1 is reserved for other errors. 47 | * 48 | * Low-level module errors (0x0002-0x007E, 0x0003-0x007F) 49 | * 50 | * Module Nr Codes assigned 51 | * MPI 7 0x0002-0x0010 52 | * GCM 2 0x0012-0x0014 53 | * BLOWFISH 2 0x0016-0x0018 54 | * THREADING 3 0x001A-0x001E 55 | * AES 2 0x0020-0x0022 56 | * CAMELLIA 2 0x0024-0x0026 57 | * XTEA 1 0x0028-0x0028 58 | * BASE64 2 0x002A-0x002C 59 | * OID 1 0x002E-0x002E 0x000B-0x000B 60 | * PADLOCK 1 0x0030-0x0030 61 | * DES 1 0x0032-0x0032 62 | * CTR_DBRG 4 0x0034-0x003A 63 | * ENTROPY 3 0x003C-0x0040 0x003D-0x003F 64 | * NET 11 0x0042-0x0052 0x0043-0x0045 65 | * ASN1 7 0x0060-0x006C 66 | * PBKDF2 1 0x007C-0x007C 67 | * HMAC_DRBG 4 0x0003-0x0009 68 | * CCM 2 0x000D-0x000F 69 | * 70 | * High-level module nr (3 bits - 0x0...-0x7...) 71 | * Name ID Nr of Errors 72 | * PEM 1 9 73 | * PKCS#12 1 4 (Started from top) 74 | * X509 2 20 75 | * PKCS5 2 4 (Started from top) 76 | * DHM 3 9 77 | * PK 3 14 (Started from top) 78 | * RSA 4 9 79 | * ECP 4 8 (Started from top) 80 | * MD 5 4 81 | * CIPHER 6 6 82 | * SSL 6 17 (Started from top) 83 | * SSL 7 31 84 | * 85 | * Module dependent error code (5 bits 0x.00.-0x.F8.) 86 | */ 87 | 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | 92 | /** 93 | * \brief Translate a mbed TLS error code into a string representation, 94 | * Result is truncated if necessary and always includes a terminating 95 | * null byte. 96 | * 97 | * \param errnum error code 98 | * \param buffer buffer to place representation in 99 | * \param buflen length of the buffer 100 | */ 101 | void mbedtls_strerror( int errnum, char *buffer, size_t buflen ); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* error.h */ 108 | -------------------------------------------------------------------------------- /mbedtls/havege.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file havege.h 3 | * 4 | * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_HAVEGE_H 24 | #define MBEDTLS_HAVEGE_H 25 | 26 | #include 27 | 28 | #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief HAVEGE state structure 36 | */ 37 | typedef struct 38 | { 39 | int PT1, PT2, offset[2]; 40 | int pool[MBEDTLS_HAVEGE_COLLECT_SIZE]; 41 | int WALK[8192]; 42 | } 43 | mbedtls_havege_state; 44 | 45 | /** 46 | * \brief HAVEGE initialization 47 | * 48 | * \param hs HAVEGE state to be initialized 49 | */ 50 | void mbedtls_havege_init( mbedtls_havege_state *hs ); 51 | 52 | /** 53 | * \brief Clear HAVEGE state 54 | * 55 | * \param hs HAVEGE state to be cleared 56 | */ 57 | void mbedtls_havege_free( mbedtls_havege_state *hs ); 58 | 59 | /** 60 | * \brief HAVEGE rand function 61 | * 62 | * \param p_rng A HAVEGE state 63 | * \param output Buffer to fill 64 | * \param len Length of buffer 65 | * 66 | * \return 0 67 | */ 68 | int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len ); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* havege.h */ 75 | -------------------------------------------------------------------------------- /mbedtls/md2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md2.h 3 | * 4 | * \brief MD2 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_MD2_H 24 | #define MBEDTLS_MD2_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #if !defined(MBEDTLS_MD2_ALT) 35 | // Regular implementation 36 | // 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief MD2 context structure 44 | */ 45 | typedef struct 46 | { 47 | unsigned char cksum[16]; /*!< checksum of the data block */ 48 | unsigned char state[48]; /*!< intermediate digest state */ 49 | unsigned char buffer[16]; /*!< data block being processed */ 50 | size_t left; /*!< amount of data in buffer */ 51 | } 52 | mbedtls_md2_context; 53 | 54 | /** 55 | * \brief Initialize MD2 context 56 | * 57 | * \param ctx MD2 context to be initialized 58 | */ 59 | void mbedtls_md2_init( mbedtls_md2_context *ctx ); 60 | 61 | /** 62 | * \brief Clear MD2 context 63 | * 64 | * \param ctx MD2 context to be cleared 65 | */ 66 | void mbedtls_md2_free( mbedtls_md2_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an MD2 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_md2_clone( mbedtls_md2_context *dst, 75 | const mbedtls_md2_context *src ); 76 | 77 | /** 78 | * \brief MD2 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_md2_starts( mbedtls_md2_context *ctx ); 83 | 84 | /** 85 | * \brief MD2 process buffer 86 | * 87 | * \param ctx MD2 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief MD2 final digest 95 | * 96 | * \param ctx MD2 context 97 | * \param output MD2 checksum result 98 | */ 99 | void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #else /* MBEDTLS_MD2_ALT */ 106 | #include "md2_alt.h" 107 | #endif /* MBEDTLS_MD2_ALT */ 108 | 109 | #ifdef __cplusplus 110 | extern "C" { 111 | #endif 112 | 113 | /** 114 | * \brief Output = MD2( input buffer ) 115 | * 116 | * \param input buffer holding the data 117 | * \param ilen length of the input data 118 | * \param output MD2 checksum result 119 | */ 120 | void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] ); 121 | 122 | /** 123 | * \brief Checkup routine 124 | * 125 | * \return 0 if successful, or 1 if the test failed 126 | */ 127 | int mbedtls_md2_self_test( int verbose ); 128 | 129 | /* Internal use */ 130 | void mbedtls_md2_process( mbedtls_md2_context *ctx ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_md2.h */ 137 | -------------------------------------------------------------------------------- /mbedtls/md4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md4.h 3 | * 4 | * \brief MD4 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_MD4_H 24 | #define MBEDTLS_MD4_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_MD4_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief MD4 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[4]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_md4_context; 53 | 54 | /** 55 | * \brief Initialize MD4 context 56 | * 57 | * \param ctx MD4 context to be initialized 58 | */ 59 | void mbedtls_md4_init( mbedtls_md4_context *ctx ); 60 | 61 | /** 62 | * \brief Clear MD4 context 63 | * 64 | * \param ctx MD4 context to be cleared 65 | */ 66 | void mbedtls_md4_free( mbedtls_md4_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an MD4 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_md4_clone( mbedtls_md4_context *dst, 75 | const mbedtls_md4_context *src ); 76 | 77 | /** 78 | * \brief MD4 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_md4_starts( mbedtls_md4_context *ctx ); 83 | 84 | /** 85 | * \brief MD4 process buffer 86 | * 87 | * \param ctx MD4 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_md4_update( mbedtls_md4_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief MD4 final digest 95 | * 96 | * \param ctx MD4 context 97 | * \param output MD4 checksum result 98 | */ 99 | void mbedtls_md4_finish( mbedtls_md4_context *ctx, unsigned char output[16] ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #else /* MBEDTLS_MD4_ALT */ 106 | #include "md4_alt.h" 107 | #endif /* MBEDTLS_MD4_ALT */ 108 | 109 | #ifdef __cplusplus 110 | extern "C" { 111 | #endif 112 | 113 | /** 114 | * \brief Output = MD4( input buffer ) 115 | * 116 | * \param input buffer holding the data 117 | * \param ilen length of the input data 118 | * \param output MD4 checksum result 119 | */ 120 | void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] ); 121 | 122 | /** 123 | * \brief Checkup routine 124 | * 125 | * \return 0 if successful, or 1 if the test failed 126 | */ 127 | int mbedtls_md4_self_test( int verbose ); 128 | 129 | /* Internal use */ 130 | void mbedtls_md4_process( mbedtls_md4_context *ctx, const unsigned char data[64] ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_md4.h */ 137 | -------------------------------------------------------------------------------- /mbedtls/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md5.h 3 | * 4 | * \brief MD5 message digest algorithm (hash function) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_MD5_H 24 | #define MBEDTLS_MD5_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_MD5_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief MD5 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[4]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_md5_context; 53 | 54 | /** 55 | * \brief Initialize MD5 context 56 | * 57 | * \param ctx MD5 context to be initialized 58 | */ 59 | void mbedtls_md5_init( mbedtls_md5_context *ctx ); 60 | 61 | /** 62 | * \brief Clear MD5 context 63 | * 64 | * \param ctx MD5 context to be cleared 65 | */ 66 | void mbedtls_md5_free( mbedtls_md5_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an MD5 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_md5_clone( mbedtls_md5_context *dst, 75 | const mbedtls_md5_context *src ); 76 | 77 | /** 78 | * \brief MD5 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_md5_starts( mbedtls_md5_context *ctx ); 83 | 84 | /** 85 | * \brief MD5 process buffer 86 | * 87 | * \param ctx MD5 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief MD5 final digest 95 | * 96 | * \param ctx MD5 context 97 | * \param output MD5 checksum result 98 | */ 99 | void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] ); 100 | 101 | /* Internal use */ 102 | void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] ); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #else /* MBEDTLS_MD5_ALT */ 109 | #include "md5_alt.h" 110 | #endif /* MBEDTLS_MD5_ALT */ 111 | 112 | #ifdef __cplusplus 113 | extern "C" { 114 | #endif 115 | 116 | /** 117 | * \brief Output = MD5( input buffer ) 118 | * 119 | * \param input buffer holding the data 120 | * \param ilen length of the input data 121 | * \param output MD5 checksum result 122 | */ 123 | void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] ); 124 | 125 | /** 126 | * \brief Checkup routine 127 | * 128 | * \return 0 if successful, or 1 if the test failed 129 | */ 130 | int mbedtls_md5_self_test( int verbose ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_md5.h */ 137 | -------------------------------------------------------------------------------- /mbedtls/md_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md_internal.h 3 | * 4 | * \brief Message digest wrappers. 5 | * 6 | * \warning This in an internal header. Do not include directly. 7 | * 8 | * \author Adriaan de Jong 9 | * 10 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 11 | * SPDX-License-Identifier: Apache-2.0 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 14 | * not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | * This file is part of mbed TLS (https://tls.mbed.org) 26 | */ 27 | #ifndef MBEDTLS_MD_WRAP_H 28 | #define MBEDTLS_MD_WRAP_H 29 | 30 | #if !defined(MBEDTLS_CONFIG_FILE) 31 | #include "config.h" 32 | #else 33 | #include MBEDTLS_CONFIG_FILE 34 | #endif 35 | 36 | #include "md.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * Message digest information. 44 | * Allows message digest functions to be called in a generic way. 45 | */ 46 | struct mbedtls_md_info_t 47 | { 48 | /** Digest identifier */ 49 | mbedtls_md_type_t type; 50 | 51 | /** Name of the message digest */ 52 | const char * name; 53 | 54 | /** Output length of the digest function in bytes */ 55 | int size; 56 | 57 | /** Block length of the digest function in bytes */ 58 | int block_size; 59 | 60 | /** Digest initialisation function */ 61 | void (*starts_func)( void *ctx ); 62 | 63 | /** Digest update function */ 64 | void (*update_func)( void *ctx, const unsigned char *input, size_t ilen ); 65 | 66 | /** Digest finalisation function */ 67 | void (*finish_func)( void *ctx, unsigned char *output ); 68 | 69 | /** Generic digest function */ 70 | void (*digest_func)( const unsigned char *input, size_t ilen, 71 | unsigned char *output ); 72 | 73 | /** Allocate a new context */ 74 | void * (*ctx_alloc_func)( void ); 75 | 76 | /** Free the given context */ 77 | void (*ctx_free_func)( void *ctx ); 78 | 79 | /** Clone state from a context */ 80 | void (*clone_func)( void *dst, const void *src ); 81 | 82 | /** Internal use only */ 83 | void (*process_func)( void *ctx, const unsigned char *input ); 84 | }; 85 | 86 | #if defined(MBEDTLS_MD2_C) 87 | extern const mbedtls_md_info_t mbedtls_md2_info; 88 | #endif 89 | #if defined(MBEDTLS_MD4_C) 90 | extern const mbedtls_md_info_t mbedtls_md4_info; 91 | #endif 92 | #if defined(MBEDTLS_MD5_C) 93 | extern const mbedtls_md_info_t mbedtls_md5_info; 94 | #endif 95 | #if defined(MBEDTLS_RIPEMD160_C) 96 | extern const mbedtls_md_info_t mbedtls_ripemd160_info; 97 | #endif 98 | #if defined(MBEDTLS_SHA1_C) 99 | extern const mbedtls_md_info_t mbedtls_sha1_info; 100 | #endif 101 | #if defined(MBEDTLS_SHA256_C) 102 | extern const mbedtls_md_info_t mbedtls_sha224_info; 103 | extern const mbedtls_md_info_t mbedtls_sha256_info; 104 | #endif 105 | #if defined(MBEDTLS_SHA512_C) 106 | extern const mbedtls_md_info_t mbedtls_sha384_info; 107 | extern const mbedtls_md_info_t mbedtls_sha512_info; 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* MBEDTLS_MD_WRAP_H */ 115 | -------------------------------------------------------------------------------- /mbedtls/net.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file net.h 3 | * 4 | * \brief Deprecated header file that includes mbedtls/net_sockets.h 5 | * 6 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | * 23 | * \deprecated Superseded by mbedtls/net_sockets.h 24 | */ 25 | 26 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) 27 | #include "mbedtls/net_sockets.h" 28 | #if defined(MBEDTLS_DEPRECATED_WARNING) 29 | #warning "Deprecated header file: Superseded by mbedtls/net_sockets.h" 30 | #endif /* MBEDTLS_DEPRECATED_WARNING */ 31 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 32 | -------------------------------------------------------------------------------- /mbedtls/padlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file padlock.h 3 | * 4 | * \brief VIA PadLock ACE for HW encryption/decryption supported by some 5 | * processors 6 | * 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 8 | * SPDX-License-Identifier: Apache-2.0 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 11 | * not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * 22 | * This file is part of mbed TLS (https://tls.mbed.org) 23 | */ 24 | #ifndef MBEDTLS_PADLOCK_H 25 | #define MBEDTLS_PADLOCK_H 26 | 27 | #include "aes.h" 28 | 29 | #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ 30 | 31 | #if defined(__has_feature) 32 | #if __has_feature(address_sanitizer) 33 | #define MBEDTLS_HAVE_ASAN 34 | #endif 35 | #endif 36 | 37 | /* Some versions of ASan result in errors about not enough registers */ 38 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \ 39 | !defined(MBEDTLS_HAVE_ASAN) 40 | 41 | #ifndef MBEDTLS_HAVE_X86 42 | #define MBEDTLS_HAVE_X86 43 | #endif 44 | 45 | #include 46 | 47 | #define MBEDTLS_PADLOCK_RNG 0x000C 48 | #define MBEDTLS_PADLOCK_ACE 0x00C0 49 | #define MBEDTLS_PADLOCK_PHE 0x0C00 50 | #define MBEDTLS_PADLOCK_PMM 0x3000 51 | 52 | #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15)) 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /** 59 | * \brief PadLock detection routine 60 | * 61 | * \param feature The feature to detect 62 | * 63 | * \return 1 if CPU has support for the feature, 0 otherwise 64 | */ 65 | int mbedtls_padlock_has_support( int feature ); 66 | 67 | /** 68 | * \brief PadLock AES-ECB block en(de)cryption 69 | * 70 | * \param ctx AES context 71 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 72 | * \param input 16-byte input block 73 | * \param output 16-byte output block 74 | * 75 | * \return 0 if success, 1 if operation failed 76 | */ 77 | int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, 78 | int mode, 79 | const unsigned char input[16], 80 | unsigned char output[16] ); 81 | 82 | /** 83 | * \brief PadLock AES-CBC buffer en(de)cryption 84 | * 85 | * \param ctx AES context 86 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT 87 | * \param length length of the input data 88 | * \param iv initialization vector (updated after use) 89 | * \param input buffer holding the input data 90 | * \param output buffer holding the output data 91 | * 92 | * \return 0 if success, 1 if operation failed 93 | */ 94 | int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, 95 | int mode, 96 | size_t length, 97 | unsigned char iv[16], 98 | const unsigned char *input, 99 | unsigned char *output ); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* HAVE_X86 */ 106 | 107 | #endif /* padlock.h */ 108 | -------------------------------------------------------------------------------- /mbedtls/pk_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pk.h 3 | * 4 | * \brief Public Key abstraction layer: wrapper functions 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | 24 | #ifndef MBEDTLS_PK_WRAP_H 25 | #define MBEDTLS_PK_WRAP_H 26 | 27 | #if !defined(MBEDTLS_CONFIG_FILE) 28 | #include "config.h" 29 | #else 30 | #include MBEDTLS_CONFIG_FILE 31 | #endif 32 | 33 | #include "pk.h" 34 | 35 | struct mbedtls_pk_info_t 36 | { 37 | /** Public key type */ 38 | mbedtls_pk_type_t type; 39 | 40 | /** Type name */ 41 | const char *name; 42 | 43 | /** Get key size in bits */ 44 | size_t (*get_bitlen)( const void * ); 45 | 46 | /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */ 47 | int (*can_do)( mbedtls_pk_type_t type ); 48 | 49 | /** Verify signature */ 50 | int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg, 51 | const unsigned char *hash, size_t hash_len, 52 | const unsigned char *sig, size_t sig_len ); 53 | 54 | /** Make signature */ 55 | int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg, 56 | const unsigned char *hash, size_t hash_len, 57 | unsigned char *sig, size_t *sig_len, 58 | int (*f_rng)(void *, unsigned char *, size_t), 59 | void *p_rng ); 60 | 61 | /** Decrypt message */ 62 | int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, 63 | unsigned char *output, size_t *olen, size_t osize, 64 | int (*f_rng)(void *, unsigned char *, size_t), 65 | void *p_rng ); 66 | 67 | /** Encrypt message */ 68 | int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, 69 | unsigned char *output, size_t *olen, size_t osize, 70 | int (*f_rng)(void *, unsigned char *, size_t), 71 | void *p_rng ); 72 | 73 | /** Check public-private key pair */ 74 | int (*check_pair_func)( const void *pub, const void *prv ); 75 | 76 | /** Allocate a new context */ 77 | void * (*ctx_alloc_func)( void ); 78 | 79 | /** Free the given context */ 80 | void (*ctx_free_func)( void *ctx ); 81 | 82 | /** Interface with the debug module */ 83 | void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); 84 | 85 | }; 86 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) 87 | /* Container for RSA-alt */ 88 | typedef struct 89 | { 90 | void *key; 91 | mbedtls_pk_rsa_alt_decrypt_func decrypt_func; 92 | mbedtls_pk_rsa_alt_sign_func sign_func; 93 | mbedtls_pk_rsa_alt_key_len_func key_len_func; 94 | } mbedtls_rsa_alt_context; 95 | #endif 96 | 97 | #if defined(MBEDTLS_RSA_C) 98 | extern const mbedtls_pk_info_t mbedtls_rsa_info; 99 | #endif 100 | 101 | #if defined(MBEDTLS_ECP_C) 102 | extern const mbedtls_pk_info_t mbedtls_eckey_info; 103 | extern const mbedtls_pk_info_t mbedtls_eckeydh_info; 104 | #endif 105 | 106 | #if defined(MBEDTLS_ECDSA_C) 107 | extern const mbedtls_pk_info_t mbedtls_ecdsa_info; 108 | #endif 109 | 110 | #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) 111 | extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; 112 | #endif 113 | 114 | #endif /* MBEDTLS_PK_WRAP_H */ 115 | -------------------------------------------------------------------------------- /mbedtls/pkcs5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pkcs5.h 3 | * 4 | * \brief PKCS#5 functions 5 | * 6 | * \author Mathias Olsson 7 | * 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * This file is part of mbed TLS (https://tls.mbed.org) 24 | */ 25 | #ifndef MBEDTLS_PKCS5_H 26 | #define MBEDTLS_PKCS5_H 27 | 28 | #include "asn1.h" 29 | #include "md.h" 30 | 31 | #include 32 | #include 33 | 34 | #define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */ 35 | #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */ 36 | #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */ 37 | #define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */ 38 | 39 | #define MBEDTLS_PKCS5_DECRYPT 0 40 | #define MBEDTLS_PKCS5_ENCRYPT 1 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** 47 | * \brief PKCS#5 PBES2 function 48 | * 49 | * \param pbe_params the ASN.1 algorithm parameters 50 | * \param mode either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT 51 | * \param pwd password to use when generating key 52 | * \param pwdlen length of password 53 | * \param data data to process 54 | * \param datalen length of data 55 | * \param output output buffer 56 | * 57 | * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails. 58 | */ 59 | int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, 60 | const unsigned char *pwd, size_t pwdlen, 61 | const unsigned char *data, size_t datalen, 62 | unsigned char *output ); 63 | 64 | /** 65 | * \brief PKCS#5 PBKDF2 using HMAC 66 | * 67 | * \param ctx Generic HMAC context 68 | * \param password Password to use when generating key 69 | * \param plen Length of password 70 | * \param salt Salt to use when generating key 71 | * \param slen Length of salt 72 | * \param iteration_count Iteration count 73 | * \param key_length Length of generated key in bytes 74 | * \param output Generated key. Must be at least as big as key_length 75 | * 76 | * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails. 77 | */ 78 | int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password, 79 | size_t plen, const unsigned char *salt, size_t slen, 80 | unsigned int iteration_count, 81 | uint32_t key_length, unsigned char *output ); 82 | 83 | /** 84 | * \brief Checkup routine 85 | * 86 | * \return 0 if successful, or 1 if the test failed 87 | */ 88 | int mbedtls_pkcs5_self_test( int verbose ); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* pkcs5.h */ 95 | -------------------------------------------------------------------------------- /mbedtls/platform_time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file platform_time.h 3 | * 4 | * \brief mbed TLS Platform time abstraction 5 | * 6 | * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_PLATFORM_TIME_H 24 | #define MBEDTLS_PLATFORM_TIME_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /** 37 | * \name SECTION: Module settings 38 | * 39 | * The configuration options you can set for this module are in this section. 40 | * Either change them in config.h or define them on the compiler command line. 41 | * \{ 42 | */ 43 | 44 | /* 45 | * The time_t datatype 46 | */ 47 | #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) 48 | typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t; 49 | #else 50 | /* For time_t */ 51 | #include 52 | typedef time_t mbedtls_time_t; 53 | #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */ 54 | 55 | /* 56 | * The function pointers for time 57 | */ 58 | #if defined(MBEDTLS_PLATFORM_TIME_ALT) 59 | extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time ); 60 | 61 | /** 62 | * \brief Set your own time function pointer 63 | * 64 | * \param time_func the time function implementation 65 | * 66 | * \return 0 67 | */ 68 | int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) ); 69 | #else 70 | #if defined(MBEDTLS_PLATFORM_TIME_MACRO) 71 | #define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO 72 | #else 73 | #define mbedtls_time time 74 | #endif /* MBEDTLS_PLATFORM_TIME_MACRO */ 75 | #endif /* MBEDTLS_PLATFORM_TIME_ALT */ 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* platform_time.h */ 82 | -------------------------------------------------------------------------------- /mbedtls/ripemd160.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ripemd160.h 3 | * 4 | * \brief RIPE MD-160 message digest 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_RIPEMD160_H 24 | #define MBEDTLS_RIPEMD160_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_RIPEMD160_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief RIPEMD-160 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[5]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_ripemd160_context; 53 | 54 | /** 55 | * \brief Initialize RIPEMD-160 context 56 | * 57 | * \param ctx RIPEMD-160 context to be initialized 58 | */ 59 | void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); 60 | 61 | /** 62 | * \brief Clear RIPEMD-160 context 63 | * 64 | * \param ctx RIPEMD-160 context to be cleared 65 | */ 66 | void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) an RIPEMD-160 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, 75 | const mbedtls_ripemd160_context *src ); 76 | 77 | /** 78 | * \brief RIPEMD-160 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_ripemd160_starts( mbedtls_ripemd160_context *ctx ); 83 | 84 | /** 85 | * \brief RIPEMD-160 process buffer 86 | * 87 | * \param ctx RIPEMD-160 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, 92 | const unsigned char *input, size_t ilen ); 93 | 94 | /** 95 | * \brief RIPEMD-160 final digest 96 | * 97 | * \param ctx RIPEMD-160 context 98 | * \param output RIPEMD-160 checksum result 99 | */ 100 | void mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx, unsigned char output[20] ); 101 | 102 | /* Internal use */ 103 | void mbedtls_ripemd160_process( mbedtls_ripemd160_context *ctx, const unsigned char data[64] ); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #else /* MBEDTLS_RIPEMD160_ALT */ 110 | #include "ripemd160.h" 111 | #endif /* MBEDTLS_RIPEMD160_ALT */ 112 | 113 | #ifdef __cplusplus 114 | extern "C" { 115 | #endif 116 | 117 | /** 118 | * \brief Output = RIPEMD-160( input buffer ) 119 | * 120 | * \param input buffer holding the data 121 | * \param ilen length of the input data 122 | * \param output RIPEMD-160 checksum result 123 | */ 124 | void mbedtls_ripemd160( const unsigned char *input, size_t ilen, 125 | unsigned char output[20] ); 126 | 127 | /** 128 | * \brief Checkup routine 129 | * 130 | * \return 0 if successful, or 1 if the test failed 131 | */ 132 | int mbedtls_ripemd160_self_test( int verbose ); 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif /* mbedtls_ripemd160.h */ 139 | -------------------------------------------------------------------------------- /mbedtls/sha1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sha1.h 3 | * 4 | * \brief SHA-1 cryptographic hash function 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SHA1_H 24 | #define MBEDTLS_SHA1_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_SHA1_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief SHA-1 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[5]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | mbedtls_sha1_context; 53 | 54 | /** 55 | * \brief Initialize SHA-1 context 56 | * 57 | * \param ctx SHA-1 context to be initialized 58 | */ 59 | void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); 60 | 61 | /** 62 | * \brief Clear SHA-1 context 63 | * 64 | * \param ctx SHA-1 context to be cleared 65 | */ 66 | void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); 67 | 68 | /** 69 | * \brief Clone (the state of) a SHA-1 context 70 | * 71 | * \param dst The destination context 72 | * \param src The context to be cloned 73 | */ 74 | void mbedtls_sha1_clone( mbedtls_sha1_context *dst, 75 | const mbedtls_sha1_context *src ); 76 | 77 | /** 78 | * \brief SHA-1 context setup 79 | * 80 | * \param ctx context to be initialized 81 | */ 82 | void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); 83 | 84 | /** 85 | * \brief SHA-1 process buffer 86 | * 87 | * \param ctx SHA-1 context 88 | * \param input buffer holding the data 89 | * \param ilen length of the input data 90 | */ 91 | void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen ); 92 | 93 | /** 94 | * \brief SHA-1 final digest 95 | * 96 | * \param ctx SHA-1 context 97 | * \param output SHA-1 checksum result 98 | */ 99 | void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] ); 100 | 101 | /* Internal use */ 102 | void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] ); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #else /* MBEDTLS_SHA1_ALT */ 109 | #include "sha1_alt.h" 110 | #endif /* MBEDTLS_SHA1_ALT */ 111 | 112 | #ifdef __cplusplus 113 | extern "C" { 114 | #endif 115 | 116 | /** 117 | * \brief Output = SHA-1( input buffer ) 118 | * 119 | * \param input buffer holding the data 120 | * \param ilen length of the input data 121 | * \param output SHA-1 checksum result 122 | */ 123 | void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); 124 | 125 | /** 126 | * \brief Checkup routine 127 | * 128 | * \return 0 if successful, or 1 if the test failed 129 | */ 130 | int mbedtls_sha1_self_test( int verbose ); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* mbedtls_sha1.h */ 137 | -------------------------------------------------------------------------------- /mbedtls/sha256.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sha256.h 3 | * 4 | * \brief SHA-224 and SHA-256 cryptographic hash function 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SHA256_H 24 | #define MBEDTLS_SHA256_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_SHA256_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief SHA-256 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint32_t total[2]; /*!< number of bytes processed */ 49 | uint32_t state[8]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | int is224; /*!< 0 => SHA-256, else SHA-224 */ 52 | } 53 | mbedtls_sha256_context; 54 | 55 | /** 56 | * \brief Initialize SHA-256 context 57 | * 58 | * \param ctx SHA-256 context to be initialized 59 | */ 60 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); 61 | 62 | /** 63 | * \brief Clear SHA-256 context 64 | * 65 | * \param ctx SHA-256 context to be cleared 66 | */ 67 | void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); 68 | 69 | /** 70 | * \brief Clone (the state of) a SHA-256 context 71 | * 72 | * \param dst The destination context 73 | * \param src The context to be cloned 74 | */ 75 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, 76 | const mbedtls_sha256_context *src ); 77 | 78 | /** 79 | * \brief SHA-256 context setup 80 | * 81 | * \param ctx context to be initialized 82 | * \param is224 0 = use SHA256, 1 = use SHA224 83 | */ 84 | void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ); 85 | 86 | /** 87 | * \brief SHA-256 process buffer 88 | * 89 | * \param ctx SHA-256 context 90 | * \param input buffer holding the data 91 | * \param ilen length of the input data 92 | */ 93 | void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input, 94 | size_t ilen ); 95 | 96 | /** 97 | * \brief SHA-256 final digest 98 | * 99 | * \param ctx SHA-256 context 100 | * \param output SHA-224/256 checksum result 101 | */ 102 | void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] ); 103 | 104 | /* Internal use */ 105 | void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] ); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #else /* MBEDTLS_SHA256_ALT */ 112 | #include "sha256_alt.h" 113 | #endif /* MBEDTLS_SHA256_ALT */ 114 | 115 | #ifdef __cplusplus 116 | extern "C" { 117 | #endif 118 | 119 | /** 120 | * \brief Output = SHA-256( input buffer ) 121 | * 122 | * \param input buffer holding the data 123 | * \param ilen length of the input data 124 | * \param output SHA-224/256 checksum result 125 | * \param is224 0 = use SHA256, 1 = use SHA224 126 | */ 127 | void mbedtls_sha256( const unsigned char *input, size_t ilen, 128 | unsigned char output[32], int is224 ); 129 | 130 | /** 131 | * \brief Checkup routine 132 | * 133 | * \return 0 if successful, or 1 if the test failed 134 | */ 135 | int mbedtls_sha256_self_test( int verbose ); 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* mbedtls_sha256.h */ 142 | -------------------------------------------------------------------------------- /mbedtls/sha512.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sha512.h 3 | * 4 | * \brief SHA-384 and SHA-512 cryptographic hash function 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SHA512_H 24 | #define MBEDTLS_SHA512_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined(MBEDTLS_SHA512_ALT) 36 | // Regular implementation 37 | // 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * \brief SHA-512 context structure 45 | */ 46 | typedef struct 47 | { 48 | uint64_t total[2]; /*!< number of bytes processed */ 49 | uint64_t state[8]; /*!< intermediate digest state */ 50 | unsigned char buffer[128]; /*!< data block being processed */ 51 | int is384; /*!< 0 => SHA-512, else SHA-384 */ 52 | } 53 | mbedtls_sha512_context; 54 | 55 | /** 56 | * \brief Initialize SHA-512 context 57 | * 58 | * \param ctx SHA-512 context to be initialized 59 | */ 60 | void mbedtls_sha512_init( mbedtls_sha512_context *ctx ); 61 | 62 | /** 63 | * \brief Clear SHA-512 context 64 | * 65 | * \param ctx SHA-512 context to be cleared 66 | */ 67 | void mbedtls_sha512_free( mbedtls_sha512_context *ctx ); 68 | 69 | /** 70 | * \brief Clone (the state of) a SHA-512 context 71 | * 72 | * \param dst The destination context 73 | * \param src The context to be cloned 74 | */ 75 | void mbedtls_sha512_clone( mbedtls_sha512_context *dst, 76 | const mbedtls_sha512_context *src ); 77 | 78 | /** 79 | * \brief SHA-512 context setup 80 | * 81 | * \param ctx context to be initialized 82 | * \param is384 0 = use SHA512, 1 = use SHA384 83 | */ 84 | void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ); 85 | 86 | /** 87 | * \brief SHA-512 process buffer 88 | * 89 | * \param ctx SHA-512 context 90 | * \param input buffer holding the data 91 | * \param ilen length of the input data 92 | */ 93 | void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input, 94 | size_t ilen ); 95 | 96 | /** 97 | * \brief SHA-512 final digest 98 | * 99 | * \param ctx SHA-512 context 100 | * \param output SHA-384/512 checksum result 101 | */ 102 | void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] ); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #else /* MBEDTLS_SHA512_ALT */ 109 | #include "sha512_alt.h" 110 | #endif /* MBEDTLS_SHA512_ALT */ 111 | 112 | #ifdef __cplusplus 113 | extern "C" { 114 | #endif 115 | 116 | /** 117 | * \brief Output = SHA-512( input buffer ) 118 | * 119 | * \param input buffer holding the data 120 | * \param ilen length of the input data 121 | * \param output SHA-384/512 checksum result 122 | * \param is384 0 = use SHA512, 1 = use SHA384 123 | */ 124 | void mbedtls_sha512( const unsigned char *input, size_t ilen, 125 | unsigned char output[64], int is384 ); 126 | 127 | /** 128 | * \brief Checkup routine 129 | * 130 | * \return 0 if successful, or 1 if the test failed 131 | */ 132 | int mbedtls_sha512_self_test( int verbose ); 133 | 134 | /* Internal use */ 135 | void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] ); 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* mbedtls_sha512.h */ 142 | -------------------------------------------------------------------------------- /mbedtls/ssl_cookie.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ssl_cookie.h 3 | * 4 | * \brief DTLS cookie callbacks implementation 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_SSL_COOKIE_H 24 | #define MBEDTLS_SSL_COOKIE_H 25 | 26 | #include "ssl.h" 27 | 28 | #if defined(MBEDTLS_THREADING_C) 29 | #include "threading.h" 30 | #endif 31 | 32 | /** 33 | * \name SECTION: Module settings 34 | * 35 | * The configuration options you can set for this module are in this section. 36 | * Either change them in config.h or define them on the compiler command line. 37 | * \{ 38 | */ 39 | #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT 40 | #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ 41 | #endif 42 | 43 | /* \} name SECTION: Module settings */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | * \brief Context for the default cookie functions. 51 | */ 52 | typedef struct 53 | { 54 | mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */ 55 | #if !defined(MBEDTLS_HAVE_TIME) 56 | unsigned long serial; /*!< serial number for expiration */ 57 | #endif 58 | unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME, 59 | or in number of tickets issued */ 60 | 61 | #if defined(MBEDTLS_THREADING_C) 62 | mbedtls_threading_mutex_t mutex; 63 | #endif 64 | } mbedtls_ssl_cookie_ctx; 65 | 66 | /** 67 | * \brief Initialize cookie context 68 | */ 69 | void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx ); 70 | 71 | /** 72 | * \brief Setup cookie context (generate keys) 73 | */ 74 | int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx, 75 | int (*f_rng)(void *, unsigned char *, size_t), 76 | void *p_rng ); 77 | 78 | /** 79 | * \brief Set expiration delay for cookies 80 | * (Default MBEDTLS_SSL_COOKIE_TIMEOUT) 81 | * 82 | * \param ctx Cookie contex 83 | * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies 84 | * issued in the meantime. 85 | * 0 to disable expiration (NOT recommended) 86 | */ 87 | void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay ); 88 | 89 | /** 90 | * \brief Free cookie context 91 | */ 92 | void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx ); 93 | 94 | /** 95 | * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t 96 | */ 97 | mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write; 98 | 99 | /** 100 | * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t 101 | */ 102 | mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check; 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* ssl_cookie.h */ 109 | -------------------------------------------------------------------------------- /mbedtls/threading.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file threading.h 3 | * 4 | * \brief Threading abstraction layer 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_THREADING_H 24 | #define MBEDTLS_THREADING_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */ 39 | #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */ 40 | #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */ 41 | 42 | #if defined(MBEDTLS_THREADING_PTHREAD) 43 | #include 44 | typedef struct 45 | { 46 | pthread_mutex_t mutex; 47 | char is_valid; 48 | } mbedtls_threading_mutex_t; 49 | #endif 50 | 51 | #if defined(MBEDTLS_THREADING_ALT) 52 | /* You should define the mbedtls_threading_mutex_t type in your header */ 53 | #include "threading_alt.h" 54 | 55 | /** 56 | * \brief Set your alternate threading implementation function 57 | * pointers and initialize global mutexes. If used, this 58 | * function must be called once in the main thread before any 59 | * other mbed TLS function is called, and 60 | * mbedtls_threading_free_alt() must be called once in the main 61 | * thread after all other mbed TLS functions. 62 | * 63 | * \note mutex_init() and mutex_free() don't return a status code. 64 | * If mutex_init() fails, it should leave its argument (the 65 | * mutex) in a state such that mutex_lock() will fail when 66 | * called with this argument. 67 | * 68 | * \param mutex_init the init function implementation 69 | * \param mutex_free the free function implementation 70 | * \param mutex_lock the lock function implementation 71 | * \param mutex_unlock the unlock function implementation 72 | */ 73 | void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ), 74 | void (*mutex_free)( mbedtls_threading_mutex_t * ), 75 | int (*mutex_lock)( mbedtls_threading_mutex_t * ), 76 | int (*mutex_unlock)( mbedtls_threading_mutex_t * ) ); 77 | 78 | /** 79 | * \brief Free global mutexes. 80 | */ 81 | void mbedtls_threading_free_alt( void ); 82 | #endif /* MBEDTLS_THREADING_ALT */ 83 | 84 | #if defined(MBEDTLS_THREADING_C) 85 | /* 86 | * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock 87 | * 88 | * All these functions are expected to work or the result will be undefined. 89 | */ 90 | extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex ); 91 | extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex ); 92 | extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex ); 93 | extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); 94 | 95 | /* 96 | * Global mutexes 97 | */ 98 | extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; 99 | extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; 100 | #endif /* MBEDTLS_THREADING_C */ 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* threading.h */ 107 | -------------------------------------------------------------------------------- /mbedtls/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version information 3 | * 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 5 | * SPDX-License-Identifier: Apache-2.0 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 8 | * not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * This file is part of mbed TLS (https://tls.mbed.org) 20 | */ 21 | 22 | #if !defined(MBEDTLS_CONFIG_FILE) 23 | #include "mbedtls/config.h" 24 | #else 25 | #include MBEDTLS_CONFIG_FILE 26 | #endif 27 | 28 | #if defined(MBEDTLS_VERSION_C) 29 | 30 | #include "mbedtls/version.h" 31 | #include 32 | 33 | unsigned int mbedtls_version_get_number() 34 | { 35 | return( MBEDTLS_VERSION_NUMBER ); 36 | } 37 | 38 | void mbedtls_version_get_string( char *string ) 39 | { 40 | memcpy( string, MBEDTLS_VERSION_STRING, 41 | sizeof( MBEDTLS_VERSION_STRING ) ); 42 | } 43 | 44 | void mbedtls_version_get_string_full( char *string ) 45 | { 46 | memcpy( string, MBEDTLS_VERSION_STRING_FULL, 47 | sizeof( MBEDTLS_VERSION_STRING_FULL ) ); 48 | } 49 | 50 | #endif /* MBEDTLS_VERSION_C */ 51 | -------------------------------------------------------------------------------- /mbedtls/version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file version.h 3 | * 4 | * \brief Run-time version information 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | /* 24 | * This set of compile-time defines and run-time variables can be used to 25 | * determine the version number of the mbed TLS library used. 26 | */ 27 | #ifndef MBEDTLS_VERSION_H 28 | #define MBEDTLS_VERSION_H 29 | 30 | #if !defined(MBEDTLS_CONFIG_FILE) 31 | #include "config.h" 32 | #else 33 | #include MBEDTLS_CONFIG_FILE 34 | #endif 35 | 36 | /** 37 | * The version number x.y.z is split into three parts. 38 | * Major, Minor, Patchlevel 39 | */ 40 | #define MBEDTLS_VERSION_MAJOR 2 41 | #define MBEDTLS_VERSION_MINOR 6 42 | #define MBEDTLS_VERSION_PATCH 0 43 | 44 | /** 45 | * The single version number has the following structure: 46 | * MMNNPP00 47 | * Major version | Minor version | Patch version 48 | */ 49 | #define MBEDTLS_VERSION_NUMBER 0x02060000 50 | #define MBEDTLS_VERSION_STRING "2.6.0" 51 | #define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.6.0" 52 | 53 | #if defined(MBEDTLS_VERSION_C) 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | /** 60 | * Get the version number. 61 | * 62 | * \return The constructed version number in the format 63 | * MMNNPP00 (Major, Minor, Patch). 64 | */ 65 | unsigned int mbedtls_version_get_number( void ); 66 | 67 | /** 68 | * Get the version string ("x.y.z"). 69 | * 70 | * \param string The string that will receive the value. 71 | * (Should be at least 9 bytes in size) 72 | */ 73 | void mbedtls_version_get_string( char *string ); 74 | 75 | /** 76 | * Get the full version string ("mbed TLS x.y.z"). 77 | * 78 | * \param string The string that will receive the value. The mbed TLS version 79 | * string will use 18 bytes AT MOST including a terminating 80 | * null byte. 81 | * (So the buffer should be at least 18 bytes to receive this 82 | * version string). 83 | */ 84 | void mbedtls_version_get_string_full( char *string ); 85 | 86 | /** 87 | * \brief Check if support for a feature was compiled into this 88 | * mbed TLS binary. This allows you to see at runtime if the 89 | * library was for instance compiled with or without 90 | * Multi-threading support. 91 | * 92 | * \note only checks against defines in the sections "System 93 | * support", "mbed TLS modules" and "mbed TLS feature 94 | * support" in config.h 95 | * 96 | * \param feature The string for the define to check (e.g. "MBEDTLS_AES_C") 97 | * 98 | * \return 0 if the feature is present, 99 | * -1 if the feature is not present and 100 | * -2 if support for feature checking as a whole was not 101 | * compiled in. 102 | */ 103 | int mbedtls_version_check_feature( const char *feature ); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* MBEDTLS_VERSION_C */ 110 | 111 | #endif /* version.h */ 112 | -------------------------------------------------------------------------------- /mbedtls/xtea.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file xtea.h 3 | * 4 | * \brief XTEA block cipher (32-bit) 5 | * 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | * This file is part of mbed TLS (https://tls.mbed.org) 22 | */ 23 | #ifndef MBEDTLS_XTEA_H 24 | #define MBEDTLS_XTEA_H 25 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) 27 | #include "config.h" 28 | #else 29 | #include MBEDTLS_CONFIG_FILE 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #define MBEDTLS_XTEA_ENCRYPT 1 36 | #define MBEDTLS_XTEA_DECRYPT 0 37 | 38 | #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */ 39 | 40 | #if !defined(MBEDTLS_XTEA_ALT) 41 | // Regular implementation 42 | // 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | /** 49 | * \brief XTEA context structure 50 | */ 51 | typedef struct 52 | { 53 | uint32_t k[4]; /*!< key */ 54 | } 55 | mbedtls_xtea_context; 56 | 57 | /** 58 | * \brief Initialize XTEA context 59 | * 60 | * \param ctx XTEA context to be initialized 61 | */ 62 | void mbedtls_xtea_init( mbedtls_xtea_context *ctx ); 63 | 64 | /** 65 | * \brief Clear XTEA context 66 | * 67 | * \param ctx XTEA context to be cleared 68 | */ 69 | void mbedtls_xtea_free( mbedtls_xtea_context *ctx ); 70 | 71 | /** 72 | * \brief XTEA key schedule 73 | * 74 | * \param ctx XTEA context to be initialized 75 | * \param key the secret key 76 | */ 77 | void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] ); 78 | 79 | /** 80 | * \brief XTEA cipher function 81 | * 82 | * \param ctx XTEA context 83 | * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT 84 | * \param input 8-byte input block 85 | * \param output 8-byte output block 86 | * 87 | * \return 0 if successful 88 | */ 89 | int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx, 90 | int mode, 91 | const unsigned char input[8], 92 | unsigned char output[8] ); 93 | 94 | #if defined(MBEDTLS_CIPHER_MODE_CBC) 95 | /** 96 | * \brief XTEA CBC cipher function 97 | * 98 | * \param ctx XTEA context 99 | * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT 100 | * \param length the length of input, multiple of 8 101 | * \param iv initialization vector for CBC mode 102 | * \param input input block 103 | * \param output output block 104 | * 105 | * \return 0 if successful, 106 | * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0 107 | */ 108 | int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx, 109 | int mode, 110 | size_t length, 111 | unsigned char iv[8], 112 | const unsigned char *input, 113 | unsigned char *output); 114 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #else /* MBEDTLS_XTEA_ALT */ 121 | #include "xtea_alt.h" 122 | #endif /* MBEDTLS_XTEA_ALT */ 123 | 124 | #ifdef __cplusplus 125 | extern "C" { 126 | #endif 127 | 128 | /** 129 | * \brief Checkup routine 130 | * 131 | * \return 0 if successful, or 1 if the test failed 132 | */ 133 | int mbedtls_xtea_self_test( int verbose ); 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /* xtea.h */ 140 | -------------------------------------------------------------------------------- /nacl_genkey.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | Generates a random ed25519 SigningKey/VerifyingKey key pair for use with a digital signature system using PyNaCl 5 | """ 6 | import sys 7 | 8 | import colorama 9 | from colorama import Fore 10 | from nacl.encoding import HexEncoder, RawEncoder 11 | from nacl.signing import SigningKey 12 | 13 | 14 | if __name__ == '__main__': 15 | colorama.init(autoreset=True) 16 | 17 | expected_args = 2 18 | received_args = len(sys.argv) - 1 19 | if received_args != expected_args: 20 | print(Fore.RED + 'require {} argument, but received {}'.format(expected_args, received_args)) 21 | print(Fore.CYAN + 'USAGE: {} '.format(sys.argv[0])) 22 | sys.exit(1) 23 | 24 | private_filename = sys.argv[1] 25 | public_filename = sys.argv[2] 26 | 27 | # Generate a new random private SigningKey for producing digital signatures using the Ed25519 algorithm 28 | signing_key = SigningKey.generate() 29 | 30 | # Extract the public VerifyingKey counterpart for verifying digital signatures created with the SigningKey 31 | verify_key = signing_key.verify_key 32 | 33 | # Serialize the signing and verify keys to raw bytes for archival storage 34 | signing_bytes = signing_key.encode(encoder=RawEncoder) 35 | verify_bytes = verify_key.encode(encoder=RawEncoder) 36 | 37 | # Save the private Signing key to a file 38 | with open(private_filename, 'wb') as private_file: 39 | # Saves 32 bytes of binary data (signing key) to a file 40 | private_file.write(signing_bytes) 41 | 42 | # Save the public Verifying key to a file 43 | with open(public_filename, 'wb') as public_file: 44 | # Saves 32 bytes of binary data (verify key) to a file 45 | public_file.write(verify_bytes) 46 | 47 | # Serialize the signing and verify keys to hexadecimal for display on stdout 48 | signing_hex = signing_key.encode(encoder=HexEncoder) 49 | verify_hex = verify_key.encode(encoder=HexEncoder) 50 | 51 | # Print out the public Verifying key 52 | print(Fore.GREEN + 'the public key is ({} bytes): {}'.format(len(verify_bytes), verify_hex)) 53 | 54 | # Print out the private Signing key 55 | print(Fore.YELLOW + 'the private key is ({} bytes): {}'.format(len(signing_bytes), signing_hex)) 56 | -------------------------------------------------------------------------------- /nacl_sign.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | Uses PyNaCl to sign a message using ed25519 digital signature algorithm 5 | """ 6 | import sys 7 | 8 | import colorama 9 | from colorama import Fore 10 | from nacl.encoding import HexEncoder, RawEncoder 11 | from nacl.signing import SigningKey 12 | 13 | 14 | if __name__ == '__main__': 15 | colorama.init(autoreset=True) 16 | 17 | expected_args = 3 18 | received_args = len(sys.argv) - 1 19 | if received_args != expected_args: 20 | print(Fore.RED + 'require {} arguments, but received {}'.format(expected_args, received_args)) 21 | print(Fore.CYAN + 'USAGE: {} '.format(sys.argv[0])) 22 | sys.exit(1) 23 | 24 | key_filename = sys.argv[1] 25 | input_filename = sys.argv[2] 26 | output_filename = sys.argv[3] 27 | 28 | # Open the private key file and read in the signing key bytes 29 | with open(key_filename, 'rb') as key_file: 30 | keydata_bytes = key_file.read() 31 | 32 | # Deal with secret keys generated by libsodium C library which also have the public key embedded 33 | KEY_BYTES = 32 34 | if len(keydata_bytes) > KEY_BYTES: 35 | keydata_bytes = keydata_bytes[:KEY_BYTES] 36 | 37 | # Reconstruct the SigningKey instance from the serialized form 38 | signing_key = SigningKey(keydata_bytes, encoder=RawEncoder) 39 | 40 | # Print out the private Signing key 41 | signing_hex = signing_key.encode(encoder=HexEncoder) 42 | print(Fore.LIGHTBLUE_EX + 'the private key is {}'.format(signing_hex)) 43 | 44 | # Open the input file and read its data in as a message that we wish to sign 45 | with open(input_filename, 'rb') as msg_file: 46 | msg = msg_file.read() 47 | 48 | # Sign a message with the signing key - this also contains the original message at the end 49 | sig = signing_key.sign(msg) 50 | 51 | # Save the signature to an output file 52 | with open(output_filename, 'wb') as sig_file: 53 | sig_file.write(sig) 54 | 55 | print(Fore.GREEN + 'Saved signature to {!r} for message file {!r}'.format(output_filename, input_filename)) 56 | -------------------------------------------------------------------------------- /nacl_symmetric_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ Generates a random 256-bit (32-byte) secret symmetric key using the PyNaCl wrapper around the libsodium C library 4 | * 5 | * This key is intended tobe used with libsodium "secretbox" secret-key authenticated encryption routines. 6 | * 7 | * These routines use the XSalsa20 stream cipher for encryption and the Poly1305 MAC for authentication 8 | * in pre-packaged set of routines for doing authenticated encryption using symmetric keys. 9 | * 10 | * NOTE: While this is an AE (Authenticated Encryption) mode, this is NOT an AEAD (Authenticated Encryption with 11 | Additional Data) mode because the MAC computation is just done over the encrypted ciphertext and does not include any 12 | additional data. 13 | * 14 | * XSalsa20 is a stream cipher based upon Salsa20 but with a much longer nonce: 192 bits instead of 64 bits. 15 | * 16 | * XSalsa20 uses a 256-bit key as well as the first 128 bits of the nonce in order to compute a subkey. This subkey, as 17 | * well as the remaining 64 bits of the nonce, are the parameters of the Salsa20 function used to actually generate the 18 | * stream. 19 | * 20 | * Like Salsa20, XSalsa20 is immune to timing attacks and provides its own 64-bit block counter to avoid incrementing 21 | * the nonce after each block. But with XSalsa20's longer nonce, it is safe to generate nonces using randombytes_buf() 22 | * for every message encrypted with the same key without having to worry about a collision. 23 | """ 24 | import sys 25 | 26 | import colorama 27 | from colorama import Fore 28 | from nacl.secret import SecretBox 29 | import nacl.utils 30 | 31 | 32 | if __name__ == '__main__': 33 | colorama.init(autoreset=True) 34 | 35 | expected_args = 1 36 | received_args = len(sys.argv) - 1 37 | if received_args != expected_args: 38 | print(Fore.RED + 'require {} argument, but received {}'.format(expected_args, received_args)) 39 | print(Fore.CYAN + 'USAGE: {} '.format(sys.argv[0])) 40 | sys.exit(1) 41 | 42 | key_filename = sys.argv[1] 43 | 44 | # Generate a new random 256-bit (32 byte) secret symmetric key 45 | key = nacl.utils.random(SecretBox.KEY_SIZE) 46 | 47 | # Display the key as hexadecimal digits on stdout 48 | # Print out the public Verifying key 49 | print(Fore.GREEN + 'Generated a {}-bit secret symmetric key: {}'.format(len(key) * 8, key.hex().upper())) 50 | 51 | # Save the key to a file 52 | with open(key_filename, 'wb') as key_file: 53 | # Saves 32 bytes of binary data (signing key) to a file 54 | key_file.write(key) 55 | 56 | print(Fore.LIGHTBLUE_EX + 'Key saved to {}-byte binary file {!r}'.format(len(key), key_filename)) 57 | 58 | # Now go through a full example of encrypting and then decrypting a fixed test message 59 | # The purpose is twofold: 60 | # 1) Demonstrate how to properly use the libsodium secretbox API for authenticated encryption 61 | # 2) Serve as a built-in unit test 62 | 63 | # This an instance of the class which encapsulates the encrypt and decrypt methods 64 | box = SecretBox(key) 65 | 66 | # This is our message to send, it must be a bytestring as SecretBox will treat it as just a binary blob of data. 67 | message = b"The president will be exiting through the lower levels" 68 | 69 | # PyNaCl can automatically generate a random nonce for us, making the encryption very simple: 70 | encrypted = box.encrypt(message) 71 | # However, if we need to use an explicit nonce, it can be passed along with the message: 72 | # nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE) 73 | # encrypted = box.encrypt(message, nonce) 74 | 75 | # The encrypted message will be exactly 40 bytes longer than the original message 76 | # - It stores authentication information (16 bytes) and the nonce (24 bytes) alongside it 77 | 78 | # Decrypt message - an exception will be raised if the encryption was tampered with or there was otherwise an error 79 | plaintext = box.decrypt(encrypted) 80 | 81 | # Display everything 82 | print('Test message: {!r}'.format(message)) 83 | print('Authenticated and authenticated bundle including nonce: {!r}'.format(encrypted.hex().upper())) 84 | print('Decrypted message: {!r}'.format(plaintext)) 85 | -------------------------------------------------------------------------------- /nacl_verify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | Uses PyNaCl to verify an ed25519 signature for a specific message 5 | """ 6 | import sys 7 | 8 | import colorama 9 | from colorama import Fore 10 | from nacl.encoding import HexEncoder, RawEncoder 11 | from nacl.exceptions import BadSignatureError 12 | from nacl.signing import VerifyKey 13 | 14 | 15 | if __name__ == '__main__': 16 | colorama.init(autoreset=True) 17 | 18 | expected_args = 2 19 | received_args = len(sys.argv) - 1 20 | if received_args != expected_args: 21 | print(Fore.RED + 'require {} arguments, but received {}'.format(expected_args, received_args)) 22 | print(Fore.CYAN + 'USAGE: {} '.format(sys.argv[0])) 23 | sys.exit(1) 24 | 25 | key_filename = sys.argv[1] 26 | sig_filename = sys.argv[2] 27 | 28 | # Open the public key file and read in the VerifyKey bytes 29 | with open(key_filename, 'rb') as key_file: 30 | keydata_bytes = key_file.read() 31 | 32 | # Reconstruct the VerifyKey instance from the serialized form 33 | verify_key = VerifyKey(keydata_bytes, encoder=RawEncoder) 34 | 35 | # Print out the public Verifying key 36 | verify_hex = verify_key.encode(encoder=HexEncoder) 37 | print(Fore.LIGHTBLUE_EX + 'the public key is {}'.format(verify_hex)) 38 | 39 | # Open the signature file and read the signature which also contains the original message 40 | with open(sig_filename, 'rb') as sig_file: 41 | sig = sig_file.read() 42 | 43 | # Check the validity of a message's signature 44 | try: 45 | # Will raise nacl.exceptions.BadSignatureError if the signature check fails 46 | verify_key.verify(sig) 47 | print(Fore.GREEN + "signature is good") 48 | except BadSignatureError as err: 49 | print(Fore.RED + "signature is bad: {}".format(err)) 50 | -------------------------------------------------------------------------------- /rsa_sign.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | * RSA signature creation program 5 | * 6 | * Usage: 7 | * rsa_sig 8 | * 9 | * Where: 10 | * - priv_key - is a path to an RSA private key file in PEM or DER format 11 | * - filename - is a path to an input file you wish to create an RSA signature for 12 | * 13 | * Output: 14 | * - filename.sig - signature is saved to filename.sig where "filename" is the complete input filename 15 | * 16 | * Notes: 17 | * This uses the Probabilistic Signature Scheme (PSS) standardized as part of PKCS#1 v2.1 along with SHA-512 hashes. 18 | """ 19 | import sys 20 | 21 | import colorama 22 | from colorama import Fore 23 | from cryptography.hazmat.backends import default_backend 24 | from cryptography.hazmat.primitives import hashes, serialization 25 | from cryptography.hazmat.primitives.asymmetric import padding 26 | 27 | # RSA Padding scheme - PSS (Probabilistic Signature Scheme) should be prefered 28 | # PSS is more complex than PKCS1, but has a security proof 29 | PSS_PADDING = 'PSS' 30 | PKCS1_PADDING = 'PKCS1v15' 31 | # RSA_PADDING = PSS_PADDING 32 | RSA_PADDING = PKCS1_PADDING 33 | 34 | USAGE = """Usage: 35 | {0} 36 | 37 | Example: 38 | {0} private_key.pem myfile.txt" 39 | """.format(sys.argv[0]) 40 | 41 | 42 | def print_usage() -> None: 43 | """Display intended command-line usage""" 44 | print(Fore.CYAN + USAGE) 45 | 46 | 47 | if __name__ == '__main__': 48 | colorama.init(autoreset=True) 49 | 50 | # Parse the command-line arguments 51 | expected_args = 2 52 | if len(sys.argv) != expected_args + 1: 53 | print(Fore.RED + 'Expected {} arguments, but got {}'.format(expected_args, len(sys.argv) - 1)) 54 | print_usage() 55 | sys.exit(1) 56 | 57 | # cryptography backend (i.e. OpenSSL) 58 | backend = default_backend() 59 | 60 | # Load the private key from a PEM file 61 | print('Reading the private key from {!r}'.format(sys.argv[1])) 62 | with open(sys.argv[1], 'rb') as key_file: 63 | private_key = serialization.load_pem_private_key(key_file.read(), password=None, backend=backend) 64 | 65 | # Read the message we want to sign from the input file 66 | print('Reading the input file from {!r}'.format(sys.argv[2])) 67 | with open(sys.argv[2], 'rb') as input_file: 68 | message = input_file.read() 69 | 70 | # Instantiate an instance of AsymmetricPadding to use 71 | if RSA_PADDING == PSS_PADDING: 72 | # PKCS#1 v2.1 probabilistic padding scheme (PSS) 73 | padding = padding.PSS(mgf=padding.MGF1(hashes.SHA512()), # A mask generation function object 74 | salt_length=padding.PSS.MAX_LENGTH) # The length of the salt 75 | else: 76 | # PKCS1v1.5 deterministic padding 77 | padding = padding.PKCS1v15() 78 | 79 | # Use the private key to sign the message 80 | print(Fore.LIGHTBLUE_EX + 'Generating the RSA/SHA-512 signature using {} padding'.format(RSA_PADDING)) 81 | signature = private_key.sign(message, 82 | padding, 83 | hashes.SHA512()) 84 | 85 | # Write the signature to a new file named ".sig" 86 | sig_file = sys.argv[2] + '.sig' 87 | with open(sig_file, 'wb') as signature_file: 88 | signature_file.write(signature) 89 | 90 | print(Fore.GREEN + '\nDone. Wrote signature to {!r}'.format(sig_file)) 91 | -------------------------------------------------------------------------------- /rsa_verify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | """ 4 | * RSA signature verification program using Python cryptography module 5 | * 6 | * Usage: 7 | * rsa_verify 8 | * 9 | * Where: 10 | * - pub_key - is a path to an RSA public key file in PEM or DER format 11 | * - filename - is a path to an input file you wish to verify an RSA signature of 12 | * 13 | * ASSUMPTION: 14 | * - signature has been saved to filename.sig where "filename" is the complete input filename 15 | * 16 | * Notes: 17 | * This uses the Probabilistic Signature Scheme (PSS) standardized as part of PKCS#1 v2.1 along with SHA-512 hashes. 18 | """ 19 | import sys 20 | import traceback 21 | 22 | import colorama 23 | from colorama import Fore 24 | from cryptography.hazmat.backends import default_backend 25 | from cryptography.hazmat.primitives import hashes, serialization 26 | from cryptography.hazmat.primitives.asymmetric import padding 27 | from cryptography.exceptions import InvalidSignature 28 | 29 | # RSA Padding scheme - PSS (Probabilistic Signature Scheme) should be prefered 30 | # PSS is more complex than PKCS1, but has a security proof 31 | PSS_PADDING = 'PSS' 32 | PKCS1_PADDING = 'PKCS1v15' 33 | # RSA_PADDING = PSS_PADDING 34 | RSA_PADDING = PKCS1_PADDING 35 | 36 | USAGE = """Usage: 37 | {0} 38 | 39 | Example: 40 | {0} public_key.pem myfile.txt" 41 | """.format(sys.argv[0]) 42 | 43 | 44 | def print_usage() -> None: 45 | """Display intended command-line usage""" 46 | print(Fore.CYAN + USAGE) 47 | 48 | 49 | if __name__ == '__main__': 50 | colorama.init(autoreset=True) 51 | 52 | # Parse the command-line arguments 53 | expected_args = 2 54 | if len(sys.argv) != expected_args + 1: 55 | print(Fore.RED + 'Expected {} arguments, but got {}'.format(expected_args, len(sys.argv) - 1)) 56 | print_usage() 57 | sys.exit(1) 58 | 59 | # cryptography backend (i.e. OpenSSL) 60 | backend = default_backend() 61 | 62 | # Load the public key from a PEM file 63 | print('Reading the public key from {!r}'.format(sys.argv[1])) 64 | with open(sys.argv[1], 'rb') as key_file: 65 | public_key = serialization.load_pem_public_key(key_file.read(), backend=backend) 66 | 67 | # Read the message we want to verify the signature for from the input file 68 | print('Reading the input message from {!r}'.format(sys.argv[2])) 69 | with open(sys.argv[2], 'rb') as input_file: 70 | message = input_file.read() 71 | 72 | # Read the signature from the .sig file 73 | sig_file = sys.argv[2] + '.sig' 74 | print('Reading the RSA signature from {!r}'.format(sig_file)) 75 | with open(sig_file, 'rb') as signature_file: 76 | signature = signature_file.read() 77 | 78 | # Instantiate an instance of AsymmetricPadding to use 79 | if RSA_PADDING == PSS_PADDING: 80 | # PKCS#1 v2.1 probabilistic padding sheme (PSS) 81 | padding = padding.PSS(mgf=padding.MGF1(hashes.SHA512()), # A mask generation function object 82 | salt_length=padding.PSS.MAX_LENGTH) # The length of the salt 83 | else: 84 | # PKCS1v1.5 deterministic padding 85 | padding = padding.PKCS1v15() 86 | 87 | # Use the public key to verify that the private key associated with it was used to sign that specific message 88 | print(Fore.LIGHTBLUE_EX + 'Verifying the RSA/SHA-512 signature using {} padding'.format(RSA_PADDING)) 89 | try: 90 | public_key.verify(signature, 91 | message, 92 | padding, 93 | hashes.SHA512()) 94 | except InvalidSignature as err: 95 | # If the signature does not match, verify() will raise an InvalidSignature exception 96 | print(Fore.RED + '\nThe signature does not match! ERROR - {!r}:'.format(err)) 97 | traceback.print_exc(file=sys.stdout) 98 | else: 99 | print(Fore.GREEN + '\nOK (the signature is valid)') 100 | -------------------------------------------------------------------------------- /sodium/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | project("hello_sodium" C) 3 | 4 | # Set compiler flags in a generic cross-platform compatible manner 5 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall") 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O2 -Wall") 7 | 8 | # Set the CMAKE_MODULE_PATH so it can find the Findsodium.cmake file 9 | set(CMAKE_MODULE_PATH 10 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 11 | ${CMAKE_MODULE_PATH}) 12 | 13 | # Projects which statically link Sodium in Visual Studio must define a macro named SODIUM_STATIC 14 | add_definitions(-DSODIUM_STATIC) 15 | 16 | # Find where libsodium is installed (prevent linker errors) 17 | find_package(sodium REQUIRED) 18 | 19 | # Tell CMake where to look for header files 20 | include_directories(${CMAKE_SOURCE_DIR}/include) 21 | 22 | # Tell CMake where to look for libraries 23 | link_directories(${CMAKE_SOURCE_DIR}) 24 | 25 | set(libs sodium) 26 | 27 | # Files to build for each executable 28 | set(HELLO_SRC hello_sodium.c) 29 | set(GENKEY_SRC nacl_genkey.c) 30 | set(SIGN_SRC nacl_sign.c) 31 | set(VERIFY_SRC nacl_verify.c) 32 | set(ED25519_SRC nacl_ed25519.c) 33 | set(PYNACL_COMPAT_SRC ed25519_sodium_pynacl.c) 34 | set(SYMMETRIC_GEN_SRC nacl_symmetric_gen.c) 35 | set(SYMMETRIC_ENCRYPT_SRC nacl_encrypt_file.c) 36 | set(SYMMETRIC_DECRYPT_SRC nacl_decrypt_file.c) 37 | 38 | # Executables to build 39 | set(HELLO_EXE hello_sodium) 40 | add_executable(${HELLO_EXE} ${HELLO_SRC}) 41 | target_link_libraries(${HELLO_EXE} ${libs}) 42 | 43 | set(GENKEY_EXE nacl_keygen) 44 | add_executable(${GENKEY_EXE} ${GENKEY_SRC}) 45 | target_link_libraries(${GENKEY_EXE} ${libs}) 46 | 47 | set(SIGN_EXE nacl_sign) 48 | add_executable(${SIGN_EXE} ${SIGN_SRC}) 49 | target_link_libraries(${SIGN_EXE} ${libs}) 50 | 51 | set(VERIFY_EXE nacl_verify) 52 | add_executable(${VERIFY_EXE} ${VERIFY_SRC}) 53 | target_link_libraries(${VERIFY_EXE} ${libs}) 54 | 55 | set(ED255159_EXE test_ed25519) 56 | add_executable(${ED255159_EXE} ${ED25519_SRC}) 57 | target_link_libraries(${ED255159_EXE} ${libs}) 58 | 59 | set(PYNACL_COMPAT_EXE test_pynacl_compatibility) 60 | add_executable(${PYNACL_COMPAT_EXE} ${PYNACL_COMPAT_SRC}) 61 | target_link_libraries(${PYNACL_COMPAT_EXE} ${libs}) 62 | 63 | set(SYMMETRIC_GENKEY_EXE symmetric_keygen) 64 | add_executable(${SYMMETRIC_GENKEY_EXE} ${SYMMETRIC_GEN_SRC}) 65 | target_link_libraries(${SYMMETRIC_GENKEY_EXE} ${libs}) 66 | 67 | set(SYMMETRIC_ENCRYPT_EXE symmetric_encrypt) 68 | add_executable(${SYMMETRIC_ENCRYPT_EXE} ${SYMMETRIC_ENCRYPT_SRC}) 69 | target_link_libraries(${SYMMETRIC_ENCRYPT_EXE} ${libs}) 70 | 71 | set(SYMMETRIC_DECRYPT_EXE symmetric_decrypt) 72 | add_executable(${SYMMETRIC_DECRYPT_EXE} ${SYMMETRIC_DECRYPT_SRC}) 73 | target_link_libraries(${SYMMETRIC_DECRYPT_EXE} ${libs}) 74 | -------------------------------------------------------------------------------- /sodium/Readme.md: -------------------------------------------------------------------------------- 1 | Installing libsodium 2 | ==================== 3 | 4 | Before building these examples, you need to make sure libosdium is installed. 5 | 6 | Installing on macOS 7 | ------------------- 8 | The easiest way to install on macOS is with Homebrew: 9 | 10 | ```bash 11 | brew install libsodium 12 | xcode-select --install 13 | ``` 14 | 15 | Installing on Linux 16 | ------------------- 17 | For any Linux distro which uses the **apt** package manager (Ubuntu, Debian, Mint, etc.), do the following: 18 | ```bash 19 | sudo apt install libsodium-dev 20 | ``` 21 | 22 | Installing on Windows 23 | --------------------- 24 | The easiest way to use libsodium on Windows is to use the [pre-built libraries](https://download.libsodium.org/doc/installation/). 25 | 26 | 27 | Building libsodium examples 28 | =========================== 29 | These examples require CMake to be installed along with the platform default C compiler. 30 | 31 | Building on Windows 32 | ------------------- 33 | 34 | On Windows, CMake generates a Visual Studio solution for either x86 or x64 (not both). So in general you have to 35 | create two separate build folders. 36 | 37 | Here, we have only included an x64 static libsodium library, so we will build for that. 38 | 39 | Build requires CMake and Visual Studio 2015 40 | 41 | Use the following sequence of commands to build on Windows: 42 | 43 | ```bash 44 | mkdir build64 & pushd build64 45 | cmake -G "Visual Studio 14 2015 Win64" .. 46 | popd 47 | cmake --build build64 --config Release 48 | ``` 49 | 50 | This will generate the executables in the build64\Release folder. 51 | 52 | Building on Linux or macOS 53 | ========================== 54 | ```bash 55 | mkdir build; pushd build 56 | cmake -DCMAKE_BUILD_TYPE=Release .. 57 | make 58 | ``` 59 | 60 | This will generate the executables in the build directory. 61 | 62 | 63 | File Contents 64 | ============= 65 | 66 | Installation Verification 67 | ------------------------- 68 | * hello_sodium.c 69 | * "hello world" code to make sure you have libsodium installed and are linking to it correctly 70 | 71 | Symmetric Encryption 72 | -------------------- 73 | These examples use the simple [crypto_secretbox](https://download.libsodium.org/doc/secret-key_cryptography/authenticated_encryption.html) 74 | API which is an [authenticated encryption](https://en.wikipedia.org/wiki/Authenticated_encryption) (AE) cryptographic 75 | primitive that combines an [XSalsa20](https://download.libsodium.org/doc/advanced/xsalsa20.html) 76 | stream cipher with a [Poly1305](https://en.wikipedia.org/wiki/Poly1305) MAC. This API is very easy to use and is 77 | particularly suitable for use by newcomers to cryptography. If you have need for authenticating additional data which 78 | is transmitted in an unencrypted fashion, then you may prefer an [AEAD](https://download.libsodium.org/doc/secret-key_cryptography/aead.html) 79 | primitive instead. 80 | 81 | * nacl_symmetric_gen.c 82 | * Generates a random 256-bit (32-byte) secret symmetric key for use with the **secretbox** API 83 | * nacl_encrypt_file.c 84 | * Encrypts a file using libsodium's **secretbox** secret-key routines and adds a MAC of the ciphertext 85 | * nacl_decrypt_file.c 86 | * Authenticates and decrypts a ciphertext file encrypted using libsodium's **secretbox** encryption routines 87 | 88 | Public-key Digital Signatures 89 | ----------------------------- 90 | These examples use the simple [crypto_sign](https://download.libsodium.org/doc/public-key_cryptography/public-key_signatures.html) 91 | API which is a public-key digital signature cryptographic primitive based on elliptic curves and uses the 92 | [Ed25519](https://ed25519.cr.yp.to) algorithm. 93 | 94 | * nacl_genkey.c 95 | * Generates a random Ed25519 Secret(signing)/Public(verifying) key pair using libsodium 96 | * nacl_sign.c 97 | * Uses libsodium to sign a message using the Ed25519 digital signature algorithm 98 | * nacl_verify.c 99 | * Uses libsodium to verify a signed message using the Ed25519 digital signature algorithm 100 | * ed25519_sodium_pynacl.c 101 | * Round trip "unit test" of using libsodium Ed25519 digital signature code along with PyNacl digital signature code 102 | 103 | 104 | -------------------------------------------------------------------------------- /sodium/ed25519_sodium_pynacl.c: -------------------------------------------------------------------------------- 1 | /* Round trip unit test of using libsodium Ed25519 digital signature code along with PyNacl digital signature code 2 | * 3 | * 0) Uses a hard-coded signing key seed generated by PyNacl to reconstruct signing and verifying keys in libsodium 4 | * 1) Reconstructs the signing and verifying keys from this in libsodium 5 | * 2) Signs a test message 6 | * 3) Verifies the signature of this test message 7 | */ 8 | 9 | // A project using libsodium should include the sodium.h header. 10 | // Including individual headers from libsodium is neither required nor recommended. 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | int ret = EXIT_FAILURE; 19 | 20 | // The sodium_init() function should be called before any other function. 21 | // It is safe to call sodium_init() multiple times, or from different threads; it will 22 | // immediately return 1 without doing anything if the library has already been initialized. 23 | // After this function returns, all of the other functions provided by Sodium will be 24 | // thread-safe. Before returning, the function ensures that the system's random number 25 | // generator has been properly seeded. On some Linux systems, this may take some time, 26 | // especially when called right after a reboot of the system 27 | if (sodium_init() < 0) 28 | { 29 | /* panic! the library couldn't be initialized, it is not safe to use */ 30 | printf("ERROR: The sodium library couldn't be initialized!\n"); 31 | return EXIT_FAILURE; 32 | } 33 | 34 | // Buffer to hold the public key (verifying key) 35 | unsigned char public_key[crypto_sign_PUBLICKEYBYTES]; 36 | 37 | // Buffer to hold the secret key (signing key) - has extra info so public key can be derived 38 | unsigned char secret_key[crypto_sign_SECRETKEYBYTES]; 39 | 40 | // Buffers to hold hexadecimal encoded versions of the keys (with a null terminator) 41 | #define PUBLICKEY_HEX_BYTES (2 * crypto_sign_PUBLICKEYBYTES + 1) 42 | #define SECRETKEY_HEX_BYTES (2 * crypto_sign_SECRETKEYBYTES + 1) 43 | char hex_public[PUBLICKEY_HEX_BYTES]; 44 | char hex_secret[SECRETKEY_HEX_BYTES]; 45 | 46 | // Seed for regenerating the keyair 47 | static const uint8_t key_seed[crypto_sign_SEEDBYTES] = { 0xeb, 0x6d, 0x09, 0x28, 0x94, 0x15, 0x4b, 0xdb, 48 | 0xd6, 0x6e, 0x63, 0x69, 0xb6, 0xd8, 0x4c, 0x98, 49 | 0x12, 0x92, 0x74, 0x2c, 0x3b, 0xd2, 0x76, 0x82, 50 | 0xdd, 0x17, 0x6c, 0xa7, 0xa4, 0xfb, 0xc1, 0xa2 }; 51 | 52 | // Deterministically derive the key pair from a single key seed 53 | crypto_sign_seed_keypair(public_key, secret_key, key_seed); 54 | 55 | // Convert the binary keys into a hexadecimal strings 56 | sodium_bin2hex(hex_public, PUBLICKEY_HEX_BYTES, public_key, crypto_sign_PUBLICKEYBYTES); 57 | sodium_bin2hex(hex_secret, SECRETKEY_HEX_BYTES, secret_key, crypto_sign_SECRETKEYBYTES); 58 | 59 | // Print the keys to the screen with hexadecimal encoding 60 | printf("Generated a signing/verifying key pair:\n"); 61 | printf("\tSecret key: %s\n", hex_secret); 62 | printf("\tPublic key: %s\n", hex_public); 63 | 64 | // Now go through a full sign and verify process with a dummy message just to make sure it works 65 | #define MESSAGE (const unsigned char *) "test" 66 | #define MESSAGE_LEN 4 67 | 68 | unsigned char signed_message[crypto_sign_BYTES + MESSAGE_LEN]; 69 | unsigned long long signed_message_len; 70 | 71 | printf("Signing a test message ..."); 72 | crypto_sign(signed_message, &signed_message_len, MESSAGE, MESSAGE_LEN, secret_key); 73 | printf(" Done\n"); 74 | 75 | unsigned char unsigned_message[MESSAGE_LEN]; 76 | unsigned long long unsigned_message_len; 77 | printf("Verifying the test signed message ..."); 78 | ret = crypto_sign_open(unsigned_message, &unsigned_message_len, signed_message, signed_message_len, public_key); 79 | if ( ret != 0) 80 | { 81 | printf(" invalid signature"); 82 | } 83 | else 84 | { 85 | printf(" OK\n"); 86 | } 87 | 88 | return ret; 89 | } 90 | -------------------------------------------------------------------------------- /sodium/hello_sodium.c: -------------------------------------------------------------------------------- 1 | // A project using libsodium should include the sodium.h header. 2 | // Including individual headers from libsodium is neither required nor recommended. 3 | #include 4 | 5 | #include 6 | 7 | int main(void) 8 | { 9 | int ret = 0; 10 | 11 | // The sodium_init() function should be called before any other function. 12 | // It is safe to call sodium_init() multiple times, or from different threads; it will 13 | // immediately return 1 without doing anything if the library has already been initialized. 14 | // After this function returns, all of the other functions provided by Sodium will be 15 | // thread-safe. Before returning, the function ensures that the system's random number 16 | // generator has been properly seeded. On some Linux systems, this may take some time, 17 | // especially when called right after a reboot of the system 18 | if (sodium_init() < 0) 19 | { 20 | /* panic! the library couldn't be initialized, it is not safe to use */ 21 | printf("ERROR: The sodium library couldn't be initialized!\n"); 22 | ret = 1; 23 | } 24 | else 25 | { 26 | printf("libsodium version %s has been successfully initialized\n", sodium_version_string()); 27 | } 28 | 29 | return ret; 30 | } 31 | -------------------------------------------------------------------------------- /sodium/include/sodium.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_H 3 | #define sodium_H 4 | 5 | #include "sodium/version.h" 6 | 7 | #include "sodium/core.h" 8 | #include "sodium/crypto_aead_aes256gcm.h" 9 | #include "sodium/crypto_aead_chacha20poly1305.h" 10 | #include "sodium/crypto_aead_xchacha20poly1305.h" 11 | #include "sodium/crypto_auth.h" 12 | #include "sodium/crypto_auth_hmacsha256.h" 13 | #include "sodium/crypto_auth_hmacsha512.h" 14 | #include "sodium/crypto_auth_hmacsha512256.h" 15 | #include "sodium/crypto_box.h" 16 | #include "sodium/crypto_box_curve25519xsalsa20poly1305.h" 17 | #include "sodium/crypto_core_hsalsa20.h" 18 | #include "sodium/crypto_core_hchacha20.h" 19 | #include "sodium/crypto_core_salsa20.h" 20 | #include "sodium/crypto_core_salsa2012.h" 21 | #include "sodium/crypto_core_salsa208.h" 22 | #include "sodium/crypto_generichash.h" 23 | #include "sodium/crypto_generichash_blake2b.h" 24 | #include "sodium/crypto_hash.h" 25 | #include "sodium/crypto_hash_sha256.h" 26 | #include "sodium/crypto_hash_sha512.h" 27 | #include "sodium/crypto_kdf.h" 28 | #include "sodium/crypto_kdf_blake2b.h" 29 | #include "sodium/crypto_kx.h" 30 | #include "sodium/crypto_onetimeauth.h" 31 | #include "sodium/crypto_onetimeauth_poly1305.h" 32 | #include "sodium/crypto_pwhash.h" 33 | #include "sodium/crypto_pwhash_argon2i.h" 34 | #include "sodium/crypto_scalarmult.h" 35 | #include "sodium/crypto_scalarmult_curve25519.h" 36 | #include "sodium/crypto_secretbox.h" 37 | #include "sodium/crypto_secretbox_xsalsa20poly1305.h" 38 | #include "sodium/crypto_secretstream_xchacha20poly1305.h" 39 | #include "sodium/crypto_shorthash.h" 40 | #include "sodium/crypto_shorthash_siphash24.h" 41 | #include "sodium/crypto_sign.h" 42 | #include "sodium/crypto_sign_ed25519.h" 43 | #include "sodium/crypto_stream.h" 44 | #include "sodium/crypto_stream_chacha20.h" 45 | #include "sodium/crypto_stream_salsa20.h" 46 | #include "sodium/crypto_stream_xsalsa20.h" 47 | #include "sodium/crypto_verify_16.h" 48 | #include "sodium/crypto_verify_32.h" 49 | #include "sodium/crypto_verify_64.h" 50 | #include "sodium/randombytes.h" 51 | #ifdef __native_client__ 52 | # include "sodium/randombytes_nativeclient.h" 53 | #endif 54 | #include "sodium/randombytes_salsa20_random.h" 55 | #include "sodium/randombytes_sysrandom.h" 56 | #include "sodium/runtime.h" 57 | #include "sodium/utils.h" 58 | 59 | #ifndef SODIUM_LIBRARY_MINIMAL 60 | # include "sodium/crypto_box_curve25519xchacha20poly1305.h" 61 | # include "sodium/crypto_secretbox_xchacha20poly1305.h" 62 | # include "sodium/crypto_pwhash_scryptsalsa208sha256.h" 63 | # include "sodium/crypto_stream_salsa2012.h" 64 | # include "sodium/crypto_stream_salsa208.h" 65 | # include "sodium/crypto_stream_xchacha20.h" 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /sodium/include/sodium/core.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_core_H 3 | #define sodium_core_H 4 | 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | SODIUM_EXPORT 12 | int sodium_init(void) 13 | __attribute__ ((warn_unused_result)); 14 | 15 | /* ---- */ 16 | 17 | SODIUM_EXPORT 18 | int sodium_set_misuse_handler(void (*handler)(void)); 19 | 20 | SODIUM_EXPORT 21 | void sodium_misuse(void) 22 | __attribute__ ((noreturn)); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_auth.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_auth_H 2 | #define crypto_auth_H 3 | 4 | #include 5 | 6 | #include "crypto_auth_hmacsha512256.h" 7 | #include "export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | #define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES 17 | SODIUM_EXPORT 18 | size_t crypto_auth_bytes(void); 19 | 20 | #define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES 21 | SODIUM_EXPORT 22 | size_t crypto_auth_keybytes(void); 23 | 24 | #define crypto_auth_PRIMITIVE "hmacsha512256" 25 | SODIUM_EXPORT 26 | const char *crypto_auth_primitive(void); 27 | 28 | SODIUM_EXPORT 29 | int crypto_auth(unsigned char *out, const unsigned char *in, 30 | unsigned long long inlen, const unsigned char *k); 31 | 32 | SODIUM_EXPORT 33 | int crypto_auth_verify(const unsigned char *h, const unsigned char *in, 34 | unsigned long long inlen, const unsigned char *k) 35 | __attribute__ ((warn_unused_result)); 36 | 37 | SODIUM_EXPORT 38 | void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES]); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_auth_hmacsha256.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_auth_hmacsha256_H 2 | #define crypto_auth_hmacsha256_H 3 | 4 | #include 5 | #include "crypto_hash_sha256.h" 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | # ifdef __GNUC__ 10 | # pragma GCC diagnostic ignored "-Wlong-long" 11 | # endif 12 | extern "C" { 13 | #endif 14 | 15 | #define crypto_auth_hmacsha256_BYTES 32U 16 | SODIUM_EXPORT 17 | size_t crypto_auth_hmacsha256_bytes(void); 18 | 19 | #define crypto_auth_hmacsha256_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_auth_hmacsha256_keybytes(void); 22 | 23 | SODIUM_EXPORT 24 | int crypto_auth_hmacsha256(unsigned char *out, 25 | const unsigned char *in, 26 | unsigned long long inlen, 27 | const unsigned char *k); 28 | 29 | SODIUM_EXPORT 30 | int crypto_auth_hmacsha256_verify(const unsigned char *h, 31 | const unsigned char *in, 32 | unsigned long long inlen, 33 | const unsigned char *k) 34 | __attribute__ ((warn_unused_result)); 35 | 36 | /* ------------------------------------------------------------------------- */ 37 | 38 | typedef struct crypto_auth_hmacsha256_state { 39 | crypto_hash_sha256_state ictx; 40 | crypto_hash_sha256_state octx; 41 | } crypto_auth_hmacsha256_state; 42 | 43 | SODIUM_EXPORT 44 | size_t crypto_auth_hmacsha256_statebytes(void); 45 | 46 | SODIUM_EXPORT 47 | int crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state, 48 | const unsigned char *key, 49 | size_t keylen); 50 | 51 | SODIUM_EXPORT 52 | int crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state, 53 | const unsigned char *in, 54 | unsigned long long inlen); 55 | 56 | SODIUM_EXPORT 57 | int crypto_auth_hmacsha256_final(crypto_auth_hmacsha256_state *state, 58 | unsigned char *out); 59 | 60 | 61 | SODIUM_EXPORT 62 | void crypto_auth_hmacsha256_keygen(unsigned char k[crypto_auth_hmacsha256_KEYBYTES]); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_auth_hmacsha512.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_auth_hmacsha512_H 2 | #define crypto_auth_hmacsha512_H 3 | 4 | #include 5 | #include "crypto_hash_sha512.h" 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | # ifdef __GNUC__ 10 | # pragma GCC diagnostic ignored "-Wlong-long" 11 | # endif 12 | extern "C" { 13 | #endif 14 | 15 | #define crypto_auth_hmacsha512_BYTES 64U 16 | SODIUM_EXPORT 17 | size_t crypto_auth_hmacsha512_bytes(void); 18 | 19 | #define crypto_auth_hmacsha512_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_auth_hmacsha512_keybytes(void); 22 | 23 | SODIUM_EXPORT 24 | int crypto_auth_hmacsha512(unsigned char *out, 25 | const unsigned char *in, 26 | unsigned long long inlen, 27 | const unsigned char *k); 28 | 29 | SODIUM_EXPORT 30 | int crypto_auth_hmacsha512_verify(const unsigned char *h, 31 | const unsigned char *in, 32 | unsigned long long inlen, 33 | const unsigned char *k) 34 | __attribute__ ((warn_unused_result)); 35 | 36 | /* ------------------------------------------------------------------------- */ 37 | 38 | typedef struct crypto_auth_hmacsha512_state { 39 | crypto_hash_sha512_state ictx; 40 | crypto_hash_sha512_state octx; 41 | } crypto_auth_hmacsha512_state; 42 | 43 | SODIUM_EXPORT 44 | size_t crypto_auth_hmacsha512_statebytes(void); 45 | 46 | SODIUM_EXPORT 47 | int crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state, 48 | const unsigned char *key, 49 | size_t keylen); 50 | 51 | SODIUM_EXPORT 52 | int crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state, 53 | const unsigned char *in, 54 | unsigned long long inlen); 55 | 56 | SODIUM_EXPORT 57 | int crypto_auth_hmacsha512_final(crypto_auth_hmacsha512_state *state, 58 | unsigned char *out); 59 | 60 | SODIUM_EXPORT 61 | void crypto_auth_hmacsha512_keygen(unsigned char k[crypto_auth_hmacsha512_KEYBYTES]); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_auth_hmacsha512256.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_auth_hmacsha512256_H 2 | #define crypto_auth_hmacsha512256_H 3 | 4 | #include 5 | #include "crypto_auth_hmacsha512.h" 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | # ifdef __GNUC__ 10 | # pragma GCC diagnostic ignored "-Wlong-long" 11 | # endif 12 | extern "C" { 13 | #endif 14 | 15 | #define crypto_auth_hmacsha512256_BYTES 32U 16 | SODIUM_EXPORT 17 | size_t crypto_auth_hmacsha512256_bytes(void); 18 | 19 | #define crypto_auth_hmacsha512256_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_auth_hmacsha512256_keybytes(void); 22 | 23 | SODIUM_EXPORT 24 | int crypto_auth_hmacsha512256(unsigned char *out, const unsigned char *in, 25 | unsigned long long inlen,const unsigned char *k); 26 | 27 | SODIUM_EXPORT 28 | int crypto_auth_hmacsha512256_verify(const unsigned char *h, 29 | const unsigned char *in, 30 | unsigned long long inlen, 31 | const unsigned char *k) 32 | __attribute__ ((warn_unused_result)); 33 | 34 | /* ------------------------------------------------------------------------- */ 35 | 36 | typedef crypto_auth_hmacsha512_state crypto_auth_hmacsha512256_state; 37 | 38 | SODIUM_EXPORT 39 | size_t crypto_auth_hmacsha512256_statebytes(void); 40 | 41 | SODIUM_EXPORT 42 | int crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state, 43 | const unsigned char *key, 44 | size_t keylen); 45 | 46 | SODIUM_EXPORT 47 | int crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state, 48 | const unsigned char *in, 49 | unsigned long long inlen); 50 | 51 | SODIUM_EXPORT 52 | int crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state, 53 | unsigned char *out); 54 | 55 | SODIUM_EXPORT 56 | void crypto_auth_hmacsha512256_keygen(unsigned char k[crypto_auth_hmacsha512256_KEYBYTES]); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_core_hchacha20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_hchacha20_H 2 | #define crypto_core_hchacha20_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_hchacha20_OUTPUTBYTES 32U 12 | SODIUM_EXPORT 13 | size_t crypto_core_hchacha20_outputbytes(void); 14 | 15 | #define crypto_core_hchacha20_INPUTBYTES 16U 16 | SODIUM_EXPORT 17 | size_t crypto_core_hchacha20_inputbytes(void); 18 | 19 | #define crypto_core_hchacha20_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_core_hchacha20_keybytes(void); 22 | 23 | #define crypto_core_hchacha20_CONSTBYTES 16U 24 | SODIUM_EXPORT 25 | size_t crypto_core_hchacha20_constbytes(void); 26 | 27 | SODIUM_EXPORT 28 | int crypto_core_hchacha20(unsigned char *out, const unsigned char *in, 29 | const unsigned char *k, const unsigned char *c); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_core_hsalsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_hsalsa20_H 2 | #define crypto_core_hsalsa20_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_hsalsa20_OUTPUTBYTES 32U 12 | SODIUM_EXPORT 13 | size_t crypto_core_hsalsa20_outputbytes(void); 14 | 15 | #define crypto_core_hsalsa20_INPUTBYTES 16U 16 | SODIUM_EXPORT 17 | size_t crypto_core_hsalsa20_inputbytes(void); 18 | 19 | #define crypto_core_hsalsa20_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_core_hsalsa20_keybytes(void); 22 | 23 | #define crypto_core_hsalsa20_CONSTBYTES 16U 24 | SODIUM_EXPORT 25 | size_t crypto_core_hsalsa20_constbytes(void); 26 | 27 | SODIUM_EXPORT 28 | int crypto_core_hsalsa20(unsigned char *out, const unsigned char *in, 29 | const unsigned char *k, const unsigned char *c); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_core_salsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_salsa20_H 2 | #define crypto_core_salsa20_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_salsa20_OUTPUTBYTES 64U 12 | SODIUM_EXPORT 13 | size_t crypto_core_salsa20_outputbytes(void); 14 | 15 | #define crypto_core_salsa20_INPUTBYTES 16U 16 | SODIUM_EXPORT 17 | size_t crypto_core_salsa20_inputbytes(void); 18 | 19 | #define crypto_core_salsa20_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_core_salsa20_keybytes(void); 22 | 23 | #define crypto_core_salsa20_CONSTBYTES 16U 24 | SODIUM_EXPORT 25 | size_t crypto_core_salsa20_constbytes(void); 26 | 27 | SODIUM_EXPORT 28 | int crypto_core_salsa20(unsigned char *out, const unsigned char *in, 29 | const unsigned char *k, const unsigned char *c); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_core_salsa2012.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_salsa2012_H 2 | #define crypto_core_salsa2012_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_salsa2012_OUTPUTBYTES 64U 12 | SODIUM_EXPORT 13 | size_t crypto_core_salsa2012_outputbytes(void); 14 | 15 | #define crypto_core_salsa2012_INPUTBYTES 16U 16 | SODIUM_EXPORT 17 | size_t crypto_core_salsa2012_inputbytes(void); 18 | 19 | #define crypto_core_salsa2012_KEYBYTES 32U 20 | SODIUM_EXPORT 21 | size_t crypto_core_salsa2012_keybytes(void); 22 | 23 | #define crypto_core_salsa2012_CONSTBYTES 16U 24 | SODIUM_EXPORT 25 | size_t crypto_core_salsa2012_constbytes(void); 26 | 27 | SODIUM_EXPORT 28 | int crypto_core_salsa2012(unsigned char *out, const unsigned char *in, 29 | const unsigned char *k, const unsigned char *c); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_core_salsa208.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_salsa208_H 2 | #define crypto_core_salsa208_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_salsa208_OUTPUTBYTES 64U 12 | SODIUM_EXPORT 13 | size_t crypto_core_salsa208_outputbytes(void) 14 | __attribute__ ((deprecated)); 15 | 16 | #define crypto_core_salsa208_INPUTBYTES 16U 17 | SODIUM_EXPORT 18 | size_t crypto_core_salsa208_inputbytes(void) 19 | __attribute__ ((deprecated)); 20 | 21 | #define crypto_core_salsa208_KEYBYTES 32U 22 | SODIUM_EXPORT 23 | size_t crypto_core_salsa208_keybytes(void) 24 | __attribute__ ((deprecated)); 25 | 26 | #define crypto_core_salsa208_CONSTBYTES 16U 27 | SODIUM_EXPORT 28 | size_t crypto_core_salsa208_constbytes(void) 29 | __attribute__ ((deprecated)); 30 | 31 | SODIUM_EXPORT 32 | int crypto_core_salsa208(unsigned char *out, const unsigned char *in, 33 | const unsigned char *k, const unsigned char *c); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_generichash.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_generichash_H 2 | #define crypto_generichash_H 3 | 4 | #include 5 | 6 | #include "crypto_generichash_blake2b.h" 7 | #include "export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | #define crypto_generichash_BYTES_MIN crypto_generichash_blake2b_BYTES_MIN 17 | SODIUM_EXPORT 18 | size_t crypto_generichash_bytes_min(void); 19 | 20 | #define crypto_generichash_BYTES_MAX crypto_generichash_blake2b_BYTES_MAX 21 | SODIUM_EXPORT 22 | size_t crypto_generichash_bytes_max(void); 23 | 24 | #define crypto_generichash_BYTES crypto_generichash_blake2b_BYTES 25 | SODIUM_EXPORT 26 | size_t crypto_generichash_bytes(void); 27 | 28 | #define crypto_generichash_KEYBYTES_MIN crypto_generichash_blake2b_KEYBYTES_MIN 29 | SODIUM_EXPORT 30 | size_t crypto_generichash_keybytes_min(void); 31 | 32 | #define crypto_generichash_KEYBYTES_MAX crypto_generichash_blake2b_KEYBYTES_MAX 33 | SODIUM_EXPORT 34 | size_t crypto_generichash_keybytes_max(void); 35 | 36 | #define crypto_generichash_KEYBYTES crypto_generichash_blake2b_KEYBYTES 37 | SODIUM_EXPORT 38 | size_t crypto_generichash_keybytes(void); 39 | 40 | #define crypto_generichash_PRIMITIVE "blake2b" 41 | SODIUM_EXPORT 42 | const char *crypto_generichash_primitive(void); 43 | 44 | typedef crypto_generichash_blake2b_state crypto_generichash_state; 45 | 46 | SODIUM_EXPORT 47 | size_t crypto_generichash_statebytes(void); 48 | 49 | SODIUM_EXPORT 50 | int crypto_generichash(unsigned char *out, size_t outlen, 51 | const unsigned char *in, unsigned long long inlen, 52 | const unsigned char *key, size_t keylen); 53 | 54 | SODIUM_EXPORT 55 | int crypto_generichash_init(crypto_generichash_state *state, 56 | const unsigned char *key, 57 | const size_t keylen, const size_t outlen); 58 | 59 | SODIUM_EXPORT 60 | int crypto_generichash_update(crypto_generichash_state *state, 61 | const unsigned char *in, 62 | unsigned long long inlen); 63 | 64 | SODIUM_EXPORT 65 | int crypto_generichash_final(crypto_generichash_state *state, 66 | unsigned char *out, const size_t outlen); 67 | 68 | SODIUM_EXPORT 69 | void crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES]); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_hash.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_H 2 | #define crypto_hash_H 3 | 4 | /* 5 | * WARNING: Unless you absolutely need to use SHA512 for interoperatibility, 6 | * purposes, you might want to consider crypto_generichash() instead. 7 | * Unlike SHA512, crypto_generichash() is not vulnerable to length 8 | * extension attacks. 9 | */ 10 | 11 | #include 12 | 13 | #include "crypto_hash_sha512.h" 14 | #include "export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | #define crypto_hash_BYTES crypto_hash_sha512_BYTES 24 | SODIUM_EXPORT 25 | size_t crypto_hash_bytes(void); 26 | 27 | SODIUM_EXPORT 28 | int crypto_hash(unsigned char *out, const unsigned char *in, 29 | unsigned long long inlen); 30 | 31 | #define crypto_hash_PRIMITIVE "sha512" 32 | SODIUM_EXPORT 33 | const char *crypto_hash_primitive(void) 34 | __attribute__ ((warn_unused_result)); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_hash_sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_sha256_H 2 | #define crypto_hash_sha256_H 3 | 4 | /* 5 | * WARNING: Unless you absolutely need to use SHA256 for interoperatibility, 6 | * purposes, you might want to consider crypto_generichash() instead. 7 | * Unlike SHA256, crypto_generichash() is not vulnerable to length 8 | * extension attacks. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "export.h" 16 | 17 | #ifdef __cplusplus 18 | # ifdef __GNUC__ 19 | # pragma GCC diagnostic ignored "-Wlong-long" 20 | # endif 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct crypto_hash_sha256_state { 25 | uint32_t state[8]; 26 | uint64_t count; 27 | uint8_t buf[64]; 28 | } crypto_hash_sha256_state; 29 | 30 | SODIUM_EXPORT 31 | size_t crypto_hash_sha256_statebytes(void); 32 | 33 | #define crypto_hash_sha256_BYTES 32U 34 | SODIUM_EXPORT 35 | size_t crypto_hash_sha256_bytes(void); 36 | 37 | SODIUM_EXPORT 38 | int crypto_hash_sha256(unsigned char *out, const unsigned char *in, 39 | unsigned long long inlen); 40 | 41 | SODIUM_EXPORT 42 | int crypto_hash_sha256_init(crypto_hash_sha256_state *state); 43 | 44 | SODIUM_EXPORT 45 | int crypto_hash_sha256_update(crypto_hash_sha256_state *state, 46 | const unsigned char *in, 47 | unsigned long long inlen); 48 | 49 | SODIUM_EXPORT 50 | int crypto_hash_sha256_final(crypto_hash_sha256_state *state, 51 | unsigned char *out); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_hash_sha512.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_sha512_H 2 | #define crypto_hash_sha512_H 3 | 4 | /* 5 | * WARNING: Unless you absolutely need to use SHA512 for interoperatibility, 6 | * purposes, you might want to consider crypto_generichash() instead. 7 | * Unlike SHA512, crypto_generichash() is not vulnerable to length 8 | * extension attacks. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "export.h" 16 | 17 | #ifdef __cplusplus 18 | # ifdef __GNUC__ 19 | # pragma GCC diagnostic ignored "-Wlong-long" 20 | # endif 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct crypto_hash_sha512_state { 25 | uint64_t state[8]; 26 | uint64_t count[2]; 27 | uint8_t buf[128]; 28 | } crypto_hash_sha512_state; 29 | 30 | SODIUM_EXPORT 31 | size_t crypto_hash_sha512_statebytes(void); 32 | 33 | #define crypto_hash_sha512_BYTES 64U 34 | SODIUM_EXPORT 35 | size_t crypto_hash_sha512_bytes(void); 36 | 37 | SODIUM_EXPORT 38 | int crypto_hash_sha512(unsigned char *out, const unsigned char *in, 39 | unsigned long long inlen); 40 | 41 | SODIUM_EXPORT 42 | int crypto_hash_sha512_init(crypto_hash_sha512_state *state); 43 | 44 | SODIUM_EXPORT 45 | int crypto_hash_sha512_update(crypto_hash_sha512_state *state, 46 | const unsigned char *in, 47 | unsigned long long inlen); 48 | 49 | SODIUM_EXPORT 50 | int crypto_hash_sha512_final(crypto_hash_sha512_state *state, 51 | unsigned char *out); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_kdf.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_kdf_H 2 | #define crypto_kdf_H 3 | 4 | #include 5 | #include 6 | 7 | #include "crypto_kdf_blake2b.h" 8 | #include "export.h" 9 | 10 | #ifdef __cplusplus 11 | # ifdef __GNUC__ 12 | # pragma GCC diagnostic ignored "-Wlong-long" 13 | # endif 14 | extern "C" { 15 | #endif 16 | 17 | #define crypto_kdf_BYTES_MIN crypto_kdf_blake2b_BYTES_MIN 18 | SODIUM_EXPORT 19 | size_t crypto_kdf_bytes_min(void); 20 | 21 | #define crypto_kdf_BYTES_MAX crypto_kdf_blake2b_BYTES_MAX 22 | SODIUM_EXPORT 23 | size_t crypto_kdf_bytes_max(void); 24 | 25 | #define crypto_kdf_CONTEXTBYTES crypto_kdf_blake2b_CONTEXTBYTES 26 | SODIUM_EXPORT 27 | size_t crypto_kdf_contextbytes(void); 28 | 29 | #define crypto_kdf_KEYBYTES crypto_kdf_blake2b_KEYBYTES 30 | SODIUM_EXPORT 31 | size_t crypto_kdf_keybytes(void); 32 | 33 | #define crypto_kdf_PRIMITIVE "blake2b" 34 | SODIUM_EXPORT 35 | const char *crypto_kdf_primitive(void) 36 | __attribute__ ((warn_unused_result)); 37 | 38 | SODIUM_EXPORT 39 | int crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len, 40 | uint64_t subkey_id, 41 | const char ctx[crypto_kdf_CONTEXTBYTES], 42 | const unsigned char key[crypto_kdf_KEYBYTES]); 43 | 44 | SODIUM_EXPORT 45 | void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES]); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_kdf_blake2b.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_kdf_blake2b_H 2 | #define crypto_kdf_blake2b_H 3 | 4 | #include 5 | #include 6 | 7 | #include "crypto_kdf_blake2b.h" 8 | #include "export.h" 9 | 10 | #ifdef __cplusplus 11 | # ifdef __GNUC__ 12 | # pragma GCC diagnostic ignored "-Wlong-long" 13 | # endif 14 | extern "C" { 15 | #endif 16 | 17 | #define crypto_kdf_blake2b_BYTES_MIN 16 18 | SODIUM_EXPORT 19 | size_t crypto_kdf_blake2b_bytes_min(void); 20 | 21 | #define crypto_kdf_blake2b_BYTES_MAX 64 22 | SODIUM_EXPORT 23 | size_t crypto_kdf_blake2b_bytes_max(void); 24 | 25 | #define crypto_kdf_blake2b_CONTEXTBYTES 8 26 | SODIUM_EXPORT 27 | size_t crypto_kdf_blake2b_contextbytes(void); 28 | 29 | #define crypto_kdf_blake2b_KEYBYTES 32 30 | SODIUM_EXPORT 31 | size_t crypto_kdf_blake2b_keybytes(void); 32 | 33 | SODIUM_EXPORT 34 | int crypto_kdf_blake2b_derive_from_key(unsigned char *subkey, size_t subkey_len, 35 | uint64_t subkey_id, 36 | const char ctx[crypto_kdf_blake2b_CONTEXTBYTES], 37 | const unsigned char key[crypto_kdf_blake2b_KEYBYTES]); 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_kx.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_kx_H 2 | #define crypto_kx_H 3 | 4 | #include 5 | 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | # ifdef __GNUC__ 10 | # pragma GCC diagnostic ignored "-Wlong-long" 11 | # endif 12 | extern "C" { 13 | #endif 14 | 15 | #define crypto_kx_PUBLICKEYBYTES 32 16 | SODIUM_EXPORT 17 | size_t crypto_kx_publickeybytes(void); 18 | 19 | #define crypto_kx_SECRETKEYBYTES 32 20 | SODIUM_EXPORT 21 | size_t crypto_kx_secretkeybytes(void); 22 | 23 | #define crypto_kx_SEEDBYTES 32 24 | SODIUM_EXPORT 25 | size_t crypto_kx_seedbytes(void); 26 | 27 | #define crypto_kx_SESSIONKEYBYTES 32 28 | SODIUM_EXPORT 29 | size_t crypto_kx_sessionkeybytes(void); 30 | 31 | #define crypto_kx_PRIMITIVE "x25519blake2b" 32 | SODIUM_EXPORT 33 | const char *crypto_kx_primitive(void); 34 | 35 | SODIUM_EXPORT 36 | int crypto_kx_seed_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES], 37 | unsigned char sk[crypto_kx_SECRETKEYBYTES], 38 | const unsigned char seed[crypto_kx_SEEDBYTES]); 39 | 40 | SODIUM_EXPORT 41 | int crypto_kx_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES], 42 | unsigned char sk[crypto_kx_SECRETKEYBYTES]); 43 | 44 | SODIUM_EXPORT 45 | int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], 46 | unsigned char tx[crypto_kx_SESSIONKEYBYTES], 47 | const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES], 48 | const unsigned char client_sk[crypto_kx_SECRETKEYBYTES], 49 | const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES]) 50 | __attribute__ ((warn_unused_result)); 51 | 52 | SODIUM_EXPORT 53 | int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], 54 | unsigned char tx[crypto_kx_SESSIONKEYBYTES], 55 | const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES], 56 | const unsigned char server_sk[crypto_kx_SECRETKEYBYTES], 57 | const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES]) 58 | __attribute__ ((warn_unused_result)); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_onetimeauth.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_onetimeauth_H 2 | #define crypto_onetimeauth_H 3 | 4 | #include 5 | 6 | #include "crypto_onetimeauth_poly1305.h" 7 | #include "export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | typedef crypto_onetimeauth_poly1305_state crypto_onetimeauth_state; 17 | 18 | SODIUM_EXPORT 19 | size_t crypto_onetimeauth_statebytes(void); 20 | 21 | #define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES 22 | SODIUM_EXPORT 23 | size_t crypto_onetimeauth_bytes(void); 24 | 25 | #define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES 26 | SODIUM_EXPORT 27 | size_t crypto_onetimeauth_keybytes(void); 28 | 29 | #define crypto_onetimeauth_PRIMITIVE "poly1305" 30 | SODIUM_EXPORT 31 | const char *crypto_onetimeauth_primitive(void); 32 | 33 | SODIUM_EXPORT 34 | int crypto_onetimeauth(unsigned char *out, const unsigned char *in, 35 | unsigned long long inlen, const unsigned char *k); 36 | 37 | SODIUM_EXPORT 38 | int crypto_onetimeauth_verify(const unsigned char *h, const unsigned char *in, 39 | unsigned long long inlen, const unsigned char *k) 40 | __attribute__ ((warn_unused_result)); 41 | 42 | SODIUM_EXPORT 43 | int crypto_onetimeauth_init(crypto_onetimeauth_state *state, 44 | const unsigned char *key); 45 | 46 | SODIUM_EXPORT 47 | int crypto_onetimeauth_update(crypto_onetimeauth_state *state, 48 | const unsigned char *in, 49 | unsigned long long inlen); 50 | 51 | SODIUM_EXPORT 52 | int crypto_onetimeauth_final(crypto_onetimeauth_state *state, 53 | unsigned char *out); 54 | 55 | SODIUM_EXPORT 56 | void crypto_onetimeauth_keygen(unsigned char k[crypto_onetimeauth_KEYBYTES]); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_onetimeauth_poly1305.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_onetimeauth_poly1305_H 2 | #define crypto_onetimeauth_poly1305_H 3 | 4 | #ifdef __cplusplus 5 | # ifdef __GNUC__ 6 | # pragma GCC diagnostic ignored "-Wlong-long" 7 | # endif 8 | extern "C" { 9 | #endif 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "export.h" 18 | 19 | typedef struct CRYPTO_ALIGN(16) crypto_onetimeauth_poly1305_state { 20 | unsigned char opaque[256]; 21 | } crypto_onetimeauth_poly1305_state; 22 | 23 | SODIUM_EXPORT 24 | size_t crypto_onetimeauth_poly1305_statebytes(void); 25 | 26 | #define crypto_onetimeauth_poly1305_BYTES 16U 27 | SODIUM_EXPORT 28 | size_t crypto_onetimeauth_poly1305_bytes(void); 29 | 30 | #define crypto_onetimeauth_poly1305_KEYBYTES 32U 31 | SODIUM_EXPORT 32 | size_t crypto_onetimeauth_poly1305_keybytes(void); 33 | 34 | SODIUM_EXPORT 35 | int crypto_onetimeauth_poly1305(unsigned char *out, 36 | const unsigned char *in, 37 | unsigned long long inlen, 38 | const unsigned char *k); 39 | 40 | SODIUM_EXPORT 41 | int crypto_onetimeauth_poly1305_verify(const unsigned char *h, 42 | const unsigned char *in, 43 | unsigned long long inlen, 44 | const unsigned char *k) 45 | __attribute__ ((warn_unused_result)); 46 | 47 | SODIUM_EXPORT 48 | int crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state, 49 | const unsigned char *key); 50 | 51 | SODIUM_EXPORT 52 | int crypto_onetimeauth_poly1305_update(crypto_onetimeauth_poly1305_state *state, 53 | const unsigned char *in, 54 | unsigned long long inlen); 55 | 56 | SODIUM_EXPORT 57 | int crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state, 58 | unsigned char *out); 59 | 60 | SODIUM_EXPORT 61 | void crypto_onetimeauth_poly1305_keygen(unsigned char k[crypto_onetimeauth_poly1305_KEYBYTES]); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_scalarmult.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_scalarmult_H 2 | #define crypto_scalarmult_H 3 | 4 | #include 5 | 6 | #include "crypto_scalarmult_curve25519.h" 7 | #include "export.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES 14 | SODIUM_EXPORT 15 | size_t crypto_scalarmult_bytes(void); 16 | 17 | #define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES 18 | SODIUM_EXPORT 19 | size_t crypto_scalarmult_scalarbytes(void); 20 | 21 | #define crypto_scalarmult_PRIMITIVE "curve25519" 22 | SODIUM_EXPORT 23 | const char *crypto_scalarmult_primitive(void); 24 | 25 | SODIUM_EXPORT 26 | int crypto_scalarmult_base(unsigned char *q, const unsigned char *n); 27 | 28 | SODIUM_EXPORT 29 | int crypto_scalarmult(unsigned char *q, const unsigned char *n, 30 | const unsigned char *p) 31 | __attribute__ ((warn_unused_result)); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_scalarmult_curve25519.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_scalarmult_curve25519_H 2 | #define crypto_scalarmult_curve25519_H 3 | 4 | #include 5 | 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define crypto_scalarmult_curve25519_BYTES 32U 13 | SODIUM_EXPORT 14 | size_t crypto_scalarmult_curve25519_bytes(void); 15 | 16 | #define crypto_scalarmult_curve25519_SCALARBYTES 32U 17 | SODIUM_EXPORT 18 | size_t crypto_scalarmult_curve25519_scalarbytes(void); 19 | 20 | SODIUM_EXPORT 21 | int crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n, 22 | const unsigned char *p) 23 | __attribute__ ((warn_unused_result)); 24 | 25 | SODIUM_EXPORT 26 | int crypto_scalarmult_curve25519_base(unsigned char *q, const unsigned char *n); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_secretbox.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_secretbox_H 2 | #define crypto_secretbox_H 3 | 4 | #include 5 | 6 | #include "crypto_secretbox_xsalsa20poly1305.h" 7 | #include "export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | #define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES 17 | SODIUM_EXPORT 18 | size_t crypto_secretbox_keybytes(void); 19 | 20 | #define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES 21 | SODIUM_EXPORT 22 | size_t crypto_secretbox_noncebytes(void); 23 | 24 | #define crypto_secretbox_MACBYTES crypto_secretbox_xsalsa20poly1305_MACBYTES 25 | SODIUM_EXPORT 26 | size_t crypto_secretbox_macbytes(void); 27 | 28 | #define crypto_secretbox_PRIMITIVE "xsalsa20poly1305" 29 | SODIUM_EXPORT 30 | const char *crypto_secretbox_primitive(void); 31 | 32 | #define crypto_secretbox_MESSAGEBYTES_MAX crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX 33 | SODIUM_EXPORT 34 | size_t crypto_secretbox_messagebytes_max(void); 35 | 36 | SODIUM_EXPORT 37 | int crypto_secretbox_easy(unsigned char *c, const unsigned char *m, 38 | unsigned long long mlen, const unsigned char *n, 39 | const unsigned char *k); 40 | 41 | SODIUM_EXPORT 42 | int crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c, 43 | unsigned long long clen, const unsigned char *n, 44 | const unsigned char *k) 45 | __attribute__ ((warn_unused_result)); 46 | 47 | SODIUM_EXPORT 48 | int crypto_secretbox_detached(unsigned char *c, unsigned char *mac, 49 | const unsigned char *m, 50 | unsigned long long mlen, 51 | const unsigned char *n, 52 | const unsigned char *k); 53 | 54 | SODIUM_EXPORT 55 | int crypto_secretbox_open_detached(unsigned char *m, 56 | const unsigned char *c, 57 | const unsigned char *mac, 58 | unsigned long long clen, 59 | const unsigned char *n, 60 | const unsigned char *k) 61 | __attribute__ ((warn_unused_result)); 62 | 63 | SODIUM_EXPORT 64 | void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES]); 65 | 66 | /* -- NaCl compatibility interface ; Requires padding -- */ 67 | 68 | #define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES 69 | SODIUM_EXPORT 70 | size_t crypto_secretbox_zerobytes(void); 71 | 72 | #define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES 73 | SODIUM_EXPORT 74 | size_t crypto_secretbox_boxzerobytes(void); 75 | 76 | SODIUM_EXPORT 77 | int crypto_secretbox(unsigned char *c, const unsigned char *m, 78 | unsigned long long mlen, const unsigned char *n, 79 | const unsigned char *k); 80 | 81 | SODIUM_EXPORT 82 | int crypto_secretbox_open(unsigned char *m, const unsigned char *c, 83 | unsigned long long clen, const unsigned char *n, 84 | const unsigned char *k) 85 | __attribute__ ((warn_unused_result)); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_secretbox_xchacha20poly1305.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_secretbox_xchacha20poly1305_H 2 | #define crypto_secretbox_xchacha20poly1305_H 3 | 4 | #include 5 | #include "crypto_stream_xchacha20.h" 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | # ifdef __GNUC__ 10 | # pragma GCC diagnostic ignored "-Wlong-long" 11 | # endif 12 | extern "C" { 13 | #endif 14 | 15 | #define crypto_secretbox_xchacha20poly1305_KEYBYTES 32U 16 | SODIUM_EXPORT 17 | size_t crypto_secretbox_xchacha20poly1305_keybytes(void); 18 | 19 | #define crypto_secretbox_xchacha20poly1305_NONCEBYTES 24U 20 | SODIUM_EXPORT 21 | size_t crypto_secretbox_xchacha20poly1305_noncebytes(void); 22 | 23 | #define crypto_secretbox_xchacha20poly1305_MACBYTES 16U 24 | SODIUM_EXPORT 25 | size_t crypto_secretbox_xchacha20poly1305_macbytes(void); 26 | 27 | #define crypto_secretbox_xchacha20poly1305_MESSAGEBYTES_MAX \ 28 | (crypto_stream_xchacha20_MESSAGEBYTES_MAX - crypto_secretbox_xchacha20poly1305_MACBYTES) 29 | SODIUM_EXPORT 30 | size_t crypto_secretbox_xchacha20poly1305_messagebytes_max(void); 31 | 32 | SODIUM_EXPORT 33 | int crypto_secretbox_xchacha20poly1305_easy(unsigned char *c, 34 | const unsigned char *m, 35 | unsigned long long mlen, 36 | const unsigned char *n, 37 | const unsigned char *k); 38 | 39 | SODIUM_EXPORT 40 | int crypto_secretbox_xchacha20poly1305_open_easy(unsigned char *m, 41 | const unsigned char *c, 42 | unsigned long long clen, 43 | const unsigned char *n, 44 | const unsigned char *k) 45 | __attribute__ ((warn_unused_result)); 46 | 47 | SODIUM_EXPORT 48 | int crypto_secretbox_xchacha20poly1305_detached(unsigned char *c, 49 | unsigned char *mac, 50 | const unsigned char *m, 51 | unsigned long long mlen, 52 | const unsigned char *n, 53 | const unsigned char *k); 54 | 55 | SODIUM_EXPORT 56 | int crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m, 57 | const unsigned char *c, 58 | const unsigned char *mac, 59 | unsigned long long clen, 60 | const unsigned char *n, 61 | const unsigned char *k) 62 | __attribute__ ((warn_unused_result)); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_secretbox_xsalsa20poly1305_H 2 | #define crypto_secretbox_xsalsa20poly1305_H 3 | 4 | #include 5 | #include "crypto_stream_xsalsa20.h" 6 | #include "export.h" 7 | 8 | #ifdef __cplusplus 9 | # ifdef __GNUC__ 10 | # pragma GCC diagnostic ignored "-Wlong-long" 11 | # endif 12 | extern "C" { 13 | #endif 14 | 15 | #define crypto_secretbox_xsalsa20poly1305_KEYBYTES 32U 16 | SODIUM_EXPORT 17 | size_t crypto_secretbox_xsalsa20poly1305_keybytes(void); 18 | 19 | #define crypto_secretbox_xsalsa20poly1305_NONCEBYTES 24U 20 | SODIUM_EXPORT 21 | size_t crypto_secretbox_xsalsa20poly1305_noncebytes(void); 22 | 23 | #define crypto_secretbox_xsalsa20poly1305_MACBYTES 16U 24 | SODIUM_EXPORT 25 | size_t crypto_secretbox_xsalsa20poly1305_macbytes(void); 26 | 27 | /* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */ 28 | #define crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX \ 29 | (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_secretbox_xsalsa20poly1305_MACBYTES) 30 | SODIUM_EXPORT 31 | size_t crypto_secretbox_xsalsa20poly1305_messagebytes_max(void); 32 | 33 | SODIUM_EXPORT 34 | int crypto_secretbox_xsalsa20poly1305(unsigned char *c, 35 | const unsigned char *m, 36 | unsigned long long mlen, 37 | const unsigned char *n, 38 | const unsigned char *k); 39 | 40 | SODIUM_EXPORT 41 | int crypto_secretbox_xsalsa20poly1305_open(unsigned char *m, 42 | const unsigned char *c, 43 | unsigned long long clen, 44 | const unsigned char *n, 45 | const unsigned char *k) 46 | __attribute__ ((warn_unused_result)); 47 | 48 | SODIUM_EXPORT 49 | void crypto_secretbox_xsalsa20poly1305_keygen(unsigned char k[crypto_secretbox_xsalsa20poly1305_KEYBYTES]); 50 | 51 | /* -- NaCl compatibility interface ; Requires padding -- */ 52 | 53 | #define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES 16U 54 | SODIUM_EXPORT 55 | size_t crypto_secretbox_xsalsa20poly1305_boxzerobytes(void); 56 | 57 | #define crypto_secretbox_xsalsa20poly1305_ZEROBYTES \ 58 | (crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES + \ 59 | crypto_secretbox_xsalsa20poly1305_MACBYTES) 60 | SODIUM_EXPORT 61 | size_t crypto_secretbox_xsalsa20poly1305_zerobytes(void); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_secretstream_xchacha20poly1305.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_secretstream_xchacha20poly1305_H 2 | #define crypto_secretstream_xchacha20poly1305_H 3 | 4 | #include 5 | 6 | #include "crypto_aead_xchacha20poly1305.h" 7 | #include "crypto_stream_chacha20.h" 8 | #include "export.h" 9 | 10 | #ifdef __cplusplus 11 | # ifdef __GNUC__ 12 | # pragma GCC diagnostic ignored "-Wlong-long" 13 | # endif 14 | extern "C" { 15 | #endif 16 | 17 | #define crypto_secretstream_xchacha20poly1305_ABYTES \ 18 | (1U + crypto_aead_xchacha20poly1305_ietf_ABYTES) 19 | SODIUM_EXPORT 20 | size_t crypto_secretstream_xchacha20poly1305_abytes(void); 21 | 22 | #define crypto_secretstream_xchacha20poly1305_HEADERBYTES \ 23 | crypto_aead_xchacha20poly1305_ietf_NPUBBYTES 24 | SODIUM_EXPORT 25 | size_t crypto_secretstream_xchacha20poly1305_headerbytes(void); 26 | 27 | #define crypto_secretstream_xchacha20poly1305_KEYBYTES \ 28 | crypto_aead_xchacha20poly1305_ietf_KEYBYTES 29 | SODIUM_EXPORT 30 | size_t crypto_secretstream_xchacha20poly1305_keybytes(void); 31 | 32 | #define crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX \ 33 | SODIUM_MIN(SODIUM_SIZE_MAX, ((1ULL << 32) - 2ULL) * 64ULL) 34 | SODIUM_EXPORT 35 | size_t crypto_secretstream_xchacha20poly1305_messagebytes_max(void); 36 | 37 | #define crypto_secretstream_xchacha20poly1305_TAG_MESSAGE 0x00 38 | SODIUM_EXPORT 39 | unsigned char crypto_secretstream_xchacha20poly1305_tag_message(void); 40 | 41 | #define crypto_secretstream_xchacha20poly1305_TAG_PUSH 0x01 42 | SODIUM_EXPORT 43 | unsigned char crypto_secretstream_xchacha20poly1305_tag_push(void); 44 | 45 | #define crypto_secretstream_xchacha20poly1305_TAG_REKEY 0x02 46 | SODIUM_EXPORT 47 | unsigned char crypto_secretstream_xchacha20poly1305_tag_rekey(void); 48 | 49 | #define crypto_secretstream_xchacha20poly1305_TAG_FINAL \ 50 | (crypto_secretstream_xchacha20poly1305_TAG_PUSH | \ 51 | crypto_secretstream_xchacha20poly1305_TAG_REKEY) 52 | SODIUM_EXPORT 53 | unsigned char crypto_secretstream_xchacha20poly1305_tag_final(void); 54 | 55 | typedef struct crypto_secretstream_xchacha20poly1305_state { 56 | unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES]; 57 | unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES]; 58 | unsigned char _pad[8]; 59 | } crypto_secretstream_xchacha20poly1305_state; 60 | 61 | SODIUM_EXPORT 62 | size_t crypto_secretstream_xchacha20poly1305_statebytes(void); 63 | 64 | SODIUM_EXPORT 65 | void crypto_secretstream_xchacha20poly1305_keygen 66 | (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]); 67 | 68 | SODIUM_EXPORT 69 | int crypto_secretstream_xchacha20poly1305_init_push 70 | (crypto_secretstream_xchacha20poly1305_state *state, 71 | unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES], 72 | const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]); 73 | 74 | SODIUM_EXPORT 75 | int crypto_secretstream_xchacha20poly1305_push 76 | (crypto_secretstream_xchacha20poly1305_state *state, 77 | unsigned char *c, unsigned long long *clen_p, 78 | const unsigned char *m, unsigned long long mlen, 79 | const unsigned char *ad, unsigned long long adlen, unsigned char tag); 80 | 81 | SODIUM_EXPORT 82 | int crypto_secretstream_xchacha20poly1305_init_pull 83 | (crypto_secretstream_xchacha20poly1305_state *state, 84 | const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES], 85 | const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]); 86 | 87 | SODIUM_EXPORT 88 | int crypto_secretstream_xchacha20poly1305_pull 89 | (crypto_secretstream_xchacha20poly1305_state *state, 90 | unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p, 91 | const unsigned char *c, unsigned long long clen, 92 | const unsigned char *ad, unsigned long long adlen); 93 | 94 | SODIUM_EXPORT 95 | void crypto_secretstream_xchacha20poly1305_rekey 96 | (crypto_secretstream_xchacha20poly1305_state *state); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_shorthash.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_shorthash_H 2 | #define crypto_shorthash_H 3 | 4 | #include 5 | 6 | #include "crypto_shorthash_siphash24.h" 7 | #include "export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | #define crypto_shorthash_BYTES crypto_shorthash_siphash24_BYTES 17 | SODIUM_EXPORT 18 | size_t crypto_shorthash_bytes(void); 19 | 20 | #define crypto_shorthash_KEYBYTES crypto_shorthash_siphash24_KEYBYTES 21 | SODIUM_EXPORT 22 | size_t crypto_shorthash_keybytes(void); 23 | 24 | #define crypto_shorthash_PRIMITIVE "siphash24" 25 | SODIUM_EXPORT 26 | const char *crypto_shorthash_primitive(void); 27 | 28 | SODIUM_EXPORT 29 | int crypto_shorthash(unsigned char *out, const unsigned char *in, 30 | unsigned long long inlen, const unsigned char *k); 31 | 32 | SODIUM_EXPORT 33 | void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES]); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_shorthash_siphash24.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_shorthash_siphash24_H 2 | #define crypto_shorthash_siphash24_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | # ifdef __GNUC__ 9 | # pragma GCC diagnostic ignored "-Wlong-long" 10 | # endif 11 | extern "C" { 12 | #endif 13 | 14 | /* -- 64-bit output -- */ 15 | 16 | #define crypto_shorthash_siphash24_BYTES 8U 17 | SODIUM_EXPORT 18 | size_t crypto_shorthash_siphash24_bytes(void); 19 | 20 | #define crypto_shorthash_siphash24_KEYBYTES 16U 21 | SODIUM_EXPORT 22 | size_t crypto_shorthash_siphash24_keybytes(void); 23 | 24 | SODIUM_EXPORT 25 | int crypto_shorthash_siphash24(unsigned char *out, const unsigned char *in, 26 | unsigned long long inlen, const unsigned char *k); 27 | 28 | #ifndef SODIUM_LIBRARY_MINIMAL 29 | /* -- 128-bit output -- */ 30 | 31 | #define crypto_shorthash_siphashx24_BYTES 16U 32 | SODIUM_EXPORT 33 | size_t crypto_shorthash_siphashx24_bytes(void); 34 | 35 | #define crypto_shorthash_siphashx24_KEYBYTES 16U 36 | SODIUM_EXPORT 37 | size_t crypto_shorthash_siphashx24_keybytes(void); 38 | 39 | SODIUM_EXPORT 40 | int crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in, 41 | unsigned long long inlen, const unsigned char *k); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_sign.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_sign_H 2 | #define crypto_sign_H 3 | 4 | /* 5 | * THREAD SAFETY: crypto_sign_keypair() is thread-safe, 6 | * provided that sodium_init() was called before. 7 | * 8 | * Other functions, including crypto_sign_seed_keypair() are always thread-safe. 9 | */ 10 | 11 | #include 12 | 13 | #include "crypto_sign_ed25519.h" 14 | #include "export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | typedef crypto_sign_ed25519ph_state crypto_sign_state; 24 | 25 | SODIUM_EXPORT 26 | size_t crypto_sign_statebytes(void); 27 | 28 | #define crypto_sign_BYTES crypto_sign_ed25519_BYTES 29 | SODIUM_EXPORT 30 | size_t crypto_sign_bytes(void); 31 | 32 | #define crypto_sign_SEEDBYTES crypto_sign_ed25519_SEEDBYTES 33 | SODIUM_EXPORT 34 | size_t crypto_sign_seedbytes(void); 35 | 36 | #define crypto_sign_PUBLICKEYBYTES crypto_sign_ed25519_PUBLICKEYBYTES 37 | SODIUM_EXPORT 38 | size_t crypto_sign_publickeybytes(void); 39 | 40 | #define crypto_sign_SECRETKEYBYTES crypto_sign_ed25519_SECRETKEYBYTES 41 | SODIUM_EXPORT 42 | size_t crypto_sign_secretkeybytes(void); 43 | 44 | #define crypto_sign_MESSAGEBYTES_MAX crypto_sign_ed25519_MESSAGEBYTES_MAX 45 | SODIUM_EXPORT 46 | size_t crypto_sign_messagebytes_max(void); 47 | 48 | #define crypto_sign_PRIMITIVE "ed25519" 49 | SODIUM_EXPORT 50 | const char *crypto_sign_primitive(void); 51 | 52 | SODIUM_EXPORT 53 | int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, 54 | const unsigned char *seed); 55 | 56 | SODIUM_EXPORT 57 | int crypto_sign_keypair(unsigned char *pk, unsigned char *sk); 58 | 59 | SODIUM_EXPORT 60 | int crypto_sign(unsigned char *sm, unsigned long long *smlen_p, 61 | const unsigned char *m, unsigned long long mlen, 62 | const unsigned char *sk); 63 | 64 | SODIUM_EXPORT 65 | int crypto_sign_open(unsigned char *m, unsigned long long *mlen_p, 66 | const unsigned char *sm, unsigned long long smlen, 67 | const unsigned char *pk) 68 | __attribute__ ((warn_unused_result)); 69 | 70 | SODIUM_EXPORT 71 | int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p, 72 | const unsigned char *m, unsigned long long mlen, 73 | const unsigned char *sk); 74 | 75 | SODIUM_EXPORT 76 | int crypto_sign_verify_detached(const unsigned char *sig, 77 | const unsigned char *m, 78 | unsigned long long mlen, 79 | const unsigned char *pk) 80 | __attribute__ ((warn_unused_result)); 81 | 82 | SODIUM_EXPORT 83 | int crypto_sign_init(crypto_sign_state *state); 84 | 85 | SODIUM_EXPORT 86 | int crypto_sign_update(crypto_sign_state *state, 87 | const unsigned char *m, unsigned long long mlen); 88 | 89 | SODIUM_EXPORT 90 | int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig, 91 | unsigned long long *siglen_p, 92 | const unsigned char *sk); 93 | 94 | SODIUM_EXPORT 95 | int crypto_sign_final_verify(crypto_sign_state *state, unsigned char *sig, 96 | const unsigned char *pk) 97 | __attribute__ ((warn_unused_result)); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_sign_edwards25519sha512batch.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_sign_edwards25519sha512batch_H 2 | #define crypto_sign_edwards25519sha512batch_H 3 | 4 | /* 5 | * WARNING: This construction was a prototype, which should not be used 6 | * any more in new projects. 7 | * 8 | * crypto_sign_edwards25519sha512batch is provided for applications 9 | * initially built with NaCl, but as recommended by the author of this 10 | * construction, new applications should use ed25519 instead. 11 | * 12 | * In Sodium, you should use the high-level crypto_sign_*() functions instead. 13 | */ 14 | 15 | #include 16 | #include "export.h" 17 | 18 | #ifdef __cplusplus 19 | # ifdef __GNUC__ 20 | # pragma GCC diagnostic ignored "-Wlong-long" 21 | # endif 22 | extern "C" { 23 | #endif 24 | 25 | #define crypto_sign_edwards25519sha512batch_BYTES 64U 26 | #define crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES 32U 27 | #define crypto_sign_edwards25519sha512batch_SECRETKEYBYTES (32U + 32U) 28 | #define crypto_sign_edwards25519sha512batch_MESSAGEBYTES_MAX (SODIUM_SIZE_MAX - crypto_sign_edwards25519sha512batch_BYTES) 29 | 30 | SODIUM_EXPORT 31 | int crypto_sign_edwards25519sha512batch(unsigned char *sm, 32 | unsigned long long *smlen_p, 33 | const unsigned char *m, 34 | unsigned long long mlen, 35 | const unsigned char *sk) 36 | __attribute__ ((deprecated)); 37 | 38 | SODIUM_EXPORT 39 | int crypto_sign_edwards25519sha512batch_open(unsigned char *m, 40 | unsigned long long *mlen_p, 41 | const unsigned char *sm, 42 | unsigned long long smlen, 43 | const unsigned char *pk) 44 | __attribute__ ((deprecated)); 45 | 46 | SODIUM_EXPORT 47 | int crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk, 48 | unsigned char *sk) 49 | __attribute__ ((deprecated)); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_H 2 | #define crypto_stream_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | 14 | #include "crypto_stream_xsalsa20.h" 15 | #include "export.h" 16 | 17 | #ifdef __cplusplus 18 | # ifdef __GNUC__ 19 | # pragma GCC diagnostic ignored "-Wlong-long" 20 | # endif 21 | extern "C" { 22 | #endif 23 | 24 | #define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES 25 | SODIUM_EXPORT 26 | size_t crypto_stream_keybytes(void); 27 | 28 | #define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES 29 | SODIUM_EXPORT 30 | size_t crypto_stream_noncebytes(void); 31 | 32 | #define crypto_stream_MESSAGEBYTES_MAX crypto_stream_xsalsa20_MESSAGEBYTES_MAX 33 | SODIUM_EXPORT 34 | size_t crypto_stream_messagebytes_max(void); 35 | 36 | #define crypto_stream_PRIMITIVE "xsalsa20" 37 | SODIUM_EXPORT 38 | const char *crypto_stream_primitive(void); 39 | 40 | SODIUM_EXPORT 41 | int crypto_stream(unsigned char *c, unsigned long long clen, 42 | const unsigned char *n, const unsigned char *k); 43 | 44 | SODIUM_EXPORT 45 | int crypto_stream_xor(unsigned char *c, const unsigned char *m, 46 | unsigned long long mlen, const unsigned char *n, 47 | const unsigned char *k); 48 | 49 | SODIUM_EXPORT 50 | void crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES]); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream_chacha20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_chacha20_H 2 | #define crypto_stream_chacha20_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include 14 | #include "export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | #define crypto_stream_chacha20_KEYBYTES 32U 24 | SODIUM_EXPORT 25 | size_t crypto_stream_chacha20_keybytes(void); 26 | 27 | #define crypto_stream_chacha20_NONCEBYTES 8U 28 | SODIUM_EXPORT 29 | size_t crypto_stream_chacha20_noncebytes(void); 30 | 31 | #define crypto_stream_chacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 32 | SODIUM_EXPORT 33 | size_t crypto_stream_chacha20_messagebytes_max(void); 34 | 35 | /* ChaCha20 with a 64-bit nonce and a 64-bit counter, as originally designed */ 36 | 37 | SODIUM_EXPORT 38 | int crypto_stream_chacha20(unsigned char *c, unsigned long long clen, 39 | const unsigned char *n, const unsigned char *k); 40 | 41 | SODIUM_EXPORT 42 | int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m, 43 | unsigned long long mlen, const unsigned char *n, 44 | const unsigned char *k); 45 | 46 | SODIUM_EXPORT 47 | int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m, 48 | unsigned long long mlen, 49 | const unsigned char *n, uint64_t ic, 50 | const unsigned char *k); 51 | 52 | SODIUM_EXPORT 53 | void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES]); 54 | 55 | /* ChaCha20 with a 96-bit nonce and a 32-bit counter (IETF) */ 56 | 57 | #define crypto_stream_chacha20_ietf_KEYBYTES 32U 58 | SODIUM_EXPORT 59 | size_t crypto_stream_chacha20_ietf_keybytes(void); 60 | 61 | #define crypto_stream_chacha20_ietf_NONCEBYTES 12U 62 | SODIUM_EXPORT 63 | size_t crypto_stream_chacha20_ietf_noncebytes(void); 64 | 65 | #define crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX \ 66 | SODIUM_MIN(SODIUM_SIZE_MAX, 64ULL * (1ULL << 32)) 67 | SODIUM_EXPORT 68 | size_t crypto_stream_chacha20_ietf_messagebytes_max(void); 69 | 70 | SODIUM_EXPORT 71 | int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen, 72 | const unsigned char *n, const unsigned char *k); 73 | 74 | SODIUM_EXPORT 75 | int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m, 76 | unsigned long long mlen, const unsigned char *n, 77 | const unsigned char *k); 78 | 79 | SODIUM_EXPORT 80 | int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m, 81 | unsigned long long mlen, 82 | const unsigned char *n, uint32_t ic, 83 | const unsigned char *k); 84 | 85 | SODIUM_EXPORT 86 | void crypto_stream_chacha20_ietf_keygen(unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES]); 87 | 88 | /* Aliases */ 89 | 90 | #define crypto_stream_chacha20_IETF_KEYBYTES crypto_stream_chacha20_ietf_KEYBYTES 91 | #define crypto_stream_chacha20_IETF_NONCEBYTES crypto_stream_chacha20_ietf_NONCEBYTES 92 | #define crypto_stream_chacha20_IETF_MESSAGEBYTES_MAX crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream_salsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_salsa20_H 2 | #define crypto_stream_salsa20_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include 14 | #include "export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | #define crypto_stream_salsa20_KEYBYTES 32U 24 | SODIUM_EXPORT 25 | size_t crypto_stream_salsa20_keybytes(void); 26 | 27 | #define crypto_stream_salsa20_NONCEBYTES 8U 28 | SODIUM_EXPORT 29 | size_t crypto_stream_salsa20_noncebytes(void); 30 | 31 | #define crypto_stream_salsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 32 | SODIUM_EXPORT 33 | size_t crypto_stream_salsa20_messagebytes_max(void); 34 | 35 | SODIUM_EXPORT 36 | int crypto_stream_salsa20(unsigned char *c, unsigned long long clen, 37 | const unsigned char *n, const unsigned char *k); 38 | 39 | SODIUM_EXPORT 40 | int crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m, 41 | unsigned long long mlen, const unsigned char *n, 42 | const unsigned char *k); 43 | 44 | SODIUM_EXPORT 45 | int crypto_stream_salsa20_xor_ic(unsigned char *c, const unsigned char *m, 46 | unsigned long long mlen, 47 | const unsigned char *n, uint64_t ic, 48 | const unsigned char *k); 49 | 50 | SODIUM_EXPORT 51 | void crypto_stream_salsa20_keygen(unsigned char k[crypto_stream_salsa20_KEYBYTES]); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream_salsa2012.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_salsa2012_H 2 | #define crypto_stream_salsa2012_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include "export.h" 14 | 15 | #ifdef __cplusplus 16 | # ifdef __GNUC__ 17 | # pragma GCC diagnostic ignored "-Wlong-long" 18 | # endif 19 | extern "C" { 20 | #endif 21 | 22 | #define crypto_stream_salsa2012_KEYBYTES 32U 23 | SODIUM_EXPORT 24 | size_t crypto_stream_salsa2012_keybytes(void); 25 | 26 | #define crypto_stream_salsa2012_NONCEBYTES 8U 27 | SODIUM_EXPORT 28 | size_t crypto_stream_salsa2012_noncebytes(void); 29 | 30 | #define crypto_stream_salsa2012_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 31 | SODIUM_EXPORT 32 | size_t crypto_stream_salsa2012_messagebytes_max(void); 33 | 34 | SODIUM_EXPORT 35 | int crypto_stream_salsa2012(unsigned char *c, unsigned long long clen, 36 | const unsigned char *n, const unsigned char *k); 37 | 38 | SODIUM_EXPORT 39 | int crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m, 40 | unsigned long long mlen, const unsigned char *n, 41 | const unsigned char *k); 42 | 43 | SODIUM_EXPORT 44 | void crypto_stream_salsa2012_keygen(unsigned char k[crypto_stream_salsa2012_KEYBYTES]); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream_salsa208.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_salsa208_H 2 | #define crypto_stream_salsa208_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include "export.h" 14 | 15 | #ifdef __cplusplus 16 | # ifdef __GNUC__ 17 | # pragma GCC diagnostic ignored "-Wlong-long" 18 | # endif 19 | extern "C" { 20 | #endif 21 | 22 | #define crypto_stream_salsa208_KEYBYTES 32U 23 | SODIUM_EXPORT 24 | size_t crypto_stream_salsa208_keybytes(void) 25 | __attribute__ ((deprecated)); 26 | 27 | #define crypto_stream_salsa208_NONCEBYTES 8U 28 | SODIUM_EXPORT 29 | size_t crypto_stream_salsa208_noncebytes(void) 30 | __attribute__ ((deprecated)); 31 | 32 | #define crypto_stream_salsa208_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 33 | SODIUM_EXPORT 34 | size_t crypto_stream_salsa208_messagebytes_max(void) 35 | __attribute__ ((deprecated)); 36 | 37 | SODIUM_EXPORT 38 | int crypto_stream_salsa208(unsigned char *c, unsigned long long clen, 39 | const unsigned char *n, const unsigned char *k) 40 | __attribute__ ((deprecated)); 41 | 42 | SODIUM_EXPORT 43 | int crypto_stream_salsa208_xor(unsigned char *c, const unsigned char *m, 44 | unsigned long long mlen, const unsigned char *n, 45 | const unsigned char *k) 46 | __attribute__ ((deprecated)); 47 | 48 | SODIUM_EXPORT 49 | void crypto_stream_salsa208_keygen(unsigned char k[crypto_stream_salsa208_KEYBYTES]) 50 | __attribute__ ((deprecated)); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream_xchacha20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_xchacha20_H 2 | #define crypto_stream_xchacha20_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include 14 | #include "export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | #define crypto_stream_xchacha20_KEYBYTES 32U 24 | SODIUM_EXPORT 25 | size_t crypto_stream_xchacha20_keybytes(void); 26 | 27 | #define crypto_stream_xchacha20_NONCEBYTES 24U 28 | SODIUM_EXPORT 29 | size_t crypto_stream_xchacha20_noncebytes(void); 30 | 31 | #define crypto_stream_xchacha20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 32 | SODIUM_EXPORT 33 | size_t crypto_stream_xchacha20_messagebytes_max(void); 34 | 35 | SODIUM_EXPORT 36 | int crypto_stream_xchacha20(unsigned char *c, unsigned long long clen, 37 | const unsigned char *n, const unsigned char *k); 38 | 39 | SODIUM_EXPORT 40 | int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m, 41 | unsigned long long mlen, const unsigned char *n, 42 | const unsigned char *k); 43 | 44 | SODIUM_EXPORT 45 | int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m, 46 | unsigned long long mlen, 47 | const unsigned char *n, uint64_t ic, 48 | const unsigned char *k); 49 | 50 | SODIUM_EXPORT 51 | void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES]); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_stream_xsalsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_xsalsa20_H 2 | #define crypto_stream_xsalsa20_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include 14 | #include "export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | #define crypto_stream_xsalsa20_KEYBYTES 32U 24 | SODIUM_EXPORT 25 | size_t crypto_stream_xsalsa20_keybytes(void); 26 | 27 | #define crypto_stream_xsalsa20_NONCEBYTES 24U 28 | SODIUM_EXPORT 29 | size_t crypto_stream_xsalsa20_noncebytes(void); 30 | 31 | #define crypto_stream_xsalsa20_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 32 | SODIUM_EXPORT 33 | size_t crypto_stream_xsalsa20_messagebytes_max(void); 34 | 35 | SODIUM_EXPORT 36 | int crypto_stream_xsalsa20(unsigned char *c, unsigned long long clen, 37 | const unsigned char *n, const unsigned char *k); 38 | 39 | SODIUM_EXPORT 40 | int crypto_stream_xsalsa20_xor(unsigned char *c, const unsigned char *m, 41 | unsigned long long mlen, const unsigned char *n, 42 | const unsigned char *k); 43 | 44 | SODIUM_EXPORT 45 | int crypto_stream_xsalsa20_xor_ic(unsigned char *c, const unsigned char *m, 46 | unsigned long long mlen, 47 | const unsigned char *n, uint64_t ic, 48 | const unsigned char *k); 49 | 50 | SODIUM_EXPORT 51 | void crypto_stream_xsalsa20_keygen(unsigned char k[crypto_stream_xsalsa20_KEYBYTES]); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_verify_16.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_16_H 2 | #define crypto_verify_16_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_verify_16_BYTES 16U 12 | SODIUM_EXPORT 13 | size_t crypto_verify_16_bytes(void); 14 | 15 | SODIUM_EXPORT 16 | int crypto_verify_16(const unsigned char *x, const unsigned char *y) 17 | __attribute__ ((warn_unused_result)); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_verify_32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_32_H 2 | #define crypto_verify_32_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_verify_32_BYTES 32U 12 | SODIUM_EXPORT 13 | size_t crypto_verify_32_bytes(void); 14 | 15 | SODIUM_EXPORT 16 | int crypto_verify_32(const unsigned char *x, const unsigned char *y) 17 | __attribute__ ((warn_unused_result)); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /sodium/include/sodium/crypto_verify_64.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_64_H 2 | #define crypto_verify_64_H 3 | 4 | #include 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_verify_64_BYTES 64U 12 | SODIUM_EXPORT 13 | size_t crypto_verify_64_bytes(void); 14 | 15 | SODIUM_EXPORT 16 | int crypto_verify_64(const unsigned char *x, const unsigned char *y) 17 | __attribute__ ((warn_unused_result)); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /sodium/include/sodium/export.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_export_H 3 | #define sodium_export_H 4 | 5 | #ifndef __GNUC__ 6 | # ifdef __attribute__ 7 | # undef __attribute__ 8 | # endif 9 | # define __attribute__(a) 10 | #endif 11 | 12 | #ifdef SODIUM_STATIC 13 | # define SODIUM_EXPORT 14 | # define SODIUM_EXPORT_WEAK 15 | #else 16 | # if defined(_MSC_VER) 17 | # ifdef SODIUM_DLL_EXPORT 18 | # define SODIUM_EXPORT __declspec(dllexport) 19 | # else 20 | # define SODIUM_EXPORT __declspec(dllimport) 21 | # endif 22 | # else 23 | # if defined(__SUNPRO_C) 24 | # ifndef __GNU_C__ 25 | # define SODIUM_EXPORT __attribute__ (visibility(__global)) 26 | # else 27 | # define SODIUM_EXPORT __attribute__ __global 28 | # endif 29 | # elif defined(_MSG_VER) 30 | # define SODIUM_EXPORT extern __declspec(dllexport) 31 | # else 32 | # define SODIUM_EXPORT __attribute__ ((visibility ("default"))) 33 | # endif 34 | # endif 35 | # if defined(__ELF__) && !defined(SODIUM_DISABLE_WEAK_FUNCTIONS) 36 | # define SODIUM_EXPORT_WEAK SODIUM_EXPORT __attribute__((weak)) 37 | # else 38 | # define SODIUM_EXPORT_WEAK SODIUM_EXPORT 39 | # endif 40 | #endif 41 | 42 | #ifndef CRYPTO_ALIGN 43 | # if defined(__INTEL_COMPILER) || defined(_MSC_VER) 44 | # define CRYPTO_ALIGN(x) __declspec(align(x)) 45 | # else 46 | # define CRYPTO_ALIGN(x) __attribute__ ((aligned(x))) 47 | # endif 48 | #endif 49 | 50 | #define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B)) 51 | #define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX) 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /sodium/include/sodium/private/implementations.h: -------------------------------------------------------------------------------- 1 | #ifndef implementations_H 2 | #define implementations_H 3 | 4 | int _crypto_generichash_blake2b_pick_best_implementation(void); 5 | int _crypto_onetimeauth_poly1305_pick_best_implementation(void); 6 | int _crypto_pwhash_argon2_pick_best_implementation(void); 7 | int _crypto_scalarmult_curve25519_pick_best_implementation(void); 8 | int _crypto_stream_chacha20_pick_best_implementation(void); 9 | int _crypto_stream_salsa20_pick_best_implementation(void); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /sodium/include/sodium/private/mutex.h: -------------------------------------------------------------------------------- 1 | #ifndef mutex_H 2 | #define mutex_H 1 3 | 4 | extern int sodium_crit_enter(void); 5 | extern int sodium_crit_leave(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /sodium/include/sodium/private/sse2_64_32.h: -------------------------------------------------------------------------------- 1 | #ifndef sse2_64_32_H 2 | #define sse2_64_32_H 1 3 | 4 | #include "common.h" 5 | 6 | #ifdef HAVE_INTRIN_H 7 | # include 8 | #endif 9 | 10 | #if defined(HAVE_EMMINTRIN_H) && \ 11 | !(defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || \ 12 | defined(_M_X64) || defined(_M_AMD64)) 13 | 14 | # include 15 | # include 16 | 17 | # ifndef _mm_set_epi64x 18 | # define _mm_set_epi64x(Q0, Q1) sodium__mm_set_epi64x((Q0), (Q1)) 19 | static inline __m128i 20 | sodium__mm_set_epi64x(int64_t q1, int64_t q0) 21 | { 22 | union { int64_t as64; int32_t as32[2]; } x0, x1; 23 | x0.as64 = q0; x1.as64 = q1; 24 | return _mm_set_epi32(x1.as32[1], x1.as32[0], x0.as32[1], x0.as32[0]); 25 | } 26 | # endif 27 | 28 | # ifndef _mm_set1_epi64x 29 | # define _mm_set1_epi64x(Q) sodium__mm_set1_epi64x(Q) 30 | static inline __m128i 31 | sodium__mm_set1_epi64x(int64_t q) 32 | { 33 | return _mm_set_epi64x(q, q); 34 | } 35 | # endif 36 | 37 | # ifndef _mm_cvtsi64_si128 38 | # define _mm_cvtsi64_si128(Q) sodium__mm_cvtsi64_si128(Q) 39 | static inline __m128i 40 | sodium__mm_cvtsi64_si128(int64_t q) 41 | { 42 | union { int64_t as64; int32_t as32[2]; } x; 43 | x.as64 = q; 44 | return _mm_setr_epi32(x.as32[0], x.as32[1], 0, 0); 45 | } 46 | # endif 47 | 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /sodium/include/sodium/randombytes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_H 3 | #define randombytes_H 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "export.h" 11 | 12 | #ifdef __cplusplus 13 | # ifdef __GNUC__ 14 | # pragma GCC diagnostic ignored "-Wlong-long" 15 | # endif 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct randombytes_implementation { 20 | const char *(*implementation_name)(void); /* required */ 21 | uint32_t (*random)(void); /* required */ 22 | void (*stir)(void); /* optional */ 23 | uint32_t (*uniform)(const uint32_t upper_bound); /* optional, a default implementation will be used if NULL */ 24 | void (*buf)(void * const buf, const size_t size); /* required */ 25 | int (*close)(void); /* optional */ 26 | } randombytes_implementation; 27 | 28 | #define randombytes_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 0xffffffffUL) 29 | 30 | #define randombytes_SEEDBYTES 32U 31 | SODIUM_EXPORT 32 | size_t randombytes_seedbytes(void); 33 | 34 | SODIUM_EXPORT 35 | void randombytes_buf(void * const buf, const size_t size); 36 | 37 | SODIUM_EXPORT 38 | void randombytes_buf_deterministic(void * const buf, const size_t size, 39 | const unsigned char seed[randombytes_SEEDBYTES]); 40 | 41 | SODIUM_EXPORT 42 | uint32_t randombytes_random(void); 43 | 44 | SODIUM_EXPORT 45 | uint32_t randombytes_uniform(const uint32_t upper_bound); 46 | 47 | SODIUM_EXPORT 48 | void randombytes_stir(void); 49 | 50 | SODIUM_EXPORT 51 | int randombytes_close(void); 52 | 53 | SODIUM_EXPORT 54 | int randombytes_set_implementation(randombytes_implementation *impl); 55 | 56 | SODIUM_EXPORT 57 | const char *randombytes_implementation_name(void); 58 | 59 | /* -- NaCl compatibility interface -- */ 60 | 61 | SODIUM_EXPORT 62 | void randombytes(unsigned char * const buf, const unsigned long long buf_len); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /sodium/include/sodium/randombytes_nativeclient.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_nativeclient_H 3 | #define randombytes_nativeclient_H 4 | 5 | #ifdef __native_client__ 6 | 7 | # include "export.h" 8 | # include "randombytes.h" 9 | 10 | # ifdef __cplusplus 11 | extern "C" { 12 | # endif 13 | 14 | SODIUM_EXPORT 15 | extern struct randombytes_implementation randombytes_nativeclient_implementation; 16 | 17 | # ifdef __cplusplus 18 | } 19 | # endif 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /sodium/include/sodium/randombytes_salsa20_random.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_salsa20_random_H 3 | #define randombytes_salsa20_random_H 4 | 5 | #include "export.h" 6 | #include "randombytes.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | SODIUM_EXPORT 13 | extern struct randombytes_implementation randombytes_salsa20_implementation; 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /sodium/include/sodium/randombytes_sysrandom.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_sysrandom_H 3 | #define randombytes_sysrandom_H 4 | 5 | #include "export.h" 6 | #include "randombytes.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | SODIUM_EXPORT 13 | extern struct randombytes_implementation randombytes_sysrandom_implementation; 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /sodium/include/sodium/runtime.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_runtime_H 3 | #define sodium_runtime_H 4 | 5 | #include "export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | SODIUM_EXPORT_WEAK 12 | int sodium_runtime_has_neon(void); 13 | 14 | SODIUM_EXPORT_WEAK 15 | int sodium_runtime_has_sse2(void); 16 | 17 | SODIUM_EXPORT_WEAK 18 | int sodium_runtime_has_sse3(void); 19 | 20 | SODIUM_EXPORT_WEAK 21 | int sodium_runtime_has_ssse3(void); 22 | 23 | SODIUM_EXPORT_WEAK 24 | int sodium_runtime_has_sse41(void); 25 | 26 | SODIUM_EXPORT_WEAK 27 | int sodium_runtime_has_avx(void); 28 | 29 | SODIUM_EXPORT_WEAK 30 | int sodium_runtime_has_avx2(void); 31 | 32 | SODIUM_EXPORT_WEAK 33 | int sodium_runtime_has_avx512f(void); 34 | 35 | SODIUM_EXPORT_WEAK 36 | int sodium_runtime_has_pclmul(void); 37 | 38 | SODIUM_EXPORT_WEAK 39 | int sodium_runtime_has_aesni(void); 40 | 41 | /* ------------------------------------------------------------------------- */ 42 | 43 | int _sodium_runtime_get_cpu_features(void); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /sodium/include/sodium/version.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_version_H 3 | #define sodium_version_H 4 | 5 | #include "export.h" 6 | 7 | #define SODIUM_VERSION_STRING "1.0.15" 8 | 9 | #define SODIUM_LIBRARY_VERSION_MAJOR 10 10 | #define SODIUM_LIBRARY_VERSION_MINOR 0 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | SODIUM_EXPORT 18 | const char *sodium_version_string(void); 19 | 20 | SODIUM_EXPORT 21 | int sodium_library_version_major(void); 22 | 23 | SODIUM_EXPORT 24 | int sodium_library_version_minor(void); 25 | 26 | SODIUM_EXPORT 27 | int sodium_library_minimal(void); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /sodium/include/sodium/version.h.in: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_version_H 3 | #define sodium_version_H 4 | 5 | #include "export.h" 6 | 7 | #define SODIUM_VERSION_STRING "@VERSION@" 8 | 9 | #define SODIUM_LIBRARY_VERSION_MAJOR @SODIUM_LIBRARY_VERSION_MAJOR@ 10 | #define SODIUM_LIBRARY_VERSION_MINOR @SODIUM_LIBRARY_VERSION_MINOR@ 11 | @SODIUM_LIBRARY_MINIMAL_DEF@ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | SODIUM_EXPORT 18 | const char *sodium_version_string(void); 19 | 20 | SODIUM_EXPORT 21 | int sodium_library_version_major(void); 22 | 23 | SODIUM_EXPORT 24 | int sodium_library_version_minor(void); 25 | 26 | SODIUM_EXPORT 27 | int sodium_library_minimal(void); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /sodium/nacl_ed25519.c: -------------------------------------------------------------------------------- 1 | /* Round trip unit test of using libsodium's Ed25519 digital signature code. 2 | * 3 | * 1) Generates a random Ed25519 Secret(signing)/Public(verifying) key pair using libsodium 4 | * 2) Signs a test message 5 | * 3) Verifies the signature of this test message 6 | */ 7 | 8 | // A project using libsodium should include the sodium.h header. 9 | // Including individual headers from libsodium is neither required nor recommended. 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | int ret = EXIT_FAILURE; 18 | 19 | // The sodium_init() function should be called before any other function. 20 | // It is safe to call sodium_init() multiple times, or from different threads; it will 21 | // immediately return 1 without doing anything if the library has already been initialized. 22 | // After this function returns, all of the other functions provided by Sodium will be 23 | // thread-safe. Before returning, the function ensures that the system's random number 24 | // generator has been properly seeded. On some Linux systems, this may take some time, 25 | // especially when called right after a reboot of the system 26 | if (sodium_init() < 0) 27 | { 28 | /* panic! the library couldn't be initialized, it is not safe to use */ 29 | printf("ERROR: The sodium library couldn't be initialized!\n"); 30 | return EXIT_FAILURE; 31 | } 32 | 33 | // Buffer to hold the public key (verifying key) 34 | unsigned char public_key[crypto_sign_PUBLICKEYBYTES]; 35 | 36 | // Buffer to hold the secret key (signing key) - has extra info so public key can be derived 37 | unsigned char secret_key[crypto_sign_SECRETKEYBYTES]; 38 | 39 | // Buffers to hold hexadecimal encoded versions of the keys (with a null terminator) 40 | #define PUBLICKEY_HEX_BYTES (2 * crypto_sign_PUBLICKEYBYTES + 1) 41 | #define SECRETKEY_HEX_BYTES (2 * crypto_sign_SECRETKEYBYTES + 1) 42 | char hex_public[PUBLICKEY_HEX_BYTES]; 43 | char hex_secret[SECRETKEY_HEX_BYTES]; 44 | 45 | // crypto_sign_keypair() function randomly generates a secret key and a corresponding public key 46 | crypto_sign_keypair(public_key, secret_key); 47 | 48 | // Convert the binary keys into a hexadecimal strings 49 | sodium_bin2hex(hex_public, PUBLICKEY_HEX_BYTES, public_key, crypto_sign_PUBLICKEYBYTES); 50 | sodium_bin2hex(hex_secret, SECRETKEY_HEX_BYTES, secret_key, crypto_sign_SECRETKEYBYTES); 51 | 52 | // Print the keys to the screen with hexadecimal encoding 53 | printf("Generated a signing/verifying key pair:\n"); 54 | printf("\tSecret key: %s\n", hex_secret); 55 | printf("\tPublic key: %s\n", hex_public); 56 | 57 | // Now go through a full sign and verify process with a dummy message just to make sure it works 58 | #define MESSAGE (const unsigned char *) "test" 59 | #define MESSAGE_LEN 4 60 | 61 | unsigned char signed_message[crypto_sign_BYTES + MESSAGE_LEN]; 62 | unsigned long long signed_message_len; 63 | 64 | printf("Signing a test message ..."); 65 | crypto_sign(signed_message, &signed_message_len, MESSAGE, MESSAGE_LEN, secret_key); 66 | printf(" Done\n"); 67 | 68 | unsigned char unsigned_message[MESSAGE_LEN]; 69 | unsigned long long unsigned_message_len; 70 | printf("Verifying the test signed message ..."); 71 | ret = crypto_sign_open(unsigned_message, &unsigned_message_len, signed_message, signed_message_len, public_key); 72 | if ( ret != 0) 73 | { 74 | printf(" invalid signature"); 75 | } 76 | else 77 | { 78 | printf(" OK\n"); 79 | } 80 | 81 | return ret; 82 | } 83 | --------------------------------------------------------------------------------