├── src ├── vector │ ├── VectorConfig.h │ ├── Vector.h │ ├── Pair.h │ ├── Abort.h │ ├── static │ │ └── StaticVector.h │ └── dynamic │ │ └── DynamicVector.h ├── client │ ├── stm32_time_fix.c │ ├── UniquePtr.h │ └── Memory.h └── bssl │ ├── bssl_config.h │ ├── ec_default.c │ ├── ssl_client_default_rsapub.c │ ├── ssl_engine_default_rsavrfy.c │ ├── i15_tmont.c │ ├── i31_tmont.c │ ├── i32_tmont.c │ ├── ecdsa_default_sign_raw.c │ ├── ecdsa_default_vrfy_raw.c │ ├── ecdsa_default_sign_asn1.c │ ├── ecdsa_default_vrfy_asn1.c │ ├── enc16be.c │ ├── enc16le.c │ ├── enc32be.c │ ├── enc32le.c │ ├── enc64be.c │ ├── enc64le.c │ ├── dec16be.c │ ├── dec16le.c │ ├── dec32be.c │ ├── dec32le.c │ ├── dec64be.c │ ├── dec64le.c │ ├── i15_iszero.c │ ├── i31_iszero.c │ ├── i32_iszero.c │ ├── i32_ninv32.c │ ├── rsa_default_pubexp.c │ ├── rsa_default_modulus.c │ ├── rsa_default_privexp.c │ ├── i31_ninv31.c │ ├── ssl_engine_default_ec.c │ ├── i15_ninv15.c │ ├── rsa_default_keygen.c │ ├── rsa_default_pub.c │ ├── rsa_default_priv.c │ ├── rsa_default_pss_sign.c │ ├── rsa_default_pss_vrfy.c │ ├── rsa_default_pkcs1_sign.c │ ├── rsa_default_pkcs1_vrfy.c │ ├── rsa_default_oaep_decrypt.c │ ├── rsa_default_oaep_encrypt.c │ ├── ccopy.c │ ├── ssl_engine_default_descbc.c │ ├── prf_sha256.c │ ├── prf_sha384.c │ ├── rsa_i31_keygen.c │ ├── rsa_i15_pkcs1_sign.c │ ├── rsa_i31_pkcs1_sign.c │ ├── rsa_i32_pkcs1_sign.c │ ├── i15_bitlen.c │ ├── i31_bitlen.c │ ├── i32_bitlen.c │ ├── ssl_engine_default_ecdsa.c │ ├── ssl_hashes.c │ ├── i15_rshift.c │ ├── i15_sub.c │ ├── i31_rshift.c │ ├── i31_sub.c │ ├── i15_add.c │ ├── i31_add.c │ ├── rsa_i15_oaep_decrypt.c │ ├── rsa_i31_oaep_decrypt.c │ ├── rsa_i32_oaep_decrypt.c │ ├── rsa_i15_pss_sign.c │ ├── rsa_i31_pss_sign.c │ ├── rsa_i32_pss_sign.c │ ├── ecdsa_i15_bits.c │ ├── rsa_i15_pkcs1_vrfy.c │ ├── rsa_i31_pkcs1_vrfy.c │ ├── rsa_i32_pkcs1_vrfy.c │ ├── ecdsa_i31_bits.c │ ├── prf_md5sha1.c │ ├── rsa_i15_oaep_encrypt.c │ ├── rsa_i31_oaep_encrypt.c │ ├── rsa_i32_oaep_encrypt.c │ ├── rsa_i15_pss_vrfy.c │ ├── rsa_i31_pss_vrfy.c │ ├── rsa_i32_pss_vrfy.c │ ├── i32_add.c │ ├── i32_sub.c │ ├── dig_size.c │ ├── ecdsa_i15_sign_asn1.c │ ├── ecdsa_i31_sign_asn1.c │ ├── i15_decode.c │ ├── i15_encode.c │ ├── i31_decode.c │ ├── i15_modpow.c │ ├── i32_mulacc.c │ ├── i32_div32.c │ ├── rsa_i62_keygen.c │ ├── ec_curve25519.c │ ├── rsa_i62_pkcs1_sign.c │ ├── rsa_ssl_decrypt.c │ ├── i32_decode.c │ ├── ecdsa_i15_vrfy_asn1.c │ ├── ecdsa_i31_vrfy_asn1.c │ ├── mgf1.c │ ├── rsa_i62_pss_sign.c │ ├── rsa_i62_oaep_decrypt.c │ ├── ssl_server.c │ ├── rsa_i62_pkcs1_vrfy.c │ ├── rsa_i62_pss_vrfy.c │ ├── i15_fmont.c │ ├── i15_mulacc.c │ ├── rsa_i62_oaep_encrypt.c │ ├── i32_fmont.c │ ├── i31_fmont.c │ ├── ec_secp256r1.c │ └── i32_encode.c ├── .github ├── FUNDING.yml ├── stale.yml └── workflows │ └── cpp_lint.yml ├── library.json ├── library.properties ├── LICENSE ├── examples └── HTTPStreaming │ └── Server │ └── sse.php └── keywords.txt /src/vector/VectorConfig.h: -------------------------------------------------------------------------------- 1 | // VectorConfig.h 2 | #pragma once 3 | 4 | // Optional diagnostics 5 | #define VECTOR_DIAGNOSTICS_ENABLED 6 | #define VECTOR_CLEANUP_ENABLED 7 | -------------------------------------------------------------------------------- /src/vector/Vector.h: -------------------------------------------------------------------------------- 1 | // Vector.h 2 | #pragma once 3 | #include "VectorConfig.h" 4 | #include "static/StaticVector.h" 5 | #include "dynamic/DynamicVector.h" 6 | 7 | 8 | #ifdef USE_STATIC_VECTOR 9 | template 10 | using Vector = ReadyUtils::StaticVector; 11 | #else 12 | template 13 | using Vector = ReadyUtils::DynamicVector; 14 | #endif 15 | -------------------------------------------------------------------------------- /src/client/stm32_time_fix.c: -------------------------------------------------------------------------------- 1 | 2 | // _gettimeofday link missing in STM32 3 | 4 | #if !defined(STM32_TIME_FIX_C) && defined(ARDUINO_ARCH_STM32) 5 | #define STM32_TIME_FIX_C 6 | 7 | #include 8 | 9 | __attribute__((weak)) int _gettimeofday(struct timeval *tv, void *ignore __attribute__((unused))) 10 | { 11 | uint64_t t = 0; 12 | tv->tv_sec = t / 1000000000; 13 | tv->tv_usec = (t % 1000000000) / 1000; 14 | return 0; 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: mobizt 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: 13 | - https://www.buymeacoffee.com/Mobizt 14 | -------------------------------------------------------------------------------- /src/vector/Pair.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-FileCopyrightText: 2025 Suwatchai K. 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #ifndef PAIR_H 8 | #define PAIR_H 9 | 10 | namespace ReadyUtils 11 | { 12 | template 13 | struct Pair 14 | { 15 | T1 first; 16 | T2 second; 17 | 18 | constexpr Pair() = default; 19 | 20 | constexpr Pair(const T1 &a, const T2 &b) 21 | : first(a), second(b) {} 22 | 23 | template 24 | constexpr Pair(U1 &&a, U2 &&b) 25 | : first(static_cast(a)), second(static_cast(b)) {} 26 | }; 27 | } 28 | #endif -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 2 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 1 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: wontfix 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false 18 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ESP_SSLClient", 3 | "version": "3.1.2", 4 | "keywords": "TLS, SSL, SecureClient, communication, HTTPS, REST, MQTT, ESP32, ESP8266, RP2040, memory-efficient", 5 | "description": "A versatile and memory-optimized library providing Secure Layer Networking (SSL/TLS) TCP Client functionality. It is designed to work across a wide range of Arduino architectures (ESP32, ESP8266, RP2040, Teensy, SAMD, etc.) by wrapping standard network interfaces like WiFiClient and EthernetClient. Features include protocol upgrade (plain TCP to TLS), session caching, and memory-saving build modes.", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/mobizt/ESP_SSLClient.git" 9 | }, 10 | "authors": [{ 11 | "name": "Mobizt", 12 | "email": "k_suwatchai@hotmail.com" 13 | }], 14 | "frameworks": "arduino", 15 | "platforms": "atmelavr, espressif32, espressif8266, atmelsam, ststm32, teensy, rp2040, renesas-ra, intel_arc32, titiva, nordicnrf52, nxplpc" 16 | } -------------------------------------------------------------------------------- /src/bssl/bssl_config.h: -------------------------------------------------------------------------------- 1 | #ifndef BSSL_CONFIG_H 2 | #define BSSL_CONFIG_H 3 | 4 | #include 5 | 6 | #if defined(__has_include) 7 | #if __has_include("./BearSSL_Config.h") 8 | #include "./BearSSL_Config.h" 9 | #if defined(BEARSSL_CONFIG_BUILD_EXTERNAL_CORE) 10 | #define BSSL_BUILD_EXTERNAL_CORE 11 | #endif 12 | #endif 13 | #endif 14 | 15 | // Use BearSSL engine library internal or platform (ESP8266 and RP2040) 16 | // For non ESP8266 and RP2040 devices, define BSSL_BUILD_EXTERNAL_CORE when 17 | // external BearSSL libraries are used to prevent multiple functions definitions compile error. 18 | #if !defined(BSSL_BUILD_EXTERNAL_CORE) 19 | 20 | #if (defined(ESP8266) || defined(ARDUINO_ARCH_RP2040)) && !defined(ARDUINO_NANO_RP2040_CONNECT) 21 | #define BSSL_BUILD_PLATFORM_CORE 22 | #else 23 | #define BSSL_BUILD_INTERNAL_CORE 24 | #endif 25 | 26 | // workaround when these macros 27 | // are previousely defined. 28 | #if defined(MAX) 29 | #undef MAX 30 | #endif 31 | 32 | #if defined(MIN) 33 | #undef MIN 34 | #endif 35 | 36 | #endif 37 | #endif -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESP_SSLClient 2 | 3 | version=3.1.2 4 | 5 | author=Mobizt 6 | 7 | maintainer=Mobizt 8 | 9 | sentence=Secure Layer (SSL/TLS) TCP Client featuring protocol upgrade capability and optimized memory usage for resource-constrained boards. 10 | 11 | paragraph=This professional-grade library provides a robust SSL/TLS layer for network communication, designed to support modern 32-bit Arduino platforms (ESP8266, ESP32, RP2040, Teensy, etc.). It acts as a transparent wrapper, enabling secure connectivity over standard clients (WiFiClient, EthernetClient). Key advantages include support for dynamic memory allocation (PSRAM) on compatible boards, memory-saving build configurations (Insecure Only), and the ability to upgrade an existing plain TCP connection to TLS seamlessly. 12 | 13 | category=Communication 14 | 15 | url=https://github.com/mobizt/ESP_SSLClient.git 16 | 17 | architectures=avr, esp8266, esp32, sam, samd, stm32, teensy, rp2040, arc32, mbed, mbed_nano, mbed_rp2040, mbed_portenta, mbed_nicla, mbed_opta, mbed_giga, renesas_uno, renesas_portenta, apollo3, nrf52, ch32, gd32 18 | -------------------------------------------------------------------------------- /.github/workflows/cpp_lint.yml: -------------------------------------------------------------------------------- 1 | name: cpplint 2 | 3 | on: 4 | pull_request: 5 | paths-ignore: 6 | # Ignore linting check if only compilation workflow files changed 7 | - '.github/workflows/compile_*.yml' 8 | 9 | jobs: 10 | lint: # Renamed job from 'build' to 'lint' for clarity 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: ⬇️ Checkout Repository 14 | uses: actions/checkout@v4 # Updated to v4 for security and performance 15 | 16 | - name: 🔍 Run cpplint via Reviewdog 17 | uses: reviewdog/action-cpplint@v1 # Using @v1 as a common stable major version 18 | with: 19 | github_token: ${{ secrets.GITHUB_TOKEN }} 20 | reporter: github-pr-check 21 | flags: --linelength=100 22 | # Using YAML multi-line string (>) for improved filter readability 23 | filter: > 24 | -whitespace/tab, 25 | -readability/braces, 26 | -whitespace/braces, 27 | -whitespace/comments, 28 | -whitespace/indent, 29 | -whitespace/newline, 30 | -whitespace/operators, 31 | -whitespace/parens -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Suwatchai K. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/vector/Abort.h: -------------------------------------------------------------------------------- 1 | #ifndef EMBEDDED_UTILS_H 2 | #define EMBEDDED_UTILS_H 3 | 4 | /** 5 | * @file embedded_utils.h 6 | * @brief Defines cross-platform utility macros for embedded systems. 7 | * * Includes a mandatory halt/breakpoint function that minimizes code size 8 | * and is specific to the target architecture (AVR, ARM, or Desktop). 9 | */ 10 | 11 | // --- Halting/Breakpoint Macro --- 12 | 13 | // Define the core macro for unrecoverable errors/software breakpoints 14 | #if defined(__AVR__) 15 | // AVR specific: Uses the assembly BREAK instruction to halt the CPU. 16 | #define EMBEDDED_ASSERT_FAIL() asm("break") 17 | 18 | #elif defined(__arm__) || defined(__thumb__) || defined(__CC_ARM) 19 | // ARM Cortex-M specific (Used by ESP32, STM32, etc.): 20 | // Uses the software breakpoint instruction. 21 | #define EMBEDDED_ASSERT_FAIL() __asm__("bkpt #0") 22 | 23 | #else 24 | // Standard C/C++ platforms (Desktop, Linux, testing environment): 25 | // Uses the standard C library function to terminate execution. 26 | // Requires or . 27 | // #include 28 | #define EMBEDDED_ASSERT_FAIL() abort() 29 | #endif 30 | 31 | #endif // EMBEDDED_UTILS_H -------------------------------------------------------------------------------- /examples/HTTPStreaming/Server/sse.php: -------------------------------------------------------------------------------- 1 | $id, 'title' => 'title ' . $id, 'content' => 'content ' . $id]]; // Get news from database or service. 19 | if (empty($news)) { 20 | return false; // Return false if no new messages 21 | } 22 | $shouldStop = false; // Stop if something happens or to clear connection, browser will retry 23 | if ($shouldStop) { 24 | throw new StopSSEException(); 25 | } 26 | return json_encode(compact('news')); 27 | // return ['event' => 'ping', 'data' => 'ping data']; // Custom event temporarily: send ping event 28 | // return ['id' => uniqid(), 'data' => json_encode(compact('news'))]; // Custom event Id 29 | }; 30 | (new SSE(new Event($callback, 'news')))->start(); 31 | ?> -------------------------------------------------------------------------------- /src/vector/static/StaticVector.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-FileCopyrightText: 2025 Suwatchai K. 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #ifndef STATIC_VECTOR_H 8 | #define STATIC_VECTOR_H 9 | #include 10 | #include "../Abort.h" 11 | namespace ReadyUtils 12 | { 13 | 14 | #define STATIC_VECTOR_CLEANUP_ENABLED 15 | #define STATIC_VECTOR_OVERFLOW_ABORT 16 | 17 | template 18 | class StaticVector 19 | { 20 | static_assert(Capacity > 0, "StaticVector capacity must be > 0"); 21 | 22 | public: 23 | alignas(T) char data_storage[sizeof(T) * Capacity]; 24 | size_t count = 0; 25 | 26 | T *get_ptr(size_t i); 27 | const T *get_ptr(size_t i) const; 28 | 29 | inline StaticVector(); 30 | inline ~StaticVector(); 31 | 32 | inline StaticVector(const StaticVector &other); 33 | inline StaticVector &operator=(const StaticVector &other); 34 | 35 | inline constexpr size_t size() const; 36 | 37 | inline bool push_back(const T &value); 38 | inline bool push_back(T &&value); 39 | inline bool erase(size_t index); 40 | inline void clear(); 41 | 42 | inline T &operator[](size_t index); 43 | inline const T &operator[](size_t index) const; 44 | 45 | private: 46 | void handle_overflow(); 47 | }; 48 | } 49 | 50 | #include "StaticVector.hpp" 51 | 52 | #endif // STATIC_VECTOR_H 53 | -------------------------------------------------------------------------------- /src/bssl/ec_default.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ec.h */ 31 | const br_ec_impl * 32 | br_ec_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_ec_all_m15; 36 | #else 37 | return &br_ec_all_m31; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_client_default_rsapub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ssl.h */ 31 | void 32 | br_ssl_client_set_default_rsapub(br_ssl_client_context *cc) 33 | { 34 | br_ssl_client_set_rsapub(cc, br_rsa_public_get_default()); 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_engine_default_rsavrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ssl.h */ 31 | void 32 | br_ssl_engine_set_default_rsavrfy(br_ssl_engine_context *cc) 33 | { 34 | br_ssl_engine_set_rsavrfy(cc, br_rsa_pkcs1_vrfy_get_default()); 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_tmont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_to_monty(uint16_t *x, const uint16_t *m) 33 | { 34 | unsigned k; 35 | 36 | for (k = (m[0] + 15) >> 4; k > 0; k --) { 37 | br_i15_muladd_small(x, 0, m); 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_tmont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i31_to_monty(uint32_t *x, const uint32_t *m) 33 | { 34 | uint32_t k; 35 | 36 | for (k = (m[0] + 31) >> 5; k > 0; k --) { 37 | br_i31_muladd_small(x, 0, m); 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_tmont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i32_to_monty(uint32_t *x, const uint32_t *m) 33 | { 34 | uint32_t k; 35 | 36 | for (k = (m[0] + 31) >> 5; k > 0; k --) { 37 | br_i32_muladd_small(x, 0, m); 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_default_sign_raw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ec.h */ 31 | br_ecdsa_sign 32 | br_ecdsa_sign_raw_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_ecdsa_i15_sign_raw; 36 | #else 37 | return &br_ecdsa_i31_sign_raw; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_default_vrfy_raw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ec.h */ 31 | br_ecdsa_vrfy 32 | br_ecdsa_vrfy_raw_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_ecdsa_i15_vrfy_raw; 36 | #else 37 | return &br_ecdsa_i31_vrfy_raw; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_default_sign_asn1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ec.h */ 31 | br_ecdsa_sign 32 | br_ecdsa_sign_asn1_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_ecdsa_i15_sign_asn1; 36 | #else 37 | return &br_ecdsa_i31_sign_asn1; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_default_vrfy_asn1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ec.h */ 31 | br_ecdsa_vrfy 32 | br_ecdsa_vrfy_asn1_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_ecdsa_i15_vrfy_asn1; 36 | #else 37 | return &br_ecdsa_i31_vrfy_asn1; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/enc16be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_enc16be(void *dst, const uint16_t *v, size_t num) 33 | { 34 | unsigned char *buf; 35 | 36 | buf = dst; 37 | while (num -- > 0) { 38 | br_enc16be(buf, *v ++); 39 | buf += 2; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/enc16le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_enc16le(void *dst, const uint16_t *v, size_t num) 33 | { 34 | unsigned char *buf; 35 | 36 | buf = dst; 37 | while (num -- > 0) { 38 | br_enc16le(buf, *v ++); 39 | buf += 2; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/enc32be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_enc32be(void *dst, const uint32_t *v, size_t num) 33 | { 34 | unsigned char *buf; 35 | 36 | buf = dst; 37 | while (num -- > 0) { 38 | br_enc32be(buf, *v ++); 39 | buf += 4; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/enc32le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_enc32le(void *dst, const uint32_t *v, size_t num) 33 | { 34 | unsigned char *buf; 35 | 36 | buf = dst; 37 | while (num -- > 0) { 38 | br_enc32le(buf, *v ++); 39 | buf += 4; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/enc64be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_enc64be(void *dst, const uint64_t *v, size_t num) 33 | { 34 | unsigned char *buf; 35 | 36 | buf = dst; 37 | while (num -- > 0) { 38 | br_enc64be(buf, *v ++); 39 | buf += 8; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/enc64le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_enc64le(void *dst, const uint64_t *v, size_t num) 33 | { 34 | unsigned char *buf; 35 | 36 | buf = dst; 37 | while (num -- > 0) { 38 | br_enc64le(buf, *v ++); 39 | buf += 8; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/dec16be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_dec16be(uint16_t *v, size_t num, const void *src) 33 | { 34 | const unsigned char *buf; 35 | 36 | buf = src; 37 | while (num -- > 0) { 38 | *v ++ = br_dec16be(buf); 39 | buf += 2; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/dec16le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_dec16le(uint16_t *v, size_t num, const void *src) 33 | { 34 | const unsigned char *buf; 35 | 36 | buf = src; 37 | while (num -- > 0) { 38 | *v ++ = br_dec16le(buf); 39 | buf += 2; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/dec32be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_dec32be(uint32_t *v, size_t num, const void *src) 33 | { 34 | const unsigned char *buf; 35 | 36 | buf = src; 37 | while (num -- > 0) { 38 | *v ++ = br_dec32be(buf); 39 | buf += 4; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/dec32le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_dec32le(uint32_t *v, size_t num, const void *src) 33 | { 34 | const unsigned char *buf; 35 | 36 | buf = src; 37 | while (num -- > 0) { 38 | *v ++ = br_dec32le(buf); 39 | buf += 4; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/dec64be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_dec64be(uint64_t *v, size_t num, const void *src) 33 | { 34 | const unsigned char *buf; 35 | 36 | buf = src; 37 | while (num -- > 0) { 38 | *v ++ = br_dec64be(buf); 39 | buf += 8; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/dec64le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_range_dec64le(uint64_t *v, size_t num, const void *src) 33 | { 34 | const unsigned char *buf; 35 | 36 | buf = src; 37 | while (num -- > 0) { 38 | *v ++ = br_dec64le(buf); 39 | buf += 8; 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_iszero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i15_iszero(const uint16_t *x) 33 | { 34 | uint32_t z; 35 | size_t u; 36 | 37 | z = 0; 38 | for (u = (x[0] + 15) >> 4; u > 0; u --) { 39 | z |= x[u]; 40 | } 41 | return ~(z | -z) >> 31; 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_iszero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i31_iszero(const uint32_t *x) 33 | { 34 | uint32_t z; 35 | size_t u; 36 | 37 | z = 0; 38 | for (u = (x[0] + 31) >> 5; u > 0; u --) { 39 | z |= x[u]; 40 | } 41 | return ~(z | -z) >> 31; 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_iszero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i32_iszero(const uint32_t *x) 33 | { 34 | uint32_t z; 35 | size_t u; 36 | 37 | z = 0; 38 | for (u = (x[0] + 31) >> 5; u > 0; u --) { 39 | z |= x[u]; 40 | } 41 | return ~(z | -z) >> 31; 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_ninv32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i32_ninv32(uint32_t x) 33 | { 34 | uint32_t y; 35 | 36 | y = 2 - x; 37 | y *= 2 - y * x; 38 | y *= 2 - y * x; 39 | y *= 2 - y * x; 40 | y *= 2 - y * x; 41 | return MUX(x & 1, -y, 0); 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_pubexp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_compute_pubexp 32 | br_rsa_compute_pubexp_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_rsa_i15_compute_pubexp; 36 | #else 37 | return &br_rsa_i31_compute_pubexp; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_modulus.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_compute_modulus 32 | br_rsa_compute_modulus_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_rsa_i15_compute_modulus; 36 | #else 37 | return &br_rsa_i31_compute_modulus; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_privexp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_compute_privexp 32 | br_rsa_compute_privexp_get_default(void) 33 | { 34 | #if BR_LOMUL 35 | return &br_rsa_i15_compute_privexp; 36 | #else 37 | return &br_rsa_i31_compute_privexp; 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_ninv31.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i31_ninv31(uint32_t x) 33 | { 34 | uint32_t y; 35 | 36 | y = 2 - x; 37 | y *= 2 - y * x; 38 | y *= 2 - y * x; 39 | y *= 2 - y * x; 40 | y *= 2 - y * x; 41 | return MUX(x & 1, -y, 0) & 0x7FFFFFFF; 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_engine_default_ec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ssl.h */ 31 | void 32 | br_ssl_engine_set_default_ec(br_ssl_engine_context *cc) 33 | { 34 | #if BR_LOMUL 35 | br_ssl_engine_set_ec(cc, &br_ec_all_m15); 36 | #else 37 | br_ssl_engine_set_ec(cc, &br_ec_all_m31); 38 | #endif 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_ninv15.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint16_t 32 | br_i15_ninv15(uint16_t x) 33 | { 34 | uint32_t y; 35 | 36 | y = 2 - x; 37 | y = MUL15(y, 2 - MUL15(x, y)); 38 | y = MUL15(y, 2 - MUL15(x, y)); 39 | y = MUL15(y, 2 - MUL15(x, y)); 40 | return MUX(x & 1, -y, 0) & 0x7FFF; 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_keygen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_keygen 32 | br_rsa_keygen_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_keygen; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_keygen; 38 | #else 39 | return &br_rsa_i31_keygen; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_pub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_public 32 | br_rsa_public_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_public; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_public; 38 | #else 39 | return &br_rsa_i31_public; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_priv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_private 32 | br_rsa_private_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_private; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_private; 38 | #else 39 | return &br_rsa_i31_private; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_pss_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_pss_sign 32 | br_rsa_pss_sign_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_pss_sign; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_pss_sign; 38 | #else 39 | return &br_rsa_i31_pss_sign; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_pss_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_pss_vrfy 32 | br_rsa_pss_vrfy_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_pss_vrfy; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_pss_vrfy; 38 | #else 39 | return &br_rsa_i31_pss_vrfy; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_pkcs1_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_pkcs1_sign 32 | br_rsa_pkcs1_sign_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_pkcs1_sign; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_pkcs1_sign; 38 | #else 39 | return &br_rsa_i31_pkcs1_sign; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_pkcs1_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_pkcs1_vrfy 32 | br_rsa_pkcs1_vrfy_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_pkcs1_vrfy; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_pkcs1_vrfy; 38 | #else 39 | return &br_rsa_i31_pkcs1_vrfy; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_oaep_decrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_oaep_decrypt 32 | br_rsa_oaep_decrypt_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_oaep_decrypt; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_oaep_decrypt; 38 | #else 39 | return &br_rsa_i31_oaep_decrypt; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_default_oaep_encrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | br_rsa_oaep_encrypt 32 | br_rsa_oaep_encrypt_get_default(void) 33 | { 34 | #if BR_INT128 || BR_UMUL128 35 | return &br_rsa_i62_oaep_encrypt; 36 | #elif BR_LOMUL 37 | return &br_rsa_i15_oaep_encrypt; 38 | #else 39 | return &br_rsa_i31_oaep_encrypt; 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/ccopy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_ccopy(uint32_t ctl, void *dst, const void *src, size_t len) 33 | { 34 | unsigned char *d; 35 | const unsigned char *s; 36 | 37 | d = dst; 38 | s = src; 39 | while (len -- > 0) { 40 | uint32_t x, y; 41 | 42 | x = *s ++; 43 | y = *d; 44 | *d = MUX(ctl, x, y); 45 | d ++; 46 | } 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_engine_default_descbc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ssl.h */ 31 | void 32 | br_ssl_engine_set_default_des_cbc(br_ssl_engine_context *cc) 33 | { 34 | br_ssl_engine_set_cbc(cc, 35 | &br_sslrec_in_cbc_vtable, 36 | &br_sslrec_out_cbc_vtable); 37 | br_ssl_engine_set_des_cbc(cc, 38 | &br_des_ct_cbcenc_vtable, 39 | &br_des_ct_cbcdec_vtable); 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /src/bssl/prf_sha256.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl.h */ 31 | void 32 | br_tls12_sha256_prf(void *dst, size_t len, 33 | const void *secret, size_t secret_len, const char *label, 34 | size_t seed_num, const br_tls_prf_seed_chunk *seed) 35 | { 36 | memset(dst, 0, len); 37 | br_tls_phash(dst, len, &br_sha256_vtable, 38 | secret, secret_len, label, seed_num, seed); 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/prf_sha384.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl.h */ 31 | void 32 | br_tls12_sha384_prf(void *dst, size_t len, 33 | const void *secret, size_t secret_len, const char *label, 34 | size_t seed_num, const br_tls_prf_seed_chunk *seed) 35 | { 36 | memset(dst, 0, len); 37 | br_tls_phash(dst, len, &br_sha384_vtable, 38 | secret, secret_len, label, seed_num, seed); 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_keygen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i31_keygen(const br_prng_class **rng, 33 | br_rsa_private_key *sk, void *kbuf_priv, 34 | br_rsa_public_key *pk, void *kbuf_pub, 35 | unsigned size, uint32_t pubexp) 36 | { 37 | return br_rsa_i31_keygen_inner(rng, 38 | sk, kbuf_priv, pk, kbuf_pub, size, pubexp, 39 | &br_i31_modpow_opt); 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i15_pkcs1_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i15_pkcs1_sign(const unsigned char *hash_oid, 33 | const unsigned char *hash, size_t hash_len, 34 | const br_rsa_private_key *sk, unsigned char *x) 35 | { 36 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 37 | return 0; 38 | } 39 | return br_rsa_i15_private(x, sk); 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_pkcs1_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i31_pkcs1_sign(const unsigned char *hash_oid, 33 | const unsigned char *hash, size_t hash_len, 34 | const br_rsa_private_key *sk, unsigned char *x) 35 | { 36 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 37 | return 0; 38 | } 39 | return br_rsa_i31_private(x, sk); 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i32_pkcs1_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i32_pkcs1_sign(const unsigned char *hash_oid, 33 | const unsigned char *hash, size_t hash_len, 34 | const br_rsa_private_key *sk, unsigned char *x) 35 | { 36 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 37 | return 0; 38 | } 39 | return br_rsa_i32_private(x, sk); 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_bitlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i15_bit_length(uint16_t *x, size_t xlen) 33 | { 34 | uint32_t tw, twk; 35 | 36 | tw = 0; 37 | twk = 0; 38 | while (xlen -- > 0) { 39 | uint32_t w, c; 40 | 41 | c = EQ(tw, 0); 42 | w = x[xlen]; 43 | tw = MUX(c, w, tw); 44 | twk = MUX(c, (uint32_t)xlen, twk); 45 | } 46 | return (twk << 4) + BIT_LENGTH(tw); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_bitlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i31_bit_length(uint32_t *x, size_t xlen) 33 | { 34 | uint32_t tw, twk; 35 | 36 | tw = 0; 37 | twk = 0; 38 | while (xlen -- > 0) { 39 | uint32_t w, c; 40 | 41 | c = EQ(tw, 0); 42 | w = x[xlen]; 43 | tw = MUX(c, w, tw); 44 | twk = MUX(c, (uint32_t)xlen, twk); 45 | } 46 | return (twk << 5) + BIT_LENGTH(tw); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_bitlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i32_bit_length(uint32_t *x, size_t xlen) 33 | { 34 | uint32_t tw, twk; 35 | 36 | tw = 0; 37 | twk = 0; 38 | while (xlen -- > 0) { 39 | uint32_t w, c; 40 | 41 | c = EQ(tw, 0); 42 | w = x[xlen]; 43 | tw = MUX(c, w, tw); 44 | twk = MUX(c, (uint32_t)xlen, twk); 45 | } 46 | return (twk << 5) + BIT_LENGTH(tw); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_engine_default_ecdsa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ssl.h */ 31 | void 32 | br_ssl_engine_set_default_ecdsa(br_ssl_engine_context *cc) 33 | { 34 | #if BR_LOMUL 35 | br_ssl_engine_set_ec(cc, &br_ec_all_m15); 36 | br_ssl_engine_set_ecdsa(cc, &br_ecdsa_i15_vrfy_asn1); 37 | #else 38 | br_ssl_engine_set_ec(cc, &br_ec_all_m31); 39 | br_ssl_engine_set_ecdsa(cc, &br_ecdsa_i31_vrfy_asn1); 40 | #endif 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_hashes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | int 32 | br_ssl_choose_hash(unsigned bf) 33 | { 34 | static const unsigned char pref[] = { 35 | br_sha256_ID, br_sha384_ID, br_sha512_ID, 36 | br_sha224_ID, br_sha1_ID 37 | }; 38 | size_t u; 39 | 40 | for (u = 0; u < sizeof pref; u ++) { 41 | int x; 42 | 43 | x = pref[u]; 44 | if ((bf >> x) & 1) { 45 | return x; 46 | } 47 | } 48 | return 0; 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_rshift.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_rshift(uint16_t *x, int count) 33 | { 34 | size_t u, len; 35 | unsigned r; 36 | 37 | len = (x[0] + 15) >> 4; 38 | if (len == 0) { 39 | return; 40 | } 41 | r = x[1] >> count; 42 | for (u = 2; u <= len; u ++) { 43 | unsigned w; 44 | 45 | w = x[u]; 46 | x[u - 1] = ((w << (15 - count)) | r) & 0x7FFF; 47 | r = w >> count; 48 | } 49 | x[len] = r; 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i15_sub(uint16_t *a, const uint16_t *b, uint32_t ctl) 33 | { 34 | uint32_t cc; 35 | size_t u, m; 36 | 37 | cc = 0; 38 | m = (a[0] + 31) >> 4; 39 | for (u = 1; u < m; u ++) { 40 | uint32_t aw, bw, naw; 41 | 42 | aw = a[u]; 43 | bw = b[u]; 44 | naw = aw - bw - cc; 45 | cc = naw >> 31; 46 | a[u] = MUX(ctl, naw & 0x7FFF, aw); 47 | } 48 | return cc; 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_rshift.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i31_rshift(uint32_t *x, int count) 33 | { 34 | size_t u, len; 35 | uint32_t r; 36 | 37 | len = (x[0] + 31) >> 5; 38 | if (len == 0) { 39 | return; 40 | } 41 | r = x[1] >> count; 42 | for (u = 2; u <= len; u ++) { 43 | uint32_t w; 44 | 45 | w = x[u]; 46 | x[u - 1] = ((w << (31 - count)) | r) & 0x7FFFFFFF; 47 | r = w >> count; 48 | } 49 | x[len] = r; 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i31_sub(uint32_t *a, const uint32_t *b, uint32_t ctl) 33 | { 34 | uint32_t cc; 35 | size_t u, m; 36 | 37 | cc = 0; 38 | m = (a[0] + 63) >> 5; 39 | for (u = 1; u < m; u ++) { 40 | uint32_t aw, bw, naw; 41 | 42 | aw = a[u]; 43 | bw = b[u]; 44 | naw = aw - bw - cc; 45 | cc = naw >> 31; 46 | a[u] = MUX(ctl, naw & 0x7FFFFFFF, aw); 47 | } 48 | return cc; 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #include "bssl_config.h" 27 | #if defined(BSSL_BUILD_INTERNAL_CORE) 28 | 29 | #include "inner.h" 30 | 31 | /* see inner.h */ 32 | uint32_t 33 | br_i15_add(uint16_t *a, const uint16_t *b, uint32_t ctl) 34 | { 35 | uint32_t cc; 36 | size_t u, m; 37 | 38 | cc = 0; 39 | m = (a[0] + 31) >> 4; 40 | for (u = 1; u < m; u ++) { 41 | uint32_t aw, bw, naw; 42 | 43 | aw = a[u]; 44 | bw = b[u]; 45 | naw = aw + bw + cc; 46 | cc = naw >> 15; 47 | a[u] = MUX(ctl, naw & 0x7FFF, aw); 48 | } 49 | return cc; 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i31_add(uint32_t *a, const uint32_t *b, uint32_t ctl) 33 | { 34 | uint32_t cc; 35 | size_t u, m; 36 | 37 | cc = 0; 38 | m = (a[0] + 63) >> 5; 39 | for (u = 1; u < m; u ++) { 40 | uint32_t aw, bw, naw; 41 | 42 | aw = a[u]; 43 | bw = b[u]; 44 | naw = aw + bw + cc; 45 | cc = naw >> 31; 46 | a[u] = MUX(ctl, naw & (uint32_t)0x7FFFFFFF, aw); 47 | } 48 | return cc; 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i15_oaep_decrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i15_oaep_decrypt(const br_hash_class *dig, 33 | const void *label, size_t label_len, 34 | const br_rsa_private_key *sk, void *data, size_t *len) 35 | { 36 | uint32_t r; 37 | 38 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 39 | return 0; 40 | } 41 | r = br_rsa_i15_private(data, sk); 42 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 43 | return r; 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_oaep_decrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i31_oaep_decrypt(const br_hash_class *dig, 33 | const void *label, size_t label_len, 34 | const br_rsa_private_key *sk, void *data, size_t *len) 35 | { 36 | uint32_t r; 37 | 38 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 39 | return 0; 40 | } 41 | r = br_rsa_i31_private(data, sk); 42 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 43 | return r; 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i32_oaep_decrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i32_oaep_decrypt(const br_hash_class *dig, 33 | const void *label, size_t label_len, 34 | const br_rsa_private_key *sk, void *data, size_t *len) 35 | { 36 | uint32_t r; 37 | 38 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 39 | return 0; 40 | } 41 | r = br_rsa_i32_private(data, sk); 42 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 43 | return r; 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i15_pss_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i15_pss_sign(const br_prng_class **rng, 33 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 34 | const unsigned char *hash, size_t salt_len, 35 | const br_rsa_private_key *sk, unsigned char *x) 36 | { 37 | if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, 38 | salt_len, sk->n_bitlen, x)) 39 | { 40 | return 0; 41 | } 42 | return br_rsa_i15_private(x, sk); 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_pss_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i31_pss_sign(const br_prng_class **rng, 33 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 34 | const unsigned char *hash, size_t salt_len, 35 | const br_rsa_private_key *sk, unsigned char *x) 36 | { 37 | if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, 38 | salt_len, sk->n_bitlen, x)) 39 | { 40 | return 0; 41 | } 42 | return br_rsa_i31_private(x, sk); 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i32_pss_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i32_pss_sign(const br_prng_class **rng, 33 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 34 | const unsigned char *hash, size_t salt_len, 35 | const br_rsa_private_key *sk, unsigned char *x) 36 | { 37 | if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, 38 | salt_len, sk->n_bitlen, x)) 39 | { 40 | return 0; 41 | } 42 | return br_rsa_i32_private(x, sk); 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /src/client/UniquePtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 Suwatchai K. 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | namespace ReadyUtils { 10 | 11 | template 12 | struct default_delete { 13 | void operator()(T* ptr) const { 14 | delete ptr; 15 | } 16 | }; 17 | 18 | template > 19 | class unique_ptr { 20 | private: 21 | T* ptr; 22 | D deleter; 23 | 24 | public: 25 | 26 | explicit unique_ptr(T* p = nullptr) : ptr(p) {} 27 | 28 | ~unique_ptr() { 29 | if (ptr) deleter(ptr); 30 | } 31 | 32 | unique_ptr(const unique_ptr&) = delete; 33 | unique_ptr& operator=(const unique_ptr&) = delete; 34 | 35 | unique_ptr(unique_ptr&& other) noexcept : ptr(other.ptr) { 36 | other.ptr = nullptr; 37 | } 38 | 39 | unique_ptr& operator=(unique_ptr&& other) noexcept { 40 | if (this != &other) { 41 | if (ptr) deleter(ptr); // Clean up current 42 | ptr = other.ptr; // Take new 43 | other.ptr = nullptr; // Nullify source 44 | } 45 | return *this; 46 | } 47 | 48 | T* get() const { return ptr; } 49 | T& operator*() const { return *ptr; } 50 | T* operator->() const { return ptr; } 51 | 52 | explicit operator bool() const { return ptr != nullptr; } 53 | 54 | T* release() { 55 | T* temp = ptr; 56 | ptr = nullptr; 57 | return temp; 58 | } 59 | 60 | void reset(T* p = nullptr) { 61 | if (ptr) deleter(ptr); 62 | ptr = p; 63 | } 64 | }; 65 | 66 | template 67 | unique_ptr make_unique(Args&&... args) { 68 | return unique_ptr(new T(static_cast(args)...)); 69 | } 70 | } -------------------------------------------------------------------------------- /src/bssl/ecdsa_i15_bits.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_ecdsa_i15_bits2int(uint16_t *x, 33 | const void *src, size_t len, uint32_t ebitlen) 34 | { 35 | uint32_t bitlen, hbitlen; 36 | int sc; 37 | 38 | bitlen = ebitlen - (ebitlen >> 4); 39 | hbitlen = (uint32_t)len << 3; 40 | if (hbitlen > bitlen) { 41 | len = (bitlen + 7) >> 3; 42 | sc = (int)((hbitlen - bitlen) & 7); 43 | } else { 44 | sc = 0; 45 | } 46 | br_i15_zero(x, ebitlen); 47 | br_i15_decode(x, src, len); 48 | br_i15_rshift(x, sc); 49 | x[0] = ebitlen; 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i15_pkcs1_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i15_pkcs1_vrfy(const unsigned char *x, size_t xlen, 33 | const unsigned char *hash_oid, size_t hash_len, 34 | const br_rsa_public_key *pk, unsigned char *hash_out) 35 | { 36 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 37 | 38 | if (xlen > (sizeof sig)) { 39 | return 0; 40 | } 41 | memcpy(sig, x, xlen); 42 | if (!br_rsa_i15_public(sig, xlen, pk)) { 43 | return 0; 44 | } 45 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_pkcs1_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i31_pkcs1_vrfy(const unsigned char *x, size_t xlen, 33 | const unsigned char *hash_oid, size_t hash_len, 34 | const br_rsa_public_key *pk, unsigned char *hash_out) 35 | { 36 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 37 | 38 | if (xlen > (sizeof sig)) { 39 | return 0; 40 | } 41 | memcpy(sig, x, xlen); 42 | if (!br_rsa_i31_public(sig, xlen, pk)) { 43 | return 0; 44 | } 45 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i32_pkcs1_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i32_pkcs1_vrfy(const unsigned char *x, size_t xlen, 33 | const unsigned char *hash_oid, size_t hash_len, 34 | const br_rsa_public_key *pk, unsigned char *hash_out) 35 | { 36 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 37 | 38 | if (xlen > (sizeof sig)) { 39 | return 0; 40 | } 41 | memcpy(sig, x, xlen); 42 | if (!br_rsa_i32_public(sig, xlen, pk)) { 43 | return 0; 44 | } 45 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_i31_bits.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #include "bssl_config.h" 27 | #if defined(BSSL_BUILD_INTERNAL_CORE) 28 | 29 | #include "inner.h" 30 | 31 | /* see inner.h */ 32 | void 33 | br_ecdsa_i31_bits2int(uint32_t *x, 34 | const void *src, size_t len, uint32_t ebitlen) 35 | { 36 | uint32_t bitlen, hbitlen; 37 | int sc; 38 | 39 | bitlen = ebitlen - (ebitlen >> 5); 40 | hbitlen = (uint32_t)len << 3; 41 | if (hbitlen > bitlen) { 42 | len = (bitlen + 7) >> 3; 43 | sc = (int)((hbitlen - bitlen) & 7); 44 | } else { 45 | sc = 0; 46 | } 47 | br_i31_zero(x, ebitlen); 48 | br_i31_decode(x, src, len); 49 | br_i31_rshift(x, sc); 50 | x[0] = ebitlen; 51 | } 52 | 53 | #endif -------------------------------------------------------------------------------- /src/bssl/prf_md5sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl.h */ 31 | void 32 | br_tls10_prf(void *dst, size_t len, 33 | const void *secret, size_t secret_len, const char *label, 34 | size_t seed_num, const br_tls_prf_seed_chunk *seed) 35 | { 36 | const unsigned char *s1; 37 | size_t slen; 38 | 39 | s1 = secret; 40 | slen = (secret_len + 1) >> 1; 41 | memset(dst, 0, len); 42 | br_tls_phash(dst, len, &br_md5_vtable, 43 | s1, slen, label, seed_num, seed); 44 | br_tls_phash(dst, len, &br_sha1_vtable, 45 | s1 + secret_len - slen, slen, label, seed_num, seed); 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i15_oaep_encrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | size_t 32 | br_rsa_i15_oaep_encrypt( 33 | const br_prng_class **rnd, const br_hash_class *dig, 34 | const void *label, size_t label_len, 35 | const br_rsa_public_key *pk, 36 | void *dst, size_t dst_max_len, 37 | const void *src, size_t src_len) 38 | { 39 | size_t dlen; 40 | 41 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 42 | pk, dst, dst_max_len, src, src_len); 43 | if (dlen == 0) { 44 | return 0; 45 | } 46 | return dlen & -(size_t)br_rsa_i15_public(dst, dlen, pk); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_oaep_encrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | size_t 32 | br_rsa_i31_oaep_encrypt( 33 | const br_prng_class **rnd, const br_hash_class *dig, 34 | const void *label, size_t label_len, 35 | const br_rsa_public_key *pk, 36 | void *dst, size_t dst_max_len, 37 | const void *src, size_t src_len) 38 | { 39 | size_t dlen; 40 | 41 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 42 | pk, dst, dst_max_len, src, src_len); 43 | if (dlen == 0) { 44 | return 0; 45 | } 46 | return dlen & -(size_t)br_rsa_i31_public(dst, dlen, pk); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i32_oaep_encrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | size_t 32 | br_rsa_i32_oaep_encrypt( 33 | const br_prng_class **rnd, const br_hash_class *dig, 34 | const void *label, size_t label_len, 35 | const br_rsa_public_key *pk, 36 | void *dst, size_t dst_max_len, 37 | const void *src, size_t src_len) 38 | { 39 | size_t dlen; 40 | 41 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 42 | pk, dst, dst_max_len, src, src_len); 43 | if (dlen == 0) { 44 | return 0; 45 | } 46 | return dlen & -(size_t)br_rsa_i32_public(dst, dlen, pk); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i15_pss_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i15_pss_vrfy(const unsigned char *x, size_t xlen, 33 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 34 | const void *hash, size_t salt_len, const br_rsa_public_key *pk) 35 | { 36 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 37 | 38 | if (xlen > (sizeof sig)) { 39 | return 0; 40 | } 41 | memcpy(sig, x, xlen); 42 | if (!br_rsa_i15_public(sig, xlen, pk)) { 43 | return 0; 44 | } 45 | return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, 46 | hash, salt_len, pk, sig); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i31_pss_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i31_pss_vrfy(const unsigned char *x, size_t xlen, 33 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 34 | const void *hash, size_t salt_len, const br_rsa_public_key *pk) 35 | { 36 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 37 | 38 | if (xlen > (sizeof sig)) { 39 | return 0; 40 | } 41 | memcpy(sig, x, xlen); 42 | if (!br_rsa_i31_public(sig, xlen, pk)) { 43 | return 0; 44 | } 45 | return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, 46 | hash, salt_len, pk, sig); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i32_pss_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_i32_pss_vrfy(const unsigned char *x, size_t xlen, 33 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 34 | const void *hash, size_t salt_len, const br_rsa_public_key *pk) 35 | { 36 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 37 | 38 | if (xlen > (sizeof sig)) { 39 | return 0; 40 | } 41 | memcpy(sig, x, xlen); 42 | if (!br_rsa_i32_public(sig, xlen, pk)) { 43 | return 0; 44 | } 45 | return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, 46 | hash, salt_len, pk, sig); 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i32_add(uint32_t *a, const uint32_t *b, uint32_t ctl) 33 | { 34 | uint32_t cc; 35 | size_t u, m; 36 | 37 | cc = 0; 38 | m = (a[0] + 63) >> 5; 39 | for (u = 1; u < m; u ++) { 40 | uint32_t aw, bw, naw; 41 | 42 | aw = a[u]; 43 | bw = b[u]; 44 | naw = aw + bw + cc; 45 | 46 | /* 47 | * Carry is 1 if naw < aw. Carry is also 1 if naw == aw 48 | * AND the carry was already 1. 49 | */ 50 | cc = (cc & EQ(naw, aw)) | LT(naw, aw); 51 | a[u] = MUX(ctl, naw, aw); 52 | } 53 | return cc; 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_i32_sub(uint32_t *a, const uint32_t *b, uint32_t ctl) 33 | { 34 | uint32_t cc; 35 | size_t u, m; 36 | 37 | cc = 0; 38 | m = (a[0] + 63) >> 5; 39 | for (u = 1; u < m; u ++) { 40 | uint32_t aw, bw, naw; 41 | 42 | aw = a[u]; 43 | bw = b[u]; 44 | naw = aw - bw - cc; 45 | 46 | /* 47 | * Carry is 1 if naw > aw. Carry is 1 also if naw == aw 48 | * AND the carry was already 1. 49 | */ 50 | cc = (cc & EQ(naw, aw)) | GT(naw, aw); 51 | a[u] = MUX(ctl, naw, aw); 52 | } 53 | return cc; 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /src/bssl/dig_size.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | size_t 32 | br_digest_size_by_ID(int digest_id) 33 | { 34 | switch (digest_id) { 35 | case br_md5sha1_ID: 36 | return br_md5_SIZE + br_sha1_SIZE; 37 | case br_md5_ID: 38 | return br_md5_SIZE; 39 | case br_sha1_ID: 40 | return br_sha1_SIZE; 41 | case br_sha224_ID: 42 | return br_sha224_SIZE; 43 | case br_sha256_ID: 44 | return br_sha256_SIZE; 45 | case br_sha384_ID: 46 | return br_sha384_SIZE; 47 | case br_sha512_ID: 48 | return br_sha512_SIZE; 49 | default: 50 | /* abort(); */ 51 | return 0; 52 | } 53 | } 54 | 55 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_i15_sign_asn1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 31 | 32 | /* see bearssl_ec.h */ 33 | size_t 34 | br_ecdsa_i15_sign_asn1(const br_ec_impl *impl, 35 | const br_hash_class *hf, const void *hash_value, 36 | const br_ec_private_key *sk, void *sig) 37 | { 38 | unsigned char rsig[(ORDER_LEN << 1) + 12]; 39 | size_t sig_len; 40 | 41 | sig_len = br_ecdsa_i15_sign_raw(impl, hf, hash_value, sk, rsig); 42 | if (sig_len == 0) { 43 | return 0; 44 | } 45 | sig_len = br_ecdsa_raw_to_asn1(rsig, sig_len); 46 | memcpy(sig, rsig, sig_len); 47 | return sig_len; 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_i31_sign_asn1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #include "bssl_config.h" 27 | #if defined(BSSL_BUILD_INTERNAL_CORE) 28 | 29 | #include "inner.h" 30 | 31 | #define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 32 | 33 | /* see bearssl_ec.h */ 34 | size_t 35 | br_ecdsa_i31_sign_asn1(const br_ec_impl *impl, 36 | const br_hash_class *hf, const void *hash_value, 37 | const br_ec_private_key *sk, void *sig) 38 | { 39 | unsigned char rsig[(ORDER_LEN << 1) + 12]; 40 | size_t sig_len; 41 | 42 | sig_len = br_ecdsa_i31_sign_raw(impl, hf, hash_value, sk, rsig); 43 | if (sig_len == 0) { 44 | return 0; 45 | } 46 | sig_len = br_ecdsa_raw_to_asn1(rsig, sig_len); 47 | memcpy(sig, rsig, sig_len); 48 | return sig_len; 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_decode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_decode(uint16_t *x, const void *src, size_t len) 33 | { 34 | const unsigned char *buf; 35 | size_t v; 36 | uint32_t acc; 37 | int acc_len; 38 | 39 | buf = src; 40 | v = 1; 41 | acc = 0; 42 | acc_len = 0; 43 | while (len -- > 0) { 44 | uint32_t b; 45 | 46 | b = buf[len]; 47 | acc |= (b << acc_len); 48 | acc_len += 8; 49 | if (acc_len >= 15) { 50 | x[v ++] = acc & 0x7FFF; 51 | acc_len -= 15; 52 | acc >>= 15; 53 | } 54 | } 55 | if (acc_len != 0) { 56 | x[v ++] = acc; 57 | } 58 | x[0] = br_i15_bit_length(x + 1, v - 1); 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_encode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_encode(void *dst, size_t len, const uint16_t *x) 33 | { 34 | unsigned char *buf; 35 | size_t u, xlen; 36 | uint32_t acc; 37 | int acc_len; 38 | 39 | xlen = (x[0] + 15) >> 4; 40 | if (xlen == 0) { 41 | memset(dst, 0, len); 42 | return; 43 | } 44 | u = 1; 45 | acc = 0; 46 | acc_len = 0; 47 | buf = dst; 48 | while (len -- > 0) { 49 | if (acc_len < 8) { 50 | if (u <= xlen) { 51 | acc += (uint32_t)x[u ++] << acc_len; 52 | } 53 | acc_len += 15; 54 | } 55 | buf[len] = (unsigned char)acc; 56 | acc >>= 8; 57 | acc_len -= 8; 58 | } 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | #################################### 2 | # Syntax Coloring Map ESP_SSLClient 3 | #################################### 4 | 5 | #################################### 6 | # Classes (KEYWORD1) 7 | #################################### 8 | 9 | ESP_SSLClient KEYWORD1 10 | 11 | #################################### 12 | # Methods and Functions (KEYWORD2) 13 | #################################### 14 | 15 | setClient KEYWORD2 16 | connect KEYWORD2 17 | connected KEYWORD2 18 | validate KEYWORD2 19 | available KEYWORD2 20 | read KEYWORD2 21 | write KEYWORD2 22 | peek KEYWORD2 23 | setInsecure KEYWORD2 24 | enableSSL KEYWORD2 25 | connectSSL KEYWORD2 26 | flush KEYWORD2 27 | setBufferSizes KEYWORD2 28 | setPreSharedKey KEYWORD2 29 | setCACert KEYWORD2 30 | setCertificate KEYWORD2 31 | setPrivateKey KEYWORD2 32 | loadCACert KEYWORD2 33 | loadCertificate KEYWORD2 34 | loadPrivateKey KEYWORD2 35 | verify KEYWORD2 36 | setHandshakeTimeout KEYWORD2 37 | setTimeout KEYWORD2 38 | setSessionTimeout KEYWORD2 39 | stop KEYWORD2 40 | availableForWrite KEYWORD2 41 | setSession KEYWORD2 42 | setKnownKey KEYWORD2 43 | setFingerprint KEYWORD2 44 | allowSelfSignedCerts KEYWORD2 45 | setTrustAnchors KEYWORD2 46 | setX509Time KEYWORD2 47 | setClientRSACert KEYWORD2 48 | setClientECCert KEYWORD2 49 | getMFLNStatus KEYWORD2 50 | getLastSSLError KEYWORD2 51 | setCertStore KEYWORD2 52 | setCiphers KEYWORD2 53 | setCiphersLessSecure KEYWORD2 54 | setSSLVersion KEYWORD2 55 | probeMaxFragmentLength KEYWORD2 56 | hasPeekBufferAPI KEYWORD2 57 | peekAvailable KEYWORD2 58 | peekBuffer KEYWORD2 59 | peekConsume KEYWORD2 60 | setDebugLevel KEYWORD2 61 | 62 | #################################### 63 | # Struct (KEYWORD3) 64 | #################################### 65 | 66 | BearSSL_PublicKey KEYWORD3 67 | BearSSL_X509List KEYWORD3 68 | BearSSL_PrivateKey KEYWORD3 69 | BearSSL_CertStoreBase KEYWORD3 -------------------------------------------------------------------------------- /src/bssl/i31_decode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i31_decode(uint32_t *x, const void *src, size_t len) 33 | { 34 | const unsigned char *buf; 35 | size_t u, v; 36 | uint32_t acc; 37 | int acc_len; 38 | 39 | buf = src; 40 | u = len; 41 | v = 1; 42 | acc = 0; 43 | acc_len = 0; 44 | while (u -- > 0) { 45 | uint32_t b; 46 | 47 | b = buf[u]; 48 | acc |= (b << acc_len); 49 | acc_len += 8; 50 | if (acc_len >= 31) { 51 | x[v ++] = acc & (uint32_t)0x7FFFFFFF; 52 | acc_len -= 31; 53 | acc = b >> (8 - acc_len); 54 | } 55 | } 56 | if (acc_len != 0) { 57 | x[v ++] = acc; 58 | } 59 | x[0] = br_i31_bit_length(x + 1, v - 1); 60 | } 61 | 62 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_modpow.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_modpow(uint16_t *x, 33 | const unsigned char *e, size_t elen, 34 | const uint16_t *m, uint16_t m0i, uint16_t *t1, uint16_t *t2) 35 | { 36 | size_t mlen; 37 | unsigned k; 38 | 39 | mlen = ((m[0] + 31) >> 4) * sizeof m[0]; 40 | memcpy(t1, x, mlen); 41 | br_i15_to_monty(t1, m); 42 | br_i15_zero(x, m[0]); 43 | x[1] = 1; 44 | for (k = 0; k < ((unsigned)elen << 3); k ++) { 45 | uint32_t ctl; 46 | 47 | ctl = (e[elen - 1 - (k >> 3)] >> (k & 7)) & 1; 48 | br_i15_montymul(t2, x, t1, m, m0i); 49 | CCOPY(ctl, x, t2, mlen); 50 | br_i15_montymul(t2, t1, t1, m, m0i); 51 | memcpy(t1, t2, mlen); 52 | } 53 | } 54 | 55 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_mulacc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i32_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b) 33 | { 34 | size_t alen, blen, u; 35 | 36 | alen = (a[0] + 31) >> 5; 37 | blen = (b[0] + 31) >> 5; 38 | d[0] = a[0] + b[0]; 39 | for (u = 0; u < blen; u ++) { 40 | uint32_t f; 41 | size_t v; 42 | #if BR_64 43 | uint64_t cc; 44 | #else 45 | uint32_t cc; 46 | #endif 47 | 48 | f = b[1 + u]; 49 | cc = 0; 50 | for (v = 0; v < alen; v ++) { 51 | uint64_t z; 52 | 53 | z = (uint64_t)d[1 + u + v] + MUL(f, a[1 + v]) + cc; 54 | cc = z >> 32; 55 | d[1 + u + v] = (uint32_t)z; 56 | } 57 | d[1 + u + alen] = (uint32_t)cc; 58 | } 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_div32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | uint32_t 32 | br_divrem(uint32_t hi, uint32_t lo, uint32_t d, uint32_t *r) 33 | { 34 | /* TODO: optimize this */ 35 | uint32_t q; 36 | uint32_t ch, cf; 37 | int k; 38 | 39 | q = 0; 40 | ch = EQ(hi, d); 41 | hi = MUX(ch, 0, hi); 42 | for (k = 31; k > 0; k --) { 43 | int j; 44 | uint32_t w, ctl, hi2, lo2; 45 | 46 | j = 32 - k; 47 | w = (hi << j) | (lo >> k); 48 | ctl = GE(w, d) | (hi >> k); 49 | hi2 = (w - d) >> j; 50 | lo2 = lo - (d << k); 51 | hi = MUX(ctl, hi2, hi); 52 | lo = MUX(ctl, lo2, lo); 53 | q |= ctl << k; 54 | } 55 | cf = GE(lo, d) | hi; 56 | q |= cf; 57 | *r = MUX(cf, lo - d, lo); 58 | return q; 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_keygen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | uint32_t 34 | br_rsa_i62_keygen(const br_prng_class **rng, 35 | br_rsa_private_key *sk, void *kbuf_priv, 36 | br_rsa_public_key *pk, void *kbuf_pub, 37 | unsigned size, uint32_t pubexp) 38 | { 39 | return br_rsa_i31_keygen_inner(rng, 40 | sk, kbuf_priv, pk, kbuf_pub, size, pubexp, 41 | &br_i62_modpow_opt_as_i31); 42 | } 43 | 44 | /* see bearssl_rsa.h */ 45 | br_rsa_keygen 46 | br_rsa_i62_keygen_get() 47 | { 48 | return &br_rsa_i62_keygen; 49 | } 50 | 51 | #else 52 | 53 | /* see bearssl_rsa.h */ 54 | br_rsa_keygen 55 | br_rsa_i62_keygen_get() 56 | { 57 | return 0; 58 | } 59 | 60 | #endif 61 | 62 | #endif -------------------------------------------------------------------------------- /src/bssl/ec_curve25519.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | static const unsigned char GEN[] = { 31 | 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 35 | }; 36 | 37 | static const unsigned char ORDER[] = { 38 | 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 39 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 40 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 41 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF 42 | }; 43 | 44 | /* see inner.h */ 45 | const br_ec_curve_def br_curve25519 = { 46 | BR_EC_curve25519, 47 | ORDER, sizeof ORDER, 48 | GEN, sizeof GEN 49 | }; 50 | 51 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_pkcs1_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | uint32_t 34 | br_rsa_i62_pkcs1_sign(const unsigned char *hash_oid, 35 | const unsigned char *hash, size_t hash_len, 36 | const br_rsa_private_key *sk, unsigned char *x) 37 | { 38 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 39 | return 0; 40 | } 41 | return br_rsa_i62_private(x, sk); 42 | } 43 | 44 | /* see bearssl_rsa.h */ 45 | br_rsa_pkcs1_sign 46 | br_rsa_i62_pkcs1_sign_get(void) 47 | { 48 | return &br_rsa_i62_pkcs1_sign; 49 | } 50 | 51 | #else 52 | 53 | /* see bearssl_rsa.h */ 54 | br_rsa_pkcs1_sign 55 | br_rsa_i62_pkcs1_sign_get(void) 56 | { 57 | return 0; 58 | } 59 | 60 | #endif 61 | 62 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_ssl_decrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_rsa.h */ 31 | uint32_t 32 | br_rsa_ssl_decrypt(br_rsa_private core, const br_rsa_private_key *sk, 33 | unsigned char *data, size_t len) 34 | { 35 | uint32_t x; 36 | size_t u; 37 | 38 | /* 39 | * A first check on length. Since this test works only on the 40 | * buffer length, it needs not (and cannot) be constant-time. 41 | */ 42 | if (len < 59 || len != (sk->n_bitlen + 7) >> 3) { 43 | return 0; 44 | } 45 | x = core(data, sk); 46 | 47 | x &= EQ(data[0], 0x00); 48 | x &= EQ(data[1], 0x02); 49 | for (u = 2; u < (len - 49); u ++) { 50 | x &= NEQ(data[u], 0); 51 | } 52 | x &= EQ(data[len - 49], 0x00); 53 | memmove(data, data + len - 48, 48); 54 | return x; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_decode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i32_decode(uint32_t *x, const void *src, size_t len) 33 | { 34 | const unsigned char *buf; 35 | size_t u, v; 36 | 37 | buf = src; 38 | u = len; 39 | v = 1; 40 | for (;;) { 41 | if (u < 4) { 42 | uint32_t w; 43 | 44 | if (u < 2) { 45 | if (u == 0) { 46 | break; 47 | } else { 48 | w = buf[0]; 49 | } 50 | } else { 51 | if (u == 2) { 52 | w = br_dec16be(buf); 53 | } else { 54 | w = ((uint32_t)buf[0] << 16) 55 | | br_dec16be(buf + 1); 56 | } 57 | } 58 | x[v ++] = w; 59 | break; 60 | } else { 61 | u -= 4; 62 | x[v ++] = br_dec32be(buf + u); 63 | } 64 | } 65 | x[0] = br_i32_bit_length(x + 1, v - 1); 66 | } 67 | 68 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_i15_vrfy_asn1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #include "bssl_config.h" 27 | #if defined(BSSL_BUILD_INTERNAL_CORE) 28 | 29 | #include "inner.h" 30 | 31 | #define FIELD_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 32 | 33 | /* see bearssl_ec.h */ 34 | uint32_t 35 | br_ecdsa_i15_vrfy_asn1(const br_ec_impl *impl, 36 | const void *hash, size_t hash_len, 37 | const br_ec_public_key *pk, 38 | const void *sig, size_t sig_len) 39 | { 40 | /* 41 | * We use a double-sized buffer because a malformed ASN.1 signature 42 | * may trigger a size expansion when converting to "raw" format. 43 | */ 44 | unsigned char rsig[(FIELD_LEN << 2) + 24]; 45 | 46 | if (sig_len > ((sizeof rsig) >> 1)) { 47 | return 0; 48 | } 49 | memcpy(rsig, sig, sig_len); 50 | sig_len = br_ecdsa_asn1_to_raw(rsig, sig_len); 51 | return br_ecdsa_i15_vrfy_raw(impl, hash, hash_len, pk, rsig, sig_len); 52 | } 53 | 54 | #endif -------------------------------------------------------------------------------- /src/bssl/ecdsa_i31_vrfy_asn1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #include "bssl_config.h" 27 | #if defined(BSSL_BUILD_INTERNAL_CORE) 28 | 29 | #include "inner.h" 30 | 31 | #define FIELD_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 32 | 33 | /* see bearssl_ec.h */ 34 | uint32_t 35 | br_ecdsa_i31_vrfy_asn1(const br_ec_impl *impl, 36 | const void *hash, size_t hash_len, 37 | const br_ec_public_key *pk, 38 | const void *sig, size_t sig_len) 39 | { 40 | /* 41 | * We use a double-sized buffer because a malformed ASN.1 signature 42 | * may trigger a size expansion when converting to "raw" format. 43 | */ 44 | unsigned char rsig[(FIELD_LEN << 2) + 24]; 45 | 46 | if (sig_len > ((sizeof rsig) >> 1)) { 47 | return 0; 48 | } 49 | memcpy(rsig, sig, sig_len); 50 | sig_len = br_ecdsa_asn1_to_raw(rsig, sig_len); 51 | return br_ecdsa_i31_vrfy_raw(impl, hash, hash_len, pk, rsig, sig_len); 52 | } 53 | 54 | #endif -------------------------------------------------------------------------------- /src/bssl/mgf1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_mgf1_xor(void *data, size_t len, 33 | const br_hash_class *dig, const void *seed, size_t seed_len) 34 | { 35 | unsigned char *buf; 36 | size_t u, hlen; 37 | uint32_t c; 38 | 39 | buf = data; 40 | hlen = br_digest_size(dig); 41 | for (u = 0, c = 0; u < len; u += hlen, c ++) { 42 | br_hash_compat_context hc; 43 | unsigned char tmp[64]; 44 | size_t v; 45 | 46 | hc.vtable = dig; 47 | dig->init(&hc.vtable); 48 | dig->update(&hc.vtable, seed, seed_len); 49 | br_enc32be(tmp, c); 50 | dig->update(&hc.vtable, tmp, 4); 51 | dig->out(&hc.vtable, tmp); 52 | for (v = 0; v < hlen; v ++) { 53 | if ((u + v) >= len) { 54 | break; 55 | } 56 | buf[u + v] ^= tmp[v]; 57 | } 58 | } 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_pss_sign.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | uint32_t 34 | br_rsa_i62_pss_sign(const br_prng_class **rng, 35 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 36 | const unsigned char *hash, size_t salt_len, 37 | const br_rsa_private_key *sk, unsigned char *x) 38 | { 39 | if (!br_rsa_pss_sig_pad(rng, hf_data, hf_mgf1, hash, 40 | salt_len, sk->n_bitlen, x)) 41 | { 42 | return 0; 43 | } 44 | return br_rsa_i62_private(x, sk); 45 | } 46 | 47 | /* see bearssl_rsa.h */ 48 | br_rsa_pss_sign 49 | br_rsa_i62_pss_sign_get(void) 50 | { 51 | return &br_rsa_i62_pss_sign; 52 | } 53 | 54 | #else 55 | 56 | /* see bearssl_rsa.h */ 57 | br_rsa_pss_sign 58 | br_rsa_i62_pss_sign_get(void) 59 | { 60 | return 0; 61 | } 62 | 63 | #endif 64 | 65 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_oaep_decrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | uint32_t 34 | br_rsa_i62_oaep_decrypt(const br_hash_class *dig, 35 | const void *label, size_t label_len, 36 | const br_rsa_private_key *sk, void *data, size_t *len) 37 | { 38 | uint32_t r; 39 | 40 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 41 | return 0; 42 | } 43 | r = br_rsa_i62_private(data, sk); 44 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 45 | return r; 46 | } 47 | 48 | /* see bearssl_rsa.h */ 49 | br_rsa_oaep_decrypt 50 | br_rsa_i62_oaep_decrypt_get(void) 51 | { 52 | return &br_rsa_i62_oaep_decrypt; 53 | } 54 | 55 | #else 56 | 57 | /* see bearssl_rsa.h */ 58 | br_rsa_oaep_decrypt 59 | br_rsa_i62_oaep_decrypt_get(void) 60 | { 61 | return 0; 62 | } 63 | 64 | #endif 65 | 66 | #endif -------------------------------------------------------------------------------- /src/bssl/ssl_server.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see bearssl_ssl.h */ 31 | void 32 | br_ssl_server_zero(br_ssl_server_context *cc) 33 | { 34 | /* 35 | * For really standard C, we should explicitly set to NULL all 36 | * pointers, and 0 all other fields. However, on all our target 37 | * architectures, a direct memset() will work, be faster, and 38 | * use a lot less code. 39 | */ 40 | memset(cc, 0, sizeof *cc); 41 | } 42 | 43 | /* see bearssl_ssl.h */ 44 | int 45 | br_ssl_server_reset(br_ssl_server_context *cc) 46 | { 47 | br_ssl_engine_set_buffer(&cc->eng, NULL, 0, 0); 48 | if (!br_ssl_engine_init_rand(&cc->eng)) { 49 | return 0; 50 | } 51 | cc->eng.reneg = 0; 52 | br_ssl_engine_hs_reset(&cc->eng, 53 | br_ssl_hs_server_init_main, br_ssl_hs_server_run); 54 | return br_ssl_engine_last_error(&cc->eng) == BR_ERR_OK; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /src/vector/dynamic/DynamicVector.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-FileCopyrightText: 2025 Suwatchai K. 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #ifndef DYNAMIC_VECTOR_H 8 | #define DYNAMIC_VECTOR_H 9 | 10 | #include 11 | #include 12 | #include 13 | #if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(__AVR_ATmega4809__) 14 | 15 | #include // Required for size_t 16 | inline void *operator new(size_t size, void *ptr) noexcept 17 | { 18 | return ptr; 19 | } 20 | 21 | #else 22 | #include // fix for new/delete operators 23 | #endif 24 | #include "../Abort.h" 25 | 26 | namespace ReadyUtils 27 | { 28 | 29 | #define DYNAMIC_VECTOR_HEAP_ENABLED 30 | #define DYNAMIC_VECTOR_DIAGNOSTICS_ENABLED 31 | 32 | template 33 | class DynamicVector; 34 | 35 | template 36 | void swap(DynamicVector &a, DynamicVector &b) noexcept; 37 | 38 | template 39 | class DynamicVector 40 | { 41 | private: 42 | T *data = nullptr; 43 | size_t count = 0; 44 | size_t capacity = 0; 45 | 46 | public: 47 | explicit inline DynamicVector(size_t initial_capacity = 4); 48 | 49 | inline DynamicVector(const DynamicVector &other); 50 | inline DynamicVector &operator=(const DynamicVector &other); 51 | 52 | inline ~DynamicVector(); 53 | 54 | inline size_t size() const; 55 | inline size_t get_capacity() const; 56 | inline bool check_and_reserve(); 57 | inline bool push_back(const T &value); 58 | inline bool push_back(T &&value); 59 | inline bool emplace_back(T &&value); 60 | 61 | inline bool erase(size_t index); 62 | inline void clear(); 63 | inline bool reserve(size_t new_capacity); 64 | 65 | inline T &operator[](size_t index); 66 | inline const T &operator[](size_t index) const; 67 | 68 | friend void swap<>(DynamicVector &a, DynamicVector &b) noexcept; 69 | }; 70 | } 71 | 72 | #include "DynamicVector.hpp" 73 | 74 | #endif // DYNAMIC_VECTOR_H 75 | -------------------------------------------------------------------------------- /src/client/Memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 Suwatchai K. 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #ifndef ESP_SSL_CLIENT_MEMORY_H 8 | #define ESP_SSL_CLIENT_MEMORY_H 9 | #include 10 | 11 | static size_t esp_sslclient_get_reserve_len(size_t len) 12 | { 13 | int blen = len + 1; 14 | int newlen = (blen / 4) * 4; 15 | if (newlen < blen) 16 | newlen += 4; 17 | return (size_t)newlen; 18 | } 19 | 20 | static void *esp_sslclient_malloc(size_t len) 21 | { 22 | void *p = NULL; 23 | size_t newLen = esp_sslclient_get_reserve_len(len); 24 | 25 | #if defined(BOARD_HAS_PSRAM) && defined(ENABLE_PSRAM) 26 | if (ESP.getPsramSize() > 0) 27 | p = reinterpret_cast(ps_malloc(newLen)); 28 | else 29 | p = reinterpret_cast(malloc(newLen)); 30 | #else 31 | 32 | #if defined(ESP8266_USE_EXTERNAL_HEAP) && defined(ENABLE_PSRAM) 33 | ESP.setExternalHeap(); 34 | #endif 35 | 36 | p = reinterpret_cast(malloc(newLen)); 37 | #if defined(ESP8266_USE_EXTERNAL_HEAP) && defined(ENABLE_PSRAM) 38 | ESP.resetHeap(); 39 | #endif 40 | 41 | #endif 42 | return p; 43 | } 44 | 45 | static void esp_sslclient_free(void *ptr) 46 | { 47 | void **p = reinterpret_cast(ptr); 48 | if (*p) 49 | { 50 | free(*p); 51 | *p = 0; 52 | } 53 | } 54 | 55 | static void *esp_sslclient_realloc(void *ptr, size_t sz) 56 | { 57 | size_t newLen = esp_sslclient_get_reserve_len(sz); 58 | #if defined(BOARD_HAS_PSRAM) && defined(ENABLE_PSRAM) 59 | if (ESP.getPsramSize() > 0) 60 | ptr = reinterpret_cast(ps_realloc(ptr, newLen)); 61 | else 62 | ptr = reinterpret_cast(realloc(ptr, newLen)); 63 | #else 64 | 65 | #if defined(ESP8266_USE_EXTERNAL_HEAP) && defined(ENABLE_PSRAM) 66 | ESP.setExternalHeap(); 67 | #endif 68 | 69 | ptr = reinterpret_cast(realloc(ptr, newLen)); 70 | 71 | #if defined(ESP8266_USE_EXTERNAL_HEAP) && defined(ENABLE_PSRAM) 72 | ESP.resetHeap(); 73 | #endif 74 | 75 | #endif 76 | return ptr; 77 | } 78 | 79 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_pkcs1_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | uint32_t 34 | br_rsa_i62_pkcs1_vrfy(const unsigned char *x, size_t xlen, 35 | const unsigned char *hash_oid, size_t hash_len, 36 | const br_rsa_public_key *pk, unsigned char *hash_out) 37 | { 38 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 39 | 40 | if (xlen > (sizeof sig)) { 41 | return 0; 42 | } 43 | memcpy(sig, x, xlen); 44 | if (!br_rsa_i62_public(sig, xlen, pk)) { 45 | return 0; 46 | } 47 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 48 | } 49 | 50 | /* see bearssl_rsa.h */ 51 | br_rsa_pkcs1_vrfy 52 | br_rsa_i62_pkcs1_vrfy_get(void) 53 | { 54 | return &br_rsa_i62_pkcs1_vrfy; 55 | } 56 | 57 | #else 58 | 59 | /* see bearssl_rsa.h */ 60 | br_rsa_pkcs1_vrfy 61 | br_rsa_i62_pkcs1_vrfy_get(void) 62 | { 63 | return 0; 64 | } 65 | 66 | #endif 67 | 68 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_pss_vrfy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | uint32_t 34 | br_rsa_i62_pss_vrfy(const unsigned char *x, size_t xlen, 35 | const br_hash_class *hf_data, const br_hash_class *hf_mgf1, 36 | const void *hash, size_t salt_len, const br_rsa_public_key *pk) 37 | { 38 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 39 | 40 | if (xlen > (sizeof sig)) { 41 | return 0; 42 | } 43 | memcpy(sig, x, xlen); 44 | if (!br_rsa_i62_public(sig, xlen, pk)) { 45 | return 0; 46 | } 47 | return br_rsa_pss_sig_unpad(hf_data, hf_mgf1, 48 | hash, salt_len, pk, sig); 49 | } 50 | 51 | /* see bearssl_rsa.h */ 52 | br_rsa_pss_vrfy 53 | br_rsa_i62_pss_vrfy_get(void) 54 | { 55 | return &br_rsa_i62_pss_vrfy; 56 | } 57 | 58 | #else 59 | 60 | /* see bearssl_rsa.h */ 61 | br_rsa_pss_vrfy 62 | br_rsa_i62_pss_vrfy_get(void) 63 | { 64 | return 0; 65 | } 66 | 67 | #endif 68 | 69 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_fmont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_from_monty(uint16_t *x, const uint16_t *m, uint16_t m0i) 33 | { 34 | size_t len, u, v; 35 | 36 | len = (m[0] + 15) >> 4; 37 | for (u = 0; u < len; u ++) { 38 | uint32_t f, cc; 39 | 40 | f = MUL15(x[1], m0i) & 0x7FFF; 41 | cc = 0; 42 | for (v = 0; v < len; v ++) { 43 | uint32_t z; 44 | 45 | z = (uint32_t)x[v + 1] + MUL15(f, m[v + 1]) + cc; 46 | cc = z >> 15; 47 | if (v != 0) { 48 | x[v] = z & 0x7FFF; 49 | } 50 | } 51 | x[len] = cc; 52 | } 53 | 54 | /* 55 | * We may have to do an extra subtraction, but only if the 56 | * value in x[] is indeed greater than or equal to that of m[], 57 | * which is why we must do two calls (first call computes the 58 | * carry, second call performs the subtraction only if the carry 59 | * is 0). 60 | */ 61 | br_i15_sub(x, m, NOT(br_i15_sub(x, m, 0))); 62 | } 63 | 64 | #endif -------------------------------------------------------------------------------- /src/bssl/i15_mulacc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i15_mulacc(uint16_t *d, const uint16_t *a, const uint16_t *b) 33 | { 34 | size_t alen, blen, u; 35 | unsigned dl, dh; 36 | 37 | alen = (a[0] + 15) >> 4; 38 | blen = (b[0] + 15) >> 4; 39 | 40 | /* 41 | * Announced bit length of d[] will be the sum of the announced 42 | * bit lengths of a[] and b[]; but the lengths are encoded. 43 | */ 44 | dl = (a[0] & 15) + (b[0] & 15); 45 | dh = (a[0] >> 4) + (b[0] >> 4); 46 | d[0] = (dh << 4) + dl + (~(uint32_t)(dl - 15) >> 31); 47 | 48 | for (u = 0; u < blen; u ++) { 49 | uint32_t f; 50 | size_t v; 51 | uint32_t cc; 52 | 53 | f = b[1 + u]; 54 | cc = 0; 55 | for (v = 0; v < alen; v ++) { 56 | uint32_t z; 57 | 58 | z = (uint32_t)d[1 + u + v] + MUL15(f, a[1 + v]) + cc; 59 | cc = z >> 15; 60 | d[1 + u + v] = z & 0x7FFF; 61 | } 62 | d[1 + u + alen] = cc; 63 | } 64 | } 65 | 66 | #endif -------------------------------------------------------------------------------- /src/bssl/rsa_i62_oaep_encrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | #if BR_INT128 || BR_UMUL128 31 | 32 | /* see bearssl_rsa.h */ 33 | size_t 34 | br_rsa_i62_oaep_encrypt( 35 | const br_prng_class **rnd, const br_hash_class *dig, 36 | const void *label, size_t label_len, 37 | const br_rsa_public_key *pk, 38 | void *dst, size_t dst_max_len, 39 | const void *src, size_t src_len) 40 | { 41 | size_t dlen; 42 | 43 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 44 | pk, dst, dst_max_len, src, src_len); 45 | if (dlen == 0) { 46 | return 0; 47 | } 48 | return dlen & -(size_t)br_rsa_i62_public(dst, dlen, pk); 49 | } 50 | 51 | /* see bearssl_rsa.h */ 52 | br_rsa_oaep_encrypt 53 | br_rsa_i62_oaep_encrypt_get(void) 54 | { 55 | return &br_rsa_i62_oaep_encrypt; 56 | } 57 | 58 | #else 59 | 60 | /* see bearssl_rsa.h */ 61 | br_rsa_oaep_encrypt 62 | br_rsa_i62_oaep_encrypt_get(void) 63 | { 64 | return 0; 65 | } 66 | 67 | #endif 68 | 69 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_fmont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i32_from_monty(uint32_t *x, const uint32_t *m, uint32_t m0i) 33 | { 34 | size_t len, u, v; 35 | 36 | len = (m[0] + 31) >> 5; 37 | for (u = 0; u < len; u ++) { 38 | uint32_t f; 39 | uint64_t cc; 40 | 41 | f = x[1] * m0i; 42 | cc = 0; 43 | for (v = 0; v < len; v ++) { 44 | uint64_t z; 45 | 46 | z = (uint64_t)x[v + 1] + MUL(f, m[v + 1]) + cc; 47 | cc = z >> 32; 48 | if (v != 0) { 49 | x[v] = (uint32_t)z; 50 | } 51 | } 52 | x[len] = (uint32_t)cc; 53 | } 54 | 55 | /* 56 | * We may have to do an extra subtraction, but only if the 57 | * value in x[] is indeed greater than or equal to that of m[], 58 | * which is why we must do two calls (first call computes the 59 | * carry, second call performs the subtraction only if the carry 60 | * is 0). 61 | */ 62 | br_i32_sub(x, m, NOT(br_i32_sub(x, m, 0))); 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /src/bssl/i31_fmont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i31_from_monty(uint32_t *x, const uint32_t *m, uint32_t m0i) 33 | { 34 | size_t len, u, v; 35 | 36 | len = (m[0] + 31) >> 5; 37 | for (u = 0; u < len; u ++) { 38 | uint32_t f; 39 | uint64_t cc; 40 | 41 | f = MUL31_lo(x[1], m0i); 42 | cc = 0; 43 | for (v = 0; v < len; v ++) { 44 | uint64_t z; 45 | 46 | z = (uint64_t)x[v + 1] + MUL31(f, m[v + 1]) + cc; 47 | cc = z >> 31; 48 | if (v != 0) { 49 | x[v] = (uint32_t)z & 0x7FFFFFFF; 50 | } 51 | } 52 | x[len] = (uint32_t)cc; 53 | } 54 | 55 | /* 56 | * We may have to do an extra subtraction, but only if the 57 | * value in x[] is indeed greater than or equal to that of m[], 58 | * which is why we must do two calls (first call computes the 59 | * carry, second call performs the subtraction only if the carry 60 | * is 0). 61 | */ 62 | br_i31_sub(x, m, NOT(br_i31_sub(x, m, 0))); 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /src/bssl/ec_secp256r1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | static const unsigned char P256_N[] = { 31 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 32 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 33 | 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 34 | 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51 35 | }; 36 | 37 | static const unsigned char P256_G[] = { 38 | 0x04, 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 39 | 0x47, 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 40 | 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 41 | 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 42 | 0x96, 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 43 | 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 44 | 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 45 | 0xCE, 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 46 | 0xF5 47 | }; 48 | 49 | /* see inner.h */ 50 | const br_ec_curve_def br_secp256r1 = { 51 | BR_EC_secp256r1, 52 | P256_N, sizeof P256_N, 53 | P256_G, sizeof P256_G 54 | }; 55 | 56 | #endif -------------------------------------------------------------------------------- /src/bssl/i32_encode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "bssl_config.h" 26 | #if defined(BSSL_BUILD_INTERNAL_CORE) 27 | 28 | #include "inner.h" 29 | 30 | /* see inner.h */ 31 | void 32 | br_i32_encode(void *dst, size_t len, const uint32_t *x) 33 | { 34 | unsigned char *buf; 35 | size_t k; 36 | 37 | buf = dst; 38 | 39 | /* 40 | * Compute the announced size of x in bytes; extra bytes are 41 | * filled with zeros. 42 | */ 43 | k = (x[0] + 7) >> 3; 44 | while (len > k) { 45 | *buf ++ = 0; 46 | len --; 47 | } 48 | 49 | /* 50 | * Now we use k as index within x[]. That index starts at 1; 51 | * we initialize it to the topmost complete word, and process 52 | * any remaining incomplete word. 53 | */ 54 | k = (len + 3) >> 2; 55 | switch (len & 3) { 56 | case 3: 57 | *buf ++ = x[k] >> 16; 58 | /* fall through */ 59 | case 2: 60 | *buf ++ = x[k] >> 8; 61 | /* fall through */ 62 | case 1: 63 | *buf ++ = x[k]; 64 | k --; 65 | } 66 | 67 | /* 68 | * Encode all complete words. 69 | */ 70 | while (k > 0) { 71 | br_enc32be(buf, x[k]); 72 | k --; 73 | buf += 4; 74 | } 75 | } 76 | 77 | #endif --------------------------------------------------------------------------------