├── .gitignore ├── CHANGELOG ├── Makefile ├── README.md ├── arduino ├── component.mk ├── cores │ └── esp32 │ │ ├── Arduino.h │ │ ├── Client.h │ │ ├── IPAddress.cpp │ │ ├── IPAddress.h │ │ ├── Print.cpp │ │ ├── Print.h │ │ ├── Printable.h │ │ ├── RingBuffer.h │ │ ├── Stream.cpp │ │ ├── Stream.h │ │ ├── WInterrupts.c │ │ ├── WInterrupts.h │ │ ├── WMath.cpp │ │ ├── WMath.h │ │ ├── WString.cpp │ │ ├── WString.h │ │ ├── delay.c │ │ ├── delay.h │ │ ├── itoa.c │ │ ├── itoa.h │ │ ├── main.cpp │ │ ├── wiring.c │ │ ├── wiring_analog.c │ │ ├── wiring_analog.h │ │ ├── wiring_digital.c │ │ └── wiring_digital.h └── libraries │ ├── ArduinoBearSSL │ └── src │ │ ├── ArduinoBearSSL.cpp │ │ ├── ArduinoBearSSL.h │ │ ├── BearSSLClient.cpp │ │ ├── BearSSLClient.h │ │ ├── BearSSLTrustAnchors.h │ │ ├── SHA.cpp │ │ ├── SHA.h │ │ ├── SHA1.cpp │ │ ├── SHA1.h │ │ ├── SHA256.cpp │ │ ├── SHA256.h │ │ ├── aiotc_profile.c │ │ ├── bearssl │ │ ├── LICENSE.txt │ │ ├── aes_big_cbcdec.c │ │ ├── aes_big_cbcenc.c │ │ ├── aes_big_ctr.c │ │ ├── aes_big_ctrcbc.c │ │ ├── aes_big_dec.c │ │ ├── aes_big_enc.c │ │ ├── aes_common.c │ │ ├── aes_ct.c │ │ ├── aes_ct64.c │ │ ├── aes_ct64_cbcdec.c │ │ ├── aes_ct64_cbcenc.c │ │ ├── aes_ct64_ctr.c │ │ ├── aes_ct64_ctrcbc.c │ │ ├── aes_ct64_dec.c │ │ ├── aes_ct64_enc.c │ │ ├── aes_ct_cbcdec.c │ │ ├── aes_ct_cbcenc.c │ │ ├── aes_ct_ctr.c │ │ ├── aes_ct_ctrcbc.c │ │ ├── aes_ct_dec.c │ │ ├── aes_ct_enc.c │ │ ├── aes_pwr8.c │ │ ├── aes_pwr8_cbcdec.c │ │ ├── aes_pwr8_cbcenc.c │ │ ├── aes_pwr8_ctr.c │ │ ├── aes_pwr8_ctrcbc.c │ │ ├── aes_small_cbcdec.c │ │ ├── aes_small_cbcenc.c │ │ ├── aes_small_ctr.c │ │ ├── aes_small_ctrcbc.c │ │ ├── aes_small_dec.c │ │ ├── aes_small_enc.c │ │ ├── aes_x86ni.c │ │ ├── aes_x86ni_cbcdec.c │ │ ├── aes_x86ni_cbcenc.c │ │ ├── aes_x86ni_ctr.c │ │ ├── aesctr_drbg.c │ │ ├── asn1enc.c │ │ ├── bearssl.h │ │ ├── bearssl_aead.h │ │ ├── bearssl_block.h │ │ ├── bearssl_ec.h │ │ ├── bearssl_hash.h │ │ ├── bearssl_hmac.h │ │ ├── bearssl_kdf.h │ │ ├── bearssl_pem.h │ │ ├── bearssl_prf.h │ │ ├── bearssl_rand.h │ │ ├── bearssl_rsa.h │ │ ├── bearssl_ssl.h │ │ ├── bearssl_x509.h │ │ ├── ccm.c │ │ ├── ccopy.c │ │ ├── chacha20_ct.c │ │ ├── chacha20_sse2.c │ │ ├── config.h │ │ ├── dec16be.c │ │ ├── dec16le.c │ │ ├── dec32be.c │ │ ├── dec32le.c │ │ ├── dec64be.c │ │ ├── dec64le.c │ │ ├── des_ct.c │ │ ├── des_ct_cbcdec.c │ │ ├── des_ct_cbcenc.c │ │ ├── des_support.c │ │ ├── des_tab.c │ │ ├── des_tab_cbcdec.c │ │ ├── des_tab_cbcenc.c │ │ ├── dig_oid.c │ │ ├── dig_size.c │ │ ├── eax.c │ │ ├── ec_all_m15.c │ │ ├── ec_all_m31.c │ │ ├── ec_c25519_i15.c │ │ ├── ec_c25519_i31.c │ │ ├── ec_c25519_m15.c │ │ ├── ec_c25519_m31.c │ │ ├── ec_curve25519.c │ │ ├── ec_default.c │ │ ├── ec_keygen.c │ │ ├── ec_p256_m15.c │ │ ├── ec_p256_m31.c │ │ ├── ec_prime_i15.c │ │ ├── ec_prime_i31.c │ │ ├── ec_pubkey.c │ │ ├── ec_secp256r1.c │ │ ├── ec_secp384r1.c │ │ ├── ec_secp521r1.c │ │ ├── ecdsa_atr.c │ │ ├── ecdsa_default_sign_asn1.c │ │ ├── ecdsa_default_sign_raw.c │ │ ├── ecdsa_default_vrfy_asn1.c │ │ ├── ecdsa_default_vrfy_raw.c │ │ ├── ecdsa_i15_bits.c │ │ ├── ecdsa_i15_sign_asn1.c │ │ ├── ecdsa_i15_sign_raw.c │ │ ├── ecdsa_i15_vrfy_asn1.c │ │ ├── ecdsa_i15_vrfy_raw.c │ │ ├── ecdsa_i31_bits.c │ │ ├── ecdsa_i31_sign_asn1.c │ │ ├── ecdsa_i31_sign_raw.c │ │ ├── ecdsa_i31_vrfy_asn1.c │ │ ├── ecdsa_i31_vrfy_raw.c │ │ ├── ecdsa_rta.c │ │ ├── enc16be.c │ │ ├── enc16le.c │ │ ├── enc32be.c │ │ ├── enc32le.c │ │ ├── enc64be.c │ │ ├── enc64le.c │ │ ├── encode_ec_pk8der.c │ │ ├── encode_ec_rawder.c │ │ ├── encode_rsa_pk8der.c │ │ ├── encode_rsa_rawder.c │ │ ├── gcm.c │ │ ├── ghash_ctmul.c │ │ ├── ghash_ctmul32.c │ │ ├── ghash_ctmul64.c │ │ ├── ghash_pclmul.c │ │ ├── ghash_pwr8.c │ │ ├── hkdf.c │ │ ├── hmac.c │ │ ├── hmac_ct.c │ │ ├── hmac_drbg.c │ │ ├── i15_add.c │ │ ├── i15_bitlen.c │ │ ├── i15_decmod.c │ │ ├── i15_decode.c │ │ ├── i15_decred.c │ │ ├── i15_encode.c │ │ ├── i15_fmont.c │ │ ├── i15_iszero.c │ │ ├── i15_moddiv.c │ │ ├── i15_modpow.c │ │ ├── i15_modpow2.c │ │ ├── i15_montmul.c │ │ ├── i15_mulacc.c │ │ ├── i15_muladd.c │ │ ├── i15_ninv15.c │ │ ├── i15_reduce.c │ │ ├── i15_rshift.c │ │ ├── i15_sub.c │ │ ├── i15_tmont.c │ │ ├── i31_add.c │ │ ├── i31_bitlen.c │ │ ├── i31_decmod.c │ │ ├── i31_decode.c │ │ ├── i31_decred.c │ │ ├── i31_encode.c │ │ ├── i31_fmont.c │ │ ├── i31_iszero.c │ │ ├── i31_moddiv.c │ │ ├── i31_modpow.c │ │ ├── i31_modpow2.c │ │ ├── i31_montmul.c │ │ ├── i31_mulacc.c │ │ ├── i31_muladd.c │ │ ├── i31_ninv31.c │ │ ├── i31_reduce.c │ │ ├── i31_rshift.c │ │ ├── i31_sub.c │ │ ├── i31_tmont.c │ │ ├── i32_add.c │ │ ├── i32_bitlen.c │ │ ├── i32_decmod.c │ │ ├── i32_decode.c │ │ ├── i32_decred.c │ │ ├── i32_div32.c │ │ ├── i32_encode.c │ │ ├── i32_fmont.c │ │ ├── i32_iszero.c │ │ ├── i32_modpow.c │ │ ├── i32_montmul.c │ │ ├── i32_mulacc.c │ │ ├── i32_muladd.c │ │ ├── i32_ninv32.c │ │ ├── i32_reduce.c │ │ ├── i32_sub.c │ │ ├── i32_tmont.c │ │ ├── i62_modpow2.c │ │ ├── inner.h │ │ ├── md5.c │ │ ├── md5sha1.c │ │ ├── mgf1.c │ │ ├── multihash.c │ │ ├── pemdec.c │ │ ├── pemenc.c │ │ ├── poly1305_ctmul.c │ │ ├── poly1305_ctmul32.c │ │ ├── poly1305_ctmulq.c │ │ ├── poly1305_i15.c │ │ ├── prf.c │ │ ├── prf_md5sha1.c │ │ ├── prf_sha256.c │ │ ├── prf_sha384.c │ │ ├── rsa_default_keygen.c │ │ ├── rsa_default_modulus.c │ │ ├── rsa_default_oaep_decrypt.c │ │ ├── rsa_default_oaep_encrypt.c │ │ ├── rsa_default_pkcs1_sign.c │ │ ├── rsa_default_pkcs1_vrfy.c │ │ ├── rsa_default_priv.c │ │ ├── rsa_default_privexp.c │ │ ├── rsa_default_pub.c │ │ ├── rsa_default_pubexp.c │ │ ├── rsa_i15_keygen.c │ │ ├── rsa_i15_modulus.c │ │ ├── rsa_i15_oaep_decrypt.c │ │ ├── rsa_i15_oaep_encrypt.c │ │ ├── rsa_i15_pkcs1_sign.c │ │ ├── rsa_i15_pkcs1_vrfy.c │ │ ├── rsa_i15_priv.c │ │ ├── rsa_i15_privexp.c │ │ ├── rsa_i15_pub.c │ │ ├── rsa_i15_pubexp.c │ │ ├── rsa_i31_keygen.c │ │ ├── rsa_i31_keygen_inner.c │ │ ├── rsa_i31_modulus.c │ │ ├── rsa_i31_oaep_decrypt.c │ │ ├── rsa_i31_oaep_encrypt.c │ │ ├── rsa_i31_pkcs1_sign.c │ │ ├── rsa_i31_pkcs1_vrfy.c │ │ ├── rsa_i31_priv.c │ │ ├── rsa_i31_privexp.c │ │ ├── rsa_i31_pub.c │ │ ├── rsa_i31_pubexp.c │ │ ├── rsa_i32_oaep_decrypt.c │ │ ├── rsa_i32_oaep_encrypt.c │ │ ├── rsa_i32_pkcs1_sign.c │ │ ├── rsa_i32_pkcs1_vrfy.c │ │ ├── rsa_i32_priv.c │ │ ├── rsa_i32_pub.c │ │ ├── rsa_i62_keygen.c │ │ ├── rsa_i62_oaep_decrypt.c │ │ ├── rsa_i62_oaep_encrypt.c │ │ ├── rsa_i62_pkcs1_sign.c │ │ ├── rsa_i62_pkcs1_vrfy.c │ │ ├── rsa_i62_priv.c │ │ ├── rsa_i62_pub.c │ │ ├── rsa_oaep_pad.c │ │ ├── rsa_oaep_unpad.c │ │ ├── rsa_pkcs1_sig_pad.c │ │ ├── rsa_pkcs1_sig_unpad.c │ │ ├── rsa_ssl_decrypt.c │ │ ├── settings.c │ │ ├── sha1.c │ │ ├── sha2big.c │ │ ├── sha2small.c │ │ ├── skey_decoder.c │ │ ├── ssl_ccert_single_ec.c │ │ ├── ssl_ccert_single_rsa.c │ │ ├── ssl_client.c │ │ ├── ssl_client_default_rsapub.c │ │ ├── ssl_client_full.c │ │ ├── ssl_engine.c │ │ ├── ssl_engine_default_aescbc.c │ │ ├── ssl_engine_default_aesccm.c │ │ ├── ssl_engine_default_aesgcm.c │ │ ├── ssl_engine_default_chapol.c │ │ ├── ssl_engine_default_descbc.c │ │ ├── ssl_engine_default_ec.c │ │ ├── ssl_engine_default_ecdsa.c │ │ ├── ssl_engine_default_rsavrfy.c │ │ ├── ssl_hashes.c │ │ ├── ssl_hs_client.c │ │ ├── ssl_hs_server.c │ │ ├── ssl_io.c │ │ ├── ssl_keyexport.c │ │ ├── ssl_lru.c │ │ ├── ssl_rec_cbc.c │ │ ├── ssl_rec_ccm.c │ │ ├── ssl_rec_chapol.c │ │ ├── ssl_rec_gcm.c │ │ ├── ssl_scert_single_ec.c │ │ ├── ssl_scert_single_rsa.c │ │ ├── ssl_server.c │ │ ├── ssl_server_full_ec.c │ │ ├── ssl_server_full_rsa.c │ │ ├── ssl_server_mine2c.c │ │ ├── ssl_server_mine2g.c │ │ ├── ssl_server_minf2c.c │ │ ├── ssl_server_minf2g.c │ │ ├── ssl_server_minr2g.c │ │ ├── ssl_server_minu2g.c │ │ ├── ssl_server_minv2g.c │ │ ├── sysrng.c │ │ ├── x509_decoder.c │ │ ├── x509_knownkey.c │ │ ├── x509_minimal.c │ │ └── x509_minimal_full.c │ │ └── utility │ │ ├── eccX08_asn1.h │ │ ├── eccX08_sign_asn1.cpp │ │ └── eccX08_vrfy_asn1.cpp │ ├── ArduinoECCX08 │ └── src │ │ ├── ArduinoECCX08.h │ │ ├── ECCX08.cpp │ │ ├── ECCX08.h │ │ └── utility │ │ ├── ASN1Utils.cpp │ │ ├── ASN1Utils.h │ │ ├── ECCX08CSR.cpp │ │ ├── ECCX08CSR.h │ │ ├── ECCX08DefaultTLSConfig.h │ │ ├── ECCX08JWS.cpp │ │ ├── ECCX08JWS.h │ │ ├── ECCX08SelfSignedCert.cpp │ │ ├── ECCX08SelfSignedCert.h │ │ ├── PEMUtils.cpp │ │ ├── PEMUtils.h │ │ ├── sha1.c │ │ └── sha1.h │ ├── SPIS │ └── src │ │ ├── SPIS.cpp │ │ └── SPIS.h │ ├── WiFi │ └── src │ │ ├── WiFi.cpp │ │ ├── WiFi.h │ │ ├── WiFiClient.cpp │ │ ├── WiFiClient.h │ │ ├── WiFiSSLClient.cpp │ │ ├── WiFiSSLClient.h │ │ ├── WiFiServer.cpp │ │ ├── WiFiServer.h │ │ ├── WiFiUdp.cpp │ │ └── WiFiUdp.h │ └── Wire │ ├── keywords.txt │ ├── library.properties │ └── src │ ├── Wire.cpp │ └── Wire.h ├── combine.py ├── data ├── phy.bin └── roots.pem ├── main ├── CommandHandler.cpp ├── CommandHandler.h ├── CryptoUtil.cpp ├── CryptoUtil.h ├── ECCX08Cert.cpp ├── ECCX08Cert.h ├── component.mk ├── http_client.c └── sketch.ino.cpp ├── partitions.csv ├── sdkconfig └── tools ├── nina-fw-create-roots.sh ├── sslcheck.sh ├── url-check.txt └── url_lists ├── url_list_gtmetrix.com.txt └── url_list_moz.com.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := nina-fw 2 | 3 | EXTRA_COMPONENT_DIRS := $(PWD)/arduino 4 | 5 | CPPFLAGS += -DARDUINO 6 | 7 | ifeq ($(RELEASE),1) 8 | CFLAGS += -DNDEBUG -DCONFIG_FREERTOS_ASSERT_DISABLE -Os -DLOG_LOCAL_LEVEL=0 9 | CPPFLAGS += -DNDEBUG -Os 10 | $(info RELEASE) 11 | endif 12 | 13 | ifeq ($(UNO_WIFI_REV2),1) 14 | CFLAGS += -DUNO_WIFI_REV2 15 | CPPFLAGS += -DUNO_WIFI_REV2 16 | $(info UNO_WIFI_REV2) 17 | endif 18 | 19 | ifeq ($(NANO_RP2040_CONNECT),1) 20 | CFLAGS += -DNANO_RP2040_CONNECT 21 | CPPFLAGS += -DNANO_RP2040_CONNECT 22 | $(info NANO_RP2040_CONNECT) 23 | endif 24 | 25 | include $(IDF_PATH)/make/project.mk 26 | 27 | firmware: all 28 | python combine.py 29 | 30 | .PHONY: firmware 31 | -------------------------------------------------------------------------------- /arduino/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := cores/esp32 libraries/SPIS/src libraries/WiFi/src libraries/Wire/src libraries/ArduinoECCX08/src libraries/ArduinoBearSSL/src 2 | 3 | COMPONENT_SRCDIRS := cores/esp32 libraries/SPIS/src libraries/WiFi/src libraries/Wire/src libraries/ArduinoECCX08/src libraries/ArduinoBearSSL/src libraries/ArduinoBearSSL/src/bearssl libraries/ArduinoBearSSL/src/utility 4 | -------------------------------------------------------------------------------- /arduino/cores/esp32/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef ARDUINO_H 21 | #define ARDUINO_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | typedef bool boolean; 30 | typedef uint8_t byte; 31 | typedef uint16_t word; 32 | 33 | #define min(a,b) ((a)<(b)?(a):(b)) 34 | #define max(a,b) ((a)>(b)?(a):(b)) 35 | #define abs(x) ((x)>0?(x):-(x)) 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C"{ 40 | #endif // __cplusplus 41 | 42 | // system functions 43 | void init(void); 44 | 45 | // sketch 46 | void setup(void); 47 | void loop(void); 48 | 49 | #ifdef __cplusplus 50 | } // extern "C" 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | #include "Stream.h" 55 | #include "WMath.h" 56 | #include "WString.h" 57 | #endif 58 | #include "delay.h" 59 | 60 | #include "wiring_digital.h" 61 | #include "wiring_analog.h" 62 | 63 | #endif // ARDUINO_H 64 | -------------------------------------------------------------------------------- /arduino/cores/esp32/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /arduino/cores/esp32/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef Printable_h 20 | #define Printable_h 21 | 22 | #include 23 | 24 | class Print; 25 | 26 | /** The Printable class provides a way for new classes to allow themselves to be printed. 27 | By deriving from Printable and implementing the printTo method, it will then be possible 28 | for users to print out instances of this class by passing them into the usual 29 | Print::print and Print::println methods. 30 | */ 31 | 32 | class Printable 33 | { 34 | public: 35 | virtual size_t printTo(Print& p) const = 0; 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /arduino/cores/esp32/WInterrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _WIRING_INTERRUPTS_ 21 | #define _WIRING_INTERRUPTS_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | // #define LOW 0 30 | // #define HIGH 1 31 | #define CHANGE 2 32 | #define FALLING 3 33 | #define RISING 4 34 | 35 | typedef void (*voidFuncPtr)(void); 36 | 37 | void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /arduino/cores/esp32/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | #include "WMath.h" 25 | 26 | extern long random(long howbig) 27 | { 28 | if(howbig == 0) { 29 | return 0; 30 | } 31 | 32 | return esp_random() % howbig; 33 | } 34 | 35 | extern long random( long howsmall, long howbig ) 36 | { 37 | if (howsmall >= howbig) 38 | { 39 | return howsmall; 40 | } 41 | 42 | long diff = howbig - howsmall; 43 | 44 | return random(diff) + howsmall; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /arduino/cores/esp32/WMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _WIRING_MATH_ 21 | #define _WIRING_MATH_ 22 | 23 | extern long random(long); 24 | extern long random(long, long); 25 | 26 | #endif /* _WIRING_MATH_ */ 27 | -------------------------------------------------------------------------------- /arduino/cores/esp32/delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "delay.h" 24 | 25 | unsigned long millis() 26 | { 27 | return xTaskGetTickCount() * portTICK_PERIOD_MS; 28 | } 29 | 30 | void delay(uint32_t ms) 31 | { 32 | vTaskDelay(ms / portTICK_PERIOD_MS); 33 | } 34 | 35 | void delayMicroseconds(uint32_t usec) 36 | { 37 | ets_delay_us(usec); 38 | } 39 | -------------------------------------------------------------------------------- /arduino/cores/esp32/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef DELAY_H 21 | #define DELAY_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include 28 | 29 | extern unsigned long millis(); 30 | 31 | extern void delay(uint32_t ms); 32 | 33 | extern void delayMicroseconds(uint32_t usec) ; 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif // DELAY_H 40 | -------------------------------------------------------------------------------- /arduino/cores/esp32/itoa.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "itoa.h" 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | extern char* utoa( unsigned long value, char *string, int radix ) 27 | { 28 | return ultoa( value, string, radix ) ; 29 | } 30 | 31 | extern char* ultoa( unsigned long value, char *string, int radix ) 32 | { 33 | char tmp[33]; 34 | char *tp = tmp; 35 | long i; 36 | unsigned long v = value; 37 | char *sp; 38 | 39 | if ( string == NULL ) 40 | { 41 | return 0; 42 | } 43 | 44 | if (radix > 36 || radix <= 1) 45 | { 46 | return 0; 47 | } 48 | 49 | while (v || tp == tmp) 50 | { 51 | i = v % radix; 52 | v = v / radix; 53 | if (i < 10) 54 | *tp++ = i+'0'; 55 | else 56 | *tp++ = i + 'a' - 10; 57 | } 58 | 59 | sp = string; 60 | 61 | 62 | while (tp > tmp) 63 | *sp++ = *--tp; 64 | *sp = 0; 65 | 66 | return string; 67 | } 68 | 69 | #ifdef __cplusplus 70 | } // extern "C" 71 | #endif 72 | -------------------------------------------------------------------------------- /arduino/cores/esp32/itoa.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #ifdef __cplusplus 22 | extern "C"{ 23 | #endif 24 | 25 | extern char* ltoa( long value, char *string, int radix ) ; 26 | extern char* ultoa( unsigned long value, char *string, int radix ) ; 27 | 28 | #ifdef __cplusplus 29 | } // extern "C" 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /arduino/cores/esp32/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define ARDUINO_MAIN 24 | #include "Arduino.h" 25 | 26 | void arduino_main(void*) { 27 | init(); 28 | 29 | setup(); 30 | 31 | while (1) { 32 | loop(); 33 | } 34 | } 35 | 36 | extern "C" { 37 | void app_main() { 38 | xTaskCreatePinnedToCore(arduino_main, "arduino", 8192, NULL, 1, NULL, 1); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /arduino/cores/esp32/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "Arduino.h" 23 | 24 | void init() { 25 | if (nvs_flash_init() != ESP_OK) { 26 | nvs_flash_erase(); 27 | 28 | nvs_flash_init(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /arduino/cores/esp32/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "wiring_analog.h" 23 | 24 | void analogWrite(uint32_t pin, uint32_t value) 25 | { 26 | periph_module_enable(PERIPH_LEDC_MODULE); 27 | 28 | ledc_timer_config_t timerConf = { 29 | .bit_num = LEDC_TIMER_10_BIT, 30 | .freq_hz = 1000, 31 | .speed_mode = LEDC_HIGH_SPEED_MODE, 32 | .timer_num = (pin / 7), 33 | }; 34 | ledc_timer_config(&timerConf); 35 | 36 | ledc_channel_config_t ledc_conf = { 37 | .channel = (pin % 7), 38 | .duty = (value << 2), 39 | .gpio_num = pin, 40 | .intr_type = LEDC_INTR_DISABLE, 41 | .speed_mode = LEDC_HIGH_SPEED_MODE, 42 | .timer_sel = (pin / 7) 43 | }; 44 | ledc_channel_config(&ledc_conf); 45 | } 46 | -------------------------------------------------------------------------------- /arduino/cores/esp32/wiring_analog.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef WIRING_ANALOG_H 21 | #define WIRING_ANALOG_H 22 | 23 | #include "Arduino.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern void analogWrite(uint32_t pin, uint32_t value); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif // WIRING_ANALOG_H 36 | -------------------------------------------------------------------------------- /arduino/cores/esp32/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "wiring_digital.h" 23 | 24 | void pinMode(uint32_t pin, uint32_t mode) 25 | { 26 | switch (mode) { 27 | case INPUT: 28 | gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT); 29 | gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING); 30 | break; 31 | 32 | case OUTPUT: 33 | gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); 34 | gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING); 35 | break; 36 | 37 | case INPUT_PULLUP: 38 | gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT); 39 | gpio_set_pull_mode((gpio_num_t)pin, GPIO_PULLUP_ONLY); 40 | break; 41 | } 42 | 43 | PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO); 44 | } 45 | 46 | void digitalWrite(uint32_t pin, uint32_t val) 47 | { 48 | gpio_set_level((gpio_num_t)pin, val); 49 | } 50 | 51 | int digitalRead(uint32_t pin) 52 | { 53 | return gpio_get_level(pin); 54 | } 55 | -------------------------------------------------------------------------------- /arduino/cores/esp32/wiring_digital.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef WIRING_DIGITAL_H 21 | #define WIRING_DIGITAL_H 22 | 23 | #include "Arduino.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define LOW 0x00 30 | #define HIGH 0x01 31 | 32 | #define INPUT 0x00 33 | #define OUTPUT 0x01 34 | #define INPUT_PULLUP 0x02 35 | 36 | extern void pinMode(uint32_t pin, uint32_t mode); 37 | 38 | extern void digitalWrite(uint32_t pin, uint32_t val); 39 | 40 | extern int digitalRead(uint32_t pin); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif // WIRING_DIGITAL_H 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/ArduinoBearSSL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Arduino SA. All rights reserved. 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 "ArduinoBearSSL.h" 26 | 27 | ArduinoBearSSLClass::ArduinoBearSSLClass() : 28 | _onGetTimeCallback(NULL) 29 | { 30 | } 31 | 32 | ArduinoBearSSLClass::~ArduinoBearSSLClass() 33 | { 34 | } 35 | 36 | unsigned long ArduinoBearSSLClass::getTime() 37 | { 38 | if (_onGetTimeCallback) { 39 | return _onGetTimeCallback(); 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | void ArduinoBearSSLClass::onGetTime(unsigned long(*callback)(void)) 46 | { 47 | _onGetTimeCallback = callback; 48 | } 49 | 50 | ArduinoBearSSLClass ArduinoBearSSL; 51 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/ArduinoBearSSL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Arduino SA. All rights reserved. 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 | #ifndef _ARDUINO_BEAR_SSL_H_ 26 | #define _ARDUINO_BEAR_SSL_H_ 27 | 28 | #include "BearSSLClient.h" 29 | #include "SHA1.h" 30 | #include "SHA256.h" 31 | 32 | class ArduinoBearSSLClass { 33 | public: 34 | ArduinoBearSSLClass(); 35 | virtual ~ArduinoBearSSLClass(); 36 | 37 | unsigned long getTime(); 38 | void onGetTime(unsigned long(*)(void)); 39 | 40 | private: 41 | unsigned long (*_onGetTimeCallback)(void); 42 | }; 43 | 44 | extern ArduinoBearSSLClass ArduinoBearSSL; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/SHA1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Arduino SA. All rights reserved. 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 "SHA1.h" 26 | 27 | SHA1Class::SHA1Class() : 28 | SHAClass(SHA1_BLOCK_SIZE, SHA1_DIGEST_SIZE) 29 | { 30 | } 31 | 32 | SHA1Class::~SHA1Class() 33 | { 34 | } 35 | 36 | int SHA1Class::begin() 37 | { 38 | br_sha1_init(&_ctx); 39 | 40 | return 1; 41 | } 42 | 43 | int SHA1Class::update(const uint8_t *buffer, size_t size) 44 | { 45 | br_sha1_update(&_ctx, buffer, size); 46 | 47 | return 1; 48 | } 49 | 50 | int SHA1Class::end(uint8_t *digest) 51 | { 52 | br_sha1_out(&_ctx, digest); 53 | 54 | return 1; 55 | } 56 | 57 | SHA1Class SHA1; 58 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/SHA1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Arduino SA. All rights reserved. 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 | #ifndef SHA1_H 26 | #define SHA1_H 27 | 28 | #include 29 | 30 | #include "SHA.h" 31 | 32 | #define SHA1_BLOCK_SIZE 64 33 | #define SHA1_DIGEST_SIZE 20 34 | 35 | class SHA1Class: public SHAClass { 36 | 37 | public: 38 | SHA1Class(); 39 | virtual ~SHA1Class(); 40 | 41 | protected: 42 | virtual int begin(); 43 | virtual int update(const uint8_t *buffer, size_t size); 44 | virtual int end(uint8_t *digest); 45 | 46 | private: 47 | br_sha1_context _ctx; 48 | }; 49 | 50 | extern SHA1Class SHA1; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/SHA256.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Arduino SA. All rights reserved. 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 "SHA256.h" 26 | 27 | SHA256Class::SHA256Class() : 28 | SHAClass(SHA256_BLOCK_SIZE, SHA256_DIGEST_SIZE) 29 | { 30 | } 31 | 32 | SHA256Class::~SHA256Class() 33 | { 34 | } 35 | 36 | int SHA256Class::begin() 37 | { 38 | br_sha256_init(&_ctx); 39 | 40 | return 1; 41 | } 42 | 43 | int SHA256Class::update(const uint8_t *buffer, size_t size) 44 | { 45 | br_sha256_update(&_ctx, buffer, size); 46 | 47 | return 1; 48 | } 49 | 50 | int SHA256Class::end(uint8_t *digest) 51 | { 52 | br_sha256_out(&_ctx, digest); 53 | 54 | return 1; 55 | } 56 | 57 | SHA256Class SHA256; 58 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/SHA256.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Arduino SA. All rights reserved. 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 | #ifndef SHA256_H 26 | #define SHA256_H 27 | 28 | #include 29 | 30 | #include "SHA.h" 31 | 32 | #define SHA256_BLOCK_SIZE 64 33 | #define SHA256_DIGEST_SIZE 32 34 | 35 | class SHA256Class: public SHAClass { 36 | 37 | public: 38 | SHA256Class(); 39 | virtual ~SHA256Class(); 40 | 41 | protected: 42 | virtual int begin(); 43 | virtual int update(const uint8_t *buffer, size_t size); 44 | virtual int end(uint8_t *digest); 45 | 46 | private: 47 | br_sha256_context _ctx; 48 | }; 49 | 50 | extern SHA256Class SHA256; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Thomas Pornin 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_ccopy(uint32_t ctl, void *dst, const void *src, size_t len) 30 | { 31 | unsigned char *d; 32 | const unsigned char *s; 33 | 34 | d = dst; 35 | s = src; 36 | while (len -- > 0) { 37 | uint32_t x, y; 38 | 39 | x = *s ++; 40 | y = *d; 41 | *d = MUX(ctl, x, y); 42 | d ++; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec16be(uint16_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec16be(buf); 36 | buf += 2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec16le(uint16_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec16le(buf); 36 | buf += 2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec32be(uint32_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec32be(buf); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec32le(uint32_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec32le(buf); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec64be(uint64_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec64be(buf); 36 | buf += 8; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec64le(uint64_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec64le(buf); 36 | buf += 8; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | size_t 29 | br_digest_size_by_ID(int digest_id) 30 | { 31 | switch (digest_id) { 32 | case br_md5sha1_ID: 33 | return br_md5_SIZE + br_sha1_SIZE; 34 | case br_md5_ID: 35 | return br_md5_SIZE; 36 | case br_sha1_ID: 37 | return br_sha1_SIZE; 38 | case br_sha224_ID: 39 | return br_sha224_SIZE; 40 | case br_sha256_ID: 41 | return br_sha256_SIZE; 42 | case br_sha384_ID: 43 | return br_sha384_SIZE; 44 | case br_sha512_ID: 45 | return br_sha512_SIZE; 46 | default: 47 | /* abort(); */ 48 | return 0; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | static const unsigned char GEN[] = { 28 | 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 32 | }; 33 | 34 | static const unsigned char ORDER[] = { 35 | 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 36 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 37 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 38 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF 39 | }; 40 | 41 | /* see inner.h */ 42 | const br_ec_curve_def br_curve25519 = { 43 | BR_EC_curve25519, 44 | ORDER, sizeof ORDER, 45 | GEN, sizeof GEN 46 | }; 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ec.h */ 28 | const br_ec_impl * 29 | br_ec_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_ec_all_m15; 33 | #else 34 | return &br_ec_all_m31; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ec.h */ 28 | br_ecdsa_sign 29 | br_ecdsa_sign_asn1_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_ecdsa_i15_sign_asn1; 33 | #else 34 | return &br_ecdsa_i31_sign_asn1; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ec.h */ 28 | br_ecdsa_sign 29 | br_ecdsa_sign_raw_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_ecdsa_i15_sign_raw; 33 | #else 34 | return &br_ecdsa_i31_sign_raw; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ec.h */ 28 | br_ecdsa_vrfy 29 | br_ecdsa_vrfy_asn1_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_ecdsa_i15_vrfy_asn1; 33 | #else 34 | return &br_ecdsa_i31_vrfy_asn1; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ec.h */ 28 | br_ecdsa_vrfy 29 | br_ecdsa_vrfy_raw_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_ecdsa_i15_vrfy_raw; 33 | #else 34 | return &br_ecdsa_i31_vrfy_raw; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_ecdsa_i15_bits2int(uint16_t *x, 30 | const void *src, size_t len, uint32_t ebitlen) 31 | { 32 | uint32_t bitlen, hbitlen; 33 | int sc; 34 | 35 | bitlen = ebitlen - (ebitlen >> 4); 36 | hbitlen = (uint32_t)len << 3; 37 | if (hbitlen > bitlen) { 38 | len = (bitlen + 7) >> 3; 39 | sc = (int)((hbitlen - bitlen) & 7); 40 | } else { 41 | sc = 0; 42 | } 43 | br_i15_zero(x, ebitlen); 44 | br_i15_decode(x, src, len); 45 | br_i15_rshift(x, sc); 46 | x[0] = ebitlen; 47 | } 48 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | #define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 28 | 29 | /* see bearssl_ec.h */ 30 | size_t 31 | br_ecdsa_i15_sign_asn1(const br_ec_impl *impl, 32 | const br_hash_class *hf, const void *hash_value, 33 | const br_ec_private_key *sk, void *sig) 34 | { 35 | unsigned char rsig[(ORDER_LEN << 1) + 12]; 36 | size_t sig_len; 37 | 38 | sig_len = br_ecdsa_i15_sign_raw(impl, hf, hash_value, sk, rsig); 39 | if (sig_len == 0) { 40 | return 0; 41 | } 42 | sig_len = br_ecdsa_raw_to_asn1(rsig, sig_len); 43 | memcpy(sig, rsig, sig_len); 44 | return sig_len; 45 | } 46 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 | #include "inner.h" 26 | 27 | #define FIELD_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 28 | 29 | /* see bearssl_ec.h */ 30 | uint32_t 31 | br_ecdsa_i15_vrfy_asn1(const br_ec_impl *impl, 32 | const void *hash, size_t hash_len, 33 | const br_ec_public_key *pk, 34 | const void *sig, size_t sig_len) 35 | { 36 | /* 37 | * We use a double-sized buffer because a malformed ASN.1 signature 38 | * may trigger a size expansion when converting to "raw" format. 39 | */ 40 | unsigned char rsig[(FIELD_LEN << 2) + 24]; 41 | 42 | if (sig_len > ((sizeof rsig) >> 1)) { 43 | return 0; 44 | } 45 | memcpy(rsig, sig, sig_len); 46 | sig_len = br_ecdsa_asn1_to_raw(rsig, sig_len); 47 | return br_ecdsa_i15_vrfy_raw(impl, hash, hash_len, pk, rsig, sig_len); 48 | } 49 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 | #include "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_ecdsa_i31_bits2int(uint32_t *x, 30 | const void *src, size_t len, uint32_t ebitlen) 31 | { 32 | uint32_t bitlen, hbitlen; 33 | int sc; 34 | 35 | bitlen = ebitlen - (ebitlen >> 5); 36 | hbitlen = (uint32_t)len << 3; 37 | if (hbitlen > bitlen) { 38 | len = (bitlen + 7) >> 3; 39 | sc = (int)((hbitlen - bitlen) & 7); 40 | } else { 41 | sc = 0; 42 | } 43 | br_i31_zero(x, ebitlen); 44 | br_i31_decode(x, src, len); 45 | br_i31_rshift(x, sc); 46 | x[0] = ebitlen; 47 | } 48 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 | #include "inner.h" 26 | 27 | #define ORDER_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 28 | 29 | /* see bearssl_ec.h */ 30 | size_t 31 | br_ecdsa_i31_sign_asn1(const br_ec_impl *impl, 32 | const br_hash_class *hf, const void *hash_value, 33 | const br_ec_private_key *sk, void *sig) 34 | { 35 | unsigned char rsig[(ORDER_LEN << 1) + 12]; 36 | size_t sig_len; 37 | 38 | sig_len = br_ecdsa_i31_sign_raw(impl, hf, hash_value, sk, rsig); 39 | if (sig_len == 0) { 40 | return 0; 41 | } 42 | sig_len = br_ecdsa_raw_to_asn1(rsig, sig_len); 43 | memcpy(sig, rsig, sig_len); 44 | return sig_len; 45 | } 46 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 | #include "inner.h" 26 | 27 | #define FIELD_LEN ((BR_MAX_EC_SIZE + 7) >> 3) 28 | 29 | /* see bearssl_ec.h */ 30 | uint32_t 31 | br_ecdsa_i31_vrfy_asn1(const br_ec_impl *impl, 32 | const void *hash, size_t hash_len, 33 | const br_ec_public_key *pk, 34 | const void *sig, size_t sig_len) 35 | { 36 | /* 37 | * We use a double-sized buffer because a malformed ASN.1 signature 38 | * may trigger a size expansion when converting to "raw" format. 39 | */ 40 | unsigned char rsig[(FIELD_LEN << 2) + 24]; 41 | 42 | if (sig_len > ((sizeof rsig) >> 1)) { 43 | return 0; 44 | } 45 | memcpy(rsig, sig, sig_len); 46 | sig_len = br_ecdsa_asn1_to_raw(rsig, sig_len); 47 | return br_ecdsa_i31_vrfy_raw(impl, hash, hash_len, pk, rsig, sig_len); 48 | } 49 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc16be(void *dst, const uint16_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc16be(buf, *v ++); 36 | buf += 2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc16le(void *dst, const uint16_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc16le(buf, *v ++); 36 | buf += 2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc32be(void *dst, const uint32_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc32be(buf, *v ++); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc32le(void *dst, const uint32_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc32le(buf, *v ++); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc64be(void *dst, const uint64_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc64be(buf, *v ++); 36 | buf += 8; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc64le(void *dst, const uint64_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc64le(buf, *v ++); 36 | buf += 8; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 | #include "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i15_add(uint16_t *a, const uint16_t *b, uint32_t ctl) 30 | { 31 | uint32_t cc; 32 | size_t u, m; 33 | 34 | cc = 0; 35 | m = (a[0] + 31) >> 4; 36 | for (u = 1; u < m; u ++) { 37 | uint32_t aw, bw, naw; 38 | 39 | aw = a[u]; 40 | bw = b[u]; 41 | naw = aw + bw + cc; 42 | cc = naw >> 15; 43 | a[u] = MUX(ctl, naw & 0x7FFF, aw); 44 | } 45 | return cc; 46 | } 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i15_bit_length(uint16_t *x, size_t xlen) 30 | { 31 | uint32_t tw, twk; 32 | 33 | tw = 0; 34 | twk = 0; 35 | while (xlen -- > 0) { 36 | uint32_t w, c; 37 | 38 | c = EQ(tw, 0); 39 | w = x[xlen]; 40 | tw = MUX(c, w, tw); 41 | twk = MUX(c, (uint32_t)xlen, twk); 42 | } 43 | return (twk << 4) + BIT_LENGTH(tw); 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_decode(uint16_t *x, const void *src, size_t len) 30 | { 31 | const unsigned char *buf; 32 | size_t v; 33 | uint32_t acc; 34 | int acc_len; 35 | 36 | buf = src; 37 | v = 1; 38 | acc = 0; 39 | acc_len = 0; 40 | while (len -- > 0) { 41 | uint32_t b; 42 | 43 | b = buf[len]; 44 | acc |= (b << acc_len); 45 | acc_len += 8; 46 | if (acc_len >= 15) { 47 | x[v ++] = acc & 0x7FFF; 48 | acc_len -= 15; 49 | acc >>= 15; 50 | } 51 | } 52 | if (acc_len != 0) { 53 | x[v ++] = acc; 54 | } 55 | x[0] = br_i15_bit_length(x + 1, v - 1); 56 | } 57 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_encode(void *dst, size_t len, const uint16_t *x) 30 | { 31 | unsigned char *buf; 32 | size_t u, xlen; 33 | uint32_t acc; 34 | int acc_len; 35 | 36 | xlen = (x[0] + 15) >> 4; 37 | if (xlen == 0) { 38 | memset(dst, 0, len); 39 | return; 40 | } 41 | u = 1; 42 | acc = 0; 43 | acc_len = 0; 44 | buf = dst; 45 | while (len -- > 0) { 46 | if (acc_len < 8) { 47 | if (u <= xlen) { 48 | acc += (uint32_t)x[u ++] << acc_len; 49 | } 50 | acc_len += 15; 51 | } 52 | buf[len] = (unsigned char)acc; 53 | acc >>= 8; 54 | acc_len -= 8; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_from_monty(uint16_t *x, const uint16_t *m, uint16_t m0i) 30 | { 31 | size_t len, u, v; 32 | 33 | len = (m[0] + 15) >> 4; 34 | for (u = 0; u < len; u ++) { 35 | uint32_t f, cc; 36 | 37 | f = MUL15(x[1], m0i) & 0x7FFF; 38 | cc = 0; 39 | for (v = 0; v < len; v ++) { 40 | uint32_t z; 41 | 42 | z = (uint32_t)x[v + 1] + MUL15(f, m[v + 1]) + cc; 43 | cc = z >> 15; 44 | if (v != 0) { 45 | x[v] = z & 0x7FFF; 46 | } 47 | } 48 | x[len] = cc; 49 | } 50 | 51 | /* 52 | * We may have to do an extra subtraction, but only if the 53 | * value in x[] is indeed greater than or equal to that of m[], 54 | * which is why we must do two calls (first call computes the 55 | * carry, second call performs the subtraction only if the carry 56 | * is 0). 57 | */ 58 | br_i15_sub(x, m, NOT(br_i15_sub(x, m, 0))); 59 | } 60 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i15_iszero(const uint16_t *x) 30 | { 31 | uint32_t z; 32 | size_t u; 33 | 34 | z = 0; 35 | for (u = (x[0] + 15) >> 4; u > 0; u --) { 36 | z |= x[u]; 37 | } 38 | return ~(z | -z) >> 31; 39 | } 40 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_modpow(uint16_t *x, 30 | const unsigned char *e, size_t elen, 31 | const uint16_t *m, uint16_t m0i, uint16_t *t1, uint16_t *t2) 32 | { 33 | size_t mlen; 34 | unsigned k; 35 | 36 | mlen = ((m[0] + 31) >> 4) * sizeof m[0]; 37 | memcpy(t1, x, mlen); 38 | br_i15_to_monty(t1, m); 39 | br_i15_zero(x, m[0]); 40 | x[1] = 1; 41 | for (k = 0; k < ((unsigned)elen << 3); k ++) { 42 | uint32_t ctl; 43 | 44 | ctl = (e[elen - 1 - (k >> 3)] >> (k & 7)) & 1; 45 | br_i15_montymul(t2, x, t1, m, m0i); 46 | CCOPY(ctl, x, t2, mlen); 47 | br_i15_montymul(t2, t1, t1, m, m0i); 48 | memcpy(t1, t2, mlen); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_mulacc(uint16_t *d, const uint16_t *a, const uint16_t *b) 30 | { 31 | size_t alen, blen, u; 32 | unsigned dl, dh; 33 | 34 | alen = (a[0] + 15) >> 4; 35 | blen = (b[0] + 15) >> 4; 36 | 37 | /* 38 | * Announced bit length of d[] will be the sum of the announced 39 | * bit lengths of a[] and b[]; but the lengths are encoded. 40 | */ 41 | dl = (a[0] & 15) + (b[0] & 15); 42 | dh = (a[0] >> 4) + (b[0] >> 4); 43 | d[0] = (dh << 4) + dl + (~(uint32_t)(dl - 15) >> 31); 44 | 45 | for (u = 0; u < blen; u ++) { 46 | uint32_t f; 47 | size_t v; 48 | uint32_t cc; 49 | 50 | f = b[1 + u]; 51 | cc = 0; 52 | for (v = 0; v < alen; v ++) { 53 | uint32_t z; 54 | 55 | z = (uint32_t)d[1 + u + v] + MUL15(f, a[1 + v]) + cc; 56 | cc = z >> 15; 57 | d[1 + u + v] = z & 0x7FFF; 58 | } 59 | d[1 + u + alen] = cc; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint16_t 29 | br_i15_ninv15(uint16_t x) 30 | { 31 | uint32_t y; 32 | 33 | y = 2 - x; 34 | y = MUL15(y, 2 - MUL15(x, y)); 35 | y = MUL15(y, 2 - MUL15(x, y)); 36 | y = MUL15(y, 2 - MUL15(x, y)); 37 | return MUX(x & 1, -y, 0) & 0x7FFF; 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_rshift(uint16_t *x, int count) 30 | { 31 | size_t u, len; 32 | unsigned r; 33 | 34 | len = (x[0] + 15) >> 4; 35 | if (len == 0) { 36 | return; 37 | } 38 | r = x[1] >> count; 39 | for (u = 2; u <= len; u ++) { 40 | unsigned w; 41 | 42 | w = x[u]; 43 | x[u - 1] = ((w << (15 - count)) | r) & 0x7FFF; 44 | r = w >> count; 45 | } 46 | x[len] = r; 47 | } 48 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i15_sub(uint16_t *a, const uint16_t *b, uint32_t ctl) 30 | { 31 | uint32_t cc; 32 | size_t u, m; 33 | 34 | cc = 0; 35 | m = (a[0] + 31) >> 4; 36 | for (u = 1; u < m; u ++) { 37 | uint32_t aw, bw, naw; 38 | 39 | aw = a[u]; 40 | bw = b[u]; 41 | naw = aw - bw - cc; 42 | cc = naw >> 31; 43 | a[u] = MUX(ctl, naw & 0x7FFF, aw); 44 | } 45 | return cc; 46 | } 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i15_to_monty(uint16_t *x, const uint16_t *m) 30 | { 31 | unsigned k; 32 | 33 | for (k = (m[0] + 15) >> 4; k > 0; k --) { 34 | br_i15_muladd_small(x, 0, m); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i31_add(uint32_t *a, const uint32_t *b, uint32_t ctl) 30 | { 31 | uint32_t cc; 32 | size_t u, m; 33 | 34 | cc = 0; 35 | m = (a[0] + 63) >> 5; 36 | for (u = 1; u < m; u ++) { 37 | uint32_t aw, bw, naw; 38 | 39 | aw = a[u]; 40 | bw = b[u]; 41 | naw = aw + bw + cc; 42 | cc = naw >> 31; 43 | a[u] = MUX(ctl, naw & (uint32_t)0x7FFFFFFF, aw); 44 | } 45 | return cc; 46 | } 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i31_bit_length(uint32_t *x, size_t xlen) 30 | { 31 | uint32_t tw, twk; 32 | 33 | tw = 0; 34 | twk = 0; 35 | while (xlen -- > 0) { 36 | uint32_t w, c; 37 | 38 | c = EQ(tw, 0); 39 | w = x[xlen]; 40 | tw = MUX(c, w, tw); 41 | twk = MUX(c, (uint32_t)xlen, twk); 42 | } 43 | return (twk << 5) + BIT_LENGTH(tw); 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i31_decode(uint32_t *x, const void *src, size_t len) 30 | { 31 | const unsigned char *buf; 32 | size_t u, v; 33 | uint32_t acc; 34 | int acc_len; 35 | 36 | buf = src; 37 | u = len; 38 | v = 1; 39 | acc = 0; 40 | acc_len = 0; 41 | while (u -- > 0) { 42 | uint32_t b; 43 | 44 | b = buf[u]; 45 | acc |= (b << acc_len); 46 | acc_len += 8; 47 | if (acc_len >= 31) { 48 | x[v ++] = acc & (uint32_t)0x7FFFFFFF; 49 | acc_len -= 31; 50 | acc = b >> (8 - acc_len); 51 | } 52 | } 53 | if (acc_len != 0) { 54 | x[v ++] = acc; 55 | } 56 | x[0] = br_i31_bit_length(x + 1, v - 1); 57 | } 58 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i31_iszero(const uint32_t *x) 30 | { 31 | uint32_t z; 32 | size_t u; 33 | 34 | z = 0; 35 | for (u = (x[0] + 31) >> 5; u > 0; u --) { 36 | z |= x[u]; 37 | } 38 | return ~(z | -z) >> 31; 39 | } 40 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i31_ninv31(uint32_t x) 30 | { 31 | uint32_t y; 32 | 33 | y = 2 - x; 34 | y *= 2 - y * x; 35 | y *= 2 - y * x; 36 | y *= 2 - y * x; 37 | y *= 2 - y * x; 38 | return MUX(x & 1, -y, 0) & 0x7FFFFFFF; 39 | } 40 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i31_rshift(uint32_t *x, int count) 30 | { 31 | size_t u, len; 32 | uint32_t r; 33 | 34 | len = (x[0] + 31) >> 5; 35 | if (len == 0) { 36 | return; 37 | } 38 | r = x[1] >> count; 39 | for (u = 2; u <= len; u ++) { 40 | uint32_t w; 41 | 42 | w = x[u]; 43 | x[u - 1] = ((w << (31 - count)) | r) & 0x7FFFFFFF; 44 | r = w >> count; 45 | } 46 | x[len] = r; 47 | } 48 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i31_sub(uint32_t *a, const uint32_t *b, uint32_t ctl) 30 | { 31 | uint32_t cc; 32 | size_t u, m; 33 | 34 | cc = 0; 35 | m = (a[0] + 63) >> 5; 36 | for (u = 1; u < m; u ++) { 37 | uint32_t aw, bw, naw; 38 | 39 | aw = a[u]; 40 | bw = b[u]; 41 | naw = aw - bw - cc; 42 | cc = naw >> 31; 43 | a[u] = MUX(ctl, naw & 0x7FFFFFFF, aw); 44 | } 45 | return cc; 46 | } 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i31_to_monty(uint32_t *x, const uint32_t *m) 30 | { 31 | uint32_t k; 32 | 33 | for (k = (m[0] + 31) >> 5; k > 0; k --) { 34 | br_i31_muladd_small(x, 0, m); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i32_add(uint32_t *a, const uint32_t *b, uint32_t ctl) 30 | { 31 | uint32_t cc; 32 | size_t u, m; 33 | 34 | cc = 0; 35 | m = (a[0] + 63) >> 5; 36 | for (u = 1; u < m; u ++) { 37 | uint32_t aw, bw, naw; 38 | 39 | aw = a[u]; 40 | bw = b[u]; 41 | naw = aw + bw + cc; 42 | 43 | /* 44 | * Carry is 1 if naw < aw. Carry is also 1 if naw == aw 45 | * AND the carry was already 1. 46 | */ 47 | cc = (cc & EQ(naw, aw)) | LT(naw, aw); 48 | a[u] = MUX(ctl, naw, aw); 49 | } 50 | return cc; 51 | } 52 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i32_bit_length(uint32_t *x, size_t xlen) 30 | { 31 | uint32_t tw, twk; 32 | 33 | tw = 0; 34 | twk = 0; 35 | while (xlen -- > 0) { 36 | uint32_t w, c; 37 | 38 | c = EQ(tw, 0); 39 | w = x[xlen]; 40 | tw = MUX(c, w, tw); 41 | twk = MUX(c, (uint32_t)xlen, twk); 42 | } 43 | return (twk << 5) + BIT_LENGTH(tw); 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i32_decode(uint32_t *x, const void *src, size_t len) 30 | { 31 | const unsigned char *buf; 32 | size_t u, v; 33 | 34 | buf = src; 35 | u = len; 36 | v = 1; 37 | for (;;) { 38 | if (u < 4) { 39 | uint32_t w; 40 | 41 | if (u < 2) { 42 | if (u == 0) { 43 | break; 44 | } else { 45 | w = buf[0]; 46 | } 47 | } else { 48 | if (u == 2) { 49 | w = br_dec16be(buf); 50 | } else { 51 | w = ((uint32_t)buf[0] << 16) 52 | | br_dec16be(buf + 1); 53 | } 54 | } 55 | x[v ++] = w; 56 | break; 57 | } else { 58 | u -= 4; 59 | x[v ++] = br_dec32be(buf + u); 60 | } 61 | } 62 | x[0] = br_i32_bit_length(x + 1, v - 1); 63 | } 64 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_divrem(uint32_t hi, uint32_t lo, uint32_t d, uint32_t *r) 30 | { 31 | /* TODO: optimize this */ 32 | uint32_t q; 33 | uint32_t ch, cf; 34 | int k; 35 | 36 | q = 0; 37 | ch = EQ(hi, d); 38 | hi = MUX(ch, 0, hi); 39 | for (k = 31; k > 0; k --) { 40 | int j; 41 | uint32_t w, ctl, hi2, lo2; 42 | 43 | j = 32 - k; 44 | w = (hi << j) | (lo >> k); 45 | ctl = GE(w, d) | (hi >> k); 46 | hi2 = (w - d) >> j; 47 | lo2 = lo - (d << k); 48 | hi = MUX(ctl, hi2, hi); 49 | lo = MUX(ctl, lo2, lo); 50 | q |= ctl << k; 51 | } 52 | cf = GE(lo, d) | hi; 53 | q |= cf; 54 | *r = MUX(cf, lo - d, lo); 55 | return q; 56 | } 57 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i32_iszero(const uint32_t *x) 30 | { 31 | uint32_t z; 32 | size_t u; 33 | 34 | z = 0; 35 | for (u = (x[0] + 31) >> 5; u > 0; u --) { 36 | z |= x[u]; 37 | } 38 | return ~(z | -z) >> 31; 39 | } 40 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i32_mulacc(uint32_t *d, const uint32_t *a, const uint32_t *b) 30 | { 31 | size_t alen, blen, u; 32 | 33 | alen = (a[0] + 31) >> 5; 34 | blen = (b[0] + 31) >> 5; 35 | d[0] = a[0] + b[0]; 36 | for (u = 0; u < blen; u ++) { 37 | uint32_t f; 38 | size_t v; 39 | uint64_t cc; 40 | 41 | f = b[1 + u]; 42 | cc = 0; 43 | for (v = 0; v < alen; v ++) { 44 | uint64_t z; 45 | 46 | z = (uint64_t)d[1 + u + v] + MUL(f, a[1 + v]) + cc; 47 | cc = z >> 32; 48 | d[1 + u + v] = (uint32_t)z; 49 | } 50 | d[1 + u + alen] = (uint32_t)cc; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i32_ninv32(uint32_t x) 30 | { 31 | uint32_t y; 32 | 33 | y = 2 - x; 34 | y *= 2 - y * x; 35 | y *= 2 - y * x; 36 | y *= 2 - y * x; 37 | y *= 2 - y * x; 38 | return MUX(x & 1, -y, 0); 39 | } 40 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | uint32_t 29 | br_i32_sub(uint32_t *a, const uint32_t *b, uint32_t ctl) 30 | { 31 | uint32_t cc; 32 | size_t u, m; 33 | 34 | cc = 0; 35 | m = (a[0] + 63) >> 5; 36 | for (u = 1; u < m; u ++) { 37 | uint32_t aw, bw, naw; 38 | 39 | aw = a[u]; 40 | bw = b[u]; 41 | naw = aw - bw - cc; 42 | 43 | /* 44 | * Carry is 1 if naw > aw. Carry is 1 also if naw == aw 45 | * AND the carry was already 1. 46 | */ 47 | cc = (cc & EQ(naw, aw)) | GT(naw, aw); 48 | a[u] = MUX(ctl, naw, aw); 49 | } 50 | return cc; 51 | } 52 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_i32_to_monty(uint32_t *x, const uint32_t *m) 30 | { 31 | uint32_t k; 32 | 33 | for (k = (m[0] + 31) >> 5; k > 0; k --) { 34 | br_i32_muladd_small(x, 0, m); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_mgf1_xor(void *data, size_t len, 30 | const br_hash_class *dig, const void *seed, size_t seed_len) 31 | { 32 | unsigned char *buf; 33 | size_t u, hlen; 34 | uint32_t c; 35 | 36 | buf = data; 37 | hlen = br_digest_size(dig); 38 | for (u = 0, c = 0; u < len; u += hlen, c ++) { 39 | br_hash_compat_context hc; 40 | unsigned char tmp[64]; 41 | size_t v; 42 | 43 | hc.vtable = dig; 44 | dig->init(&hc.vtable); 45 | dig->update(&hc.vtable, seed, seed_len); 46 | br_enc32be(tmp, c); 47 | dig->update(&hc.vtable, tmp, 4); 48 | dig->out(&hc.vtable, tmp); 49 | for (v = 0; v < hlen; v ++) { 50 | if ((u + v) >= len) { 51 | break; 52 | } 53 | buf[u + v] ^= tmp[v]; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl.h */ 28 | void 29 | br_tls10_prf(void *dst, size_t len, 30 | const void *secret, size_t secret_len, const char *label, 31 | size_t seed_num, const br_tls_prf_seed_chunk *seed) 32 | { 33 | const unsigned char *s1; 34 | size_t slen; 35 | 36 | s1 = secret; 37 | slen = (secret_len + 1) >> 1; 38 | memset(dst, 0, len); 39 | br_tls_phash(dst, len, &br_md5_vtable, 40 | s1, slen, label, seed_num, seed); 41 | br_tls_phash(dst, len, &br_sha1_vtable, 42 | s1 + secret_len - slen, slen, label, seed_num, seed); 43 | } 44 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl.h */ 28 | void 29 | br_tls12_sha256_prf(void *dst, size_t len, 30 | const void *secret, size_t secret_len, const char *label, 31 | size_t seed_num, const br_tls_prf_seed_chunk *seed) 32 | { 33 | memset(dst, 0, len); 34 | br_tls_phash(dst, len, &br_sha256_vtable, 35 | secret, secret_len, label, seed_num, seed); 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl.h */ 28 | void 29 | br_tls12_sha384_prf(void *dst, size_t len, 30 | const void *secret, size_t secret_len, const char *label, 31 | size_t seed_num, const br_tls_prf_seed_chunk *seed) 32 | { 33 | memset(dst, 0, len); 34 | br_tls_phash(dst, len, &br_sha384_vtable, 35 | secret, secret_len, label, seed_num, seed); 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_keygen 29 | br_rsa_keygen_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_keygen; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_keygen; 35 | #else 36 | return &br_rsa_i31_keygen; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_compute_modulus 29 | br_rsa_compute_modulus_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_rsa_i15_compute_modulus; 33 | #else 34 | return &br_rsa_i31_compute_modulus; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_oaep_decrypt 29 | br_rsa_oaep_decrypt_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_oaep_decrypt; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_oaep_decrypt; 35 | #else 36 | return &br_rsa_i31_oaep_decrypt; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_oaep_encrypt 29 | br_rsa_oaep_encrypt_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_oaep_encrypt; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_oaep_encrypt; 35 | #else 36 | return &br_rsa_i31_oaep_encrypt; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_pkcs1_sign 29 | br_rsa_pkcs1_sign_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_pkcs1_sign; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_pkcs1_sign; 35 | #else 36 | return &br_rsa_i31_pkcs1_sign; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_pkcs1_vrfy 29 | br_rsa_pkcs1_vrfy_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_pkcs1_vrfy; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_pkcs1_vrfy; 35 | #else 36 | return &br_rsa_i31_pkcs1_vrfy; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_private 29 | br_rsa_private_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_private; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_private; 35 | #else 36 | return &br_rsa_i31_private; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_compute_privexp 29 | br_rsa_compute_privexp_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_rsa_i15_compute_privexp; 33 | #else 34 | return &br_rsa_i31_compute_privexp; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_public 29 | br_rsa_public_get_default(void) 30 | { 31 | #if BR_INT128 || BR_UMUL128 32 | return &br_rsa_i62_public; 33 | #elif BR_LOMUL 34 | return &br_rsa_i15_public; 35 | #else 36 | return &br_rsa_i31_public; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | br_rsa_compute_pubexp 29 | br_rsa_compute_pubexp_get_default(void) 30 | { 31 | #if BR_LOMUL 32 | return &br_rsa_i15_compute_pubexp; 33 | #else 34 | return &br_rsa_i31_compute_pubexp; 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i15_oaep_decrypt(const br_hash_class *dig, 30 | const void *label, size_t label_len, 31 | const br_rsa_private_key *sk, void *data, size_t *len) 32 | { 33 | uint32_t r; 34 | 35 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 36 | return 0; 37 | } 38 | r = br_rsa_i15_private(data, sk); 39 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 40 | return r; 41 | } 42 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | size_t 29 | br_rsa_i15_oaep_encrypt( 30 | const br_prng_class **rnd, const br_hash_class *dig, 31 | const void *label, size_t label_len, 32 | const br_rsa_public_key *pk, 33 | void *dst, size_t dst_max_len, 34 | const void *src, size_t src_len) 35 | { 36 | size_t dlen; 37 | 38 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 39 | pk, dst, dst_max_len, src, src_len); 40 | if (dlen == 0) { 41 | return 0; 42 | } 43 | return dlen & -(size_t)br_rsa_i15_public(dst, dlen, pk); 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i15_pkcs1_sign(const unsigned char *hash_oid, 30 | const unsigned char *hash, size_t hash_len, 31 | const br_rsa_private_key *sk, unsigned char *x) 32 | { 33 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 34 | return 0; 35 | } 36 | return br_rsa_i15_private(x, sk); 37 | } 38 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i15_pkcs1_vrfy(const unsigned char *x, size_t xlen, 30 | const unsigned char *hash_oid, size_t hash_len, 31 | const br_rsa_public_key *pk, unsigned char *hash_out) 32 | { 33 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 34 | 35 | if (xlen > (sizeof sig)) { 36 | return 0; 37 | } 38 | memcpy(sig, x, xlen); 39 | if (!br_rsa_i15_public(sig, xlen, pk)) { 40 | return 0; 41 | } 42 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 43 | } 44 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i31_keygen(const br_prng_class **rng, 30 | br_rsa_private_key *sk, void *kbuf_priv, 31 | br_rsa_public_key *pk, void *kbuf_pub, 32 | unsigned size, uint32_t pubexp) 33 | { 34 | return br_rsa_i31_keygen_inner(rng, 35 | sk, kbuf_priv, pk, kbuf_pub, size, pubexp, 36 | &br_i31_modpow_opt); 37 | } 38 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i31_oaep_decrypt(const br_hash_class *dig, 30 | const void *label, size_t label_len, 31 | const br_rsa_private_key *sk, void *data, size_t *len) 32 | { 33 | uint32_t r; 34 | 35 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 36 | return 0; 37 | } 38 | r = br_rsa_i31_private(data, sk); 39 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 40 | return r; 41 | } 42 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | size_t 29 | br_rsa_i31_oaep_encrypt( 30 | const br_prng_class **rnd, const br_hash_class *dig, 31 | const void *label, size_t label_len, 32 | const br_rsa_public_key *pk, 33 | void *dst, size_t dst_max_len, 34 | const void *src, size_t src_len) 35 | { 36 | size_t dlen; 37 | 38 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 39 | pk, dst, dst_max_len, src, src_len); 40 | if (dlen == 0) { 41 | return 0; 42 | } 43 | return dlen & -(size_t)br_rsa_i31_public(dst, dlen, pk); 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i31_pkcs1_sign(const unsigned char *hash_oid, 30 | const unsigned char *hash, size_t hash_len, 31 | const br_rsa_private_key *sk, unsigned char *x) 32 | { 33 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 34 | return 0; 35 | } 36 | return br_rsa_i31_private(x, sk); 37 | } 38 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i31_pkcs1_vrfy(const unsigned char *x, size_t xlen, 30 | const unsigned char *hash_oid, size_t hash_len, 31 | const br_rsa_public_key *pk, unsigned char *hash_out) 32 | { 33 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 34 | 35 | if (xlen > (sizeof sig)) { 36 | return 0; 37 | } 38 | memcpy(sig, x, xlen); 39 | if (!br_rsa_i31_public(sig, xlen, pk)) { 40 | return 0; 41 | } 42 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 43 | } 44 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i32_oaep_decrypt(const br_hash_class *dig, 30 | const void *label, size_t label_len, 31 | const br_rsa_private_key *sk, void *data, size_t *len) 32 | { 33 | uint32_t r; 34 | 35 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 36 | return 0; 37 | } 38 | r = br_rsa_i32_private(data, sk); 39 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 40 | return r; 41 | } 42 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | size_t 29 | br_rsa_i32_oaep_encrypt( 30 | const br_prng_class **rnd, const br_hash_class *dig, 31 | const void *label, size_t label_len, 32 | const br_rsa_public_key *pk, 33 | void *dst, size_t dst_max_len, 34 | const void *src, size_t src_len) 35 | { 36 | size_t dlen; 37 | 38 | dlen = br_rsa_oaep_pad(rnd, dig, label, label_len, 39 | pk, dst, dst_max_len, src, src_len); 40 | if (dlen == 0) { 41 | return 0; 42 | } 43 | return dlen & -(size_t)br_rsa_i32_public(dst, dlen, pk); 44 | } 45 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i32_pkcs1_sign(const unsigned char *hash_oid, 30 | const unsigned char *hash, size_t hash_len, 31 | const br_rsa_private_key *sk, unsigned char *x) 32 | { 33 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 34 | return 0; 35 | } 36 | return br_rsa_i32_private(x, sk); 37 | } 38 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_i32_pkcs1_vrfy(const unsigned char *x, size_t xlen, 30 | const unsigned char *hash_oid, size_t hash_len, 31 | const br_rsa_public_key *pk, unsigned char *hash_out) 32 | { 33 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 34 | 35 | if (xlen > (sizeof sig)) { 36 | return 0; 37 | } 38 | memcpy(sig, x, xlen); 39 | if (!br_rsa_i32_public(sig, xlen, pk)) { 40 | return 0; 41 | } 42 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 43 | } 44 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | #if BR_INT128 || BR_UMUL128 28 | 29 | /* see bearssl_rsa.h */ 30 | uint32_t 31 | br_rsa_i62_keygen(const br_prng_class **rng, 32 | br_rsa_private_key *sk, void *kbuf_priv, 33 | br_rsa_public_key *pk, void *kbuf_pub, 34 | unsigned size, uint32_t pubexp) 35 | { 36 | return br_rsa_i31_keygen_inner(rng, 37 | sk, kbuf_priv, pk, kbuf_pub, size, pubexp, 38 | &br_i62_modpow_opt_as_i31); 39 | } 40 | 41 | /* see bearssl_rsa.h */ 42 | br_rsa_keygen 43 | br_rsa_i62_keygen_get() 44 | { 45 | return &br_rsa_i62_keygen; 46 | } 47 | 48 | #else 49 | 50 | /* see bearssl_rsa.h */ 51 | br_rsa_keygen 52 | br_rsa_i62_keygen_get() 53 | { 54 | return 0; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | #if BR_INT128 || BR_UMUL128 28 | 29 | /* see bearssl_rsa.h */ 30 | uint32_t 31 | br_rsa_i62_oaep_decrypt(const br_hash_class *dig, 32 | const void *label, size_t label_len, 33 | const br_rsa_private_key *sk, void *data, size_t *len) 34 | { 35 | uint32_t r; 36 | 37 | if (*len != ((sk->n_bitlen + 7) >> 3)) { 38 | return 0; 39 | } 40 | r = br_rsa_i62_private(data, sk); 41 | r &= br_rsa_oaep_unpad(dig, label, label_len, data, len); 42 | return r; 43 | } 44 | 45 | /* see bearssl_rsa.h */ 46 | br_rsa_oaep_decrypt 47 | br_rsa_i62_oaep_decrypt_get(void) 48 | { 49 | return &br_rsa_i62_oaep_decrypt; 50 | } 51 | 52 | #else 53 | 54 | /* see bearssl_rsa.h */ 55 | br_rsa_oaep_decrypt 56 | br_rsa_i62_oaep_decrypt_get(void) 57 | { 58 | return 0; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | #if BR_INT128 || BR_UMUL128 28 | 29 | /* see bearssl_rsa.h */ 30 | uint32_t 31 | br_rsa_i62_pkcs1_sign(const unsigned char *hash_oid, 32 | const unsigned char *hash, size_t hash_len, 33 | const br_rsa_private_key *sk, unsigned char *x) 34 | { 35 | if (!br_rsa_pkcs1_sig_pad(hash_oid, hash, hash_len, sk->n_bitlen, x)) { 36 | return 0; 37 | } 38 | return br_rsa_i62_private(x, sk); 39 | } 40 | 41 | /* see bearssl_rsa.h */ 42 | br_rsa_pkcs1_sign 43 | br_rsa_i62_pkcs1_sign_get(void) 44 | { 45 | return &br_rsa_i62_pkcs1_sign; 46 | } 47 | 48 | #else 49 | 50 | /* see bearssl_rsa.h */ 51 | br_rsa_pkcs1_sign 52 | br_rsa_i62_pkcs1_sign_get(void) 53 | { 54 | return 0; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | #if BR_INT128 || BR_UMUL128 28 | 29 | /* see bearssl_rsa.h */ 30 | uint32_t 31 | br_rsa_i62_pkcs1_vrfy(const unsigned char *x, size_t xlen, 32 | const unsigned char *hash_oid, size_t hash_len, 33 | const br_rsa_public_key *pk, unsigned char *hash_out) 34 | { 35 | unsigned char sig[BR_MAX_RSA_SIZE >> 3]; 36 | 37 | if (xlen > (sizeof sig)) { 38 | return 0; 39 | } 40 | memcpy(sig, x, xlen); 41 | if (!br_rsa_i62_public(sig, xlen, pk)) { 42 | return 0; 43 | } 44 | return br_rsa_pkcs1_sig_unpad(sig, xlen, hash_oid, hash_len, hash_out); 45 | } 46 | 47 | /* see bearssl_rsa.h */ 48 | br_rsa_pkcs1_vrfy 49 | br_rsa_i62_pkcs1_vrfy_get(void) 50 | { 51 | return &br_rsa_i62_pkcs1_vrfy; 52 | } 53 | 54 | #else 55 | 56 | /* see bearssl_rsa.h */ 57 | br_rsa_pkcs1_vrfy 58 | br_rsa_i62_pkcs1_vrfy_get(void) 59 | { 60 | return 0; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_rsa.h */ 28 | uint32_t 29 | br_rsa_ssl_decrypt(br_rsa_private core, const br_rsa_private_key *sk, 30 | unsigned char *data, size_t len) 31 | { 32 | uint32_t x; 33 | size_t u; 34 | 35 | /* 36 | * A first check on length. Since this test works only on the 37 | * buffer length, it needs not (and cannot) be constant-time. 38 | */ 39 | if (len < 59 || len != (sk->n_bitlen + 7) >> 3) { 40 | return 0; 41 | } 42 | x = core(data, sk); 43 | 44 | x &= EQ(data[0], 0x00); 45 | x &= EQ(data[1], 0x02); 46 | for (u = 2; u < (len - 49); u ++) { 47 | x &= NEQ(data[u], 0); 48 | } 49 | x &= EQ(data[len - 49], 0x00); 50 | memmove(data, data + len - 48, 48); 51 | return x; 52 | } 53 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ssl.h */ 28 | void 29 | br_ssl_client_set_default_rsapub(br_ssl_client_context *cc) 30 | { 31 | br_ssl_client_set_rsapub(cc, br_rsa_public_get_default()); 32 | } 33 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ssl.h */ 28 | void 29 | br_ssl_engine_set_default_des_cbc(br_ssl_engine_context *cc) 30 | { 31 | br_ssl_engine_set_cbc(cc, 32 | &br_sslrec_in_cbc_vtable, 33 | &br_sslrec_out_cbc_vtable); 34 | br_ssl_engine_set_des_cbc(cc, 35 | &br_des_ct_cbcenc_vtable, 36 | &br_des_ct_cbcdec_vtable); 37 | } 38 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ssl.h */ 28 | void 29 | br_ssl_engine_set_default_ec(br_ssl_engine_context *cc) 30 | { 31 | #if BR_LOMUL 32 | br_ssl_engine_set_ec(cc, &br_ec_all_m15); 33 | #else 34 | br_ssl_engine_set_ec(cc, &br_ec_all_m31); 35 | #endif 36 | } 37 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ssl.h */ 28 | void 29 | br_ssl_engine_set_default_ecdsa(br_ssl_engine_context *cc) 30 | { 31 | #if BR_LOMUL 32 | br_ssl_engine_set_ec(cc, &br_ec_all_m15); 33 | br_ssl_engine_set_ecdsa(cc, &br_ecdsa_i15_vrfy_asn1); 34 | #else 35 | br_ssl_engine_set_ec(cc, &br_ec_all_m31); 36 | br_ssl_engine_set_ecdsa(cc, &br_ecdsa_i31_vrfy_asn1); 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ssl.h */ 28 | void 29 | br_ssl_engine_set_default_rsavrfy(br_ssl_engine_context *cc) 30 | { 31 | br_ssl_engine_set_rsavrfy(cc, br_rsa_pkcs1_vrfy_get_default()); 32 | } 33 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see inner.h */ 28 | int 29 | br_ssl_choose_hash(unsigned bf) 30 | { 31 | static const unsigned char pref[] = { 32 | br_sha256_ID, br_sha384_ID, br_sha512_ID, 33 | br_sha224_ID, br_sha1_ID 34 | }; 35 | size_t u; 36 | 37 | for (u = 0; u < sizeof pref; u ++) { 38 | int x; 39 | 40 | x = pref[u]; 41 | if ((bf >> x) & 1) { 42 | return x; 43 | } 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/bearssl/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 "inner.h" 26 | 27 | /* see bearssl_ssl.h */ 28 | void 29 | br_ssl_server_zero(br_ssl_server_context *cc) 30 | { 31 | /* 32 | * For really standard C, we should explicitly set to NULL all 33 | * pointers, and 0 all other fields. However, on all our target 34 | * architectures, a direct memset() will work, be faster, and 35 | * use a lot less code. 36 | */ 37 | memset(cc, 0, sizeof *cc); 38 | } 39 | 40 | /* see bearssl_ssl.h */ 41 | int 42 | br_ssl_server_reset(br_ssl_server_context *cc) 43 | { 44 | br_ssl_engine_set_buffer(&cc->eng, NULL, 0, 0); 45 | if (!br_ssl_engine_init_rand(&cc->eng)) { 46 | return 0; 47 | } 48 | cc->eng.reneg = 0; 49 | br_ssl_engine_hs_reset(&cc->eng, 50 | br_ssl_hs_server_init_main, br_ssl_hs_server_run); 51 | return br_ssl_engine_last_error(&cc->eng) == BR_ERR_OK; 52 | } 53 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoBearSSL/src/utility/eccX08_asn1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Arduino SA. All rights reserved. 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 | #ifndef _ECCX08_ASN1_H_ 26 | #define _ECCX08_ASN1_H_ 27 | 28 | #include "bearssl/bearssl.h" 29 | 30 | size_t 31 | eccX08_sign_asn1(const br_ec_impl *impl, 32 | const br_hash_class *hf, const void *hash_value, 33 | const br_ec_private_key *sk, void *sig); 34 | 35 | uint32_t 36 | eccX08_vrfy_asn1(const br_ec_impl *impl, 37 | const void *hash, size_t hash_len, 38 | const br_ec_public_key *pk, 39 | const void *sig, size_t sig_len); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoECCX08/src/ArduinoECCX08.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the ArduinoECCX08 library. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _ARDUINO_ECCX08_H_ 21 | #define _ARDUINO_ECCX08_H_ 22 | 23 | #include "ECCX08.h" 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoECCX08/src/utility/ECCX08JWS.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the ArduinoECCX08 library. 3 | Copyright (c) 2019 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _ECCX08_JWS_H_ 21 | #define _ECCX08_JWS_H_ 22 | 23 | #include 24 | 25 | class ECCX08JWSClass { 26 | public: 27 | ECCX08JWSClass(); 28 | virtual ~ECCX08JWSClass(); 29 | 30 | String publicKey(int slot, bool newPrivateKey = true); 31 | 32 | String sign(int slot, const char* header, const char* payload); 33 | String sign(int slot, const String& header, const String& payload); 34 | }; 35 | 36 | extern ECCX08JWSClass ECCX08JWS; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoECCX08/src/utility/PEMUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the ArduinoECCX08 library. 3 | Copyright (c) 2019 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _PEM_UTILS_H_ 21 | #define _PEM_UTILS_H_ 22 | 23 | #include 24 | 25 | class PEMUtilsClass { 26 | public: 27 | String base64Encode(const byte in[], unsigned int length, const char* prefix, const char* suffix); 28 | }; 29 | 30 | extern PEMUtilsClass PEMUtils; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /arduino/libraries/ArduinoECCX08/src/utility/sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | /* 5 | SHA-1 in C 6 | By Steve Reid 7 | 100% Public Domain 8 | */ 9 | 10 | #include "stdint.h" 11 | 12 | typedef struct 13 | { 14 | uint32_t state[5]; 15 | uint32_t count[2]; 16 | unsigned char buffer[64]; 17 | } SHA1_CTX; 18 | 19 | void SHA1Transform( 20 | uint32_t state[5], 21 | const unsigned char buffer[64] 22 | ); 23 | 24 | void SHA1Init( 25 | SHA1_CTX * context 26 | ); 27 | 28 | void SHA1Update( 29 | SHA1_CTX * context, 30 | const unsigned char *data, 31 | uint32_t len 32 | ); 33 | 34 | void SHA1Final( 35 | unsigned char digest[20], 36 | SHA1_CTX * context 37 | ); 38 | 39 | #ifdef ARDUINO 40 | #define SHA1 SHA1_ // to make the function "internal" 41 | #endif 42 | 43 | void SHA1( 44 | char *hash_out, 45 | const char *str, 46 | int len); 47 | 48 | #endif /* SHA1_H */ 49 | -------------------------------------------------------------------------------- /arduino/libraries/SPIS/src/SPIS.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef SPIS_H 21 | #define SPIS_H 22 | 23 | #include 24 | #include 25 | 26 | class SPISClass { 27 | 28 | public: 29 | SPISClass(spi_host_device_t hostDevice, int dmaChannel, int mosiPin, int misoPin, int sclkPin, int csPin, int readyPin); 30 | 31 | int begin(); 32 | int transfer(uint8_t out[], uint8_t in[], size_t len); 33 | 34 | private: 35 | static void onChipSelect(); 36 | void handleOnChipSelect(); 37 | 38 | static void onSetupComplete(spi_slave_transaction_t*); 39 | void handleSetupComplete(); 40 | 41 | private: 42 | spi_host_device_t _hostDevice; 43 | int _dmaChannel; 44 | int _mosiPin; 45 | int _misoPin; 46 | int _sclkPin; 47 | int _csPin; 48 | int _readyPin; 49 | 50 | intr_handle_t _csIntrHandle; 51 | 52 | SemaphoreHandle_t _readySemaphore; 53 | }; 54 | 55 | extern SPISClass SPIS; 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /arduino/libraries/WiFi/src/WiFiClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef WIFICLIENT_H 21 | #define WIFICLIENT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class WiFiServer; 28 | 29 | class WiFiClient : public Client { 30 | 31 | public: 32 | WiFiClient(); 33 | 34 | uint8_t status(); 35 | 36 | virtual int connect(IPAddress ip, uint16_t port); 37 | virtual int connect(const char* host, uint16_t port); 38 | virtual size_t write(uint8_t); 39 | virtual size_t write(const uint8_t *buf, size_t size); 40 | virtual int available(); 41 | virtual int read(); 42 | virtual int read(uint8_t *buf, size_t size); 43 | virtual int peek(); 44 | virtual void flush(); 45 | virtual void stop(); 46 | virtual uint8_t connected(); 47 | virtual operator bool(); 48 | bool operator==(const WiFiClient &other) const; 49 | 50 | virtual /*IPAddress*/uint32_t remoteIP(); 51 | virtual uint16_t remotePort(); 52 | 53 | // using Print::write; 54 | 55 | protected: 56 | friend class WiFiServer; 57 | 58 | WiFiClient(int socket); 59 | 60 | private: 61 | int _socket; 62 | }; 63 | 64 | #endif // WIFICLIENT_H 65 | -------------------------------------------------------------------------------- /arduino/libraries/WiFi/src/WiFiServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef WIFISERVER_H 21 | #define WIFISERVER_H 22 | 23 | #include 24 | 25 | #include 26 | // #include 27 | 28 | class WiFiClient; 29 | 30 | class WiFiServer /*: public Server*/ { 31 | public: 32 | WiFiServer(); 33 | WiFiClient available(uint8_t* status = NULL); 34 | WiFiClient accept(); 35 | bool hasClient(); 36 | uint8_t begin(uint16_t port); 37 | virtual size_t write(uint8_t); 38 | virtual size_t write(const uint8_t *buf, size_t size); 39 | uint8_t status(); 40 | 41 | // using Print::write; 42 | 43 | virtual operator bool(); 44 | 45 | private: 46 | uint16_t _port; 47 | int _socket; 48 | int _spawnedSockets[CONFIG_LWIP_MAX_SOCKETS]; 49 | int _accepted_sock = -1; 50 | }; 51 | 52 | #endif // WIFISERVER_H 53 | -------------------------------------------------------------------------------- /arduino/libraries/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | beginTransmission KEYWORD2 15 | endTransmission KEYWORD2 16 | requestFrom KEYWORD2 17 | onReceive KEYWORD2 18 | onRequest KEYWORD2 19 | 20 | ####################################### 21 | # Instances (KEYWORD2) 22 | ####################################### 23 | 24 | Wire KEYWORD2 25 | Wire1 KEYWORD2 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | 31 | -------------------------------------------------------------------------------- /arduino/libraries/Wire/library.properties: -------------------------------------------------------------------------------- 1 | name=Wire 2 | version=1.0 3 | author=Jonathan BAUDIN, Thibaut VIARD, Arduino 4 | maintainer=Arduino 5 | sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. Specific implementation for Arduino ESP32. 6 | paragraph= 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/Wire 9 | architectures=esp32 10 | -------------------------------------------------------------------------------- /combine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys; 4 | 5 | booloaderData = open("build/bootloader/bootloader.bin", "rb").read() 6 | partitionData = open("build/partitions.bin", "rb").read() 7 | phyData = open("data/phy.bin", "rb").read() 8 | certsData = open("data/roots.pem", "rb").read() 9 | appData = open("build/nina-fw.bin", "rb").read() 10 | 11 | # calculate the output binary size, app offset 12 | outputSize = 0x30000 + len(appData) 13 | if (outputSize % 1024): 14 | outputSize += 1024 - (outputSize % 1024) 15 | 16 | # allocate and init to 0xff 17 | outputData = bytearray(b'\xff') * outputSize 18 | 19 | # copy data: bootloader, partitions, app 20 | for i in range(0, len(booloaderData)): 21 | outputData[0x1000 + i] = booloaderData[i] 22 | 23 | for i in range(0, len(partitionData)): 24 | outputData[0x8000 + i] = partitionData[i] 25 | 26 | for i in range(0, len(phyData)): 27 | outputData[0xf000 + i] = phyData[i] 28 | 29 | for i in range(0, len(certsData)): 30 | outputData[0x10000 + i] = certsData[i] 31 | 32 | # zero terminate the pem file 33 | outputData[0x10000 + len(certsData)] = 0 34 | 35 | for i in range(0, len(appData)): 36 | outputData[0x30000 + i] = appData[i] 37 | 38 | 39 | outputFilename = "NINA_W102.bin" 40 | if (len(sys.argv) > 1): 41 | outputFilename = sys.argv[1] 42 | 43 | # write out 44 | with open(outputFilename,"w+b") as f: 45 | f.seek(0) 46 | f.write(outputData) 47 | -------------------------------------------------------------------------------- /data/phy.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/nina-fw/eca4789e11a7b89e578413f59c9d15fe6b51c6f5/data/phy.bin -------------------------------------------------------------------------------- /main/CommandHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Arduino NINA firmware. 3 | Copyright (c) 2018 Arduino SA. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef COMMAND_HANDLER_H 21 | #define COMMAND_HANDLER_H 22 | 23 | #include 24 | 25 | class CommandHandlerClass { 26 | public: 27 | CommandHandlerClass(); 28 | 29 | void begin(); 30 | int handle(const uint8_t command[], uint8_t response[]); 31 | 32 | private: 33 | static void gpio0Updater(void*); 34 | void updateGpio0Pin(); 35 | 36 | static void onWiFiReceive(); 37 | void handleWiFiReceive(); 38 | 39 | static void onWiFiDisconnect(); 40 | void handleWiFiDisconnect(); 41 | 42 | private: 43 | SemaphoreHandle_t _updateGpio0PinSemaphore; 44 | }; 45 | 46 | extern CommandHandlerClass CommandHandler; 47 | 48 | extern "C" int downloadAndSaveFile(char * url, FILE * f, const char * cert_pem); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/nina-fw/eca4789e11a7b89e578413f59c9d15fe6b51c6f5/main/component.mk -------------------------------------------------------------------------------- /main/http_client.c: -------------------------------------------------------------------------------- 1 | // esp_http_client.c 2 | #include 3 | #include 4 | #include "esp_log.h" 5 | #include 6 | 7 | #include "esp_http_client.h" 8 | 9 | #define MAX_HTTP_RECV_BUFFER 128 10 | 11 | static const char* TAG = "HTTP_CLIENT"; 12 | 13 | int downloadAndSaveFile(char * url, FILE * f, const char * cert_pem) 14 | { 15 | char *buffer = (char*)malloc(MAX_HTTP_RECV_BUFFER); 16 | if (buffer == NULL) { 17 | return -1; 18 | } 19 | esp_http_client_config_t config = { 20 | .url = url, 21 | .cert_pem = cert_pem, 22 | .timeout_ms = 20000, 23 | }; 24 | 25 | esp_http_client_handle_t client = esp_http_client_init(&config); 26 | esp_err_t err; 27 | if ((err = esp_http_client_open(client, 0)) != ESP_OK) { 28 | ESP_LOGE(TAG, "esp_http_client_open failed: %d", err); 29 | free(buffer); 30 | return -1; 31 | } 32 | int content_length = esp_http_client_fetch_headers(client); 33 | int total_read_len = 0, read_len; 34 | while (total_read_len < content_length) { 35 | read_len = esp_http_client_read(client, buffer, MAX_HTTP_RECV_BUFFER); 36 | fwrite(buffer, sizeof(uint8_t), read_len, f); 37 | if (read_len <= 0) { 38 | break; 39 | } 40 | total_read_len += read_len; 41 | ESP_LOGV(TAG, "esp_http_client_read data received: %d, total %d", read_len, total_read_len); 42 | } 43 | ESP_LOGV(TAG, "connection closed, cleaning up, total %d bytes received", total_read_len); 44 | esp_http_client_close(client); 45 | esp_http_client_cleanup(client); 46 | free(buffer); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x6000 4 | phy_init, data, phy, 0xf000, 0x1000 5 | certs, data, 0x04, 0x10000, 0x20000 6 | factory, app, factory, 0x30000, 0x180000 7 | storage, data, spiffs, 0x1B0000,0x40000 8 | -------------------------------------------------------------------------------- /tools/sslcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while getopts "c:l:e" opt;do 4 | case $opt in 5 | c ) export CER_FILE="$OPTARG";; 6 | l ) export URL_LIST="$OPTARG";; 7 | e ) export SHOW_ERR=1;; 8 | * ) 9 | echo "Unknown parameter." 10 | exit 1 11 | ;; 12 | esac 13 | done 14 | 15 | if [ $# -eq 0 ] ; then 16 | echo "Usage: $(basename $0) [-c /path/to/certificate/file.pem] [-l path/to/url/list.txt]" 17 | echo 18 | echo " -c specify certificate file to test" 19 | echo " -l specify url list" 20 | echo " -e show curl errors in log" 21 | echo 22 | echo "Example:" 23 | echo " $(basename $0) -c roots.pem -l url_list.txt" 24 | exit 0 25 | fi 26 | 27 | export SHOW_ERR=${SHOW_ERR:-0} 28 | 29 | echo 30 | echo SHOW_ERR=$SHOW_ERR 31 | echo 32 | 33 | for i in $(cat $URL_LIST) 34 | do 35 | echo -n "$i " 36 | # -s: silent 37 | # -S: show error 38 | # -m: max time 39 | # --cacert: path to certificate pem file 40 | # --capath: local certificate path 41 | # --output: stdout output 42 | if [ "$SHOW_ERR" -eq 1 ] ; then 43 | m=$(curl "$i" -s -S -m 60 --cacert $CER_FILE --capath /dev/null --output /dev/null --stderr -) 44 | else 45 | curl "$i" -s -m 60 --cacert $CER_FILE --capath /dev/null --output /dev/null 46 | fi 47 | #curl --cacert roots.pem --trace-ascii log.log -K url_list.txt 48 | if [ $? -eq 0 ] ; then 49 | echo -e "\e[32m PASS \e[39m" 50 | else 51 | echo -n -e "\e[31m FAIL \e[39m" 52 | echo $m 53 | fi 54 | done 55 | --------------------------------------------------------------------------------