void MixClient::resetState(std::map<Secret, u256> _accounts, Secret _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); m_filters.clear(); m_watches.clear(); m_stateDB = OverlayDB(); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); accountState.init(); m_userAccounts.clear(); std::map<Address, Account> genesisState; for (auto account: _accounts) { KeyPair a = KeyPair(account.first); m_userAccounts.push_back(a); genesisState.insert(std::make_pair(a.address(), Account(account.second, Account::NormalCreation))); } dev::eth::commit(genesisState, static_cast<MemoryDB&>(m_stateDB), accountState); h256 stateRoot = accountState.root(); m_bc.reset(); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); m_state = eth::State(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); m_state.sync(bc()); m_startState = m_state; WriteGuard lx(x_executions); m_executions.clear(); }
GridWorld::KeyPair GridWorld::calculateKey(GridWorld::Tile*& tile){ double key2 = std::min(tile->g, tile->rhs); double key1 = key2 + calculateH(tile) + km; //H-value should be recalculated as it can change during incremental search return KeyPair(key1, key2); }
void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); m_filters.clear(); for (auto& i: m_specialFilters) i.second.clear(); m_watches.clear(); m_stateDB = OverlayDB(); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); accountState.init(); dev::eth::commit(_accounts, accountState); h256 stateRoot = accountState.root(); m_bc.reset(); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); Block b(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); b.sync(bc()); m_preMine = b; m_postMine = b; WriteGuard lx(x_executions); m_executions.clear(); }
KeyPair KeyGenerator::generate(const unsigned char *entropy, size_t entropySize) { if(entropySize<32) { throw std::runtime_error("not enough entropy"); } for(int i=0; i<100; i++) { try { PrivateKey privateKey = _privateKeyGenerator.generate(entropy, entropySize); return KeyPair(privateKey, _publicKeyGenerator.createFromSecret(privateKey)); } catch(const std::runtime_error &) {} entropy++; entropySize--; if(entropySize<32) { break; } } throw std::runtime_error("key generation failed"); }
/* static */ void WinUtils::SetupKeyModifiersSequence(nsTArray<KeyPair>* aArray, uint32_t aModifiers) { for (uint32_t i = 0; i < ArrayLength(sModifierKeyMap); ++i) { const uint32_t* map = sModifierKeyMap[i]; if (aModifiers & map[0]) { aArray->AppendElement(KeyPair(map[1], map[2])); } } }
void Dictionary::Remove(string element) { KeyPair item = KeyPair(); if (GetElement(element, &item)) { RemoveFromDict(&item); } else { throw new exception("NO TOY"); } }
int main(int argc, char **argv) # endif { FILE *in = NULL, *out = NULL; const char *cmd = argv[1]; int rv = 0; fips_algtest_init(); if (argc == 4) { in = fopen(argv[2], "r"); if (!in) { fprintf(stderr, "Error opening input file\n"); exit(1); } out = fopen(argv[3], "w"); if (!out) { fprintf(stderr, "Error opening output file\n"); exit(1); } } else if (argc == 2) { in = stdin; out = stdout; } if (!cmd) { fprintf(stderr, "fips_ecdsavs [KeyPair|PKV|SigGen|SigVer]\n"); return 1; } if (!strcmp(cmd, "KeyPair")) rv = KeyPair(in, out); else if (!strcmp(cmd, "PKV")) rv = PKV(in, out); else if (!strcmp(cmd, "SigVer")) rv = SigVer(in, out); else if (!strcmp(cmd, "SigGen")) rv = SigGen(in, out); else { fprintf(stderr, "Unknown command %s\n", cmd); return 1; } if (argc == 4) { fclose(in); fclose(out); } if (rv <= 0) { fprintf(stderr, "Error running %s\n", cmd); return 1; } return 0; }
KeyPair KeyGenerator::generate() { for(int i=0; i<100; i++) { try { PrivateKey privateKey = _privateKeyGenerator.generate(); return KeyPair(privateKey, _publicKeyGenerator.createFromSecret(privateKey)); } catch(const std::runtime_error &) {} } throw std::runtime_error("failed to generate keypair"); }
void Dictionary::RemoveAt(unsigned int position) { KeyPair item = KeyPair(); if (GetElementAt(position, &item)) { if (RemoveFromDict(&item)) { throw new exception("NO BORRADO"); } } else { throw new exception("NO TOY"); } }
KeyboardConfig::KeyPair KeyboardConfig::getConflicts() { /** * No need to parse the square matrix: only check one triangle * that's enough to detect conflicts */ for (int i = 0; i < KEY_TOTAL; i++) { for (int j = i + 1; j < KEY_TOTAL; j++) { // Allow for item shortcut and emote keys to overlap, but no other keys // Also don't allow a key to be assigned to tab, since this // can mess up focus handling with the keyboard and cause unexpected // behavior. if (!(((j >= KEY_ITEM_SHORTCUT_1) && (j <= KEY_ITEM_SHORTCUT_12)) && ((i >= KEY_EMOTE_SHORTCUT_1) && (i <= KEY_EMOTE_SHORTCUT_12))) && (mKey[i].value == mKey[j].value || mKey[i].value == SDLK_TAB)) { return KeyPair(i, j); } } } return KeyPair(KEY_NO_VALUE, KEY_NO_VALUE); }
TVerdict CEncryptStep::doTestStepPreambleL() { ConstructL(); CTlsCryptoAttributes* atts = Provider()->Attributes(); // Reads PSK values if included in INI file. ReadPskToBeUsedL(); // Reads if NULL ciphers suites are to be allowed from INI file. ReadUseNullCipher(); // read the "server" random HBufC8* random = ServerRandomL(); atts->iMasterSecretInput.iServerRandom.Copy(*random); delete random; // and the client random random = ClientRandomL(); atts->iMasterSecretInput.iClientRandom.Copy(*random); delete random; // we only support null compression... atts->iCompressionMethod = ENullCompression; // read the cipher suite for the test atts->iCurrentCipherSuite = CipherSuiteL(); // read the protocol version TTLSProtocolVersion version = ProtocolVersionL(); atts->iNegotiatedProtocol = version; atts->iProposedProtocol = version; // set the session ID and "server" name (localhost) atts->iSessionNameAndID.iSessionId = SessionId(); atts->iSessionNameAndID.iServerName.iAddress = KLocalHost; atts->iSessionNameAndID.iServerName.iPort = 443; atts->idomainName.Copy(DomainNameL()); // If cipher suite under test is uses PSK (Pre Shared Key) if(UsePsk()) { // Populates values for PSK atts->iPskConfigured = true; atts->iPublicKeyParams->iKeyType = EPsk; atts->iPublicKeyParams->iValue4 = PskIdentity(); atts->iPublicKeyParams->iValue5 = PskKey(); } else { // If cipher suite under test is NOT PSK TRAPD(err, ReadDHParamsL()); if (err == KErrNone) { atts->iPublicKeyParams->iKeyType = EDHE; // The params are: // 1 - Prime // 2 - Generator // 3 - generator ^ random mod prime atts->iPublicKeyParams->iValue1 = Prime().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue1); atts->iPublicKeyParams->iValue2 = Generator().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue2); atts->iPublicKeyParams->iValue3 = KeyPair()->PublicKey().X().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue3); } } // No client authentication or dialogs for this test, please atts->iClientAuthenticate = EFalse; atts->iDialogNonAttendedMode = ETrue; if(UseNullCipher()) { // Enables null cipher by setting appropiate parameter atts->iAllowNullCipherSuites = ETrue; } return EPass; }
TVerdict CVerifySignatureStep::doTestStepPreambleL() { ConstructL(); CTlsCryptoAttributes* atts = Provider()->Attributes(); // read the "server" random HBufC8* random = ServerRandomL(); atts->iMasterSecretInput.iServerRandom.Copy(*random); delete random; // and the client random random = ClientRandomL(); atts->iMasterSecretInput.iClientRandom.Copy(*random); delete random; // we only support null compression... atts->iCompressionMethod = ENullCompression; // read the cipher suite for the test atts->iCurrentCipherSuite = CipherSuiteL(); // read the protocol version TTLSProtocolVersion version = ProtocolVersionL(); atts->iNegotiatedProtocol = version; atts->iProposedProtocol = version; // set the session ID and "server" name (localhost) atts->iSessionNameAndID.iSessionId = SessionId(); atts->iSessionNameAndID.iServerName.iAddress = KLocalHost; atts->iSessionNameAndID.iServerName.iPort = 443; atts->idomainName.Copy(DomainNameL()); // try and read DH params, this section may not exist RInteger gen; CleanupClosePushL(gen); RInteger prime; CleanupClosePushL(prime); TRAPD(err, ReadDHParamsL()); if (err == KErrNone) { atts->iPublicKeyParams->iKeyType = EDHE; // The params are: // 1 - Prime // 2 - Generator // 3 - generator ^ random mod prime atts->iPublicKeyParams->iValue1 = Prime().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue1); atts->iPublicKeyParams->iValue2 = Generator().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue2); atts->iPublicKeyParams->iValue3 = KeyPair()->PublicKey().X().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue3); } CleanupStack::PopAndDestroy(2, &gen); // prime // No client authentication or dialogs for this test, please atts->iClientAuthenticate = EFalse; atts->iDialogNonAttendedMode = ETrue; return EPass; }
void CNewKeyDerivationStep::doTestL() { TInt err; iProvider = CTLSProvider::ConnectL(); TCleanupItem cleanupInsProvider(CleanupCTlsProvider, iProvider); CleanupStack::PushL(cleanupInsProvider); // cleanup of key material. TCleanupItem cleanupInsKeyMaterial(CleanupKeyMaterial, this); CleanupStack::PushL(cleanupInsKeyMaterial); CTlsCryptoAttributes* atts = iProvider->Attributes(); // sets the "server" random atts->iMasterSecretInput.iServerRandom.Copy(*iServerRandom); // Sets the client random atts->iMasterSecretInput.iClientRandom.Copy(*iClientRandom); // we only support null compression... atts->iCompressionMethod = ENullCompression; // Sets cipher suite for the test. atts->iCurrentCipherSuite = iCipherSuite; // Sets protocol version. atts->iNegotiatedProtocol = iProtocolVersion; atts->iProposedProtocol = iProtocolVersion; // set the session ID and "server" name (localhost) atts->iSessionNameAndID.iSessionId = iSessionId; atts->iSessionNameAndID.iServerName.iAddress = KLocalHost; atts->iSessionNameAndID.iServerName.iPort = 443; atts->idomainName.Copy(iDomainName); // If cipher suite under test uses PSK (Pre Shared Key) if(UsePsk()) { // Populates values for PSK atts->iPskConfigured = true; atts->iPublicKeyParams->iKeyType = EPsk; atts->iPublicKeyParams->iValue4 = PskIdentity()->Alloc(); // = PskIdentity(); atts->iPublicKeyParams->iValue5 = PskKey()->Alloc(); } else { if(iUseDHParams) { // If cipher suite under test is NOT PSK atts->iPublicKeyParams->iKeyType = EDHE; // The params are: // 1 - Prime // 2 - Generator // 3 - generator ^ random mod prime atts->iPublicKeyParams->iValue1 = Prime().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue1); atts->iPublicKeyParams->iValue2 = Generator().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue2); atts->iPublicKeyParams->iValue3 = KeyPair()->PublicKey().X().BufferLC(); CleanupStack::Pop(atts->iPublicKeyParams->iValue3); } } // No client authentication or dialogs for this test, please atts->iClientAuthenticate = EFalse; atts->iDialogNonAttendedMode = ETrue; if(UseNullCipher()) { // Enables null cipher by setting appropiate parameter atts->iAllowNullCipherSuites = ETrue; } err = LeanGetCipherSuitesL(); if (err != KErrNone) { User::Leave(iActive->iStatus.Int()); } TCleanupItem cleanupInsSuitesArray(CleanupSuiteArray,&iSuites); CleanupStack::PushL(cleanupInsSuitesArray); // verifies certificate if is not a PSK cipher suite if( !UsePsk() ) { // we have to verify the server certificate, to supply the certificate // and its parameters to the TLS provider. CX509Certificate* cert = NULL; err = LeanVerifyServerCertificate(cert, iServerCertificate); delete cert; // make sure it completed sucessfully. if (err != KErrNone) { User::Leave(iActive->iStatus.Int()); } } // now, create a session with the parameters set err = LeanCreateSession(); // ensure we succeeded if (err != KErrNone) { User::Leave(iActive->iStatus.Int()); } TCleanupItem cleanupInsTlsSession(CleanupCTlsSession, iSession); CleanupStack::PushL(cleanupInsTlsSession); HBufC8* keyExMessage = NULL; err = LeanClientKeyExchange(keyExMessage); if (err != KErrNone) { User::Leave(iActive->iStatus.Int()); } CleanupStack::PushL(keyExMessage); HBufC8* premaster = LeanDerivePreMasterSecretL(*keyExMessage, iServerPrivateKey); CleanupStack::PopAndDestroy(keyExMessage); // compute the master secret from the premaster. CleanupStack::PushL(premaster); HBufC8* master = LeanComputeMasterSecretL(*premaster); CleanupStack::PopAndDestroy(premaster); CleanupStack::PushL(master); // now generate what we think the derived EAP key block should look like. TBuf8<192> ourEAP; TBuf8<64> random; random.Append(atts->iMasterSecretInput.iClientRandom); random.Append(atts->iMasterSecretInput.iServerRandom); // make sure we're using TLS. This step makes no sense for SSL 3.0 if (atts->iNegotiatedProtocol.iMajor == 3 && atts->iNegotiatedProtocol.iMinor == 0) { INFO_PRINTF1(_L("Error! Cannot use this test step with SSLv3!")); User::Leave(KErrNotSupported); } // compute the 128 byte block that uses the master secret as key. _LIT8(KEAPEncryptionLabel, "client EAP encryption"); HBufC8* block1 = CTls10PsuedoRandom::PseudoRandomL(*master, KEAPEncryptionLabel, random, 128); ourEAP.Append(*block1); delete block1; // compute the 64 byte IV block HBufC8* block2 = CTls10PsuedoRandom::PseudoRandomL(KNullDesC8, KEAPEncryptionLabel, random, 64); ourEAP.Append(*block2); delete block2; // get the TLS provider's idea of what the EAP keyblock should be, and check they match. TBuf8<192> theirEAP; User::LeaveIfError(iSession->KeyDerivation(KEAPEncryptionLabel, atts->iMasterSecretInput, theirEAP)); if (ourEAP == theirEAP) { INFO_PRINTF1(_L("Test passed.")); SetTestStepResult(EPass); } else { INFO_PRINTF1(_L("Failed! EAP-TLS is corrupt!")); SetTestStepResult(EFail); } CleanupStack::PopAndDestroy(5); }
void ClientConfiguration::createTemplateConfigurationFile(QString const& filename) { ClientConfiguration sc(ContactId(QByteArray::fromHex("AAAAAAAA")), KeyPair()); sc.toFile(filename); }