]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/ssl_init.c
Fix ntp multiple vulnerabilities.
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / ssl_init.c
1 #include "config.h"
2
3 #include "ntp.h"
4
5 #ifdef OPENSSL
6 # include "openssl/err.h"
7 # include "openssl/rand.h"
8 # include "openssl/evp.h"
9 #endif
10
11 #include "unity.h"
12
13
14 static const size_t TEST_MD5_DIGEST_LENGTH = 16;
15 static const size_t TEST_SHA1_DIGEST_LENGTH = 20;
16
17 void test_MD5KeyTypeWithoutDigestLength(void);
18 void test_MD5KeyTypeWithDigestLength(void);
19 void test_SHA1KeyTypeWithDigestLength(void);
20 void test_MD5KeyName(void);
21 void test_SHA1KeyName(void);
22
23
24 // keytype_from_text()
25 void
26 test_MD5KeyTypeWithoutDigestLength(void) {
27         TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", NULL));
28 }
29
30 void
31 test_MD5KeyTypeWithDigestLength(void) {
32         size_t digestLength;
33         size_t expected = TEST_MD5_DIGEST_LENGTH;
34
35         TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", &digestLength));
36         TEST_ASSERT_EQUAL(expected, digestLength);
37 }
38
39
40 void
41 test_SHA1KeyTypeWithDigestLength(void) {
42 #ifdef OPENSSL
43         size_t digestLength;
44         size_t expected = TEST_SHA1_DIGEST_LENGTH;
45
46         TEST_ASSERT_EQUAL(NID_sha1, keytype_from_text("SHA1", &digestLength));
47         TEST_ASSERT_EQUAL(expected, digestLength);
48         /* OPENSSL */
49 #else 
50         TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
51 #endif
52 }
53
54
55 // keytype_name()
56 void
57 test_MD5KeyName(void) {
58         TEST_ASSERT_EQUAL_STRING("MD5", keytype_name(KEY_TYPE_MD5));
59 }
60
61
62 void
63 test_SHA1KeyName(void) {
64 #ifdef OPENSSL
65         TEST_ASSERT_EQUAL_STRING("SHA1", keytype_name(NID_sha1));
66 #else
67         TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined");
68 #endif  /* OPENSSL */
69 }