void WalletSerializerV1::loadTransfers(Common::IInputStream& source, CryptoContext& cryptoContext, uint32_t version) {
  uint64_t count = 0;
  deserializeEncrypted(count, "transfers_count", cryptoContext, source);
  cryptoContext.incIv();

  m_transfers.reserve(count);

  for (uint64_t i = 0; i < count; ++i) {
    uint64_t txId = 0;
    deserializeEncrypted(txId, "transaction_id", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransferDto dto(version);
    deserializeEncrypted(dto, "transfer", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransfer tr;
    tr.address = dto.address;
    tr.amount = dto.amount;

    if (version > 2) {
      tr.type = static_cast<WalletTransferType>(dto.type);
    } else {
      tr.type = WalletTransferType::USUAL;
    }

    m_transfers.push_back(std::make_pair(txId, tr));
  }
}
Ejemplo n.º 2
0
void WalletSerializer::saveUnlockTransactionsJobs(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  auto& index = m_unlockTransactions.get<TransactionHashIndex>();
  auto& wallets = m_walletsContainer.get<TransfersContainerIndex>();

  uint64_t jobsCount = index.size();
  serializeEncrypted(jobsCount, "unlock_transactions_jobs_count", cryptoContext, destination);
  cryptoContext.incIv();

  for (const auto& j: index) {
    auto containerIt = wallets.find(j.container);
    assert(containerIt != wallets.end());

    auto rndIt = m_walletsContainer.project<RandomAccessIndex>(containerIt);
    assert(rndIt != m_walletsContainer.get<RandomAccessIndex>().end());

    uint64_t walletIndex = std::distance(m_walletsContainer.get<RandomAccessIndex>().begin(), rndIt);

    UnlockTransactionJobDto dto;
    dto.blockHeight = j.blockHeight;
    dto.transactionHash = j.transactionHash;
    dto.walletIndex = walletIndex;

    serializeEncrypted(dto, "", cryptoContext, destination);
    cryptoContext.incIv();
  }
}
Ejemplo n.º 3
0
int main ()
{
  printf ("Results of aes_context_test:\n");
  
  try
  {  
    CryptoContext context ("aes.encrypt", key, KEY_BITS);

    memset (dst_encrypt_buffer, 0, sizeof dst_decrypt_buffer);        
    
    printf ("source:             '%s'\n", src_buffer);
    printf ("encrypt update:      %u\n",  context.Update (BUFFER_SIZE, src_buffer, dst_encrypt_buffer));
    printf ("dst_encrypt_buffer:  ");
    
    for (size_t i=0; i<BUFFER_SIZE; i++)
      printf ("%02x", (unsigned char)dst_encrypt_buffer [i]);
      
    printf ("\n");

    CryptoContext ("aes.decrypt", key, KEY_BITS).Swap (context);
    
    memset (dst_decrypt_buffer, 0, sizeof dst_decrypt_buffer);

    printf ("decrypt update:      %u\n",  context.Update (BUFFER_SIZE, dst_encrypt_buffer, dst_decrypt_buffer));  
    printf ("dst_decrypt_buffer: '%s'\n", dst_decrypt_buffer);
  }
  catch (std::exception& exception)
  {
    printf ("exception: %s\n", exception.what ());
  }

  return 0;
}
void WalletSerializerV1::loadFlags(bool& details, bool& cache, Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(details, "details", cryptoContext, source);
  cryptoContext.incIv();

  deserializeEncrypted(cache, "cache", cryptoContext, source);
  cryptoContext.incIv();
}
void WalletSerializerV1::loadTransactions(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "transactions_count", cryptoContext, source);
  cryptoContext.incIv();

  m_transactions.get<RandomAccessIndex>().reserve(count);

  for (uint64_t i = 0; i < count; ++i) {
    WalletTransactionDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransaction tx;
    tx.state = dto.state;
    tx.timestamp = dto.timestamp;
    tx.blockHeight = dto.blockHeight;
    tx.hash = dto.hash;
    tx.totalAmount = dto.totalAmount;
    tx.fee = dto.fee;
    tx.creationTime = dto.creationTime;
    tx.unlockTime = dto.unlockTime;
    tx.extra = dto.extra;
    tx.isBase = false;

    m_transactions.get<RandomAccessIndex>().push_back(std::move(tx));
  }
}
void WalletSerializerV1::loadBalances(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_actualBalance, "actual_balance", cryptoContext, source);
  cryptoContext.incIv();

  deserializeEncrypted(m_pendingBalance, "pending_balance", cryptoContext, source);
  cryptoContext.incIv();
}
Ejemplo n.º 7
0
void WalletSerializer::saveFlags(bool saveDetails, bool saveCache, Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  serializeEncrypted(saveDetails, "details", cryptoContext, destination);
  cryptoContext.incIv();

  serializeEncrypted(saveCache, "cache", cryptoContext, destination);
  cryptoContext.incIv();
}
void WalletSerializerV1::loadUnlockTransactionsJobs(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_unlockTransactions.get<TransactionHashIndex>();
  auto& walletsIndex = m_walletsContainer.get<RandomAccessIndex>();
  const uint64_t walletsSize = walletsIndex.size();
  if (walletsSize) {}

  uint64_t jobsCount = 0;
  deserializeEncrypted(jobsCount, "unlock_transactions_jobs_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < jobsCount; ++i) {
    UnlockTransactionJobDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    assert(dto.walletIndex < walletsSize);

    UnlockTransactionJob job;
    job.blockHeight = dto.blockHeight;
    job.transactionHash = dto.transactionHash;
    job.container = walletsIndex[dto.walletIndex].container;

    index.insert(std::move(job));
  }
}
Ejemplo n.º 9
0
void WalletSerializer::loadSpentOutputs(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_spentOutputs.get<WalletIndex>();
  auto& walletsIndex = m_walletsContainer.get<RandomAccessIndex>();
  const uint64_t walletsSize = walletsIndex.size();

  uint64_t count = 0;
  deserializeEncrypted(count, "spent_outputs_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; ++i) {
    SpentOutputDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    assert(dto.walletIndex < walletsSize);

    SpentOutput output;
    output.amount = dto.amount;
    output.transactionHash = dto.transactionHash;
    output.outputInTransaction = dto.outputInTransaction;
    output.spendingTransactionHash = dto.spendingTransactionHash;
    output.wallet = &walletsIndex[dto.walletIndex];

    index.insert(std::move(output));
  }
}
Ejemplo n.º 10
0
void
OutgoingDataQueue::putData(uint32 stamp, const unsigned char *data, size_t datalen)
{
    if ( !data || !datalen )
        return;

    size_t step = 0, offset = 0;
    while ( offset < datalen ) {
        // remainder and step take care of segmentation
        // according to getMaxSendSegmentSize()
        size_t remainder = datalen - offset;
        step = ( remainder > getMaxSendSegmentSize() ) ?
            getMaxSendSegmentSize() : remainder;

                CryptoContext* pcc = getOutQueueCryptoContext(getLocalSSRC());
                if (pcc == NULL) {
                    pcc = getOutQueueCryptoContext(0);
                    if (pcc != NULL) {
                        pcc = pcc->newCryptoContextForSSRC(getLocalSSRC(), 0, 0L);
                        if (pcc != NULL) {
                            pcc->deriveSrtpKeys(0);
                            setOutQueueCryptoContext(pcc);
                        }
                    }
                }
                OutgoingRTPPkt* packet;
        if ( sendInfo.sendCC )
            packet = new OutgoingRTPPkt(sendInfo.sendSources,15,data + offset,step, sendInfo.paddinglen, pcc);
        else
            packet = new OutgoingRTPPkt(data + offset,step,sendInfo.paddinglen, pcc);

        packet->setPayloadType(getCurrentPayloadType());
        packet->setSeqNum(sendInfo.sendSeq++);
        packet->setTimestamp(stamp + getInitialTimestamp());

        packet->setSSRCNetwork(getLocalSSRCNetwork());
        if ( (0 == offset) && getMark() ) {
            packet->setMarker(true);
            setMark(false);
        } else {
            packet->setMarker(false);
        }
        if (pcc != NULL) {
            packet->protect(getLocalSSRC(), pcc);
        }
        // insert the packet into the "tail" of the sending queue
        sendLock.writeLock();
        OutgoingRTPPktLink *link =
            new OutgoingRTPPktLink(packet,sendLast,NULL);
        if (sendLast)
            sendLast->setNext(link);
        else
            sendFirst = link;
        sendLast = link;
        sendLock.unlock();

        offset += step;
    }
}
Ejemplo n.º 11
0
void WalletSerializer::saveBalances(Common::IOutputStream& destination, bool saveCache, CryptoContext& cryptoContext) {
  uint64_t actual = saveCache ? m_actualBalance : 0;
  uint64_t pending = saveCache ? m_pendingBalance : 0;

  serializeEncrypted(actual, "actual_balance", cryptoContext, destination);
  cryptoContext.incIv();

  serializeEncrypted(pending, "pending_balance", cryptoContext, destination);
  cryptoContext.incIv();
}
Ejemplo n.º 12
0
void WalletSerializer::saveTransactions(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  uint64_t count = m_transactions.size();
  serializeEncrypted(count, "transactions_count", cryptoContext, destination);
  cryptoContext.incIv();

  for (const auto& tx: m_transactions) {
    WalletTransactionDto dto(tx);
    serializeEncrypted(dto, "", cryptoContext, destination);
    cryptoContext.incIv();
  }
}
void WalletSerializerV1::loadObsoleteSpentOutputs(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "spent_outputs_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; ++i) {
    ObsoleteSpentOutputDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();
  }
}
void WalletSerializerV1::loadObsoleteChange(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "changes_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; i++) {
    ObsoleteChangeDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();
  }
}
Ejemplo n.º 15
0
void WalletSerializer::loadChange(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "changes_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; i++) {
    ChangeDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    m_change[dto.txHash] = dto.amount;
  }
}
Ejemplo n.º 16
0
void WalletSerializer::saveChange(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  uint64_t count = m_change.size();
  serializeEncrypted(count, "changes_count", cryptoContext, destination);
  cryptoContext.incIv();

  for (const auto& kv: m_change) {
    ChangeDto dto;
    dto.txHash = kv.first;
    dto.amount = kv.second;

    serializeEncrypted(dto, "", cryptoContext, destination);
    cryptoContext.incIv();
  }
}
Ejemplo n.º 17
0
void WalletSerializer::saveTransfers(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  uint64_t count = m_transfers.size();
  serializeEncrypted(count, "transfers_count", cryptoContext, destination);
  cryptoContext.incIv();

  for (const auto& kv: m_transfers) {
    uint64_t txId = kv.first;
    WalletTransferDto tr(kv.second);

    serializeEncrypted(txId, "transaction_id", cryptoContext, destination);
    cryptoContext.incIv();

    serializeEncrypted(tr, "transfer", cryptoContext, destination);
    cryptoContext.incIv();
  }
}
Ejemplo n.º 18
0
const char * scytale_key_derivate(RedCryptoKeyHandle * handle, const uint8_t * derivator, size_t len)
{
    SCOPED_TRACE;
    CHECK_HANDLE_R(handle, "");

    std::unique_ptr<uint8_t[]> normalized_derivator_gc;
    auto const new_derivator = CryptoContext::get_normalized_derivator(
        normalized_derivator_gc, {derivator, len});

    CryptoContext cctx;
    cctx.old_encryption_scheme = false;
    cctx.one_shot_encryption_scheme = false;
    cctx.set_master_key(handle->master);
    cctx.get_derived_key(handle->derivated, new_derivator);
    hash_to_hashhex(handle->derivated, handle->derivatedhex);
    return handle->derivatedhex;
}
Ejemplo n.º 19
0
void WalletSerializer::saveTransfersSynchronizer(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  std::stringstream stream;
  m_synchronizer.save(stream);
  stream.flush();

  std::string plain = stream.str();
  serializeEncrypted(plain, "transfers_synchronizer", cryptoContext, destination);
  cryptoContext.incIv();
}
Ejemplo n.º 20
0
void WalletSerializer::loadWallets(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_walletsContainer.get<RandomAccessIndex>();

  uint64_t count = 0;
  deserializeEncrypted(count, "wallets_count", cryptoContext, source);
  cryptoContext.incIv();

  bool isTrackingMode;

  for (uint64_t i = 0; i < count; ++i) {
    WalletRecordDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    if (i == 0) {
      isTrackingMode = dto.spendSecretKey == NULL_SECRET_KEY;
    } else if ((isTrackingMode && dto.spendSecretKey != NULL_SECRET_KEY) || (!isTrackingMode && dto.spendSecretKey == NULL_SECRET_KEY)) {
      throw std::system_error(make_error_code(error::BAD_ADDRESS), "All addresses must be whether tracking or not");
    }

    if (dto.spendSecretKey != NULL_SECRET_KEY) {
      Crypto::PublicKey restoredPublicKey;
      bool r = Crypto::secret_key_to_public_key(dto.spendSecretKey, restoredPublicKey);

      if (!r || dto.spendPublicKey != restoredPublicKey) {
        throw std::system_error(make_error_code(error::WRONG_PASSWORD), "Restored spend public key doesn't correspond to secret key");
      }
    } else {
      if (!Crypto::check_key(dto.spendPublicKey)) {
        throw std::system_error(make_error_code(error::WRONG_PASSWORD), "Public spend key is incorrect");
      }
    }

    WalletRecord wallet;
    wallet.spendPublicKey = dto.spendPublicKey;
    wallet.spendSecretKey = dto.spendSecretKey;
    wallet.actualBalance = dto.actualBalance;
    wallet.pendingBalance = dto.pendingBalance;
    wallet.creationTimestamp = static_cast<time_t>(dto.creationTimestamp);
    wallet.container = reinterpret_cast<CryptoNote::ITransfersContainer*>(i); //dirty hack. container field must be unique

    index.push_back(wallet);
  }
}
void WalletSerializerV1::loadTransfersSynchronizer(Common::IInputStream& source, CryptoContext& cryptoContext) {
  std::string deciphered;
  deserializeEncrypted(deciphered, "transfers_synchronizer", cryptoContext, source);
  cryptoContext.incIv();

  std::stringstream stream(deciphered);
  deciphered.clear();

  m_synchronizer.load(stream);
}
Ejemplo n.º 22
0
void WalletSerializer::saveWallets(Common::IOutputStream& destination, bool saveCache, CryptoContext& cryptoContext) {
  auto& index = m_walletsContainer.get<RandomAccessIndex>();

  uint64_t count = index.size();
  serializeEncrypted(count, "wallets_count", cryptoContext, destination);
  cryptoContext.incIv();

  for (const auto& w: index) {
    WalletRecordDto dto;
    dto.spendPublicKey = w.spendPublicKey;
    dto.spendSecretKey = w.spendSecretKey;
    dto.pendingBalance = saveCache ? w.pendingBalance : 0;
    dto.actualBalance = saveCache ? w.actualBalance : 0;
    dto.creationTimestamp = static_cast<uint64_t>(w.creationTimestamp);

    serializeEncrypted(dto, "", cryptoContext, destination);
    cryptoContext.incIv();
  }
}
Ejemplo n.º 23
0
    CryptoContextWrapper(
        get_hmac_key_prototype * hmac_fn, get_trace_key_prototype * trace_fn,
        bool with_encryption, bool with_checksum,
        bool old_encryption_scheme, bool one_shot_encryption_scheme,
        char const * filename_derivatator)
    {
        cctx.set_get_hmac_key_cb(hmac_fn);
        cctx.set_get_trace_key_cb(trace_fn);
        cctx.set_trace_type(
            with_encryption
            ? TraceType::cryptofile
            : with_checksum
                ? TraceType::localfile_hashed
                : TraceType::localfile);
        cctx.old_encryption_scheme = old_encryption_scheme;
        cctx.one_shot_encryption_scheme = one_shot_encryption_scheme;

        size_t base_len = 0;
        char const * base = basename_len(filename_derivatator, base_len);
        cctx.set_master_derivator({base, base_len});
    }
