Commit 54f89da4 authored by johan's avatar johan Committed by Ghislain MARY

Fix compilation warnings on windows

Export BctbxException class on Windows.

Fix build of tester on Windows.
parent fe6209a7
......@@ -772,7 +772,7 @@ BCTBX_PUBLIC void bctbx_DestroyEDDSAContext(bctbx_EDDSAContext_t *context);
* @param[in/out] signatureLength The size of the signature buffer as input, the size of the actual signature as output
*
*/
BCTBX_PUBLIC void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *AssociatedData, const size_t associatedDataLength, uint8_t *signature, size_t *signatureLength);
BCTBX_PUBLIC void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *AssociatedData, const uint8_t associatedDataLength, uint8_t *signature, size_t *signatureLength);
/**
*
......@@ -808,7 +808,7 @@ BCTBX_PUBLIC void bctbx_EDDSA_setSecretKey(bctbx_EDDSAContext_t *context, const
*
* @return BCTBX_VERIFY_SUCCESS or BCTBX_VERIFY_FAILED
*/
BCTBX_PUBLIC int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, const uint8_t *signature, size_t signatureLength);
BCTBX_PUBLIC int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, const uint8_t *signature, size_t signatureLength);
/**
......
......@@ -22,6 +22,13 @@
#include <exception>
#include <sstream>
#include "bctoolbox/port.h"
#ifdef _WIN32
#pragma warning (push)
#pragma warning (disable : 4275 4251)
#endif
/**
* @brief General pupose exception saving backtrace.
*
......@@ -34,7 +41,7 @@
*
*
*/
class BctbxException : public std::exception {
class BCTBX_PUBLIC BctbxException : public std::exception {
public:
BctbxException(const std::string &message = "");
BctbxException(const BctbxException &other);
......@@ -64,8 +71,13 @@ private:
std::ostringstream mOs;
mutable std::string mMessage;
};
std::ostream &operator<<(std::ostream &__os, const BctbxException &e);
BCTBX_PUBLIC std::ostream &operator<<(std::ostream &__os, const BctbxException &e);
#define BCTBX_EXCEPTION BctbxException() << " " << __FILE__ << ":" << __LINE__ << " "
#ifdef _WIN32
#pragma warning (pop)
#endif
#endif /* exception_h */
......@@ -343,7 +343,7 @@ void bctbx_DestroyEDDSAContext(bctbx_EDDSAContext_t *context) {
* @param[in/out] signatureLength The size of the signature buffer as input, the size of the actual signature as output
*
*/
void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, uint8_t *signature, size_t *signatureLength) {
void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, uint8_t *signature, size_t *signatureLength) {
if (context!=NULL) {
switch (context->algo) {
case BCTBX_EDDSA_25519:
......@@ -422,7 +422,7 @@ void bctbx_EDDSA_setSecretKey(bctbx_EDDSAContext_t *context, const uint8_t *secr
*
* @return BCTBX_VERIFY_SUCCESS or BCTBX_VERIFY_FAILED
*/
int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, const uint8_t *signature, size_t signatureLength) {
int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, const uint8_t *signature, size_t signatureLength) {
int ret = BCTBX_VERIFY_FAILED;
if (context!=NULL) {
decaf_error_t retDecaf = DECAF_FAILURE;
......@@ -536,10 +536,10 @@ bctbx_EDDSAContext_t *bctbx_CreateEDDSAContext(uint8_t EDDSAAlgo) {return NULL;}
void bctbx_EDDSACreateKeyPair(bctbx_EDDSAContext_t *context, int (*rngFunction)(void *, uint8_t *, size_t), void *rngContext) {return;}
void bctbx_EDDSADerivePublicKey(bctbx_EDDSAContext_t *context) {return;}
void bctbx_DestroyEDDSAContext(bctbx_EDDSAContext_t *context) {return;}
void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, uint8_t *signature, size_t *signatureLength) {return;}
void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, uint8_t *signature, size_t *signatureLength) {return;}
void bctbx_EDDSA_setPublicKey(bctbx_EDDSAContext_t *context, const uint8_t *publicKey, const size_t publicKeyLength) {return;}
void bctbx_EDDSA_setSecretKey(bctbx_EDDSAContext_t *context, const uint8_t *secretKey, const size_t secretKeyLength) {return;}
int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, const uint8_t *signature, size_t signatureLength) {return BCTBX_VERIFY_FAILED;}
int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, const uint8_t *signature, size_t signatureLength) {return BCTBX_VERIFY_FAILED;}
void bctbx_EDDSA_ECDH_privateKeyConversion(const bctbx_EDDSAContext_t *ed, bctbx_ECDHContext_t *x) {return;}
void bctbx_EDDSA_ECDH_publicKeyConversion(const bctbx_EDDSAContext_t *ed, bctbx_ECDHContext_t *x, uint8_t isSelf) {return;}
#endif
......@@ -398,18 +398,19 @@ char *get_junit_xml_file_name(const char *suite_name, const char *suffix) {
//In case tests are started in parallel.
//Merge partial JUnit suites reports into the final XML file
void merge_junit_xml_files(const char *dst_file_name) {
char *suite_junit_xml_results[nb_test_suites];
char **suite_junit_xml_results;
ssize_t total_size = 0;
char *file_name;
bctbx_vfs_file_t* bctbx_file;
ssize_t read_bytes = 0, file_size = 0, offset = 0;
int i;
suite_junit_xml_results = malloc(sizeof(char *) * nb_test_suites);
for (i = 0; i < nb_test_suites; i++) {
file_name = get_junit_xml_file_name(test_suite[i]->name, "-Results.xml");
bctbx_file = bctbx_file_open2(bctbx_vfs_get_default(), file_name, O_RDONLY);
if (bctbx_file != NULL) {
file_size = bctbx_file_size(bctbx_file);
file_size = (ssize_t)bctbx_file_size(bctbx_file);
suite_junit_xml_results[i] = malloc(file_size + 1);
read_bytes = bctbx_file_read(bctbx_file, (void *)suite_junit_xml_results[i], file_size, 0);
if (read_bytes == file_size) {
......@@ -429,8 +430,8 @@ void merge_junit_xml_files(const char *dst_file_name) {
free(file_name);
}
//Empty the destination file
truncate(dst_file_name, 0);
bctbx_file = bctbx_file_open(bctbx_vfs_get_default(), dst_file_name, "w+");
bctbx_file_truncate(bctbx_file, 0);
offset = bctbx_file_fprintf(bctbx_file, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites>\n");
for (i = 0; i < nb_test_suites; i++) {
if (suite_junit_xml_results[i] != NULL) {
......@@ -440,6 +441,7 @@ void merge_junit_xml_files(const char *dst_file_name) {
}
bctbx_file_fprintf(bctbx_file, offset, "</testsuites>\n");
bctbx_file_close(bctbx_file);
free(suite_junit_xml_results);
}
//In case tests are started in parallel AND --log-file was given
......@@ -464,7 +466,7 @@ void merge_log_files(const char *base_logfile_name) {
bc_tester_printf(bc_printf_verbosity_error, "Could not open log file '%s' to merge into '%s'", suite_logfile_name, base_logfile_name);
continue;
}
file_size = bctbx_file_size(bctbx_file);
file_size = (ssize_t)bctbx_file_size(bctbx_file);
buf = malloc(file_size);
read_bytes = bctbx_file_read(bctbx_file, buf, file_size, 0);
if (read_bytes == file_size) {
......@@ -485,6 +487,14 @@ int bc_tester_get_max_parallel_processes(void) {
return (nb_test_suites / 2) + 1;
}
#ifdef _WIN32
void kill_sub_processes(int *pids) {
// TODO: Windows support
}
#else
//If there was an error, kill zombies
void kill_sub_processes(int *pids) {
int i;
......@@ -495,6 +505,8 @@ void kill_sub_processes(int *pids) {
}
}
#endif
#ifdef _WIN32
int start_sub_process(const char *suite_name) {
//TODO Windows support
......@@ -549,8 +561,7 @@ int handle_sub_process_error(int pid, int exitStatus, int *suitesPids) {
ssize_t offset;
char *suite_file_name = get_junit_xml_file_name(test_suite[i]->name, "-Results.xml");
bctbx_vfs_file_t* bctbx_file = bctbx_file_open(bctbx_vfs_get_default(), suite_file_name, "w+");
truncate(suite_file_name, 0);
bctbx_file_truncate(bctbx_file, 0);
offset = bctbx_file_fprintf(bctbx_file, 0, "\n<testsuite name=\"%s\" tests=\"%d\" time=\"0\" failures=\"%d\" errors=\"0\" skipped=\"0\">\n", test_suite[i]->name, test_suite[i]->nb_tests, test_suite[i]->nb_tests);
for (j=0; j < test_suite[i]->nb_tests; ++j) {
......
......@@ -404,23 +404,23 @@ static void EdDSA(void) {
bctbx_EDDSACreateKeyPair(james, (int (*)(void *, unsigned char *, size_t))bctbx_rng_get, RNG);
/* james sign the important message */
bctbx_EDDSA_sign(james, importantMessage1, strlen(importantMessage1), context, 250, signature, &signatureLength);
bctbx_EDDSA_sign(james, (uint8_t *)importantMessage1, strlen(importantMessage1), context, 250, signature, &signatureLength);
BC_ASSERT_NOT_EQUAL(signatureLength, 0, int, "%d");
/* world get james public key */
bctbx_EDDSA_setPublicKey(world, james->publicKey, james->pointCoordinateLength);
/* world verifies that the important message was signed by james */
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(world, importantMessage1, strlen(importantMessage1), context, 250, signature, signatureLength), BCTBX_VERIFY_SUCCESS, int, "%d");
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(world, (uint8_t *)importantMessage1, strlen(importantMessage1), context, 250, signature, signatureLength), BCTBX_VERIFY_SUCCESS, int, "%d");
/* twist the signature to get it wrong and verify again, it shall fail */
signature[0] ^=0xFF;
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(world, importantMessage1, strlen(importantMessage1), context, 250, signature, signatureLength), BCTBX_VERIFY_FAILED, int, "%d");
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(world, (uint8_t *)importantMessage1, strlen(importantMessage1), context, 250, signature, signatureLength), BCTBX_VERIFY_FAILED, int, "%d");
/* twist the context to get it wrong and verify again, it shall fail */
signature[0] ^=0xFF;
context[0] ^=0xFF;
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(world, importantMessage1, strlen(importantMessage1), context, 250, signature, signatureLength), BCTBX_VERIFY_FAILED, int, "%d");
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(world, (uint8_t *)importantMessage1, strlen(importantMessage1), context, 250, signature, signatureLength), BCTBX_VERIFY_FAILED, int, "%d");
/* cleaning */
bctbx_DestroyEDDSAContext(james);
......@@ -509,9 +509,9 @@ static void sign_and_key_exchange(void) {
bctbx_rng_get(RNG, context2, 250);
/* sign a message */
bctbx_EDDSA_sign(aliceEDDSA, importantMessage1, strlen(importantMessage1), context1, 250, signature1, &signatureLength1);
bctbx_EDDSA_sign(aliceEDDSA, (uint8_t *)importantMessage1, strlen(importantMessage1), context1, 250, signature1, &signatureLength1);
BC_ASSERT_NOT_EQUAL(signatureLength1, 0, int, "%d");
bctbx_EDDSA_sign(bobEDDSA, importantMessage2, strlen(importantMessage2), context2, 250, signature2, &signatureLength2);
bctbx_EDDSA_sign(bobEDDSA, (uint8_t *)importantMessage2, strlen(importantMessage2), context2, 250, signature2, &signatureLength2);
BC_ASSERT_NOT_EQUAL(signatureLength2, 0, int, "%d");
/* exchange EDDSA keys: Warning: reuse the original EDDSA context, it means we will loose our self EDDSA public key */
......@@ -523,8 +523,8 @@ static void sign_and_key_exchange(void) {
bctbx_EDDSA_ECDH_publicKeyConversion(bobEDDSA, bobECDH, BCTBX_ECDH_ISPEER);
/* Verify signed messages */
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(bobEDDSA, importantMessage1, strlen(importantMessage1), context1, 250, signature1, signatureLength1), BCTBX_VERIFY_SUCCESS, int, "%d");
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(aliceEDDSA, importantMessage2, strlen(importantMessage2), context2, 250, signature2, signatureLength2), BCTBX_VERIFY_SUCCESS, int, "%d");
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(bobEDDSA, (uint8_t *)importantMessage1, strlen(importantMessage1), context1, 250, signature1, signatureLength1), BCTBX_VERIFY_SUCCESS, int, "%d");
BC_ASSERT_EQUAL(bctbx_EDDSA_verify(aliceEDDSA, (uint8_t *)importantMessage2, strlen(importantMessage2), context2, 250, signature2, signatureLength2), BCTBX_VERIFY_SUCCESS, int, "%d");
/* Compute shared secret and compare them */
bctbx_ECDHComputeSecret(aliceECDH, NULL, NULL);
......@@ -563,13 +563,13 @@ static void hash_test(void) {
uint8_t outputBuffer[64];
bctbx_sha256(sha_input, strlen(sha_input), 32, outputBuffer);
bctbx_sha256((uint8_t *)sha_input, strlen(sha_input), 32, outputBuffer);
BC_ASSERT_TRUE(memcmp(outputBuffer, sha256_pattern, 32)==0);
bctbx_sha384(sha_input, strlen(sha_input), 48, outputBuffer);
bctbx_sha384((uint8_t *)sha_input, strlen(sha_input), 48, outputBuffer);
BC_ASSERT_TRUE(memcmp(outputBuffer, sha384_pattern, 48)==0);
bctbx_sha512(sha_input, strlen(sha_input), 64, outputBuffer);
bctbx_sha512((uint8_t *)sha_input, strlen(sha_input), 64, outputBuffer);
BC_ASSERT_TRUE(memcmp(outputBuffer, sha512_pattern, 64)==0);
bctbx_hmacSha256(hmac_sha_key, sizeof(hmac_sha_key), hmac_sha_data, sizeof(hmac_sha_data), 32, outputBuffer);
......
......@@ -47,40 +47,40 @@ static void bytes_to_from_hexa_strings(void) {
BC_ASSERT_EQUAL(bctbx_byte_to_char(0x0e), "e"[0], char, "%c");
bctbx_str_to_uint8(outputBytes, a55aString, 4);
BC_ASSERT_NSTRING_EQUAL(outputBytes, a55aBytes, 2);
BC_ASSERT_NSTRING_EQUAL((char *)outputBytes, (char *)a55aBytes, 2);
bctbx_str_to_uint8(outputBytes, upString, 16);
BC_ASSERT_NSTRING_EQUAL(outputBytes, upBytes, 8);
BC_ASSERT_NSTRING_EQUAL((char *)outputBytes, (char *)upBytes, 8);
bctbx_str_to_uint8(outputBytes, downString, 16);
BC_ASSERT_NSTRING_EQUAL(outputBytes, downBytes, 8);
BC_ASSERT_NSTRING_EQUAL((char *)outputBytes, (char *)downBytes, 8);
bctbx_int8_to_str(outputString, a55aBytes, 2);
BC_ASSERT_NSTRING_EQUAL(outputString, a55aString, 4);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, (char *)a55aString, 4);
bctbx_int8_to_str(outputString, upBytes, 8);
BC_ASSERT_NSTRING_EQUAL(outputString, upString, 16);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, (char *)upString, 16);
bctbx_int8_to_str(outputString, downBytes, 8);
BC_ASSERT_NSTRING_EQUAL(outputString, downString, 16);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, (char *)downString, 16);
bctbx_uint32_to_str(outputString, 0x5aa5c376);
BC_ASSERT_NSTRING_EQUAL(outputString, "5aa5c376", 8);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, "5aa5c376", 8);
bctbx_uint32_to_str(outputString, 0x01234567);
BC_ASSERT_NSTRING_EQUAL(outputString, "01234567", 8);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, "01234567", 8);
bctbx_uint32_to_str(outputString, 0xfedcba98);
BC_ASSERT_NSTRING_EQUAL(outputString, "fedcba98", 8);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, "fedcba98", 8);
BC_ASSERT_EQUAL(bctbx_str_to_uint32("5aa5c376"), 0x5aa5c376, uint32_t, "0x%08x");
BC_ASSERT_EQUAL(bctbx_str_to_uint32("01234567"), 0x01234567, uint32_t, "0x%08x");
BC_ASSERT_EQUAL(bctbx_str_to_uint32("fedcba98"), 0xfedcba98, uint32_t, "0x%08x");
BC_ASSERT_EQUAL((char *)(bctbx_str_to_uint32("5aa5c376")), 0x5aa5c376, uint32_t, "0x%08x");
BC_ASSERT_EQUAL((char *)(bctbx_str_to_uint32("01234567")), 0x01234567, uint32_t, "0x%08x");
BC_ASSERT_EQUAL((char *)(bctbx_str_to_uint32("fedcba98")), 0xfedcba98, uint32_t, "0x%08x");
bctbx_uint64_to_str(outputString, 0xfa5c37643cde8de0);
BC_ASSERT_NSTRING_EQUAL(outputString, "fa5c37643cde8de0", 16);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, "fa5c37643cde8de0", 16);
bctbx_uint64_to_str(outputString, 0x0123456789abcdef);
BC_ASSERT_NSTRING_EQUAL(outputString, "0123456789abcdef", 16);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, "0123456789abcdef", 16);
bctbx_uint64_to_str(outputString, 0xfedcba9876543210);
BC_ASSERT_NSTRING_EQUAL(outputString, "fedcba9876543210", 16);
BC_ASSERT_NSTRING_EQUAL((char *)outputString, "fedcba9876543210", 16);
BC_ASSERT_EQUAL(bctbx_str_to_uint64("fa5c37643cde8de0"), 0xfa5c37643cde8de0, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL(bctbx_str_to_uint64("0123456789abcdef"), 0x0123456789abcdef, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL(bctbx_str_to_uint64("fedcba9876543210"), 0xfedcba9876543210, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL((char *)(bctbx_str_to_uint64("fa5c37643cde8de0")), 0xfa5c37643cde8de0, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL((char *)(bctbx_str_to_uint64("0123456789abcdef")), 0x0123456789abcdef, uint64_t, "0x%" PRIx64);
BC_ASSERT_EQUAL((char *)(bctbx_str_to_uint64("fedcba9876543210")), 0xfedcba9876543210, uint64_t, "0x%" PRIx64);
}
static void time_functions(void) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment