Loading ccsrc/Protocols/Security/hmac.cc +4 −5 Changes for ccsrc/Protocols/Security/hmac.cc: 4 added lines, 5 removed lines. Original line number Original line Diff line number Diff line Loading @@ -28,20 +28,19 @@ int hmac::generate(const unsigned char* p_buffer, const size_t p_buffer_length, if ((p_buffer == nullptr) || (p_secret_key == nullptr)) { if ((p_buffer == nullptr) || (p_secret_key == nullptr)) { return -1; return -1; } } ::HMAC_CTX_reset(_ctx); p_hmac = int2oct(0, EVP_MAX_MD_SIZE); p_hmac = int2oct(0, EVP_MAX_MD_SIZE); if (_hash_algorithms == hash_algorithms::sha_256) { if (_hash_algorithms == hash_algorithms::sha_256) { ::HMAC_Init_ex(_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha256(), NULL); ::HMAC_Init_ex(&_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha256(), NULL); } else if (_hash_algorithms == hash_algorithms::sha_384) { } else if (_hash_algorithms == hash_algorithms::sha_384) { ::HMAC_Init_ex(_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha384(), NULL); ::HMAC_Init_ex(&_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha384(), NULL); } else { // TODO To be continued } else { // TODO To be continued return -1; return -1; } } // Compute the hash value // Compute the hash value ::HMAC_Update(_ctx, p_buffer, p_buffer_length); ::HMAC_Update(&_ctx, p_buffer, p_buffer_length); unsigned int length = p_hmac.lengthof(); unsigned int length = p_hmac.lengthof(); ::HMAC_Final(_ctx, (unsigned char*)static_cast<const unsigned char*>(p_hmac), &length); ::HMAC_Final(&_ctx, (unsigned char*)static_cast<const unsigned char*>(p_hmac), &length); loggers::get_instance().log_to_hexa("hmac::generate: ", (unsigned char*)static_cast<const unsigned char*>(p_hmac), length); loggers::get_instance().log_to_hexa("hmac::generate: ", (unsigned char*)static_cast<const unsigned char*>(p_hmac), length); // Resize the hmac // Resize the hmac if (_hash_algorithms == hash_algorithms::sha_256) { if (_hash_algorithms == hash_algorithms::sha_256) { Loading ccsrc/Protocols/Security/hmac.hh +3 −3 Changes for ccsrc/Protocols/Security/hmac.hh: 3 added lines, 3 removed lines. Original line number Original line Diff line number Diff line Loading @@ -29,7 +29,7 @@ enum class hash_algorithms: unsigned char { * \brief This class provides description of HMAC helper methods * \brief This class provides description of HMAC helper methods */ */ class hmac { class hmac { HMAC_CTX *_ctx; //! HMAC context HMAC_CTX _ctx; //! HMAC context hash_algorithms _hash_algorithms; //! HMAC hash algorithm to use hash_algorithms _hash_algorithms; //! HMAC hash algorithm to use public: public: /*! /*! Loading @@ -37,11 +37,11 @@ public: * Create a new instance of the hmac class * Create a new instance of the hmac class * \param[in] p_hash_algorithms The hash algorithm to be used to compute the HMAC. Default: sha_256 * \param[in] p_hash_algorithms The hash algorithm to be used to compute the HMAC. Default: sha_256 */ */ hmac(const hash_algorithms p_hash_algorithms = hash_algorithms::sha_256): _ctx{::HMAC_CTX_new()}, _hash_algorithms(p_hash_algorithms) { }; hmac(const hash_algorithms p_hash_algorithms = hash_algorithms::sha_256): _ctx{}, _hash_algorithms(p_hash_algorithms) { }; /*! /*! * \brief Default destructor * \brief Default destructor */ */ virtual ~hmac() { if (_ctx != nullptr) { ::HMAC_CTX_free(_ctx); }; }; virtual ~hmac() { }; /*! /*! * \fn int generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING& p_hmac); * \fn int generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING& p_hmac); Loading ccsrc/Protocols/Security/security_ecc.cc +4 −4 Changes for ccsrc/Protocols/Security/security_ecc.cc: 4 added lines, 4 removed lines. Original line number Original line Diff line number Diff line Loading @@ -791,9 +791,8 @@ int security_ecc::sign(const OCTETSTRING& p_data, OCTETSTRING& p_r_sig, OCTETSTR return -1; return -1; } } const BIGNUM* r = nullptr; const BIGNUM* r = signature->r; const BIGNUM* s = nullptr; const BIGNUM* s = signature->s; ::ECDSA_SIG_get0(signature, &r, &s); loggers::get_instance().log("security_ecc::sign: r size: %d", BN_num_bytes(r)); loggers::get_instance().log("security_ecc::sign: r size: %d", BN_num_bytes(r)); p_r_sig = int2oct(0, BN_num_bytes(r)); p_r_sig = int2oct(0, BN_num_bytes(r)); ::BN_bn2bin(r, (unsigned char*)static_cast<const unsigned char*>(p_r_sig)); ::BN_bn2bin(r, (unsigned char*)static_cast<const unsigned char*>(p_r_sig)); Loading Loading @@ -823,7 +822,8 @@ int security_ecc::sign_verif(const OCTETSTRING& p_data, const OCTETSTRING& p_sig BIGNUM* s = ::BN_bin2bn(static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2, nullptr); BIGNUM* s = ::BN_bin2bn(static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2, nullptr); loggers::get_instance().log_to_hexa("security_ecc::sign_verify: s=", static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2); loggers::get_instance().log_to_hexa("security_ecc::sign_verify: s=", static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2); ECDSA_SIG *signature = ECDSA_SIG_new(); ECDSA_SIG *signature = ECDSA_SIG_new(); ::ECDSA_SIG_set0(signature, r, s); signature->r = r; signature->s = s; // Check the signature // Check the signature int result = ::ECDSA_do_verify(static_cast<const unsigned char*>(p_data), p_data.lengthof(), signature, _ec_key); int result = ::ECDSA_do_verify(static_cast<const unsigned char*>(p_data), p_data.lengthof(), signature, _ec_key); ::ECDSA_SIG_free(signature); ::ECDSA_SIG_free(signature); Loading data/v3/asn1c_cert.tar.bz2 −5.91 KiB (20.2 KiB) File changed.No diff preview for this file type. View original file View changed file scripts/run_all.bash +2 −2 Changes for scripts/run_all.bash: 2 added lines, 2 removed lines. Original line number Original line Diff line number Diff line Loading @@ -22,7 +22,7 @@ then fi fi fi fi rm ../logs/merged.log.* rm ../logs/merged.*.log for i in $(seq 1 1 $COUNTER) for i in $(seq 1 1 $COUNTER) do do Loading @@ -37,7 +37,7 @@ do done done sleep 1 sleep 1 mv ../logs/merged.log ../logs/merged.log.`date +'%Y%m%d%S'` mv ../logs/merged.log ../logs/merged.`date +'%Y%m%d%S'`.log done done exit 0 exit 0 Loading Loading
ccsrc/Protocols/Security/hmac.cc +4 −5 Changes for ccsrc/Protocols/Security/hmac.cc: 4 added lines, 5 removed lines. Original line number Original line Diff line number Diff line Loading @@ -28,20 +28,19 @@ int hmac::generate(const unsigned char* p_buffer, const size_t p_buffer_length, if ((p_buffer == nullptr) || (p_secret_key == nullptr)) { if ((p_buffer == nullptr) || (p_secret_key == nullptr)) { return -1; return -1; } } ::HMAC_CTX_reset(_ctx); p_hmac = int2oct(0, EVP_MAX_MD_SIZE); p_hmac = int2oct(0, EVP_MAX_MD_SIZE); if (_hash_algorithms == hash_algorithms::sha_256) { if (_hash_algorithms == hash_algorithms::sha_256) { ::HMAC_Init_ex(_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha256(), NULL); ::HMAC_Init_ex(&_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha256(), NULL); } else if (_hash_algorithms == hash_algorithms::sha_384) { } else if (_hash_algorithms == hash_algorithms::sha_384) { ::HMAC_Init_ex(_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha384(), NULL); ::HMAC_Init_ex(&_ctx, (const void*)p_secret_key, (long unsigned int)p_secret_key_length, EVP_sha384(), NULL); } else { // TODO To be continued } else { // TODO To be continued return -1; return -1; } } // Compute the hash value // Compute the hash value ::HMAC_Update(_ctx, p_buffer, p_buffer_length); ::HMAC_Update(&_ctx, p_buffer, p_buffer_length); unsigned int length = p_hmac.lengthof(); unsigned int length = p_hmac.lengthof(); ::HMAC_Final(_ctx, (unsigned char*)static_cast<const unsigned char*>(p_hmac), &length); ::HMAC_Final(&_ctx, (unsigned char*)static_cast<const unsigned char*>(p_hmac), &length); loggers::get_instance().log_to_hexa("hmac::generate: ", (unsigned char*)static_cast<const unsigned char*>(p_hmac), length); loggers::get_instance().log_to_hexa("hmac::generate: ", (unsigned char*)static_cast<const unsigned char*>(p_hmac), length); // Resize the hmac // Resize the hmac if (_hash_algorithms == hash_algorithms::sha_256) { if (_hash_algorithms == hash_algorithms::sha_256) { Loading
ccsrc/Protocols/Security/hmac.hh +3 −3 Changes for ccsrc/Protocols/Security/hmac.hh: 3 added lines, 3 removed lines. Original line number Original line Diff line number Diff line Loading @@ -29,7 +29,7 @@ enum class hash_algorithms: unsigned char { * \brief This class provides description of HMAC helper methods * \brief This class provides description of HMAC helper methods */ */ class hmac { class hmac { HMAC_CTX *_ctx; //! HMAC context HMAC_CTX _ctx; //! HMAC context hash_algorithms _hash_algorithms; //! HMAC hash algorithm to use hash_algorithms _hash_algorithms; //! HMAC hash algorithm to use public: public: /*! /*! Loading @@ -37,11 +37,11 @@ public: * Create a new instance of the hmac class * Create a new instance of the hmac class * \param[in] p_hash_algorithms The hash algorithm to be used to compute the HMAC. Default: sha_256 * \param[in] p_hash_algorithms The hash algorithm to be used to compute the HMAC. Default: sha_256 */ */ hmac(const hash_algorithms p_hash_algorithms = hash_algorithms::sha_256): _ctx{::HMAC_CTX_new()}, _hash_algorithms(p_hash_algorithms) { }; hmac(const hash_algorithms p_hash_algorithms = hash_algorithms::sha_256): _ctx{}, _hash_algorithms(p_hash_algorithms) { }; /*! /*! * \brief Default destructor * \brief Default destructor */ */ virtual ~hmac() { if (_ctx != nullptr) { ::HMAC_CTX_free(_ctx); }; }; virtual ~hmac() { }; /*! /*! * \fn int generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING& p_hmac); * \fn int generate(const OCTETSTRING p_buffer, const OCTETSTRING p_secret_key, OCTETSTRING& p_hmac); Loading
ccsrc/Protocols/Security/security_ecc.cc +4 −4 Changes for ccsrc/Protocols/Security/security_ecc.cc: 4 added lines, 4 removed lines. Original line number Original line Diff line number Diff line Loading @@ -791,9 +791,8 @@ int security_ecc::sign(const OCTETSTRING& p_data, OCTETSTRING& p_r_sig, OCTETSTR return -1; return -1; } } const BIGNUM* r = nullptr; const BIGNUM* r = signature->r; const BIGNUM* s = nullptr; const BIGNUM* s = signature->s; ::ECDSA_SIG_get0(signature, &r, &s); loggers::get_instance().log("security_ecc::sign: r size: %d", BN_num_bytes(r)); loggers::get_instance().log("security_ecc::sign: r size: %d", BN_num_bytes(r)); p_r_sig = int2oct(0, BN_num_bytes(r)); p_r_sig = int2oct(0, BN_num_bytes(r)); ::BN_bn2bin(r, (unsigned char*)static_cast<const unsigned char*>(p_r_sig)); ::BN_bn2bin(r, (unsigned char*)static_cast<const unsigned char*>(p_r_sig)); Loading Loading @@ -823,7 +822,8 @@ int security_ecc::sign_verif(const OCTETSTRING& p_data, const OCTETSTRING& p_sig BIGNUM* s = ::BN_bin2bn(static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2, nullptr); BIGNUM* s = ::BN_bin2bn(static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2, nullptr); loggers::get_instance().log_to_hexa("security_ecc::sign_verify: s=", static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2); loggers::get_instance().log_to_hexa("security_ecc::sign_verify: s=", static_cast<const unsigned char*>(p_signature) + p_signature.lengthof() / 2, p_signature.lengthof() / 2); ECDSA_SIG *signature = ECDSA_SIG_new(); ECDSA_SIG *signature = ECDSA_SIG_new(); ::ECDSA_SIG_set0(signature, r, s); signature->r = r; signature->s = s; // Check the signature // Check the signature int result = ::ECDSA_do_verify(static_cast<const unsigned char*>(p_data), p_data.lengthof(), signature, _ec_key); int result = ::ECDSA_do_verify(static_cast<const unsigned char*>(p_data), p_data.lengthof(), signature, _ec_key); ::ECDSA_SIG_free(signature); ::ECDSA_SIG_free(signature); Loading
data/v3/asn1c_cert.tar.bz2 −5.91 KiB (20.2 KiB) File changed.No diff preview for this file type. View original file View changed file
scripts/run_all.bash +2 −2 Changes for scripts/run_all.bash: 2 added lines, 2 removed lines. Original line number Original line Diff line number Diff line Loading @@ -22,7 +22,7 @@ then fi fi fi fi rm ../logs/merged.log.* rm ../logs/merged.*.log for i in $(seq 1 1 $COUNTER) for i in $(seq 1 1 $COUNTER) do do Loading @@ -37,7 +37,7 @@ do done done sleep 1 sleep 1 mv ../logs/merged.log ../logs/merged.log.`date +'%Y%m%d%S'` mv ../logs/merged.log ../logs/merged.`date +'%Y%m%d%S'`.log done done exit 0 exit 0 Loading