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.
sha256.h
00001 #ifndef SHA256_H 00002 #define SHA256_H 00003 #include <string> 00004 00005 class SHA256 00006 { 00007 protected: 00008 typedef unsigned char uint8; 00009 typedef unsigned int uint32; 00010 typedef unsigned long long uint64; 00011 00012 const static uint32 sha256_k[]; 00013 static const unsigned int SHA224_256_BLOCK_SIZE = (512/8); 00014 public: 00015 void init(); 00016 void update(const unsigned char *message, unsigned int len); 00017 void final(unsigned char *digest); 00018 static const unsigned int DIGEST_SIZE = ( 256 / 8); 00019 00020 protected: 00021 void transform(const unsigned char *message, unsigned int block_nb); 00022 unsigned int m_tot_len; 00023 unsigned int m_len; 00024 unsigned char m_block[2*SHA224_256_BLOCK_SIZE]; 00025 uint32 m_h[8]; 00026 }; 00027 00028 std::string sha256(std::string input); 00029 00030 #define SHA2_SHFR(x, n) (x >> n) 00031 #define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) 00032 #define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) 00033 #define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) 00034 #define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) 00035 #define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) 00036 #define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) 00037 #define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) 00038 #define SHA256_F4(x) (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10)) 00039 #define SHA2_UNPACK32(x, str) \ 00040 { \ 00041 *((str) + 3) = (uint8) ((x) ); \ 00042 *((str) + 2) = (uint8) ((x) >> 8); \ 00043 *((str) + 1) = (uint8) ((x) >> 16); \ 00044 *((str) + 0) = (uint8) ((x) >> 24); \ 00045 } 00046 #define SHA2_PACK32(str, x) \ 00047 { \ 00048 *(x) = ((uint32) *((str) + 3) ) \ 00049 | ((uint32) *((str) + 2) << 8) \ 00050 | ((uint32) *((str) + 1) << 16) \ 00051 | ((uint32) *((str) + 0) << 24); \ 00052 } 00053 #endif
Generated on Tue Jul 19 2022 15:58:40 by
1.7.2