int main(int argc, char **argv) { test_encode(); test_decode(); test_encrypt(); test_decrypt(); return 0; }
int main(void) { static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80"; static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32"; static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32"; static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD"; uint8_t buf[RTP_MAX_PACKET_LENGTH]; struct SRTPContext srtp = { 0 }; int len; ff_srtp_set_crypto(&srtp, aes128_80_suite, aes128_80_key); len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf); test_encrypt(buf, len, aes128_80_suite, test_key); test_encrypt(buf, len, aes128_32_suite, test_key); test_encrypt(buf, len, aes128_80_32_suite, test_key); test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf); test_encrypt(buf, len, aes128_80_suite, test_key); test_encrypt(buf, len, aes128_32_suite, test_key); test_encrypt(buf, len, aes128_80_32_suite, test_key); ff_srtp_free(&srtp); memset(&srtp, 0, sizeof(srtp)); // Clear the context ff_srtp_set_crypto(&srtp, aes128_32_suite, aes128_32_key); test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf); test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf); ff_srtp_free(&srtp); memset(&srtp, 0, sizeof(srtp)); // Clear the context ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key); test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf); test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf); ff_srtp_free(&srtp); return 0; }
int main(void) { int tag_size; int i; uword data_buf[64]; uword nonce_buf[4]; uword test_key[4] = { MAKE_U8(0x00010203), MAKE_U8(0x04050607), MAKE_U8(0x08090A0B), MAKE_U8(0x0C0D0E0F) }; // Only the first 7 bytes are actually used, rest just RFU ///@todo may need to make NONCE 8 bytes for C2000 uword test_nonce[4] = { MAKE_U8(0x00010203), MAKE_U8(0x04050607), MAKE_U8(0x08090A0B), MAKE_U8(0x0C0D0E0F) }; // Test payload: set to a prime-number of bytes to show non-aligned // cipher feature of EAX uword test_data[11] = { MAKE_U8(0x00010203), MAKE_U8(0x04050607), MAKE_U8(0x08090A0B), MAKE_U8(0x0C0D0E0F), MAKE_U8(0x10111213), MAKE_U8(0x14151617), MAKE_U8(0x18191A1B), MAKE_U8(0x1C1D1E1F), MAKE_U8(0x20212223), MAKE_U8(0x24252627), MAKE_U8(0x28292A00) }; // Expected output of test encryption ///@todo get this output uword test_check[12] = { MAKE_U8(0xF2D7F3DE), MAKE_U8(0xF361855F), MAKE_U8(0xCB5E7EF4), MAKE_U8(0x9651446E), MAKE_U8(0x249C81A7), MAKE_U8(0x6334F74D), MAKE_U8(0xC4D6AA31), MAKE_U8(0xB377657B), MAKE_U8(0x02B4F449), MAKE_U8(0xF175F21A), MAKE_U8(0x546450DC), MAKE_U8(0x38B8B2C7) }; // Clear buffers memset(data_buf, 0, sizeof(data_buf)); memset(nonce_buf, 0, sizeof(nonce_buf)); // Copy test_data to data_buf memcpy(data_buf, test_data, sizeof(test_data)); // Run first encryption { eax_ctx context; int retval; retval = eax_init_and_key((cuword*)test_key, &context); if (retval != 0) { printf("eax_init_and_key() failed, unknown error\n\n"); } else { for (i=0; i<44; i++) { printf("ks[%02d] = %08X\n", i, context.aes[0].ks[i]); } printf("aes.inf.l = %u\n", context.aes[0].inf.l); retval = eax_encrypt_message((cuword*)test_nonce, (uword*)data_buf, sizeof(test_data), &context); if (retval != 0) { printf("eax_encrypt_message() failed, unknown error\n\n"); } } tag_size = 4; } //tag_size = test_encrypt(test_nonce, data_buf, sizeof(test_data), test_key); if (tag_size < 0) { printf("test_encrypt() failed, unknown error\n\n"); } // Print the input, for cross-checking, and then the output printf("Plain-text Input\n"); print_hex(test_data, sizeof(test_data)); printf("\nOutput Data from EAX:\n"); print_hex(data_buf, sizeof(test_data) + tag_size); putchar('\n'); // Check against test { int j; int len_words = (sizeof(test_data) + tag_size) / 4; for (i=0, j=0; i<len_words; i++) { int k; k = (data_buf[i] != test_check[i]); j += k; if (j == 1) { printf("Errors: "); } if (k) { printf("%d, ", i); } } if (j != 0) { printf("\nOutput should be:\n"); print_hex(test_check, sizeof(test_check)); } else { printf("Check done: no errors!\n"); } putchar('\n'); } // Decrypt tag_size = test_decrypt(test_nonce, data_buf, sizeof(test_data), test_key); if (tag_size != 4) { printf("test_decrypt() failed, unknown error\n\n"); } printf("Decrypted Output\n"); print_hex(data_buf, sizeof(test_data)); putchar('\n'); return 0; }
int main (int argc, char **argv) { #ifdef ENABLE_CRYPTO const char *datadir = "data/pgp"; GMimeStream *istream, *ostream; GMimeFilterOpenPGP *filter; GMimeCryptoContext *ctx; const char *what; char *gpg, *key; struct stat st; int i; g_mime_init (); testsuite_init (argc, argv); if (!(gpg = g_find_program_in_path ("gpg2"))) if (!(gpg = g_find_program_in_path ("gpg"))) return EXIT_FAILURE; if (testsuite_setup_gpghome (gpg) != 0) return EXIT_FAILURE; g_free (gpg); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { datadir = argv[i]; break; } } if (i < argc && (stat (datadir, &st) == -1 || !S_ISDIR (st.st_mode))) return 0; testsuite_start ("GnuPG crypto context"); ctx = g_mime_gpg_context_new (); g_mime_crypto_context_set_request_password (ctx, request_passwd); testsuite_check ("GMimeGpgContext::import"); try { key = g_build_filename (datadir, "gmime.gpg.pub", NULL); import_key (ctx, key); g_free (key); key = g_build_filename (datadir, "gmime.gpg.sec", NULL); import_key (ctx, key); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("GMimeGpgContext::import failed: %s", ex->message); return EXIT_FAILURE; } finally; key = g_build_filename (datadir, "gmime.gpg.pub", NULL); testsuite_check ("GMimeGpgContext::export"); try { test_export (ctx, key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("GMimeGpgContext::export failed: %s", ex->message); } finally; g_free (key); istream = g_mime_stream_mem_new (); ostream = g_mime_stream_mem_new (); g_mime_stream_write_string (istream, "this is some cleartext\r\n"); g_mime_stream_reset (istream); what = "GMimeGpgContext::sign"; testsuite_check ("%s", what); try { test_sign (ctx, FALSE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::verify"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_verify (ctx, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (ostream); g_mime_stream_reset (istream); ostream = g_mime_stream_mem_new (); what = "GMimeGpgContext::sign (detached)"; testsuite_check ("%s", what); try { test_sign (ctx, TRUE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::verify (detached)"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_verify_detached (ctx, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (ostream); g_mime_stream_reset (istream); ostream = g_mime_stream_mem_new (); what = "GMimeGpgContext::encrypt"; testsuite_check ("%s", what); try { test_encrypt (ctx, FALSE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::decrypt"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_decrypt (ctx, FALSE, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (ostream); g_mime_stream_reset (istream); ostream = g_mime_stream_mem_new (); what = "GMimeGpgContext::encrypt+sign"; testsuite_check ("%s", what); try { test_encrypt (ctx, TRUE, istream, ostream); testsuite_check_passed (); what = "GMimeGpgContext::decrypt+verify"; testsuite_check ("%s", what); g_mime_stream_reset (istream); g_mime_stream_reset (ostream); test_decrypt (ctx, TRUE, istream, ostream); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (istream); g_object_unref (ostream); g_object_unref (ctx); filter = (GMimeFilterOpenPGP *) g_mime_filter_openpgp_new (); what = "GMimeFilterOpenPGP::public key block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "gmime.gpg.pub", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_PUBLIC_KEY, 0, 1720); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_mime_filter_reset ((GMimeFilter *) filter); what = "GMimeFilterOpenPGP::private key block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "gmime.gpg.sec", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_PRIVATE_KEY, 0, 1928); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_mime_filter_reset ((GMimeFilter *) filter); what = "GMimeFilterOpenPGP::signed message block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "signed-message.txt", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_SIGNED, 162, 440); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_mime_filter_reset ((GMimeFilter *) filter); what = "GMimeFilterOpenPGP::encrypted message block"; testsuite_check ("%s", what); try { key = g_build_filename (datadir, "encrypted-message.txt", NULL); test_openpgp_filter (filter, key, GMIME_OPENPGP_DATA_ENCRYPTED, 165, 1084); g_free (key); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("%s failed: %s", what, ex->message); } finally; g_object_unref (filter); testsuite_end (); g_mime_shutdown (); if (testsuite_destroy_gpghome () != 0) return EXIT_FAILURE; return testsuite_exit (); #else fprintf (stderr, "PGP support not enabled in this build.\n"); return EXIT_SUCCESS; #endif }