[FL-3690] Libraries cleanup; u2f crypto rework to use mbedtls (#3234)
* examples: plugins: utilize fal_embedded * libs: removed fnv1a_hash * furi: added FURI_PACKED; apps, libs: changed to use FURI_PACKED * lib: mbedtls: using custom config * lib: toolbox: removed md5, switched to mbedtls * targets: f18: link fix * lib: added mbedtls_cfg.h * apps: nfc: explicit dependency on libmbedtls * u2f: reworking to mbedtls * u2f: replaced sha256 & hmac with mbedtls * u2f: functional rework using mbedtls * libs: dropped micro-ecc * u2f: dropped old implementation * toolbox: removed sha256 impl * mcheck() for mbedtls * libs: removed libmisc; split into smaller libs * apps: debug: fixed display_test * apps: include cleanups * fbt: fixed VERSIONCOMSTR * furi: added FURI_CHECK_RETURN * lib: removed qrcode * cleanup * fbt: lint_py+format_py: fixed excessive command length * api: Removed bzero from f7 * api: Removed bzero from f18 * Bump API Symbols Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									a849d49c92
								
							
						
					
					
						commit
						890c9e87ce
					
				| @ -1 +1 @@ | |||||||
| --ignore-ccache -C gccarm --rules-config .pvsconfig -e lib/cmsis_core -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/micro-ecc -e lib/microtar -e lib/mlib -e lib/qrcode -e lib/stm32wb_cmsis -e lib/stm32wb_copro -e lib/stm32wb_hal -e lib/u8g2 -e lib/nanopb -e */arm-none-eabi/* | --ignore-ccache -C gccarm --rules-config .pvsconfig -e lib/cmsis_core -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/microtar -e lib/mlib -e lib/stm32wb_cmsis -e lib/stm32wb_copro -e lib/stm32wb_hal -e lib/u8g2 -e lib/nanopb -e */arm-none-eabi/* | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								SConstruct
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								SConstruct
									
									
									
									
									
								
							| @ -288,13 +288,17 @@ distenv.PhonyTarget( | |||||||
|     LINT_SOURCES=[n.srcnode() for n in firmware_env["LINT_SOURCES"]], |     LINT_SOURCES=[n.srcnode() for n in firmware_env["LINT_SOURCES"]], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| # PY_LINT_SOURCES contains recursively-built modules' SConscript files + application manifests | # PY_LINT_SOURCES contains recursively-built modules' SConscript files | ||||||
| # Here we add additional Python files residing in repo root | # Here we add additional Python files residing in repo root | ||||||
| firmware_env.Append( | firmware_env.Append( | ||||||
|     PY_LINT_SOURCES=[ |     PY_LINT_SOURCES=[ | ||||||
|         # Py code folders |         # Py code folders | ||||||
|         "site_scons", |         "site_scons", | ||||||
|         "scripts", |         "scripts", | ||||||
|  |         "applications", | ||||||
|  |         "applications_user", | ||||||
|  |         "assets", | ||||||
|  |         "targets", | ||||||
|         # Extra files |         # Extra files | ||||||
|         "SConstruct", |         "SConstruct", | ||||||
|         "firmware.scons", |         "firmware.scons", | ||||||
| @ -304,7 +308,10 @@ firmware_env.Append( | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| black_commandline = "@${PYTHON3} -m black ${PY_BLACK_ARGS} ${PY_LINT_SOURCES}" | black_commandline = "@${PYTHON3} -m black ${PY_BLACK_ARGS} ${PY_LINT_SOURCES}" | ||||||
| black_base_args = ["--include", '"\\.scons|\\.py|SConscript|SConstruct"'] | black_base_args = [ | ||||||
|  |     "--include", | ||||||
|  |     '"(\\.scons|\\.py|SConscript|SConstruct|\\.fam)$"', | ||||||
|  | ] | ||||||
| 
 | 
 | ||||||
| distenv.PhonyTarget( | distenv.PhonyTarget( | ||||||
|     "lint_py", |     "lint_py", | ||||||
|  | |||||||
| @ -13,12 +13,12 @@ struct ISO7816_Command_APDU { | |||||||
|     //body
 |     //body
 | ||||||
|     uint8_t Lc; |     uint8_t Lc; | ||||||
|     uint8_t Le; |     uint8_t Le; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| struct ISO7816_Response_APDU { | struct ISO7816_Response_APDU { | ||||||
|     uint8_t SW1; |     uint8_t SW1; | ||||||
|     uint8_t SW2; |     uint8_t SW2; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| void iso7816_answer_to_reset(uint8_t* atrBuffer, uint32_t* atrlen); | void iso7816_answer_to_reset(uint8_t* atrBuffer, uint32_t* atrlen); | ||||||
| void iso7816_read_command_apdu( | void iso7816_read_command_apdu( | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ App( | |||||||
|     apptype=FlipperAppType.DEBUG, |     apptype=FlipperAppType.DEBUG, | ||||||
|     entry_point="display_test_app", |     entry_point="display_test_app", | ||||||
|     requires=["gui"], |     requires=["gui"], | ||||||
|     fap_libs=["misc"], |     fap_libs=["u8g2"], | ||||||
|     stack_size=1 * 1024, |     stack_size=1 * 1024, | ||||||
|     order=120, |     order=120, | ||||||
|     fap_category="Debug", |     fap_category="Debug", | ||||||
|  | |||||||
| @ -1,27 +1,31 @@ | |||||||
| #include "flipper.pb.h" |  | ||||||
| #include <core/check.h> | #include <core/check.h> | ||||||
| #include <core/record.h> | #include <core/record.h> | ||||||
| #include "pb_decode.h" |  | ||||||
| #include <rpc/rpc.h> |  | ||||||
| #include "rpc/rpc_i.h" |  | ||||||
| #include "storage.pb.h" |  | ||||||
| #include "storage/filesystem_api_defines.h" |  | ||||||
| #include "storage/storage.h" |  | ||||||
| #include <furi.h> | #include <furi.h> | ||||||
| #include "../minunit.h" |  | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| #include <pb.h> |  | ||||||
| #include <pb_encode.h> |  | ||||||
| #include <m-list.h> |  | ||||||
| #include <lib/toolbox/md5_calc.h> |  | ||||||
| #include <lib/toolbox/path.h> |  | ||||||
| #include <cli/cli.h> |  | ||||||
| #include <loader/loader.h> |  | ||||||
| #include <protobuf_version.h> |  | ||||||
| 
 | 
 | ||||||
| #include <FreeRTOS.h> | #include <FreeRTOS.h> | ||||||
| #include <semphr.h> | #include <semphr.h> | ||||||
| 
 | 
 | ||||||
|  | #include <rpc/rpc.h> | ||||||
|  | #include <rpc/rpc_i.h> | ||||||
|  | #include <cli/cli.h> | ||||||
|  | #include <storage/storage.h> | ||||||
|  | #include <loader/loader.h> | ||||||
|  | #include <storage/filesystem_api_defines.h> | ||||||
|  | 
 | ||||||
|  | #include <lib/toolbox/md5_calc.h> | ||||||
|  | #include <lib/toolbox/path.h> | ||||||
|  | 
 | ||||||
|  | #include <m-list.h> | ||||||
|  | #include "../minunit.h" | ||||||
|  | 
 | ||||||
|  | #include <protobuf_version.h> | ||||||
|  | #include <pb.h> | ||||||
|  | #include <pb_encode.h> | ||||||
|  | #include <pb_decode.h> | ||||||
|  | #include <storage.pb.h> | ||||||
|  | #include <flipper.pb.h> | ||||||
|  | 
 | ||||||
| LIST_DEF(MsgList, PB_Main, M_POD_OPLIST) | LIST_DEF(MsgList, PB_Main, M_POD_OPLIST) | ||||||
| #define M_OPL_MsgList_t() LIST_OPLIST(MsgList) | #define M_OPL_MsgList_t() LIST_OPLIST(MsgList) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ App( | |||||||
|     entry_point="advanced_plugin1_ep", |     entry_point="advanced_plugin1_ep", | ||||||
|     requires=["example_advanced_plugins"], |     requires=["example_advanced_plugins"], | ||||||
|     sources=["plugin1.c"], |     sources=["plugin1.c"], | ||||||
|  |     fal_embedded=True, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| App( | App( | ||||||
| @ -22,4 +23,5 @@ App( | |||||||
|     entry_point="advanced_plugin2_ep", |     entry_point="advanced_plugin2_ep", | ||||||
|     requires=["example_advanced_plugins"], |     requires=["example_advanced_plugins"], | ||||||
|     sources=["plugin2.c"], |     sources=["plugin2.c"], | ||||||
|  |     fal_embedded=True, | ||||||
| ) | ) | ||||||
|  | |||||||
| @ -23,7 +23,10 @@ int32_t example_advanced_plugins_app(void* p) { | |||||||
|         PLUGIN_APP_ID, PLUGIN_API_VERSION, composite_api_resolver_get(resolver)); |         PLUGIN_APP_ID, PLUGIN_API_VERSION, composite_api_resolver_get(resolver)); | ||||||
| 
 | 
 | ||||||
|     do { |     do { | ||||||
|         if(plugin_manager_load_all(manager, APP_DATA_PATH("plugins")) != PluginManagerErrorNone) { |         // For built-in .fals (fal_embedded==True), use APP_ASSETS_PATH
 | ||||||
|  |         // Otherwise, use APP_DATA_PATH
 | ||||||
|  |         if(plugin_manager_load_all(manager, APP_ASSETS_PATH("plugins")) != | ||||||
|  |            PluginManagerErrorNone) { | ||||||
|             FURI_LOG_E(TAG, "Failed to load all libs"); |             FURI_LOG_E(TAG, "Failed to load all libs"); | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ App( | |||||||
|         "!plugins", |         "!plugins", | ||||||
|         "!nfc_cli.c", |         "!nfc_cli.c", | ||||||
|     ], |     ], | ||||||
|     fap_libs=["assets"], |     fap_libs=["assets", "mbedtls"], | ||||||
|     fap_icon="icon.png", |     fap_icon="icon.png", | ||||||
|     fap_category="NFC", |     fap_category="NFC", | ||||||
| ) | ) | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ App( | |||||||
|     icon="A_U2F_14", |     icon="A_U2F_14", | ||||||
|     order=80, |     order=80, | ||||||
|     resources="resources", |     resources="resources", | ||||||
|     fap_libs=["assets"], |     fap_libs=["assets", "mbedtls"], | ||||||
|     fap_category="USB", |     fap_category="USB", | ||||||
|     fap_icon="icon.png", |     fap_icon="icon.png", | ||||||
| ) | ) | ||||||
|  | |||||||
| @ -1,98 +0,0 @@ | |||||||
| /*
 |  | ||||||
|  * hmac.c - HMAC |  | ||||||
|  * |  | ||||||
|  * Copyright (C) 2017 Sergei Glushchenko |  | ||||||
|  * Author: Sergei Glushchenko <gl.sergei@gmail.com> |  | ||||||
|  * |  | ||||||
|  * This file is a part of U2F firmware for STM32 |  | ||||||
|  * |  | ||||||
|  * This program is free software: you can redistribute it and/or modify it |  | ||||||
|  * under the terms of the GNU General Public License as published by |  | ||||||
|  * the Free Software Foundation, either version 3 of the License, or |  | ||||||
|  * (at your option) any later version. |  | ||||||
|  * |  | ||||||
|  * This program is distributed in the hope that it will be useful, but |  | ||||||
|  * WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU |  | ||||||
|  * General Public License for more details. |  | ||||||
|  * |  | ||||||
|  * You should have received a copy of the GNU General Public License |  | ||||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 |  | ||||||
|  * |  | ||||||
|  * As additional permission under GNU GPL version 3 section 7, you may |  | ||||||
|  * distribute non-source form of the Program without the copy of the |  | ||||||
|  * GNU GPL normally required by section 4, provided you inform the |  | ||||||
|  * recipients of GNU GPL by a written offer. |  | ||||||
|  * |  | ||||||
|  */ |  | ||||||
| #include <stdint.h> |  | ||||||
| 
 |  | ||||||
| #include "sha256.h" |  | ||||||
| #include "hmac_sha256.h" |  | ||||||
| 
 |  | ||||||
| static void _hmac_sha256_init(const hmac_context* ctx) { |  | ||||||
|     hmac_sha256_context* context = (hmac_sha256_context*)ctx; |  | ||||||
|     sha256_start(&context->sha_ctx); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void |  | ||||||
|     _hmac_sha256_update(const hmac_context* ctx, const uint8_t* message, unsigned message_size) { |  | ||||||
|     hmac_sha256_context* context = (hmac_sha256_context*)ctx; |  | ||||||
|     sha256_update(&context->sha_ctx, message, message_size); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void _hmac_sha256_finish(const hmac_context* ctx, uint8_t* hash_result) { |  | ||||||
|     hmac_sha256_context* context = (hmac_sha256_context*)ctx; |  | ||||||
|     sha256_finish(&context->sha_ctx, hash_result); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /* Compute an HMAC using K as a key (as in RFC 6979). Note that K is always
 |  | ||||||
|    the same size as the hash result size. */ |  | ||||||
| static void hmac_init(const hmac_context* ctx, const uint8_t* K) { |  | ||||||
|     uint8_t* pad = ctx->tmp + 2 * ctx->result_size; |  | ||||||
|     unsigned i; |  | ||||||
|     for(i = 0; i < ctx->result_size; ++i) pad[i] = K[i] ^ 0x36; |  | ||||||
|     for(; i < ctx->block_size; ++i) pad[i] = 0x36; |  | ||||||
| 
 |  | ||||||
|     ctx->init_hash(ctx); |  | ||||||
|     ctx->update_hash(ctx, pad, ctx->block_size); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void hmac_update(const hmac_context* ctx, const uint8_t* message, unsigned message_size) { |  | ||||||
|     ctx->update_hash(ctx, message, message_size); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void hmac_finish(const hmac_context* ctx, const uint8_t* K, uint8_t* result) { |  | ||||||
|     uint8_t* pad = ctx->tmp + 2 * ctx->result_size; |  | ||||||
|     unsigned i; |  | ||||||
|     for(i = 0; i < ctx->result_size; ++i) pad[i] = K[i] ^ 0x5c; |  | ||||||
|     for(; i < ctx->block_size; ++i) pad[i] = 0x5c; |  | ||||||
| 
 |  | ||||||
|     ctx->finish_hash(ctx, result); |  | ||||||
| 
 |  | ||||||
|     ctx->init_hash(ctx); |  | ||||||
|     ctx->update_hash(ctx, pad, ctx->block_size); |  | ||||||
|     ctx->update_hash(ctx, result, ctx->result_size); |  | ||||||
|     ctx->finish_hash(ctx, result); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void hmac_sha256_init(hmac_sha256_context* ctx, const uint8_t* K) { |  | ||||||
|     ctx->hmac_ctx.init_hash = _hmac_sha256_init; |  | ||||||
|     ctx->hmac_ctx.update_hash = _hmac_sha256_update; |  | ||||||
|     ctx->hmac_ctx.finish_hash = _hmac_sha256_finish; |  | ||||||
|     ctx->hmac_ctx.block_size = 64; |  | ||||||
|     ctx->hmac_ctx.result_size = 32; |  | ||||||
|     ctx->hmac_ctx.tmp = ctx->tmp; |  | ||||||
|     hmac_init(&ctx->hmac_ctx, K); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void hmac_sha256_update( |  | ||||||
|     const hmac_sha256_context* ctx, |  | ||||||
|     const uint8_t* message, |  | ||||||
|     unsigned message_size) { |  | ||||||
|     hmac_update(&ctx->hmac_ctx, message, message_size); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void hmac_sha256_finish(const hmac_sha256_context* ctx, const uint8_t* K, uint8_t* hash_result) { |  | ||||||
|     hmac_finish(&ctx->hmac_ctx, K, hash_result); |  | ||||||
| } |  | ||||||
| @ -1,38 +0,0 @@ | |||||||
| #pragma once |  | ||||||
| 
 |  | ||||||
| #include "sha256.h" |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| typedef struct hmac_context { |  | ||||||
|     void (*init_hash)(const struct hmac_context* context); |  | ||||||
|     void (*update_hash)( |  | ||||||
|         const struct hmac_context* context, |  | ||||||
|         const uint8_t* message, |  | ||||||
|         unsigned message_size); |  | ||||||
|     void (*finish_hash)(const struct hmac_context* context, uint8_t* hash_result); |  | ||||||
|     unsigned block_size; /* Hash function block size in bytes, eg 64 for SHA-256. */ |  | ||||||
|     unsigned result_size; /* Hash function result size in bytes, eg 32 for SHA-256. */ |  | ||||||
|     uint8_t* tmp; /* Must point to a buffer of at least (2 * result_size + block_size) bytes. */ |  | ||||||
| } hmac_context; |  | ||||||
| 
 |  | ||||||
| typedef struct hmac_sha256_context { |  | ||||||
|     hmac_context hmac_ctx; |  | ||||||
|     sha256_context sha_ctx; |  | ||||||
|     uint8_t tmp[32 * 2 + 64]; |  | ||||||
| } hmac_sha256_context; |  | ||||||
| 
 |  | ||||||
| void hmac_sha256_init(hmac_sha256_context* ctx, const uint8_t* K); |  | ||||||
| 
 |  | ||||||
| void hmac_sha256_update( |  | ||||||
|     const hmac_sha256_context* ctx, |  | ||||||
|     const uint8_t* message, |  | ||||||
|     unsigned message_size); |  | ||||||
| 
 |  | ||||||
| void hmac_sha256_finish(const hmac_sha256_context* ctx, const uint8_t* K, uint8_t* hash_result); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| @ -1,18 +1,22 @@ | |||||||
| #include <furi.h> |  | ||||||
| #include "u2f.h" | #include "u2f.h" | ||||||
| #include "u2f_hid.h" | #include "u2f_hid.h" | ||||||
| #include "u2f_data.h" | #include "u2f_data.h" | ||||||
|  | 
 | ||||||
|  | #include <furi.h> | ||||||
| #include <furi_hal.h> | #include <furi_hal.h> | ||||||
| #include <furi_hal_random.h> | #include <furi_hal_random.h> | ||||||
| #include <littlefs/lfs_util.h> // for lfs_tobe32 | #include <littlefs/lfs_util.h> // for lfs_tobe32 | ||||||
| 
 | 
 | ||||||
| #include "toolbox/sha256.h" | #include <mbedtls/sha256.h> | ||||||
| #include "hmac_sha256.h" | #include <mbedtls/md.h> | ||||||
| #include "micro-ecc/uECC.h" | #include <mbedtls/ecdsa.h> | ||||||
|  | #include <mbedtls/error.h> | ||||||
| 
 | 
 | ||||||
| #define TAG "U2f" | #define TAG "U2f" | ||||||
| #define WORKER_TAG TAG "Worker" | #define WORKER_TAG TAG "Worker" | ||||||
| 
 | 
 | ||||||
|  | #define MCHECK(expr) furi_check((expr) == 0) | ||||||
|  | 
 | ||||||
| #define U2F_CMD_REGISTER 0x01 | #define U2F_CMD_REGISTER 0x01 | ||||||
| #define U2F_CMD_AUTHENTICATE 0x02 | #define U2F_CMD_AUTHENTICATE 0x02 | ||||||
| #define U2F_CMD_VERSION 0x03 | #define U2F_CMD_VERSION 0x03 | ||||||
| @ -25,16 +29,26 @@ typedef enum { | |||||||
|         0x08, // "dont-enforce-user-presence-and-sign" - send auth response even if user is missing
 |         0x08, // "dont-enforce-user-presence-and-sign" - send auth response even if user is missing
 | ||||||
| } U2fAuthMode; | } U2fAuthMode; | ||||||
| 
 | 
 | ||||||
|  | #define U2F_HASH_SIZE 32 | ||||||
|  | #define U2F_NONCE_SIZE 32 | ||||||
|  | #define U2F_CHALLENGE_SIZE 32 | ||||||
|  | #define U2F_APP_ID_SIZE 32 | ||||||
|  | 
 | ||||||
|  | #define U2F_EC_KEY_SIZE 32 | ||||||
|  | #define U2F_EC_BIGNUM_SIZE 32 | ||||||
|  | #define U2F_EC_POINT_SIZE 65 | ||||||
|  | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t format; |     uint8_t format; | ||||||
|     uint8_t xy[64]; |     uint8_t xy[64]; | ||||||
| } __attribute__((packed)) U2fPubKey; | } FURI_PACKED U2fPubKey; | ||||||
|  | _Static_assert(sizeof(U2fPubKey) == U2F_EC_POINT_SIZE, "U2fPubKey size mismatch"); | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t len; |     uint8_t len; | ||||||
|     uint8_t hash[32]; |     uint8_t hash[U2F_HASH_SIZE]; | ||||||
|     uint8_t nonce[32]; |     uint8_t nonce[U2F_NONCE_SIZE]; | ||||||
| } __attribute__((packed)) U2fKeyHandle; | } FURI_PACKED U2fKeyHandle; | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t cla; |     uint8_t cla; | ||||||
| @ -42,16 +56,16 @@ typedef struct { | |||||||
|     uint8_t p1; |     uint8_t p1; | ||||||
|     uint8_t p2; |     uint8_t p2; | ||||||
|     uint8_t len[3]; |     uint8_t len[3]; | ||||||
|     uint8_t challenge[32]; |     uint8_t challenge[U2F_CHALLENGE_SIZE]; | ||||||
|     uint8_t app_id[32]; |     uint8_t app_id[U2F_APP_ID_SIZE]; | ||||||
| } __attribute__((packed)) U2fRegisterReq; | } FURI_PACKED U2fRegisterReq; | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t reserved; |     uint8_t reserved; | ||||||
|     U2fPubKey pub_key; |     U2fPubKey pub_key; | ||||||
|     U2fKeyHandle key_handle; |     U2fKeyHandle key_handle; | ||||||
|     uint8_t cert[]; |     uint8_t cert[]; | ||||||
| } __attribute__((packed)) U2fRegisterResp; | } FURI_PACKED U2fRegisterResp; | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t cla; |     uint8_t cla; | ||||||
| @ -59,16 +73,16 @@ typedef struct { | |||||||
|     uint8_t p1; |     uint8_t p1; | ||||||
|     uint8_t p2; |     uint8_t p2; | ||||||
|     uint8_t len[3]; |     uint8_t len[3]; | ||||||
|     uint8_t challenge[32]; |     uint8_t challenge[U2F_CHALLENGE_SIZE]; | ||||||
|     uint8_t app_id[32]; |     uint8_t app_id[U2F_APP_ID_SIZE]; | ||||||
|     U2fKeyHandle key_handle; |     U2fKeyHandle key_handle; | ||||||
| } __attribute__((packed)) U2fAuthReq; | } FURI_PACKED U2fAuthReq; | ||||||
| 
 | 
 | ||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t user_present; |     uint8_t user_present; | ||||||
|     uint32_t counter; |     uint32_t counter; | ||||||
|     uint8_t signature[]; |     uint8_t signature[]; | ||||||
| } __attribute__((packed)) U2fAuthResp; | } FURI_PACKED U2fAuthResp; | ||||||
| 
 | 
 | ||||||
| static const uint8_t ver_str[] = {"U2F_V2"}; | static const uint8_t ver_str[] = {"U2F_V2"}; | ||||||
| 
 | 
 | ||||||
| @ -78,19 +92,20 @@ static const uint8_t state_user_missing[] = {0x69, 0x85}; | |||||||
| static const uint8_t state_wrong_data[] = {0x6A, 0x80}; | static const uint8_t state_wrong_data[] = {0x6A, 0x80}; | ||||||
| 
 | 
 | ||||||
| struct U2fData { | struct U2fData { | ||||||
|     uint8_t device_key[32]; |     uint8_t device_key[U2F_EC_KEY_SIZE]; | ||||||
|     uint8_t cert_key[32]; |     uint8_t cert_key[U2F_EC_KEY_SIZE]; | ||||||
|     uint32_t counter; |     uint32_t counter; | ||||||
|     const struct uECC_Curve_t* p_curve; |  | ||||||
|     bool ready; |     bool ready; | ||||||
|     bool user_present; |     bool user_present; | ||||||
|     U2fEvtCallback callback; |     U2fEvtCallback callback; | ||||||
|     void* context; |     void* context; | ||||||
|  |     mbedtls_ecp_group group; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static int u2f_uecc_random(uint8_t* dest, unsigned size) { | static int u2f_uecc_random_cb(void* context, uint8_t* dest, unsigned size) { | ||||||
|  |     UNUSED(context); | ||||||
|     furi_hal_random_fill_buf(dest, size); |     furi_hal_random_fill_buf(dest, size); | ||||||
|     return 1; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| U2fData* u2f_alloc() { | U2fData* u2f_alloc() { | ||||||
| @ -99,6 +114,7 @@ U2fData* u2f_alloc() { | |||||||
| 
 | 
 | ||||||
| void u2f_free(U2fData* U2F) { | void u2f_free(U2fData* U2F) { | ||||||
|     furi_assert(U2F); |     furi_assert(U2F); | ||||||
|  |     mbedtls_ecp_group_free(&U2F->group); | ||||||
|     free(U2F); |     free(U2F); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -129,8 +145,8 @@ bool u2f_init(U2fData* U2F) { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     U2F->p_curve = uECC_secp256r1(); |     mbedtls_ecp_group_init(&U2F->group); | ||||||
|     uECC_set_rng(u2f_uecc_random); |     mbedtls_ecp_group_load(&U2F->group, MBEDTLS_ECP_DP_SECP256R1); | ||||||
| 
 | 
 | ||||||
|     U2F->ready = true; |     U2F->ready = true; | ||||||
|     return true; |     return true; | ||||||
| @ -171,21 +187,63 @@ static uint8_t u2f_der_encode_signature(uint8_t* der, uint8_t* sig) { | |||||||
|     der[0] = 0x30; |     der[0] = 0x30; | ||||||
| 
 | 
 | ||||||
|     uint8_t len = 2; |     uint8_t len = 2; | ||||||
|     len += u2f_der_encode_int(der + len, sig, 32); |     len += u2f_der_encode_int(der + len, sig, U2F_HASH_SIZE); | ||||||
|     len += u2f_der_encode_int(der + len, sig + 32, 32); |     len += u2f_der_encode_int(der + len, sig + U2F_HASH_SIZE, U2F_HASH_SIZE); | ||||||
| 
 | 
 | ||||||
|     der[1] = len - 2; |     der[1] = len - 2; | ||||||
|     return len; |     return len; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static void | ||||||
|  |     u2f_ecc_sign(mbedtls_ecp_group* grp, const uint8_t* key, uint8_t* hash, uint8_t* signature) { | ||||||
|  |     mbedtls_mpi r, s, d; | ||||||
|  | 
 | ||||||
|  |     mbedtls_mpi_init(&r); | ||||||
|  |     mbedtls_mpi_init(&s); | ||||||
|  |     mbedtls_mpi_init(&d); | ||||||
|  | 
 | ||||||
|  |     MCHECK(mbedtls_mpi_read_binary(&d, key, U2F_EC_KEY_SIZE)); | ||||||
|  |     MCHECK(mbedtls_ecdsa_sign(grp, &r, &s, &d, hash, U2F_HASH_SIZE, u2f_uecc_random_cb, NULL)); | ||||||
|  |     MCHECK(mbedtls_mpi_write_binary(&r, signature, U2F_EC_BIGNUM_SIZE)); | ||||||
|  |     MCHECK(mbedtls_mpi_write_binary(&s, signature + U2F_EC_BIGNUM_SIZE, U2F_EC_BIGNUM_SIZE)); | ||||||
|  | 
 | ||||||
|  |     mbedtls_mpi_free(&r); | ||||||
|  |     mbedtls_mpi_free(&s); | ||||||
|  |     mbedtls_mpi_free(&d); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void u2f_ecc_compute_public_key( | ||||||
|  |     mbedtls_ecp_group* grp, | ||||||
|  |     const uint8_t* private_key, | ||||||
|  |     U2fPubKey* public_key) { | ||||||
|  |     mbedtls_ecp_point Q; | ||||||
|  |     mbedtls_mpi d; | ||||||
|  |     size_t olen; | ||||||
|  | 
 | ||||||
|  |     mbedtls_ecp_point_init(&Q); | ||||||
|  |     mbedtls_mpi_init(&d); | ||||||
|  | 
 | ||||||
|  |     MCHECK(mbedtls_mpi_read_binary(&d, private_key, U2F_EC_KEY_SIZE)); | ||||||
|  |     MCHECK(mbedtls_ecp_mul(grp, &Q, &d, &grp->G, u2f_uecc_random_cb, NULL)); | ||||||
|  |     MCHECK(mbedtls_ecp_check_privkey(grp, &d)); | ||||||
|  | 
 | ||||||
|  |     MCHECK(mbedtls_ecp_point_write_binary( | ||||||
|  |         grp, &Q, MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, (unsigned char*)public_key, sizeof(U2fPubKey))); | ||||||
|  | 
 | ||||||
|  |     mbedtls_ecp_point_free(&Q); | ||||||
|  |     mbedtls_mpi_free(&d); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ///////////////////////////////////////////
 | ||||||
|  | 
 | ||||||
| static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) { | static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) { | ||||||
|     U2fRegisterReq* req = (U2fRegisterReq*)buf; |     U2fRegisterReq* req = (U2fRegisterReq*)buf; | ||||||
|     U2fRegisterResp* resp = (U2fRegisterResp*)buf; |     U2fRegisterResp* resp = (U2fRegisterResp*)buf; | ||||||
|     U2fKeyHandle handle; |     U2fKeyHandle handle; | ||||||
|     uint8_t private[32]; |     uint8_t private[U2F_EC_KEY_SIZE]; | ||||||
|     U2fPubKey pub_key; |     U2fPubKey pub_key; | ||||||
|     uint8_t hash[32]; |     uint8_t hash[U2F_HASH_SIZE]; | ||||||
|     uint8_t signature[64]; |     uint8_t signature[U2F_EC_BIGNUM_SIZE * 2]; | ||||||
| 
 | 
 | ||||||
|     if(u2f_data_check(false) == false) { |     if(u2f_data_check(false) == false) { | ||||||
|         U2F->ready = false; |         U2F->ready = false; | ||||||
| @ -201,40 +259,54 @@ static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) { | |||||||
|     } |     } | ||||||
|     U2F->user_present = false; |     U2F->user_present = false; | ||||||
| 
 | 
 | ||||||
|     hmac_sha256_context hmac_ctx; |     handle.len = U2F_HASH_SIZE * 2; | ||||||
|     sha256_context sha_ctx; |  | ||||||
| 
 | 
 | ||||||
|     handle.len = 32 * 2; |  | ||||||
|     // Generate random nonce
 |     // Generate random nonce
 | ||||||
|     furi_hal_random_fill_buf(handle.nonce, 32); |     furi_hal_random_fill_buf(handle.nonce, 32); | ||||||
| 
 | 
 | ||||||
|     // Generate private key
 |     { | ||||||
|     hmac_sha256_init(&hmac_ctx, U2F->device_key); |         mbedtls_md_context_t hmac_ctx; | ||||||
|     hmac_sha256_update(&hmac_ctx, req->app_id, 32); |         mbedtls_md_init(&hmac_ctx); | ||||||
|     hmac_sha256_update(&hmac_ctx, handle.nonce, 32); |         MCHECK(mbedtls_md_setup(&hmac_ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1)); | ||||||
|     hmac_sha256_finish(&hmac_ctx, U2F->device_key, private); |         MCHECK(mbedtls_md_hmac_starts(&hmac_ctx, U2F->device_key, sizeof(U2F->device_key))); | ||||||
| 
 | 
 | ||||||
|     // Generate private key handle
 |         // Generate private key
 | ||||||
|     hmac_sha256_init(&hmac_ctx, U2F->device_key); |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, req->app_id, sizeof(req->app_id))); | ||||||
|     hmac_sha256_update(&hmac_ctx, private, 32); |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, handle.nonce, sizeof(handle.nonce))); | ||||||
|     hmac_sha256_update(&hmac_ctx, req->app_id, 32); |         MCHECK(mbedtls_md_hmac_finish(&hmac_ctx, private)); | ||||||
|     hmac_sha256_finish(&hmac_ctx, U2F->device_key, handle.hash); | 
 | ||||||
|  |         MCHECK(mbedtls_md_hmac_reset(&hmac_ctx)); | ||||||
|  | 
 | ||||||
|  |         // Generate private key handle
 | ||||||
|  |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, private, sizeof(private))); | ||||||
|  |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, req->app_id, sizeof(req->app_id))); | ||||||
|  |         MCHECK(mbedtls_md_hmac_finish(&hmac_ctx, handle.hash)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     // Generate public key
 |     // Generate public key
 | ||||||
|     pub_key.format = 0x04; // Uncompressed point
 |     u2f_ecc_compute_public_key(&U2F->group, private, &pub_key); | ||||||
|     uECC_compute_public_key(private, pub_key.xy, U2F->p_curve); |  | ||||||
| 
 | 
 | ||||||
|     // Generate signature
 |     // Generate signature
 | ||||||
|     uint8_t reserved_byte = 0; |     { | ||||||
|     sha256_start(&sha_ctx); |         uint8_t reserved_byte = 0; | ||||||
|     sha256_update(&sha_ctx, &reserved_byte, 1); |  | ||||||
|     sha256_update(&sha_ctx, req->app_id, 32); |  | ||||||
|     sha256_update(&sha_ctx, req->challenge, 32); |  | ||||||
|     sha256_update(&sha_ctx, handle.hash, handle.len); |  | ||||||
|     sha256_update(&sha_ctx, (uint8_t*)&pub_key, 65); |  | ||||||
|     sha256_finish(&sha_ctx, hash); |  | ||||||
| 
 | 
 | ||||||
|     uECC_sign(U2F->cert_key, hash, 32, signature, U2F->p_curve); |         mbedtls_sha256_context sha_ctx; | ||||||
|  | 
 | ||||||
|  |         mbedtls_sha256_init(&sha_ctx); | ||||||
|  |         mbedtls_sha256_starts(&sha_ctx, 0); | ||||||
|  | 
 | ||||||
|  |         mbedtls_sha256_update(&sha_ctx, &reserved_byte, 1); | ||||||
|  |         mbedtls_sha256_update(&sha_ctx, req->app_id, sizeof(req->app_id)); | ||||||
|  |         mbedtls_sha256_update(&sha_ctx, req->challenge, sizeof(req->challenge)); | ||||||
|  |         mbedtls_sha256_update(&sha_ctx, handle.hash, handle.len); | ||||||
|  |         mbedtls_sha256_update(&sha_ctx, (uint8_t*)&pub_key, sizeof(U2fPubKey)); | ||||||
|  | 
 | ||||||
|  |         mbedtls_sha256_finish(&sha_ctx, hash); | ||||||
|  |         mbedtls_sha256_free(&sha_ctx); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Sign hash
 | ||||||
|  |     u2f_ecc_sign(&U2F->group, U2F->cert_key, hash, signature); | ||||||
| 
 | 
 | ||||||
|     // Encode response message
 |     // Encode response message
 | ||||||
|     resp->reserved = 0x05; |     resp->reserved = 0x05; | ||||||
| @ -250,13 +322,11 @@ static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) { | |||||||
| static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { | static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { | ||||||
|     U2fAuthReq* req = (U2fAuthReq*)buf; |     U2fAuthReq* req = (U2fAuthReq*)buf; | ||||||
|     U2fAuthResp* resp = (U2fAuthResp*)buf; |     U2fAuthResp* resp = (U2fAuthResp*)buf; | ||||||
|     uint8_t priv_key[32]; |     uint8_t priv_key[U2F_EC_KEY_SIZE]; | ||||||
|     uint8_t mac_control[32]; |     uint8_t mac_control[32]; | ||||||
|     hmac_sha256_context hmac_ctx; |  | ||||||
|     sha256_context sha_ctx; |  | ||||||
|     uint8_t flags = 0; |     uint8_t flags = 0; | ||||||
|     uint8_t hash[32]; |     uint8_t hash[U2F_HASH_SIZE]; | ||||||
|     uint8_t signature[64]; |     uint8_t signature[U2F_HASH_SIZE * 2]; | ||||||
|     uint32_t be_u2f_counter; |     uint32_t be_u2f_counter; | ||||||
| 
 | 
 | ||||||
|     if(u2f_data_check(false) == false) { |     if(u2f_data_check(false) == false) { | ||||||
| @ -281,26 +351,42 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { | |||||||
|     be_u2f_counter = lfs_tobe32(U2F->counter + 1); |     be_u2f_counter = lfs_tobe32(U2F->counter + 1); | ||||||
| 
 | 
 | ||||||
|     // Generate hash
 |     // Generate hash
 | ||||||
|     sha256_start(&sha_ctx); |     { | ||||||
|     sha256_update(&sha_ctx, req->app_id, 32); |         mbedtls_sha256_context sha_ctx; | ||||||
|     sha256_update(&sha_ctx, &flags, 1); |  | ||||||
|     sha256_update(&sha_ctx, (uint8_t*)&(be_u2f_counter), 4); |  | ||||||
|     sha256_update(&sha_ctx, req->challenge, 32); |  | ||||||
|     sha256_finish(&sha_ctx, hash); |  | ||||||
| 
 | 
 | ||||||
|     // Recover private key
 |         mbedtls_sha256_init(&sha_ctx); | ||||||
|     hmac_sha256_init(&hmac_ctx, U2F->device_key); |         mbedtls_sha256_starts(&sha_ctx, 0); | ||||||
|     hmac_sha256_update(&hmac_ctx, req->app_id, 32); |  | ||||||
|     hmac_sha256_update(&hmac_ctx, req->key_handle.nonce, 32); |  | ||||||
|     hmac_sha256_finish(&hmac_ctx, U2F->device_key, priv_key); |  | ||||||
| 
 | 
 | ||||||
|     // Generate and verify private key handle
 |         mbedtls_sha256_update(&sha_ctx, req->app_id, sizeof(req->app_id)); | ||||||
|     hmac_sha256_init(&hmac_ctx, U2F->device_key); |         mbedtls_sha256_update(&sha_ctx, &flags, 1); | ||||||
|     hmac_sha256_update(&hmac_ctx, priv_key, 32); |         mbedtls_sha256_update(&sha_ctx, (uint8_t*)&(be_u2f_counter), sizeof(be_u2f_counter)); | ||||||
|     hmac_sha256_update(&hmac_ctx, req->app_id, 32); |         mbedtls_sha256_update(&sha_ctx, req->challenge, sizeof(req->challenge)); | ||||||
|     hmac_sha256_finish(&hmac_ctx, U2F->device_key, mac_control); |  | ||||||
| 
 | 
 | ||||||
|     if(memcmp(req->key_handle.hash, mac_control, 32) != 0) { |         mbedtls_sha256_finish(&sha_ctx, hash); | ||||||
|  |         mbedtls_sha256_free(&sha_ctx); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     { | ||||||
|  |         mbedtls_md_context_t hmac_ctx; | ||||||
|  |         mbedtls_md_init(&hmac_ctx); | ||||||
|  |         MCHECK(mbedtls_md_setup(&hmac_ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1)); | ||||||
|  |         MCHECK(mbedtls_md_hmac_starts(&hmac_ctx, U2F->device_key, sizeof(U2F->device_key))); | ||||||
|  | 
 | ||||||
|  |         // Recover private key
 | ||||||
|  |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, req->app_id, sizeof(req->app_id))); | ||||||
|  |         MCHECK(mbedtls_md_hmac_update( | ||||||
|  |             &hmac_ctx, req->key_handle.nonce, sizeof(req->key_handle.nonce))); | ||||||
|  |         MCHECK(mbedtls_md_hmac_finish(&hmac_ctx, priv_key)); | ||||||
|  | 
 | ||||||
|  |         MCHECK(mbedtls_md_hmac_reset(&hmac_ctx)); | ||||||
|  | 
 | ||||||
|  |         // Generate and verify private key handle
 | ||||||
|  |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, priv_key, sizeof(priv_key))); | ||||||
|  |         MCHECK(mbedtls_md_hmac_update(&hmac_ctx, req->app_id, sizeof(req->app_id))); | ||||||
|  |         MCHECK(mbedtls_md_hmac_finish(&hmac_ctx, mac_control)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if(memcmp(req->key_handle.hash, mac_control, sizeof(mac_control)) != 0) { | ||||||
|         FURI_LOG_W(TAG, "Wrong handle!"); |         FURI_LOG_W(TAG, "Wrong handle!"); | ||||||
|         memcpy(&buf[0], state_wrong_data, 2); |         memcpy(&buf[0], state_wrong_data, 2); | ||||||
|         return 2; |         return 2; | ||||||
| @ -311,7 +397,8 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { | |||||||
|         return 2; |         return 2; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     uECC_sign(priv_key, hash, 32, signature, U2F->p_curve); |     // Sign hash
 | ||||||
|  |     u2f_ecc_sign(&U2F->group, priv_key, hash, signature); | ||||||
| 
 | 
 | ||||||
|     resp->user_present = flags; |     resp->user_present = flags; | ||||||
|     resp->counter = be_u2f_counter; |     resp->counter = be_u2f_counter; | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ typedef struct { | |||||||
|     uint32_t counter; |     uint32_t counter; | ||||||
|     uint8_t random_salt[24]; |     uint8_t random_salt[24]; | ||||||
|     uint32_t control; |     uint32_t control; | ||||||
| } __attribute__((packed)) U2fCounterData; | } FURI_PACKED U2fCounterData; | ||||||
| 
 | 
 | ||||||
| bool u2f_data_check(bool cert_only) { | bool u2f_data_check(bool cert_only) { | ||||||
|     bool state = false; |     bool state = false; | ||||||
|  | |||||||
| @ -1,9 +1,10 @@ | |||||||
| #include "flipper.pb.h" |  | ||||||
| #include "rpc_i.h" | #include "rpc_i.h" | ||||||
| #include "gui.pb.h" |  | ||||||
| #include <gui/gui_i.h> | #include <gui/gui_i.h> | ||||||
| #include <assets_icons.h> | #include <assets_icons.h> | ||||||
| 
 | 
 | ||||||
|  | #include <flipper.pb.h> | ||||||
|  | #include <gui.pb.h> | ||||||
|  | 
 | ||||||
| #define TAG "RpcGui" | #define TAG "RpcGui" | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| #pragma once | #pragma once | ||||||
| #include "rpc.h" | #include "rpc.h" | ||||||
| #include "storage/filesystem_api_defines.h" | #include <storage/filesystem_api_defines.h> | ||||||
| #include <pb.h> | #include <pb.h> | ||||||
| #include <pb_decode.h> | #include <pb_decode.h> | ||||||
| #include <pb_encode.h> | #include <pb_encode.h> | ||||||
|  | |||||||
| @ -1,18 +1,18 @@ | |||||||
| #include "flipper.pb.h" |  | ||||||
| #include <core/common_defines.h> | #include <core/common_defines.h> | ||||||
| #include <core/memmgr.h> | #include <core/memmgr.h> | ||||||
| #include <core/record.h> | #include <core/record.h> | ||||||
| #include "pb_decode.h" | #include <rpc/rpc.h> | ||||||
| #include "rpc/rpc.h" | #include <rpc/rpc_i.h> | ||||||
| #include "rpc_i.h" | #include <storage/filesystem_api_defines.h> | ||||||
| #include "storage.pb.h" | #include <storage/storage.h> | ||||||
| #include "storage/filesystem_api_defines.h" |  | ||||||
| #include "storage/storage.h" |  | ||||||
| #include <stdint.h> |  | ||||||
| #include <lib/toolbox/md5_calc.h> | #include <lib/toolbox/md5_calc.h> | ||||||
| #include <lib/toolbox/path.h> | #include <lib/toolbox/path.h> | ||||||
| #include <update_util/lfs_backup.h> | #include <update_util/lfs_backup.h> | ||||||
| 
 | 
 | ||||||
|  | #include <pb_decode.h> | ||||||
|  | #include <storage.pb.h> | ||||||
|  | #include <flipper.pb.h> | ||||||
|  | 
 | ||||||
| #define TAG "RpcStorage" | #define TAG "RpcStorage" | ||||||
| 
 | 
 | ||||||
| #define MAX_NAME_LENGTH 255 | #define MAX_NAME_LENGTH 255 | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| #include "storage_move_to_sd.h" | #include "storage_move_to_sd.h" | ||||||
|  | 
 | ||||||
| #include <core/common_defines.h> | #include <core/common_defines.h> | ||||||
| #include <core/log.h> | #include <core/log.h> | ||||||
| #include "loader/loader.h" | #include <loader/loader.h> | ||||||
| #include <stdint.h> |  | ||||||
| #include <toolbox/dir_walk.h> | #include <toolbox/dir_walk.h> | ||||||
| #include <toolbox/path.h> | #include <toolbox/path.h> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,6 +17,10 @@ extern "C" { | |||||||
| #define FURI_WEAK __attribute__((weak)) | #define FURI_WEAK __attribute__((weak)) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #ifndef FURI_PACKED | ||||||
|  | #define FURI_PACKED __attribute__((packed)) | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #ifndef FURI_IS_IRQ_MASKED | #ifndef FURI_IS_IRQ_MASKED | ||||||
| #define FURI_IS_IRQ_MASKED() (__get_PRIMASK() != 0U) | #define FURI_IS_IRQ_MASKED() (__get_PRIMASK() != 0U) | ||||||
| #endif | #endif | ||||||
| @ -47,6 +51,10 @@ void __furi_critical_exit(__FuriCriticalInfo info); | |||||||
| #define FURI_CRITICAL_EXIT() __furi_critical_exit(__furi_critical_info); | #define FURI_CRITICAL_EXIT() __furi_critical_exit(__furi_critical_info); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #ifndef FURI_CHECK_RETURN | ||||||
|  | #define FURI_CHECK_RETURN __attribute__((__warn_unused_result__)) | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -11,7 +11,6 @@ | |||||||
| - `fatfs`               - FatFS file system driver | - `fatfs`               - FatFS file system driver | ||||||
| - `flipper_application` - Flipper application library, used for FAPs | - `flipper_application` - Flipper application library, used for FAPs | ||||||
| - `flipper_format`      - Flipper File Format library | - `flipper_format`      - Flipper File Format library | ||||||
| - `fnv1a-hash`          - FNV-1a hash library |  | ||||||
| - `heatshrink`          - Heatshrink compression library | - `heatshrink`          - Heatshrink compression library | ||||||
| - `ibutton`             - ibutton library, used by iButton application | - `ibutton`             - ibutton library, used by iButton application | ||||||
| - `infrared`            - Infrared library, used by Infrared application | - `infrared`            - Infrared library, used by Infrared application | ||||||
| @ -19,7 +18,6 @@ | |||||||
| - `libusb_stm32`        - LibUSB for STM32 series MCU | - `libusb_stm32`        - LibUSB for STM32 series MCU | ||||||
| - `littlefs`            - LittleFS file system driver, used by internal storage | - `littlefs`            - LittleFS file system driver, used by internal storage | ||||||
| - `mbedtls`             - MbedTLS cryptography library | - `mbedtls`             - MbedTLS cryptography library | ||||||
| - `micro-ecc`           - MicroECC cryptography library |  | ||||||
| - `microtar`            - MicroTAR library | - `microtar`            - MicroTAR library | ||||||
| - `mlib`                - M-Lib C containers library | - `mlib`                - M-Lib C containers library | ||||||
| - `nanopb`              - NanoPB library, protobuf implementation for MCU | - `nanopb`              - NanoPB library, protobuf implementation for MCU | ||||||
| @ -28,11 +26,10 @@ | |||||||
| - `print`               - Tiny printf implementation | - `print`               - Tiny printf implementation | ||||||
| - `digital_signal`      - Digital Signal library used by NFC for software implemented protocols | - `digital_signal`      - Digital Signal library used by NFC for software implemented protocols | ||||||
| - `pulse_reader`        - Pulse Reader library used by NFC for software implemented protocols | - `pulse_reader`        - Pulse Reader library used by NFC for software implemented protocols | ||||||
| - `qrcode`              - QR-Code library |  | ||||||
| - `stm32wb_cmsis`       - STM32WB series CMSIS headers, extends CMSIS Core | - `stm32wb_cmsis`       - STM32WB series CMSIS headers, extends CMSIS Core | ||||||
| - `stm32wb_copro`       - STM32WB Copro library: contains WPAN and radio co-processor firmware | - `stm32wb_copro`       - STM32WB Copro library: contains WPAN and radio co-processor firmware | ||||||
| - `stm32wb_hal`         - STM32WB HAL library, extends STM32WB CMSIS and provides HAL | - `stm32wb_hal`         - STM32WB HAL library, extends STM32WB CMSIS and provides HAL | ||||||
| - `subghz`              - Subghz library, used by SubGhz application | - `subghz`              - Subghz library, used by SubGhz application | ||||||
| - `toolbox`             - Toolbox library, contains various things that is used by flipper firmware | - `toolbox`             - Toolbox library, contains various things that is used by Flipper firmware | ||||||
| - `u8g2`                - u8g2 graphics library, used by GUI subsystem | - `u8g2`                - u8g2 graphics library, used by GUI subsystem | ||||||
| - `update_util`         - update utilities library, used by updater | - `update_util`         - update utilities library, used by updater | ||||||
| @ -1,87 +1,24 @@ | |||||||
| Import("env") | Import("env") | ||||||
| 
 | 
 | ||||||
| env.Append( |  | ||||||
|     LINT_SOURCES=[ |  | ||||||
|         Dir("app-scened-template"), |  | ||||||
|         Dir("digital_signal"), |  | ||||||
|         Dir("pulse_reader"), |  | ||||||
|         Dir("signal_reader"), |  | ||||||
|         Dir("drivers"), |  | ||||||
|         Dir("flipper_format"), |  | ||||||
|         Dir("infrared"), |  | ||||||
|         Dir("nfc"), |  | ||||||
|         Dir("subghz"), |  | ||||||
|         Dir("toolbox"), |  | ||||||
|         Dir("u8g2"), |  | ||||||
|         Dir("update_util"), |  | ||||||
|         Dir("print"), |  | ||||||
|         Dir("music_worker"), |  | ||||||
|     ], |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| env.Append( | env.Append( | ||||||
|     CPPPATH=[ |     CPPPATH=[ | ||||||
|         "#/", |         "#/", | ||||||
|         "#/lib",  # TODO FL-3553: remove! |         "#/lib",  # TODO FL-3553: remove! | ||||||
|         "#/lib/mlib", |  | ||||||
|         # Ugly hack |         # Ugly hack | ||||||
|         Dir("../assets/compiled"), |         Dir("../assets/compiled"), | ||||||
|     ], |     ], | ||||||
|     SDK_HEADERS=[ |  | ||||||
|         *( |  | ||||||
|             File(f"#/lib/mlib/m-{name}.h") |  | ||||||
|             for name in ( |  | ||||||
|                 "algo", |  | ||||||
|                 "array", |  | ||||||
|                 "bptree", |  | ||||||
|                 "core", |  | ||||||
|                 "deque", |  | ||||||
|                 "dict", |  | ||||||
|                 "list", |  | ||||||
|                 "rbtree", |  | ||||||
|                 "tuple", |  | ||||||
|                 "variant", |  | ||||||
|             ) |  | ||||||
|         ), |  | ||||||
|     ], |  | ||||||
|     CPPDEFINES=[ |  | ||||||
|         '"M_MEMORY_FULL(x)=abort()"', |  | ||||||
|     ], |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # drivers |  | ||||||
| # fatfs |  | ||||||
| # flipper_format |  | ||||||
| # infrared |  | ||||||
| # littlefs |  | ||||||
| # subghz |  | ||||||
| # toolbox |  | ||||||
| # one_wire |  | ||||||
| # micro-ecc |  | ||||||
| # misc |  | ||||||
| #    digital_signal |  | ||||||
| #    fnv1a_hash |  | ||||||
| #    microtar |  | ||||||
| #    nfc |  | ||||||
| #    qrcode |  | ||||||
| #    u8g2 |  | ||||||
| #    update_util |  | ||||||
| #    heatshrink |  | ||||||
| #    nanopb |  | ||||||
| # apps |  | ||||||
| #    app-scened-template |  | ||||||
| #    callback-connector |  | ||||||
| #    app-template |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| libs = env.BuildModules( | libs = env.BuildModules( | ||||||
|     [ |     [ | ||||||
|  |         "mlib", | ||||||
|         "stm32wb", |         "stm32wb", | ||||||
|         "freertos", |         "freertos", | ||||||
|         "print", |         "print", | ||||||
|         "microtar", |         "microtar", | ||||||
|  |         "mbedtls", | ||||||
|         "toolbox", |         "toolbox", | ||||||
|         "libusb_stm32", |         "libusb_stm32", | ||||||
|         "drivers", |         "drivers", | ||||||
| @ -91,17 +28,19 @@ libs = env.BuildModules( | |||||||
|         "ibutton", |         "ibutton", | ||||||
|         "infrared", |         "infrared", | ||||||
|         "littlefs", |         "littlefs", | ||||||
|         "mbedtls", |  | ||||||
|         "subghz", |         "subghz", | ||||||
|         "nfc", |         "nfc", | ||||||
|         "digital_signal", |         "digital_signal", | ||||||
|         "pulse_reader", |         "pulse_reader", | ||||||
|         "signal_reader", |         "signal_reader", | ||||||
|         "appframe", |         "appframe", | ||||||
|         "misc", |         "u8g2", | ||||||
|         "lfrfid", |         "lfrfid", | ||||||
|         "flipper_application", |         "flipper_application", | ||||||
|         "music_worker", |         "music_worker", | ||||||
|  |         "nanopb", | ||||||
|  |         "update_util", | ||||||
|  |         "heatshrink", | ||||||
|     ], |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,6 +5,9 @@ env.Append( | |||||||
|         "#/lib/app-scened-template", |         "#/lib/app-scened-template", | ||||||
|         "#/lib/callback-connector", |         "#/lib/callback-connector", | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("app-scened-template"), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -8,6 +8,9 @@ env.Append( | |||||||
|         File("digital_signal.h"), |         File("digital_signal.h"), | ||||||
|         File("digital_sequence.h"), |         File("digital_sequence.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| libenv = env.Clone(FW_LIB_NAME="digital_signal") | libenv = env.Clone(FW_LIB_NAME="digital_signal") | ||||||
|  | |||||||
| @ -9,6 +9,9 @@ env.Append( | |||||||
|         File("st25r3916_reg.h"), |         File("st25r3916_reg.h"), | ||||||
|         File("st25r3916.h"), |         File("st25r3916.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,7 +1,8 @@ | |||||||
| #include "storage/storage.h" |  | ||||||
| #include <elf.h> |  | ||||||
| #include "elf_file.h" | #include "elf_file.h" | ||||||
| #include "elf_file_i.h" | #include "elf_file_i.h" | ||||||
|  | 
 | ||||||
|  | #include <storage/storage.h> | ||||||
|  | #include <elf.h> | ||||||
| #include "elf_api_interface.h" | #include "elf_api_interface.h" | ||||||
| #include "../api_hashtable/api_hashtable.h" | #include "../api_hashtable/api_hashtable.h" | ||||||
| 
 | 
 | ||||||
| @ -34,7 +35,7 @@ const uint8_t trampoline_code_little_endian[TRAMPOLINE_CODE_SIZE] = | |||||||
| typedef struct { | typedef struct { | ||||||
|     uint8_t code[TRAMPOLINE_CODE_SIZE]; |     uint8_t code[TRAMPOLINE_CODE_SIZE]; | ||||||
|     uint32_t addr; |     uint32_t addr; | ||||||
| } __attribute__((packed)) JMPTrampoline; | } FURI_PACKED JMPTrampoline; | ||||||
| 
 | 
 | ||||||
| /**************************************************************************************************/ | /**************************************************************************************************/ | ||||||
| /********************************************* Caches *********************************************/ | /********************************************* Caches *********************************************/ | ||||||
|  | |||||||
| @ -9,6 +9,9 @@ env.Append( | |||||||
|         File("flipper_format_i.h"), |         File("flipper_format_i.h"), | ||||||
|         File("flipper_format_stream.h"), |         File("flipper_format_stream.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,10 +0,0 @@ | |||||||
| #include "fnv1a-hash.h" |  | ||||||
| 
 |  | ||||||
| // FNV-1a hash, 32-bit
 |  | ||||||
| uint32_t fnv1a_buffer_hash(const uint8_t* buffer, uint32_t length, uint32_t hash) |  | ||||||
| { |  | ||||||
|     for (uint32_t i = 0; i < length; i++) { |  | ||||||
|         hash = (hash ^ buffer[i]) * 16777619ULL; |  | ||||||
|     } |  | ||||||
|     return hash; |  | ||||||
| } |  | ||||||
| @ -1,39 +0,0 @@ | |||||||
| #pragma once |  | ||||||
| #include <stdint.h> |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #define FNV_1A_INIT 2166136261UL |  | ||||||
| 
 |  | ||||||
| // FNV-1a hash, 32-bit
 |  | ||||||
| uint32_t fnv1a_buffer_hash(const uint8_t* buffer, uint32_t length, uint32_t hash); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| // constexpr FNV-1a hash for strings, 32-bit
 |  | ||||||
| inline constexpr uint32_t fnv1a_string_hash(const char* str) { |  | ||||||
|     uint32_t hash = FNV_1A_INIT; |  | ||||||
| 
 |  | ||||||
|     while(*str) { |  | ||||||
|         hash = (hash ^ *str) * 16777619ULL; |  | ||||||
|         str += 1; |  | ||||||
|     } |  | ||||||
|     return hash; |  | ||||||
| } |  | ||||||
| #else |  | ||||||
| // FNV-1a hash for strings, 32-bit
 |  | ||||||
| inline uint32_t fnv1a_string_hash(const char* str) { |  | ||||||
|     uint32_t hash = FNV_1A_INIT; |  | ||||||
| 
 |  | ||||||
|     while(*str) { |  | ||||||
|         hash = (hash ^ *str) * 16777619ULL; |  | ||||||
|         str += 1; |  | ||||||
|     } |  | ||||||
|     return hash; |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
							
								
								
									
										23
									
								
								lib/heatshrink.scons
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								lib/heatshrink.scons
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | from fbt.util import GLOB_FILE_EXCLUSION | ||||||
|  | 
 | ||||||
|  | Import("env") | ||||||
|  | 
 | ||||||
|  | env.Append( | ||||||
|  |     CPPPATH=[ | ||||||
|  |         "#/lib/heatshrink", | ||||||
|  |     ], | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | libenv = env.Clone(FW_LIB_NAME="heatshrink") | ||||||
|  | libenv.ApplyLibFlags() | ||||||
|  | 
 | ||||||
|  | sources = Glob( | ||||||
|  |     "heatshrink/heatshrink_*.c*", | ||||||
|  |     exclude=GLOB_FILE_EXCLUSION, | ||||||
|  |     source=True, | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | ||||||
|  | libenv.Install("${LIB_DIST_DIR}", lib) | ||||||
|  | Return("lib") | ||||||
| @ -10,6 +10,9 @@ env.Append( | |||||||
|         File("worker/infrared_worker.h"), |         File("worker/infrared_worker.h"), | ||||||
|         File("worker/infrared_transmit.h"), |         File("worker/infrared_transmit.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1 +1 @@ | |||||||
| Subproject commit d65aeb37349ad1a50e0f6c9b694d4b5290d60e49 | Subproject commit edb8fec9882084344a314368ac7fd957a187519c | ||||||
| @ -2,13 +2,21 @@ Import("env") | |||||||
| 
 | 
 | ||||||
| env.Append( | env.Append( | ||||||
|     CPPPATH=[ |     CPPPATH=[ | ||||||
|         "#/lib/mbedtls", |         # "#/lib/mbedtls", | ||||||
|         "#/lib/mbedtls/include", |         "#/lib/mbedtls/include", | ||||||
|     ], |     ], | ||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("mbedtls/include/mbedtls/des.h"), |         File("mbedtls/include/mbedtls/des.h"), | ||||||
|         File("mbedtls/include/mbedtls/sha1.h"), |         File("mbedtls/include/mbedtls/sha1.h"), | ||||||
|  |         File("mbedtls/include/mbedtls/sha256.h"), | ||||||
|  |         File("mbedtls/include/mbedtls/md5.h"), | ||||||
|  |         File("mbedtls/include/mbedtls/md.h"), | ||||||
|  |         File("mbedtls/include/mbedtls/ecdsa.h"), | ||||||
|  |         File("mbedtls/include/mbedtls/ecdh.h"), | ||||||
|  |         File("mbedtls/include/mbedtls/ecp.h"), | ||||||
|  |         # File("mbedtls/include/mbedtls/sha1.h"), | ||||||
|     ], |     ], | ||||||
|  |     CPPDEFINES=[("MBEDTLS_CONFIG_FILE", '\\"mbedtls_cfg.h\\"')], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -20,14 +28,30 @@ libenv.AppendUnique( | |||||||
|         # Required for lib to be linkable with .faps |         # Required for lib to be linkable with .faps | ||||||
|         "-mword-relocations", |         "-mword-relocations", | ||||||
|         "-mlong-calls", |         "-mlong-calls", | ||||||
|  |         # Crappy code :) | ||||||
|  |         "-Wno-redundant-decls", | ||||||
|     ], |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | # If we were to build full mbedtls, we would need to use this: | ||||||
|  | # sources = libenv.GlobRecursive("*.c*", "mbedtls/library") | ||||||
|  | # Otherwise, we can just use the files we need: | ||||||
| sources = [ | sources = [ | ||||||
|     "mbedtls/library/des.c", |     File("mbedtls/library/bignum.c"), | ||||||
|     "mbedtls/library/sha1.c", |     File("mbedtls/library/bignum_core.c"), | ||||||
|     "mbedtls/library/platform_util.c", |     File("mbedtls/library/ecdsa.c"), | ||||||
|  |     File("mbedtls/library/ecp.c"), | ||||||
|  |     File("mbedtls/library/ecp_curves.c"), | ||||||
|  |     File("mbedtls/library/md.c"), | ||||||
|  |     File("mbedtls/library/md5.c"), | ||||||
|  |     File("mbedtls/library/platform_util.c"), | ||||||
|  |     File("mbedtls/library/ripemd160.c"), | ||||||
|  |     File("mbedtls/library/sha1.c"), | ||||||
|  |     File("mbedtls/library/sha256.c"), | ||||||
|  |     File("mbedtls/library/des.c"), | ||||||
| ] | ] | ||||||
|  | Depends(sources, File("mbedtls_cfg.h")) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | ||||||
| libenv.Install("${LIB_DIST_DIR}", lib) | libenv.Install("${LIB_DIST_DIR}", lib) | ||||||
|  | |||||||
							
								
								
									
										92
									
								
								lib/mbedtls_cfg.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								lib/mbedtls_cfg.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,92 @@ | |||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  | * A subset of the mbedTLS configuration options that are relevant to the | ||||||
|  | * Flipper Zero firmware and apps. They are built to "mbedtls" library you can  | ||||||
|  | * link your apps with. | ||||||
|  | *  | ||||||
|  | * If you need more features, either bring the full mbedtls library into your | ||||||
|  | * app using "fap_private_libs" or open an issue on GitHub to add them to the | ||||||
|  | * default configuration. | ||||||
|  | **/ | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_HAVE_ASM | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_NO_UDBL_DIVISION | ||||||
|  | #define MBEDTLS_NO_64BIT_MULTIPLICATION | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_DEPRECATED_WARNING | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_AES_FEWER_TABLES | ||||||
|  | // #define MBEDTLS_CHECK_RETURN_WARNING
 | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_CIPHER_MODE_CBC | ||||||
|  | #define MBEDTLS_CIPHER_MODE_CFB | ||||||
|  | #define MBEDTLS_CIPHER_MODE_CTR | ||||||
|  | #define MBEDTLS_CIPHER_MODE_OFB | ||||||
|  | #define MBEDTLS_CIPHER_MODE_XTS | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_CIPHER_PADDING_PKCS7 | ||||||
|  | #define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS | ||||||
|  | #define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN | ||||||
|  | #define MBEDTLS_CIPHER_PADDING_ZEROS | ||||||
|  | 
 | ||||||
|  | /* Short Weierstrass curves (supporting ECP, ECDH, ECDSA) */ | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
 | ||||||
|  | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP192K1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP224K1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_SECP256K1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_BP256R1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_BP384R1_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_BP512R1_ENABLED
 | ||||||
|  | /* Montgomery curves (supporting ECP) */ | ||||||
|  | // #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
 | ||||||
|  | // #define MBEDTLS_ECP_DP_CURVE448_ENABLED
 | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_ECP_NIST_OPTIM | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_GENPRIME | ||||||
|  | // #define MBEDTLS_PKCS1_V15
 | ||||||
|  | // #define MBEDTLS_PKCS1_V21
 | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_MD_C | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_ASN1_PARSE_C | ||||||
|  | #define MBEDTLS_ASN1_WRITE_C | ||||||
|  | #define MBEDTLS_BASE64_C | ||||||
|  | #define MBEDTLS_BIGNUM_C | ||||||
|  | #define MBEDTLS_OID_C | ||||||
|  | 
 | ||||||
|  | // #define MBEDTLS_CHACHA20_C
 | ||||||
|  | // #define MBEDTLS_CHACHAPOLY_C
 | ||||||
|  | #define MBEDTLS_CIPHER_C | ||||||
|  | #define MBEDTLS_DES_C | ||||||
|  | #define MBEDTLS_DHM_C | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_ECDH_C | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_ECDSA_C | ||||||
|  | #define MBEDTLS_ECP_C | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_GCM_C | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_AES_C | ||||||
|  | #define MBEDTLS_MD5_C | ||||||
|  | 
 | ||||||
|  | // #define MBEDTLS_PEM_PARSE_C
 | ||||||
|  | // #define MBEDTLS_PEM_WRITE_C
 | ||||||
|  | 
 | ||||||
|  | // #define MBEDTLS_PLATFORM_MEMORY
 | ||||||
|  | // #define MBEDTLS_PLATFORM_C
 | ||||||
|  | 
 | ||||||
|  | // #define MBEDTLS_RIPEMD160_C
 | ||||||
|  | // #define MBEDTLS_RSA_C
 | ||||||
|  | #define MBEDTLS_SHA224_C | ||||||
|  | #define MBEDTLS_SHA256_C | ||||||
|  | #define MBEDTLS_SHA1_C | ||||||
|  | 
 | ||||||
|  | #define MBEDTLS_ERROR_C | ||||||
| @ -1,21 +0,0 @@ | |||||||
| Copyright (c) 2014, Kenneth MacKay |  | ||||||
| All rights reserved. |  | ||||||
| 
 |  | ||||||
| Redistribution and use in source and binary forms, with or without modification, |  | ||||||
| are permitted provided that the following conditions are met: |  | ||||||
|  * Redistributions of source code must retain the above copyright notice, this |  | ||||||
|    list of conditions and the following disclaimer. |  | ||||||
|  * Redistributions in binary form must reproduce the above copyright notice, |  | ||||||
|    this list of conditions and the following disclaimer in the documentation |  | ||||||
|    and/or other materials provided with the distribution. |  | ||||||
| 
 |  | ||||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |  | ||||||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |  | ||||||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |  | ||||||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |  | ||||||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |  | ||||||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |  | ||||||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |  | ||||||
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |  | ||||||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |  | ||||||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |  | ||||||
| @ -1,41 +0,0 @@ | |||||||
| micro-ecc |  | ||||||
| ========== |  | ||||||
| 
 |  | ||||||
| A small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors. |  | ||||||
| 
 |  | ||||||
| The static version of micro-ecc (ie, where the curve was selected at compile-time) can be found in the "static" branch. |  | ||||||
| 
 |  | ||||||
| Features |  | ||||||
| -------- |  | ||||||
| 
 |  | ||||||
|  * Resistant to known side-channel attacks. |  | ||||||
|  * Written in C, with optional GCC inline assembly for AVR, ARM and Thumb platforms. |  | ||||||
|  * Supports 8, 32, and 64-bit architectures. |  | ||||||
|  * Small code size. |  | ||||||
|  * No dynamic memory allocation. |  | ||||||
|  * Support for 5 standard curves: secp160r1, secp192r1, secp224r1, secp256r1, and secp256k1. |  | ||||||
|  * BSD 2-clause license. |  | ||||||
| 
 |  | ||||||
| Usage Notes |  | ||||||
| ----------- |  | ||||||
| ### Point Representation ### |  | ||||||
| Compressed points are represented in the standard format as defined in http://www.secg.org/sec1-v2.pdf; uncompressed points are represented in standard format, but without the `0x04` prefix. All functions except `uECC_decompress()` only accept uncompressed points; use `uECC_compress()` and `uECC_decompress()` to convert between compressed and uncompressed point representations. |  | ||||||
| 
 |  | ||||||
| Private keys are represented in the standard format. |  | ||||||
| 
 |  | ||||||
| ### Using the Code ### |  | ||||||
| 
 |  | ||||||
| I recommend just copying (or symlink) the uECC files into your project. Then just `#include "uECC.h"` to use the micro-ecc functions. |  | ||||||
| 
 |  | ||||||
| For use with Arduino, you can use the Library Manager to download micro-ecc (**Sketch**=>**Include Library**=>**Manage Libraries**). You can then use uECC just like any other Arduino library (uECC should show up in the **Sketch**=>**Import Library** submenu). |  | ||||||
| 
 |  | ||||||
| See uECC.h for documentation for each function. |  | ||||||
| 
 |  | ||||||
| ### Compilation Notes ### |  | ||||||
| 
 |  | ||||||
|  * Should compile with any C/C++ compiler that supports stdint.h (this includes Visual Studio 2013). |  | ||||||
|  * If you want to change the defaults for any of the uECC compile-time options (such as `uECC_OPTIMIZATION_LEVEL`), you must change them in your Makefile or similar so that uECC.c is compiled with the desired values (ie, compile uECC.c with `-DuECC_OPTIMIZATION_LEVEL=3` or whatever). |  | ||||||
|  * When compiling for a Thumb-1 platform, you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher). |  | ||||||
|  * When compiling for an ARM/Thumb-2 platform with `uECC_OPTIMIZATION_LEVEL` >= 3, you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher). |  | ||||||
|  * When compiling for AVR, you must have optimizations enabled (compile with `-O1` or higher). |  | ||||||
|  * When building for Windows, you will need to link in the `advapi32.lib` system library. |  | ||||||
| @ -1,821 +0,0 @@ | |||||||
| /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ |  | ||||||
| 
 |  | ||||||
| #ifndef _UECC_ASM_ARM_H_
 |  | ||||||
| #define _UECC_ASM_ARM_H_
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_SUPPORTS_secp256r1 || uECC_SUPPORTS_secp256k1)
 |  | ||||||
|     #define uECC_MIN_WORDS 8
 |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp224r1
 |  | ||||||
|     #undef uECC_MIN_WORDS
 |  | ||||||
|     #define uECC_MIN_WORDS 7
 |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp192r1
 |  | ||||||
|     #undef uECC_MIN_WORDS
 |  | ||||||
|     #define uECC_MIN_WORDS 6
 |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp160r1
 |  | ||||||
|     #undef uECC_MIN_WORDS
 |  | ||||||
|     #define uECC_MIN_WORDS 5
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_PLATFORM == uECC_arm_thumb)
 |  | ||||||
|     #define REG_RW "+l"
 |  | ||||||
|     #define REG_WRITE "=l"
 |  | ||||||
| #else
 |  | ||||||
|     #define REG_RW "+r"
 |  | ||||||
|     #define REG_WRITE "=r"
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_PLATFORM == uECC_arm_thumb || uECC_PLATFORM == uECC_arm_thumb2)
 |  | ||||||
|     #define REG_RW_LO "+l"
 |  | ||||||
|     #define REG_WRITE_LO "=l"
 |  | ||||||
| #else
 |  | ||||||
|     #define REG_RW_LO "+r"
 |  | ||||||
|     #define REG_WRITE_LO "=r"
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_PLATFORM == uECC_arm_thumb2)
 |  | ||||||
|     #define RESUME_SYNTAX
 |  | ||||||
| #else
 |  | ||||||
|     #define RESUME_SYNTAX ".syntax divided \n\t"
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_OPTIMIZATION_LEVEL >= 2)
 |  | ||||||
| 
 |  | ||||||
| uECC_VLI_API uECC_word_t uECC_vli_add(uECC_word_t *result, |  | ||||||
|                                       const uECC_word_t *left, |  | ||||||
|                                       const uECC_word_t *right, |  | ||||||
|                                       wordcount_t num_words) { |  | ||||||
| #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|   #if (uECC_PLATFORM == uECC_arm_thumb) || (uECC_PLATFORM == uECC_arm_thumb2)
 |  | ||||||
|     uint32_t jump = (uECC_MAX_WORDS - num_words) * 4 * 2 + 1; |  | ||||||
|   #else /* ARM */
 |  | ||||||
|     uint32_t jump = (uECC_MAX_WORDS - num_words) * 4 * 4; |  | ||||||
|   #endif
 |  | ||||||
| #endif
 |  | ||||||
|     uint32_t carry; |  | ||||||
|     uint32_t left_word; |  | ||||||
|     uint32_t right_word; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|         "movs %[carry], #0 \n\t" |  | ||||||
|     #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|         "adr %[left], 1f \n\t" |  | ||||||
|         ".align 4 \n\t" |  | ||||||
|         "adds %[jump], %[left] \n\t" |  | ||||||
|     #endif
 |  | ||||||
|          |  | ||||||
|         "ldmia %[lptr]!, {%[left]} \n\t" |  | ||||||
|         "ldmia %[rptr]!, {%[right]} \n\t" |  | ||||||
|         "adds %[left], %[right] \n\t" |  | ||||||
|         "stmia %[dptr]!, {%[left]} \n\t" |  | ||||||
|          |  | ||||||
|     #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|         "bx %[jump] \n\t" |  | ||||||
|     #endif
 |  | ||||||
|         "1: \n\t" |  | ||||||
|         REPEAT(DEC(uECC_MAX_WORDS), |  | ||||||
|             "ldmia %[lptr]!, {%[left]} \n\t" |  | ||||||
|             "ldmia %[rptr]!, {%[right]} \n\t" |  | ||||||
|             "adcs %[left], %[right] \n\t" |  | ||||||
|             "stmia %[dptr]!, {%[left]} \n\t") |  | ||||||
|          |  | ||||||
|         "adcs %[carry], %[carry] \n\t" |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : [dptr] REG_RW_LO (result), [lptr] REG_RW_LO (left), [rptr] REG_RW_LO (right), |  | ||||||
|     #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|           [jump] REG_RW_LO (jump), |  | ||||||
|     #endif
 |  | ||||||
|           [carry] REG_WRITE_LO (carry), [left] REG_WRITE_LO (left_word), |  | ||||||
|           [right] REG_WRITE_LO (right_word) |  | ||||||
|         : |  | ||||||
|         : "cc", "memory" |  | ||||||
|     ); |  | ||||||
|     return carry; |  | ||||||
| } |  | ||||||
| #define asm_add 1
 |  | ||||||
| 
 |  | ||||||
| #pragma GCC diagnostic ignored "-Wredundant-decls"
 |  | ||||||
| uECC_VLI_API uECC_word_t uECC_vli_sub(uECC_word_t *result, |  | ||||||
|                                       const uECC_word_t *left, |  | ||||||
|                                       const uECC_word_t *right, |  | ||||||
|                                       wordcount_t num_words) { |  | ||||||
| #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|   #if (uECC_PLATFORM == uECC_arm_thumb) || (uECC_PLATFORM == uECC_arm_thumb2)
 |  | ||||||
|     uint32_t jump = (uECC_MAX_WORDS - num_words) * 4 * 2 + 1; |  | ||||||
|   #else /* ARM */
 |  | ||||||
|     uint32_t jump = (uECC_MAX_WORDS - num_words) * 4 * 4; |  | ||||||
|   #endif
 |  | ||||||
| #endif
 |  | ||||||
|     uint32_t carry; |  | ||||||
|     uint32_t left_word; |  | ||||||
|     uint32_t right_word; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|         "movs %[carry], #0 \n\t" |  | ||||||
|     #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|         "adr %[left], 1f \n\t" |  | ||||||
|         ".align 4 \n\t" |  | ||||||
|         "adds %[jump], %[left] \n\t" |  | ||||||
|     #endif
 |  | ||||||
|          |  | ||||||
|         "ldmia %[lptr]!, {%[left]} \n\t" |  | ||||||
|         "ldmia %[rptr]!, {%[right]} \n\t" |  | ||||||
|         "subs %[left], %[right] \n\t" |  | ||||||
|         "stmia %[dptr]!, {%[left]} \n\t" |  | ||||||
|          |  | ||||||
|     #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|         "bx %[jump] \n\t" |  | ||||||
|     #endif
 |  | ||||||
|         "1: \n\t" |  | ||||||
|         REPEAT(DEC(uECC_MAX_WORDS), |  | ||||||
|             "ldmia %[lptr]!, {%[left]} \n\t" |  | ||||||
|             "ldmia %[rptr]!, {%[right]} \n\t" |  | ||||||
|             "sbcs %[left], %[right] \n\t" |  | ||||||
|             "stmia %[dptr]!, {%[left]} \n\t") |  | ||||||
|          |  | ||||||
|         "adcs %[carry], %[carry] \n\t" |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : [dptr] REG_RW_LO (result), [lptr] REG_RW_LO (left), [rptr] REG_RW_LO (right), |  | ||||||
|     #if (uECC_MAX_WORDS != uECC_MIN_WORDS)
 |  | ||||||
|           [jump] REG_RW_LO (jump), |  | ||||||
|     #endif
 |  | ||||||
|           [carry] REG_WRITE_LO (carry), [left] REG_WRITE_LO (left_word), |  | ||||||
|           [right] REG_WRITE_LO (right_word) |  | ||||||
|         : |  | ||||||
|         : "cc", "memory" |  | ||||||
|     ); |  | ||||||
|     return !carry; /* Note that on ARM, carry flag set means "no borrow" when subtracting |  | ||||||
|                       (for some reason...) */ |  | ||||||
| } |  | ||||||
| #define asm_sub 1
 |  | ||||||
| 
 |  | ||||||
| #endif /* (uECC_OPTIMIZATION_LEVEL >= 2) */
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_OPTIMIZATION_LEVEL >= 3)
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_PLATFORM != uECC_arm_thumb)
 |  | ||||||
| 
 |  | ||||||
| #if uECC_ARM_USE_UMAAL
 |  | ||||||
|     #include "asm_arm_mult_square_umaal.inc"
 |  | ||||||
| #else
 |  | ||||||
|     #include "asm_arm_mult_square.inc"
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if (uECC_OPTIMIZATION_LEVEL == 3)
 |  | ||||||
| 
 |  | ||||||
| uECC_VLI_API void uECC_vli_mult(uint32_t *result, |  | ||||||
|                                 const uint32_t *left, |  | ||||||
|                                 const uint32_t *right, |  | ||||||
|                                 wordcount_t num_words) { |  | ||||||
|     register uint32_t *r0 __asm__("r0") = result; |  | ||||||
|     register const uint32_t *r1 __asm__("r1") = left; |  | ||||||
|     register const uint32_t *r2 __asm__("r2") = right; |  | ||||||
|     register uint32_t r3 __asm__("r3") = num_words; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
| #if (uECC_MIN_WORDS == 5)
 |  | ||||||
|         FAST_MULT_ASM_5 |  | ||||||
|     #if (uECC_MAX_WORDS > 5)
 |  | ||||||
|         FAST_MULT_ASM_5_TO_6 |  | ||||||
|     #endif
 |  | ||||||
|     #if (uECC_MAX_WORDS > 6)
 |  | ||||||
|         FAST_MULT_ASM_6_TO_7 |  | ||||||
|     #endif
 |  | ||||||
|     #if (uECC_MAX_WORDS > 7)
 |  | ||||||
|         FAST_MULT_ASM_7_TO_8 |  | ||||||
|     #endif
 |  | ||||||
| #elif (uECC_MIN_WORDS == 6)
 |  | ||||||
|         FAST_MULT_ASM_6 |  | ||||||
|     #if (uECC_MAX_WORDS > 6)
 |  | ||||||
|         FAST_MULT_ASM_6_TO_7 |  | ||||||
|     #endif
 |  | ||||||
|     #if (uECC_MAX_WORDS > 7)
 |  | ||||||
|         FAST_MULT_ASM_7_TO_8 |  | ||||||
|     #endif
 |  | ||||||
| #elif (uECC_MIN_WORDS == 7)
 |  | ||||||
|         FAST_MULT_ASM_7 |  | ||||||
|     #if (uECC_MAX_WORDS > 7)
 |  | ||||||
|         FAST_MULT_ASM_7_TO_8 |  | ||||||
|     #endif
 |  | ||||||
| #elif (uECC_MIN_WORDS == 8)
 |  | ||||||
|         FAST_MULT_ASM_8 |  | ||||||
| #endif
 |  | ||||||
|         "1: \n\t" |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : "+r" (r0), "+r" (r1), "+r" (r2) |  | ||||||
|         : "r" (r3) |  | ||||||
|         : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|     ); |  | ||||||
| } |  | ||||||
| #define asm_mult 1
 |  | ||||||
| 
 |  | ||||||
| #if uECC_SQUARE_FUNC
 |  | ||||||
| uECC_VLI_API void uECC_vli_square(uECC_word_t *result, |  | ||||||
|                                   const uECC_word_t *left, |  | ||||||
|                                   wordcount_t num_words) { |  | ||||||
|     register uint32_t *r0 __asm__("r0") = result; |  | ||||||
|     register const uint32_t *r1 __asm__("r1") = left; |  | ||||||
|     register uint32_t r2 __asm__("r2") = num_words; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
| #if (uECC_MIN_WORDS == 5)
 |  | ||||||
|         FAST_SQUARE_ASM_5 |  | ||||||
|     #if (uECC_MAX_WORDS > 5)
 |  | ||||||
|         FAST_SQUARE_ASM_5_TO_6 |  | ||||||
|     #endif
 |  | ||||||
|     #if (uECC_MAX_WORDS > 6)
 |  | ||||||
|         FAST_SQUARE_ASM_6_TO_7 |  | ||||||
|     #endif
 |  | ||||||
|     #if (uECC_MAX_WORDS > 7)
 |  | ||||||
|         FAST_SQUARE_ASM_7_TO_8 |  | ||||||
|     #endif
 |  | ||||||
| #elif (uECC_MIN_WORDS == 6)
 |  | ||||||
|         FAST_SQUARE_ASM_6 |  | ||||||
|     #if (uECC_MAX_WORDS > 6)
 |  | ||||||
|         FAST_SQUARE_ASM_6_TO_7 |  | ||||||
|     #endif
 |  | ||||||
|     #if (uECC_MAX_WORDS > 7)
 |  | ||||||
|         FAST_SQUARE_ASM_7_TO_8 |  | ||||||
|     #endif
 |  | ||||||
| #elif (uECC_MIN_WORDS == 7)
 |  | ||||||
|         FAST_SQUARE_ASM_7 |  | ||||||
|     #if (uECC_MAX_WORDS > 7)
 |  | ||||||
|         FAST_SQUARE_ASM_7_TO_8 |  | ||||||
|     #endif
 |  | ||||||
| #elif (uECC_MIN_WORDS == 8)
 |  | ||||||
|         FAST_SQUARE_ASM_8 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
|         "1: \n\t" |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : "+r" (r0), "+r" (r1) |  | ||||||
|         : "r" (r2) |  | ||||||
|         : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|     ); |  | ||||||
| } |  | ||||||
| #define asm_square 1
 |  | ||||||
| #endif /* uECC_SQUARE_FUNC */
 |  | ||||||
| 
 |  | ||||||
| #else /* (uECC_OPTIMIZATION_LEVEL > 3) */
 |  | ||||||
| 
 |  | ||||||
| uECC_VLI_API void uECC_vli_mult(uint32_t *result, |  | ||||||
|                                 const uint32_t *left, |  | ||||||
|                                 const uint32_t *right, |  | ||||||
|                                 wordcount_t num_words) { |  | ||||||
|     register uint32_t *r0 __asm__("r0") = result; |  | ||||||
|     register const uint32_t *r1 __asm__("r1") = left; |  | ||||||
|     register const uint32_t *r2 __asm__("r2") = right; |  | ||||||
|     register uint32_t r3 __asm__("r3") = num_words; |  | ||||||
|      |  | ||||||
| #if uECC_SUPPORTS_secp160r1
 |  | ||||||
|     if (num_words == 5) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_MULT_ASM_5 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1), "+r" (r2) |  | ||||||
|             : "r" (r3) |  | ||||||
|             : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp192r1
 |  | ||||||
|     if (num_words == 6) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_MULT_ASM_6 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1), "+r" (r2) |  | ||||||
|             : "r" (r3) |  | ||||||
|             : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp224r1
 |  | ||||||
|     if (num_words == 7) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_MULT_ASM_7 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1), "+r" (r2) |  | ||||||
|             : "r" (r3) |  | ||||||
|             : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| #if (uECC_SUPPORTS_secp256r1 || uECC_SUPPORTS_secp256k1)
 |  | ||||||
|     if (num_words == 8) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_MULT_ASM_8 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1), "+r" (r2) |  | ||||||
|             : "r" (r3) |  | ||||||
|             : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| } |  | ||||||
| #define asm_mult 1
 |  | ||||||
| 
 |  | ||||||
| #if uECC_SQUARE_FUNC
 |  | ||||||
| uECC_VLI_API void uECC_vli_square(uECC_word_t *result, |  | ||||||
|                                   const uECC_word_t *left, |  | ||||||
|                                   wordcount_t num_words) { |  | ||||||
|     register uint32_t *r0 __asm__("r0") = result; |  | ||||||
|     register const uint32_t *r1 __asm__("r1") = left; |  | ||||||
|     register uint32_t r2 __asm__("r2") = num_words; |  | ||||||
|      |  | ||||||
| #if uECC_SUPPORTS_secp160r1
 |  | ||||||
|     if (num_words == 5) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_SQUARE_ASM_5 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1) |  | ||||||
|             : "r" (r2) |  | ||||||
|             : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp192r1
 |  | ||||||
|     if (num_words == 6) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_SQUARE_ASM_6 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1) |  | ||||||
|             : "r" (r2) |  | ||||||
|             : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| #if uECC_SUPPORTS_secp224r1
 |  | ||||||
|     if (num_words == 7) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_SQUARE_ASM_7 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1) |  | ||||||
|             : "r" (r2) |  | ||||||
|             : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| #if (uECC_SUPPORTS_secp256r1 || uECC_SUPPORTS_secp256k1)
 |  | ||||||
|     if (num_words == 8) { |  | ||||||
|         __asm__ volatile ( |  | ||||||
|             ".syntax unified \n\t" |  | ||||||
|             FAST_SQUARE_ASM_8 |  | ||||||
|             RESUME_SYNTAX |  | ||||||
|             : "+r" (r0), "+r" (r1) |  | ||||||
|             : "r" (r2) |  | ||||||
|             : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|         ); |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| #endif
 |  | ||||||
| } |  | ||||||
| #define asm_square 1
 |  | ||||||
| #endif /* uECC_SQUARE_FUNC */
 |  | ||||||
| 
 |  | ||||||
| #endif /* (uECC_OPTIMIZATION_LEVEL > 3) */
 |  | ||||||
| 
 |  | ||||||
| #endif /* uECC_PLATFORM != uECC_arm_thumb */
 |  | ||||||
| 
 |  | ||||||
| #endif /* (uECC_OPTIMIZATION_LEVEL >= 3) */
 |  | ||||||
| 
 |  | ||||||
| /* ---- "Small" implementations ---- */ |  | ||||||
| 
 |  | ||||||
| #if !asm_add
 |  | ||||||
| uECC_VLI_API uECC_word_t uECC_vli_add(uECC_word_t *result, |  | ||||||
|                                       const uECC_word_t *left, |  | ||||||
|                                       const uECC_word_t *right, |  | ||||||
|                                       wordcount_t num_words) { |  | ||||||
|     uint32_t carry = 0; |  | ||||||
|     uint32_t left_word; |  | ||||||
|     uint32_t right_word; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|         "1: \n\t" |  | ||||||
|         "ldmia %[lptr]!, {%[left]} \n\t"  /* Load left word. */ |  | ||||||
|         "ldmia %[rptr]!, {%[right]} \n\t" /* Load right word. */ |  | ||||||
|         "lsrs %[carry], #1 \n\t"          /* Set up carry flag (carry = 0 after this). */ |  | ||||||
|         "adcs %[left], %[left], %[right] \n\t"   /* Add with carry. */ |  | ||||||
|         "adcs %[carry], %[carry], %[carry] \n\t" /* Store carry bit. */ |  | ||||||
|         "stmia %[dptr]!, {%[left]} \n\t"  /* Store result word. */ |  | ||||||
|         "subs %[ctr], #1 \n\t"            /* Decrement counter. */ |  | ||||||
|         "bne 1b \n\t"                     /* Loop until counter == 0. */ |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : [dptr] REG_RW (result), [lptr] REG_RW (left), [rptr] REG_RW (right), |  | ||||||
|           [ctr] REG_RW (num_words), [carry] REG_RW (carry), |  | ||||||
|           [left] REG_WRITE (left_word), [right] REG_WRITE (right_word) |  | ||||||
|         : |  | ||||||
|         : "cc", "memory" |  | ||||||
|     ); |  | ||||||
|     return carry; |  | ||||||
| } |  | ||||||
| #define asm_add 1
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if !asm_sub
 |  | ||||||
| uECC_VLI_API uECC_word_t uECC_vli_sub(uECC_word_t *result, |  | ||||||
|                                       const uECC_word_t *left, |  | ||||||
|                                       const uECC_word_t *right, |  | ||||||
|                                       wordcount_t num_words) { |  | ||||||
|     uint32_t carry = 1; /* carry = 1 initially (means don't borrow) */ |  | ||||||
|     uint32_t left_word; |  | ||||||
|     uint32_t right_word; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|         "1: \n\t" |  | ||||||
|         "ldmia %[lptr]!, {%[left]} \n\t"  /* Load left word. */ |  | ||||||
|         "ldmia %[rptr]!, {%[right]} \n\t" /* Load right word. */ |  | ||||||
|         "lsrs %[carry], #1 \n\t"          /* Set up carry flag (carry = 0 after this). */ |  | ||||||
|         "sbcs %[left], %[left], %[right] \n\t"   /* Subtract with borrow. */ |  | ||||||
|         "adcs %[carry], %[carry], %[carry] \n\t" /* Store carry bit. */ |  | ||||||
|         "stmia %[dptr]!, {%[left]} \n\t"  /* Store result word. */ |  | ||||||
|         "subs %[ctr], #1 \n\t"            /* Decrement counter. */ |  | ||||||
|         "bne 1b \n\t"                     /* Loop until counter == 0. */ |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : [dptr] REG_RW (result), [lptr] REG_RW (left), [rptr] REG_RW (right), |  | ||||||
|           [ctr] REG_RW (num_words), [carry] REG_RW (carry), |  | ||||||
|           [left] REG_WRITE (left_word), [right] REG_WRITE (right_word) |  | ||||||
|         : |  | ||||||
|         : "cc", "memory" |  | ||||||
|     ); |  | ||||||
|     return !carry; |  | ||||||
| } |  | ||||||
| #define asm_sub 1
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if !asm_mult
 |  | ||||||
| uECC_VLI_API void uECC_vli_mult(uECC_word_t *result, |  | ||||||
|                                 const uECC_word_t *left, |  | ||||||
|                                 const uECC_word_t *right, |  | ||||||
|                                 wordcount_t num_words) { |  | ||||||
| #if (uECC_PLATFORM != uECC_arm_thumb)
 |  | ||||||
|     uint32_t c0 = 0; |  | ||||||
|     uint32_t c1 = 0; |  | ||||||
|     uint32_t c2 = 0; |  | ||||||
|     uint32_t k = 0; |  | ||||||
|     uint32_t i; |  | ||||||
|     uint32_t t0, t1; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|          |  | ||||||
|         "1: \n\t" /* outer loop (k < num_words) */ |  | ||||||
|         "movs %[i], #0 \n\t" /* i = 0 */ |  | ||||||
|         "b 3f \n\t" |  | ||||||
|          |  | ||||||
|         "2: \n\t" /* outer loop (k >= num_words) */ |  | ||||||
|         "movs %[i], %[k] \n\t"         /* i = k */ |  | ||||||
|         "subs %[i], %[last_word] \n\t" /* i = k - (num_words - 1) (times 4) */ |  | ||||||
|          |  | ||||||
|         "3: \n\t" /* inner loop */ |  | ||||||
|         "subs %[t0], %[k], %[i] \n\t" /* t0 = k-i */ |  | ||||||
|          |  | ||||||
|         "ldr %[t1], [%[right], %[t0]] \n\t" /* t1 = right[k - i] */ |  | ||||||
|         "ldr %[t0], [%[left], %[i]] \n\t"   /* t0 = left[i] */ |  | ||||||
|          |  | ||||||
|         "umull %[t0], %[t1], %[t0], %[t1] \n\t" /* (t0, t1) = left[i] * right[k - i] */ |  | ||||||
|          |  | ||||||
|         "adds %[c0], %[c0], %[t0] \n\t" /* add low word to c0 */ |  | ||||||
|         "adcs %[c1], %[c1], %[t1] \n\t" /* add high word to c1, including carry */ |  | ||||||
|         "adcs %[c2], %[c2], #0 \n\t"    /* add carry to c2 */ |  | ||||||
| 
 |  | ||||||
|         "adds %[i], #4 \n\t"          /* i += 4 */ |  | ||||||
|         "cmp %[i], %[last_word] \n\t" /* i > (num_words - 1) (times 4)? */ |  | ||||||
|         "bgt 4f \n\t"                 /*   if so, exit the loop */ |  | ||||||
|         "cmp %[i], %[k] \n\t"         /* i <= k? */ |  | ||||||
|         "ble 3b \n\t"                 /*   if so, continue looping */ |  | ||||||
|          |  | ||||||
|         "4: \n\t" /* end inner loop */ |  | ||||||
|          |  | ||||||
|         "str %[c0], [%[result], %[k]] \n\t" /* result[k] = c0 */ |  | ||||||
|         "mov %[c0], %[c1] \n\t"       /* c0 = c1 */ |  | ||||||
|         "mov %[c1], %[c2] \n\t"       /* c1 = c2 */ |  | ||||||
|         "movs %[c2], #0 \n\t"         /* c2 = 0 */ |  | ||||||
|         "adds %[k], #4 \n\t"          /* k += 4 */ |  | ||||||
|         "cmp %[k], %[last_word] \n\t" /* k <= (num_words - 1) (times 4) ? */ |  | ||||||
|         "ble 1b \n\t"                 /*   if so, loop back, start with i = 0 */ |  | ||||||
|         "cmp %[k], %[last_word], lsl #1 \n\t" /* k <= (num_words * 2 - 2) (times 4) ? */ |  | ||||||
|         "ble 2b \n\t"                 /*   if so, loop back, start with i = (k + 1) - num_words */ |  | ||||||
|         /* end outer loop */ |  | ||||||
|          |  | ||||||
|         "str %[c0], [%[result], %[k]] \n\t" /* result[num_words * 2 - 1] = c0 */ |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : [c0] "+r" (c0), [c1] "+r" (c1), [c2] "+r" (c2), |  | ||||||
|           [k] "+r" (k), [i] "=&r" (i), [t0] "=&r" (t0), [t1] "=&r" (t1) |  | ||||||
|         : [result] "r" (result), [left] "r" (left), [right] "r" (right), |  | ||||||
|           [last_word] "r" ((num_words - 1) * 4) |  | ||||||
|         : "cc", "memory" |  | ||||||
|     ); |  | ||||||
|      |  | ||||||
| #else /* Thumb-1 */
 |  | ||||||
|     uint32_t r4, r5, r6, r7; |  | ||||||
| 
 |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|         "subs %[r3], #1 \n\t" /* r3 = num_words - 1 */ |  | ||||||
|         "lsls %[r3], #2 \n\t" /* r3 = (num_words - 1) * 4 */ |  | ||||||
|         "mov r8, %[r3] \n\t"  /* r8 = (num_words - 1) * 4 */ |  | ||||||
|         "lsls %[r3], #1 \n\t" /* r3 = (num_words - 1) * 8 */ |  | ||||||
|         "mov r9, %[r3] \n\t"  /* r9 = (num_words - 1) * 8 */ |  | ||||||
|         "movs %[r3], #0 \n\t" /* c0 = 0 */ |  | ||||||
|         "movs %[r4], #0 \n\t" /* c1 = 0 */ |  | ||||||
|         "movs %[r5], #0 \n\t" /* c2 = 0 */ |  | ||||||
|         "movs %[r6], #0 \n\t" /* k = 0 */ |  | ||||||
|          |  | ||||||
|         "push {%[r0]} \n\t" /* keep result on the stack */ |  | ||||||
|          |  | ||||||
|         "1: \n\t" /* outer loop (k < num_words) */ |  | ||||||
|         "movs %[r7], #0 \n\t" /* r7 = i = 0 */ |  | ||||||
|         "b 3f \n\t" |  | ||||||
|          |  | ||||||
|         "2: \n\t" /* outer loop (k >= num_words) */ |  | ||||||
|         "movs %[r7], %[r6] \n\t" /* r7 = k */ |  | ||||||
|         "mov %[r0], r8 \n\t"     /* r0 = (num_words - 1) * 4 */ |  | ||||||
|         "subs %[r7], %[r0] \n\t" /* r7 = i = k - (num_words - 1) (times 4) */ |  | ||||||
|          |  | ||||||
|         "3: \n\t" /* inner loop */ |  | ||||||
|         "mov r10, %[r3] \n\t" |  | ||||||
|         "mov r11, %[r4] \n\t" |  | ||||||
|         "mov r12, %[r5] \n\t" |  | ||||||
|         "mov r14, %[r6] \n\t" |  | ||||||
|         "subs %[r0], %[r6], %[r7] \n\t"          /* r0 = k - i */ |  | ||||||
|          |  | ||||||
|         "ldr %[r4], [%[r2], %[r0]] \n\t" /* r4 = right[k - i] */ |  | ||||||
|         "ldr %[r0], [%[r1], %[r7]] \n\t" /* r0 = left[i] */ |  | ||||||
|          |  | ||||||
|         "lsrs %[r3], %[r0], #16 \n\t" /* r3 = a1 */ |  | ||||||
|         "uxth %[r0], %[r0] \n\t"      /* r0 = a0 */ |  | ||||||
|          |  | ||||||
|         "lsrs %[r5], %[r4], #16 \n\t" /* r5 = b1 */ |  | ||||||
|         "uxth %[r4], %[r4] \n\t"      /* r4 = b0 */ |  | ||||||
|          |  | ||||||
|         "movs %[r6], %[r3] \n\t"        /* r6 = a1 */ |  | ||||||
|         "muls %[r6], %[r5], %[r6] \n\t" /* r6 = a1 * b1 */ |  | ||||||
|         "muls %[r3], %[r4], %[r3] \n\t" /* r3 = b0 * a1 */ |  | ||||||
|         "muls %[r5], %[r0], %[r5] \n\t" /* r5 = a0 * b1 */ |  | ||||||
|         "muls %[r0], %[r4], %[r0] \n\t" /* r0 = a0 * b0 */ |  | ||||||
|          |  | ||||||
|         /* Add middle terms */ |  | ||||||
|         "lsls %[r4], %[r3], #16 \n\t" |  | ||||||
|         "lsrs %[r3], %[r3], #16 \n\t" |  | ||||||
|         "adds %[r0], %[r4] \n\t" |  | ||||||
|         "adcs %[r6], %[r3] \n\t" |  | ||||||
|          |  | ||||||
|         "lsls %[r4], %[r5], #16 \n\t" |  | ||||||
|         "lsrs %[r5], %[r5], #16 \n\t" |  | ||||||
|         "adds %[r0], %[r4] \n\t" |  | ||||||
|         "adcs %[r6], %[r5] \n\t" |  | ||||||
|          |  | ||||||
|         "mov %[r3], r10\n\t" |  | ||||||
|         "mov %[r4], r11\n\t" |  | ||||||
|         "mov %[r5], r12\n\t" |  | ||||||
|         "adds %[r3], %[r0] \n\t"         /* add low word to c0 */ |  | ||||||
|         "adcs %[r4], %[r6] \n\t"         /* add high word to c1, including carry */ |  | ||||||
|         "movs %[r0], #0 \n\t"            /* r0 = 0 (does not affect carry bit) */ |  | ||||||
|         "adcs %[r5], %[r0] \n\t"         /* add carry to c2 */ |  | ||||||
|          |  | ||||||
|         "mov %[r6], r14\n\t" /* r6 = k */ |  | ||||||
| 
 |  | ||||||
|         "adds %[r7], #4 \n\t"   /* i += 4 */ |  | ||||||
|         "cmp %[r7], r8 \n\t"    /* i > (num_words - 1) (times 4)? */ |  | ||||||
|         "bgt 4f \n\t"           /*   if so, exit the loop */ |  | ||||||
|         "cmp %[r7], %[r6] \n\t" /* i <= k? */ |  | ||||||
|         "ble 3b \n\t"           /*   if so, continue looping */ |  | ||||||
|          |  | ||||||
|         "4: \n\t" /* end inner loop */ |  | ||||||
|          |  | ||||||
|         "ldr %[r0], [sp, #0] \n\t" /* r0 = result */ |  | ||||||
|          |  | ||||||
|         "str %[r3], [%[r0], %[r6]] \n\t" /* result[k] = c0 */ |  | ||||||
|         "mov %[r3], %[r4] \n\t"          /* c0 = c1 */ |  | ||||||
|         "mov %[r4], %[r5] \n\t"          /* c1 = c2 */ |  | ||||||
|         "movs %[r5], #0 \n\t"            /* c2 = 0 */ |  | ||||||
|         "adds %[r6], #4 \n\t"            /* k += 4 */ |  | ||||||
|         "cmp %[r6], r8 \n\t"             /* k <= (num_words - 1) (times 4) ? */ |  | ||||||
|         "ble 1b \n\t"                    /*   if so, loop back, start with i = 0 */ |  | ||||||
|         "cmp %[r6], r9 \n\t"             /* k <= (num_words * 2 - 2) (times 4) ? */ |  | ||||||
|         "ble 2b \n\t"                    /*   if so, loop back, with i = (k + 1) - num_words */ |  | ||||||
|         /* end outer loop */ |  | ||||||
|          |  | ||||||
|         "str %[r3], [%[r0], %[r6]] \n\t" /* result[num_words * 2 - 1] = c0 */ |  | ||||||
|         "pop {%[r0]} \n\t"               /* pop result off the stack */ |  | ||||||
|          |  | ||||||
|         ".syntax divided \n\t" |  | ||||||
|         : [r3] "+l" (num_words), [r4] "=&l" (r4), |  | ||||||
|           [r5] "=&l" (r5), [r6] "=&l" (r6), [r7] "=&l" (r7) |  | ||||||
|         : [r0] "l" (result), [r1] "l" (left), [r2] "l" (right) |  | ||||||
|         : "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|     ); |  | ||||||
| #endif
 |  | ||||||
| } |  | ||||||
| #define asm_mult 1
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| #if uECC_SQUARE_FUNC
 |  | ||||||
| #if !asm_square
 |  | ||||||
| uECC_VLI_API void uECC_vli_square(uECC_word_t *result, |  | ||||||
|                                   const uECC_word_t *left, |  | ||||||
|                                   wordcount_t num_words) { |  | ||||||
| #if (uECC_PLATFORM != uECC_arm_thumb)
 |  | ||||||
|     uint32_t c0 = 0; |  | ||||||
|     uint32_t c1 = 0; |  | ||||||
|     uint32_t c2 = 0; |  | ||||||
|     uint32_t k = 0; |  | ||||||
|     uint32_t i, tt; |  | ||||||
|     uint32_t t0, t1; |  | ||||||
|      |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|          |  | ||||||
|         "1: \n\t" /* outer loop (k < num_words) */ |  | ||||||
|         "movs %[i], #0 \n\t" /* i = 0 */ |  | ||||||
|         "b 3f \n\t" |  | ||||||
|          |  | ||||||
|         "2: \n\t" /* outer loop (k >= num_words) */ |  | ||||||
|         "movs %[i], %[k] \n\t"         /* i = k */ |  | ||||||
|         "subs %[i], %[last_word] \n\t" /* i = k - (num_words - 1) (times 4) */ |  | ||||||
|          |  | ||||||
|         "3: \n\t" /* inner loop */ |  | ||||||
|         "subs %[tt], %[k], %[i] \n\t" /* tt = k-i */ |  | ||||||
|          |  | ||||||
|         "ldr %[t1], [%[left], %[tt]] \n\t" /* t1 = left[k - i] */ |  | ||||||
|         "ldr %[t0], [%[left], %[i]] \n\t"  /* t0 = left[i] */ |  | ||||||
|          |  | ||||||
|         "umull %[t0], %[t1], %[t0], %[t1] \n\t" /* (t0, t1) = left[i] * right[k - i] */ |  | ||||||
|          |  | ||||||
|         "cmp %[i], %[tt] \n\t"      /* (i < k - i) ? */ |  | ||||||
|         "bge 4f \n\t"               /*   if i >= k - i, skip */ |  | ||||||
|         "adds %[c0], %[c0], %[t0] \n\t" /* add low word to c0 */ |  | ||||||
|         "adcs %[c1], %[c1], %[t1] \n\t" /* add high word to c1, including carry */ |  | ||||||
|         "adcs %[c2], %[c2], #0 \n\t"    /* add carry to c2 */ |  | ||||||
|          |  | ||||||
|         "4: \n\t" |  | ||||||
|         "adds %[c0], %[c0], %[t0] \n\t" /* add low word to c0 */ |  | ||||||
|         "adcs %[c1], %[c1], %[t1] \n\t" /* add high word to c1, including carry */ |  | ||||||
|         "adcs %[c2], %[c2], #0 \n\t"    /* add carry to c2 */ |  | ||||||
|          |  | ||||||
|         "adds %[i], #4 \n\t"          /* i += 4 */ |  | ||||||
|         "cmp %[i], %[k] \n\t"         /* i >= k? */ |  | ||||||
|         "bge 5f \n\t"                 /*   if so, exit the loop */ |  | ||||||
|         "subs %[tt], %[k], %[i] \n\t" /* tt = k - i */ |  | ||||||
|         "cmp %[i], %[tt] \n\t"        /* i <= k - i? */ |  | ||||||
|         "ble 3b \n\t"                 /*   if so, continue looping */ |  | ||||||
|          |  | ||||||
|         "5: \n\t" /* end inner loop */ |  | ||||||
|          |  | ||||||
|         "str %[c0], [%[result], %[k]] \n\t" /* result[k] = c0 */ |  | ||||||
|         "mov %[c0], %[c1] \n\t"       /* c0 = c1 */ |  | ||||||
|         "mov %[c1], %[c2] \n\t"       /* c1 = c2 */ |  | ||||||
|         "movs %[c2], #0 \n\t"         /* c2 = 0 */ |  | ||||||
|         "adds %[k], #4 \n\t"          /* k += 4 */ |  | ||||||
|         "cmp %[k], %[last_word] \n\t" /* k <= (num_words - 1) (times 4) ? */ |  | ||||||
|         "ble 1b \n\t"                 /*   if so, loop back, start with i = 0 */ |  | ||||||
|         "cmp %[k], %[last_word], lsl #1 \n\t" /* k <= (num_words * 2 - 2) (times 4) ? */ |  | ||||||
|         "ble 2b \n\t"                 /*   if so, loop back, start with i = (k + 1) - num_words */ |  | ||||||
|         /* end outer loop */ |  | ||||||
|          |  | ||||||
|         "str %[c0], [%[result], %[k]] \n\t" /* result[num_words * 2 - 1] = c0 */ |  | ||||||
|         RESUME_SYNTAX |  | ||||||
|         : [c0] "+r" (c0), [c1] "+r" (c1), [c2] "+r" (c2), |  | ||||||
|           [k] "+r" (k), [i] "=&r" (i), [tt] "=&r" (tt), [t0] "=&r" (t0), [t1] "=&r" (t1) |  | ||||||
|         : [result] "r" (result), [left] "r" (left), [last_word] "r" ((num_words - 1) * 4) |  | ||||||
|         : "cc", "memory" |  | ||||||
|     ); |  | ||||||
|      |  | ||||||
| #else
 |  | ||||||
|     uint32_t r3, r4, r5, r6, r7; |  | ||||||
| 
 |  | ||||||
|     __asm__ volatile ( |  | ||||||
|         ".syntax unified \n\t" |  | ||||||
|         "subs %[r2], #1 \n\t" /* r2 = num_words - 1 */ |  | ||||||
|         "lsls %[r2], #2 \n\t" /* r2 = (num_words - 1) * 4 */ |  | ||||||
|         "mov r8, %[r2] \n\t"  /* r8 = (num_words - 1) * 4 */ |  | ||||||
|         "lsls %[r2], #1 \n\t" /* r2 = (num_words - 1) * 8 */ |  | ||||||
|         "mov r9, %[r2] \n\t"  /* r9 = (num_words - 1) * 8 */ |  | ||||||
|         "movs %[r2], #0 \n\t" /* c0 = 0 */ |  | ||||||
|         "movs %[r3], #0 \n\t" /* c1 = 0 */ |  | ||||||
|         "movs %[r4], #0 \n\t" /* c2 = 0 */ |  | ||||||
|         "movs %[r5], #0 \n\t" /* k = 0 */ |  | ||||||
|          |  | ||||||
|         "push {%[r0]} \n\t" /* keep result on the stack */ |  | ||||||
|          |  | ||||||
|         "1: \n\t" /* outer loop (k < num_words) */ |  | ||||||
|         "movs %[r6], #0 \n\t" /* r6 = i = 0 */ |  | ||||||
|         "b 3f \n\t" |  | ||||||
|          |  | ||||||
|         "2: \n\t" /* outer loop (k >= num_words) */ |  | ||||||
|         "movs %[r6], %[r5] \n\t" /* r6 = k */ |  | ||||||
|         "mov %[r0], r8 \n\t"     /* r0 = (num_words - 1) * 4 */ |  | ||||||
|         "subs %[r6], %[r0] \n\t" /* r6 = i = k - (num_words - 1) (times 4) */ |  | ||||||
|          |  | ||||||
|         "3: \n\t" /* inner loop */ |  | ||||||
|         "mov r10, %[r2] \n\t" |  | ||||||
|         "mov r11, %[r3] \n\t" |  | ||||||
|         "mov r12, %[r4] \n\t" |  | ||||||
|         "mov r14, %[r5] \n\t" |  | ||||||
|         "subs %[r7], %[r5], %[r6] \n\t"  /* r7 = k - i */ |  | ||||||
|          |  | ||||||
|         "ldr %[r3], [%[r1], %[r7]] \n\t" /* r3 = left[k - i] */ |  | ||||||
|         "ldr %[r0], [%[r1], %[r6]] \n\t" /* r0 = left[i] */ |  | ||||||
|          |  | ||||||
|         "lsrs %[r2], %[r0], #16 \n\t" /* r2 = a1 */ |  | ||||||
|         "uxth %[r0], %[r0] \n\t"      /* r0 = a0 */ |  | ||||||
|          |  | ||||||
|         "lsrs %[r4], %[r3], #16 \n\t" /* r4 = b1 */ |  | ||||||
|         "uxth %[r3], %[r3] \n\t"      /* r3 = b0 */ |  | ||||||
|          |  | ||||||
|         "movs %[r5], %[r2] \n\t"        /* r5 = a1 */ |  | ||||||
|         "muls %[r5], %[r4], %[r5] \n\t" /* r5 = a1 * b1 */ |  | ||||||
|         "muls %[r2], %[r3], %[r2] \n\t" /* r2 = b0 * a1 */ |  | ||||||
|         "muls %[r4], %[r0], %[r4] \n\t" /* r4 = a0 * b1 */ |  | ||||||
|         "muls %[r0], %[r3], %[r0] \n\t" /* r0 = a0 * b0 */ |  | ||||||
|          |  | ||||||
|         /* Add middle terms */ |  | ||||||
|         "lsls %[r3], %[r2], #16 \n\t" |  | ||||||
|         "lsrs %[r2], %[r2], #16 \n\t" |  | ||||||
|         "adds %[r0], %[r3] \n\t" |  | ||||||
|         "adcs %[r5], %[r2] \n\t" |  | ||||||
|          |  | ||||||
|         "lsls %[r3], %[r4], #16 \n\t" |  | ||||||
|         "lsrs %[r4], %[r4], #16 \n\t" |  | ||||||
|         "adds %[r0], %[r3] \n\t" |  | ||||||
|         "adcs %[r5], %[r4] \n\t" |  | ||||||
|          |  | ||||||
|         /* Add to acc, doubling if necessary */ |  | ||||||
|         "mov %[r2], r10\n\t" |  | ||||||
|         "mov %[r3], r11\n\t" |  | ||||||
|         "mov %[r4], r12\n\t" |  | ||||||
|          |  | ||||||
|         "cmp %[r6], %[r7] \n\t"    /* (i < k - i) ? */ |  | ||||||
|         "bge 4f \n\t"            /*   if i >= k - i, skip */ |  | ||||||
|         "movs %[r7], #0 \n\t"    /* r7 = 0 */ |  | ||||||
|         "adds %[r2], %[r0] \n\t" /* add low word to c0 */ |  | ||||||
|         "adcs %[r3], %[r5] \n\t" /* add high word to c1, including carry */ |  | ||||||
|         "adcs %[r4], %[r7] \n\t" /* add carry to c2 */ |  | ||||||
|         "4: \n\t" |  | ||||||
|         "movs %[r7], #0 \n\t"    /* r7 = 0 */ |  | ||||||
|         "adds %[r2], %[r0] \n\t" /* add low word to c0 */ |  | ||||||
|         "adcs %[r3], %[r5] \n\t" /* add high word to c1, including carry */ |  | ||||||
|         "adcs %[r4], %[r7] \n\t" /* add carry to c2 */ |  | ||||||
|          |  | ||||||
|         "mov %[r5], r14\n\t" /* r5 = k */ |  | ||||||
|          |  | ||||||
|         "adds %[r6], #4 \n\t"           /* i += 4 */ |  | ||||||
|         "cmp %[r6], %[r5] \n\t"         /* i >= k? */ |  | ||||||
|         "bge 5f \n\t"                   /*   if so, exit the loop */ |  | ||||||
|         "subs %[r7], %[r5], %[r6] \n\t" /* r7 = k - i */ |  | ||||||
|         "cmp %[r6], %[r7] \n\t"         /* i <= k - i? */ |  | ||||||
|         "ble 3b \n\t"                   /*   if so, continue looping */ |  | ||||||
|          |  | ||||||
|         "5: \n\t" /* end inner loop */ |  | ||||||
|          |  | ||||||
|         "ldr %[r0], [sp, #0] \n\t" /* r0 = result */ |  | ||||||
|          |  | ||||||
|         "str %[r2], [%[r0], %[r5]] \n\t" /* result[k] = c0 */ |  | ||||||
|         "mov %[r2], %[r3] \n\t"          /* c0 = c1 */ |  | ||||||
|         "mov %[r3], %[r4] \n\t"          /* c1 = c2 */ |  | ||||||
|         "movs %[r4], #0 \n\t"            /* c2 = 0 */ |  | ||||||
|         "adds %[r5], #4 \n\t"            /* k += 4 */ |  | ||||||
|         "cmp %[r5], r8 \n\t"             /* k <= (num_words - 1) (times 4) ? */ |  | ||||||
|         "ble 1b \n\t"                    /*   if so, loop back, start with i = 0 */ |  | ||||||
|         "cmp %[r5], r9 \n\t"             /* k <= (num_words * 2 - 2) (times 4) ? */ |  | ||||||
|         "ble 2b \n\t"                    /*   if so, loop back, with i = (k + 1) - num_words */ |  | ||||||
|         /* end outer loop */ |  | ||||||
|          |  | ||||||
|         "str %[r2], [%[r0], %[r5]] \n\t" /* result[num_words * 2 - 1] = c0 */ |  | ||||||
|         "pop {%[r0]} \n\t"               /* pop result off the stack */ |  | ||||||
| 
 |  | ||||||
|         ".syntax divided \n\t" |  | ||||||
|         : [r2] "+l" (num_words), [r3] "=&l" (r3), [r4] "=&l" (r4), |  | ||||||
|           [r5] "=&l" (r5), [r6] "=&l" (r6), [r7] "=&l" (r7) |  | ||||||
|         : [r0] "l" (result), [r1] "l" (left) |  | ||||||
|         : "r8", "r9", "r10", "r11", "r12", "r14", "cc", "memory" |  | ||||||
|     ); |  | ||||||
| #endif
 |  | ||||||
| } |  | ||||||
| #define asm_square 1
 |  | ||||||
| #endif
 |  | ||||||
| #endif /* uECC_SQUARE_FUNC */
 |  | ||||||
| 
 |  | ||||||
| #endif /* _UECC_ASM_ARM_H_ */
 |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -1,94 +0,0 @@ | |||||||
| /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ |  | ||||||
| 
 |  | ||||||
| #ifndef _UECC_PLATFORM_SPECIFIC_H_
 |  | ||||||
| #define _UECC_PLATFORM_SPECIFIC_H_
 |  | ||||||
| 
 |  | ||||||
| #include "types.h"
 |  | ||||||
| 
 |  | ||||||
| #if (defined(_WIN32) || defined(_WIN64))
 |  | ||||||
| /* Windows */ |  | ||||||
| 
 |  | ||||||
| // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function
 |  | ||||||
| #pragma comment(lib, "crypt32.lib")
 |  | ||||||
| #pragma comment(lib, "advapi32.lib")
 |  | ||||||
| 
 |  | ||||||
| #define WIN32_LEAN_AND_MEAN
 |  | ||||||
| #include <windows.h>
 |  | ||||||
| #include <wincrypt.h>
 |  | ||||||
| 
 |  | ||||||
| static int default_RNG(uint8_t *dest, unsigned size) { |  | ||||||
|     HCRYPTPROV prov; |  | ||||||
|     if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     CryptGenRandom(prov, size, (BYTE *)dest); |  | ||||||
|     CryptReleaseContext(prov, 0); |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| #define default_RNG_defined 1
 |  | ||||||
| 
 |  | ||||||
| #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \
 |  | ||||||
|     (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) |  | ||||||
| 
 |  | ||||||
| /* Some POSIX-like system with /dev/urandom or /dev/random. */ |  | ||||||
| #include <sys/types.h>
 |  | ||||||
| #include <fcntl.h>
 |  | ||||||
| #include <unistd.h>
 |  | ||||||
| 
 |  | ||||||
| #ifndef O_CLOEXEC
 |  | ||||||
|     #define O_CLOEXEC 0
 |  | ||||||
| #endif
 |  | ||||||
| 
 |  | ||||||
| static int default_RNG(uint8_t *dest, unsigned size) { |  | ||||||
|     int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); |  | ||||||
|     if (fd == -1) { |  | ||||||
|         fd = open("/dev/random", O_RDONLY | O_CLOEXEC); |  | ||||||
|         if (fd == -1) { |  | ||||||
|             return 0; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     char *ptr = (char *)dest; |  | ||||||
|     size_t left = size; |  | ||||||
|     while (left > 0) { |  | ||||||
|         ssize_t bytes_read = read(fd, ptr, left); |  | ||||||
|         if (bytes_read <= 0) { // read failed
 |  | ||||||
|             close(fd); |  | ||||||
|             return 0; |  | ||||||
|         } |  | ||||||
|         left -= bytes_read; |  | ||||||
|         ptr += bytes_read; |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     close(fd); |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| #define default_RNG_defined 1
 |  | ||||||
| 
 |  | ||||||
| #elif defined(RIOT_VERSION)
 |  | ||||||
| 
 |  | ||||||
| #include <random.h>
 |  | ||||||
| 
 |  | ||||||
| static int default_RNG(uint8_t *dest, unsigned size) { |  | ||||||
|     random_bytes(dest, size); |  | ||||||
|     return 1; |  | ||||||
| } |  | ||||||
| #define default_RNG_defined 1
 |  | ||||||
| 
 |  | ||||||
| #elif defined(NRF52_SERIES)
 |  | ||||||
| 
 |  | ||||||
| #include "app_error.h"
 |  | ||||||
| #include "nrf_crypto_rng.h"
 |  | ||||||
| 
 |  | ||||||
| static int default_RNG(uint8_t *dest, unsigned size)  |  | ||||||
| { |  | ||||||
|     // make sure to call nrf_crypto_init and nrf_crypto_rng_init first
 |  | ||||||
|     ret_code_t ret_code = nrf_crypto_rng_vector_generate(dest, size); |  | ||||||
|     return (ret_code == NRF_SUCCESS) ? 1 : 0; |  | ||||||
| } |  | ||||||
| #define default_RNG_defined 1
 |  | ||||||
| 
 |  | ||||||
| #endif /* platform */
 |  | ||||||
| 
 |  | ||||||
| #endif /* _UECC_PLATFORM_SPECIFIC_H_ */
 |  | ||||||
| @ -1,108 +0,0 @@ | |||||||
| /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ |  | ||||||
| 
 |  | ||||||
| #ifndef _UECC_TYPES_H_ |  | ||||||
| #define _UECC_TYPES_H_ |  | ||||||
| 
 |  | ||||||
| #ifndef uECC_PLATFORM |  | ||||||
|     #if __AVR__ |  | ||||||
|         #define uECC_PLATFORM uECC_avr |  | ||||||
|     #elif defined(__thumb2__) || defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */ |  | ||||||
|         #define uECC_PLATFORM uECC_arm_thumb2 |  | ||||||
|     #elif defined(__thumb__) |  | ||||||
|         #define uECC_PLATFORM uECC_arm_thumb |  | ||||||
|     #elif defined(__arm__) || defined(_M_ARM) |  | ||||||
|         #define uECC_PLATFORM uECC_arm |  | ||||||
|     #elif defined(__aarch64__) |  | ||||||
|         #define uECC_PLATFORM uECC_arm64 |  | ||||||
|     #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__) |  | ||||||
|         #define uECC_PLATFORM uECC_x86 |  | ||||||
|     #elif defined(__amd64__) || defined(_M_X64) |  | ||||||
|         #define uECC_PLATFORM uECC_x86_64 |  | ||||||
|     #else |  | ||||||
|         #define uECC_PLATFORM uECC_arch_other |  | ||||||
|     #endif |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #ifndef uECC_ARM_USE_UMAAL |  | ||||||
|     #if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6) |  | ||||||
|         #define uECC_ARM_USE_UMAAL 1 |  | ||||||
|     #elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && !__ARM_ARCH_7M__ |  | ||||||
|         #define uECC_ARM_USE_UMAAL 1 |  | ||||||
|     #else |  | ||||||
|         #define uECC_ARM_USE_UMAAL 0 |  | ||||||
|     #endif |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #ifndef uECC_WORD_SIZE |  | ||||||
|     #if uECC_PLATFORM == uECC_avr |  | ||||||
|         #define uECC_WORD_SIZE 1 |  | ||||||
|     #elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64) |  | ||||||
|         #define uECC_WORD_SIZE 8 |  | ||||||
|     #else |  | ||||||
|         #define uECC_WORD_SIZE 4 |  | ||||||
|     #endif |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8) |  | ||||||
|     #error "Unsupported value for uECC_WORD_SIZE" |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1)) |  | ||||||
|     #pragma message ("uECC_WORD_SIZE must be 1 for AVR") |  | ||||||
|     #undef uECC_WORD_SIZE |  | ||||||
|     #define uECC_WORD_SIZE 1 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \ |  | ||||||
|         uECC_PLATFORM ==  uECC_arm_thumb2) && \ |  | ||||||
|      (uECC_WORD_SIZE != 4)) |  | ||||||
|     #pragma message ("uECC_WORD_SIZE must be 4 for ARM") |  | ||||||
|     #undef uECC_WORD_SIZE |  | ||||||
|     #define uECC_WORD_SIZE 4 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if defined(__SIZEOF_INT128__) || ((__clang_major__ * 100 + __clang_minor__) >= 302) |  | ||||||
|     #define SUPPORTS_INT128 1 |  | ||||||
| #else |  | ||||||
|     #define SUPPORTS_INT128 0 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| typedef int8_t wordcount_t; |  | ||||||
| typedef int16_t bitcount_t; |  | ||||||
| typedef int8_t cmpresult_t; |  | ||||||
| 
 |  | ||||||
| #if (uECC_WORD_SIZE == 1) |  | ||||||
| 
 |  | ||||||
| typedef uint8_t uECC_word_t; |  | ||||||
| typedef uint16_t uECC_dword_t; |  | ||||||
| 
 |  | ||||||
| #define HIGH_BIT_SET 0x80 |  | ||||||
| #define uECC_WORD_BITS 8 |  | ||||||
| #define uECC_WORD_BITS_SHIFT 3 |  | ||||||
| #define uECC_WORD_BITS_MASK 0x07 |  | ||||||
| 
 |  | ||||||
| #elif (uECC_WORD_SIZE == 4) |  | ||||||
| 
 |  | ||||||
| typedef uint32_t uECC_word_t; |  | ||||||
| typedef uint64_t uECC_dword_t; |  | ||||||
| 
 |  | ||||||
| #define HIGH_BIT_SET 0x80000000 |  | ||||||
| #define uECC_WORD_BITS 32 |  | ||||||
| #define uECC_WORD_BITS_SHIFT 5 |  | ||||||
| #define uECC_WORD_BITS_MASK 0x01F |  | ||||||
| 
 |  | ||||||
| #elif (uECC_WORD_SIZE == 8) |  | ||||||
| 
 |  | ||||||
| typedef uint64_t uECC_word_t; |  | ||||||
| #if SUPPORTS_INT128 |  | ||||||
| typedef unsigned __int128 uECC_dword_t; |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #define HIGH_BIT_SET 0x8000000000000000ull |  | ||||||
| #define uECC_WORD_BITS 64 |  | ||||||
| #define uECC_WORD_BITS_SHIFT 6 |  | ||||||
| #define uECC_WORD_BITS_MASK 0x03F |  | ||||||
| 
 |  | ||||||
| #endif /* uECC_WORD_SIZE */ |  | ||||||
| 
 |  | ||||||
| #endif /* _UECC_TYPES_H_ */ |  | ||||||
							
								
								
									
										1669
									
								
								lib/micro-ecc/uECC.c
									
									
									
									
									
								
							
							
						
						
									
										1669
									
								
								lib/micro-ecc/uECC.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -1,367 +0,0 @@ | |||||||
| /* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */ |  | ||||||
| 
 |  | ||||||
| #ifndef _UECC_H_ |  | ||||||
| #define _UECC_H_ |  | ||||||
| 
 |  | ||||||
| #include <stdint.h> |  | ||||||
| 
 |  | ||||||
| /* Platform selection options.
 |  | ||||||
| If uECC_PLATFORM is not defined, the code will try to guess it based on compiler macros. |  | ||||||
| Possible values for uECC_PLATFORM are defined below: */ |  | ||||||
| #define uECC_arch_other 0 |  | ||||||
| #define uECC_x86        1 |  | ||||||
| #define uECC_x86_64     2 |  | ||||||
| #define uECC_arm        3 |  | ||||||
| #define uECC_arm_thumb  4 |  | ||||||
| #define uECC_arm_thumb2 5 |  | ||||||
| #define uECC_arm64      6 |  | ||||||
| #define uECC_avr        7 |  | ||||||
| 
 |  | ||||||
| /* If desired, you can define uECC_WORD_SIZE as appropriate for your platform (1, 4, or 8 bytes).
 |  | ||||||
| If uECC_WORD_SIZE is not explicitly defined then it will be automatically set based on your |  | ||||||
| platform. */ |  | ||||||
| 
 |  | ||||||
| /* Optimization level; trade speed for code size.
 |  | ||||||
|    Larger values produce code that is faster but larger. |  | ||||||
|    Currently supported values are 0 - 4; 0 is unusably slow for most applications. |  | ||||||
|    Optimization level 4 currently only has an effect ARM platforms where more than one |  | ||||||
|    curve is enabled. */ |  | ||||||
| #ifndef uECC_OPTIMIZATION_LEVEL |  | ||||||
|     #define uECC_OPTIMIZATION_LEVEL 2 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /* uECC_SQUARE_FUNC - If enabled (defined as nonzero), this will cause a specific function to be
 |  | ||||||
| used for (scalar) squaring instead of the generic multiplication function. This can make things |  | ||||||
| faster somewhat faster, but increases the code size. */ |  | ||||||
| #ifndef uECC_SQUARE_FUNC |  | ||||||
|     #define uECC_SQUARE_FUNC 0 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /* uECC_VLI_NATIVE_LITTLE_ENDIAN - If enabled (defined as nonzero), this will switch to native
 |  | ||||||
| little-endian format for *all* arrays passed in and out of the public API. This includes public |  | ||||||
| and private keys, shared secrets, signatures and message hashes. |  | ||||||
| Using this switch reduces the amount of call stack memory used by uECC, since less intermediate |  | ||||||
| translations are required. |  | ||||||
| Note that this will *only* work on native little-endian processors and it will treat the uint8_t |  | ||||||
| arrays passed into the public API as word arrays, therefore requiring the provided byte arrays |  | ||||||
| to be word aligned on architectures that do not support unaligned accesses. |  | ||||||
| IMPORTANT: Keys and signatures generated with uECC_VLI_NATIVE_LITTLE_ENDIAN=1 are incompatible |  | ||||||
| with keys and signatures generated with uECC_VLI_NATIVE_LITTLE_ENDIAN=0; all parties must use |  | ||||||
| the same endianness. */ |  | ||||||
| #ifndef uECC_VLI_NATIVE_LITTLE_ENDIAN |  | ||||||
|     #define uECC_VLI_NATIVE_LITTLE_ENDIAN 0 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /* Curve support selection. Set to 0 to remove that curve. */ |  | ||||||
| #ifndef uECC_SUPPORTS_secp160r1 |  | ||||||
|     #define uECC_SUPPORTS_secp160r1 1 |  | ||||||
| #endif |  | ||||||
| #ifndef uECC_SUPPORTS_secp192r1 |  | ||||||
|     #define uECC_SUPPORTS_secp192r1 1 |  | ||||||
| #endif |  | ||||||
| #ifndef uECC_SUPPORTS_secp224r1 |  | ||||||
|     #define uECC_SUPPORTS_secp224r1 1 |  | ||||||
| #endif |  | ||||||
| #ifndef uECC_SUPPORTS_secp256r1 |  | ||||||
|     #define uECC_SUPPORTS_secp256r1 1 |  | ||||||
| #endif |  | ||||||
| #ifndef uECC_SUPPORTS_secp256k1 |  | ||||||
|     #define uECC_SUPPORTS_secp256k1 1 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /* Specifies whether compressed point format is supported.
 |  | ||||||
|    Set to 0 to disable point compression/decompression functions. */ |  | ||||||
| #ifndef uECC_SUPPORT_COMPRESSED_POINT |  | ||||||
|     #define uECC_SUPPORT_COMPRESSED_POINT 1 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| struct uECC_Curve_t; |  | ||||||
| typedef const struct uECC_Curve_t * uECC_Curve; |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" |  | ||||||
| { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if uECC_SUPPORTS_secp160r1 |  | ||||||
| uECC_Curve uECC_secp160r1(void); |  | ||||||
| #endif |  | ||||||
| #if uECC_SUPPORTS_secp192r1 |  | ||||||
| uECC_Curve uECC_secp192r1(void); |  | ||||||
| #endif |  | ||||||
| #if uECC_SUPPORTS_secp224r1 |  | ||||||
| uECC_Curve uECC_secp224r1(void); |  | ||||||
| #endif |  | ||||||
| #if uECC_SUPPORTS_secp256r1 |  | ||||||
| uECC_Curve uECC_secp256r1(void); |  | ||||||
| #endif |  | ||||||
| #if uECC_SUPPORTS_secp256k1 |  | ||||||
| uECC_Curve uECC_secp256k1(void); |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /* uECC_RNG_Function type
 |  | ||||||
| The RNG function should fill 'size' random bytes into 'dest'. It should return 1 if |  | ||||||
| 'dest' was filled with random data, or 0 if the random data could not be generated. |  | ||||||
| The filled-in values should be either truly random, or from a cryptographically-secure PRNG. |  | ||||||
| 
 |  | ||||||
| A correctly functioning RNG function must be set (using uECC_set_rng()) before calling |  | ||||||
| uECC_make_key() or uECC_sign(). |  | ||||||
| 
 |  | ||||||
| Setting a correctly functioning RNG function improves the resistance to side-channel attacks |  | ||||||
| for uECC_shared_secret() and uECC_sign_deterministic(). |  | ||||||
| 
 |  | ||||||
| A correct RNG function is set by default when building for Windows, Linux, or OS X. |  | ||||||
| If you are building on another POSIX-compliant system that supports /dev/random or /dev/urandom, |  | ||||||
| you can define uECC_POSIX to use the predefined RNG. For embedded platforms there is no predefined |  | ||||||
| RNG function; you must provide your own. |  | ||||||
| */ |  | ||||||
| typedef int (*uECC_RNG_Function)(uint8_t *dest, unsigned size); |  | ||||||
| 
 |  | ||||||
| /* uECC_set_rng() function.
 |  | ||||||
| Set the function that will be used to generate random bytes. The RNG function should |  | ||||||
| return 1 if the random data was generated, or 0 if the random data could not be generated. |  | ||||||
| 
 |  | ||||||
| On platforms where there is no predefined RNG function (eg embedded platforms), this must |  | ||||||
| be called before uECC_make_key() or uECC_sign() are used. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     rng_function - The function that will be used to generate random bytes. |  | ||||||
| */ |  | ||||||
| void uECC_set_rng(uECC_RNG_Function rng_function); |  | ||||||
| 
 |  | ||||||
| /* uECC_get_rng() function.
 |  | ||||||
| 
 |  | ||||||
| Returns the function that will be used to generate random bytes. |  | ||||||
| */ |  | ||||||
| uECC_RNG_Function uECC_get_rng(void); |  | ||||||
| 
 |  | ||||||
| /* uECC_curve_private_key_size() function.
 |  | ||||||
| 
 |  | ||||||
| Returns the size of a private key for the curve in bytes. |  | ||||||
| */ |  | ||||||
| int uECC_curve_private_key_size(uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_curve_public_key_size() function.
 |  | ||||||
| 
 |  | ||||||
| Returns the size of a public key for the curve in bytes. |  | ||||||
| */ |  | ||||||
| int uECC_curve_public_key_size(uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_make_key() function.
 |  | ||||||
| Create a public/private key pair. |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     public_key  - Will be filled in with the public key. Must be at least 2 * the curve size |  | ||||||
|                   (in bytes) long. For example, if the curve is secp256r1, public_key must be 64 |  | ||||||
|                   bytes long. |  | ||||||
|     private_key - Will be filled in with the private key. Must be as long as the curve order; this |  | ||||||
|                   is typically the same as the curve size, except for secp160r1. For example, if the |  | ||||||
|                   curve is secp256r1, private_key must be 32 bytes long. |  | ||||||
| 
 |  | ||||||
|                   For secp160r1, private_key must be 21 bytes long! Note that the first byte will |  | ||||||
|                   almost always be 0 (there is about a 1 in 2^80 chance of it being non-zero). |  | ||||||
| 
 |  | ||||||
| Returns 1 if the key pair was generated successfully, 0 if an error occurred. |  | ||||||
| */ |  | ||||||
| int uECC_make_key(uint8_t *public_key, uint8_t *private_key, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_shared_secret() function.
 |  | ||||||
| Compute a shared secret given your secret key and someone else's public key. If the public key |  | ||||||
| is not from a trusted source and has not been previously verified, you should verify it first |  | ||||||
| using uECC_valid_public_key(). |  | ||||||
| Note: It is recommended that you hash the result of uECC_shared_secret() before using it for |  | ||||||
| symmetric encryption or HMAC. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     public_key  - The public key of the remote party. |  | ||||||
|     private_key - Your private key. |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     secret - Will be filled in with the shared secret value. Must be the same size as the |  | ||||||
|              curve size; for example, if the curve is secp256r1, secret must be 32 bytes long. |  | ||||||
| 
 |  | ||||||
| Returns 1 if the shared secret was generated successfully, 0 if an error occurred. |  | ||||||
| */ |  | ||||||
| int uECC_shared_secret(const uint8_t *public_key, |  | ||||||
|                        const uint8_t *private_key, |  | ||||||
|                        uint8_t *secret, |  | ||||||
|                        uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| #if uECC_SUPPORT_COMPRESSED_POINT |  | ||||||
| /* uECC_compress() function.
 |  | ||||||
| Compress a public key. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     public_key - The public key to compress. |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     compressed - Will be filled in with the compressed public key. Must be at least |  | ||||||
|                  (curve size + 1) bytes long; for example, if the curve is secp256r1, |  | ||||||
|                  compressed must be 33 bytes long. |  | ||||||
| */ |  | ||||||
| void uECC_compress(const uint8_t *public_key, uint8_t *compressed, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_decompress() function.
 |  | ||||||
| Decompress a compressed public key. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     compressed - The compressed public key. |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     public_key - Will be filled in with the decompressed public key. |  | ||||||
| */ |  | ||||||
| void uECC_decompress(const uint8_t *compressed, uint8_t *public_key, uECC_Curve curve); |  | ||||||
| #endif /* uECC_SUPPORT_COMPRESSED_POINT */ |  | ||||||
| 
 |  | ||||||
| /* uECC_valid_public_key() function.
 |  | ||||||
| Check to see if a public key is valid. |  | ||||||
| 
 |  | ||||||
| Note that you are not required to check for a valid public key before using any other uECC |  | ||||||
| functions. However, you may wish to avoid spending CPU time computing a shared secret or |  | ||||||
| verifying a signature using an invalid public key. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     public_key - The public key to check. |  | ||||||
| 
 |  | ||||||
| Returns 1 if the public key is valid, 0 if it is invalid. |  | ||||||
| */ |  | ||||||
| int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_compute_public_key() function.
 |  | ||||||
| Compute the corresponding public key for a private key. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     private_key - The private key to compute the public key for |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     public_key - Will be filled in with the corresponding public key |  | ||||||
| 
 |  | ||||||
| Returns 1 if the key was computed successfully, 0 if an error occurred. |  | ||||||
| */ |  | ||||||
| int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_sign() function.
 |  | ||||||
| Generate an ECDSA signature for a given hash value. |  | ||||||
| 
 |  | ||||||
| Usage: Compute a hash of the data you wish to sign (SHA-2 is recommended) and pass it in to |  | ||||||
| this function along with your private key. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     private_key  - Your private key. |  | ||||||
|     message_hash - The hash of the message to sign. |  | ||||||
|     hash_size    - The size of message_hash in bytes. |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     signature - Will be filled in with the signature value. Must be at least 2 * curve size long. |  | ||||||
|                 For example, if the curve is secp256r1, signature must be 64 bytes long. |  | ||||||
| 
 |  | ||||||
| Returns 1 if the signature generated successfully, 0 if an error occurred. |  | ||||||
| */ |  | ||||||
| int uECC_sign(const uint8_t *private_key, |  | ||||||
|               const uint8_t *message_hash, |  | ||||||
|               unsigned hash_size, |  | ||||||
|               uint8_t *signature, |  | ||||||
|               uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_HashContext structure.
 |  | ||||||
| This is used to pass in an arbitrary hash function to uECC_sign_deterministic(). |  | ||||||
| The structure will be used for multiple hash computations; each time a new hash |  | ||||||
| is computed, init_hash() will be called, followed by one or more calls to |  | ||||||
| update_hash(), and finally a call to finish_hash() to produce the resulting hash. |  | ||||||
| 
 |  | ||||||
| The intention is that you will create a structure that includes uECC_HashContext |  | ||||||
| followed by any hash-specific data. For example: |  | ||||||
| 
 |  | ||||||
| typedef struct SHA256_HashContext { |  | ||||||
|     uECC_HashContext uECC; |  | ||||||
|     SHA256_CTX ctx; |  | ||||||
| } SHA256_HashContext; |  | ||||||
| 
 |  | ||||||
| void init_SHA256(uECC_HashContext *base) { |  | ||||||
|     SHA256_HashContext *context = (SHA256_HashContext *)base; |  | ||||||
|     SHA256_Init(&context->ctx); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void update_SHA256(uECC_HashContext *base, |  | ||||||
|                    const uint8_t *message, |  | ||||||
|                    unsigned message_size) { |  | ||||||
|     SHA256_HashContext *context = (SHA256_HashContext *)base; |  | ||||||
|     SHA256_Update(&context->ctx, message, message_size); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void finish_SHA256(uECC_HashContext *base, uint8_t *hash_result) { |  | ||||||
|     SHA256_HashContext *context = (SHA256_HashContext *)base; |  | ||||||
|     SHA256_Final(hash_result, &context->ctx); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ... when signing ... |  | ||||||
| { |  | ||||||
|     uint8_t tmp[32 + 32 + 64]; |  | ||||||
|     SHA256_HashContext ctx = {{&init_SHA256, &update_SHA256, &finish_SHA256, 64, 32, tmp}}; |  | ||||||
|     uECC_sign_deterministic(key, message_hash, &ctx.uECC, signature); |  | ||||||
| } |  | ||||||
| */ |  | ||||||
| typedef struct uECC_HashContext { |  | ||||||
|     void (*init_hash)(const struct uECC_HashContext *context); |  | ||||||
|     void (*update_hash)(const struct uECC_HashContext *context, |  | ||||||
|                         const uint8_t *message, |  | ||||||
|                         unsigned message_size); |  | ||||||
|     void (*finish_hash)(const struct uECC_HashContext *context, uint8_t *hash_result); |  | ||||||
|     unsigned block_size; /* Hash function block size in bytes, eg 64 for SHA-256. */ |  | ||||||
|     unsigned result_size; /* Hash function result size in bytes, eg 32 for SHA-256. */ |  | ||||||
|     uint8_t *tmp; /* Must point to a buffer of at least (2 * result_size + block_size) bytes. */ |  | ||||||
| } uECC_HashContext; |  | ||||||
| 
 |  | ||||||
| /* uECC_sign_deterministic() function.
 |  | ||||||
| Generate an ECDSA signature for a given hash value, using a deterministic algorithm |  | ||||||
| (see RFC 6979). You do not need to set the RNG using uECC_set_rng() before calling |  | ||||||
| this function; however, if the RNG is defined it will improve resistance to side-channel |  | ||||||
| attacks. |  | ||||||
| 
 |  | ||||||
| Usage: Compute a hash of the data you wish to sign (SHA-2 is recommended) and pass it to |  | ||||||
| this function along with your private key and a hash context. Note that the message_hash |  | ||||||
| does not need to be computed with the same hash function used by hash_context. |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     private_key  - Your private key. |  | ||||||
|     message_hash - The hash of the message to sign. |  | ||||||
|     hash_size    - The size of message_hash in bytes. |  | ||||||
|     hash_context - A hash context to use. |  | ||||||
| 
 |  | ||||||
| Outputs: |  | ||||||
|     signature - Will be filled in with the signature value. |  | ||||||
| 
 |  | ||||||
| Returns 1 if the signature generated successfully, 0 if an error occurred. |  | ||||||
| */ |  | ||||||
| int uECC_sign_deterministic(const uint8_t *private_key, |  | ||||||
|                             const uint8_t *message_hash, |  | ||||||
|                             unsigned hash_size, |  | ||||||
|                             const uECC_HashContext *hash_context, |  | ||||||
|                             uint8_t *signature, |  | ||||||
|                             uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* uECC_verify() function.
 |  | ||||||
| Verify an ECDSA signature. |  | ||||||
| 
 |  | ||||||
| Usage: Compute the hash of the signed data using the same hash as the signer and |  | ||||||
| pass it to this function along with the signer's public key and the signature values (r and s). |  | ||||||
| 
 |  | ||||||
| Inputs: |  | ||||||
|     public_key   - The signer's public key. |  | ||||||
|     message_hash - The hash of the signed data. |  | ||||||
|     hash_size    - The size of message_hash in bytes. |  | ||||||
|     signature    - The signature value. |  | ||||||
| 
 |  | ||||||
| Returns 1 if the signature is valid, 0 if it is invalid. |  | ||||||
| */ |  | ||||||
| int uECC_verify(const uint8_t *public_key, |  | ||||||
|                 const uint8_t *message_hash, |  | ||||||
|                 unsigned hash_size, |  | ||||||
|                 const uint8_t *signature, |  | ||||||
|                 uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } /* end of extern "C" */ |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #endif /* _UECC_H_ */ |  | ||||||
| @ -1,172 +0,0 @@ | |||||||
| /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ |  | ||||||
| 
 |  | ||||||
| #ifndef _UECC_VLI_H_ |  | ||||||
| #define _UECC_VLI_H_ |  | ||||||
| 
 |  | ||||||
| #include "uECC.h" |  | ||||||
| #include "types.h" |  | ||||||
| 
 |  | ||||||
| /* Functions for raw large-integer manipulation. These are only available
 |  | ||||||
|    if uECC.c is compiled with uECC_ENABLE_VLI_API defined to 1. */ |  | ||||||
| #ifndef uECC_ENABLE_VLI_API |  | ||||||
|     #define uECC_ENABLE_VLI_API 0 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" |  | ||||||
| { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if uECC_ENABLE_VLI_API |  | ||||||
| 
 |  | ||||||
| void uECC_vli_clear(uECC_word_t *vli, wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Constant-time comparison to zero - secure way to compare long integers */ |  | ||||||
| /* Returns 1 if vli == 0, 0 otherwise. */ |  | ||||||
| uECC_word_t uECC_vli_isZero(const uECC_word_t *vli, wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Returns nonzero if bit 'bit' of vli is set. */ |  | ||||||
| uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit); |  | ||||||
| 
 |  | ||||||
| /* Counts the number of bits required to represent vli. */ |  | ||||||
| bitcount_t uECC_vli_numBits(const uECC_word_t *vli, const wordcount_t max_words); |  | ||||||
| 
 |  | ||||||
| /* Sets dest = src. */ |  | ||||||
| void uECC_vli_set(uECC_word_t *dest, const uECC_word_t *src, wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Constant-time comparison function - secure way to compare long integers */ |  | ||||||
| /* Returns one if left == right, zero otherwise */ |  | ||||||
| uECC_word_t uECC_vli_equal(const uECC_word_t *left, |  | ||||||
|                            const uECC_word_t *right, |  | ||||||
|                            wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Constant-time comparison function - secure way to compare long integers */ |  | ||||||
| /* Returns sign of left - right, in constant time. */ |  | ||||||
| cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right, wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes vli = vli >> 1. */ |  | ||||||
| void uECC_vli_rshift1(uECC_word_t *vli, wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = left + right, returning carry. Can modify in place. */ |  | ||||||
| uECC_word_t uECC_vli_add(uECC_word_t *result, |  | ||||||
|                          const uECC_word_t *left, |  | ||||||
|                          const uECC_word_t *right, |  | ||||||
|                          wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = left - right, returning borrow. Can modify in place. */ |  | ||||||
| uECC_word_t uECC_vli_sub(uECC_word_t *result, |  | ||||||
|                          const uECC_word_t *left, |  | ||||||
|                          const uECC_word_t *right, |  | ||||||
|                          wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = left * right. Result must be 2 * num_words long. */ |  | ||||||
| void uECC_vli_mult(uECC_word_t *result, |  | ||||||
|                    const uECC_word_t *left, |  | ||||||
|                    const uECC_word_t *right, |  | ||||||
|                    wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = left^2. Result must be 2 * num_words long. */ |  | ||||||
| void uECC_vli_square(uECC_word_t *result, const uECC_word_t *left, wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = (left + right) % mod.
 |  | ||||||
|    Assumes that left < mod and right < mod, and that result does not overlap mod. */ |  | ||||||
| void uECC_vli_modAdd(uECC_word_t *result, |  | ||||||
|                      const uECC_word_t *left, |  | ||||||
|                      const uECC_word_t *right, |  | ||||||
|                      const uECC_word_t *mod, |  | ||||||
|                      wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = (left - right) % mod.
 |  | ||||||
|    Assumes that left < mod and right < mod, and that result does not overlap mod. */ |  | ||||||
| void uECC_vli_modSub(uECC_word_t *result, |  | ||||||
|                      const uECC_word_t *left, |  | ||||||
|                      const uECC_word_t *right, |  | ||||||
|                      const uECC_word_t *mod, |  | ||||||
|                      wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = product % mod, where product is 2N words long.
 |  | ||||||
|    Currently only designed to work for mod == curve->p or curve_n. */ |  | ||||||
| void uECC_vli_mmod(uECC_word_t *result, |  | ||||||
|                    uECC_word_t *product, |  | ||||||
|                    const uECC_word_t *mod, |  | ||||||
|                    wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Calculates result = product (mod curve->p), where product is up to
 |  | ||||||
|    2 * curve->num_words long. */ |  | ||||||
| void uECC_vli_mmod_fast(uECC_word_t *result, uECC_word_t *product, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* Computes result = (left * right) % mod.
 |  | ||||||
|    Currently only designed to work for mod == curve->p or curve_n. */ |  | ||||||
| void uECC_vli_modMult(uECC_word_t *result, |  | ||||||
|                       const uECC_word_t *left, |  | ||||||
|                       const uECC_word_t *right, |  | ||||||
|                       const uECC_word_t *mod, |  | ||||||
|                       wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = (left * right) % curve->p. */ |  | ||||||
| void uECC_vli_modMult_fast(uECC_word_t *result, |  | ||||||
|                            const uECC_word_t *left, |  | ||||||
|                            const uECC_word_t *right, |  | ||||||
|                            uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* Computes result = left^2 % mod.
 |  | ||||||
|    Currently only designed to work for mod == curve->p or curve_n. */ |  | ||||||
| void uECC_vli_modSquare(uECC_word_t *result, |  | ||||||
|                         const uECC_word_t *left, |  | ||||||
|                         const uECC_word_t *mod, |  | ||||||
|                         wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| /* Computes result = left^2 % curve->p. */ |  | ||||||
| void uECC_vli_modSquare_fast(uECC_word_t *result, const uECC_word_t *left, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* Computes result = (1 / input) % mod.*/ |  | ||||||
| void uECC_vli_modInv(uECC_word_t *result, |  | ||||||
|                      const uECC_word_t *input, |  | ||||||
|                      const uECC_word_t *mod, |  | ||||||
|                      wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| #if uECC_SUPPORT_COMPRESSED_POINT |  | ||||||
| /* Calculates a = sqrt(a) (mod curve->p) */ |  | ||||||
| void uECC_vli_mod_sqrt(uECC_word_t *a, uECC_Curve curve); |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /* Converts an integer in uECC native format to big-endian bytes. */ |  | ||||||
| void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes, const uECC_word_t *native); |  | ||||||
| /* Converts big-endian bytes to an integer in uECC native format. */ |  | ||||||
| void uECC_vli_bytesToNative(uECC_word_t *native, const uint8_t *bytes, int num_bytes); |  | ||||||
| 
 |  | ||||||
| unsigned uECC_curve_num_words(uECC_Curve curve); |  | ||||||
| unsigned uECC_curve_num_bytes(uECC_Curve curve); |  | ||||||
| unsigned uECC_curve_num_bits(uECC_Curve curve); |  | ||||||
| unsigned uECC_curve_num_n_words(uECC_Curve curve); |  | ||||||
| unsigned uECC_curve_num_n_bytes(uECC_Curve curve); |  | ||||||
| unsigned uECC_curve_num_n_bits(uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| const uECC_word_t *uECC_curve_p(uECC_Curve curve); |  | ||||||
| const uECC_word_t *uECC_curve_n(uECC_Curve curve); |  | ||||||
| const uECC_word_t *uECC_curve_G(uECC_Curve curve); |  | ||||||
| const uECC_word_t *uECC_curve_b(uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* Multiplies a point by a scalar. Points are represented by the X coordinate followed by
 |  | ||||||
|    the Y coordinate in the same array, both coordinates are curve->num_words long. Note |  | ||||||
|    that scalar must be curve->num_n_words long (NOT curve->num_words). */ |  | ||||||
| void uECC_point_mult(uECC_word_t *result, |  | ||||||
|                      const uECC_word_t *point, |  | ||||||
|                      const uECC_word_t *scalar, |  | ||||||
|                      uECC_Curve curve); |  | ||||||
| 
 |  | ||||||
| /* Generates a random integer in the range 0 < random < top.
 |  | ||||||
|    Both random and top have num_words words. */ |  | ||||||
| int uECC_generate_random_int(uECC_word_t *random, |  | ||||||
|                              const uECC_word_t *top, |  | ||||||
|                              wordcount_t num_words); |  | ||||||
| 
 |  | ||||||
| #endif /* uECC_ENABLE_VLI_API */ |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } /* end of extern "C" */ |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #endif /* _UECC_VLI_H_ */ |  | ||||||
| @ -14,7 +14,7 @@ libenv.Append( | |||||||
|     CPPDEFINES=["MICROTAR_DISABLE_API_CHECKS"], |     CPPDEFINES=["MICROTAR_DISABLE_API_CHECKS"], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| sources = libenv.GlobRecursive("*.c", "microtar/src") | sources = [File("microtar/src/microtar.c")] | ||||||
| 
 | 
 | ||||||
| lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | ||||||
| libenv.Install("${LIB_DIST_DIR}", lib) | libenv.Install("${LIB_DIST_DIR}", lib) | ||||||
|  | |||||||
| @ -1,58 +0,0 @@ | |||||||
| from fbt.util import GLOB_FILE_EXCLUSION |  | ||||||
| 
 |  | ||||||
| Import("env") |  | ||||||
| 
 |  | ||||||
| env.Append( |  | ||||||
|     CPPPATH=[ |  | ||||||
|         "#/lib/fnv1a_hash", |  | ||||||
|         "#/lib/heatshrink", |  | ||||||
|         "#/lib/micro-ecc", |  | ||||||
|         "#/lib/nanopb", |  | ||||||
|         "#/lib/u8g2", |  | ||||||
|     ], |  | ||||||
|     CPPDEFINES=[ |  | ||||||
|         "PB_ENABLE_MALLOC", |  | ||||||
|     ], |  | ||||||
|     SDK_HEADERS=[ |  | ||||||
|         File("micro-ecc/uECC.h"), |  | ||||||
|         File("nanopb/pb.h"), |  | ||||||
|         File("nanopb/pb_decode.h"), |  | ||||||
|         File("nanopb/pb_encode.h"), |  | ||||||
|     ], |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| libenv = env.Clone(FW_LIB_NAME="misc") |  | ||||||
| libenv.ApplyLibFlags() |  | ||||||
| 
 |  | ||||||
| sources = [] |  | ||||||
| 
 |  | ||||||
| libs_recurse = [ |  | ||||||
|     "micro-ecc", |  | ||||||
|     "u8g2", |  | ||||||
|     "update_util", |  | ||||||
| ] |  | ||||||
| 
 |  | ||||||
| for lib in libs_recurse: |  | ||||||
|     sources += libenv.GlobRecursive("*.c*", lib) |  | ||||||
| 
 |  | ||||||
| libs_plain = [ |  | ||||||
|     "nanopb", |  | ||||||
| ] |  | ||||||
| 
 |  | ||||||
| for lib in libs_plain: |  | ||||||
|     sources += Glob( |  | ||||||
|         lib + "/*.c*", |  | ||||||
|         exclude=GLOB_FILE_EXCLUSION, |  | ||||||
|         source=True, |  | ||||||
|     ) |  | ||||||
| 
 |  | ||||||
| sources += Glob( |  | ||||||
|     "heatshrink/heatshrink_*.c*", |  | ||||||
|     exclude=GLOB_FILE_EXCLUSION, |  | ||||||
|     source=True, |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) |  | ||||||
| libenv.Install("${LIB_DIST_DIR}", lib) |  | ||||||
| Return("lib") |  | ||||||
							
								
								
									
										27
									
								
								lib/mlib.scons
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								lib/mlib.scons
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | Import("env") | ||||||
|  | 
 | ||||||
|  | env.Append( | ||||||
|  |     CPPPATH=[ | ||||||
|  |         "#/lib/mlib", | ||||||
|  |     ], | ||||||
|  |     SDK_HEADERS=[ | ||||||
|  |         *( | ||||||
|  |             File(f"#/lib/mlib/m-{name}.h") | ||||||
|  |             for name in ( | ||||||
|  |                 "algo", | ||||||
|  |                 "array", | ||||||
|  |                 "bptree", | ||||||
|  |                 "core", | ||||||
|  |                 "deque", | ||||||
|  |                 "dict", | ||||||
|  |                 "list", | ||||||
|  |                 "rbtree", | ||||||
|  |                 "tuple", | ||||||
|  |                 "variant", | ||||||
|  |             ) | ||||||
|  |         ), | ||||||
|  |     ], | ||||||
|  |     CPPDEFINES=[ | ||||||
|  |         '"M_MEMORY_FULL(x)=abort()"', | ||||||
|  |     ], | ||||||
|  | ) | ||||||
| @ -7,6 +7,9 @@ env.Append( | |||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("music_worker.h"), |         File("music_worker.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| libenv = env.Clone(FW_LIB_NAME="music_worker") | libenv = env.Clone(FW_LIB_NAME="music_worker") | ||||||
|  | |||||||
							
								
								
									
										31
									
								
								lib/nanopb.scons
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								lib/nanopb.scons
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | |||||||
|  | from fbt.util import GLOB_FILE_EXCLUSION | ||||||
|  | 
 | ||||||
|  | Import("env") | ||||||
|  | 
 | ||||||
|  | env.Append( | ||||||
|  |     CPPPATH=[ | ||||||
|  |         "#/lib/nanopb", | ||||||
|  |     ], | ||||||
|  |     CPPDEFINES=[ | ||||||
|  |         "PB_ENABLE_MALLOC", | ||||||
|  |     ], | ||||||
|  |     SDK_HEADERS=[ | ||||||
|  |         File("nanopb/pb.h"), | ||||||
|  |         File("nanopb/pb_decode.h"), | ||||||
|  |         File("nanopb/pb_encode.h"), | ||||||
|  |     ], | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | libenv = env.Clone(FW_LIB_NAME="nanopb") | ||||||
|  | libenv.ApplyLibFlags() | ||||||
|  | 
 | ||||||
|  | sources = Glob( | ||||||
|  |     "nanopb/*.c*", | ||||||
|  |     exclude=GLOB_FILE_EXCLUSION, | ||||||
|  |     source=True, | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | ||||||
|  | libenv.Install("${LIB_DIST_DIR}", lib) | ||||||
|  | Return("lib") | ||||||
| @ -4,6 +4,9 @@ env.Append( | |||||||
|     CPPPATH=[ |     CPPPATH=[ | ||||||
|         "#/lib/nfc", |         "#/lib/nfc", | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         # Main |         # Main | ||||||
|         File("nfc.h"), |         File("nfc.h"), | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ bool mf_desfire_version_parse(MfDesfireVersion* data, const BitBuffer* buf) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool mf_desfire_free_memory_parse(MfDesfireFreeMemory* data, const BitBuffer* buf) { | bool mf_desfire_free_memory_parse(MfDesfireFreeMemory* data, const BitBuffer* buf) { | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         uint32_t bytes_free : 3 * BITS_IN_BYTE; |         uint32_t bytes_free : 3 * BITS_IN_BYTE; | ||||||
|     } MfDesfireFreeMemoryLayout; |     } MfDesfireFreeMemoryLayout; | ||||||
| 
 | 
 | ||||||
| @ -74,7 +74,7 @@ bool mf_desfire_free_memory_parse(MfDesfireFreeMemory* data, const BitBuffer* bu | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool mf_desfire_key_settings_parse(MfDesfireKeySettings* data, const BitBuffer* buf) { | bool mf_desfire_key_settings_parse(MfDesfireKeySettings* data, const BitBuffer* buf) { | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         bool is_master_key_changeable : 1; |         bool is_master_key_changeable : 1; | ||||||
|         bool is_free_directory_list : 1; |         bool is_free_directory_list : 1; | ||||||
|         bool is_free_create_delete : 1; |         bool is_free_create_delete : 1; | ||||||
| @ -143,30 +143,30 @@ bool mf_desfire_file_id_parse(MfDesfireFileId* data, uint32_t index, const BitBu | |||||||
| bool mf_desfire_file_settings_parse(MfDesfireFileSettings* data, const BitBuffer* buf) { | bool mf_desfire_file_settings_parse(MfDesfireFileSettings* data, const BitBuffer* buf) { | ||||||
|     bool parsed = false; |     bool parsed = false; | ||||||
| 
 | 
 | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         uint8_t type; |         uint8_t type; | ||||||
|         uint8_t comm; |         uint8_t comm; | ||||||
|         uint16_t access_rights; |         uint16_t access_rights; | ||||||
|     } MfDesfireFileSettingsHeader; |     } MfDesfireFileSettingsHeader; | ||||||
| 
 | 
 | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         uint32_t size : 3 * BITS_IN_BYTE; |         uint32_t size : 3 * BITS_IN_BYTE; | ||||||
|     } MfDesfireFileSettingsData; |     } MfDesfireFileSettingsData; | ||||||
| 
 | 
 | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         uint32_t lo_limit; |         uint32_t lo_limit; | ||||||
|         uint32_t hi_limit; |         uint32_t hi_limit; | ||||||
|         uint32_t limited_credit_value; |         uint32_t limited_credit_value; | ||||||
|         uint8_t limited_credit_enabled; |         uint8_t limited_credit_enabled; | ||||||
|     } MfDesfireFileSettingsValue; |     } MfDesfireFileSettingsValue; | ||||||
| 
 | 
 | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         uint32_t size : 3 * BITS_IN_BYTE; |         uint32_t size : 3 * BITS_IN_BYTE; | ||||||
|         uint32_t max : 3 * BITS_IN_BYTE; |         uint32_t max : 3 * BITS_IN_BYTE; | ||||||
|         uint32_t cur : 3 * BITS_IN_BYTE; |         uint32_t cur : 3 * BITS_IN_BYTE; | ||||||
|     } MfDesfireFileSettingsRecord; |     } MfDesfireFileSettingsRecord; | ||||||
| 
 | 
 | ||||||
|     typedef struct __attribute__((packed)) { |     typedef struct FURI_PACKED { | ||||||
|         MfDesfireFileSettingsHeader header; |         MfDesfireFileSettingsHeader header; | ||||||
|         union { |         union { | ||||||
|             MfDesfireFileSettingsData data; |             MfDesfireFileSettingsData data; | ||||||
|  | |||||||
| @ -130,7 +130,7 @@ typedef enum { | |||||||
|     MfUltralightMirrorUidCounter, |     MfUltralightMirrorUidCounter, | ||||||
| } MfUltralightMirrorConf; | } MfUltralightMirrorConf; | ||||||
| 
 | 
 | ||||||
| typedef struct __attribute__((packed)) { | typedef struct FURI_PACKED { | ||||||
|     union { |     union { | ||||||
|         uint8_t value; |         uint8_t value; | ||||||
|         struct { |         struct { | ||||||
|  | |||||||
| @ -100,6 +100,9 @@ env.Append( | |||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("wrappers.h"), |         File("wrappers.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| libenv = env.Clone(FW_LIB_NAME="print") | libenv = env.Clone(FW_LIB_NAME="print") | ||||||
|  | |||||||
| @ -7,6 +7,9 @@ env.Append( | |||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("pulse_reader.h"), |         File("pulse_reader.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| libenv = env.Clone(FW_LIB_NAME="pulse_reader") | libenv = env.Clone(FW_LIB_NAME="pulse_reader") | ||||||
|  | |||||||
| @ -1,975 +0,0 @@ | |||||||
| /**
 |  | ||||||
|  * The MIT License (MIT) |  | ||||||
|  * |  | ||||||
|  * This library is written and maintained by Richard Moore. |  | ||||||
|  * Major parts were derived from Project Nayuki's library. |  | ||||||
|  * |  | ||||||
|  * Copyright (c) 2017 Richard Moore     (https://github.com/ricmoo/QRCode)
 |  | ||||||
|  * Copyright (c) 2017 Project Nayuki    (https://www.nayuki.io/page/qr-code-generator-library)
 |  | ||||||
|  * |  | ||||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
|  * of this software and associated documentation files (the "Software"), to deal |  | ||||||
|  * in the Software without restriction, including without limitation the rights |  | ||||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
|  * copies of the Software, and to permit persons to whom the Software is |  | ||||||
|  * furnished to do so, subject to the following conditions: |  | ||||||
|  * |  | ||||||
|  * The above copyright notice and this permission notice shall be included in |  | ||||||
|  * all copies or substantial portions of the Software. |  | ||||||
|  * |  | ||||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |  | ||||||
|  * THE SOFTWARE. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *  Special thanks to Nayuki (https://www.nayuki.io/) from which this library was
 |  | ||||||
|  *  heavily inspired and compared against. |  | ||||||
|  * |  | ||||||
|  *  See: https://github.com/nayuki/QR-Code-generator/tree/master/cpp
 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #include "qrcode.h" |  | ||||||
| 
 |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include <string.h> |  | ||||||
| 
 |  | ||||||
| #pragma mark - Error Correction Lookup tables |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 |  | ||||||
| 
 |  | ||||||
| static const uint16_t NUM_ERROR_CORRECTION_CODEWORDS[4][40] = { |  | ||||||
|     // 1,  2,  3,  4,  5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,   25,   26,   27,   28,   29,   30,   31,   32,   33,   34,   35,   36,   37,   38,   39,   40    Error correction level
 |  | ||||||
|     {10,  16,  26,  36,  48,  64,   72,   88,   110,  130,  150,  176, 198, 216, |  | ||||||
|      240, 280, 308, 338, 364, 416,  442,  476,  504,  560,  588,  644, 700, 728, |  | ||||||
|      784, 812, 868, 924, 980, 1036, 1064, 1120, 1204, 1260, 1316, 1372}, // Medium
 |  | ||||||
|     {7,   10,  15,  20,  26,  36,  40,  48,  60,  72,  80,  96,  104, 120, |  | ||||||
|      132, 144, 168, 180, 196, 224, 224, 252, 270, 300, 312, 336, 360, 390, |  | ||||||
|      420, 450, 480, 510, 540, 570, 570, 600, 630, 660, 720, 750}, // Low
 |  | ||||||
|     {17,   28,   44,   64,   88,   112,  130,  156,  192,  224,  264,  308,  352,  384, |  | ||||||
|      432,  480,  532,  588,  650,  700,  750,  816,  900,  960,  1050, 1110, 1200, 1260, |  | ||||||
|      1350, 1440, 1530, 1620, 1710, 1800, 1890, 1980, 2100, 2220, 2310, 2430}, // High
 |  | ||||||
|     {13,   22,   36,   52,   72,   96,   108,  132,  160,  192,  224,  260, 288,  320, |  | ||||||
|      360,  408,  448,  504,  546,  600,  644,  690,  750,  810,  870,  952, 1020, 1050, |  | ||||||
|      1140, 1200, 1290, 1350, 1440, 1530, 1590, 1680, 1770, 1860, 1950, 2040}, // Quartile
 |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| static const uint8_t NUM_ERROR_CORRECTION_BLOCKS[4][40] = { |  | ||||||
|     // Version: (note that index 0 is for padding, and is set to an illegal value)
 |  | ||||||
|     // 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40    Error correction level
 |  | ||||||
|     {1,  1,  1,  2,  2,  4,  4,  4,  5,  5,  5,  8,  9,  9,  10, 10, 11, 13, 14, 16, |  | ||||||
|      17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49}, // Medium
 |  | ||||||
|     {1, 1, 1, 1,  1,  2,  2,  2,  2,  4,  4,  4,  4,  4,  6,  6,  6,  6,  7,  8, |  | ||||||
|      8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25}, // Low
 |  | ||||||
|     {1,  1,  2,  4,  4,  4,  5,  6,  8,  8,  11, 11, 16, 16, 18, 16, 19, 21, 25, 25, |  | ||||||
|      25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81}, // High
 |  | ||||||
|     {1,  1,  2,  2,  4,  4,  6,  6,  8,  8,  8,  10, 12, 16, 12, 17, 16, 18, 21, 20, |  | ||||||
|      23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68}, // Quartile
 |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| static const uint16_t NUM_RAW_DATA_MODULES[40] = { |  | ||||||
|     //  1,   2,   3,   4,    5,    6,    7,    8,    9,   10,   11,   12,   13,   14,   15,   16,   17,
 |  | ||||||
|     208, |  | ||||||
|     359, |  | ||||||
|     567, |  | ||||||
|     807, |  | ||||||
|     1079, |  | ||||||
|     1383, |  | ||||||
|     1568, |  | ||||||
|     1936, |  | ||||||
|     2336, |  | ||||||
|     2768, |  | ||||||
|     3232, |  | ||||||
|     3728, |  | ||||||
|     4256, |  | ||||||
|     4651, |  | ||||||
|     5243, |  | ||||||
|     5867, |  | ||||||
|     6523, |  | ||||||
|     //   18,   19,   20,   21,    22,    23,    24,    25,   26,    27,     28,    29,    30,    31,
 |  | ||||||
|     7211, |  | ||||||
|     7931, |  | ||||||
|     8683, |  | ||||||
|     9252, |  | ||||||
|     10068, |  | ||||||
|     10916, |  | ||||||
|     11796, |  | ||||||
|     12708, |  | ||||||
|     13652, |  | ||||||
|     14628, |  | ||||||
|     15371, |  | ||||||
|     16411, |  | ||||||
|     17483, |  | ||||||
|     18587, |  | ||||||
|     //    32,    33,    34,    35,    36,    37,    38,    39,    40
 |  | ||||||
|     19723, |  | ||||||
|     20891, |  | ||||||
|     22091, |  | ||||||
|     23008, |  | ||||||
|     24272, |  | ||||||
|     25568, |  | ||||||
|     26896, |  | ||||||
|     28256, |  | ||||||
|     29648}; |  | ||||||
| 
 |  | ||||||
| // @TODO: Put other LOCK_VERSIONS here
 |  | ||||||
| #elif LOCK_VERSION == 3 |  | ||||||
| 
 |  | ||||||
| static const int16_t NUM_ERROR_CORRECTION_CODEWORDS[4] = {26, 15, 44, 36}; |  | ||||||
| 
 |  | ||||||
| static const int8_t NUM_ERROR_CORRECTION_BLOCKS[4] = {1, 1, 2, 2}; |  | ||||||
| 
 |  | ||||||
| static const uint16_t NUM_RAW_DATA_MODULES = 567; |  | ||||||
| 
 |  | ||||||
| #else |  | ||||||
| 
 |  | ||||||
| #error Unsupported LOCK_VERSION (add it...) |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| static int max(int a, int b) { |  | ||||||
|     if(a > b) { |  | ||||||
|         return a; |  | ||||||
|     } |  | ||||||
|     return b; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
| static int abs(int value) { |  | ||||||
|     if (value < 0) { return -value; } |  | ||||||
|     return value; |  | ||||||
| } |  | ||||||
| */ |  | ||||||
| 
 |  | ||||||
| #pragma mark - Mode testing and conversion |  | ||||||
| 
 |  | ||||||
| static int8_t getAlphanumeric(char c) { |  | ||||||
|     if(c >= '0' && c <= '9') { |  | ||||||
|         return (c - '0'); |  | ||||||
|     } |  | ||||||
|     if(c >= 'A' && c <= 'Z') { |  | ||||||
|         return (c - 'A' + 10); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     switch(c) { |  | ||||||
|     case ' ': |  | ||||||
|         return 36; |  | ||||||
|     case '$': |  | ||||||
|         return 37; |  | ||||||
|     case '%': |  | ||||||
|         return 38; |  | ||||||
|     case '*': |  | ||||||
|         return 39; |  | ||||||
|     case '+': |  | ||||||
|         return 40; |  | ||||||
|     case '-': |  | ||||||
|         return 41; |  | ||||||
|     case '.': |  | ||||||
|         return 42; |  | ||||||
|     case '/': |  | ||||||
|         return 43; |  | ||||||
|     case ':': |  | ||||||
|         return 44; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return -1; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static bool isAlphanumeric(const char* text, uint16_t length) { |  | ||||||
|     while(length != 0) { |  | ||||||
|         if(getAlphanumeric(text[--length]) == -1) { |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static bool isNumeric(const char* text, uint16_t length) { |  | ||||||
|     while(length != 0) { |  | ||||||
|         char c = text[--length]; |  | ||||||
|         if(c < '0' || c > '9') { |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #pragma mark - Counting |  | ||||||
| 
 |  | ||||||
| // We store the following tightly packed (less 8) in modeInfo
 |  | ||||||
| //               <=9  <=26  <= 40
 |  | ||||||
| // NUMERIC      ( 10,   12,    14);
 |  | ||||||
| // ALPHANUMERIC (  9,   11,    13);
 |  | ||||||
| // BYTE         (  8,   16,    16);
 |  | ||||||
| static char getModeBits(uint8_t version, uint8_t mode) { |  | ||||||
|     // Note: We use 15 instead of 16; since 15 doesn't exist and we cannot store 16 (8 + 8) in 3 bits
 |  | ||||||
|     // hex(int("".join(reversed([('00' + bin(x - 8)[2:])[-3:] for x in [10, 9, 8, 12, 11, 15, 14, 13, 15]])), 2))
 |  | ||||||
|     unsigned int modeInfo = 0x7bbb80a; |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 || LOCK_VERSION > 9 |  | ||||||
|     if(version > 9) { |  | ||||||
|         modeInfo >>= 9; |  | ||||||
|     } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 || LOCK_VERSION > 26 |  | ||||||
|     if(version > 26) { |  | ||||||
|         modeInfo >>= 9; |  | ||||||
|     } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|     char result = 8 + ((modeInfo >> (3 * mode)) & 0x07); |  | ||||||
|     if(result == 15) { |  | ||||||
|         result = 16; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return result; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #pragma mark - BitBucket |  | ||||||
| 
 |  | ||||||
| typedef struct BitBucket { |  | ||||||
|     uint32_t bitOffsetOrWidth; |  | ||||||
|     uint16_t capacityBytes; |  | ||||||
|     uint8_t* data; |  | ||||||
| } BitBucket; |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
| void bb_dump(BitBucket *bitBuffer) { |  | ||||||
|     printf("Buffer: "); |  | ||||||
|     for (uint32_t i = 0; i < bitBuffer->capacityBytes; i++) { |  | ||||||
|         printf("%02x", bitBuffer->data[i]); |  | ||||||
|         if ((i % 4) == 3) { printf(" "); } |  | ||||||
|     } |  | ||||||
|     printf("\n"); |  | ||||||
| } |  | ||||||
| */ |  | ||||||
| 
 |  | ||||||
| static uint16_t bb_getGridSizeBytes(uint8_t size) { |  | ||||||
|     return (((size * size) + 7) / 8); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static uint16_t bb_getBufferSizeBytes(uint32_t bits) { |  | ||||||
|     return ((bits + 7) / 8); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void bb_initBuffer(BitBucket* bitBuffer, uint8_t* data, int32_t capacityBytes) { |  | ||||||
|     bitBuffer->bitOffsetOrWidth = 0; |  | ||||||
|     bitBuffer->capacityBytes = capacityBytes; |  | ||||||
|     bitBuffer->data = data; |  | ||||||
| 
 |  | ||||||
|     memset(data, 0, bitBuffer->capacityBytes); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void bb_initGrid(BitBucket* bitGrid, uint8_t* data, uint8_t size) { |  | ||||||
|     bitGrid->bitOffsetOrWidth = size; |  | ||||||
|     bitGrid->capacityBytes = bb_getGridSizeBytes(size); |  | ||||||
|     bitGrid->data = data; |  | ||||||
| 
 |  | ||||||
|     memset(data, 0, bitGrid->capacityBytes); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void bb_appendBits(BitBucket* bitBuffer, uint32_t val, uint8_t length) { |  | ||||||
|     uint32_t offset = bitBuffer->bitOffsetOrWidth; |  | ||||||
|     for(int8_t i = length - 1; i >= 0; i--, offset++) { |  | ||||||
|         bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7)); |  | ||||||
|     } |  | ||||||
|     bitBuffer->bitOffsetOrWidth = offset; |  | ||||||
| } |  | ||||||
| /*
 |  | ||||||
| void bb_setBits(BitBucket *bitBuffer, uint32_t val, int offset, uint8_t length) { |  | ||||||
|     for (int8_t i = length - 1; i >= 0; i--, offset++) { |  | ||||||
|         bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7)); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| */ |  | ||||||
| static void bb_setBit(BitBucket* bitGrid, uint8_t x, uint8_t y, bool on) { |  | ||||||
|     uint32_t offset = y * bitGrid->bitOffsetOrWidth + x; |  | ||||||
|     uint8_t mask = 1 << (7 - (offset & 0x07)); |  | ||||||
|     if(on) { |  | ||||||
|         bitGrid->data[offset >> 3] |= mask; |  | ||||||
|     } else { |  | ||||||
|         bitGrid->data[offset >> 3] &= ~mask; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void bb_invertBit(BitBucket* bitGrid, uint8_t x, uint8_t y, bool invert) { |  | ||||||
|     uint32_t offset = y * bitGrid->bitOffsetOrWidth + x; |  | ||||||
|     uint8_t mask = 1 << (7 - (offset & 0x07)); |  | ||||||
|     bool on = ((bitGrid->data[offset >> 3] & (1 << (7 - (offset & 0x07)))) != 0); |  | ||||||
|     if(on ^ invert) { |  | ||||||
|         bitGrid->data[offset >> 3] |= mask; |  | ||||||
|     } else { |  | ||||||
|         bitGrid->data[offset >> 3] &= ~mask; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static bool bb_getBit(BitBucket* bitGrid, uint8_t x, uint8_t y) { |  | ||||||
|     uint32_t offset = y * bitGrid->bitOffsetOrWidth + x; |  | ||||||
|     return (bitGrid->data[offset >> 3] & (1 << (7 - (offset & 0x07)))) != 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #pragma mark - Drawing Patterns |  | ||||||
| 
 |  | ||||||
| // XORs the data modules in this QR Code with the given mask pattern. Due to XOR's mathematical
 |  | ||||||
| // properties, calling applyMask(m) twice with the same value is equivalent to no change at all.
 |  | ||||||
| // This means it is possible to apply a mask, undo it, and try another mask. Note that a final
 |  | ||||||
| // well-formed QR Code symbol needs exactly one mask applied (not zero, not two, etc.).
 |  | ||||||
| static void applyMask(BitBucket* modules, BitBucket* isFunction, uint8_t mask) { |  | ||||||
|     uint8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
|     for(uint8_t y = 0; y < size; y++) { |  | ||||||
|         for(uint8_t x = 0; x < size; x++) { |  | ||||||
|             if(bb_getBit(isFunction, x, y)) { |  | ||||||
|                 continue; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             bool invert = 0; |  | ||||||
|             switch(mask) { |  | ||||||
|             case 0: |  | ||||||
|                 invert = (x + y) % 2 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 1: |  | ||||||
|                 invert = y % 2 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 2: |  | ||||||
|                 invert = x % 3 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 3: |  | ||||||
|                 invert = (x + y) % 3 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 4: |  | ||||||
|                 invert = (x / 3 + y / 2) % 2 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 5: |  | ||||||
|                 invert = x * y % 2 + x * y % 3 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 6: |  | ||||||
|                 invert = (x * y % 2 + x * y % 3) % 2 == 0; |  | ||||||
|                 break; |  | ||||||
|             case 7: |  | ||||||
|                 invert = ((x + y) % 2 + x * y % 3) % 2 == 0; |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|             bb_invertBit(modules, x, y, invert); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void |  | ||||||
|     setFunctionModule(BitBucket* modules, BitBucket* isFunction, uint8_t x, uint8_t y, bool on) { |  | ||||||
|     bb_setBit(modules, x, y, on); |  | ||||||
|     bb_setBit(isFunction, x, y, true); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Draws a 9*9 finder pattern including the border separator, with the center module at (x, y).
 |  | ||||||
| static void drawFinderPattern(BitBucket* modules, BitBucket* isFunction, uint8_t x, uint8_t y) { |  | ||||||
|     uint8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
|     for(int8_t i = -4; i <= 4; i++) { |  | ||||||
|         for(int8_t j = -4; j <= 4; j++) { |  | ||||||
|             uint8_t dist = max(abs(i), abs(j)); // Chebyshev/infinity norm
 |  | ||||||
|             int16_t xx = x + j, yy = y + i; |  | ||||||
|             if(0 <= xx && xx < size && 0 <= yy && yy < size) { |  | ||||||
|                 setFunctionModule(modules, isFunction, xx, yy, dist != 2 && dist != 4); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Draws a 5*5 alignment pattern, with the center module at (x, y).
 |  | ||||||
| static void drawAlignmentPattern(BitBucket* modules, BitBucket* isFunction, uint8_t x, uint8_t y) { |  | ||||||
|     for(int8_t i = -2; i <= 2; i++) { |  | ||||||
|         for(int8_t j = -2; j <= 2; j++) { |  | ||||||
|             setFunctionModule(modules, isFunction, x + j, y + i, max(abs(i), abs(j)) != 1); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Draws two copies of the format bits (with its own error correction code)
 |  | ||||||
| // based on the given mask and this object's error correction level field.
 |  | ||||||
| static void drawFormatBits(BitBucket* modules, BitBucket* isFunction, uint8_t ecc, uint8_t mask) { |  | ||||||
|     uint8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
|     // Calculate error correction code and pack bits
 |  | ||||||
|     uint32_t data = ecc << 3 | mask; // errCorrLvl is uint2, mask is uint3
 |  | ||||||
|     uint32_t rem = data; |  | ||||||
|     for(int i = 0; i < 10; i++) { |  | ||||||
|         rem = (rem << 1) ^ ((rem >> 9) * 0x537); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     data = data << 10 | rem; |  | ||||||
|     data ^= 0x5412; // uint15
 |  | ||||||
| 
 |  | ||||||
|     // Draw first copy
 |  | ||||||
|     for(uint8_t i = 0; i <= 5; i++) { |  | ||||||
|         setFunctionModule(modules, isFunction, 8, i, ((data >> i) & 1) != 0); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     setFunctionModule(modules, isFunction, 8, 7, ((data >> 6) & 1) != 0); |  | ||||||
|     setFunctionModule(modules, isFunction, 8, 8, ((data >> 7) & 1) != 0); |  | ||||||
|     setFunctionModule(modules, isFunction, 7, 8, ((data >> 8) & 1) != 0); |  | ||||||
| 
 |  | ||||||
|     for(int8_t i = 9; i < 15; i++) { |  | ||||||
|         setFunctionModule(modules, isFunction, 14 - i, 8, ((data >> i) & 1) != 0); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Draw second copy
 |  | ||||||
|     for(int8_t i = 0; i <= 7; i++) { |  | ||||||
|         setFunctionModule(modules, isFunction, size - 1 - i, 8, ((data >> i) & 1) != 0); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     for(int8_t i = 8; i < 15; i++) { |  | ||||||
|         setFunctionModule(modules, isFunction, 8, size - 15 + i, ((data >> i) & 1) != 0); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     setFunctionModule(modules, isFunction, 8, size - 8, true); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Draws two copies of the version bits (with its own error correction code),
 |  | ||||||
| // based on this object's version field (which only has an effect for 7 <= version <= 40).
 |  | ||||||
| static void drawVersion(BitBucket* modules, BitBucket* isFunction, uint8_t version) { |  | ||||||
|     int8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION != 0 && LOCK_VERSION < 7 |  | ||||||
|     return; |  | ||||||
| 
 |  | ||||||
| #else |  | ||||||
|     if(version < 7) { |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Calculate error correction code and pack bits
 |  | ||||||
|     uint32_t rem = version; // version is uint6, in the range [7, 40]
 |  | ||||||
|     for(uint8_t i = 0; i < 12; i++) { |  | ||||||
|         rem = (rem << 1) ^ ((rem >> 11) * 0x1F25); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     uint32_t data = version << 12 | rem; // uint18
 |  | ||||||
| 
 |  | ||||||
|     // Draw two copies
 |  | ||||||
|     for(uint8_t i = 0; i < 18; i++) { |  | ||||||
|         bool bit = ((data >> i) & 1) != 0; |  | ||||||
|         uint8_t a = size - 11 + i % 3, b = i / 3; |  | ||||||
|         setFunctionModule(modules, isFunction, a, b, bit); |  | ||||||
|         setFunctionModule(modules, isFunction, b, a, bit); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void |  | ||||||
|     drawFunctionPatterns(BitBucket* modules, BitBucket* isFunction, uint8_t version, uint8_t ecc) { |  | ||||||
|     uint8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
|     // Draw the horizontal and vertical timing patterns
 |  | ||||||
|     for(uint8_t i = 0; i < size; i++) { |  | ||||||
|         setFunctionModule(modules, isFunction, 6, i, i % 2 == 0); |  | ||||||
|         setFunctionModule(modules, isFunction, i, 6, i % 2 == 0); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
 |  | ||||||
|     drawFinderPattern(modules, isFunction, 3, 3); |  | ||||||
|     drawFinderPattern(modules, isFunction, size - 4, 3); |  | ||||||
|     drawFinderPattern(modules, isFunction, 3, size - 4); |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 || LOCK_VERSION > 1 |  | ||||||
| 
 |  | ||||||
|     if(version > 1) { |  | ||||||
|         // Draw the numerous alignment patterns
 |  | ||||||
| 
 |  | ||||||
|         uint8_t alignCount = version / 7 + 2; |  | ||||||
|         uint8_t step; |  | ||||||
|         if(version != 32) { |  | ||||||
|             step = (version * 4 + alignCount * 2 + 1) / (2 * alignCount - 2) * |  | ||||||
|                    2; // ceil((size - 13) / (2*numAlign - 2)) * 2
 |  | ||||||
|         } else { // C-C-C-Combo breaker!
 |  | ||||||
|             step = 26; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         uint8_t alignPositionIndex = alignCount - 1; |  | ||||||
|         uint8_t alignPosition[alignCount]; |  | ||||||
| 
 |  | ||||||
|         alignPosition[0] = 6; |  | ||||||
| 
 |  | ||||||
|         uint8_t size = version * 4 + 17; |  | ||||||
|         for(uint8_t i = 0, pos = size - 7; i < alignCount - 1; i++, pos -= step) { |  | ||||||
|             alignPosition[alignPositionIndex--] = pos; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         for(uint8_t i = 0; i < alignCount; i++) { |  | ||||||
|             for(uint8_t j = 0; j < alignCount; j++) { |  | ||||||
|                 if((i == 0 && j == 0) || (i == 0 && j == alignCount - 1) || |  | ||||||
|                    (i == alignCount - 1 && j == 0)) { |  | ||||||
|                     continue; // Skip the three finder corners
 |  | ||||||
|                 } else { |  | ||||||
|                     drawAlignmentPattern(modules, isFunction, alignPosition[i], alignPosition[j]); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|     // Draw configuration data
 |  | ||||||
|     drawFormatBits( |  | ||||||
|         modules, isFunction, ecc, 0); // Dummy mask value; overwritten later in the constructor
 |  | ||||||
|     drawVersion(modules, isFunction, version); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
 |  | ||||||
| // data area of this QR Code symbol. Function modules need to be marked off before this is called.
 |  | ||||||
| static void drawCodewords(BitBucket* modules, BitBucket* isFunction, BitBucket* codewords) { |  | ||||||
|     uint32_t bitLength = codewords->bitOffsetOrWidth; |  | ||||||
|     uint8_t* data = codewords->data; |  | ||||||
| 
 |  | ||||||
|     uint8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
|     // Bit index into the data
 |  | ||||||
|     uint32_t i = 0; |  | ||||||
| 
 |  | ||||||
|     // Do the funny zigzag scan
 |  | ||||||
|     for(int16_t right = size - 1; right >= 1; |  | ||||||
|         right -= 2) { // Index of right column in each column pair
 |  | ||||||
|         if(right == 6) { |  | ||||||
|             right = 5; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         for(uint8_t vert = 0; vert < size; vert++) { // Vertical counter
 |  | ||||||
|             for(int j = 0; j < 2; j++) { |  | ||||||
|                 uint8_t x = right - j; // Actual x coordinate
 |  | ||||||
|                 bool upwards = ((right & 2) == 0) ^ (x < 6); |  | ||||||
|                 uint8_t y = upwards ? size - 1 - vert : vert; // Actual y coordinate
 |  | ||||||
|                 if(!bb_getBit(isFunction, x, y) && i < bitLength) { |  | ||||||
|                     bb_setBit(modules, x, y, ((data[i >> 3] >> (7 - (i & 7))) & 1) != 0); |  | ||||||
|                     i++; |  | ||||||
|                 } |  | ||||||
|                 // If there are any remainder bits (0 to 7), they are already
 |  | ||||||
|                 // set to 0/false/white when the grid of modules was initialized
 |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #pragma mark - Penalty Calculation |  | ||||||
| 
 |  | ||||||
| #define PENALTY_N1 3 |  | ||||||
| #define PENALTY_N2 3 |  | ||||||
| #define PENALTY_N3 40 |  | ||||||
| #define PENALTY_N4 10 |  | ||||||
| 
 |  | ||||||
| // Calculates and returns the penalty score based on state of this QR Code's current modules.
 |  | ||||||
| // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
 |  | ||||||
| // @TODO: This can be optimized by working with the bytes instead of bits.
 |  | ||||||
| static uint32_t getPenaltyScore(BitBucket* modules) { |  | ||||||
|     uint32_t result = 0; |  | ||||||
| 
 |  | ||||||
|     uint8_t size = modules->bitOffsetOrWidth; |  | ||||||
| 
 |  | ||||||
|     // Adjacent modules in row having same color
 |  | ||||||
|     for(uint8_t y = 0; y < size; y++) { |  | ||||||
|         bool colorX = bb_getBit(modules, 0, y); |  | ||||||
|         for(uint8_t x = 1, runX = 1; x < size; x++) { |  | ||||||
|             bool cx = bb_getBit(modules, x, y); |  | ||||||
|             if(cx != colorX) { |  | ||||||
|                 colorX = cx; |  | ||||||
|                 runX = 1; |  | ||||||
| 
 |  | ||||||
|             } else { |  | ||||||
|                 runX++; |  | ||||||
|                 if(runX == 5) { |  | ||||||
|                     result += PENALTY_N1; |  | ||||||
|                 } else if(runX > 5) { |  | ||||||
|                     result++; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Adjacent modules in column having same color
 |  | ||||||
|     for(uint8_t x = 0; x < size; x++) { |  | ||||||
|         bool colorY = bb_getBit(modules, x, 0); |  | ||||||
|         for(uint8_t y = 1, runY = 1; y < size; y++) { |  | ||||||
|             bool cy = bb_getBit(modules, x, y); |  | ||||||
|             if(cy != colorY) { |  | ||||||
|                 colorY = cy; |  | ||||||
|                 runY = 1; |  | ||||||
|             } else { |  | ||||||
|                 runY++; |  | ||||||
|                 if(runY == 5) { |  | ||||||
|                     result += PENALTY_N1; |  | ||||||
|                 } else if(runY > 5) { |  | ||||||
|                     result++; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     uint16_t black = 0; |  | ||||||
|     for(uint8_t y = 0; y < size; y++) { |  | ||||||
|         uint16_t bitsRow = 0, bitsCol = 0; |  | ||||||
|         for(uint8_t x = 0; x < size; x++) { |  | ||||||
|             bool color = bb_getBit(modules, x, y); |  | ||||||
| 
 |  | ||||||
|             // 2*2 blocks of modules having same color
 |  | ||||||
|             if(x > 0 && y > 0) { |  | ||||||
|                 bool colorUL = bb_getBit(modules, x - 1, y - 1); |  | ||||||
|                 bool colorUR = bb_getBit(modules, x, y - 1); |  | ||||||
|                 bool colorL = bb_getBit(modules, x - 1, y); |  | ||||||
|                 if(color == colorUL && color == colorUR && color == colorL) { |  | ||||||
|                     result += PENALTY_N2; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             // Finder-like pattern in rows and columns
 |  | ||||||
|             bitsRow = ((bitsRow << 1) & 0x7FF) | color; |  | ||||||
|             bitsCol = ((bitsCol << 1) & 0x7FF) | bb_getBit(modules, y, x); |  | ||||||
| 
 |  | ||||||
|             // Needs 11 bits accumulated
 |  | ||||||
|             if(x >= 10) { |  | ||||||
|                 if(bitsRow == 0x05D || bitsRow == 0x5D0) { |  | ||||||
|                     result += PENALTY_N3; |  | ||||||
|                 } |  | ||||||
|                 if(bitsCol == 0x05D || bitsCol == 0x5D0) { |  | ||||||
|                     result += PENALTY_N3; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             // Balance of black and white modules
 |  | ||||||
|             if(color) { |  | ||||||
|                 black++; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Find smallest k such that (45-5k)% <= dark/total <= (55+5k)%
 |  | ||||||
|     uint16_t total = size * size; |  | ||||||
|     for(uint16_t k = 0; black * 20 < (9 - k) * total || black * 20 > (11 + k) * total; k++) { |  | ||||||
|         result += PENALTY_N4; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return result; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #pragma mark - Reed-Solomon Generator |  | ||||||
| 
 |  | ||||||
| static uint8_t rs_multiply(uint8_t x, uint8_t y) { |  | ||||||
|     // Russian peasant multiplication
 |  | ||||||
|     // See: https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication
 |  | ||||||
|     uint16_t z = 0; |  | ||||||
|     for(int8_t i = 7; i >= 0; i--) { |  | ||||||
|         z = (z << 1) ^ ((z >> 7) * 0x11D); |  | ||||||
|         z ^= ((y >> i) & 1) * x; |  | ||||||
|     } |  | ||||||
|     return z; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void rs_init(uint8_t degree, uint8_t* coeff) { |  | ||||||
|     memset(coeff, 0, degree); |  | ||||||
|     coeff[degree - 1] = 1; |  | ||||||
| 
 |  | ||||||
|     // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
 |  | ||||||
|     // drop the highest term, and store the rest of the coefficients in order of descending powers.
 |  | ||||||
|     // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
 |  | ||||||
|     uint16_t root = 1; |  | ||||||
|     for(uint8_t i = 0; i < degree; i++) { |  | ||||||
|         // Multiply the current product by (x - r^i)
 |  | ||||||
|         for(uint8_t j = 0; j < degree; j++) { |  | ||||||
|             coeff[j] = rs_multiply(coeff[j], root); |  | ||||||
|             if(j + 1 < degree) { |  | ||||||
|                 coeff[j] ^= coeff[j + 1]; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         root = (root << 1) ^ ((root >> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D)
 |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void rs_getRemainder( |  | ||||||
|     uint8_t degree, |  | ||||||
|     uint8_t* coeff, |  | ||||||
|     uint8_t* data, |  | ||||||
|     uint8_t length, |  | ||||||
|     uint8_t* result, |  | ||||||
|     uint8_t stride) { |  | ||||||
|     // Compute the remainder by performing polynomial division
 |  | ||||||
| 
 |  | ||||||
|     //for (uint8_t i = 0; i < degree; i++) { result[] = 0; }
 |  | ||||||
|     //memset(result, 0, degree);
 |  | ||||||
| 
 |  | ||||||
|     for(uint8_t i = 0; i < length; i++) { |  | ||||||
|         uint8_t factor = data[i] ^ result[0]; |  | ||||||
|         for(uint8_t j = 1; j < degree; j++) { |  | ||||||
|             result[(j - 1) * stride] = result[j * stride]; |  | ||||||
|         } |  | ||||||
|         result[(degree - 1) * stride] = 0; |  | ||||||
| 
 |  | ||||||
|         for(uint8_t j = 0; j < degree; j++) { |  | ||||||
|             result[j * stride] ^= rs_multiply(coeff[j], factor); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #pragma mark - QrCode |  | ||||||
| 
 |  | ||||||
| static int8_t encodeDataCodewords( |  | ||||||
|     BitBucket* dataCodewords, |  | ||||||
|     const uint8_t* text, |  | ||||||
|     uint16_t length, |  | ||||||
|     uint8_t version) { |  | ||||||
|     int8_t mode = MODE_BYTE; |  | ||||||
| 
 |  | ||||||
|     if(isNumeric((char*)text, length)) { |  | ||||||
|         mode = MODE_NUMERIC; |  | ||||||
|         bb_appendBits(dataCodewords, 1 << MODE_NUMERIC, 4); |  | ||||||
|         bb_appendBits(dataCodewords, length, getModeBits(version, MODE_NUMERIC)); |  | ||||||
| 
 |  | ||||||
|         uint16_t accumData = 0; |  | ||||||
|         uint8_t accumCount = 0; |  | ||||||
|         for(uint16_t i = 0; i < length; i++) { |  | ||||||
|             accumData = accumData * 10 + ((char)(text[i]) - '0'); |  | ||||||
|             accumCount++; |  | ||||||
|             if(accumCount == 3) { |  | ||||||
|                 bb_appendBits(dataCodewords, accumData, 10); |  | ||||||
|                 accumData = 0; |  | ||||||
|                 accumCount = 0; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         // 1 or 2 digits remaining
 |  | ||||||
|         if(accumCount > 0) { |  | ||||||
|             bb_appendBits(dataCodewords, accumData, accumCount * 3 + 1); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|     } else if(isAlphanumeric((char*)text, length)) { |  | ||||||
|         mode = MODE_ALPHANUMERIC; |  | ||||||
|         bb_appendBits(dataCodewords, 1 << MODE_ALPHANUMERIC, 4); |  | ||||||
|         bb_appendBits(dataCodewords, length, getModeBits(version, MODE_ALPHANUMERIC)); |  | ||||||
| 
 |  | ||||||
|         uint16_t accumData = 0; |  | ||||||
|         uint8_t accumCount = 0; |  | ||||||
|         for(uint16_t i = 0; i < length; i++) { |  | ||||||
|             accumData = accumData * 45 + getAlphanumeric((char)(text[i])); |  | ||||||
|             accumCount++; |  | ||||||
|             if(accumCount == 2) { |  | ||||||
|                 bb_appendBits(dataCodewords, accumData, 11); |  | ||||||
|                 accumData = 0; |  | ||||||
|                 accumCount = 0; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         // 1 character remaining
 |  | ||||||
|         if(accumCount > 0) { |  | ||||||
|             bb_appendBits(dataCodewords, accumData, 6); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|     } else { |  | ||||||
|         bb_appendBits(dataCodewords, 1 << MODE_BYTE, 4); |  | ||||||
|         bb_appendBits(dataCodewords, length, getModeBits(version, MODE_BYTE)); |  | ||||||
|         for(uint16_t i = 0; i < length; i++) { |  | ||||||
|             bb_appendBits(dataCodewords, (char)(text[i]), 8); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     //bb_setBits(dataCodewords, length, 4, getModeBits(version, mode));
 |  | ||||||
| 
 |  | ||||||
|     return mode; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void performErrorCorrection(uint8_t version, uint8_t ecc, BitBucket* data) { |  | ||||||
|     // See: http://www.thonky.com/qr-code-tutorial/structure-final-message
 |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 |  | ||||||
|     uint8_t numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecc][version - 1]; |  | ||||||
|     uint16_t totalEcc = NUM_ERROR_CORRECTION_CODEWORDS[ecc][version - 1]; |  | ||||||
|     uint16_t moduleCount = NUM_RAW_DATA_MODULES[version - 1]; |  | ||||||
| #else |  | ||||||
|     uint8_t numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecc]; |  | ||||||
|     uint16_t totalEcc = NUM_ERROR_CORRECTION_CODEWORDS[ecc]; |  | ||||||
|     uint16_t moduleCount = NUM_RAW_DATA_MODULES; |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|     uint8_t blockEccLen = totalEcc / numBlocks; |  | ||||||
|     uint8_t numShortBlocks = numBlocks - moduleCount / 8 % numBlocks; |  | ||||||
|     uint8_t shortBlockLen = moduleCount / 8 / numBlocks; |  | ||||||
| 
 |  | ||||||
|     uint8_t shortDataBlockLen = shortBlockLen - blockEccLen; |  | ||||||
| 
 |  | ||||||
|     uint8_t result[data->capacityBytes]; |  | ||||||
|     memset(result, 0, sizeof(result)); |  | ||||||
| 
 |  | ||||||
|     uint8_t coeff[blockEccLen]; |  | ||||||
|     rs_init(blockEccLen, coeff); |  | ||||||
| 
 |  | ||||||
|     uint16_t offset = 0; |  | ||||||
|     uint8_t* dataBytes = data->data; |  | ||||||
| 
 |  | ||||||
|     // Interleave all short blocks
 |  | ||||||
|     for(uint8_t i = 0; i < shortDataBlockLen; i++) { |  | ||||||
|         uint16_t index = i; |  | ||||||
|         uint8_t stride = shortDataBlockLen; |  | ||||||
|         for(uint8_t blockNum = 0; blockNum < numBlocks; blockNum++) { |  | ||||||
|             result[offset++] = dataBytes[index]; |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 || LOCK_VERSION >= 5 |  | ||||||
|             if(blockNum == numShortBlocks) { |  | ||||||
|                 stride++; |  | ||||||
|             } |  | ||||||
| #endif |  | ||||||
|             index += stride; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Version less than 5 only have short blocks
 |  | ||||||
| #if LOCK_VERSION == 0 || LOCK_VERSION >= 5 |  | ||||||
|     { |  | ||||||
|         // Interleave long blocks
 |  | ||||||
|         uint16_t index = shortDataBlockLen * (numShortBlocks + 1); |  | ||||||
|         uint8_t stride = shortDataBlockLen; |  | ||||||
|         for(uint8_t blockNum = 0; blockNum < numBlocks - numShortBlocks; blockNum++) { |  | ||||||
|             result[offset++] = dataBytes[index]; |  | ||||||
| 
 |  | ||||||
|             if(blockNum == 0) { |  | ||||||
|                 stride++; |  | ||||||
|             } |  | ||||||
|             index += stride; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|     // Add all ecc blocks, interleaved
 |  | ||||||
|     uint8_t blockSize = shortDataBlockLen; |  | ||||||
|     for(uint8_t blockNum = 0; blockNum < numBlocks; blockNum++) { |  | ||||||
| #if LOCK_VERSION == 0 || LOCK_VERSION >= 5 |  | ||||||
|         if(blockNum == numShortBlocks) { |  | ||||||
|             blockSize++; |  | ||||||
|         } |  | ||||||
| #endif |  | ||||||
|         rs_getRemainder( |  | ||||||
|             blockEccLen, coeff, dataBytes, blockSize, &result[offset + blockNum], numBlocks); |  | ||||||
|         dataBytes += blockSize; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     memcpy(data->data, result, data->capacityBytes); |  | ||||||
|     data->bitOffsetOrWidth = moduleCount; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // We store the Format bits tightly packed into a single byte (each of the 4 modes is 2 bits)
 |  | ||||||
| // The format bits can be determined by ECC_FORMAT_BITS >> (2 * ecc)
 |  | ||||||
| static const uint8_t ECC_FORMAT_BITS = (0x02 << 6) | (0x03 << 4) | (0x00 << 2) | (0x01 << 0); |  | ||||||
| 
 |  | ||||||
| #pragma mark - Public QRCode functions |  | ||||||
| 
 |  | ||||||
| uint16_t qrcode_getBufferSize(uint8_t version) { |  | ||||||
|     return bb_getGridSizeBytes(4 * version + 17); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // @TODO: Return error if data is too big.
 |  | ||||||
| int8_t qrcode_initBytes( |  | ||||||
|     QRCode* qrcode, |  | ||||||
|     uint8_t* modules, |  | ||||||
|     uint8_t version, |  | ||||||
|     uint8_t ecc, |  | ||||||
|     uint8_t* data, |  | ||||||
|     uint16_t length) { |  | ||||||
|     uint8_t size = version * 4 + 17; |  | ||||||
|     qrcode->version = version; |  | ||||||
|     qrcode->size = size; |  | ||||||
|     qrcode->ecc = ecc; |  | ||||||
|     qrcode->modules = modules; |  | ||||||
| 
 |  | ||||||
|     uint8_t eccFormatBits = (ECC_FORMAT_BITS >> (2 * ecc)) & 0x03; |  | ||||||
| 
 |  | ||||||
| #if LOCK_VERSION == 0 |  | ||||||
|     uint16_t moduleCount = NUM_RAW_DATA_MODULES[version - 1]; |  | ||||||
|     uint16_t dataCapacity = |  | ||||||
|         moduleCount / 8 - NUM_ERROR_CORRECTION_CODEWORDS[eccFormatBits][version - 1]; |  | ||||||
| #else |  | ||||||
|     version = LOCK_VERSION; |  | ||||||
|     uint16_t moduleCount = NUM_RAW_DATA_MODULES; |  | ||||||
|     uint16_t dataCapacity = moduleCount / 8 - NUM_ERROR_CORRECTION_CODEWORDS[eccFormatBits]; |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|     struct BitBucket codewords; |  | ||||||
|     uint8_t codewordBytes[bb_getBufferSizeBytes(moduleCount)]; |  | ||||||
|     bb_initBuffer(&codewords, codewordBytes, (int32_t)sizeof(codewordBytes)); |  | ||||||
| 
 |  | ||||||
|     // Place the data code words into the buffer
 |  | ||||||
|     int8_t mode = encodeDataCodewords(&codewords, data, length, version); |  | ||||||
| 
 |  | ||||||
|     if(mode < 0) { |  | ||||||
|         return -1; |  | ||||||
|     } |  | ||||||
|     qrcode->mode = mode; |  | ||||||
| 
 |  | ||||||
|     // Add terminator and pad up to a byte if applicable
 |  | ||||||
|     uint32_t padding = (dataCapacity * 8) - codewords.bitOffsetOrWidth; |  | ||||||
|     if(padding > 4) { |  | ||||||
|         padding = 4; |  | ||||||
|     } |  | ||||||
|     bb_appendBits(&codewords, 0, padding); |  | ||||||
|     bb_appendBits(&codewords, 0, (8 - codewords.bitOffsetOrWidth % 8) % 8); |  | ||||||
| 
 |  | ||||||
|     // Pad with alternate bytes until data capacity is reached
 |  | ||||||
|     for(uint8_t padByte = 0xEC; codewords.bitOffsetOrWidth < (dataCapacity * 8); |  | ||||||
|         padByte ^= 0xEC ^ 0x11) { |  | ||||||
|         bb_appendBits(&codewords, padByte, 8); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     BitBucket modulesGrid; |  | ||||||
|     bb_initGrid(&modulesGrid, modules, size); |  | ||||||
| 
 |  | ||||||
|     BitBucket isFunctionGrid; |  | ||||||
|     uint8_t isFunctionGridBytes[bb_getGridSizeBytes(size)]; |  | ||||||
|     bb_initGrid(&isFunctionGrid, isFunctionGridBytes, size); |  | ||||||
| 
 |  | ||||||
|     // Draw function patterns, draw all codewords, do masking
 |  | ||||||
|     drawFunctionPatterns(&modulesGrid, &isFunctionGrid, version, eccFormatBits); |  | ||||||
|     performErrorCorrection(version, eccFormatBits, &codewords); |  | ||||||
|     drawCodewords(&modulesGrid, &isFunctionGrid, &codewords); |  | ||||||
| 
 |  | ||||||
|     // Find the best (lowest penalty) mask
 |  | ||||||
|     uint8_t mask = 0; |  | ||||||
|     int32_t minPenalty = INT32_MAX; |  | ||||||
|     for(uint8_t i = 0; i < 8; i++) { |  | ||||||
|         drawFormatBits(&modulesGrid, &isFunctionGrid, eccFormatBits, i); |  | ||||||
|         applyMask(&modulesGrid, &isFunctionGrid, i); |  | ||||||
|         int penalty = getPenaltyScore(&modulesGrid); |  | ||||||
|         if(penalty < minPenalty) { |  | ||||||
|             mask = i; |  | ||||||
|             minPenalty = penalty; |  | ||||||
|         } |  | ||||||
|         applyMask(&modulesGrid, &isFunctionGrid, i); // Undoes the mask due to XOR
 |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     qrcode->mask = mask; |  | ||||||
| 
 |  | ||||||
|     // Overwrite old format bits
 |  | ||||||
|     drawFormatBits(&modulesGrid, &isFunctionGrid, eccFormatBits, mask); |  | ||||||
| 
 |  | ||||||
|     // Apply the final choice of mask
 |  | ||||||
|     applyMask(&modulesGrid, &isFunctionGrid, mask); |  | ||||||
| 
 |  | ||||||
|     return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| int8_t qrcode_initText( |  | ||||||
|     QRCode* qrcode, |  | ||||||
|     uint8_t* modules, |  | ||||||
|     uint8_t version, |  | ||||||
|     uint8_t ecc, |  | ||||||
|     const char* data) { |  | ||||||
|     return qrcode_initBytes(qrcode, modules, version, ecc, (uint8_t*)data, strlen(data)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| bool qrcode_getModule(QRCode* qrcode, uint8_t x, uint8_t y) { |  | ||||||
|     if(x < 0 || x >= qrcode->size || y < 0 || y >= qrcode->size) { |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     uint32_t offset = y * qrcode->size + x; |  | ||||||
|     return (qrcode->modules[offset >> 3] & (1 << (7 - (offset & 0x07)))) != 0; |  | ||||||
| } |  | ||||||
| @ -1,99 +0,0 @@ | |||||||
| /**
 |  | ||||||
|  * The MIT License (MIT) |  | ||||||
|  * |  | ||||||
|  * This library is written and maintained by Richard Moore. |  | ||||||
|  * Major parts were derived from Project Nayuki's library. |  | ||||||
|  * |  | ||||||
|  * Copyright (c) 2017 Richard Moore     (https://github.com/ricmoo/QRCode)
 |  | ||||||
|  * Copyright (c) 2017 Project Nayuki    (https://www.nayuki.io/page/qr-code-generator-library)
 |  | ||||||
|  * |  | ||||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy |  | ||||||
|  * of this software and associated documentation files (the "Software"), to deal |  | ||||||
|  * in the Software without restriction, including without limitation the rights |  | ||||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
|  * copies of the Software, and to permit persons to whom the Software is |  | ||||||
|  * furnished to do so, subject to the following conditions: |  | ||||||
|  * |  | ||||||
|  * The above copyright notice and this permission notice shall be included in |  | ||||||
|  * all copies or substantial portions of the Software. |  | ||||||
|  * |  | ||||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |  | ||||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |  | ||||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |  | ||||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |  | ||||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |  | ||||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |  | ||||||
|  * THE SOFTWARE. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *  Special thanks to Nayuki (https://www.nayuki.io/) from which this library was
 |  | ||||||
|  *  heavily inspired and compared against. |  | ||||||
|  * |  | ||||||
|  *  See: https://github.com/nayuki/QR-Code-generator/tree/master/cpp
 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #ifndef __QRCODE_H_ |  | ||||||
| #define __QRCODE_H_ |  | ||||||
| 
 |  | ||||||
| #ifndef __cplusplus |  | ||||||
| typedef unsigned char bool; |  | ||||||
| static const bool false = 0; |  | ||||||
| static const bool true = 1; |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #include <stdint.h> |  | ||||||
| 
 |  | ||||||
| // QR Code Format Encoding
 |  | ||||||
| #define MODE_NUMERIC 0 |  | ||||||
| #define MODE_ALPHANUMERIC 1 |  | ||||||
| #define MODE_BYTE 2 |  | ||||||
| 
 |  | ||||||
| // Error Correction Code Levels
 |  | ||||||
| #define ECC_LOW 0 |  | ||||||
| #define ECC_MEDIUM 1 |  | ||||||
| #define ECC_QUARTILE 2 |  | ||||||
| #define ECC_HIGH 3 |  | ||||||
| 
 |  | ||||||
| // If set to non-zero, this library can ONLY produce QR codes at that version
 |  | ||||||
| // This saves a lot of dynamic memory, as the codeword tables are skipped
 |  | ||||||
| #ifndef LOCK_VERSION |  | ||||||
| #define LOCK_VERSION 0 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| typedef struct QRCode { |  | ||||||
|     uint8_t version; |  | ||||||
|     uint8_t size; |  | ||||||
|     uint8_t ecc; |  | ||||||
|     uint8_t mode; |  | ||||||
|     uint8_t mask; |  | ||||||
|     uint8_t* modules; |  | ||||||
| } QRCode; |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" { |  | ||||||
| #endif /* __cplusplus */ |  | ||||||
| 
 |  | ||||||
| uint16_t qrcode_getBufferSize(uint8_t version); |  | ||||||
| 
 |  | ||||||
| int8_t qrcode_initText( |  | ||||||
|     QRCode* qrcode, |  | ||||||
|     uint8_t* modules, |  | ||||||
|     uint8_t version, |  | ||||||
|     uint8_t ecc, |  | ||||||
|     const char* data); |  | ||||||
| int8_t qrcode_initBytes( |  | ||||||
|     QRCode* qrcode, |  | ||||||
|     uint8_t* modules, |  | ||||||
|     uint8_t version, |  | ||||||
|     uint8_t ecc, |  | ||||||
|     uint8_t* data, |  | ||||||
|     uint16_t length); |  | ||||||
| 
 |  | ||||||
| bool qrcode_getModule(QRCode* qrcode, uint8_t x, uint8_t y); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } |  | ||||||
| #endif /* __cplusplus */ |  | ||||||
| 
 |  | ||||||
| #endif /* __QRCODE_H_ */ |  | ||||||
| @ -7,11 +7,14 @@ env.Append( | |||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("signal_reader.h"), |         File("signal_reader.h"), | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| libenv = env.Clone(FW_LIB_NAME="signal_reader") | libenv = env.Clone(FW_LIB_NAME="signal_reader") | ||||||
| libenv.ApplyLibFlags() | libenv.ApplyLibFlags() | ||||||
| libenv.Append(CCFLAGS=["-O3", "-funroll-loops", "-Ofast"]) | libenv.AppendUnique(CCFLAGS=["-O3", "-funroll-loops", "-Ofast"]) | ||||||
| 
 | 
 | ||||||
| sources = libenv.GlobRecursive("*.c*") | sources = libenv.GlobRecursive("*.c*") | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,6 +4,9 @@ env.Append( | |||||||
|     CPPPATH=[ |     CPPPATH=[ | ||||||
|         "#/lib/subghz", |         "#/lib/subghz", | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("environment.h"), |         File("environment.h"), | ||||||
|         File("receiver.h"), |         File("receiver.h"), | ||||||
|  | |||||||
| @ -7,6 +7,9 @@ env.Append( | |||||||
|     CPPPATH=[ |     CPPPATH=[ | ||||||
|         "#/lib/toolbox", |         "#/lib/toolbox", | ||||||
|     ], |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
|     SDK_HEADERS=[ |     SDK_HEADERS=[ | ||||||
|         File("api_lock.h"), |         File("api_lock.h"), | ||||||
|         File("compress.h"), |         File("compress.h"), | ||||||
| @ -14,10 +17,8 @@ env.Append( | |||||||
|         File("manchester_encoder.h"), |         File("manchester_encoder.h"), | ||||||
|         File("path.h"), |         File("path.h"), | ||||||
|         File("name_generator.h"), |         File("name_generator.h"), | ||||||
|         File("sha256.h"), |  | ||||||
|         File("crc32_calc.h"), |         File("crc32_calc.h"), | ||||||
|         File("dir_walk.h"), |         File("dir_walk.h"), | ||||||
|         File("md5.h"), |  | ||||||
|         File("args.h"), |         File("args.h"), | ||||||
|         File("saved_struct.h"), |         File("saved_struct.h"), | ||||||
|         File("version.h"), |         File("version.h"), | ||||||
|  | |||||||
| @ -1,299 +0,0 @@ | |||||||
| /*******************************************************************************
 |  | ||||||
| *            Portions COPYRIGHT 2015 STMicroelectronics                        * |  | ||||||
| *            Portions Copyright (C) 2006-2013, Brainspark B.V.                 * |  | ||||||
| *******************************************************************************/ |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  *  RFC 1321 compliant MD5 implementation |  | ||||||
|  * |  | ||||||
|  *  Copyright (C) 2006-2013, Brainspark B.V. |  | ||||||
|  * |  | ||||||
|  *  This file is part of PolarSSL (http://www.polarssl.org)
 |  | ||||||
|  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |  | ||||||
|  * |  | ||||||
|  *  All rights reserved. |  | ||||||
|  * |  | ||||||
|  *  This program is free software; you can redistribute it and/or modify |  | ||||||
|  *  it under the terms of the GNU General Public License as published by |  | ||||||
|  *  the Free Software Foundation; either version 2 of the License, or |  | ||||||
|  *  (at your option) any later version. |  | ||||||
|  * |  | ||||||
|  *  This program is distributed in the hope that it will be useful, |  | ||||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
|  *  GNU General Public License for more details. |  | ||||||
|  * |  | ||||||
|  *  You should have received a copy of the GNU General Public License along |  | ||||||
|  *  with this program; if not, write to the Free Software Foundation, Inc., |  | ||||||
|  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |  | ||||||
|  */ |  | ||||||
| /*
 |  | ||||||
|  *  The MD5 algorithm was designed by Ron Rivest in 1991. |  | ||||||
|  * |  | ||||||
|  *  http://www.ietf.org/rfc/rfc1321.txt
 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|   ****************************************************************************** |  | ||||||
|   * @file    md5.c |  | ||||||
|   * @author  MCD Application Team |  | ||||||
|   * @brief   This file has been modified to support the hardware Cryptographic and |  | ||||||
|   *          Hash processors embedded in STM32F415xx/417xx/437xx/439xx/756xx devices. |  | ||||||
|   *          This support is activated by defining the "USE_STM32F4XX_HW_CRYPTO" |  | ||||||
|   *          or "USE_STM32F7XX_HW_CRYPTO" macro in PolarSSL config.h file. |  | ||||||
|   ****************************************************************************** |  | ||||||
|   * @attention |  | ||||||
|   * |  | ||||||
|   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |  | ||||||
|   * You may not use this file except in compliance with the License. |  | ||||||
|   * You may obtain a copy of the License at: |  | ||||||
|   * |  | ||||||
|   *        http://www.st.com/software_license_agreement_liberty_v2
 |  | ||||||
|   * |  | ||||||
|   * Unless required by applicable law or agreed to in writing, software |  | ||||||
|   * distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
|   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
|   * See the License for the specific language governing permissions and |  | ||||||
|   * limitations under the License. |  | ||||||
|   * |  | ||||||
|   ****************************************************************************** |  | ||||||
|   */ |  | ||||||
| 
 |  | ||||||
| #include "md5.h" |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * 32-bit integer manipulation macros (little endian) |  | ||||||
|  */ |  | ||||||
| #ifndef GET_UINT32_LE |  | ||||||
| #define GET_UINT32_LE(n, b, i)                                                 \ |  | ||||||
|     {                                                                          \ |  | ||||||
|         (n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) |           \ |  | ||||||
|               ((uint32_t)(b)[(i) + 2] << 16) | ((uint32_t)(b)[(i) + 3] << 24); \ |  | ||||||
|     } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #ifndef PUT_UINT32_LE |  | ||||||
| #define PUT_UINT32_LE(n, b, i)                     \ |  | ||||||
|     {                                              \ |  | ||||||
|         (b)[(i)] = (unsigned char)((n));           \ |  | ||||||
|         (b)[(i) + 1] = (unsigned char)((n) >> 8);  \ |  | ||||||
|         (b)[(i) + 2] = (unsigned char)((n) >> 16); \ |  | ||||||
|         (b)[(i) + 3] = (unsigned char)((n) >> 24); \ |  | ||||||
|     } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * MD5 context setup |  | ||||||
|  */ |  | ||||||
| void md5_starts(md5_context* ctx) { |  | ||||||
|     ctx->total[0] = 0; |  | ||||||
|     ctx->total[1] = 0; |  | ||||||
| 
 |  | ||||||
|     ctx->state[0] = 0x67452301; |  | ||||||
|     ctx->state[1] = 0xEFCDAB89; |  | ||||||
|     ctx->state[2] = 0x98BADCFE; |  | ||||||
|     ctx->state[3] = 0x10325476; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void md5_process(md5_context* ctx, const unsigned char data[64]) { |  | ||||||
|     uint32_t X[16], A, B, C, D; |  | ||||||
| 
 |  | ||||||
|     GET_UINT32_LE(X[0], data, 0); |  | ||||||
|     GET_UINT32_LE(X[1], data, 4); |  | ||||||
|     GET_UINT32_LE(X[2], data, 8); |  | ||||||
|     GET_UINT32_LE(X[3], data, 12); |  | ||||||
|     GET_UINT32_LE(X[4], data, 16); |  | ||||||
|     GET_UINT32_LE(X[5], data, 20); |  | ||||||
|     GET_UINT32_LE(X[6], data, 24); |  | ||||||
|     GET_UINT32_LE(X[7], data, 28); |  | ||||||
|     GET_UINT32_LE(X[8], data, 32); |  | ||||||
|     GET_UINT32_LE(X[9], data, 36); |  | ||||||
|     GET_UINT32_LE(X[10], data, 40); |  | ||||||
|     GET_UINT32_LE(X[11], data, 44); |  | ||||||
|     GET_UINT32_LE(X[12], data, 48); |  | ||||||
|     GET_UINT32_LE(X[13], data, 52); |  | ||||||
|     GET_UINT32_LE(X[14], data, 56); |  | ||||||
|     GET_UINT32_LE(X[15], data, 60); |  | ||||||
| 
 |  | ||||||
| #define S(x, n) (((x) << (n)) | (((x)&0xFFFFFFFF) >> (32 - (n)))) |  | ||||||
| 
 |  | ||||||
| #define P(a, b, c, d, k, s, t)      \ |  | ||||||
|     {                               \ |  | ||||||
|         a += F(b, c, d) + X[k] + t; \ |  | ||||||
|         a = S(a, s) + b;            \ |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     A = ctx->state[0]; |  | ||||||
|     B = ctx->state[1]; |  | ||||||
|     C = ctx->state[2]; |  | ||||||
|     D = ctx->state[3]; |  | ||||||
| 
 |  | ||||||
| #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) |  | ||||||
| 
 |  | ||||||
|     P(A, B, C, D, 0, 7, 0xD76AA478); |  | ||||||
|     P(D, A, B, C, 1, 12, 0xE8C7B756); |  | ||||||
|     P(C, D, A, B, 2, 17, 0x242070DB); |  | ||||||
|     P(B, C, D, A, 3, 22, 0xC1BDCEEE); |  | ||||||
|     P(A, B, C, D, 4, 7, 0xF57C0FAF); |  | ||||||
|     P(D, A, B, C, 5, 12, 0x4787C62A); |  | ||||||
|     P(C, D, A, B, 6, 17, 0xA8304613); |  | ||||||
|     P(B, C, D, A, 7, 22, 0xFD469501); |  | ||||||
|     P(A, B, C, D, 8, 7, 0x698098D8); |  | ||||||
|     P(D, A, B, C, 9, 12, 0x8B44F7AF); |  | ||||||
|     P(C, D, A, B, 10, 17, 0xFFFF5BB1); |  | ||||||
|     P(B, C, D, A, 11, 22, 0x895CD7BE); |  | ||||||
|     P(A, B, C, D, 12, 7, 0x6B901122); |  | ||||||
|     P(D, A, B, C, 13, 12, 0xFD987193); |  | ||||||
|     P(C, D, A, B, 14, 17, 0xA679438E); |  | ||||||
|     P(B, C, D, A, 15, 22, 0x49B40821); |  | ||||||
| 
 |  | ||||||
| #undef F |  | ||||||
| 
 |  | ||||||
| #define F(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) |  | ||||||
| 
 |  | ||||||
|     P(A, B, C, D, 1, 5, 0xF61E2562); |  | ||||||
|     P(D, A, B, C, 6, 9, 0xC040B340); |  | ||||||
|     P(C, D, A, B, 11, 14, 0x265E5A51); |  | ||||||
|     P(B, C, D, A, 0, 20, 0xE9B6C7AA); |  | ||||||
|     P(A, B, C, D, 5, 5, 0xD62F105D); |  | ||||||
|     P(D, A, B, C, 10, 9, 0x02441453); |  | ||||||
|     P(C, D, A, B, 15, 14, 0xD8A1E681); |  | ||||||
|     P(B, C, D, A, 4, 20, 0xE7D3FBC8); |  | ||||||
|     P(A, B, C, D, 9, 5, 0x21E1CDE6); |  | ||||||
|     P(D, A, B, C, 14, 9, 0xC33707D6); |  | ||||||
|     P(C, D, A, B, 3, 14, 0xF4D50D87); |  | ||||||
|     P(B, C, D, A, 8, 20, 0x455A14ED); |  | ||||||
|     P(A, B, C, D, 13, 5, 0xA9E3E905); |  | ||||||
|     P(D, A, B, C, 2, 9, 0xFCEFA3F8); |  | ||||||
|     P(C, D, A, B, 7, 14, 0x676F02D9); |  | ||||||
|     P(B, C, D, A, 12, 20, 0x8D2A4C8A); |  | ||||||
| 
 |  | ||||||
| #undef F |  | ||||||
| 
 |  | ||||||
| #define F(x, y, z) ((x) ^ (y) ^ (z)) |  | ||||||
| 
 |  | ||||||
|     P(A, B, C, D, 5, 4, 0xFFFA3942); |  | ||||||
|     P(D, A, B, C, 8, 11, 0x8771F681); |  | ||||||
|     P(C, D, A, B, 11, 16, 0x6D9D6122); |  | ||||||
|     P(B, C, D, A, 14, 23, 0xFDE5380C); |  | ||||||
|     P(A, B, C, D, 1, 4, 0xA4BEEA44); |  | ||||||
|     P(D, A, B, C, 4, 11, 0x4BDECFA9); |  | ||||||
|     P(C, D, A, B, 7, 16, 0xF6BB4B60); |  | ||||||
|     P(B, C, D, A, 10, 23, 0xBEBFBC70); |  | ||||||
|     P(A, B, C, D, 13, 4, 0x289B7EC6); |  | ||||||
|     P(D, A, B, C, 0, 11, 0xEAA127FA); |  | ||||||
|     P(C, D, A, B, 3, 16, 0xD4EF3085); |  | ||||||
|     P(B, C, D, A, 6, 23, 0x04881D05); |  | ||||||
|     P(A, B, C, D, 9, 4, 0xD9D4D039); |  | ||||||
|     P(D, A, B, C, 12, 11, 0xE6DB99E5); |  | ||||||
|     P(C, D, A, B, 15, 16, 0x1FA27CF8); |  | ||||||
|     P(B, C, D, A, 2, 23, 0xC4AC5665); |  | ||||||
| 
 |  | ||||||
| #undef F |  | ||||||
| 
 |  | ||||||
| #define F(x, y, z) ((y) ^ ((x) | ~(z))) |  | ||||||
| 
 |  | ||||||
|     P(A, B, C, D, 0, 6, 0xF4292244); |  | ||||||
|     P(D, A, B, C, 7, 10, 0x432AFF97); |  | ||||||
|     P(C, D, A, B, 14, 15, 0xAB9423A7); |  | ||||||
|     P(B, C, D, A, 5, 21, 0xFC93A039); |  | ||||||
|     P(A, B, C, D, 12, 6, 0x655B59C3); |  | ||||||
|     P(D, A, B, C, 3, 10, 0x8F0CCC92); |  | ||||||
|     P(C, D, A, B, 10, 15, 0xFFEFF47D); |  | ||||||
|     P(B, C, D, A, 1, 21, 0x85845DD1); |  | ||||||
|     P(A, B, C, D, 8, 6, 0x6FA87E4F); |  | ||||||
|     P(D, A, B, C, 15, 10, 0xFE2CE6E0); |  | ||||||
|     P(C, D, A, B, 6, 15, 0xA3014314); |  | ||||||
|     P(B, C, D, A, 13, 21, 0x4E0811A1); |  | ||||||
|     P(A, B, C, D, 4, 6, 0xF7537E82); |  | ||||||
|     P(D, A, B, C, 11, 10, 0xBD3AF235); |  | ||||||
|     P(C, D, A, B, 2, 15, 0x2AD7D2BB); |  | ||||||
|     P(B, C, D, A, 9, 21, 0xEB86D391); |  | ||||||
| 
 |  | ||||||
| #undef F |  | ||||||
| 
 |  | ||||||
|     ctx->state[0] += A; |  | ||||||
|     ctx->state[1] += B; |  | ||||||
|     ctx->state[2] += C; |  | ||||||
|     ctx->state[3] += D; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * MD5 process buffer |  | ||||||
|  */ |  | ||||||
| void md5_update(md5_context* ctx, const unsigned char* input, size_t ilen) { |  | ||||||
|     size_t fill; |  | ||||||
|     uint32_t left; |  | ||||||
| 
 |  | ||||||
|     if(ilen <= 0) return; |  | ||||||
| 
 |  | ||||||
|     left = ctx->total[0] & 0x3F; |  | ||||||
|     fill = 64 - left; |  | ||||||
| 
 |  | ||||||
|     ctx->total[0] += (uint32_t)ilen; |  | ||||||
|     ctx->total[0] &= 0xFFFFFFFF; |  | ||||||
| 
 |  | ||||||
|     if(ctx->total[0] < (uint32_t)ilen) ctx->total[1]++; |  | ||||||
| 
 |  | ||||||
|     if(left && ilen >= fill) { |  | ||||||
|         memcpy((void*)(ctx->buffer + left), input, fill); |  | ||||||
|         md5_process(ctx, ctx->buffer); |  | ||||||
|         input += fill; |  | ||||||
|         ilen -= fill; |  | ||||||
|         left = 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     while(ilen >= 64) { |  | ||||||
|         md5_process(ctx, input); |  | ||||||
|         input += 64; |  | ||||||
|         ilen -= 64; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     if(ilen > 0) { |  | ||||||
|         memcpy((void*)(ctx->buffer + left), input, ilen); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static const unsigned char md5_padding[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |  | ||||||
|                                               0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |  | ||||||
|                                               0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |  | ||||||
|                                               0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * MD5 final digest |  | ||||||
|  */ |  | ||||||
| void md5_finish(md5_context* ctx, unsigned char output[16]) { |  | ||||||
|     uint32_t last, padn; |  | ||||||
|     uint32_t high, low; |  | ||||||
|     unsigned char msglen[8]; |  | ||||||
| 
 |  | ||||||
|     high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); |  | ||||||
|     low = (ctx->total[0] << 3); |  | ||||||
| 
 |  | ||||||
|     PUT_UINT32_LE(low, msglen, 0); |  | ||||||
|     PUT_UINT32_LE(high, msglen, 4); |  | ||||||
| 
 |  | ||||||
|     last = ctx->total[0] & 0x3F; |  | ||||||
|     padn = (last < 56) ? (56 - last) : (120 - last); |  | ||||||
| 
 |  | ||||||
|     md5_update(ctx, md5_padding, padn); |  | ||||||
|     md5_update(ctx, msglen, 8); |  | ||||||
| 
 |  | ||||||
|     PUT_UINT32_LE(ctx->state[0], output, 0); |  | ||||||
|     PUT_UINT32_LE(ctx->state[1], output, 4); |  | ||||||
|     PUT_UINT32_LE(ctx->state[2], output, 8); |  | ||||||
|     PUT_UINT32_LE(ctx->state[3], output, 12); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * output = MD5( input buffer ) |  | ||||||
|  */ |  | ||||||
| void md5(const unsigned char* input, size_t ilen, unsigned char output[16]) { |  | ||||||
|     md5_context ctx; |  | ||||||
| 
 |  | ||||||
|     md5_starts(&ctx); |  | ||||||
|     md5_update(&ctx, input, ilen); |  | ||||||
|     md5_finish(&ctx, output); |  | ||||||
| 
 |  | ||||||
|     memset(&ctx, 0, sizeof(md5_context)); //-V597
 |  | ||||||
| } |  | ||||||
| @ -1,83 +0,0 @@ | |||||||
| /**
 |  | ||||||
|  * \file md5.h |  | ||||||
|  * |  | ||||||
|  * \brief MD5 message digest algorithm (hash function) |  | ||||||
|  * |  | ||||||
|  *  Copyright (C) 2006-2013, Brainspark B.V. |  | ||||||
|  * |  | ||||||
|  *  This file is part of PolarSSL (http://www.polarssl.org)
 |  | ||||||
|  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |  | ||||||
|  * |  | ||||||
|  *  All rights reserved. |  | ||||||
|  * |  | ||||||
|  *  This program is free software; you can redistribute it and/or modify |  | ||||||
|  *  it under the terms of the GNU General Public License as published by |  | ||||||
|  *  the Free Software Foundation; either version 2 of the License, or |  | ||||||
|  *  (at your option) any later version. |  | ||||||
|  * |  | ||||||
|  *  This program is distributed in the hope that it will be useful, |  | ||||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
|  *  GNU General Public License for more details. |  | ||||||
|  * |  | ||||||
|  *  You should have received a copy of the GNU General Public License along |  | ||||||
|  *  with this program; if not, write to the Free Software Foundation, Inc., |  | ||||||
|  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #include <string.h> |  | ||||||
| #include <stdint.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  * \brief          MD5 context structure |  | ||||||
|  */ |  | ||||||
| typedef struct { |  | ||||||
|     uint32_t total[2]; /*!< number of bytes processed  */ |  | ||||||
|     uint32_t state[4]; /*!< intermediate digest state  */ |  | ||||||
|     unsigned char buffer[64]; /*!< data block being processed */ |  | ||||||
| } md5_context; |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  * \brief          MD5 context setup |  | ||||||
|  * |  | ||||||
|  * \param ctx      context to be initialized |  | ||||||
|  */ |  | ||||||
| void md5_starts(md5_context* ctx); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  * \brief          MD5 process buffer |  | ||||||
|  * |  | ||||||
|  * \param ctx      MD5 context |  | ||||||
|  * \param input    buffer holding the  data |  | ||||||
|  * \param ilen     length of the input data |  | ||||||
|  */ |  | ||||||
| void md5_update(md5_context* ctx, const unsigned char* input, size_t ilen); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  * \brief          MD5 final digest |  | ||||||
|  * |  | ||||||
|  * \param ctx      MD5 context |  | ||||||
|  * \param output   MD5 checksum result |  | ||||||
|  */ |  | ||||||
| void md5_finish(md5_context* ctx, unsigned char output[16]); |  | ||||||
| 
 |  | ||||||
| /* Internal use */ |  | ||||||
| void md5_process(md5_context* ctx, const unsigned char data[64]); |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  * \brief          Output = MD5( input buffer ) |  | ||||||
|  * |  | ||||||
|  * \param input    buffer holding the  data |  | ||||||
|  * \param ilen     length of the input data |  | ||||||
|  * \param output   MD5 checksum result |  | ||||||
|  */ |  | ||||||
| void md5(const unsigned char* input, size_t ilen, unsigned char output[16]); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| @ -1,25 +1,39 @@ | |||||||
| #include "md5.h" |  | ||||||
| #include "md5_calc.h" | #include "md5_calc.h" | ||||||
| 
 | 
 | ||||||
|  | #include <storage/filesystem_api_defines.h> | ||||||
|  | #include <storage/storage.h> | ||||||
|  | #include <mbedtls/md5.h> | ||||||
|  | 
 | ||||||
| bool md5_calc_file(File* file, const char* path, unsigned char output[16], FS_Error* file_error) { | bool md5_calc_file(File* file, const char* path, unsigned char output[16], FS_Error* file_error) { | ||||||
|     bool result = storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING); |     if(!storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||||
| 
 |         if(file_error != NULL) { | ||||||
|     if(result) { |             *file_error = storage_file_get_error(file); | ||||||
|         const size_t size_to_read = 512; |  | ||||||
|         uint8_t* data = malloc(size_to_read); |  | ||||||
|         md5_context* md5_ctx = malloc(sizeof(md5_context)); |  | ||||||
| 
 |  | ||||||
|         md5_starts(md5_ctx); |  | ||||||
|         while(true) { |  | ||||||
|             size_t read_size = storage_file_read(file, data, size_to_read); |  | ||||||
|             if(read_size == 0) break; |  | ||||||
|             md5_update(md5_ctx, data, read_size); |  | ||||||
|         } |         } | ||||||
|         md5_finish(md5_ctx, output); |         return false; | ||||||
|         free(md5_ctx); |  | ||||||
|         free(data); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     const size_t size_to_read = 512; | ||||||
|  |     uint8_t* data = malloc(size_to_read); | ||||||
|  |     bool result = true; | ||||||
|  | 
 | ||||||
|  |     mbedtls_md5_context* md5_ctx = malloc(sizeof(mbedtls_md5_context)); | ||||||
|  |     mbedtls_md5_init(md5_ctx); | ||||||
|  |     mbedtls_md5_starts(md5_ctx); | ||||||
|  |     while(true) { | ||||||
|  |         size_t read_size = storage_file_read(file, data, size_to_read); | ||||||
|  |         if(storage_file_get_error(file) != FSE_OK) { | ||||||
|  |             result = false; | ||||||
|  |             break; | ||||||
|  |         } | ||||||
|  |         if(read_size == 0) { | ||||||
|  |             break; | ||||||
|  |         } | ||||||
|  |         mbedtls_md5_update(md5_ctx, data, read_size); | ||||||
|  |     } | ||||||
|  |     mbedtls_md5_finish(md5_ctx, output); | ||||||
|  |     free(md5_ctx); | ||||||
|  |     free(data); | ||||||
|  | 
 | ||||||
|     if(file_error != NULL) { |     if(file_error != NULL) { | ||||||
|         *file_error = storage_file_get_error(file); |         *file_error = storage_file_get_error(file); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,221 +0,0 @@ | |||||||
| /*
 |  | ||||||
|  * sha256.c -- Compute SHA-256 hash |  | ||||||
|  * |  | ||||||
|  * Just for little endian architecture. |  | ||||||
|  * |  | ||||||
|  * Code taken from: |  | ||||||
|  *  http://gladman.plushost.co.uk/oldsite/cryptography_technology/sha/index.php
 |  | ||||||
|  * |  | ||||||
|  *  File names are sha2.c, sha2.h, brg_types.h, brg_endian.h |  | ||||||
|  *  in the archive sha2-07-01-07.zip. |  | ||||||
|  * |  | ||||||
|  * Code is modified in the style of PolarSSL API. |  | ||||||
|  * |  | ||||||
|  * See original copyright notice below. |  | ||||||
|  */ |  | ||||||
| /*
 |  | ||||||
|  --------------------------------------------------------------------------- |  | ||||||
|  Copyright (c) 2002, Dr Brian Gladman, Worcester, UK.   All rights reserved. |  | ||||||
| 
 |  | ||||||
|  LICENSE TERMS |  | ||||||
| 
 |  | ||||||
|  The free distribution and use of this software in both source and binary |  | ||||||
|  form is allowed (with or without changes) provided that: |  | ||||||
| 
 |  | ||||||
|    1. distributions of this source code include the above copyright |  | ||||||
|       notice, this list of conditions and the following disclaimer; |  | ||||||
| 
 |  | ||||||
|    2. distributions in binary form include the above copyright |  | ||||||
|       notice, this list of conditions and the following disclaimer |  | ||||||
|       in the documentation and/or other associated materials; |  | ||||||
| 
 |  | ||||||
|    3. the copyright holder's name is not used to endorse products |  | ||||||
|       built using this software without specific written permission. |  | ||||||
| 
 |  | ||||||
|  ALTERNATIVELY, provided that this notice is retained in full, this product |  | ||||||
|  may be distributed under the terms of the GNU General Public License (GPL), |  | ||||||
|  in which case the provisions of the GPL apply INSTEAD OF those given above. |  | ||||||
| 
 |  | ||||||
|  DISCLAIMER |  | ||||||
| 
 |  | ||||||
|  This software is provided 'as is' with no explicit or implied warranties |  | ||||||
|  in respect of its properties, including, but not limited to, correctness |  | ||||||
|  and/or fitness for purpose. |  | ||||||
|  --------------------------------------------------------------------------- |  | ||||||
|  Issue Date: 01/08/2005 |  | ||||||
| */ |  | ||||||
| 
 |  | ||||||
| #include <string.h> |  | ||||||
| #include <stdint.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include "sha256.h" |  | ||||||
| 
 |  | ||||||
| #define SHA256_MASK (SHA256_BLOCK_SIZE - 1) |  | ||||||
| 
 |  | ||||||
| static void memcpy_output_bswap32(unsigned char* dst, const uint32_t* p) { |  | ||||||
|     int i; |  | ||||||
|     uint32_t q = 0; |  | ||||||
| 
 |  | ||||||
|     for(i = 0; i < 32; i++) { |  | ||||||
|         if((i & 3) == 0) q = __builtin_bswap32(p[i >> 2]); /* bswap32 is GCC extention */ |  | ||||||
|         dst[i] = q >> ((i & 3) * 8); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #define rotr32(x, n) (((x) >> n) | ((x) << (32 - (n)))) |  | ||||||
| 
 |  | ||||||
| #define ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) |  | ||||||
| #define maj(x, y, z) (((x) & (y)) | ((z) & ((x) ^ (y)))) |  | ||||||
| 
 |  | ||||||
| /* round transforms for SHA256 compression functions */ |  | ||||||
| #define vf(n, i) v[((n) - (i)) & 7] |  | ||||||
| 
 |  | ||||||
| #define hf(i) (p[(i)&15] += g_1(p[((i) + 14) & 15]) + p[((i) + 9) & 15] + g_0(p[((i) + 1) & 15])) |  | ||||||
| 
 |  | ||||||
| #define v_cycle0(i)                                                               \ |  | ||||||
|     p[i] = __builtin_bswap32(p[i]);                                               \ |  | ||||||
|     vf(7, i) += p[i] + k_0[i] + s_1(vf(4, i)) + ch(vf(4, i), vf(5, i), vf(6, i)); \ |  | ||||||
|     vf(3, i) += vf(7, i);                                                         \ |  | ||||||
|     vf(7, i) += s_0(vf(0, i)) + maj(vf(0, i), vf(1, i), vf(2, i)) |  | ||||||
| 
 |  | ||||||
| #define v_cycle(i, j)                                                                  \ |  | ||||||
|     vf(7, i) += hf(i) + k_0[i + j] + s_1(vf(4, i)) + ch(vf(4, i), vf(5, i), vf(6, i)); \ |  | ||||||
|     vf(3, i) += vf(7, i);                                                              \ |  | ||||||
|     vf(7, i) += s_0(vf(0, i)) + maj(vf(0, i), vf(1, i), vf(2, i)) |  | ||||||
| 
 |  | ||||||
| #define s_0(x) (rotr32((x), 2) ^ rotr32((x), 13) ^ rotr32((x), 22)) |  | ||||||
| #define s_1(x) (rotr32((x), 6) ^ rotr32((x), 11) ^ rotr32((x), 25)) |  | ||||||
| #define g_0(x) (rotr32((x), 7) ^ rotr32((x), 18) ^ ((x) >> 3)) |  | ||||||
| #define g_1(x) (rotr32((x), 17) ^ rotr32((x), 19) ^ ((x) >> 10)) |  | ||||||
| #define k_0 k256 |  | ||||||
| 
 |  | ||||||
| static const uint32_t k256[64] = { |  | ||||||
|     0X428A2F98, 0X71374491, 0XB5C0FBCF, 0XE9B5DBA5, 0X3956C25B, 0X59F111F1, 0X923F82A4, 0XAB1C5ED5, |  | ||||||
|     0XD807AA98, 0X12835B01, 0X243185BE, 0X550C7DC3, 0X72BE5D74, 0X80DEB1FE, 0X9BDC06A7, 0XC19BF174, |  | ||||||
|     0XE49B69C1, 0XEFBE4786, 0X0FC19DC6, 0X240CA1CC, 0X2DE92C6F, 0X4A7484AA, 0X5CB0A9DC, 0X76F988DA, |  | ||||||
|     0X983E5152, 0XA831C66D, 0XB00327C8, 0XBF597FC7, 0XC6E00BF3, 0XD5A79147, 0X06CA6351, 0X14292967, |  | ||||||
|     0X27B70A85, 0X2E1B2138, 0X4D2C6DFC, 0X53380D13, 0X650A7354, 0X766A0ABB, 0X81C2C92E, 0X92722C85, |  | ||||||
|     0XA2BFE8A1, 0XA81A664B, 0XC24B8B70, 0XC76C51A3, 0XD192E819, 0XD6990624, 0XF40E3585, 0X106AA070, |  | ||||||
|     0X19A4C116, 0X1E376C08, 0X2748774C, 0X34B0BCB5, 0X391C0CB3, 0X4ED8AA4A, 0X5B9CCA4F, 0X682E6FF3, |  | ||||||
|     0X748F82EE, 0X78A5636F, 0X84C87814, 0X8CC70208, 0X90BEFFFA, 0XA4506CEB, 0XBEF9A3F7, 0XC67178F2, |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| void sha256_process(sha256_context* ctx) { |  | ||||||
|     uint32_t i; |  | ||||||
|     uint32_t* p = ctx->wbuf; |  | ||||||
|     uint32_t v[8]; |  | ||||||
| 
 |  | ||||||
|     memcpy(v, ctx->state, 8 * sizeof(uint32_t)); |  | ||||||
| 
 |  | ||||||
|     v_cycle0(0); |  | ||||||
|     v_cycle0(1); |  | ||||||
|     v_cycle0(2); |  | ||||||
|     v_cycle0(3); |  | ||||||
|     v_cycle0(4); |  | ||||||
|     v_cycle0(5); |  | ||||||
|     v_cycle0(6); |  | ||||||
|     v_cycle0(7); |  | ||||||
|     v_cycle0(8); |  | ||||||
|     v_cycle0(9); |  | ||||||
|     v_cycle0(10); |  | ||||||
|     v_cycle0(11); |  | ||||||
|     v_cycle0(12); |  | ||||||
|     v_cycle0(13); |  | ||||||
|     v_cycle0(14); |  | ||||||
|     v_cycle0(15); |  | ||||||
| 
 |  | ||||||
|     for(i = 16; i < 64; i += 16) { |  | ||||||
|         v_cycle(0, i); |  | ||||||
|         v_cycle(1, i); |  | ||||||
|         v_cycle(2, i); |  | ||||||
|         v_cycle(3, i); |  | ||||||
|         v_cycle(4, i); |  | ||||||
|         v_cycle(5, i); |  | ||||||
|         v_cycle(6, i); |  | ||||||
|         v_cycle(7, i); |  | ||||||
|         v_cycle(8, i); |  | ||||||
|         v_cycle(9, i); |  | ||||||
|         v_cycle(10, i); |  | ||||||
|         v_cycle(11, i); |  | ||||||
|         v_cycle(12, i); |  | ||||||
|         v_cycle(13, i); |  | ||||||
|         v_cycle(14, i); |  | ||||||
|         v_cycle(15, i); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     ctx->state[0] += v[0]; |  | ||||||
|     ctx->state[1] += v[1]; |  | ||||||
|     ctx->state[2] += v[2]; |  | ||||||
|     ctx->state[3] += v[3]; |  | ||||||
|     ctx->state[4] += v[4]; |  | ||||||
|     ctx->state[5] += v[5]; |  | ||||||
|     ctx->state[6] += v[6]; |  | ||||||
|     ctx->state[7] += v[7]; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void sha256_update(sha256_context* ctx, const unsigned char* input, unsigned int ilen) { |  | ||||||
|     uint32_t left = (ctx->total[0] & SHA256_MASK); |  | ||||||
|     uint32_t fill = SHA256_BLOCK_SIZE - left; |  | ||||||
| 
 |  | ||||||
|     ctx->total[0] += ilen; |  | ||||||
|     if(ctx->total[0] < ilen) ctx->total[1]++; |  | ||||||
| 
 |  | ||||||
|     while(ilen >= fill) { |  | ||||||
|         memcpy(((unsigned char*)ctx->wbuf) + left, input, fill); |  | ||||||
|         sha256_process(ctx); |  | ||||||
|         input += fill; |  | ||||||
|         ilen -= fill; |  | ||||||
|         left = 0; |  | ||||||
|         fill = SHA256_BLOCK_SIZE; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     memcpy(((unsigned char*)ctx->wbuf) + left, input, ilen); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void sha256_finish(sha256_context* ctx, unsigned char output[32]) { |  | ||||||
|     uint32_t last = (ctx->total[0] & SHA256_MASK); |  | ||||||
| 
 |  | ||||||
|     ctx->wbuf[last >> 2] = __builtin_bswap32(ctx->wbuf[last >> 2]); |  | ||||||
|     ctx->wbuf[last >> 2] &= 0xffffff80UL << (8 * (~last & 3)); |  | ||||||
|     ctx->wbuf[last >> 2] |= 0x00000080UL << (8 * (~last & 3)); |  | ||||||
|     ctx->wbuf[last >> 2] = __builtin_bswap32(ctx->wbuf[last >> 2]); |  | ||||||
| 
 |  | ||||||
|     if(last > SHA256_BLOCK_SIZE - 9) { |  | ||||||
|         if(last < 60) ctx->wbuf[15] = 0; |  | ||||||
|         sha256_process(ctx); |  | ||||||
|         last = 0; |  | ||||||
|     } else |  | ||||||
|         last = (last >> 2) + 1; |  | ||||||
| 
 |  | ||||||
|     while(last < 14) ctx->wbuf[last++] = 0; |  | ||||||
| 
 |  | ||||||
|     ctx->wbuf[14] = __builtin_bswap32((ctx->total[0] >> 29) | (ctx->total[1] << 3)); |  | ||||||
|     ctx->wbuf[15] = __builtin_bswap32(ctx->total[0] << 3); |  | ||||||
|     sha256_process(ctx); |  | ||||||
| 
 |  | ||||||
|     memcpy_output_bswap32(output, ctx->state); |  | ||||||
|     memset(ctx, 0, sizeof(sha256_context)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static const uint32_t initial_state[8] = { |  | ||||||
|     0x6a09e667, |  | ||||||
|     0xbb67ae85, |  | ||||||
|     0x3c6ef372, |  | ||||||
|     0xa54ff53a, |  | ||||||
|     0x510e527f, |  | ||||||
|     0x9b05688c, |  | ||||||
|     0x1f83d9ab, |  | ||||||
|     0x5be0cd19}; |  | ||||||
| 
 |  | ||||||
| void sha256_start(sha256_context* ctx) { |  | ||||||
|     ctx->total[0] = ctx->total[1] = 0; |  | ||||||
|     memcpy(ctx->state, initial_state, 8 * sizeof(uint32_t)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void sha256(const unsigned char* input, unsigned int ilen, unsigned char output[32]) { |  | ||||||
|     sha256_context ctx; |  | ||||||
| 
 |  | ||||||
|     sha256_start(&ctx); |  | ||||||
|     sha256_update(&ctx, input, ilen); |  | ||||||
|     sha256_finish(&ctx, output); |  | ||||||
| } |  | ||||||
| @ -1,24 +0,0 @@ | |||||||
| #pragma once |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| extern "C" { |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #define SHA256_DIGEST_SIZE 32 |  | ||||||
| #define SHA256_BLOCK_SIZE 64 |  | ||||||
| 
 |  | ||||||
| typedef struct { |  | ||||||
|     uint32_t total[2]; |  | ||||||
|     uint32_t state[8]; |  | ||||||
|     uint32_t wbuf[16]; |  | ||||||
| } sha256_context; |  | ||||||
| 
 |  | ||||||
| void sha256(const unsigned char* input, unsigned int ilen, unsigned char output[32]); |  | ||||||
| void sha256_start(sha256_context* ctx); |  | ||||||
| void sha256_finish(sha256_context* ctx, unsigned char output[32]); |  | ||||||
| void sha256_update(sha256_context* ctx, const unsigned char* input, unsigned int ilen); |  | ||||||
| void sha256_process(sha256_context* ctx); |  | ||||||
| 
 |  | ||||||
| #ifdef __cplusplus |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
							
								
								
									
										20
									
								
								lib/u8g2/SConscript
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								lib/u8g2/SConscript
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | |||||||
|  | Import("env") | ||||||
|  | 
 | ||||||
|  | env.Append( | ||||||
|  |     CPPPATH=[ | ||||||
|  |         "#/lib/u8g2", | ||||||
|  |     ], | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | libenv = env.Clone(FW_LIB_NAME="u8g2") | ||||||
|  | libenv.ApplyLibFlags() | ||||||
|  | 
 | ||||||
|  | sources = libenv.GlobRecursive("*.c") | ||||||
|  | 
 | ||||||
|  | lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | ||||||
|  | libenv.Install("${LIB_DIST_DIR}", lib) | ||||||
|  | Return("lib") | ||||||
							
								
								
									
										16
									
								
								lib/update_util/SConscript
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								lib/update_util/SConscript
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | Import("env") | ||||||
|  | 
 | ||||||
|  | env.Append( | ||||||
|  |     LINT_SOURCES=[ | ||||||
|  |         Dir("."), | ||||||
|  |     ], | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | libenv = env.Clone(FW_LIB_NAME="update_util") | ||||||
|  | libenv.ApplyLibFlags() | ||||||
|  | 
 | ||||||
|  | sources = libenv.GlobRecursive("*.c") | ||||||
|  | 
 | ||||||
|  | lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) | ||||||
|  | libenv.Install("${LIB_DIST_DIR}", lib) | ||||||
|  | Return("lib") | ||||||
| @ -125,7 +125,6 @@ def LoadAppManifest(env, entry): | |||||||
| 
 | 
 | ||||||
|         app_manifest_file_path = manifest_glob[0].rfile().abspath |         app_manifest_file_path = manifest_glob[0].rfile().abspath | ||||||
|         env["APPMGR"].load_manifest(app_manifest_file_path, entry) |         env["APPMGR"].load_manifest(app_manifest_file_path, entry) | ||||||
|         env.Append(PY_LINT_SOURCES=[app_manifest_file_path]) |  | ||||||
|     except FlipperManifestException as e: |     except FlipperManifestException as e: | ||||||
|         if not GetOption("silent"): |         if not GetOption("silent"): | ||||||
|             warn(WarningOnByDefault, str(e)) |             warn(WarningOnByDefault, str(e)) | ||||||
|  | |||||||
| @ -32,9 +32,9 @@ def generate(env): | |||||||
|                             "${TARGET.dir.posix}", |                             "${TARGET.dir.posix}", | ||||||
|                             "--dir", |                             "--dir", | ||||||
|                             "${ROOT_DIR}", |                             "${ROOT_DIR}", | ||||||
|                             "${VERSIONCOMSTR}", |  | ||||||
|                         ] |                         ] | ||||||
|                     ] |                     ], | ||||||
|  |                     "${VERSIONCOMSTR}", | ||||||
|                 ), |                 ), | ||||||
|                 emitter=_version_emitter, |                 emitter=_version_emitter, | ||||||
|             ), |             ), | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| entry,status,name,type,params | entry,status,name,type,params | ||||||
| Version,+,47.0,, | Version,+,48.0,, | ||||||
| Header,+,applications/services/bt/bt_service/bt.h,, | Header,+,applications/services/bt/bt_service/bt.h,, | ||||||
| Header,+,applications/services/cli/cli.h,, | Header,+,applications/services/cli/cli.h,, | ||||||
| Header,+,applications/services/cli/cli_vcp.h,, | Header,+,applications/services/cli/cli_vcp.h,, | ||||||
| @ -77,8 +77,13 @@ Header,+,lib/libusb_stm32/inc/usb_std.h,, | |||||||
| Header,+,lib/libusb_stm32/inc/usb_tmc.h,, | Header,+,lib/libusb_stm32/inc/usb_tmc.h,, | ||||||
| Header,+,lib/libusb_stm32/inc/usbd_core.h,, | Header,+,lib/libusb_stm32/inc/usbd_core.h,, | ||||||
| Header,+,lib/mbedtls/include/mbedtls/des.h,, | Header,+,lib/mbedtls/include/mbedtls/des.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/ecdh.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/ecdsa.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/ecp.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/md.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/md5.h,, | ||||||
| Header,+,lib/mbedtls/include/mbedtls/sha1.h,, | Header,+,lib/mbedtls/include/mbedtls/sha1.h,, | ||||||
| Header,+,lib/micro-ecc/uECC.h,, | Header,+,lib/mbedtls/include/mbedtls/sha256.h,, | ||||||
| Header,+,lib/mlib/m-algo.h,, | Header,+,lib/mlib/m-algo.h,, | ||||||
| Header,+,lib/mlib/m-array.h,, | Header,+,lib/mlib/m-array.h,, | ||||||
| Header,+,lib/mlib/m-bptree.h,, | Header,+,lib/mlib/m-bptree.h,, | ||||||
| @ -136,13 +141,11 @@ Header,+,lib/toolbox/float_tools.h,, | |||||||
| Header,+,lib/toolbox/hex.h,, | Header,+,lib/toolbox/hex.h,, | ||||||
| Header,+,lib/toolbox/manchester_decoder.h,, | Header,+,lib/toolbox/manchester_decoder.h,, | ||||||
| Header,+,lib/toolbox/manchester_encoder.h,, | Header,+,lib/toolbox/manchester_encoder.h,, | ||||||
| Header,+,lib/toolbox/md5.h,, |  | ||||||
| Header,+,lib/toolbox/name_generator.h,, | Header,+,lib/toolbox/name_generator.h,, | ||||||
| Header,+,lib/toolbox/path.h,, | Header,+,lib/toolbox/path.h,, | ||||||
| Header,+,lib/toolbox/pretty_format.h,, | Header,+,lib/toolbox/pretty_format.h,, | ||||||
| Header,+,lib/toolbox/protocols/protocol_dict.h,, | Header,+,lib/toolbox/protocols/protocol_dict.h,, | ||||||
| Header,+,lib/toolbox/saved_struct.h,, | Header,+,lib/toolbox/saved_struct.h,, | ||||||
| Header,+,lib/toolbox/sha256.h,, |  | ||||||
| Header,+,lib/toolbox/simple_array.h,, | Header,+,lib/toolbox/simple_array.h,, | ||||||
| Header,+,lib/toolbox/stream/buffered_file_stream.h,, | Header,+,lib/toolbox/stream/buffered_file_stream.h,, | ||||||
| Header,+,lib/toolbox/stream/file_stream.h,, | Header,+,lib/toolbox/stream/file_stream.h,, | ||||||
| @ -452,7 +455,6 @@ Function,-,_system_r,int,"_reent*, const char*" | |||||||
| Function,-,_tempnam_r,char*,"_reent*, const char*, const char*" | Function,-,_tempnam_r,char*,"_reent*, const char*, const char*" | ||||||
| Function,-,_tmpfile_r,FILE*,_reent* | Function,-,_tmpfile_r,FILE*,_reent* | ||||||
| Function,-,_tmpnam_r,char*,"_reent*, char*" | Function,-,_tmpnam_r,char*,"_reent*, char*" | ||||||
| Function,-,_tzset_r,void,_reent* |  | ||||||
| Function,-,_ungetc_r,int,"_reent*, int, FILE*" | Function,-,_ungetc_r,int,"_reent*, int, FILE*" | ||||||
| Function,-,_unsetenv_r,int,"_reent*, const char*" | Function,-,_unsetenv_r,int,"_reent*, const char*" | ||||||
| Function,-,_vasiprintf_r,int,"_reent*, char**, const char*, __gnuc_va_list" | Function,-,_vasiprintf_r,int,"_reent*, char**, const char*, __gnuc_va_list" | ||||||
| @ -499,8 +501,6 @@ Function,+,args_read_hex_bytes,_Bool,"FuriString*, uint8_t*, size_t" | |||||||
| Function,+,args_read_int_and_trim,_Bool,"FuriString*, int*" | Function,+,args_read_int_and_trim,_Bool,"FuriString*, int*" | ||||||
| Function,+,args_read_probably_quoted_string_and_trim,_Bool,"FuriString*, FuriString*" | Function,+,args_read_probably_quoted_string_and_trim,_Bool,"FuriString*, FuriString*" | ||||||
| Function,+,args_read_string_and_trim,_Bool,"FuriString*, FuriString*" | Function,+,args_read_string_and_trim,_Bool,"FuriString*, FuriString*" | ||||||
| Function,-,asctime,char*,const tm* |  | ||||||
| Function,-,asctime_r,char*,"const tm*, char*" |  | ||||||
| Function,-,asin,double,double | Function,-,asin,double,double | ||||||
| Function,-,asinf,float,float | Function,-,asinf,float,float | ||||||
| Function,-,asinh,double,double | Function,-,asinh,double,double | ||||||
| @ -611,7 +611,7 @@ Function,+,byte_input_get_view,View*,ByteInput* | |||||||
| Function,+,byte_input_set_header_text,void,"ByteInput*, const char*" | Function,+,byte_input_set_header_text,void,"ByteInput*, const char*" | ||||||
| Function,+,byte_input_set_result_callback,void,"ByteInput*, ByteInputCallback, ByteChangedCallback, void*, uint8_t*, uint8_t" | Function,+,byte_input_set_result_callback,void,"ByteInput*, ByteInputCallback, ByteChangedCallback, void*, uint8_t*, uint8_t" | ||||||
| Function,-,bzero,void,"void*, size_t" | Function,-,bzero,void,"void*, size_t" | ||||||
| Function,-,calloc,void*,"size_t, size_t" | Function,+,calloc,void*,"size_t, size_t" | ||||||
| Function,+,canvas_clear,void,Canvas* | Function,+,canvas_clear,void,Canvas* | ||||||
| Function,+,canvas_commit,void,Canvas* | Function,+,canvas_commit,void,Canvas* | ||||||
| Function,+,canvas_current_font_height,uint8_t,const Canvas* | Function,+,canvas_current_font_height,uint8_t,const Canvas* | ||||||
| @ -665,7 +665,6 @@ Function,+,cli_read_timeout,size_t,"Cli*, uint8_t*, size_t, uint32_t" | |||||||
| Function,+,cli_session_close,void,Cli* | Function,+,cli_session_close,void,Cli* | ||||||
| Function,+,cli_session_open,void,"Cli*, void*" | Function,+,cli_session_open,void,"Cli*, void*" | ||||||
| Function,+,cli_write,void,"Cli*, const uint8_t*, size_t" | Function,+,cli_write,void,"Cli*, const uint8_t*, size_t" | ||||||
| Function,-,clock,clock_t, |  | ||||||
| Function,+,composite_api_resolver_add,void,"CompositeApiResolver*, const ElfApiInterface*" | Function,+,composite_api_resolver_add,void,"CompositeApiResolver*, const ElfApiInterface*" | ||||||
| Function,+,composite_api_resolver_alloc,CompositeApiResolver*, | Function,+,composite_api_resolver_alloc,CompositeApiResolver*, | ||||||
| Function,+,composite_api_resolver_free,void,CompositeApiResolver* | Function,+,composite_api_resolver_free,void,CompositeApiResolver* | ||||||
| @ -689,8 +688,6 @@ Function,-,cosl,long double,long double | |||||||
| Function,+,crc32_calc_buffer,uint32_t,"uint32_t, const void*, size_t" | Function,+,crc32_calc_buffer,uint32_t,"uint32_t, const void*, size_t" | ||||||
| Function,+,crc32_calc_file,uint32_t,"File*, const FileCrcProgressCb, void*" | Function,+,crc32_calc_file,uint32_t,"File*, const FileCrcProgressCb, void*" | ||||||
| Function,-,ctermid,char*,char* | Function,-,ctermid,char*,char* | ||||||
| Function,-,ctime,char*,const time_t* |  | ||||||
| Function,-,ctime_r,char*,"const time_t*, char*" |  | ||||||
| Function,-,cuserid,char*,char* | Function,-,cuserid,char*,char* | ||||||
| Function,+,dialog_ex_alloc,DialogEx*, | Function,+,dialog_ex_alloc,DialogEx*, | ||||||
| Function,+,dialog_ex_disable_extended_events,void,DialogEx* | Function,+,dialog_ex_disable_extended_events,void,DialogEx* | ||||||
| @ -716,7 +713,6 @@ Function,+,dialog_message_set_icon,void,"DialogMessage*, const Icon*, uint8_t, u | |||||||
| Function,+,dialog_message_set_text,void,"DialogMessage*, const char*, uint8_t, uint8_t, Align, Align" | Function,+,dialog_message_set_text,void,"DialogMessage*, const char*, uint8_t, uint8_t, Align, Align" | ||||||
| Function,+,dialog_message_show,DialogMessageButton,"DialogsApp*, const DialogMessage*" | Function,+,dialog_message_show,DialogMessageButton,"DialogsApp*, const DialogMessage*" | ||||||
| Function,+,dialog_message_show_storage_error,void,"DialogsApp*, const char*" | Function,+,dialog_message_show_storage_error,void,"DialogsApp*, const char*" | ||||||
| Function,-,difftime,double,"time_t, time_t" |  | ||||||
| Function,+,digital_sequence_add_signal,void,"DigitalSequence*, uint8_t" | Function,+,digital_sequence_add_signal,void,"DigitalSequence*, uint8_t" | ||||||
| Function,-,digital_sequence_alloc,DigitalSequence*,"uint32_t, const GpioPin*" | Function,-,digital_sequence_alloc,DigitalSequence*,"uint32_t, const GpioPin*" | ||||||
| Function,-,digital_sequence_clear,void,DigitalSequence* | Function,-,digital_sequence_clear,void,DigitalSequence* | ||||||
| @ -1518,8 +1514,6 @@ Function,-,getenv,char*,const char* | |||||||
| Function,-,gets,char*,char* | Function,-,gets,char*,char* | ||||||
| Function,-,getsubopt,int,"char**, char**, char**" | Function,-,getsubopt,int,"char**, char**, char**" | ||||||
| Function,-,getw,int,FILE* | Function,-,getw,int,FILE* | ||||||
| Function,-,gmtime,tm*,const time_t* |  | ||||||
| Function,-,gmtime_r,tm*,"const time_t*, tm*" |  | ||||||
| Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*" | Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*" | ||||||
| Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer" | Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer" | ||||||
| Function,+,gui_direct_draw_acquire,Canvas*,Gui* | Function,+,gui_direct_draw_acquire,Canvas*,Gui* | ||||||
| @ -1637,8 +1631,6 @@ Function,+,locale_get_time_format,LocaleTimeFormat, | |||||||
| Function,+,locale_set_date_format,void,LocaleDateFormat | Function,+,locale_set_date_format,void,LocaleDateFormat | ||||||
| Function,+,locale_set_measurement_unit,void,LocaleMeasurementUnits | Function,+,locale_set_measurement_unit,void,LocaleMeasurementUnits | ||||||
| Function,+,locale_set_time_format,void,LocaleTimeFormat | Function,+,locale_set_time_format,void,LocaleTimeFormat | ||||||
| Function,-,localtime,tm*,const time_t* |  | ||||||
| Function,-,localtime_r,tm*,"const time_t*, tm*" |  | ||||||
| Function,-,log,double,double | Function,-,log,double,double | ||||||
| Function,-,log10,double,double | Function,-,log10,double,double | ||||||
| Function,-,log10f,float,float | Function,-,log10f,float,float | ||||||
| @ -1682,29 +1674,167 @@ Function,-,mbedtls_des_init,void,mbedtls_des_context* | |||||||
| Function,-,mbedtls_des_key_check_key_parity,int,const unsigned char[8] | Function,-,mbedtls_des_key_check_key_parity,int,const unsigned char[8] | ||||||
| Function,-,mbedtls_des_key_check_weak,int,const unsigned char[8] | Function,-,mbedtls_des_key_check_weak,int,const unsigned char[8] | ||||||
| Function,-,mbedtls_des_key_set_parity,void,unsigned char[8] | Function,-,mbedtls_des_key_set_parity,void,unsigned char[8] | ||||||
| Function,-,mbedtls_des_self_test,int,int |  | ||||||
| Function,-,mbedtls_des_setkey,void,"uint32_t[32], const unsigned char[8]" | Function,-,mbedtls_des_setkey,void,"uint32_t[32], const unsigned char[8]" | ||||||
| Function,-,mbedtls_des_setkey_dec,int,"mbedtls_des_context*, const unsigned char[8]" | Function,-,mbedtls_des_setkey_dec,int,"mbedtls_des_context*, const unsigned char[8]" | ||||||
| Function,-,mbedtls_des_setkey_enc,int,"mbedtls_des_context*, const unsigned char[8]" | Function,-,mbedtls_des_setkey_enc,int,"mbedtls_des_context*, const unsigned char[8]" | ||||||
|  | Function,-,mbedtls_ecdh_calc_secret,int,"mbedtls_ecdh_context*, size_t*, unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_can_do,int,mbedtls_ecp_group_id | ||||||
|  | Function,-,mbedtls_ecdh_compute_shared,int,"mbedtls_ecp_group*, mbedtls_mpi*, const mbedtls_ecp_point*, const mbedtls_mpi*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_free,void,mbedtls_ecdh_context* | ||||||
|  | Function,-,mbedtls_ecdh_gen_public,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_get_params,int,"mbedtls_ecdh_context*, const mbedtls_ecp_keypair*, mbedtls_ecdh_side" | ||||||
|  | Function,-,mbedtls_ecdh_init,void,mbedtls_ecdh_context* | ||||||
|  | Function,-,mbedtls_ecdh_make_params,int,"mbedtls_ecdh_context*, size_t*, unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_make_public,int,"mbedtls_ecdh_context*, size_t*, unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_read_params,int,"mbedtls_ecdh_context*, const unsigned char**, const unsigned char*" | ||||||
|  | Function,-,mbedtls_ecdh_read_public,int,"mbedtls_ecdh_context*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecdh_setup,int,"mbedtls_ecdh_context*, mbedtls_ecp_group_id" | ||||||
|  | Function,-,mbedtls_ecdsa_can_do,int,mbedtls_ecp_group_id | ||||||
|  | Function,-,mbedtls_ecdsa_free,void,mbedtls_ecdsa_context* | ||||||
|  | Function,-,mbedtls_ecdsa_from_keypair,int,"mbedtls_ecdsa_context*, const mbedtls_ecp_keypair*" | ||||||
|  | Function,-,mbedtls_ecdsa_genkey,int,"mbedtls_ecdsa_context*, mbedtls_ecp_group_id, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdsa_init,void,mbedtls_ecdsa_context* | ||||||
|  | Function,-,mbedtls_ecdsa_read_signature,int,"mbedtls_ecdsa_context*, const unsigned char*, size_t, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecdsa_read_signature_restartable,int,"mbedtls_ecdsa_context*, const unsigned char*, size_t, const unsigned char*, size_t, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecdsa_sign,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, const unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdsa_sign_restartable,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, const unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*, int (*)(void*, unsigned char*, size_t), void*, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecdsa_verify,int,"mbedtls_ecp_group*, const unsigned char*, size_t, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_ecdsa_verify_restartable,int,"mbedtls_ecp_group*, const unsigned char*, size_t, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_mpi*, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecdsa_write_signature,int,"mbedtls_ecdsa_context*, mbedtls_md_type_t, const unsigned char*, size_t, unsigned char*, size_t, size_t*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdsa_write_signature_restartable,int,"mbedtls_ecdsa_context*, mbedtls_md_type_t, const unsigned char*, size_t, unsigned char*, size_t, size_t*, int (*)(void*, unsigned char*, size_t), void*, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecp_check_privkey,int,"const mbedtls_ecp_group*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_ecp_check_pub_priv,int,"const mbedtls_ecp_keypair*, const mbedtls_ecp_keypair*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_check_pubkey,int,"const mbedtls_ecp_group*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_copy,int,"mbedtls_ecp_point*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_curve_info_from_grp_id,const mbedtls_ecp_curve_info*,mbedtls_ecp_group_id | ||||||
|  | Function,-,mbedtls_ecp_curve_info_from_name,const mbedtls_ecp_curve_info*,const char* | ||||||
|  | Function,-,mbedtls_ecp_curve_info_from_tls_id,const mbedtls_ecp_curve_info*,uint16_t | ||||||
|  | Function,-,mbedtls_ecp_curve_list,const mbedtls_ecp_curve_info*, | ||||||
|  | Function,-,mbedtls_ecp_export,int,"const mbedtls_ecp_keypair*, mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_gen_key,int,"mbedtls_ecp_group_id, mbedtls_ecp_keypair*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_gen_keypair,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_gen_keypair_base,int,"mbedtls_ecp_group*, const mbedtls_ecp_point*, mbedtls_mpi*, mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_gen_privkey,int,"const mbedtls_ecp_group*, mbedtls_mpi*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_get_type,mbedtls_ecp_curve_type,const mbedtls_ecp_group* | ||||||
|  | Function,-,mbedtls_ecp_group_copy,int,"mbedtls_ecp_group*, const mbedtls_ecp_group*" | ||||||
|  | Function,-,mbedtls_ecp_group_free,void,mbedtls_ecp_group* | ||||||
|  | Function,-,mbedtls_ecp_group_init,void,mbedtls_ecp_group* | ||||||
|  | Function,-,mbedtls_ecp_group_load,int,"mbedtls_ecp_group*, mbedtls_ecp_group_id" | ||||||
|  | Function,-,mbedtls_ecp_grp_id_list,const mbedtls_ecp_group_id*, | ||||||
|  | Function,-,mbedtls_ecp_is_zero,int,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_keypair_free,void,mbedtls_ecp_keypair* | ||||||
|  | Function,-,mbedtls_ecp_keypair_init,void,mbedtls_ecp_keypair* | ||||||
|  | Function,-,mbedtls_ecp_mul,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_mul_restartable,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*, mbedtls_ecp_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecp_muladd,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_muladd_restartable,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, mbedtls_ecp_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecp_point_cmp,int,"const mbedtls_ecp_point*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_point_free,void,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_point_init,void,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_point_read_binary,int,"const mbedtls_ecp_group*, mbedtls_ecp_point*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_point_read_string,int,"mbedtls_ecp_point*, int, const char*, const char*" | ||||||
|  | Function,-,mbedtls_ecp_point_write_binary,int,"const mbedtls_ecp_group*, const mbedtls_ecp_point*, int, size_t*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_read_key,int,"mbedtls_ecp_group_id, mbedtls_ecp_keypair*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_set_zero,int,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_tls_read_group,int,"mbedtls_ecp_group*, const unsigned char**, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_read_group_id,int,"mbedtls_ecp_group_id*, const unsigned char**, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_read_point,int,"const mbedtls_ecp_group*, mbedtls_ecp_point*, const unsigned char**, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_write_group,int,"const mbedtls_ecp_group*, size_t*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_write_point,int,"const mbedtls_ecp_group*, const mbedtls_ecp_point*, int, size_t*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_write_key,int,"mbedtls_ecp_keypair*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_internal_md5_process,int,"mbedtls_md5_context*, const unsigned char[64]" | ||||||
| Function,-,mbedtls_internal_sha1_process,int,"mbedtls_sha1_context*, const unsigned char[64]" | Function,-,mbedtls_internal_sha1_process,int,"mbedtls_sha1_context*, const unsigned char[64]" | ||||||
| Function,-,mbedtls_platform_gmtime_r,tm*,"const mbedtls_time_t*, tm*" | Function,-,mbedtls_internal_sha256_process,int,"mbedtls_sha256_context*, const unsigned char[64]" | ||||||
|  | Function,-,mbedtls_md,int,"const mbedtls_md_info_t*, const unsigned char*, size_t, unsigned char*" | ||||||
|  | Function,-,mbedtls_md5,int,"const unsigned char*, size_t, unsigned char[16]" | ||||||
|  | Function,-,mbedtls_md5_clone,void,"mbedtls_md5_context*, const mbedtls_md5_context*" | ||||||
|  | Function,-,mbedtls_md5_finish,int,"mbedtls_md5_context*, unsigned char[16]" | ||||||
|  | Function,-,mbedtls_md5_free,void,mbedtls_md5_context* | ||||||
|  | Function,-,mbedtls_md5_init,void,mbedtls_md5_context* | ||||||
|  | Function,-,mbedtls_md5_starts,int,mbedtls_md5_context* | ||||||
|  | Function,-,mbedtls_md5_update,int,"mbedtls_md5_context*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_md_clone,int,"mbedtls_md_context_t*, const mbedtls_md_context_t*" | ||||||
|  | Function,-,mbedtls_md_finish,int,"mbedtls_md_context_t*, unsigned char*" | ||||||
|  | Function,-,mbedtls_md_free,void,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_get_name,const char*,const mbedtls_md_info_t* | ||||||
|  | Function,-,mbedtls_md_get_size,unsigned char,const mbedtls_md_info_t* | ||||||
|  | Function,-,mbedtls_md_get_type,mbedtls_md_type_t,const mbedtls_md_info_t* | ||||||
|  | Function,-,mbedtls_md_hmac,int,"const mbedtls_md_info_t*, const unsigned char*, size_t, const unsigned char*, size_t, unsigned char*" | ||||||
|  | Function,-,mbedtls_md_hmac_finish,int,"mbedtls_md_context_t*, unsigned char*" | ||||||
|  | Function,-,mbedtls_md_hmac_reset,int,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_hmac_starts,int,"mbedtls_md_context_t*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_md_hmac_update,int,"mbedtls_md_context_t*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_md_info_from_ctx,const mbedtls_md_info_t*,const mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_info_from_string,const mbedtls_md_info_t*,const char* | ||||||
|  | Function,-,mbedtls_md_info_from_type,const mbedtls_md_info_t*,mbedtls_md_type_t | ||||||
|  | Function,-,mbedtls_md_init,void,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_list,const int*, | ||||||
|  | Function,-,mbedtls_md_setup,int,"mbedtls_md_context_t*, const mbedtls_md_info_t*, int" | ||||||
|  | Function,-,mbedtls_md_starts,int,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_update,int,"mbedtls_md_context_t*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_add_abs,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_add_int,int,"mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_add_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_bitlen,size_t,const mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_cmp_abs,int,"const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_cmp_int,int,"const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_cmp_mpi,int,"const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_copy,int,"mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_div_int,int,"mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_div_mpi,int,"mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_exp_mod,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_fill_random,int,"mbedtls_mpi*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_free,void,mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_gcd,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_gen_prime,int,"mbedtls_mpi*, size_t, int, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_get_bit,int,"const mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_grow,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_init,void,mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_inv_mod,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_is_prime_ext,int,"const mbedtls_mpi*, int, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_lsb,size_t,const mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_lset,int,"mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_lt_mpi_ct,int,"const mbedtls_mpi*, const mbedtls_mpi*, unsigned*" | ||||||
|  | Function,-,mbedtls_mpi_mod_int,int,"mbedtls_mpi_uint*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_mod_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_mul_int,int,"mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_uint" | ||||||
|  | Function,-,mbedtls_mpi_mul_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_random,int,"mbedtls_mpi*, mbedtls_mpi_sint, const mbedtls_mpi*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_read_binary,int,"mbedtls_mpi*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_read_binary_le,int,"mbedtls_mpi*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_read_string,int,"mbedtls_mpi*, int, const char*" | ||||||
|  | Function,-,mbedtls_mpi_safe_cond_assign,int,"mbedtls_mpi*, const mbedtls_mpi*, unsigned char" | ||||||
|  | Function,-,mbedtls_mpi_safe_cond_swap,int,"mbedtls_mpi*, mbedtls_mpi*, unsigned char" | ||||||
|  | Function,-,mbedtls_mpi_set_bit,int,"mbedtls_mpi*, size_t, unsigned char" | ||||||
|  | Function,-,mbedtls_mpi_shift_l,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_shift_r,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_shrink,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_size,size_t,const mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_sub_abs,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_sub_int,int,"mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_sub_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_swap,void,"mbedtls_mpi*, mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_write_binary,int,"const mbedtls_mpi*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_write_binary_le,int,"const mbedtls_mpi*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_write_string,int,"const mbedtls_mpi*, int, char*, size_t, size_t*" | ||||||
| Function,-,mbedtls_platform_zeroize,void,"void*, size_t" | Function,-,mbedtls_platform_zeroize,void,"void*, size_t" | ||||||
| Function,-,mbedtls_sha1,int,"const unsigned char*, size_t, unsigned char[20]" | Function,-,mbedtls_sha1,int,"const unsigned char*, size_t, unsigned char[20]" | ||||||
| Function,-,mbedtls_sha1_clone,void,"mbedtls_sha1_context*, const mbedtls_sha1_context*" | Function,-,mbedtls_sha1_clone,void,"mbedtls_sha1_context*, const mbedtls_sha1_context*" | ||||||
| Function,-,mbedtls_sha1_finish,int,"mbedtls_sha1_context*, unsigned char[20]" | Function,-,mbedtls_sha1_finish,int,"mbedtls_sha1_context*, unsigned char[20]" | ||||||
| Function,-,mbedtls_sha1_free,void,mbedtls_sha1_context* | Function,-,mbedtls_sha1_free,void,mbedtls_sha1_context* | ||||||
| Function,-,mbedtls_sha1_init,void,mbedtls_sha1_context* | Function,-,mbedtls_sha1_init,void,mbedtls_sha1_context* | ||||||
| Function,-,mbedtls_sha1_self_test,int,int |  | ||||||
| Function,-,mbedtls_sha1_starts,int,mbedtls_sha1_context* | Function,-,mbedtls_sha1_starts,int,mbedtls_sha1_context* | ||||||
| Function,-,mbedtls_sha1_update,int,"mbedtls_sha1_context*, const unsigned char*, size_t" | Function,-,mbedtls_sha1_update,int,"mbedtls_sha1_context*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_sha256,int,"const unsigned char*, size_t, unsigned char*, int" | ||||||
|  | Function,-,mbedtls_sha256_clone,void,"mbedtls_sha256_context*, const mbedtls_sha256_context*" | ||||||
|  | Function,-,mbedtls_sha256_finish,int,"mbedtls_sha256_context*, unsigned char*" | ||||||
|  | Function,-,mbedtls_sha256_free,void,mbedtls_sha256_context* | ||||||
|  | Function,-,mbedtls_sha256_init,void,mbedtls_sha256_context* | ||||||
|  | Function,-,mbedtls_sha256_starts,int,"mbedtls_sha256_context*, int" | ||||||
|  | Function,-,mbedtls_sha256_update,int,"mbedtls_sha256_context*, const unsigned char*, size_t" | ||||||
| Function,-,mblen,int,"const char*, size_t" | Function,-,mblen,int,"const char*, size_t" | ||||||
| Function,-,mbstowcs,size_t,"wchar_t*, const char*, size_t" | Function,-,mbstowcs,size_t,"wchar_t*, const char*, size_t" | ||||||
| Function,-,mbtowc,int,"wchar_t*, const char*, size_t" | Function,-,mbtowc,int,"wchar_t*, const char*, size_t" | ||||||
| Function,+,md5,void,"const unsigned char*, size_t, unsigned char[16]" |  | ||||||
| Function,+,md5_finish,void,"md5_context*, unsigned char[16]" |  | ||||||
| Function,+,md5_process,void,"md5_context*, const unsigned char[64]" |  | ||||||
| Function,+,md5_starts,void,md5_context* |  | ||||||
| Function,+,md5_update,void,"md5_context*, const unsigned char*, size_t" |  | ||||||
| Function,-,memccpy,void*,"void*, const void*, int, size_t" | Function,-,memccpy,void*,"void*, const void*, int, size_t" | ||||||
| Function,+,memchr,void*,"const void*, int, size_t" | Function,+,memchr,void*,"const void*, int, size_t" | ||||||
| Function,+,memcmp,int,"const void*, const void*, size_t" | Function,+,memcmp,int,"const void*, const void*, size_t" | ||||||
| @ -1737,7 +1867,6 @@ Function,-,mkostemps,int,"char*, int, int" | |||||||
| Function,-,mkstemp,int,char* | Function,-,mkstemp,int,char* | ||||||
| Function,-,mkstemps,int,"char*, int" | Function,-,mkstemps,int,"char*, int" | ||||||
| Function,-,mktemp,char*,char* | Function,-,mktemp,char*,char* | ||||||
| Function,-,mktime,time_t,tm* |  | ||||||
| Function,-,modf,double,"double, double*" | Function,-,modf,double,"double, double*" | ||||||
| Function,-,modff,float,"float, float*" | Function,-,modff,float,"float, float*" | ||||||
| Function,-,modfl,long double,"long double, long double*" | Function,-,modfl,long double,"long double, long double*" | ||||||
| @ -2003,11 +2132,6 @@ Function,-,setkey,void,const char* | |||||||
| Function,-,setlinebuf,int,FILE* | Function,-,setlinebuf,int,FILE* | ||||||
| Function,-,setstate,char*,char* | Function,-,setstate,char*,char* | ||||||
| Function,-,setvbuf,int,"FILE*, char*, int, size_t" | Function,-,setvbuf,int,"FILE*, char*, int, size_t" | ||||||
| Function,+,sha256,void,"const unsigned char*, unsigned int, unsigned char[32]" |  | ||||||
| Function,+,sha256_finish,void,"sha256_context*, unsigned char[32]" |  | ||||||
| Function,+,sha256_process,void,sha256_context* |  | ||||||
| Function,+,sha256_start,void,sha256_context* |  | ||||||
| Function,+,sha256_update,void,"sha256_context*, const unsigned char*, unsigned int" |  | ||||||
| Function,+,signal_reader_alloc,SignalReader*,"const GpioPin*, uint32_t" | Function,+,signal_reader_alloc,SignalReader*,"const GpioPin*, uint32_t" | ||||||
| Function,+,signal_reader_free,void,SignalReader* | Function,+,signal_reader_free,void,SignalReader* | ||||||
| Function,+,signal_reader_set_polarity,void,"SignalReader*, SignalReaderPolarity" | Function,+,signal_reader_set_polarity,void,"SignalReader*, SignalReaderPolarity" | ||||||
| @ -2171,8 +2295,6 @@ Function,+,stream_write_vaformat,size_t,"Stream*, const char*, va_list" | |||||||
| Function,-,strerror,char*,int | Function,-,strerror,char*,int | ||||||
| Function,-,strerror_l,char*,"int, locale_t" | Function,-,strerror_l,char*,"int, locale_t" | ||||||
| Function,-,strerror_r,char*,"int, char*, size_t" | Function,-,strerror_r,char*,"int, char*, size_t" | ||||||
| Function,-,strftime,size_t,"char*, size_t, const char*, const tm*" |  | ||||||
| Function,-,strftime_l,size_t,"char*, size_t, const char*, const tm*, locale_t" |  | ||||||
| Function,+,string_stream_alloc,Stream*, | Function,+,string_stream_alloc,Stream*, | ||||||
| Function,-,strlcat,size_t,"char*, const char*, size_t" | Function,-,strlcat,size_t,"char*, const char*, size_t" | ||||||
| Function,+,strlcpy,size_t,"char*, const char*, size_t" | Function,+,strlcpy,size_t,"char*, const char*, size_t" | ||||||
| @ -2187,8 +2309,6 @@ Function,-,strndup,char*,"const char*, size_t" | |||||||
| Function,-,strnlen,size_t,"const char*, size_t" | Function,-,strnlen,size_t,"const char*, size_t" | ||||||
| Function,-,strnstr,char*,"const char*, const char*, size_t" | Function,-,strnstr,char*,"const char*, const char*, size_t" | ||||||
| Function,-,strpbrk,char*,"const char*, const char*" | Function,-,strpbrk,char*,"const char*, const char*" | ||||||
| Function,-,strptime,char*,"const char*, const char*, tm*" |  | ||||||
| Function,-,strptime_l,char*,"const char*, const char*, tm*, locale_t" |  | ||||||
| Function,+,strrchr,char*,"const char*, int" | Function,+,strrchr,char*,"const char*, int" | ||||||
| Function,-,strsep,char*,"char**, const char*" | Function,-,strsep,char*,"char**, const char*" | ||||||
| Function,-,strsignal,char*,int | Function,-,strsignal,char*,int | ||||||
| @ -2263,7 +2383,6 @@ Function,+,text_input_set_validator,void,"TextInput*, TextInputValidatorCallback | |||||||
| Function,-,tgamma,double,double | Function,-,tgamma,double,double | ||||||
| Function,-,tgammaf,float,float | Function,-,tgammaf,float,float | ||||||
| Function,-,tgammal,long double,long double | Function,-,tgammal,long double,long double | ||||||
| Function,-,time,time_t,time_t* |  | ||||||
| Function,-,timingsafe_bcmp,int,"const void*, const void*, size_t" | Function,-,timingsafe_bcmp,int,"const void*, const void*, size_t" | ||||||
| Function,-,timingsafe_memcmp,int,"const void*, const void*, size_t" | Function,-,timingsafe_memcmp,int,"const void*, const void*, size_t" | ||||||
| Function,-,tmpfile,FILE*, | Function,-,tmpfile,FILE*, | ||||||
| @ -2277,25 +2396,6 @@ Function,-,toupper_l,int,"int, locale_t" | |||||||
| Function,-,trunc,double,double | Function,-,trunc,double,double | ||||||
| Function,-,truncf,float,float | Function,-,truncf,float,float | ||||||
| Function,-,truncl,long double,long double | Function,-,truncl,long double,long double | ||||||
| Function,-,tzset,void, |  | ||||||
| Function,-,uECC_compress,void,"const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,+,uECC_compute_public_key,int,"const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_curve_private_key_size,int,uECC_Curve |  | ||||||
| Function,-,uECC_curve_public_key_size,int,uECC_Curve |  | ||||||
| Function,-,uECC_decompress,void,"const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_get_rng,uECC_RNG_Function, |  | ||||||
| Function,-,uECC_make_key,int,"uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_secp160r1,uECC_Curve, |  | ||||||
| Function,-,uECC_secp192r1,uECC_Curve, |  | ||||||
| Function,-,uECC_secp224r1,uECC_Curve, |  | ||||||
| Function,-,uECC_secp256k1,uECC_Curve, |  | ||||||
| Function,+,uECC_secp256r1,uECC_Curve, |  | ||||||
| Function,+,uECC_set_rng,void,uECC_RNG_Function |  | ||||||
| Function,-,uECC_shared_secret,int,"const uint8_t*, const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,+,uECC_sign,int,"const uint8_t*, const uint8_t*, unsigned, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_sign_deterministic,int,"const uint8_t*, const uint8_t*, unsigned, const uECC_HashContext*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_valid_public_key,int,"const uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_verify,int,"const uint8_t*, const uint8_t*, unsigned, const uint8_t*, uECC_Curve" |  | ||||||
| Function,+,uint8_to_hex_chars,void,"const uint8_t*, uint8_t*, int" | Function,+,uint8_to_hex_chars,void,"const uint8_t*, uint8_t*, int" | ||||||
| Function,-,ungetc,int,"int, FILE*" | Function,-,ungetc,int,"int, FILE*" | ||||||
| Function,-,unsetenv,int,const char* | Function,-,unsetenv,int,const char* | ||||||
| @ -2428,13 +2528,10 @@ Variable,-,MSIRangeTable,const uint32_t[16], | |||||||
| Variable,-,SmpsPrescalerTable,const uint32_t[4][6], | Variable,-,SmpsPrescalerTable,const uint32_t[4][6], | ||||||
| Variable,+,SystemCoreClock,uint32_t, | Variable,+,SystemCoreClock,uint32_t, | ||||||
| Variable,+,_ctype_,const char[], | Variable,+,_ctype_,const char[], | ||||||
| Variable,-,_daylight,int, |  | ||||||
| Variable,+,_global_impure_ptr,_reent*, | Variable,+,_global_impure_ptr,_reent*, | ||||||
| Variable,+,_impure_ptr,_reent*, | Variable,+,_impure_ptr,_reent*, | ||||||
| Variable,-,_sys_errlist,const char*[], | Variable,-,_sys_errlist,const char*[], | ||||||
| Variable,-,_sys_nerr,int, | Variable,-,_sys_nerr,int, | ||||||
| Variable,-,_timezone,long, |  | ||||||
| Variable,-,_tzname,char*[2], |  | ||||||
| Variable,+,cli_vcp,CliSession, | Variable,+,cli_vcp,CliSession, | ||||||
| Variable,+,firmware_api_interface,const ElfApiInterface*, | Variable,+,firmware_api_interface,const ElfApiInterface*, | ||||||
| Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus, | Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus, | ||||||
|  | |||||||
| 
 | 
| @ -18,7 +18,6 @@ | |||||||
|         "hwdrivers", |         "hwdrivers", | ||||||
|         "fatfs", |         "fatfs", | ||||||
|         "littlefs", |         "littlefs", | ||||||
|         "flipperformat", |  | ||||||
|         "toolbox", |         "toolbox", | ||||||
|         "digital_signal", |         "digital_signal", | ||||||
|         "signal_reader", |         "signal_reader", | ||||||
| @ -28,12 +27,15 @@ | |||||||
|         "assets", |         "assets", | ||||||
|         "one_wire", |         "one_wire", | ||||||
|         "music_worker", |         "music_worker", | ||||||
|         "misc", |         "mbedtls", | ||||||
|         "flipper_application", |         "flipper_application", | ||||||
|         "flipperformat", |  | ||||||
|         "toolbox", |         "toolbox", | ||||||
|  |         "u8g2", | ||||||
|  |         "nanopb", | ||||||
|  |         "update_util", | ||||||
|  |         "heatshrink", | ||||||
|  |         "flipperformat", | ||||||
|         "flipper18" |         "flipper18" | ||||||
| 
 |  | ||||||
|     ], |     ], | ||||||
|     "excluded_sources": [ |     "excluded_sources": [ | ||||||
|         "furi_hal_infrared.c", |         "furi_hal_infrared.c", | ||||||
| @ -63,4 +65,4 @@ | |||||||
|         "ibutton", |         "ibutton", | ||||||
|         "infrared" |         "infrared" | ||||||
|     ] |     ] | ||||||
| } | } | ||||||
| @ -1,5 +1,5 @@ | |||||||
| entry,status,name,type,params | entry,status,name,type,params | ||||||
| Version,+,47.0,, | Version,+,48.0,, | ||||||
| Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, | Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, | ||||||
| Header,+,applications/services/bt/bt_service/bt.h,, | Header,+,applications/services/bt/bt_service/bt.h,, | ||||||
| Header,+,applications/services/cli/cli.h,, | Header,+,applications/services/cli/cli.h,, | ||||||
| @ -90,8 +90,13 @@ Header,+,lib/libusb_stm32/inc/usb_std.h,, | |||||||
| Header,+,lib/libusb_stm32/inc/usb_tmc.h,, | Header,+,lib/libusb_stm32/inc/usb_tmc.h,, | ||||||
| Header,+,lib/libusb_stm32/inc/usbd_core.h,, | Header,+,lib/libusb_stm32/inc/usbd_core.h,, | ||||||
| Header,+,lib/mbedtls/include/mbedtls/des.h,, | Header,+,lib/mbedtls/include/mbedtls/des.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/ecdh.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/ecdsa.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/ecp.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/md.h,, | ||||||
|  | Header,+,lib/mbedtls/include/mbedtls/md5.h,, | ||||||
| Header,+,lib/mbedtls/include/mbedtls/sha1.h,, | Header,+,lib/mbedtls/include/mbedtls/sha1.h,, | ||||||
| Header,+,lib/micro-ecc/uECC.h,, | Header,+,lib/mbedtls/include/mbedtls/sha256.h,, | ||||||
| Header,+,lib/mlib/m-algo.h,, | Header,+,lib/mlib/m-algo.h,, | ||||||
| Header,+,lib/mlib/m-array.h,, | Header,+,lib/mlib/m-array.h,, | ||||||
| Header,+,lib/mlib/m-bptree.h,, | Header,+,lib/mlib/m-bptree.h,, | ||||||
| @ -200,13 +205,11 @@ Header,+,lib/toolbox/float_tools.h,, | |||||||
| Header,+,lib/toolbox/hex.h,, | Header,+,lib/toolbox/hex.h,, | ||||||
| Header,+,lib/toolbox/manchester_decoder.h,, | Header,+,lib/toolbox/manchester_decoder.h,, | ||||||
| Header,+,lib/toolbox/manchester_encoder.h,, | Header,+,lib/toolbox/manchester_encoder.h,, | ||||||
| Header,+,lib/toolbox/md5.h,, |  | ||||||
| Header,+,lib/toolbox/name_generator.h,, | Header,+,lib/toolbox/name_generator.h,, | ||||||
| Header,+,lib/toolbox/path.h,, | Header,+,lib/toolbox/path.h,, | ||||||
| Header,+,lib/toolbox/pretty_format.h,, | Header,+,lib/toolbox/pretty_format.h,, | ||||||
| Header,+,lib/toolbox/protocols/protocol_dict.h,, | Header,+,lib/toolbox/protocols/protocol_dict.h,, | ||||||
| Header,+,lib/toolbox/saved_struct.h,, | Header,+,lib/toolbox/saved_struct.h,, | ||||||
| Header,+,lib/toolbox/sha256.h,, |  | ||||||
| Header,+,lib/toolbox/simple_array.h,, | Header,+,lib/toolbox/simple_array.h,, | ||||||
| Header,+,lib/toolbox/stream/buffered_file_stream.h,, | Header,+,lib/toolbox/stream/buffered_file_stream.h,, | ||||||
| Header,+,lib/toolbox/stream/file_stream.h,, | Header,+,lib/toolbox/stream/file_stream.h,, | ||||||
| @ -521,7 +524,6 @@ Function,-,_system_r,int,"_reent*, const char*" | |||||||
| Function,-,_tempnam_r,char*,"_reent*, const char*, const char*" | Function,-,_tempnam_r,char*,"_reent*, const char*, const char*" | ||||||
| Function,-,_tmpfile_r,FILE*,_reent* | Function,-,_tmpfile_r,FILE*,_reent* | ||||||
| Function,-,_tmpnam_r,char*,"_reent*, char*" | Function,-,_tmpnam_r,char*,"_reent*, char*" | ||||||
| Function,-,_tzset_r,void,_reent* |  | ||||||
| Function,-,_ungetc_r,int,"_reent*, int, FILE*" | Function,-,_ungetc_r,int,"_reent*, int, FILE*" | ||||||
| Function,-,_unsetenv_r,int,"_reent*, const char*" | Function,-,_unsetenv_r,int,"_reent*, const char*" | ||||||
| Function,-,_vasiprintf_r,int,"_reent*, char**, const char*, __gnuc_va_list" | Function,-,_vasiprintf_r,int,"_reent*, char**, const char*, __gnuc_va_list" | ||||||
| @ -568,8 +570,6 @@ Function,+,args_read_hex_bytes,_Bool,"FuriString*, uint8_t*, size_t" | |||||||
| Function,+,args_read_int_and_trim,_Bool,"FuriString*, int*" | Function,+,args_read_int_and_trim,_Bool,"FuriString*, int*" | ||||||
| Function,+,args_read_probably_quoted_string_and_trim,_Bool,"FuriString*, FuriString*" | Function,+,args_read_probably_quoted_string_and_trim,_Bool,"FuriString*, FuriString*" | ||||||
| Function,+,args_read_string_and_trim,_Bool,"FuriString*, FuriString*" | Function,+,args_read_string_and_trim,_Bool,"FuriString*, FuriString*" | ||||||
| Function,-,asctime,char*,const tm* |  | ||||||
| Function,-,asctime_r,char*,"const tm*, char*" |  | ||||||
| Function,-,asin,double,double | Function,-,asin,double,double | ||||||
| Function,-,asinf,float,float | Function,-,asinf,float,float | ||||||
| Function,-,asinh,double,double | Function,-,asinh,double,double | ||||||
| @ -700,7 +700,7 @@ Function,+,byte_input_get_view,View*,ByteInput* | |||||||
| Function,+,byte_input_set_header_text,void,"ByteInput*, const char*" | Function,+,byte_input_set_header_text,void,"ByteInput*, const char*" | ||||||
| Function,+,byte_input_set_result_callback,void,"ByteInput*, ByteInputCallback, ByteChangedCallback, void*, uint8_t*, uint8_t" | Function,+,byte_input_set_result_callback,void,"ByteInput*, ByteInputCallback, ByteChangedCallback, void*, uint8_t*, uint8_t" | ||||||
| Function,-,bzero,void,"void*, size_t" | Function,-,bzero,void,"void*, size_t" | ||||||
| Function,-,calloc,void*,"size_t, size_t" | Function,+,calloc,void*,"size_t, size_t" | ||||||
| Function,+,canvas_clear,void,Canvas* | Function,+,canvas_clear,void,Canvas* | ||||||
| Function,+,canvas_commit,void,Canvas* | Function,+,canvas_commit,void,Canvas* | ||||||
| Function,+,canvas_current_font_height,uint8_t,const Canvas* | Function,+,canvas_current_font_height,uint8_t,const Canvas* | ||||||
| @ -754,7 +754,6 @@ Function,+,cli_read_timeout,size_t,"Cli*, uint8_t*, size_t, uint32_t" | |||||||
| Function,+,cli_session_close,void,Cli* | Function,+,cli_session_close,void,Cli* | ||||||
| Function,+,cli_session_open,void,"Cli*, void*" | Function,+,cli_session_open,void,"Cli*, void*" | ||||||
| Function,+,cli_write,void,"Cli*, const uint8_t*, size_t" | Function,+,cli_write,void,"Cli*, const uint8_t*, size_t" | ||||||
| Function,-,clock,clock_t, |  | ||||||
| Function,+,composite_api_resolver_add,void,"CompositeApiResolver*, const ElfApiInterface*" | Function,+,composite_api_resolver_add,void,"CompositeApiResolver*, const ElfApiInterface*" | ||||||
| Function,+,composite_api_resolver_alloc,CompositeApiResolver*, | Function,+,composite_api_resolver_alloc,CompositeApiResolver*, | ||||||
| Function,+,composite_api_resolver_free,void,CompositeApiResolver* | Function,+,composite_api_resolver_free,void,CompositeApiResolver* | ||||||
| @ -778,8 +777,6 @@ Function,-,cosl,long double,long double | |||||||
| Function,+,crc32_calc_buffer,uint32_t,"uint32_t, const void*, size_t" | Function,+,crc32_calc_buffer,uint32_t,"uint32_t, const void*, size_t" | ||||||
| Function,+,crc32_calc_file,uint32_t,"File*, const FileCrcProgressCb, void*" | Function,+,crc32_calc_file,uint32_t,"File*, const FileCrcProgressCb, void*" | ||||||
| Function,-,ctermid,char*,char* | Function,-,ctermid,char*,char* | ||||||
| Function,-,ctime,char*,const time_t* |  | ||||||
| Function,-,ctime_r,char*,"const time_t*, char*" |  | ||||||
| Function,-,cuserid,char*,char* | Function,-,cuserid,char*,char* | ||||||
| Function,+,dialog_ex_alloc,DialogEx*, | Function,+,dialog_ex_alloc,DialogEx*, | ||||||
| Function,+,dialog_ex_disable_extended_events,void,DialogEx* | Function,+,dialog_ex_disable_extended_events,void,DialogEx* | ||||||
| @ -805,7 +802,6 @@ Function,+,dialog_message_set_icon,void,"DialogMessage*, const Icon*, uint8_t, u | |||||||
| Function,+,dialog_message_set_text,void,"DialogMessage*, const char*, uint8_t, uint8_t, Align, Align" | Function,+,dialog_message_set_text,void,"DialogMessage*, const char*, uint8_t, uint8_t, Align, Align" | ||||||
| Function,+,dialog_message_show,DialogMessageButton,"DialogsApp*, const DialogMessage*" | Function,+,dialog_message_show,DialogMessageButton,"DialogsApp*, const DialogMessage*" | ||||||
| Function,+,dialog_message_show_storage_error,void,"DialogsApp*, const char*" | Function,+,dialog_message_show_storage_error,void,"DialogsApp*, const char*" | ||||||
| Function,-,difftime,double,"time_t, time_t" |  | ||||||
| Function,+,digital_sequence_add_signal,void,"DigitalSequence*, uint8_t" | Function,+,digital_sequence_add_signal,void,"DigitalSequence*, uint8_t" | ||||||
| Function,-,digital_sequence_alloc,DigitalSequence*,"uint32_t, const GpioPin*" | Function,-,digital_sequence_alloc,DigitalSequence*,"uint32_t, const GpioPin*" | ||||||
| Function,-,digital_sequence_clear,void,DigitalSequence* | Function,-,digital_sequence_clear,void,DigitalSequence* | ||||||
| @ -1714,8 +1710,6 @@ Function,-,getenv,char*,const char* | |||||||
| Function,-,gets,char*,char* | Function,-,gets,char*,char* | ||||||
| Function,-,getsubopt,int,"char**, char**, char**" | Function,-,getsubopt,int,"char**, char**, char**" | ||||||
| Function,-,getw,int,FILE* | Function,-,getw,int,FILE* | ||||||
| Function,-,gmtime,tm*,const time_t* |  | ||||||
| Function,-,gmtime_r,tm*,"const time_t*, tm*" |  | ||||||
| Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*" | Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*" | ||||||
| Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer" | Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer" | ||||||
| Function,+,gui_direct_draw_acquire,Canvas*,Gui* | Function,+,gui_direct_draw_acquire,Canvas*,Gui* | ||||||
| @ -2036,8 +2030,6 @@ Function,+,locale_get_time_format,LocaleTimeFormat, | |||||||
| Function,+,locale_set_date_format,void,LocaleDateFormat | Function,+,locale_set_date_format,void,LocaleDateFormat | ||||||
| Function,+,locale_set_measurement_unit,void,LocaleMeasurementUnits | Function,+,locale_set_measurement_unit,void,LocaleMeasurementUnits | ||||||
| Function,+,locale_set_time_format,void,LocaleTimeFormat | Function,+,locale_set_time_format,void,LocaleTimeFormat | ||||||
| Function,-,localtime,tm*,const time_t* |  | ||||||
| Function,-,localtime_r,tm*,"const time_t*, tm*" |  | ||||||
| Function,-,log,double,double | Function,-,log,double,double | ||||||
| Function,-,log10,double,double | Function,-,log10,double,double | ||||||
| Function,-,log10f,float,float | Function,-,log10f,float,float | ||||||
| @ -2081,29 +2073,167 @@ Function,-,mbedtls_des_init,void,mbedtls_des_context* | |||||||
| Function,-,mbedtls_des_key_check_key_parity,int,const unsigned char[8] | Function,-,mbedtls_des_key_check_key_parity,int,const unsigned char[8] | ||||||
| Function,-,mbedtls_des_key_check_weak,int,const unsigned char[8] | Function,-,mbedtls_des_key_check_weak,int,const unsigned char[8] | ||||||
| Function,-,mbedtls_des_key_set_parity,void,unsigned char[8] | Function,-,mbedtls_des_key_set_parity,void,unsigned char[8] | ||||||
| Function,-,mbedtls_des_self_test,int,int |  | ||||||
| Function,-,mbedtls_des_setkey,void,"uint32_t[32], const unsigned char[8]" | Function,-,mbedtls_des_setkey,void,"uint32_t[32], const unsigned char[8]" | ||||||
| Function,-,mbedtls_des_setkey_dec,int,"mbedtls_des_context*, const unsigned char[8]" | Function,-,mbedtls_des_setkey_dec,int,"mbedtls_des_context*, const unsigned char[8]" | ||||||
| Function,-,mbedtls_des_setkey_enc,int,"mbedtls_des_context*, const unsigned char[8]" | Function,-,mbedtls_des_setkey_enc,int,"mbedtls_des_context*, const unsigned char[8]" | ||||||
|  | Function,-,mbedtls_ecdh_calc_secret,int,"mbedtls_ecdh_context*, size_t*, unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_can_do,int,mbedtls_ecp_group_id | ||||||
|  | Function,-,mbedtls_ecdh_compute_shared,int,"mbedtls_ecp_group*, mbedtls_mpi*, const mbedtls_ecp_point*, const mbedtls_mpi*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_free,void,mbedtls_ecdh_context* | ||||||
|  | Function,-,mbedtls_ecdh_gen_public,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_get_params,int,"mbedtls_ecdh_context*, const mbedtls_ecp_keypair*, mbedtls_ecdh_side" | ||||||
|  | Function,-,mbedtls_ecdh_init,void,mbedtls_ecdh_context* | ||||||
|  | Function,-,mbedtls_ecdh_make_params,int,"mbedtls_ecdh_context*, size_t*, unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_make_public,int,"mbedtls_ecdh_context*, size_t*, unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdh_read_params,int,"mbedtls_ecdh_context*, const unsigned char**, const unsigned char*" | ||||||
|  | Function,-,mbedtls_ecdh_read_public,int,"mbedtls_ecdh_context*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecdh_setup,int,"mbedtls_ecdh_context*, mbedtls_ecp_group_id" | ||||||
|  | Function,-,mbedtls_ecdsa_can_do,int,mbedtls_ecp_group_id | ||||||
|  | Function,-,mbedtls_ecdsa_free,void,mbedtls_ecdsa_context* | ||||||
|  | Function,-,mbedtls_ecdsa_from_keypair,int,"mbedtls_ecdsa_context*, const mbedtls_ecp_keypair*" | ||||||
|  | Function,-,mbedtls_ecdsa_genkey,int,"mbedtls_ecdsa_context*, mbedtls_ecp_group_id, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdsa_init,void,mbedtls_ecdsa_context* | ||||||
|  | Function,-,mbedtls_ecdsa_read_signature,int,"mbedtls_ecdsa_context*, const unsigned char*, size_t, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecdsa_read_signature_restartable,int,"mbedtls_ecdsa_context*, const unsigned char*, size_t, const unsigned char*, size_t, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecdsa_sign,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, const unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdsa_sign_restartable,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, const unsigned char*, size_t, int (*)(void*, unsigned char*, size_t), void*, int (*)(void*, unsigned char*, size_t), void*, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecdsa_verify,int,"mbedtls_ecp_group*, const unsigned char*, size_t, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_ecdsa_verify_restartable,int,"mbedtls_ecp_group*, const unsigned char*, size_t, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_mpi*, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecdsa_write_signature,int,"mbedtls_ecdsa_context*, mbedtls_md_type_t, const unsigned char*, size_t, unsigned char*, size_t, size_t*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecdsa_write_signature_restartable,int,"mbedtls_ecdsa_context*, mbedtls_md_type_t, const unsigned char*, size_t, unsigned char*, size_t, size_t*, int (*)(void*, unsigned char*, size_t), void*, mbedtls_ecdsa_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecp_check_privkey,int,"const mbedtls_ecp_group*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_ecp_check_pub_priv,int,"const mbedtls_ecp_keypair*, const mbedtls_ecp_keypair*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_check_pubkey,int,"const mbedtls_ecp_group*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_copy,int,"mbedtls_ecp_point*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_curve_info_from_grp_id,const mbedtls_ecp_curve_info*,mbedtls_ecp_group_id | ||||||
|  | Function,-,mbedtls_ecp_curve_info_from_name,const mbedtls_ecp_curve_info*,const char* | ||||||
|  | Function,-,mbedtls_ecp_curve_info_from_tls_id,const mbedtls_ecp_curve_info*,uint16_t | ||||||
|  | Function,-,mbedtls_ecp_curve_list,const mbedtls_ecp_curve_info*, | ||||||
|  | Function,-,mbedtls_ecp_export,int,"const mbedtls_ecp_keypair*, mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_gen_key,int,"mbedtls_ecp_group_id, mbedtls_ecp_keypair*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_gen_keypair,int,"mbedtls_ecp_group*, mbedtls_mpi*, mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_gen_keypair_base,int,"mbedtls_ecp_group*, const mbedtls_ecp_point*, mbedtls_mpi*, mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_gen_privkey,int,"const mbedtls_ecp_group*, mbedtls_mpi*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_get_type,mbedtls_ecp_curve_type,const mbedtls_ecp_group* | ||||||
|  | Function,-,mbedtls_ecp_group_copy,int,"mbedtls_ecp_group*, const mbedtls_ecp_group*" | ||||||
|  | Function,-,mbedtls_ecp_group_free,void,mbedtls_ecp_group* | ||||||
|  | Function,-,mbedtls_ecp_group_init,void,mbedtls_ecp_group* | ||||||
|  | Function,-,mbedtls_ecp_group_load,int,"mbedtls_ecp_group*, mbedtls_ecp_group_id" | ||||||
|  | Function,-,mbedtls_ecp_grp_id_list,const mbedtls_ecp_group_id*, | ||||||
|  | Function,-,mbedtls_ecp_is_zero,int,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_keypair_free,void,mbedtls_ecp_keypair* | ||||||
|  | Function,-,mbedtls_ecp_keypair_init,void,mbedtls_ecp_keypair* | ||||||
|  | Function,-,mbedtls_ecp_mul,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_ecp_mul_restartable,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, int (*)(void*, unsigned char*, size_t), void*, mbedtls_ecp_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecp_muladd,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_muladd_restartable,int,"mbedtls_ecp_group*, mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, const mbedtls_mpi*, const mbedtls_ecp_point*, mbedtls_ecp_restart_ctx*" | ||||||
|  | Function,-,mbedtls_ecp_point_cmp,int,"const mbedtls_ecp_point*, const mbedtls_ecp_point*" | ||||||
|  | Function,-,mbedtls_ecp_point_free,void,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_point_init,void,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_point_read_binary,int,"const mbedtls_ecp_group*, mbedtls_ecp_point*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_point_read_string,int,"mbedtls_ecp_point*, int, const char*, const char*" | ||||||
|  | Function,-,mbedtls_ecp_point_write_binary,int,"const mbedtls_ecp_group*, const mbedtls_ecp_point*, int, size_t*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_read_key,int,"mbedtls_ecp_group_id, mbedtls_ecp_keypair*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_set_zero,int,mbedtls_ecp_point* | ||||||
|  | Function,-,mbedtls_ecp_tls_read_group,int,"mbedtls_ecp_group*, const unsigned char**, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_read_group_id,int,"mbedtls_ecp_group_id*, const unsigned char**, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_read_point,int,"const mbedtls_ecp_group*, mbedtls_ecp_point*, const unsigned char**, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_write_group,int,"const mbedtls_ecp_group*, size_t*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_tls_write_point,int,"const mbedtls_ecp_group*, const mbedtls_ecp_point*, int, size_t*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_ecp_write_key,int,"mbedtls_ecp_keypair*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_internal_md5_process,int,"mbedtls_md5_context*, const unsigned char[64]" | ||||||
| Function,-,mbedtls_internal_sha1_process,int,"mbedtls_sha1_context*, const unsigned char[64]" | Function,-,mbedtls_internal_sha1_process,int,"mbedtls_sha1_context*, const unsigned char[64]" | ||||||
| Function,-,mbedtls_platform_gmtime_r,tm*,"const mbedtls_time_t*, tm*" | Function,-,mbedtls_internal_sha256_process,int,"mbedtls_sha256_context*, const unsigned char[64]" | ||||||
|  | Function,-,mbedtls_md,int,"const mbedtls_md_info_t*, const unsigned char*, size_t, unsigned char*" | ||||||
|  | Function,-,mbedtls_md5,int,"const unsigned char*, size_t, unsigned char[16]" | ||||||
|  | Function,-,mbedtls_md5_clone,void,"mbedtls_md5_context*, const mbedtls_md5_context*" | ||||||
|  | Function,-,mbedtls_md5_finish,int,"mbedtls_md5_context*, unsigned char[16]" | ||||||
|  | Function,-,mbedtls_md5_free,void,mbedtls_md5_context* | ||||||
|  | Function,-,mbedtls_md5_init,void,mbedtls_md5_context* | ||||||
|  | Function,-,mbedtls_md5_starts,int,mbedtls_md5_context* | ||||||
|  | Function,-,mbedtls_md5_update,int,"mbedtls_md5_context*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_md_clone,int,"mbedtls_md_context_t*, const mbedtls_md_context_t*" | ||||||
|  | Function,-,mbedtls_md_finish,int,"mbedtls_md_context_t*, unsigned char*" | ||||||
|  | Function,-,mbedtls_md_free,void,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_get_name,const char*,const mbedtls_md_info_t* | ||||||
|  | Function,-,mbedtls_md_get_size,unsigned char,const mbedtls_md_info_t* | ||||||
|  | Function,-,mbedtls_md_get_type,mbedtls_md_type_t,const mbedtls_md_info_t* | ||||||
|  | Function,-,mbedtls_md_hmac,int,"const mbedtls_md_info_t*, const unsigned char*, size_t, const unsigned char*, size_t, unsigned char*" | ||||||
|  | Function,-,mbedtls_md_hmac_finish,int,"mbedtls_md_context_t*, unsigned char*" | ||||||
|  | Function,-,mbedtls_md_hmac_reset,int,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_hmac_starts,int,"mbedtls_md_context_t*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_md_hmac_update,int,"mbedtls_md_context_t*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_md_info_from_ctx,const mbedtls_md_info_t*,const mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_info_from_string,const mbedtls_md_info_t*,const char* | ||||||
|  | Function,-,mbedtls_md_info_from_type,const mbedtls_md_info_t*,mbedtls_md_type_t | ||||||
|  | Function,-,mbedtls_md_init,void,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_list,const int*, | ||||||
|  | Function,-,mbedtls_md_setup,int,"mbedtls_md_context_t*, const mbedtls_md_info_t*, int" | ||||||
|  | Function,-,mbedtls_md_starts,int,mbedtls_md_context_t* | ||||||
|  | Function,-,mbedtls_md_update,int,"mbedtls_md_context_t*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_add_abs,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_add_int,int,"mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_add_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_bitlen,size_t,const mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_cmp_abs,int,"const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_cmp_int,int,"const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_cmp_mpi,int,"const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_copy,int,"mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_div_int,int,"mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_div_mpi,int,"mbedtls_mpi*, mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_exp_mod,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_fill_random,int,"mbedtls_mpi*, size_t, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_free,void,mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_gcd,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_gen_prime,int,"mbedtls_mpi*, size_t, int, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_get_bit,int,"const mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_grow,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_init,void,mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_inv_mod,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_is_prime_ext,int,"const mbedtls_mpi*, int, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_lsb,size_t,const mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_lset,int,"mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_lt_mpi_ct,int,"const mbedtls_mpi*, const mbedtls_mpi*, unsigned*" | ||||||
|  | Function,-,mbedtls_mpi_mod_int,int,"mbedtls_mpi_uint*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_mod_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_mul_int,int,"mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_uint" | ||||||
|  | Function,-,mbedtls_mpi_mul_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_random,int,"mbedtls_mpi*, mbedtls_mpi_sint, const mbedtls_mpi*, int (*)(void*, unsigned char*, size_t), void*" | ||||||
|  | Function,-,mbedtls_mpi_read_binary,int,"mbedtls_mpi*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_read_binary_le,int,"mbedtls_mpi*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_read_string,int,"mbedtls_mpi*, int, const char*" | ||||||
|  | Function,-,mbedtls_mpi_safe_cond_assign,int,"mbedtls_mpi*, const mbedtls_mpi*, unsigned char" | ||||||
|  | Function,-,mbedtls_mpi_safe_cond_swap,int,"mbedtls_mpi*, mbedtls_mpi*, unsigned char" | ||||||
|  | Function,-,mbedtls_mpi_set_bit,int,"mbedtls_mpi*, size_t, unsigned char" | ||||||
|  | Function,-,mbedtls_mpi_shift_l,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_shift_r,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_shrink,int,"mbedtls_mpi*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_size,size_t,const mbedtls_mpi* | ||||||
|  | Function,-,mbedtls_mpi_sub_abs,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_sub_int,int,"mbedtls_mpi*, const mbedtls_mpi*, mbedtls_mpi_sint" | ||||||
|  | Function,-,mbedtls_mpi_sub_mpi,int,"mbedtls_mpi*, const mbedtls_mpi*, const mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_swap,void,"mbedtls_mpi*, mbedtls_mpi*" | ||||||
|  | Function,-,mbedtls_mpi_write_binary,int,"const mbedtls_mpi*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_write_binary_le,int,"const mbedtls_mpi*, unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_mpi_write_string,int,"const mbedtls_mpi*, int, char*, size_t, size_t*" | ||||||
| Function,-,mbedtls_platform_zeroize,void,"void*, size_t" | Function,-,mbedtls_platform_zeroize,void,"void*, size_t" | ||||||
| Function,+,mbedtls_sha1,int,"const unsigned char*, size_t, unsigned char[20]" | Function,-,mbedtls_sha1,int,"const unsigned char*, size_t, unsigned char[20]" | ||||||
| Function,-,mbedtls_sha1_clone,void,"mbedtls_sha1_context*, const mbedtls_sha1_context*" | Function,-,mbedtls_sha1_clone,void,"mbedtls_sha1_context*, const mbedtls_sha1_context*" | ||||||
| Function,-,mbedtls_sha1_finish,int,"mbedtls_sha1_context*, unsigned char[20]" | Function,-,mbedtls_sha1_finish,int,"mbedtls_sha1_context*, unsigned char[20]" | ||||||
| Function,-,mbedtls_sha1_free,void,mbedtls_sha1_context* | Function,-,mbedtls_sha1_free,void,mbedtls_sha1_context* | ||||||
| Function,-,mbedtls_sha1_init,void,mbedtls_sha1_context* | Function,-,mbedtls_sha1_init,void,mbedtls_sha1_context* | ||||||
| Function,-,mbedtls_sha1_self_test,int,int |  | ||||||
| Function,-,mbedtls_sha1_starts,int,mbedtls_sha1_context* | Function,-,mbedtls_sha1_starts,int,mbedtls_sha1_context* | ||||||
| Function,-,mbedtls_sha1_update,int,"mbedtls_sha1_context*, const unsigned char*, size_t" | Function,-,mbedtls_sha1_update,int,"mbedtls_sha1_context*, const unsigned char*, size_t" | ||||||
|  | Function,-,mbedtls_sha256,int,"const unsigned char*, size_t, unsigned char*, int" | ||||||
|  | Function,-,mbedtls_sha256_clone,void,"mbedtls_sha256_context*, const mbedtls_sha256_context*" | ||||||
|  | Function,-,mbedtls_sha256_finish,int,"mbedtls_sha256_context*, unsigned char*" | ||||||
|  | Function,-,mbedtls_sha256_free,void,mbedtls_sha256_context* | ||||||
|  | Function,-,mbedtls_sha256_init,void,mbedtls_sha256_context* | ||||||
|  | Function,-,mbedtls_sha256_starts,int,"mbedtls_sha256_context*, int" | ||||||
|  | Function,-,mbedtls_sha256_update,int,"mbedtls_sha256_context*, const unsigned char*, size_t" | ||||||
| Function,-,mblen,int,"const char*, size_t" | Function,-,mblen,int,"const char*, size_t" | ||||||
| Function,-,mbstowcs,size_t,"wchar_t*, const char*, size_t" | Function,-,mbstowcs,size_t,"wchar_t*, const char*, size_t" | ||||||
| Function,-,mbtowc,int,"wchar_t*, const char*, size_t" | Function,-,mbtowc,int,"wchar_t*, const char*, size_t" | ||||||
| Function,+,md5,void,"const unsigned char*, size_t, unsigned char[16]" |  | ||||||
| Function,+,md5_finish,void,"md5_context*, unsigned char[16]" |  | ||||||
| Function,+,md5_process,void,"md5_context*, const unsigned char[64]" |  | ||||||
| Function,+,md5_starts,void,md5_context* |  | ||||||
| Function,+,md5_update,void,"md5_context*, const unsigned char*, size_t" |  | ||||||
| Function,-,memccpy,void*,"void*, const void*, int, size_t" | Function,-,memccpy,void*,"void*, const void*, int, size_t" | ||||||
| Function,+,memchr,void*,"const void*, int, size_t" | Function,+,memchr,void*,"const void*, int, size_t" | ||||||
| Function,+,memcmp,int,"const void*, const void*, size_t" | Function,+,memcmp,int,"const void*, const void*, size_t" | ||||||
| @ -2255,7 +2385,6 @@ Function,-,mkostemps,int,"char*, int, int" | |||||||
| Function,-,mkstemp,int,char* | Function,-,mkstemp,int,char* | ||||||
| Function,-,mkstemps,int,"char*, int" | Function,-,mkstemps,int,"char*, int" | ||||||
| Function,-,mktemp,char*,char* | Function,-,mktemp,char*,char* | ||||||
| Function,-,mktime,time_t,tm* |  | ||||||
| Function,-,modf,double,"double, double*" | Function,-,modf,double,"double, double*" | ||||||
| Function,-,modff,float,"float, float*" | Function,-,modff,float,"float, float*" | ||||||
| Function,-,modfl,long double,"long double, long double*" | Function,-,modfl,long double,"long double, long double*" | ||||||
| @ -2593,11 +2722,6 @@ Function,-,setkey,void,const char* | |||||||
| Function,-,setlinebuf,int,FILE* | Function,-,setlinebuf,int,FILE* | ||||||
| Function,-,setstate,char*,char* | Function,-,setstate,char*,char* | ||||||
| Function,-,setvbuf,int,"FILE*, char*, int, size_t" | Function,-,setvbuf,int,"FILE*, char*, int, size_t" | ||||||
| Function,+,sha256,void,"const unsigned char*, unsigned int, unsigned char[32]" |  | ||||||
| Function,+,sha256_finish,void,"sha256_context*, unsigned char[32]" |  | ||||||
| Function,+,sha256_process,void,sha256_context* |  | ||||||
| Function,+,sha256_start,void,sha256_context* |  | ||||||
| Function,+,sha256_update,void,"sha256_context*, const unsigned char*, unsigned int" |  | ||||||
| Function,+,signal_reader_alloc,SignalReader*,"const GpioPin*, uint32_t" | Function,+,signal_reader_alloc,SignalReader*,"const GpioPin*, uint32_t" | ||||||
| Function,+,signal_reader_free,void,SignalReader* | Function,+,signal_reader_free,void,SignalReader* | ||||||
| Function,+,signal_reader_set_polarity,void,"SignalReader*, SignalReaderPolarity" | Function,+,signal_reader_set_polarity,void,"SignalReader*, SignalReaderPolarity" | ||||||
| @ -2800,8 +2924,6 @@ Function,+,stream_write_vaformat,size_t,"Stream*, const char*, va_list" | |||||||
| Function,-,strerror,char*,int | Function,-,strerror,char*,int | ||||||
| Function,-,strerror_l,char*,"int, locale_t" | Function,-,strerror_l,char*,"int, locale_t" | ||||||
| Function,-,strerror_r,char*,"int, char*, size_t" | Function,-,strerror_r,char*,"int, char*, size_t" | ||||||
| Function,-,strftime,size_t,"char*, size_t, const char*, const tm*" |  | ||||||
| Function,-,strftime_l,size_t,"char*, size_t, const char*, const tm*, locale_t" |  | ||||||
| Function,+,string_stream_alloc,Stream*, | Function,+,string_stream_alloc,Stream*, | ||||||
| Function,-,strlcat,size_t,"char*, const char*, size_t" | Function,-,strlcat,size_t,"char*, const char*, size_t" | ||||||
| Function,+,strlcpy,size_t,"char*, const char*, size_t" | Function,+,strlcpy,size_t,"char*, const char*, size_t" | ||||||
| @ -2816,8 +2938,6 @@ Function,-,strndup,char*,"const char*, size_t" | |||||||
| Function,-,strnlen,size_t,"const char*, size_t" | Function,-,strnlen,size_t,"const char*, size_t" | ||||||
| Function,-,strnstr,char*,"const char*, const char*, size_t" | Function,-,strnstr,char*,"const char*, const char*, size_t" | ||||||
| Function,-,strpbrk,char*,"const char*, const char*" | Function,-,strpbrk,char*,"const char*, const char*" | ||||||
| Function,-,strptime,char*,"const char*, const char*, tm*" |  | ||||||
| Function,-,strptime_l,char*,"const char*, const char*, tm*, locale_t" |  | ||||||
| Function,+,strrchr,char*,"const char*, int" | Function,+,strrchr,char*,"const char*, int" | ||||||
| Function,-,strsep,char*,"char**, const char*" | Function,-,strsep,char*,"char**, const char*" | ||||||
| Function,-,strsignal,char*,int | Function,-,strsignal,char*,int | ||||||
| @ -3047,7 +3167,6 @@ Function,+,text_input_set_validator,void,"TextInput*, TextInputValidatorCallback | |||||||
| Function,-,tgamma,double,double | Function,-,tgamma,double,double | ||||||
| Function,-,tgammaf,float,float | Function,-,tgammaf,float,float | ||||||
| Function,-,tgammal,long double,long double | Function,-,tgammal,long double,long double | ||||||
| Function,-,time,time_t,time_t* |  | ||||||
| Function,-,timingsafe_bcmp,int,"const void*, const void*, size_t" | Function,-,timingsafe_bcmp,int,"const void*, const void*, size_t" | ||||||
| Function,-,timingsafe_memcmp,int,"const void*, const void*, size_t" | Function,-,timingsafe_memcmp,int,"const void*, const void*, size_t" | ||||||
| Function,-,tmpfile,FILE*, | Function,-,tmpfile,FILE*, | ||||||
| @ -3061,25 +3180,6 @@ Function,-,toupper_l,int,"int, locale_t" | |||||||
| Function,-,trunc,double,double | Function,-,trunc,double,double | ||||||
| Function,-,truncf,float,float | Function,-,truncf,float,float | ||||||
| Function,-,truncl,long double,long double | Function,-,truncl,long double,long double | ||||||
| Function,-,tzset,void, |  | ||||||
| Function,-,uECC_compress,void,"const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,+,uECC_compute_public_key,int,"const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_curve_private_key_size,int,uECC_Curve |  | ||||||
| Function,-,uECC_curve_public_key_size,int,uECC_Curve |  | ||||||
| Function,-,uECC_decompress,void,"const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_get_rng,uECC_RNG_Function, |  | ||||||
| Function,-,uECC_make_key,int,"uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_secp160r1,uECC_Curve, |  | ||||||
| Function,-,uECC_secp192r1,uECC_Curve, |  | ||||||
| Function,-,uECC_secp224r1,uECC_Curve, |  | ||||||
| Function,-,uECC_secp256k1,uECC_Curve, |  | ||||||
| Function,+,uECC_secp256r1,uECC_Curve, |  | ||||||
| Function,+,uECC_set_rng,void,uECC_RNG_Function |  | ||||||
| Function,-,uECC_shared_secret,int,"const uint8_t*, const uint8_t*, uint8_t*, uECC_Curve" |  | ||||||
| Function,+,uECC_sign,int,"const uint8_t*, const uint8_t*, unsigned, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_sign_deterministic,int,"const uint8_t*, const uint8_t*, unsigned, const uECC_HashContext*, uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_valid_public_key,int,"const uint8_t*, uECC_Curve" |  | ||||||
| Function,-,uECC_verify,int,"const uint8_t*, const uint8_t*, unsigned, const uint8_t*, uECC_Curve" |  | ||||||
| Function,+,uint8_to_hex_chars,void,"const uint8_t*, uint8_t*, int" | Function,+,uint8_to_hex_chars,void,"const uint8_t*, uint8_t*, int" | ||||||
| Function,-,ungetc,int,"int, FILE*" | Function,-,ungetc,int,"int, FILE*" | ||||||
| Function,-,unsetenv,int,const char* | Function,-,unsetenv,int,const char* | ||||||
| @ -3212,13 +3312,10 @@ Variable,-,MSIRangeTable,const uint32_t[16], | |||||||
| Variable,-,SmpsPrescalerTable,const uint32_t[4][6], | Variable,-,SmpsPrescalerTable,const uint32_t[4][6], | ||||||
| Variable,+,SystemCoreClock,uint32_t, | Variable,+,SystemCoreClock,uint32_t, | ||||||
| Variable,+,_ctype_,const char[], | Variable,+,_ctype_,const char[], | ||||||
| Variable,-,_daylight,int, |  | ||||||
| Variable,+,_global_impure_ptr,_reent*, | Variable,+,_global_impure_ptr,_reent*, | ||||||
| Variable,+,_impure_ptr,_reent*, | Variable,+,_impure_ptr,_reent*, | ||||||
| Variable,-,_sys_errlist,const char*[], | Variable,-,_sys_errlist,const char*[], | ||||||
| Variable,-,_sys_nerr,int, | Variable,-,_sys_nerr,int, | ||||||
| Variable,-,_timezone,long, |  | ||||||
| Variable,-,_tzname,char*[2], |  | ||||||
| Variable,+,cli_vcp,CliSession, | Variable,+,cli_vcp,CliSession, | ||||||
| Variable,+,firmware_api_interface,const ElfApiInterface*, | Variable,+,firmware_api_interface,const ElfApiInterface*, | ||||||
| Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus, | Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus, | ||||||
|  | |||||||
| 
 | 
| @ -39,12 +39,12 @@ struct CcidIntfDescriptor { | |||||||
|     struct usb_ccid_descriptor ccid_desc; |     struct usb_ccid_descriptor ccid_desc; | ||||||
|     struct usb_endpoint_descriptor ccid_bulk_in; |     struct usb_endpoint_descriptor ccid_bulk_in; | ||||||
|     struct usb_endpoint_descriptor ccid_bulk_out; |     struct usb_endpoint_descriptor ccid_bulk_out; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| struct CcidConfigDescriptor { | struct CcidConfigDescriptor { | ||||||
|     struct usb_config_descriptor config; |     struct usb_config_descriptor config; | ||||||
|     struct CcidIntfDescriptor intf_0; |     struct CcidIntfDescriptor intf_0; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| enum CCID_Features_Auto_t { | enum CCID_Features_Auto_t { | ||||||
|     CCID_Features_Auto_None = 0x0, |     CCID_Features_Auto_None = 0x0, | ||||||
| @ -255,7 +255,7 @@ typedef struct ccid_bulk_message_header { | |||||||
|     uint32_t dwLength; |     uint32_t dwLength; | ||||||
|     uint8_t bSlot; |     uint8_t bSlot; | ||||||
|     uint8_t bSeq; |     uint8_t bSeq; | ||||||
| } __attribute__((packed)) ccid_bulk_message_header_t; | } FURI_PACKED ccid_bulk_message_header_t; | ||||||
| 
 | 
 | ||||||
| uint8_t SendBuffer[sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE]; | uint8_t SendBuffer[sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -35,13 +35,13 @@ struct CdcIadDescriptor { | |||||||
| struct CdcConfigDescriptorSingle { | struct CdcConfigDescriptorSingle { | ||||||
|     struct usb_config_descriptor config; |     struct usb_config_descriptor config; | ||||||
|     struct CdcIadDescriptor iad_0; |     struct CdcIadDescriptor iad_0; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| struct CdcConfigDescriptorDual { | struct CdcConfigDescriptorDual { | ||||||
|     struct usb_config_descriptor config; |     struct usb_config_descriptor config; | ||||||
|     struct CdcIadDescriptor iad_0; |     struct CdcIadDescriptor iad_0; | ||||||
|     struct CdcIadDescriptor iad_1; |     struct CdcIadDescriptor iad_1; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| static const struct usb_string_descriptor dev_manuf_desc = USB_STRING_DESC("Flipper Devices Inc."); | static const struct usb_string_descriptor dev_manuf_desc = USB_STRING_DESC("Flipper Devices Inc."); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ struct HidIntfDescriptor { | |||||||
| struct HidConfigDescriptor { | struct HidConfigDescriptor { | ||||||
|     struct usb_config_descriptor config; |     struct usb_config_descriptor config; | ||||||
|     struct HidIntfDescriptor intf_0; |     struct HidIntfDescriptor intf_0; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| enum HidReportId { | enum HidReportId { | ||||||
|     ReportIdKeyboard = 1, |     ReportIdKeyboard = 1, | ||||||
| @ -199,7 +199,7 @@ struct HidReportMouse { | |||||||
|     int8_t x; |     int8_t x; | ||||||
|     int8_t y; |     int8_t y; | ||||||
|     int8_t wheel; |     int8_t wheel; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| struct HidReportKB { | struct HidReportKB { | ||||||
|     uint8_t report_id; |     uint8_t report_id; | ||||||
| @ -208,23 +208,23 @@ struct HidReportKB { | |||||||
|         uint8_t reserved; |         uint8_t reserved; | ||||||
|         uint8_t btn[HID_KB_MAX_KEYS]; |         uint8_t btn[HID_KB_MAX_KEYS]; | ||||||
|     } boot; |     } boot; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| struct HidReportConsumer { | struct HidReportConsumer { | ||||||
|     uint8_t report_id; |     uint8_t report_id; | ||||||
|     uint16_t btn[HID_CONSUMER_MAX_KEYS]; |     uint16_t btn[HID_CONSUMER_MAX_KEYS]; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| struct HidReportLED { | struct HidReportLED { | ||||||
|     uint8_t report_id; |     uint8_t report_id; | ||||||
|     uint8_t led_state; |     uint8_t led_state; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| static struct HidReport { | static struct HidReport { | ||||||
|     struct HidReportKB keyboard; |     struct HidReportKB keyboard; | ||||||
|     struct HidReportMouse mouse; |     struct HidReportMouse mouse; | ||||||
|     struct HidReportConsumer consumer; |     struct HidReportConsumer consumer; | ||||||
| } __attribute__((packed)) hid_report; | } FURI_PACKED hid_report; | ||||||
| 
 | 
 | ||||||
| static void hid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx); | static void hid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx); | ||||||
| static void hid_deinit(usbd_device* dev); | static void hid_deinit(usbd_device* dev); | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ struct HidIadDescriptor { | |||||||
| struct HidConfigDescriptor { | struct HidConfigDescriptor { | ||||||
|     struct usb_config_descriptor config; |     struct usb_config_descriptor config; | ||||||
|     struct HidIadDescriptor iad_0; |     struct HidIadDescriptor iad_0; | ||||||
| } __attribute__((packed)); | } FURI_PACKED; | ||||||
| 
 | 
 | ||||||
| /* HID report: FIDO U2F */ | /* HID report: FIDO U2F */ | ||||||
| static const uint8_t hid_u2f_report_desc[] = { | static const uint8_t hid_u2f_report_desc[] = { | ||||||
|  | |||||||
| @ -25,7 +25,6 @@ | |||||||
|         "fatfs", |         "fatfs", | ||||||
|         "littlefs", |         "littlefs", | ||||||
|         "subghz", |         "subghz", | ||||||
|         "flipperformat", |  | ||||||
|         "toolbox", |         "toolbox", | ||||||
|         "nfc", |         "nfc", | ||||||
|         "digital_signal", |         "digital_signal", | ||||||
| @ -39,12 +38,15 @@ | |||||||
|         "one_wire", |         "one_wire", | ||||||
|         "ibutton", |         "ibutton", | ||||||
|         "music_worker", |         "music_worker", | ||||||
|         "misc", |  | ||||||
|         "mbedtls", |         "mbedtls", | ||||||
|         "lfrfid", |         "lfrfid", | ||||||
|         "flipper_application", |         "flipper_application", | ||||||
|         "flipperformat", |  | ||||||
|         "toolbox", |         "toolbox", | ||||||
|  |         "u8g2", | ||||||
|  |         "nanopb", | ||||||
|  |         "update_util", | ||||||
|  |         "heatshrink", | ||||||
|  |         "flipperformat", | ||||||
|         "flipper7" |         "flipper7" | ||||||
|     ] |     ] | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 hedger
						hedger