Commit 62165440 authored by YannGarcia's avatar YannGarcia
Browse files

Build lib_its_security on Windows

parent f58d1de6
Loading
Loading
Loading
Loading
+2232 −2219
Original line number Diff line number Diff line
@@ -13,7 +13,14 @@

#include <math.h>
#include <assert.h>
#ifndef _Win64
#include <arpa/inet.h>
#else
#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
 // Windows Header Files
#include <windows.h>
#include <Winsock2.h>
#endif

#include <openssl/bio.h>

@@ -41,7 +48,9 @@ void show_ec_point(const int8_t* p_prefix, lib_its_security_context_t* p_lib_its
  char* result = EC_POINT_point2hex(p_lib_its_security_context->ec_group, p_ec_point, POINT_CONVERSION_UNCOMPRESSED, p_lib_its_security_context->bn_ctx);
  if (result != NULL) {
    fprintf(stderr, "%s\n", result);
#ifdef _Win64
    free(result);
#endif
  } else {
    fprintf(stderr, "(null)\n");
  }
@@ -239,7 +248,7 @@ int kdf2_sha256(
    uint8_t* h;
    hash_with_sha256(hash_input, hash_input_length, &h);
    //show_hex((const int8_t*)"h", (const void*)h, 32);
    memcpy((void*)digest + digest_idx, (const void*)h, sha256_blk_len);
    memcpy((void*)(digest + digest_idx), (const void*)h, sha256_blk_len);
    //show_hex((const int8_t*)"digest", (const void*)digest, digest_idx + sha256_blk_len);
    digest_idx += sha256_blk_len;
    free(h);
@@ -545,7 +554,7 @@ int32_t generate_and_derive_ephemeral_key_for_decryption(
  memcpy((void*)k1, (const void*)digest, k_enc);
  show_hex((const int8_t*)"k1", k1, k_enc);
  p_lib_its_security_context->sym_key = (uint8_t*)malloc(k_enc);
  for (int i = 0; i < k_enc; *(p_lib_its_security_context->sym_key + i) = *(k1 + i) ^ *(p_lib_its_security_context->enc_sym_key + i), i++);
  for (unsigned int i = 0; i < k_enc; *(p_lib_its_security_context->sym_key + i) = *(k1 + i) ^ *(p_lib_its_security_context->enc_sym_key + i), i++);
  show_hex((const int8_t*)"sym_key", p_lib_its_security_context->sym_key, p_lib_its_security_context->sym_key_length);
  free(k1);
  free(k2);
@@ -1038,14 +1047,18 @@ int32_t generic_verify(
    return -1;
  }

  uint8_t sig_r[p_lib_its_security_context->key_length];
  uint8_t* sig_r = (uint8_t*)malloc(p_lib_its_security_context->key_length);
  memcpy((void*)sig_r, (const void*)p_signature, p_lib_its_security_context->key_length);
  uint8_t sig_s[p_lib_its_security_context->key_length];
  uint8_t* sig_s = (uint8_t*)malloc(p_lib_its_security_context->key_length);
  memcpy((void*)sig_s, (const void*)(p_signature + p_lib_its_security_context->key_length), p_lib_its_security_context->key_length);
  if (sign_verify(p_lib_its_security_context, hashed_data, p_lib_its_security_context->key_length, sig_r, sig_s, p_lib_its_security_context->key_length) == -1) {
    free(sig_r);
    free(sig_s);
    free(hashed_data);
    return -1;
  }
  free(sig_r);
  free(sig_s);
  free(hashed_data);

  return 0;
+404 −384
Original line number Diff line number Diff line
@@ -10,7 +10,23 @@
 */
#pragma once

#ifdef _Win64
#ifdef LIBITSSECURITY_EXPORTS
#define LIBITSSECURITY_API __declspec(dllexport)
#else
#define LIBITSSECURITY_API __declspec(dllimport)
#endif
#else // _Win64
#define LIBITSSECURITY_API
#endif // _Win64

#ifdef __cplusplus
extern "C" {
#endif // !__cplusplus

#ifndef _Win64
#include <unistd.h>
#endif // !_Win32
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -39,12 +55,12 @@ typedef enum ecc_elliptic_curves_ {
 * \enum Public key coordinates compression mode
 */
typedef enum ecc_compressed_mode_ {
  compressed_y_0, /*!< The last significant bit of Y-coodinate ended with 0 */
  compressed_y_1  /*!< The last significant bit of Y-coodinate ended with 1 */
  compressed_y_0, /*!< The last significant bit of Y-coordinate ended with 0 */
  compressed_y_1  /*!< The last significant bit of Y-coordinate ended with 1 */
} ecc_compressed_mode_t;

/*!
 * \enum Supported encryption algorithem
 * \enum Supported encryption algorithm
 */
typedef enum ecc_encryption_algorithm_ {
  aes_128_ccm,
@@ -64,8 +80,8 @@ typedef struct lib_its_security_context_ {
  BN_CTX*                bn_ctx;               /*!< Pre-alocated memory used to increase OpenSSL processing */
  size_t                 key_length;           /*!< private/public keys length */
  uint8_t*               private_key;          /*!< Private key */
  uint8_t*               public_key_x;         /*!< Public key Y-coodinate */
  uint8_t*               public_key_y;         /*!< Public key Y-coodinate */
  uint8_t*               public_key_x;         /*!< Public key Y-coordinate */
  uint8_t*               public_key_y;         /*!< Public key Y-coordinate */
  uint8_t*               public_key_c;         /*!< Compressed Public key */
  ecc_compressed_mode_t  compressed_mode;      /*!< Compression mode */

@@ -85,18 +101,18 @@ typedef struct lib_its_security_context_ {
 * \fn int32_t initialize(const ecc_elliptic_curves_t p_elliptic_curve, lib_its_security_context_t** p_lib_its_security_context);
 * \brief Initialize the ITS security context according to the specified elliptic curve. This function shall be called before any othe lib_its_security function.
 * \param[in] p_elliptic_curve The elliptic curve to be used
 * \param[out] p_lib_its_security_context The internl context (To be released using uninitialize function)
 * \param[out] p_lib_its_security_context The internal context (To be released using uninitialize function)
 * \return 0 on success, -1 otherwise
 */
int32_t initialize(const ecc_elliptic_curves_t p_elliptic_curve, lib_its_security_context_t** p_lib_its_security_context);
LIBITSSECURITY_API int32_t initialize(const ecc_elliptic_curves_t p_elliptic_curve, lib_its_security_context_t** p_lib_its_security_context);

/**
 * \fn int32_t uninitialize(lib_its_security_context_t** p_lib_its_security_context);
 * \brief Release resources allocated by initialize fiunction
 * \param[in/out] p_lib_its_security_context The internl context
 * \param[in/out] p_lib_its_security_context The internal context
 * \return 0 on success, -1 otherwise
 */
int32_t uninitialize(lib_its_security_context_t** p_lib_its_security_context);
LIBITSSECURITY_API int32_t uninitialize(lib_its_security_context_t** p_lib_its_security_context);

/**
 * \fn int32_t hash_with_sha256(const uint8_t* p_to_be_hashed_data,const size_t p_to_be_hashed_data_length,uint8_t** p_hashed_data);
@@ -106,7 +122,7 @@ int32_t uninitialize(lib_its_security_context_t** p_lib_its_security_context);
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \return 0 on success, -1 otherwise
 */
int32_t hash_with_sha256(const uint8_t* p_to_be_hashed_data, const size_t p_to_be_hashed_data_length, uint8_t** p_hashed_data);
LIBITSSECURITY_API int32_t hash_with_sha256(const uint8_t* p_to_be_hashed_data, const size_t p_to_be_hashed_data_length, uint8_t** p_hashed_data);
/**
 * \fn int32_t hash_with_sha384(const uint8_t* p_to_be_hashed_data,const size_t p_to_be_hashed_data_length,uint8_t** p_hashed_data);
 * \brief Produces a 384-bit (48-bytes) hash value
@@ -115,7 +131,7 @@ int32_t hash_with_sha256(const uint8_t* p_to_be_hashed_data, const size_t p_to_b
 * \param[in] p_hashed_data The data to be used to calculate the hash value
 * \return 0 on success, -1 otherwise
 */
int32_t hash_with_sha384(const uint8_t* p_to_be_hashed_data, const size_t p_to_be_hashed_data_length, uint8_t** p_hashed_data);
LIBITSSECURITY_API int32_t hash_with_sha384(const uint8_t* p_to_be_hashed_data, const size_t p_to_be_hashed_data_length, uint8_t** p_hashed_data);

/**
 * \fn int32_t hmac_sha256(const uint8_t* p_secret_key,const size p_secret_key_length,const OCTETSTRING& p_message,const size p_message_length, uint8_t** p_hmac);
@@ -125,19 +141,19 @@ int32_t hash_with_sha384(const uint8_t* p_to_be_hashed_data, const size_t p_to_b
 * \param[out] p_hmac The HMAC with SHA256 of the message resized to 16-bytes (To be released after use)
 * \return 0 on success, -1 otherwise
 */
int32_t hmac_sha256(const uint8_t* p_secret_key, const size_t p_secret_key_length, const uint8_t* p_message, const size_t p_message_length, uint8_t** p_hmac);
LIBITSSECURITY_API int32_t hmac_sha256(const uint8_t* p_secret_key, const size_t p_secret_key_length, const uint8_t* p_message, const size_t p_message_length, uint8_t** p_hmac);

/**
 * \fn int32_t sign_with_ecdsa_nistp256_with_sha256(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_signed_secured_message,const size_t p_to_be_signed_secured_message_length,const uint8_t* p_certificate_issuer,const uint8_t* p_private_key,uint8_t** p_signature);
 * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The security context
 * \param[in] p_to_be_signed_secured_message The data to be signed
 * \param[in] p_certificate_issuer The whole-hash issuer certificate or int2oct(0,32) in case of self signed certificate
 * \param[in] p_private_key The private key
 * \param[out] p_signature The signature of the data to be signed (To be released after use)
 * \return The signature value
 */
int32_t sign_with_ecdsa_nistp256_with_sha256(
LIBITSSECURITY_API int32_t sign_with_ecdsa_nistp256_with_sha256(
                                                                lib_its_security_context_t* p_lib_its_security_context,
                                                                const uint8_t* p_to_be_signed_secured_message,
                                                                const size_t p_to_be_signed_secured_message_length,
@@ -149,14 +165,14 @@ int32_t sign_with_ecdsa_nistp256_with_sha256(
/**
 * \fn int32_t sign_with_ecdsa_brainpoolp256r1_with_sha256(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_signed_secured_message,const size_t p_to_be_signed_secured_message_length,const uint8_t* p_certificate_issuer,const uint8_t* p_private_key,uint8_t** p_signature);
 * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_signed_secured_message The data to be signed
 * \param[in] p_certificate_issuer The whole-hash issuer certificate or int2oct(0,32) in case of self signed certificate
 * \param[in] p_private_key The private key
 * \param[out] p_signature The signature of the data to be signed (To be released after use)
 * \return The signature value
 */
int32_t sign_with_ecdsa_brainpoolp256r1_with_sha256(
LIBITSSECURITY_API int32_t sign_with_ecdsa_brainpoolp256r1_with_sha256(
                                                                       lib_its_security_context_t* p_lib_its_security_context,
                                                                       const uint8_t* p_to_be_signed_secured_message,
                                                                       const size_t p_to_be_signed_secured_message_length,
@@ -168,14 +184,14 @@ int32_t sign_with_ecdsa_brainpoolp256r1_with_sha256(
/**
 * \fn int32_t sign_with_ecdsa_brainpoolp384r1_with_sha384(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_signed_secured_message,const size_t p_to_be_signed_secured_message_length,const uint8_t* p_certificate_issuer,const uint8_t* p_private_key,uint8_t** p_signature);
 * \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature based on standard IEEE 1609.2
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_signed_secured_message The data to be signed
 * \param[in] p_certificate_issuer The whole-hash issuer certificate or int2oct(0,32) in case of self signed certificate
 * \param[in] p_private_key The private key
 * \param[out] p_signature The signature of the data to be signed (To be released after use)
 * \return 0 on success, -1 otherwise
 */
int32_t sign_with_ecdsa_brainpoolp384r1_with_sha384(
LIBITSSECURITY_API int32_t sign_with_ecdsa_brainpoolp384r1_with_sha384(
                                                                       lib_its_security_context_t* p_lib_its_security_context,
                                                                       const uint8_t* p_to_be_signed_secured_message,
                                                                       const size_t p_to_be_signed_secured_message_length,
@@ -187,14 +203,14 @@ int32_t sign_with_ecdsa_brainpoolp384r1_with_sha384(
/**
 * \fn int32_t verify_with_ecdsa_nistp256_with_sha256(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_verified_data,const size_t p_to_be_verified_data_length,const uint8_t* p_certificate_issuer,const uint8_t* p_signature,const uint8_t* p_ecdsa_nistp256_publicKey_compressed, const ecc_compressed_mode_t p_compressed_mode);
 * \brief Verify the signature of the specified data based on standard IEEE 1609.2
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_verified_data The data to be verified
 * \param[in] p_certificate_issuer The whole-hash issuer certificate or int2oct(0,32) in case of self signed certificate
 * \param[in] p_signature The signature
 * \param[in] p_ecdsa_nistp256_publicKey_compressed The compressed public key (x coordinate only)
 * \return 0 on success, -1 otherwise
 */
int32_t verify_with_ecdsa_nistp256_with_sha256(
LIBITSSECURITY_API int32_t verify_with_ecdsa_nistp256_with_sha256(
                                                                  lib_its_security_context_t* p_lib_its_security_context,
                                                                  const uint8_t* p_to_be_verified_data,
                                                                  const size_t p_to_be_verified_data_length,
@@ -207,13 +223,13 @@ int32_t verify_with_ecdsa_nistp256_with_sha256(
/**
 * \fn int32_t verify_with_ecdsa_nistp256_with_sha256_raw(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_verified_data,const size_t p_to_be_verified_data_length,const uint8_t* p_certificate_issuer,const uint8_t* p_signature,const uint8_t* p_ecdsa_nistp256_publicKey_compressed, const ecc_compressed_mode_t p_compressed_mode));
 * \brief Verify the signature of the specified data based on raw data
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_verified_data The data to be verified
 * \param[in] p_signature The signature
 * \param[in] p_ecdsa_nistp256_publicKey_compressed The compressed public key (x coordinate only)
 * \return 0 on success, -1 otherwise
 */
int32_t verify_with_ecdsa_nistp256_with_sha256_raw(
LIBITSSECURITY_API int32_t verify_with_ecdsa_nistp256_with_sha256_raw(
                                                   lib_its_security_context_t* p_lib_its_security_context,
                                                   const uint8_t* p_to_be_verified_data,
                                                   const size_t p_to_be_verified_data_length,
@@ -225,14 +241,14 @@ int32_t verify_with_ecdsa_nistp256_with_sha256_raw(
/**
 * \fn int32_t verify_with_ecdsa_brainpoolp256r1_with_sha256(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_verified_data,const size_t p_to_be_verified_data_length,const uint8_t* p_certificate_issuer,const uint8_t* p_signature,const uint8_t* p_ecdsa_nistp256_publicKey_compressed, const ecc_compressed_mode_t p_compressed_mode);
 * \brief Verify the signature of the specified data based on standard IEEE 1609.2
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_verified_data The data to be verified
 * \param[in] p_certificate_issuer The whole-hash issuer certificate or int2oct(0,32) in case of self signed certificate
 * \param[in] p_signature The signature
 * \param[in] p_ecdsaBrainpoolp256PublicKeyCompressed The compressed public key (x coordinate only)
 * \return 0 on success, -1 otherwise
 */
int32_t verify_with_ecdsa_brainpoolp256r1_with_sha256(
LIBITSSECURITY_API int32_t verify_with_ecdsa_brainpoolp256r1_with_sha256(
                                                      lib_its_security_context_t* p_lib_its_security_context,
                                                      const uint8_t* p_to_be_verified_data,
                                                      const size_t p_to_be_verified_data_length,
@@ -245,14 +261,14 @@ int32_t verify_with_ecdsa_brainpoolp256r1_with_sha256(
/**
 * \fn int32_t verify_with_ecdsa_brainpoolp384r1_with_sha384(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_to_be_verified_data,const size_t p_to_be_verified_data_length,const uint8_t* p_certificate_issuer,const uint8_t* p_signature,const uint8_t* p_ecdsa_nistp256_publicKey_compressed, const ecc_compressed_mode_t p_compressed_mode);
 * \brief Verify the signature of the specified data based on standard IEEE 1609.2
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_verified_data The data to be verified
 * \param[in] p_certificate_issuer The whole-hash issuer certificate or int2oct(0,32) in case of self signed certificate
 * \param[in] p_signature The signature
 * \param[in] p_ecdsaBrainpoolp384PublicKeyCompressed The compressed public key (x coordinate only)
 * \return 0 on success, -1 otherwise
 */
int32_t verify_with_ecdsa_brainpoolp384r1_with_sha384(
LIBITSSECURITY_API int32_t verify_with_ecdsa_brainpoolp384r1_with_sha384(
                                                      lib_its_security_context_t* p_lib_its_security_context,
                                                      const uint8_t* p_to_be_verified_data,
                                                      const size_t p_to_be_verified_data_length,
@@ -264,7 +280,7 @@ int32_t verify_with_ecdsa_brainpoolp384r1_with_sha384(

/**
 * \brief Encrypt the message using ECIES algorithm to encrypt AES 128 CCM symmetric key,as defined in IEEE Std 1609.2-2017
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_to_be_encrypted_secured_message The message to be encrypted
 * \param[in] p_recipients_public_key_compressed The Recipient's compressed public key
 * \param[in] p_compressed_mode The compressed mode,0 if the latest bit of Y-coordinate is 0,1 otherwise
@@ -280,7 +296,7 @@ int32_t verify_with_ecdsa_brainpoolp384r1_with_sha384(
 * \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/
 * \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf
 */
int32_t encrypt_with_ecies_nistp256_with_sha256(
LIBITSSECURITY_API int32_t encrypt_with_ecies_nistp256_with_sha256(
                                                lib_its_security_context_t* p_lib_its_security_context,
                                                const uint8_t* p_to_be_encrypted_secured_message,
                                                const size_t p_to_be_encrypted_secured_message_length,
@@ -300,7 +316,7 @@ int32_t encrypt_with_ecies_nistp256_with_sha256(

/**
 * \brief Decrypt the message using ECIES algorithm to decrypt AES 128 CCM symmetric key,as defined in IEEE Std 1609.2-2017
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[in] p_encrypted_secured_message The encrypted message
 * \param[in] p_private_enc_key The private encryption key
 * \param[in] p_public_ephemeral_key_compressed The public ephemeral compressed key
@@ -313,7 +329,7 @@ int32_t encrypt_with_ecies_nistp256_with_sha256(
 * \see https://www.nominet.uk/researchblog/how-elliptic-curve-cryptography-encryption-works/
 * \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf
 */
int32_t decrypt_with_ecies_nistp256_with_sha256(
LIBITSSECURITY_API int32_t decrypt_with_ecies_nistp256_with_sha256(
                                                lib_its_security_context_t* p_lib_its_security_context,
                                                const uint8_t* p_encrypted_secured_message,
                                                const size_t p_encrypted_secured_message_length,
@@ -330,7 +346,7 @@ int32_t decrypt_with_ecies_nistp256_with_sha256(
                                                size_t* p_plain_text_message_length
                                                );

int32_t encrypt_with_ecies_brainpoolp256r1_with_sha256(
LIBITSSECURITY_API int32_t encrypt_with_ecies_brainpoolp256r1_with_sha256(
                                                       lib_its_security_context_t* p_lib_its_security_context,
                                                       const uint8_t* p_to_be_encrypted_secured_message,
                                                       const size_t p_to_be_encrypted_secured_message_length,
@@ -348,7 +364,7 @@ int32_t encrypt_with_ecies_brainpoolp256r1_with_sha256(
                                                       size_t* p_encrypted_secured_message_length
                                                       );

int32_t decrypt_with_ecies_brainpoolp256r1_with_sha256(
LIBITSSECURITY_API int32_t decrypt_with_ecies_brainpoolp256r1_with_sha256(
                                                       lib_its_security_context_t* p_lib_its_security_context,
                                                       const uint8_t* p_encrypted_secured_message,
                                                       const size_t p_encrypted_secured_message_length,
@@ -368,13 +384,13 @@ int32_t decrypt_with_ecies_brainpoolp256r1_with_sha256(
/**
 * \fn int32_t generate_key_pair(lib_its_security_context_t* p_lib_its_security_context, uint8_t** p_private_key,uint8_t** p_public_key_x,uint8_t** p_public_key_y,uint8_t** p_public_key_compressed, ecc_compressed_mode_t* p_compressed_mode);
 * \brief    Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm.
 * \param[in/out] p_hashed_data The data to be used to calculate the hash value
 * \param[in/out] p_lib_its_security_context The internal context
 * \param[out] p_private_key    The new private key value (To be released after use)
 * \param[out] p_public_key_x    The new public key value (x coordinate) (To be released after use)
 * \param[out] p_public_key_x    The new public key value (y coordinate) (To be released after use)
 * \return 0 on success, -1 otherwise
 */
int32_t generate_key_pair(
LIBITSSECURITY_API int32_t generate_key_pair(
                          lib_its_security_context_t* p_lib_its_security_context,
                          uint8_t** p_private_key,
                          uint8_t** p_public_key_x,
@@ -382,3 +398,7 @@ int32_t generate_key_pair(
                          uint8_t** p_public_key_compressed,
                          ecc_compressed_mode_t* p_compressed_mode
                          );

#ifdef __cplusplus
}
#endif // !__cplusplus
+49 −10
Original line number Diff line number Diff line
#ifdef _Win64
#include "pch.h"
#else
#include <gtest/gtest.h>
#endif
#include "gtest/gtest.h"

extern "C" {
#include "lib_its_security.h"
int8_t* bin_to_hex(const uint8_t* p_buffer, const size_t p_buffer_length);
#ifndef _Win64
uint8_t* hex_to_bin(const int8_t* p_buffer, size_t* p_buffer_length);
#endif
}

#ifdef _Win64
uint8_t* hex_to_bin(const int8_t* p_buffer, size_t* p_buffer_length) {
    int8_t a;
    size_t i, len;
    uint8_t* retval = NULL;

    // Sanity check
    if (p_buffer == NULL) {
        return NULL;
    }
    if ((len = strlen((const char*)p_buffer)) & 1) {
        return NULL;
}

    retval = (uint8_t*)malloc(len >> 1);
    for (i = 0; i < len; i++) {
        a = toupper(*(p_buffer + i));
        if (!isxdigit(a)) {
            break;
        }
        if (isdigit(a)) {
            a -= '0';
        }
        else {
            a = a - 'A' + 0x0A;
        }
        if (i & 1) {
            retval[i >> 1] |= a;
        }
        else {
            retval[i >> 1] = a << 4;
        }
    } // End of 'for' statement
    if (i < len) {
        free(retval);
        retval = NULL;
    }
    *p_buffer_length = len >> 1;

    return retval;
}
#endif

#ifndef _Win64
/**
 * @class lib_its_security unit tests suite implementation
 */
@@ -19,6 +59,7 @@ protected:
    virtual void SetUp() { };
    virtual void TearDown() { };
};
#endif

TEST(lib_its_security_test_suite, Init1) {
    EXPECT_TRUE(initialize(nist_p_256, NULL) == -1);
@@ -1222,5 +1263,3 @@ int main(int argc, char **argv) {
  return RUN_ALL_TESTS();
}