hash_test.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 sha1_hash_test() {
  25. zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
  26. assert_non_null(hash);
  27. hash->hash_self_test(hash);
  28. }
  29. static void sha1_hmac_test() {
  30. zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
  31. assert_non_null(hash);
  32. hash->hmac_self_test(hash);
  33. }
  34. static void sha256_hash_test() {
  35. zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
  36. assert_non_null(hash);
  37. hash->hash_self_test(hash);
  38. }
  39. static void sha256_hmac_test() {
  40. zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
  41. assert_non_null(hash);
  42. hash->hmac_self_test(hash);
  43. }
  44. static void sha384_hash_test() {
  45. zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
  46. assert_non_null(hash);
  47. hash->hash_self_test(hash);
  48. }
  49. static void sha384_hmac_test() {
  50. zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
  51. assert_non_null(hash);
  52. hash->hmac_self_test(hash);
  53. }
  54. int main(void) {
  55. const UnitTest tests[] = {
  56. unit_test_setup_teardown(sha1_hash_test, setup, teardown),
  57. unit_test_setup_teardown(sha1_hmac_test, setup, teardown),
  58. unit_test_setup_teardown(sha256_hash_test, setup, teardown),
  59. unit_test_setup_teardown(sha256_hmac_test, setup, teardown),
  60. unit_test_setup_teardown(sha384_hash_test, setup, teardown),
  61. unit_test_setup_teardown(sha384_hmac_test, setup, teardown),
  62. };
  63. return run_tests(tests);
  64. }