int main (int argc, char *argv[]) { int failureCount = 0; GNUNET_log_setup ("test-crypto-rsa", "WARNING", NULL); GNUNET_CRYPTO_random_disable_entropy_gathering (); if (GNUNET_OK != testCreateFromFile ()) failureCount++; #if PERF if (GNUNET_OK != testEncryptPerformance ()) failureCount++; if (GNUNET_OK != testSignPerformance ()) failureCount++; #endif if (GNUNET_OK != testEncryptDecryptSK ()) failureCount++; if (GNUNET_OK != testEncryptDecrypt ()) failureCount++; if (GNUNET_OK != testSignVerify ()) failureCount++; if (failureCount != 0) { printf ("\n\n%d TESTS FAILED!\n\n", failureCount); return -1; } return 0; } /* end of main */
/** * Main function that will be run by the scheduler. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param cfg configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CRYPTO_RsaPrivateKey *pk; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; struct GNUNET_PeerIdentity pid; if (NULL == args[0]) { fprintf (stderr, _("No hostkey file specified on command line\n")); return; } if (0 != weak_random) GNUNET_CRYPTO_random_disable_entropy_gathering (); if (make_keys > 0) { create_keys (args[0]); return; } pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); if (NULL == pk) return; if (print_public_key) { char *s; GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); s = GNUNET_CRYPTO_rsa_public_key_to_string (&pub); fprintf (stdout, "%s\n", s); GNUNET_free (s); } if (print_peer_identity) { struct GNUNET_CRYPTO_HashAsciiEncoded enc; GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc); fprintf (stdout, "%s\n", enc.encoding); } if (print_short_identity) { struct GNUNET_CRYPTO_ShortHashAsciiEncoded enc; struct GNUNET_CRYPTO_ShortHashCode sh; GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &sh); GNUNET_CRYPTO_short_hash_to_enc (&sh, &enc); fprintf (stdout, "%s\n", enc.short_encoding); } GNUNET_CRYPTO_rsa_key_free (pk); }
int main (int argc, char *argv[]) { int ok; struct GNUNET_HashCode rid1; struct GNUNET_HashCode id2; struct GNUNET_HashCode rid2; struct GNUNET_HashCode fid; struct GNUNET_HashCode id3; int old; int newVal; struct GNUNET_CONFIGURATION_Handle *cfg; char *name1; char *name2; char *name3; char *name1_unique; char *name2_unique; char *noname; int noname_is_a_dup; int notiCount, fakenotiCount; int count; static char m[1024 * 1024 * 10]; memset (m, 'b', sizeof (m)); m[sizeof (m) - 1] = '\0'; GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); ok = GNUNET_YES; GNUNET_CRYPTO_random_disable_entropy_gathering (); (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); cfg = GNUNET_CONFIGURATION_create (); if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) { GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (0); return -1; } notiCount = 0; fakenotiCount = 0; count = 0; GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, &fakenotiCount); GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, ¬iCount); GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, &fakenotiCount); /* ACTUAL TEST CODE */ old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "test", strlen ("test") + 1); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 2); newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); old = newVal; GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2); GNUNET_PSEUDONYM_add (cfg, &id2, meta); CHECK (notiCount == 3); newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_COMMENT, EXTRACTOR_METAFORMAT_UTF8, "text/plain", m, strlen (m) + 1)); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); GNUNET_PSEUDONYM_add (cfg, &id3, meta); GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL); CHECK (name3 != NULL); GNUNET_PSEUDONYM_get_info (cfg, &id2, NULL, NULL, &name2, NULL); CHECK (name2 != NULL); GNUNET_PSEUDONYM_get_info (cfg, &id1, NULL, NULL, &name1, NULL); CHECK (name1 != NULL); CHECK (0 == strcmp (name1, name2)); name1_unique = GNUNET_PSEUDONYM_name_uniquify (cfg, &id1, name1, NULL); name2_unique = GNUNET_PSEUDONYM_name_uniquify (cfg, &id2, name2, NULL); CHECK (0 != strcmp (name1_unique, name2_unique)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2)); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1)); CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_HashCode))); CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_HashCode))); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid); GNUNET_log_skip (1, GNUNET_NO); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0)); GNUNET_log_skip (0, GNUNET_YES); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_get_info (cfg, &fid, NULL, NULL, &noname, &noname_is_a_dup)); CHECK (noname != NULL); CHECK (noname_is_a_dup == GNUNET_YES); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0)); CHECK (5 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); CHECK (-5 == GNUNET_PSEUDONYM_rank (cfg, &id1, -10)); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); GNUNET_free (name1); GNUNET_free (name2); GNUNET_free (name1_unique); GNUNET_free (name2_unique); GNUNET_free (name3); GNUNET_free (noname); /* END OF TEST CODE */ FAILURE: GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); return (ok == GNUNET_YES) ? 0 : 1; }