Re: TOTP implementation
Arik Agazarian <[email protected]> Sat, 4 Nov 2023 19:19:39 +0100
| Newsgroups | gmane.comp.encryption.cryptopp |
|---|---|
| Message-ID | <CAOLESwnyCwLm2c6gfaZM60=_d=pQzdzSMsH0fEnfj8RTHUH3+g@mail.gmail.com> |
--000000000000d43186060957aab4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable We Need wallet address of 7 months for clean transactions, traceable on Blockchain, Ratio 45%/45%/10% Sender/Reciever/Mandate Telegram sender: @Arik_loader On Thu, Nov 2, 2023, 7:23 PM Catherine Issabel <[email protected]> wrote: > > $500 million dollars available only for good and trusted receiver or > mandate > Kindly contact the sender for more information:+1 (336) 345-9681 > On Friday, August 4, 2023 at 6:28:39=E2=80=AFPM UTC+1 [email protected]= wrote: > >> Also, their version of Base32Decoder uses DUDE instead of RFC 4648. >> >> On Friday, August 4, 2023 at 2:14:12=E2=80=AFPM UTC+1 Steven Green wrote= : >> >>> Shouldn't... >>> >>> * hmac.Update(byteArray, sizeof(byteArraySize));* >>> >>> be simply.. >>> >>> >>> * hmac.Update(byteArray, byteArraySize); * >>> >>> Otherwise you passing in sizeof(size_t) rather than the size of the >>> byteArray (which is sizeof(uint64_t)). Although on a 64 bit system I wo= uld >>> expect them both to be 8 bytes, so maybe there is another problem. >>> >>> Otherwise the function looks very similar to what I have. >>> >>> - Steven >>> On 03/08/2023 10:51, Aravindh B wrote: >>> >>> Need to get some information how counter value is handled in this >>> library. >>> >>> std::string generateTOTP(const std::string& secretKey) { >>> >>> using namespace CryptoPP; >>> const int timeStep =3D 30; // Time step in seconds >>> SecByteBlock key(HMAC<SHA1>::DEFAULT_KEYLENGTH); >>> StringSource(secretKey, true, new Base32Decoder(new ArraySink(key, >>> key.size()))); >>> >>> // Get the current time in 30-second intervals (TOTP time step) >>> std::time_t currentTime =3D std::time(nullptr); >>> uint64_t counter =3D static_cast<uint64_t>(currentTime) / timeStep; >>> const size_t byteArraySize =3D sizeof(counter); >>> byte* byteArray =3D new byte[byteArraySize]; >>> >>> //Big endian representation >>> for (size_t i =3D 0; i < byteArraySize; ++i) { >>> byteArray[sizeof(counter) - 1 - i] =3D static_cast<byte>((counter >> (8= * >>> i)) & 0xFF); >>> } >>> >>> // Calculate the HMAC-SHA1 using the secret key and the counter bytes >>> byte mac[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE]; >>> CryptoPP::HMAC<CryptoPP::SHA1> hmac(key, sizeof(key)); >>> >>> * hmac.Update(byteArray, sizeof(byteArraySize)); * hmac.Final(mac); >>> >>> // Generate the TOTP value from the last 4 bits of the HMAC-SHA1 result >>> int offset =3D mac[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE - 1] & 0x= F; >>> uint32_t otpValue =3D (mac[offset] & 0x7F) << 24 | >>> (mac[offset + 1] & 0xFF) << 16 | >>> (mac[offset + 2] & 0xFF) << 8 | >>> (mac[offset + 3] & 0xFF); >>> >>> // Convert the OTP value to a 6-digit OTP (modulo 10^6) >>> otpValue %=3D 1000000; >>> >>> //Format the OTP as a 6-digit string with leading zeros if needed >>> std::string otp =3D std::to_string(otpValue); >>> otp.insert(otp.begin(), 6 - otp.size(), '0'); >>> delete[] byteArray; >>> >>> return otp; >>> } >>> >>> This code have issues with hmac.update(). Seems problem with counter >>> value.Does anyone help to generate correct otp? >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Crypto++ Users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/cryptopp-users/5cc93e58-cf8b-41fd-985= 5-8b84e707b19fn%40googlegroups.com >>> <https://groups.google.com/d/msgid/cryptopp-users/5cc93e58-cf8b-41fd-98= 55-8b84e707b19fn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter> >>> . >>> >>> -- > You received this message because you are subscribed to the Google Groups > "Crypto++ Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/cryptopp-users/ef830633-e0ca-417f-b23a-= 6cdb32ac237dn%40googlegroups.com > <https://groups.google.com/d/msgid/cryptopp-users/ef830633-e0ca-417f-b23a= -6cdb32ac237dn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter> > . > --=20 You received this message because you are subscribed to the Google Groups "= Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/= cryptopp-users/CAOLESwnyCwLm2c6gfaZM60%3D_d%3DpQzdzSMsH0fEnfj8RTHUH3%2Bg%40= mail.gmail.com. --000000000000d43186060957aab4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div dir=3D"auto">We Need wallet address of 7 months for = clean transactions, traceable on Blockchain,=C2=A0</div><div dir=3D"auto">R= atio 45%/45%/10%</div><div dir=3D"auto">Sender/Reciever/Mandate</div><div d= ir=3D"auto">Telegram sender: @Arik_loader</div><div dir=3D"auto"><br></div>= </div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">= On Thu, Nov 2, 2023, 7:23 PM Catherine Issabel <<a href=3D"mailto:issabe= [email protected]">[email protected]</a>> wrote:<br></div><b= lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px = #ccc solid;padding-left:1ex"><br>$500 million dollars available only for go= od and trusted receiver or mandate <br>Kindly contact the sender for more i= nformation:+1 (336) 345-9681<br><div class=3D"gmail_quote"><div dir=3D"auto= " class=3D"gmail_attr">On Friday, August 4, 2023 at 6:28:39=E2=80=AFPM UTC+= 1 <a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noreferre= r">[email protected]</a> wrote:<br></div><blockquote class=3D"gmail_quote= " style=3D"margin:0 0 0 0.8ex;border-left:1px solid rgb(204,204,204);paddin= g-left:1ex">Also, their version of Base32Decoder uses DUDE instead of RFC 4= 648.<br><br><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmail_att= r">On Friday, August 4, 2023 at 2:14:12=E2=80=AFPM UTC+1 Steven Green wrote= :<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 0.8ex;bo= rder-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u> =20 =20 =20 <div> <p>Shouldn't...<br> </p> <p><b><span style=3D"white-space:pre-wrap"> </span>hmac.Update(byteArra= y, sizeof(byteArraySize));</b></p> <p>be simply..<br> </p> <p><b><span style=3D"white-space:pre-wrap"> </span>hmac.Update(byteArra= y, byteArraySize);<br> </b></p> <p>Otherwise you passing in sizeof(size_t) rather than the size of the byteArray (which is sizeof(uint64_t)). Although on a 64 bit system I would expect them both to be 8 bytes, so maybe there is another problem.<br> </p> <p>Otherwise the function looks very similar to what I have.</p> <p>- Steven<br> </p></div><div> <div>On 03/08/2023 10:51, Aravindh B wrote:<br> </div> </div><div><blockquote type=3D"cite"> =20 Need to get some information how counter value is handled in this library.<br> <br> <div>std::string generateTOTP(const std::string& secretKey) {<br> <br> <span style=3D"white-space:pre-wrap"> </span>using namespace CryptoPP;<br> <span style=3D"white-space:pre-wrap"> </span>const int timeStep =3D= 30; // Time step in seconds<br> <span style=3D"white-space:pre-wrap"> </span>SecByteBlock key(HMAC<SHA1>::DEFAULT_KEYLENGTH);<br> <span style=3D"white-space:pre-wrap"> </span>StringSource(secretKey= , true, new Base32Decoder(new ArraySink(key, key.size())));<br> <br> <span style=3D"white-space:pre-wrap"> </span>// Get the current tim= e in 30-second intervals (TOTP time step)<br> <span style=3D"white-space:pre-wrap"> </span>std::time_t currentTim= e =3D std::time(nullptr);<br> <span style=3D"white-space:pre-wrap"> </span>uint64_t counter =3D static_cast<uint64_t>(currentTime) / timeStep;<br> <span style=3D"white-space:pre-wrap"> </span>const size_t byteArraySize =3D sizeof(counter);<br> <span style=3D"white-space:pre-wrap"> </span>byte* byteArray =3D ne= w byte[byteArraySize];<br> <br> <span style=3D"white-space:pre-wrap"> </span>//Big endian representation</div> <div>for (size_t i =3D 0; i < byteArraySize; ++i) {<br> <span style=3D"white-space:pre-wrap"> </span>byteArray[sizeof(coun= ter) - 1 - i] =3D static_cast<byte>((counter >> (8 * i)) & 0xFF);<br> <span style=3D"white-space:pre-wrap"> </span>}<br> <br> <span style=3D"white-space:pre-wrap"> </span>// Calculate the HMAC-SHA1 using the secret key and the counter bytes<br> <span style=3D"white-space:pre-wrap"> </span>byte mac[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE];<br> <span style=3D"white-space:pre-wrap"> </span>CryptoPP::HMAC<Cryp= toPP::SHA1> hmac(key, sizeof(key));<br> <b><span style=3D"white-space:pre-wrap"> </span>hmac.Update(byteArr= ay, sizeof(byteArraySize));<br> </b><span style=3D"white-space:pre-wrap"> </span>hmac.Final(mac);<b= r> <br> <span style=3D"white-space:pre-wrap"> </span>// Generate the TOTP value from the last 4 bits of the HMAC-SHA1 result<br> <span style=3D"white-space:pre-wrap"> </span>int offset =3D mac[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE - 1] & 0xF;<br> <span style=3D"white-space:pre-wrap"> </span>uint32_t otpValue =3D (mac[offset] & 0x7F) << 24 |<br> <span style=3D"white-space:pre-wrap"> </span>(mac[offset + 1] &= ; 0xFF) << 16 |<br> <span style=3D"white-space:pre-wrap"> </span>(mac[offset + 2] &= ; 0xFF) << 8 |<br> <span style=3D"white-space:pre-wrap"> </span>(mac[offset + 3] &= ; 0xFF);<br> <br> <span style=3D"white-space:pre-wrap"> </span>// Convert the OTP val= ue to a 6-digit OTP (modulo 10^6)<br> <span style=3D"white-space:pre-wrap"> </span>otpValue %=3D 1000000;= <br> <br> <span style=3D"white-space:pre-wrap"> </span>//Format the OTP as a 6-digit string with leading zeros if needed<br> <span style=3D"white-space:pre-wrap"> </span>std::string otp =3D std::to_string(otpValue);<br> <span style=3D"white-space:pre-wrap"> </span>otp.insert(otp.begin()= , 6 - otp.size(), '0');<br> <span style=3D"white-space:pre-wrap"> </span>delete[] byteArray;<br= > <br> <span style=3D"white-space:pre-wrap"> </span>return otp;<br> }<br> <br> This code have issues with hmac.update(). Seems problem with counter value.Does anyone help to generate correct otp?</div></bloc= kquote></div><div><blockquote type=3D"cite"> -- <br> You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.<br> To unsubscribe from this group and stop receiving emails from it, send an email to <a rel=3D"nofollow noreferrer">cryptopp-user...@goog= legroups.com</a>.<br> To view this discussion on the web visit <a href=3D"https://groups.go= ogle.com/d/msgid/cryptopp-users/5cc93e58-cf8b-41fd-9855-8b84e707b19fn%40goo= glegroups.com?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow n= oreferrer" target=3D"_blank">https://groups.google.com/d/msgid/cryptopp-use= rs/5cc93e58-cf8b-41fd-9855-8b84e707b19fn%40googlegroups.com</a>.<br> </blockquote> </div> </blockquote></div></blockquote></div> <p></p> -- <br> You received this message because you are subscribed to the Google Groups &= quot;Crypto++ Users" group.<br> To unsubscribe from this group and stop receiving emails from it, send an e= mail to <a href=3D"mailto:[email protected]" targ= et=3D"_blank" rel=3D"noreferrer">[email protected]= m</a>.<br> To view this discussion on the web visit <a href=3D"https://groups.google.c= om/d/msgid/cryptopp-users/ef830633-e0ca-417f-b23a-6cdb32ac237dn%40googlegro= ups.com?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" rel= =3D"noreferrer">https://groups.google.com/d/msgid/cryptopp-users/ef830633-e= 0ca-417f-b23a-6cdb32ac237dn%40googlegroups.com</a>.<br> </blockquote></div> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups &= quot;Crypto++ Users" group.<br /> To unsubscribe from this group and stop receiving emails from it, send an e= mail to <a href=3D"mailto:[email protected]">cryp= [email protected]</a>.<br /> To view this discussion on the web visit <a href=3D"https://groups.google.c= om/d/msgid/cryptopp-users/CAOLESwnyCwLm2c6gfaZM60%3D_d%3DpQzdzSMsH0fEnfj8RT= HUH3%2Bg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://g= roups.google.com/d/msgid/cryptopp-users/CAOLESwnyCwLm2c6gfaZM60%3D_d%3DpQzd= zSMsH0fEnfj8RTHUH3%2Bg%40mail.gmail.com</a>.<br /> --000000000000d43186060957aab4--