+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup apr_lib General Purpose Library Routines
+ * @ingroup APR
+ * This is collection of oddballs that didn't fit anywhere else,
+ * and might move to more appropriate headers with the release
+ * of APR 1.0.
+ * @{
+ */
+
+/** A constant representing a 'large' string. */
+#define HUGE_STRING_LEN 8192
+
+/*
+ * Define the structures used by the APR general-purpose library.
+ */
+
+/** @see apr_vformatter_buff_t */
+typedef struct apr_vformatter_buff_t apr_vformatter_buff_t;
+
+/**
+ * Structure used by the variable-formatter routines.
+ */
+struct apr_vformatter_buff_t {
+ /** The current position */
+ char *curpos;
+ /** The end position of the format string */
+ char *endpos;
+};
+
+/**
+ * return the final element of the pathname
+ * @param pathname The path to get the final element of
+ * @return the final element of the path
+ * @remark
+ *
+ * For example:
+ * "/foo/bar/gum" -> "gum"
+ * "/foo/bar/gum/" -> ""
+ * "gum" -> "gum"
+ * "bs\\path\\stuff" -> "stuff"
+ *
+ */
+//APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname);
+
+/**
+ * apr_killpg
+ * Small utility macros to make things easier to read. Not usually a
+ * goal, to be sure..
+ */
+
+#ifdef WIN32
+#define apr_killpg(x, y)
+#else /* WIN32 */
+#ifdef NO_KILLPG
+#define apr_killpg(x, y) (kill (-(x), (y)))
+#else /* NO_KILLPG */
+#define apr_killpg(x, y) (killpg ((x), (y)))
+#endif /* NO_KILLPG */
+#endif /* WIN32 */
+
+/**
+ * apr_vformatter() is a generic printf-style formatting routine
+ * with some extensions.
+ * @param flush_func The function to call when the buffer is full
+ * @param c The buffer to write to
+ * @param fmt The format string
+ * @param ap The arguments to use to fill out the format string.
+ *
+ * @remark
+ *
+ * The extensions are:
+ *
+ * - %%pA takes a struct in_addr *, and prints it as a.b.c.d
+ * - %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or
+ * \[ipv6-address\]:port
+ * - %%pT takes an apr_os_thread_t * and prints it in decimal
+ * ('0' is printed if !APR_HAS_THREADS)
+ * - %%pt takes an apr_os_thread_t * and prints it in hexadecimal
+ * ('0' is printed if !APR_HAS_THREADS)
+ * - %%pm takes an apr_status_t * and prints the appropriate error
+ * string (from apr_strerror) corresponding to that error code.
+ * - %%pp takes a void * and outputs it in hex
+ * - %%pB takes a apr_uint32_t * as bytes and outputs it's apr_strfsize
+ * - %%pF same as above, but takes a apr_off_t *
+ * - %%pS same as above, but takes a apr_size_t *
+ *
+ * %%pA, %%pI, %%pT, %%pp are available from APR 1.0.0 onwards (and in 0.9.x).
+ * %%pt is only available from APR 1.2.0 onwards.
+ * %%pm, %%pB, %%pF and %%pS are only available from APR 1.3.0 onwards.
+ *
+ * The %%p hacks are to force gcc's printf warning code to skip
+ * over a pointer argument without complaining. This does
+ * mean that the ANSI-style %%p (output a void * in hex format) won't
+ * work as expected at all, but that seems to be a fair trade-off
+ * for the increased robustness of having printf-warnings work.
+ *
+ * Additionally, apr_vformatter allows for arbitrary output methods
+ * using the apr_vformatter_buff and flush_func.
+ *
+ * The apr_vformatter_buff has two elements curpos and endpos.
+ * curpos is where apr_vformatter will write the next byte of output.
+ * It proceeds writing output to curpos, and updating curpos, until
+ * either the end of output is reached, or curpos == endpos (i.e. the
+ * buffer is full).
+ *
+ * If the end of output is reached, apr_vformatter returns the
+ * number of bytes written.
+ *
+ * When the buffer is full, the flush_func is called. The flush_func
+ * can return -1 to indicate that no further output should be attempted,
+ * and apr_vformatter will return immediately with -1. Otherwise
+ * the flush_func should flush the buffer in whatever manner is
+ * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0.
+ *
+ * Note that flush_func is only invoked as a result of attempting to
+ * write another byte at curpos when curpos >= endpos. So for
+ * example, it's possible when the output exactly matches the buffer
+ * space available that curpos == endpos will be true when
+ * apr_vformatter returns.
+ *
+ * apr_vformatter does not call out to any other code, it is entirely
+ * self-contained. This allows the callers to do things which are
+ * otherwise "unsafe". For example, apr_psprintf uses the "scratch"
+ * space at the unallocated end of a block, and doesn't actually
+ * complete the allocation until apr_vformatter returns. apr_psprintf
+ * would be completely broken if apr_vformatter were to call anything
+ * that used this same pool. Similarly http_bprintf() uses the "scratch"
+ * space at the end of its output buffer, and doesn't actually note
+ * that the space is in use until it either has to flush the buffer
+ * or until apr_vformatter returns.
+ *
+
+APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b),
+ apr_vformatter_buff_t *c, const char *fmt,
+ va_list ap);
+*/
+
+/**
+ * Display a prompt and read in the password from stdin.
+ * @param prompt The prompt to display
+ * @param pwbuf Buffer to store the password
+ * @param bufsize The length of the password buffer.
+ * @remark If the password entered must be truncated to fit in
+ * the provided buffer, APR_ENAMETOOLONG will be returned.
+ * Note that the bufsize paramater is passed by reference for no
+ * reason; its value will never be modified by the apr_password_get()
+ * function.
+
+APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf,
+ apr_size_t *bufsize);
+*/
+
+/** @} */
+
+/**
+ * @defgroup apr_ctype ctype functions
+ * These macros allow correct support of 8-bit characters on systems which
+ * support 8-bit characters. Pretty dumb how the cast is required, but
+ * that's legacy libc for ya. These new macros do not support EOF like
+ * the standard macros do. Tough.
+ * @{
+ */
+/** @see isalnum */
+#define apr_isalnum(c) (isalnum(((unsigned char)(c))))
+/** @see isalpha */
+#define apr_isalpha(c) (isalpha(((unsigned char)(c))))
+/** @see iscntrl */
+#define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
+/** @see isdigit */
+#define apr_isdigit(c) (isdigit(((unsigned char)(c))))
+/** @see isgraph */
+#define apr_isgraph(c) (isgraph(((unsigned char)(c))))
+/** @see islower*/
+#define apr_islower(c) (islower(((unsigned char)(c))))
+/** @see isascii */
+#ifdef isascii
+#define apr_isascii(c) (isascii(((unsigned char)(c))))
+#else
+#define apr_isascii(c) (((c) & ~0x7f)==0)
+#endif
+/** @see isprint */
+#define apr_isprint(c) (isprint(((unsigned char)(c))))
+/** @see ispunct */
+#define apr_ispunct(c) (ispunct(((unsigned char)(c))))
+/** @see isspace */
+#define apr_isspace(c) (isspace(((unsigned char)(c))))
+/** @see isupper */
+#define apr_isupper(c) (isupper(((unsigned char)(c))))
+/** @see isxdigit */
+#define apr_isxdigit(c) (isxdigit(((unsigned char)(c))))
+/** @see tolower */
+#define apr_tolower(c) (tolower(((unsigned char)(c))))
+/** @see toupper */
+#define apr_toupper(c) (toupper(((unsigned char)(c))))
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! APR_LIB_H */
diff --git a/code/application/source/sf_app/code/include/apr_pools.h b/code/application/source/sf_app/code/include/apr_pools.h
new file mode 100755
index 000000000..2bb0822f2
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apr_pools.h
@@ -0,0 +1,817 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+#ifndef APR_POOLS_H
+#define APR_POOLS_H
+
+/**
+ * @file apr_pools.h
+ * @brief APR memory allocation
+ *
+ * Resource allocation routines...
+ *
+ * designed so that we don't have to keep track of EVERYTHING so that
+ * it can be explicitly freed later (a fundamentally unsound strategy ---
+ * particularly in the presence of die()).
+ *
+ * Instead, we maintain pools, and allocate items (both memory and I/O
+ * handlers) from the pools --- currently there are two, one for
+ * per-transaction info, and one for config info. When a transaction is
+ * over, we can delete everything in the per-transaction apr_pool_t without
+ * fear, and without thinking too hard about it either.
+ *
+ * Note that most operations on pools are not thread-safe: a single pool
+ * should only be accessed by a single thread at any given time. The one
+ * exception to this rule is creating a subpool of a given pool: one or more
+ * threads can safely create subpools at the same time that another thread
+ * accesses the parent pool.
+ */
+
+#include "apr.h"
+#include "apr_errno.h"
+#include "apr_general.h" /* for APR_STRINGIFY */
+#define APR_WANT_MEMFUNC /**< for no good reason? */
+#include "apr_want.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup apr_pools Memory Pool Functions
+ * @ingroup APR
+ * @{
+ */
+
+/** The fundamental pool type */
+typedef struct apr_pool_t apr_pool_t;
+
+
+/**
+ * Declaration helper macro to construct apr_foo_pool_get()s.
+ *
+ * This standardized macro is used by opaque (APR) data types to return
+ * the apr_pool_t that is associated with the data type.
+ *
+ * APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the
+ * accessor function. A typical usage and result would be:
+ *
+ * APR_POOL_DECLARE_ACCESSOR(file);
+ * becomes:
+ * APR_DECLARE(apr_pool_t *) apr_file_pool_get(const apr_file_t *thefile);
+ *
+ * @remark Doxygen unwraps this macro (via doxygen.conf) to provide
+ * actual help for each specific occurrence of apr_foo_pool_get.
+ * @remark the linkage is specified for APR. It would be possible to expand
+ * the macros to support other linkages.
+ */
+#define APR_POOL_DECLARE_ACCESSOR(type) \
+ APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
+ (const apr_##type##_t *the##type)
+
+/**
+ * Implementation helper macro to provide apr_foo_pool_get()s.
+ *
+ * In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to
+ * actually define the function. It assumes the field is named "pool".
+ */
+#define APR_POOL_IMPLEMENT_ACCESSOR(type) \
+ APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
+ (const apr_##type##_t *the##type) \
+ { return the##type->pool; }
+
+
+/**
+ * Pool debug levels
+ *
+ *
+ * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * ---------------------------------
+ * | | | | | | | | x | General debug code enabled (useful in
+ * combination with --with-efence).
+ *
+ * | | | | | | | x | | Verbose output on stderr (report
+ * CREATE, CLEAR, DESTROY).
+ *
+ * | | | | x | | | | | Verbose output on stderr (report
+ * PALLOC, PCALLOC).
+ *
+ * | | | | | | x | | | Lifetime checking. On each use of a
+ * pool, check its lifetime. If the pool
+ * is out of scope, abort().
+ * In combination with the verbose flag
+ * above, it will output LIFE in such an
+ * event prior to aborting.
+ *
+ * | | | | | x | | | | Pool owner checking. On each use of a
+ * pool, check if the current thread is the
+ * pool's owner. If not, abort(). In
+ * combination with the verbose flag above,
+ * it will output OWNER in such an event
+ * prior to aborting. Use the debug
+ * function apr_pool_owner_set() to switch
+ * a pool's ownership.
+ *
+ * When no debug level was specified, assume general debug mode.
+ * If level 0 was specified, debugging is switched off.
+ *
+ */
+#if defined(APR_POOL_DEBUG)
+/* If APR_POOL_DEBUG is blank, we get 1; if it is a number, we get -1. */
+#if (APR_POOL_DEBUG - APR_POOL_DEBUG -1 == 1)
+#undef APR_POOL_DEBUG
+#define APR_POOL_DEBUG 1
+#endif
+#else
+#define APR_POOL_DEBUG 0
+#endif
+
+/** the place in the code where the particular function was called */
+#define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
+
+
+#if 0
+/** A function that is called when allocation fails. */
+typedef int (*apr_abortfunc_t)(int retcode);
+
+/*
+ * APR memory structure manipulators (pools, tables, and arrays).
+ */
+
+/*
+ * Initialization
+ */
+
+/**
+ * Setup all of the internal structures required to use pools
+ * @remark Programs do NOT need to call this directly. APR will call this
+ * automatically from apr_initialize.
+ * @internal
+ */
+//APR_DECLARE(apr_status_t) apr_pool_initialize(void);
+
+/**
+ * Tear down all of the internal structures required to use pools
+ * @remark Programs do NOT need to call this directly. APR will call this
+ * automatically from apr_terminate.
+ * @internal
+ */
+//APR_DECLARE(void) apr_pool_terminate(void);
+
+
+/*
+ * Pool creation/destruction
+ */
+
+//#include "apr_allocator.h"
+
+/**
+ * Create a new pool.
+ * @param newpool The pool we have just created.
+ * @param parent The parent pool. If this is NULL, the new pool is a root
+ * pool. If it is non-NULL, the new pool will inherit all
+ * of its parent pool's attributes, except the apr_pool_t will
+ * be a sub-pool.
+ * @param abort_fn A function to use if the pool cannot allocate more memory.
+ * @param allocator The allocator to use with the new pool. If NULL the
+ * allocator of the parent pool will be used.
+ * @remark This function is thread-safe, in the sense that multiple threads
+ * can safely create subpools of the same parent pool concurrently.
+ * Similarly, a subpool can be created by one thread at the same
+ * time that another thread accesses the parent pool.
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator)
+ __attribute__((nonnull(1)));
+
+/**
+ * Create a new pool.
+ * @deprecated @see apr_pool_create_unmanaged_ex.
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_core_ex(apr_pool_t **newpool,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator);
+
+/**
+ * Create a new unmanaged pool.
+ * @param newpool The pool we have just created.
+ * @param abort_fn A function to use if the pool cannot allocate more memory.
+ * @param allocator The allocator to use with the new pool. If NULL a
+ * new allocator will be created with the new pool as owner.
+ * @remark An unmanaged pool is a special pool without a parent; it will
+ * NOT be destroyed upon apr_terminate. It must be explicitly
+ * destroyed by calling apr_pool_destroy, to prevent memory leaks.
+ * Use of this function is discouraged, think twice about whether
+ * you really really need it.
+ * @warning Any child cleanups registered against the new pool, or
+ * against sub-pools thereof, will not be executed during an
+ * invocation of apr_proc_create(), so resources created in an
+ * "unmanaged" pool hierarchy will leak to child processes.
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex(apr_pool_t **newpool,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator)
+ __attribute__((nonnull(1)));
+
+/**
+ * Debug version of apr_pool_create_ex.
+ * @param newpool @see apr_pool_create.
+ * @param parent @see apr_pool_create.
+ * @param abort_fn @see apr_pool_create.
+ * @param allocator @see apr_pool_create.
+ * @param file_line Where the function is called from.
+ * This is usually APR_POOL__FILE_LINE__.
+ * @remark Only available when APR_POOL_DEBUG is defined.
+ * Call this directly if you have your apr_pool_create_ex
+ * calls in a wrapper function and wish to override
+ * the file_line argument to reflect the caller of
+ * your wrapper function. If you do not have
+ * apr_pool_create_ex in a wrapper, trust the macro
+ * and don't call apr_pool_create_ex_debug directly.
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator,
+ const char *file_line)
+ __attribute__((nonnull(1)));
+
+#if APR_POOL_DEBUG
+#define apr_pool_create_ex(newpool, parent, abort_fn, allocator) \
+ apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
+ APR_POOL__FILE_LINE__)
+#endif
+
+/**
+ * Debug version of apr_pool_create_core_ex.
+ * @deprecated @see apr_pool_create_unmanaged_ex_debug.
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_core_ex_debug(apr_pool_t **newpool,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator,
+ const char *file_line);
+
+/**
+ * Debug version of apr_pool_create_unmanaged_ex.
+ * @param newpool @see apr_pool_create_unmanaged.
+ * @param abort_fn @see apr_pool_create_unmanaged.
+ * @param allocator @see apr_pool_create_unmanaged.
+ * @param file_line Where the function is called from.
+ * This is usually APR_POOL__FILE_LINE__.
+ * @remark Only available when APR_POOL_DEBUG is defined.
+ * Call this directly if you have your apr_pool_create_unmanaged_ex
+ * calls in a wrapper function and wish to override
+ * the file_line argument to reflect the caller of
+ * your wrapper function. If you do not have
+ * apr_pool_create_core_ex in a wrapper, trust the macro
+ * and don't call apr_pool_create_core_ex_debug directly.
+ */
+APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex_debug(apr_pool_t **newpool,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator,
+ const char *file_line)
+ __attribute__((nonnull(1)));
+
+#if APR_POOL_DEBUG
+#define apr_pool_create_core_ex(newpool, abort_fn, allocator) \
+ apr_pool_create_unmanaged_ex_debug(newpool, abort_fn, allocator, \
+ APR_POOL__FILE_LINE__)
+
+#define apr_pool_create_unmanaged_ex(newpool, abort_fn, allocator) \
+ apr_pool_create_unmanaged_ex_debug(newpool, abort_fn, allocator, \
+ APR_POOL__FILE_LINE__)
+
+#endif
+
+/**
+ * Create a new pool.
+ * @param newpool The pool we have just created.
+ * @param parent The parent pool. If this is NULL, the new pool is a root
+ * pool. If it is non-NULL, the new pool will inherit all
+ * of its parent pool's attributes, except the apr_pool_t will
+ * be a sub-pool.
+ * @remark This function is thread-safe, in the sense that multiple threads
+ * can safely create subpools of the same parent pool concurrently.
+ * Similarly, a subpool can be created by one thread at the same
+ * time that another thread accesses the parent pool.
+ */
+#if defined(DOXYGEN)
+APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool,
+ apr_pool_t *parent);
+#else
+#if APR_POOL_DEBUG
+#define apr_pool_create(newpool, parent) \
+ apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
+ APR_POOL__FILE_LINE__)
+#else
+#define apr_pool_create(newpool, parent) \
+ apr_pool_create_ex(newpool, parent, NULL, NULL)
+#endif
+#endif
+
+/**
+ * Create a new unmanaged pool.
+ * @param newpool The pool we have just created.
+ */
+#if defined(DOXYGEN)
+APR_DECLARE(apr_status_t) apr_pool_create_core(apr_pool_t **newpool);
+APR_DECLARE(apr_status_t) apr_pool_create_unmanaged(apr_pool_t **newpool);
+#else
+#if APR_POOL_DEBUG
+#define apr_pool_create_core(newpool) \
+ apr_pool_create_unmanaged_ex_debug(newpool, NULL, NULL, \
+ APR_POOL__FILE_LINE__)
+#define apr_pool_create_unmanaged(newpool) \
+ apr_pool_create_unmanaged_ex_debug(newpool, NULL, NULL, \
+ APR_POOL__FILE_LINE__)
+#else
+#define apr_pool_create_core(newpool) \
+ apr_pool_create_unmanaged_ex(newpool, NULL, NULL)
+#define apr_pool_create_unmanaged(newpool) \
+ apr_pool_create_unmanaged_ex(newpool, NULL, NULL)
+#endif
+#endif
+
+/**
+ * Find the pool's allocator
+ * @param pool The pool to get the allocator from.
+ */
+APR_DECLARE(apr_allocator_t *) apr_pool_allocator_get(apr_pool_t *pool)
+ __attribute__((nonnull(1)));
+
+/**
+ * Clear all memory in the pool and run all the cleanups. This also destroys all
+ * subpools.
+ * @param p The pool to clear
+ * @remark This does not actually free the memory, it just allows the pool
+ * to re-use this memory for the next allocation.
+ * @see apr_pool_destroy()
+ */
+APR_DECLARE(void) apr_pool_clear(apr_pool_t *p) __attribute__((nonnull(1)));
+
+/**
+ * Debug version of apr_pool_clear.
+ * @param p See: apr_pool_clear.
+ * @param file_line Where the function is called from.
+ * This is usually APR_POOL__FILE_LINE__.
+ * @remark Only available when APR_POOL_DEBUG is defined.
+ * Call this directly if you have your apr_pool_clear
+ * calls in a wrapper function and wish to override
+ * the file_line argument to reflect the caller of
+ * your wrapper function. If you do not have
+ * apr_pool_clear in a wrapper, trust the macro
+ * and don't call apr_pool_destroy_clear directly.
+ */
+APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *p,
+ const char *file_line)
+ __attribute__((nonnull(1)));
+
+#if APR_POOL_DEBUG
+#define apr_pool_clear(p) \
+ apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
+#endif
+
+/**
+ * Destroy the pool. This takes similar action as apr_pool_clear() and then
+ * frees all the memory.
+ * @param p The pool to destroy
+ * @remark This will actually free the memory
+ */
+APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p) __attribute__((nonnull(1)));
+
+/**
+ * Debug version of apr_pool_destroy.
+ * @param p See: apr_pool_destroy.
+ * @param file_line Where the function is called from.
+ * This is usually APR_POOL__FILE_LINE__.
+ * @remark Only available when APR_POOL_DEBUG is defined.
+ * Call this directly if you have your apr_pool_destroy
+ * calls in a wrapper function and wish to override
+ * the file_line argument to reflect the caller of
+ * your wrapper function. If you do not have
+ * apr_pool_destroy in a wrapper, trust the macro
+ * and don't call apr_pool_destroy_debug directly.
+ */
+APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *p,
+ const char *file_line)
+ __attribute__((nonnull(1)));
+
+#if APR_POOL_DEBUG
+#define apr_pool_destroy(p) \
+ apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
+#endif
+
+
+/*
+ * Memory allocation
+ */
+
+/**
+ * Allocate a block of memory from a pool
+ * @param p The pool to allocate from
+ * @param size The amount of memory to allocate
+ * @return The allocated memory
+ */
+APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t size)
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+ __attribute__((alloc_size(2)))
+#endif
+ __attribute__((nonnull(1)));
+
+/**
+ * Debug version of apr_palloc
+ * @param p See: apr_palloc
+ * @param size See: apr_palloc
+ * @param file_line Where the function is called from.
+ * This is usually APR_POOL__FILE_LINE__.
+ * @return See: apr_palloc
+ */
+APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *p, apr_size_t size,
+ const char *file_line)
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+ __attribute__((alloc_size(2)))
+#endif
+ __attribute__((nonnull(1)));
+
+#if APR_POOL_DEBUG
+#define apr_palloc(p, size) \
+ apr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
+#endif
+
+/**
+ * Allocate a block of memory from a pool and set all of the memory to 0
+ * @param p The pool to allocate from
+ * @param size The amount of memory to allocate
+ * @return The allocated memory
+ */
+#if defined(DOXYGEN)
+APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);
+#elif !APR_POOL_DEBUG
+#define apr_pcalloc(p, size) memset(apr_palloc(p, size), 0, size)
+#endif
+
+/**
+ * Debug version of apr_pcalloc
+ * @param p See: apr_pcalloc
+ * @param size See: apr_pcalloc
+ * @param file_line Where the function is called from.
+ * This is usually APR_POOL__FILE_LINE__.
+ * @return See: apr_pcalloc
+ */
+APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size,
+ const char *file_line)
+ __attribute__((nonnull(1)));
+
+#if APR_POOL_DEBUG
+#define apr_pcalloc(p, size) \
+ apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
+#endif
+
+
+/*
+ * Pool Properties
+ */
+
+/**
+ * Set the function to be called when an allocation failure occurs.
+ * @remark If the program wants APR to exit on a memory allocation error,
+ * then this function can be called to set the callback to use (for
+ * performing cleanup and then exiting). If this function is not called,
+ * then APR will return an error and expect the calling program to
+ * deal with the error accordingly.
+ */
+APR_DECLARE(void) apr_pool_abort_set(apr_abortfunc_t abortfunc,
+ apr_pool_t *pool)
+ __attribute__((nonnull(2)));
+
+/**
+ * Get the abort function associated with the specified pool.
+ * @param pool The pool for retrieving the abort function.
+ * @return The abort function for the given pool.
+ */
+APR_DECLARE(apr_abortfunc_t) apr_pool_abort_get(apr_pool_t *pool)
+ __attribute__((nonnull(1)));
+
+/**
+ * Get the parent pool of the specified pool.
+ * @param pool The pool for retrieving the parent pool.
+ * @return The parent of the given pool.
+ */
+APR_DECLARE(apr_pool_t *) apr_pool_parent_get(apr_pool_t *pool)
+ __attribute__((nonnull(1)));
+
+/**
+ * Determine if pool a is an ancestor of pool b.
+ * @param a The pool to search
+ * @param b The pool to search for
+ * @return True if a is an ancestor of b, NULL is considered an ancestor
+ * of all pools.
+ * @remark if compiled with APR_POOL_DEBUG, this function will also
+ * return true if A is a pool which has been guaranteed by the caller
+ * (using apr_pool_join) to have a lifetime at least as long as some
+ * ancestor of pool B.
+ */
+APR_DECLARE(int) apr_pool_is_ancestor(apr_pool_t *a, apr_pool_t *b);
+
+/**
+ * Tag a pool (give it a name)
+ * @param pool The pool to tag
+ * @param tag The tag
+ */
+APR_DECLARE(void) apr_pool_tag(apr_pool_t *pool, const char *tag)
+ __attribute__((nonnull(1)));
+
+
+/*
+ * User data management
+ */
+
+/**
+ * Set the data associated with the current pool
+ * @param data The user data associated with the pool.
+ * @param key The key to use for association
+ * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
+ * @param pool The current pool
+ * @warning The data to be attached to the pool should have a life span
+ * at least as long as the pool it is being attached to.
+ *
+ * Users of APR must take EXTREME care when choosing a key to
+ * use for their data. It is possible to accidentally overwrite
+ * data by choosing a key that another part of the program is using.
+ * Therefore it is advised that steps are taken to ensure that unique
+ * keys are used for all of the userdata objects in a particular pool
+ * (the same key in two different pools or a pool and one of its
+ * subpools is okay) at all times. Careful namespace prefixing of
+ * key names is a typical way to help ensure this uniqueness.
+ *
+ */
+APR_DECLARE(apr_status_t) apr_pool_userdata_set(const void *data,
+ const char *key,
+ apr_status_t (*cleanup)(void *),
+ apr_pool_t *pool)
+ __attribute__((nonnull(2,4)));
+
+/**
+ * Set the data associated with the current pool
+ * @param data The user data associated with the pool.
+ * @param key The key to use for association
+ * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
+ * @param pool The current pool
+ * @note same as apr_pool_userdata_set(), except that this version doesn't
+ * make a copy of the key (this function is useful, for example, when
+ * the key is a string literal)
+ * @warning This should NOT be used if the key could change addresses by
+ * any means between the apr_pool_userdata_setn() call and a
+ * subsequent apr_pool_userdata_get() on that key, such as if a
+ * static string is used as a userdata key in a DSO and the DSO could
+ * be unloaded and reloaded between the _setn() and the _get(). You
+ * MUST use apr_pool_userdata_set() in such cases.
+ * @warning More generally, the key and the data to be attached to the
+ * pool should have a life span at least as long as the pool itself.
+ *
+ */
+APR_DECLARE(apr_status_t) apr_pool_userdata_setn(
+ const void *data, const char *key,
+ apr_status_t (*cleanup)(void *),
+ apr_pool_t *pool)
+ __attribute__((nonnull(2,4)));
+
+/**
+ * Return the data associated with the current pool.
+ * @param data The user data associated with the pool.
+ * @param key The key for the data to retrieve
+ * @param pool The current pool.
+ */
+APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char *key,
+ apr_pool_t *pool)
+ __attribute__((nonnull(1,2,3)));
+
+
+/**
+ * @defgroup PoolCleanup Pool Cleanup Functions
+ *
+ * Cleanups are performed in the reverse order they were registered. That is:
+ * Last In, First Out. A cleanup function can safely allocate memory from
+ * the pool that is being cleaned up. It can also safely register additional
+ * cleanups which will be run LIFO, directly after the current cleanup
+ * terminates. Cleanups have to take caution in calling functions that
+ * create subpools. Subpools, created during cleanup will NOT automatically
+ * be cleaned up. In other words, cleanups are to clean up after themselves.
+ *
+ * @{
+ */
+
+/**
+ * Register a function to be called when a pool is cleared or destroyed
+ * @param p The pool to register the cleanup with
+ * @param data The data to pass to the cleanup function.
+ * @param plain_cleanup The function to call when the pool is cleared
+ * or destroyed
+ * @param child_cleanup The function to call when a child process is about
+ * to exec - this function is called in the child, obviously!
+ */
+APR_DECLARE(void) apr_pool_cleanup_register(
+ apr_pool_t *p, const void *data,
+ apr_status_t (*plain_cleanup)(void *),
+ apr_status_t (*child_cleanup)(void *))
+ __attribute__((nonnull(3,4)));
+
+/**
+ * Register a function to be called when a pool is cleared or destroyed.
+ *
+ * Unlike apr_pool_cleanup_register which registers a cleanup
+ * that is called AFTER all subpools are destroyed, this function registers
+ * a function that will be called before any of the subpools are destroyed.
+ *
+ * @param p The pool to register the cleanup with
+ * @param data The data to pass to the cleanup function.
+ * @param plain_cleanup The function to call when the pool is cleared
+ * or destroyed
+ */
+APR_DECLARE(void) apr_pool_pre_cleanup_register(
+ apr_pool_t *p, const void *data,
+ apr_status_t (*plain_cleanup)(void *))
+ __attribute__((nonnull(3)));
+
+/**
+ * Remove a previously registered cleanup function.
+ *
+ * The cleanup most recently registered with @a p having the same values of
+ * @a data and @a cleanup will be removed.
+ *
+ * @param p The pool to remove the cleanup from
+ * @param data The data of the registered cleanup
+ * @param cleanup The function to remove from cleanup
+ * @remarks For some strange reason only the plain_cleanup is handled by this
+ * function
+ */
+APR_DECLARE(void) apr_pool_cleanup_kill(apr_pool_t *p, const void *data,
+ apr_status_t (*cleanup)(void *))
+ __attribute__((nonnull(3)));
+
+/**
+ * Replace the child cleanup function of a previously registered cleanup.
+ *
+ * The cleanup most recently registered with @a p having the same values of
+ * @a data and @a plain_cleanup will have the registered child cleanup
+ * function replaced with @a child_cleanup.
+ *
+ * @param p The pool of the registered cleanup
+ * @param data The data of the registered cleanup
+ * @param plain_cleanup The plain cleanup function of the registered cleanup
+ * @param child_cleanup The function to register as the child cleanup
+ */
+APR_DECLARE(void) apr_pool_child_cleanup_set(
+ apr_pool_t *p, const void *data,
+ apr_status_t (*plain_cleanup)(void *),
+ apr_status_t (*child_cleanup)(void *))
+ __attribute__((nonnull(3,4)));
+
+/**
+ * Run the specified cleanup function immediately and unregister it.
+ *
+ * The cleanup most recently registered with @a p having the same values of
+ * @a data and @a cleanup will be removed and @a cleanup will be called
+ * with @a data as the argument.
+ *
+ * @param p The pool to remove the cleanup from
+ * @param data The data to remove from cleanup
+ * @param cleanup The function to remove from cleanup
+ */
+APR_DECLARE(apr_status_t) apr_pool_cleanup_run(apr_pool_t *p, void *data,
+ apr_status_t (*cleanup)(void *))
+ __attribute__((nonnull(3)));
+
+/**
+ * An empty cleanup function.
+ *
+ * Passed to apr_pool_cleanup_register() when no cleanup is required.
+ *
+ * @param data The data to cleanup, will not be used by this function.
+ */
+APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
+
+/**
+ * Run all registered child cleanups, in preparation for an exec()
+ * call in a forked child -- close files, etc., but *don't* flush I/O
+ * buffers, *don't* wait for subprocesses, and *don't* free any
+ * memory.
+ */
+APR_DECLARE(void) apr_pool_cleanup_for_exec(void);
+
+/** @} */
+
+/**
+ * @defgroup PoolDebug Pool Debugging functions.
+ *
+ * pools have nested lifetimes -- sub_pools are destroyed when the
+ * parent pool is cleared. We allow certain liberties with operations
+ * on things such as tables (and on other structures in a more general
+ * sense) where we allow the caller to insert values into a table which
+ * were not allocated from the table's pool. The table's data will
+ * remain valid as long as all the pools from which its values are
+ * allocated remain valid.
+ *
+ * For example, if B is a sub pool of A, and you build a table T in
+ * pool B, then it's safe to insert data allocated in A or B into T
+ * (because B lives at most as long as A does, and T is destroyed when
+ * B is cleared/destroyed). On the other hand, if S is a table in
+ * pool A, it is safe to insert data allocated in A into S, but it
+ * is *not safe* to insert data allocated from B into S... because
+ * B can be cleared/destroyed before A is (which would leave dangling
+ * pointers in T's data structures).
+ *
+ * In general we say that it is safe to insert data into a table T
+ * if the data is allocated in any ancestor of T's pool. This is the
+ * basis on which the APR_POOL_DEBUG code works -- it tests these ancestor
+ * relationships for all data inserted into tables. APR_POOL_DEBUG also
+ * provides tools (apr_pool_find, and apr_pool_is_ancestor) for other
+ * folks to implement similar restrictions for their own data
+ * structures.
+ *
+ * However, sometimes this ancestor requirement is inconvenient --
+ * sometimes it's necessary to create a sub pool where the sub pool is
+ * guaranteed to have the same lifetime as the parent pool. This is a
+ * guarantee implemented by the *caller*, not by the pool code. That
+ * is, the caller guarantees they won't destroy the sub pool
+ * individually prior to destroying the parent pool.
+ *
+ * In this case the caller must call apr_pool_join() to indicate this
+ * guarantee to the APR_POOL_DEBUG code.
+ *
+ * These functions are only implemented when #APR_POOL_DEBUG is set.
+ *
+ * @{
+ */
+#if APR_POOL_DEBUG || defined(DOXYGEN)
+/**
+ * Guarantee that a subpool has the same lifetime as the parent.
+ * @param p The parent pool
+ * @param sub The subpool
+ */
+APR_DECLARE(void) apr_pool_join(apr_pool_t *p, apr_pool_t *sub)
+ __attribute__((nonnull(2)));
+
+/**
+ * Find a pool from something allocated in it.
+ * @param mem The thing allocated in the pool
+ * @return The pool it is allocated in
+ */
+APR_DECLARE(apr_pool_t *) apr_pool_find(const void *mem);
+
+/**
+ * Report the number of bytes currently in the pool
+ * @param p The pool to inspect
+ * @param recurse Recurse/include the subpools' sizes
+ * @return The number of bytes
+ */
+APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse)
+ __attribute__((nonnull(1)));
+
+/**
+ * Lock a pool
+ * @param pool The pool to lock
+ * @param flag The flag
+ */
+APR_DECLARE(void) apr_pool_lock(apr_pool_t *pool, int flag);
+
+/* @} */
+
+#else /* APR_POOL_DEBUG or DOXYGEN */
+
+#ifdef apr_pool_join
+#undef apr_pool_join
+#endif
+#define apr_pool_join(a,b)
+
+#ifdef apr_pool_lock
+#undef apr_pool_lock
+#endif
+#define apr_pool_lock(pool, lock)
+
+#endif /* APR_POOL_DEBUG or DOXYGEN */
+
+/** @} */
+
+
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !APR_POOLS_H */
diff --git a/code/application/source/sf_app/code/include/apr_sha1.h b/code/application/source/sf_app/code/include/apr_sha1.h
new file mode 100755
index 000000000..9bba8e048
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apr_sha1.h
@@ -0,0 +1,122 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+/* NIST Secure Hash Algorithm
+ * heavily modified by Uwe Hollerbach uh@alumni.caltech edu
+ * from Peter C. Gutmann's implementation as found in
+ * Applied Cryptography by Bruce Schneier
+ * This code is hereby placed in the public domain
+ */
+
+#ifndef APR_SHA1_H
+#define APR_SHA1_H
+
+#include "apu.h"
+#include "apr_general.h"
+#include "sf_type.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file apr_sha1.h
+ * @brief APR-UTIL SHA1 library
+ */
+
+/** size of the SHA1 DIGEST */
+#define APR_SHA1_DIGESTSIZE 20
+
+/**
+ * Define the Magic String prefix that identifies a password as being
+ * hashed using our algorithm.
+ */
+#define APR_SHA1PW_ID "{SHA}"
+
+/** length of the SHA Password */
+#define APR_SHA1PW_IDLEN 5
+
+/** @see apr_sha1_ctx_t */
+typedef struct apr_sha1_ctx_t apr_sha1_ctx_t;
+
+/**
+ * SHA1 context structure
+ */
+struct apr_sha1_ctx_t {
+ /** message digest */
+ UINT32 digest[5];
+ /** 64-bit bit counts */
+ UINT32 count_lo, count_hi;
+ /** SHA data buffer */
+ UINT32 data[16];
+ /** unprocessed amount in data */
+ int local;
+};
+
+/**
+ * Provide a means to SHA1 crypt/encode a plaintext password in a way which
+ * makes password file compatible with those commonly use in netscape web
+ * and ldap installations.
+ * @param clear The plaintext password
+ * @param len The length of the plaintext password
+ * @param out The encrypted/encoded password
+ * @note SHA1 support is useful for migration purposes, but is less
+ * secure than Apache's password format, since Apache's (MD5)
+ * password format uses a random eight character salt to generate
+ * one of many possible hashes for the same password. Netscape
+ * uses plain SHA1 without a salt, so the same password
+ * will always generate the same hash, making it easier
+ * to break since the search space is smaller.
+ */
+APU_DECLARE(void) apr_sha1_base64(const char *clear, int len, char *out);
+
+/**
+ * Initialize the SHA digest
+ * @param context The SHA context to initialize
+ */
+APU_DECLARE(void) apr_sha1_init(apr_sha1_ctx_t *context);
+
+/**
+ * Update the SHA digest
+ * @param context The SHA1 context to update
+ * @param input The buffer to add to the SHA digest
+ * @param inputLen The length of the input buffer
+ */
+APU_DECLARE(void) apr_sha1_update(apr_sha1_ctx_t *context, const char *input,
+ unsigned int inputLen);
+
+/**
+ * Update the SHA digest with binary data
+ * @param context The SHA1 context to update
+ * @param input The buffer to add to the SHA digest
+ * @param inputLen The length of the input buffer
+ */
+APU_DECLARE(void) apr_sha1_update_binary(apr_sha1_ctx_t *context,
+ const unsigned char *input,
+ unsigned int inputLen);
+
+/**
+ * Finish computing the SHA digest
+ * @param digest the output buffer in which to store the digest
+ * @param context The context to finalize
+ */
+APU_DECLARE(void) apr_sha1_final(unsigned char digest[APR_SHA1_DIGESTSIZE],
+ apr_sha1_ctx_t *context);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* APR_SHA1_H */
diff --git a/code/application/source/sf_app/code/include/apr_strings.h b/code/application/source/sf_app/code/include/apr_strings.h
new file mode 100755
index 000000000..9dd029f1c
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apr_strings.h
@@ -0,0 +1,390 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+/* Portions of this file are covered by */
+/* -*- mode: c; c-file-style: "k&r" -*-
+
+ strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
+ Copyright (C) 2000 by Martin Pool
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef APR_STRINGS_H
+#define APR_STRINGS_H
+
+/**
+ * @file apr_strings.h
+ * @brief APR Strings library
+ */
+
+#include "apr.h"
+#include "apr_errno.h"
+#include "apr_pools.h"
+#define APR_WANT_IOVEC
+#include "apr_want.h"
+
+#if APR_HAVE_STDARG_H
+#include
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup apr_strings String routines
+ * @ingroup APR
+ * @{
+ */
+
+/**
+ * Do a natural order comparison of two strings.
+ * @param a The first string to compare
+ * @param b The second string to compare
+ * @return Either <0, 0, or >0. If the first string is less than the second
+ * this returns <0, if they are equivalent it returns 0, and if the
+ * first string is greater than second string it retuns >0.
+ */
+//APR_DECLARE(int) apr_strnatcmp(char const *a, char const *b);
+
+/**
+ * Do a natural order comparison of two strings ignoring the case of the
+ * strings.
+ * @param a The first string to compare
+ * @param b The second string to compare
+ * @return Either <0, 0, or >0. If the first string is less than the second
+ * this returns <0, if they are equivalent it returns 0, and if the
+ * first string is greater than second string it retuns >0.
+ */
+//APR_DECLARE(int) apr_strnatcasecmp(char const *a, char const *b);
+
+/**
+ * duplicate a string into memory allocated out of a pool
+ * @param p The pool to allocate out of
+ * @param s The string to duplicate
+ * @return The new string or NULL if s == NULL
+ */
+//APR_DECLARE(char *) apr_pstrdup(apr_pool_t *p, const char *s);
+
+/**
+ * Create a null-terminated string by making a copy of a sequence
+ * of characters and appending a null byte
+ * @param p The pool to allocate out of
+ * @param s The block of characters to duplicate
+ * @param n The number of characters to duplicate
+ * @return The new string or NULL if s == NULL
+ * @remark This is a faster alternative to apr_pstrndup, for use
+ * when you know that the string being duplicated really
+ * has 'n' or more characters. If the string might contain
+ * fewer characters, use apr_pstrndup.
+
+APR_DECLARE(char *) apr_pstrmemdup(apr_pool_t *p, const char *s, apr_size_t n)
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+ __attribute__((alloc_size(3)))
+#endif
+ ;
+*/
+
+/**
+ * Duplicate at most n characters of a string into memory allocated
+ * out of a pool; the new string will be NUL-terminated
+ * @param p The pool to allocate out of
+ * @param s The string to duplicate
+ * @param n The maximum number of characters to duplicate
+ * @return The new string or NULL if s == NULL
+ * @remark The amount of memory allocated from the pool is the length
+ * of the returned string including the NUL terminator
+ */
+//APR_DECLARE(char *) apr_pstrndup(apr_pool_t *p, const char *s, apr_size_t n);
+
+/**
+ * Duplicate a block of memory.
+ *
+ * @param p The pool to allocate from
+ * @param m The memory to duplicate
+ * @param n The number of bytes to duplicate
+ * @return The new block of memory or NULL if m == NULL
+
+APR_DECLARE(void *) apr_pmemdup(apr_pool_t *p, const void *m, apr_size_t n)
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+ __attribute__((alloc_size(3)))
+#endif
+ ;
+*/
+
+/**
+ * Concatenate multiple strings, allocating memory out a pool
+ * @param p The pool to allocate out of
+ * @param ... The strings to concatenate. The final string must be NULL
+ * @return The new string
+
+APR_DECLARE_NONSTD(char *) apr_pstrcat(apr_pool_t *p, ...)
+#if defined(__GNUC__) && __GNUC__ >= 4
+ __attribute__((sentinel))
+#endif
+ ;
+*/
+
+/**
+ * Concatenate multiple strings specified in a writev-style vector
+ * @param p The pool from which to allocate
+ * @param vec The strings to concatenate
+ * @param nvec The number of strings to concatenate
+ * @param nbytes (output) strlen of new string (pass in NULL to omit)
+ * @return The new string
+
+APR_DECLARE(char *) apr_pstrcatv(apr_pool_t *p, const struct iovec *vec,
+ apr_size_t nvec, apr_size_t *nbytes);
+*/
+
+/**
+ * printf-style style printing routine. The data is output to a string
+ * allocated from a pool
+ * @param p The pool to allocate out of
+ * @param fmt The format of the string
+ * @param ap The arguments to use while printing the data
+ * @return The new string
+ */
+//APR_DECLARE(char *) apr_pvsprintf(apr_pool_t *p, const char *fmt, va_list ap);
+
+/**
+ * printf-style style printing routine. The data is output to a string
+ * allocated from a pool
+ * @param p The pool to allocate out of
+ * @param fmt The format of the string
+ * @param ... The arguments to use while printing the data
+ * @return The new string
+
+APR_DECLARE_NONSTD(char *) apr_psprintf(apr_pool_t *p, const char *fmt, ...)
+ __attribute__((format(printf,2,3)));
+*/
+
+/**
+ * Copy up to dst_size characters from src to dst; does not copy
+ * past a NUL terminator in src, but always terminates dst with a NUL
+ * regardless.
+ * @param dst The destination string
+ * @param src The source string
+ * @param dst_size The space available in dst; dst always receives
+ * NUL termination, so if src is longer than
+ * dst_size, the actual number of characters copied is
+ * dst_size - 1.
+ * @return Pointer to the NUL terminator of the destination string, dst
+ * @remark
+ *
+ * Note the differences between this function and strncpy():
+ * 1) strncpy() doesn't always NUL terminate; apr_cpystrn() does.
+ * 2) strncpy() pads the destination string with NULs, which is often
+ * unnecessary; apr_cpystrn() does not.
+ * 3) strncpy() returns a pointer to the beginning of the dst string;
+ * apr_cpystrn() returns a pointer to the NUL terminator of dst,
+ * to allow a check for truncation.
+ *
+
+APR_DECLARE(char *) apr_cpystrn(char *dst, const char *src,
+ apr_size_t dst_size);
+*/
+
+/**
+ * Remove all whitespace from a string
+ * @param dest The destination string. It is okay to modify the string
+ * in place. Namely dest == src
+ * @param src The string to rid the spaces from.
+ * @return A pointer to the destination string's null terminator.
+ */
+//APR_DECLARE(char *) apr_collapse_spaces(char *dest, const char *src);
+
+/**
+ * Convert the arguments to a program from one string to an array of
+ * strings terminated by a NULL pointer
+ * @param arg_str The arguments to convert
+ * @param argv_out Output location. This is a pointer to an array of strings.
+ * @param token_context Pool to use.
+
+APR_DECLARE(apr_status_t) apr_tokenize_to_argv(const char *arg_str,
+ char ***argv_out,
+ apr_pool_t *token_context);
+*/
+
+/**
+ * Split a string into separate null-terminated tokens. The tokens are
+ * delimited in the string by one or more characters from the sep
+ * argument.
+ * @param str The string to separate; this should be specified on the
+ * first call to apr_strtok() for a given string, and NULL
+ * on subsequent calls.
+ * @param sep The set of delimiters
+ * @param last State saved by apr_strtok() between calls.
+ * @return The next token from the string
+ * @note the 'last' state points to the trailing NUL char of the final
+ * token, otherwise it points to the character following the current
+ * token (all successive or empty occurances of sep are skiped on the
+ * subsequent call to apr_strtok). Therefore it is possible to avoid
+ * a strlen() determination, with the following logic;
+ * toklen = last - retval; if (*last) --toklen;
+ */
+//APR_DECLARE(char *) apr_strtok(char *str, const char *sep, char **last);
+
+/**
+ * @defgroup APR_Strings_Snprintf snprintf implementations
+ * @warning
+ * These are snprintf implementations based on apr_vformatter().
+ *
+ * Note that various standards and implementations disagree on the return
+ * value of snprintf, and side-effects due to %n in the formatting string.
+ * apr_snprintf (and apr_vsnprintf) behaves as follows:
+ *
+ * Process the format string until the entire string is exhausted, or
+ * the buffer fills. If the buffer fills then stop processing immediately
+ * (so no further %n arguments are processed), and return the buffer
+ * length. In all cases the buffer is NUL terminated. It will return the
+ * number of characters inserted into the buffer, not including the
+ * terminating NUL. As a special case, if len is 0, apr_snprintf will
+ * return the number of characters that would have been inserted if
+ * the buffer had been infinite (in this case, *buffer can be NULL)
+ *
+ * In no event does apr_snprintf return a negative number.
+ * @{
+ */
+
+/**
+ * snprintf routine based on apr_vformatter. This means it understands the
+ * same extensions.
+ * @param buf The buffer to write to
+ * @param len The size of the buffer
+ * @param format The format string
+ * @param ... The arguments to use to fill out the format string.
+
+APR_DECLARE_NONSTD(int) apr_snprintf(char *buf, apr_size_t len,
+ const char *format, ...)
+ __attribute__((format(printf,3,4)));
+*/
+
+/**
+ * vsnprintf routine based on apr_vformatter. This means it understands the
+ * same extensions.
+ * @param buf The buffer to write to
+ * @param len The size of the buffer
+ * @param format The format string
+ * @param ap The arguments to use to fill out the format string.
+
+APR_DECLARE(int) apr_vsnprintf(char *buf, apr_size_t len, const char *format,
+ va_list ap);
+*/
+/** @} */
+
+/**
+ * create a string representation of an int, allocated from a pool
+ * @param p The pool from which to allocate
+ * @param n The number to format
+ * @return The string representation of the number
+ */
+//APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n);
+
+/**
+ * create a string representation of a long, allocated from a pool
+ * @param p The pool from which to allocate
+ * @param n The number to format
+ * @return The string representation of the number
+ */
+//APR_DECLARE(char *) apr_ltoa(apr_pool_t *p, long n);
+
+/**
+ * create a string representation of an apr_off_t, allocated from a pool
+ * @param p The pool from which to allocate
+ * @param n The number to format
+ * @return The string representation of the number
+ */
+//APR_DECLARE(char *) apr_off_t_toa(apr_pool_t *p, apr_off_t n);
+
+/**
+ * Convert a numeric string into an apr_off_t numeric value.
+ * @param offset The value of the parsed string.
+ * @param buf The string to parse. It may contain optional whitespace,
+ * followed by an optional '+' (positive, default) or '-' (negative)
+ * character, followed by an optional '0x' prefix if base is 0 or 16,
+ * followed by numeric digits appropriate for base.
+ * @param end A pointer to the end of the valid character in buf. If
+ * not NULL, it is set to the first invalid character in buf.
+ * @param base A numeric base in the range between 2 and 36 inclusive,
+ * or 0. If base is zero, buf will be treated as base ten unless its
+ * digits are prefixed with '0x', in which case it will be treated as
+ * base 16.
+ * @bug *end breaks type safety; where *buf is const, *end needs to be
+ * declared as const in APR 2.0
+
+APR_DECLARE(apr_status_t) apr_strtoff(apr_off_t *offset, const char *buf,
+ char **end, int base);
+*/
+
+/**
+ * parse a numeric string into a 64-bit numeric value
+ * @param buf The string to parse. It may contain optional whitespace,
+ * followed by an optional '+' (positive, default) or '-' (negative)
+ * character, followed by an optional '0x' prefix if base is 0 or 16,
+ * followed by numeric digits appropriate for base.
+ * @param end A pointer to the end of the valid character in buf. If
+ * not NULL, it is set to the first invalid character in buf.
+ * @param base A numeric base in the range between 2 and 36 inclusive,
+ * or 0. If base is zero, buf will be treated as base ten unless its
+ * digits are prefixed with '0x', in which case it will be treated as
+ * base 16.
+ * @return The numeric value of the string. On overflow, errno is set
+ * to ERANGE. On success, errno is set to 0.
+ */
+//APR_DECLARE(apr_int64_t) apr_strtoi64(const char *buf, char **end, int base);
+
+/**
+ * parse a base-10 numeric string into a 64-bit numeric value.
+ * Equivalent to apr_strtoi64(buf, (char**)NULL, 10).
+ * @param buf The string to parse
+ * @return The numeric value of the string. On overflow, errno is set
+ * to ERANGE. On success, errno is set to 0.
+ */
+//APR_DECLARE(apr_int64_t) apr_atoi64(const char *buf);
+
+/**
+ * Format a binary size (magnitiudes are 2^10 rather than 10^3) from an apr_off_t,
+ * as bytes, K, M, T, etc, to a four character compacted human readable string.
+ * @param size The size to format
+ * @param buf The 5 byte text buffer (counting the trailing null)
+ * @return The buf passed to apr_strfsize()
+ * @remark All negative sizes report ' - ', apr_strfsize only formats positive values.
+ */
+//APR_DECLARE(char *) apr_strfsize(apr_off_t size, char *buf);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !APR_STRINGS_H */
diff --git a/code/application/source/sf_app/code/include/apr_want.h b/code/application/source/sf_app/code/include/apr_want.h
new file mode 100755
index 000000000..f48d3549b
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apr_want.h
@@ -0,0 +1,126 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "apr.h" /* configuration data */
+/**
+ * @file apr_want.h
+ * @brief APR Standard Headers Support
+ *
+ *
+ * Features:
+ *
+ * APR_WANT_STRFUNC: strcmp, strcat, strcpy, etc
+ * APR_WANT_MEMFUNC: memcmp, memcpy, etc
+ * APR_WANT_STDIO: and related bits
+ * APR_WANT_IOVEC: struct iovec
+ * APR_WANT_BYTEFUNC: htons, htonl, ntohl, ntohs
+ *
+ * Typical usage:
+ *
+ * \#define APR_WANT_STRFUNC
+ * \#define APR_WANT_MEMFUNC
+ * \#include "apr_want.h"
+ *
+ * The appropriate headers will be included.
+ *
+ * Note: it is safe to use this in a header (it won't interfere with other
+ * headers' or source files' use of apr_want.h)
+ *
+ */
+
+/* --------------------------------------------------------------------- */
+
+#ifdef APR_WANT_STRFUNC
+
+#if APR_HAVE_STRING_H
+#include
+#endif
+#if APR_HAVE_STRINGS_H
+#include
+#endif
+
+#undef APR_WANT_STRFUNC
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#ifdef APR_WANT_MEMFUNC
+
+#if APR_HAVE_STRING_H
+#include
+#endif
+
+#undef APR_WANT_MEMFUNC
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#ifdef APR_WANT_STDIO
+
+#if APR_HAVE_STDIO_H
+#include
+#endif
+
+#undef APR_WANT_STDIO
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#ifdef APR_WANT_IOVEC
+
+#if APR_HAVE_IOVEC
+
+#if APR_HAVE_SYS_UIO_H
+#include
+#endif
+
+#else
+
+#ifndef APR_IOVEC_DEFINED
+#define APR_IOVEC_DEFINED
+#if 0
+struct iovec
+{
+ void *iov_base;
+ size_t iov_len;
+};
+#endif
+#endif /* !APR_IOVEC_DEFINED */
+
+#endif /* APR_HAVE_IOVEC */
+
+#undef APR_WANT_IOVEC
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#ifdef APR_WANT_BYTEFUNC
+
+/* Single Unix says they are in arpa/inet.h. Linux has them in
+ * netinet/in.h. FreeBSD has them in arpa/inet.h but requires that
+ * netinet/in.h be included first.
+ */
+#if APR_HAVE_NETINET_IN_H
+#include
+#endif
+#if APR_HAVE_ARPA_INET_H
+#include
+#endif
+
+#undef APR_WANT_BYTEFUNC
+#endif
+
+/* --------------------------------------------------------------------- */
diff --git a/code/application/source/sf_app/code/include/apr_xlate.h b/code/application/source/sf_app/code/include/apr_xlate.h
new file mode 100755
index 000000000..5d98903de
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apr_xlate.h
@@ -0,0 +1,164 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+#ifndef APR_XLATE_H
+#define APR_XLATE_H
+
+#include "apu.h"
+#include "apr_pools.h"
+#include "apr_errno.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @file apr_xlate.h
+ * @brief APR I18N translation library
+ */
+
+/**
+ * @defgroup APR_XLATE I18N translation library
+ * @ingroup APR
+ * @{
+ */
+/** Opaque translation buffer */
+typedef struct apr_xlate_t apr_xlate_t;
+
+/**
+ * Set up for converting text from one charset to another.
+ * @param convset The handle to be filled in by this function
+ * @param topage The name of the target charset
+ * @param frompage The name of the source charset
+ * @param pool The pool to use
+ * @remark
+ * Specify APR_DEFAULT_CHARSET for one of the charset
+ * names to indicate the charset of the source code at
+ * compile time. This is useful if there are literal
+ * strings in the source code which must be translated
+ * according to the charset of the source code.
+ * APR_DEFAULT_CHARSET is not useful if the source code
+ * of the caller was not encoded in the same charset as
+ * APR at compile time.
+ *
+ * @remark
+ * Specify APR_LOCALE_CHARSET for one of the charset
+ * names to indicate the charset of the current locale.
+ *
+ * @remark
+ * Return APR_EINVAL if unable to procure a convset, or APR_ENOTIMPL
+ * if charset transcoding is not available in this instance of
+ * apr-util at all (i.e., APR_HAS_XLATE is undefined).
+ */
+APU_DECLARE(apr_status_t) apr_xlate_open(apr_xlate_t **convset,
+ const char *topage,
+ const char *frompage,
+ apr_pool_t *pool);
+
+/**
+ * This is to indicate the charset of the sourcecode at compile time
+ * names to indicate the charset of the source code at
+ * compile time. This is useful if there are literal
+ * strings in the source code which must be translated
+ * according to the charset of the source code.
+ */
+#define APR_DEFAULT_CHARSET (const char *)0
+/**
+ * To indicate charset names of the current locale
+ */
+#define APR_LOCALE_CHARSET (const char *)1
+
+/**
+ * Find out whether or not the specified conversion is single-byte-only.
+ * @param convset The handle allocated by apr_xlate_open, specifying the
+ * parameters of conversion
+ * @param onoff Output: whether or not the conversion is single-byte-only
+ * @remark
+ * Return APR_ENOTIMPL if charset transcoding is not available
+ * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined).
+ */
+APU_DECLARE(apr_status_t) apr_xlate_sb_get(apr_xlate_t *convset, int *onoff);
+
+/**
+ * Convert a buffer of text from one codepage to another.
+ * @param convset The handle allocated by apr_xlate_open, specifying
+ * the parameters of conversion
+ * @param inbuf The address of the source buffer
+ * @param inbytes_left Input: the amount of input data to be translated
+ * Output: the amount of input data not yet translated
+ * @param outbuf The address of the destination buffer
+ * @param outbytes_left Input: the size of the output buffer
+ * Output: the amount of the output buffer not yet used
+ * @remark
+ * Returns APR_ENOTIMPL if charset transcoding is not available
+ * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined).
+ * Returns APR_INCOMPLETE if the input buffer ends in an incomplete
+ * multi-byte character.
+ *
+ * To correctly terminate the output buffer for some multi-byte
+ * character set encodings, a final call must be made to this function
+ * after the complete input string has been converted, passing
+ * the inbuf and inbytes_left parameters as NULL. (Note that this
+ * mode only works from version 1.1.0 onwards)
+ */
+APU_DECLARE(apr_status_t) apr_xlate_conv_buffer(apr_xlate_t *convset,
+ const char *inbuf,
+ UINT32 *inbytes_left,
+ char *outbuf,
+ UINT32 *outbytes_left);
+
+/* @see apr_file_io.h the comment in apr_file_io.h about this hack */
+#ifdef APR_NOT_DONE_YET
+/**
+ * The purpose of apr_xlate_conv_char is to translate one character
+ * at a time. This needs to be written carefully so that it works
+ * with double-byte character sets.
+ * @param convset The handle allocated by apr_xlate_open, specifying the
+ * parameters of conversion
+ * @param inchar The character to convert
+ * @param outchar The converted character
+ */
+APU_DECLARE(apr_status_t) apr_xlate_conv_char(apr_xlate_t *convset,
+ char inchar, char outchar);
+#endif
+
+/**
+ * Convert a single-byte character from one charset to another.
+ * @param convset The handle allocated by apr_xlate_open, specifying the
+ * parameters of conversion
+ * @param inchar The single-byte character to convert.
+ * @warning This only works when converting between single-byte character sets.
+ * -1 will be returned if the conversion can't be performed.
+ */
+//APU_DECLARE(apr_int32_t) apr_xlate_conv_byte(apr_xlate_t *convset,
+ // unsigned char inchar);
+
+/**
+ * Close a codepage translation handle.
+ * @param convset The codepage translation handle to close
+ * @remark
+ * Return APR_ENOTIMPL if charset transcoding is not available
+ * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined).
+ */
+APU_DECLARE(apr_status_t) apr_xlate_close(apr_xlate_t *convset);
+
+/** @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! APR_XLATE_H */
diff --git a/code/application/source/sf_app/code/include/apu.h b/code/application/source/sf_app/code/include/apu.h
new file mode 100755
index 000000000..450dfbff8
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apu.h
@@ -0,0 +1,146 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+/*
+ * apu.h is duplicated from apu.hw at build time -- do not edit apu.h
+ */
+/* @file apu.h
+ * @brief APR-Utility main file
+ */
+/**
+ * @defgroup APR_Util APR Utility Functions
+ * @{
+ */
+
+
+#ifndef APU_H
+#define APU_H
+
+/**
+ * APU_DECLARE_EXPORT is defined when building the APR-UTIL dynamic library,
+ * so that all public symbols are exported.
+ *
+ * APU_DECLARE_STATIC is defined when including the APR-UTIL public headers,
+ * to provide static linkage when the dynamic library may be unavailable.
+ *
+ * APU_DECLARE_STATIC and APU_DECLARE_EXPORT are left undefined when
+ * including the APR-UTIL public headers, to import and link the symbols from
+ * the dynamic APR-UTIL library and assure appropriate indirection and calling
+ * conventions at compile time.
+ */
+
+/* Make sure we have our platform identifier macro defined we ask for later.
+ */
+#if defined(_WIN32) && !defined(WIN32)
+#define WIN32 1
+#endif
+
+#if defined(DOXYGEN) || !defined(WIN32)
+/**
+ * The public APR-UTIL functions are declared with APU_DECLARE(), so they may
+ * use the most appropriate calling convention. Public APR functions with
+ * variable arguments must use APU_DECLARE_NONSTD().
+ *
+ * @fn APU_DECLARE(rettype) apr_func(args);
+ */
+#define APU_DECLARE(type) type
+/**
+ * The public APR-UTIL functions using variable arguments are declared with
+ * APU_DECLARE_NONSTD(), as they must use the C language calling convention.
+ *
+ * @fn APU_DECLARE_NONSTD(rettype) apr_func(args, ...);
+ */
+#define APU_DECLARE_NONSTD(type) type
+/**
+ * The public APR-UTIL variables are declared with APU_DECLARE_DATA.
+ * This assures the appropriate indirection is invoked at compile time.
+ *
+ * @fn APU_DECLARE_DATA type apr_variable;
+ * @note extern APU_DECLARE_DATA type apr_variable; syntax is required for
+ * declarations within headers to properly import the variable.
+ */
+#define APU_DECLARE_DATA
+#elif defined(APU_DECLARE_STATIC)
+#define APU_DECLARE(type) type __stdcall
+#define APU_DECLARE_NONSTD(type) type __cdecl
+#define APU_DECLARE_DATA
+#elif defined(APU_DECLARE_EXPORT)
+#define APU_DECLARE(type) __declspec(dllexport) type __stdcall
+#define APU_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
+#define APU_DECLARE_DATA __declspec(dllexport)
+#else
+#define APU_DECLARE(type) __declspec(dllimport) type __stdcall
+#define APU_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
+#define APU_DECLARE_DATA __declspec(dllimport)
+#endif
+
+#if !defined(WIN32) || defined(APU_MODULE_DECLARE_STATIC)
+/**
+ * Declare a dso module's exported module structure as APU_MODULE_DECLARE_DATA.
+ *
+ * Unless APU_MODULE_DECLARE_STATIC is defined at compile time, symbols
+ * declared with APU_MODULE_DECLARE_DATA are always exported.
+ * @code
+ * module APU_MODULE_DECLARE_DATA mod_tag
+ * @endcode
+ */
+#define APU_MODULE_DECLARE_DATA
+#else
+#define APU_MODULE_DECLARE_DATA __declspec(dllexport)
+#endif
+
+/*
+ * we always have SDBM (it's in our codebase)
+ */
+#define APU_HAVE_SDBM 1
+
+#ifndef APU_DSO_MODULE_BUILD
+#define APU_HAVE_GDBM 0
+#define APU_HAVE_NDBM 0
+#define APU_HAVE_DB 0
+
+#if APU_HAVE_DB
+#define APU_HAVE_DB_VERSION 0
+#endif
+#endif
+
+/*
+ * we always enable dynamic driver loads within apr_dbd
+ * Win32 always has odbc (it's always installed)
+ */
+#ifndef APU_DSO_MODULE_BUILD
+#define APU_HAVE_PGSQL 0
+#define APU_HAVE_MYSQL 0
+#define APU_HAVE_SQLITE3 0
+#define APU_HAVE_SQLITE2 0
+#define APU_HAVE_ORACLE 0
+#define APU_HAVE_FREETDS 0
+#define APU_HAVE_ODBC 1
+#endif
+
+#define APU_HAVE_CRYPTO 0
+
+#ifndef APU_DSO_MODULE_BUILD
+#define APU_HAVE_OPENSSL 0
+#define APU_HAVE_NSS 0
+#endif
+
+#define APU_HAVE_APR_ICONV 0
+#define APU_HAVE_ICONV 0
+#define APR_HAS_XLATE (APU_HAVE_APR_ICONV || APU_HAVE_ICONV)
+
+#endif /* APU_H */
+/** @} */
diff --git a/code/application/source/sf_app/code/include/apu_config.h b/code/application/source/sf_app/code/include/apu_config.h
new file mode 100755
index 000000000..b0e203932
--- /dev/null
+++ b/code/application/source/sf_app/code/include/apu_config.h
@@ -0,0 +1,52 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+/*
+ * Note: This is a Windows specific version of apu_config.hw. It is copied
+ * as apu_config.h at the start of a Windows build.
+ */
+
+#ifdef WIN32
+
+#ifndef APU_CONFIG_H
+#define APU_CONFIG_H
+
+/* Compile win32 with DSO support for .dll builds */
+#ifdef APU_DECLARE_STATIC
+#define APU_DSO_BUILD 0
+#else
+#define APU_DSO_BUILD 1
+#endif
+
+/* Presume a standard, modern (5.x) mysql sdk/
+#define HAVE_MY_GLOBAL_H 1
+
+/* my_sys.h is broken on VC/Win32, and apparently not required */
+/* #undef HAVE_MY_SYS_H 0 */
+
+/*
+ * Windows does not have GDBM, and we always use the bundled (new) Expat
+ */
+
+/* Define if you have the gdbm library (-lgdbm). */
+/* #undef HAVE_LIBGDBM */
+
+/* define if Expat 1.0 or 1.1 was found */
+/* #undef APR_HAVE_OLD_EXPAT */
+
+
+#endif /* APU_CONFIG_H */
+#endif /* WIN32 */
diff --git a/code/application/source/sf_app/code/include/bitstream.h b/code/application/source/sf_app/code/include/bitstream.h
new file mode 100755
index 000000000..6aa545604
--- /dev/null
+++ b/code/application/source/sf_app/code/include/bitstream.h
@@ -0,0 +1,48 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Binary sequence class.
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __BITSTREAM_H__
+#define __BITSTREAM_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+typedef struct {
+ int length;
+ unsigned char *data;
+} BitStream;
+
+extern BitStream *BitStream_new(void);
+extern int BitStream_append(BitStream *bstream, BitStream *arg);
+extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num);
+extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data);
+#define BitStream_size(__bstream__) (__bstream__->length)
+extern unsigned char *BitStream_toByte(BitStream *bstream);
+extern void BitStream_free(BitStream *bstream);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __BITSTREAM_H__ */
diff --git a/code/application/source/sf_app/code/include/cJSON.h b/code/application/source/sf_app/code/include/cJSON.h
new file mode 100755
index 000000000..53017090b
--- /dev/null
+++ b/code/application/source/sf_app/code/include/cJSON.h
@@ -0,0 +1,276 @@
+/*
+ Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
+
+ 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.
+*/
+
+#ifndef cJSON__h
+#define cJSON__h
+#include "sf_type.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* project version */
+#define CJSON_VERSION_MAJOR 1
+#define CJSON_VERSION_MINOR 7
+#define CJSON_VERSION_PATCH 1
+
+#include
+
+/* cJSON Types: */
+#define cJSON_Invalid (0)
+#define cJSON_False (1 << 0)
+#define cJSON_True (1 << 1)
+#define cJSON_NULL (1 << 2)
+#define cJSON_Number (1 << 3)
+#define cJSON_String (1 << 4)
+#define cJSON_Array (1 << 5)
+#define cJSON_Object (1 << 6)
+#define cJSON_Raw (1 << 7) /* raw json */
+
+#define cJSON_IsReference 256
+#define cJSON_StringIsConst 512
+
+/* The cJSON structure: */
+typedef struct cJSON
+{
+ /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
+ struct cJSON *next;
+ struct cJSON *prev;
+ /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
+ struct cJSON *child;
+
+ /* The type of the item, as above. */
+ int type;
+
+ /* The item's string, if type==cJSON_String and type == cJSON_Raw */
+ char *valuestring;
+ /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
+ int valueint;
+ /* The item's number, if type==cJSON_Number */
+ SINT32 valueSINT32;
+
+ /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
+ char *string;
+} cJSON;
+
+typedef struct cJSON_Hooks
+{
+ void *(*malloc_fn)(size_t sz);
+ void (*free_fn)(void *ptr);
+} cJSON_Hooks;
+
+typedef int cJSON_bool;
+
+#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
+#define __WINDOWS__
+#endif
+#ifdef __WINDOWS__
+
+/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options:
+
+CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
+CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
+CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
+
+For *nix builds that support visibility attribute, you can define similar behavior by
+
+setting default visibility to hidden by adding
+-fvisibility=hidden (for gcc)
+or
+-xldscope=hidden (for sun cc)
+to CFLAGS
+
+then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
+
+*/
+
+/* export symbols by default, this is necessary for copy pasting the C and header file */
+#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
+#define CJSON_EXPORT_SYMBOLS
+#endif
+
+#if defined(CJSON_HIDE_SYMBOLS)
+#define CJSON_PUBLIC(type) type __stdcall
+#elif defined(CJSON_EXPORT_SYMBOLS)
+#define CJSON_PUBLIC(type) __declspec(dllexport) type __stdcall
+#elif defined(CJSON_IMPORT_SYMBOLS)
+#define CJSON_PUBLIC(type) __declspec(dllimport) type __stdcall
+#endif
+#else /* !WIN32 */
+#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
+#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
+#else
+#define CJSON_PUBLIC(type) type
+#endif
+#endif
+
+/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
+ * This is to prevent stack overflows. */
+#ifndef CJSON_NESTING_LIMIT
+#define CJSON_NESTING_LIMIT 1000
+#endif
+
+/* returns the version of cJSON as a string */
+CJSON_PUBLIC(const char*) cJSON_Version(void);
+
+/* Supply malloc, realloc and free functions to cJSON */
+CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
+
+/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
+/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
+CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
+/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
+/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
+CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
+
+/* Render a cJSON entity to text for transfer/storage. */
+CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
+/* Render a cJSON entity to text for transfer/storage without any formatting. */
+CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
+/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
+CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
+/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
+/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
+CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
+/* Delete a cJSON entity and all subentities. */
+CJSON_PUBLIC(void) cJSON_Delete(cJSON *c);
+
+/* Returns the number of items in an array (or object). */
+CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
+/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
+CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
+/* Get item "string" from object. Case insensitive. */
+CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
+CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
+CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
+/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
+CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
+
+/* Check if the item is a string and return its valuestring */
+CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
+
+/* These functions check the type of an item */
+CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
+CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
+
+/* These calls create a cJSON item of the appropriate type. */
+CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
+CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(SINT32 num);
+CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
+/* raw json */
+CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
+CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
+CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
+
+/* Create a string where valuestring references a string so
+ * it will not be freed by cJSON_Delete */
+CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
+/* Create an object/arrray that only references it's elements so
+ * they will not be freed by cJSON_Delete */
+CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
+CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
+
+/* These utilities create an Array of count items. */
+CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
+CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
+CJSON_PUBLIC(cJSON *) cJSON_CreateSINT32Array(const SINT32 *numbers, int count);
+CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count);
+
+/* Append item to the specified array/object. */
+CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
+CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
+/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
+ * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
+ * writing to `item->string` */
+CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
+/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
+CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
+CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
+
+/* Remove/Detatch items from Arrays/Objects. */
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
+CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
+CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
+CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
+CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
+
+/* Update array items. */
+CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
+CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
+CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
+CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
+
+/* Duplicate a cJSON item */
+CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
+/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
+need to be released. With recurse!=0, it will duplicate any children connected to the item.
+The item->next and ->prev pointers are always zero on return from Duplicate. */
+/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
+ * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
+CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
+
+
+CJSON_PUBLIC(void) cJSON_Minify(char *json);
+
+/* Helper functions for creating and adding items to an object at the same time.
+ * They return the added item or NULL on failure. */
+CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
+CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const SINT32 number);
+CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
+CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
+CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
+CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
+
+/* When assigning an integer value, it needs to be propagated to valueSINT32 too. */
+#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valueSINT32 = (number) : (number))
+/* helper for the cJSON_SetNumberValue macro */
+CJSON_PUBLIC(SINT32) cJSON_SetNumberHelper(cJSON *object, SINT32 number);
+#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (SINT32)number) : (number))
+
+/* Macro for iterating over an array or object */
+#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
+
+/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
+CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
+CJSON_PUBLIC(void) cJSON_free(void *object);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/code/application/source/sf_app/code/include/mask.h b/code/application/source/sf_app/code/include/mask.h
new file mode 100755
index 000000000..934fa856f
--- /dev/null
+++ b/code/application/source/sf_app/code/include/mask.h
@@ -0,0 +1,47 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Masking.
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __MASK_H__
+#define __MASK_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level);
+extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level);
+
+#ifdef WITH_TESTS
+extern int Mask_calcN2(int width, unsigned char *frame);
+extern int Mask_calcN1N3(int length, int *runLength);
+extern int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *runLength);
+extern int Mask_evaluateSymbol(int width, unsigned char *frame);
+extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level);
+extern unsigned char *Mask_makeMaskedFrame(int width, unsigned char *frame, int mask);
+#endif
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __MASK_H__ */
diff --git a/code/application/source/sf_app/code/include/mbedtls.h b/code/application/source/sf_app/code/include/mbedtls.h
new file mode 100755
index 000000000..45839a71b
--- /dev/null
+++ b/code/application/source/sf_app/code/include/mbedtls.h
@@ -0,0 +1,25941 @@
+/*
+ * MbedTLS Source Code Library Header
+ */
+
+
+#if 1//ME_COM_MBEDTLS
+/*
+#if defined(MBEDTLS_CONFIG_FILE)
+#include MBEDTLS_CONFIG_FILE
+#endif
+*/
+
+
+
+#define MBEDTLS_PLATFORM_C
+#define MBEDTLS_PLATFORM_MEMORY
+#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
+#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
+#define MBEDTLS_PLATFORM_EXIT_ALT
+#define MBEDTLS_NO_PLATFORM_ENTROPY
+#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+#define MBEDTLS_PLATFORM_PRINTF_ALT
+
+/* mbed TLS modules */
+#define MBEDTLS_AES_C
+#define MBEDTLS_CIPHER_C
+#define MBEDTLS_CIPHER_MODE_CBC
+#define MBEDTLS_CIPHER_MODE_CTR
+#define MBEDTLS_CIPHER_MODE_WITH_PADDING
+#define MBEDTLS_CIPHER_PADDING_PKCS7
+//#define MBEDTLS_CIPHER_PADDING_PKCS5
+
+
+#define MBEDTLS_AES_ROM_TABLES
+
+
+
+
+
+
+
+#if 0 //modified by ljy 20220330
+
+
+
+/********* Start of file include/mbedtls/config.h ************/
+
+/**
+ * \file config.h
+ *
+ * \brief Configuration options (set of defines)
+ *
+ * This set of compile-time options may be used to enable
+ * or disable features selectively, and reduce the global
+ * memory footprint.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_CONFIG_H
+#define MBEDTLS_CONFIG_H
+
+#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
+#define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+
+/**
+ * \name SECTION: System support
+ *
+ * This section sets system specific settings.
+ * \{
+ */
+
+/**
+ * \def MBEDTLS_HAVE_ASM
+ *
+ * The compiler has support for asm().
+ *
+ * Requires support for asm() in compiler.
+ *
+ * Used in:
+ * library/timing.c
+ * library/padlock.c
+ * include/mbedtls/bn_mul.h
+ *
+ * Comment to disable the use of assembly code.
+ */
+#define MBEDTLS_HAVE_ASM
+
+/**
+ * \def MBEDTLS_NO_UDBL_DIVISION
+ *
+ * The platform lacks support for double-width integer division (64-bit
+ * division on a 32-bit platform, 128-bit division on a 64-bit platform).
+ *
+ * Used in:
+ * include/mbedtls/bignum.h
+ * library/bignum.c
+ *
+ * The bignum code uses double-width division to speed up some operations.
+ * Double-width division is often implemented in software that needs to
+ * be linked with the program. The presence of a double-width integer
+ * type is usually detected automatically through preprocessor macros,
+ * but the automatic detection cannot know whether the code needs to
+ * and can be linked with an implementation of division for that type.
+ * By default division is assumed to be usable if the type is present.
+ * Uncomment this option to prevent the use of double-width division.
+ *
+ * Note that division for the native integer type is always required.
+ * Furthermore, a 64-bit type is always required even on a 32-bit
+ * platform, but it need not support multiplication or division. In some
+ * cases it is also desirable to disable some double-width operations. For
+ * example, if double-width division is implemented in software, disabling
+ * it can reduce code size in some embedded targets.
+ */
+//#define MBEDTLS_NO_UDBL_DIVISION
+
+/**
+ * \def MBEDTLS_HAVE_SSE2
+ *
+ * CPU supports SSE2 instruction set.
+ *
+ * Uncomment if the CPU supports SSE2 (IA-32 specific).
+ */
+//#define MBEDTLS_HAVE_SSE2
+
+/**
+ * \def MBEDTLS_HAVE_TIME
+ *
+ * System has time.h and time().
+ * The time does not need to be correct, only time differences are used,
+ * by contrast with MBEDTLS_HAVE_TIME_DATE
+ *
+ * Defining MBEDTLS_HAVE_TIME allows you to specify MBEDTLS_PLATFORM_TIME_ALT,
+ * MBEDTLS_PLATFORM_TIME_MACRO, MBEDTLS_PLATFORM_TIME_TYPE_MACRO and
+ * MBEDTLS_PLATFORM_STD_TIME.
+ *
+ * Comment if your system does not support time functions
+ */
+#define MBEDTLS_HAVE_TIME
+
+/**
+ * \def MBEDTLS_HAVE_TIME_DATE
+ *
+ * System has time.h and time(), gmtime() and the clock is correct.
+ * The time needs to be correct (not necesarily very accurate, but at least
+ * the date should be correct). This is used to verify the validity period of
+ * X.509 certificates.
+ *
+ * Comment if your system does not have a correct clock.
+ */
+#define MBEDTLS_HAVE_TIME_DATE
+
+/**
+ * \def MBEDTLS_PLATFORM_MEMORY
+ *
+ * Enable the memory allocation layer.
+ *
+ * By default mbed TLS uses the system-provided calloc() and free().
+ * This allows different allocators (self-implemented or provided) to be
+ * provided to the platform abstraction layer.
+ *
+ * Enabling MBEDTLS_PLATFORM_MEMORY without the
+ * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
+ * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
+ * free() function pointer at runtime.
+ *
+ * Enabling MBEDTLS_PLATFORM_MEMORY and specifying
+ * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
+ * alternate function at compile time.
+ *
+ * Requires: MBEDTLS_PLATFORM_C
+ *
+ * Enable this layer to allow use of alternative memory allocators.
+ */
+//#define MBEDTLS_PLATFORM_MEMORY
+
+/**
+ * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
+ *
+ * Do not assign standard functions in the platform layer (e.g. calloc() to
+ * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF)
+ *
+ * This makes sure there are no linking errors on platforms that do not support
+ * these functions. You will HAVE to provide alternatives, either at runtime
+ * via the platform_set_xxx() functions or at compile time by setting
+ * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a
+ * MBEDTLS_PLATFORM_XXX_MACRO.
+ *
+ * Requires: MBEDTLS_PLATFORM_C
+ *
+ * Uncomment to prevent default assignment of standard functions in the
+ * platform layer.
+ */
+//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
+
+/**
+ * \def MBEDTLS_PLATFORM_EXIT_ALT
+ *
+ * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the
+ * function in the platform abstraction layer.
+ *
+ * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will
+ * provide a function "mbedtls_platform_set_printf()" that allows you to set an
+ * alternative printf function pointer.
+ *
+ * All these define require MBEDTLS_PLATFORM_C to be defined!
+ *
+ * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows;
+ * it will be enabled automatically by check_config.h
+ *
+ * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as
+ * MBEDTLS_PLATFORM_XXX_MACRO!
+ *
+ * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME
+ *
+ * Uncomment a macro to enable alternate implementation of specific base
+ * platform function
+ */
+//#define MBEDTLS_PLATFORM_EXIT_ALT
+//#define MBEDTLS_PLATFORM_TIME_ALT
+//#define MBEDTLS_PLATFORM_FPRINTF_ALT
+//#define MBEDTLS_PLATFORM_PRINTF_ALT
+//#define MBEDTLS_PLATFORM_SNPRINTF_ALT
+//#define MBEDTLS_PLATFORM_NV_SEED_ALT
+//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
+
+/**
+ * \def MBEDTLS_DEPRECATED_WARNING
+ *
+ * Mark deprecated functions so that they generate a warning if used.
+ * Functions deprecated in one version will usually be removed in the next
+ * version. You can enable this to help you prepare the transition to a new
+ * major version by making sure your code is not using these functions.
+ *
+ * This only works with GCC and Clang. With other compilers, you may want to
+ * use MBEDTLS_DEPRECATED_REMOVED
+ *
+ * Uncomment to get warnings on using deprecated functions.
+ */
+//#define MBEDTLS_DEPRECATED_WARNING
+
+/**
+ * \def MBEDTLS_DEPRECATED_REMOVED
+ *
+ * Remove deprecated functions so that they generate an error if used.
+ * Functions deprecated in one version will usually be removed in the next
+ * version. You can enable this to help you prepare the transition to a new
+ * major version by making sure your code is not using these functions.
+ *
+ * Uncomment to get errors on using deprecated functions.
+ */
+//#define MBEDTLS_DEPRECATED_REMOVED
+
+/* \} name SECTION: System support */
+
+/**
+ * \name SECTION: mbed TLS feature support
+ *
+ * This section sets support for features that are or are not needed
+ * within the modules that are enabled.
+ * \{
+ */
+
+/**
+ * \def MBEDTLS_TIMING_ALT
+ *
+ * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(),
+ * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay()
+ *
+ * Only works if you have MBEDTLS_TIMING_C enabled.
+ *
+ * You will need to provide a header "timing_alt.h" and an implementation at
+ * compile time.
+ */
+//#define MBEDTLS_TIMING_ALT
+
+/**
+ * \def MBEDTLS_AES_ALT
+ *
+ * MBEDTLS__MODULE_NAME__ALT: Uncomment a macro to let mbed TLS use your
+ * alternate core implementation of a symmetric crypto, an arithmetic or hash
+ * module (e.g. platform specific assembly optimized implementations). Keep
+ * in mind that the function prototypes should remain the same.
+ *
+ * This replaces the whole module. If you only want to replace one of the
+ * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags.
+ *
+ * Example: In case you uncomment MBEDTLS_AES_ALT, mbed TLS will no longer
+ * provide the "struct mbedtls_aes_context" definition and omit the base
+ * function declarations and implementations. "aes_alt.h" will be included from
+ * "aes.h" to include the new function definitions.
+ *
+ * Uncomment a macro to enable alternate implementation of the corresponding
+ * module.
+ *
+ * \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their
+ * use constitutes a security risk. If possible, we recommend
+ * avoiding dependencies on them, and considering stronger message
+ * digests and ciphers instead.
+ *
+ */
+//#define MBEDTLS_AES_ALT
+//#define MBEDTLS_ARC4_ALT
+//#define MBEDTLS_BLOWFISH_ALT
+//#define MBEDTLS_CAMELLIA_ALT
+//#define MBEDTLS_CCM_ALT
+//#define MBEDTLS_CMAC_ALT
+//#define MBEDTLS_DES_ALT
+//#define MBEDTLS_DHM_ALT
+//#define MBEDTLS_ECJPAKE_ALT
+//#define MBEDTLS_GCM_ALT
+//#define MBEDTLS_MD2_ALT
+//#define MBEDTLS_MD4_ALT
+//#define MBEDTLS_MD5_ALT
+//#define MBEDTLS_RIPEMD160_ALT
+//#define MBEDTLS_RSA_ALT
+//#define MBEDTLS_SHA1_ALT
+//#define MBEDTLS_SHA256_ALT
+//#define MBEDTLS_SHA512_ALT
+//#define MBEDTLS_XTEA_ALT
+/*
+ * When replacing the elliptic curve module, pleace consider, that it is
+ * implemented with two .c files:
+ * - ecp.c
+ * - ecp_curves.c
+ * You can replace them very much like all the other MBEDTLS__MODULE_NAME__ALT
+ * macros as described above. The only difference is that you have to make sure
+ * that you provide functionality for both .c files.
+ */
+//#define MBEDTLS_ECP_ALT
+
+/**
+ * \def MBEDTLS_MD2_PROCESS_ALT
+ *
+ * MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use you
+ * alternate core implementation of symmetric crypto or hash function. Keep in
+ * mind that function prototypes should remain the same.
+ *
+ * This replaces only one function. The header file from mbed TLS is still
+ * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags.
+ *
+ * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, mbed TLS will
+ * no longer provide the mbedtls_sha1_process() function, but it will still provide
+ * the other function (using your mbedtls_sha1_process() function) and the definition
+ * of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible
+ * with this definition.
+ *
+ * \note Because of a signature change, the core AES encryption and decryption routines are
+ * currently named mbedtls_aes_internal_encrypt and mbedtls_aes_internal_decrypt,
+ * respectively. When setting up alternative implementations, these functions should
+ * be overriden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt
+ * must stay untouched.
+ *
+ * \note If you use the AES_xxx_ALT macros, then is is recommended to also set
+ * MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES
+ * tables.
+ *
+ * Uncomment a macro to enable alternate implementation of the corresponding
+ * function.
+ *
+ * \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use
+ * constitutes a security risk. If possible, we recommend avoiding
+ * dependencies on them, and considering stronger message digests
+ * and ciphers instead.
+ *
+ */
+//#define MBEDTLS_MD2_PROCESS_ALT
+//#define MBEDTLS_MD4_PROCESS_ALT
+//#define MBEDTLS_MD5_PROCESS_ALT
+//#define MBEDTLS_RIPEMD160_PROCESS_ALT
+//#define MBEDTLS_SHA1_PROCESS_ALT
+//#define MBEDTLS_SHA256_PROCESS_ALT
+//#define MBEDTLS_SHA512_PROCESS_ALT
+//#define MBEDTLS_DES_SETKEY_ALT
+//#define MBEDTLS_DES_CRYPT_ECB_ALT
+//#define MBEDTLS_DES3_CRYPT_ECB_ALT
+//#define MBEDTLS_AES_SETKEY_ENC_ALT
+//#define MBEDTLS_AES_SETKEY_DEC_ALT
+//#define MBEDTLS_AES_ENCRYPT_ALT
+//#define MBEDTLS_AES_DECRYPT_ALT
+//#define MBEDTLS_ECDH_GEN_PUBLIC_ALT
+//#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT
+//#define MBEDTLS_ECDSA_VERIFY_ALT
+//#define MBEDTLS_ECDSA_SIGN_ALT
+//#define MBEDTLS_ECDSA_GENKEY_ALT
+
+/**
+ * \def MBEDTLS_ECP_INTERNAL_ALT
+ *
+ * Expose a part of the internal interface of the Elliptic Curve Point module.
+ *
+ * MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your
+ * alternative core implementation of elliptic curve arithmetic. Keep in mind
+ * that function prototypes should remain the same.
+ *
+ * This partially replaces one function. The header file from mbed TLS is still
+ * used, in contrast to the MBEDTLS_ECP_ALT flag. The original implementation
+ * is still present and it is used for group structures not supported by the
+ * alternative.
+ *
+ * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT
+ * and implementing the following functions:
+ * unsigned char mbedtls_internal_ecp_grp_capable(
+ * const mbedtls_ecp_group *grp )
+ * int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
+ * void mbedtls_internal_ecp_deinit( const mbedtls_ecp_group *grp )
+ * The mbedtls_internal_ecp_grp_capable function should return 1 if the
+ * replacement functions implement arithmetic for the given group and 0
+ * otherwise.
+ * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_deinit are
+ * called before and after each point operation and provide an opportunity to
+ * implement optimized set up and tear down instructions.
+ *
+ * Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and
+ * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac
+ * function, but will use your mbedtls_internal_ecp_double_jac if the group is
+ * supported (your mbedtls_internal_ecp_grp_capable function returns 1 when
+ * receives it as an argument). If the group is not supported then the original
+ * implementation is used. The other functions and the definition of
+ * mbedtls_ecp_group and mbedtls_ecp_point will not change, so your
+ * implementation of mbedtls_internal_ecp_double_jac and
+ * mbedtls_internal_ecp_grp_capable must be compatible with this definition.
+ *
+ * Uncomment a macro to enable alternate implementation of the corresponding
+ * function.
+ */
+/* Required for all the functions in this section */
+//#define MBEDTLS_ECP_INTERNAL_ALT
+/* Support for Weierstrass curves with Jacobi representation */
+//#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT
+//#define MBEDTLS_ECP_ADD_MIXED_ALT
+//#define MBEDTLS_ECP_DOUBLE_JAC_ALT
+//#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT
+//#define MBEDTLS_ECP_NORMALIZE_JAC_ALT
+/* Support for curves with Montgomery arithmetic */
+//#define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT
+//#define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT
+//#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT
+
+/**
+ * \def MBEDTLS_TEST_NULL_ENTROPY
+ *
+ * Enables testing and use of mbed TLS without any configured entropy sources.
+ * This permits use of the library on platforms before an entropy source has
+ * been integrated (see for example the MBEDTLS_ENTROPY_HARDWARE_ALT or the
+ * MBEDTLS_ENTROPY_NV_SEED switches).
+ *
+ * WARNING! This switch MUST be disabled in production builds, and is suitable
+ * only for development.
+ * Enabling the switch negates any security provided by the library.
+ *
+ * Requires MBEDTLS_ENTROPY_C, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+ *
+ */
+//#define MBEDTLS_TEST_NULL_ENTROPY
+
+/**
+ * \def MBEDTLS_ENTROPY_HARDWARE_ALT
+ *
+ * Uncomment this macro to let mbed TLS use your own implementation of a
+ * hardware entropy collector.
+ *
+ * Your function must be called \c mbedtls_hardware_poll(), have the same
+ * prototype as declared in entropy_poll.h, and accept NULL as first argument.
+ *
+ * Uncomment to use your own hardware entropy collector.
+ */
+//#define MBEDTLS_ENTROPY_HARDWARE_ALT
+
+/**
+ * \def MBEDTLS_AES_ROM_TABLES
+ *
+ * Store the AES tables in ROM.
+ *
+ * Uncomment this macro to store the AES tables in ROM.
+ */
+//#define MBEDTLS_AES_ROM_TABLES
+
+/**
+ * \def MBEDTLS_CAMELLIA_SMALL_MEMORY
+ *
+ * Use less ROM for the Camellia implementation (saves about 768 bytes).
+ *
+ * Uncomment this macro to use less memory for Camellia.
+ */
+//#define MBEDTLS_CAMELLIA_SMALL_MEMORY
+
+/**
+ * \def MBEDTLS_CIPHER_MODE_CBC
+ *
+ * Enable Cipher Block Chaining mode (CBC) for symmetric ciphers.
+ */
+#define MBEDTLS_CIPHER_MODE_CBC
+
+/**
+ * \def MBEDTLS_CIPHER_MODE_CFB
+ *
+ * Enable Cipher Feedback mode (CFB) for symmetric ciphers.
+ */
+#define MBEDTLS_CIPHER_MODE_CFB
+
+/**
+ * \def MBEDTLS_CIPHER_MODE_CTR
+ *
+ * Enable Counter Block Cipher mode (CTR) for symmetric ciphers.
+ */
+#define MBEDTLS_CIPHER_MODE_CTR
+
+/**
+ * \def MBEDTLS_CIPHER_NULL_CIPHER
+ *
+ * Enable NULL cipher.
+ * Warning: Only do so when you know what you are doing. This allows for
+ * encryption or channels without any security!
+ *
+ * Requires MBEDTLS_ENABLE_WEAK_CIPHERSUITES as well to enable
+ * the following ciphersuites:
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA
+ * MBEDTLS_TLS_RSA_WITH_NULL_SHA256
+ * MBEDTLS_TLS_RSA_WITH_NULL_SHA
+ * MBEDTLS_TLS_RSA_WITH_NULL_MD5
+ * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA
+ * MBEDTLS_TLS_PSK_WITH_NULL_SHA384
+ * MBEDTLS_TLS_PSK_WITH_NULL_SHA256
+ * MBEDTLS_TLS_PSK_WITH_NULL_SHA
+ *
+ * Uncomment this macro to enable the NULL cipher and ciphersuites
+ */
+//#define MBEDTLS_CIPHER_NULL_CIPHER
+
+/**
+ * \def MBEDTLS_CIPHER_PADDING_PKCS7
+ *
+ * MBEDTLS_CIPHER_PADDING_XXX: Uncomment or comment macros to add support for
+ * specific padding modes in the cipher layer with cipher modes that support
+ * padding (e.g. CBC)
+ *
+ * If you disable all padding modes, only full blocks can be used with CBC.
+ *
+ * Enable padding modes in the cipher layer.
+ */
+#define MBEDTLS_CIPHER_PADDING_PKCS7
+#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
+#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
+#define MBEDTLS_CIPHER_PADDING_ZEROS
+
+/**
+ * \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES
+ *
+ * Enable weak ciphersuites in SSL / TLS.
+ * Warning: Only do so when you know what you are doing. This allows for
+ * channels with virtually no security at all!
+ *
+ * This enables the following ciphersuites:
+ * MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA
+ *
+ * Uncomment this macro to enable weak ciphersuites
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers instead.
+ */
+//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
+
+/**
+ * \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES
+ *
+ * Remove RC4 ciphersuites by default in SSL / TLS.
+ * This flag removes the ciphersuites based on RC4 from the default list as
+ * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to
+ * enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them
+ * explicitly.
+ *
+ * Uncomment this macro to remove RC4 ciphersuites by default.
+ */
+#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
+
+/**
+ * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED
+ *
+ * MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic Curve
+ * module. By default all supported curves are enabled.
+ *
+ * Comment macros to disable the curve and functions for it
+ */
+#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
+#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
+
+/**
+ * \def MBEDTLS_ECP_NIST_OPTIM
+ *
+ * Enable specific 'modulo p' routines for each NIST prime.
+ * Depending on the prime and architecture, makes operations 4 to 8 times
+ * faster on the corresponding curve.
+ *
+ * Comment this macro to disable NIST curves optimisation.
+ */
+#define MBEDTLS_ECP_NIST_OPTIM
+
+/**
+ * \def MBEDTLS_ECDSA_DETERMINISTIC
+ *
+ * Enable deterministic ECDSA (RFC 6979).
+ * Standard ECDSA is "fragile" in the sense that lack of entropy when signing
+ * may result in a compromise of the long-term signing key. This is avoided by
+ * the deterministic variant.
+ *
+ * Requires: MBEDTLS_HMAC_DRBG_C
+ *
+ * Comment this macro to disable deterministic ECDSA.
+ */
+#define MBEDTLS_ECDSA_DETERMINISTIC
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
+ *
+ * Enable the PSK based ciphersuite modes in SSL / TLS.
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
+ */
+#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
+ *
+ * Enable the DHE-PSK based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_DHM_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
+ *
+ * \warning Using DHE constitutes a security risk as it
+ * is not possible to validate custom DH parameters.
+ * If possible, it is recommended users should consider
+ * preferring other methods of key exchange.
+ * See dhm.h for more details.
+ *
+ */
+#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
+ *
+ * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_ECDH_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
+ */
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
+ *
+ * Enable the RSA-PSK based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
+ * MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
+ */
+#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
+ *
+ * Enable the RSA-only based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
+ * MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
+ */
+#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
+ *
+ * Enable the DHE-RSA based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_DHM_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
+ * MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ *
+ * \warning Using DHE constitutes a security risk as it
+ * is not possible to validate custom DH parameters.
+ * If possible, it is recommended users should consider
+ * preferring other methods of key exchange.
+ * See dhm.h for more details.
+ *
+ */
+#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
+ *
+ * Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
+ * MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
+ */
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
+ *
+ * Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C,
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
+ */
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
+ *
+ * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
+ */
+#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
+ *
+ * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ */
+#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
+ *
+ * Enable the ECJPAKE based ciphersuite modes in SSL / TLS.
+ *
+ * \warning This is currently experimental. EC J-PAKE support is based on the
+ * Thread v1.0.0 specification; incompatible changes to the specification
+ * might still happen. For this reason, this is disabled by default.
+ *
+ * Requires: MBEDTLS_ECJPAKE_C
+ * MBEDTLS_SHA256_C
+ * MBEDTLS_ECP_DP_SECP256R1_ENABLED
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
+ */
+//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
+
+/**
+ * \def MBEDTLS_PK_PARSE_EC_EXTENDED
+ *
+ * Enhance support for reading EC keys using variants of SEC1 not allowed by
+ * RFC 5915 and RFC 5480.
+ *
+ * Currently this means parsing the SpecifiedECDomain choice of EC
+ * parameters (only known groups are supported, not arbitrary domains, to
+ * avoid validation issues).
+ *
+ * Disable if you only need to support RFC 5915 + 5480 key formats.
+ */
+#define MBEDTLS_PK_PARSE_EC_EXTENDED
+
+/**
+ * \def MBEDTLS_ERROR_STRERROR_DUMMY
+ *
+ * Enable a dummy error function to make use of mbedtls_strerror() in
+ * third party libraries easier when MBEDTLS_ERROR_C is disabled
+ * (no effect when MBEDTLS_ERROR_C is enabled).
+ *
+ * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're
+ * not using mbedtls_strerror() or error_strerror() in your application.
+ *
+ * Disable if you run into name conflicts and want to really remove the
+ * mbedtls_strerror()
+ */
+#define MBEDTLS_ERROR_STRERROR_DUMMY
+
+/**
+ * \def MBEDTLS_GENPRIME
+ *
+ * Enable the prime-number generation code.
+ *
+ * Requires: MBEDTLS_BIGNUM_C
+ */
+#define MBEDTLS_GENPRIME
+
+/**
+ * \def MBEDTLS_FS_IO
+ *
+ * Enable functions that use the filesystem.
+ */
+#define MBEDTLS_FS_IO
+
+/**
+ * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+ *
+ * Do not add default entropy sources. These are the platform specific,
+ * mbedtls_timing_hardclock and HAVEGE based poll functions.
+ *
+ * This is useful to have more control over the added entropy sources in an
+ * application.
+ *
+ * Uncomment this macro to prevent loading of default entropy functions.
+ */
+//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+
+/**
+ * \def MBEDTLS_NO_PLATFORM_ENTROPY
+ *
+ * Do not use built-in platform entropy functions.
+ * This is useful if your platform does not support
+ * standards like the /dev/urandom or Windows CryptoAPI.
+ *
+ * Uncomment this macro to disable the built-in platform entropy functions.
+ */
+//#define MBEDTLS_NO_PLATFORM_ENTROPY
+
+/**
+ * \def MBEDTLS_ENTROPY_FORCE_SHA256
+ *
+ * Force the entropy accumulator to use a SHA-256 accumulator instead of the
+ * default SHA-512 based one (if both are available).
+ *
+ * Requires: MBEDTLS_SHA256_C
+ *
+ * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option
+ * if you have performance concerns.
+ *
+ * This option is only useful if both MBEDTLS_SHA256_C and
+ * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used.
+ */
+//#define MBEDTLS_ENTROPY_FORCE_SHA256
+
+/**
+ * \def MBEDTLS_ENTROPY_NV_SEED
+ *
+ * Enable the non-volatile (NV) seed file-based entropy source.
+ * (Also enables the NV seed read/write functions in the platform layer)
+ *
+ * This is crucial (if not required) on systems that do not have a
+ * cryptographic entropy source (in hardware or kernel) available.
+ *
+ * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
+ *
+ * \note The read/write functions that are used by the entropy source are
+ * determined in the platform layer, and can be modified at runtime and/or
+ * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
+ *
+ * \note If you use the default implementation functions that read a seedfile
+ * with regular fopen(), please make sure you make a seedfile with the
+ * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
+ * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
+ * and written to or you will get an entropy source error! The default
+ * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
+ * bytes from the file.
+ *
+ * \note The entropy collector will write to the seed file before entropy is
+ * given to an external source, to update it.
+ */
+//#define MBEDTLS_ENTROPY_NV_SEED
+
+/**
+ * \def MBEDTLS_MEMORY_DEBUG
+ *
+ * Enable debugging of buffer allocator memory issues. Automatically prints
+ * (to stderr) all (fatal) messages on memory allocation issues. Enables
+ * function for 'debug output' of allocated memory.
+ *
+ * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
+ *
+ * Uncomment this macro to let the buffer allocator print out error messages.
+ */
+//#define MBEDTLS_MEMORY_DEBUG
+
+/**
+ * \def MBEDTLS_MEMORY_BACKTRACE
+ *
+ * Include backtrace information with each allocated block.
+ *
+ * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
+ * GLIBC-compatible backtrace() an backtrace_symbols() support
+ *
+ * Uncomment this macro to include backtrace information
+ */
+//#define MBEDTLS_MEMORY_BACKTRACE
+
+/**
+ * \def MBEDTLS_PK_RSA_ALT_SUPPORT
+ *
+ * Support external private RSA keys (eg from a HSM) in the PK layer.
+ *
+ * Comment this macro to disable support for external private RSA keys.
+ */
+#define MBEDTLS_PK_RSA_ALT_SUPPORT
+
+/**
+ * \def MBEDTLS_PKCS1_V15
+ *
+ * Enable support for PKCS#1 v1.5 encoding.
+ *
+ * Requires: MBEDTLS_RSA_C
+ *
+ * This enables support for PKCS#1 v1.5 operations.
+ */
+#define MBEDTLS_PKCS1_V15
+
+/**
+ * \def MBEDTLS_PKCS1_V21
+ *
+ * Enable support for PKCS#1 v2.1 encoding.
+ *
+ * Requires: MBEDTLS_MD_C, MBEDTLS_RSA_C
+ *
+ * This enables support for RSAES-OAEP and RSASSA-PSS operations.
+ */
+#define MBEDTLS_PKCS1_V21
+
+/**
+ * \def MBEDTLS_RSA_NO_CRT
+ *
+ * Do not use the Chinese Remainder Theorem
+ * for the RSA private operation.
+ *
+ * Uncomment this macro to disable the use of CRT in RSA.
+ *
+ */
+//#define MBEDTLS_RSA_NO_CRT
+
+/**
+ * \def MBEDTLS_SELF_TEST
+ *
+ * Enable the checkup functions (*_self_test).
+ */
+#define MBEDTLS_SELF_TEST
+
+/**
+ * \def MBEDTLS_SHA256_SMALLER
+ *
+ * Enable an implementation of SHA-256 that has lower ROM footprint but also
+ * lower performance.
+ *
+ * The default implementation is meant to be a reasonnable compromise between
+ * performance and size. This version optimizes more aggressively for size at
+ * the expense of performance. Eg on Cortex-M4 it reduces the size of
+ * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about
+ * 30%.
+ *
+ * Uncomment to enable the smaller implementation of SHA256.
+ */
+//#define MBEDTLS_SHA256_SMALLER
+
+/**
+ * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES
+ *
+ * Enable sending of alert messages in case of encountered errors as per RFC.
+ * If you choose not to send the alert messages, mbed TLS can still communicate
+ * with other servers, only debugging of failures is harder.
+ *
+ * The advantage of not sending alert messages, is that no information is given
+ * about reasons for failures thus preventing adversaries of gaining intel.
+ *
+ * Enable sending of all alert messages
+ */
+#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
+
+/**
+ * \def MBEDTLS_SSL_DEBUG_ALL
+ *
+ * Enable the debug messages in SSL module for all issues.
+ * Debug messages have been disabled in some places to prevent timing
+ * attacks due to (unbalanced) debugging function calls.
+ *
+ * If you need all error reporting you should enable this during debugging,
+ * but remove this for production servers that should log as well.
+ *
+ * Uncomment this macro to report all debug messages on errors introducing
+ * a timing side-channel.
+ *
+ */
+//#define MBEDTLS_SSL_DEBUG_ALL
+
+/** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC
+ *
+ * Enable support for Encrypt-then-MAC, RFC 7366.
+ *
+ * This allows peers that both support it to use a more robust protection for
+ * ciphersuites using CBC, providing deep resistance against timing attacks
+ * on the padding or underlying cipher.
+ *
+ * This only affects CBC ciphersuites, and is useless if none is defined.
+ *
+ * Requires: MBEDTLS_SSL_PROTO_TLS1 or
+ * MBEDTLS_SSL_PROTO_TLS1_1 or
+ * MBEDTLS_SSL_PROTO_TLS1_2
+ *
+ * Comment this macro to disable support for Encrypt-then-MAC
+ */
+#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
+
+/** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET
+ *
+ * Enable support for Extended Master Secret, aka Session Hash
+ * (draft-ietf-tls-session-hash-02).
+ *
+ * This was introduced as "the proper fix" to the Triple Handshake familiy of
+ * attacks, but it is recommended to always use it (even if you disable
+ * renegotiation), since it actually fixes a more fundamental issue in the
+ * original SSL/TLS design, and has implications beyond Triple Handshake.
+ *
+ * Requires: MBEDTLS_SSL_PROTO_TLS1 or
+ * MBEDTLS_SSL_PROTO_TLS1_1 or
+ * MBEDTLS_SSL_PROTO_TLS1_2
+ *
+ * Comment this macro to disable support for Extended Master Secret.
+ */
+#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
+
+/**
+ * \def MBEDTLS_SSL_FALLBACK_SCSV
+ *
+ * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00).
+ *
+ * For servers, it is recommended to always enable this, unless you support
+ * only one version of TLS, or know for sure that none of your clients
+ * implements a fallback strategy.
+ *
+ * For clients, you only need this if you're using a fallback strategy, which
+ * is not recommended in the first place, unless you absolutely need it to
+ * interoperate with buggy (version-intolerant) servers.
+ *
+ * Comment this macro to disable support for FALLBACK_SCSV
+ */
+#define MBEDTLS_SSL_FALLBACK_SCSV
+
+/**
+ * \def MBEDTLS_SSL_HW_RECORD_ACCEL
+ *
+ * Enable hooking functions in SSL module for hardware acceleration of
+ * individual records.
+ *
+ * Uncomment this macro to enable hooking functions.
+ */
+//#define MBEDTLS_SSL_HW_RECORD_ACCEL
+
+/**
+ * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING
+ *
+ * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
+ *
+ * This is a countermeasure to the BEAST attack, which also minimizes the risk
+ * of interoperability issues compared to sending 0-length records.
+ *
+ * Comment this macro to disable 1/n-1 record splitting.
+ */
+#define MBEDTLS_SSL_CBC_RECORD_SPLITTING
+
+/**
+ * \def MBEDTLS_SSL_RENEGOTIATION
+ *
+ * Disable support for TLS renegotiation.
+ *
+ * The two main uses of renegotiation are (1) refresh keys on long-lived
+ * connections and (2) client authentication after the initial handshake.
+ * If you don't need renegotiation, it's probably better to disable it, since
+ * it has been associated with security issues in the past and is easy to
+ * misuse/misunderstand.
+ *
+ * Comment this to disable support for renegotiation.
+ *
+ * \note Even if this option is disabled, both client and server are aware
+ * of the Renegotiation Indication Extension (RFC 5746) used to
+ * prevent the SSL renegotiation attack (see RFC 5746 Sect. 1).
+ * (See \c mbedtls_ssl_conf_legacy_renegotiation for the
+ * configuration of this extension).
+ *
+ */
+#define MBEDTLS_SSL_RENEGOTIATION
+
+/**
+ * \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
+ *
+ * Enable support for receiving and parsing SSLv2 Client Hello messages for the
+ * SSL Server module (MBEDTLS_SSL_SRV_C).
+ *
+ * Uncomment this macro to enable support for SSLv2 Client Hello messages.
+ */
+//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
+
+/**
+ * \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
+ *
+ * Pick the ciphersuite according to the client's preferences rather than ours
+ * in the SSL Server module (MBEDTLS_SSL_SRV_C).
+ *
+ * Uncomment this macro to respect client's ciphersuite order
+ */
+//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
+
+/**
+ * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
+ *
+ * Enable support for RFC 6066 max_fragment_length extension in SSL.
+ *
+ * Comment this macro to disable support for the max_fragment_length extension
+ */
+#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
+
+/**
+ * \def MBEDTLS_SSL_PROTO_SSL3
+ *
+ * Enable support for SSL 3.0.
+ *
+ * Requires: MBEDTLS_MD5_C
+ * MBEDTLS_SHA1_C
+ *
+ * Comment this macro to disable support for SSL 3.0
+ */
+//#define MBEDTLS_SSL_PROTO_SSL3
+
+/**
+ * \def MBEDTLS_SSL_PROTO_TLS1
+ *
+ * Enable support for TLS 1.0.
+ *
+ * Requires: MBEDTLS_MD5_C
+ * MBEDTLS_SHA1_C
+ *
+ * Comment this macro to disable support for TLS 1.0
+ */
+#define MBEDTLS_SSL_PROTO_TLS1
+
+/**
+ * \def MBEDTLS_SSL_PROTO_TLS1_1
+ *
+ * Enable support for TLS 1.1 (and DTLS 1.0 if DTLS is enabled).
+ *
+ * Requires: MBEDTLS_MD5_C
+ * MBEDTLS_SHA1_C
+ *
+ * Comment this macro to disable support for TLS 1.1 / DTLS 1.0
+ */
+#define MBEDTLS_SSL_PROTO_TLS1_1
+
+/**
+ * \def MBEDTLS_SSL_PROTO_TLS1_2
+ *
+ * Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled).
+ *
+ * Requires: MBEDTLS_SHA1_C or MBEDTLS_SHA256_C or MBEDTLS_SHA512_C
+ * (Depends on ciphersuites)
+ *
+ * Comment this macro to disable support for TLS 1.2 / DTLS 1.2
+ */
+#define MBEDTLS_SSL_PROTO_TLS1_2
+
+/**
+ * \def MBEDTLS_SSL_PROTO_DTLS
+ *
+ * Enable support for DTLS (all available versions).
+ *
+ * Enable this and MBEDTLS_SSL_PROTO_TLS1_1 to enable DTLS 1.0,
+ * and/or this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2.
+ *
+ * Requires: MBEDTLS_SSL_PROTO_TLS1_1
+ * or MBEDTLS_SSL_PROTO_TLS1_2
+ *
+ * Comment this macro to disable support for DTLS
+ */
+#define MBEDTLS_SSL_PROTO_DTLS
+
+/**
+ * \def MBEDTLS_SSL_ALPN
+ *
+ * Enable support for RFC 7301 Application Layer Protocol Negotiation.
+ *
+ * Comment this macro to disable support for ALPN.
+ */
+#define MBEDTLS_SSL_ALPN
+
+/**
+ * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY
+ *
+ * Enable support for the anti-replay mechanism in DTLS.
+ *
+ * Requires: MBEDTLS_SSL_TLS_C
+ * MBEDTLS_SSL_PROTO_DTLS
+ *
+ * \warning Disabling this is often a security risk!
+ * See mbedtls_ssl_conf_dtls_anti_replay() for details.
+ *
+ * Comment this to disable anti-replay in DTLS.
+ */
+#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
+
+/**
+ * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY
+ *
+ * Enable support for HelloVerifyRequest on DTLS servers.
+ *
+ * This feature is highly recommended to prevent DTLS servers being used as
+ * amplifiers in DoS attacks against other hosts. It should always be enabled
+ * unless you know for sure amplification cannot be a problem in the
+ * environment in which your server operates.
+ *
+ * \warning Disabling this can ba a security risk! (see above)
+ *
+ * Requires: MBEDTLS_SSL_PROTO_DTLS
+ *
+ * Comment this to disable support for HelloVerifyRequest.
+ */
+#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
+
+/**
+ * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
+ *
+ * Enable server-side support for clients that reconnect from the same port.
+ *
+ * Some clients unexpectedly close the connection and try to reconnect using the
+ * same source port. This needs special support from the server to handle the
+ * new connection securely, as described in section 4.2.8 of RFC 6347. This
+ * flag enables that support.
+ *
+ * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY
+ *
+ * Comment this to disable support for clients reusing the source port.
+ */
+#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
+
+/**
+ * \def MBEDTLS_SSL_DTLS_BADMAC_LIMIT
+ *
+ * Enable support for a limit of records with bad MAC.
+ *
+ * See mbedtls_ssl_conf_dtls_badmac_limit().
+ *
+ * Requires: MBEDTLS_SSL_PROTO_DTLS
+ */
+#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
+
+/**
+ * \def MBEDTLS_SSL_SESSION_TICKETS
+ *
+ * Enable support for RFC 5077 session tickets in SSL.
+ * Client-side, provides full support for session tickets (maintainance of a
+ * session store remains the responsibility of the application, though).
+ * Server-side, you also need to provide callbacks for writing and parsing
+ * tickets, including authenticated encryption and key management. Example
+ * callbacks are provided by MBEDTLS_SSL_TICKET_C.
+ *
+ * Comment this macro to disable support for SSL session tickets
+ */
+#define MBEDTLS_SSL_SESSION_TICKETS
+
+/**
+ * \def MBEDTLS_SSL_EXPORT_KEYS
+ *
+ * Enable support for exporting key block and master secret.
+ * This is required for certain users of TLS, e.g. EAP-TLS.
+ *
+ * Comment this macro to disable support for key export
+ */
+#define MBEDTLS_SSL_EXPORT_KEYS
+
+/**
+ * \def MBEDTLS_SSL_SERVER_NAME_INDICATION
+ *
+ * Enable support for RFC 6066 server name indication (SNI) in SSL.
+ *
+ * Requires: MBEDTLS_X509_CRT_PARSE_C
+ *
+ * Comment this macro to disable support for server name indication in SSL
+ */
+#define MBEDTLS_SSL_SERVER_NAME_INDICATION
+
+/**
+ * \def MBEDTLS_SSL_TRUNCATED_HMAC
+ *
+ * Enable support for RFC 6066 truncated HMAC in SSL.
+ *
+ * Comment this macro to disable support for truncated HMAC in SSL
+ */
+#define MBEDTLS_SSL_TRUNCATED_HMAC
+
+/**
+ * \def MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
+ *
+ * Fallback to old (pre-2.7), non-conforming implementation of the truncated
+ * HMAC extension which also truncates the HMAC key. Note that this option is
+ * only meant for a transitory upgrade period and is likely to be removed in
+ * a future version of the library.
+ *
+ * \warning The old implementation is non-compliant and has a security weakness
+ * (2^80 brute force attack on the HMAC key used for a single,
+ * uninterrupted connection). This should only be enabled temporarily
+ * when (1) the use of truncated HMAC is essential in order to save
+ * bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use
+ * the fixed implementation yet (pre-2.7).
+ *
+ * \deprecated This option is deprecated and will likely be removed in a
+ * future version of Mbed TLS.
+ *
+ * Uncomment to fallback to old, non-compliant truncated HMAC implementation.
+ *
+ * Requires: MBEDTLS_SSL_TRUNCATED_HMAC
+ */
+//#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
+
+/**
+ * \def MBEDTLS_THREADING_ALT
+ *
+ * Provide your own alternate threading implementation.
+ *
+ * Requires: MBEDTLS_THREADING_C
+ *
+ * Uncomment this to allow your own alternate threading implementation.
+ */
+//#define MBEDTLS_THREADING_ALT
+
+/**
+ * \def MBEDTLS_THREADING_PTHREAD
+ *
+ * Enable the pthread wrapper layer for the threading layer.
+ *
+ * Requires: MBEDTLS_THREADING_C
+ *
+ * Uncomment this to enable pthread mutexes.
+ */
+//#define MBEDTLS_THREADING_PTHREAD
+
+/**
+ * \def MBEDTLS_VERSION_FEATURES
+ *
+ * Allow run-time checking of compile-time enabled features. Thus allowing users
+ * to check at run-time if the library is for instance compiled with threading
+ * support via mbedtls_version_check_feature().
+ *
+ * Requires: MBEDTLS_VERSION_C
+ *
+ * Comment this to disable run-time checking and save ROM space
+ */
+#define MBEDTLS_VERSION_FEATURES
+
+/**
+ * \def MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
+ *
+ * If set, the X509 parser will not break-off when parsing an X509 certificate
+ * and encountering an extension in a v1 or v2 certificate.
+ *
+ * Uncomment to prevent an error.
+ */
+//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
+
+/**
+ * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
+ *
+ * If set, the X509 parser will not break-off when parsing an X509 certificate
+ * and encountering an unknown critical extension.
+ *
+ * \warning Depending on your PKI use, enabling this can be a security risk!
+ *
+ * Uncomment to prevent an error.
+ */
+//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
+
+/**
+ * \def MBEDTLS_X509_CHECK_KEY_USAGE
+ *
+ * Enable verification of the keyUsage extension (CA and leaf certificates).
+ *
+ * Disabling this avoids problems with mis-issued and/or misused
+ * (intermediate) CA and leaf certificates.
+ *
+ * \warning Depending on your PKI use, disabling this can be a security risk!
+ *
+ * Comment to skip keyUsage checking for both CA and leaf certificates.
+ */
+#define MBEDTLS_X509_CHECK_KEY_USAGE
+
+/**
+ * \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
+ *
+ * Enable verification of the extendedKeyUsage extension (leaf certificates).
+ *
+ * Disabling this avoids problems with mis-issued and/or misused certificates.
+ *
+ * \warning Depending on your PKI use, disabling this can be a security risk!
+ *
+ * Comment to skip extendedKeyUsage checking for certificates.
+ */
+#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
+
+/**
+ * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT
+ *
+ * Enable parsing and verification of X.509 certificates, CRLs and CSRS
+ * signed with RSASSA-PSS (aka PKCS#1 v2.1).
+ *
+ * Comment this macro to disallow using RSASSA-PSS in certificates.
+ */
+#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
+
+/**
+ * \def MBEDTLS_ZLIB_SUPPORT
+ *
+ * If set, the SSL/TLS module uses ZLIB to support compression and
+ * decompression of packet data.
+ *
+ * \warning TLS-level compression MAY REDUCE SECURITY! See for example the
+ * CRIME attack. Before enabling this option, you should examine with care if
+ * CRIME or similar exploits may be a applicable to your use case.
+ *
+ * \note Currently compression can't be used with DTLS.
+ *
+ * \deprecated This feature is deprecated and will be removed
+ * in the next major revision of the library.
+ *
+ * Used in: library/ssl_tls.c
+ * library/ssl_cli.c
+ * library/ssl_srv.c
+ *
+ * This feature requires zlib library and headers to be present.
+ *
+ * Uncomment to enable use of ZLIB
+ */
+//#define MBEDTLS_ZLIB_SUPPORT
+/* \} name SECTION: mbed TLS feature support */
+
+/**
+ * \name SECTION: mbed TLS modules
+ *
+ * This section enables or disables entire modules in mbed TLS
+ * \{
+ */
+
+/**
+ * \def MBEDTLS_AESNI_C
+ *
+ * Enable AES-NI support on x86-64.
+ *
+ * Module: library/aesni.c
+ * Caller: library/aes.c
+ *
+ * Requires: MBEDTLS_HAVE_ASM
+ *
+ * This modules adds support for the AES-NI instructions on x86-64
+ */
+#define MBEDTLS_AESNI_C
+
+/**
+ * \def MBEDTLS_AES_C
+ *
+ * Enable the AES block cipher.
+ *
+ * Module: library/aes.c
+ * Caller: library/ssl_tls.c
+ * library/pem.c
+ * library/ctr_drbg.c
+ *
+ * This module enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
+ * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
+ * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
+ * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
+ * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
+ * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
+ * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
+ *
+ * PEM_PARSE uses AES for decrypting encrypted keys.
+ */
+#define MBEDTLS_AES_C
+
+/**
+ * \def MBEDTLS_ARC4_C
+ *
+ * Enable the ARCFOUR stream cipher.
+ *
+ * Module: library/arc4.c
+ * Caller: library/ssl_tls.c
+ *
+ * This module enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
+ * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
+ * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. If possible, we recommend avoidng dependencies on
+ * it, and considering stronger ciphers instead.
+ *
+ */
+#define MBEDTLS_ARC4_C
+
+/**
+ * \def MBEDTLS_ASN1_PARSE_C
+ *
+ * Enable the generic ASN1 parser.
+ *
+ * Module: library/asn1.c
+ * Caller: library/x509.c
+ * library/dhm.c
+ * library/pkcs12.c
+ * library/pkcs5.c
+ * library/pkparse.c
+ */
+#define MBEDTLS_ASN1_PARSE_C
+
+/**
+ * \def MBEDTLS_ASN1_WRITE_C
+ *
+ * Enable the generic ASN1 writer.
+ *
+ * Module: library/asn1write.c
+ * Caller: library/ecdsa.c
+ * library/pkwrite.c
+ * library/x509_create.c
+ * library/x509write_crt.c
+ * library/x509write_csr.c
+ */
+#define MBEDTLS_ASN1_WRITE_C
+
+/**
+ * \def MBEDTLS_BASE64_C
+ *
+ * Enable the Base64 module.
+ *
+ * Module: library/base64.c
+ * Caller: library/pem.c
+ *
+ * This module is required for PEM support (required by X.509).
+ */
+#define MBEDTLS_BASE64_C
+
+/**
+ * \def MBEDTLS_BIGNUM_C
+ *
+ * Enable the multi-precision integer library.
+ *
+ * Module: library/bignum.c
+ * Caller: library/dhm.c
+ * library/ecp.c
+ * library/ecdsa.c
+ * library/rsa.c
+ * library/rsa_internal.c
+ * library/ssl_tls.c
+ *
+ * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support.
+ */
+#define MBEDTLS_BIGNUM_C
+
+/**
+ * \def MBEDTLS_BLOWFISH_C
+ *
+ * Enable the Blowfish block cipher.
+ *
+ * Module: library/blowfish.c
+ */
+#define MBEDTLS_BLOWFISH_C
+
+/**
+ * \def MBEDTLS_CAMELLIA_C
+ *
+ * Enable the Camellia block cipher.
+ *
+ * Module: library/camellia.c
+ * Caller: library/ssl_tls.c
+ *
+ * This module enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ */
+#define MBEDTLS_CAMELLIA_C
+
+/**
+ * \def MBEDTLS_CCM_C
+ *
+ * Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher.
+ *
+ * Module: library/ccm.c
+ *
+ * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C
+ *
+ * This module enables the AES-CCM ciphersuites, if other requisites are
+ * enabled as well.
+ */
+#define MBEDTLS_CCM_C
+
+/**
+ * \def MBEDTLS_CERTS_C
+ *
+ * Enable the test certificates.
+ *
+ * Module: library/certs.c
+ * Caller:
+ *
+ * This module is used for testing (ssl_client/server).
+ */
+#define MBEDTLS_CERTS_C
+
+/**
+ * \def MBEDTLS_CIPHER_C
+ *
+ * Enable the generic cipher layer.
+ *
+ * Module: library/cipher.c
+ * Caller: library/ssl_tls.c
+ *
+ * Uncomment to enable generic cipher wrappers.
+ */
+#define MBEDTLS_CIPHER_C
+
+/**
+ * \def MBEDTLS_CMAC_C
+ *
+ * Enable the CMAC (Cipher-based Message Authentication Code) mode for block
+ * ciphers.
+ *
+ * Module: library/cmac.c
+ *
+ * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
+ *
+ */
+//#define MBEDTLS_CMAC_C
+
+/**
+ * \def MBEDTLS_CTR_DRBG_C
+ *
+ * Enable the CTR_DRBG AES-256-based random generator.
+ *
+ * Module: library/ctr_drbg.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_AES_C
+ *
+ * This module provides the CTR_DRBG AES-256 random number generator.
+ */
+#define MBEDTLS_CTR_DRBG_C
+
+/**
+ * \def MBEDTLS_DEBUG_C
+ *
+ * Enable the debug functions.
+ *
+ * Module: library/debug.c
+ * Caller: library/ssl_cli.c
+ * library/ssl_srv.c
+ * library/ssl_tls.c
+ *
+ * This module provides debugging functions.
+ */
+#define MBEDTLS_DEBUG_C
+
+/**
+ * \def MBEDTLS_DES_C
+ *
+ * Enable the DES block cipher.
+ *
+ * Module: library/des.c
+ * Caller: library/pem.c
+ * library/ssl_tls.c
+ *
+ * This module enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
+ * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
+ *
+ * PEM_PARSE uses DES/3DES for decrypting encrypted keys.
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers instead.
+ */
+#define MBEDTLS_DES_C
+
+/**
+ * \def MBEDTLS_DHM_C
+ *
+ * Enable the Diffie-Hellman-Merkle module.
+ *
+ * Module: library/dhm.c
+ * Caller: library/ssl_cli.c
+ * library/ssl_srv.c
+ *
+ * This module is used by the following key exchanges:
+ * DHE-RSA, DHE-PSK
+ *
+ * \warning Using DHE constitutes a security risk as it
+ * is not possible to validate custom DH parameters.
+ * If possible, it is recommended users should consider
+ * preferring other methods of key exchange.
+ * See dhm.h for more details.
+ *
+ */
+#define MBEDTLS_DHM_C
+
+/**
+ * \def MBEDTLS_ECDH_C
+ *
+ * Enable the elliptic curve Diffie-Hellman library.
+ *
+ * Module: library/ecdh.c
+ * Caller: library/ssl_cli.c
+ * library/ssl_srv.c
+ *
+ * This module is used by the following key exchanges:
+ * ECDHE-ECDSA, ECDHE-RSA, DHE-PSK
+ *
+ * Requires: MBEDTLS_ECP_C
+ */
+#define MBEDTLS_ECDH_C
+
+/**
+ * \def MBEDTLS_ECDSA_C
+ *
+ * Enable the elliptic curve DSA library.
+ *
+ * Module: library/ecdsa.c
+ * Caller:
+ *
+ * This module is used by the following key exchanges:
+ * ECDHE-ECDSA
+ *
+ * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C
+ */
+#define MBEDTLS_ECDSA_C
+
+/**
+ * \def MBEDTLS_ECJPAKE_C
+ *
+ * Enable the elliptic curve J-PAKE library.
+ *
+ * \warning This is currently experimental. EC J-PAKE support is based on the
+ * Thread v1.0.0 specification; incompatible changes to the specification
+ * might still happen. For this reason, this is disabled by default.
+ *
+ * Module: library/ecjpake.c
+ * Caller:
+ *
+ * This module is used by the following key exchanges:
+ * ECJPAKE
+ *
+ * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C
+ */
+//#define MBEDTLS_ECJPAKE_C
+
+/**
+ * \def MBEDTLS_ECP_C
+ *
+ * Enable the elliptic curve over GF(p) library.
+ *
+ * Module: library/ecp.c
+ * Caller: library/ecdh.c
+ * library/ecdsa.c
+ * library/ecjpake.c
+ *
+ * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED
+ */
+#define MBEDTLS_ECP_C
+
+/**
+ * \def MBEDTLS_ENTROPY_C
+ *
+ * Enable the platform-specific entropy code.
+ *
+ * Module: library/entropy.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C
+ *
+ * This module provides a generic entropy pool
+ */
+#define MBEDTLS_ENTROPY_C
+
+/**
+ * \def MBEDTLS_ERROR_C
+ *
+ * Enable error code to error string conversion.
+ *
+ * Module: library/error.c
+ * Caller:
+ *
+ * This module enables mbedtls_strerror().
+ */
+#define MBEDTLS_ERROR_C
+
+/**
+ * \def MBEDTLS_GCM_C
+ *
+ * Enable the Galois/Counter Mode (GCM) for AES.
+ *
+ * Module: library/gcm.c
+ *
+ * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C
+ *
+ * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other
+ * requisites are enabled as well.
+ */
+#define MBEDTLS_GCM_C
+
+/**
+ * \def MBEDTLS_HAVEGE_C
+ *
+ * Enable the HAVEGE random generator.
+ *
+ * Warning: the HAVEGE random generator is not suitable for virtualized
+ * environments
+ *
+ * Warning: the HAVEGE random generator is dependent on timing and specific
+ * processor traits. It is therefore not advised to use HAVEGE as
+ * your applications primary random generator or primary entropy pool
+ * input. As a secondary input to your entropy pool, it IS able add
+ * the (limited) extra entropy it provides.
+ *
+ * Module: library/havege.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_TIMING_C
+ *
+ * Uncomment to enable the HAVEGE random generator.
+ */
+//#define MBEDTLS_HAVEGE_C
+
+/**
+ * \def MBEDTLS_HMAC_DRBG_C
+ *
+ * Enable the HMAC_DRBG random generator.
+ *
+ * Module: library/hmac_drbg.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_MD_C
+ *
+ * Uncomment to enable the HMAC_DRBG random number geerator.
+ */
+#define MBEDTLS_HMAC_DRBG_C
+
+/**
+ * \def MBEDTLS_MD_C
+ *
+ * Enable the generic message digest layer.
+ *
+ * Module: library/md.c
+ * Caller:
+ *
+ * Uncomment to enable generic message digest wrappers.
+ */
+#define MBEDTLS_MD_C
+
+/**
+ * \def MBEDTLS_MD2_C
+ *
+ * Enable the MD2 hash algorithm.
+ *
+ * Module: library/md2.c
+ * Caller:
+ *
+ * Uncomment to enable support for (rare) MD2-signed X.509 certs.
+ *
+ * \warning MD2 is considered a weak message digest and its use constitutes a
+ * security risk. If possible, we recommend avoiding dependencies on
+ * it, and considering stronger message digests instead.
+ *
+ */
+//#define MBEDTLS_MD2_C
+
+/**
+ * \def MBEDTLS_MD4_C
+ *
+ * Enable the MD4 hash algorithm.
+ *
+ * Module: library/md4.c
+ * Caller:
+ *
+ * Uncomment to enable support for (rare) MD4-signed X.509 certs.
+ *
+ * \warning MD4 is considered a weak message digest and its use constitutes a
+ * security risk. If possible, we recommend avoiding dependencies on
+ * it, and considering stronger message digests instead.
+ *
+ */
+//#define MBEDTLS_MD4_C
+
+/**
+ * \def MBEDTLS_MD5_C
+ *
+ * Enable the MD5 hash algorithm.
+ *
+ * Module: library/md5.c
+ * Caller: library/md.c
+ * library/pem.c
+ * library/ssl_tls.c
+ *
+ * This module is required for SSL/TLS up to version 1.1, and for TLS 1.2
+ * depending on the handshake parameters. Further, it is used for checking
+ * MD5-signed certificates, and for PBKDF1 when decrypting PEM-encoded
+ * encrypted keys.
+ *
+ * \warning MD5 is considered a weak message digest and its use constitutes a
+ * security risk. If possible, we recommend avoiding dependencies on
+ * it, and considering stronger message digests instead.
+ *
+ */
+#define MBEDTLS_MD5_C
+
+/**
+ * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
+ *
+ * Enable the buffer allocator implementation that makes use of a (stack)
+ * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
+ * calls)
+ *
+ * Module: library/memory_buffer_alloc.c
+ *
+ * Requires: MBEDTLS_PLATFORM_C
+ * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS)
+ *
+ * Enable this module to enable the buffer memory allocator.
+ */
+//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
+
+/**
+ * \def MBEDTLS_NET_C
+ *
+ * Enable the TCP and UDP over IPv6/IPv4 networking routines.
+ *
+ * \note This module only works on POSIX/Unix (including Linux, BSD and OS X)
+ * and Windows. For other platforms, you'll want to disable it, and write your
+ * own networking callbacks to be passed to \c mbedtls_ssl_set_bio().
+ *
+ * \note See also our Knowledge Base article about porting to a new
+ * environment:
+ * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
+ *
+ * Module: library/net_sockets.c
+ *
+ * This module provides networking routines.
+ */
+#define MBEDTLS_NET_C
+
+/**
+ * \def MBEDTLS_OID_C
+ *
+ * Enable the OID database.
+ *
+ * Module: library/oid.c
+ * Caller: library/asn1write.c
+ * library/pkcs5.c
+ * library/pkparse.c
+ * library/pkwrite.c
+ * library/rsa.c
+ * library/x509.c
+ * library/x509_create.c
+ * library/x509_crl.c
+ * library/x509_crt.c
+ * library/x509_csr.c
+ * library/x509write_crt.c
+ * library/x509write_csr.c
+ *
+ * This modules translates between OIDs and internal values.
+ */
+#define MBEDTLS_OID_C
+
+/**
+ * \def MBEDTLS_PADLOCK_C
+ *
+ * Enable VIA Padlock support on x86.
+ *
+ * Module: library/padlock.c
+ * Caller: library/aes.c
+ *
+ * Requires: MBEDTLS_HAVE_ASM
+ *
+ * This modules adds support for the VIA PadLock on x86.
+ */
+#define MBEDTLS_PADLOCK_C
+
+/**
+ * \def MBEDTLS_PEM_PARSE_C
+ *
+ * Enable PEM decoding / parsing.
+ *
+ * Module: library/pem.c
+ * Caller: library/dhm.c
+ * library/pkparse.c
+ * library/x509_crl.c
+ * library/x509_crt.c
+ * library/x509_csr.c
+ *
+ * Requires: MBEDTLS_BASE64_C
+ *
+ * This modules adds support for decoding / parsing PEM files.
+ */
+#define MBEDTLS_PEM_PARSE_C
+
+/**
+ * \def MBEDTLS_PEM_WRITE_C
+ *
+ * Enable PEM encoding / writing.
+ *
+ * Module: library/pem.c
+ * Caller: library/pkwrite.c
+ * library/x509write_crt.c
+ * library/x509write_csr.c
+ *
+ * Requires: MBEDTLS_BASE64_C
+ *
+ * This modules adds support for encoding / writing PEM files.
+ */
+#define MBEDTLS_PEM_WRITE_C
+
+/**
+ * \def MBEDTLS_PK_C
+ *
+ * Enable the generic public (asymetric) key layer.
+ *
+ * Module: library/pk.c
+ * Caller: library/ssl_tls.c
+ * library/ssl_cli.c
+ * library/ssl_srv.c
+ *
+ * Requires: MBEDTLS_RSA_C or MBEDTLS_ECP_C
+ *
+ * Uncomment to enable generic public key wrappers.
+ */
+#define MBEDTLS_PK_C
+
+/**
+ * \def MBEDTLS_PK_PARSE_C
+ *
+ * Enable the generic public (asymetric) key parser.
+ *
+ * Module: library/pkparse.c
+ * Caller: library/x509_crt.c
+ * library/x509_csr.c
+ *
+ * Requires: MBEDTLS_PK_C
+ *
+ * Uncomment to enable generic public key parse functions.
+ */
+#define MBEDTLS_PK_PARSE_C
+
+/**
+ * \def MBEDTLS_PK_WRITE_C
+ *
+ * Enable the generic public (asymetric) key writer.
+ *
+ * Module: library/pkwrite.c
+ * Caller: library/x509write.c
+ *
+ * Requires: MBEDTLS_PK_C
+ *
+ * Uncomment to enable generic public key write functions.
+ */
+#define MBEDTLS_PK_WRITE_C
+
+/**
+ * \def MBEDTLS_PKCS5_C
+ *
+ * Enable PKCS#5 functions.
+ *
+ * Module: library/pkcs5.c
+ *
+ * Requires: MBEDTLS_MD_C
+ *
+ * This module adds support for the PKCS#5 functions.
+ */
+#define MBEDTLS_PKCS5_C
+
+/**
+ * \def MBEDTLS_PKCS11_C
+ *
+ * Enable wrapper for PKCS#11 smartcard support.
+ *
+ * Module: library/pkcs11.c
+ * Caller: library/pk.c
+ *
+ * Requires: MBEDTLS_PK_C
+ *
+ * This module enables SSL/TLS PKCS #11 smartcard support.
+ * Requires the presence of the PKCS#11 helper library (libpkcs11-helper)
+ */
+//#define MBEDTLS_PKCS11_C
+
+/**
+ * \def MBEDTLS_PKCS12_C
+ *
+ * Enable PKCS#12 PBE functions.
+ * Adds algorithms for parsing PKCS#8 encrypted private keys
+ *
+ * Module: library/pkcs12.c
+ * Caller: library/pkparse.c
+ *
+ * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_CIPHER_C, MBEDTLS_MD_C
+ * Can use: MBEDTLS_ARC4_C
+ *
+ * This module enables PKCS#12 functions.
+ */
+#define MBEDTLS_PKCS12_C
+
+/**
+ * \def MBEDTLS_PLATFORM_C
+ *
+ * Enable the platform abstraction layer that allows you to re-assign
+ * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
+ *
+ * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
+ * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
+ * above to be specified at runtime or compile time respectively.
+ *
+ * \note This abstraction layer must be enabled on Windows (including MSYS2)
+ * as other module rely on it for a fixed snprintf implementation.
+ *
+ * Module: library/platform.c
+ * Caller: Most other .c files
+ *
+ * This module enables abstraction of common (libc) functions.
+ */
+#define MBEDTLS_PLATFORM_C
+
+/**
+ * \def MBEDTLS_RIPEMD160_C
+ *
+ * Enable the RIPEMD-160 hash algorithm.
+ *
+ * Module: library/ripemd160.c
+ * Caller: library/md.c
+ *
+ */
+#define MBEDTLS_RIPEMD160_C
+
+/**
+ * \def MBEDTLS_RSA_C
+ *
+ * Enable the RSA public-key cryptosystem.
+ *
+ * Module: library/rsa.c
+ * library/rsa_internal.c
+ * Caller: library/ssl_cli.c
+ * library/ssl_srv.c
+ * library/ssl_tls.c
+ * library/x509.c
+ *
+ * This module is used by the following key exchanges:
+ * RSA, DHE-RSA, ECDHE-RSA, RSA-PSK
+ *
+ * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C
+ */
+#define MBEDTLS_RSA_C
+
+/**
+ * \def MBEDTLS_SHA1_C
+ *
+ * Enable the SHA1 cryptographic hash algorithm.
+ *
+ * Module: library/sha1.c
+ * Caller: library/md.c
+ * library/ssl_cli.c
+ * library/ssl_srv.c
+ * library/ssl_tls.c
+ * library/x509write_crt.c
+ *
+ * This module is required for SSL/TLS up to version 1.1, for TLS 1.2
+ * depending on the handshake parameters, and for SHA1-signed certificates.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use constitutes
+ * a security risk. If possible, we recommend avoiding dependencies
+ * on it, and considering stronger message digests instead.
+ *
+ */
+#define MBEDTLS_SHA1_C
+
+/**
+ * \def MBEDTLS_SHA256_C
+ *
+ * Enable the SHA-224 and SHA-256 cryptographic hash algorithms.
+ *
+ * Module: library/sha256.c
+ * Caller: library/entropy.c
+ * library/md.c
+ * library/ssl_cli.c
+ * library/ssl_srv.c
+ * library/ssl_tls.c
+ *
+ * This module adds support for SHA-224 and SHA-256.
+ * This module is required for the SSL/TLS 1.2 PRF function.
+ */
+#define MBEDTLS_SHA256_C
+
+/**
+ * \def MBEDTLS_SHA512_C
+ *
+ * Enable the SHA-384 and SHA-512 cryptographic hash algorithms.
+ *
+ * Module: library/sha512.c
+ * Caller: library/entropy.c
+ * library/md.c
+ * library/ssl_cli.c
+ * library/ssl_srv.c
+ *
+ * This module adds support for SHA-384 and SHA-512.
+ */
+#define MBEDTLS_SHA512_C
+
+/**
+ * \def MBEDTLS_SSL_CACHE_C
+ *
+ * Enable simple SSL cache implementation.
+ *
+ * Module: library/ssl_cache.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_SSL_CACHE_C
+ */
+#define MBEDTLS_SSL_CACHE_C
+
+/**
+ * \def MBEDTLS_SSL_COOKIE_C
+ *
+ * Enable basic implementation of DTLS cookies for hello verification.
+ *
+ * Module: library/ssl_cookie.c
+ * Caller:
+ */
+#define MBEDTLS_SSL_COOKIE_C
+
+/**
+ * \def MBEDTLS_SSL_TICKET_C
+ *
+ * Enable an implementation of TLS server-side callbacks for session tickets.
+ *
+ * Module: library/ssl_ticket.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_CIPHER_C
+ */
+#define MBEDTLS_SSL_TICKET_C
+
+/**
+ * \def MBEDTLS_SSL_CLI_C
+ *
+ * Enable the SSL/TLS client code.
+ *
+ * Module: library/ssl_cli.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_SSL_TLS_C
+ *
+ * This module is required for SSL/TLS client support.
+ */
+#define MBEDTLS_SSL_CLI_C
+
+/**
+ * \def MBEDTLS_SSL_SRV_C
+ *
+ * Enable the SSL/TLS server code.
+ *
+ * Module: library/ssl_srv.c
+ * Caller:
+ *
+ * Requires: MBEDTLS_SSL_TLS_C
+ *
+ * This module is required for SSL/TLS server support.
+ */
+#define MBEDTLS_SSL_SRV_C
+
+/**
+ * \def MBEDTLS_SSL_TLS_C
+ *
+ * Enable the generic SSL/TLS code.
+ *
+ * Module: library/ssl_tls.c
+ * Caller: library/ssl_cli.c
+ * library/ssl_srv.c
+ *
+ * Requires: MBEDTLS_CIPHER_C, MBEDTLS_MD_C
+ * and at least one of the MBEDTLS_SSL_PROTO_XXX defines
+ *
+ * This module is required for SSL/TLS.
+ */
+#define MBEDTLS_SSL_TLS_C
+
+/**
+ * \def MBEDTLS_THREADING_C
+ *
+ * Enable the threading abstraction layer.
+ * By default mbed TLS assumes it is used in a non-threaded environment or that
+ * contexts are not shared between threads. If you do intend to use contexts
+ * between threads, you will need to enable this layer to prevent race
+ * conditions. See also our Knowledge Base article about threading:
+ * https://tls.mbed.org/kb/development/thread-safety-and-multi-threading
+ *
+ * Module: library/threading.c
+ *
+ * This allows different threading implementations (self-implemented or
+ * provided).
+ *
+ * You will have to enable either MBEDTLS_THREADING_ALT or
+ * MBEDTLS_THREADING_PTHREAD.
+ *
+ * Enable this layer to allow use of mutexes within mbed TLS
+ */
+//#define MBEDTLS_THREADING_C
+
+/**
+ * \def MBEDTLS_TIMING_C
+ *
+ * Enable the semi-portable timing interface.
+ *
+ * \note The provided implementation only works on POSIX/Unix (including Linux,
+ * BSD and OS X) and Windows. On other platforms, you can either disable that
+ * module and provide your own implementations of the callbacks needed by
+ * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide
+ * your own implementation of the whole module by setting
+ * \c MBEDTLS_TIMING_ALT in the current file.
+ *
+ * \note See also our Knowledge Base article about porting to a new
+ * environment:
+ * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
+ *
+ * Module: library/timing.c
+ * Caller: library/havege.c
+ *
+ * This module is used by the HAVEGE random number generator.
+ */
+#define MBEDTLS_TIMING_C
+
+/**
+ * \def MBEDTLS_VERSION_C
+ *
+ * Enable run-time version information.
+ *
+ * Module: library/version.c
+ *
+ * This module provides run-time version information.
+ */
+#define MBEDTLS_VERSION_C
+
+/**
+ * \def MBEDTLS_X509_USE_C
+ *
+ * Enable X.509 core for using certificates.
+ *
+ * Module: library/x509.c
+ * Caller: library/x509_crl.c
+ * library/x509_crt.c
+ * library/x509_csr.c
+ *
+ * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C,
+ * MBEDTLS_PK_PARSE_C
+ *
+ * This module is required for the X.509 parsing modules.
+ */
+#define MBEDTLS_X509_USE_C
+
+/**
+ * \def MBEDTLS_X509_CRT_PARSE_C
+ *
+ * Enable X.509 certificate parsing.
+ *
+ * Module: library/x509_crt.c
+ * Caller: library/ssl_cli.c
+ * library/ssl_srv.c
+ * library/ssl_tls.c
+ *
+ * Requires: MBEDTLS_X509_USE_C
+ *
+ * This module is required for X.509 certificate parsing.
+ */
+#define MBEDTLS_X509_CRT_PARSE_C
+
+/**
+ * \def MBEDTLS_X509_CRL_PARSE_C
+ *
+ * Enable X.509 CRL parsing.
+ *
+ * Module: library/x509_crl.c
+ * Caller: library/x509_crt.c
+ *
+ * Requires: MBEDTLS_X509_USE_C
+ *
+ * This module is required for X.509 CRL parsing.
+ */
+#define MBEDTLS_X509_CRL_PARSE_C
+
+/**
+ * \def MBEDTLS_X509_CSR_PARSE_C
+ *
+ * Enable X.509 Certificate Signing Request (CSR) parsing.
+ *
+ * Module: library/x509_csr.c
+ * Caller: library/x509_crt_write.c
+ *
+ * Requires: MBEDTLS_X509_USE_C
+ *
+ * This module is used for reading X.509 certificate request.
+ */
+#define MBEDTLS_X509_CSR_PARSE_C
+
+/**
+ * \def MBEDTLS_X509_CREATE_C
+ *
+ * Enable X.509 core for creating certificates.
+ *
+ * Module: library/x509_create.c
+ *
+ * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C
+ *
+ * This module is the basis for creating X.509 certificates and CSRs.
+ */
+#define MBEDTLS_X509_CREATE_C
+
+/**
+ * \def MBEDTLS_X509_CRT_WRITE_C
+ *
+ * Enable creating X.509 certificates.
+ *
+ * Module: library/x509_crt_write.c
+ *
+ * Requires: MBEDTLS_X509_CREATE_C
+ *
+ * This module is required for X.509 certificate creation.
+ */
+#define MBEDTLS_X509_CRT_WRITE_C
+
+/**
+ * \def MBEDTLS_X509_CSR_WRITE_C
+ *
+ * Enable creating X.509 Certificate Signing Requests (CSR).
+ *
+ * Module: library/x509_csr_write.c
+ *
+ * Requires: MBEDTLS_X509_CREATE_C
+ *
+ * This module is required for X.509 certificate request writing.
+ */
+#define MBEDTLS_X509_CSR_WRITE_C
+
+/**
+ * \def MBEDTLS_XTEA_C
+ *
+ * Enable the XTEA block cipher.
+ *
+ * Module: library/xtea.c
+ * Caller:
+ */
+#define MBEDTLS_XTEA_C
+
+/* \} name SECTION: mbed TLS modules */
+
+/**
+ * \name SECTION: Module configuration options
+ *
+ * This section allows for the setting of module specific sizes and
+ * configuration options. The default values are already present in the
+ * relevant header files and should suffice for the regular use cases.
+ *
+ * Our advice is to enable options and change their values here
+ * only if you have a good reason and know the consequences.
+ *
+ * Please check the respective header file for documentation on these
+ * parameters (to prevent duplicate documentation).
+ * \{
+ */
+
+/* MPI / BIGNUM options */
+//#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */
+//#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
+
+/* CTR_DRBG options */
+//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */
+//#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
+//#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
+//#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
+//#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
+
+/* HMAC_DRBG options */
+//#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
+//#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
+//#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
+//#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
+
+/* ECP options */
+//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
+//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
+//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
+
+/* Entropy options */
+//#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
+//#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
+//#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Default minimum number of bytes required for the hardware entropy source mbedtls_hardware_poll() before entropy is released */
+
+/* Memory buffer allocator options */
+//#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
+
+/* Platform options */
+//#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
+//#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
+//#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
+/* Note: your snprintf must correclty zero-terminate the buffer! */
+//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
+//#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to read/write with default implementation */
+
+/* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */
+/* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */
+//#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, can be undefined */
+//#define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
+//#define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
+//#define MBEDTLS_PLATFORM_TIME_MACRO time /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
+//#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
+//#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
+//#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
+/* Note: your snprintf must correclty zero-terminate the buffer! */
+//#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
+//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
+//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
+
+/* SSL Cache options */
+//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */
+//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */
+
+/* SSL options */
+//#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Maxium fragment length in bytes, determines the size of each of the two internal I/O buffers */
+//#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
+//#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */
+//#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
+
+/**
+ * Complete list of ciphersuites to use, in order of preference.
+ *
+ * \warning No dependency checking is done on that field! This option can only
+ * be used to restrict the set of available ciphersuites. It is your
+ * responsibility to make sure the needed modules are active.
+ *
+ * Use this to save a few hundred bytes of ROM (default ordering of all
+ * available ciphersuites) and a few to a few hundred bytes of RAM.
+ *
+ * The value below is only an example, not the default.
+ */
+//#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
+
+/* X509 options */
+//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */
+//#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */
+
+/**
+ * Allow SHA-1 in the default TLS configuration for certificate signing.
+ * Without this build-time option, SHA-1 support must be activated explicitly
+ * through mbedtls_ssl_conf_cert_profile. Turning on this option is not
+ * recommended because of it is possible to generate SHA-1 collisions, however
+ * this may be safe for legacy infrastructure where additional controls apply.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use constitutes
+ * a security risk. If possible, we recommend avoiding dependencies
+ * on it, and considering stronger message digests instead.
+ *
+ */
+// #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
+
+/**
+ * Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake
+ * signature and ciphersuite selection. Without this build-time option, SHA-1
+ * support must be activated explicitly through mbedtls_ssl_conf_sig_hashes.
+ * The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by
+ * default. At the time of writing, there is no practical attack on the use
+ * of SHA-1 in handshake signatures, hence this option is turned on by default
+ * to preserve compatibility with existing peers, but the general
+ * warning applies nonetheless:
+ *
+ * \warning SHA-1 is considered a weak message digest and its use constitutes
+ * a security risk. If possible, we recommend avoiding dependencies
+ * on it, and considering stronger message digests instead.
+ *
+ */
+#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE
+
+/* \} name SECTION: Customisation configuration options */
+
+/* Target and application specific configurations */
+//#define YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE "mbedtls/target_config.h"
+
+#if defined(TARGET_LIKE_MBED) && defined(YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE)
+#include YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE
+#endif
+
+/*
+ * Allow user to override any previous default.
+ *
+ * Use two macro names for that, as:
+ * - with yotta the prefix YOTTA_CFG_ is forced
+ * - without yotta is looks weird to have a YOTTA prefix.
+ */
+#if defined(YOTTA_CFG_MBEDTLS_USER_CONFIG_FILE)
+#include YOTTA_CFG_MBEDTLS_USER_CONFIG_FILE
+#elif defined(MBEDTLS_USER_CONFIG_FILE)
+#include MBEDTLS_USER_CONFIG_FILE
+#endif
+
+
+
+#endif /* MBEDTLS_CONFIG_H */
+
+
+
+
+#endif //lijiayong
+
+
+/********* Start of file include/mbedtls/check_config.h ************/
+
+/**
+ * \file check_config.h
+ *
+ * \brief Consistency checks for configuration options
+ */
+/*
+ * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+/*
+ * It is recommended to include this file from your config.h
+ * in order to catch dependency issues early.
+ */
+
+#ifndef MBEDTLS_CHECK_CONFIG_H
+#define MBEDTLS_CHECK_CONFIG_H
+
+/*
+ * We assume CHAR_BIT is 8 in many places. In practice, this is true on our
+ * target platforms, so not an issue, but let's just be extra sure.
+ */
+#include
+#if CHAR_BIT != 8
+#error "mbed TLS requires a platform with 8-bit chars"
+#endif
+
+#if defined(_WIN32)
+#if !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_C is required on Windows"
+#endif
+
+/* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
+ * it would confuse config.pl. */
+#if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
+ !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
+#define MBEDTLS_PLATFORM_SNPRINTF_ALT
+#endif
+#endif /* _WIN32 */
+
+#if defined(TARGET_LIKE_MBED) && \
+ ( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
+#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
+#endif
+
+#if defined(MBEDTLS_DEPRECATED_WARNING) && \
+ !defined(__GNUC__) && !defined(__clang__)
+#error "MBEDTLS_DEPRECATED_WARNING only works with GCC and Clang"
+#endif
+
+#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_HAVE_TIME)
+#error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense"
+#endif
+
+#if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM)
+#error "MBEDTLS_AESNI_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C)
+#error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_DHM_C) && !defined(MBEDTLS_BIGNUM_C)
+#error "MBEDTLS_DHM_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT) && !defined(MBEDTLS_SSL_TRUNCATED_HMAC)
+#error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_CMAC_C) && \
+ !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
+#error "MBEDTLS_CMAC_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
+#error "MBEDTLS_ECDH_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECDSA_C) && \
+ ( !defined(MBEDTLS_ECP_C) || \
+ !defined(MBEDTLS_ASN1_PARSE_C) || \
+ !defined(MBEDTLS_ASN1_WRITE_C) )
+#error "MBEDTLS_ECDSA_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECJPAKE_C) && \
+ ( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) )
+#error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
+#error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_C) && ( !defined(MBEDTLS_BIGNUM_C) || ( \
+ !defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) && \
+ !defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) ) )
+#error "MBEDTLS_ECP_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \
+ !defined(MBEDTLS_SHA256_C))
+#error "MBEDTLS_ENTROPY_C defined, but not all prerequisites"
+#endif
+#if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && \
+ defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64)
+#error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
+#endif
+#if defined(MBEDTLS_ENTROPY_C) && \
+ ( !defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256) ) \
+ && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32)
+#error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
+#endif
+#if defined(MBEDTLS_ENTROPY_C) && \
+ defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C)
+#error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
+ ( !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) )
+#error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites"
+#endif
+#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
+ ( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
+ defined(MBEDTLS_HAVEGE_C) )
+#error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too"
+#endif
+
+#if defined(MBEDTLS_GCM_C) && ( \
+ !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) )
+#error "MBEDTLS_GCM_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_ADD_MIXED_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_DOUBLE_JAC_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_NORMALIZE_JAC_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
+#error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
+#error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C)
+#error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \
+ ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
+#error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
+ ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
+#error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) && !defined(MBEDTLS_DHM_C)
+#error "MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \
+ !defined(MBEDTLS_ECDH_C)
+#error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
+ ( !defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || \
+ !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
+#error "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
+ ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \
+ !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
+#error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \
+ ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \
+ !defined(MBEDTLS_X509_CRT_PARSE_C) )
+#error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && \
+ ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
+ !defined(MBEDTLS_PKCS1_V15) )
+#error "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
+ ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
+ !defined(MBEDTLS_PKCS1_V15) )
+#error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
+ ( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \
+ !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) )
+#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
+ ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
+#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
+#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PEM_PARSE_C) && !defined(MBEDTLS_BASE64_C)
+#error "MBEDTLS_PEM_PARSE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PEM_WRITE_C) && !defined(MBEDTLS_BASE64_C)
+#error "MBEDTLS_PEM_WRITE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PK_C) && \
+ ( !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C) )
+#error "MBEDTLS_PK_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_PK_C)
+#error "MBEDTLS_PK_PARSE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PK_WRITE_C) && !defined(MBEDTLS_PK_C)
+#error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PKCS11_C) && !defined(MBEDTLS_PK_C)
+#error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_EXIT) ||\
+ defined(MBEDTLS_PLATFORM_EXIT_ALT) )
+#error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\
+ ( !defined(MBEDTLS_PLATFORM_C) ||\
+ !defined(MBEDTLS_HAVE_TIME) )
+#error "MBEDTLS_PLATFORM_TIME_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
+ ( !defined(MBEDTLS_PLATFORM_C) ||\
+ !defined(MBEDTLS_HAVE_TIME) )
+#error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
+ ( !defined(MBEDTLS_PLATFORM_C) ||\
+ !defined(MBEDTLS_HAVE_TIME) )
+#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
+ defined(MBEDTLS_PLATFORM_TIME_ALT) )
+#error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
+ defined(MBEDTLS_PLATFORM_TIME_ALT) )
+#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_FPRINTF) ||\
+ defined(MBEDTLS_PLATFORM_FPRINTF_ALT) )
+#error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
+ ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
+#error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
+ defined(MBEDTLS_PLATFORM_STD_FREE)
+#error "MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_STD_FREE cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && !defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
+#error "MBEDTLS_PLATFORM_CALLOC_MACRO must be defined if MBEDTLS_PLATFORM_FREE_MACRO is"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
+ ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
+#error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
+ defined(MBEDTLS_PLATFORM_STD_CALLOC)
+#error "MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_STD_CALLOC cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && !defined(MBEDTLS_PLATFORM_FREE_MACRO)
+#error "MBEDTLS_PLATFORM_FREE_MACRO must be defined if MBEDTLS_PLATFORM_CALLOC_MACRO is"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_MEMORY) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_MEMORY defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_PRINTF) ||\
+ defined(MBEDTLS_PLATFORM_PRINTF_ALT) )
+#error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
+#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_SNPRINTF) ||\
+ defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) )
+#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
+ !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
+#error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
+#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
+#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
+#error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_EXIT) &&\
+ !defined(MBEDTLS_PLATFORM_EXIT_ALT)
+#error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_TIME) &&\
+ ( !defined(MBEDTLS_PLATFORM_TIME_ALT) ||\
+ !defined(MBEDTLS_HAVE_TIME) )
+#error "MBEDTLS_PLATFORM_STD_TIME defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
+ !defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
+#error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_PRINTF) &&\
+ !defined(MBEDTLS_PLATFORM_PRINTF_ALT)
+#error "MBEDTLS_PLATFORM_STD_PRINTF defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_SNPRINTF) &&\
+ !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
+#error "MBEDTLS_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_ENTROPY_NV_SEED) &&\
+ ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_ENTROPY_C) )
+#error "MBEDTLS_ENTROPY_NV_SEED defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) &&\
+ !defined(MBEDTLS_ENTROPY_NV_SEED)
+#error "MBEDTLS_PLATFORM_NV_SEED_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) &&\
+ !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
+#error "MBEDTLS_PLATFORM_STD_NV_SEED_READ defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) &&\
+ !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
+#error "MBEDTLS_PLATFORM_STD_NV_SEED_WRITE defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) ||\
+ defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
+#error "MBEDTLS_PLATFORM_NV_SEED_READ_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_READ cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) &&\
+ ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) ||\
+ defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
+#error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
+#endif
+
+#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
+ !defined(MBEDTLS_OID_C) )
+#error "MBEDTLS_RSA_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_PKCS1_V21) && \
+ !defined(MBEDTLS_PKCS1_V15) )
+#error "MBEDTLS_RSA_C defined, but none of the PKCS1 versions enabled"
+#endif
+
+#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) && \
+ ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_PKCS1_V21) )
+#error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \
+ !defined(MBEDTLS_SHA1_C) )
+#error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1) && ( !defined(MBEDTLS_MD5_C) || \
+ !defined(MBEDTLS_SHA1_C) )
+#error "MBEDTLS_SSL_PROTO_TLS1 defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1_1) && ( !defined(MBEDTLS_MD5_C) || \
+ !defined(MBEDTLS_SHA1_C) )
+#error "MBEDTLS_SSL_PROTO_TLS1_1 defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && ( !defined(MBEDTLS_SHA1_C) && \
+ !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) )
+#error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_PROTO_DTLS) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_CLI_C) && !defined(MBEDTLS_SSL_TLS_C)
+#error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \
+ !defined(MBEDTLS_MD_C) )
+#error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_SRV_C) && !defined(MBEDTLS_SSL_TLS_C)
+#error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_SSL3) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_2))
+#error "MBEDTLS_SSL_TLS_C defined, but no protocols are active"
+#endif
+
+#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
+ defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
+#error "Illegal protocol selection"
+#endif
+
+#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && \
+ defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1))
+#error "Illegal protocol selection"
+#endif
+
+#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
+ defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SSL_PROTO_TLS1) || \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_1)))
+#error "Illegal protocol selection"
+#endif
+
+#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && !defined(MBEDTLS_SSL_PROTO_DTLS)
+#error "MBEDTLS_SSL_DTLS_HELLO_VERIFY defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE) && \
+ !defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
+#error "MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) && \
+ ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
+#error "MBEDTLS_SSL_DTLS_ANTI_REPLAY defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) && \
+ ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
+#error "MBEDTLS_SSL_DTLS_BADMAC_LIMIT defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites"
+#endif
+
+#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
+ !defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites"
+#endif
+
+#if defined(MBEDTLS_SSL_TICKET_C) && !defined(MBEDTLS_CIPHER_C)
+#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && \
+ !defined(MBEDTLS_SSL_PROTO_SSL3) && !defined(MBEDTLS_SSL_PROTO_TLS1)
+#error "MBEDTLS_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
+ !defined(MBEDTLS_X509_CRT_PARSE_C)
+#error "MBEDTLS_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_THREADING_PTHREAD)
+#if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
+#error "MBEDTLS_THREADING_PTHREAD defined, but not all prerequisites"
+#endif
+#define MBEDTLS_THREADING_IMPL
+#endif
+
+#if defined(MBEDTLS_THREADING_ALT)
+#if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
+#error "MBEDTLS_THREADING_ALT defined, but not all prerequisites"
+#endif
+#define MBEDTLS_THREADING_IMPL
+#endif
+
+#if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_IMPL)
+#error "MBEDTLS_THREADING_C defined, single threading implementation required"
+#endif
+#undef MBEDTLS_THREADING_IMPL
+
+#if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
+#error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
+ !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \
+ !defined(MBEDTLS_PK_PARSE_C) )
+#error "MBEDTLS_X509_USE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_CREATE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
+ !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \
+ !defined(MBEDTLS_PK_WRITE_C) )
+#error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
+#error "MBEDTLS_X509_CRT_PARSE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_CRL_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
+#error "MBEDTLS_X509_CRL_PARSE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_CSR_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
+#error "MBEDTLS_X509_CSR_PARSE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_CRT_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
+#error "MBEDTLS_X509_CRT_WRITE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_X509_CSR_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
+#error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites"
+#endif
+
+#if defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)
+#error "MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 cannot be defined simultaneously"
+#endif /* MBEDTLS_HAVE_INT32 && MBEDTLS_HAVE_INT64 */
+
+#if ( defined(MBEDTLS_HAVE_INT32) || defined(MBEDTLS_HAVE_INT64) ) && \
+ defined(MBEDTLS_HAVE_ASM)
+#error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously"
+#endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */
+
+/*
+ * Avoid warning from -pedantic. This is a convenient place for this
+ * workaround since this is included by every single file before the
+ * #if defined(MBEDTLS_xxx_C) that results in emtpy translation units.
+ */
+typedef int mbedtls_iso_c_forbids_empty_translation_units;
+
+#endif /* MBEDTLS_CHECK_CONFIG_H */
+
+
+/********* Start of file include/mbedtls/platform.h ************/
+
+/**
+ * \file platform.h
+ *
+ * \brief The Mbed TLS platform abstraction layer.
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PLATFORM_H
+#define MBEDTLS_PLATFORM_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#if defined(MBEDTLS_HAVE_TIME)
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
+#include
+#include
+#include
+#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
+#if defined(_WIN32)
+#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */
+#else
+#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */
+#endif
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
+#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
+#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
+#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_FREE)
+#define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
+#define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_TIME)
+#define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
+#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
+#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */
+#endif
+#if defined(MBEDTLS_FS_IO)
+#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
+#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
+#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
+#endif
+#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
+#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
+#endif
+#endif /* MBEDTLS_FS_IO */
+#else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
+#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
+#include MBEDTLS_PLATFORM_STD_MEM_HDR
+#endif
+#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
+
+
+/* \} name SECTION: Module settings */
+
+/*
+ * The function pointers for calloc and free
+ */
+#if defined(MBEDTLS_PLATFORM_MEMORY)
+#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
+ defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
+#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
+#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
+#else
+/* For size_t */
+#include
+extern void * (*mbedtls_calloc)( size_t n, size_t size );
+extern void (*mbedtls_free)( void *ptr );
+
+/**
+ * \brief This function allows configuring custom memory-management functions.
+ *
+ * \param calloc_func The \c calloc function implementation.
+ * \param free_func The \c free function implementation.
+ *
+ * \return \c 0.
+ */
+int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
+ void (*free_func)( void * ) );
+#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
+#else /* !MBEDTLS_PLATFORM_MEMORY */
+#define mbedtls_free free
+#define mbedtls_calloc calloc
+#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
+
+/*
+ * The function pointers for fprintf
+ */
+#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
+/* We need FILE * */
+#include
+extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
+
+/**
+ * \brief This function allows configuring a custom \p fprintf function pointer.
+ *
+ * \param fprintf_func The \c fprintf function implementation.
+ *
+ * \return \c 0.
+ */
+int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
+ ... ) );
+#else
+#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
+#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
+#else
+#define mbedtls_fprintf fprintf
+#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
+#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
+
+/*
+ * The function pointers for printf
+ */
+#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
+extern int (*mbedtls_printf)( const char *format, ... );
+
+/**
+ * \brief This function allows configuring a custom \c printf function
+ * pointer.
+ *
+ * \param printf_func The \c printf function implementation.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
+#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
+#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
+#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
+#else
+#define mbedtls_printf printf
+#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
+#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
+
+/*
+ * The function pointers for snprintf
+ *
+ * The snprintf implementation should conform to C99:
+ * - it *must* always correctly zero-terminate the buffer
+ * (except when n == 0, then it must leave the buffer untouched)
+ * - however it is acceptable to return -1 instead of the required length when
+ * the destination buffer is too short.
+ */
+#if defined(_WIN32)
+/* For Windows (inc. MSYS2), we provide our own fixed implementation */
+int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
+#endif
+
+#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
+extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
+
+/**
+ * \brief This function allows configuring a custom \c snprintf function
+ * pointer.
+ *
+ * \param snprintf_func The \c snprintf function implementation.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
+ const char * format, ... ) );
+#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
+#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
+#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
+#else
+#define mbedtls_snprintf snprintf
+#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
+#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
+
+/*
+ * The function pointers for exit
+ */
+#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
+extern void (*mbedtls_exit)( int status );
+
+/**
+ * \brief This function allows configuring a custom \c exit function
+ * pointer.
+ *
+ * \param exit_func The \c exit function implementation.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
+#else
+#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
+#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
+#else
+#define mbedtls_exit exit
+#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
+#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
+
+/*
+ * The default exit values
+ */
+#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
+#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
+#else
+#define MBEDTLS_EXIT_SUCCESS 0
+#endif
+#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
+#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
+#else
+#define MBEDTLS_EXIT_FAILURE 1
+#endif
+
+/*
+ * The function pointers for reading from and writing a seed file to
+ * Non-Volatile storage (NV) in a platform-independent way
+ *
+ * Only enabled when the NV seed entropy source is enabled
+ */
+#if defined(MBEDTLS_ENTROPY_NV_SEED)
+#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
+/* Internal standard platform definitions */
+int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
+int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
+#endif
+
+#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
+extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
+extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
+
+/**
+ * \brief This function allows configuring custom seed file writing and
+ * reading functions.
+ *
+ * \param nv_seed_read_func The seed reading function implementation.
+ * \param nv_seed_write_func The seed writing function implementation.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_platform_set_nv_seed(
+ int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
+ int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
+ );
+#else
+#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
+ defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
+#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
+#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
+#else
+#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
+#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
+#endif
+#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
+#endif /* MBEDTLS_ENTROPY_NV_SEED */
+
+#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
+
+/**
+ * \brief The platform context structure.
+ *
+ * \note This structure may be used to assist platform-specific
+ * setup or teardown operations.
+ */
+typedef struct {
+ char dummy; /**< Placeholder member, as empty structs are not portable. */
+}
+mbedtls_platform_context;
+
+#else
+
+#endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
+
+/**
+ * \brief This function performs any platform initialization operations.
+ *
+ * \param ctx The Mbed TLS context.
+ *
+ * \return \c 0 on success.
+ *
+ * \note This function is intended to allow platform-specific initialization,
+ * and should be called before any other library functions. Its
+ * implementation is platform-specific, and unless
+ * platform-specific code is provided, it does nothing.
+ *
+ * Its use and whether it is necessary to call it is dependent on the
+ * platform.
+ */
+int mbedtls_platform_setup( mbedtls_platform_context *ctx );
+/**
+ * \brief This function performs any platform teardown operations.
+ *
+ * \param ctx The Mbed TLS context.
+ *
+ * \note This function should be called after every other Mbed TLS module
+ * has been correctly freed using the appropriate free function.
+ * Its implementation is platform-specific, and unless
+ * platform-specific code is provided, it does nothing.
+ *
+ * Its use and whether it is necessary to call it is dependent on the
+ * platform.
+ */
+void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* platform.h */
+
+
+/********* Start of file include/mbedtls/platform_time.h ************/
+
+/**
+ * \file platform_time.h
+ *
+ * \brief mbed TLS Platform time abstraction
+ */
+/*
+ * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PLATFORM_TIME_H
+#define MBEDTLS_PLATFORM_TIME_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+/*
+ * The time_t datatype
+ */
+#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
+typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
+#else
+/* For time_t */
+#include
+typedef time_t mbedtls_time_t;
+#endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
+
+/*
+ * The function pointers for time
+ */
+#if defined(MBEDTLS_PLATFORM_TIME_ALT)
+extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time );
+
+/**
+ * \brief Set your own time function pointer
+ *
+ * \param time_func the time function implementation
+ *
+ * \return 0
+ */
+int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) );
+#else
+#if defined(MBEDTLS_PLATFORM_TIME_MACRO)
+#define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO
+#else
+#define mbedtls_time time
+#endif /* MBEDTLS_PLATFORM_TIME_MACRO */
+#endif /* MBEDTLS_PLATFORM_TIME_ALT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* platform_time.h */
+
+
+/********* Start of file include/mbedtls/threading.h ************/
+
+/**
+ * \file threading.h
+ *
+ * \brief Threading abstraction layer
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_THREADING_H
+#define MBEDTLS_THREADING_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */
+#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */
+
+#if defined(MBEDTLS_THREADING_PTHREAD)
+#include
+typedef struct
+{
+ pthread_mutex_t mutex;
+ char is_valid;
+} mbedtls_threading_mutex_t;
+#endif
+
+#if defined(MBEDTLS_THREADING_ALT)
+/* You should define the mbedtls_threading_mutex_t type in your header */
+
+
+/**
+ * \brief Set your alternate threading implementation function
+ * pointers and initialize global mutexes. If used, this
+ * function must be called once in the main thread before any
+ * other mbed TLS function is called, and
+ * mbedtls_threading_free_alt() must be called once in the main
+ * thread after all other mbed TLS functions.
+ *
+ * \note mutex_init() and mutex_free() don't return a status code.
+ * If mutex_init() fails, it should leave its argument (the
+ * mutex) in a state such that mutex_lock() will fail when
+ * called with this argument.
+ *
+ * \param mutex_init the init function implementation
+ * \param mutex_free the free function implementation
+ * \param mutex_lock the lock function implementation
+ * \param mutex_unlock the unlock function implementation
+ */
+void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
+ void (*mutex_free)( mbedtls_threading_mutex_t * ),
+ int (*mutex_lock)( mbedtls_threading_mutex_t * ),
+ int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
+
+/**
+ * \brief Free global mutexes.
+ */
+void mbedtls_threading_free_alt( void );
+#endif /* MBEDTLS_THREADING_ALT */
+
+#if defined(MBEDTLS_THREADING_C)
+/*
+ * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
+ *
+ * All these functions are expected to work or the result will be undefined.
+ */
+extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
+extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
+extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
+extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
+
+/*
+ * Global mutexes
+ */
+extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
+extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
+#endif /* MBEDTLS_THREADING_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* threading.h */
+
+
+/********* Start of file include/mbedtls/bignum.h ************/
+
+/**
+ * \file bignum.h
+ *
+ * \brief Multi-precision integer library
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_BIGNUM_H
+#define MBEDTLS_BIGNUM_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#if defined(MBEDTLS_FS_IO)
+#include
+#endif
+
+#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */
+#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */
+#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The buffer is too small to write to. */
+#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */
+#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */
+#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */
+#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */
+
+#define MBEDTLS_MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 )
+
+/*
+ * Maximum size MPIs are allowed to grow to in number of limbs.
+ */
+#define MBEDTLS_MPI_MAX_LIMBS 10000
+
+#if !defined(MBEDTLS_MPI_WINDOW_SIZE)
+/*
+ * Maximum window size used for modular exponentiation. Default: 6
+ * Minimum value: 1. Maximum value: 6.
+ *
+ * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used
+ * for the sliding window calculation. (So 64 by default)
+ *
+ * Reduction in size, reduces speed.
+ */
+#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */
+#endif /* !MBEDTLS_MPI_WINDOW_SIZE */
+
+#if !defined(MBEDTLS_MPI_MAX_SIZE)
+/*
+ * Maximum size of MPIs allowed in bits and bytes for user-MPIs.
+ * ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits )
+ *
+ * Note: Calculations can temporarily result in larger MPIs. So the number
+ * of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher.
+ */
+#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
+#endif /* !MBEDTLS_MPI_MAX_SIZE */
+
+#define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */
+
+/*
+ * When reading from files with mbedtls_mpi_read_file() and writing to files with
+ * mbedtls_mpi_write_file() the buffer should have space
+ * for a (short) label, the MPI (in the provided radix), the newline
+ * characters and the '\0'.
+ *
+ * By default we assume at least a 10 char label, a minimum radix of 10
+ * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars).
+ * Autosized at compile time for at least a 10 char label, a minimum radix
+ * of 10 (decimal) for a number of MBEDTLS_MPI_MAX_BITS size.
+ *
+ * This used to be statically sized to 1250 for a maximum of 4096 bit
+ * numbers (1234 decimal chars).
+ *
+ * Calculate using the formula:
+ * MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) +
+ * LabelSize + 6
+ */
+#define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS )
+#define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332
+#define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 )
+
+/*
+ * Define the base integer type, architecture-wise.
+ *
+ * 32 or 64-bit integer types can be forced regardless of the underlying
+ * architecture by defining MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64
+ * respectively and undefining MBEDTLS_HAVE_ASM.
+ *
+ * Double-width integers (e.g. 128-bit in 64-bit architectures) can be
+ * disabled by defining MBEDTLS_NO_UDBL_DIVISION.
+ */
+#if !defined(MBEDTLS_HAVE_INT32)
+ #if defined(_MSC_VER) && defined(_M_AMD64)
+ /* Always choose 64-bit when using MSC */
+ #if !defined(MBEDTLS_HAVE_INT64)
+ #define MBEDTLS_HAVE_INT64
+ #endif /* !MBEDTLS_HAVE_INT64 */
+ typedef int64_t mbedtls_mpi_sint;
+ typedef uint64_t mbedtls_mpi_uint;
+ #elif defined(__GNUC__) && ( \
+ defined(__amd64__) || defined(__x86_64__) || \
+ defined(__ppc64__) || defined(__powerpc64__) || \
+ defined(__ia64__) || defined(__alpha__) || \
+ ( defined(__sparc__) && defined(__arch64__) ) || \
+ defined(__s390x__) || defined(__mips64) )
+ #if !defined(MBEDTLS_HAVE_INT64)
+ #define MBEDTLS_HAVE_INT64
+ #endif /* MBEDTLS_HAVE_INT64 */
+ typedef int64_t mbedtls_mpi_sint;
+ typedef uint64_t mbedtls_mpi_uint;
+ #if !defined(MBEDTLS_NO_UDBL_DIVISION)
+ /* mbedtls_t_udbl defined as 128-bit unsigned int */
+ typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
+ #define MBEDTLS_HAVE_UDBL
+ #endif /* !MBEDTLS_NO_UDBL_DIVISION */
+ #elif defined(__ARMCC_VERSION) && defined(__aarch64__)
+ /*
+ * __ARMCC_VERSION is defined for both armcc and armclang and
+ * __aarch64__ is only defined by armclang when compiling 64-bit code
+ */
+ #if !defined(MBEDTLS_HAVE_INT64)
+ #define MBEDTLS_HAVE_INT64
+ #endif /* !MBEDTLS_HAVE_INT64 */
+ typedef int64_t mbedtls_mpi_sint;
+ typedef uint64_t mbedtls_mpi_uint;
+ #if !defined(MBEDTLS_NO_UDBL_DIVISION)
+ /* mbedtls_t_udbl defined as 128-bit unsigned int */
+ typedef __uint128_t mbedtls_t_udbl;
+ #define MBEDTLS_HAVE_UDBL
+ #endif /* !MBEDTLS_NO_UDBL_DIVISION */
+ #elif defined(MBEDTLS_HAVE_INT64)
+ /* Force 64-bit integers with unknown compiler */
+ typedef int64_t mbedtls_mpi_sint;
+ typedef uint64_t mbedtls_mpi_uint;
+ #endif
+#endif /* !MBEDTLS_HAVE_INT32 */
+
+#if !defined(MBEDTLS_HAVE_INT64)
+ /* Default to 32-bit compilation */
+ #if !defined(MBEDTLS_HAVE_INT32)
+ #define MBEDTLS_HAVE_INT32
+ #endif /* !MBEDTLS_HAVE_INT32 */
+ typedef int32_t mbedtls_mpi_sint;
+ typedef uint32_t mbedtls_mpi_uint;
+ #if !defined(MBEDTLS_NO_UDBL_DIVISION)
+ typedef uint64_t mbedtls_t_udbl;
+ #define MBEDTLS_HAVE_UDBL
+ #endif /* !MBEDTLS_NO_UDBL_DIVISION */
+#endif /* !MBEDTLS_HAVE_INT64 */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief MPI structure
+ */
+typedef struct
+{
+ int s; /*!< integer sign */
+ size_t n; /*!< total # of limbs */
+ mbedtls_mpi_uint *p; /*!< pointer to limbs */
+}
+mbedtls_mpi;
+
+/**
+ * \brief Initialize one MPI (make internal references valid)
+ * This just makes it ready to be set or freed,
+ * but does not define a value for the MPI.
+ *
+ * \param X One MPI to initialize.
+ */
+void mbedtls_mpi_init( mbedtls_mpi *X );
+
+/**
+ * \brief Unallocate one MPI
+ *
+ * \param X One MPI to unallocate.
+ */
+void mbedtls_mpi_free( mbedtls_mpi *X );
+
+/**
+ * \brief Enlarge to the specified number of limbs
+ *
+ * \param X MPI to grow
+ * \param nblimbs The target number of limbs
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
+
+/**
+ * \brief Resize down, keeping at least the specified number of limbs
+ *
+ * \param X MPI to shrink
+ * \param nblimbs The minimum number of limbs to keep
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
+
+/**
+ * \brief Copy the contents of Y into X
+ *
+ * \param X Destination MPI
+ * \param Y Source MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y );
+
+/**
+ * \brief Swap the contents of X and Y
+ *
+ * \param X First MPI value
+ * \param Y Second MPI value
+ */
+void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
+
+/**
+ * \brief Safe conditional assignement X = Y if assign is 1
+ *
+ * \param X MPI to conditionally assign to
+ * \param Y Value to be assigned
+ * \param assign 1: perform the assignment, 0: keep X's original value
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ *
+ * \note This function is equivalent to
+ * if( assign ) mbedtls_mpi_copy( X, Y );
+ * except that it avoids leaking any information about whether
+ * the assignment was done or not (the above code may leak
+ * information through branch prediction and/or memory access
+ * patterns analysis).
+ */
+int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign );
+
+/**
+ * \brief Safe conditional swap X <-> Y if swap is 1
+ *
+ * \param X First mbedtls_mpi value
+ * \param Y Second mbedtls_mpi value
+ * \param assign 1: perform the swap, 0: keep X and Y's original values
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ *
+ * \note This function is equivalent to
+ * if( assign ) mbedtls_mpi_swap( X, Y );
+ * except that it avoids leaking any information about whether
+ * the assignment was done or not (the above code may leak
+ * information through branch prediction and/or memory access
+ * patterns analysis).
+ */
+int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign );
+
+/**
+ * \brief Set value from integer
+ *
+ * \param X MPI to set
+ * \param z Value to use
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z );
+
+/**
+ * \brief Get a specific bit from X
+ *
+ * \param X MPI to use
+ * \param pos Zero-based index of the bit in X
+ *
+ * \return Either a 0 or a 1
+ */
+int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
+
+/**
+ * \brief Set a bit of X to a specific value of 0 or 1
+ *
+ * \note Will grow X if necessary to set a bit to 1 in a not yet
+ * existing limb. Will not grow if bit should be set to 0
+ *
+ * \param X MPI to use
+ * \param pos Zero-based index of the bit in X
+ * \param val The value to set the bit to (0 or 1)
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1
+ */
+int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
+
+/**
+ * \brief Return the number of zero-bits before the least significant
+ * '1' bit
+ *
+ * Note: Thus also the zero-based index of the least significant '1' bit
+ *
+ * \param X MPI to use
+ */
+size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
+
+/**
+ * \brief Return the number of bits up to and including the most
+ * significant '1' bit'
+ *
+ * Note: Thus also the one-based index of the most significant '1' bit
+ *
+ * \param X MPI to use
+ */
+size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X );
+
+/**
+ * \brief Return the total size in bytes
+ *
+ * \param X MPI to use
+ */
+size_t mbedtls_mpi_size( const mbedtls_mpi *X );
+
+/**
+ * \brief Import from an ASCII string
+ *
+ * \param X Destination MPI
+ * \param radix Input numeric base
+ * \param s Null-terminated string buffer
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
+ */
+int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
+
+/**
+ * \brief Export into an ASCII string
+ *
+ * \param X Source MPI
+ * \param radix Output numeric base
+ * \param buf Buffer to write the string to
+ * \param buflen Length of buf
+ * \param olen Length of the string written, including final NUL byte
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code.
+ * *olen is always updated to reflect the amount
+ * of data that has (or would have) been written.
+ *
+ * \note Call this function with buflen = 0 to obtain the
+ * minimum required buffer size in *olen.
+ */
+int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
+ char *buf, size_t buflen, size_t *olen );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief Read MPI from a line in an opened file
+ *
+ * \param X Destination MPI
+ * \param radix Input numeric base
+ * \param fin Input file handle
+ *
+ * \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
+ * the file read buffer is too small or a
+ * MBEDTLS_ERR_MPI_XXX error code
+ *
+ * \note On success, this function advances the file stream
+ * to the end of the current line or to EOF.
+ *
+ * The function returns 0 on an empty line.
+ *
+ * Leading whitespaces are ignored, as is a
+ * '0x' prefix for radix 16.
+ *
+ */
+int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
+
+/**
+ * \brief Write X into an opened file, or stdout if fout is NULL
+ *
+ * \param p Prefix, can be NULL
+ * \param X Source MPI
+ * \param radix Output numeric base
+ * \param fout Output file handle (can be NULL)
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
+ *
+ * \note Set fout == NULL to print X on the console.
+ */
+int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE *fout );
+#endif /* MBEDTLS_FS_IO */
+
+/**
+ * \brief Import X from unsigned binary data, big endian
+ *
+ * \param X Destination MPI
+ * \param buf Input buffer
+ * \param buflen Input buffer size
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen );
+
+/**
+ * \brief Export X into unsigned binary data, big endian.
+ * Always fills the whole buffer, which will start with zeros
+ * if the number is smaller.
+ *
+ * \param X Source MPI
+ * \param buf Output buffer
+ * \param buflen Output buffer size
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough
+ */
+int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, size_t buflen );
+
+/**
+ * \brief Left-shift: X <<= count
+ *
+ * \param X MPI to shift
+ * \param count Amount to shift
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
+
+/**
+ * \brief Right-shift: X >>= count
+ *
+ * \param X MPI to shift
+ * \param count Amount to shift
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
+
+/**
+ * \brief Compare unsigned values
+ *
+ * \param X Left-hand MPI
+ * \param Y Right-hand MPI
+ *
+ * \return 1 if |X| is greater than |Y|,
+ * -1 if |X| is lesser than |Y| or
+ * 0 if |X| is equal to |Y|
+ */
+int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
+
+/**
+ * \brief Compare signed values
+ *
+ * \param X Left-hand MPI
+ * \param Y Right-hand MPI
+ *
+ * \return 1 if X is greater than Y,
+ * -1 if X is lesser than Y or
+ * 0 if X is equal to Y
+ */
+int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
+
+/**
+ * \brief Compare signed values
+ *
+ * \param X Left-hand MPI
+ * \param z The integer value to compare to
+ *
+ * \return 1 if X is greater than z,
+ * -1 if X is lesser than z or
+ * 0 if X is equal to z
+ */
+int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z );
+
+/**
+ * \brief Unsigned addition: X = |A| + |B|
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Unsigned subtraction: X = |A| - |B|
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B is greater than A
+ */
+int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Signed addition: X = A + B
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Signed subtraction: X = A - B
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Signed addition: X = A + b
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param b The integer value to add
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b );
+
+/**
+ * \brief Signed subtraction: X = A - b
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param b The integer value to subtract
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b );
+
+/**
+ * \brief Baseline multiplication: X = A * B
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Baseline multiplication: X = A * b
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param b The unsigned integer value to multiply with
+ *
+ * \note b is unsigned
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b );
+
+/**
+ * \brief Division by mbedtls_mpi: A = Q * B + R
+ *
+ * \param Q Destination MPI for the quotient
+ * \param R Destination MPI for the rest value
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0
+ *
+ * \note Either Q or R can be NULL.
+ */
+int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Division by int: A = Q * b + R
+ *
+ * \param Q Destination MPI for the quotient
+ * \param R Destination MPI for the rest value
+ * \param A Left-hand MPI
+ * \param b Integer to divide by
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0
+ *
+ * \note Either Q or R can be NULL.
+ */
+int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b );
+
+/**
+ * \brief Modulo: R = A mod B
+ *
+ * \param R Destination MPI for the rest value
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0,
+ * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B < 0
+ */
+int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Modulo: r = A mod b
+ *
+ * \param r Destination mbedtls_mpi_uint
+ * \param A Left-hand MPI
+ * \param b Integer to divide by
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0,
+ * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if b < 0
+ */
+int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b );
+
+/**
+ * \brief Sliding-window exponentiation: X = A^E mod N
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param E Exponent MPI
+ * \param N Modular MPI
+ * \param _RR Speed-up MPI used for recalculations
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or even or
+ * if E is negative
+ *
+ * \note _RR is used to avoid re-computing R*R mod N across
+ * multiple calls, which speeds up things a bit. It can
+ * be set to NULL if the extra performance is unneeded.
+ */
+int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR );
+
+/**
+ * \brief Fill an MPI X with size bytes of random
+ *
+ * \param X Destination MPI
+ * \param size Size in bytes
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ *
+ * \note The bytes obtained from the PRNG are interpreted
+ * as a big-endian representation of an MPI; this can
+ * be relevant in applications like deterministic ECDSA.
+ */
+int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Greatest common divisor: G = gcd(A, B)
+ *
+ * \param G Destination MPI
+ * \param A Left-hand MPI
+ * \param B Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B );
+
+/**
+ * \brief Modular inverse: X = A^-1 mod N
+ *
+ * \param X Destination MPI
+ * \param A Left-hand MPI
+ * \param N Right-hand MPI
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is <= 1,
+ MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N.
+ */
+int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N );
+
+/**
+ * \brief Miller-Rabin primality test
+ *
+ * \param X MPI to check
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful (probably prime),
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime
+ */
+int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Prime number generation
+ *
+ * \param X Destination MPI
+ * \param nbits Required size of X in bits
+ * ( 3 <= nbits <= MBEDTLS_MPI_MAX_BITS )
+ * \param dh_flag If 1, then (X-1)/2 will be prime too
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful (probably prime),
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
+ */
+int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_mpi_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* bignum.h */
+
+
+/********* Start of file include/mbedtls/net.h ************/
+
+/**
+ * \file net.h
+ *
+ * \brief Deprecated header file that includes mbedtls/net_sockets.h
+ *
+ * \deprecated Superseded by mbedtls/net_sockets.h
+ */
+/*
+ * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#warning "Deprecated header file: Superseded by mbedtls/net_sockets.h"
+#endif /* MBEDTLS_DEPRECATED_WARNING */
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+
+/********* Start of file include/mbedtls/net_sockets.h ************/
+
+/**
+ * \file net_sockets.h
+ *
+ * \brief Network communication functions
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_NET_SOCKETS_H
+#define MBEDTLS_NET_SOCKETS_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#include
+#include
+
+#define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042 /**< Failed to open a socket. */
+#define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044 /**< The connection to the given server / port failed. */
+#define MBEDTLS_ERR_NET_BIND_FAILED -0x0046 /**< Binding of the socket failed. */
+#define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048 /**< Could not listen on the socket. */
+#define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A /**< Could not accept the incoming connection. */
+#define MBEDTLS_ERR_NET_RECV_FAILED -0x004C /**< Reading information from the socket failed. */
+#define MBEDTLS_ERR_NET_SEND_FAILED -0x004E /**< Sending information through the socket failed. */
+#define MBEDTLS_ERR_NET_CONN_RESET -0x0050 /**< Connection was reset by peer. */
+#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052 /**< Failed to get an IP address for the given hostname. */
+#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043 /**< Buffer is too small to hold the data. */
+#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045 /**< The context is invalid, eg because it was free()ed. */
+
+#define MBEDTLS_NET_LISTEN_BACKLOG 10 /**< The backlog that listen() should use. */
+
+#define MBEDTLS_NET_PROTO_TCP 0 /**< The TCP transport protocol */
+#define MBEDTLS_NET_PROTO_UDP 1 /**< The UDP transport protocol */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Wrapper type for sockets.
+ *
+ * Currently backed by just a file descriptor, but might be more in the future
+ * (eg two file descriptors for combined IPv4 + IPv6 support, or additional
+ * structures for hand-made UDP demultiplexing).
+ */
+typedef struct
+{
+ int fd; /**< The underlying file descriptor */
+}
+mbedtls_net_context;
+
+/**
+ * \brief Initialize a context
+ * Just makes the context ready to be used or freed safely.
+ *
+ * \param ctx Context to initialize
+ */
+void mbedtls_net_init( mbedtls_net_context *ctx );
+
+/**
+ * \brief Initiate a connection with host:port in the given protocol
+ *
+ * \param ctx Socket to use
+ * \param host Host to connect to
+ * \param port Port to connect to
+ * \param proto Protocol: MBEDTLS_NET_PROTO_TCP or MBEDTLS_NET_PROTO_UDP
+ *
+ * \return 0 if successful, or one of:
+ * MBEDTLS_ERR_NET_SOCKET_FAILED,
+ * MBEDTLS_ERR_NET_UNKNOWN_HOST,
+ * MBEDTLS_ERR_NET_CONNECT_FAILED
+ *
+ * \note Sets the socket in connected mode even with UDP.
+ */
+int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto );
+
+/**
+ * \brief Create a receiving socket on bind_ip:port in the chosen
+ * protocol. If bind_ip == NULL, all interfaces are bound.
+ *
+ * \param ctx Socket to use
+ * \param bind_ip IP to bind to, can be NULL
+ * \param port Port number to use
+ * \param proto Protocol: MBEDTLS_NET_PROTO_TCP or MBEDTLS_NET_PROTO_UDP
+ *
+ * \return 0 if successful, or one of:
+ * MBEDTLS_ERR_NET_SOCKET_FAILED,
+ * MBEDTLS_ERR_NET_BIND_FAILED,
+ * MBEDTLS_ERR_NET_LISTEN_FAILED
+ *
+ * \note Regardless of the protocol, opens the sockets and binds it.
+ * In addition, make the socket listening if protocol is TCP.
+ */
+int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto );
+
+/**
+ * \brief Accept a connection from a remote client
+ *
+ * \param bind_ctx Relevant socket
+ * \param client_ctx Will contain the connected client socket
+ * \param client_ip Will contain the client IP address
+ * \param buf_size Size of the client_ip buffer
+ * \param ip_len Will receive the size of the client IP written
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_NET_ACCEPT_FAILED, or
+ * MBEDTLS_ERR_NET_BUFFER_TOO_SMALL if buf_size is too small,
+ * MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to
+ * non-blocking and accept() would block.
+ */
+int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
+ mbedtls_net_context *client_ctx,
+ void *client_ip, size_t buf_size, size_t *ip_len );
+
+/**
+ * \brief Set the socket blocking
+ *
+ * \param ctx Socket to set
+ *
+ * \return 0 if successful, or a non-zero error code
+ */
+int mbedtls_net_set_block( mbedtls_net_context *ctx );
+
+/**
+ * \brief Set the socket non-blocking
+ *
+ * \param ctx Socket to set
+ *
+ * \return 0 if successful, or a non-zero error code
+ */
+int mbedtls_net_set_nonblock( mbedtls_net_context *ctx );
+
+/**
+ * \brief Portable usleep helper
+ *
+ * \param usec Amount of microseconds to sleep
+ *
+ * \note Real amount of time slept will not be less than
+ * select()'s timeout granularity (typically, 10ms).
+ */
+void mbedtls_net_usleep( unsigned long usec );
+
+/**
+ * \brief Read at most 'len' characters. If no error occurs,
+ * the actual amount read is returned.
+ *
+ * \param ctx Socket
+ * \param buf The buffer to write to
+ * \param len Maximum length of the buffer
+ *
+ * \return the number of bytes received,
+ * or a non-zero error code; with a non-blocking socket,
+ * MBEDTLS_ERR_SSL_WANT_READ indicates read() would block.
+ */
+int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len );
+
+/**
+ * \brief Write at most 'len' characters. If no error occurs,
+ * the actual amount read is returned.
+ *
+ * \param ctx Socket
+ * \param buf The buffer to read from
+ * \param len The length of the buffer
+ *
+ * \return the number of bytes sent,
+ * or a non-zero error code; with a non-blocking socket,
+ * MBEDTLS_ERR_SSL_WANT_WRITE indicates write() would block.
+ */
+int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
+
+/**
+ * \brief Read at most 'len' characters, blocking for at most
+ * 'timeout' seconds. If no error occurs, the actual amount
+ * read is returned.
+ *
+ * \param ctx Socket
+ * \param buf The buffer to write to
+ * \param len Maximum length of the buffer
+ * \param timeout Maximum number of milliseconds to wait for data
+ * 0 means no timeout (wait forever)
+ *
+ * \return the number of bytes received,
+ * or a non-zero error code:
+ * MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
+ * MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
+ *
+ * \note This function will block (until data becomes available or
+ * timeout is reached) even if the socket is set to
+ * non-blocking. Handling timeouts with non-blocking reads
+ * requires a different strategy.
+ */
+int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
+ uint32_t timeout );
+
+/**
+ * \brief Gracefully shutdown the connection and free associated data
+ *
+ * \param ctx The context to free
+ */
+void mbedtls_net_free( mbedtls_net_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* net_sockets.h */
+
+
+/********* Start of file include/mbedtls/dhm.h ************/
+
+/**
+ * \file dhm.h
+ *
+ * \brief Diffie-Hellman-Merkle key exchange.
+ *
+ * RFC-3526: More Modular Exponential (MODP) Diffie-Hellman groups for
+ * Internet Key Exchange (IKE) defines a number of standardized
+ * Diffie-Hellman groups for IKE.
+ *
+ * RFC-5114: Additional Diffie-Hellman Groups for Use with IETF
+ * Standards defines a number of standardized Diffie-Hellman
+ * groups that can be used.
+ *
+ * \warning The security of the DHM key exchange relies on the proper choice
+ * of prime modulus - optimally, it should be a safe prime. The usage
+ * of non-safe primes both decreases the difficulty of the underlying
+ * discrete logarithm problem and can lead to small subgroup attacks
+ * leaking private exponent bits when invalid public keys are used
+ * and not detected. This is especially relevant if the same DHM
+ * parameters are reused for multiple key exchanges as in static DHM,
+ * while the criticality of small-subgroup attacks is lower for
+ * ephemeral DHM.
+ *
+ * \warning For performance reasons, the code does neither perform primality
+ * nor safe primality tests, nor the expensive checks for invalid
+ * subgroups. Moreover, even if these were performed, non-standardized
+ * primes cannot be trusted because of the possibility of backdoors
+ * that can't be effectively checked for.
+ *
+ * \warning Diffie-Hellman-Merkle is therefore a security risk when not using
+ * standardized primes generated using a trustworthy ("nothing up
+ * my sleeve") method, such as the RFC 3526 / 7919 primes. In the TLS
+ * protocol, DH parameters need to be negotiated, so using the default
+ * primes systematically is not always an option. If possible, use
+ * Elliptic Curve Diffie-Hellman (ECDH), which has better performance,
+ * and for which the TLS protocol mandates the use of standard
+ * parameters.
+ *
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_DHM_H
+#define MBEDTLS_DHM_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#if !defined(MBEDTLS_DHM_ALT)
+
+/*
+ * DHM Error codes
+ */
+#define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters. */
+#define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */
+#define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */
+#define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */
+#define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */
+#define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */
+#define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */
+#define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */
+#define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */
+#define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 /**< DHM hardware accelerator failed. */
+#define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The DHM context structure.
+ */
+typedef struct
+{
+ size_t len; /*!< The size of \p P in Bytes. */
+ mbedtls_mpi P; /*!< The prime modulus. */
+ mbedtls_mpi G; /*!< The generator. */
+ mbedtls_mpi X; /*!< Our secret value. */
+ mbedtls_mpi GX; /*!< Our public key = \c G^X mod \c P. */
+ mbedtls_mpi GY; /*!< The public key of the peer = \c G^Y mod \c P. */
+ mbedtls_mpi K; /*!< The shared secret = \c G^(XY) mod \c P. */
+ mbedtls_mpi RP; /*!< The cached value = \c R^2 mod \c P. */
+ mbedtls_mpi Vi; /*!< The blinding value. */
+ mbedtls_mpi Vf; /*!< The unblinding value. */
+ mbedtls_mpi pX; /*!< The previous \c X. */
+}
+mbedtls_dhm_context;
+
+/**
+ * \brief This function initializes the DHM context.
+ *
+ * \param ctx The DHM context to initialize.
+ */
+void mbedtls_dhm_init( mbedtls_dhm_context *ctx );
+
+/**
+ * \brief This function parses the ServerKeyExchange parameters.
+ *
+ * \param ctx The DHM context.
+ * \param p On input, *p must be the start of the input buffer.
+ * On output, *p is updated to point to the end of the data
+ * that has been read. On success, this is the first byte
+ * past the end of the ServerKeyExchange parameters.
+ * On error, this is the point at which an error has been
+ * detected, which is usually not useful except to debug
+ * failures.
+ * \param end The end of the input buffer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
+ * on failure.
+ */
+int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx,
+ unsigned char **p,
+ const unsigned char *end );
+
+/**
+ * \brief This function sets up and writes the ServerKeyExchange
+ * parameters.
+ *
+ * \param ctx The DHM context.
+ * \param x_size The private value size in Bytes.
+ * \param olen The number of characters written.
+ * \param output The destination buffer.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \note The destination buffer must be large enough to hold
+ * the reduced binary presentation of the modulus, the generator
+ * and the public key, each wrapped with a 2-byte length field.
+ * It is the responsibility of the caller to ensure that enough
+ * space is available. Refer to \c mbedtls_mpi_size to computing
+ * the byte-size of an MPI.
+ *
+ * \note This function assumes that \c ctx->P and \c ctx->G
+ * have already been properly set. For that, use
+ * mbedtls_dhm_set_group() below in conjunction with
+ * mbedtls_mpi_read_binary() and mbedtls_mpi_read_string().
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
+ * on failure.
+ */
+int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
+ unsigned char *output, size_t *olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Set prime modulus and generator
+ *
+ * \param ctx The DHM context.
+ * \param P The MPI holding DHM prime modulus.
+ * \param G The MPI holding DHM generator.
+ *
+ * \note This function can be used to set P, G
+ * in preparation for \c mbedtls_dhm_make_params.
+ *
+ * \return \c 0 if successful, or an \c MBEDTLS_ERR_DHM_XXX error code
+ * on failure.
+ */
+int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx,
+ const mbedtls_mpi *P,
+ const mbedtls_mpi *G );
+
+/**
+ * \brief This function imports the public value G^Y of the peer.
+ *
+ * \param ctx The DHM context.
+ * \param input The input buffer.
+ * \param ilen The size of the input buffer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
+ * on failure.
+ */
+int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx,
+ const unsigned char *input, size_t ilen );
+
+/**
+ * \brief This function creates its own private value \c X and
+ * exports \c G^X.
+ *
+ * \param ctx The DHM context.
+ * \param x_size The private value size in Bytes.
+ * \param output The destination buffer.
+ * \param olen The length of the destination buffer. Must be at least
+ equal to ctx->len (the size of \c P).
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \note The destination buffer will always be fully written
+ * so as to contain a big-endian presentation of G^X mod P.
+ * If it is larger than ctx->len, it will accordingly be
+ * padded with zero-bytes in the beginning.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
+ * on failure.
+ */
+int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size,
+ unsigned char *output, size_t olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief This function derives and exports the shared secret
+ * \c (G^Y)^X mod \c P.
+ *
+ * \param ctx The DHM context.
+ * \param output The destination buffer.
+ * \param output_size The size of the destination buffer. Must be at least
+ * the size of ctx->len.
+ * \param olen On exit, holds the actual number of Bytes written.
+ * \param f_rng The RNG function, for blinding purposes.
+ * \param p_rng The RNG parameter.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
+ * on failure.
+ *
+ * \note If non-NULL, \p f_rng is used to blind the input as
+ * a countermeasure against timing attacks. Blinding is used
+ * only if our secret value \p X is re-used and omitted
+ * otherwise. Therefore, we recommend always passing a
+ * non-NULL \p f_rng argument.
+ */
+int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx,
+ unsigned char *output, size_t output_size, size_t *olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief This function frees and clears the components of a DHM key.
+ *
+ * \param ctx The DHM context to free and clear.
+ */
+void mbedtls_dhm_free( mbedtls_dhm_context *ctx );
+
+#if defined(MBEDTLS_ASN1_PARSE_C)
+/** \ingroup x509_module */
+/**
+ * \brief This function parses DHM parameters in PEM or DER format.
+ *
+ * \param dhm The DHM context to initialize.
+ * \param dhmin The input buffer.
+ * \param dhminlen The size of the buffer, including the terminating null
+ * Byte for PEM data.
+ *
+ * \return \c 0 on success, or a specific DHM or PEM error code
+ * on failure.
+ */
+int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
+ size_t dhminlen );
+
+#if defined(MBEDTLS_FS_IO)
+/** \ingroup x509_module */
+/**
+ * \brief This function loads and parses DHM parameters from a file.
+ *
+ * \param dhm The DHM context to load the parameters to.
+ * \param path The filename to read the DHM parameters from.
+ *
+ * \return \c 0 on success, or a specific DHM or PEM error code
+ * on failure.
+ */
+int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
+#endif /* MBEDTLS_FS_IO */
+#endif /* MBEDTLS_ASN1_PARSE_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_DHM_ALT */
+
+#endif /* MBEDTLS_DHM_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The DMH checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_dhm_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * RFC 3526, RFC 5114 and RFC 7919 standardize a number of
+ * Diffie-Hellman groups, some of which are included here
+ * for use within the SSL/TLS module and the user's convenience
+ * when configuring the Diffie-Hellman parameters by hand
+ * through \c mbedtls_ssl_conf_dh_param.
+ *
+ * The following lists the source of the above groups in the standards:
+ * - RFC 5114 section 2.2: 2048-bit MODP Group with 224-bit Prime Order Subgroup
+ * - RFC 3526 section 3: 2048-bit MODP Group
+ * - RFC 3526 section 4: 3072-bit MODP Group
+ * - RFC 3526 section 5: 4096-bit MODP Group
+ * - RFC 7919 section A.1: ffdhe2048
+ * - RFC 7919 section A.2: ffdhe3072
+ * - RFC 7919 section A.3: ffdhe4096
+ * - RFC 7919 section A.4: ffdhe6144
+ * - RFC 7919 section A.5: ffdhe8192
+ *
+ * The constants with suffix "_p" denote the chosen prime moduli, while
+ * the constants with suffix "_g" denote the chosen generator
+ * of the associated prime field.
+ *
+ * The constants further suffixed with "_bin" are provided in binary format,
+ * while all other constants represent null-terminated strings holding the
+ * hexadecimal presentation of the respective numbers.
+ *
+ * The primes from RFC 3526 and RFC 7919 have been generating by the following
+ * trust-worthy procedure:
+ * - Fix N in { 2048, 3072, 4096, 6144, 8192 } and consider the N-bit number
+ * the first and last 64 bits are all 1, and the remaining N - 128 bits of
+ * which are 0x7ff...ff.
+ * - Add the smallest multiple of the first N - 129 bits of the binary expansion
+ * of pi (for RFC 5236) or e (for RFC 7919) to this intermediate bit-string
+ * such that the resulting integer is a safe-prime.
+ * - The result is the respective RFC 3526 / 7919 prime, and the corresponding
+ * generator is always chosen to be 2 (which is a square for these prime,
+ * hence the corresponding subgroup has order (p-1)/2 and avoids leaking a
+ * bit in the private exponent).
+ *
+ */
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_constant_t;
+#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
+ ( (mbedtls_deprecated_constant_t) ( VAL ) )
+#else
+#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
+#endif /* ! MBEDTLS_DEPRECATED_WARNING */
+
+/**
+ * \warning The origin of the primes in RFC 5114 is not documented and
+ * their use therefore constitutes a security risk!
+ *
+ * \deprecated The hex-encoded primes from RFC 5114 are deprecated and are
+ * likely to be removed in a future version of the library without
+ * replacement.
+ */
+
+/**
+ * The hexadecimal presentation of the prime underlying the
+ * 2048-bit MODP Group with 224-bit Prime Order Subgroup, as defined
+ * in RFC-5114: Additional Diffie-Hellman Groups for Use with
+ * IETF Standards.
+ */
+#define MBEDTLS_DHM_RFC5114_MODP_2048_P \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( \
+ "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \
+ "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \
+ "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \
+ "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \
+ "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \
+ "B3BF8A317091883681286130BC8985DB1602E714415D9330" \
+ "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \
+ "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \
+ "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \
+ "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \
+ "CF9DE5384E71B81C0AC4DFFE0C10E64F" )
+
+/**
+ * The hexadecimal presentation of the chosen generator of the 2048-bit MODP
+ * Group with 224-bit Prime Order Subgroup, as defined in RFC-5114:
+ * Additional Diffie-Hellman Groups for Use with IETF Standards.
+ */
+#define MBEDTLS_DHM_RFC5114_MODP_2048_G \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( \
+ "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF" \
+ "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA" \
+ "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7" \
+ "C17669101999024AF4D027275AC1348BB8A762D0521BC98A" \
+ "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE" \
+ "F180EB34118E98D119529A45D6F834566E3025E316A330EF" \
+ "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB" \
+ "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381" \
+ "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269" \
+ "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179" \
+ "81BC087F2A7065B384B890D3191F2BFA" )
+
+/**
+ * The hexadecimal presentation of the prime underlying the 2048-bit MODP
+ * Group, as defined in RFC-3526: More Modular Exponential (MODP)
+ * Diffie-Hellman groups for Internet Key Exchange (IKE).
+ *
+ * \deprecated The hex-encoded primes from RFC 3625 are deprecated and
+ * superseded by the corresponding macros providing them as
+ * binary constants. Their hex-encoded constants are likely
+ * to be removed in a future version of the library.
+ *
+ */
+#define MBEDTLS_DHM_RFC3526_MODP_2048_P \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( \
+ "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
+ "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
+ "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
+ "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
+ "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
+ "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
+ "15728E5A8AACAA68FFFFFFFFFFFFFFFF" )
+
+/**
+ * The hexadecimal presentation of the chosen generator of the 2048-bit MODP
+ * Group, as defined in RFC-3526: More Modular Exponential (MODP)
+ * Diffie-Hellman groups for Internet Key Exchange (IKE).
+ */
+#define MBEDTLS_DHM_RFC3526_MODP_2048_G \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
+
+/**
+ * The hexadecimal presentation of the prime underlying the 3072-bit MODP
+ * Group, as defined in RFC-3072: More Modular Exponential (MODP)
+ * Diffie-Hellman groups for Internet Key Exchange (IKE).
+ */
+#define MBEDTLS_DHM_RFC3526_MODP_3072_P \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( \
+ "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
+ "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
+ "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
+ "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
+ "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
+ "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
+ "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
+ "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
+ "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
+ "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
+ "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
+ "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" )
+
+/**
+ * The hexadecimal presentation of the chosen generator of the 3072-bit MODP
+ * Group, as defined in RFC-3526: More Modular Exponential (MODP)
+ * Diffie-Hellman groups for Internet Key Exchange (IKE).
+ */
+#define MBEDTLS_DHM_RFC3526_MODP_3072_G \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
+
+/**
+ * The hexadecimal presentation of the prime underlying the 4096-bit MODP
+ * Group, as defined in RFC-3526: More Modular Exponential (MODP)
+ * Diffie-Hellman groups for Internet Key Exchange (IKE).
+ */
+#define MBEDTLS_DHM_RFC3526_MODP_4096_P \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( \
+ "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
+ "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
+ "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
+ "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
+ "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
+ "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
+ "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
+ "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
+ "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
+ "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
+ "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
+ "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
+ "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
+ "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
+ "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
+ "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
+ "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \
+ "FFFFFFFFFFFFFFFF" )
+
+/**
+ * The hexadecimal presentation of the chosen generator of the 4096-bit MODP
+ * Group, as defined in RFC-3526: More Modular Exponential (MODP)
+ * Diffie-Hellman groups for Internet Key Exchange (IKE).
+ */
+#define MBEDTLS_DHM_RFC3526_MODP_4096_G \
+ MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
+
+#endif /* MBEDTLS_DEPRECATED_REMOVED */
+
+/*
+ * Trustworthy DHM parameters in binary form
+ */
+
+#define MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
+ 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
+ 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
+ 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
+ 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
+ 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
+ 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
+ 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
+ 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
+ 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
+ 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
+ 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
+ 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
+ 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
+ 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
+ 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
+ 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
+ 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
+ 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
+ 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
+ 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
+ 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
+ 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
+ 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
+ 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
+ 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
+ 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
+ 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
+ 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
+ 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
+ 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
+ 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
+ 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
+ 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
+ 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
+ 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
+ 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
+ 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
+ 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
+ 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
+ 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
+ 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
+ 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
+ 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
+ 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
+ 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
+ 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
+ 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
+ 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
+ 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
+ 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
+ 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
+ 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
+ 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
+ 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
+ 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
+ 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
+ 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
+ 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, \
+ 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \
+ 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, \
+ 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, \
+ 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, \
+ 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, \
+ 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, \
+ 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, \
+ 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, \
+ 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, \
+ 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, \
+ 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, \
+ 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, \
+ 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, \
+ 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, \
+ 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, \
+ 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC3526_MODP_4096_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
+ 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
+ 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
+ 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
+ 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
+ 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
+ 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
+ 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
+ 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
+ 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
+ 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
+ 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
+ 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
+ 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
+ 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
+ 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
+ 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
+ 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
+ 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
+ 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
+ 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
+ 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
+ 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
+ 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
+ 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
+ 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
+ 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
+ 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
+ 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
+ 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, \
+ 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \
+ 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, \
+ 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, \
+ 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, \
+ 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, \
+ 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, \
+ 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, \
+ 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, \
+ 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, \
+ 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, \
+ 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, \
+ 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, \
+ 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, \
+ 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, \
+ 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, \
+ 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, \
+ 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, \
+ 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, \
+ 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, \
+ 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, \
+ 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, \
+ 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, \
+ 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, \
+ 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, \
+ 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, \
+ 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, \
+ 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, \
+ 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, \
+ 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, \
+ 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, \
+ 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F, \
+ 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC3526_MODP_4096_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
+ 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
+ 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
+ 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
+ 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
+ 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
+ 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
+ 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
+ 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
+ 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
+ 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
+ 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
+ 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
+ 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
+ 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
+ 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
+ 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
+ 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
+ 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
+ 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
+ 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
+ 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
+ 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
+ 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
+ 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
+ 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
+ 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
+ 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
+ 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
+ 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
+ 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
+ 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
+ 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
+ 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
+ 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
+ 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
+ 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
+ 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
+ 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
+ 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
+ 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
+ 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
+ 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
+ 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
+ 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
+ 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
+ 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
+ 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
+ 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
+ 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
+ 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
+ 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
+ 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
+ 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
+ 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
+ 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
+ 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
+ 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
+ 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
+ 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
+ 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
+ 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
+ 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
+ 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
+ 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
+ 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
+ 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
+ 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
+ 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
+ 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
+ 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
+ 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
+ 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
+ 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
+ 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE3072_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
+ 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
+ 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
+ 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
+ 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
+ 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
+ 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
+ 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
+ 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
+ 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
+ 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
+ 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
+ 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
+ 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
+ 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
+ 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
+ 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
+ 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
+ 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
+ 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
+ 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
+ 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
+ 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
+ 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
+ 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
+ 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
+ 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
+ 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
+ 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
+ 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
+ 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
+ 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
+ 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
+ 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
+ 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
+ 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
+ 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
+ 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
+ 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
+ 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
+ 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
+ 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
+ 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
+ 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
+ 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
+ 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
+ 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
+ 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
+ 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
+ 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
+ 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
+ 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
+ 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
+ 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
+ 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
+ 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
+ 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
+ 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
+ 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
+ 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
+ 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
+ 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE6144_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
+ 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
+ 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
+ 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
+ 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
+ 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
+ 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
+ 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
+ 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
+ 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
+ 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
+ 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
+ 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
+ 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
+ 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
+ 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
+ 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
+ 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
+ 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
+ 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
+ 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
+ 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
+ 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
+ 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
+ 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
+ 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
+ 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
+ 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
+ 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
+ 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
+ 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
+ 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
+ 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
+ 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
+ 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
+ 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
+ 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
+ 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
+ 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
+ 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
+ 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
+ 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
+ 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
+ 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
+ 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
+ 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
+ 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
+ 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
+ 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
+ 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
+ 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
+ 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
+ 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
+ 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
+ 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
+ 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
+ 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
+ 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
+ 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
+ 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
+ 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
+ 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, \
+ 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, \
+ 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, \
+ 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \
+ 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, \
+ 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, \
+ 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, \
+ 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, \
+ 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, \
+ 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, \
+ 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, \
+ 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, \
+ 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, \
+ 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, \
+ 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, \
+ 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, \
+ 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, \
+ 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, \
+ 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, \
+ 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, \
+ 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \
+ 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, \
+ 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, \
+ 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, \
+ 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, \
+ 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, \
+ 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, \
+ 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, \
+ 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, \
+ 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, \
+ 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, \
+ 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, \
+ 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN { 0x02 }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN { \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
+ 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
+ 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
+ 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
+ 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
+ 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
+ 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
+ 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
+ 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
+ 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
+ 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
+ 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
+ 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
+ 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
+ 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
+ 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
+ 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
+ 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
+ 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
+ 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
+ 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
+ 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
+ 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
+ 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
+ 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
+ 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
+ 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
+ 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
+ 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
+ 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
+ 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
+ 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
+ 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
+ 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
+ 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
+ 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
+ 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
+ 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
+ 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
+ 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
+ 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
+ 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
+ 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
+ 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
+ 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
+ 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
+ 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
+ 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
+ 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
+ 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
+ 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
+ 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
+ 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
+ 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
+ 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
+ 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
+ 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
+ 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
+ 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
+ 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
+ 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
+ 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
+ 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, \
+ 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, \
+ 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, \
+ 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \
+ 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, \
+ 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, \
+ 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, \
+ 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, \
+ 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, \
+ 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, \
+ 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, \
+ 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, \
+ 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, \
+ 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, \
+ 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, \
+ 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, \
+ 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, \
+ 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, \
+ 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, \
+ 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, \
+ 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \
+ 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, \
+ 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, \
+ 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, \
+ 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, \
+ 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, \
+ 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, \
+ 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, \
+ 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, \
+ 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, \
+ 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, \
+ 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, \
+ 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, \
+ 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, \
+ 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, \
+ 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, \
+ 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, \
+ 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, \
+ 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, \
+ 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, \
+ 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, \
+ 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, \
+ 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, \
+ 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, \
+ 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, \
+ 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, \
+ 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, \
+ 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, \
+ 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, \
+ 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, \
+ 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B, \
+ 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, \
+ 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, \
+ 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, \
+ 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, \
+ 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, \
+ 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, \
+ 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, \
+ 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, \
+ 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, \
+ 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, \
+ 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D, \
+ 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, \
+ 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, \
+ 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
+
+#define MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN { 0x02 }
+
+#endif /* dhm.h */
+
+
+/********* Start of file include/mbedtls/error.h ************/
+
+/**
+ * \file error.h
+ *
+ * \brief Error to string translation
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ERROR_H
+#define MBEDTLS_ERROR_H
+
+#include
+
+/**
+ * Error code layout.
+ *
+ * Currently we try to keep all error codes within the negative space of 16
+ * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
+ * addition we'd like to give two layers of information on the error if
+ * possible.
+ *
+ * For that purpose the error codes are segmented in the following manner:
+ *
+ * 16 bit error code bit-segmentation
+ *
+ * 1 bit - Unused (sign bit)
+ * 3 bits - High level module ID
+ * 5 bits - Module-dependent error code
+ * 7 bits - Low level module errors
+ *
+ * For historical reasons, low-level error codes are divided in even and odd,
+ * even codes were assigned first, and -1 is reserved for other errors.
+ *
+ * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
+ *
+ * Module Nr Codes assigned
+ * MPI 7 0x0002-0x0010
+ * GCM 3 0x0012-0x0014 0x0013-0x0013
+ * BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
+ * THREADING 3 0x001A-0x001E
+ * AES 4 0x0020-0x0022 0x0023-0x0025
+ * CAMELLIA 3 0x0024-0x0026 0x0027-0x0027
+ * XTEA 2 0x0028-0x0028 0x0029-0x0029
+ * BASE64 2 0x002A-0x002C
+ * OID 1 0x002E-0x002E 0x000B-0x000B
+ * PADLOCK 1 0x0030-0x0030
+ * DES 2 0x0032-0x0032 0x0033-0x0033
+ * CTR_DBRG 4 0x0034-0x003A
+ * ENTROPY 3 0x003C-0x0040 0x003D-0x003F
+ * NET 11 0x0042-0x0052 0x0043-0x0045
+ * ASN1 7 0x0060-0x006C
+ * CMAC 1 0x007A-0x007A
+ * PBKDF2 1 0x007C-0x007C
+ * HMAC_DRBG 4 0x0003-0x0009
+ * CCM 3 0x000D-0x0011
+ * ARC4 1 0x0019-0x0019
+ * MD2 1 0x002B-0x002B
+ * MD4 1 0x002D-0x002D
+ * MD5 1 0x002F-0x002F
+ * RIPEMD160 1 0x0031-0x0031
+ * SHA1 1 0x0035-0x0035
+ * SHA256 1 0x0037-0x0037
+ * SHA512 1 0x0039-0x0039
+ *
+ * High-level module nr (3 bits - 0x0...-0x7...)
+ * Name ID Nr of Errors
+ * PEM 1 9
+ * PKCS#12 1 4 (Started from top)
+ * X509 2 20
+ * PKCS5 2 4 (Started from top)
+ * DHM 3 11
+ * PK 3 15 (Started from top)
+ * RSA 4 11
+ * ECP 4 9 (Started from top)
+ * MD 5 5
+ * CIPHER 6 8
+ * SSL 6 17 (Started from top)
+ * SSL 7 31
+ *
+ * Module dependent error code (5 bits 0x.00.-0x.F8.)
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Translate a mbed TLS error code into a string representation,
+ * Result is truncated if necessary and always includes a terminating
+ * null byte.
+ *
+ * \param errnum error code
+ * \param buffer buffer to place representation in
+ * \param buflen length of the buffer
+ */
+void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* error.h */
+
+
+/********* Start of file include/mbedtls/md.h ************/
+
+ /**
+ * \file md.h
+ *
+ * \brief The generic message-digest wrapper.
+ *
+ * \author Adriaan de Jong
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_MD_H
+#define MBEDTLS_MD_H
+
+#include
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
+#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
+#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
+#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Enumeration of supported message digests
+ *
+ * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
+ * their use constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+typedef enum {
+ MBEDTLS_MD_NONE=0,
+ MBEDTLS_MD_MD2,
+ MBEDTLS_MD_MD4,
+ MBEDTLS_MD_MD5,
+ MBEDTLS_MD_SHA1,
+ MBEDTLS_MD_SHA224,
+ MBEDTLS_MD_SHA256,
+ MBEDTLS_MD_SHA384,
+ MBEDTLS_MD_SHA512,
+ MBEDTLS_MD_RIPEMD160,
+} mbedtls_md_type_t;
+
+#if defined(MBEDTLS_SHA512_C)
+#define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
+#else
+#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
+#endif
+
+/**
+ * Opaque struct defined in md_internal.h.
+ */
+typedef struct mbedtls_md_info_t mbedtls_md_info_t;
+
+/**
+ * The generic message-digest context.
+ */
+typedef struct {
+ /** Information about the associated message digest. */
+ const mbedtls_md_info_t *md_info;
+
+ /** The digest-specific context. */
+ void *md_ctx;
+
+ /** The HMAC part of the context. */
+ void *hmac_ctx;
+} mbedtls_md_context_t;
+
+/**
+ * \brief This function returns the list of digests supported by the
+ * generic digest module.
+ *
+ * \return A statically allocated array of digests. Each element
+ * in the returned list is an integer belonging to the
+ * message-digest enumeration #mbedtls_md_type_t.
+ * The last entry is 0.
+ */
+const int *mbedtls_md_list( void );
+
+/**
+ * \brief This function returns the message-digest information
+ * associated with the given digest name.
+ *
+ * \param md_name The name of the digest to search for.
+ *
+ * \return The message-digest information associated with \p md_name,
+ * or NULL if not found.
+ */
+const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
+
+/**
+ * \brief This function returns the message-digest information
+ * associated with the given digest type.
+ *
+ * \param md_type The type of digest to search for.
+ *
+ * \return The message-digest information associated with \p md_type,
+ * or NULL if not found.
+ */
+const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
+
+/**
+ * \brief This function initializes a message-digest context without
+ * binding it to a particular message-digest algorithm.
+ *
+ * This function should always be called first. It prepares the
+ * context for mbedtls_md_setup() for binding it to a
+ * message-digest algorithm.
+ */
+void mbedtls_md_init( mbedtls_md_context_t *ctx );
+
+/**
+ * \brief This function clears the internal structure of \p ctx and
+ * frees any embedded internal structure, but does not free
+ * \p ctx itself.
+ *
+ * If you have called mbedtls_md_setup() on \p ctx, you must
+ * call mbedtls_md_free() when you are no longer using the
+ * context.
+ * Calling this function if you have previously
+ * called mbedtls_md_init() and nothing else is optional.
+ * You must not call this function if you have not called
+ * mbedtls_md_init().
+ */
+void mbedtls_md_free( mbedtls_md_context_t *ctx );
+
+#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief This function selects the message digest algorithm to use,
+ * and allocates internal structures.
+ *
+ * It should be called after mbedtls_md_init() or mbedtls_md_free().
+ * Makes it necessary to call mbedtls_md_free() later.
+ *
+ * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
+ *
+ * \param ctx The context to set up.
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ *
+ * \returns \c 0 on success,
+ * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
+ * #MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
+ */
+int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
+#undef MBEDTLS_DEPRECATED
+#endif /* MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief This function selects the message digest algorithm to use,
+ * and allocates internal structures.
+ *
+ * It should be called after mbedtls_md_init() or
+ * mbedtls_md_free(). Makes it necessary to call
+ * mbedtls_md_free() later.
+ *
+ * \param ctx The context to set up.
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ * \param hmac - 0: HMAC is not used. Saves some memory.
+ * - non-zero: HMAC is used with this context.
+ *
+ * \returns \c 0 on success,
+ * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, or
+ * #MBEDTLS_ERR_MD_ALLOC_FAILED on memory allocation failure.
+ */
+int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
+
+/**
+ * \brief This function clones the state of an message-digest
+ * context.
+ *
+ * \note You must call mbedtls_md_setup() on \c dst before calling
+ * this function.
+ *
+ * \note The two contexts must have the same type,
+ * for example, both are SHA-256.
+ *
+ * \warning This function clones the message-digest state, not the
+ * HMAC state.
+ *
+ * \param dst The destination context.
+ * \param src The context to be cloned.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
+ */
+int mbedtls_md_clone( mbedtls_md_context_t *dst,
+ const mbedtls_md_context_t *src );
+
+/**
+ * \brief This function extracts the message-digest size from the
+ * message-digest information structure.
+ *
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ *
+ * \return The size of the message-digest output in Bytes.
+ */
+unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
+
+/**
+ * \brief This function extracts the message-digest type from the
+ * message-digest information structure.
+ *
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ *
+ * \return The type of the message digest.
+ */
+mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
+
+/**
+ * \brief This function extracts the message-digest name from the
+ * message-digest information structure.
+ *
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ *
+ * \return The name of the message digest.
+ */
+const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
+
+/**
+ * \brief This function starts a message-digest computation.
+ *
+ * You must call this function after setting up the context
+ * with mbedtls_md_setup(), and before passing data with
+ * mbedtls_md_update().
+ *
+ * \param ctx The generic message-digest context.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_starts( mbedtls_md_context_t *ctx );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing
+ * message-digest computation.
+ *
+ * You must call mbedtls_md_starts() before calling this
+ * function. You may call this function multiple times.
+ * Afterwards, call mbedtls_md_finish().
+ *
+ * \param ctx The generic message-digest context.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
+
+/**
+ * \brief This function finishes the digest operation,
+ * and writes the result to the output buffer.
+ *
+ * Call this function after a call to mbedtls_md_starts(),
+ * followed by any number of calls to mbedtls_md_update().
+ * Afterwards, you may either clear the context with
+ * mbedtls_md_free(), or call mbedtls_md_starts() to reuse
+ * the context for another digest operation with the same
+ * algorithm.
+ *
+ * \param ctx The generic message-digest context.
+ * \param output The buffer for the generic message-digest checksum result.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
+
+/**
+ * \brief This function calculates the message-digest of a buffer,
+ * with respect to a configurable message-digest algorithm
+ * in a single call.
+ *
+ * The result is calculated as
+ * Output = message_digest(input buffer).
+ *
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ * \param input The buffer holding the data.
+ * \param ilen The length of the input data.
+ * \param output The generic message-digest checksum result.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
+ unsigned char *output );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief This function calculates the message-digest checksum
+ * result of the contents of the provided file.
+ *
+ * The result is calculated as
+ * Output = message_digest(file contents).
+ *
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ * \param path The input file name.
+ * \param output The generic message-digest checksum result.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed, or
+ * #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
+ */
+int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
+ unsigned char *output );
+#endif /* MBEDTLS_FS_IO */
+
+/**
+ * \brief This function sets the HMAC key and prepares to
+ * authenticate a new message.
+ *
+ * Call this function after mbedtls_md_setup(), to use
+ * the MD context for an HMAC calculation, then call
+ * mbedtls_md_hmac_update() to provide the input data, and
+ * mbedtls_md_hmac_finish() to get the HMAC value.
+ *
+ * \param ctx The message digest context containing an embedded HMAC
+ * context.
+ * \param key The HMAC secret key.
+ * \param keylen The length of the HMAC key in Bytes.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
+ size_t keylen );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing HMAC
+ * computation.
+ *
+ * Call mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
+ * before calling this function.
+ * You may call this function multiple times to pass the
+ * input piecewise.
+ * Afterwards, call mbedtls_md_hmac_finish().
+ *
+ * \param ctx The message digest context containing an embedded HMAC
+ * context.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief This function finishes the HMAC operation, and writes
+ * the result to the output buffer.
+ *
+ * Call this function after mbedtls_md_hmac_starts() and
+ * mbedtls_md_hmac_update() to get the HMAC value. Afterwards
+ * you may either call mbedtls_md_free() to clear the context,
+ * or call mbedtls_md_hmac_reset() to reuse the context with
+ * the same HMAC key.
+ *
+ * \param ctx The message digest context containing an embedded HMAC
+ * context.
+ * \param output The generic HMAC checksum result.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
+
+/**
+ * \brief This function prepares to authenticate a new message with
+ * the same key as the previous HMAC operation.
+ *
+ * You may call this function after mbedtls_md_hmac_finish().
+ * Afterwards call mbedtls_md_hmac_update() to pass the new
+ * input.
+ *
+ * \param ctx The message digest context containing an embedded HMAC
+ * context.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
+
+/**
+ * \brief This function calculates the full generic HMAC
+ * on the input buffer with the provided key.
+ *
+ * The function allocates the context, performs the
+ * calculation, and frees the context.
+ *
+ * The HMAC result is calculated as
+ * output = generic HMAC(hmac key, input buffer).
+ *
+ * \param md_info The information structure of the message-digest algorithm
+ * to use.
+ * \param key The HMAC secret key.
+ * \param keylen The length of the HMAC secret key in Bytes.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The generic HMAC result.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
+ * parameter verification fails.
+ */
+int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output );
+
+/* Internal use */
+int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_MD_H */
+
+
+/********* Start of file include/mbedtls/md_internal.h ************/
+
+/**
+ * \file md_internal.h
+ *
+ * \brief Message digest wrappers.
+ *
+ * \warning This in an internal header. Do not include directly.
+ *
+ * \author Adriaan de Jong
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_MD_WRAP_H
+#define MBEDTLS_MD_WRAP_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Message digest information.
+ * Allows message digest functions to be called in a generic way.
+ */
+struct mbedtls_md_info_t
+{
+ /** Digest identifier */
+ mbedtls_md_type_t type;
+
+ /** Name of the message digest */
+ const char * name;
+
+ /** Output length of the digest function in bytes */
+ int size;
+
+ /** Block length of the digest function in bytes */
+ int block_size;
+
+ /** Digest initialisation function */
+ int (*starts_func)( void *ctx );
+
+ /** Digest update function */
+ int (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
+
+ /** Digest finalisation function */
+ int (*finish_func)( void *ctx, unsigned char *output );
+
+ /** Generic digest function */
+ int (*digest_func)( const unsigned char *input, size_t ilen,
+ unsigned char *output );
+
+ /** Allocate a new context */
+ void * (*ctx_alloc_func)( void );
+
+ /** Free the given context */
+ void (*ctx_free_func)( void *ctx );
+
+ /** Clone state from a context */
+ void (*clone_func)( void *dst, const void *src );
+
+ /** Internal use only */
+ int (*process_func)( void *ctx, const unsigned char *input );
+};
+
+#if defined(MBEDTLS_MD2_C)
+extern const mbedtls_md_info_t mbedtls_md2_info;
+#endif
+#if defined(MBEDTLS_MD4_C)
+extern const mbedtls_md_info_t mbedtls_md4_info;
+#endif
+#if defined(MBEDTLS_MD5_C)
+extern const mbedtls_md_info_t mbedtls_md5_info;
+#endif
+#if defined(MBEDTLS_RIPEMD160_C)
+extern const mbedtls_md_info_t mbedtls_ripemd160_info;
+#endif
+#if defined(MBEDTLS_SHA1_C)
+extern const mbedtls_md_info_t mbedtls_sha1_info;
+#endif
+#if defined(MBEDTLS_SHA256_C)
+extern const mbedtls_md_info_t mbedtls_sha224_info;
+extern const mbedtls_md_info_t mbedtls_sha256_info;
+#endif
+#if defined(MBEDTLS_SHA512_C)
+extern const mbedtls_md_info_t mbedtls_sha384_info;
+extern const mbedtls_md_info_t mbedtls_sha512_info;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_MD_WRAP_H */
+
+
+/********* Start of file include/mbedtls/md5.h ************/
+
+/**
+ * \file md5.h
+ *
+ * \brief MD5 message digest algorithm (hash function)
+ *
+ * \warning MD5 is considered a weak message digest and its use constitutes a
+ * security risk. We recommend considering stronger message
+ * digests instead.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_MD5_H
+#define MBEDTLS_MD5_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
+
+#if !defined(MBEDTLS_MD5_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief MD5 context structure
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+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 */
+}
+mbedtls_md5_context;
+
+/**
+ * \brief Initialize MD5 context
+ *
+ * \param ctx MD5 context to be initialized
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md5_init( mbedtls_md5_context *ctx );
+
+/**
+ * \brief Clear MD5 context
+ *
+ * \param ctx MD5 context to be cleared
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md5_free( mbedtls_md5_context *ctx );
+
+/**
+ * \brief Clone (the state of) an MD5 context
+ *
+ * \param dst The destination context
+ * \param src The context to be cloned
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md5_clone( mbedtls_md5_context *dst,
+ const mbedtls_md5_context *src );
+
+/**
+ * \brief MD5 context setup
+ *
+ * \param ctx context to be initialized
+ *
+ * \return 0 if successful
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
+
+/**
+ * \brief MD5 process buffer
+ *
+ * \param ctx MD5 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \return 0 if successful
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief MD5 final digest
+ *
+ * \param ctx MD5 context
+ * \param output MD5 checksum result
+ *
+ * \return 0 if successful
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
+ unsigned char output[16] );
+
+/**
+ * \brief MD5 process data block (internal use only)
+ *
+ * \param ctx MD5 context
+ * \param data buffer holding one block of data
+ *
+ * \return 0 if successful
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
+ const unsigned char data[64] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief MD5 context setup
+ *
+ * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
+ *
+ * \param ctx context to be initialized
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
+
+/**
+ * \brief MD5 process buffer
+ *
+ * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
+ *
+ * \param ctx MD5 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief MD5 final digest
+ *
+ * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
+ *
+ * \param ctx MD5 context
+ * \param output MD5 checksum result
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
+ unsigned char output[16] );
+
+/**
+ * \brief MD5 process data block (internal use only)
+ *
+ * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
+ *
+ * \param ctx MD5 context
+ * \param data buffer holding one block of data
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
+ const unsigned char data[64] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_MD5_ALT */
+
+#endif /* MBEDTLS_MD5_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Output = MD5( input buffer )
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output MD5 checksum result
+ *
+ * \return 0 if successful
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md5_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[16] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Output = MD5( input buffer )
+ *
+ * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output MD5 checksum result
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[16] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ *
+ * \warning MD5 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md5_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_md5.h */
+
+
+/********* Start of file include/mbedtls/md2.h ************/
+
+/**
+ * \file md2.h
+ *
+ * \brief MD2 message digest algorithm (hash function)
+ *
+ * \warning MD2 is considered a weak message digest and its use constitutes a
+ * security risk. We recommend considering stronger message digests
+ * instead.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ *
+ */
+#ifndef MBEDTLS_MD2_H
+#define MBEDTLS_MD2_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
+
+#if !defined(MBEDTLS_MD2_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief MD2 context structure
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+typedef struct
+{
+ unsigned char cksum[16]; /*!< checksum of the data block */
+ unsigned char state[48]; /*!< intermediate digest state */
+ unsigned char buffer[16]; /*!< data block being processed */
+ size_t left; /*!< amount of data in buffer */
+}
+mbedtls_md2_context;
+
+/**
+ * \brief Initialize MD2 context
+ *
+ * \param ctx MD2 context to be initialized
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md2_init( mbedtls_md2_context *ctx );
+
+/**
+ * \brief Clear MD2 context
+ *
+ * \param ctx MD2 context to be cleared
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md2_free( mbedtls_md2_context *ctx );
+
+/**
+ * \brief Clone (the state of) an MD2 context
+ *
+ * \param dst The destination context
+ * \param src The context to be cloned
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md2_clone( mbedtls_md2_context *dst,
+ const mbedtls_md2_context *src );
+
+/**
+ * \brief MD2 context setup
+ *
+ * \param ctx context to be initialized
+ *
+ * \return 0 if successful
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
+
+/**
+ * \brief MD2 process buffer
+ *
+ * \param ctx MD2 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \return 0 if successful
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief MD2 final digest
+ *
+ * \param ctx MD2 context
+ * \param output MD2 checksum result
+ *
+ * \return 0 if successful
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
+ unsigned char output[16] );
+
+/**
+ * \brief MD2 process data block (internal use only)
+ *
+ * \param ctx MD2 context
+ *
+ * \return 0 if successful
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief MD2 context setup
+ *
+ * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
+ *
+ * \param ctx context to be initialized
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
+
+/**
+ * \brief MD2 process buffer
+ *
+ * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
+ *
+ * \param ctx MD2 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief MD2 final digest
+ *
+ * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
+ *
+ * \param ctx MD2 context
+ * \param output MD2 checksum result
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
+ unsigned char output[16] );
+
+/**
+ * \brief MD2 process data block (internal use only)
+ *
+ * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
+ *
+ * \param ctx MD2 context
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_MD2_ALT */
+
+#endif /* MBEDTLS_MD2_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Output = MD2( input buffer )
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output MD2 checksum result
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md2_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[16] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Output = MD2( input buffer )
+ *
+ * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output MD2 checksum result
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[16] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ *
+ * \warning MD2 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md2_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_md2.h */
+
+
+/********* Start of file include/mbedtls/md4.h ************/
+
+/**
+ * \file md4.h
+ *
+ * \brief MD4 message digest algorithm (hash function)
+ *
+ * \warning MD4 is considered a weak message digest and its use constitutes a
+ * security risk. We recommend considering stronger message digests
+ * instead.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ *
+ */
+#ifndef MBEDTLS_MD4_H
+#define MBEDTLS_MD4_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
+
+#if !defined(MBEDTLS_MD4_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief MD4 context structure
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+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 */
+}
+mbedtls_md4_context;
+
+/**
+ * \brief Initialize MD4 context
+ *
+ * \param ctx MD4 context to be initialized
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md4_init( mbedtls_md4_context *ctx );
+
+/**
+ * \brief Clear MD4 context
+ *
+ * \param ctx MD4 context to be cleared
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md4_free( mbedtls_md4_context *ctx );
+
+/**
+ * \brief Clone (the state of) an MD4 context
+ *
+ * \param dst The destination context
+ * \param src The context to be cloned
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_md4_clone( mbedtls_md4_context *dst,
+ const mbedtls_md4_context *src );
+
+/**
+ * \brief MD4 context setup
+ *
+ * \param ctx context to be initialized
+ *
+ * \return 0 if successful
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ */
+int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
+
+/**
+ * \brief MD4 process buffer
+ *
+ * \param ctx MD4 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \return 0 if successful
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief MD4 final digest
+ *
+ * \param ctx MD4 context
+ * \param output MD4 checksum result
+ *
+ * \return 0 if successful
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
+ unsigned char output[16] );
+
+/**
+ * \brief MD4 process data block (internal use only)
+ *
+ * \param ctx MD4 context
+ * \param data buffer holding one block of data
+ *
+ * \return 0 if successful
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
+ const unsigned char data[64] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief MD4 context setup
+ *
+ * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
+ *
+ * \param ctx context to be initialized
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
+
+/**
+ * \brief MD4 process buffer
+ *
+ * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
+ *
+ * \param ctx MD4 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief MD4 final digest
+ *
+ * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
+ *
+ * \param ctx MD4 context
+ * \param output MD4 checksum result
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
+ unsigned char output[16] );
+
+/**
+ * \brief MD4 process data block (internal use only)
+ *
+ * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
+ *
+ * \param ctx MD4 context
+ * \param data buffer holding one block of data
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
+ const unsigned char data[64] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_MD4_ALT */
+
+#endif /* MBEDTLS_MD4_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Output = MD4( input buffer )
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output MD4 checksum result
+ *
+ * \return 0 if successful
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md4_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[16] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Output = MD4( input buffer )
+ *
+ * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output MD4 checksum result
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[16] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ *
+ * \warning MD4 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_md4_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_md4.h */
+
+
+/********* Start of file include/mbedtls/rsa.h ************/
+
+/**
+ * \file rsa.h
+ *
+ * \brief The RSA public-key cryptosystem.
+ *
+ * For more information, see Public-Key Cryptography Standards (PKCS)
+ * #1 v1.5: RSA Encryption and Public-Key Cryptography Standards
+ * (PKCS) #1 v2.1: RSA Cryptography Specifications.
+ *
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_RSA_H
+#define MBEDTLS_RSA_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+/*
+ * RSA Error codes
+ */
+#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
+#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
+#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the validity check of the library. */
+#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
+#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
+#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
+#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */
+#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */
+#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /**< The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */
+#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /**< RSA hardware accelerator failed. */
+
+/*
+ * RSA constants
+ */
+#define MBEDTLS_RSA_PUBLIC 0 /**< Request private key operation. */
+#define MBEDTLS_RSA_PRIVATE 1 /**< Request public key operation. */
+
+#define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS-1 v1.5 encoding. */
+#define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS-1 v2.1 encoding. */
+
+#define MBEDTLS_RSA_SIGN 1 /**< Identifier for RSA signature operations. */
+#define MBEDTLS_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */
+
+#define MBEDTLS_RSA_SALT_LEN_ANY -1
+
+/*
+ * The above constants may be used even if the RSA module is compile out,
+ * eg for alternative (PKCS#11) RSA implemenations in the PK layers.
+ */
+
+#if !defined(MBEDTLS_RSA_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The RSA context structure.
+ *
+ * \note Direct manipulation of the members of this structure
+ * is deprecated. All manipulation should instead be done through
+ * the public interface functions.
+ */
+typedef struct
+{
+ int ver; /*!< Always 0.*/
+ size_t len; /*!< The size of \p N in Bytes. */
+
+ mbedtls_mpi N; /*!< The public modulus. */
+ mbedtls_mpi E; /*!< The public exponent. */
+
+ mbedtls_mpi D; /*!< The private exponent. */
+ mbedtls_mpi P; /*!< The first prime factor. */
+ mbedtls_mpi Q; /*!< The second prime factor. */
+
+ mbedtls_mpi DP; /*!< \p D % (P - 1) */
+ mbedtls_mpi DQ; /*!< \p D % (Q - 1) */
+ mbedtls_mpi QP; /*!< 1 / (Q % P) */
+
+ mbedtls_mpi RN; /*!< cached R^2 mod \p N */
+
+ mbedtls_mpi RP; /*!< cached R^2 mod \p P */
+ mbedtls_mpi RQ; /*!< cached R^2 mod \p Q */
+
+ mbedtls_mpi Vi; /*!< The cached blinding value. */
+ mbedtls_mpi Vf; /*!< The cached un-blinding value. */
+
+ int padding; /*!< Selects padding mode:
+ #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
+ #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
+ int hash_id; /*!< Hash identifier of mbedtls_md_type_t type,
+ as specified in md.h for use in the MGF
+ mask generating function used in the
+ EME-OAEP and EMSA-PSS encodings. */
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex. */
+#endif
+}
+mbedtls_rsa_context;
+
+/**
+ * \brief This function initializes an RSA context.
+ *
+ * \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
+ * encryption scheme and the RSASSA-PSS signature scheme.
+ *
+ * \param ctx The RSA context to initialize.
+ * \param padding Selects padding mode: #MBEDTLS_RSA_PKCS_V15 or
+ * #MBEDTLS_RSA_PKCS_V21.
+ * \param hash_id The hash identifier of #mbedtls_md_type_t type, if
+ * \p padding is #MBEDTLS_RSA_PKCS_V21.
+ *
+ * \note The \p hash_id parameter is ignored when using
+ * #MBEDTLS_RSA_PKCS_V15 padding.
+ *
+ * \note The choice of padding mode is strictly enforced for private key
+ * operations, since there might be security concerns in
+ * mixing padding modes. For public key operations it is
+ * a default value, which can be overriden by calling specific
+ * \c rsa_rsaes_xxx or \c rsa_rsassa_xxx functions.
+ *
+ * \note The hash selected in \p hash_id is always used for OEAP
+ * encryption. For PSS signatures, it is always used for
+ * making signatures, but can be overriden for verifying them.
+ * If set to #MBEDTLS_MD_NONE, it is always overriden.
+ */
+void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
+ int padding,
+ int hash_id);
+
+/**
+ * \brief This function imports a set of core parameters into an
+ * RSA context.
+ *
+ * \param ctx The initialized RSA context to store the parameters in.
+ * \param N The RSA modulus, or NULL.
+ * \param P The first prime factor of \p N, or NULL.
+ * \param Q The second prime factor of \p N, or NULL.
+ * \param D The private exponent, or NULL.
+ * \param E The public exponent, or NULL.
+ *
+ * \note This function can be called multiple times for successive
+ * imports, if the parameters are not simultaneously present.
+ *
+ * Any sequence of calls to this function should be followed
+ * by a call to mbedtls_rsa_complete(), which checks and
+ * completes the provided information to a ready-for-use
+ * public or private RSA key.
+ *
+ * \note See mbedtls_rsa_complete() for more information on which
+ * parameters are necessary to set up a private or public
+ * RSA key.
+ *
+ * \note The imported parameters are copied and need not be preserved
+ * for the lifetime of the RSA context being set up.
+ *
+ * \return \c 0 on success, or a non-zero error code on failure.
+ */
+int mbedtls_rsa_import( mbedtls_rsa_context *ctx,
+ const mbedtls_mpi *N,
+ const mbedtls_mpi *P, const mbedtls_mpi *Q,
+ const mbedtls_mpi *D, const mbedtls_mpi *E );
+
+/**
+ * \brief This function imports core RSA parameters, in raw big-endian
+ * binary format, into an RSA context.
+ *
+ * \param ctx The initialized RSA context to store the parameters in.
+ * \param N The RSA modulus, or NULL.
+ * \param N_len The Byte length of \p N, ignored if \p N == NULL.
+ * \param P The first prime factor of \p N, or NULL.
+ * \param P_len The Byte length of \p P, ignored if \p P == NULL.
+ * \param Q The second prime factor of \p N, or NULL.
+ * \param Q_len The Byte length of \p Q, ignored if \p Q == NULL.
+ * \param D The private exponent, or NULL.
+ * \param D_len The Byte length of \p D, ignored if \p D == NULL.
+ * \param E The public exponent, or NULL.
+ * \param E_len The Byte length of \p E, ignored if \p E == NULL.
+ *
+ * \note This function can be called multiple times for successive
+ * imports, if the parameters are not simultaneously present.
+ *
+ * Any sequence of calls to this function should be followed
+ * by a call to mbedtls_rsa_complete(), which checks and
+ * completes the provided information to a ready-for-use
+ * public or private RSA key.
+ *
+ * \note See mbedtls_rsa_complete() for more information on which
+ * parameters are necessary to set up a private or public
+ * RSA key.
+ *
+ * \note The imported parameters are copied and need not be preserved
+ * for the lifetime of the RSA context being set up.
+ *
+ * \return \c 0 on success, or a non-zero error code on failure.
+ */
+int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx,
+ unsigned char const *N, size_t N_len,
+ unsigned char const *P, size_t P_len,
+ unsigned char const *Q, size_t Q_len,
+ unsigned char const *D, size_t D_len,
+ unsigned char const *E, size_t E_len );
+
+/**
+ * \brief This function completes an RSA context from
+ * a set of imported core parameters.
+ *
+ * To setup an RSA public key, precisely \p N and \p E
+ * must have been imported.
+ *
+ * To setup an RSA private key, sufficient information must
+ * be present for the other parameters to be derivable.
+ *
+ * The default implementation supports the following:
+ * - Derive \p P, \p Q from \p N, \p D, \p E.
+ * - Derive \p N, \p D from \p P, \p Q, \p E.
+ * Alternative implementations need not support these.
+ *
+ * If this function runs successfully, it guarantees that
+ * the RSA context can be used for RSA operations without
+ * the risk of failure or crash.
+ *
+ * \param ctx The initialized RSA context holding imported parameters.
+ *
+ * \return \c 0 on success, or #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the
+ * attempted derivations failed.
+ *
+ * \warning This function need not perform consistency checks
+ * for the imported parameters. In particular, parameters that
+ * are not needed by the implementation might be silently
+ * discarded and left unchecked. To check the consistency
+ * of the key material, see mbedtls_rsa_check_privkey().
+ *
+ */
+int mbedtls_rsa_complete( mbedtls_rsa_context *ctx );
+
+/**
+ * \brief This function exports the core parameters of an RSA key.
+ *
+ * If this function runs successfully, the non-NULL buffers
+ * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
+ * written, with additional unused space filled leading by
+ * zero Bytes.
+ *
+ * Possible reasons for returning
+ * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION:
+ * - An alternative RSA implementation is in use, which
+ * stores the key externally, and either cannot or should
+ * not export it into RAM.
+ * - A SW or HW implementation might not support a certain
+ * deduction. For example, \p P, \p Q from \p N, \p D,
+ * and \p E if the former are not part of the
+ * implementation.
+ *
+ * If the function fails due to an unsupported operation,
+ * the RSA context stays intact and remains usable.
+ *
+ * \param ctx The initialized RSA context.
+ * \param N The MPI to hold the RSA modulus, or NULL.
+ * \param P The MPI to hold the first prime factor of \p N, or NULL.
+ * \param Q The MPI to hold the second prime factor of \p N, or NULL.
+ * \param D The MPI to hold the private exponent, or NULL.
+ * \param E The MPI to hold the public exponent, or NULL.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION if exporting the
+ * requested parameters cannot be done due to missing
+ * functionality or because of security policies,
+ * or a non-zero return code on any other failure.
+ *
+ */
+int mbedtls_rsa_export( const mbedtls_rsa_context *ctx,
+ mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q,
+ mbedtls_mpi *D, mbedtls_mpi *E );
+
+/**
+ * \brief This function exports core parameters of an RSA key
+ * in raw big-endian binary format.
+ *
+ * If this function runs successfully, the non-NULL buffers
+ * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
+ * written, with additional unused space filled leading by
+ * zero Bytes.
+ *
+ * Possible reasons for returning
+ * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION:
+ * - An alternative RSA implementation is in use, which
+ * stores the key externally, and either cannot or should
+ * not export it into RAM.
+ * - A SW or HW implementation might not support a certain
+ * deduction. For example, \p P, \p Q from \p N, \p D,
+ * and \p E if the former are not part of the
+ * implementation.
+ * If the function fails due to an unsupported operation,
+ * the RSA context stays intact and remains usable.
+ *
+ * \param ctx The initialized RSA context.
+ * \param N The Byte array to store the RSA modulus, or NULL.
+ * \param N_len The size of the buffer for the modulus.
+ * \param P The Byte array to hold the first prime factor of \p N, or
+ * NULL.
+ * \param P_len The size of the buffer for the first prime factor.
+ * \param Q The Byte array to hold the second prime factor of \p N, or
+ NULL.
+ * \param Q_len The size of the buffer for the second prime factor.
+ * \param D The Byte array to hold the private exponent, or NULL.
+ * \param D_len The size of the buffer for the private exponent.
+ * \param E The Byte array to hold the public exponent, or NULL.
+ * \param E_len The size of the buffer for the public exponent.
+ *
+ * \note The length fields are ignored if the corresponding
+ * buffer pointers are NULL.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION if exporting the
+ * requested parameters cannot be done due to missing
+ * functionality or because of security policies,
+ * or a non-zero return code on any other failure.
+ */
+int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx,
+ unsigned char *N, size_t N_len,
+ unsigned char *P, size_t P_len,
+ unsigned char *Q, size_t Q_len,
+ unsigned char *D, size_t D_len,
+ unsigned char *E, size_t E_len );
+
+/**
+ * \brief This function exports CRT parameters of a private RSA key.
+ *
+ * \param ctx The initialized RSA context.
+ * \param DP The MPI to hold D modulo P-1, or NULL.
+ * \param DQ The MPI to hold D modulo Q-1, or NULL.
+ * \param QP The MPI to hold modular inverse of Q modulo P, or NULL.
+ *
+ * \return \c 0 on success, non-zero error code otherwise.
+ *
+ * \note Alternative RSA implementations not using CRT-parameters
+ * internally can implement this function based on
+ * mbedtls_rsa_deduce_opt().
+ *
+ */
+int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx,
+ mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP );
+
+/**
+ * \brief This function sets padding for an already initialized RSA
+ * context. See mbedtls_rsa_init() for details.
+ *
+ * \param ctx The RSA context to be set.
+ * \param padding Selects padding mode: #MBEDTLS_RSA_PKCS_V15 or
+ * #MBEDTLS_RSA_PKCS_V21.
+ * \param hash_id The #MBEDTLS_RSA_PKCS_V21 hash identifier.
+ */
+void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
+ int hash_id);
+
+/**
+ * \brief This function retrieves the length of RSA modulus in Bytes.
+ *
+ * \param ctx The initialized RSA context.
+ *
+ * \return The length of the RSA modulus in Bytes.
+ *
+ */
+size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx );
+
+/**
+ * \brief This function generates an RSA keypair.
+ *
+ * \param ctx The RSA context used to hold the key.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ * \param nbits The size of the public key in bits.
+ * \param exponent The public exponent. For example, 65537.
+ *
+ * \note mbedtls_rsa_init() must be called before this function,
+ * to set up the RSA context.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ on failure.
+ */
+int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ unsigned int nbits, int exponent );
+
+/**
+ * \brief This function checks if a context contains at least an RSA
+ * public key.
+ *
+ * If the function runs successfully, it is guaranteed that
+ * enough information is present to perform an RSA public key
+ * operation using mbedtls_rsa_public().
+ *
+ * \param ctx The RSA context to check.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ */
+int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx );
+
+/**
+ * \brief This function checks if a context contains an RSA private key
+ * and perform basic consistency checks.
+ *
+ * \param ctx The RSA context to check.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code on
+ * failure.
+ *
+ * \note The consistency checks performed by this function not only
+ * ensure that mbedtls_rsa_private() can be called successfully
+ * on the given context, but that the various parameters are
+ * mutually consistent with high probability, in the sense that
+ * mbedtls_rsa_public() and mbedtls_rsa_private() are inverses.
+ *
+ * \warning This function should catch accidental misconfigurations
+ * like swapping of parameters, but it cannot establish full
+ * trust in neither the quality nor the consistency of the key
+ * material that was used to setup the given RSA context:
+ * - Consistency: Imported parameters that are irrelevant
+ * for the implementation might be silently dropped. If dropped,
+ * the current function does not have access to them,
+ * and therefore cannot check them. See mbedtls_rsa_complete().
+ * If you want to check the consistency of the entire
+ * content of an PKCS1-encoded RSA private key, for example, you
+ * should use mbedtls_rsa_validate_params() before setting
+ * up the RSA context.
+ * Additionally, if the implementation performs empirical checks,
+ * these checks substantiate but do not guarantee consistency.
+ * - Quality: This function is not expected to perform
+ * extended quality assessments like checking that the prime
+ * factors are safe. Additionally, it is the responsibility of the
+ * user to ensure the trustworthiness of the source of his RSA
+ * parameters, which goes beyond what is effectively checkable
+ * by the library.
+ */
+int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx );
+
+/**
+ * \brief This function checks a public-private RSA key pair.
+ *
+ * It checks each of the contexts, and makes sure they match.
+ *
+ * \param pub The RSA context holding the public key.
+ * \param prv The RSA context holding the private key.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ */
+int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub,
+ const mbedtls_rsa_context *prv );
+
+/**
+ * \brief This function performs an RSA public key operation.
+ *
+ * \param ctx The RSA context.
+ * \param input The input buffer.
+ * \param output The output buffer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note This function does not handle message padding.
+ *
+ * \note Make sure to set \p input[0] = 0 or ensure that
+ * input is smaller than \p N.
+ *
+ * \note The input and output buffers must be large
+ * enough. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function performs an RSA private key operation.
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Needed for blinding.
+ * \param p_rng The RNG parameter.
+ * \param input The input buffer.
+ * \param output The output buffer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The input and output buffers must be large
+ * enough. For example, 128 Bytes if RSA-1024 is used.
+ *
+ * \note Blinding is used if and only if a PRNG is provided.
+ *
+ * \note If blinding is used, both the base of exponentation
+ * and the exponent are blinded, providing protection
+ * against some side-channel attacks.
+ *
+ * \warning It is deprecated and a security risk to not provide
+ * a PRNG here and thereby prevent the use of blinding.
+ * Future versions of the library may enforce the presence
+ * of a PRNG.
+ *
+ */
+int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function adds the message padding, then performs an RSA
+ * operation.
+ *
+ * It is the generic wrapper for performing a PKCS#1 encryption
+ * operation using the \p mode from the context.
+ *
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Needed for padding, PKCS#1 v2.1
+ * encoding, and #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param ilen The length of the plaintext.
+ * \param input The buffer holding the data to encrypt.
+ * \param output The buffer used to hold the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PUBLIC.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The input and output buffers must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode, size_t ilen,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function performs a PKCS#1 v1.5 encryption operation
+ * (RSAES-PKCS1-v1_5-ENCRYPT).
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Needed for padding and
+ * #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param ilen The length of the plaintext.
+ * \param input The buffer holding the data to encrypt.
+ * \param output The buffer used to hold the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PUBLIC.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The output buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode, size_t ilen,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function performs a PKCS#1 v2.1 OAEP encryption
+ * operation (RSAES-OAEP-ENCRYPT).
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Needed for padding and PKCS#1 v2.1
+ * encoding and #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param label The buffer holding the custom label to use.
+ * \param label_len The length of the label.
+ * \param ilen The length of the plaintext.
+ * \param input The buffer holding the data to encrypt.
+ * \param output The buffer used to hold the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PUBLIC.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The output buffer must be as large as the size
+ * of ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ const unsigned char *label, size_t label_len,
+ size_t ilen,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function performs an RSA operation, then removes the
+ * message padding.
+ *
+ * It is the generic wrapper for performing a PKCS#1 decryption
+ * operation using the \p mode from the context.
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param olen The length of the plaintext.
+ * \param input The buffer holding the encrypted data.
+ * \param output The buffer used to hold the plaintext.
+ * \param output_max_len The maximum length of the output buffer.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PRIVATE.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The output buffer length \c output_max_len should be
+ * as large as the size \p ctx->len of \p ctx->N (for example,
+ * 128 Bytes if RSA-1024 is used) to be able to hold an
+ * arbitrary decrypted message. If it is not large enough to
+ * hold the decryption of the particular ciphertext provided,
+ * the function returns \c MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
+ *
+ * \note The input buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode, size_t *olen,
+ const unsigned char *input,
+ unsigned char *output,
+ size_t output_max_len );
+
+/**
+ * \brief This function performs a PKCS#1 v1.5 decryption
+ * operation (RSAES-PKCS1-v1_5-DECRYPT).
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param olen The length of the plaintext.
+ * \param input The buffer holding the encrypted data.
+ * \param output The buffer to hold the plaintext.
+ * \param output_max_len The maximum length of the output buffer.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PRIVATE.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The output buffer length \c output_max_len should be
+ * as large as the size \p ctx->len of \p ctx->N, for example,
+ * 128 Bytes if RSA-1024 is used, to be able to hold an
+ * arbitrary decrypted message. If it is not large enough to
+ * hold the decryption of the particular ciphertext provided,
+ * the function returns #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
+ *
+ * \note The input buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode, size_t *olen,
+ const unsigned char *input,
+ unsigned char *output,
+ size_t output_max_len );
+
+/**
+ * \brief This function performs a PKCS#1 v2.1 OAEP decryption
+ * operation (RSAES-OAEP-DECRYPT).
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param label The buffer holding the custom label to use.
+ * \param label_len The length of the label.
+ * \param olen The length of the plaintext.
+ * \param input The buffer holding the encrypted data.
+ * \param output The buffer to hold the plaintext.
+ * \param output_max_len The maximum length of the output buffer.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PRIVATE.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The output buffer length \c output_max_len should be
+ * as large as the size \p ctx->len of \p ctx->N, for
+ * example, 128 Bytes if RSA-1024 is used, to be able to
+ * hold an arbitrary decrypted message. If it is not
+ * large enough to hold the decryption of the particular
+ * ciphertext provided, the function returns
+ * #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
+ *
+ * \note The input buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ const unsigned char *label, size_t label_len,
+ size_t *olen,
+ const unsigned char *input,
+ unsigned char *output,
+ size_t output_max_len );
+
+/**
+ * \brief This function performs a private RSA operation to sign
+ * a message digest using PKCS#1.
+ *
+ * It is the generic wrapper for performing a PKCS#1
+ * signature using the \p mode from the context.
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Needed for PKCS#1 v2.1 encoding and for
+ * #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param sig The buffer to hold the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PRIVATE.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 if the signing operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ *
+ * \note For PKCS#1 v2.1 encoding, see comments on
+ * mbedtls_rsa_rsassa_pss_sign() for details on
+ * \p md_alg and \p hash_id.
+ */
+int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ unsigned char *sig );
+
+/**
+ * \brief This function performs a PKCS#1 v1.5 signature
+ * operation (RSASSA-PKCS1-v1_5-SIGN).
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param sig The buffer to hold the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PRIVATE.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 if the signing operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ unsigned char *sig );
+
+/**
+ * \brief This function performs a PKCS#1 v2.1 PSS signature
+ * operation (RSASSA-PSS-SIGN).
+ *
+ * \param ctx The RSA context.
+ * \param f_rng The RNG function. Needed for PKCS#1 v2.1 encoding and for
+ * #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param sig The buffer to hold the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PRIVATE.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 if the signing operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ *
+ * \note The \p hash_id in the RSA context is the one used for the
+ * encoding. \p md_alg in the function call is the type of hash
+ * that is encoded. According to RFC-3447: Public-Key
+ * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
+ * Specifications it is advised to keep both hashes the
+ * same.
+ */
+int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ unsigned char *sig );
+
+/**
+ * \brief This function performs a public RSA operation and checks
+ * the message digest.
+ *
+ * This is the generic wrapper for performing a PKCS#1
+ * verification using the mode from the context.
+ *
+ * \param ctx The RSA public key context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param sig The buffer holding the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * set to #MBEDTLS_RSA_PUBLIC.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 if the verify operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ *
+ * \note For PKCS#1 v2.1 encoding, see comments on
+ * mbedtls_rsa_rsassa_pss_verify() about \p md_alg and
+ * \p hash_id.
+ */
+int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ const unsigned char *sig );
+
+/**
+ * \brief This function performs a PKCS#1 v1.5 verification
+ * operation (RSASSA-PKCS1-v1_5-VERIFY).
+ *
+ * \param ctx The RSA public key context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param sig The buffer holding the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * set to #MBEDTLS_RSA_PUBLIC.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 if the verify operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ */
+int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ const unsigned char *sig );
+
+/**
+ * \brief This function performs a PKCS#1 v2.1 PSS verification
+ * operation (RSASSA-PSS-VERIFY).
+ *
+ * The hash function for the MGF mask generating function
+ * is that specified in the RSA context.
+ *
+ * \param ctx The RSA public key context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param sig The buffer holding the ciphertext.
+ *
+ * \deprecated It is deprecated and discouraged to call this function
+ * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
+ * are likely to remove the \p mode argument and have it
+ * implicitly set to #MBEDTLS_RSA_PUBLIC.
+ *
+ * \note Alternative implementations of RSA need not support
+ * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
+ * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
+ *
+ * \return \c 0 if the verify operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ *
+ * \note The \p hash_id in the RSA context is the one used for the
+ * verification. \p md_alg in the function call is the type of
+ * hash that is verified. According to RFC-3447: Public-Key
+ * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
+ * Specifications it is advised to keep both hashes the
+ * same. If \p hash_id in the RSA context is unset,
+ * the \p md_alg from the function call is used.
+ */
+int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ const unsigned char *sig );
+
+/**
+ * \brief This function performs a PKCS#1 v2.1 PSS verification
+ * operation (RSASSA-PSS-VERIFY).
+ *
+ * The hash function for the MGF mask generating function
+ * is that specified in \p mgf1_hash_id.
+ *
+ * \param ctx The RSA public key context.
+ * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
+ * \param p_rng The RNG parameter.
+ * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
+ * \param md_alg The message-digest algorithm used to hash the original data.
+ * Use #MBEDTLS_MD_NONE for signing raw data.
+ * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
+ * \param hash The buffer holding the message digest.
+ * \param mgf1_hash_id The message digest used for mask generation.
+ * \param expected_salt_len The length of the salt used in padding. Use
+ * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
+ * \param sig The buffer holding the ciphertext.
+ *
+ * \return \c 0 if the verify operation was successful,
+ * or an \c MBEDTLS_ERR_RSA_XXX error code
+ * on failure.
+ *
+ * \note The \p sig buffer must be as large as the size
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
+ *
+ * \note The \p hash_id in the RSA context is ignored.
+ */
+int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ mbedtls_md_type_t mgf1_hash_id,
+ int expected_salt_len,
+ const unsigned char *sig );
+
+/**
+ * \brief This function copies the components of an RSA context.
+ *
+ * \param dst The destination context.
+ * \param src The source context.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure.
+ */
+int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src );
+
+/**
+ * \brief This function frees the components of an RSA key.
+ *
+ * \param ctx The RSA Context to free.
+ */
+void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_RSA_ALT */
+
+#endif /* MBEDTLS_RSA_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The RSA checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_rsa_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* rsa.h */
+
+
+/********* Start of file include/mbedtls/rsa_internal.h ************/
+
+/**
+ * \file rsa_internal.h
+ *
+ * \brief Context-independent RSA helper functions
+ */
+/*
+ * Copyright (C) 2006-2017, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ *
+ *
+ * This file declares some RSA-related helper functions useful when
+ * implementing the RSA interface. They are public and provided in a
+ * separate compilation unit in order to make it easy for designers of
+ * alternative RSA implementations to use them in their code, as it is
+ * conceived that the functionality they provide will be necessary
+ * for most complete implementations.
+ *
+ * End-users of Mbed TLS not intending to re-implement the RSA functionality
+ * are not expected to get into the need of making use of these functions directly,
+ * but instead should be able to use the functions declared in rsa.h.
+ *
+ * There are two classes of helper functions:
+ * (1) Parameter-generating helpers. These are:
+ * - mbedtls_rsa_deduce_primes
+ * - mbedtls_rsa_deduce_private_exponent
+ * - mbedtls_rsa_deduce_crt
+ * Each of these functions takes a set of core RSA parameters
+ * and generates some other, or CRT related parameters.
+ * (2) Parameter-checking helpers. These are:
+ * - mbedtls_rsa_validate_params
+ * - mbedtls_rsa_validate_crt
+ * They take a set of core or CRT related RSA parameters
+ * and check their validity.
+ *
+ */
+
+#ifndef MBEDTLS_RSA_INTERNAL_H
+#define MBEDTLS_RSA_INTERNAL_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \brief Compute RSA prime moduli P, Q from public modulus N=PQ
+ * and a pair of private and public key.
+ *
+ * \note This is a 'static' helper function not operating on
+ * an RSA context. Alternative implementations need not
+ * overwrite it.
+ *
+ * \param N RSA modulus N = PQ, with P, Q to be found
+ * \param E RSA public exponent
+ * \param D RSA private exponent
+ * \param P Pointer to MPI holding first prime factor of N on success
+ * \param Q Pointer to MPI holding second prime factor of N on success
+ *
+ * \return
+ * - 0 if successful. In this case, P and Q constitute a
+ * factorization of N.
+ * - A non-zero error code otherwise.
+ *
+ * \note It is neither checked that P, Q are prime nor that
+ * D, E are modular inverses wrt. P-1 and Q-1. For that,
+ * use the helper function \c mbedtls_rsa_validate_params.
+ *
+ */
+int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, mbedtls_mpi const *E,
+ mbedtls_mpi const *D,
+ mbedtls_mpi *P, mbedtls_mpi *Q );
+
+/**
+ * \brief Compute RSA private exponent from
+ * prime moduli and public key.
+ *
+ * \note This is a 'static' helper function not operating on
+ * an RSA context. Alternative implementations need not
+ * overwrite it.
+ *
+ * \param P First prime factor of RSA modulus
+ * \param Q Second prime factor of RSA modulus
+ * \param E RSA public exponent
+ * \param D Pointer to MPI holding the private exponent on success.
+ *
+ * \return
+ * - 0 if successful. In this case, D is set to a simultaneous
+ * modular inverse of E modulo both P-1 and Q-1.
+ * - A non-zero error code otherwise.
+ *
+ * \note This function does not check whether P and Q are primes.
+ *
+ */
+int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P,
+ mbedtls_mpi const *Q,
+ mbedtls_mpi const *E,
+ mbedtls_mpi *D );
+
+
+/**
+ * \brief Generate RSA-CRT parameters
+ *
+ * \note This is a 'static' helper function not operating on
+ * an RSA context. Alternative implementations need not
+ * overwrite it.
+ *
+ * \param P First prime factor of N
+ * \param Q Second prime factor of N
+ * \param D RSA private exponent
+ * \param DP Output variable for D modulo P-1
+ * \param DQ Output variable for D modulo Q-1
+ * \param QP Output variable for the modular inverse of Q modulo P.
+ *
+ * \return 0 on success, non-zero error code otherwise.
+ *
+ * \note This function does not check whether P, Q are
+ * prime and whether D is a valid private exponent.
+ *
+ */
+int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
+ const mbedtls_mpi *D, mbedtls_mpi *DP,
+ mbedtls_mpi *DQ, mbedtls_mpi *QP );
+
+
+/**
+ * \brief Check validity of core RSA parameters
+ *
+ * \note This is a 'static' helper function not operating on
+ * an RSA context. Alternative implementations need not
+ * overwrite it.
+ *
+ * \param N RSA modulus N = PQ
+ * \param P First prime factor of N
+ * \param Q Second prime factor of N
+ * \param D RSA private exponent
+ * \param E RSA public exponent
+ * \param f_rng PRNG to be used for primality check, or NULL
+ * \param p_rng PRNG context for f_rng, or NULL
+ *
+ * \return
+ * - 0 if the following conditions are satisfied
+ * if all relevant parameters are provided:
+ * - P prime if f_rng != NULL (%)
+ * - Q prime if f_rng != NULL (%)
+ * - 1 < N = P * Q
+ * - 1 < D, E < N
+ * - D and E are modular inverses modulo P-1 and Q-1
+ * (%) This is only done if MBEDTLS_GENPRIME is defined.
+ * - A non-zero error code otherwise.
+ *
+ * \note The function can be used with a restricted set of arguments
+ * to perform specific checks only. E.g., calling it with
+ * (-,P,-,-,-) and a PRNG amounts to a primality check for P.
+ */
+int mbedtls_rsa_validate_params( const mbedtls_mpi *N, const mbedtls_mpi *P,
+ const mbedtls_mpi *Q, const mbedtls_mpi *D,
+ const mbedtls_mpi *E,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Check validity of RSA CRT parameters
+ *
+ * \note This is a 'static' helper function not operating on
+ * an RSA context. Alternative implementations need not
+ * overwrite it.
+ *
+ * \param P First prime factor of RSA modulus
+ * \param Q Second prime factor of RSA modulus
+ * \param D RSA private exponent
+ * \param DP MPI to check for D modulo P-1
+ * \param DQ MPI to check for D modulo P-1
+ * \param QP MPI to check for the modular inverse of Q modulo P.
+ *
+ * \return
+ * - 0 if the following conditions are satisfied:
+ * - D = DP mod P-1 if P, D, DP != NULL
+ * - Q = DQ mod P-1 if P, D, DQ != NULL
+ * - QP = Q^-1 mod P if P, Q, QP != NULL
+ * - \c MBEDTLS_ERR_RSA_KEY_CHECK_FAILED if check failed,
+ * potentially including \c MBEDTLS_ERR_MPI_XXX if some
+ * MPI calculations failed.
+ * - \c MBEDTLS_ERR_RSA_BAD_INPUT_DATA if insufficient
+ * data was provided to check DP, DQ or QP.
+ *
+ * \note The function can be used with a restricted set of arguments
+ * to perform specific checks only. E.g., calling it with the
+ * parameters (P, -, D, DP, -, -) will check DP = D mod P-1.
+ */
+int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
+ const mbedtls_mpi *D, const mbedtls_mpi *DP,
+ const mbedtls_mpi *DQ, const mbedtls_mpi *QP );
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* rsa_internal.h */
+
+
+/********* Start of file include/mbedtls/asn1.h ************/
+
+/**
+ * \file asn1.h
+ *
+ * \brief Generic ASN.1 parsing
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ASN1_H
+#define MBEDTLS_ASN1_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#if defined(MBEDTLS_BIGNUM_C)
+
+#endif
+
+/**
+ * \addtogroup asn1_module
+ * \{
+ */
+
+/**
+ * \name ASN1 Error codes
+ * These error codes are OR'ed to X509 error codes for
+ * higher error granularity.
+ * ASN1 is a standard to specify data structures.
+ * \{
+ */
+#define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */
+#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */
+#define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */
+#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */
+#define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */
+#define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A /**< Memory allocation failed */
+#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */
+
+/* \} name */
+
+/**
+ * \name DER constants
+ * These constants comply with the DER encoded ASN.1 type tags.
+ * DER encoding uses hexadecimal representation.
+ * An example DER sequence is:\n
+ * - 0x02 -- tag indicating INTEGER
+ * - 0x01 -- length in octets
+ * - 0x05 -- value
+ * Such sequences are typically read into \c ::mbedtls_x509_buf.
+ * \{
+ */
+#define MBEDTLS_ASN1_BOOLEAN 0x01
+#define MBEDTLS_ASN1_INTEGER 0x02
+#define MBEDTLS_ASN1_BIT_STRING 0x03
+#define MBEDTLS_ASN1_OCTET_STRING 0x04
+#define MBEDTLS_ASN1_NULL 0x05
+#define MBEDTLS_ASN1_OID 0x06
+#define MBEDTLS_ASN1_UTF8_STRING 0x0C
+#define MBEDTLS_ASN1_SEQUENCE 0x10
+#define MBEDTLS_ASN1_SET 0x11
+#define MBEDTLS_ASN1_PRINTABLE_STRING 0x13
+#define MBEDTLS_ASN1_T61_STRING 0x14
+#define MBEDTLS_ASN1_IA5_STRING 0x16
+#define MBEDTLS_ASN1_UTC_TIME 0x17
+#define MBEDTLS_ASN1_GENERALIZED_TIME 0x18
+#define MBEDTLS_ASN1_UNIVERSAL_STRING 0x1C
+#define MBEDTLS_ASN1_BMP_STRING 0x1E
+#define MBEDTLS_ASN1_PRIMITIVE 0x00
+#define MBEDTLS_ASN1_CONSTRUCTED 0x20
+#define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80
+
+/*
+ * Bit masks for each of the components of an ASN.1 tag as specified in
+ * ITU X.690 (08/2015), section 8.1 "General rules for encoding",
+ * paragraph 8.1.2.2:
+ *
+ * Bit 8 7 6 5 1
+ * +-------+-----+------------+
+ * | Class | P/C | Tag number |
+ * +-------+-----+------------+
+ */
+#define MBEDTLS_ASN1_TAG_CLASS_MASK 0xC0
+#define MBEDTLS_ASN1_TAG_PC_MASK 0x20
+#define MBEDTLS_ASN1_TAG_VALUE_MASK 0x1F
+
+/* \} name */
+/* \} addtogroup asn1_module */
+
+/** Returns the size of the binary string, without the trailing \\0 */
+#define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1)
+
+/**
+ * Compares an mbedtls_asn1_buf structure to a reference OID.
+ *
+ * Only works for 'defined' oid_str values (MBEDTLS_OID_HMAC_SHA1), you cannot use a
+ * 'unsigned char *oid' here!
+ */
+#define MBEDTLS_OID_CMP(oid_str, oid_buf) \
+ ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \
+ memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 )
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name Functions to parse ASN.1 data structures
+ * \{
+ */
+
+/**
+ * Type-length-value structure that allows for ASN1 using DER.
+ */
+typedef struct mbedtls_asn1_buf
+{
+ int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
+ size_t len; /**< ASN1 length, in octets. */
+ unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
+}
+mbedtls_asn1_buf;
+
+/**
+ * Container for ASN1 bit strings.
+ */
+typedef struct mbedtls_asn1_bitstring
+{
+ size_t len; /**< ASN1 length, in octets. */
+ unsigned char unused_bits; /**< Number of unused bits at the end of the string */
+ unsigned char *p; /**< Raw ASN1 data for the bit string */
+}
+mbedtls_asn1_bitstring;
+
+/**
+ * Container for a sequence of ASN.1 items
+ */
+typedef struct mbedtls_asn1_sequence
+{
+ mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
+ struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
+}
+mbedtls_asn1_sequence;
+
+/**
+ * Container for a sequence or list of 'named' ASN.1 data items
+ */
+typedef struct mbedtls_asn1_named_data
+{
+ mbedtls_asn1_buf oid; /**< The object identifier. */
+ mbedtls_asn1_buf val; /**< The named value. */
+ struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
+ unsigned char next_merged; /**< Merge next item into the current one? */
+}
+mbedtls_asn1_named_data;
+
+/**
+ * \brief Get the length of an ASN.1 element.
+ * Updates the pointer to immediately behind the length.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param len The variable that will receive the value
+ *
+ * \return 0 if successful, MBEDTLS_ERR_ASN1_OUT_OF_DATA on reaching
+ * end of data, MBEDTLS_ERR_ASN1_INVALID_LENGTH if length is
+ * unparseable.
+ */
+int mbedtls_asn1_get_len( unsigned char **p,
+ const unsigned char *end,
+ size_t *len );
+
+/**
+ * \brief Get the tag and length of the tag. Check for the requested tag.
+ * Updates the pointer to immediately behind the tag and length.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param len The variable that will receive the length
+ * \param tag The expected tag
+ *
+ * \return 0 if successful, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if tag did
+ * not match requested tag, or another specific ASN.1 error code.
+ */
+int mbedtls_asn1_get_tag( unsigned char **p,
+ const unsigned char *end,
+ size_t *len, int tag );
+
+/**
+ * \brief Retrieve a boolean ASN.1 tag and its value.
+ * Updates the pointer to immediately behind the full tag.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param val The variable that will receive the value
+ *
+ * \return 0 if successful or a specific ASN.1 error code.
+ */
+int mbedtls_asn1_get_bool( unsigned char **p,
+ const unsigned char *end,
+ int *val );
+
+/**
+ * \brief Retrieve an integer ASN.1 tag and its value.
+ * Updates the pointer to immediately behind the full tag.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param val The variable that will receive the value
+ *
+ * \return 0 if successful or a specific ASN.1 error code.
+ */
+int mbedtls_asn1_get_int( unsigned char **p,
+ const unsigned char *end,
+ int *val );
+
+/**
+ * \brief Retrieve a bitstring ASN.1 tag and its value.
+ * Updates the pointer to immediately behind the full tag.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param bs The variable that will receive the value
+ *
+ * \return 0 if successful or a specific ASN.1 error code.
+ */
+int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
+ mbedtls_asn1_bitstring *bs);
+
+/**
+ * \brief Retrieve a bitstring ASN.1 tag without unused bits and its
+ * value.
+ * Updates the pointer to the beginning of the bit/octet string.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param len Length of the actual bit/octect string in bytes
+ *
+ * \return 0 if successful or a specific ASN.1 error code.
+ */
+int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
+ size_t *len );
+
+/**
+ * \brief Parses and splits an ASN.1 "SEQUENCE OF "
+ * Updated the pointer to immediately behind the full sequence tag.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param cur First variable in the chain to fill
+ * \param tag Type of sequence
+ *
+ * \return 0 if successful or a specific ASN.1 error code.
+ */
+int mbedtls_asn1_get_sequence_of( unsigned char **p,
+ const unsigned char *end,
+ mbedtls_asn1_sequence *cur,
+ int tag);
+
+#if defined(MBEDTLS_BIGNUM_C)
+/**
+ * \brief Retrieve a MPI value from an integer ASN.1 tag.
+ * Updates the pointer to immediately behind the full tag.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param X The MPI that will receive the value
+ *
+ * \return 0 if successful or a specific ASN.1 or MPI error code.
+ */
+int mbedtls_asn1_get_mpi( unsigned char **p,
+ const unsigned char *end,
+ mbedtls_mpi *X );
+#endif /* MBEDTLS_BIGNUM_C */
+
+/**
+ * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence.
+ * Updates the pointer to immediately behind the full
+ * AlgorithmIdentifier.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param alg The buffer to receive the OID
+ * \param params The buffer to receive the params (if any)
+ *
+ * \return 0 if successful or a specific ASN.1 or MPI error code.
+ */
+int mbedtls_asn1_get_alg( unsigned char **p,
+ const unsigned char *end,
+ mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params );
+
+/**
+ * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no
+ * params.
+ * Updates the pointer to immediately behind the full
+ * AlgorithmIdentifier.
+ *
+ * \param p The position in the ASN.1 data
+ * \param end End of data
+ * \param alg The buffer to receive the OID
+ *
+ * \return 0 if successful or a specific ASN.1 or MPI error code.
+ */
+int mbedtls_asn1_get_alg_null( unsigned char **p,
+ const unsigned char *end,
+ mbedtls_asn1_buf *alg );
+
+/**
+ * \brief Find a specific named_data entry in a sequence or list based on
+ * the OID.
+ *
+ * \param list The list to seek through
+ * \param oid The OID to look for
+ * \param len Size of the OID
+ *
+ * \return NULL if not found, or a pointer to the existing entry.
+ */
+mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
+ const char *oid, size_t len );
+
+/**
+ * \brief Free a mbedtls_asn1_named_data entry
+ *
+ * \param entry The named data entry to free
+ */
+void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry );
+
+/**
+ * \brief Free all entries in a mbedtls_asn1_named_data list
+ * Head will be set to NULL
+ *
+ * \param head Pointer to the head of the list of named data entries to free
+ */
+void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* asn1.h */
+
+
+/********* Start of file include/mbedtls/ecp.h ************/
+
+/**
+ * \file ecp.h
+ *
+ * \brief Elliptic curves over GF(p)
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ECP_H
+#define MBEDTLS_ECP_H
+
+
+
+/*
+ * ECP error codes
+ */
+#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */
+#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< Requested curve not available. */
+#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */
+#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */
+#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as (ephemeral) key, failed. */
+#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */
+#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< Signature is valid but shorter than the user-supplied length. */
+#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< ECP hardware accelerator failed. */
+
+#if !defined(MBEDTLS_ECP_ALT)
+/*
+ * default mbed TLS elliptic curve arithmetic implementation
+ *
+ * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
+ * alternative implementation for the whole module and it will replace this
+ * one.)
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Domain parameters (curve, subgroup and generator) identifiers.
+ *
+ * Only curves over prime fields are supported.
+ *
+ * \warning This library does not support validation of arbitrary domain
+ * parameters. Therefore, only well-known domain parameters from trusted
+ * sources should be used. See mbedtls_ecp_group_load().
+ */
+typedef enum
+{
+ MBEDTLS_ECP_DP_NONE = 0,
+ MBEDTLS_ECP_DP_SECP192R1, /*!< 192-bits NIST curve */
+ MBEDTLS_ECP_DP_SECP224R1, /*!< 224-bits NIST curve */
+ MBEDTLS_ECP_DP_SECP256R1, /*!< 256-bits NIST curve */
+ MBEDTLS_ECP_DP_SECP384R1, /*!< 384-bits NIST curve */
+ MBEDTLS_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */
+ MBEDTLS_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */
+ MBEDTLS_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */
+ MBEDTLS_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */
+ MBEDTLS_ECP_DP_CURVE25519, /*!< Curve25519 */
+ MBEDTLS_ECP_DP_SECP192K1, /*!< 192-bits "Koblitz" curve */
+ MBEDTLS_ECP_DP_SECP224K1, /*!< 224-bits "Koblitz" curve */
+ MBEDTLS_ECP_DP_SECP256K1, /*!< 256-bits "Koblitz" curve */
+} mbedtls_ecp_group_id;
+
+/**
+ * Number of supported curves (plus one for NONE).
+ *
+ * (Montgomery curves excluded for now.)
+ */
+#define MBEDTLS_ECP_DP_MAX 12
+
+/**
+ * Curve information for use by other modules
+ */
+typedef struct
+{
+ mbedtls_ecp_group_id grp_id; /*!< Internal identifier */
+ uint16_t tls_id; /*!< TLS NamedCurve identifier */
+ uint16_t bit_size; /*!< Curve size in bits */
+ const char *name; /*!< Human-friendly name */
+} mbedtls_ecp_curve_info;
+
+/**
+ * \brief ECP point structure (jacobian coordinates)
+ *
+ * \note All functions expect and return points satisfying
+ * the following condition: Z == 0 or Z == 1. (Other
+ * values of Z are used by internal functions only.)
+ * The point is zero, or "at infinity", if Z == 0.
+ * Otherwise, X and Y are its standard (affine) coordinates.
+ */
+typedef struct
+{
+ mbedtls_mpi X; /*!< the point's X coordinate */
+ mbedtls_mpi Y; /*!< the point's Y coordinate */
+ mbedtls_mpi Z; /*!< the point's Z coordinate */
+}
+mbedtls_ecp_point;
+
+/**
+ * \brief ECP group structure
+ *
+ * We consider two types of curves equations:
+ * 1. Short Weierstrass y^2 = x^3 + A x + B mod P (SEC1 + RFC 4492)
+ * 2. Montgomery, y^2 = x^3 + A x^2 + x mod P (Curve25519 + draft)
+ * In both cases, a generator G for a prime-order subgroup is fixed. In the
+ * short weierstrass, this subgroup is actually the whole curve, and its
+ * cardinal is denoted by N.
+ *
+ * In the case of Short Weierstrass curves, our code requires that N is an odd
+ * prime. (Use odd in mbedtls_ecp_mul() and prime in mbedtls_ecdsa_sign() for blinding.)
+ *
+ * In the case of Montgomery curves, we don't store A but (A + 2) / 4 which is
+ * the quantity actually used in the formulas. Also, nbits is not the size of N
+ * but the required size for private keys.
+ *
+ * If modp is NULL, reduction modulo P is done using a generic algorithm.
+ * Otherwise, it must point to a function that takes an mbedtls_mpi in the range
+ * 0..2^(2*pbits)-1 and transforms it in-place in an integer of little more
+ * than pbits, so that the integer may be efficiently brought in the 0..P-1
+ * range by a few additions or substractions. It must return 0 on success and
+ * non-zero on failure.
+ */
+typedef struct
+{
+ mbedtls_ecp_group_id id; /*!< internal group identifier */
+ mbedtls_mpi P; /*!< prime modulus of the base field */
+ mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4 */
+ mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused */
+ mbedtls_ecp_point G; /*!< generator of the (sub)group used */
+ mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */
+ size_t pbits; /*!< number of bits in P */
+ size_t nbits; /*!< number of bits in 1. P, or 2. private keys */
+ unsigned int h; /*!< internal: 1 if the constants are static */
+ int (*modp)(mbedtls_mpi *); /*!< function for fast reduction mod P */
+ int (*t_pre)(mbedtls_ecp_point *, void *); /*!< unused */
+ int (*t_post)(mbedtls_ecp_point *, void *); /*!< unused */
+ void *t_data; /*!< unused */
+ mbedtls_ecp_point *T; /*!< pre-computed points for ecp_mul_comb() */
+ size_t T_size; /*!< number for pre-computed points */
+}
+mbedtls_ecp_group;
+
+/**
+ * \brief ECP key pair structure
+ *
+ * A generic key pair that could be used for ECDSA, fixed ECDH, etc.
+ *
+ * \note Members purposefully in the same order as struc mbedtls_ecdsa_context.
+ */
+typedef struct
+{
+ mbedtls_ecp_group grp; /*!< Elliptic curve and base point */
+ mbedtls_mpi d; /*!< our secret value */
+ mbedtls_ecp_point Q; /*!< our public value */
+}
+mbedtls_ecp_keypair;
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_ECP_MAX_BITS)
+/**
+ * Maximum size of the groups (that is, of N and P)
+ */
+#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
+#endif
+
+#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
+#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
+
+#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
+/*
+ * Maximum "window" size used for point multiplication.
+ * Default: 6.
+ * Minimum value: 2. Maximum value: 7.
+ *
+ * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
+ * points used for point multiplication. This value is directly tied to EC
+ * peak memory usage, so decreasing it by one should roughly cut memory usage
+ * by two (if large curves are in use).
+ *
+ * Reduction in size may reduce speed, but larger curves are impacted first.
+ * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
+ * w-size: 6 5 4 3 2
+ * 521 145 141 135 120 97
+ * 384 214 209 198 177 146
+ * 256 320 320 303 262 226
+
+ * 224 475 475 453 398 342
+ * 192 640 640 633 587 476
+ */
+#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
+#endif /* MBEDTLS_ECP_WINDOW_SIZE */
+
+#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
+/*
+ * Trade memory for speed on fixed-point multiplication.
+ *
+ * This speeds up repeated multiplication of the generator (that is, the
+ * multiplication in ECDSA signatures, and half of the multiplications in
+ * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
+ *
+ * The cost is increasing EC peak memory usage by a factor roughly 2.
+ *
+ * Change this value to 0 to reduce peak memory usage.
+ */
+#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
+#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
+
+/* \} name SECTION: Module settings */
+
+/*
+ * Point formats, from RFC 4492's enum ECPointFormat
+ */
+#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */
+#define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format */
+
+/*
+ * Some other constants from RFC 4492
+ */
+#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */
+
+/**
+ * \brief Get the list of supported curves in order of preferrence
+ * (full information)
+ *
+ * \return A statically allocated array, the last entry is 0.
+ */
+const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
+
+/**
+ * \brief Get the list of supported curves in order of preferrence
+ * (grp_id only)
+ *
+ * \return A statically allocated array,
+ * terminated with MBEDTLS_ECP_DP_NONE.
+ */
+const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
+
+/**
+ * \brief Get curve information from an internal group identifier
+ *
+ * \param grp_id A MBEDTLS_ECP_DP_XXX value
+ *
+ * \return The associated curve information or NULL
+ */
+const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id );
+
+/**
+ * \brief Get curve information from a TLS NamedCurve value
+ *
+ * \param tls_id A MBEDTLS_ECP_DP_XXX value
+ *
+ * \return The associated curve information or NULL
+ */
+const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id );
+
+/**
+ * \brief Get curve information from a human-readable name
+ *
+ * \param name The name
+ *
+ * \return The associated curve information or NULL
+ */
+const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name );
+
+/**
+ * \brief Initialize a point (as zero)
+ */
+void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
+
+/**
+ * \brief Initialize a group (to something meaningless)
+ */
+void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
+
+/**
+ * \brief Initialize a key pair (as an invalid one)
+ */
+void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key );
+
+/**
+ * \brief Free the components of a point
+ */
+void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
+
+/**
+ * \brief Free the components of an ECP group
+ */
+void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
+
+/**
+ * \brief Free the components of a key pair
+ */
+void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
+
+/**
+ * \brief Copy the contents of point Q into P
+ *
+ * \param P Destination point
+ * \param Q Source point
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
+
+/**
+ * \brief Copy the contents of a group object
+ *
+ * \param dst Destination group
+ * \param src Source group
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src );
+
+/**
+ * \brief Set a point to zero
+ *
+ * \param pt Destination point
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
+
+/**
+ * \brief Tell if a point is zero
+ *
+ * \param pt Point to test
+ *
+ * \return 1 if point is zero, 0 otherwise
+ */
+int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
+
+/**
+ * \brief Compare two points
+ *
+ * \note This assumes the points are normalized. Otherwise,
+ * they may compare as "not equal" even if they are.
+ *
+ * \param P First point to compare
+ * \param Q Second point to compare
+ *
+ * \return 0 if the points are equal,
+ * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise
+ */
+int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P,
+ const mbedtls_ecp_point *Q );
+
+/**
+ * \brief Import a non-zero point from two ASCII strings
+ *
+ * \param P Destination point
+ * \param radix Input numeric base
+ * \param x First affine coordinate as a null-terminated string
+ * \param y Second affine coordinate as a null-terminated string
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
+ */
+int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
+ const char *x, const char *y );
+
+/**
+ * \brief Export a point into unsigned binary data
+ *
+ * \param grp Group to which the point should belong
+ * \param P Point to export
+ * \param format Point format, should be a MBEDTLS_ECP_PF_XXX macro
+ * \param olen Length of the actual output
+ * \param buf Output buffer
+ * \param buflen Length of the output buffer
+ *
+ * \return 0 if successful,
+ * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA
+ * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
+ */
+int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P,
+ int format, size_t *olen,
+ unsigned char *buf, size_t buflen );
+
+/**
+ * \brief Import a point from unsigned binary data
+ *
+ * \param grp Group to which the point should belong
+ * \param P Point to import
+ * \param buf Input buffer
+ * \param ilen Actual length of input
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
+ * is not implemented.
+ *
+ * \note This function does NOT check that the point actually
+ * belongs to the given group, see mbedtls_ecp_check_pubkey() for
+ * that.
+ */
+int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P,
+ const unsigned char *buf, size_t ilen );
+
+/**
+ * \brief Import a point from a TLS ECPoint record
+ *
+ * \param grp ECP group used
+ * \param pt Destination point
+ * \param buf $(Start of input buffer)
+ * \param len Buffer length
+ *
+ * \note buf is updated to point right after the ECPoint on exit
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_XXX if initialization failed
+ * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid
+ */
+int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt,
+ const unsigned char **buf, size_t len );
+
+/**
+ * \brief Export a point as a TLS ECPoint record
+ *
+ * \param grp ECP group used
+ * \param pt Point to export
+ * \param format Export format
+ * \param olen length of data written
+ * \param buf Buffer to write to
+ * \param blen Buffer length
+ *
+ * \return 0 if successful,
+ * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA
+ * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
+ */
+int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt,
+ int format, size_t *olen,
+ unsigned char *buf, size_t blen );
+
+/**
+ * \brief Set a group using well-known domain parameters
+ *
+ * \param grp Destination group
+ * \param id Index in the list of well-known domain parameters
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_XXX if initialization failed
+ * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups
+ *
+ * \note Index should be a value of RFC 4492's enum NamedCurve,
+ * usually in the form of a MBEDTLS_ECP_DP_XXX macro.
+ */
+int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id );
+
+/**
+ * \brief Set a group from a TLS ECParameters record
+ *
+ * \param grp Destination group
+ * \param buf &(Start of input buffer)
+ * \param len Buffer length
+ *
+ * \note buf is updated to point right after ECParameters on exit
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_MPI_XXX if initialization failed
+ * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid
+ */
+int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len );
+
+/**
+ * \brief Write the TLS ECParameters record for a group
+ *
+ * \param grp ECP group used
+ * \param olen Number of bytes actually written
+ * \param buf Buffer to write to
+ * \param blen Buffer length
+ *
+ * \return 0 if successful,
+ * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
+ */
+int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
+ unsigned char *buf, size_t blen );
+
+/**
+ * \brief Multiplication by an integer: R = m * P
+ * (Not thread-safe to use same group in multiple threads)
+ *
+ * \note In order to prevent timing attacks, this function
+ * executes the exact same sequence of (base field)
+ * operations for any valid m. It avoids any if-branch or
+ * array index depending on the value of m.
+ *
+ * \note If f_rng is not NULL, it is used to randomize intermediate
+ * results in order to prevent potential timing attacks
+ * targeting these results. It is recommended to always
+ * provide a non-NULL f_rng (the overhead is negligible).
+ *
+ * \param grp ECP group
+ * \param R Destination point
+ * \param m Integer by which to multiply
+ * \param P Point to multiply
+ * \param f_rng RNG function (see notes)
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_ECP_INVALID_KEY if m is not a valid privkey
+ * or P is not a valid pubkey,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+ const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+/**
+ * \brief Multiplication and addition of two points by integers:
+ * R = m * P + n * Q
+ * (Not thread-safe to use same group in multiple threads)
+ *
+ * \note In contrast to mbedtls_ecp_mul(), this function does not guarantee
+ * a constant execution flow and timing.
+ *
+ * \param grp ECP group
+ * \param R Destination point
+ * \param m Integer by which to multiply P
+ * \param P Point to multiply by m
+ * \param n Integer by which to multiply Q
+ * \param Q Point to be multiplied by n
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_ECP_INVALID_KEY if m or n is not a valid privkey
+ * or P or Q is not a valid pubkey,
+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
+ */
+int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
+ const mbedtls_mpi *m, const mbedtls_ecp_point *P,
+ const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
+
+/**
+ * \brief Check that a point is a valid public key on this curve
+ *
+ * \param grp Curve/group the point should belong to
+ * \param pt Point to check
+ *
+ * \return 0 if point is a valid public key,
+ * MBEDTLS_ERR_ECP_INVALID_KEY otherwise.
+ *
+ * \note This function only checks the point is non-zero, has valid
+ * coordinates and lies on the curve, but not that it is
+ * indeed a multiple of G. This is additional check is more
+ * expensive, isn't required by standards, and shouldn't be
+ * necessary if the group used has a small cofactor. In
+ * particular, it is useless for the NIST groups which all
+ * have a cofactor of 1.
+ *
+ * \note Uses bare components rather than an mbedtls_ecp_keypair structure
+ * in order to ease use with other structures such as
+ * mbedtls_ecdh_context of mbedtls_ecdsa_context.
+ */
+int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt );
+
+/**
+ * \brief Check that an mbedtls_mpi is a valid private key for this curve
+ *
+ * \param grp Group used
+ * \param d Integer to check
+ *
+ * \return 0 if point is a valid private key,
+ * MBEDTLS_ERR_ECP_INVALID_KEY otherwise.
+ *
+ * \note Uses bare components rather than an mbedtls_ecp_keypair structure
+ * in order to ease use with other structures such as
+ * mbedtls_ecdh_context of mbedtls_ecdsa_context.
+ */
+int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d );
+
+/**
+ * \brief Generate a keypair with configurable base point
+ *
+ * \param grp ECP group
+ * \param G Chosen base point
+ * \param d Destination MPI (secret part)
+ * \param Q Destination point (public part)
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful,
+ * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
+ *
+ * \note Uses bare components rather than an mbedtls_ecp_keypair structure
+ * in order to ease use with other structures such as
+ * mbedtls_ecdh_context of mbedtls_ecdsa_context.
+ */
+int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp,
+ const mbedtls_ecp_point *G,
+ mbedtls_mpi *d, mbedtls_ecp_point *Q,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Generate a keypair
+ *
+ * \param grp ECP group
+ * \param d Destination MPI (secret part)
+ * \param Q Destination point (public part)
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful,
+ * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
+ *
+ * \note Uses bare components rather than an mbedtls_ecp_keypair structure
+ * in order to ease use with other structures such as
+ * mbedtls_ecdh_context of mbedtls_ecdsa_context.
+ */
+int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Generate a keypair
+ *
+ * \param grp_id ECP group identifier
+ * \param key Destination keypair
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful,
+ * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
+ */
+int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+/**
+ * \brief Check a public-private key pair
+ *
+ * \param pub Keypair structure holding a public key
+ * \param prv Keypair structure holding a private (plus public) key
+ *
+ * \return 0 if successful (keys are valid and match), or
+ * MBEDTLS_ERR_ECP_BAD_INPUT_DATA, or
+ * a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX code.
+ */
+int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv );
+
+#if defined(MBEDTLS_SELF_TEST)
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int mbedtls_ecp_self_test( int verbose );
+
+#endif /* MBEDTLS_SELF_TEST */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_ECP_ALT */
+
+#endif /* MBEDTLS_ECP_ALT */
+
+#endif /* ecp.h */
+
+
+/********* Start of file include/mbedtls/ecdsa.h ************/
+
+/**
+ * \file ecdsa.h
+ *
+ * \brief The Elliptic Curve Digital Signature Algorithm (ECDSA).
+ *
+ * ECDSA is defined in Standards for Efficient Cryptography Group (SECG):
+ * SEC1 Elliptic Curve Cryptography.
+ * The use of ECDSA for TLS is defined in RFC-4492: Elliptic Curve
+ * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS).
+ *
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_ECDSA_H
+#define MBEDTLS_ECDSA_H
+
+
+
+
+/*
+ * RFC-4492 page 20:
+ *
+ * Ecdsa-Sig-Value ::= SEQUENCE {
+ * r INTEGER,
+ * s INTEGER
+ * }
+ *
+ * Size is at most
+ * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
+ * twice that + 1 (tag) + 2 (len) for the sequence
+ * (assuming ECP_MAX_BYTES is less than 126 for r and s,
+ * and less than 124 (total len <= 255) for the sequence)
+ */
+#if MBEDTLS_ECP_MAX_BYTES > 124
+#error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
+#endif
+/** The maximal size of an ECDSA signature in Bytes. */
+#define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
+
+/**
+ * \brief The ECDSA context structure.
+ */
+typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief This function computes the ECDSA signature of a
+ * previously-hashed message.
+ *
+ * \note The deterministic version is usually preferred.
+ *
+ * \param grp The ECP group.
+ * \param r The first output integer.
+ * \param s The second output integer.
+ * \param d The private signing key.
+ * \param buf The message hash.
+ * \param blen The length of \p buf.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \note If the bitlength of the message hash is larger than the
+ * bitlength of the group order, then the hash is truncated
+ * as defined in Standards for Efficient Cryptography Group
+ * (SECG): SEC1 Elliptic Curve Cryptography, section
+ * 4.1.3, step 5.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX
+ * or \c MBEDTLS_MPI_XXX error code on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
+ const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+/**
+ * \brief This function computes the ECDSA signature of a
+ * previously-hashed message, deterministic version.
+ * For more information, see RFC-6979: Deterministic
+ * Usage of the Digital Signature Algorithm (DSA) and Elliptic
+ * Curve Digital Signature Algorithm (ECDSA).
+ *
+ * \param grp The ECP group.
+ * \param r The first output integer.
+ * \param s The second output integer.
+ * \param d The private signing key.
+ * \param buf The message hash.
+ * \param blen The length of \p buf.
+ * \param md_alg The MD algorithm used to hash the message.
+ *
+ * \note If the bitlength of the message hash is larger than the
+ * bitlength of the group order, then the hash is truncated as
+ * defined in Standards for Efficient Cryptography Group
+ * (SECG): SEC1 Elliptic Curve Cryptography, section
+ * 4.1.3, step 5.
+ *
+ * \return \c 0 on success,
+ * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
+ * error code on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
+ const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
+ mbedtls_md_type_t md_alg );
+#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
+
+/**
+ * \brief This function verifies the ECDSA signature of a
+ * previously-hashed message.
+ *
+ * \param grp The ECP group.
+ * \param buf The message hash.
+ * \param blen The length of \p buf.
+ * \param Q The public key to use for verification.
+ * \param r The first integer of the signature.
+ * \param s The second integer of the signature.
+ *
+ * \note If the bitlength of the message hash is larger than the
+ * bitlength of the group order, then the hash is truncated as
+ * defined in Standards for Efficient Cryptography Group
+ * (SECG): SEC1 Elliptic Curve Cryptography, section
+ * 4.1.4, step 3.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
+ * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
+ * error code on failure for any other reason.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
+ const unsigned char *buf, size_t blen,
+ const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
+
+/**
+ * \brief This function computes the ECDSA signature and writes it
+ * to a buffer, serialized as defined in RFC-4492:
+ * Elliptic Curve Cryptography (ECC) Cipher Suites for
+ * Transport Layer Security (TLS).
+ *
+ * \warning It is not thread-safe to use the same context in
+ * multiple threads.
+ *
+ * \note The deterministic version is used if
+ * #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more
+ * information, see RFC-6979: Deterministic Usage
+ * of the Digital Signature Algorithm (DSA) and Elliptic
+ * Curve Digital Signature Algorithm (ECDSA).
+ *
+ * \param ctx The ECDSA context.
+ * \param md_alg The message digest that was used to hash the message.
+ * \param hash The message hash.
+ * \param hlen The length of the hash.
+ * \param sig The buffer that holds the signature.
+ * \param slen The length of the signature written.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \note The \p sig buffer must be at least twice as large as the
+ * size of the curve used, plus 9. For example, 73 Bytes if
+ * a 256-bit curve is used. A buffer length of
+ * #MBEDTLS_ECDSA_MAX_LEN is always safe.
+ *
+ * \note If the bitlength of the message hash is larger than the
+ * bitlength of the group order, then the hash is truncated as
+ * defined in Standards for Efficient Cryptography Group
+ * (SECG): SEC1 Elliptic Curve Cryptography, section
+ * 4.1.3, step 5.
+ *
+ * \return \c 0 on success,
+ * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
+ * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
+ const unsigned char *hash, size_t hlen,
+ unsigned char *sig, size_t *slen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
+#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief This function computes an ECDSA signature and writes it to a buffer,
+ * serialized as defined in RFC-4492: Elliptic Curve Cryptography
+ * (ECC) Cipher Suites for Transport Layer Security (TLS).
+ *
+ * The deterministic version is defined in RFC-6979:
+ * Deterministic Usage of the Digital Signature Algorithm (DSA) and
+ * Elliptic Curve Digital Signature Algorithm (ECDSA).
+ *
+ * \warning It is not thread-safe to use the same context in
+ * multiple threads.
+
+ *
+ * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0
+ *
+ * \param ctx The ECDSA context.
+ * \param hash The Message hash.
+ * \param hlen The length of the hash.
+ * \param sig The buffer that holds the signature.
+ * \param slen The length of the signature written.
+ * \param md_alg The MD algorithm used to hash the message.
+ *
+ * \note The \p sig buffer must be at least twice as large as the
+ * size of the curve used, plus 9. For example, 73 Bytes if a
+ * 256-bit curve is used. A buffer length of
+ * #MBEDTLS_ECDSA_MAX_LEN is always safe.
+ *
+ * \note If the bitlength of the message hash is larger than the
+ * bitlength of the group order, then the hash is truncated as
+ * defined in Standards for Efficient Cryptography Group
+ * (SECG): SEC1 Elliptic Curve Cryptography, section
+ * 4.1.3, step 5.
+ *
+ * \return \c 0 on success,
+ * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
+ * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
+ const unsigned char *hash, size_t hlen,
+ unsigned char *sig, size_t *slen,
+ mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
+#undef MBEDTLS_DEPRECATED
+#endif /* MBEDTLS_DEPRECATED_REMOVED */
+#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
+
+/**
+ * \brief This function reads and verifies an ECDSA signature.
+ *
+ * \param ctx The ECDSA context.
+ * \param hash The message hash.
+ * \param hlen The size of the hash.
+ * \param sig The signature to read and verify.
+ * \param slen The size of \p sig.
+ *
+ * \note If the bitlength of the message hash is larger than the
+ * bitlength of the group order, then the hash is truncated as
+ * defined in Standards for Efficient Cryptography Group
+ * (SECG): SEC1 Elliptic Curve Cryptography, section
+ * 4.1.4, step 3.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
+ * #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if the signature is
+ * valid but its actual length is less than \p siglen,
+ * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
+ * error code on failure for any other reason.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
+ const unsigned char *hash, size_t hlen,
+ const unsigned char *sig, size_t slen );
+
+/**
+ * \brief This function generates an ECDSA keypair on the given curve.
+ *
+ * \param ctx The ECDSA context to store the keypair in.
+ * \param gid The elliptic curve to use. One of the various
+ * \c MBEDTLS_ECP_DP_XXX macros depending on configuration.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on
+ * failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+/**
+ * \brief This function sets an ECDSA context from an EC key pair.
+ *
+ * \param ctx The ECDSA context to set.
+ * \param key The EC key to use.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on
+ * failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
+
+/**
+ * \brief This function initializes an ECDSA context.
+ *
+ * \param ctx The ECDSA context to initialize.
+ */
+void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
+
+/**
+ * \brief This function frees an ECDSA context.
+ *
+ * \param ctx The ECDSA context to free.
+ */
+void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ecdsa.h */
+
+
+/********* Start of file include/mbedtls/ecjpake.h ************/
+
+/**
+ * \file ecjpake.h
+ *
+ * \brief Elliptic curve J-PAKE
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ECJPAKE_H
+#define MBEDTLS_ECJPAKE_H
+
+/*
+ * J-PAKE is a password-authenticated key exchange that allows deriving a
+ * strong shared secret from a (potentially low entropy) pre-shared
+ * passphrase, with forward secrecy and mutual authentication.
+ * https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling
+ *
+ * This file implements the Elliptic Curve variant of J-PAKE,
+ * as defined in Chapter 7.4 of the Thread v1.0 Specification,
+ * available to members of the Thread Group http://threadgroup.org/
+ *
+ * As the J-PAKE algorithm is inherently symmetric, so is our API.
+ * Each party needs to send its first round message, in any order, to the
+ * other party, then each sends its second round message, in any order.
+ * The payloads are serialized in a way suitable for use in TLS, but could
+ * also be use outside TLS.
+ */
+
+
+
+
+#if !defined(MBEDTLS_ECJPAKE_ALT)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Roles in the EC J-PAKE exchange
+ */
+typedef enum {
+ MBEDTLS_ECJPAKE_CLIENT = 0, /**< Client */
+ MBEDTLS_ECJPAKE_SERVER, /**< Server */
+} mbedtls_ecjpake_role;
+
+/**
+ * EC J-PAKE context structure.
+ *
+ * J-PAKE is a symmetric protocol, except for the identifiers used in
+ * Zero-Knowledge Proofs, and the serialization of the second message
+ * (KeyExchange) as defined by the Thread spec.
+ *
+ * In order to benefit from this symmetry, we choose a different naming
+ * convetion from the Thread v1.0 spec. Correspondance is indicated in the
+ * description as a pair C: client name, S: server name
+ */
+typedef struct
+{
+ const mbedtls_md_info_t *md_info; /**< Hash to use */
+ mbedtls_ecp_group grp; /**< Elliptic curve */
+ mbedtls_ecjpake_role role; /**< Are we client or server? */
+ int point_format; /**< Format for point export */
+
+ mbedtls_ecp_point Xm1; /**< My public key 1 C: X1, S: X3 */
+ mbedtls_ecp_point Xm2; /**< My public key 2 C: X2, S: X4 */
+ mbedtls_ecp_point Xp1; /**< Peer public key 1 C: X3, S: X1 */
+ mbedtls_ecp_point Xp2; /**< Peer public key 2 C: X4, S: X2 */
+ mbedtls_ecp_point Xp; /**< Peer public key C: Xs, S: Xc */
+
+ mbedtls_mpi xm1; /**< My private key 1 C: x1, S: x3 */
+ mbedtls_mpi xm2; /**< My private key 2 C: x2, S: x4 */
+
+ mbedtls_mpi s; /**< Pre-shared secret (passphrase) */
+} mbedtls_ecjpake_context;
+
+/**
+ * \brief Initialize a context
+ * (just makes it ready for setup() or free()).
+ *
+ * \param ctx context to initialize
+ */
+void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
+
+/**
+ * \brief Set up a context for use
+ *
+ * \note Currently the only values for hash/curve allowed by the
+ * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1.
+ *
+ * \param ctx context to set up
+ * \param role Our role: client or server
+ * \param hash hash function to use (MBEDTLS_MD_XXX)
+ * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX)
+ * \param secret pre-shared secret (passphrase)
+ * \param len length of the shared secret
+ *
+ * \return 0 if successfull,
+ * a negative error code otherwise
+ */
+int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
+ mbedtls_ecjpake_role role,
+ mbedtls_md_type_t hash,
+ mbedtls_ecp_group_id curve,
+ const unsigned char *secret,
+ size_t len );
+
+/**
+ * \brief Check if a context is ready for use
+ *
+ * \param ctx Context to check
+ *
+ * \return 0 if the context is ready for use,
+ * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise
+ */
+int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx );
+
+/**
+ * \brief Generate and write the first round message
+ * (TLS: contents of the Client/ServerHello extension,
+ * excluding extension type and length bytes)
+ *
+ * \param ctx Context to use
+ * \param buf Buffer to write the contents to
+ * \param len Buffer size
+ * \param olen Will be updated with the number of bytes written
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successfull,
+ * a negative error code otherwise
+ */
+int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
+ unsigned char *buf, size_t len, size_t *olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Read and process the first round message
+ * (TLS: contents of the Client/ServerHello extension,
+ * excluding extension type and length bytes)
+ *
+ * \param ctx Context to use
+ * \param buf Pointer to extension contents
+ * \param len Extension length
+ *
+ * \return 0 if successfull,
+ * a negative error code otherwise
+ */
+int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
+ const unsigned char *buf,
+ size_t len );
+
+/**
+ * \brief Generate and write the second round message
+ * (TLS: contents of the Client/ServerKeyExchange)
+ *
+ * \param ctx Context to use
+ * \param buf Buffer to write the contents to
+ * \param len Buffer size
+ * \param olen Will be updated with the number of bytes written
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successfull,
+ * a negative error code otherwise
+ */
+int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
+ unsigned char *buf, size_t len, size_t *olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Read and process the second round message
+ * (TLS: contents of the Client/ServerKeyExchange)
+ *
+ * \param ctx Context to use
+ * \param buf Pointer to the message
+ * \param len Message length
+ *
+ * \return 0 if successfull,
+ * a negative error code otherwise
+ */
+int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
+ const unsigned char *buf,
+ size_t len );
+
+/**
+ * \brief Derive the shared secret
+ * (TLS: Pre-Master Secret)
+ *
+ * \param ctx Context to use
+ * \param buf Buffer to write the contents to
+ * \param len Buffer size
+ * \param olen Will be updated with the number of bytes written
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successfull,
+ * a negative error code otherwise
+ */
+int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
+ unsigned char *buf, size_t len, size_t *olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Free a context's content
+ *
+ * \param ctx context to free
+ */
+void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_ECJPAKE_ALT */
+
+#endif /* MBEDTLS_ECJPAKE_ALT */
+
+#if defined(MBEDTLS_SELF_TEST)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int mbedtls_ecjpake_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_SELF_TEST */
+
+#endif /* ecjpake.h */
+
+
+/********* Start of file include/mbedtls/pk.h ************/
+
+/**
+ * \file pk.h
+ *
+ * \brief Public Key abstraction layer
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_PK_H
+#define MBEDTLS_PK_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#if defined(MBEDTLS_RSA_C)
+
+#endif
+
+#if defined(MBEDTLS_ECP_C)
+
+#endif
+
+#if defined(MBEDTLS_ECDSA_C)
+
+#endif
+
+#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
+ !defined(inline) && !defined(__cplusplus)
+#define inline __inline
+#endif
+
+#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 /**< Memory allocation failed. */
+#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */
+#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00 /**< Read/write of file failed. */
+#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80 /**< Unsupported key version */
+#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 /**< Invalid key tag or value. */
+#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */
+#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 /**< Private key password can't be empty. */
+#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 /**< Given private key password does not allow for correct decryption. */
+#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
+#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80 /**< The algorithm tag or value is invalid. */
+#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */
+#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */
+#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The signature is valid but its length is less than expected. */
+#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880 /**< PK hardware accelerator failed. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Public key types
+ */
+typedef enum {
+ MBEDTLS_PK_NONE=0,
+ MBEDTLS_PK_RSA,
+ MBEDTLS_PK_ECKEY,
+ MBEDTLS_PK_ECKEY_DH,
+ MBEDTLS_PK_ECDSA,
+ MBEDTLS_PK_RSA_ALT,
+ MBEDTLS_PK_RSASSA_PSS,
+} mbedtls_pk_type_t;
+
+/**
+ * \brief Options for RSASSA-PSS signature verification.
+ * See \c mbedtls_rsa_rsassa_pss_verify_ext()
+ */
+typedef struct
+{
+ mbedtls_md_type_t mgf1_hash_id;
+ int expected_salt_len;
+
+} mbedtls_pk_rsassa_pss_options;
+
+/**
+ * \brief Types for interfacing with the debug module
+ */
+typedef enum
+{
+ MBEDTLS_PK_DEBUG_NONE = 0,
+ MBEDTLS_PK_DEBUG_MPI,
+ MBEDTLS_PK_DEBUG_ECP,
+} mbedtls_pk_debug_type;
+
+/**
+ * \brief Item to send to the debug module
+ */
+typedef struct
+{
+ mbedtls_pk_debug_type type;
+ const char *name;
+ void *value;
+} mbedtls_pk_debug_item;
+
+/** Maximum number of item send for debugging, plus 1 */
+#define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
+
+/**
+ * \brief Public key information and operations
+ */
+typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
+
+/**
+ * \brief Public key container
+ */
+typedef struct
+{
+ const mbedtls_pk_info_t * pk_info; /**< Public key informations */
+ void * pk_ctx; /**< Underlying public key context */
+} mbedtls_pk_context;
+
+#if defined(MBEDTLS_RSA_C)
+/**
+ * Quick access to an RSA context inside a PK context.
+ *
+ * \warning You must make sure the PK context actually holds an RSA context
+ * before using this function!
+ */
+static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
+{
+ return( (mbedtls_rsa_context *) (pk).pk_ctx );
+}
+#endif /* MBEDTLS_RSA_C */
+
+#if defined(MBEDTLS_ECP_C)
+/**
+ * Quick access to an EC context inside a PK context.
+ *
+ * \warning You must make sure the PK context actually holds an EC context
+ * before using this function!
+ */
+static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk )
+{
+ return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
+}
+#endif /* MBEDTLS_ECP_C */
+
+#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+/**
+ * \brief Types for RSA-alt abstraction
+ */
+typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, int mode, size_t *olen,
+ const unsigned char *input, unsigned char *output,
+ size_t output_max_len );
+typedef int (*mbedtls_pk_rsa_alt_sign_func)( void *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+ int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
+ const unsigned char *hash, unsigned char *sig );
+typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx );
+#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+
+/**
+ * \brief Return information associated with the given PK type
+ *
+ * \param pk_type PK type to search for.
+ *
+ * \return The PK info associated with the type or NULL if not found.
+ */
+const mbedtls_pk_info_t *mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type );
+
+/**
+ * \brief Initialize a mbedtls_pk_context (as NONE)
+ */
+void mbedtls_pk_init( mbedtls_pk_context *ctx );
+
+/**
+ * \brief Free a mbedtls_pk_context
+ */
+void mbedtls_pk_free( mbedtls_pk_context *ctx );
+
+/**
+ * \brief Initialize a PK context with the information given
+ * and allocates the type-specific PK subcontext.
+ *
+ * \param ctx Context to initialize. Must be empty (type NONE).
+ * \param info Information to use
+ *
+ * \return 0 on success,
+ * MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input,
+ * MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
+ *
+ * \note For contexts holding an RSA-alt key, use
+ * \c mbedtls_pk_setup_rsa_alt() instead.
+ */
+int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
+
+#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+/**
+ * \brief Initialize an RSA-alt context
+ *
+ * \param ctx Context to initialize. Must be empty (type NONE).
+ * \param key RSA key pointer
+ * \param decrypt_func Decryption function
+ * \param sign_func Signing function
+ * \param key_len_func Function returning key length in bytes
+ *
+ * \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
+ * context wasn't already initialized as RSA_ALT.
+ *
+ * \note This function replaces \c mbedtls_pk_setup() for RSA-alt.
+ */
+int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key,
+ mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
+ mbedtls_pk_rsa_alt_sign_func sign_func,
+ mbedtls_pk_rsa_alt_key_len_func key_len_func );
+#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
+
+/**
+ * \brief Get the size in bits of the underlying key
+ *
+ * \param ctx Context to use
+ *
+ * \return Key size in bits, or 0 on error
+ */
+size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx );
+
+/**
+ * \brief Get the length in bytes of the underlying key
+ * \param ctx Context to use
+ *
+ * \return Key length in bytes, or 0 on error
+ */
+static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx )
+{
+ return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 );
+}
+
+/**
+ * \brief Tell if a context can do the operation given by type
+ *
+ * \param ctx Context to test
+ * \param type Target type
+ *
+ * \return 0 if context can't do the operations,
+ * 1 otherwise.
+ */
+int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type );
+
+/**
+ * \brief Verify signature (including padding if relevant).
+ *
+ * \param ctx PK context to use
+ * \param md_alg Hash algorithm used (see notes)
+ * \param hash Hash of the message to sign
+ * \param hash_len Hash length or 0 (see notes)
+ * \param sig Signature to verify
+ * \param sig_len Signature length
+ *
+ * \return 0 on success (signature is valid),
+ * MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if the signature is
+ * valid but its actual length is less than sig_len,
+ * or a specific error code.
+ *
+ * \note For RSA keys, the default padding type is PKCS#1 v1.5.
+ * Use \c mbedtls_pk_verify_ext( MBEDTLS_PK_RSASSA_PSS, ... )
+ * to verify RSASSA_PSS signatures.
+ *
+ * \note If hash_len is 0, then the length associated with md_alg
+ * is used instead, or an error returned if it is invalid.
+ *
+ * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
+ */
+int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+ const unsigned char *hash, size_t hash_len,
+ const unsigned char *sig, size_t sig_len );
+
+/**
+ * \brief Verify signature, with options.
+ * (Includes verification of the padding depending on type.)
+ *
+ * \param type Signature type (inc. possible padding type) to verify
+ * \param options Pointer to type-specific options, or NULL
+ * \param ctx PK context to use
+ * \param md_alg Hash algorithm used (see notes)
+ * \param hash Hash of the message to sign
+ * \param hash_len Hash length or 0 (see notes)
+ * \param sig Signature to verify
+ * \param sig_len Signature length
+ *
+ * \return 0 on success (signature is valid),
+ * MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
+ * used for this type of signatures,
+ * MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if the signature is
+ * valid but its actual length is less than sig_len,
+ * or a specific error code.
+ *
+ * \note If hash_len is 0, then the length associated with md_alg
+ * is used instead, or an error returned if it is invalid.
+ *
+ * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
+ *
+ * \note If type is MBEDTLS_PK_RSASSA_PSS, then options must point
+ * to a mbedtls_pk_rsassa_pss_options structure,
+ * otherwise it must be NULL.
+ */
+int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
+ mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+ const unsigned char *hash, size_t hash_len,
+ const unsigned char *sig, size_t sig_len );
+
+/**
+ * \brief Make signature, including padding if relevant.
+ *
+ * \param ctx PK context to use - must hold a private key
+ * \param md_alg Hash algorithm used (see notes)
+ * \param hash Hash of the message to sign
+ * \param hash_len Hash length or 0 (see notes)
+ * \param sig Place to write the signature
+ * \param sig_len Number of bytes written
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \return 0 on success, or a specific error code.
+ *
+ * \note For RSA keys, the default padding type is PKCS#1 v1.5.
+ * There is no interface in the PK module to make RSASSA-PSS
+ * signatures yet.
+ *
+ * \note If hash_len is 0, then the length associated with md_alg
+ * is used instead, or an error returned if it is invalid.
+ *
+ * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
+ * For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
+ */
+int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
+ const unsigned char *hash, size_t hash_len,
+ unsigned char *sig, size_t *sig_len,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+/**
+ * \brief Decrypt message (including padding if relevant).
+ *
+ * \param ctx PK context to use - must hold a private key
+ * \param input Input to decrypt
+ * \param ilen Input size
+ * \param output Decrypted output
+ * \param olen Decrypted message length
+ * \param osize Size of the output buffer
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \note For RSA keys, the default padding type is PKCS#1 v1.5.
+ *
+ * \return 0 on success, or a specific error code.
+ */
+int mbedtls_pk_decrypt( mbedtls_pk_context *ctx,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen, size_t osize,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+/**
+ * \brief Encrypt message (including padding if relevant).
+ *
+ * \param ctx PK context to use
+ * \param input Message to encrypt
+ * \param ilen Message size
+ * \param output Encrypted output
+ * \param olen Encrypted output length
+ * \param osize Size of the output buffer
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ *
+ * \note For RSA keys, the default padding type is PKCS#1 v1.5.
+ *
+ * \return 0 on success, or a specific error code.
+ */
+int mbedtls_pk_encrypt( mbedtls_pk_context *ctx,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen, size_t osize,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+
+/**
+ * \brief Check if a public-private pair of keys matches.
+ *
+ * \param pub Context holding a public key.
+ * \param prv Context holding a private (and public) key.
+ *
+ * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
+ */
+int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv );
+
+/**
+ * \brief Export debug information
+ *
+ * \param ctx Context to use
+ * \param items Place to write debug items
+ *
+ * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
+ */
+int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items );
+
+/**
+ * \brief Access the type name
+ *
+ * \param ctx Context to use
+ *
+ * \return Type name on success, or "invalid PK"
+ */
+const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx );
+
+/**
+ * \brief Get the key type
+ *
+ * \param ctx Context to use
+ *
+ * \return Type on success, or MBEDTLS_PK_NONE
+ */
+mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
+
+#if defined(MBEDTLS_PK_PARSE_C)
+/** \ingroup pk_module */
+/**
+ * \brief Parse a private key in PEM or DER format
+ *
+ * \param ctx key to be initialized
+ * \param key input buffer
+ * \param keylen size of the buffer
+ * (including the terminating null byte for PEM data)
+ * \param pwd password for decryption (optional)
+ * \param pwdlen size of the password
+ *
+ * \note On entry, ctx must be empty, either freshly initialised
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
+ * specific key type, check the result with mbedtls_pk_can_do().
+ *
+ * \note The key is also checked for correctness.
+ *
+ * \return 0 if successful, or a specific PK or PEM error code
+ */
+int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
+ const unsigned char *key, size_t keylen,
+ const unsigned char *pwd, size_t pwdlen );
+
+/** \ingroup pk_module */
+/**
+ * \brief Parse a public key in PEM or DER format
+ *
+ * \param ctx key to be initialized
+ * \param key input buffer
+ * \param keylen size of the buffer
+ * (including the terminating null byte for PEM data)
+ *
+ * \note On entry, ctx must be empty, either freshly initialised
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
+ * specific key type, check the result with mbedtls_pk_can_do().
+ *
+ * \note The key is also checked for correctness.
+ *
+ * \return 0 if successful, or a specific PK or PEM error code
+ */
+int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
+ const unsigned char *key, size_t keylen );
+
+#if defined(MBEDTLS_FS_IO)
+/** \ingroup pk_module */
+/**
+ * \brief Load and parse a private key
+ *
+ * \param ctx key to be initialized
+ * \param path filename to read the private key from
+ * \param password password to decrypt the file (can be NULL)
+ *
+ * \note On entry, ctx must be empty, either freshly initialised
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
+ * specific key type, check the result with mbedtls_pk_can_do().
+ *
+ * \note The key is also checked for correctness.
+ *
+ * \return 0 if successful, or a specific PK or PEM error code
+ */
+int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
+ const char *path, const char *password );
+
+/** \ingroup pk_module */
+/**
+ * \brief Load and parse a public key
+ *
+ * \param ctx key to be initialized
+ * \param path filename to read the public key from
+ *
+ * \note On entry, ctx must be empty, either freshly initialised
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If
+ * you need a specific key type, check the result with
+ * mbedtls_pk_can_do().
+ *
+ * \note The key is also checked for correctness.
+ *
+ * \return 0 if successful, or a specific PK or PEM error code
+ */
+int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path );
+#endif /* MBEDTLS_FS_IO */
+#endif /* MBEDTLS_PK_PARSE_C */
+
+#if defined(MBEDTLS_PK_WRITE_C)
+/**
+ * \brief Write a private key to a PKCS#1 or SEC1 DER structure
+ * Note: data is written at the end of the buffer! Use the
+ * return value to determine where you should start
+ * using the buffer
+ *
+ * \param ctx private to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ *
+ * \return length of data written if successful, or a specific
+ * error code
+ */
+int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
+
+/**
+ * \brief Write a public key to a SubjectPublicKeyInfo DER structure
+ * Note: data is written at the end of the buffer! Use the
+ * return value to determine where you should start
+ * using the buffer
+ *
+ * \param ctx public key to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ *
+ * \return length of data written if successful, or a specific
+ * error code
+ */
+int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
+
+#if defined(MBEDTLS_PEM_WRITE_C)
+/**
+ * \brief Write a public key to a PEM string
+ *
+ * \param ctx public key to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ *
+ * \return 0 if successful, or a specific error code
+ */
+int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
+
+/**
+ * \brief Write a private key to a PKCS#1 or SEC1 PEM string
+ *
+ * \param ctx private to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ *
+ * \return 0 if successful, or a specific error code
+ */
+int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
+#endif /* MBEDTLS_PEM_WRITE_C */
+#endif /* MBEDTLS_PK_WRITE_C */
+
+/*
+ * WARNING: Low-level functions. You probably do not want to use these unless
+ * you are certain you do ;)
+ */
+
+#if defined(MBEDTLS_PK_PARSE_C)
+/**
+ * \brief Parse a SubjectPublicKeyInfo DER structure
+ *
+ * \param p the position in the ASN.1 data
+ * \param end end of the buffer
+ * \param pk the key to fill
+ *
+ * \return 0 if successful, or a specific PK error code
+ */
+int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
+ mbedtls_pk_context *pk );
+#endif /* MBEDTLS_PK_PARSE_C */
+
+#if defined(MBEDTLS_PK_WRITE_C)
+/**
+ * \brief Write a subjectPublicKey to ASN.1 data
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param key public key to write away
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
+ const mbedtls_pk_context *key );
+#endif /* MBEDTLS_PK_WRITE_C */
+
+/*
+ * Internal module functions. You probably do not want to use these unless you
+ * know you do.
+ */
+#if defined(MBEDTLS_FS_IO)
+int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_PK_H */
+
+
+/********* Start of file include/mbedtls/pk_internal.h ************/
+
+/**
+ * \file pk_internal.h
+ *
+ * \brief Public Key abstraction layer: wrapper functions
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_PK_WRAP_H
+#define MBEDTLS_PK_WRAP_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+struct mbedtls_pk_info_t
+{
+ /** Public key type */
+ mbedtls_pk_type_t type;
+
+ /** Type name */
+ const char *name;
+
+ /** Get key size in bits */
+ size_t (*get_bitlen)( const void * );
+
+ /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
+ int (*can_do)( mbedtls_pk_type_t type );
+
+ /** Verify signature */
+ int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
+ const unsigned char *hash, size_t hash_len,
+ const unsigned char *sig, size_t sig_len );
+
+ /** Make signature */
+ int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
+ const unsigned char *hash, size_t hash_len,
+ unsigned char *sig, size_t *sig_len,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+ /** Decrypt message */
+ int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen, size_t osize,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+ /** Encrypt message */
+ int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen, size_t osize,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+ /** Check public-private key pair */
+ int (*check_pair_func)( const void *pub, const void *prv );
+
+ /** Allocate a new context */
+ void * (*ctx_alloc_func)( void );
+
+ /** Free the given context */
+ void (*ctx_free_func)( void *ctx );
+
+ /** Interface with the debug module */
+ void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
+
+};
+#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+/* Container for RSA-alt */
+typedef struct
+{
+ void *key;
+ mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
+ mbedtls_pk_rsa_alt_sign_func sign_func;
+ mbedtls_pk_rsa_alt_key_len_func key_len_func;
+} mbedtls_rsa_alt_context;
+#endif
+
+#if defined(MBEDTLS_RSA_C)
+extern const mbedtls_pk_info_t mbedtls_rsa_info;
+#endif
+
+#if defined(MBEDTLS_ECP_C)
+extern const mbedtls_pk_info_t mbedtls_eckey_info;
+extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
+#endif
+
+#if defined(MBEDTLS_ECDSA_C)
+extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
+#endif
+
+#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
+extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
+#endif
+
+#endif /* MBEDTLS_PK_WRAP_H */
+
+
+/********* Start of file include/mbedtls/x509.h ************/
+
+/**
+ * \file x509.h
+ *
+ * \brief X.509 generic defines and structures
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_X509_H
+#define MBEDTLS_X509_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+
+#if defined(MBEDTLS_RSA_C)
+
+#endif
+
+/**
+ * \addtogroup x509_module
+ * \{
+ */
+
+#if !defined(MBEDTLS_X509_MAX_INTERMEDIATE_CA)
+/**
+ * Maximum number of intermediate CAs in a verification chain.
+ * That is, maximum length of the chain, excluding the end-entity certificate
+ * and the trusted root certificate.
+ *
+ * Set this to a low value to prevent an adversary from making you waste
+ * resources verifying an overlong certificate chain.
+ */
+#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8
+#endif
+
+/**
+ * \name X509 Error codes
+ * \{
+ */
+#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
+#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */
+#define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The CRT/CRL/CSR format is invalid, e.g. different type expected. */
+#define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200 /**< The CRT/CRL/CSR version element is invalid. */
+#define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
+#define MBEDTLS_ERR_X509_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
+#define MBEDTLS_ERR_X509_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
+#define MBEDTLS_ERR_X509_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
+#define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480 /**< The signature tag or value invalid. */
+#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500 /**< The extension tag or value is invalid. */
+#define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580 /**< CRT/CRL/CSR has an unsupported version number. */
+#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600 /**< Signature algorithm (oid) is unsupported. */
+#define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680 /**< Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */
+#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
+#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */
+#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 /**< Input invalid. */
+#define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 /**< Allocation of memory failed. */
+#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900 /**< Read/write of file failed. */
+#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980 /**< Destination buffer is too small. */
+#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000 /**< A fatal error occured, eg the chain is too long or the vrfy callback failed. */
+/* \} name */
+
+/**
+ * \name X509 Verify codes
+ * \{
+ */
+/* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
+#define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
+#define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
+#define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
+#define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
+#define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */
+#define MBEDTLS_X509_BADCRL_EXPIRED 0x20 /**< The CRL is expired. */
+#define MBEDTLS_X509_BADCERT_MISSING 0x40 /**< Certificate was missing. */
+#define MBEDTLS_X509_BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
+#define MBEDTLS_X509_BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
+#define MBEDTLS_X509_BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
+#define MBEDTLS_X509_BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
+#define MBEDTLS_X509_BADCERT_KEY_USAGE 0x0800 /**< Usage does not match the keyUsage extension. */
+#define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE 0x1000 /**< Usage does not match the extendedKeyUsage extension. */
+#define MBEDTLS_X509_BADCERT_NS_CERT_TYPE 0x2000 /**< Usage does not match the nsCertType extension. */
+#define MBEDTLS_X509_BADCERT_BAD_MD 0x4000 /**< The certificate is signed with an unacceptable hash. */
+#define MBEDTLS_X509_BADCERT_BAD_PK 0x8000 /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
+#define MBEDTLS_X509_BADCERT_BAD_KEY 0x010000 /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
+#define MBEDTLS_X509_BADCRL_BAD_MD 0x020000 /**< The CRL is signed with an unacceptable hash. */
+#define MBEDTLS_X509_BADCRL_BAD_PK 0x040000 /**< The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
+#define MBEDTLS_X509_BADCRL_BAD_KEY 0x080000 /**< The CRL is signed with an unacceptable key (eg bad curve, RSA too short). */
+
+/* \} name */
+/* \} addtogroup x509_module */
+
+/*
+ * X.509 v3 Key Usage Extension flags
+ * Reminder: update x509_info_key_usage() when adding new flags.
+ */
+#define MBEDTLS_X509_KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
+#define MBEDTLS_X509_KU_NON_REPUDIATION (0x40) /* bit 1 */
+#define MBEDTLS_X509_KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
+#define MBEDTLS_X509_KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
+#define MBEDTLS_X509_KU_KEY_AGREEMENT (0x08) /* bit 4 */
+#define MBEDTLS_X509_KU_KEY_CERT_SIGN (0x04) /* bit 5 */
+#define MBEDTLS_X509_KU_CRL_SIGN (0x02) /* bit 6 */
+#define MBEDTLS_X509_KU_ENCIPHER_ONLY (0x01) /* bit 7 */
+#define MBEDTLS_X509_KU_DECIPHER_ONLY (0x8000) /* bit 8 */
+
+/*
+ * Netscape certificate types
+ * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
+ */
+
+#define MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
+#define MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
+#define MBEDTLS_X509_NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
+#define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
+#define MBEDTLS_X509_NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
+#define MBEDTLS_X509_NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
+#define MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
+#define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
+
+/*
+ * X.509 extension types
+ *
+ * Comments refer to the status for using certificates. Status can be
+ * different for writing certificates or reading CRLs or CSRs.
+ */
+#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
+#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
+#define MBEDTLS_X509_EXT_KEY_USAGE (1 << 2)
+#define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES (1 << 3)
+#define MBEDTLS_X509_EXT_POLICY_MAPPINGS (1 << 4)
+#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME (1 << 5) /* Supported (DNS) */
+#define MBEDTLS_X509_EXT_ISSUER_ALT_NAME (1 << 6)
+#define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
+#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS (1 << 8) /* Supported */
+#define MBEDTLS_X509_EXT_NAME_CONSTRAINTS (1 << 9)
+#define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS (1 << 10)
+#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE (1 << 11)
+#define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
+#define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
+#define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14)
+
+#define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16)
+
+/*
+ * Storage format identifiers
+ * Recognized formats: PEM and DER
+ */
+#define MBEDTLS_X509_FORMAT_DER 1
+#define MBEDTLS_X509_FORMAT_PEM 2
+
+#define MBEDTLS_X509_MAX_DN_NAME_SIZE 256 /**< Maximum value size of a DN entry */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \addtogroup x509_module
+ * \{ */
+
+/**
+ * \name Structures for parsing X.509 certificates, CRLs and CSRs
+ * \{
+ */
+
+/**
+ * Type-length-value structure that allows for ASN1 using DER.
+ */
+typedef mbedtls_asn1_buf mbedtls_x509_buf;
+
+/**
+ * Container for ASN1 bit strings.
+ */
+typedef mbedtls_asn1_bitstring mbedtls_x509_bitstring;
+
+/**
+ * Container for ASN1 named information objects.
+ * It allows for Relative Distinguished Names (e.g. cn=localhost,ou=code,etc.).
+ */
+typedef mbedtls_asn1_named_data mbedtls_x509_name;
+
+/**
+ * Container for a sequence of ASN.1 items
+ */
+typedef mbedtls_asn1_sequence mbedtls_x509_sequence;
+
+/** Container for date and time (precision in seconds). */
+typedef struct mbedtls_x509_time
+{
+ int year, mon, day; /**< Date. */
+ int hour, min, sec; /**< Time. */
+}
+mbedtls_x509_time;
+
+/** \} name Structures for parsing X.509 certificates, CRLs and CSRs */
+/** \} addtogroup x509_module */
+
+/**
+ * \brief Store the certificate DN in printable form into buf;
+ * no more than size characters will be written.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param dn The X509 name to represent
+ *
+ * \return The length of the string written (not including the
+ * terminated nul byte), or a negative error code.
+ */
+int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn );
+
+/**
+ * \brief Store the certificate serial in printable form into buf;
+ * no more than size characters will be written.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param serial The X509 serial to represent
+ *
+ * \return The length of the string written (not including the
+ * terminated nul byte), or a negative error code.
+ */
+int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *serial );
+
+/**
+ * \brief Check a given mbedtls_x509_time against the system time
+ * and tell if it's in the past.
+ *
+ * \note Intended usage is "if( is_past( valid_to ) ) ERROR".
+ * Hence the return value of 1 if on internal errors.
+ *
+ * \param to mbedtls_x509_time to check
+ *
+ * \return 1 if the given time is in the past or an error occured,
+ * 0 otherwise.
+ */
+int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
+
+/**
+ * \brief Check a given mbedtls_x509_time against the system time
+ * and tell if it's in the future.
+ *
+ * \note Intended usage is "if( is_future( valid_from ) ) ERROR".
+ * Hence the return value of 1 if on internal errors.
+ *
+ * \param from mbedtls_x509_time to check
+ *
+ * \return 1 if the given time is in the future or an error occured,
+ * 0 otherwise.
+ */
+int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_x509_self_test( int verbose );
+
+/*
+ * Internal module functions. You probably do not want to use these unless you
+ * know you do.
+ */
+int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
+ mbedtls_x509_name *cur );
+int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
+ mbedtls_x509_buf *alg );
+int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
+ mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
+#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
+int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
+ mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
+ int *salt_len );
+#endif
+int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
+int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
+ mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
+ void **sig_opts );
+int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
+ mbedtls_x509_time *t );
+int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
+ mbedtls_x509_buf *serial );
+int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
+ mbedtls_x509_buf *ext, int tag );
+int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
+ mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
+ const void *sig_opts );
+int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
+int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
+int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
+ int critical, const unsigned char *val,
+ size_t val_len );
+int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
+ mbedtls_asn1_named_data *first );
+int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
+ mbedtls_asn1_named_data *first );
+int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
+ const char *oid, size_t oid_len,
+ unsigned char *sig, size_t size );
+
+#define MBEDTLS_X509_SAFE_SNPRINTF \
+ do { \
+ if( ret < 0 || (size_t) ret >= n ) \
+ return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); \
+ \
+ n -= (size_t) ret; \
+ p += (size_t) ret; \
+ } while( 0 )
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* x509.h */
+
+
+/********* Start of file include/mbedtls/x509_crl.h ************/
+
+/**
+ * \file x509_crl.h
+ *
+ * \brief X.509 certificate revocation list parsing
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_X509_CRL_H
+#define MBEDTLS_X509_CRL_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \addtogroup x509_module
+ * \{ */
+
+/**
+ * \name Structures and functions for parsing CRLs
+ * \{
+ */
+
+/**
+ * Certificate revocation list entry.
+ * Contains the CA-specific serial numbers and revocation dates.
+ */
+typedef struct mbedtls_x509_crl_entry
+{
+ mbedtls_x509_buf raw;
+
+ mbedtls_x509_buf serial;
+
+ mbedtls_x509_time revocation_date;
+
+ mbedtls_x509_buf entry_ext;
+
+ struct mbedtls_x509_crl_entry *next;
+}
+mbedtls_x509_crl_entry;
+
+/**
+ * Certificate revocation list structure.
+ * Every CRL may have multiple entries.
+ */
+typedef struct mbedtls_x509_crl
+{
+ mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
+ mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
+
+ int version; /**< CRL version (1=v1, 2=v2) */
+ mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
+
+ mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
+
+ mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
+
+ mbedtls_x509_time this_update;
+ mbedtls_x509_time next_update;
+
+ mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
+
+ mbedtls_x509_buf crl_ext;
+
+ mbedtls_x509_buf sig_oid2;
+ mbedtls_x509_buf sig;
+ mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
+ mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
+ void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
+
+ struct mbedtls_x509_crl *next;
+}
+mbedtls_x509_crl;
+
+/**
+ * \brief Parse a DER-encoded CRL and append it to the chained list
+ *
+ * \param chain points to the start of the chain
+ * \param buf buffer holding the CRL data in DER format
+ * \param buflen size of the buffer
+ * (including the terminating null byte for PEM data)
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
+ const unsigned char *buf, size_t buflen );
+/**
+ * \brief Parse one or more CRLs and append them to the chained list
+ *
+ * \note Mutliple CRLs are accepted only if using PEM format
+ *
+ * \param chain points to the start of the chain
+ * \param buf buffer holding the CRL data in PEM or DER format
+ * \param buflen size of the buffer
+ * (including the terminating null byte for PEM data)
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief Load one or more CRLs and append them to the chained list
+ *
+ * \note Mutliple CRLs are accepted only if using PEM format
+ *
+ * \param chain points to the start of the chain
+ * \param path filename to read the CRLs from (in PEM or DER encoding)
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
+#endif /* MBEDTLS_FS_IO */
+
+/**
+ * \brief Returns an informational string about the CRL.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param prefix A line prefix
+ * \param crl The X509 CRL to represent
+ *
+ * \return The length of the string written (not including the
+ * terminated nul byte), or a negative error code.
+ */
+int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
+ const mbedtls_x509_crl *crl );
+
+/**
+ * \brief Initialize a CRL (chain)
+ *
+ * \param crl CRL chain to initialize
+ */
+void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
+
+/**
+ * \brief Unallocate all CRL data
+ *
+ * \param crl CRL chain to free
+ */
+void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
+
+/* \} name */
+/* \} addtogroup x509_module */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_x509_crl.h */
+
+
+/********* Start of file include/mbedtls/x509_crt.h ************/
+
+/**
+ * \file x509_crt.h
+ *
+ * \brief X.509 certificate parsing and writing
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_X509_CRT_H
+#define MBEDTLS_X509_CRT_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+
+/**
+ * \addtogroup x509_module
+ * \{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name Structures and functions for parsing and writing X.509 certificates
+ * \{
+ */
+
+/**
+ * Container for an X.509 certificate. The certificate may be chained.
+ */
+typedef struct mbedtls_x509_crt
+{
+ mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
+ mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
+
+ int version; /**< The X.509 version. (1=v1, 2=v2, 3=v3) */
+ mbedtls_x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
+ mbedtls_x509_buf sig_oid; /**< Signature algorithm, e.g. sha1RSA */
+
+ mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
+ mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
+
+ mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
+ mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
+
+ mbedtls_x509_time valid_from; /**< Start time of certificate validity. */
+ mbedtls_x509_time valid_to; /**< End time of certificate validity. */
+
+ mbedtls_pk_context pk; /**< Container for the public key context. */
+
+ mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
+ mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
+ mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
+ mbedtls_x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
+
+ int ext_types; /**< Bit string containing detected and parsed extensions */
+ int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
+ int max_pathlen; /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. Path length is 1 higher than RFC 5280 'meaning', so 1+ */
+
+ unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */
+
+ mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
+
+ unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
+
+ mbedtls_x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
+ mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
+ mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
+ void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
+
+ struct mbedtls_x509_crt *next; /**< Next certificate in the CA-chain. */
+}
+mbedtls_x509_crt;
+
+/**
+ * Build flag from an algorithm/curve identifier (pk, md, ecp)
+ * Since 0 is always XXX_NONE, ignore it.
+ */
+#define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( id - 1 ) )
+
+/**
+ * Security profile for certificate verification.
+ *
+ * All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG().
+ */
+typedef struct
+{
+ uint32_t allowed_mds; /**< MDs for signatures */
+ uint32_t allowed_pks; /**< PK algs for signatures */
+ uint32_t allowed_curves; /**< Elliptic curves for ECDSA */
+ uint32_t rsa_min_bitlen; /**< Minimum size for RSA keys */
+}
+mbedtls_x509_crt_profile;
+
+#define MBEDTLS_X509_CRT_VERSION_1 0
+#define MBEDTLS_X509_CRT_VERSION_2 1
+#define MBEDTLS_X509_CRT_VERSION_3 2
+
+#define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 32
+#define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
+
+#if !defined( MBEDTLS_X509_MAX_FILE_PATH_LEN )
+#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
+#endif
+
+/**
+ * Container for writing a certificate (CRT)
+ */
+typedef struct mbedtls_x509write_cert
+{
+ int version;
+ mbedtls_mpi serial;
+ mbedtls_pk_context *subject_key;
+ mbedtls_pk_context *issuer_key;
+ mbedtls_asn1_named_data *subject;
+ mbedtls_asn1_named_data *issuer;
+ mbedtls_md_type_t md_alg;
+ char not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
+ char not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
+ mbedtls_asn1_named_data *extensions;
+}
+mbedtls_x509write_cert;
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/**
+ * Default security profile. Should provide a good balance between security
+ * and compatibility with current deployments.
+ */
+extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
+
+/**
+ * Expected next default profile. Recommended for new deployments.
+ * Currently targets a 128-bit security level, except for RSA-2048.
+ */
+extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
+
+/**
+ * NSA Suite B profile.
+ */
+extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
+
+/**
+ * \brief Parse a single DER formatted certificate and add it
+ * to the chained list.
+ *
+ * \param chain points to the start of the chain
+ * \param buf buffer holding the certificate DER data
+ * \param buflen size of the buffer
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *buf,
+ size_t buflen );
+
+/**
+ * \brief Parse one or more certificates and add them
+ * to the chained list. Parses permissively. If some
+ * certificates can be parsed, the result is the number
+ * of failed certificates it encountered. If none complete
+ * correctly, the first error is returned.
+ *
+ * \param chain points to the start of the chain
+ * \param buf buffer holding the certificate data in PEM or DER format
+ * \param buflen size of the buffer
+ * (including the terminating null byte for PEM data)
+ *
+ * \return 0 if all certificates parsed successfully, a positive number
+ * if partly successful or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief Load one or more certificates and add them
+ * to the chained list. Parses permissively. If some
+ * certificates can be parsed, the result is the number
+ * of failed certificates it encountered. If none complete
+ * correctly, the first error is returned.
+ *
+ * \param chain points to the start of the chain
+ * \param path filename to read the certificates from
+ *
+ * \return 0 if all certificates parsed successfully, a positive number
+ * if partly successful or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path );
+
+/**
+ * \brief Load one or more certificate files from a path and add them
+ * to the chained list. Parses permissively. If some
+ * certificates can be parsed, the result is the number
+ * of failed certificates it encountered. If none complete
+ * correctly, the first error is returned.
+ *
+ * \param chain points to the start of the chain
+ * \param path directory / folder to read the certificate files from
+ *
+ * \return 0 if all certificates parsed successfully, a positive number
+ * if partly successful or a specific X509 or PEM error code
+ */
+int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
+#endif /* MBEDTLS_FS_IO */
+
+/**
+ * \brief Returns an informational string about the
+ * certificate.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param prefix A line prefix
+ * \param crt The X509 certificate to represent
+ *
+ * \return The length of the string written (not including the
+ * terminated nul byte), or a negative error code.
+ */
+int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
+ const mbedtls_x509_crt *crt );
+
+/**
+ * \brief Returns an informational string about the
+ * verification status of a certificate.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param prefix A line prefix
+ * \param flags Verification flags created by mbedtls_x509_crt_verify()
+ *
+ * \return The length of the string written (not including the
+ * terminated nul byte), or a negative error code.
+ */
+int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
+ uint32_t flags );
+
+/**
+ * \brief Verify the certificate signature
+ *
+ * The verify callback is a user-supplied callback that
+ * can clear / modify / add flags for a certificate. If set,
+ * the verification callback is called for each
+ * certificate in the chain (from the trust-ca down to the
+ * presented crt). The parameters for the callback are:
+ * (void *parameter, mbedtls_x509_crt *crt, int certificate_depth,
+ * int *flags). With the flags representing current flags for
+ * that specific certificate and the certificate depth from
+ * the bottom (Peer cert depth = 0).
+ *
+ * All flags left after returning from the callback
+ * are also returned to the application. The function should
+ * return 0 for anything (including invalid certificates)
+ * other than fatal error, as a non-zero return code
+ * immediately aborts the verification process. For fatal
+ * errors, a specific error code should be used (different
+ * from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not
+ * be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR
+ * can be used if no better code is available.
+ *
+ * \note In case verification failed, the results can be displayed
+ * using \c mbedtls_x509_crt_verify_info()
+ *
+ * \note Same as \c mbedtls_x509_crt_verify_with_profile() with the
+ * default security profile.
+ *
+ * \note It is your responsibility to provide up-to-date CRLs for
+ * all trusted CAs. If no CRL is provided for the CA that was
+ * used to sign the certificate, CRL verification is skipped
+ * silently, that is *without* setting any flag.
+ *
+ * \param crt a certificate (chain) to be verified
+ * \param trust_ca the list of trusted CAs
+ * \param ca_crl the list of CRLs for trusted CAs (see note above)
+ * \param cn expected Common Name (can be set to
+ * NULL if the CN must not be verified)
+ * \param flags result of the verification
+ * \param f_vrfy verification function
+ * \param p_vrfy verification parameter
+ *
+ * \return 0 (and flags set to 0) if the chain was verified and valid,
+ * MBEDTLS_ERR_X509_CERT_VERIFY_FAILED if the chain was verified
+ * but found to be invalid, in which case *flags will have one
+ * or more MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX
+ * flags set, or another error (and flags set to 0xffffffff)
+ * in case of a fatal error encountered during the
+ * verification process.
+ */
+int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt,
+ mbedtls_x509_crt *trust_ca,
+ mbedtls_x509_crl *ca_crl,
+ const char *cn, uint32_t *flags,
+ int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+ void *p_vrfy );
+
+/**
+ * \brief Verify the certificate signature according to profile
+ *
+ * \note Same as \c mbedtls_x509_crt_verify(), but with explicit
+ * security profile.
+ *
+ * \note The restrictions on keys (RSA minimum size, allowed curves
+ * for ECDSA) apply to all certificates: trusted root,
+ * intermediate CAs if any, and end entity certificate.
+ *
+ * \param crt a certificate (chain) to be verified
+ * \param trust_ca the list of trusted CAs
+ * \param ca_crl the list of CRLs for trusted CAs
+ * \param profile security profile for verification
+ * \param cn expected Common Name (can be set to
+ * NULL if the CN must not be verified)
+ * \param flags result of the verification
+ * \param f_vrfy verification function
+ * \param p_vrfy verification parameter
+ *
+ * \return 0 if successful or MBEDTLS_ERR_X509_CERT_VERIFY_FAILED
+ * in which case *flags will have one or more
+ * MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX flags
+ * set,
+ * or another error in case of a fatal error encountered
+ * during the verification process.
+ */
+int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt,
+ mbedtls_x509_crt *trust_ca,
+ mbedtls_x509_crl *ca_crl,
+ const mbedtls_x509_crt_profile *profile,
+ const char *cn, uint32_t *flags,
+ int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+ void *p_vrfy );
+
+#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
+/**
+ * \brief Check usage of certificate against keyUsage extension.
+ *
+ * \param crt Leaf certificate used.
+ * \param usage Intended usage(s) (eg MBEDTLS_X509_KU_KEY_ENCIPHERMENT
+ * before using the certificate to perform an RSA key
+ * exchange).
+ *
+ * \note Except for decipherOnly and encipherOnly, a bit set in the
+ * usage argument means this bit MUST be set in the
+ * certificate. For decipherOnly and encipherOnly, it means
+ * that bit MAY be set.
+ *
+ * \return 0 is these uses of the certificate are allowed,
+ * MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
+ * is present but does not match the usage argument.
+ *
+ * \note You should only call this function on leaf certificates, on
+ * (intermediate) CAs the keyUsage extension is automatically
+ * checked by \c mbedtls_x509_crt_verify().
+ */
+int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
+ unsigned int usage );
+#endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
+
+#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
+/**
+ * \brief Check usage of certificate against extendedKeyUsage.
+ *
+ * \param crt Leaf certificate used.
+ * \param usage_oid Intended usage (eg MBEDTLS_OID_SERVER_AUTH or
+ * MBEDTLS_OID_CLIENT_AUTH).
+ * \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()).
+ *
+ * \return 0 if this use of the certificate is allowed,
+ * MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
+ *
+ * \note Usually only makes sense on leaf certificates.
+ */
+int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
+ const char *usage_oid,
+ size_t usage_len );
+#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
+
+#if defined(MBEDTLS_X509_CRL_PARSE_C)
+/**
+ * \brief Verify the certificate revocation status
+ *
+ * \param crt a certificate to be verified
+ * \param crl the CRL to verify against
+ *
+ * \return 1 if the certificate is revoked, 0 otherwise
+ *
+ */
+int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl );
+#endif /* MBEDTLS_X509_CRL_PARSE_C */
+
+/**
+ * \brief Initialize a certificate (chain)
+ *
+ * \param crt Certificate chain to initialize
+ */
+void mbedtls_x509_crt_init( mbedtls_x509_crt *crt );
+
+/**
+ * \brief Unallocate all certificate data
+ *
+ * \param crt Certificate chain to free
+ */
+void mbedtls_x509_crt_free( mbedtls_x509_crt *crt );
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+/* \} name */
+/* \} addtogroup x509_module */
+
+#if defined(MBEDTLS_X509_CRT_WRITE_C)
+/**
+ * \brief Initialize a CRT writing context
+ *
+ * \param ctx CRT context to initialize
+ */
+void mbedtls_x509write_crt_init( mbedtls_x509write_cert *ctx );
+
+/**
+ * \brief Set the verion for a Certificate
+ * Default: MBEDTLS_X509_CRT_VERSION_3
+ *
+ * \param ctx CRT context to use
+ * \param version version to set (MBEDTLS_X509_CRT_VERSION_1, MBEDTLS_X509_CRT_VERSION_2 or
+ * MBEDTLS_X509_CRT_VERSION_3)
+ */
+void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version );
+
+/**
+ * \brief Set the serial number for a Certificate.
+ *
+ * \param ctx CRT context to use
+ * \param serial serial number to set
+ *
+ * \return 0 if successful
+ */
+int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial );
+
+/**
+ * \brief Set the validity period for a Certificate
+ * Timestamps should be in string format for UTC timezone
+ * i.e. "YYYYMMDDhhmmss"
+ * e.g. "20131231235959" for December 31st 2013
+ * at 23:59:59
+ *
+ * \param ctx CRT context to use
+ * \param not_before not_before timestamp
+ * \param not_after not_after timestamp
+ *
+ * \return 0 if timestamp was parsed successfully, or
+ * a specific error code
+ */
+int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
+ const char *not_after );
+
+/**
+ * \brief Set the issuer name for a Certificate
+ * Issuer names should contain a comma-separated list
+ * of OID types and values:
+ * e.g. "C=UK,O=ARM,CN=mbed TLS CA"
+ *
+ * \param ctx CRT context to use
+ * \param issuer_name issuer name to set
+ *
+ * \return 0 if issuer name was parsed successfully, or
+ * a specific error code
+ */
+int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
+ const char *issuer_name );
+
+/**
+ * \brief Set the subject name for a Certificate
+ * Subject names should contain a comma-separated list
+ * of OID types and values:
+ * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
+ *
+ * \param ctx CRT context to use
+ * \param subject_name subject name to set
+ *
+ * \return 0 if subject name was parsed successfully, or
+ * a specific error code
+ */
+int mbedtls_x509write_crt_set_subject_name( mbedtls_x509write_cert *ctx,
+ const char *subject_name );
+
+/**
+ * \brief Set the subject public key for the certificate
+ *
+ * \param ctx CRT context to use
+ * \param key public key to include
+ */
+void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
+
+/**
+ * \brief Set the issuer key used for signing the certificate
+ *
+ * \param ctx CRT context to use
+ * \param key private key to sign with
+ */
+void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
+
+/**
+ * \brief Set the MD algorithm to use for the signature
+ * (e.g. MBEDTLS_MD_SHA1)
+ *
+ * \param ctx CRT context to use
+ * \param md_alg MD algorithm to use
+ */
+void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg );
+
+/**
+ * \brief Generic function to add to or replace an extension in the
+ * CRT
+ *
+ * \param ctx CRT context to use
+ * \param oid OID of the extension
+ * \param oid_len length of the OID
+ * \param critical if the extension is critical (per the RFC's definition)
+ * \param val value of the extension OCTET STRING
+ * \param val_len length of the value data
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
+ const char *oid, size_t oid_len,
+ int critical,
+ const unsigned char *val, size_t val_len );
+
+/**
+ * \brief Set the basicConstraints extension for a CRT
+ *
+ * \param ctx CRT context to use
+ * \param is_ca is this a CA certificate
+ * \param max_pathlen maximum length of certificate chains below this
+ * certificate (only for CA certificates, -1 is
+ * inlimited)
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
+ int is_ca, int max_pathlen );
+
+#if defined(MBEDTLS_SHA1_C)
+/**
+ * \brief Set the subjectKeyIdentifier extension for a CRT
+ * Requires that mbedtls_x509write_crt_set_subject_key() has been
+ * called before
+ *
+ * \param ctx CRT context to use
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx );
+
+/**
+ * \brief Set the authorityKeyIdentifier extension for a CRT
+ * Requires that mbedtls_x509write_crt_set_issuer_key() has been
+ * called before
+ *
+ * \param ctx CRT context to use
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *ctx );
+#endif /* MBEDTLS_SHA1_C */
+
+/**
+ * \brief Set the Key Usage Extension flags
+ * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
+ *
+ * \param ctx CRT context to use
+ * \param key_usage key usage flags to set
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
+ unsigned int key_usage );
+
+/**
+ * \brief Set the Netscape Cert Type flags
+ * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
+ *
+ * \param ctx CRT context to use
+ * \param ns_cert_type Netscape Cert Type flags to set
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
+ unsigned char ns_cert_type );
+
+/**
+ * \brief Free the contents of a CRT write context
+ *
+ * \param ctx CRT context to free
+ */
+void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx );
+
+/**
+ * \brief Write a built up certificate to a X509 DER structure
+ * Note: data is written at the end of the buffer! Use the
+ * return value to determine where you should start
+ * using the buffer
+ *
+ * \param ctx certificate to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ * \param f_rng RNG function (for signature, see note)
+ * \param p_rng RNG parameter
+ *
+ * \return length of data written if successful, or a specific
+ * error code
+ *
+ * \note f_rng may be NULL if RSA is used for signature and the
+ * signature is made offline (otherwise f_rng is desirable
+ * for countermeasures against timing attacks).
+ * ECDSA signatures always require a non-NULL f_rng.
+ */
+int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+#if defined(MBEDTLS_PEM_WRITE_C)
+/**
+ * \brief Write a built up certificate to a X509 PEM string
+ *
+ * \param ctx certificate to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ * \param f_rng RNG function (for signature, see note)
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful, or a specific error code
+ *
+ * \note f_rng may be NULL if RSA is used for signature and the
+ * signature is made offline (otherwise f_rng is desirable
+ * for countermeasures against timing attacks).
+ * ECDSA signatures always require a non-NULL f_rng.
+ */
+int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+#endif /* MBEDTLS_PEM_WRITE_C */
+#endif /* MBEDTLS_X509_CRT_WRITE_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_x509_crt.h */
+
+
+/********* Start of file include/mbedtls/x509_csr.h ************/
+
+/**
+ * \file x509_csr.h
+ *
+ * \brief X.509 certificate signing request parsing and writing
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_X509_CSR_H
+#define MBEDTLS_X509_CSR_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \addtogroup x509_module
+ * \{ */
+
+/**
+ * \name Structures and functions for X.509 Certificate Signing Requests (CSR)
+ * \{
+ */
+
+/**
+ * Certificate Signing Request (CSR) structure.
+ */
+typedef struct mbedtls_x509_csr
+{
+ mbedtls_x509_buf raw; /**< The raw CSR data (DER). */
+ mbedtls_x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */
+
+ int version; /**< CSR version (1=v1). */
+
+ mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). */
+ mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
+
+ mbedtls_pk_context pk; /**< Container for the public key context. */
+
+ mbedtls_x509_buf sig_oid;
+ mbedtls_x509_buf sig;
+ mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
+ mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
+ void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
+}
+mbedtls_x509_csr;
+
+/**
+ * Container for writing a CSR
+ */
+typedef struct mbedtls_x509write_csr
+{
+ mbedtls_pk_context *key;
+ mbedtls_asn1_named_data *subject;
+ mbedtls_md_type_t md_alg;
+ mbedtls_asn1_named_data *extensions;
+}
+mbedtls_x509write_csr;
+
+#if defined(MBEDTLS_X509_CSR_PARSE_C)
+/**
+ * \brief Load a Certificate Signing Request (CSR) in DER format
+ *
+ * \note CSR attributes (if any) are currently silently ignored.
+ *
+ * \param csr CSR context to fill
+ * \param buf buffer holding the CRL data
+ * \param buflen size of the buffer
+ *
+ * \return 0 if successful, or a specific X509 error code
+ */
+int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
+ const unsigned char *buf, size_t buflen );
+
+/**
+ * \brief Load a Certificate Signing Request (CSR), DER or PEM format
+ *
+ * \note See notes for \c mbedtls_x509_csr_parse_der()
+ *
+ * \param csr CSR context to fill
+ * \param buf buffer holding the CRL data
+ * \param buflen size of the buffer
+ * (including the terminating null byte for PEM data)
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief Load a Certificate Signing Request (CSR)
+ *
+ * \note See notes for \c mbedtls_x509_csr_parse()
+ *
+ * \param csr CSR context to fill
+ * \param path filename to read the CSR from
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path );
+#endif /* MBEDTLS_FS_IO */
+
+/**
+ * \brief Returns an informational string about the
+ * CSR.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param prefix A line prefix
+ * \param csr The X509 CSR to represent
+ *
+ * \return The length of the string written (not including the
+ * terminated nul byte), or a negative error code.
+ */
+int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
+ const mbedtls_x509_csr *csr );
+
+/**
+ * \brief Initialize a CSR
+ *
+ * \param csr CSR to initialize
+ */
+void mbedtls_x509_csr_init( mbedtls_x509_csr *csr );
+
+/**
+ * \brief Unallocate all CSR data
+ *
+ * \param csr CSR to free
+ */
+void mbedtls_x509_csr_free( mbedtls_x509_csr *csr );
+#endif /* MBEDTLS_X509_CSR_PARSE_C */
+
+/* \} name */
+/* \} addtogroup x509_module */
+
+#if defined(MBEDTLS_X509_CSR_WRITE_C)
+/**
+ * \brief Initialize a CSR context
+ *
+ * \param ctx CSR context to initialize
+ */
+void mbedtls_x509write_csr_init( mbedtls_x509write_csr *ctx );
+
+/**
+ * \brief Set the subject name for a CSR
+ * Subject names should contain a comma-separated list
+ * of OID types and values:
+ * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
+ *
+ * \param ctx CSR context to use
+ * \param subject_name subject name to set
+ *
+ * \return 0 if subject name was parsed successfully, or
+ * a specific error code
+ */
+int mbedtls_x509write_csr_set_subject_name( mbedtls_x509write_csr *ctx,
+ const char *subject_name );
+
+/**
+ * \brief Set the key for a CSR (public key will be included,
+ * private key used to sign the CSR when writing it)
+ *
+ * \param ctx CSR context to use
+ * \param key Asymetric key to include
+ */
+void mbedtls_x509write_csr_set_key( mbedtls_x509write_csr *ctx, mbedtls_pk_context *key );
+
+/**
+ * \brief Set the MD algorithm to use for the signature
+ * (e.g. MBEDTLS_MD_SHA1)
+ *
+ * \param ctx CSR context to use
+ * \param md_alg MD algorithm to use
+ */
+void mbedtls_x509write_csr_set_md_alg( mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg );
+
+/**
+ * \brief Set the Key Usage Extension flags
+ * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
+ *
+ * \param ctx CSR context to use
+ * \param key_usage key usage flags to set
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage );
+
+/**
+ * \brief Set the Netscape Cert Type flags
+ * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
+ *
+ * \param ctx CSR context to use
+ * \param ns_cert_type Netscape Cert Type flags to set
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx,
+ unsigned char ns_cert_type );
+
+/**
+ * \brief Generic function to add to or replace an extension in the
+ * CSR
+ *
+ * \param ctx CSR context to use
+ * \param oid OID of the extension
+ * \param oid_len length of the OID
+ * \param val value of the extension OCTET STRING
+ * \param val_len length of the value data
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
+ */
+int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx,
+ const char *oid, size_t oid_len,
+ const unsigned char *val, size_t val_len );
+
+/**
+ * \brief Free the contents of a CSR context
+ *
+ * \param ctx CSR context to free
+ */
+void mbedtls_x509write_csr_free( mbedtls_x509write_csr *ctx );
+
+/**
+ * \brief Write a CSR (Certificate Signing Request) to a
+ * DER structure
+ * Note: data is written at the end of the buffer! Use the
+ * return value to determine where you should start
+ * using the buffer
+ *
+ * \param ctx CSR to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ * \param f_rng RNG function (for signature, see note)
+ * \param p_rng RNG parameter
+ *
+ * \return length of data written if successful, or a specific
+ * error code
+ *
+ * \note f_rng may be NULL if RSA is used for signature and the
+ * signature is made offline (otherwise f_rng is desirable
+ * for countermeasures against timing attacks).
+ * ECDSA signatures always require a non-NULL f_rng.
+ */
+int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+#if defined(MBEDTLS_PEM_WRITE_C)
+/**
+ * \brief Write a CSR (Certificate Signing Request) to a
+ * PEM string
+ *
+ * \param ctx CSR to write away
+ * \param buf buffer to write to
+ * \param size size of the buffer
+ * \param f_rng RNG function (for signature, see note)
+ * \param p_rng RNG parameter
+ *
+ * \return 0 if successful, or a specific error code
+ *
+ * \note f_rng may be NULL if RSA is used for signature and the
+ * signature is made offline (otherwise f_rng is desirable
+ * for countermeasures against timing attacks).
+ * ECDSA signatures always require a non-NULL f_rng.
+ */
+int mbedtls_x509write_csr_pem( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+#endif /* MBEDTLS_PEM_WRITE_C */
+#endif /* MBEDTLS_X509_CSR_WRITE_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_x509_csr.h */
+
+
+/********* Start of file include/mbedtls/cipher.h ************/
+
+/**
+ * \file cipher.h
+ *
+ * \brief The generic cipher wrapper.
+ *
+ * \author Adriaan de Jong
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_CIPHER_H
+#define MBEDTLS_CIPHER_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C)
+#define MBEDTLS_CIPHER_MODE_AEAD
+#endif
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+#define MBEDTLS_CIPHER_MODE_WITH_PADDING
+#endif
+
+#if defined(MBEDTLS_ARC4_C)
+#define MBEDTLS_CIPHER_MODE_STREAM
+#endif
+
+#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
+ !defined(inline) && !defined(__cplusplus)
+#define inline __inline
+#endif
+
+#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */
+#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters. */
+#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 /**< Failed to allocate memory. */
+#define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 /**< Input data contains invalid padding and is rejected. */
+#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */
+#define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 /**< Authentication failed (for AEAD modes). */
+#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /**< The context is invalid. For example, because it was freed. */
+#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 /**< Cipher hardware accelerator failed. */
+
+#define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */
+#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 /**< Cipher accepts keys of variable length. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief An enumeration of supported ciphers.
+ *
+ * \warning ARC4 and DES are considered weak ciphers and their use
+ * constitutes a security risk. We recommend considering stronger
+ * ciphers instead.
+ */
+typedef enum {
+ MBEDTLS_CIPHER_ID_NONE = 0,
+ MBEDTLS_CIPHER_ID_NULL,
+ MBEDTLS_CIPHER_ID_AES,
+ MBEDTLS_CIPHER_ID_DES,
+ MBEDTLS_CIPHER_ID_3DES,
+ MBEDTLS_CIPHER_ID_CAMELLIA,
+ MBEDTLS_CIPHER_ID_BLOWFISH,
+ MBEDTLS_CIPHER_ID_ARC4,
+} mbedtls_cipher_id_t;
+
+/**
+ * \brief An enumeration of supported (cipher, mode) pairs.
+ *
+ * \warning ARC4 and DES are considered weak ciphers and their use
+ * constitutes a security risk. We recommend considering stronger
+ * ciphers instead.
+ */
+typedef enum {
+ MBEDTLS_CIPHER_NONE = 0,
+ MBEDTLS_CIPHER_NULL,
+ MBEDTLS_CIPHER_AES_128_ECB,
+ MBEDTLS_CIPHER_AES_192_ECB,
+ MBEDTLS_CIPHER_AES_256_ECB,
+ MBEDTLS_CIPHER_AES_128_CBC,
+ MBEDTLS_CIPHER_AES_192_CBC,
+ MBEDTLS_CIPHER_AES_256_CBC,
+ MBEDTLS_CIPHER_AES_128_CFB128,
+ MBEDTLS_CIPHER_AES_192_CFB128,
+ MBEDTLS_CIPHER_AES_256_CFB128,
+ MBEDTLS_CIPHER_AES_128_CTR,
+ MBEDTLS_CIPHER_AES_192_CTR,
+ MBEDTLS_CIPHER_AES_256_CTR,
+ MBEDTLS_CIPHER_AES_128_GCM,
+ MBEDTLS_CIPHER_AES_192_GCM,
+ MBEDTLS_CIPHER_AES_256_GCM,
+ MBEDTLS_CIPHER_CAMELLIA_128_ECB,
+ MBEDTLS_CIPHER_CAMELLIA_192_ECB,
+ MBEDTLS_CIPHER_CAMELLIA_256_ECB,
+ MBEDTLS_CIPHER_CAMELLIA_128_CBC,
+ MBEDTLS_CIPHER_CAMELLIA_192_CBC,
+ MBEDTLS_CIPHER_CAMELLIA_256_CBC,
+ MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
+ MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
+ MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
+ MBEDTLS_CIPHER_CAMELLIA_128_CTR,
+ MBEDTLS_CIPHER_CAMELLIA_192_CTR,
+ MBEDTLS_CIPHER_CAMELLIA_256_CTR,
+ MBEDTLS_CIPHER_CAMELLIA_128_GCM,
+ MBEDTLS_CIPHER_CAMELLIA_192_GCM,
+ MBEDTLS_CIPHER_CAMELLIA_256_GCM,
+ MBEDTLS_CIPHER_DES_ECB,
+ MBEDTLS_CIPHER_DES_CBC,
+ MBEDTLS_CIPHER_DES_EDE_ECB,
+ MBEDTLS_CIPHER_DES_EDE_CBC,
+ MBEDTLS_CIPHER_DES_EDE3_ECB,
+ MBEDTLS_CIPHER_DES_EDE3_CBC,
+ MBEDTLS_CIPHER_BLOWFISH_ECB,
+ MBEDTLS_CIPHER_BLOWFISH_CBC,
+ MBEDTLS_CIPHER_BLOWFISH_CFB64,
+ MBEDTLS_CIPHER_BLOWFISH_CTR,
+ MBEDTLS_CIPHER_ARC4_128,
+ MBEDTLS_CIPHER_AES_128_CCM,
+ MBEDTLS_CIPHER_AES_192_CCM,
+ MBEDTLS_CIPHER_AES_256_CCM,
+ MBEDTLS_CIPHER_CAMELLIA_128_CCM,
+ MBEDTLS_CIPHER_CAMELLIA_192_CCM,
+ MBEDTLS_CIPHER_CAMELLIA_256_CCM,
+} mbedtls_cipher_type_t;
+
+/** Supported cipher modes. */
+typedef enum {
+ MBEDTLS_MODE_NONE = 0,
+ MBEDTLS_MODE_ECB,
+ MBEDTLS_MODE_CBC,
+ MBEDTLS_MODE_CFB,
+ MBEDTLS_MODE_OFB, /* Unused! */
+ MBEDTLS_MODE_CTR,
+ MBEDTLS_MODE_GCM,
+ MBEDTLS_MODE_STREAM,
+ MBEDTLS_MODE_CCM,
+} mbedtls_cipher_mode_t;
+
+/** Supported cipher padding types. */
+typedef enum {
+ MBEDTLS_PADDING_PKCS7 = 0, /**< PKCS7 padding (default). */
+ MBEDTLS_PADDING_ONE_AND_ZEROS, /**< ISO/IEC 7816-4 padding. */
+ MBEDTLS_PADDING_ZEROS_AND_LEN, /**< ANSI X.923 padding. */
+ MBEDTLS_PADDING_ZEROS, /**< zero padding (not reversible). */
+ MBEDTLS_PADDING_NONE, /**< never pad (full blocks only). */
+} mbedtls_cipher_padding_t;
+
+/** Type of operation. */
+typedef enum {
+ MBEDTLS_OPERATION_NONE = -1,
+ MBEDTLS_DECRYPT = 0,
+ MBEDTLS_ENCRYPT,
+} mbedtls_operation_t;
+
+enum {
+ /** Undefined key length. */
+ MBEDTLS_KEY_LENGTH_NONE = 0,
+ /** Key length, in bits (including parity), for DES keys. */
+ MBEDTLS_KEY_LENGTH_DES = 64,
+ /** Key length in bits, including parity, for DES in two-key EDE. */
+ MBEDTLS_KEY_LENGTH_DES_EDE = 128,
+ /** Key length in bits, including parity, for DES in three-key EDE. */
+ MBEDTLS_KEY_LENGTH_DES_EDE3 = 192,
+};
+
+/** Maximum length of any IV, in Bytes. */
+#define MBEDTLS_MAX_IV_LENGTH 16
+/** Maximum block size of any cipher, in Bytes. */
+#define MBEDTLS_MAX_BLOCK_LENGTH 16
+
+/**
+ * Base cipher information (opaque struct).
+ */
+typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t;
+
+/**
+ * CMAC context (opaque struct).
+ */
+typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
+
+/**
+ * Cipher information. Allows calling cipher functions
+ * in a generic way.
+ */
+typedef struct {
+ /** Full cipher identifier. For example,
+ * MBEDTLS_CIPHER_AES_256_CBC.
+ */
+ mbedtls_cipher_type_t type;
+
+ /** The cipher mode. For example, MBEDTLS_MODE_CBC. */
+ mbedtls_cipher_mode_t mode;
+
+ /** The cipher key length, in bits. This is the
+ * default length for variable sized ciphers.
+ * Includes parity bits for ciphers like DES.
+ */
+ unsigned int key_bitlen;
+
+ /** Name of the cipher. */
+ const char * name;
+
+ /** IV or nonce size, in Bytes.
+ * For ciphers that accept variable IV sizes,
+ * this is the recommended size.
+ */
+ unsigned int iv_size;
+
+ /** Flags to set. For example, if the cipher supports variable IV sizes or variable key sizes. */
+ int flags;
+
+ /** The block size, in Bytes. */
+ unsigned int block_size;
+
+ /** Struct for base cipher information and functions. */
+ const mbedtls_cipher_base_t *base;
+
+} mbedtls_cipher_info_t;
+
+/**
+ * Generic cipher context.
+ */
+typedef struct {
+ /** Information about the associated cipher. */
+ const mbedtls_cipher_info_t *cipher_info;
+
+ /** Key length to use. */
+ int key_bitlen;
+
+ /** Operation that the key of the context has been
+ * initialized for.
+ */
+ mbedtls_operation_t operation;
+
+#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+ /** Padding functions to use, if relevant for
+ * the specific cipher mode.
+ */
+ void (*add_padding)( unsigned char *output, size_t olen, size_t data_len );
+ int (*get_padding)( unsigned char *input, size_t ilen, size_t *data_len );
+#endif
+
+ /** Buffer for input that has not been processed yet. */
+ unsigned char unprocessed_data[MBEDTLS_MAX_BLOCK_LENGTH];
+
+ /** Number of Bytes that have not been processed yet. */
+ size_t unprocessed_len;
+
+ /** Current IV or NONCE_COUNTER for CTR-mode. */
+ unsigned char iv[MBEDTLS_MAX_IV_LENGTH];
+
+ /** IV size in Bytes, for ciphers with variable-length IVs. */
+ size_t iv_size;
+
+ /** The cipher-specific context. */
+ void *cipher_ctx;
+
+#if defined(MBEDTLS_CMAC_C)
+ /** CMAC-specific context. */
+ mbedtls_cmac_context_t *cmac_ctx;
+#endif
+} mbedtls_cipher_context_t;
+
+/**
+ * \brief This function retrieves the list of ciphers supported by the generic
+ * cipher module.
+ *
+ * \return A statically-allocated array of ciphers. The last entry
+ * is zero.
+ */
+const int *mbedtls_cipher_list( void );
+
+/**
+ * \brief This function retrieves the cipher-information
+ * structure associated with the given cipher name.
+ *
+ * \param cipher_name Name of the cipher to search for.
+ *
+ * \return The cipher information structure associated with the
+ * given \p cipher_name, or NULL if not found.
+ */
+const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name );
+
+/**
+ * \brief This function retrieves the cipher-information
+ * structure associated with the given cipher type.
+ *
+ * \param cipher_type Type of the cipher to search for.
+ *
+ * \return The cipher information structure associated with the
+ * given \p cipher_type, or NULL if not found.
+ */
+const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type );
+
+/**
+ * \brief This function retrieves the cipher-information
+ * structure associated with the given cipher ID,
+ * key size and mode.
+ *
+ * \param cipher_id The ID of the cipher to search for. For example,
+ * #MBEDTLS_CIPHER_ID_AES.
+ * \param key_bitlen The length of the key in bits.
+ * \param mode The cipher mode. For example, #MBEDTLS_MODE_CBC.
+ *
+ * \return The cipher information structure associated with the
+ * given \p cipher_id, or NULL if not found.
+ */
+const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id,
+ int key_bitlen,
+ const mbedtls_cipher_mode_t mode );
+
+/**
+ * \brief This function initializes a \p cipher_context as NONE.
+ */
+void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx );
+
+/**
+ * \brief This function frees and clears the cipher-specific
+ * context of \p ctx. Freeing \p ctx itself remains the
+ * responsibility of the caller.
+ */
+void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
+
+
+/**
+ * \brief This function initializes and fills the cipher-context
+ * structure with the appropriate values. It also clears
+ * the structure.
+ *
+ * \param ctx The context to initialize. May not be NULL.
+ * \param cipher_info The cipher to use.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on parameter failure,
+ * #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
+ * cipher-specific context failed.
+ *
+ * \internal Currently, the function also clears the structure.
+ * In future versions, the caller will be required to call
+ * mbedtls_cipher_init() on the structure first.
+ */
+int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info );
+
+/**
+ * \brief This function returns the block size of the given cipher.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return The size of the blocks of the cipher, or zero if \p ctx
+ * has not been initialized.
+ */
+static inline unsigned int mbedtls_cipher_get_block_size( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return 0;
+
+ return ctx->cipher_info->block_size;
+}
+
+/**
+ * \brief This function returns the mode of operation for
+ * the cipher. For example, MBEDTLS_MODE_CBC.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return The mode of operation, or #MBEDTLS_MODE_NONE if
+ * \p ctx has not been initialized.
+ */
+static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return MBEDTLS_MODE_NONE;
+
+ return ctx->cipher_info->mode;
+}
+
+/**
+ * \brief This function returns the size of the IV or nonce
+ * of the cipher, in Bytes.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return - If no IV has been set: the recommended IV size.
+ * 0 for ciphers not using IV or nonce.
+ * - If IV has already been set: the actual size.
+ */
+static inline int mbedtls_cipher_get_iv_size( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return 0;
+
+ if( ctx->iv_size != 0 )
+ return (int) ctx->iv_size;
+
+ return (int) ctx->cipher_info->iv_size;
+}
+
+/**
+ * \brief This function returns the type of the given cipher.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return The type of the cipher, or #MBEDTLS_CIPHER_NONE if
+ * \p ctx has not been initialized.
+ */
+static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return MBEDTLS_CIPHER_NONE;
+
+ return ctx->cipher_info->type;
+}
+
+/**
+ * \brief This function returns the name of the given cipher
+ * as a string.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return The name of the cipher, or NULL if \p ctx has not
+ * been not initialized.
+ */
+static inline const char *mbedtls_cipher_get_name( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return 0;
+
+ return ctx->cipher_info->name;
+}
+
+/**
+ * \brief This function returns the key length of the cipher.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return The key length of the cipher in bits, or
+ * #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been
+ * initialized.
+ */
+static inline int mbedtls_cipher_get_key_bitlen( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return MBEDTLS_KEY_LENGTH_NONE;
+
+ return (int) ctx->cipher_info->key_bitlen;
+}
+
+/**
+ * \brief This function returns the operation of the given cipher.
+ *
+ * \param ctx The context of the cipher. Must be initialized.
+ *
+ * \return The type of operation: #MBEDTLS_ENCRYPT or
+ * #MBEDTLS_DECRYPT, or #MBEDTLS_OPERATION_NONE if \p ctx
+ * has not been initialized.
+ */
+static inline mbedtls_operation_t mbedtls_cipher_get_operation( const mbedtls_cipher_context_t *ctx )
+{
+ if( NULL == ctx || NULL == ctx->cipher_info )
+ return MBEDTLS_OPERATION_NONE;
+
+ return ctx->operation;
+}
+
+/**
+ * \brief This function sets the key to use with the given context.
+ *
+ * \param ctx The generic cipher context. May not be NULL. Must have
+ * been initialized using mbedtls_cipher_info_from_type()
+ * or mbedtls_cipher_info_from_string().
+ * \param key The key to use.
+ * \param key_bitlen The key length to use, in bits.
+ * \param operation The operation that the key will be used for:
+ * #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if
+ * parameter verification fails, or a cipher-specific
+ * error code.
+ */
+int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key,
+ int key_bitlen, const mbedtls_operation_t operation );
+
+#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
+/**
+ * \brief This function sets the padding mode, for cipher modes
+ * that use padding.
+ *
+ * The default passing mode is PKCS7 padding.
+ *
+ * \param ctx The generic cipher context.
+ * \param mode The padding mode.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
+ * if the selected padding mode is not supported, or
+ * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode
+ * does not support padding.
+ */
+int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode );
+#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
+
+/**
+ * \brief This function sets the initialization vector (IV)
+ * or nonce.
+ *
+ * \param ctx The generic cipher context.
+ * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
+ * \param iv_len The IV length for ciphers with variable-size IV.
+ * This parameter is discarded by ciphers with fixed-size IV.
+ *
+ * \returns \c 0 on success, or #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
+ *
+ * \note Some ciphers do not use IVs nor nonce. For these
+ * ciphers, this function has no effect.
+ */
+int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
+ const unsigned char *iv, size_t iv_len );
+
+/**
+ * \brief This function resets the cipher state.
+ *
+ * \param ctx The generic cipher context.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
+ * if parameter verification fails.
+ */
+int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
+
+#if defined(MBEDTLS_GCM_C)
+/**
+ * \brief This function adds additional data for AEAD ciphers.
+ * Only supported with GCM. Must be called
+ * exactly once, after mbedtls_cipher_reset().
+ *
+ * \param ctx The generic cipher context.
+ * \param ad The additional data to use.
+ * \param ad_len the Length of \p ad.
+ *
+ * \return \c 0 on success, or a specific error code on failure.
+ */
+int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
+ const unsigned char *ad, size_t ad_len );
+#endif /* MBEDTLS_GCM_C */
+
+/**
+ * \brief The generic cipher update function. It encrypts or
+ * decrypts using the given cipher context. Writes as
+ * many block-sized blocks of data as possible to output.
+ * Any data that cannot be written immediately is either
+ * added to the next block, or flushed when
+ * mbedtls_cipher_finish() is called.
+ * Exception: For MBEDTLS_MODE_ECB, expects a single block
+ * in size. For example, 16 Bytes for AES.
+ *
+ * \param ctx The generic cipher context.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The buffer for the output data. Must be able to hold at
+ * least \p ilen + block_size. Must not be the same buffer
+ * as input.
+ * \param olen The length of the output data, to be updated with the
+ * actual number of Bytes written.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if
+ * parameter verification fails,
+ * #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an
+ * unsupported mode for a cipher, or a cipher-specific
+ * error code.
+ *
+ * \note If the underlying cipher is GCM, all calls to this
+ * function, except the last one before
+ * mbedtls_cipher_finish(). Must have \p ilen as a
+ * multiple of the block_size.
+ */
+int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input,
+ size_t ilen, unsigned char *output, size_t *olen );
+
+/**
+ * \brief The generic cipher finalization function. If data still
+ * needs to be flushed from an incomplete block, the data
+ * contained in it is padded to the size of
+ * the last block, and written to the \p output buffer.
+ *
+ * \param ctx The generic cipher context.
+ * \param output The buffer to write data to. Needs block_size available.
+ * \param olen The length of the data written to the \p output buffer.
+ *
+ * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if
+ * parameter verification fails,
+ * #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption
+ * expected a full block but was not provided one,
+ * #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
+ * while decrypting, or a cipher-specific error code
+ * on failure for any other reason.
+ */
+int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
+ unsigned char *output, size_t *olen );
+
+#if defined(MBEDTLS_GCM_C)
+/**
+ * \brief This function writes a tag for AEAD ciphers.
+ * Only supported with GCM.
+ * Must be called after mbedtls_cipher_finish().
+ *
+ * \param ctx The generic cipher context.
+ * \param tag The buffer to write the tag to.
+ * \param tag_len The length of the tag to write.
+ *
+ * \return \c 0 on success, or a specific error code on failure.
+ */
+int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
+ unsigned char *tag, size_t tag_len );
+
+/**
+ * \brief This function checks the tag for AEAD ciphers.
+ * Only supported with GCM.
+ * Must be called after mbedtls_cipher_finish().
+ *
+ * \param ctx The generic cipher context.
+ * \param tag The buffer holding the tag.
+ * \param tag_len The length of the tag to check.
+ *
+ * \return \c 0 on success, or a specific error code on failure.
+ */
+int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
+ const unsigned char *tag, size_t tag_len );
+#endif /* MBEDTLS_GCM_C */
+
+/**
+ * \brief The generic all-in-one encryption/decryption function,
+ * for all ciphers except AEAD constructs.
+ *
+ * \param ctx The generic cipher context.
+ * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
+ * \param iv_len The IV length for ciphers with variable-size IV.
+ * This parameter is discarded by ciphers with fixed-size
+ * IV.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The buffer for the output data. Must be able to hold at
+ * least \p ilen + block_size. Must not be the same buffer
+ * as input.
+ * \param olen The length of the output data, to be updated with the
+ * actual number of Bytes written.
+ *
+ * \note Some ciphers do not use IVs nor nonce. For these
+ * ciphers, use \p iv = NULL and \p iv_len = 0.
+ *
+ * \returns \c 0 on success, or
+ * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or
+ * #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption
+ * expected a full block but was not provided one, or
+ * #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
+ * while decrypting, or a cipher-specific error code on
+ * failure for any other reason.
+ */
+int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen );
+
+#if defined(MBEDTLS_CIPHER_MODE_AEAD)
+/**
+ * \brief The generic autenticated encryption (AEAD) function.
+ *
+ * \param ctx The generic cipher context.
+ * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
+ * \param iv_len The IV length for ciphers with variable-size IV.
+ * This parameter is discarded by ciphers with fixed-size IV.
+ * \param ad The additional data to authenticate.
+ * \param ad_len The length of \p ad.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The buffer for the output data.
+ * Must be able to hold at least \p ilen.
+ * \param olen The length of the output data, to be updated with the
+ * actual number of Bytes written.
+ * \param tag The buffer for the authentication tag.
+ * \param tag_len The desired length of the authentication tag.
+ *
+ * \returns \c 0 on success, or
+ * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or
+ * a cipher-specific error code.
+ */
+int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *ad, size_t ad_len,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen,
+ unsigned char *tag, size_t tag_len );
+
+/**
+ * \brief The generic autenticated decryption (AEAD) function.
+ *
+ * \param ctx The generic cipher context.
+ * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
+ * \param iv_len The IV length for ciphers with variable-size IV.
+ * This parameter is discarded by ciphers with fixed-size IV.
+ * \param ad The additional data to be authenticated.
+ * \param ad_len The length of \p ad.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The buffer for the output data.
+ * Must be able to hold at least \p ilen.
+ * \param olen The length of the output data, to be updated with the
+ * actual number of Bytes written.
+ * \param tag The buffer holding the authentication tag.
+ * \param tag_len The length of the authentication tag.
+ *
+ * \returns \c 0 on success, or
+ * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or
+ * #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic,
+ * or a cipher-specific error code on failure for any other reason.
+ *
+ * \note If the data is not authentic, then the output buffer
+ * is zeroed out to prevent the unauthentic plaintext being
+ * used, making this interface safer.
+ */
+int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *ad, size_t ad_len,
+ const unsigned char *input, size_t ilen,
+ unsigned char *output, size_t *olen,
+ const unsigned char *tag, size_t tag_len );
+#endif /* MBEDTLS_CIPHER_MODE_AEAD */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_CIPHER_H */
+
+
+/********* Start of file include/mbedtls/cipher_internal.h ************/
+
+/**
+ * \file cipher_internal.h
+ *
+ * \brief Cipher wrappers.
+ *
+ * \author Adriaan de Jong
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_CIPHER_WRAP_H
+#define MBEDTLS_CIPHER_WRAP_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Base cipher information. The non-mode specific functions and values.
+ */
+struct mbedtls_cipher_base_t
+{
+ /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
+ mbedtls_cipher_id_t cipher;
+
+ /** Encrypt using ECB */
+ int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
+ const unsigned char *input, unsigned char *output );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+ /** Encrypt using CBC */
+ int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
+ unsigned char *iv, const unsigned char *input,
+ unsigned char *output );
+#endif
+
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
+ /** Encrypt using CFB (Full length) */
+ int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
+ unsigned char *iv, const unsigned char *input,
+ unsigned char *output );
+#endif
+
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
+ /** Encrypt using CTR */
+ int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
+ unsigned char *nonce_counter, unsigned char *stream_block,
+ const unsigned char *input, unsigned char *output );
+#endif
+
+#if defined(MBEDTLS_CIPHER_MODE_STREAM)
+ /** Encrypt using STREAM */
+ int (*stream_func)( void *ctx, size_t length,
+ const unsigned char *input, unsigned char *output );
+#endif
+
+ /** Set key for encryption purposes */
+ int (*setkey_enc_func)( void *ctx, const unsigned char *key,
+ unsigned int key_bitlen );
+
+ /** Set key for decryption purposes */
+ int (*setkey_dec_func)( void *ctx, const unsigned char *key,
+ unsigned int key_bitlen);
+
+ /** Allocate a new context */
+ void * (*ctx_alloc_func)( void );
+
+ /** Free the given context */
+ void (*ctx_free_func)( void *ctx );
+
+};
+
+typedef struct
+{
+ mbedtls_cipher_type_t type;
+ const mbedtls_cipher_info_t *info;
+} mbedtls_cipher_definition_t;
+
+extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
+
+extern int mbedtls_cipher_supported[];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_CIPHER_WRAP_H */
+
+
+/********* Start of file include/mbedtls/ssl_ciphersuites.h ************/
+
+/**
+ * \file ssl_ciphersuites.h
+ *
+ * \brief SSL Ciphersuites for mbed TLS
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SSL_CIPHERSUITES_H
+#define MBEDTLS_SSL_CIPHERSUITES_H
+
+
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Supported ciphersuites (Official IANA names)
+ */
+#define MBEDTLS_TLS_RSA_WITH_NULL_MD5 0x01 /**< Weak! */
+#define MBEDTLS_TLS_RSA_WITH_NULL_SHA 0x02 /**< Weak! */
+
+#define MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 0x04
+#define MBEDTLS_TLS_RSA_WITH_RC4_128_SHA 0x05
+#define MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA 0x09 /**< Weak! Not in TLS 1.2 */
+
+#define MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
+
+#define MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15 /**< Weak! Not in TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
+
+#define MBEDTLS_TLS_PSK_WITH_NULL_SHA 0x2C /**< Weak! */
+#define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA 0x2D /**< Weak! */
+#define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA 0x2E /**< Weak! */
+#define MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA 0x2F
+
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x33
+#define MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA 0x35
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x39
+
+#define MBEDTLS_TLS_RSA_WITH_NULL_SHA256 0x3B /**< Weak! */
+#define MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 0x3C /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 0x3D /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x41
+#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x45
+
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x67 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x6B /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
+#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
+
+#define MBEDTLS_TLS_PSK_WITH_RC4_128_SHA 0x8A
+#define MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA 0x8B
+#define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA 0x8C
+#define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA 0x8D
+
+#define MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA 0x8E
+#define MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x8F
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA 0x90
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA 0x91
+
+#define MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA 0x92
+#define MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x93
+#define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA 0x94
+#define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA 0x95
+
+#define MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 0x9C /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 0x9D /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x9E /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x9F /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 0xA8 /**< TLS 1.2 */
+#define MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 0xA9 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 0xAA /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 0xAB /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 0xAC /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 0xAD /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 0xAE
+#define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 0xAF
+#define MBEDTLS_TLS_PSK_WITH_NULL_SHA256 0xB0 /**< Weak! */
+#define MBEDTLS_TLS_PSK_WITH_NULL_SHA384 0xB1 /**< Weak! */
+
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 0xB2
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 0xB3
+#define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 0xB4 /**< Weak! */
+#define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 0xB5 /**< Weak! */
+
+#define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 0xB6
+#define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 0xB7
+#define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 0xB8 /**< Weak! */
+#define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 0xB9 /**< Weak! */
+
+#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBA /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBE /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC0 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4 /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 /**< Weak! */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA 0xC002 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005 /**< Not in SSL3! */
+
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 /**< Weak! */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 0xC007 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A /**< Not in SSL3! */
+
+#define MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B /**< Weak! */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA 0xC00C /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F /**< Not in SSL3! */
+
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 /**< Weak! */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA 0xC011 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014 /**< Not in SSL3! */
+
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 0xC025 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 0xC026 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 0xC029 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 0xC02A /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0xC02D /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0xC02E /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA 0xC033 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0xC034 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA 0xC039 /**< Weak! No SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 0xC03A /**< Weak! No SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 0xC03B /**< Weak! No SSL3! */
+
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078 /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079 /**< Not in SSL3! */
+
+#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07A /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07B /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07C /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07D /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC086 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC087 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC088 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC089 /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08A /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08B /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08C /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08D /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC08E /**< TLS 1.2 */
+#define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC08F /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC090 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC091 /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC092 /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC093 /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC094
+#define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC095
+#define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC096
+#define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC097
+#define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC098
+#define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC099
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC09A /**< Not in SSL3! */
+#define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC09B /**< Not in SSL3! */
+
+#define MBEDTLS_TLS_RSA_WITH_AES_128_CCM 0xC09C /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_WITH_AES_256_CCM 0xC09D /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM 0xC09E /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM 0xC09F /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8 0xC0A0 /**< TLS 1.2 */
+#define MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8 0xC0A1 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8 0xC0A2 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8 0xC0A3 /**< TLS 1.2 */
+#define MBEDTLS_TLS_PSK_WITH_AES_128_CCM 0xC0A4 /**< TLS 1.2 */
+#define MBEDTLS_TLS_PSK_WITH_AES_256_CCM 0xC0A5 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM 0xC0A6 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM 0xC0A7 /**< TLS 1.2 */
+#define MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8 0xC0A8 /**< TLS 1.2 */
+#define MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8 0xC0A9 /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8 0xC0AA /**< TLS 1.2 */
+#define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8 0xC0AB /**< TLS 1.2 */
+/* The last two are named with PSK_DHE in the RFC, which looks like a typo */
+
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM 0xC0AC /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM 0xC0AD /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 0xC0AE /**< TLS 1.2 */
+#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 0xC0AF /**< TLS 1.2 */
+
+#define MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 0xC0FF /**< experimental */
+
+/* Reminder: update mbedtls_ssl_premaster_secret when adding a new key exchange.
+ * Reminder: update MBEDTLS_KEY_EXCHANGE__xxx below
+ */
+typedef enum {
+ MBEDTLS_KEY_EXCHANGE_NONE = 0,
+ MBEDTLS_KEY_EXCHANGE_RSA,
+ MBEDTLS_KEY_EXCHANGE_DHE_RSA,
+ MBEDTLS_KEY_EXCHANGE_ECDHE_RSA,
+ MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA,
+ MBEDTLS_KEY_EXCHANGE_PSK,
+ MBEDTLS_KEY_EXCHANGE_DHE_PSK,
+ MBEDTLS_KEY_EXCHANGE_RSA_PSK,
+ MBEDTLS_KEY_EXCHANGE_ECDHE_PSK,
+ MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
+ MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
+ MBEDTLS_KEY_EXCHANGE_ECJPAKE,
+} mbedtls_key_exchange_type_t;
+
+/* Key exchanges using a certificate */
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED
+#endif
+
+/* Key exchanges allowing client certificate requests */
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED
+#endif
+
+/* Key exchanges involving server signature in ServerKeyExchange */
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED
+#endif
+
+/* Key exchanges using ECDH */
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED
+#endif
+
+/* Key exchanges that don't involve ephemeral keys */
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED
+#endif
+
+/* Key exchanges that involve ephemeral keys */
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED
+#endif
+
+/* Key exchanges using a PSK */
+#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED
+#endif
+
+/* Key exchanges using DHE */
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED
+#endif
+
+/* Key exchanges using ECDHE */
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
+#define MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED
+#endif
+
+typedef struct mbedtls_ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t;
+
+#define MBEDTLS_CIPHERSUITE_WEAK 0x01 /**< Weak ciphersuite flag */
+#define MBEDTLS_CIPHERSUITE_SHORT_TAG 0x02 /**< Short authentication tag,
+ eg for CCM_8 */
+#define MBEDTLS_CIPHERSUITE_NODTLS 0x04 /**< Can't be used with DTLS */
+
+/**
+ * \brief This structure is used for storing ciphersuite information
+ */
+struct mbedtls_ssl_ciphersuite_t
+{
+ int id;
+ const char * name;
+
+ mbedtls_cipher_type_t cipher;
+ mbedtls_md_type_t mac;
+ mbedtls_key_exchange_type_t key_exchange;
+
+ int min_major_ver;
+ int min_minor_ver;
+ int max_major_ver;
+ int max_minor_ver;
+
+ unsigned char flags;
+};
+
+const int *mbedtls_ssl_list_ciphersuites( void );
+
+const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_string( const char *ciphersuite_name );
+const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_id( int ciphersuite_id );
+
+#if defined(MBEDTLS_PK_C)
+mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg( const mbedtls_ssl_ciphersuite_t *info );
+mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg( const mbedtls_ssl_ciphersuite_t *info );
+#endif
+
+int mbedtls_ssl_ciphersuite_uses_ec( const mbedtls_ssl_ciphersuite_t *info );
+int mbedtls_ssl_ciphersuite_uses_psk( const mbedtls_ssl_ciphersuite_t *info );
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED)
+static inline int mbedtls_ssl_ciphersuite_has_pfs( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_DHE_PSK:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
+ case MBEDTLS_KEY_EXCHANGE_ECJPAKE:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+#endif /* MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED)
+static inline int mbedtls_ssl_ciphersuite_no_pfs( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
+ case MBEDTLS_KEY_EXCHANGE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_PSK:
+ case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+#endif /* MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED)
+static inline int mbedtls_ssl_ciphersuite_uses_ecdh( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+#endif /* MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED */
+
+static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED)
+static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_DHE_PSK:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+#endif /* MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED) */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED)
+static inline int mbedtls_ssl_ciphersuite_uses_ecdhe( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+#endif /* MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED) */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED)
+static inline int mbedtls_ssl_ciphersuite_uses_server_signature( const mbedtls_ssl_ciphersuite_t *info )
+{
+ switch( info->key_exchange )
+ {
+ case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
+ case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
+ return( 1 );
+
+ default:
+ return( 0 );
+ }
+}
+#endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl_ciphersuites.h */
+
+
+/********* Start of file include/mbedtls/ecdh.h ************/
+
+/**
+ * \file ecdh.h
+ *
+ * \brief The Elliptic Curve Diffie-Hellman (ECDH) protocol APIs.
+ *
+ * ECDH is an anonymous key agreement protocol allowing two parties to
+ * establish a shared secret over an insecure channel. Each party must have an
+ * elliptic-curve public–private key pair.
+ *
+ * For more information, see NIST SP 800-56A Rev. 2: Recommendation for
+ * Pair-Wise Key Establishment Schemes Using Discrete Logarithm
+ * Cryptography.
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_ECDH_H
+#define MBEDTLS_ECDH_H
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Defines the source of the imported EC key:
+ * - Our key.
+ * - The key of the peer.
+ */
+typedef enum
+{
+ MBEDTLS_ECDH_OURS,
+ MBEDTLS_ECDH_THEIRS,
+} mbedtls_ecdh_side;
+
+/**
+ * \brief The ECDH context structure.
+ */
+typedef struct
+{
+ mbedtls_ecp_group grp; /*!< The elliptic curve used. */
+ mbedtls_mpi d; /*!< The private key. */
+ mbedtls_ecp_point Q; /*!< The public key. */
+ mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */
+ mbedtls_mpi z; /*!< The shared secret. */
+ int point_format; /*!< The format of point export in TLS messages. */
+ mbedtls_ecp_point Vi; /*!< The blinding value. */
+ mbedtls_ecp_point Vf; /*!< The unblinding value. */
+ mbedtls_mpi _d; /*!< The previous \p d. */
+}
+mbedtls_ecdh_context;
+
+/**
+ * \brief This function generates an ECDH keypair on an elliptic
+ * curve.
+ *
+ * This function performs the first of two core computations
+ * implemented during the ECDH key exchange. The second core
+ * computation is performed by mbedtls_ecdh_compute_shared().
+ *
+ * \param grp The ECP group.
+ * \param d The destination MPI (private key).
+ * \param Q The destination point (public key).
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX or
+ * \c MBEDTLS_MPI_XXX error code on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief This function computes the shared secret.
+ *
+ * This function performs the second of two core computations
+ * implemented during the ECDH key exchange. The first core
+ * computation is performed by mbedtls_ecdh_gen_public().
+ *
+ * \param grp The ECP group.
+ * \param z The destination MPI (shared secret).
+ * \param Q The public key from another party.
+ * \param d Our secret exponent (private key).
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX or
+ * \c MBEDTLS_MPI_XXX error code on failure.
+ *
+ * \see ecp.h
+ *
+ * \note If \p f_rng is not NULL, it is used to implement
+ * countermeasures against potential elaborate timing
+ * attacks. For more information, see mbedtls_ecp_mul().
+ */
+int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
+ const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief This function initializes an ECDH context.
+ *
+ * \param ctx The ECDH context to initialize.
+ */
+void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
+
+/**
+ * \brief This function frees a context.
+ *
+ * \param ctx The context to free.
+ */
+void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
+
+/**
+ * \brief This function generates a public key and a TLS
+ * ServerKeyExchange payload.
+ *
+ * This is the first function used by a TLS server for ECDHE
+ * ciphersuites.
+ *
+ * \param ctx The ECDH context.
+ * \param olen The number of characters written.
+ * \param buf The destination buffer.
+ * \param blen The length of the destination buffer.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \note This function assumes that the ECP group (grp) of the
+ * \p ctx context has already been properly set,
+ * for example, using mbedtls_ecp_group_load().
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
+ * on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
+ unsigned char *buf, size_t blen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief This function parses and processes a TLS ServerKeyExhange
+ * payload.
+ *
+ * This is the first function used by a TLS client for ECDHE
+ * ciphersuites.
+ *
+ * \param ctx The ECDH context.
+ * \param buf The pointer to the start of the input buffer.
+ * \param end The address for one Byte past the end of the buffer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
+ * on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
+ const unsigned char **buf, const unsigned char *end );
+
+/**
+ * \brief This function sets up an ECDH context from an EC key.
+ *
+ * It is used by clients and servers in place of the
+ * ServerKeyEchange for static ECDH, and imports ECDH
+ * parameters from the EC key information of a certificate.
+ *
+ * \param ctx The ECDH context to set up.
+ * \param key The EC key to use.
+ * \param side Defines the source of the key:
+ * - 1: Our key.
+ - 0: The key of the peer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
+ * on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
+ mbedtls_ecdh_side side );
+
+/**
+ * \brief This function generates a public key and a TLS
+ * ClientKeyExchange payload.
+ *
+ * This is the second function used by a TLS client for ECDH(E)
+ * ciphersuites.
+ *
+ * \param ctx The ECDH context.
+ * \param olen The number of Bytes written.
+ * \param buf The destination buffer.
+ * \param blen The size of the destination buffer.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
+ * on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
+ unsigned char *buf, size_t blen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief This function parses and processes a TLS ClientKeyExchange
+ * payload.
+ *
+ * This is the second function used by a TLS server for ECDH(E)
+ * ciphersuites.
+ *
+ * \param ctx The ECDH context.
+ * \param buf The start of the input buffer.
+ * \param blen The length of the input buffer.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
+ * on failure.
+ *
+ * \see ecp.h
+ */
+int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
+ const unsigned char *buf, size_t blen );
+
+/**
+ * \brief This function derives and exports the shared secret.
+ *
+ * This is the last function used by both TLS client
+ * and servers.
+ *
+ * \param ctx The ECDH context.
+ * \param olen The number of Bytes written.
+ * \param buf The destination buffer.
+ * \param blen The length of the destination buffer.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG parameter.
+ *
+ * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
+ * on failure.
+ *
+ * \see ecp.h
+ *
+ * \note If \p f_rng is not NULL, it is used to implement
+ * countermeasures against potential elaborate timing
+ * attacks. For more information, see mbedtls_ecp_mul().
+ */
+int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
+ unsigned char *buf, size_t blen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ecdh.h */
+
+
+/********* Start of file include/mbedtls/sha1.h ************/
+
+/**
+ * \file sha1.h
+ *
+ * \brief The SHA-1 cryptographic hash function.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use constitutes
+ * a security risk. We recommend considering stronger message
+ * digests instead.
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SHA1_H
+#define MBEDTLS_SHA1_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
+
+#if !defined(MBEDTLS_SHA1_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The SHA-1 context structure.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+typedef struct
+{
+ uint32_t total[2]; /*!< The number of Bytes processed. */
+ uint32_t state[5]; /*!< The intermediate digest state. */
+ unsigned char buffer[64]; /*!< The data block being processed. */
+}
+mbedtls_sha1_context;
+
+/**
+ * \brief This function initializes a SHA-1 context.
+ *
+ * \param ctx The SHA-1 context to initialize.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
+
+/**
+ * \brief This function clears a SHA-1 context.
+ *
+ * \param ctx The SHA-1 context to clear.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
+
+/**
+ * \brief This function clones the state of a SHA-1 context.
+ *
+ * \param dst The destination context.
+ * \param src The context to clone.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
+ const mbedtls_sha1_context *src );
+
+/**
+ * \brief This function starts a SHA-1 checksum calculation.
+ *
+ * \param ctx The context to initialize.
+ *
+ * \return \c 0 if successful
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing SHA-1
+ * checksum calculation.
+ *
+ * \param ctx The SHA-1 context.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ *
+ * \return \c 0 if successful
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief This function finishes the SHA-1 operation, and writes
+ * the result to the output buffer.
+ *
+ * \param ctx The SHA-1 context.
+ * \param output The SHA-1 checksum result.
+ *
+ * \return \c 0 if successful
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
+ unsigned char output[20] );
+
+/**
+ * \brief SHA-1 process data block (internal use only)
+ *
+ * \param ctx SHA-1 context
+ * \param data The data block being processed.
+ *
+ * \return \c 0 if successful
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
+ const unsigned char data[64] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief SHA-1 context setup
+ *
+ * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0
+ *
+ * \param ctx The SHA-1 context to be initialized.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
+
+/**
+ * \brief SHA-1 process buffer
+ *
+ * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0
+ *
+ * \param ctx The SHA-1 context.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief SHA-1 final digest
+ *
+ * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0
+ *
+ * \param ctx The SHA-1 context.
+ * \param output The SHA-1 checksum result.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
+ unsigned char output[20] );
+
+/**
+ * \brief SHA-1 process data block (internal use only)
+ *
+ * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0
+ *
+ * \param ctx The SHA-1 context.
+ * \param data The data block being processed.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
+ const unsigned char data[64] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_SHA1_ALT */
+
+#endif /* MBEDTLS_SHA1_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief This function calculates the SHA-1 checksum of a buffer.
+ *
+ * The function allocates the context, performs the
+ * calculation, and frees the context.
+ *
+ * The SHA-1 result is calculated as
+ * output = SHA-1(input buffer).
+ *
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The SHA-1 checksum result.
+ *
+ * \return \c 0 if successful
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_sha1_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[20] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Output = SHA-1( input buffer )
+ *
+ * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0
+ *
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The SHA-1 checksum result.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[20] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief The SHA-1 checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ *
+ * \warning SHA-1 is considered a weak message digest and its use
+ * constitutes a security risk. We recommend considering
+ * stronger message digests instead.
+ *
+ */
+int mbedtls_sha1_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_sha1.h */
+
+
+/********* Start of file include/mbedtls/sha256.h ************/
+
+/**
+ * \file sha256.h
+ *
+ * \brief The SHA-224 and SHA-256 cryptographic hash function.
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SHA256_H
+#define MBEDTLS_SHA256_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */
+
+#if !defined(MBEDTLS_SHA256_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The SHA-256 context structure.
+ *
+ * The structure is used both for SHA-256 and for SHA-224
+ * checksum calculations. The choice between these two is
+ * made in the call to mbedtls_sha256_starts_ret().
+ */
+typedef struct
+{
+ uint32_t total[2]; /*!< The number of Bytes processed. */
+ uint32_t state[8]; /*!< The intermediate digest state. */
+ unsigned char buffer[64]; /*!< The data block being processed. */
+ int is224; /*!< Determines which function to use.
+ - 0: Use SHA-256.
+ - 1: Use SHA-224.
*/
+}
+mbedtls_sha256_context;
+
+/**
+ * \brief This function initializes a SHA-256 context.
+ *
+ * \param ctx The SHA-256 context to initialize.
+ */
+void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
+
+/**
+ * \brief This function clears a SHA-256 context.
+ *
+ * \param ctx The SHA-256 context to clear.
+ */
+void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
+
+/**
+ * \brief This function clones the state of a SHA-256 context.
+ *
+ * \param dst The destination context.
+ * \param src The context to clone.
+ */
+void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
+ const mbedtls_sha256_context *src );
+
+/**
+ * \brief This function starts a SHA-224 or SHA-256 checksum
+ * calculation.
+ *
+ * \param ctx The context to initialize.
+ * \param is224 Determines which function to use.
+ * - 0: Use SHA-256.
+ * - 1: Use SHA-224.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing
+ * SHA-256 checksum calculation.
+ *
+ * \param ctx SHA-256 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief This function finishes the SHA-256 operation, and writes
+ * the result to the output buffer.
+ *
+ * \param ctx The SHA-256 context.
+ * \param output The SHA-224 or SHA-256 checksum result.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
+ unsigned char output[32] );
+
+/**
+ * \brief This function processes a single data block within
+ * the ongoing SHA-256 computation. This function is for
+ * internal use only.
+ *
+ * \param ctx The SHA-256 context.
+ * \param data The buffer holding one block of data.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
+ const unsigned char data[64] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief This function starts a SHA-256 checksum calculation.
+ *
+ * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
+ *
+ * \param ctx The SHA-256 context to initialize.
+ * \param is224 Determines which function to use.
+ * - 0: Use SHA-256.
+ * - 1: Use SHA-224.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
+ int is224 );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing
+ * SHA-256 checksum calculation.
+ *
+ * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
+ *
+ * \param ctx The SHA-256 context to initialize.
+ * \param input The buffer holding the data.
+ * \param ilen The length of the input data.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief This function finishes the SHA-256 operation, and writes
+ * the result to the output buffer.
+ *
+ * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
+ *
+ * \param ctx The SHA-256 context.
+ * \param output The SHA-224or SHA-256 checksum result.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
+ unsigned char output[32] );
+
+/**
+ * \brief This function processes a single data block within
+ * the ongoing SHA-256 computation. This function is for
+ * internal use only.
+ *
+ * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
+ *
+ * \param ctx The SHA-256 context.
+ * \param data The buffer holding one block of data.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
+ const unsigned char data[64] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_SHA256_ALT */
+
+#endif /* MBEDTLS_SHA256_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief This function calculates the SHA-224 or SHA-256
+ * checksum of a buffer.
+ *
+ * The function allocates the context, performs the
+ * calculation, and frees the context.
+ *
+ * The SHA-256 result is calculated as
+ * output = SHA-256(input buffer).
+ *
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The SHA-224 or SHA-256 checksum result.
+ * \param is224 Determines which function to use.
+ * - 0: Use SHA-256.
+ * - 1: Use SHA-224.
+ */
+int mbedtls_sha256_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[32],
+ int is224 );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+
+/**
+ * \brief This function calculates the SHA-224 or SHA-256 checksum
+ * of a buffer.
+ *
+ * The function allocates the context, performs the
+ * calculation, and frees the context.
+ *
+ * The SHA-256 result is calculated as
+ * output = SHA-256(input buffer).
+ *
+ * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0.
+ *
+ * \param input The buffer holding the data.
+ * \param ilen The length of the input data.
+ * \param output The SHA-224 or SHA-256 checksum result.
+ * \param is224 Determines which function to use.
+ * - 0: Use SHA-256.
+ * - 1: Use SHA-224.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[32],
+ int is224 );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief The SHA-224 and SHA-256 checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_sha256_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_sha256.h */
+
+
+/********* Start of file include/mbedtls/sha512.h ************/
+
+/**
+ * \file sha512.h
+ *
+ * \brief The SHA-384 and SHA-512 cryptographic hash function.
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SHA512_H
+#define MBEDTLS_SHA512_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 /**< SHA-512 hardware accelerator failed */
+
+#if !defined(MBEDTLS_SHA512_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The SHA-512 context structure.
+ *
+ * The structure is used both for SHA-384 and for SHA-512
+ * checksum calculations. The choice between these two is
+ * made in the call to mbedtls_sha512_starts_ret().
+ */
+typedef struct
+{
+ uint64_t total[2]; /*!< The number of Bytes processed. */
+ uint64_t state[8]; /*!< The intermediate digest state. */
+ unsigned char buffer[128]; /*!< The data block being processed. */
+ int is384; /*!< Determines which function to use.
+ * - 0: Use SHA-512.
+ * - 1: Use SHA-384.
*/
+}
+mbedtls_sha512_context;
+
+/**
+ * \brief This function initializes a SHA-512 context.
+ *
+ * \param ctx The SHA-512 context to initialize.
+ */
+void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
+
+/**
+ * \brief This function clears a SHA-512 context.
+ *
+ * \param ctx The SHA-512 context to clear.
+ */
+void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
+
+/**
+ * \brief This function clones the state of a SHA-512 context.
+ *
+ * \param dst The destination context.
+ * \param src The context to clone.
+ */
+void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
+ const mbedtls_sha512_context *src );
+
+/**
+ * \brief This function starts a SHA-384 or SHA-512 checksum
+ * calculation.
+ *
+ * \param ctx The SHA-512 context to initialize.
+ * \param is384 Determines which function to use.
+ * - 0: Use SHA-512.
+ * - 1: Use SHA-384.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing
+ * SHA-512 checksum calculation.
+ *
+ * \param ctx The SHA-512 context.
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief This function finishes the SHA-512 operation, and writes
+ * the result to the output buffer. This function is for
+ * internal use only.
+ *
+ * \param ctx The SHA-512 context.
+ * \param output The SHA-384 or SHA-512 checksum result.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
+ unsigned char output[64] );
+
+/**
+ * \brief This function processes a single data block within
+ * the ongoing SHA-512 computation.
+ *
+ * \param ctx The SHA-512 context.
+ * \param data The buffer holding one block of data.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
+ const unsigned char data[128] );
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief This function starts a SHA-384 or SHA-512 checksum
+ * calculation.
+ *
+ * \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0
+ *
+ * \param ctx The SHA-512 context to initialize.
+ * \param is384 Determines which function to use.
+ * - 0: Use SHA-512.
+ * - 1: Use SHA-384.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
+ int is384 );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing
+ * SHA-512 checksum calculation.
+ *
+ * \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0
+ *
+ * \param ctx The SHA-512 context.
+ * \param input The buffer holding the data.
+ * \param ilen The length of the input data.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief This function finishes the SHA-512 operation, and writes
+ * the result to the output buffer.
+ *
+ * \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0
+ *
+ * \param ctx The SHA-512 context.
+ * \param output The SHA-384 or SHA-512 checksum result.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
+ unsigned char output[64] );
+
+/**
+ * \brief This function processes a single data block within
+ * the ongoing SHA-512 computation. This function is for
+ * internal use only.
+ *
+ * \deprecated Superseded by mbedtls_internal_sha512_process() in 2.7.0
+ *
+ * \param ctx The SHA-512 context.
+ * \param data The buffer holding one block of data.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha512_process(
+ mbedtls_sha512_context *ctx,
+ const unsigned char data[128] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_SHA512_ALT */
+
+#endif /* MBEDTLS_SHA512_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief This function calculates the SHA-512 or SHA-384
+ * checksum of a buffer.
+ *
+ * The function allocates the context, performs the
+ * calculation, and frees the context.
+ *
+ * The SHA-512 result is calculated as
+ * output = SHA-512(input buffer).
+ *
+ * \param input The buffer holding the input data.
+ * \param ilen The length of the input data.
+ * \param output The SHA-384 or SHA-512 checksum result.
+ * \param is384 Determines which function to use.
+ * - 0: Use SHA-512.
+ * - 1: Use SHA-384.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_sha512_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[64],
+ int is384 );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief This function calculates the SHA-512 or SHA-384
+ * checksum of a buffer.
+ *
+ * The function allocates the context, performs the
+ * calculation, and frees the context.
+ *
+ * The SHA-512 result is calculated as
+ * output = SHA-512(input buffer).
+ *
+ * \deprecated Superseded by mbedtls_sha512_ret() in 2.7.0
+ *
+ * \param input The buffer holding the data.
+ * \param ilen The length of the input data.
+ * \param output The SHA-384 or SHA-512 checksum result.
+ * \param is384 Determines which function to use.
+ * - 0: Use SHA-512.
+ * - 1: Use SHA-384.
+ */
+MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[64],
+ int is384 );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+ /**
+ * \brief The SHA-384 or SHA-512 checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_sha512_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_sha512.h */
+
+
+/********* Start of file include/mbedtls/aes.h ************/
+
+/**
+ * \file aes.h
+ *
+ * \brief The Advanced Encryption Standard (AES) specifies a FIPS-approved
+ * cryptographic algorithm that can be used to protect electronic
+ * data.
+ *
+ * The AES algorithm is a symmetric block cipher that can
+ * encrypt and decrypt information. For more information, see
+ * FIPS Publication 197: Advanced Encryption Standard and
+ * ISO/IEC 18033-2:2006: Information technology -- Security
+ * techniques -- Encryption algorithms -- Part 2: Asymmetric
+ * ciphers.
+ */
+/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_AES_H
+#define MBEDTLS_AES_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+/* padlock.c and aesni.c rely on these values! */
+#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
+#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
+
+/* Error codes in range 0x0020-0x0022 */
+#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
+#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
+
+/* Error codes in range 0x0023-0x0025 */
+#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
+#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
+
+#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
+ !defined(inline) && !defined(__cplusplus)
+#define inline __inline
+#endif
+
+#if !defined(MBEDTLS_AES_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The AES context-type definition.
+ */
+typedef struct
+{
+ int nr; /*!< The number of rounds. */
+ uint32_t *rk; /*!< AES round keys. */
+ uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
+ hold 32 extra Bytes, which can be used for
+ one of the following purposes:
+ - Alignment if VIA padlock is
+ used.
+ - Simplifying key expansion in the 256-bit
+ case by generating an extra round key.
+
*/
+}
+mbedtls_aes_context;
+
+/**
+ * \brief This function initializes the specified AES context.
+ *
+ * It must be the first API called before using
+ * the context.
+ *
+ * \param ctx The AES context to initialize.
+ */
+void mbedtls_aes_init( mbedtls_aes_context *ctx );
+
+/**
+ * \brief This function releases and clears the specified AES context.
+ *
+ * \param ctx The AES context to clear.
+ */
+void mbedtls_aes_free( mbedtls_aes_context *ctx );
+
+/**
+ * \brief This function sets the encryption key.
+ *
+ * \param ctx The AES context to which the key should be bound.
+ * \param key The encryption key.
+ * \param keybits The size of data passed in bits. Valid options are:
+ * - 128 bits
+ * - 192 bits
+ * - 256 bits
+ *
+ * \return \c 0 on success or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
+ * on failure.
+ */
+int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief This function sets the decryption key.
+ *
+ * \param ctx The AES context to which the key should be bound.
+ * \param key The decryption key.
+ * \param keybits The size of data passed. Valid options are:
+ * - 128 bits
+ * - 192 bits
+ * - 256 bits
+ *
+ * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
+ */
+int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief This function performs an AES single-block encryption or
+ * decryption operation.
+ *
+ * It performs the operation defined in the \p mode parameter
+ * (encrypt or decrypt), on the input data buffer defined in
+ * the \p input parameter.
+ *
+ * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
+ * mbedtls_aes_setkey_dec() must be called before the first
+ * call to this API with the same context.
+ *
+ * \param ctx The AES context to use for encryption or decryption.
+ * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
+ * #MBEDTLS_AES_DECRYPT.
+ * \param input The 16-Byte buffer holding the input data.
+ * \param output The 16-Byte buffer holding the output data.
+
+ * \return \c 0 on success.
+ */
+int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
+ int mode,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+/**
+ * \brief This function performs an AES-CBC encryption or decryption operation
+ * on full blocks.
+ *
+ * It performs the operation defined in the \p mode
+ * parameter (encrypt/decrypt), on the input data buffer defined in
+ * the \p input parameter.
+ *
+ * It can be called as many times as needed, until all the input
+ * data is processed. mbedtls_aes_init(), and either
+ * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
+ * before the first call to this API with the same context.
+ *
+ * \note This function operates on aligned blocks, that is, the input size
+ * must be a multiple of the AES block size of 16 Bytes.
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the same function again on the next
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If you need to retain the contents of the IV, you should
+ * either save it manually or use the cipher module instead.
+ *
+ *
+ * \param ctx The AES context to use for encryption or decryption.
+ * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
+ * #MBEDTLS_AES_DECRYPT.
+ * \param length The length of the input data in Bytes. This must be a
+ * multiple of the block size (16 Bytes).
+ * \param iv Initialization vector (updated after use).
+ * \param input The buffer holding the input data.
+ * \param output The buffer holding the output data.
+ *
+ * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
+ * on failure.
+ */
+int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
+/**
+ * \brief This function performs an AES-CFB128 encryption or decryption
+ * operation.
+ *
+ * It performs the operation defined in the \p mode
+ * parameter (encrypt or decrypt), on the input data buffer
+ * defined in the \p input parameter.
+ *
+ * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
+ * regardless of whether you are performing an encryption or decryption
+ * operation, that is, regardless of the \p mode parameter. This is
+ * because CFB mode uses the same key schedule for encryption and
+ * decryption.
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the same function again on the next
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If you need to retain the contents of the
+ * IV, you must either save it manually or use the cipher
+ * module instead.
+ *
+ *
+ * \param ctx The AES context to use for encryption or decryption.
+ * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
+ * #MBEDTLS_AES_DECRYPT.
+ * \param length The length of the input data.
+ * \param iv_off The offset in IV (updated after use).
+ * \param iv The initialization vector (updated after use).
+ * \param input The buffer holding the input data.
+ * \param output The buffer holding the output data.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
+ int mode,
+ size_t length,
+ size_t *iv_off,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function performs an AES-CFB8 encryption or decryption
+ * operation.
+ *
+ * It performs the operation defined in the \p mode
+ * parameter (encrypt/decrypt), on the input data buffer defined
+ * in the \p input parameter.
+ *
+ * Due to the nature of CFB, you must use the same key schedule for
+ * both encryption and decryption operations. Therefore, you must
+ * use the context initialized with mbedtls_aes_setkey_enc() for
+ * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the same function again on the next
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ *
+ * \param ctx The AES context to use for encryption or decryption.
+ * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
+ * #MBEDTLS_AES_DECRYPT
+ * \param length The length of the input data.
+ * \param iv The initialization vector (updated after use).
+ * \param input The buffer holding the input data.
+ * \param output The buffer holding the output data.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /*MBEDTLS_CIPHER_MODE_CFB */
+
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
+/**
+ * \brief This function performs an AES-CTR encryption or decryption
+ * operation.
+ *
+ * This function performs the operation defined in the \p mode
+ * parameter (encrypt/decrypt), on the input data buffer
+ * defined in the \p input parameter.
+ *
+ * Due to the nature of CTR, you must use the same key schedule
+ * for both encryption and decryption operations. Therefore, you
+ * must use the context initialized with mbedtls_aes_setkey_enc()
+ * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
+ *
+ * \warning You must keep the maximum use of your counter in mind.
+ *
+ * \param ctx The AES context to use for encryption or decryption.
+ * \param length The length of the input data.
+ * \param nc_off The offset in the current \p stream_block, for
+ * resuming within the current cipher stream. The
+ * offset pointer should be 0 at the start of a stream.
+ * \param nonce_counter The 128-bit nonce and counter.
+ * \param stream_block The saved stream block for resuming. This is
+ * overwritten by the function.
+ * \param input The buffer holding the input data.
+ * \param output The buffer holding the output data.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
+ size_t length,
+ size_t *nc_off,
+ unsigned char nonce_counter[16],
+ unsigned char stream_block[16],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CTR */
+
+/**
+ * \brief Internal AES block encryption function. This is only
+ * exposed to allow overriding it using
+ * \c MBEDTLS_AES_ENCRYPT_ALT.
+ *
+ * \param ctx The AES context to use for encryption.
+ * \param input The plaintext block.
+ * \param output The output (ciphertext) block.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+/**
+ * \brief Internal AES block decryption function. This is only
+ * exposed to allow overriding it using see
+ * \c MBEDTLS_AES_DECRYPT_ALT.
+ *
+ * \param ctx The AES context to use for decryption.
+ * \param input The ciphertext block.
+ * \param output The output (plaintext) block.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Deprecated internal AES block encryption function
+ * without return value.
+ *
+ * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
+ *
+ * \param ctx The AES context to use for encryption.
+ * \param input Plaintext block.
+ * \param output Output (ciphertext) block.
+ */
+MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+/**
+ * \brief Deprecated internal AES block decryption function
+ * without return value.
+ *
+ * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
+ *
+ * \param ctx The AES context to use for decryption.
+ * \param input Ciphertext block.
+ * \param output Output (plaintext) block.
+ */
+MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_AES_ALT */
+
+#endif /* MBEDTLS_AES_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_aes_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* aes.h */
+
+
+/********* Start of file include/mbedtls/aesni.h ************/
+
+/**
+ * \file aesni.h
+ *
+ * \brief AES-NI for hardware AES acceleration on some Intel processors
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_AESNI_H
+#define MBEDTLS_AESNI_H
+
+
+
+#define MBEDTLS_AESNI_AES 0x02000000u
+#define MBEDTLS_AESNI_CLMUL 0x00000002u
+
+#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
+ ( defined(__amd64__) || defined(__x86_64__) ) && \
+ ! defined(MBEDTLS_HAVE_X86_64)
+#define MBEDTLS_HAVE_X86_64
+#endif
+
+#if defined(MBEDTLS_HAVE_X86_64)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief AES-NI features detection routine
+ *
+ * \param what The feature to detect
+ * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
+ *
+ * \return 1 if CPU has support for the feature, 0 otherwise
+ */
+int mbedtls_aesni_has_support( unsigned int what );
+
+/**
+ * \brief AES-NI AES-ECB block en(de)cryption
+ *
+ * \param ctx AES context
+ * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
+ * \param input 16-byte input block
+ * \param output 16-byte output block
+ *
+ * \return 0 on success (cannot fail)
+ */
+int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
+ int mode,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+/**
+ * \brief GCM multiplication: c = a * b in GF(2^128)
+ *
+ * \param c Result
+ * \param a First operand
+ * \param b Second operand
+ *
+ * \note Both operands and result are bit strings interpreted as
+ * elements of GF(2^128) as per the GCM spec.
+ */
+void mbedtls_aesni_gcm_mult( unsigned char c[16],
+ const unsigned char a[16],
+ const unsigned char b[16] );
+
+/**
+ * \brief Compute decryption round keys from encryption round keys
+ *
+ * \param invkey Round keys for the equivalent inverse cipher
+ * \param fwdkey Original round keys (for encryption)
+ * \param nr Number of rounds (that is, number of round keys minus one)
+ */
+void mbedtls_aesni_inverse_key( unsigned char *invkey,
+ const unsigned char *fwdkey, int nr );
+
+/**
+ * \brief Perform key expansion (for encryption)
+ *
+ * \param rk Destination buffer where the round keys are written
+ * \param key Encryption key
+ * \param bits Key size in bits (must be 128, 192 or 256)
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
+ */
+int mbedtls_aesni_setkey_enc( unsigned char *rk,
+ const unsigned char *key,
+ size_t bits );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_HAVE_X86_64 */
+
+#endif /* MBEDTLS_AESNI_H */
+
+
+/********* Start of file include/mbedtls/arc4.h ************/
+
+/**
+ * \file arc4.h
+ *
+ * \brief The ARCFOUR stream cipher
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers instead.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ *
+ */
+#ifndef MBEDTLS_ARC4_H
+#define MBEDTLS_ARC4_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
+
+#if !defined(MBEDTLS_ARC4_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief ARC4 context structure
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers instead.
+ *
+ */
+typedef struct
+{
+ int x; /*!< permutation index */
+ int y; /*!< permutation index */
+ unsigned char m[256]; /*!< permutation table */
+}
+mbedtls_arc4_context;
+
+/**
+ * \brief Initialize ARC4 context
+ *
+ * \param ctx ARC4 context to be initialized
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ *
+ */
+void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
+
+/**
+ * \brief Clear ARC4 context
+ *
+ * \param ctx ARC4 context to be cleared
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ *
+ */
+void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
+
+/**
+ * \brief ARC4 key schedule
+ *
+ * \param ctx ARC4 context to be setup
+ * \param key the secret key
+ * \param keylen length of the key, in bytes
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ *
+ */
+void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
+ unsigned int keylen );
+
+/**
+ * \brief ARC4 cipher function
+ *
+ * \param ctx ARC4 context
+ * \param length length of the input data
+ * \param input buffer holding the input data
+ * \param output buffer for the output data
+ *
+ * \return 0 if successful
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ *
+ */
+int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
+ unsigned char *output );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_ARC4_ALT */
+
+#endif /* MBEDTLS_ARC4_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ *
+ * \warning ARC4 is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ *
+ */
+int mbedtls_arc4_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* arc4.h */
+
+
+/********* Start of file include/mbedtls/base64.h ************/
+
+/**
+ * \file base64.h
+ *
+ * \brief RFC 1521 base64 encoding/decoding
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_BASE64_H
+#define MBEDTLS_BASE64_H
+
+#include
+
+#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
+#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Encode a buffer into base64 format
+ *
+ * \param dst destination buffer
+ * \param dlen size of the destination buffer
+ * \param olen number of bytes written
+ * \param src source buffer
+ * \param slen amount of data to be encoded
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
+ * *olen is always updated to reflect the amount
+ * of data that has (or would have) been written.
+ * If that length cannot be represented, then no data is
+ * written to the buffer and *olen is set to the maximum
+ * length representable as a size_t.
+ *
+ * \note Call this function with dlen = 0 to obtain the
+ * required buffer size in *olen
+ */
+int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
+ const unsigned char *src, size_t slen );
+
+/**
+ * \brief Decode a base64-formatted buffer
+ *
+ * \param dst destination buffer (can be NULL for checking size)
+ * \param dlen size of the destination buffer
+ * \param olen number of bytes written
+ * \param src source buffer
+ * \param slen amount of data to be decoded
+ *
+ * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
+ * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
+ * not correct. *olen is always updated to reflect the amount
+ * of data that has (or would have) been written.
+ *
+ * \note Call this function with *dst = NULL or dlen = 0 to obtain
+ * the required buffer size in *olen
+ */
+int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
+ const unsigned char *src, size_t slen );
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_base64_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* base64.h */
+
+
+/********* Start of file include/mbedtls/bn_mul.h ************/
+
+/**
+ * \file bn_mul.h
+ *
+ * \brief Multi-precision integer library
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+/*
+ * Multiply source vector [s] with b, add result
+ * to destination vector [d] and set carry c.
+ *
+ * Currently supports:
+ *
+ * . IA-32 (386+) . AMD64 / EM64T
+ * . IA-32 (SSE2) . Motorola 68000
+ * . PowerPC, 32-bit . MicroBlaze
+ * . PowerPC, 64-bit . TriCore
+ * . SPARC v8 . ARM v3+
+ * . Alpha . MIPS32
+ * . C, longlong . C, generic
+ */
+#ifndef MBEDTLS_BN_MUL_H
+#define MBEDTLS_BN_MUL_H
+
+
+
+#if defined(MBEDTLS_HAVE_ASM)
+
+#ifndef asm
+#define asm __asm
+#endif
+
+/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
+#if defined(__GNUC__) && \
+ ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
+#if defined(__i386__)
+
+#define MULADDC_INIT \
+ asm( \
+ "movl %%ebx, %0 \n\t" \
+ "movl %5, %%esi \n\t" \
+ "movl %6, %%edi \n\t" \
+ "movl %7, %%ecx \n\t" \
+ "movl %8, %%ebx \n\t"
+
+#define MULADDC_CORE \
+ "lodsl \n\t" \
+ "mull %%ebx \n\t" \
+ "addl %%ecx, %%eax \n\t" \
+ "adcl $0, %%edx \n\t" \
+ "addl (%%edi), %%eax \n\t" \
+ "adcl $0, %%edx \n\t" \
+ "movl %%edx, %%ecx \n\t" \
+ "stosl \n\t"
+
+#if defined(MBEDTLS_HAVE_SSE2)
+
+#define MULADDC_HUIT \
+ "movd %%ecx, %%mm1 \n\t" \
+ "movd %%ebx, %%mm0 \n\t" \
+ "movd (%%edi), %%mm3 \n\t" \
+ "paddq %%mm3, %%mm1 \n\t" \
+ "movd (%%esi), %%mm2 \n\t" \
+ "pmuludq %%mm0, %%mm2 \n\t" \
+ "movd 4(%%esi), %%mm4 \n\t" \
+ "pmuludq %%mm0, %%mm4 \n\t" \
+ "movd 8(%%esi), %%mm6 \n\t" \
+ "pmuludq %%mm0, %%mm6 \n\t" \
+ "movd 12(%%esi), %%mm7 \n\t" \
+ "pmuludq %%mm0, %%mm7 \n\t" \
+ "paddq %%mm2, %%mm1 \n\t" \
+ "movd 4(%%edi), %%mm3 \n\t" \
+ "paddq %%mm4, %%mm3 \n\t" \
+ "movd 8(%%edi), %%mm5 \n\t" \
+ "paddq %%mm6, %%mm5 \n\t" \
+ "movd 12(%%edi), %%mm4 \n\t" \
+ "paddq %%mm4, %%mm7 \n\t" \
+ "movd %%mm1, (%%edi) \n\t" \
+ "movd 16(%%esi), %%mm2 \n\t" \
+ "pmuludq %%mm0, %%mm2 \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "movd 20(%%esi), %%mm4 \n\t" \
+ "pmuludq %%mm0, %%mm4 \n\t" \
+ "paddq %%mm3, %%mm1 \n\t" \
+ "movd 24(%%esi), %%mm6 \n\t" \
+ "pmuludq %%mm0, %%mm6 \n\t" \
+ "movd %%mm1, 4(%%edi) \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "movd 28(%%esi), %%mm3 \n\t" \
+ "pmuludq %%mm0, %%mm3 \n\t" \
+ "paddq %%mm5, %%mm1 \n\t" \
+ "movd 16(%%edi), %%mm5 \n\t" \
+ "paddq %%mm5, %%mm2 \n\t" \
+ "movd %%mm1, 8(%%edi) \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "paddq %%mm7, %%mm1 \n\t" \
+ "movd 20(%%edi), %%mm5 \n\t" \
+ "paddq %%mm5, %%mm4 \n\t" \
+ "movd %%mm1, 12(%%edi) \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "paddq %%mm2, %%mm1 \n\t" \
+ "movd 24(%%edi), %%mm5 \n\t" \
+ "paddq %%mm5, %%mm6 \n\t" \
+ "movd %%mm1, 16(%%edi) \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "paddq %%mm4, %%mm1 \n\t" \
+ "movd 28(%%edi), %%mm5 \n\t" \
+ "paddq %%mm5, %%mm3 \n\t" \
+ "movd %%mm1, 20(%%edi) \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "paddq %%mm6, %%mm1 \n\t" \
+ "movd %%mm1, 24(%%edi) \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "paddq %%mm3, %%mm1 \n\t" \
+ "movd %%mm1, 28(%%edi) \n\t" \
+ "addl $32, %%edi \n\t" \
+ "addl $32, %%esi \n\t" \
+ "psrlq $32, %%mm1 \n\t" \
+ "movd %%mm1, %%ecx \n\t"
+
+#define MULADDC_STOP \
+ "emms \n\t" \
+ "movl %4, %%ebx \n\t" \
+ "movl %%ecx, %1 \n\t" \
+ "movl %%edi, %2 \n\t" \
+ "movl %%esi, %3 \n\t" \
+ : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "eax", "ecx", "edx", "esi", "edi" \
+ );
+
+#else
+
+#define MULADDC_STOP \
+ "movl %4, %%ebx \n\t" \
+ "movl %%ecx, %1 \n\t" \
+ "movl %%edi, %2 \n\t" \
+ "movl %%esi, %3 \n\t" \
+ : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "eax", "ecx", "edx", "esi", "edi" \
+ );
+#endif /* SSE2 */
+#endif /* i386 */
+
+#if defined(__amd64__) || defined (__x86_64__)
+
+#define MULADDC_INIT \
+ asm( \
+ "xorq %%r8, %%r8 \n\t"
+
+#define MULADDC_CORE \
+ "movq (%%rsi), %%rax \n\t" \
+ "mulq %%rbx \n\t" \
+ "addq $8, %%rsi \n\t" \
+ "addq %%rcx, %%rax \n\t" \
+ "movq %%r8, %%rcx \n\t" \
+ "adcq $0, %%rdx \n\t" \
+ "nop \n\t" \
+ "addq %%rax, (%%rdi) \n\t" \
+ "adcq %%rdx, %%rcx \n\t" \
+ "addq $8, %%rdi \n\t"
+
+#define MULADDC_STOP \
+ : "+c" (c), "+D" (d), "+S" (s) \
+ : "b" (b) \
+ : "rax", "rdx", "r8" \
+ );
+
+#endif /* AMD64 */
+
+#if defined(__mc68020__) || defined(__mcpu32__)
+
+#define MULADDC_INIT \
+ asm( \
+ "movl %3, %%a2 \n\t" \
+ "movl %4, %%a3 \n\t" \
+ "movl %5, %%d3 \n\t" \
+ "movl %6, %%d2 \n\t" \
+ "moveq #0, %%d0 \n\t"
+
+#define MULADDC_CORE \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d4:%%d1 \n\t" \
+ "addl %%d3, %%d1 \n\t" \
+ "addxl %%d0, %%d4 \n\t" \
+ "moveq #0, %%d3 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "addxl %%d4, %%d3 \n\t"
+
+#define MULADDC_STOP \
+ "movl %%d3, %0 \n\t" \
+ "movl %%a3, %1 \n\t" \
+ "movl %%a2, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
+ );
+
+#define MULADDC_HUIT \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d4:%%d1 \n\t" \
+ "addxl %%d3, %%d1 \n\t" \
+ "addxl %%d0, %%d4 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d3:%%d1 \n\t" \
+ "addxl %%d4, %%d1 \n\t" \
+ "addxl %%d0, %%d3 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d4:%%d1 \n\t" \
+ "addxl %%d3, %%d1 \n\t" \
+ "addxl %%d0, %%d4 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d3:%%d1 \n\t" \
+ "addxl %%d4, %%d1 \n\t" \
+ "addxl %%d0, %%d3 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d4:%%d1 \n\t" \
+ "addxl %%d3, %%d1 \n\t" \
+ "addxl %%d0, %%d4 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d3:%%d1 \n\t" \
+ "addxl %%d4, %%d1 \n\t" \
+ "addxl %%d0, %%d3 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d4:%%d1 \n\t" \
+ "addxl %%d3, %%d1 \n\t" \
+ "addxl %%d0, %%d4 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "movel %%a2@+, %%d1 \n\t" \
+ "mulul %%d2, %%d3:%%d1 \n\t" \
+ "addxl %%d4, %%d1 \n\t" \
+ "addxl %%d0, %%d3 \n\t" \
+ "addl %%d1, %%a3@+ \n\t" \
+ "addxl %%d0, %%d3 \n\t"
+
+#endif /* MC68000 */
+
+#if defined(__powerpc64__) || defined(__ppc64__)
+
+#if defined(__MACH__) && defined(__APPLE__)
+
+#define MULADDC_INIT \
+ asm( \
+ "ld r3, %3 \n\t" \
+ "ld r4, %4 \n\t" \
+ "ld r5, %5 \n\t" \
+ "ld r6, %6 \n\t" \
+ "addi r3, r3, -8 \n\t" \
+ "addi r4, r4, -8 \n\t" \
+ "addic r5, r5, 0 \n\t"
+
+#define MULADDC_CORE \
+ "ldu r7, 8(r3) \n\t" \
+ "mulld r8, r7, r6 \n\t" \
+ "mulhdu r9, r7, r6 \n\t" \
+ "adde r8, r8, r5 \n\t" \
+ "ld r7, 8(r4) \n\t" \
+ "addze r5, r9 \n\t" \
+ "addc r8, r8, r7 \n\t" \
+ "stdu r8, 8(r4) \n\t"
+
+#define MULADDC_STOP \
+ "addze r5, r5 \n\t" \
+ "addi r4, r4, 8 \n\t" \
+ "addi r3, r3, 8 \n\t" \
+ "std r5, %0 \n\t" \
+ "std r4, %1 \n\t" \
+ "std r3, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
+ );
+
+
+#else /* __MACH__ && __APPLE__ */
+
+#define MULADDC_INIT \
+ asm( \
+ "ld %%r3, %3 \n\t" \
+ "ld %%r4, %4 \n\t" \
+ "ld %%r5, %5 \n\t" \
+ "ld %%r6, %6 \n\t" \
+ "addi %%r3, %%r3, -8 \n\t" \
+ "addi %%r4, %%r4, -8 \n\t" \
+ "addic %%r5, %%r5, 0 \n\t"
+
+#define MULADDC_CORE \
+ "ldu %%r7, 8(%%r3) \n\t" \
+ "mulld %%r8, %%r7, %%r6 \n\t" \
+ "mulhdu %%r9, %%r7, %%r6 \n\t" \
+ "adde %%r8, %%r8, %%r5 \n\t" \
+ "ld %%r7, 8(%%r4) \n\t" \
+ "addze %%r5, %%r9 \n\t" \
+ "addc %%r8, %%r8, %%r7 \n\t" \
+ "stdu %%r8, 8(%%r4) \n\t"
+
+#define MULADDC_STOP \
+ "addze %%r5, %%r5 \n\t" \
+ "addi %%r4, %%r4, 8 \n\t" \
+ "addi %%r3, %%r3, 8 \n\t" \
+ "std %%r5, %0 \n\t" \
+ "std %%r4, %1 \n\t" \
+ "std %%r3, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
+ );
+
+#endif /* __MACH__ && __APPLE__ */
+
+#elif defined(__powerpc__) || defined(__ppc__) /* end PPC64/begin PPC32 */
+
+#if defined(__MACH__) && defined(__APPLE__)
+
+#define MULADDC_INIT \
+ asm( \
+ "lwz r3, %3 \n\t" \
+ "lwz r4, %4 \n\t" \
+ "lwz r5, %5 \n\t" \
+ "lwz r6, %6 \n\t" \
+ "addi r3, r3, -4 \n\t" \
+ "addi r4, r4, -4 \n\t" \
+ "addic r5, r5, 0 \n\t"
+
+#define MULADDC_CORE \
+ "lwzu r7, 4(r3) \n\t" \
+ "mullw r8, r7, r6 \n\t" \
+ "mulhwu r9, r7, r6 \n\t" \
+ "adde r8, r8, r5 \n\t" \
+ "lwz r7, 4(r4) \n\t" \
+ "addze r5, r9 \n\t" \
+ "addc r8, r8, r7 \n\t" \
+ "stwu r8, 4(r4) \n\t"
+
+#define MULADDC_STOP \
+ "addze r5, r5 \n\t" \
+ "addi r4, r4, 4 \n\t" \
+ "addi r3, r3, 4 \n\t" \
+ "stw r5, %0 \n\t" \
+ "stw r4, %1 \n\t" \
+ "stw r3, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
+ );
+
+#else /* __MACH__ && __APPLE__ */
+
+#define MULADDC_INIT \
+ asm( \
+ "lwz %%r3, %3 \n\t" \
+ "lwz %%r4, %4 \n\t" \
+ "lwz %%r5, %5 \n\t" \
+ "lwz %%r6, %6 \n\t" \
+ "addi %%r3, %%r3, -4 \n\t" \
+ "addi %%r4, %%r4, -4 \n\t" \
+ "addic %%r5, %%r5, 0 \n\t"
+
+#define MULADDC_CORE \
+ "lwzu %%r7, 4(%%r3) \n\t" \
+ "mullw %%r8, %%r7, %%r6 \n\t" \
+ "mulhwu %%r9, %%r7, %%r6 \n\t" \
+ "adde %%r8, %%r8, %%r5 \n\t" \
+ "lwz %%r7, 4(%%r4) \n\t" \
+ "addze %%r5, %%r9 \n\t" \
+ "addc %%r8, %%r8, %%r7 \n\t" \
+ "stwu %%r8, 4(%%r4) \n\t"
+
+#define MULADDC_STOP \
+ "addze %%r5, %%r5 \n\t" \
+ "addi %%r4, %%r4, 4 \n\t" \
+ "addi %%r3, %%r3, 4 \n\t" \
+ "stw %%r5, %0 \n\t" \
+ "stw %%r4, %1 \n\t" \
+ "stw %%r3, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
+ );
+
+#endif /* __MACH__ && __APPLE__ */
+
+#endif /* PPC32 */
+
+/*
+ * The Sparc(64) assembly is reported to be broken.
+ * Disable it for now, until we're able to fix it.
+ */
+#if 0 && defined(__sparc__)
+#if defined(__sparc64__)
+
+#define MULADDC_INIT \
+ asm( \
+ "ldx %3, %%o0 \n\t" \
+ "ldx %4, %%o1 \n\t" \
+ "ld %5, %%o2 \n\t" \
+ "ld %6, %%o3 \n\t"
+
+#define MULADDC_CORE \
+ "ld [%%o0], %%o4 \n\t" \
+ "inc 4, %%o0 \n\t" \
+ "ld [%%o1], %%o5 \n\t" \
+ "umul %%o3, %%o4, %%o4 \n\t" \
+ "addcc %%o4, %%o2, %%o4 \n\t" \
+ "rd %%y, %%g1 \n\t" \
+ "addx %%g1, 0, %%g1 \n\t" \
+ "addcc %%o4, %%o5, %%o4 \n\t" \
+ "st %%o4, [%%o1] \n\t" \
+ "addx %%g1, 0, %%o2 \n\t" \
+ "inc 4, %%o1 \n\t"
+
+ #define MULADDC_STOP \
+ "st %%o2, %0 \n\t" \
+ "stx %%o1, %1 \n\t" \
+ "stx %%o0, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "g1", "o0", "o1", "o2", "o3", "o4", \
+ "o5" \
+ );
+
+#else /* __sparc64__ */
+
+#define MULADDC_INIT \
+ asm( \
+ "ld %3, %%o0 \n\t" \
+ "ld %4, %%o1 \n\t" \
+ "ld %5, %%o2 \n\t" \
+ "ld %6, %%o3 \n\t"
+
+#define MULADDC_CORE \
+ "ld [%%o0], %%o4 \n\t" \
+ "inc 4, %%o0 \n\t" \
+ "ld [%%o1], %%o5 \n\t" \
+ "umul %%o3, %%o4, %%o4 \n\t" \
+ "addcc %%o4, %%o2, %%o4 \n\t" \
+ "rd %%y, %%g1 \n\t" \
+ "addx %%g1, 0, %%g1 \n\t" \
+ "addcc %%o4, %%o5, %%o4 \n\t" \
+ "st %%o4, [%%o1] \n\t" \
+ "addx %%g1, 0, %%o2 \n\t" \
+ "inc 4, %%o1 \n\t"
+
+#define MULADDC_STOP \
+ "st %%o2, %0 \n\t" \
+ "st %%o1, %1 \n\t" \
+ "st %%o0, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "g1", "o0", "o1", "o2", "o3", "o4", \
+ "o5" \
+ );
+
+#endif /* __sparc64__ */
+#endif /* __sparc__ */
+
+#if defined(__microblaze__) || defined(microblaze)
+
+#define MULADDC_INIT \
+ asm( \
+ "lwi r3, %3 \n\t" \
+ "lwi r4, %4 \n\t" \
+ "lwi r5, %5 \n\t" \
+ "lwi r6, %6 \n\t" \
+ "andi r7, r6, 0xffff \n\t" \
+ "bsrli r6, r6, 16 \n\t"
+
+#define MULADDC_CORE \
+ "lhui r8, r3, 0 \n\t" \
+ "addi r3, r3, 2 \n\t" \
+ "lhui r9, r3, 0 \n\t" \
+ "addi r3, r3, 2 \n\t" \
+ "mul r10, r9, r6 \n\t" \
+ "mul r11, r8, r7 \n\t" \
+ "mul r12, r9, r7 \n\t" \
+ "mul r13, r8, r6 \n\t" \
+ "bsrli r8, r10, 16 \n\t" \
+ "bsrli r9, r11, 16 \n\t" \
+ "add r13, r13, r8 \n\t" \
+ "add r13, r13, r9 \n\t" \
+ "bslli r10, r10, 16 \n\t" \
+ "bslli r11, r11, 16 \n\t" \
+ "add r12, r12, r10 \n\t" \
+ "addc r13, r13, r0 \n\t" \
+ "add r12, r12, r11 \n\t" \
+ "addc r13, r13, r0 \n\t" \
+ "lwi r10, r4, 0 \n\t" \
+ "add r12, r12, r10 \n\t" \
+ "addc r13, r13, r0 \n\t" \
+ "add r12, r12, r5 \n\t" \
+ "addc r5, r13, r0 \n\t" \
+ "swi r12, r4, 0 \n\t" \
+ "addi r4, r4, 4 \n\t"
+
+#define MULADDC_STOP \
+ "swi r5, %0 \n\t" \
+ "swi r4, %1 \n\t" \
+ "swi r3, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r3", "r4" "r5", "r6", "r7", "r8", \
+ "r9", "r10", "r11", "r12", "r13" \
+ );
+
+#endif /* MicroBlaze */
+
+#if defined(__tricore__)
+
+#define MULADDC_INIT \
+ asm( \
+ "ld.a %%a2, %3 \n\t" \
+ "ld.a %%a3, %4 \n\t" \
+ "ld.w %%d4, %5 \n\t" \
+ "ld.w %%d1, %6 \n\t" \
+ "xor %%d5, %%d5 \n\t"
+
+#define MULADDC_CORE \
+ "ld.w %%d0, [%%a2+] \n\t" \
+ "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
+ "ld.w %%d0, [%%a3] \n\t" \
+ "addx %%d2, %%d2, %%d0 \n\t" \
+ "addc %%d3, %%d3, 0 \n\t" \
+ "mov %%d4, %%d3 \n\t" \
+ "st.w [%%a3+], %%d2 \n\t"
+
+#define MULADDC_STOP \
+ "st.w %0, %%d4 \n\t" \
+ "st.a %1, %%a3 \n\t" \
+ "st.a %2, %%a2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "d0", "d1", "e2", "d4", "a2", "a3" \
+ );
+
+#endif /* TriCore */
+
+/*
+ * gcc -O0 by default uses r7 for the frame pointer, so it complains about our
+ * use of r7 below, unless -fomit-frame-pointer is passed. Unfortunately,
+ * passing that option is not easy when building with yotta.
+ *
+ * On the other hand, -fomit-frame-pointer is implied by any -Ox options with
+ * x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
+ * clang and armcc5 under the same conditions).
+ *
+ * So, only use the optimized assembly below for optimized build, which avoids
+ * the build error and is pretty reasonable anyway.
+ */
+#if defined(__GNUC__) && !defined(__OPTIMIZE__)
+#define MULADDC_CANNOT_USE_R7
+#endif
+
+#if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
+
+#if defined(__thumb__) && !defined(__thumb2__)
+
+#define MULADDC_INIT \
+ asm( \
+ "ldr r0, %3 \n\t" \
+ "ldr r1, %4 \n\t" \
+ "ldr r2, %5 \n\t" \
+ "ldr r3, %6 \n\t" \
+ "lsr r7, r3, #16 \n\t" \
+ "mov r9, r7 \n\t" \
+ "lsl r7, r3, #16 \n\t" \
+ "lsr r7, r7, #16 \n\t" \
+ "mov r8, r7 \n\t"
+
+#define MULADDC_CORE \
+ "ldmia r0!, {r6} \n\t" \
+ "lsr r7, r6, #16 \n\t" \
+ "lsl r6, r6, #16 \n\t" \
+ "lsr r6, r6, #16 \n\t" \
+ "mov r4, r8 \n\t" \
+ "mul r4, r6 \n\t" \
+ "mov r3, r9 \n\t" \
+ "mul r6, r3 \n\t" \
+ "mov r5, r9 \n\t" \
+ "mul r5, r7 \n\t" \
+ "mov r3, r8 \n\t" \
+ "mul r7, r3 \n\t" \
+ "lsr r3, r6, #16 \n\t" \
+ "add r5, r5, r3 \n\t" \
+ "lsr r3, r7, #16 \n\t" \
+ "add r5, r5, r3 \n\t" \
+ "add r4, r4, r2 \n\t" \
+ "mov r2, #0 \n\t" \
+ "adc r5, r2 \n\t" \
+ "lsl r3, r6, #16 \n\t" \
+ "add r4, r4, r3 \n\t" \
+ "adc r5, r2 \n\t" \
+ "lsl r3, r7, #16 \n\t" \
+ "add r4, r4, r3 \n\t" \
+ "adc r5, r2 \n\t" \
+ "ldr r3, [r1] \n\t" \
+ "add r4, r4, r3 \n\t" \
+ "adc r2, r5 \n\t" \
+ "stmia r1!, {r4} \n\t"
+
+#define MULADDC_STOP \
+ "str r2, %0 \n\t" \
+ "str r1, %1 \n\t" \
+ "str r0, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r0", "r1", "r2", "r3", "r4", "r5", \
+ "r6", "r7", "r8", "r9", "cc" \
+ );
+
+#else
+
+#define MULADDC_INIT \
+ asm( \
+ "ldr r0, %3 \n\t" \
+ "ldr r1, %4 \n\t" \
+ "ldr r2, %5 \n\t" \
+ "ldr r3, %6 \n\t"
+
+#define MULADDC_CORE \
+ "ldr r4, [r0], #4 \n\t" \
+ "mov r5, #0 \n\t" \
+ "ldr r6, [r1] \n\t" \
+ "umlal r2, r5, r3, r4 \n\t" \
+ "adds r7, r6, r2 \n\t" \
+ "adc r2, r5, #0 \n\t" \
+ "str r7, [r1], #4 \n\t"
+
+#define MULADDC_STOP \
+ "str r2, %0 \n\t" \
+ "str r1, %1 \n\t" \
+ "str r0, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "r0", "r1", "r2", "r3", "r4", "r5", \
+ "r6", "r7", "cc" \
+ );
+
+#endif /* Thumb */
+
+#endif /* ARMv3 */
+
+#if defined(__alpha__)
+
+#define MULADDC_INIT \
+ asm( \
+ "ldq $1, %3 \n\t" \
+ "ldq $2, %4 \n\t" \
+ "ldq $3, %5 \n\t" \
+ "ldq $4, %6 \n\t"
+
+#define MULADDC_CORE \
+ "ldq $6, 0($1) \n\t" \
+ "addq $1, 8, $1 \n\t" \
+ "mulq $6, $4, $7 \n\t" \
+ "umulh $6, $4, $6 \n\t" \
+ "addq $7, $3, $7 \n\t" \
+ "cmpult $7, $3, $3 \n\t" \
+ "ldq $5, 0($2) \n\t" \
+ "addq $7, $5, $7 \n\t" \
+ "cmpult $7, $5, $5 \n\t" \
+ "stq $7, 0($2) \n\t" \
+ "addq $2, 8, $2 \n\t" \
+ "addq $6, $3, $3 \n\t" \
+ "addq $5, $3, $3 \n\t"
+
+#define MULADDC_STOP \
+ "stq $3, %0 \n\t" \
+ "stq $2, %1 \n\t" \
+ "stq $1, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
+ );
+#endif /* Alpha */
+
+#if defined(__mips__) && !defined(__mips64)
+
+#define MULADDC_INIT \
+ asm( \
+ "lw $10, %3 \n\t" \
+ "lw $11, %4 \n\t" \
+ "lw $12, %5 \n\t" \
+ "lw $13, %6 \n\t"
+
+#define MULADDC_CORE \
+ "lw $14, 0($10) \n\t" \
+ "multu $13, $14 \n\t" \
+ "addi $10, $10, 4 \n\t" \
+ "mflo $14 \n\t" \
+ "mfhi $9 \n\t" \
+ "addu $14, $12, $14 \n\t" \
+ "lw $15, 0($11) \n\t" \
+ "sltu $12, $14, $12 \n\t" \
+ "addu $15, $14, $15 \n\t" \
+ "sltu $14, $15, $14 \n\t" \
+ "addu $12, $12, $9 \n\t" \
+ "sw $15, 0($11) \n\t" \
+ "addu $12, $12, $14 \n\t" \
+ "addi $11, $11, 4 \n\t"
+
+#define MULADDC_STOP \
+ "sw $12, %0 \n\t" \
+ "sw $11, %1 \n\t" \
+ "sw $10, %2 \n\t" \
+ : "=m" (c), "=m" (d), "=m" (s) \
+ : "m" (s), "m" (d), "m" (c), "m" (b) \
+ : "$9", "$10", "$11", "$12", "$13", "$14", "$15" \
+ );
+
+#endif /* MIPS */
+#endif /* GNUC */
+
+#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
+
+#define MULADDC_INIT \
+ __asm mov esi, s \
+ __asm mov edi, d \
+ __asm mov ecx, c \
+ __asm mov ebx, b
+
+#define MULADDC_CORE \
+ __asm lodsd \
+ __asm mul ebx \
+ __asm add eax, ecx \
+ __asm adc edx, 0 \
+ __asm add eax, [edi] \
+ __asm adc edx, 0 \
+ __asm mov ecx, edx \
+ __asm stosd
+
+#if defined(MBEDTLS_HAVE_SSE2)
+
+#define EMIT __asm _emit
+
+#define MULADDC_HUIT \
+ EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
+ EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
+ EMIT 0x0F EMIT 0x6E EMIT 0x1F \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
+ EMIT 0x0F EMIT 0x6E EMIT 0x16 \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
+ EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
+ EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
+ EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
+ EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
+ EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
+ EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
+ EMIT 0x0F EMIT 0x7E EMIT 0x0F \
+ EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
+ EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
+ EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
+ EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
+ EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
+ EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
+ EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
+ EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
+ EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
+ EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
+ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
+ EMIT 0x0F EMIT 0x7E EMIT 0xC9
+
+#define MULADDC_STOP \
+ EMIT 0x0F EMIT 0x77 \
+ __asm mov c, ecx \
+ __asm mov d, edi \
+ __asm mov s, esi \
+
+#else
+
+#define MULADDC_STOP \
+ __asm mov c, ecx \
+ __asm mov d, edi \
+ __asm mov s, esi \
+
+#endif /* SSE2 */
+#endif /* MSVC */
+
+#endif /* MBEDTLS_HAVE_ASM */
+
+#if !defined(MULADDC_CORE)
+#if defined(MBEDTLS_HAVE_UDBL)
+
+#define MULADDC_INIT \
+{ \
+ mbedtls_t_udbl r; \
+ mbedtls_mpi_uint r0, r1;
+
+#define MULADDC_CORE \
+ r = *(s++) * (mbedtls_t_udbl) b; \
+ r0 = (mbedtls_mpi_uint) r; \
+ r1 = (mbedtls_mpi_uint)( r >> biL ); \
+ r0 += c; r1 += (r0 < c); \
+ r0 += *d; r1 += (r0 < *d); \
+ c = r1; *(d++) = r0;
+
+#define MULADDC_STOP \
+}
+
+#else
+#define MULADDC_INIT \
+{ \
+ mbedtls_mpi_uint s0, s1, b0, b1; \
+ mbedtls_mpi_uint r0, r1, rx, ry; \
+ b0 = ( b << biH ) >> biH; \
+ b1 = ( b >> biH );
+
+#define MULADDC_CORE \
+ s0 = ( *s << biH ) >> biH; \
+ s1 = ( *s >> biH ); s++; \
+ rx = s0 * b1; r0 = s0 * b0; \
+ ry = s1 * b0; r1 = s1 * b1; \
+ r1 += ( rx >> biH ); \
+ r1 += ( ry >> biH ); \
+ rx <<= biH; ry <<= biH; \
+ r0 += rx; r1 += (r0 < rx); \
+ r0 += ry; r1 += (r0 < ry); \
+ r0 += c; r1 += (r0 < c); \
+ r0 += *d; r1 += (r0 < *d); \
+ c = r1; *(d++) = r0;
+
+#define MULADDC_STOP \
+}
+
+#endif /* C (generic) */
+#endif /* C (longlong) */
+
+#endif /* bn_mul.h */
+
+
+/********* Start of file include/mbedtls/camellia.h ************/
+
+/**
+ * \file camellia.h
+ *
+ * \brief Camellia block cipher
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_CAMELLIA_H
+#define MBEDTLS_CAMELLIA_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_CAMELLIA_ENCRYPT 1
+#define MBEDTLS_CAMELLIA_DECRYPT 0
+
+#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */
+#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
+#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */
+
+#if !defined(MBEDTLS_CAMELLIA_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief CAMELLIA context structure
+ */
+typedef struct
+{
+ int nr; /*!< number of rounds */
+ uint32_t rk[68]; /*!< CAMELLIA round keys */
+}
+mbedtls_camellia_context;
+
+/**
+ * \brief Initialize CAMELLIA context
+ *
+ * \param ctx CAMELLIA context to be initialized
+ */
+void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
+
+/**
+ * \brief Clear CAMELLIA context
+ *
+ * \param ctx CAMELLIA context to be cleared
+ */
+void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
+
+/**
+ * \brief CAMELLIA key schedule (encryption)
+ *
+ * \param ctx CAMELLIA context to be initialized
+ * \param key encryption key
+ * \param keybits must be 128, 192 or 256
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH
+ */
+int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief CAMELLIA key schedule (decryption)
+ *
+ * \param ctx CAMELLIA context to be initialized
+ * \param key decryption key
+ * \param keybits must be 128, 192 or 256
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH
+ */
+int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief CAMELLIA-ECB block encryption/decryption
+ *
+ * \param ctx CAMELLIA context
+ * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT
+ * \param input 16-byte input block
+ * \param output 16-byte output block
+ *
+ * \return 0 if successful
+ */
+int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
+ int mode,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+/**
+ * \brief CAMELLIA-CBC buffer encryption/decryption
+ * Length should be a multiple of the block
+ * size (16 bytes)
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ * \param ctx CAMELLIA context
+ * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT
+ * \param length length of the input data
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH
+ */
+int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
+/**
+ * \brief CAMELLIA-CFB128 buffer encryption/decryption
+ *
+ * Note: Due to the nature of CFB you should use the same key schedule for
+ * both encryption and decryption. So a context initialized with
+ * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT.
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ * \param ctx CAMELLIA context
+ * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT
+ * \param length length of the input data
+ * \param iv_off offset in IV (updated after use)
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH
+ */
+int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
+ int mode,
+ size_t length,
+ size_t *iv_off,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CFB */
+
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
+/**
+ * \brief CAMELLIA-CTR buffer encryption/decryption
+ *
+ * Warning: You have to keep the maximum use of your counter in mind!
+ *
+ * Note: Due to the nature of CTR you should use the same key schedule for
+ * both encryption and decryption. So a context initialized with
+ * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and MBEDTLS_CAMELLIA_DECRYPT.
+ *
+ * \param ctx CAMELLIA context
+ * \param length The length of the data
+ * \param nc_off The offset in the current stream_block (for resuming
+ * within current cipher stream). The offset pointer to
+ * should be 0 at the start of a stream.
+ * \param nonce_counter The 128-bit nonce and counter.
+ * \param stream_block The saved stream-block for resuming. Is overwritten
+ * by the function.
+ * \param input The input data stream
+ * \param output The output data stream
+ *
+ * \return 0 if successful
+ */
+int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
+ size_t length,
+ size_t *nc_off,
+ unsigned char nonce_counter[16],
+ unsigned char stream_block[16],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CTR */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_CAMELLIA_ALT */
+
+#endif /* MBEDTLS_CAMELLIA_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_camellia_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* camellia.h */
+
+
+/********* Start of file include/mbedtls/ctr_drbg.h ************/
+
+/**
+ * \file ctr_drbg.h
+ *
+ * \brief CTR_DRBG is based on AES-256, as defined in NIST SP 800-90A:
+ * Recommendation for Random Number Generation Using Deterministic
+ * Random Bit Generators.
+ *
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_CTR_DRBG_H
+#define MBEDTLS_CTR_DRBG_H
+
+
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */
+#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< The requested random buffer length is too big. */
+#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< The input (entropy + additional data) is too large. */
+#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */
+
+#define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */
+#define MBEDTLS_CTR_DRBG_KEYSIZE 32 /**< The key size used by the cipher. */
+#define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */
+#define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them using the compiler command
+ * line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
+#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
+#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
+/**< The amount of entropy used per seed by default:
+ * - 48 with SHA-512.
+ * - 32 with SHA-256.
+ */
+#else
+#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
+/**< Amount of entropy used per seed by default:
+ * - 48 with SHA-512.
+ * - 32 with SHA-256.
+ */
+#endif
+#endif
+
+#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
+#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
+/**< The interval before reseed is performed by default. */
+#endif
+
+#if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
+#define MBEDTLS_CTR_DRBG_MAX_INPUT 256
+/**< The maximum number of additional input Bytes. */
+#endif
+
+#if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
+#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
+/**< The maximum number of requested Bytes per call. */
+#endif
+
+#if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
+#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
+/**< The maximum size of seed or reseed buffer. */
+#endif
+
+/* \} name SECTION: Module settings */
+
+#define MBEDTLS_CTR_DRBG_PR_OFF 0
+/**< Prediction resistance is disabled. */
+#define MBEDTLS_CTR_DRBG_PR_ON 1
+/**< Prediction resistance is enabled. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The CTR_DRBG context structure.
+ */
+typedef struct
+{
+ unsigned char counter[16]; /*!< The counter (V). */
+ int reseed_counter; /*!< The reseed counter. */
+ int prediction_resistance; /*!< This determines whether prediction
+ resistance is enabled, that is
+ whether to systematically reseed before
+ each random generation. */
+ size_t entropy_len; /*!< The amount of entropy grabbed on each
+ seed or reseed operation. */
+ int reseed_interval; /*!< The reseed interval. */
+
+ mbedtls_aes_context aes_ctx; /*!< The AES context. */
+
+ /*
+ * Callbacks (Entropy)
+ */
+ int (*f_entropy)(void *, unsigned char *, size_t);
+ /*!< The entropy callback function. */
+
+ void *p_entropy; /*!< The context for the entropy function. */
+
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex;
+#endif
+}
+mbedtls_ctr_drbg_context;
+
+/**
+ * \brief This function initializes the CTR_DRBG context,
+ * and prepares it for mbedtls_ctr_drbg_seed()
+ * or mbedtls_ctr_drbg_free().
+ *
+ * \param ctx The CTR_DRBG context to initialize.
+ */
+void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
+
+/**
+ * \brief This function seeds and sets up the CTR_DRBG
+ * entropy source for future reseeds.
+ *
+ * \note Personalization data can be provided in addition to the more generic
+ * entropy source, to make this instantiation as unique as possible.
+ *
+ * \param ctx The CTR_DRBG context to seed.
+ * \param f_entropy The entropy callback, taking as arguments the
+ * \p p_entropy context, the buffer to fill, and the
+ length of the buffer.
+ * \param p_entropy The entropy context.
+ * \param custom Personalization data, that is device-specific
+ identifiers. Can be NULL.
+ * \param len The length of the personalization data.
+ *
+ * \return \c 0 on success, or
+ * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
+ */
+int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
+ int (*f_entropy)(void *, unsigned char *, size_t),
+ void *p_entropy,
+ const unsigned char *custom,
+ size_t len );
+
+/**
+ * \brief This function clears CTR_CRBG context data.
+ *
+ * \param ctx The CTR_DRBG context to clear.
+ */
+void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
+
+/**
+ * \brief This function turns prediction resistance on or off.
+ * The default value is off.
+ *
+ * \note If enabled, entropy is gathered at the beginning of
+ * every call to mbedtls_ctr_drbg_random_with_add().
+ * Only use this if your entropy source has sufficient
+ * throughput.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param resistance #MBEDTLS_CTR_DRBG_PR_ON or #MBEDTLS_CTR_DRBG_PR_OFF.
+ */
+void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
+ int resistance );
+
+/**
+ * \brief This function sets the amount of entropy grabbed on each
+ * seed or reseed. The default value is
+ * #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param len The amount of entropy to grab.
+ */
+void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
+ size_t len );
+
+/**
+ * \brief This function sets the reseed interval.
+ * The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param interval The reseed interval.
+ */
+void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
+ int interval );
+
+/**
+ * \brief This function reseeds the CTR_DRBG context, that is
+ * extracts data from the entropy source.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param additional Additional data to add to the state. Can be NULL.
+ * \param len The length of the additional data.
+ *
+ * \return \c 0 on success, or
+ * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
+ */
+int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
+ const unsigned char *additional, size_t len );
+
+/**
+ * \brief This function updates the state of the CTR_DRBG context.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param additional The data to update the state with.
+ * \param add_len Length of \p additional data.
+ *
+ * \note If \p add_len is greater than #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT,
+ * only the first #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used.
+ * The remaining Bytes are silently discarded.
+ */
+void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
+ const unsigned char *additional, size_t add_len );
+
+/**
+ * \brief This function updates a CTR_DRBG instance with additional
+ * data and uses it to generate random data.
+ *
+ * \note The function automatically reseeds if the reseed counter is exceeded.
+ *
+ * \param p_rng The CTR_DRBG context. This must be a pointer to a
+ * #mbedtls_ctr_drbg_context structure.
+ * \param output The buffer to fill.
+ * \param output_len The length of the buffer.
+ * \param additional Additional data to update. Can be NULL.
+ * \param add_len The length of the additional data.
+ *
+ * \return \c 0 on success, or
+ * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
+ * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
+ */
+int mbedtls_ctr_drbg_random_with_add( void *p_rng,
+ unsigned char *output, size_t output_len,
+ const unsigned char *additional, size_t add_len );
+
+/**
+ * \brief This function uses CTR_DRBG to generate random data.
+ *
+ * \note The function automatically reseeds if the reseed counter is exceeded.
+ *
+ * \param p_rng The CTR_DRBG context. This must be a pointer to a
+ * #mbedtls_ctr_drbg_context structure.
+ * \param output The buffer to fill.
+ * \param output_len The length of the buffer.
+ *
+ * \return \c 0 on success, or
+ * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
+ * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
+ */
+int mbedtls_ctr_drbg_random( void *p_rng,
+ unsigned char *output, size_t output_len );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief This function writes a seed file.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param path The name of the file.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or
+ * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
+ * failure.
+ */
+int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
+
+/**
+ * \brief This function reads and updates a seed file. The seed
+ * is added to this instance.
+ *
+ * \param ctx The CTR_DRBG context.
+ * \param path The name of the file.
+ *
+ * \return \c 0 on success,
+ * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error,
+ * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
+ * #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG on failure.
+ */
+int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
+#endif /* MBEDTLS_FS_IO */
+
+/**
+ * \brief The CTR_DRBG checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_ctr_drbg_self_test( int verbose );
+
+/* Internal functions (do not call directly) */
+int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
+ int (*)(void *, unsigned char *, size_t), void *,
+ const unsigned char *, size_t, size_t );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ctr_drbg.h */
+
+
+/********* Start of file include/mbedtls/des.h ************/
+
+/**
+ * \file des.h
+ *
+ * \brief DES block cipher
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ *
+ */
+#ifndef MBEDTLS_DES_H
+#define MBEDTLS_DES_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_DES_ENCRYPT 1
+#define MBEDTLS_DES_DECRYPT 0
+
+#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032 /**< The data input has an invalid length. */
+#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033 /**< DES hardware accelerator failed. */
+
+#define MBEDTLS_DES_KEY_SIZE 8
+
+#if !defined(MBEDTLS_DES_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief DES context structure
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+typedef struct
+{
+ uint32_t sk[32]; /*!< DES subkeys */
+}
+mbedtls_des_context;
+
+/**
+ * \brief Triple-DES context structure
+ */
+typedef struct
+{
+ uint32_t sk[96]; /*!< 3DES subkeys */
+}
+mbedtls_des3_context;
+
+/**
+ * \brief Initialize DES context
+ *
+ * \param ctx DES context to be initialized
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+void mbedtls_des_init( mbedtls_des_context *ctx );
+
+/**
+ * \brief Clear DES context
+ *
+ * \param ctx DES context to be cleared
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+void mbedtls_des_free( mbedtls_des_context *ctx );
+
+/**
+ * \brief Initialize Triple-DES context
+ *
+ * \param ctx DES3 context to be initialized
+ */
+void mbedtls_des3_init( mbedtls_des3_context *ctx );
+
+/**
+ * \brief Clear Triple-DES context
+ *
+ * \param ctx DES3 context to be cleared
+ */
+void mbedtls_des3_free( mbedtls_des3_context *ctx );
+
+/**
+ * \brief Set key parity on the given key to odd.
+ *
+ * DES keys are 56 bits long, but each byte is padded with
+ * a parity bit to allow verification.
+ *
+ * \param key 8-byte secret key
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+
+/**
+ * \brief Check that key parity on the given key is odd.
+ *
+ * DES keys are 56 bits long, but each byte is padded with
+ * a parity bit to allow verification.
+ *
+ * \param key 8-byte secret key
+ *
+ * \return 0 is parity was ok, 1 if parity was not correct.
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+
+/**
+ * \brief Check that key is not a weak or semi-weak DES key
+ *
+ * \param key 8-byte secret key
+ *
+ * \return 0 if no weak key was found, 1 if a weak key was identified.
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+
+/**
+ * \brief DES key schedule (56-bit, encryption)
+ *
+ * \param ctx DES context to be initialized
+ * \param key 8-byte secret key
+ *
+ * \return 0
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+
+/**
+ * \brief DES key schedule (56-bit, decryption)
+ *
+ * \param ctx DES context to be initialized
+ * \param key 8-byte secret key
+ *
+ * \return 0
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+
+/**
+ * \brief Triple-DES key schedule (112-bit, encryption)
+ *
+ * \param ctx 3DES context to be initialized
+ * \param key 16-byte secret key
+ *
+ * \return 0
+ */
+int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
+ const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
+
+/**
+ * \brief Triple-DES key schedule (112-bit, decryption)
+ *
+ * \param ctx 3DES context to be initialized
+ * \param key 16-byte secret key
+ *
+ * \return 0
+ */
+int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
+ const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
+
+/**
+ * \brief Triple-DES key schedule (168-bit, encryption)
+ *
+ * \param ctx 3DES context to be initialized
+ * \param key 24-byte secret key
+ *
+ * \return 0
+ */
+int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
+ const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
+
+/**
+ * \brief Triple-DES key schedule (168-bit, decryption)
+ *
+ * \param ctx 3DES context to be initialized
+ * \param key 24-byte secret key
+ *
+ * \return 0
+ */
+int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
+ const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
+
+/**
+ * \brief DES-ECB block encryption/decryption
+ *
+ * \param ctx DES context
+ * \param input 64-bit input block
+ * \param output 64-bit output block
+ *
+ * \return 0 if successful
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
+ const unsigned char input[8],
+ unsigned char output[8] );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+/**
+ * \brief DES-CBC buffer encryption/decryption
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ * \param ctx DES context
+ * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
+ * \param length length of the input data
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[8],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+
+/**
+ * \brief 3DES-ECB block encryption/decryption
+ *
+ * \param ctx 3DES context
+ * \param input 64-bit input block
+ * \param output 64-bit output block
+ *
+ * \return 0 if successful
+ */
+int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
+ const unsigned char input[8],
+ unsigned char output[8] );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+/**
+ * \brief 3DES-CBC buffer encryption/decryption
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ * \param ctx 3DES context
+ * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
+ * \param length length of the input data
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
+ */
+int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[8],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+
+/**
+ * \brief Internal function for key expansion.
+ * (Only exposed to allow overriding it,
+ * see MBEDTLS_DES_SETKEY_ALT)
+ *
+ * \param SK Round keys
+ * \param key Base key
+ *
+ * \warning DES is considered a weak cipher and its use constitutes a
+ * security risk. We recommend considering stronger ciphers
+ * instead.
+ */
+void mbedtls_des_setkey( uint32_t SK[32],
+ const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_DES_ALT */
+
+#endif /* MBEDTLS_DES_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_des_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* des.h */
+
+
+/********* Start of file include/mbedtls/entropy.h ************/
+
+/**
+ * \file entropy.h
+ *
+ * \brief Entropy accumulator implementation
+ */
+/*
+ * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ENTROPY_H
+#define MBEDTLS_ENTROPY_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
+
+#define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR
+#else
+#if defined(MBEDTLS_SHA256_C)
+#define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR
+
+#endif
+#endif
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+#if defined(MBEDTLS_HAVEGE_C)
+
+#endif
+
+#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C /**< Critical entropy source failure. */
+#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E /**< No more sources can be added. */
+#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 /**< No sources have been added to poll. */
+#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D /**< No strong sources have been added to poll. */
+#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F /**< Read/write error in file. */
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_ENTROPY_MAX_SOURCES)
+#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
+#endif
+
+#if !defined(MBEDTLS_ENTROPY_MAX_GATHER)
+#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
+#endif
+
+/* \} name SECTION: Module settings */
+
+#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
+#define MBEDTLS_ENTROPY_BLOCK_SIZE 64 /**< Block size of entropy accumulator (SHA-512) */
+#else
+#define MBEDTLS_ENTROPY_BLOCK_SIZE 32 /**< Block size of entropy accumulator (SHA-256) */
+#endif
+
+#define MBEDTLS_ENTROPY_MAX_SEED_SIZE 1024 /**< Maximum size of seed we read from seed file */
+#define MBEDTLS_ENTROPY_SOURCE_MANUAL MBEDTLS_ENTROPY_MAX_SOURCES
+
+#define MBEDTLS_ENTROPY_SOURCE_STRONG 1 /**< Entropy source is strong */
+#define MBEDTLS_ENTROPY_SOURCE_WEAK 0 /**< Entropy source is weak */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Entropy poll callback pointer
+ *
+ * \param data Callback-specific data pointer
+ * \param output Data to fill
+ * \param len Maximum size to provide
+ * \param olen The actual amount of bytes put into the buffer (Can be 0)
+ *
+ * \return 0 if no critical failures occurred,
+ * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise
+ */
+typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
+ size_t *olen);
+
+/**
+ * \brief Entropy source state
+ */
+typedef struct
+{
+ mbedtls_entropy_f_source_ptr f_source; /**< The entropy source callback */
+ void * p_source; /**< The callback data pointer */
+ size_t size; /**< Amount received in bytes */
+ size_t threshold; /**< Minimum bytes required before release */
+ int strong; /**< Is the source strong? */
+}
+mbedtls_entropy_source_state;
+
+/**
+ * \brief Entropy context structure
+ */
+typedef struct
+{
+ int accumulator_started;
+#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
+ mbedtls_sha512_context accumulator;
+#else
+ mbedtls_sha256_context accumulator;
+#endif
+ int source_count;
+ mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
+#if defined(MBEDTLS_HAVEGE_C)
+ mbedtls_havege_state havege_data;
+#endif
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex; /*!< mutex */
+#endif
+#if defined(MBEDTLS_ENTROPY_NV_SEED)
+ int initial_entropy_run;
+#endif
+}
+mbedtls_entropy_context;
+
+/**
+ * \brief Initialize the context
+ *
+ * \param ctx Entropy context to initialize
+ */
+void mbedtls_entropy_init( mbedtls_entropy_context *ctx );
+
+/**
+ * \brief Free the data in the context
+ *
+ * \param ctx Entropy context to free
+ */
+void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
+
+/**
+ * \brief Adds an entropy source to poll
+ * (Thread-safe if MBEDTLS_THREADING_C is enabled)
+ *
+ * \param ctx Entropy context
+ * \param f_source Entropy function
+ * \param p_source Function data
+ * \param threshold Minimum required from source before entropy is released
+ * ( with mbedtls_entropy_func() ) (in bytes)
+ * \param strong MBEDTLS_ENTROPY_SOURCE_STRONG or
+ * MBEDTSL_ENTROPY_SOURCE_WEAK.
+ * At least one strong source needs to be added.
+ * Weaker sources (such as the cycle counter) can be used as
+ * a complement.
+ *
+ * \return 0 if successful or MBEDTLS_ERR_ENTROPY_MAX_SOURCES
+ */
+int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
+ mbedtls_entropy_f_source_ptr f_source, void *p_source,
+ size_t threshold, int strong );
+
+/**
+ * \brief Trigger an extra gather poll for the accumulator
+ * (Thread-safe if MBEDTLS_THREADING_C is enabled)
+ *
+ * \param ctx Entropy context
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+ */
+int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
+
+/**
+ * \brief Retrieve entropy from the accumulator
+ * (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE)
+ * (Thread-safe if MBEDTLS_THREADING_C is enabled)
+ *
+ * \param data Entropy context
+ * \param output Buffer to fill
+ * \param len Number of bytes desired, must be at most MBEDTLS_ENTROPY_BLOCK_SIZE
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+ */
+int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
+
+/**
+ * \brief Add data to the accumulator manually
+ * (Thread-safe if MBEDTLS_THREADING_C is enabled)
+ *
+ * \param ctx Entropy context
+ * \param data Data to add
+ * \param len Length of data
+ *
+ * \return 0 if successful
+ */
+int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
+ const unsigned char *data, size_t len );
+
+#if defined(MBEDTLS_ENTROPY_NV_SEED)
+/**
+ * \brief Trigger an update of the seed file in NV by using the
+ * current entropy pool.
+ *
+ * \param ctx Entropy context
+ *
+ * \return 0 if successful
+ */
+int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
+#endif /* MBEDTLS_ENTROPY_NV_SEED */
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief Write a seed file
+ *
+ * \param ctx Entropy context
+ * \param path Name of the file
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error, or
+ * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+ */
+int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
+
+/**
+ * \brief Read and update a seed file. Seed is added to this
+ * instance. No more than MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes are
+ * read from the seed file. The rest is ignored.
+ *
+ * \param ctx Entropy context
+ * \param path Name of the file
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error,
+ * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+ */
+int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
+#endif /* MBEDTLS_FS_IO */
+
+#if defined(MBEDTLS_SELF_TEST)
+/**
+ * \brief Checkup routine
+ *
+ * This module self-test also calls the entropy self-test,
+ * mbedtls_entropy_source_self_test();
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int mbedtls_entropy_self_test( int verbose );
+
+#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
+/**
+ * \brief Checkup routine
+ *
+ * Verifies the integrity of the hardware entropy source
+ * provided by the function 'mbedtls_hardware_poll()'.
+ *
+ * Note this is the only hardware entropy source that is known
+ * at link time, and other entropy sources configured
+ * dynamically at runtime by the function
+ * mbedtls_entropy_add_source() will not be tested.
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int mbedtls_entropy_source_self_test( int verbose );
+#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
+#endif /* MBEDTLS_SELF_TEST */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* entropy.h */
+
+
+/********* Start of file include/mbedtls/entropy_poll.h ************/
+
+/**
+ * \file entropy_poll.h
+ *
+ * \brief Platform-specific and custom entropy polling functions
+ */
+/*
+ * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ENTROPY_POLL_H
+#define MBEDTLS_ENTROPY_POLL_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Default thresholds for built-in sources, in bytes
+ */
+#define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */
+#define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */
+#define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */
+#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
+#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
+#endif
+
+/**
+ * \brief Entropy poll callback that provides 0 entropy.
+ */
+#if defined(MBEDTLS_TEST_NULL_ENTROPY)
+ int mbedtls_null_entropy_poll( void *data,
+ unsigned char *output, size_t len, size_t *olen );
+#endif
+
+#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
+/**
+ * \brief Platform-specific entropy poll callback
+ */
+int mbedtls_platform_entropy_poll( void *data,
+ unsigned char *output, size_t len, size_t *olen );
+#endif
+
+#if defined(MBEDTLS_HAVEGE_C)
+/**
+ * \brief HAVEGE based entropy poll callback
+ *
+ * Requires an HAVEGE state as its data pointer.
+ */
+int mbedtls_havege_poll( void *data,
+ unsigned char *output, size_t len, size_t *olen );
+#endif
+
+#if defined(MBEDTLS_TIMING_C)
+/**
+ * \brief mbedtls_timing_hardclock-based entropy poll callback
+ */
+int mbedtls_hardclock_poll( void *data,
+ unsigned char *output, size_t len, size_t *olen );
+#endif
+
+#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
+/**
+ * \brief Entropy poll callback for a hardware source
+ *
+ * \warning This is not provided by mbed TLS!
+ * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h.
+ *
+ * \note This must accept NULL as its first argument.
+ */
+int mbedtls_hardware_poll( void *data,
+ unsigned char *output, size_t len, size_t *olen );
+#endif
+
+#if defined(MBEDTLS_ENTROPY_NV_SEED)
+/**
+ * \brief Entropy poll callback for a non-volatile seed file
+ *
+ * \note This must accept NULL as its first argument.
+ */
+int mbedtls_nv_seed_poll( void *data,
+ unsigned char *output, size_t len, size_t *olen );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* entropy_poll.h */
+
+
+/********* Start of file include/mbedtls/havege.h ************/
+
+/**
+ * \file havege.h
+ *
+ * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_HAVEGE_H
+#define MBEDTLS_HAVEGE_H
+
+#include
+
+#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief HAVEGE state structure
+ */
+typedef struct
+{
+ int PT1, PT2, offset[2];
+ int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
+ int WALK[8192];
+}
+mbedtls_havege_state;
+
+/**
+ * \brief HAVEGE initialization
+ *
+ * \param hs HAVEGE state to be initialized
+ */
+void mbedtls_havege_init( mbedtls_havege_state *hs );
+
+/**
+ * \brief Clear HAVEGE state
+ *
+ * \param hs HAVEGE state to be cleared
+ */
+void mbedtls_havege_free( mbedtls_havege_state *hs );
+
+/**
+ * \brief HAVEGE rand function
+ *
+ * \param p_rng A HAVEGE state
+ * \param output Buffer to fill
+ * \param len Length of buffer
+ *
+ * \return 0
+ */
+int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* havege.h */
+
+
+/********* Start of file include/mbedtls/memory_buffer_alloc.h ************/
+
+/**
+ * \file memory_buffer_alloc.h
+ *
+ * \brief Buffer-based memory allocator
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H
+#define MBEDTLS_MEMORY_BUFFER_ALLOC_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_MEMORY_ALIGN_MULTIPLE)
+#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
+#endif
+
+/* \} name SECTION: Module settings */
+
+#define MBEDTLS_MEMORY_VERIFY_NONE 0
+#define MBEDTLS_MEMORY_VERIFY_ALLOC (1 << 0)
+#define MBEDTLS_MEMORY_VERIFY_FREE (1 << 1)
+#define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Initialize use of stack-based memory allocator.
+ * The stack-based allocator does memory management inside the
+ * presented buffer and does not call calloc() and free().
+ * It sets the global mbedtls_calloc() and mbedtls_free() pointers
+ * to its own functions.
+ * (Provided mbedtls_calloc() and mbedtls_free() are thread-safe if
+ * MBEDTLS_THREADING_C is defined)
+ *
+ * \note This code is not optimized and provides a straight-forward
+ * implementation of a stack-based memory allocator.
+ *
+ * \param buf buffer to use as heap
+ * \param len size of the buffer
+ */
+void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len );
+
+/**
+ * \brief Free the mutex for thread-safety and clear remaining memory
+ */
+void mbedtls_memory_buffer_alloc_free( void );
+
+/**
+ * \brief Determine when the allocator should automatically verify the state
+ * of the entire chain of headers / meta-data.
+ * (Default: MBEDTLS_MEMORY_VERIFY_NONE)
+ *
+ * \param verify One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC,
+ * MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS
+ */
+void mbedtls_memory_buffer_set_verify( int verify );
+
+#if defined(MBEDTLS_MEMORY_DEBUG)
+/**
+ * \brief Print out the status of the allocated memory (primarily for use
+ * after a program should have de-allocated all memory)
+ * Prints out a list of 'still allocated' blocks and their stack
+ * trace if MBEDTLS_MEMORY_BACKTRACE is defined.
+ */
+void mbedtls_memory_buffer_alloc_status( void );
+
+/**
+ * \brief Get the peak heap usage so far
+ *
+ * \param max_used Peak number of bytes in use or committed. This
+ * includes bytes in allocated blocks too small to split
+ * into smaller blocks but larger than the requested size.
+ * \param max_blocks Peak number of blocks in use, including free and used
+ */
+void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks );
+
+/**
+ * \brief Reset peak statistics
+ */
+void mbedtls_memory_buffer_alloc_max_reset( void );
+
+/**
+ * \brief Get the current heap usage
+ *
+ * \param cur_used Current number of bytes in use or committed. This
+ * includes bytes in allocated blocks too small to split
+ * into smaller blocks but larger than the requested size.
+ * \param cur_blocks Current number of blocks in use, including free and used
+ */
+void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks );
+#endif /* MBEDTLS_MEMORY_DEBUG */
+
+/**
+ * \brief Verifies that all headers in the memory buffer are correct
+ * and contain sane values. Helps debug buffer-overflow errors.
+ *
+ * Prints out first failure if MBEDTLS_MEMORY_DEBUG is defined.
+ * Prints out full header information if MBEDTLS_MEMORY_DEBUG
+ * is defined. (Includes stack trace information for each block if
+ * MBEDTLS_MEMORY_BACKTRACE is defined as well).
+ *
+ * \return 0 if verified, 1 otherwise
+ */
+int mbedtls_memory_buffer_alloc_verify( void );
+
+#if defined(MBEDTLS_SELF_TEST)
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int mbedtls_memory_buffer_alloc_self_test( int verbose );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* memory_buffer_alloc.h */
+
+
+/********* Start of file include/mbedtls/padlock.h ************/
+
+/**
+ * \file padlock.h
+ *
+ * \brief VIA PadLock ACE for HW encryption/decryption supported by some
+ * processors
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PADLOCK_H
+#define MBEDTLS_PADLOCK_H
+
+
+
+#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
+
+#if defined(__has_feature)
+#if __has_feature(address_sanitizer)
+#define MBEDTLS_HAVE_ASAN
+#endif
+#endif
+
+/* Some versions of ASan result in errors about not enough registers */
+#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
+ !defined(MBEDTLS_HAVE_ASAN)
+
+#ifndef MBEDTLS_HAVE_X86
+#define MBEDTLS_HAVE_X86
+#endif
+
+#include
+
+#define MBEDTLS_PADLOCK_RNG 0x000C
+#define MBEDTLS_PADLOCK_ACE 0x00C0
+#define MBEDTLS_PADLOCK_PHE 0x0C00
+#define MBEDTLS_PADLOCK_PMM 0x3000
+
+#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief PadLock detection routine
+ *
+ * \param feature The feature to detect
+ *
+ * \return 1 if CPU has support for the feature, 0 otherwise
+ */
+int mbedtls_padlock_has_support( int feature );
+
+/**
+ * \brief PadLock AES-ECB block en(de)cryption
+ *
+ * \param ctx AES context
+ * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
+ * \param input 16-byte input block
+ * \param output 16-byte output block
+ *
+ * \return 0 if success, 1 if operation failed
+ */
+int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
+ int mode,
+ const unsigned char input[16],
+ unsigned char output[16] );
+
+/**
+ * \brief PadLock AES-CBC buffer en(de)cryption
+ *
+ * \param ctx AES context
+ * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
+ * \param length length of the input data
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \return 0 if success, 1 if operation failed
+ */
+int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAVE_X86 */
+
+#endif /* padlock.h */
+
+
+/********* Start of file include/mbedtls/timing.h ************/
+
+/**
+ * \file timing.h
+ *
+ * \brief Portable interface to timeouts and to the CPU cycle counter
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_TIMING_H
+#define MBEDTLS_TIMING_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#if !defined(MBEDTLS_TIMING_ALT)
+// Regular implementation
+//
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief timer structure
+ */
+struct mbedtls_timing_hr_time
+{
+ unsigned char opaque[32];
+};
+
+/**
+ * \brief Context for mbedtls_timing_set/get_delay()
+ */
+typedef struct
+{
+ struct mbedtls_timing_hr_time timer;
+ uint32_t int_ms;
+ uint32_t fin_ms;
+} mbedtls_timing_delay_context;
+
+extern volatile int mbedtls_timing_alarmed;
+
+/**
+ * \brief Return the CPU cycle counter value
+ *
+ * \warning This is only a best effort! Do not rely on this!
+ * In particular, it is known to be unreliable on virtual
+ * machines.
+ *
+ * \note This value starts at an unspecified origin and
+ * may wrap around.
+ */
+unsigned long mbedtls_timing_hardclock( void );
+
+/**
+ * \brief Return the elapsed time in milliseconds
+ *
+ * \param val points to a timer structure
+ * \param reset If 0, query the elapsed time. Otherwise (re)start the timer.
+ *
+ * \return Elapsed time since the previous reset in ms. When
+ * restarting, this is always 0.
+ *
+ * \note To initialize a timer, call this function with reset=1.
+ *
+ * Determining the elapsed time and resetting the timer is not
+ * atomic on all platforms, so after the sequence
+ * `{ get_timer(1); ...; time1 = get_timer(1); ...; time2 =
+ * get_timer(0) }` the value time1+time2 is only approximately
+ * the delay since the first reset.
+ */
+unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset );
+
+/**
+ * \brief Setup an alarm clock
+ *
+ * \param seconds delay before the "mbedtls_timing_alarmed" flag is set
+ * (must be >=0)
+ *
+ * \warning Only one alarm at a time is supported. In a threaded
+ * context, this means one for the whole process, not one per
+ * thread.
+ */
+void mbedtls_set_alarm( int seconds );
+
+/**
+ * \brief Set a pair of delays to watch
+ * (See \c mbedtls_timing_get_delay().)
+ *
+ * \param data Pointer to timing data.
+ * Must point to a valid \c mbedtls_timing_delay_context struct.
+ * \param int_ms First (intermediate) delay in milliseconds.
+ * The effect if int_ms > fin_ms is unspecified.
+ * \param fin_ms Second (final) delay in milliseconds.
+ * Pass 0 to cancel the current delay.
+ *
+ * \note To set a single delay, either use \c mbedtls_timing_set_timer
+ * directly or use this function with int_ms == fin_ms.
+ */
+void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms );
+
+/**
+ * \brief Get the status of delays
+ * (Memory helper: number of delays passed.)
+ *
+ * \param data Pointer to timing data
+ * Must point to a valid \c mbedtls_timing_delay_context struct.
+ *
+ * \return -1 if cancelled (fin_ms = 0),
+ * 0 if none of the delays are passed,
+ * 1 if only the intermediate delay is passed,
+ * 2 if the final delay is passed.
+ */
+int mbedtls_timing_get_delay( void *data );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_TIMING_ALT */
+
+#endif /* MBEDTLS_TIMING_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(MBEDTLS_SELF_TEST)
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int mbedtls_timing_self_test( int verbose );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* timing.h */
+
+
+/********* Start of file include/mbedtls/xtea.h ************/
+
+/**
+ * \file xtea.h
+ *
+ * \brief XTEA block cipher (32-bit)
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_XTEA_H
+#define MBEDTLS_XTEA_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_XTEA_ENCRYPT 1
+#define MBEDTLS_XTEA_DECRYPT 0
+
+#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
+#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
+
+#if !defined(MBEDTLS_XTEA_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief XTEA context structure
+ */
+typedef struct
+{
+ uint32_t k[4]; /*!< key */
+}
+mbedtls_xtea_context;
+
+/**
+ * \brief Initialize XTEA context
+ *
+ * \param ctx XTEA context to be initialized
+ */
+void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
+
+/**
+ * \brief Clear XTEA context
+ *
+ * \param ctx XTEA context to be cleared
+ */
+void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
+
+/**
+ * \brief XTEA key schedule
+ *
+ * \param ctx XTEA context to be initialized
+ * \param key the secret key
+ */
+void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
+
+/**
+ * \brief XTEA cipher function
+ *
+ * \param ctx XTEA context
+ * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
+ * \param input 8-byte input block
+ * \param output 8-byte output block
+ *
+ * \return 0 if successful
+ */
+int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
+ int mode,
+ const unsigned char input[8],
+ unsigned char output[8] );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+/**
+ * \brief XTEA CBC cipher function
+ *
+ * \param ctx XTEA context
+ * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
+ * \param length the length of input, multiple of 8
+ * \param iv initialization vector for CBC mode
+ * \param input input block
+ * \param output output block
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
+ */
+int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[8],
+ const unsigned char *input,
+ unsigned char *output);
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_XTEA_ALT */
+
+#endif /* MBEDTLS_XTEA_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_xtea_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* xtea.h */
+
+
+/********* Start of file include/mbedtls/ssl.h ************/
+
+/**
+ * \file ssl.h
+ *
+ * \brief SSL/TLS functions.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SSL_H
+#define MBEDTLS_SSL_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+
+
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+
+
+#endif
+
+#if defined(MBEDTLS_DHM_C)
+
+#endif
+
+#if defined(MBEDTLS_ECDH_C)
+
+#endif
+
+#if defined(MBEDTLS_ZLIB_SUPPORT)
+
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library"
+#endif
+
+#if defined(MBEDTLS_DEPRECATED_REMOVED)
+#error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set"
+#endif
+
+
+#endif
+
+#if defined(MBEDTLS_HAVE_TIME)
+
+#endif
+
+/*
+ * SSL Error codes
+ */
+#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */
+#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */
+#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */
+#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */
+#define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */
+#define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
+#define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */
+#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
+#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */
+#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
+#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */
+#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
+#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */
+#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
+#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */
+#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */
+#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */
+#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */
+#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */
+#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */
+#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */
+#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */
+#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */
+#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */
+#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
+#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */
+#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */
+#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */
+#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */
+#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */
+#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */
+#define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
+#define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< Connection requires a read call. */
+#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */
+#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */
+#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */
+#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */
+#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */
+#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */
+
+/*
+ * Various constants
+ */
+#define MBEDTLS_SSL_MAJOR_VERSION_3 3
+#define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
+#define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
+#define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
+#define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
+
+#define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
+#define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
+
+#define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 /*!< Maximum host name defined in RFC 1035 */
+
+/* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
+ * NONE must be zero so that memset()ing structure to zero works */
+#define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 /*!< don't use this extension */
+#define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 /*!< MaxFragmentLength 2^9 */
+#define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 /*!< MaxFragmentLength 2^10 */
+#define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 /*!< MaxFragmentLength 2^11 */
+#define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 /*!< MaxFragmentLength 2^12 */
+#define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 /*!< first invalid value */
+
+#define MBEDTLS_SSL_IS_CLIENT 0
+#define MBEDTLS_SSL_IS_SERVER 1
+
+#define MBEDTLS_SSL_IS_NOT_FALLBACK 0
+#define MBEDTLS_SSL_IS_FALLBACK 1
+
+#define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
+#define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
+
+#define MBEDTLS_SSL_ETM_DISABLED 0
+#define MBEDTLS_SSL_ETM_ENABLED 1
+
+#define MBEDTLS_SSL_COMPRESS_NULL 0
+#define MBEDTLS_SSL_COMPRESS_DEFLATE 1
+
+#define MBEDTLS_SSL_VERIFY_NONE 0
+#define MBEDTLS_SSL_VERIFY_OPTIONAL 1
+#define MBEDTLS_SSL_VERIFY_REQUIRED 2
+#define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
+
+#define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
+#define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
+
+#define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
+#define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
+
+#define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
+#define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
+
+#define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
+#define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
+
+#define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
+#define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
+#define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
+
+#define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
+#define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
+#define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
+
+#define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
+#define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
+
+#define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
+#define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
+
+#define MBEDTLS_SSL_ARC4_ENABLED 0
+#define MBEDTLS_SSL_ARC4_DISABLED 1
+
+#define MBEDTLS_SSL_PRESET_DEFAULT 0
+#define MBEDTLS_SSL_PRESET_SUITEB 2
+
+#define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1
+#define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0
+
+/*
+ * Default range for DTLS retransmission timer value, in milliseconds.
+ * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
+ */
+#define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
+#define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
+#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
+#endif
+
+/*
+ * Maxium fragment length in bytes,
+ * determines the size of each of the two internal I/O buffers.
+ *
+ * Note: the RFC defines the default size of SSL / TLS messages. If you
+ * change the value here, other clients / servers may not be able to
+ * communicate with you anymore. Only change this value if you control
+ * both sides of the connection and have it reduced at both sides, or
+ * if you're using the Max Fragment Length extension and you know all your
+ * peers are using it too!
+ */
+#if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
+#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
+#endif
+
+/* \} name SECTION: Module settings */
+
+/*
+ * Length of the verify data for secure renegotiation
+ */
+#if defined(MBEDTLS_SSL_PROTO_SSL3)
+#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
+#else
+#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
+#endif
+
+/*
+ * Signaling ciphersuite values (SCSV)
+ */
+#define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
+#define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600 /**< RFC 7507 section 2 */
+
+/*
+ * Supported Signature and Hash algorithms (For TLS 1.2)
+ * RFC 5246 section 7.4.1.4.1
+ */
+#define MBEDTLS_SSL_HASH_NONE 0
+#define MBEDTLS_SSL_HASH_MD5 1
+#define MBEDTLS_SSL_HASH_SHA1 2
+#define MBEDTLS_SSL_HASH_SHA224 3
+#define MBEDTLS_SSL_HASH_SHA256 4
+#define MBEDTLS_SSL_HASH_SHA384 5
+#define MBEDTLS_SSL_HASH_SHA512 6
+
+#define MBEDTLS_SSL_SIG_ANON 0
+#define MBEDTLS_SSL_SIG_RSA 1
+#define MBEDTLS_SSL_SIG_ECDSA 3
+
+/*
+ * Client Certificate Types
+ * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
+ */
+#define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
+#define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
+
+/*
+ * Message, alert and handshake types
+ */
+#define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
+#define MBEDTLS_SSL_MSG_ALERT 21
+#define MBEDTLS_SSL_MSG_HANDSHAKE 22
+#define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
+
+#define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
+#define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
+
+#define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
+#define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
+#define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
+#define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
+#define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
+#define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
+#define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
+#define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
+#define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
+#define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
+#define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
+#define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
+#define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
+#define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
+#define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
+#define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
+#define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
+#define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
+#define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
+#define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
+#define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
+#define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
+#define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
+#define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
+#define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
+#define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
+#define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
+#define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
+#define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
+
+#define MBEDTLS_SSL_HS_HELLO_REQUEST 0
+#define MBEDTLS_SSL_HS_CLIENT_HELLO 1
+#define MBEDTLS_SSL_HS_SERVER_HELLO 2
+#define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
+#define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
+#define MBEDTLS_SSL_HS_CERTIFICATE 11
+#define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
+#define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
+#define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
+#define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
+#define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
+#define MBEDTLS_SSL_HS_FINISHED 20
+
+/*
+ * TLS extensions
+ */
+#define MBEDTLS_TLS_EXT_SERVERNAME 0
+#define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
+
+#define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
+
+#define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
+
+#define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
+#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
+
+#define MBEDTLS_TLS_EXT_SIG_ALG 13
+
+#define MBEDTLS_TLS_EXT_ALPN 16
+
+#define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
+#define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
+
+#define MBEDTLS_TLS_EXT_SESSION_TICKET 35
+
+#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
+
+#define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
+
+/*
+ * Size defines
+ */
+#if !defined(MBEDTLS_PSK_MAX_LEN)
+#define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
+#endif
+
+/* Dummy type used only for its size */
+union mbedtls_ssl_premaster_secret
+{
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
+ unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
+ unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
+ unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
+ unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
+ unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
+ + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
+ unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
+ unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
+ + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+ unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
+#endif
+};
+
+#define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * SSL state machine
+ */
+typedef enum
+{
+ MBEDTLS_SSL_HELLO_REQUEST,
+ MBEDTLS_SSL_CLIENT_HELLO,
+ MBEDTLS_SSL_SERVER_HELLO,
+ MBEDTLS_SSL_SERVER_CERTIFICATE,
+ MBEDTLS_SSL_SERVER_KEY_EXCHANGE,
+ MBEDTLS_SSL_CERTIFICATE_REQUEST,
+ MBEDTLS_SSL_SERVER_HELLO_DONE,
+ MBEDTLS_SSL_CLIENT_CERTIFICATE,
+ MBEDTLS_SSL_CLIENT_KEY_EXCHANGE,
+ MBEDTLS_SSL_CERTIFICATE_VERIFY,
+ MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC,
+ MBEDTLS_SSL_CLIENT_FINISHED,
+ MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC,
+ MBEDTLS_SSL_SERVER_FINISHED,
+ MBEDTLS_SSL_FLUSH_BUFFERS,
+ MBEDTLS_SSL_HANDSHAKE_WRAPUP,
+ MBEDTLS_SSL_HANDSHAKE_OVER,
+ MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET,
+ MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT,
+}
+mbedtls_ssl_states;
+
+/**
+ * \brief Callback type: send data on the network.
+ *
+ * \note That callback may be either blocking or non-blocking.
+ *
+ * \param ctx Context for the send callback (typically a file descriptor)
+ * \param buf Buffer holding the data to send
+ * \param len Length of the data to send
+ *
+ * \return The callback must return the number of bytes sent if any,
+ * or a non-zero error code.
+ * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_WRITE
+ * must be returned when the operation would block.
+ *
+ * \note The callback is allowed to send fewer bytes than requested.
+ * It must always return the number of bytes actually sent.
+ */
+typedef int mbedtls_ssl_send_t( void *ctx,
+ const unsigned char *buf,
+ size_t len );
+
+/**
+ * \brief Callback type: receive data from the network.
+ *
+ * \note That callback may be either blocking or non-blocking.
+ *
+ * \param ctx Context for the receive callback (typically a file
+ * descriptor)
+ * \param buf Buffer to write the received data to
+ * \param len Length of the receive buffer
+ *
+ * \return The callback must return the number of bytes received,
+ * or a non-zero error code.
+ * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ
+ * must be returned when the operation would block.
+ *
+ * \note The callback may receive fewer bytes than the length of the
+ * buffer. It must always return the number of bytes actually
+ * received and written to the buffer.
+ */
+typedef int mbedtls_ssl_recv_t( void *ctx,
+ unsigned char *buf,
+ size_t len );
+
+/**
+ * \brief Callback type: receive data from the network, with timeout
+ *
+ * \note That callback must block until data is received, or the
+ * timeout delay expires, or the operation is interrupted by a
+ * signal.
+ *
+ * \param ctx Context for the receive callback (typically a file descriptor)
+ * \param buf Buffer to write the received data to
+ * \param len Length of the receive buffer
+ * \param timeout Maximum nomber of millisecondes to wait for data
+ * 0 means no timeout (potentially waiting forever)
+ *
+ * \return The callback must return the number of bytes received,
+ * or a non-zero error code:
+ * \c MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
+ * \c MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
+ *
+ * \note The callback may receive fewer bytes than the length of the
+ * buffer. It must always return the number of bytes actually
+ * received and written to the buffer.
+ */
+typedef int mbedtls_ssl_recv_timeout_t( void *ctx,
+ unsigned char *buf,
+ size_t len,
+ uint32_t timeout );
+/**
+ * \brief Callback type: set a pair of timers/delays to watch
+ *
+ * \param ctx Context pointer
+ * \param int_ms Intermediate delay in milliseconds
+ * \param fin_ms Final delay in milliseconds
+ * 0 cancels the current timer.
+ *
+ * \note This callback must at least store the necessary information
+ * for the associated \c mbedtls_ssl_get_timer_t callback to
+ * return correct information.
+ *
+ * \note If using a event-driven style of programming, an event must
+ * be generated when the final delay is passed. The event must
+ * cause a call to \c mbedtls_ssl_handshake() with the proper
+ * SSL context to be scheduled. Care must be taken to ensure
+ * that at most one such call happens at a time.
+ *
+ * \note Only one timer at a time must be running. Calling this
+ * function while a timer is running must cancel it. Cancelled
+ * timers must not generate any event.
+ */
+typedef void mbedtls_ssl_set_timer_t( void * ctx,
+ uint32_t int_ms,
+ uint32_t fin_ms );
+
+/**
+ * \brief Callback type: get status of timers/delays
+ *
+ * \param ctx Context pointer
+ *
+ * \return This callback must return:
+ * -1 if cancelled (fin_ms == 0),
+ * 0 if none of the delays have passed,
+ * 1 if only the intermediate delay has passed,
+ * 2 if the final delay has passed.
+ */
+typedef int mbedtls_ssl_get_timer_t( void * ctx );
+
+
+/* Defined below */
+typedef struct mbedtls_ssl_session mbedtls_ssl_session;
+typedef struct mbedtls_ssl_context mbedtls_ssl_context;
+typedef struct mbedtls_ssl_config mbedtls_ssl_config;
+
+/* Defined in ssl_internal.h */
+typedef struct mbedtls_ssl_transform mbedtls_ssl_transform;
+typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params;
+typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t;
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert;
+#endif
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item;
+#endif
+
+/*
+ * This structure is used for storing current session data.
+ */
+struct mbedtls_ssl_session
+{
+#if defined(MBEDTLS_HAVE_TIME)
+ mbedtls_time_t start; /*!< starting time */
+#endif
+ int ciphersuite; /*!< chosen ciphersuite */
+ int compression; /*!< chosen compression */
+ size_t id_len; /*!< session id length */
+ unsigned char id[32]; /*!< session identifier */
+ unsigned char master[48]; /*!< the master secret */
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+ mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+ uint32_t verify_result; /*!< verification result */
+
+#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
+ unsigned char *ticket; /*!< RFC 5077 session ticket */
+ size_t ticket_len; /*!< session ticket length */
+ uint32_t ticket_lifetime; /*!< ticket lifetime hint */
+#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
+
+#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+ unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
+#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
+
+#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
+ int trunc_hmac; /*!< flag for truncated hmac activation */
+#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
+
+#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
+ int encrypt_then_mac; /*!< flag for EtM activation */
+#endif
+};
+
+/**
+ * SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
+ */
+struct mbedtls_ssl_config
+{
+ /* Group items by size (largest first) to minimize padding overhead */
+
+ /*
+ * Pointers
+ */
+
+ const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */
+
+ /** Callback for printing debug output */
+ void (*f_dbg)(void *, int, const char *, int, const char *);
+ void *p_dbg; /*!< context for the debug function */
+
+ /** Callback for getting (pseudo-)random numbers */
+ int (*f_rng)(void *, unsigned char *, size_t);
+ void *p_rng; /*!< context for the RNG function */
+
+ /** Callback to retrieve a session from the cache */
+ int (*f_get_cache)(void *, mbedtls_ssl_session *);
+ /** Callback to store a session into the cache */
+ int (*f_set_cache)(void *, const mbedtls_ssl_session *);
+ void *p_cache; /*!< context for cache callbacks */
+
+#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
+ /** Callback for setting cert according to SNI extension */
+ int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
+ void *p_sni; /*!< context for SNI callback */
+#endif
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+ /** Callback to customize X.509 certificate chain verification */
+ int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
+ void *p_vrfy; /*!< context for X.509 verify calllback */
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
+ /** Callback to retrieve PSK key from identity */
+ int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
+ void *p_psk; /*!< context for PSK callback */
+#endif
+
+#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
+ /** Callback to create & write a cookie for ClientHello veirifcation */
+ int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
+ const unsigned char *, size_t );
+ /** Callback to verify validity of a ClientHello cookie */
+ int (*f_cookie_check)( void *, const unsigned char *, size_t,
+ const unsigned char *, size_t );
+ void *p_cookie; /*!< context for the cookie callbacks */
+#endif
+
+#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
+ /** Callback to create & write a session ticket */
+ int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
+ unsigned char *, const unsigned char *, size_t *, uint32_t * );
+ /** Callback to parse a session ticket into a session structure */
+ int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
+ void *p_ticket; /*!< context for the ticket callbacks */
+#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
+
+#if defined(MBEDTLS_SSL_EXPORT_KEYS)
+ /** Callback to export key block and master secret */
+ int (*f_export_keys)( void *, const unsigned char *,
+ const unsigned char *, size_t, size_t, size_t );
+ void *p_export_keys; /*!< context for key export callback */
+#endif
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+ const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */
+ mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */
+ mbedtls_x509_crt *ca_chain; /*!< trusted CAs */
+ mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
+ const int *sig_hashes; /*!< allowed signature hashes */
+#endif
+
+#if defined(MBEDTLS_ECP_C)
+ const mbedtls_ecp_group_id *curve_list; /*!< allowed curves */
+#endif
+
+#if defined(MBEDTLS_DHM_C)
+ mbedtls_mpi dhm_P; /*!< prime modulus for DHM */
+ mbedtls_mpi dhm_G; /*!< generator for DHM */
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
+ unsigned char *psk; /*!< pre-shared key */
+ size_t psk_len; /*!< length of the pre-shared key */
+ unsigned char *psk_identity; /*!< identity for PSK negotiation */
+ size_t psk_identity_len;/*!< length of identity */
+#endif
+
+#if defined(MBEDTLS_SSL_ALPN)
+ const char **alpn_list; /*!< ordered list of protocols */
+#endif
+
+ /*
+ * Numerical settings (int then char)
+ */
+
+ uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
+
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+ uint32_t hs_timeout_min; /*!< initial value of the handshake
+ retransmission timeout (ms) */
+ uint32_t hs_timeout_max; /*!< maximum value of the handshake
+ retransmission timeout (ms) */
+#endif
+
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+ int renego_max_records; /*!< grace period for renegotiation */
+ unsigned char renego_period[8]; /*!< value of the record counters
+ that triggers renegotiation */
+#endif
+
+#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
+ unsigned int badmac_limit; /*!< limit of records with a bad MAC */
+#endif
+
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
+ unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
+#endif
+
+ unsigned char max_major_ver; /*!< max. major version used */
+ unsigned char max_minor_ver; /*!< max. minor version used */
+ unsigned char min_major_ver; /*!< min. major version used */
+ unsigned char min_minor_ver; /*!< min. minor version used */
+
+ /*
+ * Flags (bitfields)
+ */
+
+ unsigned int endpoint : 1; /*!< 0: client, 1: server */
+ unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */
+ unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */
+ /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
+ unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */
+#if defined(MBEDTLS_ARC4_C)
+ unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */
+#endif
+#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+ unsigned int mfl_code : 3; /*!< desired fragment length */
+#endif
+#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
+ unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */
+#endif
+#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
+ unsigned int extended_ms : 1; /*!< negotiate extended master secret? */
+#endif
+#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
+ unsigned int anti_replay : 1; /*!< detect and prevent replay? */
+#endif
+#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
+ unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */
+#endif
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+ unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */
+#endif
+#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
+ unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */
+#endif
+#if defined(MBEDTLS_SSL_SESSION_TICKETS)
+ unsigned int session_tickets : 1; /*!< use session tickets? */
+#endif
+#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
+ unsigned int fallback : 1; /*!< is this a fallback? */
+#endif
+#if defined(MBEDTLS_SSL_SRV_C)
+ unsigned int cert_req_ca_list : 1; /*!< enable sending CA list in
+ Certificate Request messages? */
+#endif
+};
+
+
+struct mbedtls_ssl_context
+{
+ const mbedtls_ssl_config *conf; /*!< configuration information */
+
+ /*
+ * Miscellaneous
+ */
+ int state; /*!< SSL handshake: current state */
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+ int renego_status; /*!< Initial, in progress, pending? */
+ int renego_records_seen; /*!< Records since renego request, or with DTLS,
+ number of retransmissions of request if
+ renego_max_records is < 0 */
+#endif
+
+ int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */
+ int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
+
+#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
+ unsigned badmac_seen; /*!< records with a bad MAC received */
+#endif
+
+ mbedtls_ssl_send_t *f_send; /*!< Callback for network send */
+ mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */
+ mbedtls_ssl_recv_timeout_t *f_recv_timeout;
+ /*!< Callback for network receive with timeout */
+
+ void *p_bio; /*!< context for I/O operations */
+
+ /*
+ * Session layer
+ */
+ mbedtls_ssl_session *session_in; /*!< current session data (in) */
+ mbedtls_ssl_session *session_out; /*!< current session data (out) */
+ mbedtls_ssl_session *session; /*!< negotiated session data */
+ mbedtls_ssl_session *session_negotiate; /*!< session data in negotiation */
+
+ mbedtls_ssl_handshake_params *handshake; /*!< params required only during
+ the handshake process */
+
+ /*
+ * Record layer transformations
+ */
+ mbedtls_ssl_transform *transform_in; /*!< current transform params (in) */
+ mbedtls_ssl_transform *transform_out; /*!< current transform params (in) */
+ mbedtls_ssl_transform *transform; /*!< negotiated transform params */
+ mbedtls_ssl_transform *transform_negotiate; /*!< transform params in negotiation */
+
+ /*
+ * Timers
+ */
+ void *p_timer; /*!< context for the timer callbacks */
+
+ mbedtls_ssl_set_timer_t *f_set_timer; /*!< set timer callback */
+ mbedtls_ssl_get_timer_t *f_get_timer; /*!< get timer callback */
+
+ /*
+ * Record layer (incoming data)
+ */
+ unsigned char *in_buf; /*!< input buffer */
+ unsigned char *in_ctr; /*!< 64-bit incoming message counter
+ TLS: maintained by us
+ DTLS: read from peer */
+ unsigned char *in_hdr; /*!< start of record header */
+ unsigned char *in_len; /*!< two-bytes message length field */
+ unsigned char *in_iv; /*!< ivlen-byte IV */
+ unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */
+ unsigned char *in_offt; /*!< read offset in application data */
+
+ int in_msgtype; /*!< record header: message type */
+ size_t in_msglen; /*!< record header: message length */
+ size_t in_left; /*!< amount of data read so far */
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+ uint16_t in_epoch; /*!< DTLS epoch for incoming records */
+ size_t next_record_offset; /*!< offset of the next record in datagram
+ (equal to in_left if none) */
+#endif
+#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
+ uint64_t in_window_top; /*!< last validated record seq_num */
+ uint64_t in_window; /*!< bitmask for replay detection */
+#endif
+
+ size_t in_hslen; /*!< current handshake message length,
+ including the handshake header */
+ int nb_zero; /*!< # of 0-length encrypted messages */
+
+ int keep_current_message; /*!< drop or reuse current message
+ on next call to record layer? */
+
+ /*
+ * Record layer (outgoing data)
+ */
+ unsigned char *out_buf; /*!< output buffer */
+ unsigned char *out_ctr; /*!< 64-bit outgoing message counter */
+ unsigned char *out_hdr; /*!< start of record header */
+ unsigned char *out_len; /*!< two-bytes message length field */
+ unsigned char *out_iv; /*!< ivlen-byte IV */
+ unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */
+
+ int out_msgtype; /*!< record header: message type */
+ size_t out_msglen; /*!< record header: message length */
+ size_t out_left; /*!< amount of data not yet written */
+
+#if defined(MBEDTLS_ZLIB_SUPPORT)
+ unsigned char *compress_buf; /*!< zlib data buffer */
+#endif
+#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
+ signed char split_done; /*!< current record already splitted? */
+#endif
+
+ /*
+ * PKI layer
+ */
+ int client_auth; /*!< flag for client auth. */
+
+ /*
+ * User settings
+ */
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+ char *hostname; /*!< expected peer CN for verification
+ (and SNI if available) */
+#endif
+
+#if defined(MBEDTLS_SSL_ALPN)
+ const char *alpn_chosen; /*!< negotiated protocol */
+#endif
+
+ /*
+ * Information for DTLS hello verify
+ */
+#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
+ unsigned char *cli_id; /*!< transport-level ID of the client */
+ size_t cli_id_len; /*!< length of cli_id */
+#endif
+
+ /*
+ * Secure renegotiation
+ */
+ /* needed to know when to send extension on server */
+ int secure_renegotiation; /*!< does peer support legacy or
+ secure renegotiation */
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+ size_t verify_data_len; /*!< length of verify data stored */
+ char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
+ char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
+#endif
+ void *appData;
+};
+
+#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
+
+#define MBEDTLS_SSL_CHANNEL_OUTBOUND 0
+#define MBEDTLS_SSL_CHANNEL_INBOUND 1
+
+extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl,
+ const unsigned char *key_enc, const unsigned char *key_dec,
+ size_t keylen,
+ const unsigned char *iv_enc, const unsigned char *iv_dec,
+ size_t ivlen,
+ const unsigned char *mac_enc, const unsigned char *mac_dec,
+ size_t maclen);
+extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction);
+extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl);
+extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl);
+extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl);
+extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl);
+#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
+
+/**
+ * \brief Returns the list of ciphersuites supported by the SSL/TLS module.
+ *
+ * \return a statically allocated array of ciphersuites, the last
+ * entry is 0.
+ */
+const int *mbedtls_ssl_list_ciphersuites( void );
+
+/**
+ * \brief Return the name of the ciphersuite associated with the
+ * given ID
+ *
+ * \param ciphersuite_id SSL ciphersuite ID
+ *
+ * \return a string containing the ciphersuite name
+ */
+const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
+
+/**
+ * \brief Return the ID of the ciphersuite associated with the
+ * given name
+ *
+ * \param ciphersuite_name SSL ciphersuite name
+ *
+ * \return the ID with the ciphersuite or 0 if not found
+ */
+int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
+
+/**
+ * \brief Initialize an SSL context
+ * Just makes the context ready for mbedtls_ssl_setup() or
+ * mbedtls_ssl_free()
+ *
+ * \param ssl SSL context
+ */
+void mbedtls_ssl_init( mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Set up an SSL context for use
+ *
+ * \note No copy of the configuration context is made, it can be
+ * shared by many mbedtls_ssl_context structures.
+ *
+ * \warning The conf structure will be accessed during the session.
+ * It must not be modified or freed as long as the session
+ * is active.
+ *
+ * \warning This function must be called exactly once per context.
+ * Calling mbedtls_ssl_setup again is not supported, even
+ * if no session is active.
+ *
+ * \param ssl SSL context
+ * \param conf SSL configuration to use
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if
+ * memory allocation failed
+ */
+int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
+ const mbedtls_ssl_config *conf );
+
+/**
+ * \brief Reset an already initialized SSL context for re-use
+ * while retaining application-set variables, function
+ * pointers and data.
+ *
+ * \param ssl SSL context
+ * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED,
+ MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or
+ * MBEDTLS_ERR_SSL_COMPRESSION_FAILED
+ */
+int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Set the current endpoint type
+ *
+ * \param conf SSL configuration
+ * \param endpoint must be MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
+ */
+void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
+
+/**
+ * \brief Set the transport type (TLS or DTLS).
+ * Default: TLS
+ *
+ * \note For DTLS, you must either provide a recv callback that
+ * doesn't block, or one that handles timeouts, see
+ * \c mbedtls_ssl_set_bio(). You also need to provide timer
+ * callbacks with \c mbedtls_ssl_set_timer_cb().
+ *
+ * \param conf SSL configuration
+ * \param transport transport type:
+ * MBEDTLS_SSL_TRANSPORT_STREAM for TLS,
+ * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS.
+ */
+void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
+
+/**
+ * \brief Set the certificate verification mode
+ * Default: NONE on server, REQUIRED on client
+ *
+ * \param conf SSL configuration
+ * \param authmode can be:
+ *
+ * MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked
+ * (default on server)
+ * (insecure on client)
+ *
+ * MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the
+ * handshake continues even if verification failed;
+ * mbedtls_ssl_get_verify_result() can be called after the
+ * handshake is complete.
+ *
+ * MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate,
+ * handshake is aborted if verification failed.
+ * (default on client)
+ *
+ * \note On client, MBEDTLS_SSL_VERIFY_REQUIRED is the recommended mode.
+ * With MBEDTLS_SSL_VERIFY_OPTIONAL, the user needs to call mbedtls_ssl_get_verify_result() at
+ * the right time(s), which may not be obvious, while REQUIRED always perform
+ * the verification as soon as possible. For example, REQUIRED was protecting
+ * against the "triple handshake" attack even before it was found.
+ */
+void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/**
+ * \brief Set the verification callback (Optional).
+ *
+ * If set, the verify callback is called for each
+ * certificate in the chain. For implementation
+ * information, please see \c mbedtls_x509_crt_verify()
+ *
+ * \param conf SSL configuration
+ * \param f_vrfy verification function
+ * \param p_vrfy verification parameter
+ */
+void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf,
+ int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
+ void *p_vrfy );
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+/**
+ * \brief Set the random number generator callback
+ *
+ * \param conf SSL configuration
+ * \param f_rng RNG function
+ * \param p_rng RNG parameter
+ */
+void mbedtls_ssl_conf_rng( mbedtls_ssl_config *conf,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Set the debug callback
+ *
+ * The callback has the following argument:
+ * void * opaque context for the callback
+ * int debug level
+ * const char * file name
+ * int line number
+ * const char * message
+ *
+ * \param conf SSL configuration
+ * \param f_dbg debug function
+ * \param p_dbg debug parameter
+ */
+void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf,
+ void (*f_dbg)(void *, int, const char *, int, const char *),
+ void *p_dbg );
+
+/**
+ * \brief Set the underlying BIO callbacks for write, read and
+ * read-with-timeout.
+ *
+ * \param ssl SSL context
+ * \param p_bio parameter (context) shared by BIO callbacks
+ * \param f_send write callback
+ * \param f_recv read callback
+ * \param f_recv_timeout blocking read callback with timeout.
+ *
+ * \note One of f_recv or f_recv_timeout can be NULL, in which case
+ * the other is used. If both are non-NULL, f_recv_timeout is
+ * used and f_recv is ignored (as if it were NULL).
+ *
+ * \note The two most common use cases are:
+ * - non-blocking I/O, f_recv != NULL, f_recv_timeout == NULL
+ * - blocking I/O, f_recv == NULL, f_recv_timout != NULL
+ *
+ * \note For DTLS, you need to provide either a non-NULL
+ * f_recv_timeout callback, or a f_recv that doesn't block.
+ *
+ * \note See the documentations of \c mbedtls_ssl_sent_t,
+ * \c mbedtls_ssl_recv_t and \c mbedtls_ssl_recv_timeout_t for
+ * the conventions those callbacks must follow.
+ *
+ * \note On some platforms, net_sockets.c provides
+ * \c mbedtls_net_send(), \c mbedtls_net_recv() and
+ * \c mbedtls_net_recv_timeout() that are suitable to be used
+ * here.
+ */
+void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
+ void *p_bio,
+ mbedtls_ssl_send_t *f_send,
+ mbedtls_ssl_recv_t *f_recv,
+ mbedtls_ssl_recv_timeout_t *f_recv_timeout );
+
+/**
+ * \brief Set the timeout period for mbedtls_ssl_read()
+ * (Default: no timeout.)
+ *
+ * \param conf SSL configuration context
+ * \param timeout Timeout value in milliseconds.
+ * Use 0 for no timeout (default).
+ *
+ * \note With blocking I/O, this will only work if a non-NULL
+ * \c f_recv_timeout was set with \c mbedtls_ssl_set_bio().
+ * With non-blocking I/O, this will only work if timer
+ * callbacks were set with \c mbedtls_ssl_set_timer_cb().
+ *
+ * \note With non-blocking I/O, you may also skip this function
+ * altogether and handle timeouts at the application layer.
+ */
+void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
+
+/**
+ * \brief Set the timer callbacks (Mandatory for DTLS.)
+ *
+ * \param ssl SSL context
+ * \param p_timer parameter (context) shared by timer callbacks
+ * \param f_set_timer set timer callback
+ * \param f_get_timer get timer callback. Must return:
+ *
+ * \note See the documentation of \c mbedtls_ssl_set_timer_t and
+ * \c mbedtls_ssl_get_timer_t for the conventions this pair of
+ * callbacks must follow.
+ *
+ * \note On some platforms, timing.c provides
+ * \c mbedtls_timing_set_delay() and
+ * \c mbedtls_timing_get_delay() that are suitable for using
+ * here, except if using an event-driven style.
+ *
+ * \note See also the "DTLS tutorial" article in our knowledge base.
+ * https://tls.mbed.org/kb/how-to/dtls-tutorial
+ */
+void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl,
+ void *p_timer,
+ mbedtls_ssl_set_timer_t *f_set_timer,
+ mbedtls_ssl_get_timer_t *f_get_timer );
+
+/**
+ * \brief Callback type: generate and write session ticket
+ *
+ * \note This describes what a callback implementation should do.
+ * This callback should generate an encrypted and
+ * authenticated ticket for the session and write it to the
+ * output buffer. Here, ticket means the opaque ticket part
+ * of the NewSessionTicket structure of RFC 5077.
+ *
+ * \param p_ticket Context for the callback
+ * \param session SSL session to be written in the ticket
+ * \param start Start of the output buffer
+ * \param end End of the output buffer
+ * \param tlen On exit, holds the length written
+ * \param lifetime On exit, holds the lifetime of the ticket in seconds
+ *
+ * \return 0 if successful, or
+ * a specific MBEDTLS_ERR_XXX code.
+ */
+typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
+ const mbedtls_ssl_session *session,
+ unsigned char *start,
+ const unsigned char *end,
+ size_t *tlen,
+ uint32_t *lifetime );
+
+#if defined(MBEDTLS_SSL_EXPORT_KEYS)
+/**
+ * \brief Callback type: Export key block and master secret
+ *
+ * \note This is required for certain uses of TLS, e.g. EAP-TLS
+ * (RFC 5216) and Thread. The key pointers are ephemeral and
+ * therefore must not be stored. The master secret and keys
+ * should not be used directly except as an input to a key
+ * derivation function.
+ *
+ * \param p_expkey Context for the callback
+ * \param ms Pointer to master secret (fixed length: 48 bytes)
+ * \param kb Pointer to key block, see RFC 5246 section 6.3
+ * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
+ * \param maclen MAC length
+ * \param keylen Key length
+ * \param ivlen IV length
+ *
+ * \return 0 if successful, or
+ * a specific MBEDTLS_ERR_XXX code.
+ */
+typedef int mbedtls_ssl_export_keys_t( void *p_expkey,
+ const unsigned char *ms,
+ const unsigned char *kb,
+ size_t maclen,
+ size_t keylen,
+ size_t ivlen );
+#endif /* MBEDTLS_SSL_EXPORT_KEYS */
+
+/**
+ * \brief Callback type: parse and load session ticket
+ *
+ * \note This describes what a callback implementation should do.
+ * This callback should parse a session ticket as generated
+ * by the corresponding mbedtls_ssl_ticket_write_t function,
+ * and, if the ticket is authentic and valid, load the
+ * session.
+ *
+ * \note The implementation is allowed to modify the first len
+ * bytes of the input buffer, eg to use it as a temporary
+ * area for the decrypted ticket contents.
+ *
+ * \param p_ticket Context for the callback
+ * \param session SSL session to be loaded
+ * \param buf Start of the buffer containing the ticket
+ * \param len Length of the ticket.
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_SSL_INVALID_MAC if not authentic, or
+ * MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED if expired, or
+ * any other non-zero code for other failures.
+ */
+typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
+ mbedtls_ssl_session *session,
+ unsigned char *buf,
+ size_t len );
+
+#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
+/**
+ * \brief Configure SSL session ticket callbacks (server only).
+ * (Default: none.)
+ *
+ * \note On server, session tickets are enabled by providing
+ * non-NULL callbacks.
+ *
+ * \note On client, use \c mbedtls_ssl_conf_session_tickets().
+ *
+ * \param conf SSL configuration context
+ * \param f_ticket_write Callback for writing a ticket
+ * \param f_ticket_parse Callback for parsing a ticket
+ * \param p_ticket Context shared by the two callbacks
+ */
+void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf,
+ mbedtls_ssl_ticket_write_t *f_ticket_write,
+ mbedtls_ssl_ticket_parse_t *f_ticket_parse,
+ void *p_ticket );
+#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
+
+#if defined(MBEDTLS_SSL_EXPORT_KEYS)
+/**
+ * \brief Configure key export callback.
+ * (Default: none.)
+ *
+ * \note See \c mbedtls_ssl_export_keys_t.
+ *
+ * \param conf SSL configuration context
+ * \param f_export_keys Callback for exporting keys
+ * \param p_export_keys Context for the callback
+ */
+void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf,
+ mbedtls_ssl_export_keys_t *f_export_keys,
+ void *p_export_keys );
+#endif /* MBEDTLS_SSL_EXPORT_KEYS */
+
+/**
+ * \brief Callback type: generate a cookie
+ *
+ * \param ctx Context for the callback
+ * \param p Buffer to write to,
+ * must be updated to point right after the cookie
+ * \param end Pointer to one past the end of the output buffer
+ * \param info Client ID info that was passed to
+ * \c mbedtls_ssl_set_client_transport_id()
+ * \param ilen Length of info in bytes
+ *
+ * \return The callback must return 0 on success,
+ * or a negative error code.
+ */
+typedef int mbedtls_ssl_cookie_write_t( void *ctx,
+ unsigned char **p, unsigned char *end,
+ const unsigned char *info, size_t ilen );
+
+/**
+ * \brief Callback type: verify a cookie
+ *
+ * \param ctx Context for the callback
+ * \param cookie Cookie to verify
+ * \param clen Length of cookie
+ * \param info Client ID info that was passed to
+ * \c mbedtls_ssl_set_client_transport_id()
+ * \param ilen Length of info in bytes
+ *
+ * \return The callback must return 0 if cookie is valid,
+ * or a negative error code.
+ */
+typedef int mbedtls_ssl_cookie_check_t( void *ctx,
+ const unsigned char *cookie, size_t clen,
+ const unsigned char *info, size_t ilen );
+
+#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
+/**
+ * \brief Register callbacks for DTLS cookies
+ * (Server only. DTLS only.)
+ *
+ * Default: dummy callbacks that fail, in order to force you to
+ * register working callbacks (and initialize their context).
+ *
+ * To disable HelloVerifyRequest, register NULL callbacks.
+ *
+ * \warning Disabling hello verification allows your server to be used
+ * for amplification in DoS attacks against other hosts.
+ * Only disable if you known this can't happen in your
+ * particular environment.
+ *
+ * \note See comments on \c mbedtls_ssl_handshake() about handling
+ * the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED that is expected
+ * on the first handshake attempt when this is enabled.
+ *
+ * \note This is also necessary to handle client reconnection from
+ * the same port as described in RFC 6347 section 4.2.8 (only
+ * the variant with cookies is supported currently). See
+ * comments on \c mbedtls_ssl_read() for details.
+ *
+ * \param conf SSL configuration
+ * \param f_cookie_write Cookie write callback
+ * \param f_cookie_check Cookie check callback
+ * \param p_cookie Context for both callbacks
+ */
+void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf,
+ mbedtls_ssl_cookie_write_t *f_cookie_write,
+ mbedtls_ssl_cookie_check_t *f_cookie_check,
+ void *p_cookie );
+
+/**
+ * \brief Set client's transport-level identification info.
+ * (Server only. DTLS only.)
+ *
+ * This is usually the IP address (and port), but could be
+ * anything identify the client depending on the underlying
+ * network stack. Used for HelloVerifyRequest with DTLS.
+ * This is *not* used to route the actual packets.
+ *
+ * \param ssl SSL context
+ * \param info Transport-level info identifying the client (eg IP + port)
+ * \param ilen Length of info in bytes
+ *
+ * \note An internal copy is made, so the info buffer can be reused.
+ *
+ * \return 0 on success,
+ * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client,
+ * MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory.
+ */
+int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
+ const unsigned char *info,
+ size_t ilen );
+
+#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
+
+#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
+/**
+ * \brief Enable or disable anti-replay protection for DTLS.
+ * (DTLS only, no effect on TLS.)
+ * Default: enabled.
+ *
+ * \param conf SSL configuration
+ * \param mode MBEDTLS_SSL_ANTI_REPLAY_ENABLED or MBEDTLS_SSL_ANTI_REPLAY_DISABLED.
+ *
+ * \warning Disabling this is a security risk unless the application
+ * protocol handles duplicated packets in a safe way. You
+ * should not disable this without careful consideration.
+ * However, if your application already detects duplicated
+ * packets and needs information about them to adjust its
+ * transmission strategy, then you'll want to disable this.
+ */
+void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
+#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
+
+#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
+/**
+ * \brief Set a limit on the number of records with a bad MAC
+ * before terminating the connection.
+ * (DTLS only, no effect on TLS.)
+ * Default: 0 (disabled).
+ *
+ * \param conf SSL configuration
+ * \param limit Limit, or 0 to disable.
+ *
+ * \note If the limit is N, then the connection is terminated when
+ * the Nth non-authentic record is seen.
+ *
+ * \note Records with an invalid header are not counted, only the
+ * ones going through the authentication-decryption phase.
+ *
+ * \note This is a security trade-off related to the fact that it's
+ * often relatively easy for an active attacker ot inject UDP
+ * datagrams. On one hand, setting a low limit here makes it
+ * easier for such an attacker to forcibly terminated a
+ * connection. On the other hand, a high limit or no limit
+ * might make us waste resources checking authentication on
+ * many bogus packets.
+ */
+void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
+#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
+
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+/**
+ * \brief Set retransmit timeout values for the DTLS handshake.
+ * (DTLS only, no effect on TLS.)
+ *
+ * \param conf SSL configuration
+ * \param min Initial timeout value in milliseconds.
+ * Default: 1000 (1 second).
+ * \param max Maximum timeout value in milliseconds.
+ * Default: 60000 (60 seconds).
+ *
+ * \note Default values are from RFC 6347 section 4.2.4.1.
+ *
+ * \note The 'min' value should typically be slightly above the
+ * expected round-trip time to your peer, plus whatever time
+ * it takes for the peer to process the message. For example,
+ * if your RTT is about 600ms and you peer needs up to 1s to
+ * do the cryptographic operations in the handshake, then you
+ * should set 'min' slightly above 1600. Lower values of 'min'
+ * might cause spurious resends which waste network resources,
+ * while larger value of 'min' will increase overall latency
+ * on unreliable network links.
+ *
+ * \note The more unreliable your network connection is, the larger
+ * your max / min ratio needs to be in order to achieve
+ * reliable handshakes.
+ *
+ * \note Messages are retransmitted up to log2(ceil(max/min)) times.
+ * For example, if min = 1s and max = 5s, the retransmit plan
+ * goes: send ... 1s -> resend ... 2s -> resend ... 4s ->
+ * resend ... 5s -> give up and return a timeout error.
+ */
+void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
+#endif /* MBEDTLS_SSL_PROTO_DTLS */
+
+#if defined(MBEDTLS_SSL_SRV_C)
+/**
+ * \brief Set the session cache callbacks (server-side only)
+ * If not set, no session resuming is done (except if session
+ * tickets are enabled too).
+ *
+ * The session cache has the responsibility to check for stale
+ * entries based on timeout. See RFC 5246 for recommendations.
+ *
+ * Warning: session.peer_cert is cleared by the SSL/TLS layer on
+ * connection shutdown, so do not cache the pointer! Either set
+ * it to NULL or make a full copy of the certificate.
+ *
+ * The get callback is called once during the initial handshake
+ * to enable session resuming. The get function has the
+ * following parameters: (void *parameter, mbedtls_ssl_session *session)
+ * If a valid entry is found, it should fill the master of
+ * the session object with the cached values and return 0,
+ * return 1 otherwise. Optionally peer_cert can be set as well
+ * if it is properly present in cache entry.
+ *
+ * The set callback is called once during the initial handshake
+ * to enable session resuming after the entire handshake has
+ * been finished. The set function has the following parameters:
+ * (void *parameter, const mbedtls_ssl_session *session). The function
+ * should create a cache entry for future retrieval based on
+ * the data in the session structure and should keep in mind
+ * that the mbedtls_ssl_session object presented (and all its referenced
+ * data) is cleared by the SSL/TLS layer when the connection is
+ * terminated. It is recommended to add metadata to determine if
+ * an entry is still valid in the future. Return 0 if
+ * successfully cached, return 1 otherwise.
+ *
+ * \param conf SSL configuration
+ * \param p_cache parmater (context) for both callbacks
+ * \param f_get_cache session get callback
+ * \param f_set_cache session set callback
+ */
+void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf,
+ void *p_cache,
+ int (*f_get_cache)(void *, mbedtls_ssl_session *),
+ int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
+#endif /* MBEDTLS_SSL_SRV_C */
+
+#if defined(MBEDTLS_SSL_CLI_C)
+/**
+ * \brief Request resumption of session (client-side only)
+ * Session data is copied from presented session structure.
+ *
+ * \param ssl SSL context
+ * \param session session context
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
+ * arguments are otherwise invalid
+ *
+ * \sa mbedtls_ssl_get_session()
+ */
+int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session );
+#endif /* MBEDTLS_SSL_CLI_C */
+
+/**
+ * \brief Set the list of allowed ciphersuites and the preference
+ * order. First in the list has the highest preference.
+ * (Overrides all version-specific lists)
+ *
+ * The ciphersuites array is not copied, and must remain
+ * valid for the lifetime of the ssl_config.
+ *
+ * Note: The server uses its own preferences
+ * over the preference of the client unless
+ * MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined!
+ *
+ * \param conf SSL configuration
+ * \param ciphersuites 0-terminated list of allowed ciphersuites
+ */
+void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
+ const int *ciphersuites );
+
+/**
+ * \brief Set the list of allowed ciphersuites and the
+ * preference order for a specific version of the protocol.
+ * (Only useful on the server side)
+ *
+ * The ciphersuites array is not copied, and must remain
+ * valid for the lifetime of the ssl_config.
+ *
+ * \param conf SSL configuration
+ * \param ciphersuites 0-terminated list of allowed ciphersuites
+ * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
+ * supported)
+ * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
+ * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
+ * MBEDTLS_SSL_MINOR_VERSION_3 supported)
+ *
+ * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0
+ * and MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
+ */
+void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
+ const int *ciphersuites,
+ int major, int minor );
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/**
+ * \brief Set the X.509 security profile used for verification
+ *
+ * \note The restrictions are enforced for all certificates in the
+ * chain. However, signatures in the handshake are not covered
+ * by this setting but by \b mbedtls_ssl_conf_sig_hashes().
+ *
+ * \param conf SSL configuration
+ * \param profile Profile to use
+ */
+void mbedtls_ssl_conf_cert_profile( mbedtls_ssl_config *conf,
+ const mbedtls_x509_crt_profile *profile );
+
+/**
+ * \brief Set the data required to verify peer certificate
+ *
+ * \param conf SSL configuration
+ * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
+ * \param ca_crl trusted CA CRLs
+ */
+void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
+ mbedtls_x509_crt *ca_chain,
+ mbedtls_x509_crl *ca_crl );
+
+/**
+ * \brief Set own certificate chain and private key
+ *
+ * \note own_cert should contain in order from the bottom up your
+ * certificate chain. The top certificate (self-signed)
+ * can be omitted.
+ *
+ * \note On server, this function can be called multiple times to
+ * provision more than one cert/key pair (eg one ECDSA, one
+ * RSA with SHA-256, one RSA with SHA-1). An adequate
+ * certificate will be selected according to the client's
+ * advertised capabilities. In case mutliple certificates are
+ * adequate, preference is given to the one set by the first
+ * call to this function, then second, etc.
+ *
+ * \note On client, only the first call has any effect. That is,
+ * only one client certificate can be provisioned. The
+ * server's preferences in its CertficateRequest message will
+ * be ignored and our only cert will be sent regardless of
+ * whether it matches those preferences - the server can then
+ * decide what it wants to do with it.
+ *
+ * \param conf SSL configuration
+ * \param own_cert own public certificate chain
+ * \param pk_key own private key
+ *
+ * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
+ */
+int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf,
+ mbedtls_x509_crt *own_cert,
+ mbedtls_pk_context *pk_key );
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
+/**
+ * \brief Set the Pre Shared Key (PSK) and the expected identity name
+ *
+ * \note This is mainly useful for clients. Servers will usually
+ * want to use \c mbedtls_ssl_conf_psk_cb() instead.
+ *
+ * \note Currently clients can only register one pre-shared key.
+ * In other words, the servers' identity hint is ignored.
+ * Support for setting multiple PSKs on clients and selecting
+ * one based on the identity hint is not a planned feature but
+ * feedback is welcomed.
+ *
+ * \param conf SSL configuration
+ * \param psk pointer to the pre-shared key
+ * \param psk_len pre-shared key length
+ * \param psk_identity pointer to the pre-shared key identity
+ * \param psk_identity_len identity key length
+ *
+ * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
+ */
+int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
+ const unsigned char *psk, size_t psk_len,
+ const unsigned char *psk_identity, size_t psk_identity_len );
+
+
+/**
+ * \brief Set the Pre Shared Key (PSK) for the current handshake
+ *
+ * \note This should only be called inside the PSK callback,
+ * ie the function passed to \c mbedtls_ssl_conf_psk_cb().
+ *
+ * \param ssl SSL context
+ * \param psk pointer to the pre-shared key
+ * \param psk_len pre-shared key length
+ *
+ * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
+ */
+int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
+ const unsigned char *psk, size_t psk_len );
+
+/**
+ * \brief Set the PSK callback (server-side only).
+ *
+ * If set, the PSK callback is called for each
+ * handshake where a PSK ciphersuite was negotiated.
+ * The caller provides the identity received and wants to
+ * receive the actual PSK data and length.
+ *
+ * The callback has the following parameters: (void *parameter,
+ * mbedtls_ssl_context *ssl, const unsigned char *psk_identity,
+ * size_t identity_len)
+ * If a valid PSK identity is found, the callback should use
+ * \c mbedtls_ssl_set_hs_psk() on the ssl context to set the
+ * correct PSK and return 0.
+ * Any other return value will result in a denied PSK identity.
+ *
+ * \note If you set a PSK callback using this function, then you
+ * don't need to set a PSK key and identity using
+ * \c mbedtls_ssl_conf_psk().
+ *
+ * \param conf SSL configuration
+ * \param f_psk PSK identity function
+ * \param p_psk PSK identity parameter
+ */
+void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
+ int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
+ size_t),
+ void *p_psk );
+#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
+
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+
+/**
+ * \brief Set the Diffie-Hellman public P and G values,
+ * read as hexadecimal strings (server-side only)
+ * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG])
+ *
+ * \param conf SSL configuration
+ * \param dhm_P Diffie-Hellman-Merkle modulus
+ * \param dhm_G Diffie-Hellman-Merkle generator
+ *
+ * \deprecated Superseded by \c mbedtls_ssl_conf_dh_param_bin.
+ *
+ * \return 0 if successful
+ */
+MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf,
+ const char *dhm_P,
+ const char *dhm_G );
+
+#endif /* MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief Set the Diffie-Hellman public P and G values
+ * from big-endian binary presentations.
+ * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN)
+ *
+ * \param conf SSL configuration
+ * \param dhm_P Diffie-Hellman-Merkle modulus in big-endian binary form
+ * \param P_len Length of DHM modulus
+ * \param dhm_G Diffie-Hellman-Merkle generator in big-endian binary form
+ * \param G_len Length of DHM generator
+ *
+ * \return 0 if successful
+ */
+int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf,
+ const unsigned char *dhm_P, size_t P_len,
+ const unsigned char *dhm_G, size_t G_len );
+
+/**
+ * \brief Set the Diffie-Hellman public P and G values,
+ * read from existing context (server-side only)
+ *
+ * \param conf SSL configuration
+ * \param dhm_ctx Diffie-Hellman-Merkle context
+ *
+ * \return 0 if successful
+ */
+int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx );
+#endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
+
+#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
+/**
+ * \brief Set the minimum length for Diffie-Hellman parameters.
+ * (Client-side only.)
+ * (Default: 1024 bits.)
+ *
+ * \param conf SSL configuration
+ * \param bitlen Minimum bit length of the DHM prime
+ */
+void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
+ unsigned int bitlen );
+#endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
+
+#if defined(MBEDTLS_ECP_C)
+/**
+ * \brief Set the allowed curves in order of preference.
+ * (Default: all defined curves.)
+ *
+ * On server: this only affects selection of the ECDHE curve;
+ * the curves used for ECDH and ECDSA are determined by the
+ * list of available certificates instead.
+ *
+ * On client: this affects the list of curves offered for any
+ * use. The server can override our preference order.
+ *
+ * Both sides: limits the set of curves accepted for use in
+ * ECDHE and in the peer's end-entity certificate.
+ *
+ * \note This has no influence on which curves are allowed inside the
+ * certificate chains, see \c mbedtls_ssl_conf_cert_profile()
+ * for that. For the end-entity certificate however, the key
+ * will be accepted only if it is allowed both by this list
+ * and by the cert profile.
+ *
+ * \note This list should be ordered by decreasing preference
+ * (preferred curve first).
+ *
+ * \param conf SSL configuration
+ * \param curves Ordered list of allowed curves,
+ * terminated by MBEDTLS_ECP_DP_NONE.
+ */
+void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,
+ const mbedtls_ecp_group_id *curves );
+#endif /* MBEDTLS_ECP_C */
+
+#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
+/**
+ * \brief Set the allowed hashes for signatures during the handshake.
+ * (Default: all available hashes except MD5.)
+ *
+ * \note This only affects which hashes are offered and can be used
+ * for signatures during the handshake. Hashes for message
+ * authentication and the TLS PRF are controlled by the
+ * ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes
+ * used for certificate signature are controlled by the
+ * verification profile, see \c mbedtls_ssl_conf_cert_profile().
+ *
+ * \note This list should be ordered by decreasing preference
+ * (preferred hash first).
+ *
+ * \param conf SSL configuration
+ * \param hashes Ordered list of allowed signature hashes,
+ * terminated by \c MBEDTLS_MD_NONE.
+ */
+void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf,
+ const int *hashes );
+#endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/**
+ * \brief Set or reset the hostname to check against the received
+ * server certificate. It sets the ServerName TLS extension,
+ * too, if that extension is enabled. (client-side only)
+ *
+ * \param ssl SSL context
+ * \param hostname the server hostname, may be NULL to clear hostname
+
+ * \note Maximum hostname length MBEDTLS_SSL_MAX_HOST_NAME_LEN.
+ *
+ * \return 0 if successful, MBEDTLS_ERR_SSL_ALLOC_FAILED on
+ * allocation failure, MBEDTLS_ERR_SSL_BAD_INPUT_DATA on
+ * too long input hostname.
+ *
+ * Hostname set to the one provided on success (cleared
+ * when NULL). On allocation failure hostname is cleared.
+ * On too long input failure, old hostname is unchanged.
+ */
+int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
+/**
+ * \brief Set own certificate and key for the current handshake
+ *
+ * \note Same as \c mbedtls_ssl_conf_own_cert() but for use within
+ * the SNI callback.
+ *
+ * \param ssl SSL context
+ * \param own_cert own public certificate chain
+ * \param pk_key own private key
+ *
+ * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
+ */
+int mbedtls_ssl_set_hs_own_cert( mbedtls_ssl_context *ssl,
+ mbedtls_x509_crt *own_cert,
+ mbedtls_pk_context *pk_key );
+
+/**
+ * \brief Set the data required to verify peer certificate for the
+ * current handshake
+ *
+ * \note Same as \c mbedtls_ssl_conf_ca_chain() but for use within
+ * the SNI callback.
+ *
+ * \param ssl SSL context
+ * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
+ * \param ca_crl trusted CA CRLs
+ */
+void mbedtls_ssl_set_hs_ca_chain( mbedtls_ssl_context *ssl,
+ mbedtls_x509_crt *ca_chain,
+ mbedtls_x509_crl *ca_crl );
+
+/**
+ * \brief Set authmode for the current handshake.
+ *
+ * \note Same as \c mbedtls_ssl_conf_authmode() but for use within
+ * the SNI callback.
+ *
+ * \param ssl SSL context
+ * \param authmode MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL or
+ * MBEDTLS_SSL_VERIFY_REQUIRED
+ */
+void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl,
+ int authmode );
+
+/**
+ * \brief Set server side ServerName TLS extension callback
+ * (optional, server-side only).
+ *
+ * If set, the ServerName callback is called whenever the
+ * server receives a ServerName TLS extension from the client
+ * during a handshake. The ServerName callback has the
+ * following parameters: (void *parameter, mbedtls_ssl_context *ssl,
+ * const unsigned char *hostname, size_t len). If a suitable
+ * certificate is found, the callback must set the
+ * certificate(s) and key(s) to use with \c
+ * mbedtls_ssl_set_hs_own_cert() (can be called repeatedly),
+ * and may optionally adjust the CA and associated CRL with \c
+ * mbedtls_ssl_set_hs_ca_chain() as well as the client
+ * authentication mode with \c mbedtls_ssl_set_hs_authmode(),
+ * then must return 0. If no matching name is found, the
+ * callback must either set a default cert, or
+ * return non-zero to abort the handshake at this point.
+ *
+ * \param conf SSL configuration
+ * \param f_sni verification function
+ * \param p_sni verification parameter
+ */
+void mbedtls_ssl_conf_sni( mbedtls_ssl_config *conf,
+ int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
+ size_t),
+ void *p_sni );
+#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+/**
+ * \brief Set the EC J-PAKE password for current handshake.
+ *
+ * \note An internal copy is made, and destroyed as soon as the
+ * handshake is completed, or when the SSL context is reset or
+ * freed.
+ *
+ * \note The SSL context needs to be already set up. The right place
+ * to call this function is between \c mbedtls_ssl_setup() or
+ * \c mbedtls_ssl_reset() and \c mbedtls_ssl_handshake().
+ *
+ * \param ssl SSL context
+ * \param pw EC J-PAKE password (pre-shared secret)
+ * \param pw_len length of pw in bytes
+ *
+ * \return 0 on success, or a negative error code.
+ */
+int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
+ const unsigned char *pw,
+ size_t pw_len );
+#endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
+
+#if defined(MBEDTLS_SSL_ALPN)
+/**
+ * \brief Set the supported Application Layer Protocols.
+ *
+ * \param conf SSL configuration
+ * \param protos Pointer to a NULL-terminated list of supported protocols,
+ * in decreasing preference order. The pointer to the list is
+ * recorded by the library for later reference as required, so
+ * the lifetime of the table must be atleast as long as the
+ * lifetime of the SSL configuration structure.
+ *
+ * \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA.
+ */
+int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
+
+/**
+ * \brief Get the name of the negotiated Application Layer Protocol.
+ * This function should be called after the handshake is
+ * completed.
+ *
+ * \param ssl SSL context
+ *
+ * \return Protcol name, or NULL if no protocol was negotiated.
+ */
+const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
+#endif /* MBEDTLS_SSL_ALPN */
+
+/**
+ * \brief Set the maximum supported version sent from the client side
+ * and/or accepted at the server side
+ * (Default: MBEDTLS_SSL_MAX_MAJOR_VERSION, MBEDTLS_SSL_MAX_MINOR_VERSION)
+ *
+ * \note This ignores ciphersuites from higher versions.
+ *
+ * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
+ * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
+ *
+ * \param conf SSL configuration
+ * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
+ * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
+ * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
+ * MBEDTLS_SSL_MINOR_VERSION_3 supported)
+ */
+void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
+
+/**
+ * \brief Set the minimum accepted SSL/TLS protocol version
+ * (Default: TLS 1.0)
+ *
+ * \note Input outside of the SSL_MAX_XXXXX_VERSION and
+ * SSL_MIN_XXXXX_VERSION range is ignored.
+ *
+ * \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
+ *
+ * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
+ * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
+ *
+ * \param conf SSL configuration
+ * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
+ * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
+ * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
+ * MBEDTLS_SSL_MINOR_VERSION_3 supported)
+ */
+void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
+
+#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
+/**
+ * \brief Set the fallback flag (client-side only).
+ * (Default: MBEDTLS_SSL_IS_NOT_FALLBACK).
+ *
+ * \note Set to MBEDTLS_SSL_IS_FALLBACK when preparing a fallback
+ * connection, that is a connection with max_version set to a
+ * lower value than the value you're willing to use. Such
+ * fallback connections are not recommended but are sometimes
+ * necessary to interoperate with buggy (version-intolerant)
+ * servers.
+ *
+ * \warning You should NOT set this to MBEDTLS_SSL_IS_FALLBACK for
+ * non-fallback connections! This would appear to work for a
+ * while, then cause failures when the server is upgraded to
+ * support a newer TLS version.
+ *
+ * \param conf SSL configuration
+ * \param fallback MBEDTLS_SSL_IS_NOT_FALLBACK or MBEDTLS_SSL_IS_FALLBACK
+ */
+void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
+#endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
+
+#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
+/**
+ * \brief Enable or disable Encrypt-then-MAC
+ * (Default: MBEDTLS_SSL_ETM_ENABLED)
+ *
+ * \note This should always be enabled, it is a security
+ * improvement, and should not cause any interoperability
+ * issue (used only if the peer supports it too).
+ *
+ * \param conf SSL configuration
+ * \param etm MBEDTLS_SSL_ETM_ENABLED or MBEDTLS_SSL_ETM_DISABLED
+ */
+void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm );
+#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
+/**
+ * \brief Enable or disable Extended Master Secret negotiation.
+ * (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED)
+ *
+ * \note This should always be enabled, it is a security fix to the
+ * protocol, and should not cause any interoperability issue
+ * (used only if the peer supports it too).
+ *
+ * \param conf SSL configuration
+ * \param ems MBEDTLS_SSL_EXTENDED_MS_ENABLED or MBEDTLS_SSL_EXTENDED_MS_DISABLED
+ */
+void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems );
+#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
+
+#if defined(MBEDTLS_ARC4_C)
+/**
+ * \brief Disable or enable support for RC4
+ * (Default: MBEDTLS_SSL_ARC4_DISABLED)
+ *
+ * \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465
+ * for security reasons. Use at your own risk.
+ *
+ * \note This function is deprecated and will likely be removed in
+ * a future version of the library.
+ * RC4 is disabled by default at compile time and needs to be
+ * actively enabled for use with legacy systems.
+ *
+ * \param conf SSL configuration
+ * \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED
+ */
+void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
+#endif /* MBEDTLS_ARC4_C */
+
+#if defined(MBEDTLS_SSL_SRV_C)
+/**
+ * \brief Whether to send a list of acceptable CAs in
+ * CertificateRequest messages.
+ * (Default: do send)
+ *
+ * \param conf SSL configuration
+ * \param cert_req_ca_list MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED or
+ * MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED
+ */
+void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf,
+ char cert_req_ca_list );
+#endif /* MBEDTLS_SSL_SRV_C */
+
+#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+/**
+ * \brief Set the maximum fragment length to emit and/or negotiate
+ * (Default: MBEDTLS_SSL_MAX_CONTENT_LEN, usually 2^14 bytes)
+ * (Server: set maximum fragment length to emit,
+ * usually negotiated by the client during handshake
+ * (Client: set maximum fragment length to emit *and*
+ * negotiate with the server during handshake)
+ *
+ * \param conf SSL configuration
+ * \param mfl_code Code for maximum fragment length (allowed values:
+ * MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024,
+ * MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096)
+ *
+ * \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA
+ */
+int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
+#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
+
+#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
+/**
+ * \brief Activate negotiation of truncated HMAC
+ * (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
+ *
+ * \param conf SSL configuration
+ * \param truncate Enable or disable (MBEDTLS_SSL_TRUNC_HMAC_ENABLED or
+ * MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
+ */
+void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
+#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
+
+#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
+/**
+ * \brief Enable / Disable 1/n-1 record splitting
+ * (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED)
+ *
+ * \note Only affects SSLv3 and TLS 1.0, not higher versions.
+ * Does not affect non-CBC ciphersuites in any version.
+ *
+ * \param conf SSL configuration
+ * \param split MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED or
+ * MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED
+ */
+void mbedtls_ssl_conf_cbc_record_splitting( mbedtls_ssl_config *conf, char split );
+#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
+
+#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
+/**
+ * \brief Enable / Disable session tickets (client only).
+ * (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED.)
+ *
+ * \note On server, use \c mbedtls_ssl_conf_session_tickets_cb().
+ *
+ * \param conf SSL configuration
+ * \param use_tickets Enable or disable (MBEDTLS_SSL_SESSION_TICKETS_ENABLED or
+ * MBEDTLS_SSL_SESSION_TICKETS_DISABLED)
+ */
+void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
+#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
+
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+/**
+ * \brief Enable / Disable renegotiation support for connection when
+ * initiated by peer
+ * (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED)
+ *
+ * \warning It is recommended to always disable renegotation unless you
+ * know you need it and you know what you're doing. In the
+ * past, there have been several issues associated with
+ * renegotiation or a poor understanding of its properties.
+ *
+ * \note Server-side, enabling renegotiation also makes the server
+ * susceptible to a resource DoS by a malicious client.
+ *
+ * \param conf SSL configuration
+ * \param renegotiation Enable or disable (MBEDTLS_SSL_RENEGOTIATION_ENABLED or
+ * MBEDTLS_SSL_RENEGOTIATION_DISABLED)
+ */
+void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
+#endif /* MBEDTLS_SSL_RENEGOTIATION */
+
+/**
+ * \brief Prevent or allow legacy renegotiation.
+ * (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION)
+ *
+ * MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to
+ * be established even if the peer does not support
+ * secure renegotiation, but does not allow renegotiation
+ * to take place if not secure.
+ * (Interoperable and secure option)
+ *
+ * MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations
+ * with non-upgraded peers. Allowing legacy renegotiation
+ * makes the connection vulnerable to specific man in the
+ * middle attacks. (See RFC 5746)
+ * (Most interoperable and least secure option)
+ *
+ * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections
+ * if peer does not support secure renegotiation. Results
+ * in interoperability issues with non-upgraded peers
+ * that do not support renegotiation altogether.
+ * (Most secure option, interoperability issues)
+ *
+ * \param conf SSL configuration
+ * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION,
+ * SSL_ALLOW_LEGACY_RENEGOTIATION or
+ * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE)
+ */
+void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
+
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+/**
+ * \brief Enforce renegotiation requests.
+ * (Default: enforced, max_records = 16)
+ *
+ * When we request a renegotiation, the peer can comply or
+ * ignore the request. This function allows us to decide
+ * whether to enforce our renegotiation requests by closing
+ * the connection if the peer doesn't comply.
+ *
+ * However, records could already be in transit from the peer
+ * when the request is emitted. In order to increase
+ * reliability, we can accept a number of records before the
+ * expected handshake records.
+ *
+ * The optimal value is highly dependent on the specific usage
+ * scenario.
+ *
+ * \note With DTLS and server-initiated renegotiation, the
+ * HelloRequest is retransmited every time mbedtls_ssl_read() times
+ * out or receives Application Data, until:
+ * - max_records records have beens seen, if it is >= 0, or
+ * - the number of retransmits that would happen during an
+ * actual handshake has been reached.
+ * Please remember the request might be lost a few times
+ * if you consider setting max_records to a really low value.
+ *
+ * \warning On client, the grace period can only happen during
+ * mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate()
+ * which always behave as if max_record was 0. The reason is,
+ * if we receive application data from the server, we need a
+ * place to write it, which only happens during mbedtls_ssl_read().
+ *
+ * \param conf SSL configuration
+ * \param max_records Use MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED if you don't want to
+ * enforce renegotiation, or a non-negative value to enforce
+ * it but allow for a grace period of max_records records.
+ */
+void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
+
+/**
+ * \brief Set record counter threshold for periodic renegotiation.
+ * (Default: 2^48 - 1)
+ *
+ * Renegotiation is automatically triggered when a record
+ * counter (outgoing or ingoing) crosses the defined
+ * threshold. The default value is meant to prevent the
+ * connection from being closed when the counter is about to
+ * reached its maximal value (it is not allowed to wrap).
+ *
+ * Lower values can be used to enforce policies such as "keys
+ * must be refreshed every N packets with cipher X".
+ *
+ * The renegotiation period can be disabled by setting
+ * conf->disable_renegotiation to
+ * MBEDTLS_SSL_RENEGOTIATION_DISABLED.
+ *
+ * \note When the configured transport is
+ * MBEDTLS_SSL_TRANSPORT_DATAGRAM the maximum renegotiation
+ * period is 2^48 - 1, and for MBEDTLS_SSL_TRANSPORT_STREAM,
+ * the maximum renegotiation period is 2^64 - 1.
+ *
+ * \param conf SSL configuration
+ * \param period The threshold value: a big-endian 64-bit number.
+ */
+void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
+ const unsigned char period[8] );
+#endif /* MBEDTLS_SSL_RENEGOTIATION */
+
+/**
+ * \brief Return the number of data bytes available to read
+ *
+ * \param ssl SSL context
+ *
+ * \return how many bytes are available in the read buffer
+ */
+size_t mbedtls_ssl_get_bytes_avail( const mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Return the result of the certificate verification
+ *
+ * \param ssl SSL context
+ *
+ * \return 0 if successful,
+ * -1 if result is not available (eg because the handshake was
+ * aborted too early), or
+ * a combination of BADCERT_xxx and BADCRL_xxx flags, see
+ * x509.h
+ */
+uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Return the name of the current ciphersuite
+ *
+ * \param ssl SSL context
+ *
+ * \return a string containing the ciphersuite name
+ */
+const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Return the current SSL version (SSLv3/TLSv1/etc)
+ *
+ * \param ssl SSL context
+ *
+ * \return a string containing the SSL version
+ */
+const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Return the (maximum) number of bytes added by the record
+ * layer: header + encryption/MAC overhead (inc. padding)
+ *
+ * \param ssl SSL context
+ *
+ * \return Current maximum record expansion in bytes, or
+ * MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is
+ * enabled, which makes expansion much less predictable
+ */
+int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl );
+
+#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+/**
+ * \brief Return the maximum fragment length (payload, in bytes).
+ * This is the value negotiated with peer if any,
+ * or the locally configured value.
+ *
+ * \note With DTLS, \c mbedtls_ssl_write() will return an error if
+ * called with a larger length value.
+ * With TLS, \c mbedtls_ssl_write() will fragment the input if
+ * necessary and return the number of bytes written; it is up
+ * to the caller to call \c mbedtls_ssl_write() again in
+ * order to send the remaining bytes if any.
+ *
+ * \param ssl SSL context
+ *
+ * \return Current maximum fragment length.
+ */
+size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl );
+#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/**
+ * \brief Return the peer certificate from the current connection
+ *
+ * Note: Can be NULL in case no certificate was sent during
+ * the handshake. Different calls for the same connection can
+ * return the same or different pointers for the same
+ * certificate and even a different certificate altogether.
+ * The peer cert CAN change in a single connection if
+ * renegotiation is performed.
+ *
+ * \param ssl SSL context
+ *
+ * \return the current peer certificate
+ */
+const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+#if defined(MBEDTLS_SSL_CLI_C)
+/**
+ * \brief Save session in order to resume it later (client-side only)
+ * Session data is copied to presented session structure.
+ *
+ * \warning Currently, peer certificate is lost in the operation.
+ *
+ * \param ssl SSL context
+ * \param session session context
+ *
+ * \return 0 if successful,
+ * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
+ * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
+ * arguments are otherwise invalid
+ *
+ * \sa mbedtls_ssl_set_session()
+ */
+int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session );
+#endif /* MBEDTLS_SSL_CLI_C */
+
+/**
+ * \brief Perform the SSL handshake
+ *
+ * \param ssl SSL context
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
+ * MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED (see below), or
+ * a specific SSL error code.
+ *
+ * \note If this function returns something other than 0 or
+ * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ *
+ * \note If DTLS is in use, then you may choose to handle
+ * MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED specially for logging
+ * purposes, as it is an expected return value rather than an
+ * actual error, but you still need to reset/free the context.
+ */
+int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Perform a single step of the SSL handshake
+ *
+ * \note The state of the context (ssl->state) will be at
+ * the next state after execution of this function. Do not
+ * call this function if state is MBEDTLS_SSL_HANDSHAKE_OVER.
+ *
+ * \note If this function returns something other than 0 or
+ * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ *
+ * \param ssl SSL context
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
+ * a specific SSL error code.
+ */
+int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl );
+
+#if defined(MBEDTLS_SSL_RENEGOTIATION)
+/**
+ * \brief Initiate an SSL renegotiation on the running connection.
+ * Client: perform the renegotiation right now.
+ * Server: request renegotiation, which will be performed
+ * during the next call to mbedtls_ssl_read() if honored by
+ * client.
+ *
+ * \param ssl SSL context
+ *
+ * \return 0 if successful, or any mbedtls_ssl_handshake() return
+ * value.
+ *
+ * \note If this function returns something other than 0 or
+ * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ */
+int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl );
+#endif /* MBEDTLS_SSL_RENEGOTIATION */
+
+/**
+ * \brief Read at most 'len' application data bytes
+ *
+ * \param ssl SSL context
+ * \param buf buffer that will hold the data
+ * \param len maximum number of bytes to read
+ *
+ * \return the number of bytes read, or
+ * 0 for EOF, or
+ * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
+ * MBEDTLS_ERR_SSL_CLIENT_RECONNECT (see below), or
+ * another negative error code.
+ *
+ * \note If this function returns something other than a positive
+ * value or MBEDTLS_ERR_SSL_WANT_READ/WRITE or
+ * MBEDTLS_ERR_SSL_CLIENT_RECONNECT, then the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ *
+ * \note When this function return MBEDTLS_ERR_SSL_CLIENT_RECONNECT
+ * (which can only happen server-side), it means that a client
+ * is initiating a new connection using the same source port.
+ * You can either treat that as a connection close and wait
+ * for the client to resend a ClientHello, or directly
+ * continue with \c mbedtls_ssl_handshake() with the same
+ * context (as it has beeen reset internally). Either way, you
+ * should make sure this is seen by the application as a new
+ * connection: application state, if any, should be reset, and
+ * most importantly the identity of the client must be checked
+ * again. WARNING: not validating the identity of the client
+ * again, or not transmitting the new identity to the
+ * application layer, would allow authentication bypass!
+ */
+int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
+
+/**
+ * \brief Try to write exactly 'len' application data bytes
+ *
+ * \warning This function will do partial writes in some cases. If the
+ * return value is non-negative but less than length, the
+ * function must be called again with updated arguments:
+ * buf + ret, len - ret (if ret is the return value) until
+ * it returns a value equal to the last 'len' argument.
+ *
+ * \param ssl SSL context
+ * \param buf buffer holding the data
+ * \param len how many bytes must be written
+ *
+ * \return the number of bytes actually written (may be less than len),
+ * or MBEDTLS_ERR_SSL_WANT_WRITE or MBEDTLS_ERR_SSL_WANT_READ,
+ * or another negative error code.
+ *
+ * \note If this function returns something other than a positive
+ * value or MBEDTLS_ERR_SSL_WANT_READ/WRITE, the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ *
+ * \note When this function returns MBEDTLS_ERR_SSL_WANT_WRITE/READ,
+ * it must be called later with the *same* arguments,
+ * until it returns a positive value.
+ *
+ * \note If the requested length is greater than the maximum
+ * fragment length (either the built-in limit or the one set
+ * or negotiated with the peer), then:
+ * - with TLS, less bytes than requested are written.
+ * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
+ * \c mbedtls_ssl_get_max_frag_len() may be used to query the
+ * active maximum fragment length.
+ */
+int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
+
+/**
+ * \brief Send an alert message
+ *
+ * \param ssl SSL context
+ * \param level The alert level of the message
+ * (MBEDTLS_SSL_ALERT_LEVEL_WARNING or MBEDTLS_SSL_ALERT_LEVEL_FATAL)
+ * \param message The alert message (SSL_ALERT_MSG_*)
+ *
+ * \return 0 if successful, or a specific SSL error code.
+ *
+ * \note If this function returns something other than 0 or
+ * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ */
+int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl,
+ unsigned char level,
+ unsigned char message );
+/**
+ * \brief Notify the peer that the connection is being closed
+ *
+ * \param ssl SSL context
+ *
+ * \return 0 if successful, or a specific SSL error code.
+ *
+ * \note If this function returns something other than 0 or
+ * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
+ * becomes unusable, and you should either free it or call
+ * \c mbedtls_ssl_session_reset() on it before re-using it for
+ * a new connection; the current connection must be closed.
+ */
+int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Free referenced items in an SSL context and clear memory
+ *
+ * \param ssl SSL context
+ */
+void mbedtls_ssl_free( mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Initialize an SSL configuration context
+ * Just makes the context ready for
+ * mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free().
+ *
+ * \note You need to call mbedtls_ssl_config_defaults() unless you
+ * manually set all of the relevent fields yourself.
+ *
+ * \param conf SSL configuration context
+ */
+void mbedtls_ssl_config_init( mbedtls_ssl_config *conf );
+
+/**
+ * \brief Load reasonnable default SSL configuration values.
+ * (You need to call mbedtls_ssl_config_init() first.)
+ *
+ * \param conf SSL configuration context
+ * \param endpoint MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
+ * \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
+ * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
+ * \param preset a MBEDTLS_SSL_PRESET_XXX value
+ *
+ * \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_XXX_ALLOC_FAILED on memory allocation error.
+ */
+int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
+ int endpoint, int transport, int preset );
+
+/**
+ * \brief Free an SSL configuration context
+ *
+ * \param conf SSL configuration context
+ */
+void mbedtls_ssl_config_free( mbedtls_ssl_config *conf );
+
+/**
+ * \brief Initialize SSL session structure
+ *
+ * \param session SSL session
+ */
+void mbedtls_ssl_session_init( mbedtls_ssl_session *session );
+
+/**
+ * \brief Free referenced items in an SSL session including the
+ * peer certificate and clear memory
+ *
+ * \param session SSL session
+ */
+void mbedtls_ssl_session_free( mbedtls_ssl_session *session );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl.h */
+
+
+/********* Start of file include/mbedtls/ssl_cookie.h ************/
+
+/**
+ * \file ssl_cookie.h
+ *
+ * \brief DTLS cookie callbacks implementation
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SSL_COOKIE_H
+#define MBEDTLS_SSL_COOKIE_H
+
+
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+#ifndef MBEDTLS_SSL_COOKIE_TIMEOUT
+#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
+#endif
+
+/* \} name SECTION: Module settings */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Context for the default cookie functions.
+ */
+typedef struct
+{
+ mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */
+#if !defined(MBEDTLS_HAVE_TIME)
+ unsigned long serial; /*!< serial number for expiration */
+#endif
+ unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME,
+ or in number of tickets issued */
+
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex;
+#endif
+} mbedtls_ssl_cookie_ctx;
+
+/**
+ * \brief Initialize cookie context
+ */
+void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx );
+
+/**
+ * \brief Setup cookie context (generate keys)
+ */
+int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+/**
+ * \brief Set expiration delay for cookies
+ * (Default MBEDTLS_SSL_COOKIE_TIMEOUT)
+ *
+ * \param ctx Cookie contex
+ * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies
+ * issued in the meantime.
+ * 0 to disable expiration (NOT recommended)
+ */
+void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay );
+
+/**
+ * \brief Free cookie context
+ */
+void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx );
+
+/**
+ * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t
+ */
+mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write;
+
+/**
+ * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t
+ */
+mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl_cookie.h */
+
+
+/********* Start of file include/mbedtls/ssl_internal.h ************/
+
+/**
+ * \file ssl_internal.h
+ *
+ * \brief Internal functions shared by the SSL modules
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SSL_INTERNAL_H
+#define MBEDTLS_SSL_INTERNAL_H
+
+
+
+
+#if defined(MBEDTLS_MD5_C)
+
+#endif
+
+#if defined(MBEDTLS_SHA1_C)
+
+#endif
+
+#if defined(MBEDTLS_SHA256_C)
+
+#endif
+
+#if defined(MBEDTLS_SHA512_C)
+
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+
+#endif
+
+#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
+ !defined(inline) && !defined(__cplusplus)
+#define inline __inline
+#endif
+
+/* Determine minimum supported version */
+#define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
+
+#if defined(MBEDTLS_SSL_PROTO_SSL3)
+#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
+#else
+#if defined(MBEDTLS_SSL_PROTO_TLS1)
+#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
+#else
+#if defined(MBEDTLS_SSL_PROTO_TLS1_1)
+#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
+#else
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
+#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
+#endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
+#endif /* MBEDTLS_SSL_PROTO_TLS1 */
+#endif /* MBEDTLS_SSL_PROTO_SSL3 */
+
+#define MBEDTLS_SSL_MIN_VALID_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
+#define MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
+
+/* Determine maximum supported version */
+#define MBEDTLS_SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
+#else
+#if defined(MBEDTLS_SSL_PROTO_TLS1_1)
+#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
+#else
+#if defined(MBEDTLS_SSL_PROTO_TLS1)
+#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
+#else
+#if defined(MBEDTLS_SSL_PROTO_SSL3)
+#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
+#endif /* MBEDTLS_SSL_PROTO_SSL3 */
+#endif /* MBEDTLS_SSL_PROTO_TLS1 */
+#endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
+#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
+
+#define MBEDTLS_SSL_INITIAL_HANDSHAKE 0
+#define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS 1 /* In progress */
+#define MBEDTLS_SSL_RENEGOTIATION_DONE 2 /* Done or aborted */
+#define MBEDTLS_SSL_RENEGOTIATION_PENDING 3 /* Requested (server only) */
+
+/*
+ * DTLS retransmission states, see RFC 6347 4.2.4
+ *
+ * The SENDING state is merged in PREPARING for initial sends,
+ * but is distinct for resends.
+ *
+ * Note: initial state is wrong for server, but is not used anyway.
+ */
+#define MBEDTLS_SSL_RETRANS_PREPARING 0
+#define MBEDTLS_SSL_RETRANS_SENDING 1
+#define MBEDTLS_SSL_RETRANS_WAITING 2
+#define MBEDTLS_SSL_RETRANS_FINISHED 3
+
+/*
+ * Allow extra bytes for record, authentication and encryption overhead:
+ * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256)
+ * and allow for a maximum of 1024 of compression expansion if
+ * enabled.
+ */
+#if defined(MBEDTLS_ZLIB_SUPPORT)
+#define MBEDTLS_SSL_COMPRESSION_ADD 1024
+#else
+#define MBEDTLS_SSL_COMPRESSION_ADD 0
+#endif
+
+#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_MODE_CBC)
+/* Ciphersuites using HMAC */
+#if defined(MBEDTLS_SHA512_C)
+#define MBEDTLS_SSL_MAC_ADD 48 /* SHA-384 used for HMAC */
+#elif defined(MBEDTLS_SHA256_C)
+#define MBEDTLS_SSL_MAC_ADD 32 /* SHA-256 used for HMAC */
+#else
+#define MBEDTLS_SSL_MAC_ADD 20 /* SHA-1 used for HMAC */
+#endif
+#else
+/* AEAD ciphersuites: GCM and CCM use a 128 bits tag */
+#define MBEDTLS_SSL_MAC_ADD 16
+#endif
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+#define MBEDTLS_SSL_PADDING_ADD 256
+#else
+#define MBEDTLS_SSL_PADDING_ADD 0
+#endif
+
+#define MBEDTLS_SSL_PAYLOAD_LEN ( MBEDTLS_SSL_MAX_CONTENT_LEN \
+ + MBEDTLS_SSL_COMPRESSION_ADD \
+ + MBEDTLS_MAX_IV_LENGTH \
+ + MBEDTLS_SSL_MAC_ADD \
+ + MBEDTLS_SSL_PADDING_ADD \
+ )
+
+/*
+ * Check that we obey the standard's message size bounds
+ */
+
+#if MBEDTLS_SSL_MAX_CONTENT_LEN > 16384
+#error Bad configuration - record content too large.
+#endif
+
+#if MBEDTLS_SSL_PAYLOAD_LEN > 16384 + 2048
+#error Bad configuration - protected record payload too large.
+#endif
+
+/* Note: Even though the TLS record header is only 5 bytes
+ long, we're internally using 8 bytes to store the
+ implicit sequence number. */
+#define MBEDTLS_SSL_HEADER_LEN 13
+
+#define MBEDTLS_SSL_BUFFER_LEN \
+ ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_PAYLOAD_LEN ) )
+
+/*
+ * TLS extension flags (for extensions with outgoing ServerHello content
+ * that need it (e.g. for RENEGOTIATION_INFO the server already knows because
+ * of state of the renegotiation flag, so no indicator is required)
+ */
+#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
+#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK (1 << 1)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
+ defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
+/*
+ * Abstraction for a grid of allowed signature-hash-algorithm pairs.
+ */
+struct mbedtls_ssl_sig_hash_set_t
+{
+ /* At the moment, we only need to remember a single suitable
+ * hash algorithm per signature algorithm. As long as that's
+ * the case - and we don't need a general lookup function -
+ * we can implement the sig-hash-set as a map from signatures
+ * to hash algorithms. */
+ mbedtls_md_type_t rsa;
+ mbedtls_md_type_t ecdsa;
+};
+#endif /* MBEDTLS_SSL_PROTO_TLS1_2 &&
+ MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
+
+/*
+ * This structure contains the parameters only needed during handshake.
+ */
+struct mbedtls_ssl_handshake_params
+{
+ /*
+ * Handshake specific crypto variables
+ */
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
+ defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
+ mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */
+#endif
+#if defined(MBEDTLS_DHM_C)
+ mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
+#endif
+#if defined(MBEDTLS_ECDH_C)
+ mbedtls_ecdh_context ecdh_ctx; /*!< ECDH key exchange */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+ mbedtls_ecjpake_context ecjpake_ctx; /*!< EC J-PAKE key exchange */
+#if defined(MBEDTLS_SSL_CLI_C)
+ unsigned char *ecjpake_cache; /*!< Cache for ClientHello ext */
+ size_t ecjpake_cache_len; /*!< Length of cached data */
+#endif
+#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
+#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
+ defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
+ const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
+#endif
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
+ unsigned char *psk; /*!< PSK from the callback */
+ size_t psk_len; /*!< Length of PSK from callback */
+#endif
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+ mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
+#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
+ int sni_authmode; /*!< authmode from SNI callback */
+ mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
+ mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
+ mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
+#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+ unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
+ unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
+
+ unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie
+ Srv: unused */
+ unsigned char verify_cookie_len; /*!< Cli: cookie length
+ Srv: flag for sending a cookie */
+
+ unsigned char *hs_msg; /*!< Reassembled handshake message */
+
+ uint32_t retransmit_timeout; /*!< Current value of timeout */
+ unsigned char retransmit_state; /*!< Retransmission state */
+ mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
+ mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
+ unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
+ flight being received */
+ mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
+ resending messages */
+ unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter
+ for resending messages */
+#endif /* MBEDTLS_SSL_PROTO_DTLS */
+
+ /*
+ * Checksum contexts
+ */
+#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
+ defined(MBEDTLS_SSL_PROTO_TLS1_1)
+ mbedtls_md5_context fin_md5;
+ mbedtls_sha1_context fin_sha1;
+#endif
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
+#if defined(MBEDTLS_SHA256_C)
+ mbedtls_sha256_context fin_sha256;
+#endif
+#if defined(MBEDTLS_SHA512_C)
+ mbedtls_sha512_context fin_sha512;
+#endif
+#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
+
+ void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
+ void (*calc_verify)(mbedtls_ssl_context *, unsigned char *);
+ void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
+ int (*tls_prf)(const unsigned char *, size_t, const char *,
+ const unsigned char *, size_t,
+ unsigned char *, size_t);
+
+ size_t pmslen; /*!< premaster length */
+
+ unsigned char randbytes[64]; /*!< random bytes */
+ unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
+ /*!< premaster secret */
+
+ int resume; /*!< session resume indicator*/
+ int max_major_ver; /*!< max. major version client*/
+ int max_minor_ver; /*!< max. minor version client*/
+ int cli_exts; /*!< client extension presence*/
+
+#if defined(MBEDTLS_SSL_SESSION_TICKETS)
+ int new_session_ticket; /*!< use NewSessionTicket? */
+#endif /* MBEDTLS_SSL_SESSION_TICKETS */
+#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
+ int extended_ms; /*!< use Extended Master Secret? */
+#endif
+};
+
+/*
+ * This structure contains a full set of runtime transform parameters
+ * either in negotiation or active.
+ */
+struct mbedtls_ssl_transform
+{
+ /*
+ * Session specific crypto layer
+ */
+ const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
+ /*!< Chosen cipersuite_info */
+ unsigned int keylen; /*!< symmetric key length (bytes) */
+ size_t minlen; /*!< min. ciphertext length */
+ size_t ivlen; /*!< IV length */
+ size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
+ size_t maclen; /*!< MAC length */
+
+ unsigned char iv_enc[16]; /*!< IV (encryption) */
+ unsigned char iv_dec[16]; /*!< IV (decryption) */
+
+#if defined(MBEDTLS_SSL_PROTO_SSL3)
+ /* Needed only for SSL v3.0 secret */
+ unsigned char mac_enc[20]; /*!< SSL v3.0 secret (enc) */
+ unsigned char mac_dec[20]; /*!< SSL v3.0 secret (dec) */
+#endif /* MBEDTLS_SSL_PROTO_SSL3 */
+
+ mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */
+ mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */
+
+ mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
+ mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
+
+ /*
+ * Session specific compression layer
+ */
+#if defined(MBEDTLS_ZLIB_SUPPORT)
+ z_stream ctx_deflate; /*!< compression context */
+ z_stream ctx_inflate; /*!< decompression context */
+#endif
+};
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/*
+ * List of certificate + private key pairs
+ */
+struct mbedtls_ssl_key_cert
+{
+ mbedtls_x509_crt *cert; /*!< cert */
+ mbedtls_pk_context *key; /*!< private key */
+ mbedtls_ssl_key_cert *next; /*!< next key/cert pair */
+};
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+/*
+ * List of handshake messages kept around for resending
+ */
+struct mbedtls_ssl_flight_item
+{
+ unsigned char *p; /*!< message, including handshake headers */
+ size_t len; /*!< length of p */
+ unsigned char type; /*!< type of the message: handshake or CCS */
+ mbedtls_ssl_flight_item *next; /*!< next handshake message(s) */
+};
+#endif /* MBEDTLS_SSL_PROTO_DTLS */
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
+ defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
+
+/* Find an entry in a signature-hash set matching a given hash algorithm. */
+mbedtls_md_type_t mbedtls_ssl_sig_hash_set_find( mbedtls_ssl_sig_hash_set_t *set,
+ mbedtls_pk_type_t sig_alg );
+/* Add a signature-hash-pair to a signature-hash set */
+void mbedtls_ssl_sig_hash_set_add( mbedtls_ssl_sig_hash_set_t *set,
+ mbedtls_pk_type_t sig_alg,
+ mbedtls_md_type_t md_alg );
+/* Allow exactly one hash algorithm for each signature. */
+void mbedtls_ssl_sig_hash_set_const_hash( mbedtls_ssl_sig_hash_set_t *set,
+ mbedtls_md_type_t md_alg );
+
+/* Setup an empty signature-hash set */
+static inline void mbedtls_ssl_sig_hash_set_init( mbedtls_ssl_sig_hash_set_t *set )
+{
+ mbedtls_ssl_sig_hash_set_const_hash( set, MBEDTLS_MD_NONE );
+}
+
+#endif /* MBEDTLS_SSL_PROTO_TLS1_2) &&
+ MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
+
+/**
+ * \brief Free referenced items in an SSL transform context and clear
+ * memory
+ *
+ * \param transform SSL transform context
+ */
+void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform );
+
+/**
+ * \brief Free referenced items in an SSL handshake context and clear
+ * memory
+ *
+ * \param handshake SSL handshake context
+ */
+void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake );
+
+int mbedtls_ssl_handshake_client_step( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl );
+void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl );
+
+int mbedtls_ssl_send_fatal_handshake_failure( mbedtls_ssl_context *ssl );
+
+void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl );
+
+int mbedtls_ssl_read_record_layer( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl );
+void mbedtls_ssl_update_handshake_status( mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Update record layer
+ *
+ * This function roughly separates the implementation
+ * of the logic of (D)TLS from the implementation
+ * of the secure transport.
+ *
+ * \param ssl SSL context to use
+ *
+ * \return 0 or non-zero error code.
+ *
+ * \note A clarification on what is called 'record layer' here
+ * is in order, as many sensible definitions are possible:
+ *
+ * The record layer takes as input an untrusted underlying
+ * transport (stream or datagram) and transforms it into
+ * a serially multiplexed, secure transport, which
+ * conceptually provides the following:
+ *
+ * (1) Three datagram based, content-agnostic transports
+ * for handshake, alert and CCS messages.
+ * (2) One stream- or datagram-based transport
+ * for application data.
+ * (3) Functionality for changing the underlying transform
+ * securing the contents.
+ *
+ * The interface to this functionality is given as follows:
+ *
+ * a Updating
+ * [Currently implemented by mbedtls_ssl_read_record]
+ *
+ * Check if and on which of the four 'ports' data is pending:
+ * Nothing, a controlling datagram of type (1), or application
+ * data (2). In any case data is present, internal buffers
+ * provide access to the data for the user to process it.
+ * Consumption of type (1) datagrams is done automatically
+ * on the next update, invalidating that the internal buffers
+ * for previous datagrams, while consumption of application
+ * data (2) is user-controlled.
+ *
+ * b Reading of application data
+ * [Currently manual adaption of ssl->in_offt pointer]
+ *
+ * As mentioned in the last paragraph, consumption of data
+ * is different from the automatic consumption of control
+ * datagrams (1) because application data is treated as a stream.
+ *
+ * c Tracking availability of application data
+ * [Currently manually through decreasing ssl->in_msglen]
+ *
+ * For efficiency and to retain datagram semantics for
+ * application data in case of DTLS, the record layer
+ * provides functionality for checking how much application
+ * data is still available in the internal buffer.
+ *
+ * d Changing the transformation securing the communication.
+ *
+ * Given an opaque implementation of the record layer in the
+ * above sense, it should be possible to implement the logic
+ * of (D)TLS on top of it without the need to know anything
+ * about the record layer's internals. This is done e.g.
+ * in all the handshake handling functions, and in the
+ * application data reading function mbedtls_ssl_read.
+ *
+ * \note The above tries to give a conceptual picture of the
+ * record layer, but the current implementation deviates
+ * from it in some places. For example, our implementation of
+ * the update functionality through mbedtls_ssl_read_record
+ * discards datagrams depending on the current state, which
+ * wouldn't fall under the record layer's responsibility
+ * following the above definition.
+ *
+ */
+int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want );
+
+int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl );
+
+int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl );
+
+int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_write_change_cipher_spec( mbedtls_ssl_context *ssl );
+
+int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl );
+
+void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl,
+ const mbedtls_ssl_ciphersuite_t *ciphersuite_info );
+
+#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
+int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exchange_type_t key_ex );
+#endif
+
+#if defined(MBEDTLS_PK_C)
+unsigned char mbedtls_ssl_sig_from_pk( mbedtls_pk_context *pk );
+unsigned char mbedtls_ssl_sig_from_pk_alg( mbedtls_pk_type_t type );
+mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig( unsigned char sig );
+#endif
+
+mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash( unsigned char hash );
+unsigned char mbedtls_ssl_hash_from_md_alg( int md );
+int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md );
+
+#if defined(MBEDTLS_ECP_C)
+int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id );
+#endif
+
+#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
+int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl,
+ mbedtls_md_type_t md );
+#endif
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
+{
+ mbedtls_ssl_key_cert *key_cert;
+
+ if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
+ key_cert = ssl->handshake->key_cert;
+ else
+ key_cert = ssl->conf->key_cert;
+
+ return( key_cert == NULL ? NULL : key_cert->key );
+}
+
+static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl )
+{
+ mbedtls_ssl_key_cert *key_cert;
+
+ if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
+ key_cert = ssl->handshake->key_cert;
+ else
+ key_cert = ssl->conf->key_cert;
+
+ return( key_cert == NULL ? NULL : key_cert->cert );
+}
+
+/*
+ * Check usage of a certificate wrt extensions:
+ * keyUsage, extendedKeyUsage (later), and nSCertType (later).
+ *
+ * Warning: cert_endpoint is the endpoint of the cert (ie, of our peer when we
+ * check a cert we received from them)!
+ *
+ * Return 0 if everything is OK, -1 if not.
+ */
+int mbedtls_ssl_check_cert_usage( const mbedtls_x509_crt *cert,
+ const mbedtls_ssl_ciphersuite_t *ciphersuite,
+ int cert_endpoint,
+ uint32_t *flags );
+#endif /* MBEDTLS_X509_CRT_PARSE_C */
+
+void mbedtls_ssl_write_version( int major, int minor, int transport,
+ unsigned char ver[2] );
+void mbedtls_ssl_read_version( int *major, int *minor, int transport,
+ const unsigned char ver[2] );
+
+static inline size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl )
+{
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+ if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
+ return( 13 );
+#else
+ ((void) ssl);
+#endif
+ return( 5 );
+}
+
+static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl )
+{
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+ if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
+ return( 12 );
+#else
+ ((void) ssl);
+#endif
+ return( 4 );
+}
+
+#if defined(MBEDTLS_SSL_PROTO_DTLS)
+void mbedtls_ssl_send_flight_completed( mbedtls_ssl_context *ssl );
+void mbedtls_ssl_recv_flight_completed( mbedtls_ssl_context *ssl );
+int mbedtls_ssl_resend( mbedtls_ssl_context *ssl );
+#endif
+
+/* Visible for testing purposes only */
+#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
+int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl );
+void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
+#endif
+
+/* constant-time buffer comparison */
+static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
+{
+ size_t i;
+ volatile const unsigned char *A = (volatile const unsigned char *) a;
+ volatile const unsigned char *B = (volatile const unsigned char *) b;
+ volatile unsigned char diff = 0;
+
+ for( i = 0; i < n; i++ )
+ diff |= A[i] ^ B[i];
+
+ return( diff );
+}
+
+#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
+ defined(MBEDTLS_SSL_PROTO_TLS1_1)
+int mbedtls_ssl_get_key_exchange_md_ssl_tls( mbedtls_ssl_context *ssl,
+ unsigned char *output,
+ unsigned char *data, size_t data_len );
+#endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
+ MBEDTLS_SSL_PROTO_TLS1_1 */
+
+#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
+ defined(MBEDTLS_SSL_PROTO_TLS1_2)
+int mbedtls_ssl_get_key_exchange_md_tls1_2( mbedtls_ssl_context *ssl,
+ unsigned char *output,
+ unsigned char *data, size_t data_len,
+ mbedtls_md_type_t md_alg );
+#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
+ MBEDTLS_SSL_PROTO_TLS1_2 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl_internal.h */
+
+
+/********* Start of file include/mbedtls/ssl_cache.h ************/
+
+/**
+ * \file ssl_cache.h
+ *
+ * \brief SSL session cache implementation
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SSL_CACHE_H
+#define MBEDTLS_SSL_CACHE_H
+
+
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT)
+#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */
+#endif
+
+#if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES)
+#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */
+#endif
+
+/* \} name SECTION: Module settings */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct mbedtls_ssl_cache_context mbedtls_ssl_cache_context;
+typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry;
+
+/**
+ * \brief This structure is used for storing cache entries
+ */
+struct mbedtls_ssl_cache_entry
+{
+#if defined(MBEDTLS_HAVE_TIME)
+ mbedtls_time_t timestamp; /*!< entry timestamp */
+#endif
+ mbedtls_ssl_session session; /*!< entry session */
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+ mbedtls_x509_buf peer_cert; /*!< entry peer_cert */
+#endif
+ mbedtls_ssl_cache_entry *next; /*!< chain pointer */
+};
+
+/**
+ * \brief Cache context
+ */
+struct mbedtls_ssl_cache_context
+{
+ mbedtls_ssl_cache_entry *chain; /*!< start of the chain */
+ int timeout; /*!< cache entry timeout */
+ int max_entries; /*!< maximum entries */
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex; /*!< mutex */
+#endif
+};
+
+/**
+ * \brief Initialize an SSL cache context
+ *
+ * \param cache SSL cache context
+ */
+void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache );
+
+/**
+ * \brief Cache get callback implementation
+ * (Thread-safe if MBEDTLS_THREADING_C is enabled)
+ *
+ * \param data SSL cache context
+ * \param session session to retrieve entry for
+ */
+int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session );
+
+/**
+ * \brief Cache set callback implementation
+ * (Thread-safe if MBEDTLS_THREADING_C is enabled)
+ *
+ * \param data SSL cache context
+ * \param session session to store entry for
+ */
+int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session );
+
+#if defined(MBEDTLS_HAVE_TIME)
+/**
+ * \brief Set the cache timeout
+ * (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day))
+ *
+ * A timeout of 0 indicates no timeout.
+ *
+ * \param cache SSL cache context
+ * \param timeout cache entry timeout in seconds
+ */
+void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout );
+#endif /* MBEDTLS_HAVE_TIME */
+
+/**
+ * \brief Set the maximum number of cache entries
+ * (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50))
+ *
+ * \param cache SSL cache context
+ * \param max cache entry maximum
+ */
+void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max );
+
+/**
+ * \brief Free referenced items in a cache context and clear memory
+ *
+ * \param cache SSL cache context
+ */
+void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl_cache.h */
+
+
+/********* Start of file include/mbedtls/ssl_ticket.h ************/
+
+/**
+ * \file ssl_ticket.h
+ *
+ * \brief TLS server ticket callbacks implementation
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_SSL_TICKET_H
+#define MBEDTLS_SSL_TICKET_H
+
+/*
+ * This implementation of the session ticket callbacks includes key
+ * management, rotating the keys periodically in order to preserve forward
+ * secrecy, when MBEDTLS_HAVE_TIME is defined.
+ */
+
+
+
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Information for session ticket protection
+ */
+typedef struct
+{
+ unsigned char name[4]; /*!< random key identifier */
+ uint32_t generation_time; /*!< key generation timestamp (seconds) */
+ mbedtls_cipher_context_t ctx; /*!< context for auth enc/decryption */
+}
+mbedtls_ssl_ticket_key;
+
+/**
+ * \brief Context for session ticket handling functions
+ */
+typedef struct
+{
+ mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys */
+ unsigned char active; /*!< index of the currently active key */
+
+ uint32_t ticket_lifetime; /*!< lifetime of tickets in seconds */
+
+ /** Callback for getting (pseudo-)random numbers */
+ int (*f_rng)(void *, unsigned char *, size_t);
+ void *p_rng; /*!< context for the RNG function */
+
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex;
+#endif
+}
+mbedtls_ssl_ticket_context;
+
+/**
+ * \brief Initialize a ticket context.
+ * (Just make it ready for mbedtls_ssl_ticket_setup()
+ * or mbedtls_ssl_ticket_free().)
+ *
+ * \param ctx Context to be initialized
+ */
+void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
+
+/**
+ * \brief Prepare context to be actually used
+ *
+ * \param ctx Context to be set up
+ * \param f_rng RNG callback function
+ * \param p_rng RNG callback context
+ * \param cipher AEAD cipher to use for ticket protection.
+ * Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
+ * \param lifetime Tickets lifetime in seconds
+ * Recommended value: 86400 (one day).
+ *
+ * \note It is highly recommended to select a cipher that is at
+ * least as strong as the the strongest ciphersuite
+ * supported. Usually that means a 256-bit key.
+ *
+ * \note The lifetime of the keys is twice the lifetime of tickets.
+ * It is recommended to pick a reasonnable lifetime so as not
+ * to negate the benefits of forward secrecy.
+ *
+ * \return 0 if successful,
+ * or a specific MBEDTLS_ERR_XXX error code
+ */
+int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+ mbedtls_cipher_type_t cipher,
+ uint32_t lifetime );
+
+/**
+ * \brief Implementation of the ticket write callback
+ *
+ * \note See \c mbedlts_ssl_ticket_write_t for description
+ */
+mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write;
+
+/**
+ * \brief Implementation of the ticket parse callback
+ *
+ * \note See \c mbedlts_ssl_ticket_parse_t for description
+ */
+mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse;
+
+/**
+ * \brief Free a context's content and zeroize it.
+ *
+ * \param ctx Context to be cleaned up
+ */
+void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ssl_ticket.h */
+
+
+/********* Start of file include/mbedtls/debug.h ************/
+
+/**
+ * \file debug.h
+ *
+ * \brief Functions for controlling and providing debug output from the library.
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_DEBUG_H
+#define MBEDTLS_DEBUG_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+#if defined(MBEDTLS_ECP_C)
+
+#endif
+
+#if defined(MBEDTLS_DEBUG_C)
+
+#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
+
+#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
+ mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
+ MBEDTLS_DEBUG_STRIP_PARENS args )
+
+#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
+ mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
+
+#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
+ mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
+
+#if defined(MBEDTLS_BIGNUM_C)
+#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
+ mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
+#endif
+
+#if defined(MBEDTLS_ECP_C)
+#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
+ mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
+#endif
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
+ mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
+#endif
+
+#else /* MBEDTLS_DEBUG_C */
+
+#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
+#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
+#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
+#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
+#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
+#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
+
+#endif /* MBEDTLS_DEBUG_C */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Set the threshold error level to handle globally all debug output.
+ * Debug messages that have a level over the threshold value are
+ * discarded.
+ * (Default value: 0 = No debug )
+ *
+ * \param threshold theshold level of messages to filter on. Messages at a
+ * higher level will be discarded.
+ * - Debug levels
+ * - 0 No debug
+ * - 1 Error
+ * - 2 State change
+ * - 3 Informational
+ * - 4 Verbose
+ */
+void mbedtls_debug_set_threshold( int threshold );
+
+/**
+ * \brief Print a message to the debug output. This function is always used
+ * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
+ * context, file and line number parameters.
+ *
+ * \param ssl SSL context
+ * \param level error level of the debug message
+ * \param file file the message has occurred in
+ * \param line line number the message has occurred at
+ * \param format format specifier, in printf format
+ * \param ... variables used by the format specifier
+ *
+ * \attention This function is intended for INTERNAL usage within the
+ * library only.
+ */
+void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
+ const char *file, int line,
+ const char *format, ... );
+
+/**
+ * \brief Print the return value of a function to the debug output. This
+ * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
+ * which supplies the ssl context, file and line number parameters.
+ *
+ * \param ssl SSL context
+ * \param level error level of the debug message
+ * \param file file the error has occurred in
+ * \param line line number the error has occurred in
+ * \param text the name of the function that returned the error
+ * \param ret the return code value
+ *
+ * \attention This function is intended for INTERNAL usage within the
+ * library only.
+ */
+void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
+ const char *file, int line,
+ const char *text, int ret );
+
+/**
+ * \brief Output a buffer of size len bytes to the debug output. This function
+ * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
+ * which supplies the ssl context, file and line number parameters.
+ *
+ * \param ssl SSL context
+ * \param level error level of the debug message
+ * \param file file the error has occurred in
+ * \param line line number the error has occurred in
+ * \param text a name or label for the buffer being dumped. Normally the
+ * variable or buffer name
+ * \param buf the buffer to be outputted
+ * \param len length of the buffer
+ *
+ * \attention This function is intended for INTERNAL usage within the
+ * library only.
+ */
+void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
+ const char *file, int line, const char *text,
+ const unsigned char *buf, size_t len );
+
+#if defined(MBEDTLS_BIGNUM_C)
+/**
+ * \brief Print a MPI variable to the debug output. This function is always
+ * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
+ * ssl context, file and line number parameters.
+ *
+ * \param ssl SSL context
+ * \param level error level of the debug message
+ * \param file file the error has occurred in
+ * \param line line number the error has occurred in
+ * \param text a name or label for the MPI being output. Normally the
+ * variable name
+ * \param X the MPI variable
+ *
+ * \attention This function is intended for INTERNAL usage within the
+ * library only.
+ */
+void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
+ const char *file, int line,
+ const char *text, const mbedtls_mpi *X );
+#endif
+
+#if defined(MBEDTLS_ECP_C)
+/**
+ * \brief Print an ECP point to the debug output. This function is always
+ * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
+ * ssl context, file and line number parameters.
+ *
+ * \param ssl SSL context
+ * \param level error level of the debug message
+ * \param file file the error has occurred in
+ * \param line line number the error has occurred in
+ * \param text a name or label for the ECP point being output. Normally the
+ * variable name
+ * \param X the ECP point
+ *
+ * \attention This function is intended for INTERNAL usage within the
+ * library only.
+ */
+void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
+ const char *file, int line,
+ const char *text, const mbedtls_ecp_point *X );
+#endif
+
+#if defined(MBEDTLS_X509_CRT_PARSE_C)
+/**
+ * \brief Print a X.509 certificate structure to the debug output. This
+ * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
+ * which supplies the ssl context, file and line number parameters.
+ *
+ * \param ssl SSL context
+ * \param level error level of the debug message
+ * \param file file the error has occurred in
+ * \param line line number the error has occurred in
+ * \param text a name or label for the certificate being output
+ * \param crt X.509 certificate structure
+ *
+ * \attention This function is intended for INTERNAL usage within the
+ * library only.
+ */
+void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
+ const char *file, int line,
+ const char *text, const mbedtls_x509_crt *crt );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* debug.h */
+
+
+
+/********* Start of file include/mbedtls/blowfish.h ************/
+
+/**
+ * \file blowfish.h
+ *
+ * \brief Blowfish block cipher
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_BLOWFISH_H
+#define MBEDTLS_BLOWFISH_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_BLOWFISH_ENCRYPT 1
+#define MBEDTLS_BLOWFISH_DECRYPT 0
+#define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
+#define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
+#define MBEDTLS_BLOWFISH_ROUNDS 16 /**< Rounds to use. When increasing this value, make sure to extend the initialisation vectors */
+#define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
+
+#define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016 /**< Invalid key length. */
+#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 /**< Blowfish hardware accelerator failed. */
+#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */
+
+#if !defined(MBEDTLS_BLOWFISH_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Blowfish context structure
+ */
+typedef struct
+{
+ uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
+ uint32_t S[4][256]; /*!< key dependent S-boxes */
+}
+mbedtls_blowfish_context;
+
+/**
+ * \brief Initialize Blowfish context
+ *
+ * \param ctx Blowfish context to be initialized
+ */
+void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
+
+/**
+ * \brief Clear Blowfish context
+ *
+ * \param ctx Blowfish context to be cleared
+ */
+void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
+
+/**
+ * \brief Blowfish key schedule
+ *
+ * \param ctx Blowfish context to be initialized
+ * \param key encryption key
+ * \param keybits must be between 32 and 448 bits
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH
+ */
+int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief Blowfish-ECB block encryption/decryption
+ *
+ * \param ctx Blowfish context
+ * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT
+ * \param input 8-byte input block
+ * \param output 8-byte output block
+ *
+ * \return 0 if successful
+ */
+int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
+ int mode,
+ const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
+ unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
+
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
+/**
+ * \brief Blowfish-CBC buffer encryption/decryption
+ * Length should be a multiple of the block
+ * size (8 bytes)
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ * \param ctx Blowfish context
+ * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT
+ * \param length length of the input data
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH
+ */
+int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
+ int mode,
+ size_t length,
+ unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
+
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
+/**
+ * \brief Blowfish CFB buffer encryption/decryption.
+ *
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
+ * \param ctx Blowfish context
+ * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT
+ * \param length length of the input data
+ * \param iv_off offset in IV (updated after use)
+ * \param iv initialization vector (updated after use)
+ * \param input buffer holding the input data
+ * \param output buffer holding the output data
+ *
+ * \return 0 if successful
+ */
+int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
+ int mode,
+ size_t length,
+ size_t *iv_off,
+ unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /*MBEDTLS_CIPHER_MODE_CFB */
+
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
+/**
+ * \brief Blowfish-CTR buffer encryption/decryption
+ *
+ * Warning: You have to keep the maximum use of your counter in mind!
+ *
+ * \param ctx Blowfish context
+ * \param length The length of the data
+ * \param nc_off The offset in the current stream_block (for resuming
+ * within current cipher stream). The offset pointer to
+ * should be 0 at the start of a stream.
+ * \param nonce_counter The 64-bit nonce and counter.
+ * \param stream_block The saved stream-block for resuming. Is overwritten
+ * by the function.
+ * \param input The input data stream
+ * \param output The output data stream
+ *
+ * \return 0 if successful
+ */
+int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
+ size_t length,
+ size_t *nc_off,
+ unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
+ unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
+ const unsigned char *input,
+ unsigned char *output );
+#endif /* MBEDTLS_CIPHER_MODE_CTR */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_BLOWFISH_ALT */
+
+#endif /* MBEDTLS_BLOWFISH_ALT */
+
+#endif /* blowfish.h */
+
+
+/********* Start of file include/mbedtls/ccm.h ************/
+
+/**
+ * \file ccm.h
+ *
+ * \brief CCM combines Counter mode encryption with CBC-MAC authentication
+ * for 128-bit block ciphers.
+ *
+ * Input to CCM includes the following elements:
+ * - Payload - data that is both authenticated and encrypted.
+ * - Associated data (Adata) - data that is authenticated but not
+ * encrypted, For example, a header.
+ * - Nonce - A unique value that is assigned to the payload and the
+ * associated data.
+ *
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_CCM_H
+#define MBEDTLS_CCM_H
+
+
+
+#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */
+#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */
+#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */
+
+#if !defined(MBEDTLS_CCM_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The CCM context-type definition. The CCM context is passed
+ * to the APIs called.
+ */
+typedef struct {
+ mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
+}
+mbedtls_ccm_context;
+
+/**
+ * \brief This function initializes the specified CCM context,
+ * to make references valid, and prepare the context
+ * for mbedtls_ccm_setkey() or mbedtls_ccm_free().
+ *
+ * \param ctx The CCM context to initialize.
+ */
+void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
+
+/**
+ * \brief This function initializes the CCM context set in the
+ * \p ctx parameter and sets the encryption key.
+ *
+ * \param ctx The CCM context to initialize.
+ * \param cipher The 128-bit block cipher to use.
+ * \param key The encryption key.
+ * \param keybits The key size in bits. This must be acceptable by the cipher.
+ *
+ * \return \c 0 on success, or a cipher-specific error code.
+ */
+int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
+ mbedtls_cipher_id_t cipher,
+ const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief This function releases and clears the specified CCM context
+ * and underlying cipher sub-context.
+ *
+ * \param ctx The CCM context to clear.
+ */
+void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
+
+/**
+ * \brief This function encrypts a buffer using CCM.
+ *
+ * \param ctx The CCM context to use for encryption.
+ * \param length The length of the input data in Bytes.
+ * \param iv Initialization vector (nonce).
+ * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13.
+ * \param add The additional data field.
+ * \param add_len The length of additional data in Bytes.
+ * Must be less than 2^16 - 2^8.
+ * \param input The buffer holding the input data.
+ * \param output The buffer holding the output data.
+ * Must be at least \p length Bytes wide.
+ * \param tag The buffer holding the tag.
+ * \param tag_len The length of the tag to generate in Bytes:
+ * 4, 6, 8, 10, 12, 14 or 16.
+ *
+ * \note The tag is written to a separate buffer. To concatenate
+ * the \p tag with the \p output, as done in RFC-3610:
+ * Counter with CBC-MAC (CCM), use
+ * \p tag = \p output + \p length, and make sure that the
+ * output buffer is at least \p length + \p tag_len wide.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *add, size_t add_len,
+ const unsigned char *input, unsigned char *output,
+ unsigned char *tag, size_t tag_len );
+
+/**
+ * \brief This function performs a CCM authenticated decryption of a
+ * buffer.
+ *
+ * \param ctx The CCM context to use for decryption.
+ * \param length The length of the input data in Bytes.
+ * \param iv Initialization vector.
+ * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13.
+ * \param add The additional data field.
+ * \param add_len The length of additional data in Bytes.
+ * Must be less than 2^16 - 2^8.
+ * \param input The buffer holding the input data.
+ * \param output The buffer holding the output data.
+ * Must be at least \p length Bytes wide.
+ * \param tag The buffer holding the tag.
+ * \param tag_len The length of the tag in Bytes.
+ * 4, 6, 8, 10, 12, 14 or 16.
+ *
+ * \return 0 if successful and authenticated, or
+ * #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
+ */
+int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
+ const unsigned char *iv, size_t iv_len,
+ const unsigned char *add, size_t add_len,
+ const unsigned char *input, unsigned char *output,
+ const unsigned char *tag, size_t tag_len );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_CCM_ALT */
+
+#endif /* MBEDTLS_CCM_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
+/**
+ * \brief The CCM checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_ccm_self_test( int verbose );
+#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_CCM_H */
+
+
+/********* Start of file include/mbedtls/gcm.h ************/
+
+/**
+ * \file gcm.h
+ *
+ * \brief Galois/Counter Mode (GCM) for 128-bit block ciphers, as defined
+ * in D. McGrew, J. Viega, The Galois/Counter Mode of Operation
+ * (GCM), Natl. Inst. Stand. Technol.
+ *
+ * For more information on GCM, see NIST SP 800-38D: Recommendation for
+ * Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC.
+ *
+ */
+/*
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_GCM_H
+#define MBEDTLS_GCM_H
+
+
+
+#include
+
+#define MBEDTLS_GCM_ENCRYPT 1
+#define MBEDTLS_GCM_DECRYPT 0
+
+#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */
+#define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */
+#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */
+
+#if !defined(MBEDTLS_GCM_ALT)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The GCM context structure.
+ */
+typedef struct {
+ mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
+ uint64_t HL[16]; /*!< Precalculated HTable low. */
+ uint64_t HH[16]; /*!< Precalculated HTable high. */
+ uint64_t len; /*!< The total length of the encrypted data. */
+ uint64_t add_len; /*!< The total length of the additional data. */
+ unsigned char base_ectr[16]; /*!< The first ECTR for tag. */
+ unsigned char y[16]; /*!< The Y working value. */
+ unsigned char buf[16]; /*!< The buf working value. */
+ int mode; /*!< The operation to perform:
+ #MBEDTLS_GCM_ENCRYPT or
+ #MBEDTLS_GCM_DECRYPT. */
+}
+mbedtls_gcm_context;
+
+/**
+ * \brief This function initializes the specified GCM context,
+ * to make references valid, and prepares the context
+ * for mbedtls_gcm_setkey() or mbedtls_gcm_free().
+ *
+ * The function does not bind the GCM context to a particular
+ * cipher, nor set the key. For this purpose, use
+ * mbedtls_gcm_setkey().
+ *
+ * \param ctx The GCM context to initialize.
+ */
+void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
+
+/**
+ * \brief This function associates a GCM context with a
+ * cipher algorithm and a key.
+ *
+ * \param ctx The GCM context to initialize.
+ * \param cipher The 128-bit block cipher to use.
+ * \param key The encryption key.
+ * \param keybits The key size in bits. Valid options are:
+ * - 128 bits
+ * - 192 bits
+ * - 256 bits
+ *
+ * \return \c 0 on success, or a cipher specific error code.
+ */
+int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
+ mbedtls_cipher_id_t cipher,
+ const unsigned char *key,
+ unsigned int keybits );
+
+/**
+ * \brief This function performs GCM encryption or decryption of a buffer.
+ *
+ * \note For encryption, the output buffer can be the same as the input buffer.
+ * For decryption, the output buffer cannot be the same as input buffer.
+ * If the buffers overlap, the output buffer must trail at least 8 Bytes
+ * behind the input buffer.
+ *
+ * \param ctx The GCM context to use for encryption or decryption.
+ * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or
+ * #MBEDTLS_GCM_DECRYPT.
+ * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish().
+ * \param iv The initialization vector.
+ * \param iv_len The length of the IV.
+ * \param add The buffer holding the additional data.
+ * \param add_len The length of the additional data.
+ * \param input The buffer holding the input data.
+ * \param output The buffer for holding the output data.
+ * \param tag_len The length of the tag to generate.
+ * \param tag The buffer for holding the tag.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
+ int mode,
+ size_t length,
+ const unsigned char *iv,
+ size_t iv_len,
+ const unsigned char *add,
+ size_t add_len,
+ const unsigned char *input,
+ unsigned char *output,
+ size_t tag_len,
+ unsigned char *tag );
+
+/**
+ * \brief This function performs a GCM authenticated decryption of a
+ * buffer.
+ *
+ * \note For decryption, the output buffer cannot be the same as input buffer.
+ * If the buffers overlap, the output buffer must trail at least 8 Bytes
+ * behind the input buffer.
+ *
+ * \param ctx The GCM context.
+ * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish().
+ * \param iv The initialization vector.
+ * \param iv_len The length of the IV.
+ * \param add The buffer holding the additional data.
+ * \param add_len The length of the additional data.
+ * \param tag The buffer holding the tag.
+ * \param tag_len The length of the tag.
+ * \param input The buffer holding the input data.
+ * \param output The buffer for holding the output data.
+ *
+ * \return 0 if successful and authenticated, or
+ * #MBEDTLS_ERR_GCM_AUTH_FAILED if tag does not match.
+ */
+int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
+ size_t length,
+ const unsigned char *iv,
+ size_t iv_len,
+ const unsigned char *add,
+ size_t add_len,
+ const unsigned char *tag,
+ size_t tag_len,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function starts a GCM encryption or decryption
+ * operation.
+ *
+ * \param ctx The GCM context.
+ * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or
+ * #MBEDTLS_GCM_DECRYPT.
+ * \param iv The initialization vector.
+ * \param iv_len The length of the IV.
+ * \param add The buffer holding the additional data, or NULL if \p add_len is 0.
+ * \param add_len The length of the additional data. If 0, \p add is NULL.
+ *
+ * \return \c 0 on success.
+ */
+int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
+ int mode,
+ const unsigned char *iv,
+ size_t iv_len,
+ const unsigned char *add,
+ size_t add_len );
+
+/**
+ * \brief This function feeds an input buffer into an ongoing GCM
+ * encryption or decryption operation.
+ *
+ * ` The function expects input to be a multiple of 16
+ * Bytes. Only the last call before calling
+ * mbedtls_gcm_finish() can be less than 16 Bytes.
+ *
+ * \note For decryption, the output buffer cannot be the same as input buffer.
+ * If the buffers overlap, the output buffer must trail at least 8 Bytes
+ * behind the input buffer.
+ *
+ * \param ctx The GCM context.
+ * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish().
+ * \param input The buffer holding the input data.
+ * \param output The buffer for holding the output data.
+ *
+ * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
+ */
+int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
+ size_t length,
+ const unsigned char *input,
+ unsigned char *output );
+
+/**
+ * \brief This function finishes the GCM operation and generates
+ * the authentication tag.
+ *
+ * It wraps up the GCM stream, and generates the
+ * tag. The tag can have a maximum length of 16 Bytes.
+ *
+ * \param ctx The GCM context.
+ * \param tag The buffer for holding the tag.
+ * \param tag_len The length of the tag to generate. Must be at least four.
+ *
+ * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
+ */
+int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
+ unsigned char *tag,
+ size_t tag_len );
+
+/**
+ * \brief This function clears a GCM context and the underlying
+ * cipher sub-context.
+ *
+ * \param ctx The GCM context to clear.
+ */
+void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* !MBEDTLS_GCM_ALT */
+
+#endif /* !MBEDTLS_GCM_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The GCM checkup routine.
+ *
+ * \return \c 0 on success, or \c 1 on failure.
+ */
+int mbedtls_gcm_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* gcm.h */
+
+
+/********* Start of file include/mbedtls/pem.h ************/
+
+/**
+ * \file pem.h
+ *
+ * \brief Privacy Enhanced Mail (PEM) decoding
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PEM_H
+#define MBEDTLS_PEM_H
+
+#include
+
+/**
+ * \name PEM Error codes
+ * These error codes are returned in case of errors reading the
+ * PEM data.
+ * \{
+ */
+#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */
+#define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */
+#define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 /**< Failed to allocate memory. */
+#define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */
+#define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */
+#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */
+#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */
+#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */
+#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */
+/* \} name */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(MBEDTLS_PEM_PARSE_C)
+/**
+ * \brief PEM context structure
+ */
+typedef struct
+{
+ unsigned char *buf; /*!< buffer for decoded data */
+ size_t buflen; /*!< length of the buffer */
+ unsigned char *info; /*!< buffer for extra header information */
+}
+mbedtls_pem_context;
+
+/**
+ * \brief PEM context setup
+ *
+ * \param ctx context to be initialized
+ */
+void mbedtls_pem_init( mbedtls_pem_context *ctx );
+
+/**
+ * \brief Read a buffer for PEM information and store the resulting
+ * data into the specified context buffers.
+ *
+ * \param ctx context to use
+ * \param header header string to seek and expect
+ * \param footer footer string to seek and expect
+ * \param data source data to look in (must be nul-terminated)
+ * \param pwd password for decryption (can be NULL)
+ * \param pwdlen length of password
+ * \param use_len destination for total length used (set after header is
+ * correctly read, so unless you get
+ * MBEDTLS_ERR_PEM_BAD_INPUT_DATA or
+ * MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is
+ * the length to skip)
+ *
+ * \note Attempts to check password correctness by verifying if
+ * the decrypted text starts with an ASN.1 sequence of
+ * appropriate length
+ *
+ * \return 0 on success, or a specific PEM error code
+ */
+int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
+ const unsigned char *data,
+ const unsigned char *pwd,
+ size_t pwdlen, size_t *use_len );
+
+/**
+ * \brief PEM context memory freeing
+ *
+ * \param ctx context to be freed
+ */
+void mbedtls_pem_free( mbedtls_pem_context *ctx );
+#endif /* MBEDTLS_PEM_PARSE_C */
+
+#if defined(MBEDTLS_PEM_WRITE_C)
+/**
+ * \brief Write a buffer of PEM information from a DER encoded
+ * buffer.
+ *
+ * \param header header string to write
+ * \param footer footer string to write
+ * \param der_data DER data to write
+ * \param der_len length of the DER data
+ * \param buf buffer to write to
+ * \param buf_len length of output buffer
+ * \param olen total length written / required (if buf_len is not enough)
+ *
+ * \return 0 on success, or a specific PEM or BASE64 error code. On
+ * MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL olen is the required
+ * size.
+ */
+int mbedtls_pem_write_buffer( const char *header, const char *footer,
+ const unsigned char *der_data, size_t der_len,
+ unsigned char *buf, size_t buf_len, size_t *olen );
+#endif /* MBEDTLS_PEM_WRITE_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* pem.h */
+
+
+/********* Start of file include/mbedtls/asn1write.h ************/
+
+/**
+ * \file asn1write.h
+ *
+ * \brief ASN.1 buffer writing functionality
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_ASN1_WRITE_H
+#define MBEDTLS_ASN1_WRITE_H
+
+
+
+#define MBEDTLS_ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \
+ g += ret; } while( 0 )
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Write a length field in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param len the length to write
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len );
+
+/**
+ * \brief Write a ASN.1 tag in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param tag the tag to write
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
+ unsigned char tag );
+
+/**
+ * \brief Write raw buffer data
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param buf data buffer to write
+ * \param size length of the data buffer
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
+ const unsigned char *buf, size_t size );
+
+#if defined(MBEDTLS_BIGNUM_C)
+/**
+ * \brief Write a big number (MBEDTLS_ASN1_INTEGER) in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param X the MPI to write
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedtls_mpi *X );
+#endif /* MBEDTLS_BIGNUM_C */
+
+/**
+ * \brief Write a NULL tag (MBEDTLS_ASN1_NULL) with zero data in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
+
+/**
+ * \brief Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param oid the OID to write
+ * \param oid_len length of the OID
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
+ const char *oid, size_t oid_len );
+
+/**
+ * \brief Write an AlgorithmIdentifier sequence in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param oid the OID of the algorithm
+ * \param oid_len length of the OID
+ * \param par_len length of parameters, which must be already written.
+ * If 0, NULL parameters are added
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
+ const char *oid, size_t oid_len,
+ size_t par_len );
+
+/**
+ * \brief Write a boolean tag (MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param boolean 0 or 1
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolean );
+
+/**
+ * \brief Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param val the integer value
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
+
+/**
+ * \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and
+ * value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param text the text to write
+ * \param text_len length of the text
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start,
+ const char *text, size_t text_len );
+
+/**
+ * \brief Write an IA5 string tag (MBEDTLS_ASN1_IA5_STRING) and
+ * value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param text the text to write
+ * \param text_len length of the text
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
+ const char *text, size_t text_len );
+
+/**
+ * \brief Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and
+ * value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param buf the bitstring
+ * \param bits the total number of bits in the bitstring
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
+ const unsigned char *buf, size_t bits );
+
+/**
+ * \brief Write an octet string tag (MBEDTLS_ASN1_OCTET_STRING) and
+ * value in ASN.1 format
+ * Note: function works backwards in data buffer
+ *
+ * \param p reference to current position pointer
+ * \param start start of the buffer (for bounds-checking)
+ * \param buf data buffer to write
+ * \param size length of the data buffer
+ *
+ * \return the length written or a negative error code
+ */
+int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
+ const unsigned char *buf, size_t size );
+
+/**
+ * \brief Create or find a specific named_data entry for writing in a
+ * sequence or list based on the OID. If not already in there,
+ * a new entry is added to the head of the list.
+ * Warning: Destructive behaviour for the val data!
+ *
+ * \param list Pointer to the location of the head of the list to seek
+ * through (will be updated in case of a new entry)
+ * \param oid The OID to look for
+ * \param oid_len Size of the OID
+ * \param val Data to store (can be NULL if you want to fill it by hand)
+ * \param val_len Minimum length of the data buffer needed
+ *
+ * \return NULL if if there was a memory allocation error, or a pointer
+ * to the new / existing entry.
+ */
+mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
+ const char *oid, size_t oid_len,
+ const unsigned char *val,
+ size_t val_len );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_ASN1_WRITE_H */
+
+
+/********* Start of file include/mbedtls/hmac_drbg.h ************/
+
+/**
+ * \file hmac_drbg.h
+ *
+ * \brief HMAC_DRBG (NIST SP 800-90A)
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_HMAC_DRBG_H
+#define MBEDTLS_HMAC_DRBG_H
+
+
+
+#if defined(MBEDTLS_THREADING_C)
+
+#endif
+
+/*
+ * Error codes
+ */
+#define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 /**< Too many random requested in single call. */
+#define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 /**< Input too large (Entropy + additional). */
+#define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 /**< Read/write error in file. */
+#define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /**< The entropy source failed. */
+
+/**
+ * \name SECTION: Module settings
+ *
+ * The configuration options you can set for this module are in this section.
+ * Either change them in config.h or define them on the compiler command line.
+ * \{
+ */
+
+#if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
+#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
+#endif
+
+#if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
+#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
+#endif
+
+#if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
+#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
+#endif
+
+#if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
+#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
+#endif
+
+/* \} name SECTION: Module settings */
+
+#define MBEDTLS_HMAC_DRBG_PR_OFF 0 /**< No prediction resistance */
+#define MBEDTLS_HMAC_DRBG_PR_ON 1 /**< Prediction resistance enabled */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * HMAC_DRBG context.
+ */
+typedef struct
+{
+ /* Working state: the key K is not stored explicitely,
+ * but is implied by the HMAC context */
+ mbedtls_md_context_t md_ctx; /*!< HMAC context (inc. K) */
+ unsigned char V[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
+ int reseed_counter; /*!< reseed counter */
+
+ /* Administrative state */
+ size_t entropy_len; /*!< entropy bytes grabbed on each (re)seed */
+ int prediction_resistance; /*!< enable prediction resistance (Automatic
+ reseed before every random generation) */
+ int reseed_interval; /*!< reseed interval */
+
+ /* Callbacks */
+ int (*f_entropy)(void *, unsigned char *, size_t); /*!< entropy function */
+ void *p_entropy; /*!< context for the entropy function */
+
+#if defined(MBEDTLS_THREADING_C)
+ mbedtls_threading_mutex_t mutex;
+#endif
+} mbedtls_hmac_drbg_context;
+
+/**
+ * \brief HMAC_DRBG context initialization
+ * Makes the context ready for mbedtls_hmac_drbg_seed(),
+ * mbedtls_hmac_drbg_seed_buf() or
+ * mbedtls_hmac_drbg_free().
+ *
+ * \param ctx HMAC_DRBG context to be initialized
+ */
+void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
+
+/**
+ * \brief HMAC_DRBG initial seeding
+ * Seed and setup entropy source for future reseeds.
+ *
+ * \param ctx HMAC_DRBG context to be seeded
+ * \param md_info MD algorithm to use for HMAC_DRBG
+ * \param f_entropy Entropy callback (p_entropy, buffer to fill, buffer
+ * length)
+ * \param p_entropy Entropy context
+ * \param custom Personalization data (Device specific identifiers)
+ * (Can be NULL)
+ * \param len Length of personalization data
+ *
+ * \note The "security strength" as defined by NIST is set to:
+ * 128 bits if md_alg is SHA-1,
+ * 192 bits if md_alg is SHA-224,
+ * 256 bits if md_alg is SHA-256 or higher.
+ * Note that SHA-256 is just as efficient as SHA-224.
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
+ * MBEDTLS_ERR_MD_ALLOC_FAILED, or
+ * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED.
+ */
+int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
+ const mbedtls_md_info_t * md_info,
+ int (*f_entropy)(void *, unsigned char *, size_t),
+ void *p_entropy,
+ const unsigned char *custom,
+ size_t len );
+
+/**
+ * \brief Initilisation of simpified HMAC_DRBG (never reseeds).
+ * (For use with deterministic ECDSA.)
+ *
+ * \param ctx HMAC_DRBG context to be initialised
+ * \param md_info MD algorithm to use for HMAC_DRBG
+ * \param data Concatenation of entropy string and additional data
+ * \param data_len Length of data in bytes
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
+ * MBEDTLS_ERR_MD_ALLOC_FAILED.
+ */
+int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
+ const mbedtls_md_info_t * md_info,
+ const unsigned char *data, size_t data_len );
+
+/**
+ * \brief Enable / disable prediction resistance (Default: Off)
+ *
+ * Note: If enabled, entropy is used for ctx->entropy_len before each call!
+ * Only use this if you have ample supply of good entropy!
+ *
+ * \param ctx HMAC_DRBG context
+ * \param resistance MBEDTLS_HMAC_DRBG_PR_ON or MBEDTLS_HMAC_DRBG_PR_OFF
+ */
+void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
+ int resistance );
+
+/**
+ * \brief Set the amount of entropy grabbed on each reseed
+ * (Default: given by the security strength, which
+ * depends on the hash used, see \c mbedtls_hmac_drbg_init() )
+ *
+ * \param ctx HMAC_DRBG context
+ * \param len Amount of entropy to grab, in bytes
+ */
+void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
+ size_t len );
+
+/**
+ * \brief Set the reseed interval
+ * (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
+ *
+ * \param ctx HMAC_DRBG context
+ * \param interval Reseed interval
+ */
+void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
+ int interval );
+
+/**
+ * \brief HMAC_DRBG update state
+ *
+ * \param ctx HMAC_DRBG context
+ * \param additional Additional data to update state with, or NULL
+ * \param add_len Length of additional data, or 0
+ *
+ * \note Additional data is optional, pass NULL and 0 as second
+ * third argument if no additional data is being used.
+ */
+void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
+ const unsigned char *additional, size_t add_len );
+
+/**
+ * \brief HMAC_DRBG reseeding (extracts data from entropy source)
+ *
+ * \param ctx HMAC_DRBG context
+ * \param additional Additional data to add to state (Can be NULL)
+ * \param len Length of additional data
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
+ */
+int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
+ const unsigned char *additional, size_t len );
+
+/**
+ * \brief HMAC_DRBG generate random with additional update input
+ *
+ * Note: Automatically reseeds if reseed_counter is reached or PR is enabled.
+ *
+ * \param p_rng HMAC_DRBG context
+ * \param output Buffer to fill
+ * \param output_len Length of the buffer
+ * \param additional Additional data to update with (can be NULL)
+ * \param add_len Length of additional data (can be 0)
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
+ * MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG, or
+ * MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG.
+ */
+int mbedtls_hmac_drbg_random_with_add( void *p_rng,
+ unsigned char *output, size_t output_len,
+ const unsigned char *additional,
+ size_t add_len );
+
+/**
+ * \brief HMAC_DRBG generate random
+ *
+ * Note: Automatically reseeds if reseed_counter is reached or PR is enabled.
+ *
+ * \param p_rng HMAC_DRBG context
+ * \param output Buffer to fill
+ * \param out_len Length of the buffer
+ *
+ * \return 0 if successful, or
+ * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
+ * MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG
+ */
+int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
+
+/**
+ * \brief Free an HMAC_DRBG context
+ *
+ * \param ctx HMAC_DRBG context to free.
+ */
+void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
+
+#if defined(MBEDTLS_FS_IO)
+/**
+ * \brief Write a seed file
+ *
+ * \param ctx HMAC_DRBG context
+ * \param path Name of the file
+ *
+ * \return 0 if successful, 1 on file error, or
+ * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
+ */
+int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
+
+/**
+ * \brief Read and update a seed file. Seed is added to this
+ * instance
+ *
+ * \param ctx HMAC_DRBG context
+ * \param path Name of the file
+ *
+ * \return 0 if successful, 1 on file error,
+ * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED or
+ * MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG
+ */
+int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
+#endif /* MBEDTLS_FS_IO */
+
+
+#if defined(MBEDTLS_SELF_TEST)
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_hmac_drbg_self_test( int verbose );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* hmac_drbg.h */
+
+
+/********* Start of file include/mbedtls/pkcs12.h ************/
+
+/**
+ * \file pkcs12.h
+ *
+ * \brief PKCS#12 Personal Information Exchange Syntax
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PKCS12_H
+#define MBEDTLS_PKCS12_H
+
+
+
+
+
+#include
+
+#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
+#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
+#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
+
+#define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
+#define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */
+#define MBEDTLS_PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
+
+#define MBEDTLS_PKCS12_PBE_DECRYPT 0
+#define MBEDTLS_PKCS12_PBE_ENCRYPT 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief PKCS12 Password Based function (encryption / decryption)
+ * for pbeWithSHAAnd128BitRC4
+ *
+ * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
+ * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
+ * \param pwd the password used (may be NULL if no password is used)
+ * \param pwdlen length of the password (may be 0)
+ * \param input the input data
+ * \param len data length
+ * \param output the output buffer
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_XXX code
+ */
+int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
+ const unsigned char *pwd, size_t pwdlen,
+ const unsigned char *input, size_t len,
+ unsigned char *output );
+
+/**
+ * \brief PKCS12 Password Based function (encryption / decryption)
+ * for cipher-based and mbedtls_md-based PBE's
+ *
+ * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
+ * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
+ * \param cipher_type the cipher used
+ * \param md_type the mbedtls_md used
+ * \param pwd the password used (may be NULL if no password is used)
+ * \param pwdlen length of the password (may be 0)
+ * \param input the input data
+ * \param len data length
+ * \param output the output buffer
+ *
+ * \return 0 if successful, or a MBEDTLS_ERR_XXX code
+ */
+int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
+ mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type,
+ const unsigned char *pwd, size_t pwdlen,
+ const unsigned char *input, size_t len,
+ unsigned char *output );
+
+/**
+ * \brief The PKCS#12 derivation function uses a password and a salt
+ * to produce pseudo-random bits for a particular "purpose".
+ *
+ * Depending on the given id, this function can produce an
+ * encryption/decryption key, an nitialization vector or an
+ * integrity key.
+ *
+ * \param data buffer to store the derived data in
+ * \param datalen length to fill
+ * \param pwd password to use (may be NULL if no password is used)
+ * \param pwdlen length of the password (may be 0)
+ * \param salt salt buffer to use
+ * \param saltlen length of the salt
+ * \param mbedtls_md mbedtls_md type to use during the derivation
+ * \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY,
+ * MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY)
+ * \param iterations number of iterations
+ *
+ * \return 0 if successful, or a MD, BIGNUM type error.
+ */
+int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
+ const unsigned char *pwd, size_t pwdlen,
+ const unsigned char *salt, size_t saltlen,
+ mbedtls_md_type_t mbedtls_md, int id, int iterations );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* pkcs12.h */
+
+
+/********* Start of file include/mbedtls/pkcs11.h ************/
+
+/**
+ * \file pkcs11.h
+ *
+ * \brief Wrapper for PKCS#11 library libpkcs11-helper
+ *
+ * \author Adriaan de Jong
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PKCS11_H
+#define MBEDTLS_PKCS11_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#if defined(MBEDTLS_PKCS11_C)
+
+
+
+#include
+
+#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
+ !defined(inline) && !defined(__cplusplus)
+#define inline __inline
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Context for PKCS #11 private keys.
+ */
+typedef struct {
+ pkcs11h_certificate_t pkcs11h_cert;
+ int len;
+} mbedtls_pkcs11_context;
+
+/**
+ * Initialize a mbedtls_pkcs11_context.
+ * (Just making memory references valid.)
+ */
+void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
+
+/**
+ * Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
+ *
+ * \param cert X.509 certificate to fill
+ * \param pkcs11h_cert PKCS #11 helper certificate
+ *
+ * \return 0 on success.
+ */
+int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
+
+/**
+ * Set up a mbedtls_pkcs11_context storing the given certificate. Note that the
+ * mbedtls_pkcs11_context will take over control of the certificate, freeing it when
+ * done.
+ *
+ * \param priv_key Private key structure to fill.
+ * \param pkcs11_cert PKCS #11 helper certificate
+ *
+ * \return 0 on success
+ */
+int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
+ pkcs11h_certificate_t pkcs11_cert );
+
+/**
+ * Free the contents of the given private key context. Note that the structure
+ * itself is not freed.
+ *
+ * \param priv_key Private key structure to cleanup
+ */
+void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
+
+/**
+ * \brief Do an RSA private key decrypt, then remove the message
+ * padding
+ *
+ * \param ctx PKCS #11 context
+ * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
+ * \param input buffer holding the encrypted data
+ * \param output buffer that will hold the plaintext
+ * \param olen will contain the plaintext length
+ * \param output_max_len maximum length of the output buffer
+ *
+ * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
+ *
+ * \note The output buffer must be as large as the size
+ * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
+ * an error is thrown.
+ */
+int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
+ int mode, size_t *olen,
+ const unsigned char *input,
+ unsigned char *output,
+ size_t output_max_len );
+
+/**
+ * \brief Do a private RSA to sign a message digest
+ *
+ * \param ctx PKCS #11 context
+ * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
+ * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
+ * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
+ * \param hash buffer holding the message digest
+ * \param sig buffer that will hold the ciphertext
+ *
+ * \return 0 if the signing operation was successful,
+ * or an MBEDTLS_ERR_RSA_XXX error code
+ *
+ * \note The "sig" buffer must be as large as the size
+ * of ctx->N (eg. 128 bytes if RSA-1024 is used).
+ */
+int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
+ int mode,
+ mbedtls_md_type_t md_alg,
+ unsigned int hashlen,
+ const unsigned char *hash,
+ unsigned char *sig );
+
+/**
+ * SSL/TLS wrappers for PKCS#11 functions
+ */
+static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
+ const unsigned char *input, unsigned char *output,
+ size_t output_max_len )
+{
+ return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
+ output_max_len );
+}
+
+static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
+ int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
+ const unsigned char *hash, unsigned char *sig )
+{
+ ((void) f_rng);
+ ((void) p_rng);
+ return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
+ hashlen, hash, sig );
+}
+
+static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
+{
+ return ( (mbedtls_pkcs11_context *) ctx )->len;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_PKCS11_C */
+
+#endif /* MBEDTLS_PKCS11_H */
+
+
+/********* Start of file include/mbedtls/pkcs5.h ************/
+
+/**
+ * \file pkcs5.h
+ *
+ * \brief PKCS#5 functions
+ *
+ * \author Mathias Olsson
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_PKCS5_H
+#define MBEDTLS_PKCS5_H
+
+
+
+
+#include
+#include
+
+#define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */
+#define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */
+#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */
+
+#define MBEDTLS_PKCS5_DECRYPT 0
+#define MBEDTLS_PKCS5_ENCRYPT 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief PKCS#5 PBES2 function
+ *
+ * \param pbe_params the ASN.1 algorithm parameters
+ * \param mode either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT
+ * \param pwd password to use when generating key
+ * \param pwdlen length of password
+ * \param data data to process
+ * \param datalen length of data
+ * \param output output buffer
+ *
+ * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
+ */
+int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
+ const unsigned char *pwd, size_t pwdlen,
+ const unsigned char *data, size_t datalen,
+ unsigned char *output );
+
+/**
+ * \brief PKCS#5 PBKDF2 using HMAC
+ *
+ * \param ctx Generic HMAC context
+ * \param password Password to use when generating key
+ * \param plen Length of password
+ * \param salt Salt to use when generating key
+ * \param slen Length of salt
+ * \param iteration_count Iteration count
+ * \param key_length Length of generated key in bytes
+ * \param output Generated key. Must be at least as big as key_length
+ *
+ * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
+ */
+int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password,
+ size_t plen, const unsigned char *salt, size_t slen,
+ unsigned int iteration_count,
+ uint32_t key_length, unsigned char *output );
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_pkcs5_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* pkcs5.h */
+
+
+/********* Start of file include/mbedtls/oid.h ************/
+
+/**
+ * \file oid.h
+ *
+ * \brief Object Identifier (OID) database
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_OID_H
+#define MBEDTLS_OID_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+
+
+
+#include
+
+#if defined(MBEDTLS_CIPHER_C)
+
+#endif
+
+#if defined(MBEDTLS_MD_C)
+
+#endif
+
+#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
+
+#endif
+
+#define MBEDTLS_ERR_OID_NOT_FOUND -0x002E /**< OID is not found. */
+#define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B /**< output buffer is too small */
+
+/*
+ * Top level OID tuples
+ */
+#define MBEDTLS_OID_ISO_MEMBER_BODIES "\x2a" /* {iso(1) member-body(2)} */
+#define MBEDTLS_OID_ISO_IDENTIFIED_ORG "\x2b" /* {iso(1) identified-organization(3)} */
+#define MBEDTLS_OID_ISO_CCITT_DS "\x55" /* {joint-iso-ccitt(2) ds(5)} */
+#define MBEDTLS_OID_ISO_ITU_COUNTRY "\x60" /* {joint-iso-itu-t(2) country(16)} */
+
+/*
+ * ISO Member bodies OID parts
+ */
+#define MBEDTLS_OID_COUNTRY_US "\x86\x48" /* {us(840)} */
+#define MBEDTLS_OID_ORG_RSA_DATA_SECURITY "\x86\xf7\x0d" /* {rsadsi(113549)} */
+#define MBEDTLS_OID_RSA_COMPANY MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \
+ MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) rsadsi(113549)} */
+#define MBEDTLS_OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */
+#define MBEDTLS_OID_ANSI_X9_62 MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \
+ MBEDTLS_OID_ORG_ANSI_X9_62
+
+/*
+ * ISO Identified organization OID parts
+ */
+#define MBEDTLS_OID_ORG_DOD "\x06" /* {dod(6)} */
+#define MBEDTLS_OID_ORG_OIW "\x0e"
+#define MBEDTLS_OID_OIW_SECSIG MBEDTLS_OID_ORG_OIW "\x03"
+#define MBEDTLS_OID_OIW_SECSIG_ALG MBEDTLS_OID_OIW_SECSIG "\x02"
+#define MBEDTLS_OID_OIW_SECSIG_SHA1 MBEDTLS_OID_OIW_SECSIG_ALG "\x1a"
+#define MBEDTLS_OID_ORG_CERTICOM "\x81\x04" /* certicom(132) */
+#define MBEDTLS_OID_CERTICOM MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_CERTICOM
+#define MBEDTLS_OID_ORG_TELETRUST "\x24" /* teletrust(36) */
+#define MBEDTLS_OID_TELETRUST MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_TELETRUST
+
+/*
+ * ISO ITU OID parts
+ */
+#define MBEDTLS_OID_ORGANIZATION "\x01" /* {organization(1)} */
+#define MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ISO_ITU_COUNTRY MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORGANIZATION /* {joint-iso-itu-t(2) country(16) us(840) organization(1)} */
+
+#define MBEDTLS_OID_ORG_GOV "\x65" /* {gov(101)} */
+#define MBEDTLS_OID_GOV MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_GOV /* {joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)} */
+
+#define MBEDTLS_OID_ORG_NETSCAPE "\x86\xF8\x42" /* {netscape(113730)} */
+#define MBEDTLS_OID_NETSCAPE MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_NETSCAPE /* Netscape OID {joint-iso-itu-t(2) country(16) us(840) organization(1) netscape(113730)} */
+
+/* ISO arc for standard certificate and CRL extensions */
+#define MBEDTLS_OID_ID_CE MBEDTLS_OID_ISO_CCITT_DS "\x1D" /**< id-ce OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 29} */
+
+/**
+ * Private Internet Extensions
+ * { iso(1) identified-organization(3) dod(6) internet(1)
+ * security(5) mechanisms(5) pkix(7) }
+ */
+#define MBEDTLS_OID_PKIX MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01\x05\x05\x07"
+
+/*
+ * Arc for standard naming attributes
+ */
+#define MBEDTLS_OID_AT MBEDTLS_OID_ISO_CCITT_DS "\x04" /**< id-at OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 4} */
+#define MBEDTLS_OID_AT_CN MBEDTLS_OID_AT "\x03" /**< id-at-commonName AttributeType:= {id-at 3} */
+#define MBEDTLS_OID_AT_SUR_NAME MBEDTLS_OID_AT "\x04" /**< id-at-surName AttributeType:= {id-at 4} */
+#define MBEDTLS_OID_AT_SERIAL_NUMBER MBEDTLS_OID_AT "\x05" /**< id-at-serialNumber AttributeType:= {id-at 5} */
+#define MBEDTLS_OID_AT_COUNTRY MBEDTLS_OID_AT "\x06" /**< id-at-countryName AttributeType:= {id-at 6} */
+#define MBEDTLS_OID_AT_LOCALITY MBEDTLS_OID_AT "\x07" /**< id-at-locality AttributeType:= {id-at 7} */
+#define MBEDTLS_OID_AT_STATE MBEDTLS_OID_AT "\x08" /**< id-at-state AttributeType:= {id-at 8} */
+#define MBEDTLS_OID_AT_ORGANIZATION MBEDTLS_OID_AT "\x0A" /**< id-at-organizationName AttributeType:= {id-at 10} */
+#define MBEDTLS_OID_AT_ORG_UNIT MBEDTLS_OID_AT "\x0B" /**< id-at-organizationalUnitName AttributeType:= {id-at 11} */
+#define MBEDTLS_OID_AT_TITLE MBEDTLS_OID_AT "\x0C" /**< id-at-title AttributeType:= {id-at 12} */
+#define MBEDTLS_OID_AT_POSTAL_ADDRESS MBEDTLS_OID_AT "\x10" /**< id-at-postalAddress AttributeType:= {id-at 16} */
+#define MBEDTLS_OID_AT_POSTAL_CODE MBEDTLS_OID_AT "\x11" /**< id-at-postalCode AttributeType:= {id-at 17} */
+#define MBEDTLS_OID_AT_GIVEN_NAME MBEDTLS_OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */
+#define MBEDTLS_OID_AT_INITIALS MBEDTLS_OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */
+#define MBEDTLS_OID_AT_GENERATION_QUALIFIER MBEDTLS_OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */
+#define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER MBEDTLS_OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributType:= {id-at 45} */
+#define MBEDTLS_OID_AT_DN_QUALIFIER MBEDTLS_OID_AT "\x2E" /**< id-at-dnQualifier AttributeType:= {id-at 46} */
+#define MBEDTLS_OID_AT_PSEUDONYM MBEDTLS_OID_AT "\x41" /**< id-at-pseudonym AttributeType:= {id-at 65} */
+
+#define MBEDTLS_OID_DOMAIN_COMPONENT "\x09\x92\x26\x89\x93\xF2\x2C\x64\x01\x19" /** id-domainComponent AttributeType:= {itu-t(0) data(9) pss(2342) ucl(19200300) pilot(100) pilotAttributeType(1) domainComponent(25)} */
+
+/*
+ * OIDs for standard certificate extensions
+ */
+#define MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_ID_CE "\x23" /**< id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } */
+#define MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER MBEDTLS_OID_ID_CE "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */
+#define MBEDTLS_OID_KEY_USAGE MBEDTLS_OID_ID_CE "\x0F" /**< id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } */
+#define MBEDTLS_OID_CERTIFICATE_POLICIES MBEDTLS_OID_ID_CE "\x20" /**< id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } */
+#define MBEDTLS_OID_POLICY_MAPPINGS MBEDTLS_OID_ID_CE "\x21" /**< id-ce-policyMappings OBJECT IDENTIFIER ::= { id-ce 33 } */
+#define MBEDTLS_OID_SUBJECT_ALT_NAME MBEDTLS_OID_ID_CE "\x11" /**< id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } */
+#define MBEDTLS_OID_ISSUER_ALT_NAME MBEDTLS_OID_ID_CE "\x12" /**< id-ce-issuerAltName OBJECT IDENTIFIER ::= { id-ce 18 } */
+#define MBEDTLS_OID_SUBJECT_DIRECTORY_ATTRS MBEDTLS_OID_ID_CE "\x09" /**< id-ce-subjectDirectoryAttributes OBJECT IDENTIFIER ::= { id-ce 9 } */
+#define MBEDTLS_OID_BASIC_CONSTRAINTS MBEDTLS_OID_ID_CE "\x13" /**< id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } */
+#define MBEDTLS_OID_NAME_CONSTRAINTS MBEDTLS_OID_ID_CE "\x1E" /**< id-ce-nameConstraints OBJECT IDENTIFIER ::= { id-ce 30 } */
+#define MBEDTLS_OID_POLICY_CONSTRAINTS MBEDTLS_OID_ID_CE "\x24" /**< id-ce-policyConstraints OBJECT IDENTIFIER ::= { id-ce 36 } */
+#define MBEDTLS_OID_EXTENDED_KEY_USAGE MBEDTLS_OID_ID_CE "\x25" /**< id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } */
+#define MBEDTLS_OID_CRL_DISTRIBUTION_POINTS MBEDTLS_OID_ID_CE "\x1F" /**< id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } */
+#define MBEDTLS_OID_INIHIBIT_ANYPOLICY MBEDTLS_OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */
+#define MBEDTLS_OID_FRESHEST_CRL MBEDTLS_OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */
+
+/*
+ * Netscape certificate extensions
+ */
+#define MBEDTLS_OID_NS_CERT MBEDTLS_OID_NETSCAPE "\x01"
+#define MBEDTLS_OID_NS_CERT_TYPE MBEDTLS_OID_NS_CERT "\x01"
+#define MBEDTLS_OID_NS_BASE_URL MBEDTLS_OID_NS_CERT "\x02"
+#define MBEDTLS_OID_NS_REVOCATION_URL MBEDTLS_OID_NS_CERT "\x03"
+#define MBEDTLS_OID_NS_CA_REVOCATION_URL MBEDTLS_OID_NS_CERT "\x04"
+#define MBEDTLS_OID_NS_RENEWAL_URL MBEDTLS_OID_NS_CERT "\x07"
+#define MBEDTLS_OID_NS_CA_POLICY_URL MBEDTLS_OID_NS_CERT "\x08"
+#define MBEDTLS_OID_NS_SSL_SERVER_NAME MBEDTLS_OID_NS_CERT "\x0C"
+#define MBEDTLS_OID_NS_COMMENT MBEDTLS_OID_NS_CERT "\x0D"
+#define MBEDTLS_OID_NS_DATA_TYPE MBEDTLS_OID_NETSCAPE "\x02"
+#define MBEDTLS_OID_NS_CERT_SEQUENCE MBEDTLS_OID_NS_DATA_TYPE "\x05"
+
+/*
+ * OIDs for CRL extensions
+ */
+#define MBEDTLS_OID_PRIVATE_KEY_USAGE_PERIOD MBEDTLS_OID_ID_CE "\x10"
+#define MBEDTLS_OID_CRL_NUMBER MBEDTLS_OID_ID_CE "\x14" /**< id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } */
+
+/*
+ * X.509 v3 Extended key usage OIDs
+ */
+#define MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE MBEDTLS_OID_EXTENDED_KEY_USAGE "\x00" /**< anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 } */
+
+#define MBEDTLS_OID_KP MBEDTLS_OID_PKIX "\x03" /**< id-kp OBJECT IDENTIFIER ::= { id-pkix 3 } */
+#define MBEDTLS_OID_SERVER_AUTH MBEDTLS_OID_KP "\x01" /**< id-kp-serverAuth OBJECT IDENTIFIER ::= { id-kp 1 } */
+#define MBEDTLS_OID_CLIENT_AUTH MBEDTLS_OID_KP "\x02" /**< id-kp-clientAuth OBJECT IDENTIFIER ::= { id-kp 2 } */
+#define MBEDTLS_OID_CODE_SIGNING MBEDTLS_OID_KP "\x03" /**< id-kp-codeSigning OBJECT IDENTIFIER ::= { id-kp 3 } */
+#define MBEDTLS_OID_EMAIL_PROTECTION MBEDTLS_OID_KP "\x04" /**< id-kp-emailProtection OBJECT IDENTIFIER ::= { id-kp 4 } */
+#define MBEDTLS_OID_TIME_STAMPING MBEDTLS_OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */
+#define MBEDTLS_OID_OCSP_SIGNING MBEDTLS_OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */
+
+/*
+ * PKCS definition OIDs
+ */
+
+#define MBEDTLS_OID_PKCS MBEDTLS_OID_RSA_COMPANY "\x01" /**< pkcs OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) 1 } */
+#define MBEDTLS_OID_PKCS1 MBEDTLS_OID_PKCS "\x01" /**< pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1 } */
+#define MBEDTLS_OID_PKCS5 MBEDTLS_OID_PKCS "\x05" /**< pkcs-5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 5 } */
+#define MBEDTLS_OID_PKCS9 MBEDTLS_OID_PKCS "\x09" /**< pkcs-9 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 9 } */
+#define MBEDTLS_OID_PKCS12 MBEDTLS_OID_PKCS "\x0c" /**< pkcs-12 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 12 } */
+
+/*
+ * PKCS#1 OIDs
+ */
+#define MBEDTLS_OID_PKCS1_RSA MBEDTLS_OID_PKCS1 "\x01" /**< rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 } */
+#define MBEDTLS_OID_PKCS1_MD2 MBEDTLS_OID_PKCS1 "\x02" /**< md2WithRSAEncryption ::= { pkcs-1 2 } */
+#define MBEDTLS_OID_PKCS1_MD4 MBEDTLS_OID_PKCS1 "\x03" /**< md4WithRSAEncryption ::= { pkcs-1 3 } */
+#define MBEDTLS_OID_PKCS1_MD5 MBEDTLS_OID_PKCS1 "\x04" /**< md5WithRSAEncryption ::= { pkcs-1 4 } */
+#define MBEDTLS_OID_PKCS1_SHA1 MBEDTLS_OID_PKCS1 "\x05" /**< sha1WithRSAEncryption ::= { pkcs-1 5 } */
+#define MBEDTLS_OID_PKCS1_SHA224 MBEDTLS_OID_PKCS1 "\x0e" /**< sha224WithRSAEncryption ::= { pkcs-1 14 } */
+#define MBEDTLS_OID_PKCS1_SHA256 MBEDTLS_OID_PKCS1 "\x0b" /**< sha256WithRSAEncryption ::= { pkcs-1 11 } */
+#define MBEDTLS_OID_PKCS1_SHA384 MBEDTLS_OID_PKCS1 "\x0c" /**< sha384WithRSAEncryption ::= { pkcs-1 12 } */
+#define MBEDTLS_OID_PKCS1_SHA512 MBEDTLS_OID_PKCS1 "\x0d" /**< sha512WithRSAEncryption ::= { pkcs-1 13 } */
+
+#define MBEDTLS_OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
+
+#define MBEDTLS_OID_PKCS9_EMAIL MBEDTLS_OID_PKCS9 "\x01" /**< emailAddress AttributeType ::= { pkcs-9 1 } */
+
+/* RFC 4055 */
+#define MBEDTLS_OID_RSASSA_PSS MBEDTLS_OID_PKCS1 "\x0a" /**< id-RSASSA-PSS ::= { pkcs-1 10 } */
+#define MBEDTLS_OID_MGF1 MBEDTLS_OID_PKCS1 "\x08" /**< id-mgf1 ::= { pkcs-1 8 } */
+
+/*
+ * Digest algorithms
+ */
+#define MBEDTLS_OID_DIGEST_ALG_MD2 MBEDTLS_OID_RSA_COMPANY "\x02\x02" /**< id-mbedtls_md2 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 2 } */
+#define MBEDTLS_OID_DIGEST_ALG_MD4 MBEDTLS_OID_RSA_COMPANY "\x02\x04" /**< id-mbedtls_md4 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 4 } */
+#define MBEDTLS_OID_DIGEST_ALG_MD5 MBEDTLS_OID_RSA_COMPANY "\x02\x05" /**< id-mbedtls_md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5 } */
+#define MBEDTLS_OID_DIGEST_ALG_SHA1 MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1 /**< id-mbedtls_sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26 } */
+#define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_GOV "\x03\x04\x02\x04" /**< id-sha224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 4 } */
+#define MBEDTLS_OID_DIGEST_ALG_SHA256 MBEDTLS_OID_GOV "\x03\x04\x02\x01" /**< id-mbedtls_sha256 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 1 } */
+
+#define MBEDTLS_OID_DIGEST_ALG_SHA384 MBEDTLS_OID_GOV "\x03\x04\x02\x02" /**< id-sha384 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 2 } */
+
+#define MBEDTLS_OID_DIGEST_ALG_SHA512 MBEDTLS_OID_GOV "\x03\x04\x02\x03" /**< id-mbedtls_sha512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 3 } */
+
+#define MBEDTLS_OID_HMAC_SHA1 MBEDTLS_OID_RSA_COMPANY "\x02\x07" /**< id-hmacWithSHA1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 7 } */
+
+#define MBEDTLS_OID_HMAC_SHA224 MBEDTLS_OID_RSA_COMPANY "\x02\x08" /**< id-hmacWithSHA224 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 8 } */
+
+#define MBEDTLS_OID_HMAC_SHA256 MBEDTLS_OID_RSA_COMPANY "\x02\x09" /**< id-hmacWithSHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 9 } */
+
+#define MBEDTLS_OID_HMAC_SHA384 MBEDTLS_OID_RSA_COMPANY "\x02\x0A" /**< id-hmacWithSHA384 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 10 } */
+
+#define MBEDTLS_OID_HMAC_SHA512 MBEDTLS_OID_RSA_COMPANY "\x02\x0B" /**< id-hmacWithSHA512 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 11 } */
+
+/*
+ * Encryption algorithms
+ */
+#define MBEDTLS_OID_DES_CBC MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 7 } */
+#define MBEDTLS_OID_DES_EDE3_CBC MBEDTLS_OID_RSA_COMPANY "\x03\x07" /**< des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) -- us(840) rsadsi(113549) encryptionAlgorithm(3) 7 } */
+
+/*
+ * PKCS#5 OIDs
+ */
+#define MBEDTLS_OID_PKCS5_PBKDF2 MBEDTLS_OID_PKCS5 "\x0c" /**< id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12} */
+#define MBEDTLS_OID_PKCS5_PBES2 MBEDTLS_OID_PKCS5 "\x0d" /**< id-PBES2 OBJECT IDENTIFIER ::= {pkcs-5 13} */
+#define MBEDTLS_OID_PKCS5_PBMAC1 MBEDTLS_OID_PKCS5 "\x0e" /**< id-PBMAC1 OBJECT IDENTIFIER ::= {pkcs-5 14} */
+
+/*
+ * PKCS#5 PBES1 algorithms
+ */
+#define MBEDTLS_OID_PKCS5_PBE_MD2_DES_CBC MBEDTLS_OID_PKCS5 "\x01" /**< pbeWithMD2AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 1} */
+#define MBEDTLS_OID_PKCS5_PBE_MD2_RC2_CBC MBEDTLS_OID_PKCS5 "\x04" /**< pbeWithMD2AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 4} */
+#define MBEDTLS_OID_PKCS5_PBE_MD5_DES_CBC MBEDTLS_OID_PKCS5 "\x03" /**< pbeWithMD5AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 3} */
+#define MBEDTLS_OID_PKCS5_PBE_MD5_RC2_CBC MBEDTLS_OID_PKCS5 "\x06" /**< pbeWithMD5AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 6} */
+#define MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC MBEDTLS_OID_PKCS5 "\x0a" /**< pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10} */
+#define MBEDTLS_OID_PKCS5_PBE_SHA1_RC2_CBC MBEDTLS_OID_PKCS5 "\x0b" /**< pbeWithSHA1AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 11} */
+
+/*
+ * PKCS#8 OIDs
+ */
+#define MBEDTLS_OID_PKCS9_CSR_EXT_REQ MBEDTLS_OID_PKCS9 "\x0e" /**< extensionRequest OBJECT IDENTIFIER ::= {pkcs-9 14} */
+
+/*
+ * PKCS#12 PBE OIDs
+ */
+#define MBEDTLS_OID_PKCS12_PBE MBEDTLS_OID_PKCS12 "\x01" /**< pkcs-12PbeIds OBJECT IDENTIFIER ::= {pkcs-12 1} */
+
+#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_128 MBEDTLS_OID_PKCS12_PBE "\x01" /**< pbeWithSHAAnd128BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 1} */
+#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_40 MBEDTLS_OID_PKCS12_PBE "\x02" /**< pbeWithSHAAnd40BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 2} */
+#define MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x03" /**< pbeWithSHAAnd3-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 3} */
+#define MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x04" /**< pbeWithSHAAnd2-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 4} */
+#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC MBEDTLS_OID_PKCS12_PBE "\x05" /**< pbeWithSHAAnd128BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 5} */
+#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_40_CBC MBEDTLS_OID_PKCS12_PBE "\x06" /**< pbeWithSHAAnd40BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 6} */
+
+/*
+ * EC key algorithms from RFC 5480
+ */
+
+/* id-ecPublicKey OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 } */
+#define MBEDTLS_OID_EC_ALG_UNRESTRICTED MBEDTLS_OID_ANSI_X9_62 "\x02\01"
+
+/* id-ecDH OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132)
+ * schemes(1) ecdh(12) } */
+#define MBEDTLS_OID_EC_ALG_ECDH MBEDTLS_OID_CERTICOM "\x01\x0c"
+
+/*
+ * ECParameters namedCurve identifiers, from RFC 5480, RFC 5639, and SEC2
+ */
+
+/* secp192r1 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 1 } */
+#define MBEDTLS_OID_EC_GRP_SECP192R1 MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x01"
+
+/* secp224r1 OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132) curve(0) 33 } */
+#define MBEDTLS_OID_EC_GRP_SECP224R1 MBEDTLS_OID_CERTICOM "\x00\x21"
+
+/* secp256r1 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 7 } */
+#define MBEDTLS_OID_EC_GRP_SECP256R1 MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x07"
+
+/* secp384r1 OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132) curve(0) 34 } */
+#define MBEDTLS_OID_EC_GRP_SECP384R1 MBEDTLS_OID_CERTICOM "\x00\x22"
+
+/* secp521r1 OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132) curve(0) 35 } */
+#define MBEDTLS_OID_EC_GRP_SECP521R1 MBEDTLS_OID_CERTICOM "\x00\x23"
+
+/* secp192k1 OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132) curve(0) 31 } */
+#define MBEDTLS_OID_EC_GRP_SECP192K1 MBEDTLS_OID_CERTICOM "\x00\x1f"
+
+/* secp224k1 OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132) curve(0) 32 } */
+#define MBEDTLS_OID_EC_GRP_SECP224K1 MBEDTLS_OID_CERTICOM "\x00\x20"
+
+/* secp256k1 OBJECT IDENTIFIER ::= {
+ * iso(1) identified-organization(3) certicom(132) curve(0) 10 } */
+#define MBEDTLS_OID_EC_GRP_SECP256K1 MBEDTLS_OID_CERTICOM "\x00\x0a"
+
+/* RFC 5639 4.1
+ * ecStdCurvesAndGeneration OBJECT IDENTIFIER::= {iso(1)
+ * identified-organization(3) teletrust(36) algorithm(3) signature-
+ * algorithm(3) ecSign(2) 8}
+ * ellipticCurve OBJECT IDENTIFIER ::= {ecStdCurvesAndGeneration 1}
+ * versionOne OBJECT IDENTIFIER ::= {ellipticCurve 1} */
+#define MBEDTLS_OID_EC_BRAINPOOL_V1 MBEDTLS_OID_TELETRUST "\x03\x03\x02\x08\x01\x01"
+
+/* brainpoolP256r1 OBJECT IDENTIFIER ::= {versionOne 7} */
+#define MBEDTLS_OID_EC_GRP_BP256R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x07"
+
+/* brainpoolP384r1 OBJECT IDENTIFIER ::= {versionOne 11} */
+#define MBEDTLS_OID_EC_GRP_BP384R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0B"
+
+/* brainpoolP512r1 OBJECT IDENTIFIER ::= {versionOne 13} */
+#define MBEDTLS_OID_EC_GRP_BP512R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0D"
+
+/*
+ * SEC1 C.1
+ *
+ * prime-field OBJECT IDENTIFIER ::= { id-fieldType 1 }
+ * id-fieldType OBJECT IDENTIFIER ::= { ansi-X9-62 fieldType(1)}
+ */
+#define MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE MBEDTLS_OID_ANSI_X9_62 "\x01"
+#define MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE "\x01"
+
+/*
+ * ECDSA signature identifiers, from RFC 5480
+ */
+#define MBEDTLS_OID_ANSI_X9_62_SIG MBEDTLS_OID_ANSI_X9_62 "\x04" /* signatures(4) */
+#define MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 MBEDTLS_OID_ANSI_X9_62_SIG "\x03" /* ecdsa-with-SHA2(3) */
+
+/* ecdsa-with-SHA1 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) 1 } */
+#define MBEDTLS_OID_ECDSA_SHA1 MBEDTLS_OID_ANSI_X9_62_SIG "\x01"
+
+/* ecdsa-with-SHA224 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
+ * ecdsa-with-SHA2(3) 1 } */
+#define MBEDTLS_OID_ECDSA_SHA224 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x01"
+
+/* ecdsa-with-SHA256 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
+ * ecdsa-with-SHA2(3) 2 } */
+#define MBEDTLS_OID_ECDSA_SHA256 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x02"
+
+/* ecdsa-with-SHA384 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
+ * ecdsa-with-SHA2(3) 3 } */
+#define MBEDTLS_OID_ECDSA_SHA384 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x03"
+
+/* ecdsa-with-SHA512 OBJECT IDENTIFIER ::= {
+ * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
+ * ecdsa-with-SHA2(3) 4 } */
+#define MBEDTLS_OID_ECDSA_SHA512 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Base OID descriptor structure
+ */
+typedef struct {
+ const char *asn1; /*!< OID ASN.1 representation */
+ size_t asn1_len; /*!< length of asn1 */
+ const char *name; /*!< official name (e.g. from RFC) */
+ const char *description; /*!< human friendly description */
+} mbedtls_oid_descriptor_t;
+
+/**
+ * \brief Translate an ASN.1 OID into its numeric representation
+ * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549")
+ *
+ * \param buf buffer to put representation in
+ * \param size size of the buffer
+ * \param oid OID to translate
+ *
+ * \return Length of the string written (excluding final NULL) or
+ * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error
+ */
+int mbedtls_oid_get_numeric_string( char *buf, size_t size, const mbedtls_asn1_buf *oid );
+
+#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
+/**
+ * \brief Translate an X.509 extension OID into local values
+ *
+ * \param oid OID to use
+ * \param ext_type place to store the extension type
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_x509_ext_type( const mbedtls_asn1_buf *oid, int *ext_type );
+#endif
+
+/**
+ * \brief Translate an X.509 attribute type OID into the short name
+ * (e.g. the OID for an X520 Common Name into "CN")
+ *
+ * \param oid OID to use
+ * \param short_name place to store the string pointer
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_attr_short_name( const mbedtls_asn1_buf *oid, const char **short_name );
+
+/**
+ * \brief Translate PublicKeyAlgorithm OID into pk_type
+ *
+ * \param oid OID to use
+ * \param pk_alg place to store public key algorithm
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_pk_alg( const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg );
+
+/**
+ * \brief Translate pk_type into PublicKeyAlgorithm OID
+ *
+ * \param pk_alg Public key type to look for
+ * \param oid place to store ASN.1 OID string pointer
+ * \param olen length of the OID
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_oid_by_pk_alg( mbedtls_pk_type_t pk_alg,
+ const char **oid, size_t *olen );
+
+#if defined(MBEDTLS_ECP_C)
+/**
+ * \brief Translate NamedCurve OID into an EC group identifier
+ *
+ * \param oid OID to use
+ * \param grp_id place to store group id
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_ec_grp( const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id );
+
+/**
+ * \brief Translate EC group identifier into NamedCurve OID
+ *
+ * \param grp_id EC group identifier
+ * \param oid place to store ASN.1 OID string pointer
+ * \param olen length of the OID
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_oid_by_ec_grp( mbedtls_ecp_group_id grp_id,
+ const char **oid, size_t *olen );
+#endif /* MBEDTLS_ECP_C */
+
+#if defined(MBEDTLS_MD_C)
+/**
+ * \brief Translate SignatureAlgorithm OID into md_type and pk_type
+ *
+ * \param oid OID to use
+ * \param md_alg place to store message digest algorithm
+ * \param pk_alg place to store public key algorithm
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_sig_alg( const mbedtls_asn1_buf *oid,
+ mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg );
+
+/**
+ * \brief Translate SignatureAlgorithm OID into description
+ *
+ * \param oid OID to use
+ * \param desc place to store string pointer
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_sig_alg_desc( const mbedtls_asn1_buf *oid, const char **desc );
+
+/**
+ * \brief Translate md_type and pk_type into SignatureAlgorithm OID
+ *
+ * \param md_alg message digest algorithm
+ * \param pk_alg public key algorithm
+ * \param oid place to store ASN.1 OID string pointer
+ * \param olen length of the OID
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_oid_by_sig_alg( mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
+ const char **oid, size_t *olen );
+
+/**
+ * \brief Translate hash algorithm OID into md_type
+ *
+ * \param oid OID to use
+ * \param md_alg place to store message digest algorithm
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_md_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg );
+
+/**
+ * \brief Translate hmac algorithm OID into md_type
+ *
+ * \param oid OID to use
+ * \param md_hmac place to store message hmac algorithm
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac );
+#endif /* MBEDTLS_MD_C */
+
+/**
+ * \brief Translate Extended Key Usage OID into description
+ *
+ * \param oid OID to use
+ * \param desc place to store string pointer
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc );
+
+/**
+ * \brief Translate md_type into hash algorithm OID
+ *
+ * \param md_alg message digest algorithm
+ * \param oid place to store ASN.1 OID string pointer
+ * \param olen length of the OID
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_oid_by_md( mbedtls_md_type_t md_alg, const char **oid, size_t *olen );
+
+#if defined(MBEDTLS_CIPHER_C)
+/**
+ * \brief Translate encryption algorithm OID into cipher_type
+ *
+ * \param oid OID to use
+ * \param cipher_alg place to store cipher algorithm
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_cipher_alg( const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg );
+#endif /* MBEDTLS_CIPHER_C */
+
+#if defined(MBEDTLS_PKCS12_C)
+/**
+ * \brief Translate PKCS#12 PBE algorithm OID into md_type and
+ * cipher_type
+ *
+ * \param oid OID to use
+ * \param md_alg place to store message digest algorithm
+ * \param cipher_alg place to store cipher algorithm
+ *
+ * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
+ */
+int mbedtls_oid_get_pkcs12_pbe_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg,
+ mbedtls_cipher_type_t *cipher_alg );
+#endif /* MBEDTLS_PKCS12_C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* oid.h */
+
+
+/********* Start of file include/mbedtls/ripemd160.h ************/
+
+/**
+ * \file ripemd160.h
+ *
+ * \brief RIPE MD-160 message digest
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_RIPEMD160_H
+#define MBEDTLS_RIPEMD160_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+#include
+#include
+
+#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
+
+#if !defined(MBEDTLS_RIPEMD160_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief RIPEMD-160 context structure
+ */
+typedef struct
+{
+ uint32_t total[2]; /*!< number of bytes processed */
+ uint32_t state[5]; /*!< intermediate digest state */
+ unsigned char buffer[64]; /*!< data block being processed */
+}
+mbedtls_ripemd160_context;
+
+/**
+ * \brief Initialize RIPEMD-160 context
+ *
+ * \param ctx RIPEMD-160 context to be initialized
+ */
+void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
+
+/**
+ * \brief Clear RIPEMD-160 context
+ *
+ * \param ctx RIPEMD-160 context to be cleared
+ */
+void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
+
+/**
+ * \brief Clone (the state of) an RIPEMD-160 context
+ *
+ * \param dst The destination context
+ * \param src The context to be cloned
+ */
+void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
+ const mbedtls_ripemd160_context *src );
+
+/**
+ * \brief RIPEMD-160 context setup
+ *
+ * \param ctx context to be initialized
+ *
+ * \return 0 if successful
+ */
+int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
+
+/**
+ * \brief RIPEMD-160 process buffer
+ *
+ * \param ctx RIPEMD-160 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ *
+ * \return 0 if successful
+ */
+int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief RIPEMD-160 final digest
+ *
+ * \param ctx RIPEMD-160 context
+ * \param output RIPEMD-160 checksum result
+ *
+ * \return 0 if successful
+ */
+int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
+ unsigned char output[20] );
+
+/**
+ * \brief RIPEMD-160 process data block (internal use only)
+ *
+ * \param ctx RIPEMD-160 context
+ * \param data buffer holding one block of data
+ *
+ * \return 0 if successful
+ */
+int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
+ const unsigned char data[64] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief RIPEMD-160 context setup
+ *
+ * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
+ *
+ * \param ctx context to be initialized
+ */
+MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
+ mbedtls_ripemd160_context *ctx );
+
+/**
+ * \brief RIPEMD-160 process buffer
+ *
+ * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
+ *
+ * \param ctx RIPEMD-160 context
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ */
+MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
+ mbedtls_ripemd160_context *ctx,
+ const unsigned char *input,
+ size_t ilen );
+
+/**
+ * \brief RIPEMD-160 final digest
+ *
+ * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
+ *
+ * \param ctx RIPEMD-160 context
+ * \param output RIPEMD-160 checksum result
+ */
+MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
+ mbedtls_ripemd160_context *ctx,
+ unsigned char output[20] );
+
+/**
+ * \brief RIPEMD-160 process data block (internal use only)
+ *
+ * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
+ *
+ * \param ctx RIPEMD-160 context
+ * \param data buffer holding one block of data
+ */
+MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
+ mbedtls_ripemd160_context *ctx,
+ const unsigned char data[64] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#else /* MBEDTLS_RIPEMD160_ALT */
+
+#endif /* MBEDTLS_RIPEMD160_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Output = RIPEMD-160( input buffer )
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output RIPEMD-160 checksum result
+ *
+ * \return 0 if successful
+ */
+int mbedtls_ripemd160_ret( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[20] );
+
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
+#if defined(MBEDTLS_DEPRECATED_WARNING)
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))
+#else
+#define MBEDTLS_DEPRECATED
+#endif
+/**
+ * \brief Output = RIPEMD-160( input buffer )
+ *
+ * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
+ *
+ * \param input buffer holding the data
+ * \param ilen length of the input data
+ * \param output RIPEMD-160 checksum result
+ */
+MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
+ size_t ilen,
+ unsigned char output[20] );
+
+#undef MBEDTLS_DEPRECATED
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
+
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if the test failed
+ */
+int mbedtls_ripemd160_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_ripemd160.h */
+
+
+/********* Start of file include/mbedtls/version.h ************/
+
+/**
+ * \file version.h
+ *
+ * \brief Run-time version information
+ */
+/*
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ * This file is part of mbed TLS (https://tls.mbed.org)
+ */
+/*
+ * This set of compile-time defines and run-time variables can be used to
+ * determine the version number of the mbed TLS library used.
+ */
+#ifndef MBEDTLS_VERSION_H
+#define MBEDTLS_VERSION_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+
+#else
+
+#endif
+
+/**
+ * The version number x.y.z is split into three parts.
+ * Major, Minor, Patchlevel
+ */
+#define MBEDTLS_VERSION_MAJOR 2
+#define MBEDTLS_VERSION_MINOR 8
+#define MBEDTLS_VERSION_PATCH 0
+
+/**
+ * The single version number has the following structure:
+ * MMNNPP00
+ * Major version | Minor version | Patch version
+ */
+#define MBEDTLS_VERSION_NUMBER 0x02080000
+#define MBEDTLS_VERSION_STRING "2.8.0"
+#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.8.0"
+
+#if defined(MBEDTLS_VERSION_C)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Get the version number.
+ *
+ * \return The constructed version number in the format
+ * MMNNPP00 (Major, Minor, Patch).
+ */
+unsigned int mbedtls_version_get_number( void );
+
+/**
+ * Get the version string ("x.y.z").
+ *
+ * \param string The string that will receive the value.
+ * (Should be at least 9 bytes in size)
+ */
+void mbedtls_version_get_string( char *string );
+
+/**
+ * Get the full version string ("mbed TLS x.y.z").
+ *
+ * \param string The string that will receive the value. The mbed TLS version
+ * string will use 18 bytes AT MOST including a terminating
+ * null byte.
+ * (So the buffer should be at least 18 bytes to receive this
+ * version string).
+ */
+void mbedtls_version_get_string_full( char *string );
+
+/**
+ * \brief Check if support for a feature was compiled into this
+ * mbed TLS binary. This allows you to see at runtime if the
+ * library was for instance compiled with or without
+ * Multi-threading support.
+ *
+ * \note only checks against defines in the sections "System
+ * support", "mbed TLS modules" and "mbed TLS feature
+ * support" in config.h
+ *
+ * \param feature The string for the define to check (e.g. "MBEDTLS_AES_C")
+ *
+ * \return 0 if the feature is present,
+ * -1 if the feature is not present and
+ * -2 if support for feature checking as a whole was not
+ * compiled in.
+ */
+int mbedtls_version_check_feature( const char *feature );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MBEDTLS_VERSION_C */
+
+#endif /* version.h */
+
+#endif /* ME_COM_MBEDTLS */
diff --git a/code/application/source/sf_app/code/include/mmask.h b/code/application/source/sf_app/code/include/mmask.h
new file mode 100755
index 000000000..f095727b1
--- /dev/null
+++ b/code/application/source/sf_app/code/include/mmask.h
@@ -0,0 +1,44 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Masking for Micro QR Code.
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __MMASK_H__
+#define __MMASK_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+extern unsigned char *MMask_makeMask(int version, unsigned char *frame, int mask, QRecLevel level);
+extern unsigned char *MMask_mask(int version, unsigned char *frame, QRecLevel level);
+
+#ifdef WITH_TESTS
+extern int MMask_evaluateSymbol(int width, unsigned char *frame);
+extern void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level);
+extern unsigned char *MMask_makeMaskedFrame(int width, unsigned char *frame, int mask);
+#endif
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __MMASK_H__ */
diff --git a/code/application/source/sf_app/code/include/mqrspec.h b/code/application/source/sf_app/code/include/mqrspec.h
new file mode 100755
index 000000000..71ff5f454
--- /dev/null
+++ b/code/application/source/sf_app/code/include/mqrspec.h
@@ -0,0 +1,167 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Micro QR Code specification in convenient format.
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __MQRSPEC_H__
+#define __MQRSPEC_H__
+
+#include "qrencode.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+/******************************************************************************
+ * Version and capacity
+ *****************************************************************************/
+
+/**
+ * Maximum width of a symbol
+ */
+#define MQRSPEC_WIDTH_MAX 17
+
+/**
+ * Return maximum data code length (bits) for the version.
+ * @param version
+ * @param level
+ * @return maximum size (bits)
+ */
+extern int MQRspec_getDataLengthBit(int version, QRecLevel level);
+
+/**
+ * Return maximum data code length (bytes) for the version.
+ * @param version
+ * @param level
+ * @return maximum size (bytes)
+ */
+extern int MQRspec_getDataLength(int version, QRecLevel level);
+
+/**
+ * Return maximum error correction code length (bytes) for the version.
+ * @param version
+ * @param level
+ * @return ECC size (bytes)
+ */
+extern int MQRspec_getECCLength(int version, QRecLevel level);
+
+/**
+ * Return a version number that satisfies the input code length.
+ * @param size input code length (byte)
+ * @param level
+ * @return version number
+ */
+extern int MQRspec_getMinimumVersion(int size, QRecLevel level);
+
+/**
+ * Return the width of the symbol for the version.
+ * @param version
+ * @return width
+ */
+extern int MQRspec_getWidth(int version);
+
+/**
+ * Return the numer of remainder bits.
+ * @param version
+ * @return number of remainder bits
+ */
+extern int MQRspec_getRemainder(int version);
+
+/******************************************************************************
+ * Length indicator
+ *****************************************************************************/
+
+/**
+ * Return the size of lenght indicator for the mode and version.
+ * @param mode
+ * @param version
+ * @return the size of the appropriate length indicator (bits).
+ */
+extern int MQRspec_lengthIndicator(QRencodeMode mode, int version);
+
+/**
+ * Return the maximum length for the mode and version.
+ * @param mode
+ * @param version
+ * @return the maximum length (bytes)
+ */
+extern int MQRspec_maximumWords(QRencodeMode mode, int version);
+
+/******************************************************************************
+ * Version information pattern
+ *****************************************************************************/
+
+/**
+ * Return BCH encoded version information pattern that is used for the symbol
+ * of version 7 or greater. Use lower 18 bits.
+ * @param version
+ * @return BCH encoded version information pattern
+ */
+extern unsigned int MQRspec_getVersionPattern(int version);
+
+/******************************************************************************
+ * Format information
+ *****************************************************************************/
+
+/**
+ * Return BCH encoded format information pattern.
+ * @param mask
+ * @param version
+ * @param level
+ * @return BCH encoded format information pattern
+ */
+extern unsigned int MQRspec_getFormatInfo(int mask, int version, QRecLevel level);
+
+/******************************************************************************
+ * Frame
+ *****************************************************************************/
+
+/**
+ * Return a copy of initialized frame.
+ * When the same version is requested twice or more, a copy of cached frame
+ * is returned.
+ * @param version
+ * @return Array of unsigned char. You can free it by free().
+ */
+extern unsigned char *MQRspec_newFrame(int version);
+
+/**
+ * Clear the frame cache. Typically for debug.
+ */
+extern void MQRspec_clearCache(void);
+
+/******************************************************************************
+ * Mode indicator
+ *****************************************************************************/
+
+/**
+ * Mode indicator. See Table 2 in Appendix 1 of JIS X0510:2004, pp.107.
+ */
+#define MQRSPEC_MODEID_NUM 0
+#define MQRSPEC_MODEID_AN 1
+#define MQRSPEC_MODEID_8 2
+#define MQRSPEC_MODEID_KANJI 3
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __MQRSPEC_H__ */
diff --git a/code/application/source/sf_app/code/include/qrenc.h b/code/application/source/sf_app/code/include/qrenc.h
new file mode 100755
index 000000000..4ecab822f
--- /dev/null
+++ b/code/application/source/sf_app/code/include/qrenc.h
@@ -0,0 +1,44 @@
+/**
+ * qrencode - QR Code encoder
+ *
+ * QR Code encoding tool
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include
+#include
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+//#include "getopt.h"
+//#include "jpeglib.h"
+
+#include "qrencode.h"
+
+#define INCHES_PER_METER (100.0/2.54)
+
+QRcode *encode(const unsigned char *intext, int length);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/code/application/source/sf_app/code/include/qrencode.h b/code/application/source/sf_app/code/include/qrencode.h
new file mode 100755
index 000000000..a2d8372e2
--- /dev/null
+++ b/code/application/source/sf_app/code/include/qrencode.h
@@ -0,0 +1,415 @@
+/**
+ * qrencode - QR Code encoder
+ *
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute · it and/or
+ * modify it under the terms ofʲôʲô the GNU Lesser General Public
+ * License (GNUȨ)as published (棬)by the Free Software Foundation(); either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/** \mainpage
+ * Libqrencode is a library for encoding data in a QR Code symbol, a kind of 2D
+ * symbology. LibqrencodeQRŵıݣһ2DŵĿ
+ *
+ * \section encoding Encoding ֱı
+ *
+ * There are two ways to encode data:ַʽ encoding a string Ϊַб or
+ * encoding a structured dataΪݽб.
+ *
+ * \subsection encoding-string Encoding a string encoding-stringһΪַб
+ * You can encode a string by calling QRcode_encodeString().ͨQRcode_encodeString()Ϊַб
+ * The given string is parsed automatically and encoded.ַԶͱ If you want to encode
+ * data that can be represented as a C string style (NUL terminated ֹ), you can
+ * simply use this way.
+ *
+ * If the input data contains Kanji (Shift-JIS) characters and you want to
+ * encode them as Kanji in QR Code, you should give QR_MODE_KANJI as a hint.ʾʾ
+ * Otherwise, all of non-alphanumeric ĸַ characters are encoded as 8 bit data.
+ * If you want to encode a whole string in 8 bit mode, use
+ * QRcode_encodeString8bit() instead.
+ *
+ * Please note that a C string can not contain NUL character. If your data
+ * contains NUL, you should chose the second way. ע⣬CַܰNULLַаNULӦѡڶַʽ
+ *
+ * \subsection encoding-input Encoding a structured data encoding-inputһΪݽб
+ * You can construct a structured input data manually. ֶһṹݡIf the structure of the
+ * input data is known, you can use this way.
+ * At first, create a ::QRinput object by QRinput_new(). Then add input data
+ * to the QRinput object by QRinput_append(). Finally call QRcode_encodeInput()
+ * to encode the QRinput data.
+ * You can reuse the QRinput data again to encode it in other symbols with
+ * different parameters.ͬ
+ *
+ * \section result Result
+ * The encoded symbol is resulted as a ::QRcode object. It will contain
+ * its version number汾, width of the symbolŵĿ and an array represents the symbol ʾ.
+ * See ::QRcode for the details. You can free the object by QRcode_free().
+ *
+ * Please note that the version of the result may be larger than specified.
+ * In such cases, the input data would be too large to be encoded in a
+ * symbol of the specified version.ݻΪָ̫汾ķ
+ *
+ * \section structured Structured append
+ * Libqrencode can generate "Structured-appended" symbols that enables to split
+ * a large data set into mulitple QR codes.һܴݷֳɶQRcode A QR code reader concatenates
+ * multiple QR code symbols into a string.QRĶӶQRתַ
+ * Just like QRcode_encodeString(), you can use QRcode_encodeStringStructured()
+ * to generate structured-appended symbols. This functions returns an instance
+ * of ::QRcode_List. The returned list is a singly-linked list of QRcode: you
+ * can retrieve each QR code in this way:
+ *
+ * \code
+ * QRcode_List *qrcodes;
+ * QRcode_List *entry;
+ * QRcode *qrcode;
+ *
+ * qrcodes = QRcode_encodeStringStructured(...);
+ * entry = qrcodes;
+ * while(entry != NULL) {
+ * qrcode = entry->code;
+ * // do something
+ * entry = entry->next;
+ * }
+ * QRcode_List_free(entry);
+ * \endcode
+ *
+ * Instead of using auto-parsing functions, you can construct your own
+ * structured input. At first, instantiate an object of ::QRinput_Struct
+ * by calling QRinput_Struct_new(). This object can hold multiple ::QRinput,
+ * and one QR code is generated for a ::QRinput.
+ * QRinput_Struct_appendInput() appends a ::QRinput to a ::QRinput_Struct
+ * object. In order to generate structured-appended symbols, it is required to
+ * embed headers to each symbol. You can use
+ * QRinput_Struct_insertStructuredAppendHeaders() to insert appropriate
+ * headers to each symbol. You should call this function just once before
+ * encoding symbols.
+ *ԹԼinputṹȡԶȣQRinput_Struct_new()ʵһQRinput_Struct
+ *ԱQRinputQRinput_Struct_appendInput()һQRinputQRinput_StructС
+ *Ϊstructured-appendedţҪǶͷÿСʹQRinput_Struct_insertStructuredAppendHeaders()ʵͷÿС
+ *ڱǮһΡ
+ */
+
+#ifndef __QRENCODE_H__
+#define __QRENCODE_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+
+/**
+ * Encoding mode.
+ */
+typedef enum {
+ QR_MODE_NUL = -1, ///< Terminator (NUL character). Internal use only
+ QR_MODE_NUM = 0, ///< Numeric mode ģʽ
+ QR_MODE_AN, ///< Alphabet-numeric mode ĸģʽ
+ QR_MODE_8, ///< 8-bit data mode 8λģʽ
+ QR_MODE_KANJI, ///< Kanji (shift-jis) mode ģʽ
+ QR_MODE_STRUCTURE, ///< Internal use only
+ QR_MODE_ECI, ///< ECI mode
+ QR_MODE_FNC1FIRST, ///< FNC1, first position
+ QR_MODE_FNC1SECOND, ///< FNC1, second position
+} QRencodeMode;
+
+/**
+ * Level of error correction.
+ */
+typedef enum {
+ QR_ECLEVEL_L = 0, ///< lowest
+ QR_ECLEVEL_M,
+ QR_ECLEVEL_Q,
+ QR_ECLEVEL_H ///< highest
+} QRecLevel;
+
+/**
+ * Maximum version (size) of QR-code symbol.
+ */
+#define QRSPEC_VERSION_MAX 40
+
+/**
+ * Maximum version (size) of QR-code symbol.
+ */
+#define MQRSPEC_VERSION_MAX 4
+
+
+/******************************************************************************
+ * Input data (qrinput.c)
+ *****************************************************************************/
+
+/**
+ * Singly linked list to contain input strings. An instance of this class
+ * contains its version and error correction level too. It is required to
+ * set them by QRinput_setVersion() and QRinput_setErrorCorrectionLevel(),
+ * or use QRinput_new2() to instantiate an object.
+ */
+typedef struct _QRinput QRinput;
+
+/**
+ * Instantiate an input data object.ʵһݶ The version is set to 0 (auto-select)
+ * and the error correction level is set to QR_ECLEVEL_L.
+ * @return an input object (initialized)һʵ. On error, NULL is returned and errno
+ * is set to indicate the error.
+ * @throw ENOMEM unable to allocate memory.
+ */
+extern QRinput *QRinput_new(void);
+
+/**
+ * Instantiate an input data object.
+ * @param version version number.
+ * @param level Error correction level.
+ * @return an input object (initialized). On error, NULL is returned and errno
+ * is set to indicate the error.
+ * @throw ENOMEM unable to allocate memory for input objects.
+ * @throw EINVAL invalid arguments.
+ */
+extern QRinput *QRinput_new2(int version, QRecLevel level);
+
+/**
+ * Instantiate an input data object. Object's Micro QR Code (һֶά,ֻһλΣ洢ȽСڴӡռС)flag is set.
+ * Unlike with full-sized QR Code, version number must be specified (>0).
+ * @param version version number (1--4).
+ * @param level Error correction level.
+ * @return an input object (initialized). On error, NULL is returned and errno
+ * is set to indicate the error.
+ * @throw ENOMEM unable to allocate memory for input objects.
+ * @throw EINVAL invalid arguments.
+ */
+extern QRinput *QRinput_newMQR(int version, QRecLevel level);
+
+/**
+ * Append data to an input object.
+ * The data is copied and appended to the input object.
+ * @param input input object.
+ * @param mode encoding mode.
+ * @param size size of data (byte).
+ * @param data a pointer to the memory area of the input data.
+ * @retval 0 success.
+ * @retval -1 an error occurred and errno is set to indeicate the error.
+ * See Execptions for the details.
+ * @throw ENOMEM unable to allocate memory.
+ * @throw EINVAL input data is invalid.
+ *
+ */
+extern int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data);
+
+/**
+ * Append ECI header.ַ
+ * @param input input object.
+ * @param ecinum ECI indicator number (0 - 999999)
+ * @retval 0 success.
+ * @retval -1 an error occurred and errno is set to indeicate the error.
+ * See Execptions for the details.
+ * @throw ENOMEM unable to allocate memory.
+ * @throw EINVAL input data is invalid.
+ *
+ */
+extern int QRinput_appendECIheader(QRinput *input, unsigned int ecinum);
+
+/**
+ * Get current version.
+ * @param input input object.
+ * @return current version.
+ */
+extern int QRinput_getVersion(QRinput *input);
+
+/**
+ * Set version of the QR code that is to be encoded.
+ * This function cannot be applied to Micro QR Code.ð汾ŲMicro QR Code
+ * @param input input object.
+ * @param version version number (0 = auto)
+ * @retval 0 success.
+ * @retval -1 invalid argument.
+ */
+extern int QRinput_setVersion(QRinput *input, int version);
+
+/**
+ * Get current error correction level.
+ * @param input input object.
+ * @return Current error correcntion level.
+ */
+extern QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input);
+
+/**
+ * Set error correction level of the QR code that is to be encoded.
+ * This function cannot be applied to Micro QR Code.
+ * @param input input object.
+ * @param level Error correction level.
+ * @retval 0 success.
+ * @retval -1 invalid argument.
+ */
+extern int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level);
+
+/**
+ *ڸMicro QR Code ð汾ź;
+ * Set version and error correction level of the QR code at once.
+ * This function is recommened for Micro QR Code.
+ * @param input input object.
+ * @param version version number (0 = auto)
+ * @param level Error correction level.
+ * @retval 0 success.
+ * @retval -1 invalid argument.
+ */
+extern int QRinput_setVersionAndErrorCorrectionLevel(QRinput *input, int version, QRecLevel level);
+
+/**
+ * Free the input object.
+ * All of data chunks in the input object are freed too.
+ * @param input input object.
+ */
+extern void QRinput_free(QRinput *input);
+
+/**
+ * Validate the input data.
+ * @param mode encoding mode.
+ * @param size size of data (byte).
+ * @param data a pointer to the memory area of the input data.
+ * @retval 0 success.
+ * @retval -1 invalid arguments.
+ */
+extern int QRinput_check(QRencodeMode mode, int size, const unsigned char *data);
+
+
+/**
+ * Free all of QRinput in the set.
+ * @param s a structured input object.
+ */
+
+
+/******************************************************************************
+ * QRcode output (qrencode.c)
+ *****************************************************************************/
+
+/**
+ * QRcode class.
+ * Symbol data is represented as an array contains width*width uchars.
+ * Each uchar represents a module (dot). If the less significant bitλ of
+ * the uchar is 1, the corresponding module is black. The other bits are
+ * meaningless for usual applications, but here its specification is described.
+ *
+ *
+ * MSB 76543210 LSB
+ * |||||||`- 1=black/0=white
+ * ||||||`-- data and ecc code area
+ * |||||`--- format information
+ * ||||`---- version information
+ * |||`----- timing pattern
+ * ||`------ alignment pattern
+ * |`------- finder pattern and separator
+ * `-------- non-data modules (format, timing, etc.)
+ *
+ */
+typedef struct {
+ int version; ///< version of the symbol
+ int width; ///< width of the symbol
+ unsigned char *data; ///< symbol data
+} QRcode;
+
+/**
+ * Singly-linked list of QRcode. Used to represent a structured symbols.
+ * A list is terminated with NULL.
+ */
+typedef struct _QRcode_List QRcode_List;
+
+struct _QRcode_List {
+ QRcode *code;
+ QRcode_List *next;
+};
+
+/**
+ * Create a symbol from the input data.
+ * @warning This function is THREAD UNSAFE when pthread is disabled.
+ * @param input input data.
+ * @return an instance of QRcode class. The version of the result QRcode may
+ * be larger than the designated version. On error, NULL is returned,
+ * and errno is set to indicate the error. See Exceptions for the
+ * details.
+ * @throw EINVAL invalid input object.
+ * @throw ENOMEM unable to allocate memory for input objects.
+ */
+extern QRcode *QRcode_encodeInput(QRinput *input);
+
+/**
+ * Create a symbol from the string. The library automatically parses the input
+ * string and encodes in a QR Code symbol.ַͨһţַԶַȻΪб롣
+ * @warning This function is THREAD UNSAFE when pthread is disabled.
+ * @param string input string. It must be NUL terminated.
+ * @param version version of the symbol. If 0, the library chooses the minimum
+ * version for the given input data.
+ * @param level error correction level.
+ * @param hint tell the library how non-alphanumerical characters should be
+ * encoded. If QR_MODE_KANJI is given, kanji characters will be
+ * encoded as Shif-JIS characters. If QR_MODE_8 is given, all of
+ * non-alphanumerical characters will be encoded as is. If you want
+ * to embed UTF-8 string, choose this.
+ * @param casesensitive case-sensitive(1) or not(0).
+ * @return an instance of QRcode class. The version of the result QRcode may
+ * be larger than the designated version. On error, NULL is returned,
+ * and errno is set to indicate the error. See Exceptions for the
+ * details.
+ * @throw EINVAL invalid input object.
+ * @throw ENOMEM unable to allocate memory for input objects.
+ * @throw ERANGE input data is too large.
+ */
+extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
+
+/**
+ * Same to QRcode_encodeString(), but encode whole data in 8-bit mode.
+ * @warning This function is THREAD UNSAFE when pthread is disabled.
+ */
+
+
+/**
+ * Micro QR Code version of QRcode_encodeString().
+ * @warning This function is THREAD UNSAFE when pthread is disabled.
+ */
+extern QRcode *QRcode_encodeStringMQR(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
+
+/**
+ * Encode byte stream (may include '\0') in 8-bit mode.8λģʽ¶ֽб
+ * @warning This function is THREAD UNSAFE when pthread is disabled.
+ * @param size size of the input data.
+ * @param data input data.
+ * @param version version of the symbol. If 0, the library chooses the minimum
+ * version for the given input data.
+ * @param level error correction level.
+ * @throw EINVAL invalid input object.
+ * @throw ENOMEM unable to allocate memory for input objects.
+ * @throw ERANGE input data is too large.
+ */
+extern QRcode *QRcode_encodeData(int size, const unsigned char *data, int version, QRecLevel level);
+
+/**
+ * Micro QR Code version of QRcode_encodeData().
+ * @warning This function is THREAD UNSAFE when pthread is disabled.
+ */
+extern QRcode *QRcode_encodeDataMQR(int size, const unsigned char *data, int version, QRecLevel level);
+
+/**
+ * Free the instance of QRcode class.
+ * @param qrcode an instance of QRcode class.
+ */
+extern void QRcode_free(QRcode *qrcode);
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+#endif /* __QRENCODE_H__ */
diff --git a/code/application/source/sf_app/code/include/qrencode_inner.h b/code/application/source/sf_app/code/include/qrencode_inner.h
new file mode 100755
index 000000000..8dc95f4d0
--- /dev/null
+++ b/code/application/source/sf_app/code/include/qrencode_inner.h
@@ -0,0 +1,97 @@
+/**
+ * qrencode - QR Code encoder
+ *
+ * Header for test use
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __QRENCODE_INNER_H__
+#define __QRENCODE_INNER_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+/**
+ * This header file includes definitions for test use.
+ */
+
+/******************************************************************************
+ * Raw code
+ *****************************************************************************/
+
+typedef struct {
+ int dataLength;
+ unsigned char *data;
+ int eccLength;
+ unsigned char *ecc;
+} RSblock;
+
+typedef struct {
+ int version;
+ int dataLength;
+ int eccLength;
+ unsigned char *datacode;
+ unsigned char *ecccode;
+ int b1;
+ int blocks;
+ RSblock *rsblock;
+ int count;
+} QRRawCode;
+
+extern QRRawCode *QRraw_new(QRinput *input);
+extern unsigned char QRraw_getCode(QRRawCode *raw);
+extern void QRraw_free(QRRawCode *raw);
+
+/******************************************************************************
+ * Raw code for Micro QR Code
+ *****************************************************************************/
+
+typedef struct {
+ int version;
+ int dataLength;
+ int eccLength;
+ unsigned char *datacode;
+ unsigned char *ecccode;
+ RSblock *rsblock;
+ int oddbits;
+ int count;
+} MQRRawCode;
+
+extern MQRRawCode *MQRraw_new(QRinput *input);
+extern unsigned char MQRraw_getCode(MQRRawCode *raw);
+extern void MQRraw_free(MQRRawCode *raw);
+
+/******************************************************************************
+ * Frame filling
+ *****************************************************************************/
+
+
+/******************************************************************************
+ * QR-code encoding
+ *****************************************************************************/
+extern QRcode *QRcode_encodeMask(QRinput *input, int mask);
+extern QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask);
+extern QRcode *QRcode_new(int version, int width, unsigned char *data);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __QRENCODE_INNER_H__ */
diff --git a/code/application/source/sf_app/code/include/qrinput.h b/code/application/source/sf_app/code/include/qrinput.h
new file mode 100755
index 000000000..8a73402ea
--- /dev/null
+++ b/code/application/source/sf_app/code/include/qrinput.h
@@ -0,0 +1,132 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Input data chunk class
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __QRINPUT_H__
+#define __QRINPUT_H__
+
+#include "qrencode.h"
+#include "bitstream.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+int QRinput_isSplittableMode(QRencodeMode mode);
+
+/******************************************************************************
+ * Entry of input data
+ *****************************************************************************/
+typedef struct _QRinput_List QRinput_List;
+
+struct _QRinput_List {
+ QRencodeMode mode;
+ int size; ///< Size of data chunk (byte).
+ unsigned char *data; ///< Data chunk.
+ BitStream *bstream;
+ QRinput_List *next;
+};
+
+/******************************************************************************
+ * Input Data
+ *****************************************************************************/
+struct _QRinput {
+ int version;
+ QRecLevel level;
+ QRinput_List *head;
+ QRinput_List *tail;
+ int mqr;
+ int fnc1;
+ unsigned char appid;
+};
+
+/******************************************************************************
+ * Structured append input data
+ *****************************************************************************/
+typedef struct _QRinput_InputList QRinput_InputList;
+
+struct _QRinput_InputList {
+ QRinput *input;
+ QRinput_InputList *next;
+};
+
+struct _QRinput_Struct {
+ int size; ///< number of structured symbols
+ int parity;
+ QRinput_InputList *head;
+ QRinput_InputList *tail;
+};
+
+/**
+ * Pack all bit streams padding bits into a byte array.
+ * @param input input data.
+ * @return padded merged byte stream
+ */
+extern unsigned char *QRinput_getByteStream(QRinput *input);
+
+
+extern int QRinput_estimateBitsModeNum(int size);
+extern int QRinput_estimateBitsModeAn(int size);
+extern int QRinput_estimateBitsMode8(int size);
+extern int QRinput_estimateBitsModeKanji(int size);
+
+extern QRinput *QRinput_dup(QRinput *input);
+
+extern const signed char QRinput_anTable[128];
+
+/**
+ * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
+ * @param __c__ character
+ * @return value
+ */
+#define QRinput_lookAnTable(__c__) \
+ ((__c__ & 0x80)?-1:QRinput_anTable[(int)__c__])
+
+/**
+ * Length of a standard mode indicator in bits.
+ */
+
+#define MODE_INDICATOR_SIZE 4
+
+/**
+ * Length of a segment of structured-append header.
+ */
+#define STRUCTURE_HEADER_SIZE 20
+
+/**
+ * Maximum number of symbols in a set of structured-appended symbols.
+ */
+#define MAX_STRUCTURED_SYMBOLS 16
+
+#ifdef WITH_TESTS
+extern BitStream *QRinput_mergeBitStream(QRinput *input);
+extern BitStream *QRinput_getBitStream(QRinput *input);
+extern int QRinput_estimateBitStreamSize(QRinput *input, int version);
+extern int QRinput_lengthOfCode(QRencodeMode mode, int version, int bits);
+extern int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity);
+#endif
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __QRINPUT_H__ */
diff --git a/code/application/source/sf_app/code/include/qrspec.h b/code/application/source/sf_app/code/include/qrspec.h
new file mode 100755
index 000000000..78d9deb46
--- /dev/null
+++ b/code/application/source/sf_app/code/include/qrspec.h
@@ -0,0 +1,190 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * QR Code specification in convenient format.
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __QRSPEC_H__
+#define __QRSPEC_H__
+
+#include "qrencode.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+/******************************************************************************
+ * Version and capacity
+ *****************************************************************************/
+
+/**
+ * Maximum width of a symbol
+ */
+#define QRSPEC_WIDTH_MAX 177
+
+/**
+ * Return maximum data code length (bytes) for the version.
+ * @param version
+ * @param level
+ * @return maximum size (bytes)
+ */
+extern int QRspec_getDataLength(int version, QRecLevel level);
+
+/**
+ * Return maximum error correction code length (bytes) for the version.
+ * @param version
+ * @param level
+ * @return ECC size (bytes)
+ */
+extern int QRspec_getECCLength(int version, QRecLevel level);
+
+/**
+ * Return a version number that satisfies the input code length.
+ * @param size input code length (byte)
+ * @param level
+ * @return version number
+ */
+extern int QRspec_getMinimumVersion(int size, QRecLevel level);
+
+/**
+ * Return the width of the symbol for the version.
+ * @param version
+ * @return width
+ */
+extern int QRspec_getWidth(int version);
+
+/**
+ * Return the numer of remainder bits.
+ * @param version
+ * @return number of remainder bits
+ */
+extern int QRspec_getRemainder(int version);
+
+/******************************************************************************
+ * Length indicator
+ *****************************************************************************/
+
+/**
+ * Return the size of lenght indicator for the mode and version.
+ * @param mode
+ * @param version
+ * @return the size of the appropriate length indicator (bits).
+ */
+extern int QRspec_lengthIndicator(QRencodeMode mode, int version);
+
+/**
+ * Return the maximum length for the mode and version.
+ * @param mode
+ * @param version
+ * @return the maximum length (bytes)
+ */
+extern int QRspec_maximumWords(QRencodeMode mode, int version);
+
+/******************************************************************************
+ * Error correction code
+ *****************************************************************************/
+
+/**
+ * Return an array of ECC specification.
+ * @param version
+ * @param level
+ * @param spec an array of ECC specification contains as following:
+ * {# of type1 blocks, # of data code, # of ecc code,
+ * # of type2 blocks, # of data code}
+ */
+void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]);
+
+#define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3])
+#define QRspec_rsBlockNum1(__spec__) (__spec__[0])
+#define QRspec_rsDataCodes1(__spec__) (__spec__[1])
+#define QRspec_rsEccCodes1(__spec__) (__spec__[2])
+#define QRspec_rsBlockNum2(__spec__) (__spec__[3])
+#define QRspec_rsDataCodes2(__spec__) (__spec__[4])
+#define QRspec_rsEccCodes2(__spec__) (__spec__[2])
+
+#define QRspec_rsDataLength(__spec__) \
+ ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \
+ (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__)))
+#define QRspec_rsEccLength(__spec__) \
+ (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__))
+
+/******************************************************************************
+ * Version information pattern
+ *****************************************************************************/
+
+/**
+ * Return BCH encoded version information pattern that is used for the symbol
+ * of version 7 or greater. Use lower 18 bits.
+ * @param version
+ * @return BCH encoded version information pattern
+ */
+extern unsigned int QRspec_getVersionPattern(int version);
+
+/******************************************************************************
+ * Format information
+ *****************************************************************************/
+
+/**
+ * Return BCH encoded format information pattern.
+ * @param mask
+ * @param level
+ * @return BCH encoded format information pattern
+ */
+extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level);
+
+/******************************************************************************
+ * Frame
+ *****************************************************************************/
+
+/**
+ * Return a copy of initialized frame.
+ * When the same version is requested twice or more, a copy of cached frame
+ * is returned.
+ * @param version
+ * @return Array of unsigned char. You can free it by free().
+ */
+extern unsigned char *QRspec_newFrame(int version);
+
+/**
+ * Clear the frame cache. Typically for debug.
+ */
+extern void QRspec_clearCache(void);
+
+/******************************************************************************
+ * Mode indicator
+ *****************************************************************************/
+
+/**
+ * Mode indicator. See Table 2 of JIS X0510:2004, pp.16.
+ */
+#define QRSPEC_MODEID_ECI 7
+#define QRSPEC_MODEID_NUM 1
+#define QRSPEC_MODEID_AN 2
+#define QRSPEC_MODEID_8 4
+#define QRSPEC_MODEID_KANJI 8
+#define QRSPEC_MODEID_FNC1FIRST 5
+#define QRSPEC_MODEID_FNC1SECOND 9
+#define QRSPEC_MODEID_STRUCTURE 3
+#define QRSPEC_MODEID_TERMINATOR 0
+ #ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+#endif /* __QRSPEC_H__ */
diff --git a/code/application/source/sf_app/code/include/rscode.h b/code/application/source/sf_app/code/include/rscode.h
new file mode 100755
index 000000000..09a243d2c
--- /dev/null
+++ b/code/application/source/sf_app/code/include/rscode.h
@@ -0,0 +1,51 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Reed solomon encoder. This code is taken from Phil Karn's libfec then
+ * editted and packed into a pair of .c and .h files.
+ *
+ * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
+ * (libfec is released under the GNU Lesser General Public License.)
+ *
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __RSCODE_H__
+#define __RSCODE_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+/*
+ * General purpose RS codec, 8-bit symbols.
+ */
+
+typedef struct _RS RS;
+
+extern RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad);
+extern void encode_rs_char(RS *rs, const unsigned char *data, unsigned char *parity);
+extern void free_rs_char(RS *rs);
+extern void free_rs_cache(void);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __RSCODE_H__ */
diff --git a/code/application/source/sf_app/code/include/sf_aes.h b/code/application/source/sf_app/code/include/sf_aes.h
new file mode 100755
index 000000000..8b2125c8a
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_aes.h
@@ -0,0 +1,34 @@
+#ifndef __SF_AES_H
+#define __SF_AES_H
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_type.h"
+
+
+//UINT32 sf_cipher(UINT32 aesType,UINT8 operation,UINT8 *input,UINT8 *output);
+UINT32 sf_cipher(UINT32 aesType,UINT8 operation,UINT8 *input,UINT8 *output, UINT8 srcl);
+
+
+
+extern void sf_cipher_test(void);
+extern void sf_cipher_test1(void);
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
+
+
+
+
+
+
diff --git a/code/lib/source/sifar/code/include/sf_base64.h b/code/application/source/sf_app/code/include/sf_base64.h
similarity index 100%
rename from code/lib/source/sifar/code/include/sf_base64.h
rename to code/application/source/sf_app/code/include/sf_base64.h
diff --git a/code/application/source/sf_app/code/include/sf_bmp.h b/code/application/source/sf_app/code/include/sf_bmp.h
new file mode 100755
index 000000000..651832030
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_bmp.h
@@ -0,0 +1,47 @@
+/**************************************************************************
+ *
+ * Copyright (c) 2015-2020 by WuYuan Technology, Inc.
+ *
+ * This software is copyrighted by and is the property of SiFar
+ * Technology, Inc.. All rights are reserved by SiFar Technology, Inc..
+ * This software may only be used in accordance with the corresponding
+ * license agreement. Any unauthorized use, duplication, distribution,
+ * or disclosure of this software is expressly forbidden.
+ *
+ * This Copyright notice MUST not be removed or modified without prior
+ * written consent of SiFar Technology, Inc..
+ *
+ * WuYuan Technology, Inc. reserves the right to modify this software without notice.
+ *
+ * Author: jiamin
+ * Ver: 1.0.0 2021.04.15
+ * Description: creat
+**************************************************************************/
+#ifndef _SF_BMP_H_
+#define _SF_BMP_H_
+#include "qrencode.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+typedef struct sfBMP_DATA_S
+{
+ int width; //width of the symbol
+ int height; //height of the symbol
+ unsigned char *data; //symbol data
+
+} SF_BMP_DATA_S;
+
+
+int sf_qrcode_bmpfile_write(QRcode *DataInfo, const char *outfile, int magnification);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
+
diff --git a/code/application/source/sf_app/code/include/sf_commMng.h b/code/application/source/sf_app/code/include/sf_commMng.h
new file mode 100755
index 000000000..801112396
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_commMng.h
@@ -0,0 +1,39 @@
+#ifndef __SF_COMMMNG_H__
+#define __SF_COMMMNG_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+
+
+SINT32 sf_sem_init(SF_CHAR *pathname,SINT32 *psemid);
+
+SINT32 sf_sem_down(SINT32 semid, SINT32 who);
+
+SINT32 sf_sem_up(SINT32 semid, SINT32 who);
+
+SINT32 sf_sem_deinit(SINT32 semid);
+
+SINT32 sf_share_mem_file_init(void);
+
+SINT32 sf_share_mem_file_deinit(void);
+
+SINT32 sf_share_mem_customer_init(void);
+
+SINT32 sf_share_mem_customer_deinit(void);
+
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
diff --git a/code/application/source/sf_app/code/include/sf_commu_mcu.h b/code/application/source/sf_app/code/include/sf_commu_mcu.h
new file mode 100755
index 000000000..3b1467c75
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_commu_mcu.h
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * Copyright (c) 2015-2020 by WuYuan Technology, Inc.
+ *
+ * This software is copyrighted by and is the property of SiFar
+ * Technology, Inc.. All rights are reserved by SiFar Technology, Inc..
+ * This software may only be used in accordance with the corresponding
+ * license agreement. Any unauthorized use, duplication, distribution,
+ * or disclosure of this software is expressly forbidden.
+ *
+ * This Copyright notice MUST not be removed or modified without prior
+ * written consent of SiFar Technology, Inc..
+ *
+ * WuYuan Technology, Inc. reserves the right to modify this software without notice.
+ *
+ * Author: ljy
+ * Ver: 1.0.0 2022.06.15
+ * Description: creat
+**************************************************************************/
+
+#ifndef __SF_COMMU_MCU_H
+#define __SF_COMMU_MCU_H
+
+#ifdef __cplusplus
+extern "C"{
+#endif // __cplusplus
+#include
+
+#define SERIAL_DEVICE_PATH "/dev/ttyS2"
+#define BUF_REG_SIZE (REG_SIZE*2+8)
+
+typedef struct {
+ unsigned char buf[BUF_REG_SIZE];
+ unsigned int index;
+}SMAPBUF_t;
+
+
+void mcubuf_reset(void);
+int sf_commu_mcu_interface_init(int speed, char flow_ctrl, int databits, int stopbits, char parity);
+int sf_commu_mcu_open(void);
+int sf_commu_mcu_close(void);
+int sf_commu_write(unsigned char * buf, int len);
+int sf_commu_read(unsigned char * buf, int len);
+int sf_set_mcu_reg(unsigned char reg, unsigned char val);
+int sf_get_mcu_reg(unsigned char reg);
+unsigned int sf_set_mcu_reg_ack_depack(unsigned int * address, unsigned int * value);
+unsigned int sf_get_mcu_reg_ack_depack(unsigned int * address, unsigned int * value);
+int sf_commu_wait(unsigned char cmd);
+void sf_commu_reset(void);
+int sf_commu_set_mcu(unsigned char reg, unsigned char val);
+int sf_commu_get_mcu(unsigned char reg);
+int sf_getRegFromMcu_depack(unsigned char * dataToParse, unsigned int datalen, unsigned char * regAddr, unsigned char * regVal);
+int sf_getRegFromMcu_ack(unsigned char regAddr, unsigned char regVal);
+unsigned char sf_commu_parse_mcu_data(unsigned char * src, unsigned int len);
+void sf_commu_mcu_task_start(void);
+void sf_commu_mcu_task_stop(void);
+unsigned char sf_commu_mcu_task_running(void);
+unsigned int sf_get_mcu_reg_ack_depack_many(unsigned char reg[], unsigned char val[], unsigned int * num);
+int sf_set_mcu_reg_many(unsigned char reg[], unsigned char val[], unsigned int num);
+int sf_get_mcu_reg_many(unsigned char reg[], unsigned int num);
+int sf_commu_set_mcu_many(unsigned char reg[], unsigned char val[], unsigned int *num);
+int sf_commu_get_mcu_many(unsigned char reg[], unsigned char val[], unsigned int *num);
+
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+
+
+#endif
diff --git a/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h b/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h
new file mode 100755
index 000000000..2475ee3ea
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_commu_mcu_reg.h
@@ -0,0 +1,349 @@
+#ifndef __SF_COMMU_MCU_REG_H
+#define __SF_COMMU_MCU_REG_H
+
+/**************************************************************************
+ *
+ * Copyright (c) 2009-2018 by SiFar Technology, Inc.
+ *
+ * This software is copyrighted by and is the property of SiFar
+ * Technology, Inc.. All rights are reserved by SiFar Technology, Inc..
+ * This software may only be used in accordance with the corresponding
+ * license agreement. Any unauthorized use, duplication, distribution,
+ * or disclosure of this software is expressly forbidden.
+ *
+ * This Copyright notice MUST not be removed or modified without prior
+ * written consent of SiFar Technology, Inc..
+ *
+ * SiFar Technology, Inc. reserves the right to modify this software without notice.
+ *
+ * Author: oliver
+ * Ver: 1.0.0 2019.06.06
+ * Description:
+**************************************************************************/
+#ifndef _SF_MCU_H_
+#define _SF_MCU_H_
+
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+
+#define DIGITAL_PIR 1
+
+#define REG_SIZE 91
+
+#define SF_MCU_NIGHT_MODE_LUMINANCE 380
+
+/*REG POWER_OFFON*/
+#define MCU_MODE_AUTO 0x00
+#define MCU_MODE_OFF 0x40
+#define MCU_MODE_SETUP 0x80
+
+#define PWR_OFF 0x00
+#define PWR_ON_SETUP 0x01
+#define PWR_ON_TIMELAPSE 0x02
+#define PWR_ON_AUTO 0x03
+#define PWR_ON_SMS 0x04
+#define PWR_ON_PIR 0x05
+#define PWR_ON_LBAT 0x06
+#define PWR_ON_SERVER 0x07
+#define PWR_ON_DAILY_REPORT 0x08
+#define PWR_ON_USB 0x09
+#define PWR_ON_GPRS_INIT 0x0A
+#define PWR_ON_TIME_SYNC 0x0B
+#define PWR_ON_TIME_SEND 0x0C
+
+/*REG FUNCTION_SWTICH*/
+#define PIR_OFF 0x00
+#define PIR_ON 0x01
+#define TIMELAPSE_ON 0x02
+#define PIR_DELAY_ON 0x04
+#define TIME_SYNC_ON 0x08
+#define DAILY_REPORT_ON 0x10
+#define DAILY_SEND1_ON 0x20
+#define DAILY_SEND2_ON 0x40
+#define GPS_ALWAYS_ON 0x80
+
+/*REG FUNCTION_SWTICH1*/
+#define DAILY_SEND3_ON 0x01
+#define DAILY_SEND4_ON 0x02
+
+/*REG FUNCTION_SWTICH2*/
+#define WDT_OFF 0x01
+#define DEBUG_MODE_ON 0x02
+
+/*REG GPS_POWER_TIMER_CLEAR */
+#define GPS_COUNTDOWM_RESET 0x01
+
+/*REG GPS_POWER_CTRL */
+#define GPS_PWR_ON 0x01
+
+/*REG PIR_SENSITIVITY*/
+#define DIGITAL_PIR_SENSITIVITY_MASK 0xFF
+#define GPRS_ON 0x80
+#define GPRS_MODE_MASK 0x60
+#define GPRS_DAILY 0x00
+#define GPRS_INSTANT 0x40
+#define GPRS_HYBRID 0x20
+#define TIME_SYNC_RESET 0x10
+#define PIR_SEN_HIGH 0x00
+#define PIR_SEN_MIDDLE 0x01
+#define PIR_SEN_LOW 0x02
+
+/*REG DSP_BUSY*/
+#define DSP_BUSY 0x01
+#define DSP_IDLE 0x00
+
+/*REG SYS_STATUS*/
+#define SYS_SD_INSERT 0x01
+#define SYS_MENORY_FULL 0x02
+#define SYS_USB_INSERT 0x04
+#define SYS_SOFT_UPDATE 0x08
+#define GPRS_RESTART 0x10
+#define POWER_CYCLE 0x20
+#define SYS_CAM_OFF 0x40
+#define PIR_RESTART 0x80
+
+/*REG POWEROFF_TYPE*/
+#define PWROFF_NOUSE 0x00
+#define PWROFF_GPRS_INIT 0x01
+#define PWROFF_SMS_RESTART 0x02
+#define PWROFF_LBAT 0x40
+#define PWROFF_TIMEOUT 0x80
+
+typedef enum
+{
+ MCU_SUB_VER = 0,
+ MCU_VER_L = 1,
+ MCU_VER_H = 2,
+ MCU_PRODUCT_INFO = 3,
+ START_MODE = 4,
+ LUMINANCE_L = 5,
+ LUMINANCE_H = 6,
+ RESERVER1 = 7,
+
+ SF_RTC_YEAR = 8,
+ SF_RTC_MONTH = 9,
+ SF_RTC_DAY = 10,
+ SF_RTC_HOUR = 11,
+ SF_RTC_MINUTE = 12,
+ SF_RTC_SEC = 13,
+ SF_RTC_WEEK = 14,
+ FUNCTION_SWTICH0 = 15,
+ FUNCTION_SWTICH1 = 16,
+ FUNCTION_SWTICH2 = 17,
+ RESERVER2 = 18,
+
+ GPS_POWER_TIMER_CLEAR = 19,
+ GPS_POWER_CTRL = 20,
+ ANALOG_PIR_SENSITIVITY = 21,
+ DIGITAL_PIR_SENSITIVITY= 22,
+ DIGITAL_PIR_CFG = 23,
+ DSP_BUSY_STATUS = 24,
+ SYS_STATUS = 25,
+ RESERVER3 = 26,
+
+ POWEROFF_TYPE = 27,
+ WDT_TIME = 28,
+ VBAT_LOW_WARN_VAL = 29,
+ VBAT_RECOVER_VAL = 30,
+ RESERVER4 = 31,
+
+ TIMELAPSE_HOUR = 32,
+ TIMELAPSE_MINUTE = 33,
+ TIMELAPSE_SEC = 34,
+ PIR_DELAY_HOUR = 35,
+ PIR_DELAY_MINUTE = 36,
+ PIR_DELAY_SEC = 37,
+ TIME_SYNC_HOUR = 38,
+ TIME_SYNC_MINUTE = 39,
+ TIME_SYNC_SEC = 40,
+ DAILY_REPORT_HOUR = 41,
+ DAILY_REPORT_MINUTE = 42,
+ DAILY_SEND1_HOUR = 43,
+ DAILY_SEND1_MINUTE = 44,
+ DAILY_SEND2_HOUR = 45,
+ DAILY_SEND2_MINUTE = 46,
+ DAILY_SEND3_HOUR = 47,
+ DAILY_SEND3_MINUTE = 48,
+ DAILY_SEND4_HOUR = 49,
+ DAILY_SEND4_MINUTE = 50,
+ RESERVER5 = 51,
+ RESERVER6 = 52,
+ RESERVER7 = 53,
+
+ WORKTIME1_SWITCH = 54,
+ WORKTIME1_START_HOUR = 55,
+ WORKTIME1_START_MINUTE = 56,
+ WORKTIME1_STOP_HOUR = 57,
+ WORKTIME1_STOP_MINUTE = 58,
+
+ WORKTIME2_SWITCH = 59,
+ WORKTIME2_START_HOUR = 60,
+ WORKTIME2_START_MINUTE = 61,
+ WORKTIME2_STOP_HOUR = 62,
+ WORKTIME2_STOP_MINUTE = 63,
+
+ WORKTIME3_SWITCH = 64,
+ WORKTIME3_START_HOUR = 65,
+ WORKTIME3_START_MINUTE = 66,
+ WORKTIME3_STOP_HOUR = 67,
+ WORKTIME3_STOP_MINUTE = 68,
+
+ WORKTIME4_SWITCH = 69,
+ WORKTIME4_START_HOUR = 70,
+ WORKTIME4_START_MINUTE = 71,
+ WORKTIME4_STOP_HOUR = 72,
+ WORKTIME4_STOP_MINUTE = 73,
+
+ WORKTIME5_SWITCH = 74,
+ WORKTIME5_START_HOUR = 75,
+ WORKTIME5_START_MINUTE = 76,
+ WORKTIME5_STOP_HOUR = 77,
+ WORKTIME5_STOP_MINUTE = 78,
+
+ WORKTIME6_SWITCH = 79,
+ WORKTIME6_START_HOUR = 80,
+ WORKTIME6_START_MINUTE = 81,
+ WORKTIME6_STOP_HOUR = 82,
+ WORKTIME6_STOP_MINUTE = 83,
+
+ DSP_WRITE_FLG = 84,
+
+ RESERVER8 = 85,
+ RESERVER9 = 86,
+ RESERVER10 = 87,
+ RESERVER11 = 88,
+ RESERVER12 = 89,
+ RESERVER13 = 90,
+}PARA_REG;
+
+
+
+typedef enum {
+ POWEROFF_COUNTDOWN = 1,
+ POWEROFF_PVDOWN,
+ POWEROFF_KEYDOWN,
+ POWEROFF_KEYREBOOT,
+ POWEROFF_GPRSREBOOT,
+ POWEROFF_KEYOFF
+}POWEROFF_MODE;
+
+
+typedef enum {
+ SF_MCU_STARTMODE = 0,
+ SF_MCU_POWERON,
+ SF_MCU_POWEROFF,
+ SF_MCU_CTRL_MODULE_PIR,
+ SF_MCU_PARA,
+ SF_MCU_RESET_MODULE,
+ SF_MCU_SOFT_UPDATE,
+ SF_MCU_POWER_RESTART,
+ SF_MCU_PIR_RESTART,
+ SF_MCU_TEST_PIR,
+ SF_MCU_PARAM_MAX
+} MCUParam_t;
+
+
+typedef enum {
+ TRIG_MOTION = 1,
+ TRIG_TIMELAPSE,
+ TRIG_SETUP,
+ TRIG_COMMOND,
+}TRIG_TYPE;
+
+
+typedef enum {
+ WORKING_TIME_0 = 0,
+ WORKING_TIME_1,
+ WORKING_TIME_2,
+ WORKING_TIME_3,
+ WORKING_TIME_4,
+ WORKING_TIME_5,
+ WORKING_TIME_ALL = 0xff,
+}WORKING_TIME_TYPE;
+#if 0
+typedef enum sfMCU_STARTUP_TYPE_E
+{
+ SF_MCU_STARTUP_OFF = 0x00,/* POWER OFF*/
+ SF_MCU_STARTUP_ONKEY = 0x01,/*key on SETUP*/
+ SF_MCU_STARTUP_TIMELAPSE = 0x02,/*timelapse power on*/
+ SF_MCU_STARTUP_NORMAL = 0x03,/*Dial the key to ON*/
+ SF_MCU_STARTUP_RING = 0x04,/*ring power on*/
+ SF_MCU_STARTUP_PIR = 0x05,/*pir power on*/
+ SF_MCU_STARTUP_WARNING = 0x06,/*low bat worning power on*/
+ SF_MCU_STARTUP_SERVER = 0x07,/*server power on(reserve)*/
+ SF_MCU_STARTUP_DP = 0x08,/*DailyReport power on*/
+ SF_MCU_STARTUP_USB = 0x09,/*USB power on*/
+ SF_MCU_STARTUP_RESET = 0x0A,/*power on to reset(reserve)*/
+ SF_MCU_STARTUP_SYN_PARAM = 0x0B,/*power on to syn param(reserve)*/
+ SF_MCU_STARTUP_BATCH_SEND= 0x0C,/*power on to send batch*/
+ SF_MCU_STARTUP_BUTT = 0X0D,
+} SF_STARTUP_TYPE_E;
+
+typedef enum sfPOWEROFF_TYPE_E
+{
+ SF_POWEROFF_NORMAL = 0x00,
+ SF_POWEROFF_AUTO = 0x01, /*auto power when 3min no operation*/
+ SF_POWEROFF_REBOOT = 0x02, /*poweroff to reboot*/
+ SF_POWEROFF_KEYON = 0x03,
+ SF_POWEROFF_KEYOFF = 0x04,
+ SF_POWEROFF_SYNC_PARAM = 0x05,
+ SF_POWEROFF_GPS_DP = 0x06,
+ SF_POWEROFF_SD_FULL = 0x07,
+ SF_POWEROFF_LOW_BAT = 0x08,
+ SF_POWEROFF_NO_SD = 0x09,
+ SF_POWEROFF_BUTT,
+} SF_POWEROFF_TYPE_E;
+#endif
+typedef struct sf_TIME_S {
+ unsigned short Year; /* Year > 1970*/
+ unsigned short Mon; /* Mon range[1-12]*/
+ unsigned short Day; /*Day range[1-31]*/
+ unsigned short Hour; /*Hour range[0-23]*/
+ unsigned short Min; /*Min range[0-59]*/
+ unsigned short Sec; /*Sec range[0-59]*/
+} SF_TIME_S;
+
+unsigned char sf_mcu_power_on_para_get (MCUParam_t attrId);
+unsigned char sf_mcu_wdg_set(unsigned char value);
+void sf_mcu_poweron_4g_module(void);
+unsigned char sf_mcu_start_mode_get(void);
+
+SF_BOOL sf_is_night_mode(unsigned int isRefresh);
+unsigned char sf_mcu_rtc_get (SF_TIME_S *time);
+unsigned char sf_mcu_reg_set(MCUParam_t attrId, unsigned char val);
+void sf_set_mcu_sub_ver(unsigned char mcuSubVersion);
+void sf_set_mcu_ver(unsigned short mcuVersion);
+unsigned short sf_get_light_value(void);
+unsigned char sf_get_mcu_sub_ver(void);
+unsigned short sf_get_mcu_ver(void);
+
+int sf_get_ae_shutter(void);
+int sf_get_ae_sensor_gain(void);
+
+
+int sf_set_ae_shutter(unsigned int value);
+
+int sf_set_ae_sensor_gain(unsigned int value);
+
+
+int sf_set_cur_light_val(unsigned int value);
+
+int sf_get_last_light_val(void);
+SF_TIME_S sf_get_mcu_poweroff_date(void);
+void sf_set_mcu_poweroff_date(SF_PARA_TIME_S date);
+
+
+extern unsigned char PowerOnMode;
+extern unsigned short TrigType;
+
+
+#endif
+
+
+
+
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/include/sf_dataMng.h b/code/application/source/sf_app/code/include/sf_dataMng.h
new file mode 100755
index 000000000..b63c7c95a
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_dataMng.h
@@ -0,0 +1,90 @@
+
+#ifndef __SF_DATA_PROC_H__
+#define __SF_DATA_PROC_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+
+typedef enum SF_CMD_QUERYPENDING_E {
+
+ SF_CMD_QUERYPENDING_GETCFGFILE = 0X2000,
+ SF_CMD_QUERYPENDING_GETPICTURE = 0X2002,
+ SF_CMD_QUERYPENDING_GETSTATUS = 0X2004,
+ SF_CMD_QUERYPENDING_GETSLEEPTIME = 0X2006,
+ SF_CMD_QUERYPENDING_REBOOT = 0X2008,
+ SF_CMD_QUERYPENDING_SETSYSTEMTIME = 0X200A,
+ SF_CMD_QUERYPENDING_SETCAMERAMODE = 0X200C,
+ SF_CMD_QUERYPENDING_SETWORKMODE = 0X200E,
+ SF_CMD_QUERYPENDING_SETOTHER = 0X2010,
+ SF_CMD_QUERYPENDING_SETSERVER = 0X2012,
+ SF_CMD_QUERYPENDING_UPLOADCFGFILE = 0X2014,
+ SF_CMD_QUERYPENDING_GETCAMERAMODE = 0X2016,
+ SF_CMD_QUERYPENDING_GETMODECFG = 0X2018,
+ SF_CMD_QUERYPENDING_GETOTHERCFG = 0X201A,
+ SF_CMD_QUERYPENDING_GETSERVERPAREAM = 0X201C,
+ SF_CMD_QUERYPENDING_SETUPLOADPICSIZE = 0X201E,
+ SF_CMD_QUERYPENDING_GETUPLOADPICSIZE = 0X2020,
+ SF_CMD_QUERYPENDING_SYNPARAM = 0X2022,
+ SF_CMD_QUERYPENDING_VERSIONUPDATE = 0X2024,
+ SF_CMD_QUERYPENDING_GETGPSINFO = 0X2026,
+ SF_CMD_QUERYPENDING_SETGPSANTITHIEF = 0X2028,
+
+ SF_QUERYPENDING_COMMAND_RESET = 0X202A,
+ SF_QUERYPENDING_COMMAND_GETPICFLAG = 0X202C,
+ SF_QUERYPENDING_COMMAND_FORMAT = 0X202E,
+ SF_QUERYPENDING_COMMAND_BUTT = 0X2030,
+
+
+ }SF_CMD_QUERYPENDING_E;
+UINT16 crcCheck( UINT8 strContent[],UINT16 usDataLen,UINT16 crc);
+UINT16 makeCrc(UINT8 strContent[], UINT16 len);
+
+ void sf_data_subscribe_result_set(UINT16 ret);
+
+ UINT8 sf_data_has_command_get(void);
+
+ UINT8 sf_data_transfer_mode_get(void);
+
+ SINT32 sf_data_cam_local_time_get(SF_PARA_TIME_S* pstdata);
+
+ UINT32 sf_data_pendingcmd_get(void);
+
+
+SINT32 sf_data_grouping_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+SINT32 sf_data_grouping_fileresult(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam,SF_VOID *pstfileAttr);
+
+SINT32 sf_data_grouping_disconnection(SF_DATA_ATTR_S *pstdata,SF_VOID *Param);
+SINT32 sf_data_grouping_query_cmd(SF_DATA_ATTR_S *pstdata);
+SINT32 sf_data_grouping_query_cmd_param(SF_DATA_ATTR_S *pstdata);
+SINT32 sf_data_grouping_cmd_report(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam, SF_FILE_ATTR_S *pstfileAttr);
+SINT32 sf_data_grouping_get_bind_account(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+SINT32 sf_data_grouping_sync_cfg(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_data_analysis_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+SINT32 sf_data_analysis_fileresult(SF_DATA_ATTR_S *param);
+SINT32 sf_data_analysis_query_cmd(SF_DATA_ATTR_S *param);
+SINT32 sf_data_analysis_query_cmd_param(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+SINT32 sf_data_analysis_cmd_report(SF_DATA_ATTR_S *param);
+SINT32 sf_data_analysis_bind_account(SF_DATA_ATTR_S *pstdata,SF_FN_PARAM_S *pfnParam);
+SINT32 sf_data_analysis_trigger(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+SINT32 sf_data_analysis_sync_cfg(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+
+SF_PARA_TIME_S* sf_server_time_get(void);
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+#endif
+
diff --git a/code/application/source/sf_app/code/include/sf_datahttp.h b/code/application/source/sf_app/code/include/sf_datahttp.h
new file mode 100755
index 000000000..2bb83e75a
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_datahttp.h
@@ -0,0 +1,56 @@
+
+#ifndef __SF_TRANSDATA1_H__
+#define __SF_TRANSDATA1_H__
+
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+#define SF_DATA_ERROR_REQUEST SF_ERR_ID(SF_MOD_DATA, ERROR_REQUEST)
+#define SF_DATA_ERROR_FILE_SEND SF_ERR_ID(SF_MOD_DATA, ERROR_FILE_SEND)
+#define SF_DATA_ERROR_IP_CHANGE SF_ERR_ID(SF_MOD_DATA, ERROR_IP_CHANGE)
+#define SF_DATA_ERROR_DATA_FORMAT SF_ERR_ID(SF_MOD_DATA, ERROR_DATA_FORMAT)
+
+typedef struct
+{
+ char fileName[64];
+ int fileType;
+}SF_RESERVE_THUMB;
+extern LOGIN_ACM_RESPONSE_S stLoginAcmResponse;
+
+SINT32 sf_net_packetgrouping_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+SINT32 sf_net_packetgrouping_fileresult(SF_DATA_ATTR_S *pstdata, SF_PDT_PARAM_STATISTICS_S *pStaticParam,SF_REPORT_FILE_ATTR_S *pstfileAttr);
+
+SINT32 sf_net_packetgrouping_sync(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_net_packetgrouping_disconnection(SF_DATA_ATTR_S *pstdata,SF_VOID *Param);
+
+SINT32 sf_net_packetanalysis_login(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_net_packetanalysis_fileresult(SF_DATA_ATTR_S *param);
+
+SINT32 sf_net_packetanalysis_sync(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam);
+
+LOGIN_ACM_RESPONSE_S* sf_get_login_reponse(void);
+
+SF_REPORT_FILE_ATTR_S* sf_get_sub_report_file_attr(void);
+
+SF_REPORT_FILE_ATTR_S* sf_get_thm_report_file_attr(void);
+
+
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
diff --git a/code/application/source/sf_app/code/include/sf_debug.h b/code/application/source/sf_app/code/include/sf_debug.h
new file mode 100755
index 000000000..a7367ceb1
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_debug.h
@@ -0,0 +1,68 @@
+/**************************************************************************
+ *
+ * Copyright (c) 2015-2020 by WuYuan Technology, Inc.
+ *
+ * This software is copyrighted by and is the property of SiFar
+ * Technology, Inc.. All rights are reserved by SiFar Technology, Inc..
+ * This software may only be used in accordance with the corresponding
+ * license agreement. Any unauthorized use, duplication, distribution,
+ * or disclosure of this software is expressly forbidden.
+ *
+ * This Copyright notice MUST not be removed or modified without prior
+ * written consent of SiFar Technology, Inc..
+ *
+ * WuYuan Technology, Inc. reserves the right to modify this software without notice.
+ *
+ * Author: Kola
+ * Ver: 1.0.0 2021.04.15
+ * Description: create
+**************************************************************************/
+#ifndef _SF_DEBUG_H_
+#define _SF_DEBUG_H_
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+typedef SINT32 (*SF_DEBUG_CALLBACK_FN_PTR)(SINT32 argc, SF_CHAR **argv[]);
+
+typedef struct SF_DEBUG_CMD_ATTR_S {
+
+ SF_CHAR cmdStr[64];
+ SF_DEBUG_CALLBACK_FN_PTR pfn_debug_cmd_exe;
+
+} SF_DEBUG_CMD_ATTR_S;
+
+SINT32 sf_debug_init(SF_CHAR *filepath,SINT32 *fd);
+
+SINT32 sf_debug_create(SF_DEBUG_CMD_ATTR_S *pDebugCmdArray,SINT16 lenth);
+
+SINT32 sf_debug_start(SINT32 fd);
+
+SINT32 sf_debug_stop(void);
+
+SINT32 sf_debug_deinit(SINT32 fd);
+
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
diff --git a/code/application/source/sf_app/code/include/sf_dev_other.h b/code/application/source/sf_app/code/include/sf_dev_other.h
new file mode 100755
index 000000000..c6516f376
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_dev_other.h
@@ -0,0 +1,24 @@
+#ifndef __SF_DEV_OTHER_H__
+#define __SF_DEV_OTHER_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_type.h"
+#include "sf_hal_gpio.h"
+
+#include "sf_param_common.h"
+SINT32 sf_dev_pir_status_get(void);
+UINT16 sf_pir_to_digit_analog(UINT8 pirs);
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
diff --git a/code/application/source/sf_app/code/include/sf_dev_usb.h b/code/application/source/sf_app/code/include/sf_dev_usb.h
new file mode 100755
index 000000000..b28ea6fe7
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_dev_usb.h
@@ -0,0 +1,35 @@
+#ifndef __SF_DEV_USB_H__
+#define __SF_DEV_USB_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_type.h"
+#include "sf_hal_gpio.h"
+
+#include "sf_param_common.h"
+
+typedef enum sf_USB_MODE_E
+{
+ SF_USB_APP_CHARGE = 0,
+ SF_USB_APP_MSDC,
+ SF_USB_APP_UVC,
+}SF_USB_MODE_E;
+
+void sf_usb_app_mode_set(SF_USB_MODE_E mode);
+
+SF_USB_MODE_E sf_usb_app_mode_get(void);
+
+SINT32 sf_usb_IsInsert(void);
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
diff --git a/code/application/source/sf_app/code/include/sf_device.h b/code/application/source/sf_app/code/include/sf_device.h
new file mode 100755
index 000000000..ed35ec10b
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_device.h
@@ -0,0 +1,64 @@
+#ifndef __SF_DEVICE_H__
+#define __SF_DEVICE_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include
+#include "sf_param_common.h"
+typedef enum sfHAL_LED_GPIO_IDX_E
+{
+ SF_HAL_LED_IDX_0 = 0, /**
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#define LOG_TMP_MOD_FILE_PATH SF_SD_ROOT"SF_GPS.TXT"
+#define LOG_AT_FILE_PATH SF_SD_ROOT"SF_GPS.TXT"
+#define WARNING_FILE_PATH SF_SD_ROOT"warning.txt"
+#define INFO_FILE_PATH SF_SD_ROOT"info.txt"
+
+#define SF_ENCRYPTION_ENBLE 1
+
+typedef enum SF_LOG_LEVEL_E
+{
+ SF_LOG_LEVEL_ERROR = 0, /**
+
+#define SF_MUTEX_INIT_LOCK(mutex) \
+ do { \
+ (void)pthread_mutex_init(&mutex, NULL); \
+ } while (0)
+
+#define SF_MUTEX_LOCK(mutex) \
+ do { \
+ (void)pthread_mutex_lock(&mutex); \
+ } while (0)
+
+#define SF_MUTEX_UNLOCK(mutex) \
+ do { \
+ (void)pthread_mutex_unlock(&mutex); \
+ } while (0)
+
+#define SF_MUTEX_DESTROY(mutex) \
+ do { \
+ (void)pthread_mutex_destroy(&mutex); \
+ } while (0)
+
+
+#define SF_APPCOMM_CHECK_RETURN(ret, errcode) \
+ do { \
+ if (SF_SUCCESS != ret) { \
+ MLOGE("Error Code: [0x%08X]\n\n", ret); \
+ return errcode; \
+ } \
+ } while (0)
+#define SF_APPCOMM_CHECK_OPENFILE_RETURN(ret, str,errcode) \
+ do { \
+ if (ret < 0) { \
+ MLOGE("open file: [%s] failed!!!\n\n", str); \
+ return errcode; \
+ } \
+ } while (0)
+
+#define SF_CS_CHECK_BERAK(ret) \
+ if (SF_SUCCESS != ret) { \
+ MLOGE("Error Code: [0x%08X]\n\n", ret); \
+ break; \
+ }
+#define SF_COMM_CHECK_POINTER(p, errcode) \
+ do { \
+ if (!(p)) { \
+ MLOGE("pointer[%s] is NULL\n", #p); \
+ return errcode; \
+ } \
+ } while (0)
+
+#define SF_TTYUSB_RECV_MAX 580
+#define SF_HTTP_RECV_MAX 4096
+
+
+#define CFG_FLAT_ANGLE_LEN
+//#define CFG_WIDE_ANGLE_LEN
+
+
+#define SF_VER_MAX_LEN 12
+
+
+
+#define SF_BATCH_MAX_NUMBER (2)
+
+#define SF_CAMERA_NAME_MAX_LEN (12)
+#define SF_ICCID_MAX_LEN (22)
+#define SF_DAILY_MAX_NUMBER (2)
+#define SF_IMEI_MAX_LEN (32)
+#define SF_OPERATOR_CODE_MAX_LEN (8)
+#define SF_APN_MAX_LEN (40)
+#define SF_APN_PASSWORD_MAX_LEN (20)
+#define SF_FTP_MAX_LEN (40)
+#define SF_FTP_PORT_MAX_LEN (5)
+#define SF_GPS_INFO_MAX_LEN (16)
+#define SF_MODULE_VER_MAX_LEN (50)
+#define SF_BIND_ACCOUNT_MAX_LEN (50)
+#define SF_TOKEN_MAX_LEN (64)
+#define SF_ALIVE_IP_MAX_LEN (32)
+#define SF_UUID_MAX_LEN (32)
+
+
+#define SF_MAX_PATH_LEN 128
+#define SF_MAX_PIC_LEN 64
+#define SF_SRCFILE_MAX 4
+#define SF_THUMB_FILE_MAX_LEN 20
+
+
+#define GPIOID_PIR_TEST 3
+#define GPIOID_SIM_INSRET 4
+#define GPIOID_USB_INSERT 61
+#define GPIOID_WIFI_POWER 6
+#define GPIOID_USB_MUX1 16 //t100 only one usb mux
+#define GPIOID_USB_MUX2 16
+
+#define GPIOID_ADC_MUXA 52
+#define GPIOID_ADC_MUXB 53
+
+#define GPIOID_IRCUT_MEN1 50
+#define GPIOID_IRCUT_MEN2 51
+
+
+#define SD_WARNING_SPACE 30 /*30MB*/
+
+
+
+#define HTTP_PORT 80
+#define HTTPS_PORT 443
+#define HTTPCLIENT_REV_SIZE 512
+#define BUFFER_SIZE 2048
+
+
+#define SF_DEV_NOT_EXIST 20002
+#define SF_DEV_NOT_BIND 20006
+#define SF_SYS_ERR 1
+#define SF_PARA_ERR 3
+#define SF_USER_NOT_EXIST 10006
+#define SF_SIM_NOT_EXIST 30002
+#define SF_SIM_NET_NOT_TURN_ON 30004
+#define SF_SIM_DEV_NOT_BIND 20011
+#define SF_DEV_DETAILS_NOT_VILLAGE 20009
+#define SF_DEV_AUTH_INVALID 401
+
+
+#define MSYS_IOCTL_MAGIC 'S'
+#define IOCTL_MSYS_GET_RTOSSTATUS _IO(MSYS_IOCTL_MAGIC, 0x95)
+#define IOCTL_MSYS_GET_MODULE_DATA _IO(MSYS_IOCTL_MAGIC, 0x96)
+#define IOCTL_MSYS_GET_SY_RTOS_DATA _IO(MSYS_IOCTL_MAGIC, 0x97)
+#define IOCTL_MSYS_SET_RTOS_CMD _IO(MSYS_IOCTL_MAGIC, 0x98)
+
+#define DEFAULT_RTC_DEVICE "/dev/rtc0"
+
+#define SF_SD_ROOT "/mnt/sd/"
+
+#define SIFAR_CUSTOMER_PARAM_PATH "/misc/sfSysParm.bin"
+#define SIFAR_STATISTICS_PARAM_PATH "/mnt/sd/DCIM/THUMB/sfStatisticsParm.bin"
+
+
+
+#define GPIO_DIR_OUT 1
+#define GPIO_DIR_IN 0
+
+#define AMZ_HOST "s3.amazonaws.com"
+#define AMZ_PW_TITLE "AWS4"
+#define SECRET_TYPE "AWS4-HMAC-SHA256"
+#define SECRET_VER "aws4_request"
+#define AMZ "s3"
+
+#define SF_4G_PIC_THUMB_PATH SF_SD_ROOT"DCIM/THUMB/"
+#define SF_4G_SMALL_VIDEO_STREAM_PATH SF_SD_ROOT"DCIM/SMALL/"
+#define SIM_AUTO_MATCH_FILE_PATH SF_SD_ROOT"SIM Auto Match.TXT"
+
+#define SF_DCF_DIR_NAME_SUFFIX "SYCAM" /**< DCF Directory Name (it must be 5-characters) */
+#define SF_DCF_ROOT_DIR_NAME "DCIM" /**< DCF Root Directory Name */
+#define SF_DCF_THM_DIR_NAME "THUMB" /**< DCF Directory Name (it must be 5-characters) */
+
+#define SF_DCF_EXT_PHOTO "jpg" /**< File extenstion name for Date DB */
+#define SF_DCF_EXT_MOV "mp4" /**< File extenstion name for Date DB */
+#define SF_DCF_EXT_AUDIO "WAV" /**< File extenstion name for Date DB */
+#define SF_DCF_EXT_THM "jpg" /**< File extenstion name for Date DB */
+
+#if defined(CFG_FLAT_ANGLE_LEN)
+#define SF_DCF_FILE_NAME_PREFIX "HRT1"
+#elif defined(CFG_WIDE_ANGLE_LEN)
+#define SF_DCF_FILE_NAME_PREFIX "SWT1"
+#else
+#define SF_DCF_FILE_NAME_PREFIX "SYEW"
+#endif
+
+
+
+
+#define SF_QLOG_ENABLE 1
+//#define SF_VERSION_RELEASE
+//#define SF_HARDWARE_TEST
+//#define SF_FACTORY_TEST
+//#define SF_GPS_TEST
+#define SF_EMC_TEST
+
+#define CMD_SHORT_LONG_CLICK_OFFSET (128)
+
+#ifdef SF_VERSION_RELEASE
+#define ACCESS_KEY "ACT1CSHKRO01"
+#else
+#define ACCESS_KEY "AC40CSHKRO01"
+#endif
+
+#define SF_ERR_ID(module, err) ((SINT16)(((module) << 8) | (err)))
+/** SF Module ID */
+typedef enum SF_MOD_e {
+
+ SF_MOD_4G = 1,
+ SF_MOD_GPS,
+ SF_MOD_FILE,
+ SF_MOD_HTTP,
+ SF_MOD_TTY,
+ SF_MOD_DATA,
+ SF_MOD_COM,
+ SF_MOD_LOG,
+ SF_MOD_STORE,
+ SF_MOD_SYS,
+ SF_MOD_APP,
+ SF_MOD_BUTT,
+} SF_MOD_E;
+
+typedef enum ERR_CODE_e{
+ ERROR_AT_APN,
+ ERROR_AT_TIMEOUT,
+ ERROR_AT_ACTIVE,
+ ERROR_AT_READ,
+ ERROR_AT_WRITE,
+ ERROR_AT_OPEN,
+ ERROR_AT_DISCONNECT,
+ ERROR_NO_SIMCARD,
+ ERROR_NO_SUPPORT,
+ ERROR_NO_SIGNAL,
+ ERROR_NO_FILE,
+ ERROR_FILE_SEND,
+ ERROR_INS_EXIT,
+ ERROR_NOT_MATCH,
+ ERROR_IP_ADDR,
+ ERROR_IP_CHANGE,
+ ERROR_REQUEST,
+ ERROR_WRITE,
+ ERROR_DATA_FORMAT,
+ ERROR_MODULE_OPEN,
+ ERROR_REG_NET,
+ ERROR_BUTT,
+}ERR_CODE_E;
+typedef enum sf_FILE_TYPE_E
+
+{
+ SF_FILE_TYPE_PIC_THUM_3M = 0x00,
+ SF_FILE_TYPE_PIC_3M = 0x01,
+ SF_FILE_TYPE_VIDEO_THUM_WVGA = 0X02,
+ SF_FILE_TYPE_VIDEO_WVGA = 0X03,
+ SF_FILE_TYPE_VIDEO_THUM_720P = 0X04,
+ SF_FILE_TYPE_VIDEO_720P = 0X05,
+ SF_FILE_TYPE_VIDEO_THUM_1080P = 0X06,
+ SF_FILE_TYPE_VIDEO_1080P = 0X07,
+ SF_FILE_TYPE_PIC_THUM_5M = 0x08,
+ SF_FILE_TYPE_PIC_5M = 0x09,
+ SF_FILE_TYPE_LOG_ERROR = 0x0A,
+ SF_FILE_TYPE_CFG = 0x0B,
+ SF_FILE_TYPE_TRIGGER = 0x0C,
+
+ SF_FILE_TYPE_PIC_BIG,
+ SF_FILE_TYPE_PIC_SMALL,
+ SF_FILE_TYPE_PIC_VIDEO,
+ SF_FILE_TYPE_VIDEO,
+ SF_FILE_TYPE_LOG_DP, /*dailyreport file*/
+ SF_FILE_TYPE_GPS,
+ SF_FILE_TYPE_TXT,
+ SF_FILE_TYPE_UPDATE,
+ SF_FILE_TYPE_FOTA,
+ SF_FILE_TYPE_BT_ALARM, /*Bettery Alarm*/
+ SF_FILE_TYPE_OTHER,
+ SF_FILE_TYPE_BUTT,
+}SF_FILE_TYPE_E;
+
+typedef enum {
+ SF_USB_MUX_HOST_4G = 0,
+ SF_USB_MUX_PC_4G = 1,
+ SF_USB_MUX_PC_HOST =2,
+ SF_USB_MUX_MAX = 3,
+}SF_USB_MUX_FUN_e;
+
+typedef enum sfSD_STATUS_E
+{
+ SF_SD_UNPLUGED = 0x00,
+ SF_SD_OUT,
+ SF_SD_OK,
+ SF_SD_FULL,
+ SF_SD_ERROR,
+ SF_SD_PLUGED,
+ SF_SD_BUTT,
+} SF_SD_STATUS_E;
+
+typedef enum sf_STARTUP_TYPE_E
+{
+ SF_MCU_STARTUP_OFF = 0x00,/* POWER OFF*/
+ SF_MCU_STARTUP_ONKEY = 0x01,/*key on SETUP*/
+ SF_MCU_STARTUP_TIMELAPSE = 0x02,/*timelapse power on*/
+ SF_MCU_STARTUP_NORMAL = 0x03,/*Dial the key to ON*/
+ SF_MCU_STARTUP_RING = 0x04,/*ring power on*/
+ SF_MCU_STARTUP_PIR = 0x05,/*pir power on*/
+ SF_MCU_STARTUP_WARNING = 0x06,/*low bat worning power on*/
+ SF_MCU_STARTUP_SERVER = 0x07,/*server power on(reserve)*/
+ SF_MCU_STARTUP_DP = 0x08,/*DailyReport power on*/
+ SF_MCU_STARTUP_USB = 0x09,/*USB power on*/
+ SF_MCU_STARTUP_RESET = 0x0A,/*power on to reset(reserve)*/
+ SF_MCU_STARTUP_SYN_PARAM = 0x0B,/*power on to syn param(reserve)*/
+ SF_MCU_STARTUP_BATCH_SEND= 0x0C,/*power on to send batch*/
+ SF_MCU_STARTUP_BUTT = 0X0D,
+} SF_STARTUP_TYPE_E;
+
+typedef enum sfPOWEROFF_TYPE_E
+{
+ SF_POWEROFF_NOT = 0x00,
+ SF_POWEROFF_AUTO = 0x01, /*auto power when 3min no operation*/
+ SF_POWEROFF_REBOOT = 0x02, /*poweroff to reboot*/
+ SF_POWEROFF_KEYON = 0x03,
+ SF_POWEROFF_KEYOFF = 0x04,
+ SF_POWEROFF_SYNC_PARAM = 0x05,
+ SF_POWEROFF_GPS_DP = 0x06,
+ SF_POWEROFF_SD_FULL = 0x07,
+ SF_POWEROFF_LOW_BAT = 0x08,
+ SF_POWEROFF_NO_SD = 0x09,
+ SF_POWEROFF_BUTT,
+} SF_POWEROFF_TYPE_E;
+
+typedef enum sf_CAMMODE_E
+{
+ SF_CAMMODE_PIC = 0,
+ SF_CAMMODE_VIDEO ,
+ SF_CAMMODE_PV, /* pic+video*/
+ SF_CAMMODE_BUTT
+}SF_CAMMODE_E;
+typedef enum sf_IMG_SIZE_E
+{
+ SF_IMG_SIZE_32M = 0,
+ SF_IMG_SIZE_24M,
+ SF_IMG_SIZE_12M,
+ SF_IMG_SIZE_8M,
+ SF_IMG_SIZE_5M,
+ SF_IMG_SIZE_3M,
+ SF_IMG_SIZE_BUTT
+}SF_IMG_SIZE_E;
+typedef enum sf_VIDEO_SIZE_E
+{
+ SF_VIDEO_SIZE_1080 = 0,
+ SF_VIDEO_SIZE_720,
+ SF_VIDEO_SIZE_WVGA,
+ SF_VIDEO_SIZE_BUTT
+}SF_VIDEO_SIZE_E;
+typedef enum sfBAT_TYPE_E
+{
+ SF_BAT_AL = 0x00,
+ SF_BAT_NI = 0x01,
+ SF_BAT_LI = 0x02,
+ SF_BAT_CUS_LI = 0x03,
+ SF_BAT_BUTT,
+} BAT_TYPE_E;
+typedef enum sf_MESSAGE_TYPE_E
+{
+ CMD_KEY = 0x1A00,
+ CMD_SD = 0x1B00,
+ CMD_LED = 0x1C00,
+ CMD_FILE = 0x1D00,
+ CMD_POWEROFF = 0x1E00,
+ CMD_VENC = 0x1F00,
+
+}SF_MESSAGE_TYPE_E;
+
+
+typedef enum sf_MESSAGE_CMD_SD_e
+{
+ CMD_SD_MOUNT_SUCCESS = 0x01,
+ CMD_SD_ERROR = 0x02,
+ CMD_SD_OUT = 0x03,
+ CMD_SD_FULL = 0x04,
+ CMD_SD_MOUNT_FAILURE = 0x05,
+
+}SF_MESSAGE_CMD_SD_E;
+
+typedef enum sf_MESSAGE_CMD_LEDD_e
+{
+
+ CMD_LED_EVT = 0x01,
+
+}SF_MESSAGE_CMD_LED_E;
+
+typedef enum sf_MESSAGE_CMD_VENC_e
+{
+
+ CMD_VENC_START_SUCCESS = 0x01,
+ CMD_VENC_START_FAILURE = 0x02,
+ CMD_VENC_STOP_SUCCESS = 0x03,
+ CMD_VENC_STOP_FAILURE = 0x04,
+ CMD_VENC_STREAM_START = 0x05,
+ CMD_VENC_STREAM_STOP = 0x06,
+}SF_MESSAGE_CMD_VENC_E;
+#ifdef CFG_TRANSDATA_AT
+
+typedef enum sf_UPLOAD_STATUS_E{
+ SF_UPLOAD_FTP = 0x01,
+ SF_UPLOAD_OSS,
+ SF_UPLOAD_AMZ,
+ SF_UPLOAD_BUTT,
+} SF_UPLOAD_STATUS_E;
+#else
+typedef enum sf_UPLOAD_STATUS_E{
+ SF_UPLOAD_FTP = 0x00,
+ SF_UPLOAD_OSS,
+ SF_UPLOAD_AMZ,
+ SF_UPLOAD_BUTT,
+} SF_UPLOAD_STATUS_E;
+#endif
+
+
+typedef enum sf_DATE_TYPE_E{
+ DATE_TYPE_YYMMDD = 0,
+ DATE_TYPE_MMDDYY,
+ DATE_TYPE_DDMMYY,
+ DATE_TYPE_BUTT,
+} SF_DATE_TYPE_E;
+typedef enum sf_SIM_TYPE_E
+{
+ SF_SIM_MEGA = 0, // normal mega sim, use in abroad
+ SF_SIM_MEGA_IOT, //special mega sim, only use in T110
+ SF_SIM_OTHER, //other sim
+ SF_SIM_BUTT
+}SF_SIM_TYPE_E;
+
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
+
diff --git a/code/application/source/sf_app/code/include/sf_param_struct.h b/code/application/source/sf_app/code/include/sf_param_struct.h
new file mode 100755
index 000000000..060fc84bd
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_param_struct.h
@@ -0,0 +1,359 @@
+#ifndef __SF_PARAM_STRUCT_H__
+#define __SF_PARAM_STRUCT_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include
+
+#include "sf_type.h"
+#include "sf_param_enum.h"
+
+
+typedef struct sf_URL_s {
+ SF_CHAR url[160];
+}SF_URL_S;
+
+typedef struct sf_OSS_s {
+ UINT8 szIP[64];
+ UINT8 szBucket[32];
+ UINT8 szUsername[32];
+ UINT8 szPassword[48];
+}SF_OSS_S;
+
+typedef struct sf_THREAD_CFG_S {
+ unsigned char IsRun;
+ unsigned char IsStopFlag;
+ pthread_t TskId;
+} SF_THREAD_CFG_S ;
+
+#ifndef SF_DATA_UI_TYPE
+#define SF_DATA_UI_TYPE
+#define SF_TIMER_MAX_NUMBER (2)
+typedef struct SF_PARA_TIME_S {
+
+ UINT16 Year;
+ UINT16 Mon;
+ UINT16 Day;
+
+ UINT16 Hour;
+ UINT16 Min;
+ UINT16 Sec;
+} SF_PARA_TIME_S;
+
+typedef struct SF_WORKTIME_S
+{
+ SF_PARA_TIME_S StartTime;
+ SF_PARA_TIME_S StopTime;
+} SF_WORKTIME_S;
+
+#endif
+
+typedef struct sf_subscribe_ATTR_S {
+ UINT8 subscribeType;
+ char subscribeFileName[40];
+}SF_SUBSCRIBE_ATTR_S;
+
+typedef struct sf_subscribe_file_ATTR_S {
+ UINT8 subscribeCnt;
+ SF_SUBSCRIBE_ATTR_S *pSubscribe;
+}SF_SUBSCRIBE_FILE_ATTR_S;
+
+#ifndef SF_PDT_PARAM_CFG_S
+typedef struct sfPDT_PARAM_CFG_S
+{
+ /*camera param*/
+ UINT8 WorkMode;
+ UINT8 CamMode; // Picture, Video, Picture+Video
+ UINT8 ImgSize; // 8M, 16M, 32M
+ UINT8 VideoSize; // WVGA, 720P, 1080P
+ UINT8 VideoLenth;
+ UINT8 Multishot; // shot picture number 1~5,1 single shot 2~5 continuous shot
+ UINT8 MultishotInterval; // shot interval. 0: shot in one second; 1: 1 pic per sec; 2: 2 pic per sec
+ UINT8 NightMode;
+ UINT8 FlashLed;
+ UINT8 PirSensitivity;
+ UINT8 PirDelaySwitch; /*DelayFlag;*/
+ UINT8 TimelapseSwitch;
+ UINT8 WorkTime1Switch; /*WorkTime*/
+ UINT8 WorkTime2Switch; /*WorkTime*/
+ UINT8 CameraNameFlag;
+ UINT8 PirSwitch;
+ UINT8 SdLoop; /*SdCycle*/
+ UINT8 DigitPirSensitivity;
+
+ UINT8 DailyReportswitch;
+ UINT8 ReDailyReport; /*if network error, reboot an hour later,liteOS need this param,not separete*/
+ UINT8 FristSendDailyAndGps;
+
+ UINT8 GprsMode; /*0:Daily, 1:Intant*/
+ UINT8 GprsSwitch; /*0:gprs off, 1:gprs on*/
+ UINT8 SendMaxNum;
+ UINT8 SendPicSize; // thumbnail 0:640*480, 1:1920*1440
+ UINT8 SendType; /*0:send immediately, 1:send once per day, 2:send twice per day*/
+ UINT8 SendMultishot;
+ UINT8 SendVideo;
+ UINT8 SendPhoto;
+
+ UINT8 BatteryType;
+ UINT8 StampSwitch;
+ UINT8 DateStyle;
+ UINT8 DebugMode;
+ UINT8 Zoom; // APP preview magnification, 1x,2x,4z
+ UINT8 LightFreq; // 50HZ, 60H
+ SINT8 TimeZone;
+
+ UINT8 GpsSwitch; /*0:OFF 1:ON*/
+ UINT8 GpsSendType; /*0:when camera trun on 1: one time 2:twice time*/
+ UINT8 DateAuto;
+ UINT8 PicUponDailyReport;
+ UINT8 FtpSwitch;
+ UINT8 VideoFrame;
+ UINT8 ParaSync;
+ UINT16 RTCYear;
+ UINT8 RtcMonth;
+ UINT8 RTCDay;
+ UINT8 RTCHour;
+ UINT8 RTCMinute;
+ UINT8 RTCSecond;
+ UINT8 FirstUpdateFlag; /*1: indicate first update start*/
+ UINT8 FormateFlag;
+ UINT8 Formatestatus;
+ UINT8 ResetFlag;
+ UINT8 GPSFlag;
+ UINT8 BatchSendTimelapse;
+ UINT8 GPSEnterResetModeFlag;
+ UINT8 GPSWaitRestartFlag;
+ UINT8 GPSMapeUpdateFlag;
+ UINT8 GPSAntitheftFlag;
+ UINT8 Lastsetuptype;
+ UINT8 OtaFlag;
+ SF_PARA_TIME_S TimelapseTime;
+ SF_WORKTIME_S WorkTime[SF_TIMER_MAX_NUMBER];
+ SF_PARA_TIME_S PirDelayTime;
+ SF_PARA_TIME_S DailyReportTime;
+ SF_PARA_TIME_S TimeSend1;/*batch send1 time*/
+
+ char CameraNameStr[SF_CAMERA_NAME_MAX_LEN];
+ UINT32 CheckSum;
+}SF_PDT_PARAM_CFG_S;
+#endif
+typedef struct sfPDT_PARAM_STATISTICS_S
+{
+ /*DailyReport Part*/
+ UINT8 DailyReportNum;/*0:OFF, 1:one time per day, 2:two Times per day*/
+ UINT16 DialyReportFailCnt;
+ UINT16 Year;
+ UINT16 Mon;
+ UINT16 Day;
+
+ UINT16 TriggerTimes;
+ UINT8 SubscribeSendCnt;
+ UINT8 SubVideoSendCnt;
+ UINT8 SendBatchAgain; /*copy from 3.8CG needReConcentratedSend*/
+ UINT8 DailyReportAgain; /* copy from 3.8CG ReDailyFlag:if network error, reboot an hour later*/
+ UINT16 SendPicDayCnt; /*copy from 3.8CG picSendMax, send success pic number per day*/
+ UINT16 SendDailyCnt; /*send pic count success+fail*/
+ UINT16 SendDailyThumbCnt;/* send small pic times, success + fail*/
+ UINT16 SendSuccessThumbCnt;/* send small pic times, success*/
+ UINT16 SendDailyOriginalCnt;
+ UINT16 SendSuccessOriginalCnt;
+ UINT16 SendDailyVideoCnt;/* send video times, success + fail*/
+ UINT16 SendSuccessVideoCnt;/* send video times,success*/
+ UINT32 SendThumbTotalTime;/* send small pic time, uint:second*/
+ UINT32 SendOriginalTotalTime;
+ UINT32 SendVideoTotalTime;/* send video time, uint:second*/
+
+ UINT32 OldFileKey;
+ UINT16 SdTotalFile;
+ UINT16 SendDailyFailCnt;
+ UINT16 SendDailyTimeoutCnt;
+ UINT16 SynParamFlag;
+ UINT16 SynMcuSet; /* 1: set sync 0: not set (void)*/
+ UINT8 InstantFtpRecfg; /*1: must cfg ftps , 0 : do not cfg ftps*/
+ UINT8 GpsPowerONSendFlag; /*1: send gps txt when first time to on 0: send gps txt base gps num setting*/
+ UINT8 LoginACMFailedCnt;
+ UINT8 u8GetPicFlag;
+ UINT8 u8ResetLimited;
+ UINT8 bindFlag;
+ UINT8 GPSInfoGetFailed;
+ UINT8 SimType;
+
+ /*SIM Card Info*/
+ char OperatorCode[SF_OPERATOR_CODE_MAX_LEN];
+ //char Carrier[64];
+ char ApnGPRS[SF_APN_MAX_LEN];
+ char ApnUsername[SF_APN_MAX_LEN];
+ char ApnPassword[SF_APN_PASSWORD_MAX_LEN];
+ char ServiceProvider[64];
+
+ char MMSC[SF_APN_MAX_LEN];
+ char MMSAPN[SF_APN_MAX_LEN];
+ char Proxy[SF_APN_MAX_LEN];
+ char Port[SF_APN_MAX_LEN];
+ char UserName[SF_APN_MAX_LEN];
+ char Password[SF_APN_MAX_LEN];
+ /*ftp info*/
+ char WebIP[SF_FTP_MAX_LEN];
+ char AcmIP[64];
+
+
+ /*SIM Card Info*/
+ char IMEI[SF_IMEI_MAX_LEN];
+ char SimID[SF_ICCID_MAX_LEN];
+ char ModuleVersion[SF_MODULE_VER_MAX_LEN];
+ char ModuleSubversion[SF_MODULE_VER_MAX_LEN];
+ /*GPS INFO*/
+ UINT16 GpsSendFlag;
+ UINT16 GpsSendYear;
+ UINT16 GspSendMon;
+ UINT16 GpsSendDay;
+ SINT32 Did;
+ SINT32 AlivePort;
+ UINT8 UploadMode;
+ char GpsInfo[SF_GPS_INFO_MAX_LEN];
+ char Latitude[SF_GPS_INFO_MAX_LEN];
+ char Longitude[SF_GPS_INFO_MAX_LEN];
+ char BindAccount[SF_BIND_ACCOUNT_MAX_LEN];
+
+ char Token[SF_TOKEN_MAX_LEN];
+ char AliveIp[SF_ALIVE_IP_MAX_LEN];
+ char Uuid[SF_UUID_MAX_LEN];
+ /*Low Power Alarm */
+ UINT16 LowPowerAlarmFlag; /*0: no alarm upload, 1: alarm already upload.*/
+ char PicPlan;
+ UINT8 startup;
+ UINT8 FcTemper;
+ UINT8 BatRemainCap;
+ UINT8 OtaUpgradeFlag;
+
+ UINT8 netGeneration;
+ UINT8 SimSignal;
+ SF_SUBSCRIBE_FILE_ATTR_S stSubscribe;
+ SF_OSS_S stOssCfg;
+ SF_PARA_TIME_S httpTime;
+
+ UINT32 CheckSum;
+}SF_PDT_PARAM_STATISTICS_S;
+
+typedef struct sf_FILE_ATTR_S {
+
+ SF_FILE_TYPE_E enFileTye;
+ SF_CHAR thumbfileName[SF_MAX_PIC_LEN];
+ SF_CHAR thumbfilePath[SF_MAX_PATH_LEN];
+ SF_CHAR txtfilePath[SF_MAX_PATH_LEN];
+ SF_CHAR txtfileName[SF_MAX_PIC_LEN];
+ UINT32 thumbfileSize;
+
+}SF_FILE_ATTR_S;
+
+typedef struct sf_SEND_FILE_ATTR_S {
+
+ SF_FILE_TYPE_E enFileTye; //upload sub hd or video file type; upload batch send thumb file type;
+ SF_CHAR SubFileName[SF_MAX_PIC_LEN]; //sub hd or video file name, use as bind file; when batch send thumb file, this is null.
+ SF_CHAR SendFileName[SF_MAX_PIC_LEN];//upload sub hd or video file name; upload batch send thumb file name;
+ UINT32 SendFileSize; //upload sub hd or video file size; upload batch send thumb file size;
+ UINT32 SendRet; //0:send success; other:error code
+ UINT8 SameFlag;
+
+}SF_SEND_FILE_ATTR_S;
+
+typedef struct sf_SRCFILE_ATTR_S {
+ UINT8 filecnt;
+ SF_FILE_ATTR_S stfileattr[SF_SRCFILE_MAX];
+}SF_SRCFILE_ATTR_S;
+typedef struct sf_REPORT_FILE_ATTR_S {
+ UINT8 filecnt;
+ SF_SEND_FILE_ATTR_S stSendFileAttr[100];
+}SF_REPORT_FILE_ATTR_S;
+
+typedef struct sf_MESSAGE_Buf_S
+{
+ long mtype;
+ SINT32 cmdId;
+ SINT32 s32Wait;
+ SINT32 arg1;
+ SINT32 arg2;
+ SINT32 arg3;
+}SF_MESSAGE_BUF_S;
+typedef struct sf_RtosInfo_t{
+ unsigned int test1;
+ unsigned int test2;
+ unsigned int test3;
+ unsigned int IsNight;
+ unsigned int BatPer;
+ unsigned int Fctemp;
+ unsigned short McuVer;
+ unsigned char McuSubVer;
+ unsigned int rtosBootTime;
+} SF_RTOSINFO_S;
+typedef struct SF_RTOS_CMD_s{
+ unsigned char cmd;
+ unsigned char arg[8];
+ unsigned char info[256];
+} SF_RTOS_CMD_T;
+
+typedef struct sf_THREAD_S
+{
+ SF_BOOL IsRun; /** max)\
+ {\
+ MLOGE("Parameter[%d] out of normal range [%d,%d)!!!\n",cmd,min,max);\
+ return SF_FAILURE;\
+ } \
+ } while (0)
+
+
+typedef enum {
+ SF_SD_FORMAT_SUCUSS = 0,
+ SF_SD_FORMAT_NO_CARD = 1,
+ SF_SD_FORMAT_NOT_SUPPORT_FAT =2,
+ SF_SD_FORMAT_MAX = 3,
+}SF_SD_FORMAT_RESULT_e;
+typedef struct sf_STORE_ATTR_S {
+
+ U32 SDStatus;
+ U32 SDFree;
+ U32 SDTotalSize;
+
+}SF_STORE_ATTR_S;
+
+
+
+SINT32 sf_sd_info_get(SF_STORE_ATTR_S *pstoreattrs);
+
+SINT32 sf_sd_remove_file(const char *path,SINT32 threshold) ;
+
+SINT32 sf_sd_loopremove(const char *path);
+
+SINT32 sf_sd_isfull(SINT8 *Isfull);
+
+SF_SD_STATUS_E sf_sd_status_get(void);
+
+SINT32 sf_sd_status_set(SF_SD_STATUS_E enStatus);
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /*_SF_COMMON_H_*/
+
diff --git a/code/application/source/sf_app/code/include/sf_systemMng.h b/code/application/source/sf_app/code/include/sf_systemMng.h
new file mode 100755
index 000000000..06d91321c
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_systemMng.h
@@ -0,0 +1,83 @@
+#ifndef _SF_SYSTEMMNG_H_
+#define _SF_SYSTEMMNG_H_
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_param_common.h"
+#define SF_SYS_CHECK_RANGE(cmd, min,max) \
+ do { \
+ if(cmd < min || cmd > max)\
+ {\
+ MLOGE("Parameter[%d] out of normal range [%d,%d)!!!\n",cmd,min,max);\
+ return SF_FAILURE;\
+ } \
+ } while (0)
+
+// following define must be same to "kernel\drivers\sstar\include\mdrv_msys_io.h"
+
+#define SF_VER_FILE_PATH SF_SD_ROOT"CAM_INFO.txt"
+
+typedef enum sfUPGRADE_STATUS_E
+{
+ SF_UPGRADE_PRE = 0x01, /*Upgrade*/
+ SF_UPGRADE_ING, /*upgrade ing*/
+ SF_UPGRADE_FAIL, /*upgrade fail*/
+ SF_UPGRADE_SUCCESS,
+ SF_UPGRADE_BUTT,
+} SF_UPGRADE_STATUS_E;
+
+typedef enum
+{
+ LINUX2RTK_CMD_STOP_RECORD = 1, // stop record venc chn
+ LINUX2RTK_CMD_SET_RTKMODE = 2, // set work mode to rtk,for manual control mode
+ LINUX2RTK_CMD_SET_POWEROFF = 3, // set POWEROFF type
+ LINUX2RTK_CMD_SET_RTCTIME = 4, // set rtc time
+ LINUX2RTK_CMD_SET_DEVINFO = 5, // set dev info
+ LINUX2RTK_CMD_SET_UVCCTRL = 6, // set rtos uvc ctrl,open/close
+ LINUX2RTK_CMD_SET_P2PCTRL = 7, // set rtos p2p live ctrl,open/close
+ LINUX2RTK_CMD_SET_OTHER = 8,
+ LINUX2RTK_CMD_SET_BUTT
+} CUS_LINUX2RTK_CMD_E;
+SF_UPGRADE_STATUS_E sf_upgrade_status_get(void);
+
+void sf_upgrade_status_set(SF_UPGRADE_STATUS_E status);
+
+SF_POWEROFF_TYPE_E sf_poweroff_type_get(void);
+
+SINT32 sf_poweroff_type_set(SF_POWEROFF_TYPE_E enType);
+
+SINT32 sf_sys_rtc_time_get(SF_PARA_TIME_S *pstDateTime);
+
+SINT32 sf_sys_rtc_time_set(SF_PARA_TIME_S* pstDateTime);
+
+SINT32 sf_sys_rtc_time_check(SF_PARA_TIME_S *pstDateTime);
+
+SINT32 sf_sys_rtc_time_reset(void);
+
+SINT64 sf_sys_os_time_get(void);
+
+SINT64 sf_sys_os_utime_get(void);
+
+SINT32 sf_sys_software_version_get(SF_CHAR* version);
+
+SINT32 sf_sys_camera_about(void);
+
+SINT32 sf_sys_rtoscmd_set(SINT8 cmd, SINT8 *para);
+
+SINT32 sf_sys_rtosdata_get(SF_RTOSINFO_S *pstRtosData);
+
+SINT32 sf_sys_poweroff(SF_POWEROFF_TYPE_E poweroffType);
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+#endif
+
+
diff --git a/code/application/source/sf_app/code/include/sf_transdata1.h b/code/application/source/sf_app/code/include/sf_transdata1.h
new file mode 100755
index 000000000..145a1f06a
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_transdata1.h
@@ -0,0 +1,53 @@
+
+#ifndef __SF_TRANSDATA1_H__
+#define __SF_TRANSDATA1_H__
+
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#define SF_DATA_ERROR_REQUEST SF_ERR_ID(SF_MOD_DATA, ERROR_REQUEST)
+#define SF_DATA_ERROR_FILE_SEND SF_ERR_ID(SF_MOD_DATA, ERROR_FILE_SEND)
+
+SINT32 sf_packetgrouping_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_packetgrouping_fileresult(SF_DATA_ATTR_S *pstdata, SF_PDT_PARAM_CFG_S *pstParam,SF_FILE_ATTR_S *pstfileAttr);
+
+SINT32 sf_packetgrouping_get_bind_account(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_packetgrouping_query_cmd(SF_DATA_ATTR_S *pstdata);
+
+SINT32 sf_packetgrouping_query_cmd_param(SF_DATA_ATTR_S *pstdata);
+
+SINT32 sf_packetgrouping_cmd_report(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam, SF_FILE_ATTR_S *pstfileAttr);
+
+SINT32 sf_packetgrouping_disconnection(SF_DATA_ATTR_S *pstdata,SF_VOID *Param);
+
+SINT32 sf_MultiPacket_Parsing(UINT16 enCmdID,UINT16 *pdatahead,SF_DATA_ATTR_S *pdatattr);
+
+SINT32 sf_packetanalysis_login(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_packetanalysis_fileresult(SF_DATA_ATTR_S *param);
+
+SINT32 sf_packetanalysis_query_cmd(SF_DATA_ATTR_S *param);
+
+SINT32 sf_packetanalysis_query_cmd_param(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_packetanalysis_trigger(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_packetanalysis_bind_account(SF_DATA_ATTR_S *param,SF_FN_PARAM_S *pfnParam);
+
+SINT32 sf_packetanalysis_cmd_report(SF_DATA_ATTR_S *param);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif
+
diff --git a/code/application/source/sf_app/code/include/sf_type.h b/code/application/source/sf_app/code/include/sf_type.h
new file mode 100755
index 000000000..53fd5ff95
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sf_type.h
@@ -0,0 +1,54 @@
+#ifndef _SF_TYPE_H_
+#define _SF_TYPE_H_
+
+#include "kwrap/nvt_type.h"
+#ifndef SF_DATA_TYPE
+#define SF_DATA_TYPE
+
+
+//typedef unsigned long int UINT64;
+//typedef unsigned int UINT32; //hd_type.h:157
+typedef unsigned short UINT16;
+typedef unsigned char UINT8;
+
+typedef signed long int SINT64;
+typedef signed int SINT32;
+typedef signed short SINT16;
+typedef signed char SINT8;
+
+typedef unsigned char UCHAR;
+typedef unsigned char U8;
+typedef unsigned short U16;
+typedef unsigned int U32;
+typedef unsigned int long ULONG;
+typedef unsigned long int U64;
+
+//typedef signed char CHAR;//hd_type.h:169
+typedef char S8;
+typedef short S16;
+typedef int S32;
+typedef long SLONG;
+typedef signed long int S64;
+
+
+
+
+
+typedef char SF_CHAR;
+
+typedef unsigned char SF_BOOL;
+
+typedef void SF_VOID;
+
+
+#define SF_NULL 0L
+#define SF_SUCCESS 0
+#define SF_FAILURE (-1)
+
+#define SUCCESS 0
+#define FAIL 1
+
+#define SF_TRUE 1
+#define SF_FALSE 0
+#endif
+#endif
\ No newline at end of file
diff --git a/code/application/source/sf_app/code/include/sha256.h b/code/application/source/sf_app/code/include/sha256.h
new file mode 100755
index 000000000..5af8c29e5
--- /dev/null
+++ b/code/application/source/sf_app/code/include/sha256.h
@@ -0,0 +1,33 @@
+#include "sf_type.h"
+
+#define SHA256_HASH_SIZE 32
+
+/* Hash size in 32-bit words */
+#define SHA256_HASH_WORDS 8
+
+struct _SHA256Context {
+ unsigned long long totalLength;
+ UINT32 hash[SHA256_HASH_WORDS];
+ UINT32 bufferLength;
+ union {
+ UINT32 words[16];
+ UINT8 bytes[64];
+ } buffer;
+#ifdef RUNTIME_ENDIAN
+ int littleEndian;
+#endif /* RUNTIME_ENDIAN */
+};
+
+typedef struct _SHA256Context SHA256Context;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void SHA256Init (SHA256Context *sc);
+ void SHA256Update (SHA256Context *sc, const void *data, UINT32 len);
+ void SHA256Final (SHA256Context *sc, UINT8 hash[SHA256_HASH_SIZE]);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/code/application/source/sf_app/code/include/split.h b/code/application/source/sf_app/code/include/split.h
new file mode 100755
index 000000000..0881dc402
--- /dev/null
+++ b/code/application/source/sf_app/code/include/split.h
@@ -0,0 +1,57 @@
+/*
+ * qrencode - QR Code encoder
+ *
+ * Input data splitter.
+ * Copyright (C) 2006-2011 Kentaro Fukuchi
+ *
+ * The following data / specifications are taken from
+ * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
+ * or
+ * "Automatic identification and data capture techniques --
+ * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __SPLIT_H__
+#define __SPLIT_H__
+
+#include "qrencode.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+/**
+ * Split the input string (null terminated) into QRinput.
+ * @param string input string
+ * @param hint give QR_MODE_KANJI if the input string contains Kanji character encoded in Shift-JIS. If not, give QR_MODE_8.
+ * @param casesensitive 0 for case-insensitive encoding (all alphabet characters are replaced to UPPER-CASE CHARACTERS.
+ * @retval 0 success.
+ * @retval -1 an error occurred. errno is set to indicate the error. See
+ * Exceptions for the details.
+ * @throw EINVAL invalid input object.
+ * @throw ENOMEM unable to allocate memory for input objects.
+ */
+extern int Split_splitStringToQRinput(const char *string, QRinput *input,
+ QRencodeMode hint, int casesensitive);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif /* __SPLIT_H__ */
diff --git a/code/application/source/sf_app/code/source/4gMng/sf_eg91_gps.c b/code/application/source/sf_app/code/source/4gMng/sf_eg91_gps.c
new file mode 100755
index 000000000..de505fbc2
--- /dev/null
+++ b/code/application/source/sf_app/code/source/4gMng/sf_eg91_gps.c
@@ -0,0 +1,1027 @@
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "sf_type.h"
+#include "sf_log.h"
+#include "sf_hal_ttyusb.h"
+#include "sf_eg91_server.h"
+#include "sf_eg91_gps.h"
+#include "sf_param_common.h"
+#include "sf_module.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+static unsigned long int gps_get_seconds(SF_PARA_TIME_S *pTime)
+{
+ unsigned long int res = 0;
+ SF_PARA_TIME_S sfparamtime = {0};
+
+ memcpy(&sfparamtime,pTime,sizeof(SF_PARA_TIME_S));
+ if(sfparamtime.Mon <= 2)
+ {
+ sfparamtime.Mon += 10;
+ sfparamtime.Year -= 1;
+ }
+ else
+ {
+ sfparamtime.Mon -= 2;
+ }
+
+ res = (UINT32)(sfparamtime.Year/4 -sfparamtime.Year/100 +sfparamtime.Year/400) + 367*sfparamtime.Mon/12 + sfparamtime.Day + sfparamtime.Year * 365 -719499;
+ res = ((res*24 + sfparamtime.Hour) * 60 + sfparamtime.Min)*60 + sfparamtime.Sec;
+
+ return res;
+
+}
+static int gps_diffSec_from_date(SF_PARA_TIME_S *pnowDate, SF_PARA_TIME_S *poldDate)
+{
+ int diffSec = gps_get_seconds(pnowDate) - gps_get_seconds(poldDate);
+ return diffSec;
+}
+
+static void gps_infor_convert(SF_CHAR *str)
+{
+ SF_CHAR strTemp[32] = { 0 };
+ UINT32 temp;
+
+ memcpy((char*)strTemp, str, 4);
+ temp = atoi(strTemp);
+ temp = temp * 60 / 100;
+ sprintf(strTemp, "%04d", temp);
+ memcpy(str, strTemp, 4);
+}
+
+SINT16 eg91_gps_greendate_Get(SF_FN_PARAM_S *pfnParam,SF_PARA_TIME_S *pNowTime)
+ {
+ SINT16 ttyRet = SF_SUCCESS;
+ SINT16 ret = SF_SUCCESS;
+ SINT16 sts = 1;
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+ UINT8 reHttpSRequest=0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR dataStr[SF_TTYUSB_RECV_MAX] = { 0 };
+ MODULE_SERVER_AUTHEN_E enATcmdType = MODULE_HTTP_AUTHEN_AT_QIACT_PRE;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch(enATcmdType)
+ {
+ case MODULE_HTTP_AUTHEN_AT_QIACT_PRE:
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QIACT;
+ break;
+ case MODULE_HTTP_AUTHEN_AT_QIACT:
+ sprintf(ttyData,"AT+QIACT=%d\r",HTTP_PDP);/**/
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPURL_1:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ sprintf(dataStr,"http://acenter.wuyuantech.com/CameraManager/device/getGreenDate"/*, pStaticParam->WebIP*/);
+ sprintf(ttyData, "AT+QHTTPURL=%d,80\r",strlen(dataStr));
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_2;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ callTime++;
+ if(callTime < PDP_TRY_TIME)
+ {
+ sf_sleep_s(2);
+ sprintf(ttyData, "AT+QIACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ callTime=0;
+ sts = 0;
+ ret = SF_GPS_ERROR_QIACT;
+ SLOGE("Moudle QIACT ERROR.DATA:%s", ttyData);
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+
+
+ }
+ }
+ else if(timeout_count > 100)
+ {
+ sts = 0;
+ ret = SF_GPS_ERROR_QIACT;
+ SLOGE("Moudle QIACT timeout");
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPURL_2:
+ if(strstr(ttyData, "CONNECT"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData,"http://acenter.wuyuantech.com/CameraManager/device/getGreenDate"/*, pStaticParam->WebIP*/);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPGET;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPGET:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ sprintf(ttyData,"%s","AT+QHTTPGET=80\r");
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPREAD;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPREAD:
+ timeout_count = 0;
+ callTime++;
+ if(strstr(ttyData, "+QHTTPGET:"))
+ {
+ if(strstr(ttyData, "+QHTTPGET: 0,200"))
+ {
+ timeout_count= 0;
+ callTime = 0;
+ sprintf(ttyData,"%s","AT+QHTTPREAD=80\r");
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QIDEACT;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(reHttpSRequest == 0)
+ {
+ SLOGW("HTTP Send Failed,try again");
+ reHttpSRequest = 1;
+ sprintf(ttyData,"%s","AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ }
+ else
+ {
+ SLOGE("HTTP Send Failed,data:%s", ttyData);
+ SLOGE("FAILED:send http failed!!!!!\n");
+
+ ret = SF_HTTP_ERROR_REQUEST;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ else
+ {
+ if((strstr(ttyData,"ERROR")) || (callTime > 400))
+ {
+ if(reHttpSRequest == 0)
+ {
+ SLOGD("FAILED:send http timeout,try again\n");
+ reHttpSRequest = 1;
+ sprintf(ttyData,"%s","AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ }
+ else
+ {
+ SLOGD("FAILED:send http timeout!!!!!\n");
+ ret = SF_HTTP_ERROR_REQUEST;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ }
+ }
+
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QIDEACT:
+ timeout_count = 0;
+ if(strstr(ttyData,"statu"))
+ {
+ UINT8 *P1 = NULL;
+
+ P1 = strstr(ttyData,"greenDate");
+ if(P1 != NULL)
+ {
+ //printf("greenDate:%s\n",P1);
+ UINT8 tempStr[5] = {0};
+
+ strncpy(tempStr,P1+12,4);
+ pNowTime->Year = atoi(tempStr);
+
+ memset(tempStr,'\0',sizeof(tempStr));
+ strncpy(tempStr,P1+12+4,2);
+ pNowTime->Mon = atoi(tempStr);
+
+ strncpy(tempStr,P1+12+6,2);
+ pNowTime->Day = atoi(tempStr);
+
+ strncpy(tempStr,P1+12+8,2);
+ pNowTime->Hour = atoi(tempStr);
+
+ strncpy(tempStr,P1+12+10,2);
+ pNowTime->Min = atoi(tempStr);
+
+ strncpy(tempStr,P1+12+12,2);
+ pNowTime->Sec = atoi(tempStr);
+ SLOGD("%d/%02d/%02d %02d:%02d:%02d\n",pNowTime->Year,pNowTime->Mon,pNowTime->Day,pNowTime->Hour,pNowTime->Min,pNowTime->Sec);
+
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ else
+ {
+ callTime++;
+ if(callTime >600)
+ {
+ SLOGE("FAILED:send http timeout!!!!!\n");
+ callTime = 0;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+
+ }
+ }
+ break;
+ case MODULE_HTTP_AUTHEN_AT_END:
+ if(strstr(ttyData, "OK") || (timeout_count > 100))
+ return ret;
+ break;
+ default:
+ break;
+ }
+
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("callTIme:%d, location:%d\n", callTime, enATcmdType);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enATcmdType);
+ timeout_count = 0;
+ return SF_HTTP_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+ }
+
+SINT32 eg91_gps_Isupdate(SF_FN_PARAM_S *pfnParam,UINT8 *pIsupdate,SF_PARA_TIME_S *pNowTime,UINT8 u8day)
+{
+
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pNowTime,SF_FAILURE);
+
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT16 sts =1;
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+
+ SF_PARA_TIME_S preDate;
+
+ SIM_SEARCH_GPS_e enMmcLocation = SIM_SEARCH_GPS_FIRST;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_GPS_ERROR_INS_EXIT;
+ }
+
+ switch(enMmcLocation)
+ {
+ case SIM_SEARCH_GPS_FIRST:
+ sprintf(ttyData, "%s", "AT+QGPSXTRA?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_FIRST_1;
+ break;
+ case SIM_SEARCH_GPS_FIRST_1:
+ if(strstr(ttyData,"+QGPSXTRA: 1"))
+ {
+ sprintf(ttyData, "AT+QGPSXTRADATA?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_QGPSXTRA;
+
+ }
+ else if(strstr(ttyData,"+QGPSXTRA: 0"))
+ {
+ callTime = 0;
+ sprintf(ttyData, "AT+QGPSXTRA=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_FIRST_2;
+ }
+ else if(timeout_count > 200)
+ {
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+
+ }
+ break;
+ case SIM_SEARCH_GPS_FIRST_2:
+ if(strstr(ttyData,"OK"))
+ {
+ sprintf(ttyData, "%s", "AT+QGPSXTRADATA?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_QGPSXTRA;
+ }
+ else
+ {
+ callTime++;
+ if(callTime > 10)
+ return SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ break;
+ case SIM_SEARCH_GPS_QGPSXTRA:
+ if(strstr((const char *)ttyData,"OK"))
+ {
+ if(strstr(ttyData,",\"")!=NULL)
+ {
+ int diffsec = 0;
+ SF_CHAR *CCLK = strstr(ttyData, ",\"");
+
+ preDate.Year = (CCLK[2]- '0')*1000 + (CCLK[3]- '0')*100 + (CCLK[4]-'0')*10 + (CCLK[5]-'0');
+ preDate.Mon = (CCLK[7]- '0')*10 + (CCLK[8]- '0');
+ preDate.Day = (CCLK[10]-'0')*10 + (CCLK[11]-'0');
+ preDate.Hour = (CCLK[13]-'0')*10 + (CCLK[14]-'0');
+ preDate.Min = (CCLK[16]-'0')*10 + (CCLK[17]-'0');
+ preDate.Sec = (CCLK[19]-'0')*10 + (CCLK[20]-'0');
+
+ SLOGD("-[last update time:]-----%d/%d/%d %d:%d:%d\n", preDate.Year, preDate.Mon, preDate.Day, preDate.Hour, preDate.Min, preDate.Sec);
+ SLOGD("-[now update time:]-----%d/%d/%d %d:%d:%d\n", pNowTime->Year, pNowTime->Mon, pNowTime->Day, pNowTime->Hour, pNowTime->Min, pNowTime->Sec);
+
+ diffsec = gps_diffSec_from_date(pNowTime, &preDate);
+ printf("------diffSec:%d--------------------------\n", diffsec);
+
+ *pIsupdate = (diffsec < 0 || diffsec >(u8day*24*3600))?1:0;
+
+ sts = 0;
+ return SF_SUCCESS;
+
+ }
+ else
+ {
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ sprintf(ttyData, "AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ else
+ {
+ callTime++;
+ if(callTime > 10)
+ return SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ break;
+ case SIM_SEARCH_GPS_EXIT:
+ sts = 0;
+ return SF_GPS_ERROR_NOT_MATCH;
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("callTIme:%d, location:%d\n", callTime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enMmcLocation);
+ timeout_count = 0;
+ return SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ }
+ return SF_SUCCESS;
+}
+
+
+SINT32 eg91_gps_search(SF_FN_PARAM_S *pfnParam,SF_PARA_TIME_S *pNowTime,UINT8 autoModeFlag)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pNowTime,SF_FAILURE);
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT16 sts =1;
+ UINT16 calltime = 0;
+ UINT8 pdpdeact = 0;
+ SINT16 ret = SF_FAILURE;
+
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ SIM_SEARCH_GPS_e enMmcLocation = SIM_SEARCH_GPS_FIRST;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_GPS_ERROR_INS_EXIT;
+ }
+
+ switch(enMmcLocation)
+ {
+ case SIM_SEARCH_GPS_FIRST:
+ enMmcLocation = SIM_SEARCH_GPS_DELRAM;
+ sprintf(ttyData, "AT+QFDEL=\"RAM:*\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_SEARCH_GPS_DELRAM:
+ if(strstr(ttyData,"OK") || strstr(ttyData,"ERROR"))
+ {
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ {
+ sprintf(ttyData, "AT+QHTTPCFG=\"contextid\",%d\r", V_PDP_INDEX);
+ }
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ {
+ sprintf(ttyData, "AT+QHTTPCFG=\"contextid\",%d\r", A_PDP_INDEX);
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QHTTPCFG=\"contextid\",%d\r", E_PDP_INDEX);
+ }
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_REQUESTHEADER;
+ }
+ break;
+ case SIM_SEARCH_GPS_REQUESTHEADER:
+ sprintf(ttyData, "AT+QHTTPCFG=\"requestheader\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD1;
+ break;
+ case SIM_SEARCH_GPS_DOWNLOAD1:
+ sprintf(ttyData, "AT+QHTTPCFG=\"responseheader\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD2;
+ break;
+
+ case SIM_SEARCH_GPS_DOWNLOAD2:
+
+ SLOGD("APN:%s \n", pStaticParam->ApnGPRS);
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ {
+ sprintf(ttyData, "AT+QICSGP=%d\r", V_PDP_INDEX);
+ enMmcLocation = SIM_SEARCH_GPS_CSGP;
+ }
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ {
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", A_PDP_INDEX,
+ pStaticParam->ApnGPRS, pStaticParam->ApnUsername, pStaticParam->ApnPassword);
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD3;;
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", E_PDP_INDEX,
+ pStaticParam->ApnGPRS, pStaticParam->ApnUsername, pStaticParam->ApnPassword);
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD3;
+ }
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+
+ case SIM_SEARCH_GPS_CSGP:
+ if(strstr(ttyData, "OK"))
+ {
+ if(strstr(ttyData, "+QICSGP: 0") || strstr(ttyData, "+QICSGP: 1,\"\""))
+ {
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r",V_PDP_INDEX,
+ pStaticParam->ApnGPRS, pStaticParam->ApnUsername, pStaticParam->ApnPassword);
+ }
+ else
+ {
+ sprintf(ttyData, "AT\r");
+ }
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD3;
+ }
+ break;
+
+ case SIM_SEARCH_GPS_DOWNLOAD3:
+ if(strstr(ttyData, "OK"))
+ {
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ sprintf(ttyData, "AT+QIACT=%d\r", V_PDP_INDEX);
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ sprintf(ttyData, "AT+QIACT=%d\r", A_PDP_INDEX);
+ else
+ sprintf(ttyData, "AT+QIACT=%d\r", E_PDP_INDEX);
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD4;
+
+ }
+ break;
+
+ case SIM_SEARCH_GPS_DOWNLOAD4:
+ if(strstr(ttyData, "OK"))
+ {
+ int len=0;
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD5;
+ len = strlen("http://xtrapath3.izatcloud.net/xtra3grc.bin");
+ sprintf(ttyData, "AT+QHTTPURL=%d,80\r", len);
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else if(strstr(ttyData,"ERROR"))
+ {
+ calltime++;
+ SLOGD("calltime++=%d\n",calltime);
+ if(calltime<6)
+ {
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ sprintf(ttyData, "AT+QIACT=%d\r", V_PDP_INDEX);
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ sprintf(ttyData, "AT+QIACT=%d\r", A_PDP_INDEX);
+ else
+ sprintf(ttyData, "AT+QIACT=%d\r", E_PDP_INDEX);
+
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(1700);
+ }
+ else
+ {
+ SLOGE("[ERROR]GPS AT+QIACT over try 6 times\n");
+ calltime = 0;
+ sts = 0;
+ ret = SF_GPS_ERROR_QIACT;
+ }
+ }
+ break;
+
+ case SIM_SEARCH_GPS_DOWNLOAD5:
+ if(strstr(ttyData, "CONNECT"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD6;
+ sprintf(ttyData, "http://xtrapath3.izatcloud.net/xtra3grc.bin\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+ case SIM_SEARCH_GPS_DOWNLOAD6:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD7;
+ sprintf(ttyData, "AT+QHTTPGET=80\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_SEARCH_GPS_DOWNLOAD7:
+ if(strstr(ttyData, "+QHTTPGET: 0,200"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD8;
+ sprintf(ttyData, "AT+QHTTPREADFILE=\"RAM:xtra2.bin\",80\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ calltime++;
+ printf("calltime=%d\n",calltime);
+ if(calltime > 50)
+ {
+ calltime = 0;
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ SLOGE("[ERROR]GPS QHTTPGET time out\n");
+
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ sprintf(ttyData, "AT+QIDEACT=%d\r", V_PDP_INDEX);
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ sprintf(ttyData, "AT+QIDEACT=%d\r", A_PDP_INDEX);
+ else
+ sprintf(ttyData, "AT+QIDEACT=%d\r", E_PDP_INDEX);
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ break;
+ case SIM_SEARCH_GPS_DOWNLOAD8:
+ if(strstr(ttyData,"+QHTTPREADFILE: 0"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD10;
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ sprintf(ttyData, "AT+QIDEACT=%d\r", V_PDP_INDEX);
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ sprintf(ttyData, "AT+QIDEACT=%d\r", A_PDP_INDEX);
+ else
+ sprintf(ttyData, "AT+QIDEACT=%d\r", E_PDP_INDEX);
+
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(ttyData,"+QHTTPREADFILE: 702") != NULL)
+ {
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ SLOGE("[ERROR]GPS +QHTTPREADFILE: 702\n");
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ sprintf(ttyData, "AT+QIDEACT=%d\r", V_PDP_INDEX);
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ sprintf(ttyData, "AT+QIDEACT=%d\r", A_PDP_INDEX);
+ else
+ sprintf(ttyData, "AT+QIDEACT=%d\r", E_PDP_INDEX);
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+ case SIM_SEARCH_GPS_DOWNLOAD9:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_DOWNLOAD10;
+ sprintf(ttyData, "AT+QGPSXTRA=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+ case SIM_SEARCH_GPS_DOWNLOAD10:
+ if(strstr(ttyData,"OK"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_GPS_XTRADATA2;
+ sprintf(ttyData, "AT+QGPSXTRATIME=0,\"%04d/%02d/%02d,%02d:%02d:%02d\",1,1,5\r",
+ pNowTime->Year, pNowTime->Mon, pNowTime->Day, pNowTime->Hour, pNowTime->Min, pNowTime->Sec);
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_SEARCH_GPS_GPS_XTRADATA1:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_GPS_XTRADATA2;
+ sprintf(ttyData, "AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(ttyData, "+QGPSURC") != 0 )
+ {
+ printf("SIYUAN:qrc");
+ enMmcLocation = SIM_SEARCH_GPS_GPS_XTRADATA2;
+ sprintf(ttyData, "AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+
+ }
+ break;
+
+ case SIM_SEARCH_GPS_GPS_XTRADATA2:
+ if(strstr(ttyData, "OK"))
+ {
+
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ sprintf(ttyData, "AT+QGPSXTRADATA=\"RAM:xtra2.bin\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_SEARCH_GPS_ON:
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ sprintf(ttyData, "AT+QGPS=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_SEARCH_GPS_EXIT:
+ sts = 0;
+ return SF_SUCCESS;
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("callTIme:%d, location:%d\n", callTime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enMmcLocation);
+ timeout_count = 0;
+ return SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+}
+SINT32 eg91_gps_preconfig(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+
+ UINT16 timeout_count = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT16 sts =1;
+ UINT16 calltime = 0;
+ UINT8 pdpdeact = 0;
+ UINT8 sendTryTime = 0;
+ SINT16 ret = SF_FAILURE;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ SIM_SEARCH_GPS_e enMmcLocation = SIM_SEARCH_GPS_FIRST;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_GPS_ERROR_INS_EXIT;
+ }
+
+ switch(enMmcLocation)
+ {
+ case SIM_SEARCH_GPS_FIRST:
+ enMmcLocation = SIM_SEARCH_GPS_ON;
+ sprintf(ttyData, "%s", "AT+QGPSCFG=\"outport\",\"uartdebug\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_SEARCH_GPS_ON:
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ sprintf(ttyData, "AT+QGPS=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+
+ case SIM_SEARCH_GPS_LOC:
+ if(strstr(ttyData,"OK"))
+ {
+ enMmcLocation = SIM_SEARCH_GPS_END;
+ sprintf(ttyData, "AT+QGPSLOC=2\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ calltime = 0;
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ if(sendTryTime == 0)
+ {
+ calltime = 0;
+ sendTryTime++;
+ enMmcLocation = SIM_SEARCH_GPS_ON;
+ sprintf(ttyData, "AT+QGPSEND\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SLOGE("[ERROR] GPS ON ERR, Try:%d\n", sendTryTime);
+ }
+ else
+ {
+ calltime = 0;
+ sendTryTime = 0;
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ sprintf(ttyData, "AT+QGPSEND\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SLOGE("[ERROR] GPS ON ERR\n");
+ }
+ }
+ break;
+
+ case SIM_SEARCH_GPS_END:
+ if(strstr(ttyData, "ERROR") != 0)
+ {
+ //3minite timeout.
+ if(calltime > GPS_SEARCH_TIMEOUT_TIMES)
+ {
+ calltime = 0;
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ pStaticParam->DialyReportFailCnt++;
+ sprintf(ttyData, "AT+QGPSEND\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SLOGE("[ERROR] GPS timeout\n");
+ sts = 0;
+ ret = SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QGPSLOC=2\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ calltime++;
+ sf_sleep_ms(100);
+
+ }
+ else if(strstr(ttyData, "+QGPSLOC:") != 0)
+ {
+ printf("--------Loc:----------------------\n");
+
+ SF_CHAR *str=NULL;
+ strtok(ttyData,",");
+ str = strtok(NULL,",");
+ if(NULL!=str)
+ {
+ strcpy(pStaticParam->Latitude,str);
+ //sf_gps_infor_convert(&sim_info_t->Latitude[5]);
+ }
+ str = strtok(NULL,",");
+ if(NULL!=str)
+ {
+ strcpy(pStaticParam->Longitude,str);
+ //sf_gps_infor_convert(&sim_info_t->Longitude[6]);
+ }
+
+ //sf_set_netsearch_step(SIM_NETSEARCH_STEP_GPS);
+ pStaticParam->DialyReportFailCnt = 0;
+
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ calltime = 0;
+ sprintf(ttyData, "AT+QGPSEND\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ printf("SIYUAN-Bob:latitude=%s,longitude=%s\n", pStaticParam->Latitude, pStaticParam->Longitude);
+ }
+ break;
+ case SIM_SEARCH_GPS_EXIT:
+ sts = 0;
+ if(pdpdeact)
+ {
+ pdpdeact = 0;
+ //sf_pdp_flg_set(0);
+ }
+ return SF_SUCCESS;
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("callTIme:%d, location:%d\n", calltime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enMmcLocation);
+ timeout_count = 0;
+ return SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+}
+
+SINT32 eg91_gps_search_result(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+
+ UINT16 timeout_count = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT16 sts =1;
+ UINT16 calltime = 0;
+ UINT8 pdpdeact = 0;
+ UINT8 sendTryTime = 0;
+ SINT16 ret = SF_SUCCESS;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ SIM_SEARCH_GPS_e enMmcLocation = SIM_SEARCH_GPS_LOC;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_GPS_ERROR_INS_EXIT;
+ }
+
+ switch(enMmcLocation)
+ {
+ case SIM_SEARCH_GPS_ON:
+ enMmcLocation = SIM_SEARCH_GPS_LOC;
+ sprintf(ttyData, "AT+QGPS=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_SEARCH_GPS_LOC:
+
+ #ifndef SF_GPS_TEST
+ enMmcLocation = SIM_SEARCH_GPS_END;
+ #endif
+ sprintf(ttyData, "AT+QGPSLOC?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ #ifdef SF_GPS_TEST
+ calltime++;
+ #else
+ calltime = 0;
+ #endif
+ break;
+ case SIM_SEARCH_GPS_END:
+ if(strstr(ttyData, "ERROR") != 0)
+ {
+
+ if(calltime > GPS_SEARCH_TIMEOUT_TIMES)
+ {
+ calltime = 0;
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ pStaticParam->DialyReportFailCnt++;
+
+ sprintf(ttyData, "AT+QGPSEND\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SLOGE("[ERROR] GPS timeout\n");
+ ret = SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QGPSLOC?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ calltime++;
+ sf_sleep_ms(100);
+
+ }
+ else if(strstr(ttyData, "+QGPSLOC:") != 0)
+ {
+
+ SF_CHAR *str=NULL;
+ strtok(ttyData,",");
+ str = strtok(NULL,",");
+ if(NULL!=str)
+ {
+ strcpy(pStaticParam->Latitude,str);
+ gps_infor_convert(&pStaticParam->Latitude[5]);
+ }
+ str = strtok(NULL,",");
+ if(NULL!=str)
+ {
+ strcpy(pStaticParam->Longitude,str);
+ gps_infor_convert(&pStaticParam->Longitude[6]);
+ }
+
+
+ enMmcLocation = SIM_SEARCH_GPS_EXIT;
+ calltime = 0;
+ sprintf(ttyData, "AT+QGPSEND\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ printf("SIYUAN-Bob:latitude=%s,longitude=%s\n", pStaticParam->Latitude, pStaticParam->Longitude);
+ }
+ break;
+ case SIM_SEARCH_GPS_EXIT:
+ sts = 0;
+ return SF_SUCCESS;
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("callTIme:%d, location:%d\n", calltime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ #ifndef SF_GPS_TEST
+ timeout_count++;
+ #endif
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enMmcLocation);
+ timeout_count = 0;
+ return SF_GPS_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+}
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/source/4gMng/sf_eg91_server.c b/code/application/source/sf_app/code/source/4gMng/sf_eg91_server.c
new file mode 100755
index 000000000..8c0a66715
--- /dev/null
+++ b/code/application/source/sf_app/code/source/4gMng/sf_eg91_server.c
@@ -0,0 +1,1451 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+#include "sf_log.h"
+
+#include "sf_hal_ttyusb.h"
+#include "sf_opera_adapt.h"
+#include "sf_param_common.h"
+#include "sf_eg91_server.h"
+#include "sf_dataMng.h"
+#include "cJSON.h"
+#include "sf_base64.h"
+SINT32 eg91_file_to_module(SF_CHAR *fileName, SINT32 *fileSize, SF_FILE_TYPE_E fileType)
+{
+ SF_COMM_CHECK_POINTER(fileName,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(fileSize,SF_FAILURE);
+
+ SINT32 fileFd = 0;
+ SINT32 tolFileSize = 0;
+ SINT32 readSize = 0;
+ UINT16 count = 0;
+ SINT16 ret = SF_SUCCESS;
+ SINT16 ret1 = SF_SUCCESS;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR tempFileName[32] = { 0 };
+ SF_CHAR *pBuf = NULL;
+ SF_CHAR *bufBak = NULL;
+ struct stat statBuf;
+
+ SLOGD("fileName:%s type: %d,filename :%d \n",fileName,fileType,strlen(fileName));
+
+ sprintf(ttyData, "AT+QFDEL=\"*\"\r");
+
+ ret1 = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+
+ sf_hal_ttyusb2_read(ttyData, 150);
+ SLOGD("filename:%s\n", fileName);
+
+ fileFd = open(fileName, O_RDONLY);
+
+ if(fileFd)
+ {
+ fstat(fileFd, &statBuf);
+ tolFileSize = statBuf.st_size;
+ *fileSize = tolFileSize;
+ SLOGD("tolFileSize:%d\n", *fileSize);
+
+ if(tolFileSize > 1024*1024*5)
+ {
+ bufBak = malloc(1024*1024*5);
+ }
+ else
+ {
+ bufBak = malloc(tolFileSize);
+ }
+
+ if(bufBak)
+ {
+ if(fileType == SF_FILE_TYPE_PIC_BIG)
+ memcpy(tempFileName, fileName + (strlen(fileName) - SF_PIC_NAME_LEN), SF_PIC_NAME_LEN);
+ else if(fileType == SF_FILE_TYPE_PIC_SMALL ||fileType == SF_FILE_TYPE_PIC_VIDEO)
+ memcpy(tempFileName, fileName + (strlen(fileName) - SF_PIC_NAME_LEN), SF_PIC_NAME_LEN);
+ else if(fileType == SF_FILE_TYPE_VIDEO)
+ memcpy(tempFileName, fileName + (strlen(fileName) - SF_PIC_NAME_LEN), SF_PIC_NAME_LEN);
+ else if(fileType == SF_FILE_TYPE_LOG_ERROR)
+ memcpy(tempFileName, fileName + (strlen(fileName) - ERROR_LOG_NAME_LEN), ERROR_LOG_NAME_LEN);
+ else if(fileType == SF_FILE_TYPE_GPS)
+ memcpy(tempFileName, fileName + (strlen(fileName) - GPS_LOG_NAME_LEN), GPS_LOG_NAME_LEN);
+ else if(fileType == SF_FILE_TYPE_BT_ALARM)
+ memcpy(tempFileName, fileName + (strlen(fileName) - BT_ALARM_NAME_LEN), BT_ALARM_NAME_LEN);
+ else if(fileType == SF_FILE_TYPE_FOTA)
+ strcpy(tempFileName,OTA_FTP_UPDATAFILENAME);
+ else
+ memcpy(tempFileName, fileName + (strlen(fileName) - 15), 15);
+
+ SLOGD("tempFileName:%s\n", tempFileName);
+ sprintf(ttyData, "AT+QFUPL=\"%s\",%d\r", tempFileName, tolFileSize);
+ SLOGD("sendbuf:%s\n", ttyData);
+
+ ret1 = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ret1, ret1);
+ sf_hal_ttyusb2_read(ttyData, 200);
+
+ while(count < 15)
+ {
+ count++;
+ SLOGD("ttyData:%s\n", ttyData);
+
+ if(strstr(ttyData,"+CME ERROR"))
+ {
+ SLOGE("recv error!\n");
+ ret = SF_4G_ERROR_AT_READ;
+ break;
+ }
+ else if(strstr(ttyData,"CONNECT"))
+ {
+ //MLOGD("read file\n");
+ while(tolFileSize > 0)
+ {
+ pBuf = bufBak;
+ if(tolFileSize >= 1024*1024*5)
+ readSize = read(fileFd, pBuf, 1024*1024*5);
+ else
+ readSize = read(fileFd, pBuf, tolFileSize);
+
+ SLOGD("send file data, tolFileSize:%d, read size:%d\n", tolFileSize, readSize);
+ tolFileSize -= readSize;
+
+
+ while(readSize > 0)
+ {
+ if(readSize > 10240)
+ {
+ //sf_hal_ttyusb2_write(fd, pBuf, 10240);
+ ret1 = sf_hal_ttyusb2_write(pBuf, 10240);
+ SF_APPCOMM_CHECK_RETURN(ret1, ret1);
+
+ readSize -= 10240;
+ pBuf += 10240;
+ }
+ else
+ {
+ //sf_hal_ttyusb2_write(fd, pBuf, readSize);
+ ret1 = sf_hal_ttyusb2_write(pBuf, readSize);
+ SF_APPCOMM_CHECK_RETURN(ret1, ret1);
+ pBuf += readSize;
+ readSize = 0;
+ }
+ sf_sleep_ms(1);
+ }
+ }
+
+ sf_hal_ttyusb2_read(ttyData, 300);
+ SLOGD("ttyData:%s\n", ttyData);
+
+ if((strstr(ttyData,"+QFUPL:")))
+ {
+ //nothing to do
+ }
+ else
+ {
+ sf_hal_ttyusb2_read(ttyData, 300);
+ }
+ SLOGD("send end\n");
+ SLOGD("send end\n");
+ break;
+ }
+ else
+ {
+ sf_hal_ttyusb2_read(ttyData, 300);
+ }
+ }
+
+ SLOGD("\n");
+ free(bufBak);
+ close(fileFd);
+ }
+ else
+ {
+ SLOGE("malloc buf fail!\n");
+ close(fileFd);
+ ret = SF_4G_ERROR_FILE_SEND;
+ }
+ }
+ else
+ {
+ SLOGE("open file error!\n");
+ }
+
+ SLOGD("\n");
+ return ret;
+ }
+
+static SINT16 eg91_ip_get(cJSON *object, SF_CHAR *webIP, SF_CHAR *acmIP)
+{
+ SF_CHAR tempStr[128] = {0};
+ SF_CHAR decode_tempStr[128] = {0};
+ UINT8 type = 0;
+
+ type = cJSON_GetObjectItem(object,"serverType")->valueSINT32;
+ sprintf(tempStr,"%s",cJSON_GetObjectItem(object,"ip")->valuestring);
+ printf("type:%d,ip:%s\n",type,tempStr);
+
+ sf_base64_decode(tempStr,decode_tempStr);
+ printf("decode_tempStr=%s\n",decode_tempStr);
+ if(SF_NULL == strlen(decode_tempStr))
+ return SF_FAILURE;
+
+ if(type == 1)
+ {
+ sprintf(webIP,"%s",decode_tempStr);
+ }
+ else if(type == 2)
+ {
+ sprintf(acmIP,"%s",decode_tempStr);
+ }
+ else
+ {
+ memset(acmIP, '\0', strlen(acmIP));
+ memset(acmIP, '\0', strlen(acmIP));
+ return SF_FAILURE;
+ }
+ return SF_SUCCESS;
+
+}
+static SINT16 eg91_parse_server_get(SF_CHAR *buf, SF_CHAR *webIp, SF_CHAR *acmIp)
+ {
+ SF_COMM_CHECK_POINTER(buf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(webIp,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(acmIp,SF_FAILURE);
+
+ cJSON_Hooks hooks = {malloc, free};
+
+ UINT8 statu[5] = {1};
+ UINT8 msg[10] = {0};
+ SINT16 errorcode = SF_SUCCESS;
+
+ cJSON_InitHooks(&hooks);
+ cJSON *root = cJSON_Parse(buf);
+
+ sprintf((SF_CHAR*)statu,"%s",cJSON_GetObjectItem(root,"statu")->valuestring);
+ errorcode = cJSON_GetObjectItem(root,"errCode")->valueSINT32;
+ printf("statu=%s\n",statu);
+ printf("errCode=%d\n",errorcode);
+ if(!strstr(buf,"null"))
+ {
+ cJSON *content = cJSON_GetObjectItem(root,"content");/**/
+ cJSON *object1 = cJSON_GetArrayItem(content,0);
+ cJSON *object2 = cJSON_GetArrayItem(content,1);
+ eg91_ip_get(object1, webIp, acmIp);
+ eg91_ip_get(object2, webIp, acmIp);
+ }
+
+ cJSON_Delete(root);
+
+ printf("webIp=%s\n",webIp);
+ printf("acmIp=%s\n",acmIp);
+ printf("ret=%d\n",errorcode);
+ return errorcode;
+
+ }
+
+ UINT32 eg91_parse_server_get_time(UINT8 *buf)
+ {
+ SF_COMM_CHECK_POINTER(buf,SF_FAILURE);
+ cJSON_Hooks hooks = {malloc, free};
+
+ UINT8 statu[10] = {0};
+ UINT32 errCode = 0;
+
+ cJSON_InitHooks(&hooks);
+
+ printf("dest_buf = %s\n", buf);
+ cJSON *root = cJSON_Parse((SF_CHAR*)buf);
+
+ sprintf((SF_CHAR*)statu,"%s",cJSON_GetObjectItem(root,"statu")->valuestring);
+
+ errCode = cJSON_GetObjectItem(root,"errCode")->valueSINT32;
+ printf("statu=%s\n",statu);
+ printf("errCode=%d\n",errCode);
+ if(strstr((SF_CHAR*)buf,"null"))
+ {
+
+ }
+ else
+ {
+ cJSON *content = cJSON_GetObjectItem(root, "content");/**/
+ printf("%s,%d\n", __FUNCTION__, __LINE__);
+ sprintf((SF_CHAR*)buf, "%s", cJSON_GetObjectItem(content,"greenDate")->valuestring);
+ printf("buf:%s\n", buf);
+ //cJSON_Delete(content);
+ }
+ cJSON_Delete(root);
+
+ return errCode;
+
+ }
+
+SINT32 eg91_http_config(SF_FN_PARAM_S *pfnParam, UINT8 sslOn, UINT8 autoReqHead)
+ {
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ SINT32 ttyRet = SF_SUCCESS;
+ SINT32 ret = SF_SUCCESS;
+ UINT16 timeout_count = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ MODULE_HTTP_CONFIG_E enATcmdType = MODULE_HTTP_CONFIG_AT_QICSGP;
+ SF_PDT_PARAM_STATISTICS_S *pstParamInfo = pfnParam->pstaticParam;
+
+
+ while(1)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch(enATcmdType)
+ {
+ case MODULE_HTTP_CONFIG_AT_ATW:
+ sprintf(ttyData,"%s","AT&W\r");
+ enATcmdType = MODULE_HTTP_CONFIG_AT_QICSGP;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QICSGP:
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", HTTP_PDP, pstParamInfo->ApnGPRS, pstParamInfo->ApnUsername, pstParamInfo->ApnPassword);
+ enATcmdType = MODULE_HTTP_CONFIG_AT_QHTTPCFG_1;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QHTTPCFG_1:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData, "AT+QHTTPCFG=\"contextid\",%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_CONFIG_AT_QHTTPCFG_2;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ return SF_4G_ERROR_AT_APN;
+ }
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QHTTPCFG_2:
+ if(strstr(ttyData, "OK"))
+ {
+ if(sslOn)
+ enATcmdType = MODULE_HTTP_CONFIG_AT_QHTTPCFG_3;
+ else
+ enATcmdType = MODULE_HTTP_CONFIG_AT_END;
+
+ timeout_count = 0;
+ if(autoReqHead)
+ sprintf(ttyData,"AT+QHTTPCFG=\"requestheader\",0\r");
+ else
+ sprintf(ttyData,"AT+QHTTPCFG=\"requestheader\",1\r");
+
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QHTTPCFG_3:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData,"%s", "AT+QHTTPCFG=\"sslctxid\",1\r");
+ enATcmdType = MODULE_HTTP_CONFIG_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QSSLCFG_1:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData,"%s","AT+QSSLCFG=\"sslversion\",1,4\r");
+ enATcmdType = MODULE_HTTP_CONFIG_AT_QSSLCFG_2;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QSSLCFG_2:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData,"%s","AT+QSSLCFG=\"ciphersuite\",1,0XFFFF\r");
+ enATcmdType = MODULE_HTTP_CONFIG_AT_QSSLCFG_3;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_QSSLCFG_3:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ enATcmdType = MODULE_HTTP_CONFIG_AT_END;
+ sprintf(ttyData,"%s","AT+QSSLCFG=\"seclevel\",1,0\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_CONFIG_AT_END:
+ if(strstr(ttyData, "OK"))
+ return SF_SUCCESS;
+ break;
+
+ default:
+ break;
+ }
+
+ SLOGD("sendBuf******\n %s \n*********************\n\n",ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ MLOGI("timeout_count:%d, location:%d\n", timeout_count, enATcmdType);
+ SLOGD("revBuf******\n %s \n*********************\n\n",ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]AT timeout, enATcmdType=%d\n", enATcmdType);
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+
+ return ret;
+ }
+
+ SINT32 eg91_http_authenrequst(SF_FN_PARAM_S *pfnParam)
+ {
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ SINT32 ttyRet = SF_SUCCESS;
+ SINT32 ret = SF_SUCCESS;
+ SINT32 errorcode = 0;
+ SINT16 sts = 1;
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+ UINT8 reHttpSRequest=0;
+ UINT8 authenrequstCnt = 0;
+ SF_CHAR *P1 = NULL;
+ SF_CHAR *P2 = NULL;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR dataStr[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR webStr[40] = {0};
+ SF_CHAR acmStr[40] = {0};
+ MODULE_SERVER_AUTHEN_E enATcmdType = MODULE_HTTP_AUTHEN_AT_QIACT;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;/* Added by MaxLi 2022/03/02--15:5:56*/
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch(enATcmdType)
+ {
+ case MODULE_HTTP_AUTHEN_AT_QIACT:
+ sprintf(ttyData,"AT+QIACT=%d\r",HTTP_PDP);/**/
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPURL_1:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ sprintf(dataStr,"https://%s/device/imeiAndMSisdn?imei=%s&iccid=%s", pStaticParam->WebIP, pStaticParam->IMEI, pStaticParam->SimID);
+ sprintf(ttyData, "AT+QHTTPURL=%d,80\r",strlen(dataStr));
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_2;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ callTime++;
+ if(callTime < PDP_TRY_TIME)
+ {
+ sf_sleep_s(2);
+ sprintf(ttyData, "AT+QIACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ callTime=0;
+ sts = 0;
+ ret = SF_4G_ERROR_AT_ACTIVE;
+ SLOGE("Moudle QIACT ERROR.DATA:%s", ttyData);
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+
+
+ }
+ }
+ else if(timeout_count > 100)
+ {
+ sts = 0;
+ ret = SF_4G_ERROR_AT_ACTIVE;
+ SLOGE("Moudle QIACT timeout");
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPURL_2:
+ if(strstr(ttyData, "CONNECT"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData,"https://%s/device/imeiAndMSisdn?imei=%s&iccid=%s", pStaticParam->WebIP, pStaticParam->IMEI, pStaticParam->SimID);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPGET;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPGET:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ sprintf(ttyData,"%s","AT+QHTTPGET=80\r");
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPREAD;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QHTTPREAD:
+ timeout_count = 0;
+ callTime++;
+ if(strstr(ttyData, "+QHTTPGET:"))
+ {
+ if(strstr(ttyData, "+QHTTPGET: 0,200"))
+ {
+ timeout_count= 0;
+ callTime = 0;
+ sprintf(ttyData,"%s","AT+QHTTPREAD=80\r");
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QIDEACT;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(reHttpSRequest == 0)
+ {
+ SLOGW("HTTP Send Failed,try again\n");
+
+ reHttpSRequest = 1;
+ sprintf(ttyData,"%s","AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ }
+ else
+ {
+ SLOGE("HTTP Send Failed,data:%s\n", ttyData);
+ SLOGE("FAILED:send http failed!!!!!\n");
+
+ ret = SF_HTTP_ERROR_REQUEST;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ }
+ }
+ else
+ {
+ if((strstr(ttyData,"ERROR")) || (callTime > 400))
+ {
+ if(reHttpSRequest == 0)
+ {
+ SLOGW("HTTP Send timeout,try again\n");
+ reHttpSRequest = 1;
+ sprintf(ttyData,"%s","AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ }
+ else
+ {
+ SLOGW("HTTP Send timeout,data:%s", ttyData);
+ MLOGW("FAILED:send http timeout!!!!!\n");
+ ret = SF_HTTP_ERROR_REQUEST;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ }
+ }
+
+ }
+
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_QIDEACT:
+ timeout_count = 0;
+ P1 = strstr(ttyData, "OK");
+ if(P1)
+ {
+ memset(dataStr,'\0', sizeof(dataStr));
+
+ P2 = strstr(ttyData,"{");
+ if(P2 != NULL)
+ {
+ strncpy(dataStr, P2, P1-P2);
+ errorcode = eg91_parse_server_get(dataStr, webStr, acmStr);
+ }
+ if((errorcode == SF_SUCCESS) && (webStr[0] != '\0') && (acmStr[0] != '\0'))
+ {
+ if(authenrequstCnt < 6)
+ {
+
+ sprintf(pStaticParam->WebIP, "%s", webStr);
+ memset(pStaticParam->AcmIP,'\0', sizeof(pStaticParam->AcmIP));
+ sprintf(pStaticParam->AcmIP, "%s", acmStr);
+
+ memset(webStr,'\0', sizeof(webStr));
+ memset(acmStr,'\0', sizeof(acmStr));
+
+ reHttpSRequest = 0;
+ authenrequstCnt++;
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_QHTTPURL_1;
+ sprintf(ttyData, "AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ ret = SF_HTTP_ERROR_AT_TIMEOUT;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ else
+ {
+ if(errorcode == 30004)
+ ret = SF_4G_ERROR_NO_SUPPOET;
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ /*else if(callTime > 400)
+ {
+ SLOGD("HTTP Read timeout,data:%s", ttyData);
+ MLOGD("FAILED:send http timeout!!!!!\n");
+ callTime = 0;
+ sts = 0;
+ ret = SF_HTTP_ERROR_READ;
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }*/
+ else
+ {
+ if(callTime < 5)
+ {
+ sprintf(ttyData,"%s","AT+QHTTPREAD=80\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else
+ {
+ callTime = 0;
+ sts = 0;
+ ret = SF_HTTP_ERROR_AT_READ;
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_HTTP_AUTHEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ }
+ callTime++;
+ break;
+
+ case MODULE_HTTP_AUTHEN_AT_END:
+ if(strstr(ttyData, "OK") || (timeout_count > 100))
+ return ret;
+ break;
+
+ default:
+ break;
+ }
+ SLOGI("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ MLOGI("callTIme:%d, location:%d\n", callTime, enATcmdType);
+ SLOGI("revBuf******\n %s \n*********************\n\n", ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enATcmdType);
+ timeout_count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+
+ return ret;
+ }
+
+ SINT32 eg91_http_pushfile(SF_FILE_ATTR_S *pstFileAttr,SF_FN_PARAM_S *pfnParam)
+ {
+ SF_COMM_CHECK_POINTER(pstFileAttr,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstFileAttr->txtfileName,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ SINT32 ttyRet = SF_SUCCESS;
+ SINT32 ret = SF_SUCCESS;
+ // SINT16 sts = 1;
+ UINT16 timeout_count = 0;
+ UINT8 reHttpSRequest = 0;
+ UINT16 callTime = 0;
+ UINT8 sendfailedcnt = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR tempIP[128] = { 0 };
+
+ MODULE_SERVER_SENDFILE_E enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPCFG;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ while(1)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+ switch(enATcmdType)
+ {
+
+ case MODULE_SERVER_SENDFILE_AT_QHTTPCFG:
+ sprintf(ttyData, "AT+QIACT=%d\r", HTTP_PDP);/**/
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPURL_1;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_SERVER_SENDFILE_AT_QHTTPURL_1:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ if(sf_data_transfer_mode_get() == SF_UPLOAD_OSS)
+ {
+ sprintf(tempIP, "http://%s", pStaticParam->stOssCfg.szIP);
+ sprintf(ttyData, "AT+QHTTPURL=%d,80\r", strlen(tempIP));
+
+ }
+ else
+ {
+ sprintf(tempIP, "http://%s.%s", pStaticParam->stOssCfg.szBucket, AMZ_HOST);
+ sprintf(ttyData, "AT+QHTTPURL=%d,80\r", strlen(tempIP));
+ }
+
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPURL_2;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ callTime++;
+ if(callTime < PDP_TRY_TIME)
+ {
+ sf_sleep_s(2);
+ sprintf(ttyData, "AT+QIACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ callTime=0;
+ ret = SF_4G_ERROR_AT_ACTIVE;
+ SLOGD("Moudle QIACT ERROR.DATA:%s", ttyData);
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+
+
+ }
+ }
+ else if(timeout_count > 100)
+ {
+ ret = SF_4G_ERROR_AT_ACTIVE;
+ SLOGD("Moudle QIACT timeout");
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_SENDFILE_AT_QHTTPURL_2:
+ if(strstr(ttyData, "CONNECT"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData,"%s\r", tempIP);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPPOSTFILE;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_SENDFILE_AT_QHTTPPOSTFILE:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ sprintf(ttyData, "AT+QHTTPPOSTFILE=\"%s\",80\r", pstFileAttr->txtfileName);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTREAD;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_SENDFILE_AT_QHTTREAD:
+ timeout_count = 0;
+ if((strstr(ttyData, "+QHTTPPOSTFILE:")) || (strstr(ttyData,",200,")))
+ {
+ if((strstr(ttyData,",200,")))
+ {
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if((strstr(ttyData,"400")) || (strstr(ttyData,"403")))
+ {
+ sendfailedcnt++;
+ if(sendfailedcnt > 1)
+ {
+ callTime = 0;
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sendfailedcnt= 0;
+ ret = SF_HTTP_ERROR_FILE_SEND;
+ }
+ else
+ {
+ callTime = 0;
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPCFG;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+
+ }
+ else
+ {
+ if(reHttpSRequest == 0)
+ {
+ reHttpSRequest = 1;
+ printf("FAILED:send http file failed,try again!!!!!\n");
+ SLOGD("HTTP Send OSS Failed,try again.");
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPPOSTFILE;
+ strcpy(ttyData, "AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ SLOGD("HTTP Send File Failed.");
+ printf("FAILED:send http file failed!!!!!\n");
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_END_1;
+ ret = SF_HTTP_ERROR_FILE_SEND;
+ sprintf(ttyData, "AT+QIDEACT=%d\r",HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ }
+ else if(callTime > 400)
+ {
+ if(reHttpSRequest == 0)
+ {
+ reHttpSRequest = 1;
+ printf("FAILED:send http file timeout,try again!!!!!\n");
+ SLOGD("HTTP Send OSS timeout,try again.");
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_QHTTPPOSTFILE;
+ strcpy(ttyData, "AT\r");
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ SLOGD("HTTP Send File timeout.");
+ printf("FAILED:send http file timeout!!!!!\n");
+ callTime = 0;
+ ret = SF_HTTP_ERROR_FILE_SEND;
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_END;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", HTTP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ callTime++;
+ break;
+ case MODULE_SERVER_SENDFILE_AT_END_1:
+ timeout_count = 0;
+ if(strstr(ttyData, "OK"))
+ {
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(callTime > 400)
+ {
+ SLOGD("HTTP Read timeout,data:%s", ttyData);
+ MLOGD("FAILED:send http timeout!!!!!\n");
+ callTime = 0;
+ ret = SF_HTTP_ERROR_AT_READ;
+ sprintf(ttyData,"AT+QIDEACT=%d\r",HTTP_PDP);
+ enATcmdType = MODULE_SERVER_SENDFILE_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ callTime++;
+ break;
+
+ case MODULE_SERVER_SENDFILE_AT_END:
+ if(strstr(ttyData, "OK") || (timeout_count > 100))
+ return ret;
+ break;
+
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n",ttyData);
+
+ sf_hal_ttyusb2_read(ttyData, 200);
+ MLOGD("callTIme:%d, location:%d\n", callTime, enATcmdType);
+ SLOGD("revBuf******\n %s \n*********************\n\n",ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enATcmdType);
+ timeout_count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+
+ }
+ return SF_SUCCESS;
+ }
+SINT32 eg91_server_acm_open(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+
+ SINT16 ttyRet = SF_SUCCESS;
+ SINT16 ret = SF_SUCCESS;
+ SINT16 sts = 1;
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+ UINT16 reOpenTimes = 2;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR tempStr[32] = { 0 };
+ MODULE_SERVER_ACM_OPEN_E enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QISTATE;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ SLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch(enATcmdType)
+ {
+ case MODULE_SERVER_ACM_OPEN_AT_QICSGP:
+ if(strstr(ttyData, "OK") || strstr(ttyData, "ERROR"))
+ {
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QIACT;
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", TCP_PDP, pStaticParam->ApnGPRS, pStaticParam->ApnUsername, pStaticParam->ApnPassword);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_QISTATE:
+ sprintf(ttyData, "AT+QISTATE=0,%d\r", TCP_PDP);/**/
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QISTATE_CHECK;
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_QISTATE_CHECK:/**/
+ if(strstr(ttyData,"+QISTATE:"))
+ {
+
+ /*
+ UINT8 qiState[7][20] ={0};
+ UINT8 i = 0;
+ strcpy((char*)qiState[i],strtok(ttyData, ","));
+ while(i<6)
+ {
+ i++;
+ strcpy((char*)qiState[i],strtok(NULL, ","));
+ MLOGD("qiState=%s\n",qiState[i]);
+ }
+ */
+ char *p = NULL;
+ p = strstr(ttyData,"+QISTATE:");
+ p = strchr(p, ',');
+ p = strchr(p+1, ',');
+ p = strchr(p+1, ',');
+ p = strchr(p+1, ',');
+ p = strchr(p+1, ',');
+
+ //if(strncmp((char*)qiState[i], "2", 1) == 0)
+ if(atoi(p+1) == 2)
+ {
+ MLOGD("Keep alive login ACM.\n");
+ sprintf(ttyData, "AT+QIRD=%d,228\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(atoi(p+1) == 4)
+ {
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QIDEACT;
+ sprintf(ttyData, "AT+QICLOSE=%d,1\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QICSGP;
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ }
+ else if((strstr(ttyData,"OK")) || (timeout_count > 200))
+ {
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QIDEACT;
+ sprintf(ttyData, "AT+QICLOSE=%d,1\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+ case MODULE_SERVER_ACM_OPEN_AT_QISTATE_TEST:
+ sprintf(ttyData, "AT+QIRD=%d,228\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_QIDEACT:/**/
+ if(strstr(ttyData, "OK") || strstr(ttyData, "ERROR"))
+ {
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QICSGP;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_QIACT:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ sprintf(ttyData, "AT+QIACT=%d\r", TCP_PDP);/**/
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QICFG;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ sts = 0;
+ ret = SF_4G_ERROR_AT_READ;
+ }
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_QICFG:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ sprintf(ttyData,"%s","AT+QICFG=\"tcp/keepalive\",1,3,25,3\r");/**/
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_QIOPEN;
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else if(strstr(ttyData, "ERROR"))
+ {
+ callTime++;
+ if(callTime < TCP_PDP_TRY_TIME)
+ {
+ sf_sleep_s(2);
+ sprintf(ttyData, "AT+QIACT=%d\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ callTime=0;
+ sts = 0;
+ ret = SF_4G_ERROR_AT_ACTIVE;
+ MLOGE("Moudle QIACT ERROR.DATA:%s\n", ttyData);
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ else if(timeout_count > 100)
+ {
+ sts = 0;
+ ret = SF_4G_ERROR_AT_ACTIVE;
+ MLOGE("Moudle QIACT timeout\n");
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_QIOPEN:
+ if(strstr(ttyData, "OK"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ #if defined(CFG_TRANSDATA_AT)
+ sprintf(ttyData,"AT+QIOPEN=%d,%d,\"TCP\",\"%s\",%d,0,0\r", TCP_PDP, TCP_PDP, pStaticParam->AcmIP, 6600);
+ #else
+ sprintf(ttyData,"AT+QIOPEN=%d,%d,\"TCP\",\"%s\",%d,0,0\r", TCP_PDP, TCP_PDP, pStaticParam->AliveIp, pStaticParam->AlivePort);
+ #endif
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_ATE0;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if((strstr(ttyData, "ERROR")) || (callTime > 100))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ #if defined(CFG_TRANSDATA_AT)
+ sprintf(ttyData,"AT+QIOPEN=%d,%d,\"TCP\",\"%s\",%d,0,0\r", TCP_PDP, TCP_PDP, pStaticParam->AcmIP, 6600);
+ #else
+ sprintf(ttyData,"AT+QIOPEN=%d,%d,\"TCP\",\"%s\",%d,0,0\r", TCP_PDP, TCP_PDP, pStaticParam->AliveIp, pStaticParam->AlivePort);
+ #endif
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_ATE0;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ callTime++;
+ }
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_ATE0:
+ timeout_count = 0;
+ SF_CHAR *pbuf = NULL;
+ pbuf = strstr(ttyData, "+QIOPEN:");
+
+ if(pbuf != NULL)
+ {
+ memcpy(tempStr, pbuf, 12);
+ }
+
+ if((strncmp(tempStr, "+QIOPEN:", 8) == 0)&&(tempStr[11]=='0'))
+ {
+ return SF_SUCCESS;
+ }
+ else if(((strncmp(tempStr, "+QIOPEN:", 8) == 0)&&(tempStr[11]!='0')) || (strncmp(tempStr, "+CME ERROR", 10) == 0))
+ {
+ if(reOpenTimes)
+ {
+ reOpenTimes--;
+ MLOGE("QIOPEN Fail, re connect acm.\n");
+ #if defined(CFG_TRANSDATA_AT)
+ sprintf(ttyData,"AT+QIOPEN=%d,%d,\"TCP\",\"%s\",%d,0,0\r", TCP_PDP, TCP_PDP, pStaticParam->AcmIP, 6600);
+ #else
+ sprintf(ttyData,"AT+QIOPEN=%d,%d,\"TCP\",\"%s\",%d,0,0\r", TCP_PDP, TCP_PDP, pStaticParam->AliveIp, pStaticParam->AlivePort);
+ #endif
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+
+ }
+ else
+ {
+ MLOGE("Re connect acm fail.\n");
+ ret = SF_4G_ERROR_AT_OPEN;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ else
+ {
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ if(callTime > 600)
+ {
+ MLOGE("Connect acm timeout.\n");
+ ret = SF_4G_ERROR_AT_TIMEOUT;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_OPEN_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ callTime++;
+ break;
+
+ case MODULE_SERVER_ACM_OPEN_AT_END:
+ if(strstr(ttyData, "OK"))
+ {
+ return ret;
+ }
+ if(!strstr(ttyData, "+QIRD: 0") && (ret == SF_SUCCESS))
+ {
+ memset(&pfnParam->arrttyData, '\0', SF_TTYUSB_RECV_MAX);
+ memcpy(&pfnParam->arrttyData, ttyData, SF_TTYUSB_RECV_MAX);
+ return SF_SUCCESS;
+ }
+ else
+ return ret;
+ default:
+ break;
+ }
+
+ SLOGI("sendBuf******\n %s \n*********************\n\n",ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+
+ SLOGI("revBuf******\n %s \n*********************\n\n",ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enATcmdType);
+ timeout_count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+}
+
+
+ SINT32 eg91_server_acm_transfer(SF_DATA_ATTR_S *psenddate, SF_FN_PARAM_S *pfnParam, UINT8 needRepose)
+ {
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+
+ SINT32 ttyRet = SF_SUCCESS;
+ SINT32 ret = SF_SUCCESS;
+ SINT16 sts = 1;
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ MODULE_SERVER_ACM_WRITE_E enATcmdType = MODULE_SERVER_ACM_WRITE_AT_QISEND;
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ break;
+
+ switch(enATcmdType)
+ {
+ case MODULE_SERVER_ACM_WRITE_AT_QISEND:
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_SENDING;
+ sprintf(ttyData,"AT+QISEND=%d,%d\r", TCP_PDP, psenddate->dataSize-3);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_SERVER_ACM_WRITE_AT_SENDING:
+ if(strstr(ttyData, ">"))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ if(needRepose)
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_QIRD;
+ else
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_END;
+
+ memset(ttyData, '\0', sizeof(ttyData));
+ ttyRet = sf_hal_ttyusb2_write((SF_CHAR*)psenddate->databuf, psenddate->dataSize-2);
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_ACM_WRITE_AT_QIRD:
+ if((strstr(ttyData, "recv")) || (strstr(ttyData, "re")))
+ {
+ timeout_count = 0;
+ sprintf(ttyData, "AT+QIRD=%d,228\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_END;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else if(strstr(ttyData, "closed"))
+ {
+ callTime = 0;
+ MLOGE("send data to acm:connection closed");
+ return SF_4G_ERROR_AT_DISCONNECT;
+ }
+ else
+ {
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ callTime++;
+ timeout_count = 0;
+ if(callTime > 50)
+ {
+ callTime = 0;
+ sprintf(ttyData, "AT+QIRD=%d,228\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_ATE0;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ }
+ break;
+ case MODULE_SERVER_ACM_WRITE_AT_ATE0:
+ if(!strstr(ttyData, "+QIRD: 0"))
+ {
+ memset(&psenddate->databuf, '\0', sizeof(psenddate->databuf));
+ memcpy(psenddate->databuf, ttyData, SF_TTYUSB_RECV_MAX);
+ sts = 0;
+ return SF_SUCCESS;
+ }
+ else
+ {
+
+ callTime++;
+ if(callTime < 5)
+ {
+ sf_sleep_s(10);
+
+ sprintf(ttyData, "AT+QIRD=%d,228\r", TCP_PDP);
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_ATE0;
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ else
+ {
+ callTime = 0;
+ return SF_4G_ERROR_AT_DISCONNECT;
+
+ enATcmdType = MODULE_SERVER_ACM_WRITE_AT_QIDEACT;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ break;
+ case MODULE_SERVER_ACM_WRITE_AT_QIDEACT:
+ return SF_4G_ERROR_AT_DISCONNECT;
+ case MODULE_SERVER_ACM_WRITE_AT_END:
+ memset(&psenddate->databuf, '\0', SF_TTYUSB_RECV_MAX);
+ memcpy(psenddate->databuf, ttyData, SF_TTYUSB_RECV_MAX);
+ sts = 0;
+ return SF_SUCCESS;
+ default:
+ break;
+ }
+
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enATcmdType);
+ timeout_count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+ }
+
+ SINT32 eg91_server_acm_close(SF_FN_PARAM_S *pfnParam)
+ {
+
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ SINT32 ttyRet = SF_SUCCESS;
+ SINT32 ret = SF_SUCCESS;
+ SINT16 sts = 1;
+ UINT16 timeout_count = 0;
+ UINT16 callTime = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ MODULE_SERVER_ACM_CLOSE_E enATcmdType = MODULE_SERVER_ACM_CLOSE_AT_QICLOSE;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ break;
+
+ switch(enATcmdType)
+ {
+ case MODULE_SERVER_ACM_CLOSE_AT_QICLOSE:
+ enATcmdType = MODULE_SERVER_ACM_CLOSE_AT_QIDEACT;
+ sprintf(ttyData, "AT+QICLOSE=%d,1\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ break;
+
+ case MODULE_SERVER_ACM_CLOSE_AT_QIDEACT:
+ if((strstr(ttyData, "OK")) || (strstr(ttyData,"ERROR")) || (callTime>100))
+ {
+ timeout_count = 0;
+ callTime = 0;
+ enATcmdType = MODULE_SERVER_ACM_CLOSE_AT_END;
+ sprintf(ttyData, "AT+QIDEACT=%d\r", TCP_PDP);
+ ttyRet = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ SF_APPCOMM_CHECK_RETURN(ttyRet, ttyRet);
+ }
+ break;
+
+ case MODULE_SERVER_ACM_CLOSE_AT_END:
+ if((strstr(ttyData, "OK")) || (callTime > 100))
+ {
+ timeout_count = 0;
+ return SF_SUCCESS;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ SLOGD("sendBuf******\n %s \n*********************\n\n",ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+
+ SLOGD("revBuf******\n %s \n*********************\n\n",ttyData);
+ timeout_count++;
+ if(timeout_count > 200)
+ {
+ SLOGE("[ERROR]Init timeout, enATcmdType=%d\n", enATcmdType);
+ timeout_count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+ return ret;
+ }
+
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
diff --git a/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c b/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c
new file mode 100755
index 000000000..27e15f5f0
--- /dev/null
+++ b/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c
@@ -0,0 +1,2143 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+#include "sf_log.h"
+
+#include "sf_hal_ttyusb.h"
+#include "sf_systemMng.h"
+
+#include "sf_opera_adapt.h"
+#include "sf_eg91_sim.h"
+#include "sf_param_common.h"
+
+unsigned long int LocateTime = 0;
+
+
+void eg91_mark_time_set(unsigned long int MarkTime)
+{
+ MLOGD("markTime:%ld\n", MarkTime);
+ LocateTime = MarkTime;
+}
+
+static void eg91_parse_module_version_detail(SF_CHAR* pTemp, SF_CHAR *pT1, SF_CHAR *pT2, SF_CHAR *pT4, SF_CHAR *version)
+{
+ SF_PDT_PARAM_STATISTICS_S *sim_info_t = sf_statistics_param_get();
+ SF_CHAR str0[5] = { 0 };
+ SF_CHAR str1[5] = { 0 };
+ SF_CHAR str2[5] = { 0 };
+ SF_CHAR str3[5] = { 0 };
+ SF_CHAR str4[256] = { 0 };
+ SF_CHAR str5[256] = { 0 };
+ SF_CHAR* pT5=NULL;
+ memcpy(str1, pTemp + 4, pT1 - pTemp - 4);
+ //printf("str1 = %s\n", str1);
+ memcpy(str2, pT1 + 3, 2);
+ //printf("str2 = %s\n", str2);
+ memcpy(str3, pT1 + 6, 2);
+ //printf("str3 = %s\n", str3);
+
+ if(strstr(sim_info_t->ModuleVersion, EG91))
+ {
+ sprintf(str0, "%s", "91");
+ }
+ else if(strstr(sim_info_t->ModuleVersion, EG95))
+ {
+ sprintf(str0, "%s", "95");
+ }
+ else
+ {
+ sprintf(str0, "%s", "UN");
+ }
+
+ if(pT2 != NULL)
+ {
+ strcpy(str4, pT2 + 1);
+ //printf("str4 = %s\n", str4);
+ pT5 = strtok(str4, "\r\n");
+
+
+ if(pT5 != NULL)
+ {
+ strcpy(str5, pT5);
+ //printf("str5 = %s\n",str5);
+
+ if (pT4 != NULL)
+ sprintf(version, "S%sY%sY%sY%sY%sOS", str0, str1, str2, str3, str5);
+ else
+ sprintf(version, "S%sY%sY%sY%sY%sS", str0, str1, str2, str3, str5);
+ }
+ else
+ {
+ if (pT4 != NULL)
+ sprintf(version, "S%sY%sY%sY%sOS", str0, str1, str2, str3);
+ else
+ sprintf(version, "S%sY%sY%sY%sS", str0, str1, str2, str3);
+ }
+ }
+ else
+ {
+ if (pT4 != NULL)
+ sprintf(version, "S%sY%sY%sY%sOS", str0, str1, str2, str3);
+ else
+ sprintf(version, "S%sY%sY%sY%sS", str0, str1, str2, str3);
+ }
+
+ MLOGD("module_QGver = %s\n", version);
+ return;
+}
+
+static SINT32 eg91_parse_module_version(SF_CHAR *pTemp, SF_CHAR *version)
+{
+ SF_COMM_CHECK_POINTER(pTemp,SF_FAILURE);
+
+ SF_CHAR *pT1 = NULL;
+ SF_CHAR *pT2 = NULL;
+ SF_CHAR *pT3 = NULL;
+ SF_CHAR *pT4 = NULL;
+
+ pT1 = strstr(pTemp, "FAR");
+ pT2 = strstr(pTemp, "_");
+ pT3 = strstr(pTemp, "GAR");
+ pT4 = strstr(pTemp, "OCPU");
+
+ MLOGD("pTemp = %s\n", pTemp);
+ MLOGD("pT1 = %s\n", pT1);
+ MLOGD("pT2 = %s\n", pT2);
+ MLOGD("pT3 = %s\n", pT3);
+
+ if(pT1 != NULL)
+ eg91_parse_module_version_detail(pTemp, pT1, pT2, pT4, version);
+ else if(pT3 != NULL)
+ eg91_parse_module_version_detail(pTemp, pT3, pT2, pT4, version);
+
+
+ MLOGD("version:%s\n", version);
+ return SF_SUCCESS;
+}
+
+static SINT32 eg91_module_Polling_Comparison_CIMI(SF_CHAR *operatorName)
+{
+ SF_COMM_CHECK_POINTER(operatorName,SF_FAILURE);
+ UINT8 i = 0;
+ static UINT8 CIMIcount = 0;
+ static SF_CHAR strCIMI[5][8] = { 0 };
+
+ MLOGD("CIMIcount = %d,operatorName = [%s]\n",CIMIcount,operatorName);
+ if(operatorName == SF_NULL)
+ return SF_FAILURE;
+
+ if(CIMIcount > 5)
+ return SF_FAILURE;
+
+ for(i=0;i<5;i++)
+ {
+ MLOGD("strCIMI[%d]: [%s]\n",i,strCIMI[i]);
+ if(strncmp(strCIMI[i], operatorName, 5) == 0)
+ return SF_FAILURE;
+ else
+ {
+ if(strlen(strCIMI[i]) == 0)
+ {
+ memcpy(strCIMI[i], operatorName, 5);
+ CIMIcount++;
+ MLOGD("strCIMI[%d]: [%s]\n",i,strCIMI[i]);
+ return SF_SUCCESS;
+ }
+
+
+ }
+
+
+ }
+ return SF_SUCCESS;
+}
+
+SINT32 eg91_other_sim_apn_cfg(SF_PDT_PARAM_STATISTICS_S *pstaticParam)
+{
+ FILE *fp = NULL;
+ SF_CHAR linestr[128] = {0};
+ SF_CHAR *pTemp = SF_NULL;
+ UINT32 enbleValue = 0;
+
+ fp = fopen(SIM_AUTO_MATCH_FILE_PATH, "r");
+ if(fp == NULL)
+ {
+ SLOGE("open file [%s] failed!\n", SIM_AUTO_MATCH_FILE_PATH);
+ return SF_FAILURE;
+ }
+
+ {
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "Value:") == NULL) {
+ fclose(fp);
+ return SF_FAILURE;
+ }
+ sscanf(linestr, "Value:%d",&enbleValue);
+ if(enbleValue == 0) {
+ fclose(fp);
+ return SF_FAILURE;
+ }
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+
+ if(strstr(linestr, "4G APN:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->ApnGPRS);
+ SLOGD("4G APN:<%s>\n", pstaticParam->ApnGPRS);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "4G UserName:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->ApnUsername);
+ SLOGD("4G UserName:<%s>\n", pstaticParam->ApnUsername);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "4G Password:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->ApnPassword);
+ SLOGD("4G Password:<%s>\n", pstaticParam->ApnPassword);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "MMSC:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->MMSC);
+ SLOGD("MMSC:<%s>\n", pstaticParam->MMSC);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "MMS APN:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->MMSAPN);
+ SLOGD("MMS APN:<%s>\n", pstaticParam->MMSAPN);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "Proxy:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->Proxy);
+ SLOGD("Proxy:<%s>\n", pstaticParam->Proxy);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "Port:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->Port);
+ SLOGD("Port:<%s>\n", pstaticParam->Port);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "UserName:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->UserName);
+ SLOGD("UserName:<%s>\n", pstaticParam->UserName);
+ }
+
+ if(feof(fp)) {
+ fclose(fp);
+ return SF_SUCCESS;
+ }
+ fgets(linestr, 128, fp);
+ if(strstr(linestr, "Password:<") != NULL) {
+ sscanf(linestr, "%*[^<]<%[^>]",pstaticParam->Password);
+ SLOGD("Password:<%s>\n", pstaticParam->Password);
+ }
+
+ fclose(fp);
+ }
+
+ return SF_SUCCESS;
+
+}
+
+SINT32 eg91_iccid_get(SF_CHAR *iccid,SF_FN_PARAM_S *pfnParam)
+{
+
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ SINT16 count = 0;
+ SF_CHAR GsnNow[22] = { 0 };
+ SF_CHAR *pStr = NULL;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+
+ sprintf(ttyData, "AT+QCCID\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ while(count < 3)
+ {
+ sf_hal_ttyusb2_read(ttyData, 150);
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ break;
+
+ if(ttyData[0] != '\0')
+ {
+ UINT8 tempICCID[21]={0};
+ pStr = strstr(ttyData,"+QCCID: ");
+ if(pStr != NULL)
+ {
+ memcpy(tempICCID, pStr+8, 20);
+
+ if((tempICCID[19] <='9') && (tempICCID[19] >='0'))
+ {
+ tempICCID[20] = '\0';
+ }
+ else
+ {
+ tempICCID[19] = '\0';
+ }
+ strcpy(GsnNow, (char*)tempICCID);
+ strcpy(iccid, GsnNow);
+ MLOGD("ICCID=%s\n",tempICCID);
+ break;
+ }
+ }
+
+
+ count++;
+ }
+
+ return SF_SUCCESS;
+}
+
+SINT32 eg91_qsclk_set(SF_FN_PARAM_S *pfnParam)
+{
+
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ SINT32 sts = 1;
+ SINT32 count = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SIM_SLEEP_NET_E enMmcLocation;
+ enMmcLocation = SIM_SLEEP_FIRST;
+
+
+
+
+ while(sts)
+ {
+
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ MLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch (enMmcLocation)
+ {
+ case SIM_SLEEP_FIRST:
+ {
+ SF_PDT_PARAM_CFG_S *pstParam = pfnParam->pstParam;
+ if(sf_poweron_type_get() != SF_MCU_STARTUP_RESET
+ && sf_poweron_type_get() != SF_MCU_STARTUP_DP )
+ enMmcLocation = SIM_SLEEP_QSCLK;
+ else
+ enMmcLocation = SIM_SLEEP_QSCEX;
+// sprintf(ttyData, "%s", "AT+QCFG=\"urc/ri/other\",\"pulse\"\r");
+ sprintf(ttyData, "%s", "AT+QCFG=\"urc/ri/other\",\"pulse\",120,2\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+ case SIM_SLEEP_QSCLK:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_SLEEP_QSCEX;
+ sprintf(ttyData, "AT+QSCLK=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case SIM_SLEEP_QSCEX:
+ if(strstr(ttyData, "OK") || strstr(ttyData, "ERROR"))
+ {
+
+ sts = 0;
+ return SF_SUCCESS;
+ }
+ break;
+
+ case SIM_SLEEP_EXIT:
+ break;
+ default:
+ break;
+
+
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("count:%d, location:%d\n", count, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ count++;
+ if(count > 300)
+ {
+ MLOGE("timeout, enMmcLocation=%d\n", enMmcLocation);
+ count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+
+ }
+ return SF_SUCCESS;
+}
+
+SINT32 eg91_usb_net_apn_cfg(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam, SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam, SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit, SF_FAILURE);
+
+ UINT16 count = 0;
+ SINT16 ret = SF_SUCCESS;
+ SINT16 ret1 = SF_SUCCESS;
+ SINT32 fd = 0;
+ int retryTime = 0;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT8 sts = 1;
+ USBNET_APN_INIT_e enMmcLocation;
+ enMmcLocation = USBNET_APN_INIT_FIRST;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+
+
+ sprintf(ttyData, "AT\r");
+ ret1 = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ if(ret1 == SF_FAILURE)
+ {
+ ret1 = SF_4G_ERROR_MODULE_OPEN;
+ return ret1;
+ }
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ MLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ SLOGD("time:%d--MMC:%d\n", count, enMmcLocation);
+ sf_hal_ttyusb2_read(ttyData, 100);
+
+ count++;
+ if(count > 300)
+ {
+ SLOGE("timeout, enMmcLocation=%d\n", enMmcLocation);
+ count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+
+ SLOGD("ttyData=%s\n",ttyData);
+
+ switch (enMmcLocation)
+ {
+ case USBNET_APN_INIT_FIRST:
+ SLOGD("ApnGPRS:%s\n", pStaticParam->ApnGPRS);
+ /*if(strstr(sfPara->ApnGPRS, V_MODULE_APN))
+ {
+ sprintf(ttyData, "AT+QICSGP=%d\r", V_PDP_INDEX);
+ enMmcLocation = USBNET_APN_QICSGP1;
+ }
+ else if(strstr(sfPara->ApnGPRS, A_MODULE_APN))
+ {
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", A_PDP_INDEX,
+ sfPara->ApnGPRS, sfPara->ApnUsername, sfPara->ApnPassword);
+ enMmcLocation = USBNET_APN_QICSGP2;
+ }
+ else*/
+
+ {
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", E_PDP_INDEX,
+ pStaticParam->ApnGPRS, pStaticParam->ApnUsername, pStaticParam->ApnPassword);
+ enMmcLocation = USBNET_APN_QICSGP2;
+ }
+
+ ret1 = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ if(ret1 == SF_FAILURE)
+ {
+ ret1 = SF_4G_ERROR_MODULE_OPEN;
+ return ret1;
+ /*
+ LOG_DM_RS("4G USB has disconnet.\n");
+ sf_ttyusb_deinit();
+ fd = sf_ttyfd_init_tryother();
+ if(fd < 0)
+ {
+ ret1 = SF_GPRS_MODULE_ERROR_OPEN;
+ return ret1;
+ }
+ ret1 = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ */
+ }
+
+ break;
+ case USBNET_APN_QICSGP1:
+ if(strstr(ttyData, "OK"))
+ {
+ if(strstr(ttyData, "+QICSGP: 0") || strstr(ttyData, "+QICSGP: 1,\"\""))
+ {
+
+
+ count = 0;
+ sprintf(ttyData, "AT+QICSGP=%d,1,\"%s\",\"%s\",\"%s\",1\r", V_PDP_INDEX,
+ pStaticParam->ApnGPRS, pStaticParam->ApnUsername, pStaticParam->ApnPassword);
+ enMmcLocation = USBNET_APN_QICSGP2;
+ }
+ else
+ {
+ sprintf(ttyData, "AT\r");
+ }
+ ret1 = sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ if(ret1 == SF_FAILURE)
+ {
+ ret1 = SF_4G_ERROR_MODULE_OPEN;
+ return ret1;
+ }
+ }
+ break;
+ case USBNET_APN_QICSGP2:
+ if(strstr(ttyData, "OK"))
+ {
+ count = 0;
+ sts = 0;
+ ret = SF_SUCCESS;
+ }
+ break;
+
+ }
+
+
+ }
+
+ return ret;
+
+}
+
+SINT32 eg91_sim_init(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ UINT16 index = 0;
+ UINT16 count = 0;
+ UINT16 callTime = 0;
+ SINT16 ret = SF_SUCCESS;
+
+ SF_CHAR GsnSaved[22] = { 0 };
+ SF_CHAR GsnNow[22] = { 0 };
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ SF_CHAR operationCode[6] = { 0 };
+ UINT8 sts = 1;
+ UINT8 ModuelV05 = 0; /* Record the mode version is 05 or 07*/
+ SF_CHAR *pTemp = NULL;
+
+ SF_CHAR *p = NULL;
+ SF_CHAR tempICCID[21] = { 0 };
+ SF_CHAR lastICCID[21] = { 0 };
+ SF_CHAR *pStr = NULL;
+
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+ SIM_INIT_E enMmcLocation;
+ enMmcLocation = SIM_INIT_ATE;
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ MLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch(enMmcLocation)
+ {
+ case SIM_INIT_ATE:
+ enMmcLocation = SIM_INIT_GSN;//SIM_INIT_DEBUG;
+ sprintf(ttyData, "ATE1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_INIT_DEBUG:
+ enMmcLocation = SIM_INIT_GSN;
+ sprintf(ttyData, "%s", "AT+QGPSCFG=\"outport\",\"uartdebug\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_INIT_FIRST:
+ if(strstr(ttyData, "+QSIMSTAT: 0,0"))
+ {
+ callTime++;
+ if(callTime > 50)
+ {
+ SLOGE("SimCard not inserted.\n");
+ memset(&pStaticParam->SimID,'\0',SF_ICCID_MAX_LEN);
+ return SF_4G_ERROR_NO_SIMCARD;
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ }
+ else if(strstr(ttyData, "+QSIMSTAT: 0,1"))
+ {
+ count = 0;
+ callTime = 0;
+// enMmcLocation = SIM_INIT_QNTP;
+// sprintf(ttyData, "%s", "AT+QCFG=\"ntp\",3,5\r");
+ enMmcLocation = SIM_INIT_QURCCFG;
+ sprintf(ttyData, "%s", "AT+QURCCFG=\"urcport\",\"usbat\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(ttyData, "+CPIN: NOT INSERTED"))
+ {
+ MLOGE("SimCard not inserted.\n");
+ memset(&pStaticParam->SimID,'\0',SF_ICCID_MAX_LEN);
+ return SF_4G_ERROR_NO_SIMCARD;
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_QNTP:
+ //if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QURCCFG;
+ sprintf(ttyData, "%s", "AT+QURCCFG=\"urcport\",\"usbat\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+
+ }
+ break;
+
+ case SIM_INIT_QURCCFG:
+ {
+ enMmcLocation = SIM_INIT_QCFG;
+ sprintf(ttyData, "%s", "AT+QCFG=\"risignaltype\",\"physical\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_QCFG:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QLWCFG;
+ sprintf(ttyData, "%s", "AT+QCFG=\"urc/ri/other\",\"off\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_INIT_QCFG_PLUSE:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QLWCFG;
+ sprintf(ttyData, "%s", "AT+QCFG=\"urc/ri/other\",\"pulse\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_INIT_QNVW:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QLWCFG;
+ sprintf(ttyData, "%s", "AT+QNVW=3006,0,\"FF00\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_INIT_QLWCFG:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QLWCFG_1;
+ sprintf(ttyData, "%s", "AT+QLWCFG=\"urc\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case SIM_INIT_QLWCFG_1:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_CGDCONT;
+ sprintf(ttyData, "%s", "AT+QLWCFG=\"startup\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_ICCID:
+ if(strstr(ttyData, "READY"))
+ {
+ enMmcLocation = SIM_INIT_ICCID_1;
+ sprintf(ttyData, "%s", "AT+QCCID\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case SIM_INIT_GSN:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_ATI;
+ sprintf(ttyData, "%s", "AT+GSN\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case SIM_INIT_ATI:
+ if(ttyData[0] != '\0')
+ {
+ for(index = 0; index < SF_TTYUSB_RECV_MAX; index++)
+ {
+ if((ttyData[index] == '8')&&(ttyData[index+1] == '6'))
+ {
+ SF_CHAR tempImei[16] = {0};
+ UINT8 p = 0;
+ for(p=0; p < IMEI_LEN; p++)
+ {
+ if((ttyData[p+index] >= '0')&&(ttyData[p+index] <= '9'))
+ tempImei[p] = ttyData[p+index];
+ else
+ tempImei[p] = '\0';
+ }
+ tempImei[15] = '\0';
+ strcpy(GsnNow, tempImei);
+ break;
+ }
+ }
+ }
+
+ if((GsnNow[0] != '\0') && (strncmp(GsnNow, GsnSaved, IMEI_LEN) == 0))
+ {
+ if(strcasecmp(GsnNow, pStaticParam->IMEI) != 0)/* Added by MaxLi 2022/03/02--20:40:51*/
+ {
+ MLOGD("%s\n", GsnNow);
+
+ sprintf(pStaticParam->IMEI, "%s", GsnNow);
+ //LOGI_R("%s", sim_info_t2->IMEI);
+ MLOGD("imei:%s\n", pStaticParam->IMEI);
+
+ }
+ strcpy(ttyData, "ATI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ enMmcLocation = SIM_INIT_QFLIST;
+ }
+ else
+ {
+ strcpy(GsnSaved, GsnNow);
+ GsnNow[0] = '\0';
+
+ sprintf(ttyData, "%s", "AT+GSN\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(100);
+ }
+ break;
+
+ case SIM_INIT_QFLIST:
+ if((strstr(ttyData, "OK") != NULL) || (strstr(ttyData, "ERROR") != NULL))
+ {
+ pTemp = strstr(ttyData, "Revision:");
+ if(pTemp != NULL)
+ {
+ SF_CHAR modulVerStr[256] = { 0 };
+ strcpy(modulVerStr, pTemp+10);
+ pTemp = strtok(modulVerStr, "OK");
+ p = strtok(pTemp, "\r\n");
+ if(strcasecmp(p, pStaticParam->ModuleVersion) != 0)/* Added by MaxLi 2022/03/02--20:41:28*/
+ {
+ strcpy(pStaticParam->ModuleVersion, p);
+ }
+ }
+
+ if((strstr(ttyData, "AFAR05")))
+ {
+ enMmcLocation = SIM_INIT_QFLIST_1;
+ ModuelV05 = 1;
+ strcpy(ttyData, "at+qflst=\"../../usr/fota_ip_a/update_report.ur\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ callTime = 0;
+ sf_sleep_ms(500);
+ }
+ else if(strstr(ttyData, "AFAR07"))
+ {
+ enMmcLocation = SIM_INIT_QFLIST_1;
+ strcpy(ttyData, "at+qflst=\"../../data/fota_ip_a/update_report.ur\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ callTime = 0;
+ sf_sleep_ms(500);
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_QGMR;
+ callTime = 0;
+ sprintf(ttyData, "%s", "AT+QGMR\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(100);
+ }
+ }
+ else
+ {
+ strcpy(ttyData, "ATI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(100);
+ }
+ break;
+
+ case SIM_INIT_QFLIST_1:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QGMR;
+ callTime = 0;
+ sprintf(ttyData, "%s", "AT+QGMR\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(100);
+ }
+ else if(strstr(ttyData, "ERROR: 417"))
+ {
+ enMmcLocation = SIM_INIT_QFLIST_2;
+
+ if(ModuelV05 == 1)
+ {
+ strcpy(ttyData, "at+qfopen=\"../../usr/fota_ip_a/update_report.ur\",1\r");
+ }
+ else
+ {
+ strcpy(ttyData, "at+qfopen=\"../../data/fota_ip_a/update_report.ur\",1\r");
+ }
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(1000);
+ }
+ else
+ {
+ callTime++;
+ if(callTime > 10)
+ {
+ callTime = 0;
+ enMmcLocation = SIM_INIT_QFLIST;
+ strcpy(ttyData, "ATI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(100);
+ }
+ sf_sleep_ms(500);
+ }
+ break;
+
+ case SIM_INIT_QFLIST_2:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_QGMR;
+ callTime = 0;
+ sprintf(ttyData, "%s", "AT+QGMR\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(100);
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_QFLIST;
+ sprintf(ttyData, "ATI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(100);
+ }
+ break;
+ case SIM_INIT_QGMR:
+ if(strstr(ttyData, GPRS_MODULE_TYPE_EG91) != NULL)
+ {
+ char subTemp[SF_MODULE_VER_MAX_LEN]={0};
+ eg91_parse_module_version(strstr(ttyData, GPRS_MODULE_TYPE_EG91), subTemp);
+
+ if(strcasecmp(subTemp, pStaticParam->ModuleSubversion) != 0)/* Added by MaxLi 2022/03/02--20:41:52*/
+ {
+ strcpy(pStaticParam->ModuleSubversion, subTemp);
+ }
+
+ if(strstr(pStaticParam->ModuleVersion, GPRS_MODULE_TYPE_EG91_V))
+ {
+ enMmcLocation = SIM_INIT_QNVFR;
+ sprintf(ttyData, "%s","at+qnvfr=\"/nv/item_files/modem/uim/gstk/feature_bmsk\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_FIRST;
+ callTime = 0;
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ }
+ else if(strstr(ttyData, GPRS_MODULE_TYPE_EG95) != NULL)
+ {
+ char subTemp[SF_MODULE_VER_MAX_LEN]={0};
+ eg91_parse_module_version(strstr(ttyData, GPRS_MODULE_TYPE_EG95), subTemp);
+
+ if(strcasecmp(subTemp, pStaticParam->ModuleSubversion) != 0)/* Added by MaxLi 2022/03/02--20:42:15*/
+ {
+ strcpy(pStaticParam->ModuleSubversion, subTemp);
+ }
+
+ if(strstr(pStaticParam->ModuleVersion, GPRS_MODULE_TYPE_EG95_V))
+ {
+ enMmcLocation = SIM_INIT_QNVFR;
+ sprintf(ttyData, "%s","at+qnvfr=\"/nv/item_files/modem/uim/gstk/feature_bmsk\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_FIRST;
+ callTime = 0;
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ }
+ else
+ {
+ callTime++;
+ if(callTime > 5)
+ {
+ callTime = 0;
+ if(strstr(pStaticParam->ModuleVersion, GPRS_MODULE_TYPE_EG91_V))
+ {
+ enMmcLocation = SIM_INIT_QNVFR;
+ sprintf(ttyData, "%s","at+qnvfr=\"/nv/item_files/modem/uim/gstk/feature_bmsk\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(pStaticParam->ModuleVersion, GPRS_MODULE_TYPE_EG95_V))
+ {
+ enMmcLocation = SIM_INIT_QNVFR;
+ sprintf(ttyData, "%s","at+qnvfr=\"/nv/item_files/modem/uim/gstk/feature_bmsk\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_FIRST;
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ }
+ }
+ break;
+
+ case SIM_INIT_ICCID_1:
+ if((strstr(ttyData,"+QCCID: ") != NULL))
+ {
+
+ pStr = strstr(ttyData,"+QCCID: ");
+
+ memcpy(tempICCID, pStr+8, 20);
+
+ if((tempICCID[19] <= '9') && (tempICCID[19] >= '0'))
+ tempICCID[20] = '\0';
+ else
+ tempICCID[19] = '\0';
+
+ if(strncmp(lastICCID, tempICCID, 21) == 0)
+ {
+ sprintf(pStaticParam->SimID, "%s", tempICCID);
+ MLOGD("ICCID=%s\n", pStaticParam->SimID);
+ callTime=0;
+ #if defined(CFG_SUPPORT_GPS)
+ enMmcLocation = SIM_INIT_QGPSXTRA;
+ sprintf(ttyData,"%s","AT+QGPSXTRA?\r");
+ #else
+ enMmcLocation = SIM_INIT_CIMI;
+ sprintf(ttyData, "AT+CIMI\r");
+ #endif
+ //enMmcLocation = SIM_INIT_END;
+ //sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ }
+ else
+ {
+ strcpy(lastICCID, tempICCID);
+ memset(tempICCID, '\0', sizeof(tempICCID));
+ enMmcLocation = SIM_INIT_ICCID_1;
+ sprintf(ttyData, "AT+QCCID\r");
+ }
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+
+ }
+ else
+ {
+ if(callTime > 10)
+ {
+ callTime = 0;
+ sprintf(ttyData,"%s","AT+QCCID\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ callTime++;
+ }
+ break;
+ case SIM_INIT_QGPSXTRA:
+ if(strstr(ttyData, "QGPSXTRA: 0"))
+ {
+ enMmcLocation = SIM_INIT_CIMI;
+ sprintf(ttyData,"%s","AT+QGPSXTRA=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ callTime = 0;
+ }
+ else if(strstr(ttyData, "QGPSXTRA: 1"))
+ {
+ //enMmcLocation = SIM_INIT_END;
+ //sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ enMmcLocation = SIM_INIT_CIMI;
+ sprintf(ttyData, "AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_RESET_MODULE:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_GSN;
+ sf_hal_ttyusb2_deinit();
+ sf_hal_ttyusb2_init();
+ sprintf(ttyData, "ATE1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case SIM_INIT_CIMI:
+ pTemp = NULL;
+ pTemp = strstr(ttyData, "AT+CIMI");
+ if(pTemp)
+ {
+ memcpy(operationCode, pTemp + 10, 5);
+ MLOGD("operationCode:%s\n", operationCode);
+ sprintf(pStaticParam->OperatorCode, "%s", operationCode);
+ sf_auto_operation_adaptation(pStaticParam->OperatorCode, pStaticParam);
+ MLOGD("ApnGPRS:%s\n", pStaticParam->ApnGPRS);
+ if((strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2)) \
+ || (strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN)))//20408 sifar kpn sim
+ {
+ pStaticParam->SimType = SF_SIM_MEGA;
+ //1. mega sim,set pdp 1 apn
+ ret = eg91_module_Polling_Comparison_CIMI(operationCode);//mega sim,recorde sim operation code
+
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"AT+CGDCONT=1,\"IPV4V6\",\"%s\"\r", pStaticParam->ApnGPRS);
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else if(strstr(pStaticParam->ApnGPRS, APNGPRSTEMP))
+ {
+ #if defined(CFG_SUPPORT_OTHER_SIM)
+ MLOGD("CFG_SUPPORT_OTHER_SIM-ApnGPRS:%s\n", pStaticParam->ApnGPRS);
+ #endif
+ pStaticParam->SimType = SF_SIM_MEGA_IOT;
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else
+ {
+ #if defined(CFG_SUPPORT_OTHER_SIM)
+ eg91_other_sim_apn_cfg(pStaticParam);
+
+ pStaticParam->SimType = SF_SIM_OTHER;
+
+ //2.other sim: version sim
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ {
+ enMmcLocation = SIM_INIT_CGDCONT_1;
+ sprintf(ttyData,"%s","AT+QICSGP=1\r");
+ }
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ {
+ enMmcLocation = SIM_INIT_CGDCONT_2;
+ sprintf(ttyData,"%s","AT+QICSGP=1\r");
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ }
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ #else
+ sts = 0;
+ return SF_4G_ERROR_NO_SUPPOET;
+ #endif
+ }
+
+ }
+ else
+ {
+ sprintf(ttyData, "AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(500);
+ }
+ break;
+
+ case SIM_INIT_CGDCONT:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_ICCID;
+ sprintf(ttyData,"%s","AT+CPIN?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_CGDCONT_1:
+ pTemp = NULL;
+ pTemp = strstr(ttyData, "+QICSGP:");
+ if(pTemp != NULL)
+ {
+ pTemp = strtok(ttyData, ",");
+ MLOGD("pStr:%s\n", pTemp);
+
+ pTemp = strtok(NULL, ",");
+ MLOGD("pStr:%s\n", pTemp);
+
+ if(strncmp(pTemp, "\"ims\"", 5) == 0)
+ {
+ if((strstr(pStaticParam->ModuleVersion, GPRS_MODULE_TYPE_EG91_V)) || (strstr(pStaticParam->ModuleVersion, GPRS_MODULE_TYPE_EG95_V)))
+ {
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"%s","AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_QNVFR;
+ sprintf(ttyData, "%s","at+qnvfr=\"/nv/item_files/modem/uim/gstk/feature_bmsk\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_RESET_MODULE;
+ sprintf(ttyData,"%s","AT+QPRTPARA=3\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ break;
+ case SIM_INIT_QNVFR:
+ if(strstr(ttyData, "+QNVFR: 11000000"))
+ {
+ enMmcLocation = SIM_INIT_QNVFW;
+ sprintf(ttyData, "%s", "at+qnvfw=\"/nv/item_files/modem/uim/gstk/feature_bmsk\",01000000\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"%s","AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_QNVFW:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"%s","AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_INIT_CGDCONT_2:
+ pTemp = NULL;
+ pTemp = strstr(ttyData, "+QICSGP:");
+ if(pTemp != NULL)
+ {
+ pTemp = strtok(ttyData, ",");
+ printf("pStr:%s\n", pTemp);
+
+ pTemp = strtok(NULL, ",");
+ printf("pStr:%s\n", pTemp);
+
+ if(strncmp(pTemp, "\"nxtgenphone\"", 18) == 0)
+ {
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"%s","AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_INIT_CGDCONT_3;
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"nxtgenphone\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ break;
+
+ case SIM_INIT_CGDCONT_3:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_CFUN;
+ sprintf(ttyData,"%s","AT+CFUN=4\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_CFUN:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_CFUN_1;
+ sprintf(ttyData,"%s","AT+CFUN=1\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_CFUN_1:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_INIT_END;
+ sprintf(ttyData,"%s","AT\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_INIT_END:
+ if(strstr(ttyData, "OK"))
+ {
+ callTime=0;
+ sts = 0;
+ return SF_SUCCESS;
+ }
+ else if(strstr(ttyData, "SIM"))
+ {
+
+ }
+ else if(strstr(ttyData, "NOT"))
+ {
+ return SF_4G_ERROR_NO_SIMCARD;
+ }
+ else
+ {
+ if((count % 10) == 0)
+ {
+ MLOGD("--------count:%d.--------\n",count);
+ sprintf(ttyData, "AT+CPIN?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 300);
+ SLOGD("callTIme:%d, location:%d\n", callTime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ count++;
+ if(count > 300)
+ {
+ MLOGE("[ERROR]Init timeout, enMmcLocation=%d\n", enMmcLocation);
+ count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+
+ return ret;
+}
+SINT32 eg91_register_net_auto(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ UINT16 count = 0;
+ UINT16 callTime = 0;
+ SINT16 ret = SF_SUCCESS;
+ SINT32 csq = 0;
+ SF_CHAR *pStr = NULL;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT8 sts = 1;
+ unsigned long int locateTime = 0;
+ SF_CHAR operationCode[6] = { 0 };
+ SF_CHAR *pTemp = NULL;
+ SIM_REG_NET_e enMmcLocation;
+ enMmcLocation = SIM_REG_NET_FIRST;
+ //static SF_CHAR cimitestflagpir = 0;
+ #if SF_QLOG_ENABLE
+ SF_PDT_PARAM_CFG_S *pstparam = pfnParam->pstParam;
+ #endif
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ MLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+
+
+ switch (enMmcLocation)
+ {
+ case SIM_REG_NET_FIRST:
+ enMmcLocation = SIM_REG_NET_FIRST_1;
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ break;
+
+ case SIM_REG_NET_FIRST_1:
+ if(strstr(ttyData, "+QSIMSTAT: 0,0"))
+ {
+ callTime++;
+ if(callTime > 50)
+ {
+ MLOGE("SimCard not inserted.\n");
+ return SF_4G_ERROR_NO_SIMCARD;
+
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ }
+ else if(strstr(ttyData, "+QSIMSTAT: 0,1"))
+ {
+
+#if SF_QLOG_ENABLE
+
+ if(pstparam->DebugMode)
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_1_1;
+ sprintf(ttyData, "at+qcfg=\"dbgctl\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ count = 0;
+ callTime = 0;
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ {
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"nxtgenphone\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ if(strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN) || strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2))
+ sprintf(ttyData,"AT+CGDCONT=1,\"IPV4V6\",\"%s\"\r", pStaticParam->ApnGPRS);
+ else
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+
+#else
+ count = 0;
+ callTime = 0;
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ {
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"nxtgenphone\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ if(strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN) || strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2))
+ sprintf(ttyData,"AT+CGDCONT=1,\"IPV4V6\",\"%s\"\r", pStaticParam->ApnGPRS);
+ else
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+#endif
+
+
+ }
+ else if(strstr(ttyData, "+CPIN: NOT INSERTED"))
+ {
+ MLOGE("SimCard not inserted.\n");
+ return SF_4G_ERROR_NO_SIMCARD;
+ }
+ else
+ {
+ sprintf(ttyData, "AT+QSIMSTAT?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_REG_NET_FIRST_3:
+ enMmcLocation = SIM_REG_NET_CIMI;
+ sprintf(ttyData,"%s","AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_REG_NET_CIMI:
+ pTemp = NULL;
+ pTemp = strstr(ttyData, "AT+CIMI");
+ if(pTemp)
+ {
+ memcpy(operationCode, pTemp + 10, 5);
+
+// if(cimitestflagpir != 0)
+ {
+ ret = eg91_module_Polling_Comparison_CIMI(operationCode);
+ if(ret != SF_SUCCESS)
+ return SF_4G_ERROR_REG_NET;
+// memcpy(operationCode, strcode, 5);
+ }
+
+ MLOGD("operationCode:%s\n", operationCode);
+ sprintf(pStaticParam->OperatorCode, "%s", operationCode);
+
+ sf_auto_operation_adaptation(pStaticParam->OperatorCode, pStaticParam);
+ if((strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2)) \
+ || (strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN)))
+ {
+ //other sim card module E
+// enMmcLocation = SIM_REG_NET_FIRST_2;
+// sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ return SF_4G_ERROR_REG_NET;
+ }
+
+ }
+ else
+ {
+ sprintf(ttyData, "AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(500);
+ }
+ break;
+
+ case SIM_REG_NET_FIRST_1_1:
+ if(strstr(ttyData, "OK") || strstr(ttyData, "ERROR"))
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_1_2;
+ sprintf(ttyData, "AT+QLWCFG=\"urc\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_REG_NET_FIRST_1_2:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_1_3;
+ sprintf(ttyData, "AT+QLWCFG=\"startup\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_REG_NET_FIRST_1_3:
+ if(strstr(ttyData, "OK"))
+ {
+ count = 0;
+ callTime = 0;
+ if(strstr(pStaticParam->ApnGPRS, V_MODULE_APN))
+ {
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else if(strstr(pStaticParam->ApnGPRS, A_MODULE_APN))
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"nxtgenphone\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+
+
+ case SIM_REG_NET_FIRST_2:
+ if(strstr(ttyData, "OK"))
+ {
+ callTime = 0;
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+#if 1
+ case SIM_REG_NET_WSIZE1:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_REG_NET_WSIZE2;
+ sprintf(ttyData, "AT+QCFG=\"tcp/windowsize\",0,100\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+#endif
+
+ case SIM_REG_NET_WSIZE2:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_REG_NET_QNWINFO;
+ sprintf(ttyData, "AT+QNWINFO\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_REG_NET_CGREG:
+ if(strstr(ttyData, "+CGREG: 0,"))
+ {
+ if(strstr(ttyData, "+CGREG: 0,1") || strstr(ttyData, "+CGREG: 0,5"))
+ {
+ #if !defined(CFG_SUPPORT_OTHER_SIM)
+ if(pStaticParam->SimType == SF_SIM_OTHER)
+ {
+ sts = 0;
+ return SF_4G_ERROR_NO_SUPPOET;
+ }
+ #endif
+
+ MLOGD("reg net sucess:%s", ttyData);
+ locateTime = sf_sys_os_time_get();
+ eg91_mark_time_set(locateTime);
+ //cimitestflagpir = 1;
+ enMmcLocation = SIM_REG_NET_WSIZE1;
+ sprintf(ttyData, "AT+QCFG=\"tcp/windowsize\",1,100\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ count = 0;
+ callTime++;
+ sf_sleep_ms(400);
+ MLOGD("callTime = %d\n",callTime);
+ if(callTime > 320)
+ {
+ enMmcLocation = SIM_REG_NET_CIMI;
+ sprintf(ttyData,"%s","AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ callTime = 0;
+ }
+ else if(callTime > 180)
+ {
+ if((!strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2)) && (!strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN)))
+ {
+ ret = SF_4G_ERROR_REG_NET;
+ MLOGE("Other sim reg net timeout!");
+ return ret;
+ }
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+
+ }
+ }
+ break;
+ case SIM_REG_NET_QNWINFO:
+ if(strstr(ttyData, "+QNWINFO:") != NULL)
+ {
+ SLOGI("%s", ttyData);
+ if(strstr(ttyData, "No Service"))
+ {
+ pStaticParam->netGeneration = 2;
+ }
+ else if (NULL != strtok(ttyData,"\""))
+ {
+ SF_CHAR netStr[20] = { 0 };
+ strcpy(netStr, strtok(NULL,"\""));
+ MLOGD("netStr:%s\n", netStr);
+ if((strstr(netStr,"DD") != NULL))
+ {
+ pStaticParam->netGeneration = 4;
+ }
+ else if(strstr(netStr, "CDMA") != NULL || strstr(netStr, "HDR") != NULL \
+ || strstr(netStr, "HSUPA") != NULL || strstr(netStr, "HSDPA") != NULL \
+ || strstr(netStr, "HSPA+") != NULL)
+ {
+ pStaticParam->netGeneration = 3;
+ }
+ else
+ {
+ pStaticParam->netGeneration = 2;
+ }
+ }
+
+ if(pStaticParam->netGeneration == 4)//NetGeneration == 4
+ {
+ enMmcLocation = SIM_REG_NET_QCSQ;
+ sprintf(ttyData, "AT+QCSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_CSQ;
+ sprintf(ttyData, "AT+CSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ callTime = 0;
+ }
+ }
+ break;
+
+ case SIM_REG_NET_QCSQ:
+ if(strstr(ttyData, "+QCSQ:"))
+ {
+ SLOGI("%s", ttyData);
+ pStr = NULL;
+ pStr = strtok(ttyData, ",");
+ MLOGI("pStr:%s\n", pStr);
+ pStr = strtok(NULL, ",");
+ MLOGI("pStr:%s\n", pStr);
+ if(pStr != NULL)
+ {
+ pStr = strtok(NULL, ",");
+ MLOGI("pStr:%s\n", pStr);
+ csq = 0 - atoi(pStr);
+ MLOGD("csq:%d\n", csq);
+ pStaticParam->SimSignal = (UINT8)csq;
+ if(pStaticParam->SimSignal == 0)
+ {
+ pStaticParam->SimSignal = 105;
+ }
+
+ }
+ else
+ {
+ pStaticParam->SimSignal = 0;
+ ret = SF_4G_ERROR_NO_SIGNAL;
+ }
+ MLOGD("apn:%s\n", pStaticParam->ApnGPRS);
+ return SF_SUCCESS;
+ }
+ break;
+
+ case SIM_REG_NET_CSQ:
+ if(strstr(ttyData, "+CSQ:"))
+ {
+ SLOGI("%s", ttyData);
+ SF_CHAR *pTemp = NULL;
+ pStr = strstr(ttyData, "+CSQ:") + 6;
+ printf("pStr:%s\n", pStr);
+ pTemp = strtok(pStr, ",");
+ printf("pTemp:%s\n", pTemp);
+ if(pTemp != NULL)
+ {
+ csq = atoi(pTemp);
+ if((csq > 31) || (csq == 0))
+ {
+ callTime++;
+ if(callTime <= 10)
+ {
+ sprintf(ttyData, "AT+CSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(300);
+ }
+ else
+ {
+ callTime = 0;
+ pStaticParam->SimSignal = 0;
+ return SF_4G_ERROR_NO_SIGNAL;
+ }
+ }
+ else
+ {
+ pStaticParam->SimSignal = csq;
+ ret = SF_SUCCESS;
+ MLOGD("apn:%s\n", pStaticParam->ApnGPRS);
+ return SF_SUCCESS;
+ }
+ }
+ else
+ {
+ sprintf(ttyData, "AT+CSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+
+ }
+ break;
+ case SIM_REG_NET_COPS:
+ break;
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ MLOGD("callTIme:%d, location:%d\n", callTime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ count++;
+ if(count > 300)
+ {
+ MLOGE("timeout, enMmcLocation=%d\n", enMmcLocation);
+ count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+
+ }
+
+ return ret;
+}
+SINT32 eg91_register_net_manual(SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pfn_AT_instruction_exit,SF_FAILURE);
+ UINT16 count = 0;
+ UINT16 callTime = 0;
+ SINT16 ret = SF_SUCCESS;
+ SINT32 csq = 0;
+ SF_CHAR *pStr = NULL;
+ SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = { 0 };
+ UINT8 sts = 1;
+ SF_CHAR operationCode[6] = { 0 };
+ SF_CHAR *pTemp = NULL;
+ SIM_REG_NET_e enMmcLocation;
+ enMmcLocation = SIM_REG_NET_FIRST;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+
+ while(sts)
+ {
+ if(SF_TRUE == pfnParam->pfn_AT_instruction_exit(0))
+ {
+ MLOGE("4G module has already connected!!!\n");
+ return SF_FAILURE;
+ }
+
+ switch (enMmcLocation)
+ {
+ case SIM_REG_NET_FIRST:
+ //enMmcLocation = SIM_REG_NET_CIMI;
+ //sprintf(ttyData,"%s","AT+CIMI\r");
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ break;
+ case SIM_REG_NET_CIMI:
+ pTemp = NULL;
+ pTemp = strstr(ttyData, "AT+CIMI");
+ if(pTemp)
+ {
+ memcpy(operationCode, pTemp + 10, 5);
+ MLOGD("operationCode:%s\n", operationCode);
+
+ ret = eg91_module_Polling_Comparison_CIMI(operationCode);
+ if(ret != SF_SUCCESS)
+ return SF_4G_ERROR_NO_SUPPOET;
+
+ MLOGD("operationCode:%s\n", operationCode);
+ sprintf(pStaticParam->OperatorCode, "%s", operationCode);
+
+ sf_auto_operation_adaptation(pStaticParam->OperatorCode, pStaticParam);
+ if((strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2)) \
+ || (strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN)) )//mega sim,use in abord
+ {
+
+ enMmcLocation = SIM_REG_NET_FIRST_2;
+ sprintf(ttyData,"AT+CGDCONT=1,\"IPV4V6\",\"%s\"\r",pStaticParam->ApnGPRS);
+ //enMmcLocation = SIM_REG_NET_CGREG;
+ //sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ return SF_4G_ERROR_NO_SUPPOET;
+ }
+
+ }
+ else
+ {
+ sprintf(ttyData, "AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ sf_sleep_ms(500);
+ }
+ break;
+
+ case SIM_REG_NET_WSIZE1:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_REG_NET_WSIZE2;
+ sprintf(ttyData, "AT+QCFG=\"tcp/windowsize\",1,100\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_REG_NET_WSIZE2:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_REG_NET_QNWINFO;
+ sprintf(ttyData, "AT+QNWINFO\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+
+ case SIM_REG_NET_WSIZE3:
+ if(strstr(ttyData, "OK"))
+ {
+ enMmcLocation = SIM_REG_NET_WSIZE1;
+ sprintf(ttyData, "AT+QCFG=\"tcp/windowsize\",0,100\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ case SIM_REG_NET_CGREG:
+ if(strstr(ttyData, "+CGREG: 0,"))
+ {
+ if(strstr(ttyData, "+CGREG: 0,1") || strstr(ttyData, "+CGREG: 0,5"))
+ {
+ MLOGD("reg net sucess:%s", ttyData);
+
+ enMmcLocation = SIM_REG_NET_WSIZE3;
+ sprintf(ttyData, "AT+QCFG=\"pdp/duplicatechk\",0\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ count = 0;
+ callTime++;
+ sf_sleep_ms(400);
+ MLOGD("callTime = %d\n",callTime);
+ if(callTime > 320)
+ {
+ enMmcLocation = SIM_REG_NET_CIMI;
+ sprintf(ttyData,"%s","AT+CIMI\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ count = 0;
+ callTime = 0;
+ }
+ else if(callTime > 180)
+ {
+ if((!strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN2)) && (!strstr(pStaticParam->ApnGPRS, APNGPRS_WUYUAN)))
+ {
+ ret = SF_4G_ERROR_REG_NET;
+ MLOGE("Other sim reg net timeout!");
+ return ret;
+ }
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ }
+ }
+ break;
+
+ case SIM_REG_NET_QNWINFO:
+ if(strstr(ttyData, "+QNWINFO:") != NULL)
+ {
+ SLOGI("%s", ttyData);
+ if(strstr(ttyData, "No Service"))
+ {
+ pStaticParam->netGeneration = 2;
+ }
+ else if (NULL != strtok(ttyData,"\""))
+ {
+ SF_CHAR netStr[20] = { 0 };
+ strcpy(netStr, strtok(NULL,"\""));
+ MLOGD("netStr:%s\n", netStr);
+ if((strstr(netStr,"DD") != NULL))
+ {
+ pStaticParam->netGeneration = 4;
+ }
+ else if(strstr(netStr, "CDMA") != NULL || strstr(netStr, "HDR") != NULL \
+ || strstr(netStr, "HSUPA") != NULL || strstr(netStr, "HSDPA") != NULL \
+ || strstr(netStr, "HSPA+") != NULL)
+ {
+ pStaticParam->netGeneration = 3;
+ }
+ else
+ {
+ pStaticParam->netGeneration = 2;
+ }
+ }
+
+ enMmcLocation = SIM_REG_NET_COPS;
+ sprintf(ttyData, "AT+COPS?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ break;
+
+ case SIM_REG_NET_COPS:
+ if(strstr(ttyData, "+COPS:") != NULL)
+ {
+ SLOGI("%s", ttyData);
+ pStr = NULL;
+ strtok(ttyData, "\"");
+ pStr = strtok(NULL, "\"");
+ if(pStr != NULL)
+ {
+ strcpy(pStaticParam->ServiceProvider, pStr);
+ printf("cops1 is %s\r\n", pStr);
+ printf("cops2 is %s\r\n", pStaticParam->ServiceProvider);
+ }
+
+ if(pStaticParam->netGeneration == 4)//NetGeneration == 4
+ {
+ enMmcLocation = SIM_REG_NET_QCSQ;
+ sprintf(ttyData, "AT+QCSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ }
+ else
+ {
+ enMmcLocation = SIM_REG_NET_CSQ;
+ sprintf(ttyData, "AT+CSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ break;
+ case SIM_REG_NET_QCSQ:
+ if(strstr(ttyData, "+QCSQ:"))
+ {
+ MLOGI("%s", ttyData);
+ pStr = NULL;
+ pStr = strtok(ttyData, ",");
+ printf("pStr:%s\n", pStr);
+ pStr = strtok(NULL, ",");
+ printf("pStr:%s\n", pStr);
+ if(pStr != NULL)
+ {
+ pStr = strtok(NULL, ",");
+ printf("pStr:%s\n", pStr);
+ csq = 0 - atoi(pStr);
+ MLOGD("SINT32:%d\n", csq);
+ pStaticParam->SimSignal = (UINT8)csq;
+ //ret = sf_auto_operation_adaptation(sim_info_t->OperatorCode, sim_info_t);
+
+ if(pStaticParam->SimSignal == 0)
+ {
+ callTime++;
+
+ if(callTime < 10)
+ {
+ sprintf(ttyData, "AT+QCSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ else
+ {
+ pStaticParam->SimSignal = 105;
+ }
+ }
+ else
+ {
+ ret = SF_SUCCESS;
+ enMmcLocation = SIM_REG_NET_SAVE;
+ sprintf(ttyData, "AT&W\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ }
+ else
+ {
+ pStaticParam->SimSignal = 0;
+ ret = SF_4G_ERROR_NO_SIGNAL;
+ enMmcLocation = SIM_REG_NET_SAVE;
+ sprintf(ttyData, "AT&W\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ //MLOGD("apn:%s\n", sim_info_t->ApnGPRS);
+ }
+ break;
+
+ case SIM_REG_NET_CSQ:
+ if(strstr(ttyData, "+CSQ:"))
+ {
+ SLOGI("%s", ttyData);
+ SF_CHAR *pTemp = NULL;
+ pStr = strstr(ttyData, "+CSQ:") + 6;
+ printf("pStr:%s\n", pStr);
+ pTemp = strtok(pStr, ",");
+ printf("pTemp:%s\n", pTemp);
+ if(pTemp != NULL)
+ {
+ csq = atoi(pTemp);
+ if((csq > 31) || (csq == 0))
+ {
+ callTime++;
+ if(callTime <= 10)
+ {
+ sprintf(ttyData, "AT+CSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ sf_sleep_ms(300);
+ }
+ else
+ {
+ callTime = 0;
+ pStaticParam->SimSignal = 0;
+ ret = SF_4G_ERROR_NO_SIGNAL;
+ }
+ }
+ else
+ {
+ pStaticParam->SimSignal = csq;
+ //ret = sf_auto_operation_adaptation(sim_info_t->OperatorCode, sim_info_t);
+ ret = SF_SUCCESS;
+ MLOGD("apn:%s\n", pStaticParam->ApnGPRS);
+
+ enMmcLocation = SIM_REG_NET_SAVE;
+ sprintf(ttyData, "AT&W\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+
+ }
+ }
+ else
+ {
+ sprintf(ttyData, "AT+CSQ\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+
+ }
+ break;
+ case SIM_REG_NET_SAVE:
+ if(strstr(ttyData, "OK"))
+ {
+ sts = 0;
+ return SF_SUCCESS;
+ }
+
+ break;
+ case SIM_REG_NET_FIRST_1:
+ enMmcLocation = SIM_REG_NET_FIRST;
+ sprintf(ttyData,"%s","AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+ break;
+ case SIM_REG_NET_FIRST_2:
+ if(strstr(ttyData, "OK"))
+ {
+ callTime = 0;
+ enMmcLocation = SIM_REG_NET_CGREG;
+ sprintf(ttyData, "AT+CGREG?\r");
+ sf_hal_ttyusb2_write(ttyData, strlen(ttyData));
+
+ }
+ break;
+ default:
+ break;
+ }
+ SLOGD("sendBuf******\n %s \n*********************\n\n", ttyData);
+ memset(ttyData,'\0',SF_TTYUSB_RECV_MAX);
+ sf_hal_ttyusb2_read(ttyData, 200);
+ SLOGD("callTIme:%d, location:%d\n", callTime, enMmcLocation);
+ SLOGD("revBuf******\n %s \n*********************\n\n", ttyData);
+ count++;
+ if(count > 300)
+ {
+ MLOGE("timeout, enMmcLocation=%d\n", enMmcLocation);
+ count = 0;
+ return SF_4G_ERROR_AT_TIMEOUT;
+ }
+ }
+
+ return ret;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
diff --git a/code/application/source/sf_app/code/source/4gMng/sf_http_server.c b/code/application/source/sf_app/code/source/4gMng/sf_http_server.c
new file mode 100755
index 000000000..0683984f6
--- /dev/null
+++ b/code/application/source/sf_app/code/source/4gMng/sf_http_server.c
@@ -0,0 +1,466 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+#include
+#include
+#include
+#include
+
+#include "sf_type.h"
+#include "sf_log.h"
+
+#include "cJSON.h"
+
+#include"sf_http_server.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+SINT32 socketfd = -1;
+
+SINT32 http_server_creat(char *host, int *sock)
+{
+ struct sockaddr_in address;
+ int clt_sock;
+ int opvalue = 8;
+ socklen_t slen;
+ int i=0;
+ int ret = 0;
+
+ slen = sizeof(opvalue);
+ memset(&address, 0, sizeof(address));
+ if ((clt_sock= socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
+ setsockopt(clt_sock, IPPROTO_IP, IP_TOS, &opvalue, slen) < 0)
+ {
+ MLOGE("socket socket error.\n");
+ return -1;
+ }
+ struct timeval timeo = {120, 0};
+
+ setsockopt(clt_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
+ setsockopt(clt_sock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
+
+
+ address.sin_family = AF_INET;
+ address.sin_port = htons((unsigned short)HTTP_PORT);
+
+ struct hostent* server = gethostbyname(host);
+ if (!server)
+ {
+ MLOGE("dns error.\n");
+ return -1;
+ }
+
+ for(i = 0;server->h_addr_list[i];i++)
+ printf("...server ip addr%d: %s \n",i,inet_ntoa(*(struct in_addr*)server->h_addr_list[i]));
+
+ address.sin_addr = *(struct in_addr *)server->h_addr_list[0];
+ ret = connect(clt_sock, (struct sockaddr*)&address, sizeof(address));
+ if (ret != 0)
+ {
+ MLOGE("socket socket connect error. ret = %d\n", ret);
+ return -1;
+ }
+
+ *sock = clt_sock;
+
+ return 0;
+}
+SINT32 http_send_to_server(int sock_fd, char *data, int length)
+{
+ int written_len = 0;
+ int writelen = 0;
+ int ret = 0;
+
+// MLOGD("lenth:%d\n", length);
+ while (written_len < length)
+ {
+ if(length - written_len > 1024*20)
+ writelen = 1024*20;
+ else
+ writelen = length - written_len;
+
+// MLOGD("written_len:%d,lenth:%d\n", written_len, length);
+ ret = send(sock_fd, data + written_len, writelen, 0);
+ if (ret > 0)
+ {
+ written_len += ret;
+// MLOGD("written_len:%d,ret:%d\n", written_len,ret);
+ continue;
+ }
+ else if (ret == 0)
+ {
+// MLOGD("written_len:%d,ret:%d\n", written_len,ret);
+ return written_len;
+ }
+ else
+ {
+ MLOGD("written_len:%d,ret:%d\n", written_len, ret);
+ MLOGE("HTTP Send:%d\n", ret);
+ return -1; /* Connnection error */
+ }
+ }
+
+ MLOGD("Send End,written_len:%d\n", written_len);
+ return SF_SUCCESS;
+}
+
+SINT32 http_recv_from_server(int sock_fd, char *data, int length)
+{
+ SINT32 recv_byte = 0;
+ recv_byte = recv(sock_fd, data, length, 0);
+ if(recv_byte == 0)
+ {
+ sleep(3);
+ recv_byte = recv(sock_fd, data, length, 0);
+ }
+ return recv_byte;
+}
+SINT32 http_server_close(int sock_fd)
+{
+ return close(sock_fd);
+}
+static SINT32 http_response_status_code(char *data)
+{
+ char *p = NULL;
+ char ack[3] = {0};
+
+ p = strstr(data, "HTTP/1.1");
+ memcpy(ack, p+9, 3);
+ switch(atoi(ack)/100)
+ {
+ case 1:
+ MLOGI(">>>information corresponding\n");
+ return SF_SUCCESS;
+ case 2:
+ MLOGI(">>>successful response\n");
+ return SF_SUCCESS;
+ case 3:
+ MLOGI(">>>redirect message\n");
+ return SF_SUCCESS;
+ case 4:
+ MLOGE(">>>Client error response\n");
+ return SF_FAILURE;
+ case 5:
+ MLOGE(">>>server error response\n");
+ return SF_FAILURE;
+ default:
+ MLOGE(">>>undefined error response\n");
+ return SF_FAILURE;
+ }
+
+ return SF_SUCCESS;
+}
+static SINT32 http_authentication_parse(char *data,SF_PDT_PARAM_STATISTICS_S *pStaticParam)
+{
+ char *p = NULL;
+ char *out = NULL;
+ cJSON *json = NULL;
+ cJSON *first = NULL;
+ cJSON *second = NULL;
+ cJSON *subListItem = NULL;
+ SINT32 s32ret = SF_SUCCESS;
+ UINT16 index = 0;
+ SF_CHAR tempStr[128] = {0};
+ SF_CHAR decode_tempStr[128] = {0};
+
+ s32ret = http_response_status_code(data);
+ SF_APPCOMM_CHECK_RETURN(s32ret,SF_HTTP_ERROR_NO_SUPPORT);
+
+ p = strchr(data, '{');
+ json=cJSON_Parse(p);
+ if (!json)
+ {
+ SLOGE("Error before: [%s]\n",cJSON_GetErrorPtr());
+ cJSON_Delete(json);
+ return SF_HTTP_ERROR_DATA_FORMAT;
+ }
+
+
+ first = cJSON_GetObjectItem(json, "statu");
+ MLOGD("...code = %d\n", first->valueint);
+ first = cJSON_GetObjectItem(json, "errCode");
+ MLOGD("...errCode = %d\n", first->valueint);
+
+ if(first->valueint == 0)
+ {
+ first = cJSON_GetObjectItem(json, "msg");
+ MLOGD("...msg = %s\n", first->valuestring);
+ first = cJSON_GetObjectItem(json, "content");
+ out=cJSON_Print(first);
+ if(!strstr(out, "null"))
+ {
+ for(index = 0; index < 3; index++)
+ {
+ subListItem = cJSON_GetArrayItem(first, index);
+ if(cJSON_GetObjectItem(subListItem, "serverType")->valueSINT32 == 4)
+ {
+ second = cJSON_GetObjectItem(subListItem, "ip");
+ memcpy(tempStr, second->valuestring, strlen(second->valuestring));
+
+ sf_base64_decode(tempStr, decode_tempStr);
+
+ sprintf(pStaticParam->AcmIP, "%s", decode_tempStr);
+ MLOGD("AcmIP = %s\n", pStaticParam->AcmIP);
+ }
+ }
+ }
+ free(out);
+ }
+ else
+ {
+ s32ret = first->valueint;
+ if(first->valueint == SF_DEV_NOT_EXIST)
+ {
+ MLOGE("device does not exist\n");
+ }
+ else if(first->valueint == SF_DEV_NOT_BIND)
+ {
+ MLOGE("Device not bound\n");
+ }
+ }
+
+ cJSON_Delete(json);
+ return s32ret;
+}
+
+static SINT32 http_authentication_packet(SF_CHAR *data_buff,SF_PDT_PARAM_STATISTICS_S *pStaticParam)
+
+{
+ memset(data_buff, '\0', strlen(data_buff));
+ sprintf(data_buff, "POST /CameraManager/center/device/imeiAndMSisdn"
+ "?imei=%s&iccid=%s"
+ " HTTP/1.1\r\n"
+ "Host:%s\r\n"
+ "Connection: keep-alive\n"
+ "Content-Type: application/json\r\n\r\n",pStaticParam->IMEI, pStaticParam->SimID, pStaticParam->WebIP);
+
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("send_buff********\n%s\n", data_buff);
+ #endif
+ return SF_SUCCESS;
+
+}
+static SINT32 http_domain_name_get(char *url, char *host)
+{
+ char *pA;
+ char *pB;
+ memset(host, 0, strlen(host));
+
+ if (!(*url))
+ return -1;
+
+ pA = url;
+ if (!strncmp(pA, "http://", strlen("http://")))
+ pA = url + strlen("http://");
+ else if (!strncmp(pA, "https://", strlen("https://")))
+ pA = url + strlen("https://");
+
+ pB = strchr(pA, '/');
+
+ if (pB)
+ {
+ memcpy(host, pA, strlen(pA) - strlen(pB));
+ host[strlen(pA) - strlen(pB)] = 0;
+ }
+ else
+ {
+ memcpy(host, pA, strlen(pA));
+ host[strlen(pA)] = 0;
+ }
+// SLOGD("host = %s\n", host);
+
+ return 0;
+}
+static SINT32 http_pushfile_to_server(SINT32 socketfd, SF_FILE_ATTR_S *stFileAttr)
+{
+ SINT32 ret = SF_SUCCESS;
+ SINT32 fileFd = 0;
+ SINT32 tolFileSize = 0;
+ SINT32 readSize = 0;
+ struct stat statBuf;
+ SF_CHAR *pBuf = NULL;
+ SF_CHAR *bufBak = NULL;
+
+ fileFd = open(stFileAttr->txtfilePath, O_RDONLY);
+ if(fileFd < 0)
+ {
+ SLOGE("open file[%s] error!\n", stFileAttr->txtfilePath);
+ return SF_FAILURE;
+ }
+
+ fstat(fileFd, &statBuf);
+ tolFileSize = statBuf.st_size;
+ SLOGD("tolFileSize:%d\n", tolFileSize);
+
+ bufBak = (tolFileSize > 1024*1024*5)?malloc(1024*1024*5):malloc(tolFileSize);
+ if(bufBak == NULL)
+ {
+ SLOGE("malloc buf fail!\n");
+ close(fileFd);
+ return SF_FAILURE;
+ }
+
+ while(tolFileSize > 0)
+ {
+ pBuf = bufBak;
+ readSize = (tolFileSize >= 1024*1024*5)?read(fileFd, pBuf, 1024*1024*5):read(fileFd, pBuf, tolFileSize);
+ SLOGD("send file data, tolFileSize:%d, read size:%d\n", tolFileSize, readSize);
+ tolFileSize -= readSize;
+
+ if(readSize < 0)
+ {
+ free(bufBak);
+ close(fileFd);
+ return SF_FAILURE;
+ }
+ ret = http_send_to_server(socketfd, pBuf, readSize);
+ if (ret < 0)
+ {
+ SLOGE("Connection error (send returned %d)\n", ret);
+ free(bufBak);
+ close(fileFd);
+ return ret;
+ }
+
+ }
+
+ free(bufBak);
+ close(fileFd);
+ SLOGD("SF_SUCCESS!\n");
+ return SF_SUCCESS;
+}
+static SINT32 http_file_response_parse()
+{
+ return SF_SUCCESS;
+}
+
+SINT32 sf_usbnet_http_authenrequst(SF_PDT_PARAM_STATISTICS_S *pStaticParam)
+ {
+ SF_COMM_CHECK_POINTER(pStaticParam,SF_FAILURE);
+
+ SINT32 s32ret = 0;
+ SINT32 recv_byte = 0;
+ SINT32 sock_cli = 0;
+ SF_CHAR data_buff[BUFFER_SIZE] = { 0 };
+
+ MLOGD("WebIP:%s\n", pStaticParam->WebIP);
+ s32ret = http_server_creat(pStaticParam->WebIP, &sock_cli);
+ SF_APPCOMM_CHECK_RETURN(s32ret,SF_HTTP_ERROR_REQUEST);
+
+ s32ret = http_authentication_packet(data_buff,pStaticParam);
+ if(s32ret !=SF_SUCCESS) {
+ close(sock_cli);
+ return SF_HTTP_ERROR_REQUEST;
+ }
+
+ s32ret = http_send_to_server(sock_cli,data_buff,strlen(data_buff));
+ if(s32ret < SF_SUCCESS) {
+ close(sock_cli);
+ return SF_HTTP_ERROR_REQUEST;
+ }
+
+ memset(data_buff, '\0', sizeof(data_buff));
+ http_recv_from_server(sock_cli,data_buff,BUFFER_SIZE);
+
+ s32ret = http_authentication_parse(data_buff, pStaticParam);
+ if(s32ret != SF_SUCCESS) {
+ close(sock_cli);
+ return SF_HTTP_ERROR_REQUEST;
+ }
+ close(sock_cli);
+
+ return s32ret;
+}
+SINT32 sf_usbnet_http_pushfile(SF_FILE_ATTR_S *pstFileAttr,SF_FN_PARAM_S *pfnParam)
+{
+ SINT32 s32ret = SF_SUCCESS;
+ SINT32 socketfd = -1;
+ SF_CHAR amzIP[128] = {0};
+ SF_CHAR buf[HTTPCLIENT_REV_SIZE] = {0};
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+
+ sprintf(amzIP, "%s.%s", pStaticParam->stOssCfg.szBucket, AMZ_HOST);
+ MLOGI("login [%s]\n",amzIP);
+ s32ret = http_server_creat(amzIP,&socketfd);
+ if(s32ret != SF_SUCCESS) {
+ MLOGE("login [%s] failed\n",amzIP);
+ return SF_FAILURE;
+ }
+
+ s32ret = http_pushfile_to_server(socketfd,pstFileAttr);
+ if(s32ret != SF_SUCCESS) {
+ http_server_close(socketfd);
+ MLOGE("push file failed!!!\n");
+ return SF_FAILURE;
+ }
+
+ s32ret = http_recv_from_server(socketfd, buf, HTTPCLIENT_REV_SIZE);
+ if(s32ret <= 0)
+ {
+ SLOGE("recv innormal!!!");
+ http_server_close(socketfd);
+ return SF_FAILURE;
+ }
+ //http_file_response_parse();
+ MLOGD("recv buf:%s\n", buf);
+ http_server_close(socketfd);
+ return SF_SUCCESS;
+}
+
+int sf_usbnet_server_acm_open(SF_PDT_PARAM_STATISTICS_S *pStaticParam)
+{
+ int ret = 0;
+ SF_CHAR server_domain_name[32] = {0};
+ ret = http_domain_name_get(pStaticParam->AcmIP,server_domain_name);
+ if(ret != SF_SUCCESS)
+ return ret;
+ MLOGI("acm domain name:[%s]\n",server_domain_name );
+ ret = http_server_creat(server_domain_name, &socketfd);
+ if(ret != SF_SUCCESS)
+ return ret;
+
+ return SF_SUCCESS;
+}
+SINT32 sf_usbnet_server_acm_transfer(SF_DATA_ATTR_S *psenddate)
+{
+ SINT32 s32ret = 0;
+
+ s32ret = http_send_to_server(socketfd,(char*)psenddate->databuf,psenddate->dataSize);
+ SF_APPCOMM_CHECK_RETURN(s32ret,SF_HTTP_ERROR_WRITE);
+
+
+ memset(psenddate->databuf, '\0', SF_HTTP_RECV_MAX);
+ s32ret = http_recv_from_server(socketfd,(char*)psenddate->databuf, SF_HTTP_RECV_MAX);
+ MLOGI("datasize = %d\n",s32ret);
+ if(s32ret <= 0)
+ return SF_FAILURE;
+ psenddate->dataSize = s32ret;
+ return SF_SUCCESS;
+}
+
+SINT32 sf_usbnet_server_acm_close()
+{
+ MLOGI("\n");
+ return http_server_close(socketfd);
+
+}
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
diff --git a/code/application/source/sf_app/code/source/4gMng/sf_module.c b/code/application/source/sf_app/code/source/4gMng/sf_module.c
new file mode 100755
index 000000000..0cd9e09b7
--- /dev/null
+++ b/code/application/source/sf_app/code/source/4gMng/sf_module.c
@@ -0,0 +1,305 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_log.h"
+#include "sf_type.h"
+#include "sf_hal_gpio.h"
+#include "sf_module.h"
+#if defined(CFG_MODULE_EG91)
+#include "sf_eg91_sim.h"
+#include "sf_eg91_gps.h"
+#include "sf_eg91_server.h"
+#ifndef CFG_TRANSDATA_AT
+#include "sf_http_server.h"
+#endif
+#endif
+extern pthread_mutex_t GPIO_mutexLock;
+
+static SF_4G_STATUS_E ModuleStatus = SF_4G_FREE;
+
+void sf_4G_usb_init(void)
+{
+ sf_hal_gpio_init(GPIOID_USB_MUX1,GPIO_DIR_OUT);
+ sf_hal_gpio_set(GPIOID_USB_MUX1,1);
+}
+SF_4G_STATUS_E sf_4G_status_get(void)
+{
+ return ModuleStatus;
+}
+
+void sf_4G_status_set(SF_4G_STATUS_E enStatus)
+{
+
+ if(enStatus < SF_4G_BUTT)
+ ModuleStatus = enStatus;
+ else
+ MLOGE("Type format error\n");
+
+ return;
+}
+
+SINT32 sf_4G_sim_IsInsert(void)
+{
+ return 1;
+ SINT8 regValue = 0;
+ SF_MUTEX_LOCK(GPIO_mutexLock);
+ sf_hal_gpio_init(GPIOID_SIM_INSRET, GPIO_DIR_IN);
+ sf_hal_gpio_get(GPIOID_SIM_INSRET, ®Value);
+ sf_hal_gpio_deinit(GPIOID_SIM_INSRET);
+ SF_MUTEX_UNLOCK(GPIO_mutexLock);
+ MLOGI("SIM = %d\n",regValue);
+ return (regValue & 0xFF) ? 1:0;
+
+}
+
+static UINT8 sf_4g_net_level_get(UINT8 simSignal)
+{
+ if(simSignal == 0)
+ {
+ return 0;
+ }
+ else if((simSignal <= 95) && (simSignal > 0))
+ {
+ return 4;
+ }
+ else if((simSignal <= 105) && (simSignal > 95))
+ {
+ return 3;
+ }
+ else if((simSignal <= 115) && (simSignal > 105))
+ {
+ return 3;
+ }
+ else if((simSignal > 115))
+ return 2;
+
+
+ return SF_SUCCESS;
+}
+
+static UINT8 sf_3g_net_level_get(UINT8 simSignal)
+{
+ if(simSignal == 0)
+ {
+ return 0;
+ }
+ else if(simSignal < 10)
+ {
+ return 2;
+ }
+ else if(simSignal < 14)
+ {
+ return 3;//t100, custumer signal level,20210914
+ }
+ else if(simSignal < 18)
+ {
+ return 3;//t100, custumer signal level,20210914
+ }
+ else if(simSignal <= 31)
+ {
+ return 4;//t100, custumer signal level,20210914
+ }
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_4G_signal_level_get(SINT8 net,SINT8 signal,UINT8* value)
+{
+ SF_COMM_CHECK_POINTER(value,SF_FAILURE);
+
+ if(net == 4)
+ *value = sf_4g_net_level_get(signal);
+ else
+ *value = sf_3g_net_level_get(signal);
+
+
+ return SF_SUCCESS;
+}
+
+SINT32 sf_4G_qsclk_set(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_qsclk_set(pfnParam);
+ #endif
+}
+SINT32 sf_4G_iccid_get(SF_CHAR *iccid,SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_iccid_get(iccid,pfnParam);
+ #endif
+}
+SINT32 sf_4G_http_config(SF_FN_PARAM_S *pfnParam, UINT8 sslOn, UINT8 autoReqHead)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_http_config(pfnParam,sslOn,autoReqHead);
+ #endif
+}
+
+SINT32 sf_4G_http_authenrequst(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ #if defined(CFG_TRANSDATA_AT)
+ return eg91_http_authenrequst(pfnParam);
+ #else
+ return sf_usbnet_http_authenrequst(pfnParam->pstaticParam);
+ #endif
+ #endif
+}
+
+SINT32 sf_4G_file_transfer(SF_CHAR *fileName, SINT32 *fileSize, SF_FILE_TYPE_E fileType)
+{
+ #if defined(CFG_MODULE_EG91)
+ #if defined(CFG_TRANSDATA_AT)
+ return eg91_file_to_module(fileName, fileSize,fileType);
+ #else
+ return SF_SUCCESS;
+ #endif
+ #endif
+}
+
+SINT32 sf_4G_http_pushfile(SF_FILE_ATTR_S *pstFileAttr,SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ #if defined(CFG_TRANSDATA_AT)
+ return eg91_http_pushfile(pstFileAttr,pfnParam);
+ #else
+ return sf_usbnet_http_pushfile(pstFileAttr,pfnParam);
+ #endif
+ #endif
+}
+SINT32 sf_4G_server_open(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+
+ #if defined(CFG_TRANSDATA_AT)
+ return eg91_server_acm_open(pfnParam);
+ #else
+ return sf_usbnet_server_acm_open(pfnParam->pstaticParam);
+ #endif
+ #endif
+}
+
+SINT32 sf_4G_acm_tcp_server_open(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_server_acm_open(pfnParam);
+ #endif
+}
+
+SINT32 sf_4G_acm_tcp_server_close(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_server_acm_close(pfnParam);
+ #endif
+}
+
+SINT32 sf_4G_server_transferdata(SF_DATA_ATTR_S *psenddate, SF_FN_PARAM_S *pfnParam, UINT8 needRepose)
+{
+ #if defined(CFG_MODULE_EG91)
+ #if defined(CFG_TRANSDATA_AT)
+ return eg91_server_acm_transfer(psenddate, pfnParam, needRepose);
+ #else
+ return sf_usbnet_server_acm_transfer(psenddate);
+ #endif
+ #endif
+}
+
+SINT32 sf_4G_acm_tcp_server_transferdata(SF_DATA_ATTR_S *psenddate, SF_FN_PARAM_S *pfnParam, UINT8 needRepose)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_server_acm_transfer(psenddate, pfnParam, needRepose);
+ #endif
+}
+
+SINT32 sf_4G_server_close(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ #if defined(CFG_TRANSDATA_AT)
+ return eg91_server_acm_close(pfnParam);
+ #else
+ return sf_usbnet_server_acm_close();
+ #endif
+ #endif
+}
+SINT32 sf_4G_gps_greendate_Get(SF_FN_PARAM_S *pfnParam,SF_PARA_TIME_S *pNowTime)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_gps_greendate_Get(pfnParam,pNowTime);
+ #endif
+}
+
+SINT32 sf_4G_gps_Isupdate(SF_FN_PARAM_S *pfnParam,UINT8 *pIsupdate,SF_PARA_TIME_S *pNowTime,UINT8 u8day)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_gps_Isupdate(pfnParam,pIsupdate,pNowTime,u8day);
+ #endif
+}
+SINT32 sf_4G_gps_preconfig(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_gps_preconfig(pfnParam);
+ #endif
+}
+
+SINT32 sf_4G_gps_search(SF_FN_PARAM_S *pfnParam,SF_PARA_TIME_S *pNowTime,UINT8 autoModeFlag)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_gps_search(pfnParam,pNowTime,autoModeFlag);
+ #endif
+}
+SINT32 sf_4G_gps_search_result(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_gps_search_result(pfnParam);
+ #endif
+}
+
+SINT32 sf_4G_sim_init(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_sim_init(pfnParam);
+ #endif
+}
+SINT32 sf_4G_register_net_manual(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_register_net_manual(pfnParam);
+ #endif
+}
+SINT32 sf_4G_register_net_auto(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_register_net_auto(pfnParam);
+ #endif
+}
+
+SINT32 sf_4G_usb_net_apn_cfg(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_usb_net_apn_cfg(pfnParam);
+ #endif
+}
+SINT32 sf_4G_other_sim_apn_cfg(SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_MODULE_EG91)
+ return eg91_other_sim_apn_cfg(pfnParam->pstaticParam);
+ #endif
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/source/4gMng/sf_opera_adapt.c b/code/application/source/sf_app/code/source/4gMng/sf_opera_adapt.c
new file mode 100755
index 000000000..7d1953ef0
--- /dev/null
+++ b/code/application/source/sf_app/code/source/4gMng/sf_opera_adapt.c
@@ -0,0 +1,1703 @@
+/**************************************************************************
+ *
+ * Copyright (c) 2015-2020 by WuYuan Technology, Inc.
+ *
+ * This software is copyrighted by and is the property of SiFar
+ * Technology, Inc.. All rights are reserved by SiFar Technology, Inc..
+ * This software may only be used in accordance with the corresponding
+ * license agreement. Any unauthorized use, duplication, distribution,
+ * or disclosure of this software is expressly forbidden.
+ *
+ * This Copyright notice MUST not be removed or modified without prior
+ * written consent of SiFar Technology, Inc..
+ *
+ * WuYuan Technology, Inc. reserves the right to modify this software without notice.
+ *
+ * Author: Oliver
+ *
+ * Ver: 1.0.0 2018/5/7
+ * Ver: 1.0.1 2018/8/6: Oliver
+ * Ver: 1.1.0 2018/8/6: Oliver
+ * Ver: 1.1.1 2018/8/8: Oliver
+ * Ver: 1.1.2 2018/8/9: Will
+ * Ver: 1.1.3 2018/11/7: Will-Add Ukraine Italy Spain (AT@T Modify)
+**************************************************************************/
+#include
+#include "sf_type.h"
+#include "sf_log.h"
+
+#include "sf_opera_adapt.h"
+#include "sf_hal_ttyusb.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+#define MMS_SET (0)
+
+UINT16 sf_auto_operation_adaptation(SF_CHAR *operatorName, SF_PDT_PARAM_STATISTICS_S *sim_info_t)
+{
+ MLOGD("Auto_Operation_Adjust NEW, Name:%s\n", operatorName);
+ if((strncmp(operatorName, "46001", 5) == 0) || (strncmp(operatorName, "46010", 5) == 0)) //china union
+ {
+ //SMTP,FTP SET
+ strcpy(sim_info_t->ApnGPRS, "3gnet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+ //LOGI("Auto_Operation_Adjust NEW, ApnGPRS:%s\n", sim_info_t->ApnGPRS);
+ #if MMS_SET
+ //MMS SET
+ strcpy(puiPara->APNMMS, "3gwap");
+ strcpy(puiPara->URL, "http://mmsc.myuni.com.cn");
+ strcpy(puiPara->IP, "10.0.0.172");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+
+ }
+ else if((strncmp(operatorName, "46000", 5) == 0) || (strncmp(operatorName, "46002", 5) == 0) || (strncmp(operatorName, "46004", 5) == 0) || (strncmp(operatorName, "46007", 5) == 0))//china union
+ {
+ strcpy(sim_info_t->ApnGPRS, "CMNET");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "CMWAP");
+ strcpy(puiPara->URL, "mmsc.monternet.com");
+ strcpy(puiPara->IP, "10.0.0.172");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "46003", 5) == 0) || (strncmp(operatorName, "46005", 5) == 0) || (strncmp(operatorName, "46011", 5) == 0))//china telcom
+ {
+ strcpy(sim_info_t->ApnGPRS, "CTNET");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "CTWAP");
+ strcpy(puiPara->URL, "http://mmsc.vnet.mobi");
+ strcpy(puiPara->IP, "10.0.0.200");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "31000", 5) == 0) || (strncmp(operatorName, "31001", 5) == 0) || (strncmp(operatorName, "31059", 5) == 0)
+ || (strncmp(operatorName, "31089", 5) == 0) || (strncmp(operatorName, "31091", 5) == 0) || (strncmp(operatorName, "31111", 5) == 0)
+ || (strncmp(operatorName, "31127", 5) == 0) || (strncmp(operatorName, "31128", 5) == 0) || (strncmp(operatorName, "31139", 5) == 0)
+ || (strncmp(operatorName, "31148", 5) == 0)) //Vierzon
+ {
+ strcpy((char *)sim_info_t->ApnGPRS, "vzwinternet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy((char *)puiPara->MmsApn, "\0");
+ strcpy((char *)puiPara->MmsMmsc, "\0");
+ strcpy((char *)puiPara->MmsProxy, "\0");
+ strcpy((char *)puiPara->MmsPort, "\0");
+ strcpy((char *)puiPara->MmsUserName, "\0");
+ strcpy((char *)puiPara->MmsPassword, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "50501", 5) == 0) || (strncmp(operatorName, "50511", 5) == 0) || (strncmp(operatorName, "50571", 5) == 0) || (strncmp(operatorName, "50572", 5) == 0))//australia telstra
+ {
+ strcpy(sim_info_t->ApnGPRS, "telstra.internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "telstra.mms");
+ strcpy(puiPara->URL, "http://mmsc.telstra.com:8002");
+ strcpy(puiPara->IP, "10.1.1.180");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "21910", 5) == 0) //Croatia VIPnet
+ {
+ strcpy(sim_info_t->ApnGPRS, "data.vip.hr");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.vipnet.hr");
+ strcpy(puiPara->URL, "http://mms.vipnet.hr/servlets/mms");
+ strcpy(puiPara->IP, "212.91.99.91");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "21901", 5) == 0) //Croatia T-Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.ht.hr");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.htgprs");
+ strcpy(puiPara->URL, "http://mms.t-mobile.hr/servlets/mms");
+ strcpy(puiPara->IP, "10.12.0.4");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "21902", 5) == 0) // Croatia Tele2
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.tele2.hr");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "internet.tele2.hr");
+ strcpy(puiPara->URL, "http://mmsc.tele2.hr");
+ strcpy(puiPara->IP, "193.12.40.66");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "23820", 5) == 0) || (strncmp(operatorName, "23830", 5) == 0))//Danmark Telia
+ {
+ strcpy(sim_info_t->ApnGPRS, "www.internet.mtelia.dk");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "www.mms.mtelia.dk");
+ strcpy(puiPara->URL, "www.mms.mtelia.dk");
+ strcpy(puiPara->IP, "139.209.134.131");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "23801", 5) == 0) //TDC
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://192.168.241.114:8002");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "194.182.251.15");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "23802", 5) == 0) //Telenor
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.telenor.dk");
+ strcpy(puiPara->APNMMS, "internet");
+ strcpy(puiPara->IP, "212.88.64.8");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "23806", 5) == 0) //Oister
+ {
+ strcpy(sim_info_t->ApnGPRS, "Data.dk");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.oister.dk");
+ strcpy(puiPara->APNMMS, "mmssp");
+ strcpy(puiPara->IP, "172.16.53.12");
+ strcpy(puiPara->PORT, "8799");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+
+ }
+ else if(strncmp(operatorName, "24603", 5) == 0)//Lithuania Tele 2
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.tele2.lt");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.tele2.lt");
+ strcpy(puiPara->URL, "http://mmsc.tele2.lt");
+ strcpy(puiPara->IP, "193.12.40.29");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "24602", 5) == 0)//Lithuania BITE
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->URL, "http://mmsc/servlets/mms");
+ strcpy(puiPara->IP, "192.168.150.2");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mms@mms");
+ strcpy(puiPara->PASSWORD, "mms");
+ #endif
+ }
+ else if(strncmp(operatorName, "24601", 5) == 0)//Lithuania Omnitel
+ {
+ strcpy(sim_info_t->ApnGPRS, "omnitel");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "gprs.mms.lt");
+ strcpy(puiPara->URL, "http://mms.omnitel.net:8002/");
+ strcpy(puiPara->IP, "194.176.32.149");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "mms");
+ #endif
+ }
+ else if(strncmp(operatorName, "53001", 5) == 0)//New Zealand Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "vodafone");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "live.vodafone.com");
+ strcpy(puiPara->URL, "http://pxt.vodafone.net.nz/pxtsend");
+ strcpy(puiPara->IP, "172.30.38.3");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "53024", 5) == 0)//New Zealand Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->URL, "http://mms.2degreesmobile.net.nz:48090");
+ strcpy(puiPara->IP, "118.148.1.118");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22610", 5) == 0)// Romania Orange
+ {
+ strcpy(sim_info_t->ApnGPRS, "net");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->URL, "http://wap.mms.orange.ro:8002");
+ strcpy(puiPara->IP, "62.217.247.252");
+ strcpy(puiPara->PORT, "8799");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "mms");
+ #endif
+ }
+ else if(strncmp(operatorName, "22601", 5) == 0)// Romania Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "live.vodafone.com");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22603", 5) == 0)// Romania Romtelecom
+ {
+ strcpy(sim_info_t->ApnGPRS, "broadband");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22605", 5) == 0)// Romania DIGI.mobil
+ {
+ strcpy(sim_info_t->ApnGPRS, "prepaid");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "25028", 5) == 0) || (strncmp(operatorName, "25099", 5) == 0))// Russian Federation Beeline
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.beeline.ru");
+ strcpy(sim_info_t->ApnUsername, "beeline");
+ strcpy(sim_info_t->ApnPassword, "beeline");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.beeline.ru");
+ strcpy(puiPara->URL, "http://mmsc/");
+ strcpy(puiPara->IP, "192.168.94.23");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "beeline");
+ strcpy(puiPara->PASSWORD, "beeline");
+ #endif
+ }
+ else if(strncmp(operatorName, "25001", 5) == 0)// Russian Federation MTS
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.mts.ru");
+ strcpy(sim_info_t->ApnUsername, "mts");
+ strcpy(sim_info_t->ApnPassword, "mts");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.mts.ru");
+ strcpy(puiPara->URL, "http://mmsc");
+ strcpy(puiPara->IP, "192.168.192.192");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mts");
+ strcpy(puiPara->PASSWORD, "mts");
+ #endif
+ }
+ else if(strncmp(operatorName, "25002", 5) == 0)// Russian Federation MegaFon
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "gdata");
+ strcpy(sim_info_t->ApnPassword, "gdata");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->URL, "http://mmsc:8002");
+ strcpy(puiPara->IP, "10.10.10.10");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "gdata");
+ strcpy(puiPara->PASSWORD, "gdata");
+ #endif
+ }
+ else if(strncmp(operatorName, "25020", 5) == 0)// Russian Federation Tele2
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.tele2.ru");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.tele2.ru");
+ strcpy(puiPara->URL, "http://mmsc.tele2.ru");
+ strcpy(puiPara->IP, "193.12.40.65");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "25011", 5) == 0)// Russian Federation Yota
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.yota");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.yota");
+ strcpy(puiPara->URL, "http://mmsc:8002");
+ strcpy(puiPara->IP, "10.10.10.10");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "25035", 5) == 0)// Russian Federation Motiv
+ {
+ strcpy(sim_info_t->ApnGPRS, "inet.ycc.ru");
+ strcpy(sim_info_t->ApnUsername, "motiv");
+ strcpy(sim_info_t->ApnPassword, "motiv");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.ycc.ru");
+ strcpy(puiPara->URL, "http://mms.ycc.ru");
+ strcpy(puiPara->IP, "172.16.2.10");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "motiv");
+ strcpy(puiPara->PASSWORD, "motiv");
+ #endif
+ }
+ else if(strncmp(operatorName, "24007", 5) == 0)//Sweden Tele2 COMVIQ
+ {
+ strcpy(sim_info_t->ApnGPRS, "4G.tele2.se");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.tele2.se");
+ strcpy(puiPara->APNMMS, "4G.tele2.se");
+ strcpy(puiPara->IP, "130.244.202.30");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "24001", 5) == 0)//Sweden TeliaSonera Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "online.telia.se");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmss");
+ strcpy(puiPara->APNMMS, "mms.telia.se");
+ strcpy(puiPara->IP, "193.209.134.132");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "telia");
+ #endif
+ }
+ else if((strncmp(operatorName, "24006", 5) == 0) || (strncmp(operatorName, "24008", 5) == 0) || (strncmp(operatorName, "24024", 5) == 0))//Sweden Telenor Mobile Sverige
+ {
+ strcpy(sim_info_t->ApnGPRS, "services.telenor.se");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms");
+ strcpy(puiPara->APNMMS, "services.telenor.se");
+ strcpy(puiPara->IP, "172.30.253.241");
+ strcpy(puiPara->PORT, "8799");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "23433", 5) == 0) || (strncmp(operatorName, "23434", 5) == 0))// United Kingdom Orange
+ {
+ strcpy(sim_info_t->ApnGPRS, "orangeinternet");
+ strcpy(sim_info_t->ApnUsername, "user");
+ strcpy(sim_info_t->ApnPassword, "pass");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "orangemms");
+ strcpy(puiPara->URL, "http://mms.orange.co.uk/");
+ strcpy(puiPara->IP, "192.168.224.10");
+ strcpy(puiPara->PORT, "9201");
+ strcpy(puiPara->USERNAME, "Orange");
+ strcpy(puiPara->PASSWORD, "Multimedia");
+ #endif
+ }
+
+ else if((strncmp(operatorName, "23402", 5) == 0) || (strncmp(operatorName, "23410", 5) == 0) || (strncmp(operatorName, "23411", 5) == 0))// United Kingdom O2
+ {
+ strcpy(sim_info_t->ApnGPRS, "mobile.o2.co.uk");
+ strcpy(sim_info_t->ApnUsername, "web");
+ strcpy(sim_info_t->ApnPassword, "password");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "payandgo.o2.co.uk");
+ strcpy(puiPara->URL, "http://mmsc.mms.o2.co.uk:8002");
+ strcpy(puiPara->IP, "193.113.200.195");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "payandgo");
+ strcpy(puiPara->PASSWORD, "password");
+ #endif
+ }
+ else if(strncmp(operatorName, "23415", 5) == 0)//United Kingdom Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "pp.vodafone.co.uk");
+ strcpy(sim_info_t->ApnUsername, "web");
+ strcpy(sim_info_t->ApnPassword, "web");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "wap.vodafone.co.uk");
+ strcpy(puiPara->URL, "http://mms.vodafone.co.uk/servlets/mms/");
+ strcpy(puiPara->IP, "212.183.137.12");
+ strcpy(puiPara->PORT, "9201");
+ strcpy(puiPara->USERNAME, "wap");
+ strcpy(puiPara->PASSWORD, "wap");
+ #endif
+ }
+ else if(strncmp(operatorName, "23430", 5) == 0)//United Kingdom T-Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "general.t-mobile.uk");
+ strcpy(sim_info_t->ApnUsername, "user");
+ strcpy(sim_info_t->ApnPassword, "wap");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "general.t-mobile.uk");
+ strcpy(puiPara->URL, "http://mmsc.t-mobile.co.uk:8002/");
+ strcpy(puiPara->IP, "149.254.211.10");
+ strcpy(puiPara->PORT, "9201");
+ strcpy(puiPara->USERNAME, "user");
+ strcpy(puiPara->PASSWORD, "one2one");
+ #endif
+ }
+ else if(strncmp(operatorName, "23420", 5) == 0)//United Kingdom 3
+ {
+ strcpy(sim_info_t->ApnGPRS, "three.co.uk");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.three.co.uk");
+ strcpy(puiPara->URL, "http://mms.um.three.co.uk:10021/mmsc");
+ strcpy(puiPara->IP, "217.171.129.2");
+ strcpy(puiPara->PORT, "8799");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "24403", 5) == 0) || (strncmp(operatorName, "24412", 5) == 0))// Finland DNA
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.dnafinland.fi");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "10.1.1.2");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "24421", 5) == 0)// Finland Saunalahti
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.saunalahti");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.saunalahti.fi:8002/");
+ strcpy(puiPara->APNMMS, "mms.saunalahti.fi");
+ strcpy(puiPara->IP, "62.142.4.197");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "24405", 5) == 0)// Finland Elisa
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.elisa.fi");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "213.161.41.57");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "24491", 5) == 0)// Finland Sonera
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.sonera.net:8002/");
+ strcpy(puiPara->APNMMS, "wap.sonera.net");
+ strcpy(puiPara->IP, "195.156.25.33");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "24410", 5) == 0)// Finland TDC
+ {
+ strcpy(sim_info_t->ApnGPRS, "inet.tdc.fi");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.tdc.fi");
+ strcpy(puiPara->APNMMS, "mms.tdc.fi");
+ strcpy(puiPara->IP, "10.1.12.2");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "65507", 5) == 0)// South Africa Cell C
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.cmobile.co.za/");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "196.31.116.250");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "65510", 5) == 0)// South Africa MTN
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "guest");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.mtn.co.za/mms/wapenc");
+ strcpy(puiPara->APNMMS, "mymtn");
+ strcpy(puiPara->IP, "196.11.240.241");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "65501", 5) == 0)// South Africa Vodacom
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "guest");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.vodacom4me.co.za/");
+ strcpy(puiPara->APNMMS, "mms.vodacom.net");
+ strcpy(puiPara->IP, "196.6.128.13");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "65502", 5) == 0)// South Africa 8ta
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "guest");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.8ta.com:38090/was");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "41.151.254.162");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "guest");
+ strcpy(puiPara->PASSWORD, "guest");
+ #endif
+ }
+ else if(strncmp(operatorName, "22201", 5) == 0)// Italy TIM
+ {
+ strcpy(sim_info_t->ApnGPRS, "ibox.tim.it");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.tim.it/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms.tim.it");
+ strcpy(puiPara->IP, "213.230.130.89");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22210", 5) == 0)// Italy Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "mobile.vodafone.it");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.vodafone.it/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms.vodafone.it");
+ strcpy(puiPara->IP, "10.128.224.10");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22288", 5) == 0)// Italy wind
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.wind");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.wind.it");
+ strcpy(puiPara->APNMMS, "mms.wind");
+ strcpy(puiPara->IP, "212.245.244.11");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22208", 5) == 0) //Italy Fastweb Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "apn.fastweb.it");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22207", 5) == 0) //Italy Kena Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "web.kenamobile.it");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22215", 5) == 0) //Italy Iliad
+ {
+ strcpy(sim_info_t->ApnGPRS, "iliad");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "22233", 5) == 0) //Italy PosteMobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "wap.postemobile.it");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "20815", 5) == 0)// France Free Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "free");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.free.fr");
+ strcpy(puiPara->APNMMS, "mmsfree");
+ strcpy(puiPara->IP, "212.27.40.225");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "20801", 5) == 0) // France Orange
+ {
+ strcpy(sim_info_t->ApnGPRS, "orange");
+ strcpy(sim_info_t->ApnUsername, "orange");
+ strcpy(sim_info_t->ApnPassword, "orange");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.orange.fr");
+ strcpy(puiPara->APNMMS, "orange.acte");
+ strcpy(puiPara->IP, "192.168.10.200");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "20820", 5) == 0)// France Bouygues Telecom
+ {
+ strcpy(sim_info_t->ApnGPRS, "mmsbouygtel.com");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.bouyguestelecom.fr/mms/wap");
+ strcpy(puiPara->APNMMS, "mmsbouygtel.com");
+ strcpy(puiPara->IP, "62.201.137.17");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "20810", 5) == 0)// France SFR
+ {
+ strcpy(sim_info_t->ApnGPRS, "sl2sfr");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms1");
+ strcpy(puiPara->APNMMS, "sl2sfr");
+ strcpy(puiPara->IP, "10.151.0.1");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "31003", 5) == 0) || (strncmp(operatorName, "31009", 5) == 0) \
+ || (strncmp(operatorName, "31015", 5) == 0) || (strncmp(operatorName, "31017", 5) == 0) \
+ || (strncmp(operatorName, "31041", 5) == 0) || (strncmp(operatorName, "31056", 5) == 0) \
+ || (strncmp(operatorName, "31068", 5) == 0) || (strncmp(operatorName, "31028", 5) == 0))// United States AT&T
+ {
+ strcpy(sim_info_t->ApnGPRS, "nxtgenphone");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.mobile.att.net");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "proxy.mobile.att.net");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+
+ else if((strncmp(operatorName, "31002", 5) == 0) || (strncmp(operatorName, "31016", 5) == 0) || (strncmp(operatorName, "31020", 5) == 0)|| (strncmp(operatorName, "31021", 5) == 0)|| (strncmp(operatorName, "31022", 5) == 0)|| (strncmp(operatorName, "31023", 5) == 0)|| (strncmp(operatorName, "31024", 5) == 0)
+
+ || (strncmp(operatorName, "31025", 5) == 0) || (strncmp(operatorName, "31026", 5) == 0) || (strncmp(operatorName, "31027", 5) == 0) || (strncmp(operatorName, "31029", 5) == 0) || (strncmp(operatorName, "31031", 5) == 0) || (strncmp(operatorName, "31033", 5) == 0)
+ || (strncmp(operatorName, "31058", 5) == 0) || (strncmp(operatorName, "31066", 5) == 0) || (strncmp(operatorName, "31080", 5) == 0))// United States T-Mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "fast.t-mobile.com");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.msg.eng.t-mobile.com/mms/wapenc");
+ strcpy(puiPara->APNMMS, "wap.voicestream.com");
+ strcpy(puiPara->IP, "216.155.165.50");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if ((strncmp(operatorName, "26206", 5) == 0) || (strncmp(operatorName, "26212", 5) == 0))
+ {
+ // Germany Telekom
+ strcpy(sim_info_t->ApnGPRS, "internet.telekom");
+ strcpy(sim_info_t->ApnUsername, "t-mobile");
+ strcpy(sim_info_t->ApnPassword, "tm");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.t-mobile.de/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms.t-d1.de");
+ strcpy(puiPara->IP, "172.28.23.131");
+ strcpy(puiPara->PORT, "8008");
+ strcpy(puiPara->USERNAME, "t-mobile");
+ strcpy(puiPara->PASSWORD, "mms");
+ #endif
+ }
+ else if(strncmp(operatorName, "26201", 5) == 0)
+ {
+ // Germany T-Mobile
+ strcpy(sim_info_t->ApnGPRS, "internet.t-mobile");
+ strcpy(sim_info_t->ApnUsername, "t-mobile");
+ strcpy(sim_info_t->ApnPassword, "tm");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.t-mobile.de/servlets/mms");
+ strcpy(puiPara->APNMMS, "internet.t-mobile");
+ strcpy(puiPara->IP, "172.28.23.131");
+ strcpy(puiPara->PORT, "8008");
+ strcpy(puiPara->USERNAME, "t-mobile");
+ strcpy(puiPara->PASSWORD, "tm");
+ #endif
+ }
+ else if ((strncmp(operatorName, "26202", 5) == 0) || (strncmp(operatorName, "26204", 5) == 0) || (strncmp(operatorName, "26209", 5) == 0))
+ {
+ // Germany Vodafone
+ strcpy(sim_info_t->ApnGPRS, "web.vodafone.de");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://139.7.24.1/servlets/mms");
+ strcpy(puiPara->APNMMS, "event.vodafone.de");
+ strcpy(puiPara->IP, "139.7.29.17");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "26203", 5) == 0) || (strncmp(operatorName, "26205", 5) == 0) || (strncmp(operatorName, "26277", 5) == 0))
+ {
+ // Germany E-Plus
+ strcpy(sim_info_t->ApnGPRS, "internet.eplus.de");
+ strcpy(sim_info_t->ApnUsername, "eplus");
+ strcpy(sim_info_t->ApnPassword, "internet");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms/eplus");
+ strcpy(puiPara->APNMMS, "mms.eplus.de");
+ strcpy(puiPara->IP, "212.23.97.153");
+ strcpy(puiPara->PORT, "5080");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "eplus");
+ #endif
+ }
+ else if ((strncmp(operatorName, "26207", 5) == 0) || (strncmp(operatorName, "26208", 5) == 0) || (strncmp(operatorName, "26211", 5) == 0))
+ {
+ // Germany O2
+ strcpy(sim_info_t->ApnGPRS, "pinternet.interkom.de");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://10.81.0.7:8002/");
+ strcpy(puiPara->APNMMS, "pinternet.interkom.de");
+ strcpy(puiPara->IP, "82.113.100.6");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "29331", 5) == 0) || (strncmp(operatorName, "29341", 5) == 0) || (strncmp(operatorName, "29351", 5) == 0))
+ {
+ // Slovenia Telekom
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "mobitel");
+ strcpy(sim_info_t->ApnPassword, "internet");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.telekom.si");
+ strcpy(puiPara->APNMMS, "internet");
+ strcpy(puiPara->IP, "213.229.249.40");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mobitel");
+ strcpy(puiPara->PASSWORD, "internet");
+ #endif
+ }
+ else if (strncmp(operatorName, "29340", 5) == 0)
+ {
+ // Slovenia Simobil
+ strcpy(sim_info_t->ApnGPRS, "internet.simobil.si");
+ strcpy(sim_info_t->ApnUsername, "simobil");
+ strcpy(sim_info_t->ApnPassword, "internet");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmc");
+ strcpy(puiPara->APNMMS, "mms.simobil.si");
+ strcpy(puiPara->IP, "80.95.224.46");
+ strcpy(puiPara->PORT, "9201");
+ strcpy(puiPara->USERNAME, "simobil");
+ strcpy(puiPara->PASSWORD, "internet");
+ #endif
+ }
+ else if (strncmp(operatorName, "29364", 5) == 0)
+ {
+ // Slovenia T2
+ strcpy(sim_info_t->ApnGPRS, "mms.t-2.net");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://www.mms.t-2.net:8002");
+ strcpy(puiPara->APNMMS, "mms.t-2.net");
+ strcpy(puiPara->IP, "172.20.18.137");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "23106", 5) == 0)
+ {
+ //Slovakia O2
+ strcpy(sim_info_t->ApnGPRS, "o2internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.o2world.sk:8002");
+ strcpy(puiPara->APNMMS, "o2mms");
+ strcpy(puiPara->IP, "10.97.1.11");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if ((strncmp(operatorName, "23102", 5) == 0) || (strncmp(operatorName, "23104", 5) == 0))
+ {
+ //Slovakia T-Mobile
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "192.168.1.1");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "23101", 5) == 0)
+ {
+ //Slovakia Orange
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://imms.orange.sk");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "213.151.208.145");
+ strcpy(puiPara->PORT, "8799");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "23103", 5) == 0)
+ {
+ //Slovakia 4Ka
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "192.168.1.1");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "42501", 5) == 0)
+ {
+ //Israel orange
+ strcpy(sim_info_t->ApnGPRS, "uinternet");
+ strcpy(sim_info_t->ApnUsername, "orange");
+ strcpy(sim_info_t->ApnPassword, "orange");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://192.168.220.15/servlets/mms");
+ strcpy(puiPara->APNMMS, "uwap.orange.co.il");
+ strcpy(puiPara->IP, "192.118.11.55");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "24801", 5) == 0)
+ {
+ //Estonia(Telia)
+ strcpy(sim_info_t->ApnGPRS, "internet.emt.ee");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.emt.ee");
+ strcpy(puiPara->URL, "mms.emt.ee/servlets/mms");
+ strcpy(puiPara->IP, "217.71.32.82");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "24802", 5) == 0)
+ {
+ //Estonia(Elisa)
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->URL, "194.204.2.10");
+ strcpy(puiPara->IP, "194.204.2.6");
+ strcpy(puiPara->PORT, "8000");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "24803", 5) == 0)
+ {
+ //Estonia(Tele2)
+ strcpy(sim_info_t->ApnGPRS, "internet.tele2.ee");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->APNMMS, "mms.tele2.ee");
+ strcpy(puiPara->URL, "mmsc.tele2.ee");
+ strcpy(puiPara->IP, "193.12.40.6");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "20416", 5) == 0)
+ {
+ //Netherlands T-Mobile
+ strcpy(sim_info_t->ApnGPRS, "smartsites.t-mobile");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://t-mobilemms");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "10.10.10.11");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "tmobilemms");
+ strcpy(puiPara->PASSWORD, "tmobilemms");
+ #endif
+ }
+ else if (strncmp(operatorName, "24201", 5) == 0) //norway Telenor
+ {
+ strcpy(sim_info_t->ApnGPRS, "telenor.smart");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc");
+ strcpy(puiPara->APNMMS, "telenor");
+ strcpy(puiPara->IP, "10.10.10.11");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "24202", 5) == 0) //norway Telia/Chilli Mobil
+ {
+ strcpy(sim_info_t->ApnGPRS, "telia");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mm");
+ strcpy(puiPara->APNMMS, "telia");
+ strcpy(puiPara->IP, "212.169.66.4");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "24205", 5) == 0) //norway Ice Net
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.nwn.no");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "188.149.250.10");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if ((strncmp(operatorName, "24206", 5) == 0) || (strncmp(operatorName, "24214", 5) == 0)) //norway ice net
+ {
+ strcpy(sim_info_t->ApnGPRS, "ice.net");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms");
+ strcpy(puiPara->APNMMS, "mms.ice.net");
+ strcpy(puiPara->IP, "10.10.10.10");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "24208", 5) == 0) //norway Get
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.no");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.tdc.dk:8002");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "inetproxy.tdc.dk");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if (strncmp(operatorName, "26801", 5) == 0) //Portugal vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "net2.vodafone.pt");
+ strcpy(sim_info_t->ApnUsername, "vodafone");
+ strcpy(sim_info_t->ApnPassword, "vodafone");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.vodafone.pt/servlets/mms");
+ strcpy(puiPara->APNMMS, "net2.vodafone.pt");
+ strcpy(puiPara->IP, "Iproxy.vodafone.pt");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "vodafone");
+ strcpy(puiPara->PASSWORD, "vodafone");
+ #endif
+ }
+ else if(strncmp(operatorName, "26002", 5) == 0) //Polish Tmobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mms/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "213.158.194.226");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "26003", 5) == 0) //Polish Orange
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "internet");
+ strcpy(sim_info_t->ApnPassword, "internet");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mms.orange.pl");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "192.168.6.104");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "mms");
+ #endif
+ }
+ else if(strncmp(operatorName, "26001", 5) == 0) //Polish Plus
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mms.plusgsm.pl:8002");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "212.2.96.16");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "26006", 5) == 0) //Polish Play
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mmsc.play.pl/mms/wapenc");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "10.10.25.5");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "30261", 5) == 0) || (strncmp(operatorName, "30269", 5) == 0) || (strncmp(operatorName, "30263", 5) == 0)) //Canada Bell
+ {
+ strcpy(sim_info_t->ApnGPRS, "pda.bell.ca");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.bell.ca/mms/wapenc");
+ strcpy(puiPara->APNMMS, "pda.bell.ca");
+ strcpy(puiPara->IP, "web.wireless.bell.ca");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "30232", 5) == 0) || (strncmp(operatorName, "30272", 5) == 0))//Canada Rogers
+ {
+ strcpy(sim_info_t->ApnGPRS, "rogers-core-appl1.apn");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.gprs.rogers.com");
+ strcpy(puiPara->APNMMS, "rogers-core-appl1.apn");
+ strcpy(puiPara->IP, "10.128.1.69");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "wap@wap");
+ strcpy(puiPara->PASSWORD, "wap125");
+ #endif
+ }
+ /*
+ else if(strncmp(operatorName, "30222", 5) == 0) //Canada Telus
+ {
+ strcpy(sim_info_t->ApnGPRS, "sp.telus.com");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://aliasredirect.net/proxy/mmsc");
+ strcpy(puiPara->APNMMS, "sp.telus.com");
+ strcpy(puiPara->IP, "74.49.0.18");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ */
+ else if((strncmp(operatorName, "30268", 5) == 0) || (strncmp(operatorName, "30278", 5) == 0)) //Canada SaskTel
+ {
+ strcpy(sim_info_t->ApnGPRS, "pda.stm.sk.ca");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.sasktel.com");
+ strcpy(puiPara->APNMMS, "pda.stm.sk.ca");
+ strcpy(puiPara->IP, "mig.sasktel.com");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "23002", 5) == 0) //Czech O2
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.o2active.cz:8002");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "160.218.160.218");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "23003", 5) == 0) //Czech Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms/");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "10.11.10.111");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "23001", 5) == 0) //Czech T-mobile
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.t-mobile.cz");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms");
+ strcpy(puiPara->APNMMS, "mms.t-mobile.cz");
+ strcpy(puiPara->IP, "10.0.0.10");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "28601", 5) == 0) //Turkey Turkcell
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mms.turkcell.com.tr/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "212.252.169.217");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "28602", 5) == 0) //Turkey Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "vodafone");
+ strcpy(sim_info_t->ApnPassword, "vodafone");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mms:6001/MM1Servlet");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "217.31.233.18");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "vodafone");
+ strcpy(puiPara->PASSWORD, "vodafone");
+ #endif
+ }
+ else if((strncmp(operatorName, "28603", 5) == 0) ||(strncmp(operatorName, "28604", 5) == 0))//Turkey Avea
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "mms.avea.com.tr/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "213.161.151.201");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "28401", 5) == 0) //Bulgaria A1
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.a1.bg");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc/");
+ strcpy(puiPara->APNMMS, "mms.a1.bg");
+ strcpy(puiPara->IP, "10.150.0.33");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "28405", 5) == 0) //Bulgaria Telenor
+ {
+ strcpy(sim_info_t->ApnGPRS, "telenorbg");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc/");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "192.168.87.11");
+ strcpy(puiPara->PORT, "8004");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "28403", 5) == 0) //Bulgaria VIVACOM
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.vivacom.bg");
+ strcpy(sim_info_t->ApnUsername, "VIVACOM");
+ strcpy(sim_info_t->ApnPassword, "VIVACOM");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.vivacom.bg");
+ strcpy(puiPara->APNMMS, "mms.vivacom.bg");
+ strcpy(puiPara->IP, "192.168.123.123");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "25503", 5) == 0) //Ukraine KYIVSTAR
+ {
+ strcpy(sim_info_t->ApnGPRS, "www.kyivstar.net");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.kyivstar.net");
+ strcpy(puiPara->APNMMS, "mms.kyivstar.net");
+ strcpy(puiPara->IP, "10.10.10.10");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "25501", 5) == 0) //Ukraine Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc:8002/");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "192.168.10.10");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "25506", 5) == 0) //Ukraine LifeCell
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.life");
+ strcpy(puiPara->APNMMS, "mms");
+ strcpy(puiPara->IP, "10.10.10.10");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "21407", 5) == 0) //Spain Movistar
+ {
+ strcpy(sim_info_t->ApnGPRS, "telefonica.es");
+ strcpy(sim_info_t->ApnUsername, "telefonica");
+ strcpy(sim_info_t->ApnPassword, "telefonica");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mms.movistar.es");
+ strcpy(puiPara->APNMMS, "telefonica.es");
+ strcpy(puiPara->IP, "10.138.255.5");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "21401", 5) == 0) //Spain Vodafone
+ {
+ strcpy(sim_info_t->ApnGPRS, "airtelwap.es");
+ strcpy(sim_info_t->ApnUsername, "wap@wap");
+ strcpy(sim_info_t->ApnPassword, "wap125");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.vodafone.es/servlets/mms");
+ strcpy(puiPara->APNMMS, "mms.vodafone.net");
+ strcpy(puiPara->IP, "212.73.32.10");
+ strcpy(puiPara->PORT, "80");
+ strcpy(puiPara->USERNAME, "wap@wap");
+ strcpy(puiPara->PASSWORD, "wap125");
+ #endif
+ }
+ else if(strncmp(operatorName, "21403", 5) == 0) //Spain Simyo
+ {
+ strcpy(sim_info_t->ApnGPRS, "orangeworld");
+ strcpy(sim_info_t->ApnUsername, "orange");
+ strcpy(sim_info_t->ApnPassword, "orange");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "https://mms.orange.es");
+ strcpy(puiPara->APNMMS, "orangemms");
+ strcpy(puiPara->IP, "172.22.188.25");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if((strncmp(operatorName, "20628", 5) == 0) || (strncmp(operatorName, "20601", 5) == 0)
+ || (strncmp(operatorName, "52505", 5) == 0) || (strncmp(operatorName, "30222", 5) == 0)
+ || (strncmp(operatorName, "20809", 5) == 0))
+ {
+ if((strstr(sim_info_t->ModuleVersion, GPRS_MODULE_TYPE_EG91_V)) || (strstr(sim_info_t->ModuleVersion, GPRS_MODULE_TYPE_EG95_V)) \
+ || (strstr(sim_info_t->ModuleVersion, GPRS_MODULE_TYPE_EG91_NAXD)) || (strstr(sim_info_t->ModuleVersion, GPRS_MODULE_TYPE_EG95_NAXD)))
+ {
+ strcpy(sim_info_t->ApnGPRS, "America.bics");
+ }
+ else
+ {
+ strcpy(sim_info_t->ApnGPRS, "bicsapn");
+ }
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ }
+ else if(strncmp(operatorName, "20408", 5) == 0) //kpn sim
+ {
+ strcpy(sim_info_t->ApnGPRS, "fast.m2m");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ else if(strncmp(operatorName, "20404", 5) == 0) // wodafeng sim
+ {
+
+ strcpy(sim_info_t->ApnGPRS, "spe.inet4gd.gdsp");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "\0");
+ strcpy(puiPara->APNMMS, "\0");
+ strcpy(puiPara->IP, "\0");
+ strcpy(puiPara->PORT, "\0");
+ strcpy(puiPara->USERNAME, "\0");
+ strcpy(puiPara->PASSWORD, "\0");
+ #endif
+ }
+ /*
+ else if(strncmp(operatorName, "20601", 5) == 0) //Belgium Proximus
+ {
+ strcpy(sim_info_t->ApnGPRS, "internet.proximus.be");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+
+ #if MMS_SET
+ strcpy(puiPara->URL, "http://mmsc.proximus.be/mms");
+ strcpy(puiPara->APNMMS, "event.proximus.be");
+ strcpy(puiPara->IP, "10.55.14.75");
+ strcpy(puiPara->PORT, "8080");
+ strcpy(puiPara->USERNAME, "mms");
+ strcpy(puiPara->PASSWORD, "mms");
+ #endif
+ }
+ */
+ else
+ {
+ strcpy(sim_info_t->ApnGPRS, "\0");
+ strcpy(sim_info_t->ApnUsername, "\0");
+ strcpy(sim_info_t->ApnPassword, "\0");
+ return SF_4G_ERROR_AT_APN;
+ }
+
+ return SF_SUCCESS;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
diff --git a/code/application/source/sf_app/code/source/app/sf_app.c b/code/application/source/sf_app/code/source/app/sf_app.c
index 0c0581a15..35be902b5 100755
--- a/code/application/source/sf_app/code/source/app/sf_app.c
+++ b/code/application/source/sf_app/code/source/app/sf_app.c
@@ -6,23 +6,74 @@
*/
#include
-#include
-#include
+//#include
+//#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+//#include "UIInfo/UIInfo.h"
+#include
+
+pthread_mutex_t Param_mutexLock;
+pthread_mutex_t GPIO_mutexLock;
+
+
+ SINT32 app_ttyusb_IsOpen()
+{
+ int retryTime = 0;
+ SINT32 s32ret = 0;
+ //MLOGD("ttyUSB has not been init, will init ttyUSB!\n");
+ while ((s32ret = sf_hal_ttyusb2_init()) < 0)
+ {
+ retryTime++;
+ if((retryTime >=200)&&(retryTime%200 == 0))
+ {
+ //MLOGE("-------ttyUSB init fail!\n");
+ s32ret = SF_TTY_ERROR_OPEN;
+ break;
+ }
+ }
+
+ return s32ret;
+}
int main(int argc, char *argv[])
{
+ printf("*********************************************\n");
+ printf("* *\n");
+ printf("* sf_app *\n");
+ printf("* *\n");
+ printf("*********************************************\n");
//gpio_direction_input(C_GPIO(10));
- sf_mcu_init();
- sf_get_power_on_mode();
- sf_mcu_wdg_set(30);
- sf_usb_mux_s(1);
- //sf_mcu_reg_set(SF_MCU_CTRL_MODULE_PIR, 1);
- //sf_sd_exist_reg_cb(DrvCARD_DetStrgCard);
- /*led init*/
- sf_led_init();
- sf_sys_status_led_set(SF_LED_SYS_STATE_PIR_NOT_DETECT);
- //sf_battery_thread_init();
+ sf_share_mem_file_init();
+ sf_com_message_app_init();
+ sf_com_message_cardv_init();
+
+ sf_customer_param_load();
+
+ SF_MUTEX_INIT_LOCK(Param_mutexLock);
+ SF_MUTEX_INIT_LOCK(GPIO_mutexLock);
+
+ app_led_group_register();
+ //app_message_recv_start();
+
+ return 0;
}
diff --git a/code/application/source/sf_app/code/source/app/sf_app.o b/code/application/source/sf_app/code/source/app/sf_app.o
deleted file mode 100644
index fa614d808..000000000
Binary files a/code/application/source/sf_app/code/source/app/sf_app.o and /dev/null differ
diff --git a/code/application/source/sf_app/code/source/app/sf_device.c b/code/application/source/sf_app/code/source/app/sf_device.c
new file mode 100755
index 000000000..ba10f47e5
--- /dev/null
+++ b/code/application/source/sf_app/code/source/app/sf_device.c
@@ -0,0 +1,503 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "sf_log.h"
+#include "sf_ledmng.h"
+#include "sf_module.h"
+#include "sf_storeMng.h"
+#include "sf_keymng.h"
+#include "sf_systemMng.h"
+
+#include "sf_hal_gpio.h"
+#include "sf_hal_ttyusb.h"
+#include "sf_eg91_server.h"
+#include "sf_message_queue.h"
+#include "sf_dev_other.h"
+
+#include "sf_debug.h"
+#include "sf_device.h"
+
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+extern pthread_mutex_t GPIO_mutexLock;
+
+SF_THREAD_S PirMonitorTskCfg =
+{
+ .IsRun = 0,
+ .TskId = -1,
+};
+
+void* pir_monitoring_thread(void)
+{
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+
+ while(PirMonitorTskCfg.IsRun)
+ {
+ if(sf_cap_status_get() == 0)
+ {
+ if(!(SF_UPGRADE_ING == sf_upgrade_status_get() || SF_UPGRADE_FAIL == sf_upgrade_status_get()))
+ sf_hal_gpio_set(SF_HAL_LED_STATUS_G, (sf_dev_pir_status_get()?SF_HAL_LED_STATE_ON:SF_HAL_LED_STATE_OFF));
+ }
+ sf_sleep_ms(50);
+ }
+
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ stMessageBuf.arg2 = LED_GROUP_SIGNAL;
+ stMessageBuf.arg3 = LED_TYPE_OFF;
+ sf_com_message_send_to_app(&stMessageBuf);
+ return NULL;
+}
+SINT32 app_pir_monitoring_start(void)
+{
+ SINT32 ret = SF_SUCCESS;
+
+ if(sf_poweron_type_get() != SF_MCU_STARTUP_ONKEY){
+ MLOGE("unsupport startup mode !!!\n");
+ return SF_FAILURE;
+ }
+ if(PirMonitorTskCfg.IsRun) {
+ MLOGE("thread has already run !!!\n");
+ return SF_FAILURE;
+ }
+ ret = pthread_create(&PirMonitorTskCfg.TskId, NULL, pir_monitoring_thread, NULL);
+ if(ret != SF_SUCCESS)
+ {
+ SLOGD("thread sf_pir_monitoring_start creat fail!\n");
+ return ret;
+ }
+ PirMonitorTskCfg.IsRun = 1;
+
+ return SF_SUCCESS;
+
+}
+
+SINT32 app_pir_monitoring_stop(void)
+{
+ SINT32 ret = SF_SUCCESS;
+ if(!PirMonitorTskCfg.IsRun){
+ MLOGE("thread has not run !!!\n");
+ return SF_FAILURE;
+ }
+ PirMonitorTskCfg.IsRun = 0;
+ ret = pthread_join(PirMonitorTskCfg.TskId, NULL);
+ if(ret != SF_SUCCESS) {
+ MLOGE(" sf_pir_monitoring_stop stop fail!\n");
+ return ret;
+ }
+ return SF_SUCCESS;
+}
+
+SINT32 app_led_sd_process(SINT32 entype)
+{
+ switch(entype )
+ {
+ case LED_TYPE_OFF:
+ sf_hal_gpio_set(SF_HAL_LED_SD_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_SD_R, SF_HAL_LED_STATE_OFF);
+ break;
+ case LED_TYPE_RED:
+ sf_hal_gpio_set(SF_HAL_LED_SD_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_SD_R, SF_HAL_LED_STATE_ON);
+ break;
+ case LED_TYPE_YELLOW:
+ sf_hal_gpio_set(SF_HAL_LED_SD_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_SD_R, SF_HAL_LED_STATE_ON);
+ break;
+ case LED_TYPE_GREEN:
+ sf_hal_gpio_set(SF_HAL_LED_SD_R, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_SD_G, SF_HAL_LED_STATE_ON);
+ break;
+ default:
+ MLOGE("Uknown param [%d]!!!\n",entype);
+ return SF_FAILURE;
+ break;
+
+ }
+ return SF_SUCCESS;
+}
+SINT32 app_led_status_process(SINT8 entype)
+{
+ switch(entype )
+ {
+ case LED_TYPE_OFF:
+ sf_hal_gpio_set(SF_HAL_LED_STATUS_G, SF_HAL_LED_STATE_OFF);
+ break;
+ case LED_TYPE_GREEN:
+ case LED_TYPE_YELLOW:
+ case LED_TYPE_RED:
+ case LED_TYPE_ON:
+ sf_hal_gpio_set(SF_HAL_LED_STATUS_G, SF_HAL_LED_STATE_ON);
+ break;
+ default:
+ MLOGE("Uknown param [%d]!!!\n",entype);
+ return SF_FAILURE;
+ break;
+ }
+ return SF_SUCCESS;
+}
+SINT32 app_led_signal_process(SINT8 entype)
+{
+ switch(entype)
+ {
+ case LED_TYPE_OFF:
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_R, SF_HAL_LED_STATE_OFF);
+ break;
+ case LED_TYPE_RED:
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_R, SF_HAL_LED_STATE_ON);
+ break;
+ case LED_TYPE_YELLOW:
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_R, SF_HAL_LED_STATE_ON);
+ break;
+ case LED_TYPE_GREEN:
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_SIG1_R, SF_HAL_LED_STATE_OFF);
+ break;
+ default:
+ MLOGE("Uknown param [%d]!!!\n",entype);
+ return SF_FAILURE;
+ break;
+
+ }
+ return SF_SUCCESS;
+}
+
+SINT32 app_led_bat_process(SINT8 entype)
+{
+ switch(entype)
+ {
+ case LED_TYPE_GREEN:
+ sf_hal_gpio_set(SF_HAL_LED_BAT_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_BAT_R, SF_HAL_LED_STATE_OFF);
+ break;
+
+ case LED_TYPE_YELLOW:
+ sf_hal_gpio_set(SF_HAL_LED_BAT_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_BAT_R, SF_HAL_LED_STATE_ON);
+ break;
+
+ case LED_TYPE_RED:
+ sf_hal_gpio_set(SF_HAL_LED_BAT_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_BAT_R, SF_HAL_LED_STATE_ON);
+ break;
+
+ case LED_TYPE_OFF:
+ sf_hal_gpio_set(SF_HAL_LED_BAT_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_BAT_R, SF_HAL_LED_STATE_OFF);
+ break;
+ default:
+ MLOGE("Uknown param [%d]!!!\n",entype);
+ return SF_FAILURE;
+ break;
+ }
+ return SF_SUCCESS;
+}
+SINT32 app_led_account_process(SINT8 entype)
+{
+ switch(entype )
+ {
+ case LED_TYPE_OFF:
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_R, SF_HAL_LED_STATE_OFF);
+ break;
+ case LED_TYPE_RED:
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_G, SF_HAL_LED_STATE_OFF);
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_R, SF_HAL_LED_STATE_ON);
+ break;
+ case LED_TYPE_YELLOW:
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_R, SF_HAL_LED_STATE_ON);
+ break;
+ case LED_TYPE_GREEN:
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_G, SF_HAL_LED_STATE_ON);
+ sf_hal_gpio_set(SF_HAL_LED_USERBIND_R, SF_HAL_LED_STATE_OFF);
+ break;
+ default:
+ MLOGE("Uknown param [%d]!!!\n",entype);
+ return SF_FAILURE;
+ break;
+
+ }
+ return SF_SUCCESS;
+}
+SINT32 app_led_hold_group(SF_LED_GROUD_E enGroupType,SINT32 enstatus)
+{
+// MLOGI("enGroupType = %d, enstatus = %d\n",enGroupType, enstatus);
+ switch(enGroupType)
+ {
+ case LED_GROUP_SD:
+ app_led_sd_process(enstatus);
+ break;
+ case LED_GROUP_BAT:
+ app_led_bat_process(enstatus);
+ break;
+ case LED_GROUP_SIGNAL:
+ app_led_signal_process(enstatus);
+ break;
+ case LED_GROUP_ACCOUNT:
+ app_led_account_process(enstatus);
+ break;
+ case LED_GROUP_STATUS:
+ app_led_status_process(enstatus);
+ break;
+ default:
+ MLOGE("Uknown param [%d]!!!\n",enGroupType);
+ return SF_FAILURE;
+ break;
+
+ }
+ return SF_SUCCESS;
+}
+SINT32 app_led_all_status_set(SF_LED_STATUS_E enLedStatus,SF_LED_TYPE_E enLedType )
+{
+ SINT8 groupID = 0;
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+ stMessageBuf.cmdId = CMD_LED;
+
+ for(groupID = 0;groupID < LED_GROUP_BUIT;groupID++) {
+ stMessageBuf.arg1 = enLedStatus;
+ stMessageBuf.arg2 = groupID;
+ stMessageBuf.arg3 = enLedType;
+ sf_com_message_send_to_app(&stMessageBuf);
+ }
+
+ return SF_SUCCESS;
+}
+SINT32 app_led_sd_status_return(void)
+{
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ switch(sf_sd_status_get()) {
+ case SF_SD_UNPLUGED:
+ case SF_SD_OUT:
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ break;
+ case SF_SD_PLUGED:
+ case SF_SD_OK:
+ stMessageBuf.arg1 = (sf_customer_param_get()->DebugMode?LED_STATUS_SLOWFLASH_ON:LED_STATUS_HOLD_ON);
+ stMessageBuf.arg3 = LED_TYPE_GREEN;
+ break;
+ case SF_SD_FULL:
+ case SF_SD_ERROR:
+ stMessageBuf.arg3 = LED_TYPE_YELLOW;
+ break;
+ default:
+ return SF_FAILURE;
+ break;
+
+}
+ sf_com_message_send_to_app(&stMessageBuf);
+ return SF_SUCCESS;
+}
+
+SINT32 app_led_net_reg_start(void)
+{
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg1 = LED_STATUS_SLOWFLASH_ON;
+ stMessageBuf.arg2 = LED_GROUP_SIGNAL;
+ stMessageBuf.arg3 = LED_TYPE_GREEN;
+ sf_com_message_send_to_app(&stMessageBuf);
+
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg1 = LED_STATUS_SLOWFLASH_ON;
+ stMessageBuf.arg2 = LED_GROUP_ACCOUNT;
+ stMessageBuf.arg3 = LED_TYPE_GREEN;
+ sf_com_message_send_to_app(&stMessageBuf);
+
+ return SF_SUCCESS;
+}
+SINT32 app_led_net_reg_stop(SINT32 s32ret)
+{
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg2 = LED_GROUP_SIGNAL;
+ if(s32ret == SF_SUCCESS) {
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ UINT8 signalLevel = 0;
+ sf_4G_signal_level_get(sf_statistics_param_get()->netGeneration,sf_statistics_param_get()->SimSignal,&signalLevel);
+ MLOGI("signalLevel = %d\n",signalLevel);
+ switch(signalLevel)
+ {
+ case 2:
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ break;
+ case 3:
+ stMessageBuf.arg3 = LED_TYPE_YELLOW;
+ break;
+ case 4:
+ stMessageBuf.arg3 = LED_TYPE_GREEN;
+ break;
+ default:
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ break;
+ }
+ }
+ else if(s32ret == SF_4G_ERROR_NO_SIMCARD \
+ || s32ret == SF_4G_ERROR_NO_SUPPOET \
+ || s32ret == SF_APP_ERROR_NO_SUPPOET)
+ {
+ stMessageBuf.arg1 = LED_STATUS_SLOWFLASH_ON;
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ }
+ else if(s32ret == SF_HTTP_ERROR_REQUEST) {
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ }
+ else if(s32ret == SF_TTY_ERROR_OPEN)
+ {
+ stMessageBuf.arg1 = LED_STATUS_QUICKFLASH_ON;
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ }
+ else {
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ }
+
+ sf_com_message_send_to_app(&stMessageBuf);
+
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg2 = LED_GROUP_ACCOUNT;
+ if(s32ret == SF_SUCCESS) {
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ stMessageBuf.arg3 = LED_TYPE_GREEN;
+ }
+ else {
+ if(sf_statistics_param_get()->bindFlag) {
+ if(s32ret == SF_4G_ERROR_NO_SIMCARD \
+ || s32ret == SF_4G_ERROR_REG_NET) {
+ stMessageBuf.arg1 = LED_STATUS_SLOWFLASH_ON;
+ }
+
+ }
+ else {
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ }
+ stMessageBuf.arg3 = LED_TYPE_RED;
+ }
+ sf_com_message_send_to_app(&stMessageBuf);
+ return SF_SUCCESS;
+}
+SINT32 app_led_poweroff(void)
+{
+ UINT16 i = 0;
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+
+// stMessageBuf.cmdId = CMD_LED;
+// stMessageBuf.arg1 = LED_STATUS_SLOWFLASH_ON;
+// stMessageBuf.arg2 = LED_GROUP_STATUS;
+// stMessageBuf.arg3 = LED_TYPE_GREEN;
+// sf_com_message_send_to_app(&stMessageBuf);
+
+ while((i < 10))
+ {
+ usleep(500*1000);
+ i++;
+ }
+ if(i == 10)
+ {
+ stMessageBuf.arg1 = SF_POWEROFF_KEYON;
+ stMessageBuf.cmdId = CMD_POWEROFF;
+ sf_com_message_send_to_app(&stMessageBuf);
+ }
+ return SF_SUCCESS;
+}
+
+SINT32 app_led_group_register(void)
+{
+
+ if(sf_poweron_type_get() != SF_MCU_STARTUP_ONKEY && sf_poweron_type_get() != SF_MCU_STARTUP_NORMAL)
+ return SF_SUCCESS;
+
+ SINT8 i = 0;
+ SINT8 eventarray[5] = {
+ LED_GROUP_SD,
+ LED_GROUP_BAT,
+ LED_GROUP_SIGNAL,
+ LED_GROUP_ACCOUNT,
+ LED_GROUP_STATUS
+ };
+
+ sf_led_add_exe(app_led_hold_group);
+ for (i = 0; i < 5; i++)
+ {
+ sf_led_event_register(eventarray[i]);
+ }
+ return SF_SUCCESS;
+}
+SINT32 app_led_pin_init(void)
+{
+
+ if(sf_poweron_type_get() != SF_MCU_STARTUP_ONKEY && sf_poweron_type_get() != SF_MCU_STARTUP_NORMAL)
+ return SF_SUCCESS;
+
+ sf_hal_gpio_init(SF_HAL_LED_STATUS_G,GPIO_DIR_OUT);
+
+ sf_hal_gpio_init(SF_HAL_LED_SD_G,GPIO_DIR_OUT);
+ sf_hal_gpio_init(SF_HAL_LED_SD_R,GPIO_DIR_OUT);
+
+ sf_hal_gpio_init(SF_HAL_LED_BAT_G, GPIO_DIR_OUT);
+ sf_hal_gpio_init(SF_HAL_LED_BAT_R, GPIO_DIR_OUT);
+
+ sf_hal_gpio_init(SF_HAL_LED_SIG1_G,GPIO_DIR_OUT);
+ sf_hal_gpio_init(SF_HAL_LED_SIG1_R,GPIO_DIR_OUT);
+
+ sf_hal_gpio_init(SF_HAL_LED_USERBIND_G,GPIO_DIR_OUT);
+ sf_hal_gpio_init(SF_HAL_LED_USERBIND_R,GPIO_DIR_OUT);
+
+ sf_hal_gpio_init(GPIOID_PIR_TEST, GPIO_DIR_IN);
+// sf_hal_gpio_init(GPIOID_SIM_INSRET, GPIO_DIR_IN);
+// sf_hal_gpio_init(GPIOID_USB_INSERT, GPIO_DIR_IN);
+
+ SINT8 halvalue = 0;
+ SF_MUTEX_LOCK(GPIO_mutexLock);
+ sf_hal_gpio_init(SF_KEY_PIN_SYNC,GPIO_DIR_IN);
+ sf_hal_gpio_get(SF_KEY_PIN_SYNC,&halvalue);
+ sf_hal_gpio_deinit(SF_KEY_PIN_SYNC);
+ SF_MUTEX_UNLOCK(GPIO_mutexLock);
+ MLOGI("halvalue: %d\n",halvalue);
+ if(halvalue == 0)
+ return SF_SUCCESS;
+
+ SF_MESSAGE_BUF_S stMessageBuf = {0};
+ stMessageBuf.cmdId = CMD_LED;
+ stMessageBuf.arg1 = LED_STATUS_HOLD_ON;
+ stMessageBuf.arg2 = LED_GROUP_STATUS;
+ stMessageBuf.arg3 = LED_TYPE_GREEN;
+ sf_com_message_send_to_app(&stMessageBuf);
+
+ return SF_SUCCESS;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/source/app/sf_test.c b/code/application/source/sf_app/code/source/app/sf_test.c
deleted file mode 100755
index d344b95ac..000000000
--- a/code/application/source/sf_app/code/source/app/sf_test.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * app2.c
- *
- * Created on: 2023年4月7日
- * Author: NVT02970
- */
-
-#include
-#include
-
-int sfmain(int argc, char *argv[])
-{
- //gpio_direction_input(C_GPIO(10));
-
-
-
-}
-
-
-
-
-
-
diff --git a/code/application/source/sf_app/code/source/app/sf_test.o b/code/application/source/sf_app/code/source/app/sf_test.o
deleted file mode 100644
index 10dc23155..000000000
Binary files a/code/application/source/sf_app/code/source/app/sf_test.o and /dev/null differ
diff --git a/code/application/source/sf_app/code/source/commMng/sf_message_queue.c b/code/application/source/sf_app/code/source/commMng/sf_message_queue.c
new file mode 100755
index 000000000..58ca4b15d
--- /dev/null
+++ b/code/application/source/sf_app/code/source/commMng/sf_message_queue.c
@@ -0,0 +1,113 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include "sf_log.h"
+#include "sf_type.h"
+#include "sf_param_common.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+
+int sf_msgQueueId = -1;
+int cardv_msgQueueId = -1;
+
+
+
+
+static SINT32 message_queue_send(SINT32 MsgQueueId,SF_MESSAGE_BUF_S *pMessageBuf)
+{
+
+
+ size_t msgsz = sizeof(pMessageBuf->cmdId) + sizeof(pMessageBuf->s32Wait) + sizeof(pMessageBuf->arg1) + sizeof(pMessageBuf->arg2)+ sizeof(pMessageBuf->arg3);
+ if(msgsnd(MsgQueueId, pMessageBuf, msgsz, 0) == -1)
+ {
+ return SF_FAILURE;
+ }
+
+ return SF_SUCCESS;
+}
+static SINT32 message_queue_recv(SINT32 MsgQueueId,SF_MESSAGE_BUF_S *pMessageBuf)
+{
+
+ size_t msgsz = sizeof(pMessageBuf->cmdId) + sizeof(pMessageBuf->s32Wait) + sizeof(pMessageBuf->arg1) + sizeof(pMessageBuf->arg2)+ sizeof(pMessageBuf->arg3);
+
+ if(msgrcv(MsgQueueId, pMessageBuf, msgsz,0,IPC_NOWAIT) == -1)
+ {
+ return SF_FAILURE;
+ }
+
+ return SF_SUCCESS;
+}
+static SINT32 message_queue_create(SF_CHAR *pathname,SINT32 *pMsgQueueId)
+{
+ key_t key;
+ SF_CHAR touchPath[128] = {0};
+ if(access(pathname, F_OK) != 0)
+ {
+ sprintf(touchPath, "%s %s","touch",pathname);
+ system(touchPath);
+ }
+ if((key = ftok(pathname,'z')) < 0)
+ {
+ MLOGI("ftok error");
+ return SF_FAILURE;
+ }
+ if ((*pMsgQueueId = msgget(key, IPC_CREAT | 0660)) == -1)
+ {
+ MLOGI("MsgQueueId = %#x\n",*pMsgQueueId);
+ MLOGI("msgget failed errno.%02d is: %s\n", errno, strerror(errno));
+ return SF_FAILURE;
+ }
+ MLOGI("MsgQueueId = %#x\n",*pMsgQueueId);
+ return SF_SUCCESS;
+}
+
+SINT32 sf_com_message_app_init(void)
+{
+ return message_queue_create((char*)"/tmp/sf_message",&sf_msgQueueId);
+}
+SINT32 sf_com_message_recv_from_app(SF_MESSAGE_BUF_S *pMessageBuf)
+{
+ return message_queue_recv(sf_msgQueueId,pMessageBuf);
+}
+
+SINT32 sf_com_message_send_to_app(SF_MESSAGE_BUF_S *pMessageBuf)
+{
+ pMessageBuf->mtype = 1;
+ return message_queue_send(sf_msgQueueId,pMessageBuf);
+}
+
+SINT32 sf_com_message_cardv_init(void)
+{
+ return message_queue_create((char*)"/tmp/cardv_message",&cardv_msgQueueId);
+}
+SINT32 sf_com_message_recv_from_cardv(SF_MESSAGE_BUF_S *pMessageBuf)
+{
+ return message_queue_recv(cardv_msgQueueId,pMessageBuf);
+}
+
+SINT32 sf_com_message_send_to_cardv(SF_MESSAGE_BUF_S *pMessageBuf)
+{
+ pMessageBuf->mtype = 1;
+ return message_queue_send(cardv_msgQueueId,pMessageBuf);
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
diff --git a/code/application/source/sf_app/code/source/commMng/sf_share_mem.c b/code/application/source/sf_app/code/source/commMng/sf_share_mem.c
new file mode 100755
index 000000000..eeda3b46f
--- /dev/null
+++ b/code/application/source/sf_app/code/source/commMng/sf_share_mem.c
@@ -0,0 +1,218 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+#include "sf_log.h"
+#include "sf_type.h"
+#include "sf_param_common.h"
+#include "sf_fileMng.h"
+
+int sf_semId = -1;
+int sf_sharMemId = -1;
+int sf_sharMemfileId = -1;
+
+union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short *array;
+ struct seminfo *__buf;
+};
+
+SINT32 sem_creat(SF_CHAR *pathname,SINT32 *psemid)
+{
+ SF_CHAR touchPath[128] = {0};
+ if(access(pathname, F_OK) != 0)
+ {
+ sprintf(touchPath, "%s %s","touch",pathname);
+ system(touchPath);
+ }
+ key_t key = ftok(pathname, 111);
+ if(key < 0)
+ {
+ perror("ftok");
+ return SF_FAILURE;
+ }
+
+ *psemid = semget(key, 1, IPC_CREAT|IPC_EXCL|0666);
+ if(*psemid < 0)
+ {
+ perror("semget");
+ return SF_FAILURE;
+ }
+
+ union semun un;
+ un.val = 1;
+ if(semctl(*psemid, 0, SETVAL, un)<0)
+ {
+ perror("semctl");
+ return SF_FAILURE;
+ }
+ return SF_SUCCESS;
+
+}
+SINT32 sem_check(SINT32 semid, SINT32 who, SINT32 op)
+{
+
+ struct sembuf sf;
+ sf.sem_num = who;
+ sf.sem_op = op;
+ sf.sem_flg = 0;
+
+ if(semop(semid, &sf, 1) < 0)
+ {
+ perror("semop");
+ return SF_FAILURE;
+ }
+ return SF_SUCCESS;
+}
+
+SINT32 sf_sem_init(SF_CHAR *pathname,SINT32 *psemid)
+{
+ return sem_creat(pathname,psemid);
+}
+
+SINT32 sf_sem_down(SINT32 semid, SINT32 who)
+{
+ return sem_check(semid, who, -1);
+}
+
+SINT32 sf_sem_up(SINT32 semid, SINT32 who)
+{
+ return sem_check(semid, who, 1);
+}
+SINT32 sf_sem_deinit(SINT32 semid)
+{
+ if(semctl(semid, 0, IPC_RMID) < 0)
+ {
+ perror("semctl");
+ return SF_FAILURE;
+ }
+ return SF_SUCCESS;
+}
+int share_mem_create(SF_CHAR *pathname,int size,SINT32 *pshmID)
+{
+ SF_CHAR touchPath[128] = {0};
+ if(access(pathname, F_OK) != 0)
+ {
+ sprintf(touchPath, "%s %s","touch",pathname);
+ system(touchPath);
+ }
+ key_t key = ftok(pathname, 111);
+ if(key < 0)
+ {
+ perror("ftok");
+ return SF_FAILURE;
+ }
+
+ *pshmID = shmget(key, size, IPC_CREAT|0666);
+ if(*pshmID == -1)
+ {
+ perror("shmget");
+ return SF_FAILURE;
+ }
+
+ return SF_SUCCESS;
+}
+
+int share_mem_destory(int shmID)
+{
+
+ if(shmctl(shmID, IPC_RMID, NULL) < 0 )
+ {
+ perror("shmctl");
+ return SF_FAILURE;
+ }
+
+ return SF_SUCCESS;
+}
+void* share_mem_get(int shmID)
+{
+ return shmat(shmID, NULL, 0);
+}
+SINT32 sf_share_mem_init(SF_CHAR *pathname,int size,SINT32 *pshmID)
+{
+ return share_mem_create(pathname,size,pshmID);
+}
+SINT32 sf_share_mem_deinit(SINT32 shmID)
+{
+ return share_mem_destory(shmID);
+}
+void* sf_share_mem_get(int shmID)
+{
+ return share_mem_get(shmID);
+}
+
+SINT32 sf_share_mem_file_init(void)
+{
+ SF_SRCFILE_ATTR_S *pThumbFileCfg = 0;
+ if(SF_SUCCESS == sf_share_mem_init((char*)"/tmp/sf_file",sizeof(SF_SRCFILE_ATTR_S),&sf_sharMemfileId))
+ {
+ pThumbFileCfg = (SF_SRCFILE_ATTR_S *)sf_share_mem_get(sf_sharMemfileId);
+ if(pThumbFileCfg <= 0)
+ {
+ MLOGI("creat share mem failed!!!\n");
+ return SF_FAILURE;
+ }
+ else
+ {
+ sf_file_thumb_cfg_set(pThumbFileCfg);
+ MLOGI("creat share mem succeed!!!\n");
+ return SF_SUCCESS;
+ }
+ }
+ return SF_FAILURE;
+}
+SINT32 sf_share_mem_customer_init(void)
+{
+ SF_PDT_PARAM_CFG_S *pSfCustomerPara = 0;
+ if(SF_SUCCESS == sf_share_mem_init((char*)"/tmp/sf_share",sizeof(SF_PDT_PARAM_CFG_S),&sf_sharMemId))
+ {
+ pSfCustomerPara = (SF_PDT_PARAM_CFG_S *)sf_share_mem_get(sf_sharMemId);
+ if(pSfCustomerPara <= 0)
+ {
+ MLOGI("creat share mem failed!!!\n");
+ return SF_FAILURE;
+ }
+ else
+ {
+ sf_customer_param_set(pSfCustomerPara);
+ MLOGI("creat share mem succeed!!!\n");
+ return SF_SUCCESS;
+ }
+
+ }
+ return SF_FAILURE;
+
+}
+SINT32 sf_share_mem_file_deinit(void)
+{
+ return sf_share_mem_deinit(sf_sharMemfileId);
+}
+
+SINT32 sf_share_mem_customer_deinit(void)
+{
+ return sf_share_mem_deinit(sf_sharMemId);
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
diff --git a/code/application/source/sf_app/code/source/dataMng/sf_dataMng.c b/code/application/source/sf_app/code/source/dataMng/sf_dataMng.c
new file mode 100755
index 000000000..bf149373d
--- /dev/null
+++ b/code/application/source/sf_app/code/source/dataMng/sf_dataMng.c
@@ -0,0 +1,352 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#if defined(CFG_TRANSDATA_AT)
+#include "sf_transdata1.h"
+#endif
+#include "sf_dataMng.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+SF_PARA_TIME_S rtcTime = {0};
+SF_CMD_QUERYPENDING_E PendingOrder = SF_QUERYPENDING_COMMAND_BUTT;
+UINT8 CanUpload = 0;
+UINT8 UploadMode = 0;
+UINT8 HasCommand = 0;
+UINT16 SubscribeRet = 0;
+
+
+static UINT8 auchCRCHi[256] = {
+0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x00, 0xC1, 0x81, 0x40,
+ 0x01, 0xC0, 0x80, 0x41, 0x01,
+ 0xC0, 0x80, 0x41, 0x00, 0xC1,
+ 0x81, 0x40, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x01,
+ 0xC0, 0x80, 0x41, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x00,
+ 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40, 0x00, 0xC1,
+ 0x81, 0x40, 0x01, 0xC0, 0x80,
+ 0x41, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x01,
+ 0xC0, 0x80, 0x41, 0x00, 0xC1,
+ 0x81, 0x40, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40, 0x00, 0xC1,
+ 0x81, 0x40, 0x01, 0xC0, 0x80,
+ 0x41, 0x00, 0xC1, 0x81, 0x40,
+ 0x01, 0xC0, 0x80, 0x41, 0x01,
+ 0xC0, 0x80, 0x41, 0x00, 0xC1,
+ 0x81, 0x40, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x00, 0xC1, 0x81, 0x40,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x01, 0xC0, 0x80,
+ 0x41, 0x00, 0xC1, 0x81, 0x40,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40, 0x00, 0xC1,
+ 0x81, 0x40, 0x01, 0xC0, 0x80,
+ 0x41, 0x01, 0xC0, 0x80, 0x41,
+ 0x00, 0xC1, 0x81, 0x40, 0x00,
+ 0xC1, 0x81, 0x40, 0x01, 0xC0,
+ 0x80, 0x41, 0x00, 0xC1, 0x81,
+ 0x40, 0x01, 0xC0, 0x80, 0x41,
+ 0x01, 0xC0, 0x80, 0x41, 0x00,
+ 0xC1, 0x81, 0x40 };
+
+static UINT8 auchCRCLo[256] = {
+0x00, 0xC0, 0xC1,
+ 0x01, 0xC3, 0x03, 0x02, 0xC2,
+ 0xC6, 0x06, 0x07, 0xC7, 0x05,
+ 0xC5, 0xC4, 0x04, 0xCC, 0x0C,
+ 0x0D, 0xCD, 0x0F, 0xCF, 0xCE,
+ 0x0E, 0x0A, 0xCA, 0xCB, 0x0B,
+ 0xC9, 0x09, 0x08, 0xC8, 0xD8,
+ 0x18, 0x19, 0xD9, 0x1B, 0xDB,
+ 0xDA, 0x1A, 0x1E, 0xDE, 0xDF,
+ 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
+ 0x14, 0xD4, 0xD5, 0x15, 0xD7,
+ 0x17, 0x16, 0xD6, 0xD2, 0x12,
+ 0x13, 0xD3, 0x11, 0xD1, 0xD0,
+ 0x10, 0xF0, 0x30, 0x31, 0xF1,
+ 0x33, 0xF3, 0xF2, 0x32, 0x36,
+ 0xF6, 0xF7, 0x37, 0xF5, 0x35,
+ 0x34, 0xF4, 0x3C, 0xFC, 0xFD,
+ 0x3D, 0xFF, 0x3F, 0x3E, 0xFE,
+ 0xFA, 0x3A, 0x3B, 0xFB, 0x39,
+ 0xF9, 0xF8, 0x38, 0x28, 0xE8,
+ 0xE9, 0x29, 0xEB, 0x2B, 0x2A,
+ 0xEA, 0xEE, 0x2E, 0x2F, 0xEF,
+ 0x2D, 0xED, 0xEC, 0x2C, 0xE4,
+ 0x24, 0x25, 0xE5, 0x27, 0xE7,
+ 0xE6, 0x26, 0x22, 0xE2, 0xE3,
+ 0x23, 0xE1, 0x21, 0x20, 0xE0,
+ 0xA0, 0x60, 0x61, 0xA1, 0x63,
+ 0xA3, 0xA2, 0x62, 0x66, 0xA6,
+ 0xA7, 0x67, 0xA5, 0x65, 0x64,
+ 0xA4, 0x6C, 0xAC, 0xAD, 0x6D,
+ 0xAF, 0x6F, 0x6E, 0xAE, 0xAA,
+ 0x6A, 0x6B, 0xAB, 0x69, 0xA9,
+ 0xA8, 0x68, 0x78, 0xB8, 0xB9,
+ 0x79, 0xBB, 0x7B, 0x7A, 0xBA,
+ 0xBE, 0x7E, 0x7F, 0xBF, 0x7D,
+ 0xBD, 0xBC, 0x7C, 0xB4, 0x74,
+ 0x75, 0xB5, 0x77, 0xB7, 0xB6,
+ 0x76, 0x72, 0xB2, 0xB3, 0x73,
+ 0xB1, 0x71, 0x70, 0xB0, 0x50,
+ 0x90, 0x91, 0x51, 0x93, 0x53,
+ 0x52, 0x92, 0x96, 0x56, 0x57,
+ 0x97, 0x55, 0x95, 0x94, 0x54,
+ 0x9C, 0x5C, 0x5D, 0x9D, 0x5F,
+ 0x9F, 0x9E, 0x5E, 0x5A, 0x9A,
+ 0x9B, 0x5B, 0x99, 0x59, 0x58,
+ 0x98, 0x88, 0x48, 0x49, 0x89,
+ 0x4B, 0x8B, 0x8A, 0x4A, 0x4E,
+ 0x8E, 0x8F, 0x4F, 0x8D, 0x4D,
+ 0x4C, 0x8C, 0x44, 0x84, 0x85,
+ 0x45, 0x87, 0x47, 0x46, 0x86,
+ 0x82, 0x42, 0x43, 0x83, 0x41,
+ 0x81, 0x80, 0x40 };
+
+
+
+ UINT16 crcCheck( UINT8 strContent[],UINT16 usDataLen,UINT16 crc)
+{
+ UINT16 uIndex;
+
+ UINT8 uchCRCHi = 0xFF;
+ UINT8 uchCRCLo = 0xFF;
+ UINT16 i = 0;
+ UINT16 value=0;
+
+ for (i = 0; i < usDataLen; i++) {
+ uIndex = (uchCRCHi ^ strContent[i]) & 0xff;
+
+ uchCRCHi = (uchCRCLo ^ auchCRCHi[uIndex]);
+ uchCRCLo = auchCRCLo[uIndex];
+ }
+
+ value = ((((UINT16) uchCRCHi) << 8 | (((UINT16) uchCRCLo) & 0xff))) & 0xffff;
+
+ if (crc == value) {
+ return 0;
+ } else {
+ return 1;
+ }
+
+}
+
+UINT16 makeCrc(UINT8 strContent[], UINT16 len)
+{
+ UINT16 uIndex;
+ UINT16 usDataLen = len;
+
+ UINT8 uchCRCHi = 0xFF;
+ UINT8 uchCRCLo = 0xFF;
+ UINT16 value=0;
+ UINT16 i = 0;
+ for (i = 0; i < usDataLen; i++) {
+ uIndex = (uchCRCHi ^ strContent[i]) & 0xff;
+
+ uchCRCHi = (uchCRCLo ^ auchCRCHi[uIndex]);
+ uchCRCLo = auchCRCLo[uIndex];
+ }
+ value = ((((UINT16) uchCRCHi) << 8 | (((UINT16) uchCRCLo) & 0xff))) & 0xffff;
+ return value;
+}
+
+void sf_data_subscribe_result_set(UINT16 ret)
+{
+ if(ret == SF_SUCCESS)
+ SubscribeRet = 0;
+// else if(ret == SF_TCP_ERROR_SUBSCRIBE_NO_FILE)
+// SubscribeRet = 2;
+ else
+ SubscribeRet = 1;
+}
+
+SF_PARA_TIME_S* sf_server_time_get(void)
+{
+ return &rtcTime;
+}
+
+
+UINT8 sf_data_has_command_get(void)
+{
+ return HasCommand;
+}
+UINT8 sf_data_transfer_mode_get(void)
+{
+ return UploadMode;
+}
+SINT32 sf_data_cam_local_time_get(SF_PARA_TIME_S* pstdata)
+{
+ memcpy(pstdata,&rtcTime,sizeof(SF_PARA_TIME_S));
+ return SF_SUCCESS;
+}
+UINT32 sf_data_pendingcmd_get(void)
+{
+ return PendingOrder;
+}
+SINT32 sf_data_grouping_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_login(pstdata,pfnParam);
+ #else
+ return sf_net_packetgrouping_login(pstdata,pfnParam);
+ #endif
+}
+SINT32 sf_data_grouping_fileresult(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam,SF_VOID *pstfileAttr)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_fileresult(pstdata,(SF_PDT_PARAM_CFG_S*)pfnParam->pstParam,pstfileAttr);
+ #else
+ return sf_net_packetgrouping_fileresult(pstdata,(SF_PDT_PARAM_STATISTICS_S*)pfnParam->pstaticParam,(SF_REPORT_FILE_ATTR_S*)pstfileAttr);
+ #endif
+}
+SINT32 sf_data_grouping_disconnection(SF_DATA_ATTR_S *pstdata,SF_VOID *Param)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_disconnection(pstdata,Param);
+ #else
+ //acm http need tcp alive
+ return sf_net_packetgrouping_disconnection(pstdata,Param);
+ #endif
+}
+SINT32 sf_data_grouping_query_cmd(SF_DATA_ATTR_S *pstdata)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_query_cmd(pstdata);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_grouping_query_cmd_param(SF_DATA_ATTR_S *pstdata)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_query_cmd_param(pstdata);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_grouping_cmd_report(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam, SF_FILE_ATTR_S *pstfileAttr)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_cmd_report(pstdata,pfnParam,pstfileAttr);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_grouping_get_bind_account(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetgrouping_get_bind_account(pstdata,pfnParam);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_grouping_sync_cfg(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return SF_SUCCESS;
+ #else
+ return sf_net_packetgrouping_sync(pstdata,pfnParam);
+ #endif
+}
+
+SINT32 sf_data_analysis_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_login(pstdata,pfnParam);
+ #else
+ return sf_net_packetanalysis_login(pstdata,pfnParam);
+ #endif
+}
+SINT32 sf_data_analysis_fileresult(SF_DATA_ATTR_S *pstdata)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_fileresult(pstdata);
+ #else
+ return sf_net_packetanalysis_fileresult(pstdata);
+ #endif
+}
+SINT32 sf_data_analysis_query_cmd(SF_DATA_ATTR_S *pstdata)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_query_cmd(pstdata);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_analysis_query_cmd_param(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_query_cmd_param(pstdata,pfnParam);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_analysis_cmd_report(SF_DATA_ATTR_S *pstdata)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_cmd_report(pstdata);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_analysis_bind_account(SF_DATA_ATTR_S *pstdata,SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_bind_account(pstdata,pfnParam);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_analysis_trigger(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return sf_packetanalysis_trigger(pstdata,pfnParam);
+ #else
+ return SF_SUCCESS;
+ #endif
+}
+SINT32 sf_data_analysis_sync_cfg(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ #if defined(CFG_TRANSDATA_AT)
+ return SF_SUCCESS;
+ #else
+ return sf_net_packetanalysis_sync(pstdata,pfnParam);
+ #endif
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/source/dataMng/sf_datahttp.c b/code/application/source/sf_app/code/source/dataMng/sf_datahttp.c
new file mode 100755
index 000000000..af1dc57bd
--- /dev/null
+++ b/code/application/source/sf_app/code/source/dataMng/sf_datahttp.c
@@ -0,0 +1,1403 @@
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "sf_type.h"
+#include "sf_log.h"
+
+#include "cJSON.h"
+#include "sf_module.h"
+
+#include "sf_storeMng.h"
+#include "sf_dev_other.h"
+
+#include "sf_systemMng.h"
+#include "sf_dataMng.h"
+#include "sf_commu_mcu_reg.h"
+#include "sf_datahttp.h"
+#include
+#include
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+extern UINT8 UploadMode;
+extern SF_PARA_TIME_S rtcTime;
+
+ LOGIN_ACM_RESPONSE_S stLoginAcmResponse = { 0 };//login_acm_response
+
+ SF_REPORT_FILE_ATTR_S stSubReportFileAttr = { 0 };
+ SF_REPORT_FILE_ATTR_S stThmReportFileAttr = { 0 };
+
+
+ static SINT32 packet_log_printf(UINT8 *pbuf,UINT16 lenth)
+{
+ UINT16 i= 0;
+ for(i = 0;i < lenth;i++)
+ {
+ if(i%5 == 0)
+ printf("[%02d,%02d] = {",i,((lenth - i) < 5)?(lenth-1):(i+4));
+
+ if((i+1)%5 == 0 || (i+1) == lenth)
+ printf("0x%02x}\n",*pbuf++);
+ else
+ printf("0x%02x,",*pbuf++);
+ }
+ return SF_SUCCESS;
+
+}
+ static SINT32 packet_gps_parse(char *pstring,SF_PDT_PARAM_STATISTICS_S *pStaticParam)
+{
+ *pstring++ = pStaticParam->Latitude[9];
+ *pstring++ = pStaticParam->Latitude[0];
+ *pstring++ = pStaticParam->Latitude[1];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Latitude[2];
+ *pstring++ = pStaticParam->Latitude[3];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Latitude[5];
+ *pstring++ = pStaticParam->Latitude[6];
+ *pstring++ = '-';
+
+ *pstring++ = pStaticParam->Longitude[10];
+ *pstring++ = pStaticParam->Longitude[0];
+ *pstring++ = pStaticParam->Longitude[1];
+ *pstring++ = pStaticParam->Longitude[2];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Longitude[3];
+ *pstring++ = pStaticParam->Longitude[4];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Longitude[6];
+ *pstring++ = pStaticParam->Longitude[7];
+ *pstring++ = '\0';
+
+// *pstring++ = 'N';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '-';
+
+// *pstring++ = 'E';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '\0';
+ return SF_SUCCESS;
+}
+ static SINT32 debug_remotecontrol_packet( SF_PDT_PARAM_CFG_S *pstparam)
+ {
+ if(pstparam->GprsMode == 0)
+ {
+ pstparam->DailyReportswitch = 0;
+ pstparam->DailyReportTime.Hour = 24;
+ pstparam->DailyReportTime.Min = 0;
+ }
+ else if(pstparam->GprsMode == 1)
+ {
+ pstparam->DailyReportswitch = 0;
+ pstparam->DailyReportTime.Hour = 0;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 2)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 0;
+ pstparam->DailyReportTime.Min = 30;
+
+ }
+ else if(pstparam->GprsMode == 3)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 1;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 4)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 2;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 5)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 3;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 6)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 4;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 7)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 6;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 8)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 12;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 9)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 24;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ return SF_SUCCESS;
+ }
+
+ LOGIN_ACM_RESPONSE_S* sf_get_login_reponse(void)
+ {
+ return &stLoginAcmResponse;
+ }
+
+ SF_REPORT_FILE_ATTR_S* sf_get_sub_report_file_attr(void)
+ {
+ return &stSubReportFileAttr;
+ }
+
+ SF_REPORT_FILE_ATTR_S* sf_get_thm_report_file_attr(void)
+ {
+ return &stThmReportFileAttr;
+ }
+
+ static SINT32 data_error_collection(UINT32 valueint)
+ {
+ switch(valueint)
+ {
+ case SF_SYS_ERR:
+ SLOGE("SF_SYS_ERR\n");
+ break;
+ case SF_PARA_ERR:
+ SLOGE("SF_PARA_ERR\n");
+ break;
+ case SF_DEV_NOT_EXIST:
+ SLOGE("SF_DEV_NOT_EXIST\n");
+ break;
+ case SF_USER_NOT_EXIST:
+ SLOGE("SF_USER_NOT_EXIST\n");
+ break;
+ case SF_SIM_NOT_EXIST:
+ SLOGE("SF_SIM_NOT_EXIST\n");
+ break;
+ case SF_SIM_NET_NOT_TURN_ON:
+ SLOGE("SF_SIM_NET_NOT_TURN_ON\n");
+ break;
+ case SF_SIM_DEV_NOT_BIND:
+ SLOGE("SF_SIM_DEV_NOT_BIND\n");
+ break;
+ default:
+ SLOGE("undefined error\n!!!");
+ break;
+ }
+ return SF_SUCCESS;
+}
+
+ int sf_http_decrypt(char* src, char* dst, int len)
+ {
+ #define MBEDTLS_CIPHER_AES_128_CBC 5
+ #define MBEDTLS_DECRYPT 0
+
+ char buf[256] = {0};
+ UINT8 datalen = 0;
+
+ datalen = sf_base64_decode(src, buf);
+
+ datalen = sf_cipher(MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_DECRYPT, (UINT8 *)buf, (UINT8 *)dst, datalen);
+
+ return datalen;
+
+ }
+
+ static SINT32 http_response_status_code(char *data)
+ {
+ char *p = NULL;
+ char ack[3] = {0};
+
+ p = strstr(data, "HTTP/1.1");
+ memcpy(ack, p+9, 3);
+ switch(atoi(ack)/100)
+ {
+ case 1:
+ MLOGI(">>>information corresponding\n");
+ return SF_SUCCESS;
+
+ case 2:
+ MLOGI(">>>successful response\n");
+ return SF_SUCCESS;
+
+ case 3:
+ MLOGI(">>>redirect message\n");
+ return SF_SUCCESS;
+
+ case 4:
+ MLOGE(">>>Client error response\n");
+ return SF_FAILURE;
+
+ case 5:
+ MLOGE(">>>server error response\n");
+ return SF_FAILURE;
+
+ default:
+ MLOGE(">>>undefined error response\n");
+ return SF_FAILURE;
+
+ }
+
+ return SF_SUCCESS;
+ }
+
+ int isleap(int year)
+ {
+ return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
+ }
+
+ int get_yeardays(int year)
+ {
+ if (isleap(year))
+ return 366;
+ return 365;
+ }
+
+
+ void split_year_day_std(int days, int *year, int *day)
+ {
+ int curr_day = get_yeardays(*year=1970);
+ while (days >= curr_day)
+ {
+ days -= curr_day;
+ *year += 1;
+ curr_day = get_yeardays(*year);
+ }
+ *day = days;
+ }
+ void get_subtime(int sec_in_day, SF_PARA_TIME_S *tmx)
+ {
+ tmx->Hour = sec_in_day/(60*60);
+ tmx->Min = sec_in_day%(60*60)/60;
+ tmx->Sec = sec_in_day%60;
+ }
+ void get_monthday(int day, int is_leap, SF_PARA_TIME_S *tmx)
+ {
+ int i, mons[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ if (is_leap) mons[1] += 1;
+ for (i = 0; i < 12; ++i)
+ {
+ if (day < mons[i])
+ {
+ tmx->Mon = i+1;
+ tmx->Day = day+1;
+ return;
+ }
+ day -= mons[i];
+ }
+ }
+
+ void sf_get_date(UINT32 second, SF_PARA_TIME_S *ptmx)
+ {
+ SF_PARA_TIME_S tmx;
+
+ split_year_day_std(second/86400, (int*)&tmx.Year, (int*)&tmx.Day);
+ get_monthday(tmx.Day, isleap(tmx.Year), &tmx);
+ get_subtime(second%86400,&tmx);
+
+ printf("-----After------%04d/%02d/%02d %02d:%02d:%02d-------------------------------------\n",
+ tmx.Year, tmx.Mon, tmx.Day, tmx.Hour, tmx.Min, tmx.Sec);
+ ptmx->Year = tmx.Year;
+ ptmx->Mon = tmx.Mon;
+ ptmx->Day = tmx.Day;
+ ptmx->Hour = tmx.Hour;
+ ptmx->Min = tmx.Min;
+ ptmx->Sec = tmx.Sec;
+
+ }
+
+
+ UINT32 sf_get_seconds(SF_PARA_TIME_S rtc)
+ {
+ UINT32 res = 0;
+
+ UINT32 tempYear = rtc.Year;
+ UINT32 tempMon = rtc.Mon;
+ UINT32 tempDay = rtc.Day;
+ UINT32 tempHour = rtc.Hour;
+ UINT32 tempMin = rtc.Min;
+ UINT32 tempSec = rtc.Sec;
+
+
+ if(tempMon <= 2)
+ {
+ tempMon += 10;
+ tempYear -= 1;
+ }
+ else
+ {
+ tempMon -=2;
+ }
+
+ /*printf("----32 gprs_getSeconds---------%d/%d/%d %d:%d%d---------------------------------------\n", rtc.tmx_Year, rtc.tmx_mon, rtc.tmx_mday, rtc.tmx_hour, rtc.tmx_min, rtc.tmx_sec);*/
+
+ res = (UINT32)(tempYear/4 -tempYear/100 + tempYear/400) + 367*tempMon/12 + tempDay + tempYear * 365 -719499;
+
+ /*printf("----32 gprs_getSeconds---------res:%x----------%ld-----------------------------\n", res, res);*/
+
+ res = ((res*24 + tempHour) * 60 + tempMin)*60 + tempSec;
+
+ /*printf("-64 ---gprs_getSeconds---------res:%x----------%ld-----------------------------\n", res, res);*/
+ return res;
+
+ }
+
+ SINT32 sf_net_packetgrouping_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+
+{
+ UINT8 signalLevel = 0;
+ SF_CHAR mcuVer[16]={0};
+ SF_CHAR ver[24] = { 0 };
+ cJSON *usr ;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ SF_STORE_ATTR_S storeattrs;
+ sf_sd_info_get(&storeattrs);
+ if(storeattrs.SDStatus != 0)
+ {
+ storeattrs.SDTotalSize = 0;
+ storeattrs.SDFree = 0;
+ }
+ memset(pstdata->databuf, '\0', sizeof(pstdata->databuf));
+ sf_sys_software_version_get(ver);
+ sprintf(mcuVer, "%d.%d.%d", (sf_get_mcu_ver() & 0xff00) >> 8, sf_get_mcu_ver() & 0x00ff, sf_get_mcu_sub_ver());
+
+ sf_4G_signal_level_get(pStaticParam->netGeneration,pStaticParam->SimSignal,&signalLevel);
+ if(signalLevel == 4)
+ signalLevel = 31;
+ else if(signalLevel == 3)
+ signalLevel = 13;
+ else if(signalLevel == 2)
+ signalLevel = 7;
+
+ usr=cJSON_CreateObject();
+
+ cJSON_AddStringToObject(usr, "imei", pStaticParam->IMEI);
+ cJSON_AddStringToObject(usr, "iccid", pStaticParam->SimID);
+ cJSON_AddNumberToObject(usr, "loginType", sf_poweron_type_get());
+ cJSON_AddStringToObject(usr, "sfVersion", ver);
+ cJSON_AddStringToObject(usr, "fwVersion", pStaticParam->ModuleSubversion);
+ cJSON_AddStringToObject(usr, "mcuVersion", mcuVer);
+ cJSON_AddStringToObject(usr, "carriers", pStaticParam->ServiceProvider);
+
+ cJSON_AddNumberToObject(usr, "sdcapacity", storeattrs.SDTotalSize);
+ cJSON_AddNumberToObject(usr, "sdfree", storeattrs.SDFree);
+ cJSON_AddNumberToObject(usr, "sdPic", pStaticParam->SdTotalFile);
+
+ cJSON_AddNumberToObject(usr, "signalStrength", signalLevel);
+ cJSON_AddNumberToObject(usr, "fahrenheit", pStaticParam->FcTemper-22);
+ cJSON_AddNumberToObject(usr, "battery", pStaticParam->BatRemainCap);
+
+ char *out = cJSON_Print(usr);
+
+ sprintf((char*)pstdata->databuf, "POST /AcmService/acmhttp/v1/devLogin"
+ " HTTP/1.1\r\n"
+ "Host:%s\r\n"
+ "Connection: keep-alive\r\n"
+ "Content-Length: %d\r\n"
+ "Content-Type: application/json\r\n\r\n"
+ "%s",pStaticParam->AcmIP,strlen(out),out);
+ free(out);
+ cJSON_Delete(usr);
+ pstdata->dataSize = strlen((const char*)pstdata->databuf);
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("send_buff:%d byte\n***********************\n%s\n", pstdata->dataSize, pstdata->databuf);
+ #endif
+ return SF_SUCCESS;
+
+ }
+
+ SINT32 sf_net_packetgrouping_fileresult(SF_DATA_ATTR_S *pstdata, SF_PDT_PARAM_STATISTICS_S *pStaticParam,SF_REPORT_FILE_ATTR_S *pstfileAttr)
+ {
+ SINT32 ret = 0;
+ //SINT32 totalFileNum = 0;
+ //UINT32 pSDFree= 0, pSDTotalSize = 0;
+ // SINT32 fahrenheit = 0;
+ //UINT8 loginType = 1;
+ SF_CHAR ver[24] = { 0 };
+ SINT16 i = 0;
+ char *msg = NULL;
+ memset(pstdata->databuf, '\0', sizeof(pstdata->databuf));
+ cJSON *jsonArray = cJSON_CreateArray();
+ for(i = 0; i < pstfileAttr->filecnt; i++)
+ {
+ cJSON *ArrayItem0 = cJSON_CreateObject();
+ cJSON_AddStringToObject(ArrayItem0,"imei", pStaticParam->IMEI);
+ cJSON_AddNumberToObject(ArrayItem0,"uploadType", 2);
+ cJSON_AddNumberToObject(ArrayItem0,"type", pstfileAttr->stSendFileAttr[i].enFileTye);
+ cJSON_AddNumberToObject(ArrayItem0,"fileSize", pstfileAttr->stSendFileAttr[i].SendFileSize);
+ cJSON_AddStringToObject(ArrayItem0,"data", pstfileAttr->stSendFileAttr[i].SendFileName);
+ cJSON_AddStringToObject(ArrayItem0,"bindFile", pstfileAttr->stSendFileAttr[i].SubFileName);
+ cJSON_AddNumberToObject(ArrayItem0,"code", pstfileAttr->stSendFileAttr[i].SendRet);
+ cJSON_AddNumberToObject(ArrayItem0,"did", pStaticParam->Did);
+
+ //cJSON_AddNumberToObject(ArrayItem0, "dayNight", 1);
+ //cJSON_AddNumberToObject(ArrayItem0, "fahrenheit", fahrenheit);
+ //cJSON_AddNumberToObject(ArrayItem0, "phases", 1);
+ //cJSON_AddNumberToObject(ArrayItem0, "loginType", loginType);
+
+ cJSON_AddItemToArray(jsonArray,ArrayItem0);
+ }
+
+// cJSON *root = cJSON_CreateObject();
+ sf_sys_software_version_get(ver);
+// cJSON_AddStringToObject(root, "sfVersion", ver);
+// cJSON_AddItemToObject( root, "fileResultDTOList", jsonArray);
+//
+ msg = cJSON_Print(jsonArray);
+ cJSON_Delete(jsonArray);
+
+ SF_STORE_ATTR_S storeattrs;
+ sf_sd_info_get(&storeattrs);
+ if(storeattrs.SDStatus != 0)
+ {
+ storeattrs.SDTotalSize = 0;
+ storeattrs.SDFree = 0;
+ }
+
+ sprintf((char*)pstdata->databuf, "POST /AcmService/acmhttp/v1/fileResultReport?"
+ "sdcapacity=%d"
+ "&sdfree=%d"
+ "&sdPic=%d"
+ "&fahrenheit=%d"
+ "&sfVersion=%s"
+ "&signalStrength=%d"
+ "&battery=%d"
+ " HTTP/1.1\r\n"
+ "Host:%s\r\n"
+ "token:%s\r\n"
+ "Connection: keep-alive\r\n"
+ "Content-Length: %d\r\n"
+ "Content-Type: application/json\r\n\r\n"
+ "%s",
+ storeattrs.SDTotalSize,\
+ storeattrs.SDFree, \
+ pStaticParam->SdTotalFile, \
+ pStaticParam->FcTemper-22, \
+ ver, \
+ pStaticParam->SimSignal, \
+ pStaticParam->BatRemainCap,\
+ pStaticParam->AcmIP,\
+ pStaticParam->Token,\
+ strlen(msg),\
+ msg);
+ free(msg);
+ pstdata->dataSize = strlen((const char *)pstdata->databuf);
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("send_buff:%d byte\n***********************\n%s\n", pstdata->dataSize, pstdata->databuf);
+ #endif
+ return ret;
+ }
+ SINT32 sf_net_packetgrouping_sync(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+ {
+ //UINT16 param = 0;
+ SF_CHAR time[16] = {0};
+ //SF_CHAR workTimerWeekStr[10] = {0};
+ //SF_CHAR gpsStr[32] = {0};
+ cJSON *root = NULL;
+
+ memset(pstdata->databuf, '\0', sizeof(pstdata->databuf));
+ SF_PDT_PARAM_CFG_S *pstparam = pfnParam->pstParam;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ root = cJSON_CreateObject();
+
+ cJSON_AddNumberToObject(root, "did", pStaticParam->Did);
+ cJSON_AddNumberToObject(root, "batteryType", pstparam->BatteryType);
+ cJSON_AddNumberToObject(root, "video", pstparam->CamMode+1);
+ cJSON_AddNumberToObject(root, "ledNumber", pstparam->FlashLed);
+ cJSON_AddNumberToObject(root, "sdcycleFlag", pstparam->SdLoop);
+ cJSON_AddNumberToObject(root, "pirswitch", pstparam->PirSwitch);
+ cJSON_AddNumberToObject(root, "stamp", pstparam->StampSwitch);
+ cJSON_AddNumberToObject(root, "image", pstparam->ImgSize);
+ cJSON_AddNumberToObject(root, "multishot", pstparam->Multishot);
+ cJSON_AddNumberToObject(root, "sdFormat", sf_get_login_reponse()->sdFormatCommand);
+ cJSON_AddNumberToObject(root, "devResetCommand", sf_get_login_reponse()->devResetCommand);
+
+ /*0:1080P, 1:720P, 2:480P*/
+ cJSON_AddNumberToObject(root, "videoSize", pstparam->VideoSize+1);
+ if(pstparam->VideoSize == SF_VIDEO_SIZE_1080)
+ pstparam->VideoLenth = 10;
+ else if(pstparam->VideoSize == SF_VIDEO_SIZE_720)
+ pstparam->VideoLenth = 20;
+ else if(pstparam->VideoSize == SF_VIDEO_SIZE_WVGA)
+ pstparam->VideoLenth = 30;
+
+ cJSON_AddNumberToObject(root, "videoLength", pstparam->VideoLenth);
+ cJSON_AddNumberToObject(root, "pirsentivity", pstparam->DigitPirSensitivity);
+
+ memset(time, 0, sizeof(time));
+ cJSON_AddNumberToObject(root, "delayFlag", pstparam->PirDelaySwitch);
+ sprintf(time, "%02d%02d%02d", pstparam->PirDelayTime.Hour, pstparam->PirDelayTime.Min, pstparam->PirDelayTime.Sec);
+ cJSON_AddStringToObject(root, "delayValue", time);
+
+ memset(time, 0, sizeof(time));
+ cJSON_AddNumberToObject(root, "timelapseFlag", pstparam->TimelapseSwitch);
+ sprintf(time, "%02d%02d%02d", pstparam->TimelapseTime.Hour, pstparam->TimelapseTime.Min, pstparam->TimelapseTime.Sec);
+ cJSON_AddStringToObject(root, "timelapseValue", time);
+
+ memset(time, 0, sizeof(time));
+ cJSON_AddNumberToObject(root, "timerFlag", pstparam->WorkTime1Switch);
+ sprintf(time, "%02d%02d-%02d%02d", pstparam->WorkTime[0].StartTime.Hour, pstparam->WorkTime[0].StartTime.Min, pstparam->WorkTime[0].StopTime.Hour, pstparam->WorkTime[0].StopTime.Min);
+ cJSON_AddStringToObject(root, "timerValue", time);
+
+ memset(time, 0, sizeof(time));
+ cJSON_AddNumberToObject(root, "timerFlag2", pstparam->WorkTime2Switch);
+ sprintf(time, "%02d%02d-%02d%02d", pstparam->WorkTime[1].StartTime.Hour, pstparam->WorkTime[1].StartTime.Min, pstparam->WorkTime[1].StopTime.Hour, pstparam->WorkTime[1].StopTime.Min);
+ cJSON_AddStringToObject(root, "timerValue2", time);
+
+ #if 1
+ debug_remotecontrol_packet(pstparam);
+ #endif
+ char stringGPS[21] = {0};
+ packet_gps_parse(stringGPS,pStaticParam);
+ cJSON_AddNumberToObject(root, "gpsFlag", pstparam->GPSFlag);
+ cJSON_AddStringToObject(root, "gps", stringGPS);
+
+ cJSON_AddNumberToObject(root, "smsctrl", pstparam->GprsMode);
+
+ memset(time, 0, sizeof(time));
+ cJSON_AddNumberToObject(root, "dailyreportFlag", pstparam->DailyReportswitch);
+ sprintf(time, "%02d%02d", pstparam->DailyReportTime.Hour, pstparam->DailyReportTime.Min);
+ cJSON_AddStringToObject(root, "dailyreportValue", time);
+
+ char *devparam = cJSON_Print(root);
+
+ sprintf((char*)pstdata->databuf, "POST /AcmService/acmhttp/v1/syncConfig?modifyFlag=%d"
+ " HTTP/1.1\r\n"
+ "Host:%s\r\n"
+ "token:%s\r\n"
+ "Connection: keep-alive\r\n"
+ "Content-Length: %d\r\n"
+ "Content-Type: application/json\r\n\r\n"
+ "%s",
+ pstparam->ParaSync, \
+ pStaticParam->AcmIP,\
+ pStaticParam->Token,\
+ strlen(devparam),\
+ devparam);
+
+
+ free(devparam);
+ cJSON_Delete(root);
+ pstdata->dataSize = strlen((const char *)pstdata->databuf);
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("send_buff***********\n%s\n", pstdata->databuf);
+ #endif
+ return SF_SUCCESS;
+ }
+SINT32 sf_net_packetgrouping_disconnection(SF_DATA_ATTR_S *pstdata,SF_VOID *Param)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(Param,SF_FAILURE);
+
+ //UINT8 i=0;
+ UINT16 Crc=0;
+ UINT8 *pData = pstdata->databuf;
+ SF_PDT_PARAM_STATISTICS_S *sim_info_t2 = sf_statistics_param_get();
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+
+ *pData++ = 0; //ifver
+ *pData++ = 1; //ifver
+
+ *pData++ = 0; //len
+ *pData++ = 0x14; //len
+
+
+ /*********data***********/
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x19; //CMD
+
+ *pData++ = 17; //len
+ //16bytes imei
+ memset(pData, '\0', 16);
+ memcpy(pData, sim_info_t2->IMEI, strlen(sim_info_t2->IMEI));
+ pData += 16;
+ *pData++ = 1;
+
+ //CRC16
+ Crc = makeCrc(pstdata->databuf+2, pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+
+ return SF_SUCCESS;
+
+}
+ SINT32 sf_net_packetanalysis_login(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam)
+ {
+ char *p = NULL;
+ char * p1 = NULL;
+ char * p2 = NULL;
+ cJSON *json = NULL;
+ cJSON *first = NULL;
+ cJSON *second = NULL;
+ cJSON *subListItem = NULL;
+ SINT32 ret = SF_SUCCESS;
+ UINT16 index = 0;
+ UINT16 i = 0;
+ UINT16 declen = 0;
+ char buf[256] = {0};
+ //SF_CHAR decode_tempStr[128] = {0};
+ SF_PDT_PARAM_CFG_S* pSfParam = (SF_PDT_PARAM_CFG_S*)pfnParam->pstParam;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = sf_statistics_param_get();
+ SF_REPORT_FILE_ATTR_S *pSubReportFileAttr = sf_get_sub_report_file_attr();
+ SF_URL_S *urlCfg = sf_ota_url_get();
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("recv_buff: %d byte,\n%s\n",param->dataSize,param->databuf);
+ #endif
+ ret = http_response_status_code((char*)param->databuf);
+ if(ret == SF_FAILURE)
+ return SF_DATA_ERROR_REQUEST;
+
+ p = strchr((char*)param->databuf, '{');
+ json = cJSON_Parse(p);
+ if (!json)
+ {
+ MLOGE("Error before: [%s]\n",cJSON_GetErrorPtr());
+ cJSON_Delete(json);
+ return SF_DATA_ERROR_DATA_FORMAT;
+ }
+
+ first = cJSON_GetObjectItem(json, "code");
+ first = cJSON_GetObjectItem(json, "errCode");
+ printf("...errCode = %d\n", first->valueint);
+ pStaticParam->bindFlag = 1;
+ if(first->valueint != 0)
+ {
+ data_error_collection(first->valueint);
+
+ if(first->valueint == 10012 || first->valueint == 20013 || first->valueint == 20002)
+ {
+ pStaticParam->PicPlan = 0;
+ }
+
+ if(first->valueint == 20002 || first->valueint == 20011)
+ {
+ pStaticParam->bindFlag = 0;
+ }
+ cJSON_Delete(json);
+ return SF_FAILURE;
+ }
+
+ first = cJSON_GetObjectItem(json, "msg");
+ printf("...msg = %s\n", first->valuestring);
+ first = cJSON_GetObjectItem(json, "data");
+
+ second = cJSON_GetObjectItem(first, "serverIp");
+ if(second->valuestring != NULL){
+ memcpy(pStaticParam->AcmIP, second->valuestring, strlen(second->valuestring));
+ cJSON_Delete(json);
+ return SF_DATA_ERROR_IP_CHANGE;
+ }
+
+ second = cJSON_GetObjectItem(first, "devResetCommand");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.devResetCommand = second->valueint;
+ printf(".devResetCommand = %d\n", stLoginAcmResponse.devResetCommand);
+ }
+
+ second = cJSON_GetObjectItem(first, "did");
+ if(second != NULL)
+ {
+ pStaticParam->Did = second->valueint;
+ //printf(".did = %d\n", stLoginAcmResponse.did);
+ }
+
+ second = cJSON_GetObjectItem(first, "downloadUrl");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.downloadUrl, '\0', sizeof(stLoginAcmResponse.downloadUrl));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.downloadUrl, buf, declen);
+ memcpy(urlCfg->url, stLoginAcmResponse.downloadUrl, sizeof(stLoginAcmResponse.downloadUrl));
+ printf(".downloadUrl = %s\n", stLoginAcmResponse.downloadUrl);
+ }
+
+ second = cJSON_GetObjectItem(first, "dateFormat");
+ if(second != NULL)
+ {
+ //printf("...pStaticParam->DateStyle = %d\n", pSfParam->DateStyle);
+ pSfParam->DateStyle = second->valueint;
+ }
+
+
+ second = cJSON_GetObjectItem(first, "hdCommand");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.hdCommand = second->valueint;
+ printf(".hdCommand = %d\n", stLoginAcmResponse.hdCommand);
+ }
+
+ //sub hd pic
+ if((stLoginAcmResponse.hdCommand > 0) && (stLoginAcmResponse.hdCommand < 100))
+ {
+ second = cJSON_GetObjectItem(first, "hdPhototVOList");
+ i = pSubReportFileAttr->filecnt;
+ for(index = 0; index < stLoginAcmResponse.hdCommand; index++)
+ {
+ subListItem = cJSON_GetArrayItem(second, index);
+
+// if(cJSON_GetObjectItem(subListItem, "fileType")->valueSINT32 == 10)
+// {
+// stLoginAcmResponse.logCommand = 1;
+// if(stLoginAcmResponse.hdCommand == 1)
+// stLoginAcmResponse.hdCommand = 0;
+// }
+// else
+ {
+ pSubReportFileAttr->stSendFileAttr[i].enFileTye = cJSON_GetObjectItem(subListItem, "fileType")->valueSINT32;
+ sprintf(pSubReportFileAttr->stSendFileAttr[i].SubFileName, "%s", cJSON_GetObjectItem(subListItem, "fileName")->valuestring);
+ printf("enFileTye:%d, SubFileName:%s\n", pSubReportFileAttr->stSendFileAttr[i].enFileTye,
+ pSubReportFileAttr->stSendFileAttr[i].SubFileName);
+ i++;
+ pSubReportFileAttr->filecnt = i;
+ }
+ }
+ SLOGD("filecnt:%d\n", pSubReportFileAttr->filecnt);
+ }
+
+ second = cJSON_GetObjectItem(first, "ip");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.ip, '\0', sizeof(stLoginAcmResponse.ip));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.ip, buf, declen);
+ p1 = stLoginAcmResponse.ip;
+ p2 = strchr(stLoginAcmResponse.ip, ':');
+ pStaticParam->AlivePort = atoi(p2 + 1);
+ memcpy(pStaticParam->AliveIp, p1, p2 - p1);
+ printf("...acm ip is %s, port is %d\n", pStaticParam->AliveIp, pStaticParam->AlivePort);
+ }
+
+ second = cJSON_GetObjectItem(first, "name");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.name, '\0', sizeof(stLoginAcmResponse.name));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.name, buf, declen);
+ printf(".name = %s\n", stLoginAcmResponse.name);
+ }
+
+ second = cJSON_GetObjectItem(first, "offset");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.offset = second->valueint;
+ pSfParam->TimeZone = stLoginAcmResponse.offset/1000/3600;
+ printf(".TimeZone = %d\n", pSfParam->TimeZone);
+ }
+
+ second = cJSON_GetObjectItem(first, "otaCommand");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.otaCommand = second->valueint;
+ printf(".otaCommand = %d\n", stLoginAcmResponse.otaCommand);
+ }
+
+ second = cJSON_GetObjectItem(first, "passwd");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.passwd, '\0', sizeof(stLoginAcmResponse.passwd));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.passwd, buf, declen);
+ printf(".passwd = %s\n", stLoginAcmResponse.passwd);
+ }
+
+ second = cJSON_GetObjectItem(first, "port");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.port, '\0', sizeof(stLoginAcmResponse.port));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.port, buf, declen);
+ printf(".port = %s\n", stLoginAcmResponse.port);
+ }
+
+ second = cJSON_GetObjectItem(first, "sdFormatCommand");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.sdFormatCommand = second->valueint;
+ printf(".sdFormatCommand = %d\n", stLoginAcmResponse.sdFormatCommand);
+ }
+
+ second = cJSON_GetObjectItem(first, "synConfigCommand");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.synConfigCommand = second->valueint;
+ printf(".synConfigCommand = %d\n", stLoginAcmResponse.synConfigCommand);
+ }
+
+ #if 1
+ //
+ second = cJSON_GetObjectItem(first, "serverIp");
+ if(second->valuestring != NULL)
+ {
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.serverIp, buf, declen);
+ stLoginAcmResponse.RegionalChange = 1;
+ printf(".serverIp = %s\n", stLoginAcmResponse.serverIp);
+ }
+ #endif
+
+ second = cJSON_GetObjectItem(first, "token");
+ if(second->valuestring != NULL)
+ {
+ //memcpy(stLoginAcmResponse.token, second->valuestring, strlen(second->valuestring));
+ memcpy(pStaticParam->Token, second->valuestring, strlen(second->valuestring));
+ printf(".token = %s\n", pStaticParam->Token);
+ }
+
+ #if 0
+ second = cJSON_GetObjectItem(first, "uid");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.uid = second->valueint;
+ printf("...stLoginAcmResponse.uid = %d\n", stLoginAcmResponse.uid);
+ }
+ #endif
+
+ second = cJSON_GetObjectItem(first, "leftOverPic");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.leftOverPic = second->valueint;
+ printf(".leftOverPic = %d\n", stLoginAcmResponse.leftOverPic);
+ if(stLoginAcmResponse.leftOverPic > 0)
+ pStaticParam->PicPlan = 1;
+ else
+ pStaticParam->PicPlan = 0;
+ }
+
+ #if 0
+ second = cJSON_GetObjectItem(first, "upload");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.upload = second->valueint;
+ printf("...stLoginAcmResponse.upload = %d\n", stLoginAcmResponse.upload);
+ }
+ #endif
+
+ second = cJSON_GetObjectItem(first, "uploadType");
+ if(second != NULL)
+ {
+ //stLoginAcmResponse.uploadType = second->valueint;
+ pStaticParam->UploadMode = second->valueint;
+ UploadMode = pStaticParam->UploadMode;
+ printf(".uploadtype = %d\n", pStaticParam->UploadMode);
+ }
+
+ second = cJSON_GetObjectItem(first, "url");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.url, '\0', sizeof(stLoginAcmResponse.url));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.url, buf, declen);
+ printf(".url = %s\n", stLoginAcmResponse.url);
+ }
+
+ second = cJSON_GetObjectItem(first, "userEmail");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.userEmail, '\0', sizeof(stLoginAcmResponse.userEmail));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.userEmail, buf, declen);
+ memcpy(pStaticParam->BindAccount, stLoginAcmResponse.userEmail, strlen(stLoginAcmResponse.userEmail));
+
+ printf(".userEmail = %s\n", stLoginAcmResponse.userEmail);
+ }
+
+ second = cJSON_GetObjectItem(first, "uuid");
+ if(second->valuestring != NULL)
+ {
+ memset(stLoginAcmResponse.uuid, '\0', sizeof(stLoginAcmResponse.uuid));
+ memset(buf, '\0', sizeof(buf));
+ declen = sf_http_decrypt(second->valuestring, buf, strlen(second->valuestring));
+ memcpy(stLoginAcmResponse.uuid, buf, declen);
+ memcpy(pStaticParam->Uuid, stLoginAcmResponse.uuid, strlen(stLoginAcmResponse.uuid));
+ printf(".uuids = %s\n", stLoginAcmResponse.uuid);
+ }
+
+ second = cJSON_GetObjectItem(first, "date");
+ if(second->valuestring != NULL)
+ {
+ memcpy(stLoginAcmResponse.date, second->valuestring, strlen(second->valuestring));
+ printf(".date = %s\n", stLoginAcmResponse.date);
+ }
+
+ second = cJSON_GetObjectItem(first, "maxNumberDay");
+ if(second != NULL)
+ {
+ pSfParam->SendMaxNum = second->valueint;
+ printf(".maxNumberDay = %d\n", pSfParam->SendMaxNum);
+ }
+
+ second = cJSON_GetObjectItem(first, "getPic");
+ if(second != NULL)
+ {
+ stLoginAcmResponse.getPic = second->valueint;
+ printf(".getPic = %d\n", stLoginAcmResponse.getPic);
+ }
+
+ sprintf((char *)pStaticParam->stOssCfg.szIP , "%s", stLoginAcmResponse.url);
+ sprintf((char *)pStaticParam->stOssCfg.szBucket, "%s", stLoginAcmResponse.port);
+ sprintf((char *)pStaticParam->stOssCfg.szUsername, "%s", stLoginAcmResponse.name);
+ sprintf((char *)pStaticParam->stOssCfg.szPassword, "%s", stLoginAcmResponse.passwd);
+
+ /**/
+ SF_PARA_TIME_S http_time;
+ char * indx = NULL;
+ indx = stLoginAcmResponse.date;
+ http_time.Year = atoi(indx);
+ indx = strchr(indx, '-');
+ indx++;
+ http_time.Mon = atoi(indx);
+ indx++;
+ indx = strchr(indx, '-');
+ indx++;
+ http_time.Day = atoi(indx);
+ indx = strchr(indx, ' ');
+ indx++;
+ http_time.Hour = atoi(indx);
+ indx = strchr(indx, ':');
+ indx++;
+ http_time.Min = atoi(indx);
+ indx++;
+ indx = strchr(indx, ':');
+ indx++;
+ http_time.Sec = atoi(indx);
+
+ printf("http time is %d-%d-%d-%d-%d-%d\r\n",
+ http_time.Year, http_time.Mon, http_time.Day, http_time.Hour, http_time.Min, http_time.Sec);
+
+ pStaticParam->httpTime.Year = http_time.Year;
+ pStaticParam->httpTime.Mon = http_time.Mon;
+ pStaticParam->httpTime.Day = http_time.Day;
+ pStaticParam->httpTime.Hour = http_time.Hour;
+ pStaticParam->httpTime.Min = http_time.Min;
+ pStaticParam->httpTime.Sec = http_time.Sec; //International standard time
+
+ printf("pStaticParam http time is %d-%d-%d-%d-%d-%d\r\n",
+ pStaticParam->httpTime.Year, pStaticParam->httpTime.Mon, pStaticParam->httpTime.Day, \
+ pStaticParam->httpTime.Hour, pStaticParam->httpTime.Min, pStaticParam->httpTime.Sec);
+ SINT32 sec = 0;
+ sec = sf_get_seconds(http_time);//28800000
+ sec += stLoginAcmResponse.offset / 1000;
+ sf_get_date(sec, &rtcTime);
+
+ printf("rtcTime is %d-%d-%d-%d-%d-%d\r\n",
+ rtcTime.Year, rtcTime.Mon, rtcTime.Day, rtcTime.Hour, rtcTime.Min, rtcTime.Sec);
+
+
+
+
+ cJSON_Delete(json);
+ return ret;
+ }
+
+ SINT32 sf_net_packetanalysis_fileresult(SF_DATA_ATTR_S *param)
+ {
+ char *p = NULL;
+ char *out = NULL;
+ cJSON *json = NULL;
+ cJSON *first = NULL;
+ cJSON *second = NULL;
+ cJSON *third = NULL;
+ SF_URL_S *urlCfg = sf_ota_url_get();
+ SINT32 ret = 0;
+ SINT8 index = 0;
+ SF_REPORT_FILE_ATTR_S *pSubReportFileAttr = sf_get_sub_report_file_attr();
+
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("recv_buff: %d byte,\n%s\n",param->dataSize,param->databuf);
+ #endif
+ ret = http_response_status_code((char*)param->databuf);
+ if(ret == SF_FAILURE)
+ return SF_DATA_ERROR_REQUEST;
+
+ p = strchr((char*)param->databuf, '{');
+ json=cJSON_Parse(p);
+ if (!json)
+ {
+ printf("Error before: [%s]\n",cJSON_GetErrorPtr());
+ cJSON_Delete(json);
+ return SF_DATA_ERROR_DATA_FORMAT;
+ }
+
+
+ first = cJSON_GetObjectItem(json, "code");
+ printf("...code = %d\n", first->valueint);
+
+
+ first = cJSON_GetObjectItem(json, "errCode");
+ ret = first->valueint;
+ printf("...errCode = %d\n", first->valueint);
+
+ first = cJSON_GetObjectItem(json, "data");
+ second = cJSON_GetObjectItem(first, "otaCommand");
+ if(second != NULL) {
+ stLoginAcmResponse.otaCommand = second->valueint;
+ printf("...otaCommand = %d\n", stLoginAcmResponse.otaCommand);
+ }
+
+ second = cJSON_GetObjectItem(first, "downloadUrl");
+ if(second->valuestring != NULL) {
+ memset(stLoginAcmResponse.downloadUrl, '\0', sizeof(stLoginAcmResponse.downloadUrl));
+ sf_http_decrypt(second->valuestring, stLoginAcmResponse.downloadUrl, strlen(second->valuestring));
+ memcpy(urlCfg->url, stLoginAcmResponse.downloadUrl, sizeof(stLoginAcmResponse.downloadUrl));
+ printf("...downloadUrl = %s\n", stLoginAcmResponse.downloadUrl);
+ }
+
+ second = cJSON_GetObjectItem(first, "hdCommand");
+ if(second != NULL) {
+ stLoginAcmResponse.hdCommand = second->valueint;
+ printf("...hdCommand = %d\n", stLoginAcmResponse.hdCommand);
+ }
+
+ if((stLoginAcmResponse.hdCommand > 0) && (stLoginAcmResponse.hdCommand < 100))
+ {
+ second = cJSON_GetObjectItem(first, "hdPhototVOList");
+ SINT8 i = pSubReportFileAttr->filecnt;
+ for(index = 0; index < stLoginAcmResponse.hdCommand; index++)
+ {
+ third = cJSON_GetArrayItem(second, index);
+
+// if(cJSON_GetObjectItem(third, "fileType")->valueSINT32 == 10)
+// {
+// stLoginAcmResponse.logCommand = 1;
+// if(stLoginAcmResponse.hdCommand == 1)
+// stLoginAcmResponse.hdCommand = 0;
+// }
+// else
+ {
+ pSubReportFileAttr->stSendFileAttr[i].enFileTye = cJSON_GetObjectItem(third, "fileType")->valueSINT32;
+ sprintf(pSubReportFileAttr->stSendFileAttr[i].SubFileName, "%s", cJSON_GetObjectItem(third, "fileName")->valuestring);
+
+ printf("enFileTye:%d, SubFileName:%s\n",
+ pSubReportFileAttr->stSendFileAttr[i].enFileTye,
+ pSubReportFileAttr->stSendFileAttr[i].SubFileName);
+ i++;
+ pSubReportFileAttr->filecnt = i;
+ }
+ }
+ SLOGD("filecnt:%d\n", pSubReportFileAttr->filecnt);
+ }
+
+ cJSON_Delete(json);
+ free(out);
+
+ return ret;
+ }
+
+
+
+ SINT32 sf_net_packetanalysis_sync(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam)
+ {
+ char *p = NULL;
+ char *out = NULL;
+ cJSON *json = NULL;
+ cJSON *first = NULL;
+ cJSON *second = NULL;
+ int ret = 0;
+ //UINT8 temp = 0;
+ char * indx = NULL;
+ SF_PDT_PARAM_CFG_S* pSfParam = pfnParam->pstParam;
+ #ifndef SF_VERSION_RELEASE
+ MLOGD("recv_buff: %d byte,\n%s\n",param->dataSize,param->databuf);
+ #endif
+ ret = http_response_status_code((char*)param->databuf);
+ if(ret == SF_FAILURE)
+ return SF_DATA_ERROR_REQUEST;
+ p = strchr((char*)param->databuf, '{');
+ json=cJSON_Parse(p);
+ if (!json)
+ {
+ printf("Error before: [%s]\n",cJSON_GetErrorPtr());
+ cJSON_Delete(json);
+ return SF_DATA_ERROR_DATA_FORMAT;
+ }
+
+
+ first = cJSON_GetObjectItem(json, "code");
+ printf("...code = %d\n", first->valueint);
+
+ first = cJSON_GetObjectItem(json, "errCode");
+ MLOGI("...errCode = %d\n", first->valueint);
+ if(first->valueint != 0)
+ {
+ data_error_collection(first->valueint);
+ cJSON_Delete(json);
+ return SF_FAILURE;
+ }
+
+
+
+ first = cJSON_GetObjectItem(json, "msg");
+ printf("...msg = %s\n", first->valuestring);
+
+ first = cJSON_GetObjectItem(json, "data");
+ out = cJSON_Print(first);
+ if(!(strstr(out, "{") && strstr(out, "}"))) {
+ pSfParam->ParaSync = 0;
+ MLOGD("...ParaSync = %d\n", pSfParam->ParaSync);
+ return SF_SUCCESS;
+ }
+
+ second = cJSON_GetObjectItem(first, "video");
+ pSfParam->CamMode = second->valueint - 1;
+ printf("...camera_mode = %d\n", pSfParam->CamMode);
+
+ second = cJSON_GetObjectItem(first, "image");
+ pSfParam->ImgSize = second->valueint;
+ printf("...img_size = %d\n", pSfParam->ImgSize);
+
+ second = cJSON_GetObjectItem(first, "multishot");
+ pSfParam->Multishot = second->valueint;
+ if(pSfParam->Multishot > 3) {
+ pSfParam->Multishot = 3;
+ MLOGW("Multishot [%d] is more than [1,3],so default value [3]\n",second->valueint);
+ }
+
+ printf("...multishot = %d\n", pSfParam->Multishot);
+
+ second = cJSON_GetObjectItem(first, "videoSize");
+ pSfParam->VideoSize = (second->valueint) - 1;
+ printf("...video_size = %d\n", pSfParam->VideoSize);
+
+ second = cJSON_GetObjectItem(first, "videoLength");
+ pSfParam->VideoLenth = second->valueint;
+ printf("...video_lenth = %d\n", pSfParam->VideoLenth);
+
+ #if 0
+ second = cJSON_GetObjectItem(first, "videoFrameRate");
+ pSfParam->VideoFrame = second->valueint;
+ MLOGD("...video_frame_rate = %d\n", pSfParam->VideoFrame);
+
+ second = cJSON_GetObjectItem(first, "sendFrequency");
+ pSfParam->BatchSendTimelapse = second->valueint;
+ MLOGD("...send_frequency = %d\n", pSfParam->BatchSendTimelapse);
+ #endif
+ second = cJSON_GetObjectItem(first, "pirswitch");
+ pSfParam->PirSwitch = second->valueint;
+ printf("...pir_work_switch = %d\n", pSfParam->PirSwitch);
+
+ second = cJSON_GetObjectItem(first, "pirsentivity");
+ pSfParam->DigitPirSensitivity = second->valueint;
+ pSfParam->PirSensitivity = sf_pir_to_digit_analog(pSfParam->DigitPirSensitivity);
+
+ printf("...DigitPirSensitivity = %d\n", pSfParam->DigitPirSensitivity);
+ printf("...pirsentivity = %d\n", pSfParam->PirSensitivity);
+
+ second = cJSON_GetObjectItem(first, "delayFlag");
+ pSfParam->PirDelaySwitch = second->valueint;
+ printf("...pir_delay_switch = %d\n", pSfParam->PirDelaySwitch);
+
+ second = cJSON_GetObjectItem(first, "delayValue");
+ indx = second->valuestring;
+ pSfParam->PirDelayTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->PirDelayTime.Hour += ((*indx++) - '0');
+ pSfParam->PirDelayTime.Min = ((*indx++) - '0')*10;
+ pSfParam->PirDelayTime.Min += ((*indx++) - '0');
+ pSfParam->PirDelayTime.Sec = ((*indx++) - '0')*10;
+ pSfParam->PirDelayTime.Sec += ((*indx++) - '0');
+ printf("...pir_delay_value = %s\n", second->valuestring);
+
+ second = cJSON_GetObjectItem(first, "timelapseFlag");
+ pSfParam->TimelapseSwitch = second->valueint;
+ printf("...timelapse_switch = %d\n", pSfParam->TimelapseSwitch);
+
+ second = cJSON_GetObjectItem(first, "timelapseValue");//
+ indx = second->valuestring;
+ pSfParam->TimelapseTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->TimelapseTime.Hour += ((*indx++) - '0');
+ pSfParam->TimelapseTime.Min = ((*indx++) - '0')*10;
+ pSfParam->TimelapseTime.Min += ((*indx++) - '0');
+ pSfParam->TimelapseTime.Sec = ((*indx++) - '0')*10;
+ pSfParam->TimelapseTime.Sec += ((*indx++) - '0');
+ printf("...timelapse_value = %s\n", second->valuestring);
+
+
+ second = cJSON_GetObjectItem(first, "timerFlag");
+ pSfParam->WorkTime1Switch = second->valueint;
+ printf("...work_timer1_swtich = %d\n", pSfParam->WorkTime1Switch);
+
+ second = cJSON_GetObjectItem(first, "timerValue");
+ indx = second->valuestring;
+ pSfParam->WorkTime[0].StartTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[0].StartTime.Hour += ((*indx++) - '0');
+ pSfParam->WorkTime[0].StartTime.Min = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[0].StartTime.Min += ((*indx++) - '0');
+ indx++;
+ pSfParam->WorkTime[0].StopTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[0].StopTime.Hour += ((*indx++) - '0');
+ pSfParam->WorkTime[0].StopTime.Min = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[0].StopTime.Min += ((*indx++) - '0');
+ printf("...work time1 start, h:%d, m:%d\r\n", pSfParam->WorkTime[0].StartTime.Hour, pSfParam->WorkTime[0].StartTime.Min);
+ printf("...work time1 stop, h:%d, m:%d\r\n", pSfParam->WorkTime[0].StopTime.Hour, pSfParam->WorkTime[0].StopTime.Min);
+ printf("...work_timer1_value = %s\n", second->valuestring);
+
+ second = cJSON_GetObjectItem(first, "timerFlag2");
+ pSfParam->WorkTime2Switch = second->valueint;
+ printf("...work_timer2_swtich = %d\n", pSfParam->WorkTime2Switch);
+
+ second = cJSON_GetObjectItem(first, "timerValue2");
+ indx = second->valuestring;
+ pSfParam->WorkTime[1].StartTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[1].StartTime.Hour += ((*indx++) - '0');
+ pSfParam->WorkTime[1].StartTime.Min = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[1].StartTime.Min += ((*indx++) - '0');
+ indx++;
+ pSfParam->WorkTime[1].StopTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[1].StopTime.Hour += ((*indx++) - '0');
+ pSfParam->WorkTime[1].StopTime.Min = ((*indx++) - '0')*10;
+ pSfParam->WorkTime[1].StopTime.Min += ((*indx++) - '0');
+ printf("...work_timer2_value = %s\n", second->valuestring);
+ printf("...work time2 start, h:%d, m:%d\r\n", pSfParam->WorkTime[1].StartTime.Hour, pSfParam->WorkTime[1].StartTime.Min);
+ printf("...work time2 stop, h:%d, m:%d\r\n", pSfParam->WorkTime[1].StopTime.Hour, pSfParam->WorkTime[1].StopTime.Min);
+
+ second = cJSON_GetObjectItem(first, "batteryType");
+ pSfParam->BatteryType = second->valueint;
+ printf("...battery_type = %d\n", pSfParam->BatteryType);
+
+ second = cJSON_GetObjectItem(first, "ledNumber");
+ pSfParam->FlashLed = second->valueint;
+ printf("...flash_power = %d\n", pSfParam->FlashLed);
+
+ second = cJSON_GetObjectItem(first, "stamp");
+ pSfParam->StampSwitch = second->valueint;
+ printf("...water_stamp = %d\n", pSfParam->StampSwitch);
+
+ second = cJSON_GetObjectItem(first, "sdcycleFlag");
+ pSfParam->SdLoop = second->valueint;
+ printf("...cycle_recording = %d\n", pSfParam->SdLoop);
+
+ second = cJSON_GetObjectItem(first, "dailyreportFlag");
+ pSfParam->DailyReportswitch = second->valueint;
+ printf("...dailyreportFlag = %d\n", pSfParam->DailyReportswitch);
+
+ second = cJSON_GetObjectItem(first, "dailyreportValue");//
+ indx = second->valuestring;
+ pSfParam->DailyReportTime.Hour = ((*indx++) - '0')*10;
+ pSfParam->DailyReportTime.Hour += ((*indx++) - '0');
+ pSfParam->DailyReportTime.Min = ((*indx++) - '0')*10;
+ pSfParam->DailyReportTime.Min += ((*indx++) - '0');
+ printf("...dailyreportValue = %s\n", second->valuestring);
+ printf("...Hour = %d\n", pSfParam->DailyReportTime.Hour);
+ printf("...Min = %d\n", pSfParam->DailyReportTime.Min);
+ if(pSfParam->DailyReportswitch == 0)
+ {
+ if(pSfParam->DailyReportTime.Hour == 0 &&
+ pSfParam->DailyReportTime.Min == 0)
+ {
+ pSfParam->GprsMode = 1;/*realtime*/
+ }
+ else
+ {
+ pSfParam->GprsMode = 0;/*off*/
+ }
+ }
+ else
+ {
+
+ if((pSfParam->DailyReportTime.Hour == 0) && (pSfParam->DailyReportTime.Min == 30))
+ {
+ pSfParam->GprsMode = 2;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 1) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 3;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 2) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 4;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 3) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 5;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 4) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 6;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 6) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 7;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 12) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 8;
+ }
+ else if((pSfParam->DailyReportTime.Hour == 24) && (pSfParam->DailyReportTime.Min == 0))
+ {
+ pSfParam->GprsMode = 9;
+ }
+ }
+ MLOGD("...GprsMode = %d\n", pSfParam->GprsMode);
+ pSfParam->ParaSync = 1;
+ cJSON_Delete(json);
+ free(out);
+
+ MLOGD("...ParaSync = %d\n", pSfParam->ParaSync);
+ return SF_SUCCESS;
+ }
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/source/dataMng/sf_transdata1.c b/code/application/source/sf_app/code/source/dataMng/sf_transdata1.c
new file mode 100755
index 000000000..1ddd5c280
--- /dev/null
+++ b/code/application/source/sf_app/code/source/dataMng/sf_transdata1.c
@@ -0,0 +1,1722 @@
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "sf_type.h"
+#include "sf_log.h"
+
+#include "sf_module.h"
+
+#include "sf_storeMng.h"
+#include "sf_systemMng.h"
+#include "sf_dev_other.h"
+
+#include "sf_dataMng.h"
+#include "sf_transdata1.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+#define CS_DEBUG_INFO 1
+extern SF_PARA_TIME_S rtcTime;
+extern SF_CMD_QUERYPENDING_E PendingOrder;
+extern UINT8 CanUpload;
+extern UINT8 UploadMode;
+extern UINT8 HasCommand;
+extern UINT16 SubscribeRet;
+
+
+SF_CHAR Device_id[5] = {0};
+
+
+//const SF_CHAR* sf_param_getqueryrequeststatusstring(UINT16 enModuleType)
+//{
+// switch(enModuleType)
+// {
+// case SF_CMD_LOGIN_IN:
+// case SF_CMD_GET_LOGIN_IN:
+// return "SF_CMD_LOGIN_IN";
+// case SF_CMD_REPORT_STATE:
+// case SF_CMD_GET_REPORT_STATE:
+// return "SF_CMD_REPORT_STATE";
+// case SF_CMD_PHOTO_RESULT:
+// case SF_CMD_GET_PHOTO_RESULT:
+// return "SF_CMD_PHOTO_RESULT";
+// case SF_CMD_QUERYPENDING_CMD:
+// case SF_CMD_GET_QUERYPENDING_CMD:
+// return "SF_CMD_QUERYPENDING_CMD";
+// case SF_CMD_QUERYPENDING_PARAM:
+// case SF_CMD_GET_QUERYPENDING_PARAM:
+// return "SF_CMD_QUERYPENDING_PARAM";
+// case SF_CMD_REPORT_RESULT:
+// case SF_CMD_GET_REPORT_RESULT:
+// return "SF_CMD_REPORT_RESULT";
+// case SF_CMD_TRIGGER:
+// case SF_CMD_GET_TRIGGER:
+// return "SF_CMD_TRIGGER";
+// case SF_CMD_DISCON_SEND:
+// return "SF_CMD_DISCON_SEND";
+// default:
+// return "Unknown";
+// }
+//}
+static SINT32 packet_log_printf(UINT8 *pbuf,UINT16 lenth)
+{
+ UINT16 i= 0;
+ for(i = 0;i < lenth;i++)
+ {
+ if(i%5 == 0)
+ printf("[%02d,%02d] = {",i,((lenth - i) < 5)?(lenth-1):(i+4));
+
+ if((i+1)%5 == 0 || (i+1) == lenth)
+ printf("0x%02x}\n",*pbuf++);
+ else
+ printf("0x%02x,",*pbuf++);
+ }
+ return SF_SUCCESS;
+
+}
+static SINT32 packet_gps_parse(char *pstring,SF_PDT_PARAM_STATISTICS_S *pStaticParam)
+{
+ *pstring++ = pStaticParam->Latitude[9];
+ *pstring++ = pStaticParam->Latitude[0];
+ *pstring++ = pStaticParam->Latitude[1];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Latitude[2];
+ *pstring++ = pStaticParam->Latitude[3];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Latitude[5];
+ *pstring++ = pStaticParam->Latitude[6];
+ *pstring++ = '-';
+
+ *pstring++ = pStaticParam->Longitude[10];
+ *pstring++ = pStaticParam->Longitude[0];
+ *pstring++ = pStaticParam->Longitude[1];
+ *pstring++ = pStaticParam->Longitude[2];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Longitude[3];
+ *pstring++ = pStaticParam->Longitude[4];
+ *pstring++ = '.';
+ *pstring++ = pStaticParam->Longitude[6];
+ *pstring++ = pStaticParam->Longitude[7];
+ *pstring++ = '\0';
+
+// *pstring++ = 'N';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '-';
+
+// *pstring++ = 'E';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '.';
+// *pstring++ = '2';
+// *pstring++ = '2';
+// *pstring++ = '\0';
+ return SF_SUCCESS;
+}
+
+SINT32 sf_packetgrouping_login(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ UINT8 i=0;
+ UINT8 *pData = pstdata->databuf;
+ UINT16 Crc=0;
+ UINT16 interfaceVer = 10;
+ UINT8 signalLevel=0;
+
+ SF_PDT_PARAM_CFG_S *pstParam = pfnParam->pstParam;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ SF_CHAR version[12] = {0};
+ SF_STORE_ATTR_S storeattrs;
+
+ sf_sys_software_version_get(version);
+
+ sf_sd_info_get(&storeattrs);
+ if(storeattrs.SDStatus != 0)
+ {
+ storeattrs.SDTotalSize = 0;
+ storeattrs.SDFree = 0;
+ }
+
+ sf_4G_signal_level_get(pStaticParam->netGeneration,pStaticParam->SimSignal,&signalLevel);
+ if(signalLevel == 4)
+ signalLevel = 31;
+ else if(signalLevel == 3)
+ signalLevel = 13;
+ else if(signalLevel == 2)
+ signalLevel = 7;
+
+ MLOGD("signalLevel:%d, SDTotalSize:%d, SDFree:%d\n", signalLevel, storeattrs.SDTotalSize, storeattrs.SDFree);
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+ *pData++ = 0;
+ *pData++ = 0;
+ *pData++ = 0;
+ *pData++ = 0;
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x00; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x01; //SEQ
+
+ *pData++ = 0x00; //upload len, re calculate at end of the function
+ *pData++ = 0x00; //upload len, re calculate at end of the function
+ *pData++ = (UINT8)((interfaceVer&0xff00)>>8);; //interface ver
+ *pData++ = (UINT8)(interfaceVer&0x00ff); //interface ver
+ for(i=0; i<16; i++) //imei
+ *pData++ = pStaticParam->IMEI[i];
+
+ for(i=0;i<16;i++)
+ *pData++ = 0; //usrname
+
+ for(i=0;i<16;i++)
+ *pData++ = 0; //password
+
+ *pData++ = 0;
+ *pData++ = signalLevel; //csq
+ *pData++ = pStaticParam->BatRemainCap; //bat level
+
+ *pData++ = (UINT8)((storeattrs.SDTotalSize) >>8 & 0xFF); //SD total size high 8bit
+ *pData++ = (UINT8)((storeattrs.SDTotalSize) & 0xFF); //SD total size low 8bit
+ *pData++ = (UINT8)((storeattrs.SDFree) >>8 & 0xFF); //SD free size high 8bit
+ *pData++ = (UINT8)((storeattrs.SDFree) & 0xFF); //SD free size low 8bit
+
+ *pData++ = pStaticParam->FcTemper;//fahrenheit FC_temper
+
+ *pData++ = (UINT8)((pStaticParam->SdTotalFile) >>8 & 0xFF); //total pic high 8 bit
+ *pData++ = (UINT8)((pStaticParam->SdTotalFile) & 0xFF); //total pic low 8 bit
+ *pData++ = (UINT8)((pStaticParam->SendPicDayCnt) >>8 & 0xFF); //send pic total high 8 bit
+ *pData++ = (UINT8)((pStaticParam->SendPicDayCnt) & 0xFF); //send pic total low 8 bit
+ *pData++ = 0;
+ *pData++ = (UINT8)((pStaticParam->TriggerTimes) >>8 & 0xFF); //trigger time high 8 bit
+ *pData++ = (UINT8)((pStaticParam->TriggerTimes) & 0xFF); //trigger time low 8 bit
+
+ for(i=0;i<12;i++) //software ver
+ *pData++ = version[i];
+
+ *pData++ = pstParam->ParaSync; //cfg update flag
+ *pData++ = pStaticParam->startup; //start up type
+ *pData++ = 0; //error1
+ *pData++ = 0; //error2
+ *pData++ = 0; //error3
+ *pData++ = 0; //error4
+
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2, pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[LOGIN_IN] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+
+ #endif
+
+ return SF_SUCCESS;
+
+}
+
+SINT32 sf_packetgrouping_fileresult(SF_DATA_ATTR_S *pstdata, SF_PDT_PARAM_CFG_S *pstParam,SF_FILE_ATTR_S *pstfileAttr)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstfileAttr,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstfileAttr->thumbfileName,SF_FAILURE);
+
+ UINT8 i=0;
+ UINT8 *pData = pstdata->databuf;
+ UINT16 Crc=0;
+ SF_CHAR fileName[128] = { 0 };
+ SF_CHAR fileNameVideo[32] = { 0 };
+ UINT8 fileType = 0;
+
+ if(pstfileAttr->enFileTye == SF_FILE_TYPE_PIC_SMALL)
+ {
+ sprintf(fileName, "thumb_%s", pstfileAttr->thumbfileName);
+ fileType = 1;
+ }
+ else
+ sprintf(fileName, "%s", pstfileAttr->thumbfileName);
+
+ if(pstfileAttr->enFileTye == SF_FILE_TYPE_PIC_VIDEO)
+ {
+ if(pstParam->VideoSize == SF_VIDEO_SIZE_1080)
+ fileType = 6;
+ else if(pstParam->VideoSize == SF_VIDEO_SIZE_720)
+ fileType = 4;
+ else if(pstParam->VideoSize == SF_VIDEO_SIZE_WVGA)
+ fileType = 2;
+ }
+
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+
+ *pData++ = Device_id[0];
+ *pData++ = Device_id[1];
+ *pData++ = Device_id[2];
+ *pData++ = Device_id[3];
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x04; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x01; //seq
+
+ *pData++ = 0x00; //负载长度
+ *pData++ = 0x58; //负载长度
+
+ *pData++ = (rtcTime.Year>>8)&0XFF; //Year
+ *pData++ = rtcTime.Year&0xFF; //Year
+ *pData++ = rtcTime.Mon; //month
+ *pData++ = rtcTime.Day; //Day
+ *pData++ = rtcTime.Hour; //Hour
+ *pData++ = rtcTime.Min; //minute
+ *pData++ = rtcTime.Sec; //second
+
+ *pData++ = fileType; //file type
+ *pData++ = sf_data_transfer_mode_get(); //upload type:1=ftp,2=oss
+
+ *pData++ = (pstfileAttr->thumbfileSize>>24)&0XFF; //file size
+ *pData++ = (pstfileAttr->thumbfileSize>>16)&0XFF; //file size
+ *pData++ = (pstfileAttr->thumbfileSize>>8)&0XFF; //file size
+ *pData++ = pstfileAttr->thumbfileSize&0XFF; //file size
+
+ MLOGD("report acm file name:%s, file size:%d, file type:%d\n", fileName, pstfileAttr->thumbfileSize, fileType);
+ for(i=0;i<34;i++) //filename
+ *pData++ = fileName[i];
+
+ if(pstfileAttr->enFileTye == SF_FILE_TYPE_PIC_VIDEO)
+ {
+ *pData++ = 2;
+ memcpy(fileNameVideo, pstfileAttr->thumbfileName, strlen(pstfileAttr->thumbfileName)-4);
+ sprintf(fileName, "S%s.MP4", fileNameVideo+1);
+ MLOGD("bind file name:%s\n", fileName);
+ for(i=0;i<39;i++) //filename
+ *pData++ = fileName[i];
+ }
+ else
+ {
+ *pData++ = 0; //Bind thumbnails
+ for(i=0;i<39;i++) //filename
+ *pData++ = 0;
+ }
+
+ *pData++ = 0;
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2,pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+ #if CS_DEBUG_INFO
+ MLOGD("[PHOTO_RESULT] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+ #endif
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_packetgrouping_get_bind_account(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam)
+{
+
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ UINT8 i=0;
+ UINT8 *pData = pstdata->databuf;
+ UINT16 Crc=0;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ MLOGD("IMEI:%s\n", pStaticParam->IMEI);
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+ *pData++ = Device_id[0];
+ *pData++ = Device_id[1];
+ *pData++ = Device_id[2];
+ *pData++ = Device_id[3];
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x0e; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x01; //SEQ
+
+ *pData++ = 0x00; //upload len, re calculate at end of the function
+ *pData++ = 0x00; //upload len, re calculate at end of the function
+
+ *pData++ = 0x00;
+ *pData++ = 0x01; //1 :get bind account
+
+ for(i=0; i<16; i++) //imei
+ *pData++ = pStaticParam->IMEI[i];
+
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2, pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+ #if CS_DEBUG_INFO
+ MLOGD("[BIND_ACCOUNT] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+ #endif
+
+ return SF_SUCCESS;
+
+}
+
+SINT32 sf_packetgrouping_query_cmd(SF_DATA_ATTR_S *pstdata)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+
+ UINT16 Crc=0;
+ UINT8 *pData = pstdata->databuf;
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+
+ *pData++ = Device_id[0];
+ *pData++ = Device_id[1];
+ *pData++ = Device_id[2];
+ *pData++ = Device_id[3];
+
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x06; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x01; //SEQ
+ *pData++ = 0x00; //Payload len
+ *pData++ = 0x7; //Payload len
+
+ *pData++ = (rtcTime.Year>>8)&0XFF; //Year
+ *pData++ = rtcTime.Year&0xFF; //Year
+ *pData++ = rtcTime.Mon; //month
+ *pData++ = rtcTime.Day; //Day
+ *pData++ = rtcTime.Hour; //Hour
+ *pData++ = rtcTime.Min; //minute
+ *pData++ = rtcTime.Sec; //second
+
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2,pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+ #if CS_DEBUG_INFO
+ MLOGD("[QUERYPENDING_CMD] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+ #endif
+
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_packetgrouping_query_cmd_param(SF_DATA_ATTR_S *pstdata)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ UINT16 Crc=0;
+ UINT8 *pData = pstdata->databuf;
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+
+ *pData++ = Device_id[0];
+ *pData++ = Device_id[1];
+ *pData++ = Device_id[2];
+ *pData++ = Device_id[3];
+
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x08; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x01; //SEQ
+ *pData++ = 0x00; //负载长度
+ *pData++ = 0x9; //负载长度
+
+ *pData++ = (PendingOrder>>8)&0XFF;
+ *pData++ = PendingOrder&0xFF; //comand
+
+
+ *pData++ = (rtcTime.Year>>8)&0XFF; //Year
+ *pData++ = rtcTime.Year&0xFF; //Year
+ *pData++ = rtcTime.Mon; //month
+ *pData++ = rtcTime.Day; //Day
+ *pData++ = rtcTime.Hour; //Hour
+ *pData++ = rtcTime.Min; //minute
+ *pData++ = rtcTime.Sec; //second
+
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2,pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+ #if CS_DEBUG_INFO
+ MLOGD("[QUERYPENDING_PARAM] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+ #endif
+
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_packetgrouping_cmd_report(SF_DATA_ATTR_S *pstdata, SF_FN_PARAM_S *pfnParam, SF_FILE_ATTR_S *pstfileAttr)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstfileAttr,SF_FAILURE);
+
+ UINT8 i=0;
+ UINT8 *pData = pstdata->databuf;
+ UINT16 Crc=0;
+ UINT8 fileType = 0;
+ SF_PDT_PARAM_CFG_S *pstparam = pfnParam->pstParam;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+
+ *pData++ = Device_id[0];
+ *pData++ = Device_id[1];
+ *pData++ = Device_id[2];
+ *pData++ = Device_id[3];
+
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x0a; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x01; //SEQ
+ *pData++ = 0x00; //payload len
+ *pData++ = 0x9; //pauload len
+
+ *pData++ = (PendingOrder>>8)&0XFF;
+ *pData++ = PendingOrder&0xFF; //comand
+ if(PendingOrder == SF_CMD_QUERYPENDING_GETPICTURE)
+ {
+ //not always 0; 1 fail by net error; 2 fail by no pic/video file
+ *pData++ = (SubscribeRet>>8)&0XFF;
+ *pData++ = SubscribeRet&0xFF;
+ }
+ else
+ {
+ *pData++ = 0x00;
+ *pData++ = 0x00;
+ }
+
+ switch(PendingOrder)
+ {
+ case SF_CMD_QUERYPENDING_GETCFGFILE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETPICTURE:
+ if(pstfileAttr->enFileTye == SF_FILE_TYPE_VIDEO)
+ fileType = 2;
+ else if(pstfileAttr->enFileTye == SF_FILE_TYPE_PIC_BIG)
+ fileType = 0;
+ else if(pstfileAttr->enFileTye == SF_FILE_TYPE_GPS)
+ fileType = 3;
+
+ *pData++ = fileType; //upload type
+ *pData++ = sf_data_transfer_mode_get(); //upload mode*/
+ *pData++ = (UINT8)((pstfileAttr->thumbfileSize>>24)&0xff); /*file size*/
+ *pData++ = (UINT8)((pstfileAttr->thumbfileSize>>16)&0xff); /**/
+ *pData++ = (UINT8)((pstfileAttr->thumbfileSize>>8)&0xff); /**/
+ *pData++ = (UINT8)(pstfileAttr->thumbfileSize&0xff); /**/
+
+ for(i=0;i<35;i++)
+ *pData++ = pstfileAttr->thumbfileName[i]; /*HD filename*/
+
+ if(pstfileAttr->enFileTye != SF_FILE_TYPE_GPS)
+ {
+ /* send success bind 0; send failed bind 1*/
+
+ *pData++ = 1;
+ for(i=0;i<39;i++)
+ *pData++ = pStaticParam->stSubscribe.pSubscribe[0].subscribeFileName[i];
+ }
+ else
+ {
+ *pData++ = 0;
+ for(i=0;i<39;i++)
+ *pData++ = pStaticParam->stSubscribe.pSubscribe[0].subscribeFileName[i];
+ }
+ MLOGD("SubscribeFileName:%s\n", pStaticParam->stSubscribe.pSubscribe[0].subscribeFileName);
+ free(pStaticParam->stSubscribe.pSubscribe);
+ break;
+
+ case SF_CMD_QUERYPENDING_GETSTATUS:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETSLEEPTIME:
+ break;
+
+ case SF_CMD_QUERYPENDING_REBOOT:
+ break;
+
+ case SF_CMD_QUERYPENDING_SETSYSTEMTIME:
+ break;
+
+ case SF_CMD_QUERYPENDING_SETCAMERAMODE:
+ case SF_CMD_QUERYPENDING_GETCAMERAMODE:
+ *pData++ = pstparam->CamMode+1;
+ *pData++ = pstparam->ImgSize;
+ *pData++ = pstparam->Multishot;
+ *pData++ = pstparam->Zoom+1;
+ *pData++ = pstparam->VideoSize+1;
+ *pData++ = pstparam->VideoLenth;
+ *pData++ = 1;
+ *pData++ = 1;
+
+ SLOGI("CameraMode = [%d],ImgSize = [%d],Multishot = [%d],Zoom = [%d],\n "
+ "VideoSize = [%d],VideoLenth = [%d],VideoFrame = [%d],LightFreq = [%d]\n",
+ pstparam->CamMode,
+ pstparam->ImgSize,
+ pstparam->Multishot,
+ pstparam->Zoom,
+ pstparam->VideoSize,
+ pstparam->VideoLenth,
+ pstparam->VideoFrame,
+ pstparam->LightFreq);
+ break;
+
+ case SF_CMD_QUERYPENDING_SETWORKMODE:
+ case SF_CMD_QUERYPENDING_GETMODECFG:
+
+ *pData++ = pstparam->TimelapseSwitch;
+ *pData++ = pstparam->TimelapseTime.Hour/10+'0';
+ *pData++ = pstparam->TimelapseTime.Hour%10+'0';
+ *pData++ = pstparam->TimelapseTime.Min/10+'0';
+ *pData++ = pstparam->TimelapseTime.Min%10+'0';
+ *pData++ = pstparam->TimelapseTime.Sec/10+'0';
+ *pData++ = pstparam->TimelapseTime.Sec%10+'0';
+
+ /*
+ if(pstparam->PirSwitch == 0)
+ *pData++ = 0;
+ else if(pstparam->PirSensitivity == 0)
+ *pData++ = 3;
+ else if(pstparam->PirSensitivity == 1)
+ *pData++ = 2;
+ else if(pstparam->PirSensitivity == 2)
+ *pData++ = 1;
+ */
+ *pData++ = pstparam->DigitPirSensitivity;
+ *pData++ = pstparam->PirDelaySwitch;
+ *pData++ = pstparam->PirDelayTime.Hour/10+'0';
+ *pData++ = pstparam->PirDelayTime.Hour%10+'0';
+ *pData++ = pstparam->PirDelayTime.Min/10+ '0';
+ *pData++ = pstparam->PirDelayTime.Min%10+ '0';
+ *pData++ = pstparam->PirDelayTime.Sec/10+ '0';
+ *pData++ = pstparam->PirDelayTime.Sec%10+ '0';
+
+ *pData++ = pstparam->WorkTime1Switch;
+ *pData++ = pstparam->WorkTime[0].StartTime.Hour/10+'0';
+ *pData++ = pstparam->WorkTime[0].StartTime.Hour%10+'0';
+ *pData++ = pstparam->WorkTime[0].StartTime.Min/10+ '0';
+ *pData++ = pstparam->WorkTime[0].StartTime.Min%10+ '0';
+ *pData++ = '-';
+ *pData++ = pstparam->WorkTime[0].StopTime.Hour/10+'0';
+ *pData++ = pstparam->WorkTime[0].StopTime.Hour%10+'0';
+ *pData++ = pstparam->WorkTime[0].StopTime.Min/10+ '0';
+ *pData++ = pstparam->WorkTime[0].StopTime.Min%10+ '0';
+
+ *pData++ = pstparam->WorkTime2Switch;
+ *pData++ = pstparam->WorkTime[1].StartTime.Hour/10+'0';
+ *pData++ = pstparam->WorkTime[1].StartTime.Hour%10+'0';
+ *pData++ = pstparam->WorkTime[1].StartTime.Min/10+ '0';
+ *pData++ = pstparam->WorkTime[1].StartTime.Min%10+ '0';
+ *pData++ = '-';
+ *pData++ = pstparam->WorkTime[1].StopTime.Hour/10+'0';
+ *pData++ = pstparam->WorkTime[1].StopTime.Hour%10+'0';
+ *pData++ = pstparam->WorkTime[1].StopTime.Min/10+ '0';
+ *pData++ = pstparam->WorkTime[1].StopTime.Min%10+ '0';
+
+ *pData++ = pstparam->PirSwitch;
+
+#if 1
+ if(pstparam->GprsMode == 0)
+ {
+ pstparam->DailyReportswitch = 0;
+ pstparam->DailyReportTime.Hour = 24;
+ pstparam->DailyReportTime.Min = 0;
+ }
+ else if(pstparam->GprsMode == 1)
+ {
+ pstparam->DailyReportswitch = 0;
+ pstparam->DailyReportTime.Hour = 0;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 2)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 0;
+ pstparam->DailyReportTime.Min = 30;
+
+ }
+ else if(pstparam->GprsMode == 3)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 1;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 4)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 2;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 5)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 3;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 6)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 4;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 7)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 6;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 8)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 12;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+ else if(pstparam->GprsMode == 9)
+ {
+ pstparam->DailyReportswitch = 1;
+ pstparam->DailyReportTime.Hour = 24;
+ pstparam->DailyReportTime.Min = 0;
+
+ }
+#endif
+ *pData++ = pstparam->DailyReportswitch;;
+ *pData++ = pstparam->DailyReportTime.Hour/10+'0';
+ *pData++ = pstparam->DailyReportTime.Hour%10+'0';
+ *pData++ = pstparam->DailyReportTime.Min/10+ '0';
+ *pData++ = pstparam->DailyReportTime.Min%10+ '0';
+
+
+
+ *pData++ = pstparam->NightMode;
+
+ *pData++ = pstparam->GprsMode;
+ *pData++ = pstparam->FlashLed;
+ *pData++ = pstparam->SendVideo;//pstparam->SendVideo;
+ *pData++ = pstparam->SendPhoto;//pstparam->SendPhoto;
+ *pData++ = pstparam->SendMultishot;//pstparam->SendBrustPic;
+
+ break;
+
+ case SF_CMD_QUERYPENDING_SETOTHER:
+ case SF_CMD_QUERYPENDING_GETOTHERCFG:
+ *pData++ = pstparam->SendMaxNum; //pstparam->MmsMax;
+ *pData++ = 0; //pstparam->Tvout;
+ *pData++ = 0; //pstparam->Audiorecord;
+ *pData++ = pstparam->StampSwitch; //pstparam->Stamp;
+ *pData++ = 0; //pstparam->Startuptone;
+ *pData++ = 0; //pstparam->Keyboard;
+ *pData++ = 0; //pstparam->CameraIDflag;
+ for(i=0;i<13;i++)
+ *pData++ = 0; //pstparam->CameraID[i];
+ *pData++ = 0; //pstparam->CamerapasswdFlag;
+ for(i=0;i<6;i++)
+ *pData++ = 0; //pstparam->Camerapasswd[i];
+
+ *pData++ = pstparam->SdLoop; //pstparam->SDcycleRecord;
+ *pData++ = 0; //pstparam->TriggerLogs;
+ *pData++ = pstparam->DateStyle; //pstparam->DateStyle;
+ *pData++ = pstparam->GPSFlag; //pstparam->GPSflag;
+ {
+ char stringGPS[21] = {0};
+ packet_gps_parse(stringGPS,pStaticParam);
+ MLOGD("stringGPS = [%s]\n",stringGPS);
+ for(i=0;i<21;i++)
+ *pData++ = stringGPS[i];
+ }
+
+
+ *pData++ = pstparam->BatteryType;
+ MLOGD("SendMaxNum = [%d],StampSwitch = [%d],SdLoop = [%d],\n GPSFlag = [%d],battery = [%d],DateStyle = [%d]\n",
+ pstparam->SendMaxNum,
+ pstparam->StampSwitch,
+ pstparam->SdLoop,
+ pstparam->GPSFlag,
+ pstparam->BatteryType,
+ pstparam->DateStyle);
+
+ break;
+
+ case SF_CMD_QUERYPENDING_SETSERVER:
+ break;
+
+ case SF_CMD_QUERYPENDING_UPLOADCFGFILE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETSERVERPAREAM:
+ MLOGD("AcmIP:%s\n", pStaticParam->AcmIP);
+ for(i=0;i<26;i++)
+ *pData++ = pStaticParam->AcmIP[i];
+ for(i=0;i<5;i++)
+ *pData++ = 0;
+ break;
+
+ case SF_CMD_QUERYPENDING_SETUPLOADPICSIZE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETUPLOADPICSIZE:
+ *pData++ = pstparam->SendPicSize;
+ break;
+
+ case SF_CMD_QUERYPENDING_SYNPARAM:
+ break;
+
+ case SF_CMD_QUERYPENDING_VERSIONUPDATE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETGPSINFO:
+ { char stringGPS[21] = {0};
+ packet_gps_parse(stringGPS,pStaticParam);
+ for(i=0;i<21;i++)
+ *pData++ = stringGPS[i];
+ }
+ break;
+
+ case SF_CMD_QUERYPENDING_SETGPSANTITHIEF:
+ *pData++ = pstparam->GPSAntitheftFlag;
+ break;
+ case SF_QUERYPENDING_COMMAND_RESET:
+ *pData++ = pstparam->ResetFlag;
+ break;
+ case SF_QUERYPENDING_COMMAND_FORMAT:
+ *pData++ = pstparam->FormateFlag;
+
+ break;
+ default:
+ break;
+
+ }
+ *pData++ = (rtcTime.Year>>8)&0XFF; //Year
+ *pData++ = rtcTime.Year&0xFF; //Year
+ *pData++ = rtcTime.Mon; //month
+ *pData++ = rtcTime.Day; //Day
+ *pData++ = rtcTime.Hour; //Hour
+ *pData++ = rtcTime.Min; //minute
+ *pData++ = rtcTime.Sec; //second
+ SLOGI("TIME:%d/%d/%d %d:%d:%d\n",rtcTime.Year, rtcTime.Mon, rtcTime.Day, rtcTime.Hour, rtcTime.Min, rtcTime.Sec);
+
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2,pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+ #if CS_DEBUG_INFO
+ MLOGD("[REPORT_RESULT] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+ #endif
+
+ return SF_SUCCESS;
+
+}
+SINT32 sf_packetgrouping_disconnection(SF_DATA_ATTR_S *pstdata,SF_VOID *Param)
+{
+ SF_COMM_CHECK_POINTER(pstdata,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pstdata->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(Param,SF_FAILURE);
+
+ UINT16 Crc=0;
+ UINT8 *pData = pstdata->databuf;
+
+ *pData++ = 0x55; //CMD
+ *pData++ = 0xAA;
+
+ *pData++ = Device_id[0];
+ *pData++ = Device_id[1];
+ *pData++ = Device_id[2];
+ *pData++ = Device_id[3];
+
+ *pData++ = 0x10; //CMD
+ *pData++ = 0x0c; //CMD
+ *pData++ = 0x00; //SEQ
+ *pData++ = 0x02; //seq
+
+ *pData++ = 0x00; //负载长度
+ *pData++ = 0x02; //负载长度
+
+ *pData++ = 0x00;//1
+ *pData++ =*(UINT8*)Param;
+
+
+ pstdata->databuf[10] = ((pData-(pstdata->databuf+12))>>8)&0XFF;
+ pstdata->databuf[11] = (pData-(pstdata->databuf+12))&0xFF;
+
+ Crc = makeCrc(pstdata->databuf+2,pData-(pstdata->databuf+2));
+ *pData++ = (UINT8)((Crc&0xff00)>>8);
+ *pData++ = (UINT8)((Crc&0x00ff));
+ *pData++ = 0xef;
+ *pData++ = 0xef;
+ *pData++ = 0x1a;
+ *pData++ = '\r';
+ *pData++ = '\0';
+ pstdata->dataSize = pData-pstdata->databuf;
+ #if CS_DEBUG_INFO
+ MLOGD("[DISCON_SEND] Send:\n");
+ packet_log_printf(pstdata->databuf,(pstdata->dataSize)-2);
+ #endif
+ return SF_SUCCESS;
+
+}
+
+SINT32 sf_MultiPacket_Parsing(UINT16 enCmdID,UINT16 *pdatahead,SF_DATA_ATTR_S *pdatattr)
+{
+ UINT16 i=0,j=0;
+ UINT16 cmdID=0;
+ UINT16 datahead[3] = {0};
+ UINT16 datatail[3] = {0};
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(pdatattr->databuf[i] == 0x55 && pdatattr->databuf[i+1] == 0xAA)
+ {
+ datahead[j] = i;
+ }
+ else if(pdatattr->databuf[i] == 0xEF && pdatattr->databuf[i+1] == 0xEF)
+ {
+ datatail[j] = i+1;
+ j++;
+ }
+ i++;
+ }
+
+ for(i=0;i<3;i++)
+ {
+ MLOGD("i= %d\n",i);
+ if(datahead[i] == 0)
+ continue;
+ if(datatail[i] == 0)
+ continue;
+ if((datatail[i]-datahead[i]+1) <= 4)
+ continue;
+
+ cmdID = (pdatattr->databuf[datahead[i]+6]<<8)+pdatattr->databuf[datahead[i]+7];
+ MLOGD("cmdID[%#X] != enCmdID[%#X] is %d\n",cmdID, enCmdID,cmdID != enCmdID);
+ if(cmdID != enCmdID)
+ continue;
+
+ *pdatahead = datahead[i];
+ pdatattr->dataSize = (datatail[i]-datahead[i]+1);
+ }
+
+ MLOGD("HEAD = %d,size :%d\n",*pdatahead,pdatattr->dataSize);
+ if(pdatattr->dataSize <= 4)
+ return SF_FAILURE;
+
+#if CS_DEBUG_INFO
+
+ MLOGD(" recv:\n");
+ packet_log_printf(&pdatattr->databuf[(*pdatahead)],pdatattr->dataSize);
+#endif
+ return SF_SUCCESS;
+
+
+}
+SINT32 sf_packetanalysis_login(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ SINT16 s16Ret = SF_SUCCESS;
+ UINT16 i=0;
+ UINT16 cmdID=0;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 result=0;
+ UINT16 head = 0;
+ UINT8 *pData = 0;
+
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ s16Ret = sf_MultiPacket_Parsing(0x1001,&head,param);
+ if(s16Ret != SF_SUCCESS)
+ return SF_DATA_ERROR_REQUEST;
+
+
+ pData = (UINT8*)param->databuf+head+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+
+ memset(pStaticParam->stOssCfg.szIP, '\0', sizeof(pStaticParam->stOssCfg.szIP));
+ memset(pStaticParam->stOssCfg.szBucket, '\0', sizeof(pStaticParam->stOssCfg.szBucket));
+ memset(pStaticParam->stOssCfg.szUsername, '\0', sizeof(pStaticParam->stOssCfg.szUsername));
+ memset(pStaticParam->stOssCfg.szPassword, '\0', sizeof(pStaticParam->stOssCfg.szPassword));
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; //cmd ID
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //payload len
+ result=*pData++; result = result<<8 | *pData++; //result
+
+ for(i=0;i<4;i++) //device ID
+ Device_id[i] = *pData++;
+ MLOGD("Device_id[0x%x,0x%x,0x%x,0x%x] \n",Device_id[0],Device_id[1],Device_id[2],Device_id[3]);
+ MLOGD("cmdID= 0x%x,len = 0x%x result = 0x%x \n",cmdID, len, result);
+
+ if(result == 1)
+ return SF_FAILURE;
+
+ pStaticParam->httpTime.Year = *pData++;
+ pStaticParam->httpTime.Year = pStaticParam->httpTime.Year <<8 | *pData++;
+ pStaticParam->httpTime.Mon = *pData++;
+ pStaticParam->httpTime.Day = *pData++;
+ pStaticParam->httpTime.Hour = *pData++;
+ pStaticParam->httpTime.Min = *pData++;
+ pStaticParam->httpTime.Sec = *pData++; //International standard time
+
+ UploadMode = *pData++; //upload mode
+
+ for(i=0;i<60;i++) //OSS_IP
+ pStaticParam->stOssCfg.szIP[i] = *pData++;
+ for(i=0;i<24;i++) //OSS_BUCKET
+ pStaticParam->stOssCfg.szBucket[i] = *pData++;
+ for(i=0;i<32;i++) //OSS_USENAME
+ pStaticParam->stOssCfg.szUsername[i] = *pData++;
+ for(i=0;i<48;i++) //OSS_PASSWORD
+ pStaticParam->stOssCfg.szPassword[i] = *pData++;
+
+ CanUpload = *pData++;
+ HasCommand = *pData++;
+
+ MLOGD("HasCommand =%d Canupload =%d updateMode =%d\n", HasCommand, CanUpload, UploadMode);
+
+ MLOGD("OSS_IP: [%s]\n",pStaticParam->stOssCfg.szIP);
+ MLOGD("OSS_BUCKET: [%s]\n",pStaticParam->stOssCfg.szBucket);
+ MLOGD("OSS_USENAME: [%s]\n",pStaticParam->stOssCfg.szUsername);
+ MLOGD("OSS_PASSWORD: [%s]\n",pStaticParam->stOssCfg.szPassword);
+ MLOGD("TIME:%d/%d/%d %d:%d:%d\n", pStaticParam->httpTime.Year, pStaticParam->httpTime.Mon, pStaticParam->httpTime.Day, pStaticParam->httpTime.Hour, pStaticParam->httpTime.Min, pStaticParam->httpTime.Sec);
+
+ rtcTime.Year = *pData++;
+ rtcTime.Year = rtcTime.Year <<8 | *pData++;
+ rtcTime.Mon = *pData++;
+ rtcTime.Day = *pData++;
+ rtcTime.Hour = *pData++;
+ rtcTime.Min = *pData++;
+ rtcTime.Sec = *pData++; //local time
+
+ SLOGD("TIME:%d/%d/%d %d:%d:%d\n", rtcTime.Year, rtcTime.Mon, rtcTime.Day, rtcTime.Hour, rtcTime.Min, rtcTime.Sec);
+ return result;
+
+}
+
+SINT32 sf_packetanalysis_fileresult(SF_DATA_ATTR_S *param)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+
+ UINT8 i = 0;
+ UINT8 Temp = 0;
+ UINT8 *pData = (UINT8*)param->databuf;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 cmdID = 0;
+ UINT16 result = 0;
+
+
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(param->databuf[i] == 0x55 && param->databuf[i+1] == 0xAA)
+ break;
+ i++;
+ }
+ if(i > SF_TTYUSB_RECV_MAX)
+ return SF_DATA_ERROR_REQUEST;
+
+ pData = (UINT8*)param->databuf+i;
+ Temp = i;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[PHOTO_RESULT] recv:\n");
+ packet_log_printf(pData,50);
+ #endif
+
+ pData = (UINT8*)param->databuf+Temp+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; // 回复的登录指令
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //负载长度
+ result=*pData++; result = result<<8 | *pData++; //错误码
+
+ MLOGD("cmdID= 0x%x,len = 0x%x result = 0x%x \n",cmdID, len, result);
+ if(result != 0)
+ return SF_DATA_ERROR_FILE_SEND;
+
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_packetanalysis_query_cmd(SF_DATA_ATTR_S *param)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+
+ UINT16 i=0;
+ UINT8 Temp = 0;
+ UINT8 *pData = (UINT8*)param->databuf;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 cmdID = 0;
+ UINT16 result = 0;
+
+
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(param->databuf[i] == 0x55 && param->databuf[i+1] == 0xAA)
+ break;
+ //printf("[SF_CMD_QUERYPENDING_CMD] recivedata[%d,0x%x]\n",i,param->databuf[i]);
+ i++;
+ }
+ if(i > SF_TTYUSB_RECV_MAX)
+ return SF_DATA_ERROR_REQUEST;
+
+ pData = (UINT8*)param->databuf+i;
+ Temp = i;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[QUERYPENDING_CMD] recv:\n");
+ packet_log_printf(pData,50);
+ #endif
+
+ pData = (UINT8*)param->databuf+Temp+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; // cam id
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //payload len
+ result =*pData++; result = result<<8 | *pData++; //result
+
+ MLOGD("cmdID= 0x%x,len = 0x%x result = 0x%x \n",cmdID,len,result);
+ if(cmdID != 0x1007)
+ return SF_DATA_ERROR_REQUEST;
+
+ if(result != 0)
+ return SF_DATA_ERROR_REQUEST;
+
+ PendingOrder = *pData++;
+ PendingOrder = PendingOrder <<8 | *pData++; /*pending order*/
+
+ //MLOGD("Command:0x%x \n", PendingOrder);
+
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_packetanalysis_query_cmd_param(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ UINT8 Temp = 0;
+ UINT8 *pData = (UINT8*)param->databuf;
+ UINT8 j= 0;
+ UINT16 i= 0;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 result=0;
+ UINT16 cmdID = 0;
+ UINT16 command = 0;
+ SINT16 s16Ret = SF_SUCCESS;
+ UINT16 temPir = 0;
+ SF_PDT_PARAM_CFG_S *pstparam = pfnParam->pstParam;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(param->databuf[i] == 0x55 && param->databuf[i+1] == 0xAA)
+ break;
+ i++;
+ }
+ if(i > SF_TTYUSB_RECV_MAX)
+ return SF_DATA_ERROR_REQUEST;
+ pData = (UINT8*)param->databuf+i;
+ Temp = i;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[QUERYPENDING_PARAM] recv:\n");
+ packet_log_printf(pData,(pstparam->ParaSync?50:200));
+ #endif
+
+ pData = (UINT8*)param->databuf+Temp+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; // 回复的登录指令
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //payload len
+ result = *pData++; result = result<<8 | *pData++; //result
+ command = *pData++; command = command <<8 | *pData++;
+
+ MLOGD("cmdID= 0x%x,len = 0x%x command = 0x%x,result = 0x%x \n",cmdID,len,command,result);
+ if(cmdID != 0x1009)
+ return SF_DATA_ERROR_REQUEST;
+
+
+ if(result != SF_SUCCESS)
+ return SF_DATA_ERROR_REQUEST;
+
+ ;
+ switch(command)
+ {
+ case SF_CMD_QUERYPENDING_GETCFGFILE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETPICTURE:/*get picture*/
+ pStaticParam->stSubscribe.subscribeCnt = 1;
+ pStaticParam->stSubscribe.pSubscribe = malloc(sizeof(SF_SUBSCRIBE_ATTR_S)*pStaticParam->stSubscribe.subscribeCnt);
+ for(i = 0;istSubscribe.subscribeCnt;i++)
+ {
+ pStaticParam->stSubscribe.pSubscribe[i].subscribeType = *pData++; /*how to get pic */
+ for(j=0;j<39;j++) /*filename*/
+ pStaticParam->stSubscribe.pSubscribe[i].subscribeFileName[j] = *pData++;
+ MLOGD("SubscribeType:%d, SubscribeFileName:%s\n",
+ pStaticParam->stSubscribe.pSubscribe[i].subscribeType,
+ pStaticParam->stSubscribe.pSubscribe[i].subscribeFileName);
+ }
+ break;
+
+ case SF_CMD_QUERYPENDING_GETSTATUS:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETSLEEPTIME:
+ break;
+
+ case SF_CMD_QUERYPENDING_REBOOT: /*reboot*/
+ break;
+
+ case SF_CMD_QUERYPENDING_SETSYSTEMTIME:
+ break;
+ case SF_CMD_QUERYPENDING_GETCAMERAMODE:
+ break;
+ case SF_CMD_QUERYPENDING_SETCAMERAMODE:
+ pstparam->CamMode = (*pData++) - 1;
+ pstparam->ImgSize = (*pData++);
+ pstparam->Multishot = *pData++;
+ pstparam->Zoom = (*pData++) - 1;
+ pstparam->VideoSize = (*pData++) - 1;
+ pstparam->VideoLenth = *pData++;
+ pstparam->VideoFrame = *pData++;
+ pstparam->LightFreq = *pData++;
+
+ MLOGD("CameraMode = [%d],ImgSize = [%d],Multishot = [%d],Zoom = [%d],\n "
+ "VideoSize = [%d],VideoLenth = [%d],VideoFrame = [%d],LightFreq = [%d]\n",
+ pstparam->CamMode,
+ pstparam->ImgSize,
+ pstparam->Multishot,
+ pstparam->Zoom,
+ pstparam->VideoSize,
+ pstparam->VideoLenth,
+ pstparam->VideoFrame,
+ pstparam->LightFreq);
+ break;
+
+ case SF_CMD_QUERYPENDING_SETWORKMODE:
+ pstparam->TimelapseSwitch = *pData++;
+ pstparam->TimelapseTime.Hour = ((*pData++)-'0')*10;
+ pstparam->TimelapseTime.Hour += (*pData++)-'0';
+ pstparam->TimelapseTime.Min = ((*pData++)-'0')*10;
+ pstparam->TimelapseTime.Min += (*pData++)-'0';
+ pstparam->TimelapseTime.Sec = ((*pData++)-'0')*10;
+ pstparam->TimelapseTime.Sec += (*pData++)-'0';
+
+ temPir = *pData++;
+
+ pstparam->DigitPirSensitivity = temPir;
+ if(pstparam->DigitPirSensitivity == 0)
+ pstparam->PirSwitch = 0;
+ else
+ pstparam->PirSwitch = 1;
+
+ pstparam->PirSensitivity = sf_pir_to_digit_analog(pstparam->DigitPirSensitivity);
+
+ pstparam->PirDelaySwitch = *pData++;
+ pstparam->PirDelayTime.Hour = ((*pData++)-'0')*10;
+ pstparam->PirDelayTime.Hour += (*pData++)-'0';
+ pstparam->PirDelayTime.Min = ((*pData++)-'0')*10;
+ pstparam->PirDelayTime.Min += (*pData++)-'0';
+ pstparam->PirDelayTime.Sec = ((*pData++)-'0')*10;
+ pstparam->PirDelayTime.Sec += (*pData++)-'0';
+
+ pstparam->WorkTime1Switch = *pData++;
+ pstparam->WorkTime[0].StartTime.Hour = ((*pData++)-'0')*10;
+ pstparam->WorkTime[0].StartTime.Hour += (*pData++)-'0';
+ pstparam->WorkTime[0].StartTime.Min = ((*pData++)-'0')*10;
+ pstparam->WorkTime[0].StartTime.Min += (*pData++)-'0';
+ pData++;
+ pstparam->WorkTime[0].StopTime.Hour = ((*pData++)-'0')*10;
+ pstparam->WorkTime[0].StopTime.Hour += (*pData++)-'0';
+ pstparam->WorkTime[0].StopTime.Min = ((*pData++)-'0')*10;
+ pstparam->WorkTime[0].StopTime.Min += (*pData++)-'0';
+
+ pstparam->WorkTime2Switch = *pData++;
+ pstparam->WorkTime[1].StartTime.Hour = ((*pData++)-'0')*10;
+ pstparam->WorkTime[1].StartTime.Hour += (*pData++)-'0';
+ pstparam->WorkTime[1].StartTime.Min = ((*pData++)-'0')*10;
+ pstparam->WorkTime[1].StartTime.Min += (*pData++)-'0';
+ pData++;
+ pstparam->WorkTime[1].StopTime.Hour = ((*pData++)-'0')*10;
+ pstparam->WorkTime[1].StopTime.Hour += (*pData++)-'0';
+ pstparam->WorkTime[1].StopTime.Min = ((*pData++)-'0')*10;
+ pstparam->WorkTime[1].StopTime.Min += (*pData++)-'0';
+
+ temPir = *pData++;
+ if(temPir == 0)
+ {
+ pstparam->PirSwitch = 0;
+ pstparam->DigitPirSensitivity = 0;
+ }
+
+ pstparam->DailyReportswitch = *pData++;
+ pstparam->DailyReportTime.Hour = ((*pData++)-'0')*10;
+ pstparam->DailyReportTime.Hour += (*pData++)-'0';
+ pstparam->DailyReportTime.Min = ((*pData++)-'0')*10;
+ pstparam->DailyReportTime.Min += (*pData++)-'0';
+
+
+ pstparam->NightMode = *pData++; /*0: max 1: balance 2:Min*/
+ pstparam->GprsMode = *pData++; /*0: trigger 1: all time*/
+ pstparam->FlashLed = *pData++; /*0: all(default) 1: part*/
+ pstparam->SendVideo = *pData++; /*0: no 1: yes*/
+ pstparam->SendPhoto = *pData++; /*0: no 1: yes*/
+
+ pstparam->SendMultishot = *pData++;
+ if(pstparam->DailyReportswitch == 0)
+ {
+ if(pstparam->DailyReportTime.Hour == 0 &&
+ pstparam->DailyReportTime.Min == 0)
+ {
+ pstparam->GprsMode = 1;/*realtime*/
+ }
+ else
+ {
+ pstparam->GprsMode = 0;/*off*/
+ }
+ }
+ else
+ {
+
+ if((pstparam->DailyReportTime.Hour == 0) && (pstparam->DailyReportTime.Min == 30))
+ {
+ pstparam->GprsMode = 2;
+ }
+ else if((pstparam->DailyReportTime.Hour == 1) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 3;
+ }
+ else if((pstparam->DailyReportTime.Hour == 2) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 4;
+ }
+ else if((pstparam->DailyReportTime.Hour == 3) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 5;
+ }
+ else if((pstparam->DailyReportTime.Hour == 4) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 6;
+ }
+ else if((pstparam->DailyReportTime.Hour == 6) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 7;
+ }
+ else if((pstparam->DailyReportTime.Hour == 12) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 8;
+ }
+ else if((pstparam->DailyReportTime.Hour == 24) && (pstparam->DailyReportTime.Min == 0))
+ {
+ pstparam->GprsMode = 9;
+ }
+ }
+
+ MLOGD("senmutilshot = [%d]\n", pstparam->SendMultishot);
+ MLOGD("pir = [%d-%d-%d]\n", pstparam->PirSwitch, pstparam->PirSensitivity, pstparam->DigitPirSensitivity);
+ MLOGD("timelapsepic = [%d,%02d:%02d:%02d]\n", pstparam->TimelapseSwitch,
+ pstparam->TimelapseTime.Hour,
+ pstparam->TimelapseTime.Min,
+ pstparam->TimelapseTime.Sec);
+ MLOGD("delaypic = [%d,%02d:%02d:%02d]\n", pstparam->PirDelaySwitch,
+ pstparam->PirDelayTime.Hour,
+ pstparam->PirDelayTime.Min,
+ pstparam->PirDelayTime.Sec);
+ MLOGD("dailypic = [%d,%02d:%02d:%02d]\n",pstparam->DailyReportswitch,
+ pstparam->DailyReportTime.Hour,
+ pstparam->DailyReportTime.Min,
+ pstparam->DailyReportTime.Sec);
+ MLOGD("WorkTime[0] = [%d,%02d:%02d-%02d:%02d]\n", pstparam->WorkTime1Switch,
+ pstparam->WorkTime[0].StartTime.Hour,
+ pstparam->WorkTime[0].StartTime.Min,
+ pstparam->WorkTime[0].StopTime.Hour,
+ pstparam->WorkTime[0].StopTime.Min);
+ MLOGD("WorkTime[1] = [%d,%02d:%02d-%02d:%02d]\n", pstparam->WorkTime2Switch,
+ pstparam->WorkTime[1].StartTime.Hour,
+ pstparam->WorkTime[1].StartTime.Min,
+ pstparam->WorkTime[1].StopTime.Hour,
+ pstparam->WorkTime[1].StopTime.Min);
+
+
+
+
+ break;
+ case SF_CMD_QUERYPENDING_SETOTHER:
+ pstparam->SendMaxNum = *pData++; //pstparam->MmsMax;
+ pData++; //pstparam->Tvout;
+ pData++; //pstparam->Audiorecord;
+ pstparam->StampSwitch = *pData++; //pstparam->Stamp;
+ pData++; //pstparam->Startuptone;
+ pData++; //pstparam->Keyboard;
+ pData++; //pstparam->CameraIDflag;
+ for(i=0;i<13;i++)
+ pData++; //pstparam->CameraID[i];
+ pData++; //pstparam->CamerapasswdFlag;
+ for(i=0;i<6;i++)
+ pData++; //pstparam->Camerapasswd[i];
+
+ pstparam->SdLoop = *pData++; //pstparam->SDcycleRecord;
+ pData++ ;//pstparam->TriggerLogs;
+ pstparam->DateStyle = *pData++ ;//pstparam->DateStyle;
+ pstparam->GPSFlag = *pData++ ;
+ //pstparam->GPSFlag = 1 ;
+ for(i=0;i<21;i++)
+ pData++;//pstparam->GPSInfo[i];
+
+ MLOGD("SendMaxNum = [%d], StampSwitch = [%d], SdLoop = [%d] \n GPSFlag = [%d] DateStyle = [%d]\n",
+ pstparam->SendMaxNum,
+ pstparam->StampSwitch,
+ pstparam->SdLoop,
+ pstparam->GPSFlag,
+ pstparam->DateStyle);
+
+
+ pstparam->BatteryType = (*pData++) ;
+ MLOGD("battery = %d\n",pstparam->BatteryType);
+ break;
+
+ case SF_CMD_QUERYPENDING_SETSERVER:
+ break;
+
+ case SF_CMD_QUERYPENDING_UPLOADCFGFILE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETMODECFG:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETOTHERCFG:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETSERVERPAREAM:
+ MLOGD("\n");
+ break;
+
+ case SF_CMD_QUERYPENDING_SETUPLOADPICSIZE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETUPLOADPICSIZE:
+ break;
+ case SF_CMD_QUERYPENDING_SYNPARAM:
+ pstparam->ParaSync = *pData++;
+ MLOGD("ParaSync = [%d]\n", pstparam->ParaSync);
+ break;
+
+ case SF_CMD_QUERYPENDING_VERSIONUPDATE:
+ break;
+
+ case SF_CMD_QUERYPENDING_GETGPSINFO:
+ break;
+
+ case SF_CMD_QUERYPENDING_SETGPSANTITHIEF:
+ pstparam->GPSAntitheftFlag = *pData++;
+ break;
+ case SF_QUERYPENDING_COMMAND_RESET:
+ pstparam->ResetFlag = *pData++;
+ break;
+ case SF_QUERYPENDING_COMMAND_FORMAT:
+
+ pstparam->FormateFlag = *pData++;
+
+ break;
+ default:
+ break;
+
+ }
+
+ return s16Ret;
+
+}
+
+
+SINT32 sf_packetanalysis_trigger(SF_DATA_ATTR_S *param, SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+
+ UINT8 i = 0;
+ UINT8 Temp = 0;
+ UINT8 *pData = (UINT8*)param->databuf;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 cmdID = 0;
+ UINT16 result = 0;
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(param->databuf[i] == 0x55 && param->databuf[i+1] == 0xAA)
+ break;
+ i++;
+ }
+ if(i > SF_TTYUSB_RECV_MAX)
+ return SF_DATA_ERROR_REQUEST;
+
+ pData = (UINT8*)param->databuf+i;
+ Temp = i;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[TRIGGER] recv:\n");
+ packet_log_printf(pData,50);
+ #endif
+
+ pData = (UINT8*)param->databuf+Temp+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; // 回复的指令
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //负载长度
+ result =*pData++; result = result<<8 | *pData++; //错误码
+
+ MLOGD("cmdID= 0x%x,len = 0x%x GetPicFlag = 0x%x \n",cmdID, len, result);
+ if(cmdID != 0x100d)
+ return SF_DATA_ERROR_REQUEST;
+// if(result != 0)
+// return SF_TCP_ERROR_UPLOAD_FILE_INFO;
+ pStaticParam->u8GetPicFlag = result;
+
+ return SF_SUCCESS;
+
+}
+
+SINT32 sf_packetanalysis_bind_account(SF_DATA_ATTR_S *param,SF_FN_PARAM_S *pfnParam)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(pfnParam->pstaticParam,SF_FAILURE);
+ UINT8 i = 0;
+ UINT8 Temp = 0;
+ UINT8 *pData = (UINT8*)param->databuf;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 cmdID = 0;
+ UINT16 result = 0;
+
+ SF_PDT_PARAM_STATISTICS_S *pStaticParam = pfnParam->pstaticParam;
+
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(param->databuf[i] == 0x55 && param->databuf[i+1] == 0xAA)
+ break;
+ i++;
+ }
+ if(i > SF_TTYUSB_RECV_MAX)
+ return SF_DATA_ERROR_REQUEST;
+
+ pData = (UINT8*)param->databuf+i;
+ Temp = i;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[BIND_ACCOUNT] recv:\n");
+ packet_log_printf(pData,50);
+ #endif
+
+ pData = (UINT8*)param->databuf+Temp+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; // 回复的指令
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //负载长度
+ result =*pData++; result = result<<8 | *pData++; //reuslt
+
+ MLOGD("cmdID= 0x%x,len = 0x%x result = 0x%x \n",cmdID, len, result);
+ if(cmdID != 0x100e)
+ return SF_DATA_ERROR_REQUEST;
+
+ if(result != 0)
+ return SF_DATA_ERROR_FILE_SEND;
+
+ pStaticParam->bindFlag = *pData++;
+
+ for(i=0;i<50;i++) /*filename*/
+ pStaticParam->BindAccount[i] = *pData++;
+ MLOGD("bindFlag:%d, BindAccount:%s\n", pStaticParam->bindFlag, pStaticParam->BindAccount);
+
+ return SF_SUCCESS;
+
+}
+
+
+SINT32 sf_packetanalysis_cmd_report(SF_DATA_ATTR_S *param)
+{
+ SF_COMM_CHECK_POINTER(param,SF_FAILURE);
+ SF_COMM_CHECK_POINTER(param->databuf,SF_FAILURE);
+ UINT8 i=0;
+ UINT8 Temp = 0;
+ UINT8 *pData = (UINT8*)param->databuf;
+ UINT16 seq = 0;
+ UINT16 len = 0;
+ UINT16 cmdID = 0;
+ UINT16 result = 0;
+ UINT16 command = 0;
+
+ while(i < SF_TTYUSB_RECV_MAX)
+ {
+ if(param->databuf[i] == 0x55 && param->databuf[i+1] == 0xAA)
+ break;
+ i++;
+ }
+
+ if(i > SF_TTYUSB_RECV_MAX)
+ return SF_DATA_ERROR_REQUEST;
+
+ pData = (UINT8*)param->databuf+i;
+ Temp = i;
+
+ #if CS_DEBUG_INFO
+ MLOGD("[REPORT_RESULT] recv:\n");
+ packet_log_printf(pData,50);
+ #endif
+
+ pData = (UINT8*)param->databuf+Temp+6;
+
+ if(pData == SF_NULL)
+ return SF_DATA_ERROR_REQUEST;
+
+ cmdID = *pData++; cmdID = cmdID <<8 | *pData++; // cam id
+ seq = *pData++; seq = seq <<8 | *pData++;
+ len = *pData++; len = len <<8 | *pData++; //payload len
+ result = *pData++; result = result<<8 | *pData++; //result
+
+ MLOGD("cmdID= 0x%x,len = 0x%x result = 0x%x \n",cmdID,len,result);
+ if(cmdID != 0x100B)
+ return SF_DATA_ERROR_REQUEST;
+
+ if(result != 0)
+ return SF_DATA_ERROR_REQUEST;
+
+ command = *pData++;
+ command = command <<8 | *pData++;
+
+ //MLOGD("command= 0x%x\n", command);
+ return SF_SUCCESS;
+
+}
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+
diff --git a/code/application/source/sf_app/code/source/debugMng/sf_debug.c b/code/application/source/sf_app/code/source/debugMng/sf_debug.c
new file mode 100755
index 000000000..a4d5e84ac
--- /dev/null
+++ b/code/application/source/sf_app/code/source/debugMng/sf_debug.c
@@ -0,0 +1,140 @@
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include