From 11aa5580cedbb9be59517c65028d7feab849f422 Mon Sep 17 00:00:00 2001 From: jd984 Date: Thu, 15 Jun 2023 12:09:20 +0530 Subject: [PATCH 1/2] Jesal submission of code --- Jesal | 1 + 1 file changed, 1 insertion(+) create mode 160000 Jesal diff --git a/Jesal b/Jesal new file mode 160000 index 0000000..016878e --- /dev/null +++ b/Jesal @@ -0,0 +1 @@ +Subproject commit 016878e238a43790703f47a59225e91436945fea From d76a6c536e543076e329b0462bd332da6db89ea6 Mon Sep 17 00:00:00 2001 From: jesalthakur984 Date: Thu, 15 Jun 2023 12:41:40 +0530 Subject: [PATCH 2/2] Jesal submission --- Jesal | 1 - assignments/Jesal/Block.cpp | 39 ++++++ assignments/Jesal/Block.h | 28 ++++ .../Jesal/Blockchain Security Report.docx | Bin 0 -> 7921 bytes assignments/Jesal/Blockchain.cpp | 19 +++ assignments/Jesal/Blockchain.h | 23 +++ assignments/Jesal/Jesal | Bin 0 -> 49504 bytes assignments/Jesal/README.md | 18 +++ assignments/Jesal/main.cpp | 17 +++ assignments/Jesal/sha256-LICENSE.txt | 36 +++++ assignments/Jesal/sha256.cpp | 132 ++++++++++++++++++ assignments/Jesal/sha256.h | 53 +++++++ 12 files changed, 365 insertions(+), 1 deletion(-) delete mode 160000 Jesal create mode 100644 assignments/Jesal/Block.cpp create mode 100644 assignments/Jesal/Block.h create mode 100644 assignments/Jesal/Blockchain Security Report.docx create mode 100644 assignments/Jesal/Blockchain.cpp create mode 100644 assignments/Jesal/Blockchain.h create mode 100644 assignments/Jesal/Jesal create mode 100644 assignments/Jesal/README.md create mode 100644 assignments/Jesal/main.cpp create mode 100644 assignments/Jesal/sha256-LICENSE.txt create mode 100644 assignments/Jesal/sha256.cpp create mode 100644 assignments/Jesal/sha256.h diff --git a/Jesal b/Jesal deleted file mode 160000 index 016878e..0000000 --- a/Jesal +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 016878e238a43790703f47a59225e91436945fea diff --git a/assignments/Jesal/Block.cpp b/assignments/Jesal/Block.cpp new file mode 100644 index 0000000..02c7ea0 --- /dev/null +++ b/assignments/Jesal/Block.cpp @@ -0,0 +1,39 @@ +#include "Block.h" +#include "sha256.h" + +Block::Block(uint32_t nIndexIn, const string &sDataIn) : _nIndex(nIndexIn), _sData(sDataIn) +{ + _nNonce = 0; + _tTime = time(nullptr); + + sHash = _CalculateHash(); +} + +void Block::MineBlock(uint32_t nDifficulty) +{ + char cstr[nDifficulty + 1]; + for (uint32_t i = 0; i < nDifficulty; ++i) + { + cstr[i] = '0'; + } + cstr[nDifficulty] = '\0'; + + string str(cstr); + + do + { + _nNonce++; + sHash = _CalculateHash(); + } + while (sHash.substr(0, nDifficulty) != str); + + cout << "Block mined: " << sHash << endl; +} + +inline string Block::_CalculateHash() const +{ + stringstream ss; + ss << _nIndex << sPrevHash << _tTime << _sData << _nNonce; + + return sha256(ss.str()); +} diff --git a/assignments/Jesal/Block.h b/assignments/Jesal/Block.h new file mode 100644 index 0000000..a101f8f --- /dev/null +++ b/assignments/Jesal/Block.h @@ -0,0 +1,28 @@ +#ifndef TESTCHAIN_BLOCK_H +#define TESTCHAIN_BLOCK_H + +#include +#include +#include + +using namespace std; + +class Block { +public: + string sHash; + string sPrevHash; + + Block(uint32_t nIndexIn, const string &sDataIn); + + void MineBlock(uint32_t nDifficulty); + +private: + uint32_t _nIndex; + uint32_t _nNonce; + string _sData; + time_t _tTime; + + string _CalculateHash() const; +}; + +#endif diff --git a/assignments/Jesal/Blockchain Security Report.docx b/assignments/Jesal/Blockchain Security Report.docx new file mode 100644 index 0000000000000000000000000000000000000000..e2fc22b4d8b06a40a96208a6b2772fbf43a82293 GIT binary patch literal 7921 zcma)h1yr0(vi1Oj`yjzxLU7mM9$W_}I0SbI4#6e31$TFM2<`-TCuoo$nE*e@-rX0aoTa5-uVILG{5bWe8f0jE4eAtU>I1O# ztD8q#ZWlw|Ik-Iyq`Hu07h``s9oJi-fF4Z=r>gbs5SZX(m5(=C2&z2 z;bs|@FphUG!eG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*{i7J)T(t)PB;f$<2D>0Uag4cmo}z}tOCoS<&NHJLlg43si@t*|_rf8HKcF*evduxP?ET|u-jnj^I)FCC z%B)kFxo^Dbfa!&xH>B-~hGcLBh_vnP zr=92;Sw^Rx!*j9Ja;N^5n?ZLqe zi?zZUWhojVkvAylXMZ@hW&hrHk7sB>Q#6}9?f59hcyd1#Hy!G3H9TUiEwE!O(QkW5 znoUj^L5$+beRXnK5~N^|r2yP@t&?uI+QMyMeHtk&#vhBrc(JrTW0cib=TIWXHT$J5 z`S3BkkYi#R`*w|!dR&($i|gmf46v=a`{np_1=^I4C{JFNc zWxE{vWqBkilji&ErNScuxQC{@&6)QFQRXzo9!cX>C7j+i^kDDTI0|)8@3xQ3B96~y zKAHQJ$!{k4&oEo8s<~Uc3J`xI4i$WL>j4aN&rwe>XyE~V(n)imEAu_Z{-O;!zY^fL zny_VXxVhNYUt6l|Svb3>Y<%(N%lsMnlJ!>1OTl*dTJ9}RcC-6%Im0CMMhUZTv5`ZSwjbvb%q>x(>z^TMpr1cIX`9nLU#KE z*W9SvEY9gY$zH8QQl`NrMU{EH2i#|b%OBJW1YcC;!K-74759AhOI)Tbxj!*$U8KzyO@mRl8qXkUpsABYR~rZt zNuV)9XBcdsK^%KguCx&~c)Q%+jpyE95t1gKRpTGEv;Eb6Lt7I`#c>{hoQ%t^-hLu3 zVAyE>5YcHWTYe`jicf5o5R_?2&e83W<}nte)dV4p(^ Q03bepM4$IK_4nHUAHB>24*&oF literal 0 HcmV?d00001 diff --git a/assignments/Jesal/Blockchain.cpp b/assignments/Jesal/Blockchain.cpp new file mode 100644 index 0000000..e2d1aab --- /dev/null +++ b/assignments/Jesal/Blockchain.cpp @@ -0,0 +1,19 @@ +#include "Blockchain.h" + +Blockchain::Blockchain() +{ + _vChain.emplace_back(Block(0, "Genesis Block")); + _nDifficulty = 6; +} + +void Blockchain::AddBlock(Block bNew) +{ + bNew.sPrevHash = _GetLastBlock().sHash; + bNew.MineBlock(_nDifficulty); + _vChain.push_back(bNew); +} + +Block Blockchain::_GetLastBlock() const +{ + return _vChain.back(); +} diff --git a/assignments/Jesal/Blockchain.h b/assignments/Jesal/Blockchain.h new file mode 100644 index 0000000..112d865 --- /dev/null +++ b/assignments/Jesal/Blockchain.h @@ -0,0 +1,23 @@ +#ifndef TESTCHAIN_BLOCKCHAIN_H +#define TESTCHAIN_BLOCKCHAIN_H + +#include +#include +#include "Block.h" + +using namespace std; + +class Blockchain { +public: + Blockchain(); + + void AddBlock(Block bNew); + +private: + uint32_t _nDifficulty; + vector _vChain; + + Block _GetLastBlock() const; +}; + +#endif diff --git a/assignments/Jesal/Jesal b/assignments/Jesal/Jesal new file mode 100644 index 0000000000000000000000000000000000000000..abf8ed1774a16b1420393851176eef5d2bb8e432 GIT binary patch literal 49504 zcmeHw3wTu3wf~tsAS#lmsQ4Zf6%=D81PGut2qO~+5c9CqM-P+9kPJ*7CKCwUV)2Ib zIvrw>E4Q?2FSc5_t+lijOSNhMC1|Mzt1b1_Xl*-bs7AyZtu_DOT6^y^drsznq4)d# z-}nD>AX#Uxwf5R;uf6u#YwvSr@>Orib!je_p{{h}3kH>zTp}<epTyFkt!Lz1`vVwX&Zf}X?x50ta1zthD9@(b<-vqrsmJBDzPSmneph-Q+TvTuD zR|Nmq^~o?t+EYPgPZCEzh0>mOm?y*-3fk+{%6fJzXHlQH+30+r)Lse4?t_)XS5f0V2v|iC#IQ5FD z1-Z=)x%o_|YHs|{@XcLVX<%472`AMz($Ll1}_T+<4btedmM<*WY(2wBgq6 z|NK?aw*$mOdQ%JGYX*My2VbZw*m(82(>ITr&BzqL zTA}!PXj6S8p|J*^&+YWM; z!?>yBJm`R5Ju)@_1rGMfcFKf|J=7_&3Vw#3oT(Q8c z4mJgALd}t2Q^kVW;fDHPg}*8s6tvWo8yA*GrkQ4-wbkSCY z3bVY>q#W(c(#c>3seU8bMn_H?N-diWe zE>ak3Xg1Myu%Ng;6iFJq((B5~8_G=@YXDBPD z_wRFtqbVG*RQM=N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Y z<+17FMnSwzm~;`Ze$jh%_^6Flzfjg!P`<`zRmrmM#0|YKrq{2P^%Wd%9s|@ zzWThUf^HkXz5W+L|2sb0topA$|E-|Xe}t4{*WVBPN%&Fq)#t+%+>$9Ol8$6MRUfbU z@V5?+S`YS#KZv&k^3$DuQ^WX~h z$oix|>8bRWXrlu+WK&gNeLh`5_4#zwzN)YK|4mu{S}9O{-d#cU`FN_2SCOsuRsH*c zBfBd3h8qRC-25AF1Seni@xK>jy}sKm_$?^?QAx>>Hwr$4vRCA?#V4@zjT^m8o~#%pwA=4lSznF6u|zUT z*klm|-Yv-r{2DjZf5oOgSF2#Pt^fA+U$fOe5EPOX9HU-j7ii0WWYPGOt^Psz;iZ}9|4meI3t;_L{;wc?-kLr$r0T2hr^xw=sG|6k0995n8}-Te zRekmOrI)mM2qn*SA(wxdWfK wp$o5>^N-SB_3H%SmF~o+uI{_VUG+r@BcN(mVNbzLs`>>x1ji&>1zXYhKTu8`TmS$7 literal 0 HcmV?d00001 diff --git a/assignments/Jesal/README.md b/assignments/Jesal/README.md new file mode 100644 index 0000000..f6aaf2d --- /dev/null +++ b/assignments/Jesal/README.md @@ -0,0 +1,18 @@ +*** Project Title *** +"Blockchain In C++" + +************************* + +*** Use Linux version 22.04 *** + +************************* + +**** To Compile the Code **** + +g++ -lstdc++ -o Jesal main.cpp Block.cpp Blockchain.cpp sha256.cpp + +************************* + +**** To run the Code **** + +./Jesal diff --git a/assignments/Jesal/main.cpp b/assignments/Jesal/main.cpp new file mode 100644 index 0000000..1882eef --- /dev/null +++ b/assignments/Jesal/main.cpp @@ -0,0 +1,17 @@ +#include "Blockchain.h" + +int main() +{ + Blockchain bChain = Blockchain(); + + cout << "Mining block 1..." << endl; + bChain.AddBlock(Block(1, "Block 1 Data")); + + cout << "Mining block 2..." << endl; + bChain.AddBlock(Block(2, "Block 2 Data")); + + cout << "Mining block 3..." << endl; + bChain.AddBlock(Block(3, "Block 3 Data")); + + return 0; +} diff --git a/assignments/Jesal/sha256-LICENSE.txt b/assignments/Jesal/sha256-LICENSE.txt new file mode 100644 index 0000000..2f8eb36 --- /dev/null +++ b/assignments/Jesal/sha256-LICENSE.txt @@ -0,0 +1,36 @@ +/* + * Updated to C++, zedwood.com 2012 + * Based on Olivier Gay's version + * See Modified BSD License below: + * + * FIPS 180-2 SHA-224/256/384/512 implementation + * Issue date: 04/30/2005 + * http://www.ouah.org/ogay/sha2/ + * + * Copyright (C) 2005, 2007 Olivier Gay + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ diff --git a/assignments/Jesal/sha256.cpp b/assignments/Jesal/sha256.cpp new file mode 100644 index 0000000..b93f963 --- /dev/null +++ b/assignments/Jesal/sha256.cpp @@ -0,0 +1,132 @@ +#include +#include +#include "sha256.h" + +const unsigned int SHA256::sha256_k[64] = //UL = uint32 + {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; + +void SHA256::transform(const unsigned char *message, unsigned int block_nb) +{ + uint32 w[64]; + uint32 wv[8]; + uint32 t1, t2; + const unsigned char *sub_block; + int i; + int j; + for (i = 0; i < (int) block_nb; i++) { + sub_block = message + (i << 6); + for (j = 0; j < 16; j++) { + SHA2_PACK32(&sub_block[j << 2], &w[j]); + } + for (j = 16; j < 64; j++) { + w[j] = SHA256_F4(w[j - 2]) + w[j - 7] + SHA256_F3(w[j - 15]) + w[j - 16]; + } + for (j = 0; j < 8; j++) { + wv[j] = m_h[j]; + } + for (j = 0; j < 64; j++) { + t1 = wv[7] + SHA256_F2(wv[4]) + SHA2_CH(wv[4], wv[5], wv[6]) + + sha256_k[j] + w[j]; + t2 = SHA256_F1(wv[0]) + SHA2_MAJ(wv[0], wv[1], wv[2]); + wv[7] = wv[6]; + wv[6] = wv[5]; + wv[5] = wv[4]; + wv[4] = wv[3] + t1; + wv[3] = wv[2]; + wv[2] = wv[1]; + wv[1] = wv[0]; + wv[0] = t1 + t2; + } + for (j = 0; j < 8; j++) { + m_h[j] += wv[j]; + } + } +} + +void SHA256::init() +{ + m_h[0] = 0x6a09e667; + m_h[1] = 0xbb67ae85; + m_h[2] = 0x3c6ef372; + m_h[3] = 0xa54ff53a; + m_h[4] = 0x510e527f; + m_h[5] = 0x9b05688c; + m_h[6] = 0x1f83d9ab; + m_h[7] = 0x5be0cd19; + m_len = 0; + m_tot_len = 0; +} + +void SHA256::update(const unsigned char *message, unsigned int len) +{ + unsigned int block_nb; + unsigned int new_len, rem_len, tmp_len; + const unsigned char *shifted_message; + tmp_len = SHA224_256_BLOCK_SIZE - m_len; + rem_len = len < tmp_len ? len : tmp_len; + memcpy(&m_block[m_len], message, rem_len); + if (m_len + len < SHA224_256_BLOCK_SIZE) { + m_len += len; + return; + } + new_len = len - rem_len; + block_nb = new_len / SHA224_256_BLOCK_SIZE; + shifted_message = message + rem_len; + transform(m_block, 1); + transform(shifted_message, block_nb); + rem_len = new_len % SHA224_256_BLOCK_SIZE; + memcpy(m_block, &shifted_message[block_nb << 6], rem_len); + m_len = rem_len; + m_tot_len += (block_nb + 1) << 6; +} + +void SHA256::final(unsigned char *digest) +{ + unsigned int block_nb; + unsigned int pm_len; + unsigned int len_b; + int i; + block_nb = (1 + ((SHA224_256_BLOCK_SIZE - 9) + < (m_len % SHA224_256_BLOCK_SIZE))); + len_b = (m_tot_len + m_len) << 3; + pm_len = block_nb << 6; + memset(m_block + m_len, 0, pm_len - m_len); + m_block[m_len] = 0x80; + SHA2_UNPACK32(len_b, m_block + pm_len - 4); + transform(m_block, block_nb); + for (i = 0 ; i < 8; i++) { + SHA2_UNPACK32(m_h[i], &digest[i << 2]); + } +} + +std::string sha256(std::string input) +{ + unsigned char digest[SHA256::DIGEST_SIZE]; + memset(digest,0,SHA256::DIGEST_SIZE); + + SHA256 ctx = SHA256(); + ctx.init(); + ctx.update( (unsigned char*)input.c_str(), input.length()); + ctx.final(digest); + + char buf[2*SHA256::DIGEST_SIZE+1]; + buf[2*SHA256::DIGEST_SIZE] = 0; + for (int i = 0; i < SHA256::DIGEST_SIZE; i++) + sprintf(buf+i*2, "%02x", digest[i]); + return std::string(buf); +} diff --git a/assignments/Jesal/sha256.h b/assignments/Jesal/sha256.h new file mode 100644 index 0000000..612ab2e --- /dev/null +++ b/assignments/Jesal/sha256.h @@ -0,0 +1,53 @@ +#ifndef SHA256_H +#define SHA256_H +#include + +class SHA256 +{ +protected: + typedef unsigned char uint8; + typedef unsigned int uint32; + typedef unsigned long long uint64; + + const static uint32 sha256_k[]; + static const unsigned int SHA224_256_BLOCK_SIZE = (512/8); +public: + void init(); + void update(const unsigned char *message, unsigned int len); + void final(unsigned char *digest); + static const unsigned int DIGEST_SIZE = ( 256 / 8); + +protected: + void transform(const unsigned char *message, unsigned int block_nb); + unsigned int m_tot_len; + unsigned int m_len; + unsigned char m_block[2*SHA224_256_BLOCK_SIZE]; + uint32 m_h[8]; +}; + +std::string sha256(std::string input); + +#define SHA2_SHFR(x, n) (x >> n) +#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) +#define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) +#define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) +#define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) +#define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) +#define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) +#define SHA256_F4(x) (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10)) +#define SHA2_UNPACK32(x, str) \ +{ \ + *((str) + 3) = (uint8) ((x) ); \ + *((str) + 2) = (uint8) ((x) >> 8); \ + *((str) + 1) = (uint8) ((x) >> 16); \ + *((str) + 0) = (uint8) ((x) >> 24); \ +} +#define SHA2_PACK32(str, x) \ +{ \ + *(x) = ((uint32) *((str) + 3) ) \ + | ((uint32) *((str) + 2) << 8) \ + | ((uint32) *((str) + 1) << 16) \ + | ((uint32) *((str) + 0) << 24); \ +} +#endif