daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## AuthCrypt
  2. void AuthCrypt::Init(BigNumber *K)
  3. {
  4.     uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0x22, 0xBE, 0xE5, 0xCF, 0xBB, 0x07, 0x64, 0xD9, 0x00, 0x45, 0x1B, 0xD0, 0x24, 0xB8, 0xD5, 0x45 };
  5.     HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
  6.     uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
  7.  
  8.     uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xF4, 0x66, 0x31, 0x59, 0xFC, 0x83, 0x6E, 0x31, 0x31, 0x02, 0x51, 0xD5, 0x44, 0x31, 0x67, 0x98 };
  9.     HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
  10.     uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
  11.  
  12.     //SARC4 _serverDecrypt(encryptHash);
  13.     _clientDecrypt.Init(decryptHash);
  14.     _serverEncrypt.Init(encryptHash);
  15.     //SARC4 _clientEncrypt(decryptHash);
  16.  
  17.     uint8 syncBuf[1024];
  18.  
  19.     memset(syncBuf, 0, 1024);
  20.  
  21.     _serverEncrypt.UpdateData(1024, syncBuf);
  22.     //_clientEncrypt.UpdateData(1024, syncBuf);
  23.  
  24.     memset(syncBuf, 0, 1024);
  25.  
  26.     //_serverDecrypt.UpdateData(1024, syncBuf);
  27.     _clientDecrypt.UpdateData(1024, syncBuf);
  28.  
  29.     _initialized = true;
  30. }
  31.  
  32. void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
  33. {
  34.     if (!_initialized)
  35.         return;
  36.  
  37.     _clientDecrypt.UpdateData(len, data);
  38. }
  39.  
  40. void AuthCrypt::EncryptSend(uint8 *data, size_t len)
  41. {
  42.     if (!_initialized)
  43.         return;
  44.  
  45.     _serverEncrypt.UpdateData(len, data);
  46. }
  47.  
  48. ## HMac
  49. HmacHash::HmacHash(uint32 len, uint8 *seed)
  50. {
  51.     ASSERT(len == SEED_KEY_SIZE);
  52.  
  53.     HMAC_CTX_init(&m_ctx);
  54.     HMAC_Init_ex(&m_ctx, seed, SEED_KEY_SIZE, EVP_sha1(), NULL);
  55. }
  56.  
  57. HmacHash::~HmacHash()
  58. {
  59.     HMAC_CTX_cleanup(&m_ctx);
  60. }
  61.  
  62. void HmacHash::UpdateBigNumber(BigNumber *bn)
  63. {
  64.     UpdateData(bn->AsByteArray(), bn->GetNumBytes());
  65. }
  66.  
  67. void HmacHash::UpdateData(const uint8 *data, int length)
  68. {
  69.     HMAC_Update(&m_ctx, data, length);
  70. }
  71.  
  72. void HmacHash::Finalize()
  73. {
  74.     uint32 length = 0;
  75.     HMAC_Final(&m_ctx, (uint8*)m_digest, &length);
  76.     ASSERT(length == SHA_DIGEST_LENGTH)
  77. }
  78.  
  79. uint8 *HmacHash::ComputeHash(BigNumber *bn)
  80. {
  81.     HMAC_Update(&m_ctx, bn->AsByteArray(), bn->GetNumBytes());
  82.     Finalize();
  83.     return (uint8*)m_digest;
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top