2
0

cipher_test.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. #include <setjmp.h>
  10. #include <stdio.h>
  11. #include "zrtp.h"
  12. #include "cmockery/cmockery.h"
  13. zrtp_global_t *zrtp;
  14. void setup() {
  15. zrtp_status_t s;
  16. zrtp_config_t zrtp_config;
  17. zrtp_config_defaults(&zrtp_config);
  18. s = zrtp_init(&zrtp_config, &zrtp);
  19. assert_int_equal(s, zrtp_status_ok);
  20. }
  21. void teardown() {
  22. zrtp_down(zrtp);
  23. }
  24. static void aes128_ctr_test() {
  25. zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
  26. assert_non_null(cipher);
  27. cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR);
  28. }
  29. static void aes128_cfb_test() {
  30. zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
  31. assert_non_null(cipher);
  32. cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB);
  33. }
  34. static void aes256_ctr_test() {
  35. zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp);
  36. assert_non_null(cipher);
  37. cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR);
  38. }
  39. static void aes256_cfb_test() {
  40. zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp);
  41. assert_non_null(cipher);
  42. cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB);
  43. }
  44. int main(void) {
  45. const UnitTest tests[] = {
  46. unit_test_setup_teardown(aes128_ctr_test, setup, teardown),
  47. unit_test_setup_teardown(aes128_cfb_test, setup, teardown),
  48. unit_test_setup_teardown(aes256_ctr_test, setup, teardown),
  49. unit_test_setup_teardown(aes256_cfb_test, setup, teardown),
  50. };
  51. return run_tests(tests);
  52. }