int main ( int argc, char *argv[], char *env[] ) { int deviceFile = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY); //opening device file. ATTENTION: you have to have access to it. Easiest way is to "sudo ./a.out". if(deviceFile < 0) { printf("Device file not opened. Most likely you don't have access to it, try to run your program with sudo"); } memset(keys, 0, sizeof(keys)); //just in case, not really necessary struct Player player; player.x = width / 2; while(1) { int x; int y; for(y = 0; y < height; y++) { printf("\n"); } ioctl (deviceFile, EVIOCGKEY(sizeof keys), &keys); //update keyboard state if(testKey(leftKey) && player.x > 0) player.x--; if(testKey(rightKey) && player.x < width - 1) player.x++; for(x = 0; x < width; x++) { if(x == player.x) { printf("@"); } else if(x > 0 || x < width - 1) { printf("."); }else { printf("#"); } } printf("\n\n"); //to avoid screen tearing int w; for(w = 0; w < 10000000; w++); } return 0; }
TEST_F(KeymasterTest, SignData_RSA_Raw_InvalidSizeInput_Failure) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_SIGN_RSA_KEY_1, sizeof(TEST_SIGN_RSA_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueKey key(&sDevice, key_blob, key_blob_length); keymaster_rsa_sign_params_t params = { .digest_type = DIGEST_NONE, .padding_type = PADDING_NONE, }; uint8_t* sig; size_t sig_length; UniqueReadOnlyBlob testData(TEST_RSA_KEY_1, sizeof(TEST_RSA_KEY_1)); ASSERT_TRUE(testData.get() != NULL); ASSERT_EQ(-1, sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length, testData.get(), testData.length(), &sig, &sig_length)) << "Should not be able to do raw signature on incorrect size data"; }
TEST_F(KeymasterTest, DeleteKeyPair_RSA_DoubleDelete_Failure) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_RSA_KEY_1, sizeof(TEST_RSA_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); /* * This is only run if the module indicates it implements key deletion * by implementing delete_keypair. */ if (sDevice->delete_keypair != NULL) { ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueBlob blob(key_blob, key_blob_length); ASSERT_EQ(0, sDevice->delete_keypair(sDevice, key_blob, key_blob_length)) << "Should delete key after import"; ASSERT_EQ(-1, sDevice->delete_keypair(sDevice, key_blob, key_blob_length)) << "Should not be able to delete key twice"; } }
void test(void) { utInitTestUart(); testKey(); //testIO(); //testDAC8560(); //initTFT100 (); //testADS1110(); //testCom3(); //testCom3(); //testUart(); //testCom2(); //testStore(); //testRelay(); //testCom1(); //testLCD(); //testMotor (); //testKey (); //swgInitRelay(); //testDAC8560(); //bgStepMotor(); //bgCal656nm (); while(1); }
TEST_F(KeymasterTest, DeleteKeyPair_RSA_Success) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_RSA_KEY_1, sizeof(TEST_RSA_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueKey key(&sDevice, key_blob, key_blob_length); }
TEST_F(KeymasterTest, SignData_EC_Success) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_SIGN_EC_KEY_1, sizeof(TEST_SIGN_EC_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an EC key"; UniqueKey key(&sDevice, key_blob, key_blob_length); keymaster_ec_sign_params_t params = { .digest_type = DIGEST_NONE, }; uint8_t* sig; size_t sig_length; UniqueReadOnlyBlob testData(TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1)); ASSERT_TRUE(testData.get() != NULL); ASSERT_EQ(0, sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length, testData.get(), testData.length(), &sig, &sig_length)) << "Should sign data successfully"; UniqueBlob sig_blob(sig, sig_length); uint8_t* x509_data; size_t x509_data_length; ASSERT_EQ(0, sDevice->get_keypair_public(sDevice, key_blob, key_blob_length, &x509_data, &x509_data_length)) << "Should be able to retrieve RSA public key successfully"; UniqueBlob x509_blob(x509_data, x509_data_length); const unsigned char *tmp = static_cast<const unsigned char*>(x509_blob.get()); Unique_EVP_PKEY expected(d2i_PUBKEY((EVP_PKEY**) NULL, &tmp, static_cast<long>(x509_blob.length()))); Unique_EC_KEY ecKey(EVP_PKEY_get1_EC_KEY(expected.get())); ASSERT_EQ(1, ECDSA_verify(0, testData.get(), testData.length(), sig_blob.get(), sig_blob.length(), ecKey.get())) << "Signature should verify"; }
TEST_F(KeymasterTest, GetKeypairPublic_EC_NullDestination_Failure) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_EC_KEY_1, sizeof(TEST_EC_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueKey key(&sDevice, key_blob, key_blob_length); ASSERT_EQ(-1, sDevice->get_keypair_public(sDevice, key.get(), key.length(), NULL, NULL)) << "Should not be able to succeed with NULL destination blob"; }
int main() { int score = 0; printf("\nIniciando o teste do módulo message\n"); score += testResult(); score += testKey(); score += testValue(); score += testEntry(); score += testKeys(); score += testInvalida(); printf("Resultados do teste do módulo message: %d em 6\n\n",score); return score; }
TEST_F(KeymasterTest, GetKeypairPublic_EC_Success) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_EC_KEY_1, sizeof(TEST_EC_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an EC key"; UniqueKey key(&sDevice, key_blob, key_blob_length); uint8_t* x509_data; size_t x509_data_length; ASSERT_EQ(0, sDevice->get_keypair_public(sDevice, key_blob, key_blob_length, &x509_data, &x509_data_length)) << "Should be able to retrieve EC public key successfully"; UniqueBlob x509_blob(x509_data, x509_data_length); }
TEST_F(KeymasterTest, SignData_RSA_Raw_Success) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_SIGN_RSA_KEY_1, sizeof(TEST_SIGN_RSA_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueKey key(&sDevice, key_blob, key_blob_length); keymaster_rsa_sign_params_t params = { .digest_type = DIGEST_NONE, .padding_type = PADDING_NONE, }; uint8_t* sig; size_t sig_length; UniqueReadOnlyBlob testData(TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1)); ASSERT_TRUE(testData.get() != NULL); ASSERT_EQ(0, sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length, testData.get(), testData.length(), &sig, &sig_length)) << "Should sign data successfully"; UniqueBlob sig_blob(sig, sig_length); UniqueBlob expected_sig(TEST_SIGN_RSA_SIGNATURE_1, sizeof(TEST_SIGN_RSA_SIGNATURE_1)); ASSERT_EQ(expected_sig, sig_blob) << "Generated signature should match expected signature"; // The expected signature is actually stack data, so don't let it try to free. uint8_t* unused __attribute__((unused)) = expected_sig.release(); }
void KdfRomix::computeKdfParams(double targetComputeSec, uint32_t maxMemReqts) { // Create a random salt, even though this is probably unnecessary: // the variation in numIter and memReqts is probably effective enough salt_ = SecureBinaryData().GenerateRandom(32); // If target compute is 0s, then this method really only generates // a random salt, and sets the other params to default minimum. if(targetComputeSec == 0) { numIterations_ = 1; memoryReqtBytes_ = 1024; return; } // Here, we pick the largest memory reqt that allows the executing system // to compute the KDF is less than the target time. A maximum can be // specified, in case the target system is likely to be memory-limited // more than compute-speed limited SecureBinaryData testKey("This is an example key to test KDF iteration speed"); // Start the search for a memory value at 1kB memoryReqtBytes_ = 1024; double approxSec = 0; while(approxSec <= targetComputeSec/4 && memoryReqtBytes_ < maxMemReqts) { memoryReqtBytes_ *= 2; sequenceCount_ = memoryReqtBytes_ / hashOutputBytes_; lookupTable_.resize(memoryReqtBytes_); TIMER_RESTART("KDF_Mem_Search"); testKey = DeriveKey_OneIter(testKey); TIMER_STOP("KDF_Mem_Search"); approxSec = TIMER_READ_SEC("KDF_Mem_Search"); } // Recompute here, in case we didn't enter the search above sequenceCount_ = memoryReqtBytes_ / hashOutputBytes_; lookupTable_.resize(memoryReqtBytes_); // Depending on the search above (or if a low max memory was chosen, // we may need to do multiple iterations to achieve the desired compute // time on this system. double allItersSec = 0; uint32_t numTest = 1; while(allItersSec < 0.02) { numTest *= 2; TIMER_RESTART("KDF_Time_Search"); for(uint32_t i=0; i<numTest; i++) { SecureBinaryData testKey("This is an example key to test KDF iteration speed"); testKey = DeriveKey_OneIter(testKey); } TIMER_STOP("KDF_Time_Search"); allItersSec = TIMER_READ_SEC("KDF_Time_Search"); } double perIterSec = allItersSec / numTest; numIterations_ = (uint32_t)(targetComputeSec / (perIterSec+0.0005)); numIterations_ = (numIterations_ < 1 ? 1 : numIterations_); //cout << "System speed test results : " << endl; //cout << " Total test of the KDF took: " << allItersSec*1000 << " ms" << endl; //cout << " to execute: " << numTest << " iterations" << endl; //cout << " Target computation time is: " << targetComputeSec*1000 << " ms" << endl; //cout << " Setting numIterations to: " << numIterations_ << endl; }
bool testSDLKey(SDLKey key) { Uint32 k = SDLToDOSKey(key); return k ? testKey(k) : false; }