unit-tests: Adapted to coverity fixes
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 18 Dec 2014 14:51:13 +0000 (15:51 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 23 Dec 2014 14:40:01 +0000 (15:40 +0100)
src/libstrongswan/plugins/bliss/tests/suites/test_bliss_bitpacker.c
src/libstrongswan/tests/suites/test_mgf1.c

index f040ba7..6a728e2 100644 (file)
 
 #include <bliss_bitpacker.h>
 
-static uint32_t bits[] = { 0, 1, 2, 3, 4, 7, 1, 14, 2, 29, 3, 28, 67};
+static uint32_t bits[] = { 0, 1, 2, 3, 4, 7, 1, 14, 2, 29, 3, 28, 67, 0x2fe3a9c1};
 
 static chunk_t packed_bits = chunk_from_chars(0x6e, 0x71, 0xe1, 0x74,
-                                                                                         0x37, 0x21, 0x80);
+                                                                                         0x37, 0x21, 0x97, 0xf1,
+                                                                                         0xd4, 0xe0, 0x80);
 
 START_TEST(test_bliss_sign_bitpacker_write)
 {
@@ -28,16 +29,16 @@ START_TEST(test_bliss_sign_bitpacker_write)
        bliss_bitpacker_t *packer;
        int i;
 
-       packer = bliss_bitpacker_create(49);
+       packer = bliss_bitpacker_create(81);
 
-       ck_assert(!packer->write_bits(packer, 0, 33));
-
-       for (i = 0; i < countof(bits); i++)
+       for (i = 0; i < 13; i++)
        {
                ck_assert(packer->write_bits(packer, bits[i], 1 + i/2));
        }
+       ck_assert(packer->write_bits(packer, bits[13], 32));
+
        buf = packer->extract_buf(packer);
-       ck_assert_int_eq(packer->get_bits(packer), 49);
+       ck_assert_int_eq(packer->get_bits(packer), 81);
        ck_assert_chunk_eq(buf, packed_bits);
 
        packer->destroy(packer);
@@ -55,12 +56,13 @@ START_TEST(test_bliss_sign_bitpacker_read)
 
        ck_assert(!packer->read_bits(packer, &value, 33));
 
-       for (i = 0; i < countof(bits); i++)
+       for (i = 0; i < 13; i++)
        {
                ck_assert(packer->read_bits(packer, &value, 1 + i/2));
                ck_assert_int_eq(value, bits[i]);
        }
-       ck_assert(!packer->read_bits(packer, &value, 32));
+       ck_assert(packer->read_bits(packer, &value, 32));
+       ck_assert_int_eq(value, bits[13]);
 
        packer->destroy(packer);
 }
@@ -72,6 +74,7 @@ START_TEST(test_bliss_sign_bitpacker_fail)
        uint32_t value;
 
        packer = bliss_bitpacker_create(32);
+       ck_assert( packer->write_bits(packer, 0xff, 0));
        ck_assert(!packer->write_bits(packer, 0, 33));
        ck_assert( packer->write_bits(packer, 0x7f2a3b01, 31));
        ck_assert(!packer->write_bits(packer, 3,  2));
index a60666f..0fb548a 100644 (file)
@@ -27,7 +27,7 @@ typedef struct {
        chunk_t seed;
        chunk_t hashed_seed;
        chunk_t mask;
-       uint32_t bits[20];
+       uint32_t bits[22];
 } mgf1_test_t;
 
 /**
@@ -71,7 +71,7 @@ mgf1_test_t mgf1_tests[] = {
                                                0x71, 0x66, 0x2F, 0x70, 0x35, 0xD8, 0x8A, 0x92,
                                                0x33, 0xF0, 0x16, 0xD4, 0x0E, 0x43, 0x8A, 0x14),
                { 0, 0, 0, 4, 1, 1, 46, 103, 38, 411, 848, 57, 3540, 4058, 12403,
-                 0x63, 0x2B, 0xC9, 0x17, 0x56 },
+                 0x63, 0x2B, 0xC9, 0x17, 0x56, 669409, 0xA407A43B },
        },
        {       HASH_SHA256, 32, 64, 32, 33, 40,
                chunk_from_chars(
@@ -121,7 +121,7 @@ mgf1_test_t mgf1_tests[] = {
                                                0x44, 0x4D, 0xCD, 0xB6, 0x54, 0x5F, 0x81, 0x95,
                                                0x59, 0xA1, 0xE5, 0x4E, 0xA5, 0x0A, 0x4A, 0x42),
                 { 0, 1, 3, 4, 4, 12, 32, 36, 253, 331, 2, 1640, 503, 6924, 580,
-                  0xCB, 0x35, 0x3C, 0xDC, 0xAD }
+                  0xCB, 0x35, 0x3C, 0xDC, 0xAD, 922950, 0x0DD1AA64 }
        }
 };
 
@@ -222,6 +222,18 @@ START_TEST(mgf1_test_bitspender)
                ck_assert(byte == mgf1_tests[_i].bits[j]);
        }
 
+       j = 20; /* 23 remaining bits */
+       ck_assert(bitspender->get_bits(bitspender, 23, &bits));
+       DBG1(DBG_LIB, "bits[%d] = %u, bits = %u", j,
+                                  mgf1_tests[_i].bits[j], bits);
+       ck_assert(bits == mgf1_tests[_i].bits[j]);
+
+       j = 21; /* 32 aligned bits */
+       ck_assert(bitspender->get_bits(bitspender, 32, &bits));
+       DBG1(DBG_LIB, "bits[%d] = 0x%08x, bits = 0x%08x", j,
+                                  mgf1_tests[_i].bits[j], bits);
+       ck_assert(bits == mgf1_tests[_i].bits[j]);
+
        bitspender->destroy(bitspender);
 }
 END_TEST