Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2m_crypto.h Source File

m2m_crypto.h

Go to the documentation of this file.
00001 /**
00002  *
00003  * \file
00004  *
00005  * \brief WINC Crypto Application Interface.
00006  *
00007  * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved.
00008  *
00009  * \asf_license_start
00010  *
00011  * \page License
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. The name of Atmel may not be used to endorse or promote products derived
00024  *    from this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00027  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00028  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00029  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
00030  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00032  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00033  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00034  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00035  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * \asf_license_stop
00039  *
00040  */
00041 
00042 #ifndef __M2M_CRYPTO_H__
00043 #define __M2M_CRYPTO_H__
00044 
00045 
00046 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00047 INCLUDES
00048 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00049 
00050 
00051 #include "common/include/nm_common.h"
00052 #include "driver/include/m2m_types.h"
00053 #include "driver/source/m2m_hif.h"
00054 
00055 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00056 MACROS
00057 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00058 #define M2M_MAX_RSA_LEN                 (256)
00059 #define M2M_SHA256_DIGEST_LEN           32
00060 #define M2M_SHA256_MAX_DATA             (M2M_BUFFER_MAX_SIZE - M2M_SHA256_CONTEXT_BUFF_LEN - M2M_HIF_HDR_OFFSET)
00061 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00062 DATA TYPES
00063 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00064 
00065 /*!
00066 @struct \
00067     tstrM2mSha256Ctxt
00068 
00069 @brief
00070     SHA256 context data
00071 */
00072 typedef struct sha256ctxt{
00073     uint32  au32Sha256CtxtBuff[M2M_SHA256_CONTEXT_BUFF_LEN/sizeof(uint32)];
00074 } tstrM2mSha256Ctxt;
00075 
00076 
00077 
00078 /*!
00079 @enum   \
00080     tenuRsaSignStatus
00081 
00082 @brief
00083     RSA Signature status: pass or fail.
00084     
00085 @see
00086     m2m_crypto_rsa_sign_gen
00087 */
00088 typedef enum{
00089     M2M_RSA_SIGN_OK,
00090     M2M_RSA_SIGN_FAIL
00091 } tenuRsaSignStatus;
00092 
00093 /*!
00094 @typedef \
00095     tpfAppCryproCb
00096 
00097 @brief          Crypto Calback function receiving the crypto related messages
00098 @param [in] u8MsgType
00099                 Crypto command about which the notification is received.
00100 @param [in] pvResp
00101                 A pointer to the result associated with the notification.               
00102 @param [in] pvMsg
00103                 A pointer to a buffer containing the notification parameters (if any). It should be
00104                 Casted to the correct data type corresponding to the notification type.
00105 @see
00106     m2m_crypto_init
00107     tenuM2mCryptoCmd
00108 */
00109 typedef void (*tpfAppCryproCb) (uint8 u8MsgType,void * pvResp, void * pvMsg);
00110 
00111 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00112 FUNCTION PROTOTYPES
00113 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00114 
00115 
00116 #ifdef __cplusplus
00117      extern "C" {
00118 #endif
00119 /*!
00120 @fn \
00121     sint8 m2m_crypto_init();
00122     
00123 @brief  crypto initialization.
00124 
00125 @param[in]  pfAppCryproCb
00126                 Pointer to the Crypto Calback function receiving the crypto related messages.
00127 @see
00128     tpfAppCryproCb
00129     
00130 @return     
00131     The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
00132 */
00133 sint8 m2m_crypto_init(tpfAppCryproCb pfAppCryproCb);
00134 /*!
00135 @fn \
00136     sint8 m2m_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt);
00137     
00138 @brief  SHA256 hash initialization
00139 
00140 @param[in]  psha256Ctxt
00141                 Pointer to a sha256 context allocated by the caller.                
00142 @return     
00143     The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
00144 */
00145 sint8 m2m_crypto_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt);
00146 
00147 
00148 /*!
00149 @fn \
00150     sint8 m2m_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength);
00151     
00152 @brief  SHA256 hash update
00153 
00154 @param [in] psha256Ctxt
00155                 Pointer to the sha256 context.
00156                 
00157 @param [in] pu8Data
00158                 Buffer holding the data submitted to the hash.
00159                 
00160 @param [in] u16DataLength
00161                 Size of the data bufefr in bytes.
00162 @pre SHA256 module should be initialized first through m2m_crypto_sha256_hash_init function.
00163 
00164 @see m2m_crypto_sha256_hash_init
00165 
00166 @return     
00167     The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
00168 
00169 */
00170 sint8 m2m_crypto_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength);
00171 
00172 
00173 /*!
00174 @fn \
00175     sint8 m2m_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest);
00176     
00177 @brief  SHA256 hash finalization
00178 
00179 @param[in]  psha256Ctxt
00180                 Pointer to a sha256 context allocated by the caller.
00181                 
00182 @param [in] pu8Sha256Digest
00183                 Buffer allocated by the caller which will hold the resultant SHA256 Digest. It must be allocated no less than M2M_SHA256_DIGEST_LEN.
00184                 
00185 @return     
00186     The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
00187 */
00188 sint8 m2m_crypto_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest);
00189 
00190 
00191 /*!
00192 @fn \
00193     sint8 m2m_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, \
00194         uint16 u16HashLength, uint8 *pu8RsaSignature);
00195     
00196 @brief  RSA Signature Verification
00197 
00198     The function shall request the RSA Signature verification from the WINC Firmware for the given message. The signed message shall be 
00199     compressed to the corresponding hash algorithm before calling this function.
00200     The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256.
00201 
00202 @param[in]  pu8N
00203                 RSA Key modulus n.
00204                 
00205 @param[in]  u16NSize
00206                 Size of the RSA modulus n in bytes.
00207                 
00208 @param[in]  pu8E
00209                 RSA public exponent.
00210                 
00211 @param[in]  u16ESize
00212                 Size of the RSA public exponent in bytes.
00213 
00214 @param[in]  pu8SignedMsgHash
00215                 The hash digest of the signed message.
00216                 
00217 @param[in]  u16HashLength
00218                 The length of the hash digest.
00219                 
00220 @param[out] pu8RsaSignature
00221                 Signature value to be verified.
00222                 
00223 @return     
00224     The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
00225 */
00226 sint8 m2m_crypto_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, 
00227                           uint16 u16HashLength, uint8 *pu8RsaSignature);
00228 
00229 
00230 /*!
00231 @fn \
00232     sint8 m2m_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, \
00233         uint16 u16HashLength, uint8 *pu8RsaSignature);
00234     
00235 @brief  RSA Signature Generation
00236 
00237     The function shall request the RSA Signature generation from the WINC Firmware for the given message. The signed message shall be 
00238     compressed to the corresponding hash algorithm before calling this function.
00239     The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256.
00240 
00241 @param[in]  pu8N
00242                 RSA Key modulus n.
00243                 
00244 @param[in]  u16NSize
00245                 Size of the RSA modulus n in bytes.
00246                 
00247 @param[in]  pu8d
00248                 RSA private exponent.
00249                 
00250 @param[in]  u16dSize
00251                 Size of the RSA private exponent in bytes.
00252 
00253 @param[in]  pu8SignedMsgHash
00254                 The hash digest of the signed message.
00255                 
00256 @param[in]  u16HashLength
00257                 The length of the hash digest.
00258                 
00259 @param[out] pu8RsaSignature
00260                 Pointer to a user buffer allocated by teh caller shall hold the generated signature.
00261                 
00262 @return     
00263     The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
00264 */
00265 sint8 m2m_crypto_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, 
00266                        uint16 u16HashLength, uint8 *pu8RsaSignature);
00267 #ifdef __cplusplus
00268 }
00269 #endif
00270 
00271 
00272 #endif /* __M2M_CRYPTO_H__ */
00273 
00274