1 #pragma once 2 #ifndef IWSHA2_H 3 #define IWSHA2_H 4 5 /************************************************************************************************** 6 * SHA-256 hash generator. 7 * Based on https://github.com/amosnier/sha-2 8 * 9 * This is free and unencumbered software released into the public domain. 10 * 11 * Anyone is free to copy, modify, publish, use, compile, sell, or 12 * distribute this software, either in source code form or as a compiled 13 * binary, for any purpose, commercial or non-commercial, and by any 14 * means. 15 16 * In jurisdictions that recognize copyright laws, the author or authors 17 * of this software dedicate any and all copyright interest in the 18 * software to the public domain. We make this dedication for the benefit 19 * of the public at large and to the detriment of our heirs and 20 * successors. We intend this dedication to be an overt act of 21 * relinquishment in perpetuity of all present and future rights to this 22 * software under copyright law. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 27 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 30 * OTHER DEALINGS IN THE SOFTWARE. 31 * 32 * For more information, please refer to <http://unlicense.org> 33 * 34 *************************************************************************************************/ 35 36 #include "basedefs.h" 37 #include <stddef.h> 38 39 IW_EXTERN_C_START 40 41 /** 42 * @brief Computes sha256 sum for given `input` data of `len` bytes. 43 * 44 * Limitations: 45 * - Since input is a pointer in RAM, the data to hash should be in RAM, which could be a problem 46 * for large data sizes. 47 * - SHA algorithms theoretically operate on bit strings. However, this implementation has no support 48 * for bit string lengths that are not multiples of eight, and it really operates on arrays of bytes. 49 * In particular, the len parameter is a number of bytes. 50 * 51 * @param hash Hash sum placeholder 52 * @param input 53 * @param len 54 */ 55 IW_EXPORT void iwsha256(const void *input, size_t len, uint8_t hash_out[32]); 56 57 IW_EXPORT void iwsha256str(const void *input, size_t len, char str_out[65]); 58 59 IW_EXPORT void iwhash2str(uint8_t hash[32], char str_out[65]); 60 61 IW_EXTERN_C_END 62 #endif 63