Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
kal_crypto.h
00001 /// @copyright 00002 /// ========================================================================={{{ 00003 /// Copyright (c) 20XX / 00004 /// All rights reserved / 00005 /// / 00006 /// IMPORTANT: This Software may not be modified, copied or distributed unless / 00007 /// embedded on a WizziLab product. Other than for the foregoing purpose, this / 00008 /// Software and/or its documentation may not be used, reproduced, copied, / 00009 /// prepared derivative works of, modified, performed, distributed, displayed / 00010 /// or sold for any purpose. For the sole purpose of embedding this Software / 00011 /// on a WizziLab product, copy, modification and distribution of this / 00012 /// Software is granted provided that the following conditions are respected: / 00013 /// / 00014 /// * Redistributions of source code must retain the above copyright notice, / 00015 /// this list of conditions and the following disclaimer / 00016 /// / 00017 /// * Redistributions in binary form must reproduce the above copyright / 00018 /// notice, this list of conditions and the following disclaimer in the / 00019 /// documentation and/or other materials provided with the distribution. / 00020 /// / 00021 /// * The name of WizziLab can not be used to endorse or promote products / 00022 /// derived from this software without specific prior written permission. / 00023 /// / 00024 /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS / 00025 /// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED / 00026 /// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR / 00027 /// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR / 00028 /// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, / 00029 /// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, / 00030 /// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, / 00031 /// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY / 00032 /// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING / 00033 /// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS / 00034 /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. / 00035 /// WIZZILAB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, / 00036 /// ENHANCEMENTS OR MODIFICATIONS. / 00037 /// / 00038 /// Should you have any questions regarding your right to use this Software, / 00039 /// contact WizziLab at www.wizzilab.com. / 00040 /// / 00041 /// =========================================================================}}} 00042 /// @endcopyright 00043 00044 // ======================================================================= 00045 /// @file kal_crypto.h 00046 /// @brief KAL Crypto utilities 00047 // ======================================================================= 00048 00049 #ifndef _KAL_CRYPTO_H_ 00050 #define _KAL_CRYPTO_H_ 00051 00052 #include "hal_types.h" 00053 00054 // ====================================================================== 00055 // 00056 // 00057 // SHA-2 256 Tool-suite. 00058 // (From Brad Conte's Licence-free implementation) 00059 // 00060 // 00061 // ====================================================================== 00062 00063 /// SHA256 digest output size in bytes 00064 #define SHA256_BLOCK_SIZE 32 00065 00066 //====================================================================== 00067 // kal_sha256_init 00068 //---------------------------------------------------------------------- 00069 /// @brief Initialize an SHA Hash generation. To be called before any 00070 /// other kal_sha256_update/final functions. 00071 //====================================================================== 00072 _public void kal_sha256_init(void); 00073 00074 //====================================================================== 00075 // kal_sha256_update 00076 //---------------------------------------------------------------------- 00077 /// @brief Used to 'push' new data into the hash calculation. 00078 /// @param data pointer to the (char) data stream to hash. 00079 /// @param len data stream length in bytes 00080 //====================================================================== 00081 _public void kal_sha256_update(u8 data[], uint len); 00082 00083 //====================================================================== 00084 // kal_sha256_final 00085 //---------------------------------------------------------------------- 00086 /// @brief To be called when all data has been pushed into the hash 00087 /// generator. Finalize and outputs resulting SHA hash. 00088 /// @param hash Pointer to the Output (char) buffer. Fills 32-bytes. 00089 //====================================================================== 00090 _public void kal_sha256_final(u8 hash[]); 00091 00092 // ====================================================================== 00093 // 00094 // 00095 // CBC-MAC / CTR / CCM Tool-suite. 00096 // 00097 // 00098 // ====================================================================== 00099 00100 //====================================================================== 00101 // kal_aes128_init 00102 //---------------------------------------------------------------------- 00103 /// @brief Perform Key expansion 00104 /// @param key const u8* encryption key 00105 /// @retval void 00106 //====================================================================== 00107 _public void kal_aes128_init(u8* key); 00108 00109 //====================================================================== 00110 // kal_aes128_ecb 00111 //---------------------------------------------------------------------- 00112 /// @brief Encrypt / decrypt in ECB mode (non chaining). 00113 /// @param p u8* payload inout 00114 /// p(i) = cipher(p(i), key) 00115 /// @param len u16 payload length 00116 /// @retval void 00117 //====================================================================== 00118 _public void kal_aes128_ecb(u8* p, u16 len); 00119 00120 //====================================================================== 00121 // kal_aes128_ctr 00122 //---------------------------------------------------------------------- 00123 /// @brief Encrypt / decrypt in CTR mode (non chaining). 00124 /// Note : only 1 byte counter is supported. 00125 /// @param p u8* payload inout 00126 /// p(i) = cipher(iv+i, key) ^ p(i) 00127 /// @param len u16 payload length 00128 /// @param iv u8* counter IV (returns next value) 00129 /// @param be u8 counter endianness (byte15 is lsb when TRUE, otherwise byte0) 00130 /// @retval void 00131 //====================================================================== 00132 _public void kal_aes128_ctr(u8* p, u16 len, u8* iv, u8 be); 00133 00134 //====================================================================== 00135 // kal_aes128_cbc_mac 00136 //---------------------------------------------------------------------- 00137 /// @brief Generate MAC with block-chaining 00138 /// @param mac u8* MAC 16-bytes inout 00139 /// @param p u8* payload 00140 /// @param len u16 payload length 00141 /// @retval void 00142 //====================================================================== 00143 _public void kal_aes128_cbc_mac(u8* mac, u8* p, u16 len); 00144 00145 //====================================================================== 00146 // kal_aes128_cmac_next 00147 //---------------------------------------------------------------------- 00148 /// @brief Execute CMAC algorithm on a entire number of 16-byte blocks, 00149 /// not including the last block. 00150 /// @param mac u8* MAC 16-bytes inout 00151 /// @param p u8* payload 00152 /// @param len u16 payload length 00153 /// @retval void 00154 //====================================================================== 00155 _public void kal_aes128_cmac_next(u8* mac, u8* p, u16 len); 00156 00157 //====================================================================== 00158 // kal_aes128_cmac_last 00159 //---------------------------------------------------------------------- 00160 /// @brief Execute CMAC algorithm on any size and finalize. 00161 /// @param mac u8* MAC 16-bytes inout 00162 /// @param p u8* payload 00163 /// @param len u16 payload length 00164 /// @retval void 00165 //====================================================================== 00166 _public void kal_aes128_cmac_last(u8* mac, u8* p, u16 len); 00167 00168 // ====================================================================== 00169 // 00170 // 00171 // SIPHASH-2-4 00172 // 00173 // 00174 // ====================================================================== 00175 00176 //====================================================================== 00177 // kal_siphash24 00178 //---------------------------------------------------------------------- 00179 /// @brief Generate MAC of an input vector using SIPHASH-2-4 00180 /// @param out u8* 64-bit result 00181 /// @param in u8* input buffer 00182 /// @param len u8 input buffer length in bytes 00183 /// @param key const u8* cipher key 00184 /// @retval void 00185 //====================================================================== 00186 _public void kal_siphash24(u8 *out, u8* v, u8 len, const u8* key); 00187 00188 #endif // _KAL_CRYPTO_H_
Generated on Tue Jul 12 2022 13:52:23 by
1.7.2