ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1
TMBOY 47:9e361da97763 2 #ifndef _MBEDPACK_VERIFICATION_H
TMBOY 47:9e361da97763 3 #define _MBEDPACK_VERIFICATION_H
TMBOY 47:9e361da97763 4
TMBOY 47:9e361da97763 5 #include "mbedtls/rsa.h"
TMBOY 47:9e361da97763 6 #include "mbedtls/sha1.h"
TMBOY 47:9e361da97763 7 #include "pack_include.h"
TMBOY 47:9e361da97763 8
TMBOY 47:9e361da97763 9 typedef struct _verification_context_ {
TMBOY 47:9e361da97763 10 // internal footprint
TMBOY 47:9e361da97763 11 uint32_t stream_recieved_sz; // current size of recieved stream
TMBOY 47:9e361da97763 12 uint32_t stream_processed_sz; // current size of processed stream
TMBOY 47:9e361da97763 13 uint32_t stream_sig_stored_sz; // size of pck_header_sig_part
TMBOY 47:9e361da97763 14 unsigned char* pck_header_sig_part; // package header buffer to pck signature(include), for verify use
TMBOY 47:9e361da97763 15
TMBOY 47:9e361da97763 16 // sha1 context
TMBOY 47:9e361da97763 17 mbedtls_sha1_context* ctx;
TMBOY 47:9e361da97763 18
TMBOY 47:9e361da97763 19 } verification_context_t;
TMBOY 47:9e361da97763 20
TMBOY 47:9e361da97763 21 /**
TMBOY 47:9e361da97763 22 * init rsa context
TMBOY 47:9e361da97763 23 *
TMBOY 47:9e361da97763 24 * \param rsa_ctx point to an instance of mbedtls_rsa_context struct
TMBOY 47:9e361da97763 25 * \return 0 if success, or failed
TMBOY 47:9e361da97763 26 */
TMBOY 47:9e361da97763 27 int mbed_rsa_ca_pkcs1_init(mbedtls_rsa_context* rsa_ctx);
TMBOY 47:9e361da97763 28
TMBOY 47:9e361da97763 29 /**
TMBOY 47:9e361da97763 30 * uinit rsa context
TMBOY 47:9e361da97763 31 *
TMBOY 47:9e361da97763 32 * \param rsa_ctx point to an instance of mbedtls_rsa_context struct
TMBOY 47:9e361da97763 33 */
TMBOY 47:9e361da97763 34 void mbed_rsa_ca_pkcs1_uninit(mbedtls_rsa_context* rsa_ctx);
TMBOY 47:9e361da97763 35
TMBOY 47:9e361da97763 36 ///////////////////////////////////////////////////////////////////////////////////////
TMBOY 47:9e361da97763 37
TMBOY 47:9e361da97763 38 /**
TMBOY 47:9e361da97763 39 * verification init
TMBOY 47:9e361da97763 40 *
TMBOY 47:9e361da97763 41 * \return verification context if success, or NULL
TMBOY 47:9e361da97763 42 */
TMBOY 47:9e361da97763 43 verification_context_t* mbed_hash_init();
TMBOY 47:9e361da97763 44
TMBOY 47:9e361da97763 45 /**
TMBOY 47:9e361da97763 46 * verification update key
TMBOY 47:9e361da97763 47 *
TMBOY 47:9e361da97763 48 * \param ctx verification context
TMBOY 47:9e361da97763 49 * \param buffer data source to gen hash
TMBOY 47:9e361da97763 50 * \param buffer_size
TMBOY 47:9e361da97763 51 */
TMBOY 47:9e361da97763 52 void mbed_hash_update_key(verification_context_t* ctx, unsigned char* buffer, uint32_t buffer_size);
TMBOY 47:9e361da97763 53
TMBOY 47:9e361da97763 54 /**
TMBOY 47:9e361da97763 55 * verify key
TMBOY 47:9e361da97763 56 *
TMBOY 47:9e361da97763 57 * \param ctx verification context
TMBOY 47:9e361da97763 58 * \param buffer data source to gen hash
TMBOY 47:9e361da97763 59 * \param buffer_size
TMBOY 47:9e361da97763 60 *
TMBOY 47:9e361da97763 61 * \return 0 if success, or failed
TMBOY 47:9e361da97763 62 */
TMBOY 47:9e361da97763 63 int mbed_rsa_ca_pkcs1_verify(mbedtls_rsa_context* rsa, verification_context_t* ctx);
TMBOY 47:9e361da97763 64
TMBOY 47:9e361da97763 65 /**
TMBOY 47:9e361da97763 66 * verification uninit
TMBOY 47:9e361da97763 67 *
TMBOY 47:9e361da97763 68 * \param ctx verification context
TMBOY 47:9e361da97763 69 */
TMBOY 47:9e361da97763 70 void mbed_hash_uninit(verification_context_t* ctx);
TMBOY 47:9e361da97763 71
TMBOY 47:9e361da97763 72 #endif
TMBOY 47:9e361da97763 73