Ejemplo n.º 24
0
void WalletSerializer::saveSpentOutputs(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  auto& index = m_spentOutputs.get<WalletIndex>();

  uint64_t outsCount = index.size();
  serializeEncrypted(outsCount, "spent_outputs_count", cryptoContext, destination);
  cryptoContext.incIv();

  for (const auto& o: index) {
    auto it = m_walletsContainer.get<RandomAccessIndex>().iterator_to(*o.wallet);
    uint64_t walletIndex = std::distance(m_walletsContainer.get<RandomAccessIndex>().begin(), it);

    SpentOutputDto dto;
    dto.amount = o.amount;
    dto.transactionHash = o.transactionHash;
    dto.outputInTransaction = o.outputInTransaction;
    dto.walletIndex = walletIndex;
    dto.spendingTransactionHash = o.spendingTransactionHash;

    serializeEncrypted(dto, "", cryptoContext, destination);
    cryptoContext.incIv();
  }
}
Ejemplo n.º 25
0
void WalletSerializer::loadTransfers(Common::IInputStream& source, CryptoContext& cryptoContext) {
  uint64_t count = 0;
  deserializeEncrypted(count, "transfers_count", cryptoContext, source);
  cryptoContext.incIv();

  m_transfers.reserve(count);

  for (uint64_t i = 0; i < count; ++i) {
    uint64_t txId = 0;
    deserializeEncrypted(txId, "transaction_id", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransferDto dto;
    deserializeEncrypted(dto, "transfer", cryptoContext, source);
    cryptoContext.incIv();

    WalletTransfer tr;
    tr.address = dto.address;
    tr.amount = dto.amount;

    m_transfers.push_back(std::make_pair(txId, tr));
  }
}
Ejemplo n.º 26
0
void WalletSerializer::loadWallets(Common::IInputStream& source, CryptoContext& cryptoContext) {
  auto& index = m_walletsContainer.get<RandomAccessIndex>();

  uint64_t count = 0;
  deserializeEncrypted(count, "wallets_count", cryptoContext, source);
  cryptoContext.incIv();

  for (uint64_t i = 0; i < count; ++i) {
    WalletRecordDto dto;
    deserializeEncrypted(dto, "", cryptoContext, source);
    cryptoContext.incIv();

    WalletRecord wallet;
    wallet.spendPublicKey = dto.spendPublicKey;
    wallet.spendSecretKey = dto.spendSecretKey;
    wallet.actualBalance = dto.actualBalance;
    wallet.pendingBalance = dto.pendingBalance;
    wallet.creationTimestamp = static_cast<time_t>(dto.creationTimestamp);
    wallet.container = reinterpret_cast<CryptoNote::ITransfersContainer*>(i); //dirty hack. container field must be unique

    index.push_back(wallet);
  }
}
Ejemplo n.º 27
0
bool CtZrtpStream::srtpSecretsReady(SrtpSecret_t* secrets, EnableSecurity part)
{
    CryptoContext* recvCryptoContext;
    CryptoContext* senderCryptoContext;
    CryptoContextCtrl* recvCryptoContextCtrl;
    CryptoContextCtrl* senderCryptoContextCtrl;

    int cipher;
    int authn;
    int authKeyLen;

    if (secrets->authAlgorithm == Sha1) {
        authn = SrtpAuthenticationSha1Hmac;
        authKeyLen = 20;
    }

    if (secrets->authAlgorithm == Skein) {
        authn = SrtpAuthenticationSkeinHmac;
        authKeyLen = 32;
    }

    if (secrets->symEncAlgorithm == Aes)
        cipher = SrtpEncryptionAESCM;

    if (secrets->symEncAlgorithm == TwoFish)
        cipher = SrtpEncryptionTWOCM;

    role = secrets->role;

    if (part == ForSender) {
        // To encrypt packets: intiator uses initiator keys,
        // responder uses responder keys
        // Create a "half baked" crypto context first and store it. This is
        // the main crypto context for the sending part of the connection.
        if (secrets->role == Initiator) {
            senderCryptoContext = 
                new CryptoContext(0,                                       // SSRC (used for lookup)
                                  0,                                       // Roll-Over-Counter (ROC)
                                  0L,                                      // keyderivation << 48,
                                  cipher,                                  // encryption algo
                                  authn,                                   // authtentication algo
                                  (unsigned char*)secrets->keyInitiator,   // Master Key
                                  secrets->initKeyLen / 8,                 // Master Key length
                                  (unsigned char*)secrets->saltInitiator,  // Master Salt
                                  secrets->initSaltLen / 8,                // Master Salt length
                                  secrets->initKeyLen / 8,                 // encryption keyl
                                  authKeyLen,                              // authentication key len
                                  secrets->initSaltLen / 8,                // session salt len
                                  secrets->srtpAuthTagLen / 8);            // authentication tag lenA
            senderCryptoContextCtrl = 
                new CryptoContextCtrl(0,                                         // SSRC (used for lookup)
                                      cipher,                                    // encryption algo
                                      authn,                                     // authtication algo
                                      (unsigned char*)secrets->keyInitiator,     // Master Key
                                      secrets->initKeyLen / 8,                   // Master Key length
                                      (unsigned char*)secrets->saltInitiator,    // Master Salt
                                      secrets->initSaltLen / 8,                  // Master Salt length
                                      secrets->initKeyLen / 8,                   // encryption keyl
                                      authKeyLen,                                // authentication key len
                                      secrets->initSaltLen / 8,                  // session salt len
                                      secrets->srtpAuthTagLen / 8);              // authentication tag len
        }
        else {
            senderCryptoContext = 
                new CryptoContext(0,                                       // SSRC (used for lookup)
                                  0,                                       // Roll-Over-Counter (ROC)
                                  0L,                                      // keyderivation << 48,
                                  cipher,                                  // encryption algo
                                  authn,                                   // authtentication algo
                                  (unsigned char*)secrets->keyResponder,   // Master Key
                                  secrets->respKeyLen / 8,                 // Master Key length
                                  (unsigned char*)secrets->saltResponder,  // Master Salt
                                  secrets->respSaltLen / 8,                // Master Salt length
                                  secrets->respKeyLen / 8,                 // encryption keyl
                                  authKeyLen,                              // authentication key len
                                  secrets->respSaltLen / 8,                // session salt len
                                  secrets->srtpAuthTagLen / 8);            // authentication tag len
            senderCryptoContextCtrl = 
                new CryptoContextCtrl(0,                                         // SSRC (used for lookup)
                                      cipher,                                    // encryption algo
                                      authn,                                     // authtication algo
                                      (unsigned char*)secrets->keyResponder,     // Master Key
                                      secrets->respKeyLen / 8,                   // Master Key length
                                      (unsigned char*)secrets->saltResponder,    // Master Salt
                                      secrets->respSaltLen / 8,                  // Master Salt length
                                      secrets->respKeyLen / 8,                   // encryption keyl
                                      authKeyLen,                                // authentication key len
                                      secrets->respSaltLen / 8,                  // session salt len
                                      secrets->srtpAuthTagLen / 8);              // authentication tag len
        }
        if (senderCryptoContext == NULL) {
            return false;
        }
        senderCryptoContext->deriveSrtpKeys(0L);
        sendSrtp = senderCryptoContext;

        senderCryptoContextCtrl->deriveSrtcpKeys();
        sendSrtcp = senderCryptoContextCtrl;
    }
    if (part == ForReceiver) {
        // To decrypt packets: intiator uses responder keys,
        // responder initiator keys
        // See comment above.
        if (secrets->role == Initiator) {
            recvCryptoContext = 
                new CryptoContext(0,                                       // SSRC (used for lookup)
                                  0,                                       // Roll-Over-Counter (ROC)
                                  0L,                                      // keyderivation << 48,
                                  cipher,                                  // encryption algo
                                  authn,                                   // authtentication algo
                                  (unsigned char*)secrets->keyResponder,   // Master Key
                                  secrets->respKeyLen / 8,                 // Master Key length
                                  (unsigned char*)secrets->saltResponder,  // Master Salt
                                  secrets->respSaltLen / 8,                // Master Salt length
                                  secrets->respKeyLen / 8,                 // encryption keyl
                                  authKeyLen,                              // authentication key len
                                  secrets->respSaltLen / 8,                // session salt len
                                  secrets->srtpAuthTagLen / 8);            // authentication tag len
            recvCryptoContextCtrl = 
                new CryptoContextCtrl(0,                                         // SSRC (used for lookup)
                                      cipher,                                    // encryption algo
                                      authn,                                     // authtication algo
                                      (unsigned char*)secrets->keyResponder,     // Master Key
                                      secrets->respKeyLen / 8,                   // Master Key length
                                      (unsigned char*)secrets->saltResponder,    // Master Salt
                                      secrets->respSaltLen / 8,                  // Master Salt length
                                      secrets->respKeyLen / 8,                   // encryption keyl
                                      authKeyLen,                                // authentication key len
                                      secrets->respSaltLen / 8,                  // session salt len
                                      secrets->srtpAuthTagLen / 8);              // authentication tag len
        }
        else {
            recvCryptoContext = 
                new CryptoContext(0,                                       // SSRC (used for lookup)
                                  0,                                       // Roll-Over-Counter (ROC)
                                  0L,                                      // keyderivation << 48,
                                  cipher,                                  // encryption algo
                                  authn,                                   // authtentication algo
                                  (unsigned char*)secrets->keyInitiator,   // Master Key
                                  secrets->initKeyLen / 8,                 // Master Key length
                                  (unsigned char*)secrets->saltInitiator,  // Master Salt
                                  secrets->initSaltLen / 8,                // Master Salt length
                                  secrets->initKeyLen / 8,                 // encryption keyl
                                  authKeyLen,                              // authentication key len
                                  secrets->initSaltLen / 8,                // session salt len
                                  secrets->srtpAuthTagLen / 8);            // authentication tag len
            recvCryptoContextCtrl = 
                new CryptoContextCtrl(0,                                         // SSRC (used for lookup)
                                      cipher,                                    // encryption algo
                                      authn,                                     // authtication algo
                                      (unsigned char*)secrets->keyInitiator,     // Master Key
                                      secrets->initKeyLen / 8,                   // Master Key length
                                      (unsigned char*)secrets->saltInitiator,    // Master Salt
                                      secrets->initSaltLen / 8,                  // Master Salt length
                                      secrets->initKeyLen / 8,                   // encryption keyl
                                      authKeyLen,                                // authentication key len
                                      secrets->initSaltLen / 8,                  // session salt len
                                      secrets->srtpAuthTagLen / 8);              // authentication tag len
        }
        if (recvCryptoContext == NULL) {
            return false;
        }
        recvCryptoContext->deriveSrtpKeys(0L);
        recvSrtp = recvCryptoContext;

        recvCryptoContextCtrl->deriveSrtcpKeys();
        recvSrtcp = recvCryptoContextCtrl;

        supressCounter = 0;         // supress SRTP warnings for some packets after we switch to SRTP
    }
    if (zrtpHashMatch && recvSrtp != NULL && sendSrtp != NULL) {
        sdesActive = false;
    }
    return true;
}
void WalletSerializerV1::loadPublicKey(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_viewPublicKey, "public_key", cryptoContext, source);
  cryptoContext.incIv();
}
Ejemplo n.º 29
0
void WalletSerializer::saveSecretKey(Common::IOutputStream& destination, CryptoContext& cryptoContext) {
  serializeEncrypted(m_viewSecretKey, "secret_key", cryptoContext, destination);
  cryptoContext.incIv();
}
void WalletSerializerV1::loadSecretKey(Common::IInputStream& source, CryptoContext& cryptoContext) {
  deserializeEncrypted(m_viewSecretKey, "secret_key", cryptoContext, source);
  cryptoContext.incIv();
}