unit-tests: Completed BLISS tests

This commit is contained in:
Andreas Steffen
2015-02-25 21:45:34 +01:00
parent bfb708ea23
commit a7f0ab786d
6 changed files with 668 additions and 16 deletions
@@ -5,7 +5,10 @@ check_PROGRAMS = $(TESTS)
bliss_tests_SOURCES = \
suites/test_bliss_fft.c \
suites/test_bliss_bitpacker.c \
suites/test_bliss_huffman.c \
suites/test_bliss_keys.c \
suites/test_bliss_sampler.c \
suites/test_bliss_signature.c \
suites/test_bliss_sign.c \
bliss_tests.h bliss_tests.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Andreas Steffen
* Copyright (C) 2014-2015 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -15,6 +15,9 @@
TEST_SUITE(bliss_fft_suite_create)
TEST_SUITE(bliss_bitpacker_suite_create)
TEST_SUITE(bliss_huffman_suite_create)
TEST_SUITE(bliss_keys_suite_create)
TEST_SUITE(bliss_sampler_suite_create)
TEST_SUITE(bliss_signature_suite_create)
TEST_SUITE(bliss_sign_suite_create)
@@ -0,0 +1,122 @@
/*
* Copyright (C) 2015 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "test_suite.h"
#include <bliss_huffman_coder.h>
static chunk_t data = chunk_from_chars(0x5f, 0x71, 0x9e, 0x4c);
START_TEST(test_bliss_huffman_encode)
{
bliss_bitpacker_t *packer;
bliss_huffman_code_t *code;
bliss_huffman_coder_t *coder;
chunk_t encoding;
packer = bliss_bitpacker_create(32);
ck_assert(packer);
code = bliss_huffman_code_get_by_id(BLISS_B_I);
ck_assert(code);
coder = bliss_huffman_coder_create(code, packer);
ck_assert(coder);
ck_assert( coder->encode(coder, 0, 0)); /* 0 */
ck_assert( coder->encode(coder, 1, 0)); /* 10 */
ck_assert( coder->encode(coder, 2, 0)); /* 111 */
ck_assert( coder->encode(coder, 0, 1)); /* 1101 */
ck_assert( coder->encode(coder, 0, -1)); /* 11000 */
ck_assert( coder->encode(coder, 1, 1)); /* 110011 */
ck_assert( coder->encode(coder, 1, -1)); /* 1100100 */
ck_assert(!coder->encode(coder, 3, 0)); /* 11001010 */
ck_assert(!coder->encode(coder, 8, 0)); /* - */
encoding = packer->extract_buf(packer);
ck_assert(chunk_equals(encoding, data));
chunk_free(&encoding);
coder->destroy(coder);
packer->destroy(packer);
}
END_TEST
START_TEST(test_bliss_huffman_decode)
{
bliss_bitpacker_t *packer;
bliss_huffman_code_t *code;
bliss_huffman_coder_t *coder;
int32_t z1;
int16_t z2;
packer = bliss_bitpacker_create_from_data(data);
ck_assert(packer);
code = bliss_huffman_code_get_by_id(BLISS_II);
ck_assert(!code);
code = bliss_huffman_code_get_by_id(BLISS_B_II);
ck_assert(!code);
code = bliss_huffman_code_get_by_id(BLISS_B_I);
ck_assert(code);
coder = bliss_huffman_coder_create(code, packer);
ck_assert(coder);
ck_assert(coder->decode(coder, &z1, &z2)); /* 0 */
ck_assert(z1 == 0 && z2 == 0);
ck_assert(coder->decode(coder, &z1, &z2)); /* 10 */
ck_assert(z1 == 1 && z2 == 0);
ck_assert(coder->decode(coder, &z1, &z2)); /* 111 */
ck_assert(z1 == 2 && z2 == 0);
ck_assert(coder->decode(coder, &z1, &z2)); /* 1101 */
ck_assert(z1 == 0 && z2 == 1);
ck_assert(coder->decode(coder, &z1, &z2)); /* 11000 */
ck_assert(z1 == 0 && z2 == -1);
ck_assert(coder->decode(coder, &z1, &z2)); /* 110011 */
ck_assert(z1 == 1 && z2 == 1);
ck_assert(coder->decode(coder, &z1, &z2)); /* 1100100 */
ck_assert(z1 == 1 && z2 == -1);
ck_assert(!coder->decode(coder, &z1, &z2)); /* 11001010 */
coder->destroy(coder);
packer->destroy(packer);
}
END_TEST
Suite *bliss_huffman_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("bliss_huffman");
tc = tcase_create("huffman_encode");
tcase_add_test(tc, test_bliss_huffman_encode);
suite_add_tcase(s, tc);
tc = tcase_create("huffman_decode");
tcase_add_test(tc, test_bliss_huffman_decode);
suite_add_tcase(s, tc);
return s;
}
@@ -0,0 +1,249 @@
/*
* Copyright (C) 2015 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "test_suite.h"
#include <bliss_private_key.h>
#include <bliss_public_key.h>
static chunk_t privkey_chunk[] = {
{NULL, 0},
chunk_from_chars(0x30, 0x00),
chunk_from_chars(0x30, 0x01),
chunk_from_chars(0x30, 0x03, 0x06, 0x01, 0x01),
chunk_from_chars(0x30, 0x0d, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
0xa0, 0x2a, 0x05, 0x02, 0x06),
chunk_from_chars(0x30, 0x0f, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82,
0xa0, 0x2a, 0x05, 0x02, 0x05, 0x03, 0x00),
chunk_from_chars(0x30, 0x82, 0x04, 0x9a, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04,
0x01, 0x82, 0xa0, 0x2a, 0x05, 0x02, 0x05, 0x03, 0x82, 0x03,
0x81, 0x00, 0x81, 0xe5, 0xd2, 0x71, 0xeb, 0x98, 0xe5, 0x24,
0x34, 0xe4, 0x8a, 0x27, 0x23, 0x7d, 0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00, 0x07, 0xc0, 0x51, 0x34, 0x01, 0x30, 0x0c, 0x00, 0x00,
0x04, 0xc0, 0x3d, 0x40, 0x03, 0x07, 0x40, 0xd3, 0x50, 0x0c,
0x04, 0x03, 0x00, 0x11, 0x41, 0x30, 0x00, 0xc1, 0xc0, 0xc3,
0x03, 0x5f, 0x04, 0x30, 0x01, 0x40, 0x40, 0x00, 0x40, 0x40,
0x10, 0x40, 0x05, 0x05, 0x00, 0x53, 0x00, 0x04, 0x50, 0x00,
/* 1000 */ 0x00, 0x00, 0x0c, 0x00, 0x51, 0x00, 0x00, 0x00, 0x04, 0xc7,
0x01, 0x50, 0xc0, 0x11, 0x00, 0x04, 0x03, 0xc0, 0x04, 0x00,
0x70, 0x4c, 0x31, 0x03, 0xc0, 0x40, 0xc4, 0x40, 0x40, 0xc0,
0x0c, 0x0c, 0xf1, 0x40, 0xc1, 0x31, 0x70, 0x17, 0xc0, 0x30,
0xc1, 0x04, 0x0c, 0x04, 0x00, 0xc4, 0x01, 0x00, 0x34, 0x00,
0x03, 0x81, 0x81, 0x00, 0xcc, 0x00, 0x50, 0x30, 0xc4, 0x13,
0x0f, 0xf0, 0x43, 0x01, 0x33, 0x40, 0x30, 0x01, 0x40, 0x10,
0x57, 0x04, 0x03, 0x04, 0x10, 0x00, 0xf0, 0x03, 0x04, 0x01,
0x00, 0x10, 0x34, 0x03, 0xf0, 0x1c, 0x01, 0x40, 0x30, 0xf4,
0x00, 0x40, 0x34, 0xc3, 0x00, 0x00, 0x01, 0x00, 0x01, 0x10,
/* 1100 */ 0x3f, 0x03, 0x40, 0x00, 0x10, 0x10, 0x00, 0x40, 0x03, 0x00,
0x03, 0x04, 0x40, 0x03, 0x00, 0x13, 0x03, 0x00, 0xc0, 0x01,
0x34, 0x01, 0x00, 0x00, 0x10, 0xf4, 0x00, 0xf0, 0x30, 0x00,
0x00, 0xc3, 0x1c, 0x41, 0x00, 0x40, 0x30, 0x04, 0x10, 0xc4,
0x11, 0x03, 0x00, 0x10, 0x04, 0x4f, 0x17, 0xc0, 0x00, 0x30,
0xcd, 0x3c, 0x40, 0xc4, 0x00, 0xf0, 0x00, 0x00, 0x04, 0x30,
0x0f, 0x31, 0x34, 0xf0, 0x00, 0x07, 0x0c, 0x34, 0x00, 0x50,
0x05, 0x03, 0x10, 0x70, 0x00, 0x33, 0x0c, 0x00, 0xc4, 0x54,
0x07, 0x00)
};
START_TEST(test_bliss_keys_priv)
{
private_key_t *privkey;
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_BLOB, privkey_chunk[_i], BUILD_END);
if (_i == countof(privkey_chunk) - 1)
{
ck_assert(privkey);
privkey->destroy(privkey);
}
else
{
ck_assert(!privkey);
}
}
END_TEST
typedef struct privkey_mod_t privkey_mod_t;
struct privkey_mod_t {
int offset;
char byte;
};
static privkey_mod_t privkey_mod[] = {
{ 20, 0x80 },
{ 22, 0xc1 },
{ 920, 0x80 },
{ 922, 0x85 },
{ 1052, 0x80 },
{ 1054, 0x8c }
};
START_TEST(test_bliss_keys_priv_mod)
{
private_key_t *privkey;
chunk_t data;
data = chunk_clone(privkey_chunk[countof(privkey_chunk) - 1]);
data.ptr[privkey_mod[_i].offset] = privkey_mod[_i].byte;
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_BLOB, data, BUILD_END);
ck_assert(!privkey);
chunk_free(&data);
}
END_TEST
static chunk_t pubkey_chunk[] = {
{NULL, 0},
chunk_from_chars(0x30, 0x00),
chunk_from_chars(0x30, 0x01),
chunk_from_chars(0x30, 0x02, 0x30, 0x00),
chunk_from_chars(0x30, 0x05, 0x30, 0x03, 0x06, 0x01, 0x01),
chunk_from_chars(0x30, 0x11, 0x30, 0x0F, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04,
0x01, 0x82, 0xa0, 0x2a, 0x05, 0x01, 0x01, 0x04, 0x00),
chunk_from_chars(0x30, 0x12, 0x30, 0x10, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04,
0x01, 0x82, 0xa0, 0x2a, 0x05, 0x01, 0x01, 0x06, 0x01, 0x01),
chunk_from_chars(0x30, 0x1c, 0x30, 0x1a, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04,
0x01, 0x82, 0xa0, 0x2a, 0x05, 0x01, 0x01, 0x06, 0x0b, 0x2b,
0x06, 0x01, 0x04, 0x01, 0x82, 0xa0, 0x2a, 0x05, 0x02, 0x06),
chunk_from_chars(0x30, 0x1e, 0x30, 0x1a, 0x06, 0x0b, 0x2b, 0x06, 0x01, 0x04,
0x01, 0x82, 0xa0, 0x2a, 0x05, 0x01, 0x01, 0x06, 0x0b, 0x2b,
0x06, 0x01, 0x04, 0x01, 0x82, 0xa0, 0x2a, 0x05, 0x02, 0x05,
0x03, 0x00)
};
START_TEST(test_bliss_keys_pub)
{
public_key_t *pubkey;
pubkey = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
BUILD_BLOB, pubkey_chunk[_i], BUILD_END);
ck_assert(!pubkey);
}
END_TEST
Suite *bliss_keys_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("bliss_keys");
tc = tcase_create("keys_priv");
tcase_add_loop_test(tc, test_bliss_keys_priv, 0, countof(privkey_chunk));
suite_add_tcase(s, tc);
tc = tcase_create("keys_priv_mod");
tcase_add_loop_test(tc, test_bliss_keys_priv_mod, 0, countof(privkey_mod));
suite_add_tcase(s, tc);
tc = tcase_create("keys_pub");
tcase_add_loop_test(tc, test_bliss_keys_pub, 0, countof(pubkey_chunk));
suite_add_tcase(s, tc);
return s;
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Andreas Steffen
* Copyright (C) 2014-2015 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -19,30 +19,160 @@
#include <bliss_public_key.h>
static u_int key_type[] = { 1, 3, 4 };
static u_int key_strength[] = { 128, 160, 192 };
START_TEST(test_bliss_sign_all)
{
private_key_t *privkey, *privkey1;
public_key_t *pubkey, *pubkey1;
chunk_t msg, signature, privkey_blob, pubkey_blob, pubkey_fp, privkey_fp;
int k;
for (k = 0; k < 4; k++)
{
int verify_count = 1000;
/* enforce BLISS-B key for k = 2, 3 */
lib->settings->set_bool(lib->settings,
"%s.plugins.bliss.use_bliss_b", k >= 2, lib->ns);
msg = chunk_from_str("Hello Dolly!");
/* generate private key */
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_KEY_SIZE, key_type[_i], BUILD_END);
ck_assert(privkey);
/* generate ASN.1 DER and PEM encoding of private key */
ck_assert(privkey->get_encoding(privkey, (k % 2) ?
PRIVKEY_ASN1_DER : PRIVKEY_PEM, &privkey_blob));
/* extract public key from private key */
pubkey = privkey->get_public_key(privkey);
ck_assert(pubkey);
/* generate ASN.1 DER and PEM encodings of public key */
ck_assert(pubkey->get_encoding(pubkey, (k % 2) ?
PUBKEY_SPKI_ASN1_DER : PUBKEY_PEM, &pubkey_blob));
/* compare fingerprints of public and private key */
ck_assert(pubkey->get_fingerprint(pubkey, (k % 2) ?
KEYID_PUBKEY_INFO_SHA1 : KEYID_PUBKEY_SHA1, &pubkey_fp));
ck_assert(privkey->get_fingerprint(privkey, (k % 2) ?
KEYID_PUBKEY_INFO_SHA1 : KEYID_PUBKEY_SHA1, &privkey_fp));
ck_assert(chunk_equals(pubkey_fp, privkey_fp));
/* retrieve fingerprints of public and private key from cache */
ck_assert(pubkey->get_fingerprint(pubkey, (k % 2) ?
KEYID_PUBKEY_INFO_SHA1 : KEYID_PUBKEY_SHA1, &pubkey_fp));
ck_assert(privkey->get_fingerprint(privkey, (k % 2) ?
KEYID_PUBKEY_INFO_SHA1 : KEYID_PUBKEY_SHA1, &privkey_fp));
/* get a reference of the private key and destroy both instances */
privkey1 = privkey->get_ref(privkey);
ck_assert(privkey1);
ck_assert(privkey1 == privkey);
privkey->destroy(privkey);
privkey1->destroy(privkey1);
/* get a reference of the public key and destroy both instances */
pubkey1 = pubkey->get_ref(pubkey);
ck_assert(pubkey1);
ck_assert(pubkey1 == pubkey);
pubkey->destroy(pubkey);
pubkey1->destroy(pubkey1);
/* enforce BLISS-B key for k = 1, 3 */
lib->settings->set_bool(lib->settings,
"%s.plugins.bliss.use_bliss_b", k % 2, lib->ns);
/* load private key from ASN.1 blob */
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_BLOB, privkey_blob, BUILD_END);
ck_assert(privkey);
ck_assert(privkey->get_type(privkey) == KEY_BLISS);
ck_assert(privkey->get_keysize(privkey) == key_strength[_i]);
chunk_free(&privkey_blob);
/* load public key from ASN.1 blob */
pubkey = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
BUILD_BLOB, pubkey_blob, BUILD_END);
ck_assert(pubkey);
ck_assert(pubkey->get_type(pubkey) == KEY_BLISS);
ck_assert(pubkey->get_keysize(pubkey) == key_strength[_i]);
chunk_free(&pubkey_blob);
/* generate and verify 1000 BLISS signatures */
while (verify_count--)
{
ck_assert(privkey->sign(privkey, SIGN_BLISS_WITH_SHA512, msg,
&signature));
ck_assert(pubkey->verify(pubkey, SIGN_BLISS_WITH_SHA512, msg,
signature));
free(signature.ptr);
}
privkey->destroy(privkey);
pubkey->destroy(pubkey);
}
}
END_TEST
START_TEST(test_bliss_sign_fail)
{
private_key_t *privkey;
public_key_t *pubkey;
chunk_t msg, signature;
int verify_count = 1000;
msg = chunk_from_str("Hello Dolly!");
chunk_t msg, signature, encoding, fp;
/* generate non-supported BLISS-II private key */
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_KEY_SIZE, key_type[_i], BUILD_END);
BUILD_KEY_SIZE, BLISS_II, BUILD_END);
ck_assert(!privkey);
/* generate non-supported BLISS-B-II private key */
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_KEY_SIZE, BLISS_B_II, BUILD_END);
ck_assert(!privkey);
/* generate supported BLISS-B-I private key */
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_BLISS,
BUILD_KEY_SIZE, BLISS_B_I, BUILD_END);
ck_assert(privkey);
/* wrong private key encoding format */
ck_assert(!privkey->get_encoding(privkey, PUBKEY_PEM, &encoding));
/* wrong fingerprint encoding format */
ck_assert(!privkey->get_fingerprint(privkey, KEYID_PGPV4, &fp));
/* extract public key */
pubkey = privkey->get_public_key(privkey);
ck_assert(pubkey);
while (verify_count--)
{
ck_assert(privkey->sign(privkey, SIGN_BLISS_WITH_SHA512, msg,
&signature));
ck_assert(pubkey->verify(pubkey, SIGN_BLISS_WITH_SHA512, msg,
signature));
free(signature.ptr);
}
/* wrong private key encoding format */
ck_assert(!pubkey->get_encoding(pubkey, PRIVKEY_PEM, &encoding));
/* wrong fingerprint encoding format */
ck_assert(!pubkey->get_fingerprint(pubkey, KEYID_PGPV4, &fp));
/* encryption / decryption operation is not defined for BLISS */
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, chunk_empty, NULL));
ck_assert(!privkey->decrypt(privkey, ENCRYPT_UNKNOWN, chunk_empty, NULL));
/* sign with invalid signature scheme */
ck_assert(!privkey->sign(privkey, SIGN_UNKNOWN, msg, &signature));
/* generate valid signature */
msg = chunk_from_str("Hello Dolly!");
ck_assert(privkey->sign(privkey, SIGN_BLISS_WITH_SHA512, msg, &signature));
/* verify with invalid signature scheme */
ck_assert(!pubkey->verify(pubkey, SIGN_UNKNOWN, msg, signature));
/* corrupt signature */
signature.ptr[signature.len - 1] ^= 0x80;
ck_assert(!pubkey->verify(pubkey, SIGN_BLISS_WITH_SHA512, msg, signature));
free(signature.ptr);
privkey->destroy(privkey);
pubkey->destroy(pubkey);
}
@@ -55,10 +185,14 @@ Suite *bliss_sign_suite_create()
s = suite_create("bliss_sign");
tc = tcase_create("all");
tc = tcase_create("sign_all");
test_case_set_timeout(tc, 30);
tcase_add_loop_test(tc, test_bliss_sign_all, 0, countof(key_type));
suite_add_tcase(s, tc);
tc = tcase_create("sign_fail");
tcase_add_test(tc, test_bliss_sign_fail);
suite_add_tcase(s, tc);
return s;
}
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2015 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "test_suite.h"
#include <bliss_signature.h>
static chunk_t data = chunk_from_chars(
0xC1, 0xA1, 0x96, 0x98, 0x4F, 0x60, 0xF5, 0xCA, 0x89, 0x9E,
0x78, 0xAF, 0x64, 0xDD, 0x01, 0x76, 0x04, 0x29, 0x11, 0xD0,
0x21, 0x9E, 0xE4, 0x2D, 0xC5, 0x82, 0x69, 0x19, 0x82, 0x75,
0x30, 0xAC, 0xB0, 0x64, 0xCB, 0x65, 0x19, 0x22, 0x4A, 0x03,
0x03, 0x61, 0x4A, 0x37, 0x8E, 0xA3, 0xB6, 0xB3, 0x58, 0x44,
0xFD, 0x68, 0x38, 0xF1, 0x4B, 0xCF, 0xE8, 0xA2, 0x05, 0x39,
0x87, 0xE0, 0x5E, 0x7C, 0x45, 0x33, 0x4A, 0xEB, 0x2E, 0xCF,
0x98, 0x01, 0x3D, 0x28, 0x60, 0xCE, 0x90, 0x45, 0xF0, 0x8E,
0x36, 0x25, 0x50, 0x8B, 0xA2, 0xC0, 0x6E, 0xDF, 0xC2, 0xA1,
0x35, 0xC1, 0x16, 0x14, 0xE8, 0x6A, 0xE3, 0x9C, 0x0B, 0x32,
0x53, 0x55, 0x60, 0x52, 0x43, 0x93, 0xBB, 0x9F, 0x1D, 0x17,
0xDC, 0x6E, 0x26, 0x99, 0x60,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, 0x56, 0x07,
0x36, 0x11, 0xFB, 0x6D, 0x8E, 0xF0, 0x62, 0x5A, 0x3C, 0x8B,
0x23, 0xF1, 0x46, 0xE2, 0x76, 0x2A, 0x6F, 0xBB, 0x09, 0x24,
0x18, 0x64, 0xE6, 0x5C, 0xD0, 0x85, 0x69, 0xF0, 0x4F, 0x66,
0x97, 0x40, 0x01, 0x27, 0xD1, 0x41, 0xCC, 0xEB, 0x4D, 0xB7,
0x04, 0xC4, 0x91, 0xE0, 0x95, 0x8A, 0x43, 0x26, 0x2D, 0x1F,
0x88, 0xA0, 0xD8
);
START_TEST(test_bliss_signature_fail)
{
bliss_param_set_t set2 = { .id = BLISS_B_II };
bliss_param_set_t *set;
bliss_signature_t *signature;
chunk_t encoding;
int k;
signature = bliss_signature_create(&set2);
ck_assert(signature);
encoding = signature->get_encoding(signature);
ck_assert(encoding.len == 0);
signature->destroy(signature);
signature = bliss_signature_create_from_data(&set2, data);
ck_assert(!signature);
set = bliss_param_set_get_by_id(BLISS_B_I);
ck_assert(set);
for (k = 0; k < data.len - 2; k++)
{
chunk_t fragment = { data.ptr, k };
signature = bliss_signature_create_from_data(set, fragment);
ck_assert(!signature);
}
signature = bliss_signature_create_from_data(set, data);
ck_assert(signature);
signature->destroy(signature);
}
END_TEST
Suite *bliss_signature_suite_create()
{
Suite *s;
TCase *tc;
s = suite_create("bliss_signature");
tc = tcase_create("signature_fail");
tcase_add_test(tc, test_bliss_signature_fail);
suite_add_tcase(s, tc);
return s;
}