Commit 845969d5 authored by Johan Pascal's avatar Johan Pascal

Refactor logging system

parent f68d9484
......@@ -31,6 +31,7 @@ set(LIME_HEADER_FILES
lime_double_ratchet_protocol.hpp
lime_lime.hpp
lime_crypto_primitives.hpp
lime_log.hpp
)
set(LIME_SOURCE_FILES_C )
set(LIME_SOURCE_FILES_CXX
......
......@@ -16,15 +16,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime/lime.hpp"
#include "lime_impl.hpp"
#include "bctoolbox/exception.hh"
#include "lime_double_ratchet.hpp"
......@@ -127,7 +121,7 @@ namespace lime {
void Lime<Curve>::update_SPk(const limeCallback &callback) {
// Do we need to update the SPk
if (!is_currentSPk_valid()) {
BCTBX_SLOGI<<"User "<<m_selfDeviceId<<" updates its SPk";
LIME_LOGI<<"User "<<m_selfDeviceId<<" updates its SPk";
auto userData = make_shared<callbackUserData<Curve>>(this->shared_from_this(), callback);
// generate and publish the SPk
X<Curve, lime::Xtype::publicKey> SPk{};
......@@ -160,7 +154,7 @@ namespace lime {
template <typename Curve>
void Lime<Curve>::encrypt(std::shared_ptr<const std::string> recipientUserId, std::shared_ptr<std::vector<recipientData>> recipients, std::shared_ptr<const std::vector<uint8_t>> plainMessage, std::shared_ptr<std::vector<uint8_t>> cipherMessage, const limeCallback &callback) {
bctbx_debug("encrypt from %s to %ld recipients", m_selfDeviceId.data(), recipients->size());
LIME_LOGD<<"encrypt from "<<m_selfDeviceId<<" to "<<recipients->size()<<" recipients";
/* Check if we have all the Double Ratchet sessions ready or shall we go for an X3DH */
std::vector<std::string> missingPeers; /* vector of deviceId(GRUU) which are requested to perform X3DH before the encryption can occurs */
......@@ -217,7 +211,7 @@ namespace lime {
template <typename Curve>
bool Lime<Curve>::decrypt(const std::string &recipientUserId, const std::string &senderDeviceId, const std::vector<uint8_t> &cipherHeader, const std::vector<uint8_t> &cipherMessage, std::vector<uint8_t> &plainMessage) {
bctbx_debug("decrypt from %s to %s", senderDeviceId.data(), recipientUserId.data());
LIME_LOGD<<"decrypt from "<<senderDeviceId<<" to "<<recipientUserId;
// do we have any session (loaded or not) matching that senderDeviceId ?
auto sessionElem = m_DR_sessions_cache.find(senderDeviceId);
auto db_sessionIdInCache = 0; // this would be the db_sessionId of the session stored in cache if there is one, no session has the Id 0
......@@ -254,7 +248,7 @@ namespace lime {
DRSessions.clear();
DRSessions.push_back(DRSession);
} catch (BctbxException &e) {
BCTBX_SLOGE<<"Fail to create the DR session from the X3DH init message : "<<e;
LIME_LOGE<<"Fail to create the DR session from the X3DH init message : "<<e;
return false;
}
......@@ -296,7 +290,7 @@ namespace lime {
*/
std::shared_ptr<LimeGeneric> insert_LimeUser(const std::string &dbFilename, const std::string &deviceId, const std::string &url, const lime::CurveId curve, const uint16_t OPkInitialBatchSize,
const limeX3DHServerPostData &X3DH_post_data, const limeCallback &callback) {
BCTBX_SLOGI<<"Create Lime user "<<deviceId;
LIME_LOGI<<"Create Lime user "<<deviceId;
/* first check the requested curve is instanciable and return an exception if not */
#ifndef EC25519_ENABLED
if (curve == lime::CurveId::c25519) {
......@@ -366,7 +360,7 @@ namespace lime {
std::string x3dh_server_url;
localStorage->load_LimeUser(deviceId, Uid, curve, x3dh_server_url); // this one will throw an exception if user is not found, just let it rise
BCTBX_SLOGI<<"Load Lime user "<<deviceId;
LIME_LOGI<<"Load Lime user "<<deviceId;
/* check the curve id retrieved from DB is instanciable and return an exception if not */
#ifndef EC25519_ENABLED
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime_double_ratchet.hpp"
#include "lime_double_ratchet_protocol.hpp"
#include "lime_localStorage.hpp"
......@@ -465,7 +460,7 @@ namespace lime {
try {
decryptStatus = DRSession->ratchetDecrypt(cipherHeader, AD, randomSeed);
} catch (BctbxException &e) { // any bctbx Exception is just considered as decryption failed (it shall occurs only in case of maximum skipped keys reached)
BCTBX_SLOGW<<"Double Ratchet session failed to decrypt message and raised an exception saying : "<<e.what();
LIME_LOGW<<"Double Ratchet session failed to decrypt message and raised an exception saying : "<<e.what();
decryptStatus = false; // lets keep trying with other sessions if provided
}
......
......@@ -16,13 +16,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime/lime.hpp"
#include "lime_double_ratchet_protocol.hpp"
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime/lime.hpp"
#include "lime_localStorage.hpp"
#include "lime_double_ratchet.hpp"
......@@ -69,7 +64,7 @@ Db::Db(string filename) : sql{sqlite3, filename}{
}
if (userVersion > lime::settings::DBuserVersion) { /* nothing to do if we encounter a superior version number than expected, just hope it is compatible */
BCTBX_SLOGE<<"Lime module database schema version found in DB(v "<<userVersion<<") is more recent than the one currently supported by the lime module(v "<<static_cast<unsigned int>(lime::settings::DBuserVersion)<<")";
LIME_LOGE<<"Lime module database schema version found in DB(v "<<userVersion<<") is more recent than the one currently supported by the lime module(v "<<static_cast<unsigned int>(lime::settings::DBuserVersion)<<")";
return;
}
......@@ -449,7 +444,7 @@ bool DR<DHKey>::session_save() {
break;
case DRSessionDbStatus::clean: // Session is clean? So why have we been called?
default:
BCTBX_SLOGE<<"Double ratchet session saved call on sessionId "<<m_dbSessionId<<" but sessions appears to be clean";
LIME_LOGE<<"Double ratchet session saved call on sessionId "<<m_dbSessionId<<" but sessions appears to be clean";
break;
}
} catch (...) {
......@@ -823,14 +818,14 @@ long int Lime<Curve>::store_peerDevice(const std::string &peerDeviceId, const DS
if (m_localStorage->sql.got_data()) { // Found one
DSA<Curve, lime::DSAtype::publicKey> stored_Ik;
if (Ik_blob.get_len() != stored_Ik.size()) { // can't match they are not the same size
BCTBX_SLOGE<<"It appears that peer device "<<peerDeviceId<<" was known with an identity key but is trying to use another one now";
LIME_LOGE<<"It appears that peer device "<<peerDeviceId<<" was known with an identity key but is trying to use another one now";
throw BCTBX_EXCEPTION << "Peer device "<<peerDeviceId<<" changed its Ik";
}
Ik_blob.read(0, (char *)(stored_Ik.data()), stored_Ik.size()); // Read it to compare it to the given one
if (stored_Ik == Ik) { // they match, so we just return the Did
return Did;
} else { // Ik are not matching, peer device changed its Ik!?! Reject
BCTBX_SLOGE<<"It appears that peer device "<<peerDeviceId<<" was known with an identity key but is trying to use another one now";
LIME_LOGE<<"It appears that peer device "<<peerDeviceId<<" was known with an identity key but is trying to use another one now";
throw BCTBX_EXCEPTION << "Peer device "<<peerDeviceId<<" changed its Ik";
}
} else { // not found in local Storage
......@@ -839,7 +834,7 @@ long int Lime<Curve>::store_peerDevice(const std::string &peerDeviceId, const DS
m_localStorage->sql<<"INSERT INTO lime_PeerDevices(DeviceId,Ik) VALUES (:deviceId,:Ik) ", use(peerDeviceId), use(Ik_blob);
m_localStorage->sql<<"select last_insert_rowid()",into(Did);
tr.commit();
bctbx_debug("store peerDevice %s with device id %x", peerDeviceId.data(), Did);
LIME_LOGD<<"store peerDevice "<<peerDeviceId<<" with device id "<<Did;
return Did;
}
} catch (exception const &e) {
......
/*
lime_log.hpp
@author Johan Pascal
@copyright Copyright (C) 2018 Belledonne Communications SARL
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 3 of the License, or
(at your option) any later version.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef lime_log_hpp
#define lime_log_hpp
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#define LIME_LOGD BCTBX_SLOGD
#define LIME_LOGI BCTBX_SLOGI
#define LIME_LOGW BCTBX_SLOGW
#define LIME_LOGE BCTBX_SLOGE
#endif //lime_log_hpp
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime/lime.hpp"
#include "lime_lime.hpp"
#include "lime_localStorage.hpp"
......@@ -140,7 +135,7 @@ namespace lime {
// for each user
for (auto deviceId : deviceIds) {
BCTBX_SLOGI<<"Lime update user "<<deviceId;
LIME_LOGI<<"Lime update user "<<deviceId;
//load user
std::shared_ptr<LimeGeneric> user;
LimeManager::load_user(user, deviceId);
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime/lime.hpp"
#include "lime_impl.hpp"
#include "lime_double_ratchet_protocol.hpp"
......@@ -45,7 +40,7 @@ namespace lime {
SPkVerify->set_public(peerBundle.Ik);
if (!SPkVerify->verify(peerBundle.SPk, peerBundle.SPk_sig)) {
BCTBX_SLOGE<<"X3DH: SPk signature verification failed for device "<<peerBundle.deviceId;
LIME_LOGE<<"X3DH: SPk signature verification failed for device "<<peerBundle.deviceId;
throw BCTBX_EXCEPTION << "Verify signature on SPk failed for deviceId "<<peerBundle.deviceId;
}
......@@ -121,7 +116,7 @@ namespace lime {
}
m_DR_sessions_cache.emplace(peerBundle.deviceId, make_shared<DR<Curve>>(m_localStorage.get(), SK, AD, peerBundle.SPk, peerDid, m_db_Uid, X3DH_initMessage, m_RNG)); // will just do nothing if this peerDeviceId is already in cache
BCTBX_SLOGI<<"X3DH created session with device "<<peerBundle.deviceId;
LIME_LOGI<<"X3DH created session with device "<<peerBundle.deviceId;
}
}
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime/lime.hpp"
#include "lime_x3dh_protocol.hpp"
#include "lime_settings.hpp"
......@@ -167,7 +162,7 @@ namespace lime {
message.push_back(static_cast<uint8_t>((peer_device_ids.size())&0xFF));
if (peer_device_ids.size()>0xFFFF) { // we're asking for more than 2^16 key bundles, really?
BCTBX_SLOGW<<"We are about to request for more than 2^16 key bundles to the X3DH server, it won't fit in protocol, truncate the request to 2^16 but it's very very unusual";
LIME_LOGW<<"We are about to request for more than 2^16 key bundles to the X3DH server, it won't fit in protocol, truncate the request to 2^16 but it's very very unusual";
peer_device_ids.resize(0xFFFF); // resize to max possible value
}
......@@ -176,7 +171,7 @@ namespace lime {
message.push_back(static_cast<uint8_t>(((peer_device_id.size())>>8)&0xFF));
message.push_back(static_cast<uint8_t>((peer_device_id.size())&0xFF));
message.insert(message.end(),peer_device_id.cbegin(), peer_device_id.cend());
BCTBX_SLOGI<<"Request X3DH keys for device "<<peer_device_id;
LIME_LOGI<<"Request X3DH keys for device "<<peer_device_id;
}
}
......@@ -200,21 +195,21 @@ namespace lime {
bool parseMessage_getType(const std::vector<uint8_t> &body, x3dh_message_type &message_type, x3dh_error_code &error_code, const limeCallback callback) noexcept {
// check message holds at leat a header before trying to read it
if (body.size()<X3DH_headerSize) {
BCTBX_SLOGE<<"Got an invalid response from X3DH server";
LIME_LOGE<<"Got an invalid response from X3DH server";
if (callback) callback(lime::callbackReturn::fail, "Got an invalid response from X3DH server");
return false;
}
// check X3DH protocol version
if (body[0] != static_cast<uint8_t>(X3DH_protocolVersion)) {
BCTBX_SLOGE<<"X3DH server runs an other version of X3DH protocol(server "<<int(body[0])<<" - local "<<static_cast<uint8_t>(X3DH_protocolVersion)<<")";
LIME_LOGE<<"X3DH server runs an other version of X3DH protocol(server "<<int(body[0])<<" - local "<<static_cast<uint8_t>(X3DH_protocolVersion)<<")";
if (callback) callback(lime::callbackReturn::fail, "X3DH server and client protocol version mismatch");
return false;
}
// check curve id
if (body[2] != static_cast<uint8_t>(Curve::curveId())) {
BCTBX_SLOGE<<"X3DH server runs curve Id "<<int(body[2])<<" while local is set to "<<static_cast<uint8_t>(Curve::curveId())<<" for this server)";
LIME_LOGE<<"X3DH server runs curve Id "<<int(body[2])<<" while local is set to "<<static_cast<uint8_t>(Curve::curveId())<<" for this server)";
if (callback) callback(lime::callbackReturn::fail, "X3DH server and client curve Id mismatch");
return false;
}
......@@ -259,9 +254,9 @@ namespace lime {
}
if (body.size() == X3DH_headerSize+1) {
BCTBX_SLOGE<<"X3DH server respond error : code "<<int(body[X3DH_headerSize])<<" (no error message)";
LIME_LOGE<<"X3DH server respond error : code "<<int(body[X3DH_headerSize])<<" (no error message)";
} else {
BCTBX_SLOGE<<"X3DH server respond error : code "<<int(body[X3DH_headerSize])<<" : "<<std::string(body.cbegin()+X3DH_headerSize+1, body.cend());
LIME_LOGE<<"X3DH server respond error : code "<<int(body[X3DH_headerSize])<<" : "<<std::string(body.cbegin()+X3DH_headerSize+1, body.cend());
}
switch (static_cast<uint8_t>(body[X3DH_headerSize])) {
......@@ -530,7 +525,7 @@ namespace lime {
// server response to a getPeerBundle packet
std::vector<X3DH_peerBundle<Curve>> peersBundle;
if (!x3dh_protocol::parseMessage_getPeerBundles(responseBody, peersBundle)) { // parsing went wrong
BCTBX_SLOGE<<"Got an invalid peerBundle packet from X3DH server";
LIME_LOGE<<"Got an invalid peerBundle packet from X3DH server";
if (callback) callback(lime::callbackReturn::fail, "Got an invalid peerBundle packet from X3DH server");
cleanUserData(userData);
return;
......@@ -560,7 +555,7 @@ namespace lime {
// server response to a getSelfOPks
std::vector<uint32_t> selfOPkIds{};
if (!x3dh_protocol::parseMessage_selfOPks<Curve>(responseBody, selfOPkIds)) { // parsing went wrong
BCTBX_SLOGE<<"Got an invalid selfOPKs packet from X3DH server";
LIME_LOGE<<"Got an invalid selfOPKs packet from X3DH server";
if (callback) callback(lime::callbackReturn::fail, "Got an invalid selfOPKs packet from X3DH server");
cleanUserData(userData);
return;
......@@ -612,7 +607,7 @@ namespace lime {
auto thiz = userData->limeObj.lock(); // get a shared pointer to Lime Object from the weak pointer stored in userData
// check it is valid (lock() returns nullptr)
if (!thiz) { // our Lime caller object doesn't exists anymore
BCTBX_SLOGE<<"Got response from X3DH server but our Lime Object has been destroyed";
LIME_LOGE<<"Got response from X3DH server but our Lime Object has been destroyed";
return; // the captured shared_ptr on userData will be freed when this capture will be destroyed
}
thiz->process_response(userData, responseCode, responseBody);
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime-tester"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include <vector>
#include <string>
#include "lime_settings.hpp"
......@@ -364,7 +359,7 @@ long int get_DRsessionsId(const std::string &dbFilename, const std::string &self
return 0;
} catch (exception &e) { // swallow any error on DB
BCTBX_SLOGE<<"Got an error on DB: "<<e.what();
LIME_LOGE<<"Got an error on DB: "<<e.what();
sessionsId.clear();
return 0;
}
......@@ -385,7 +380,7 @@ unsigned int get_StoredMessageKeyCount(const std::string &dbFilename, const std:
}
} catch (exception &e) { // swallow any error on DB
BCTBX_SLOGE<<"Got an error while getting the MK count in DB: "<<e.what();
LIME_LOGE<<"Got an error while getting the MK count in DB: "<<e.what();
return 0;
}
}
......@@ -409,7 +404,7 @@ bool get_SPks(const std::string &dbFilename, const std::string &selfDeviceId, si
return false;
}
} catch (exception &e) { // swallow any error on DB
BCTBX_SLOGE<<"Got an error while getting the SPk count in DB: "<<e.what();
LIME_LOGE<<"Got an error while getting the SPk count in DB: "<<e.what();
count=0;
return false;
}
......@@ -428,7 +423,7 @@ size_t get_OPks(const std::string &dbFilename, const std::string &selfDeviceId)
return 0;
}
} catch (exception &e) { // swallow any error on DB
BCTBX_SLOGE<<"Got an error while getting the OPk count in DB: "<<e.what();
LIME_LOGE<<"Got an error while getting the OPk count in DB: "<<e.what();
return 0;
}
......@@ -445,7 +440,7 @@ void forwardTime(const std::string &dbFilename, int days) noexcept {
sql<<"UPDATE X3DH_SPK SET timeStamp = date (timeStamp, '-"<<days<<" day');";
sql<<"UPDATE X3DH_OPK SET timeStamp = date (timeStamp, '-"<<days<<" day');";
} catch (exception &e) { // swallow any error on DB
BCTBX_SLOGE<<"Got an error forwarding time in DB: "<<e.what();
LIME_LOGE<<"Got an error forwarding time in DB: "<<e.what();
}
}
......
......@@ -16,12 +16,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime-tester"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "belle-sip/belle-sip.h"
#include "lime-tester.hpp"
......@@ -80,12 +75,12 @@ int lime_tester_set_log_file(const char *filename) {
}
log_file = fopen(filename, "w");
if (!log_file) {
BCTBX_SLOGE<<"Cannot open file ["<<std::string{filename}<<"] for writing logs because ["<<std::string{strerror(errno)}<<"]";
LIME_LOGE<<"Cannot open file ["<<std::string{filename}<<"] for writing logs because ["<<std::string{strerror(errno)}<<"]";
return -1;
}
dir = bctbx_dirname(filename);
base = bctbx_basename(filename);
BCTBX_SLOGI<<"Redirecting traces to file ["<<std::string{filename}<<"]";
LIME_LOGI<<"Redirecting traces to file ["<<std::string{filename}<<"]";
filehandler = bctbx_create_file_log_handler(0, dir, base, log_file);
bctbx_add_log_handler(filehandler);
if (dir) bctbx_free(dir);
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime-tester"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime-tester.hpp"
#include "lime-tester-utils.hpp"
#include "lime_keys.hpp"
......@@ -125,7 +120,7 @@ void keyExchange_bench(uint64_t runTime_ms) {
std::string freq_unit, period_unit;
snprintSI(freq_unit, freq, "keys/s");
snprintSI(period_unit, 1/freq, "s/keys");
std::cout<<"Key generation "<<int(2*runCount)<<" ECDH keys in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl;
LIME_LOGI<<"Key generation "<<int(2*runCount)<<" ECDH keys in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl;
/* Exchange keys */
Alice->set_peerPublic(Bob->get_selfPublic());
......@@ -146,21 +141,21 @@ void keyExchange_bench(uint64_t runTime_ms) {
freq = 1000*runCount/static_cast<double>(span);
snprintSI(freq_unit, freq, "computations/s");
snprintSI(period_unit, 1/freq, "s/computation");
std::cout<<"Shared Secret "<<int(runCount)<<" computations in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl<<endl;
LIME_LOGI<<"Shared Secret "<<int(runCount)<<" computations in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl<<endl;
}
static void exchange(void) {
#ifdef EC25519_ENABLED
keyExchange_test<C255>();
if (bench) {
std::cout<<"Bench for Curve 25519:"<<endl;
LIME_LOGI<<"Bench for Curve 25519:"<<endl;
keyExchange_bench<C255>(BENCH_TIMING_MS);
}
#endif
#ifdef EC448_ENABLED
keyExchange_test<C448>();
if (bench) {
std::cout<<"Bench for Curve 448:"<<endl;
LIME_LOGI<<"Bench for Curve 448:"<<endl;
keyExchange_bench<C448>(BENCH_TIMING_MS);
}
#endif
......@@ -260,7 +255,7 @@ void signAndVerify_bench(uint64_t runTime_ms ) {
std::string freq_unit, period_unit;
snprintSI(freq_unit, freq, "generations/s");
snprintSI(period_unit, 1/freq, "s/generation");
std::cout<<"Generate "<<int(runCount)<<" Signature key pairs in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl;
LIME_LOGI<<"Generate "<<int(runCount)<<" Signature key pairs in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl;
start = bctbx_get_cur_time_ms();
span=0;
......@@ -280,7 +275,7 @@ void signAndVerify_bench(uint64_t runTime_ms ) {
freq = 1000*runCount/static_cast<double>(span);
snprintSI(freq_unit, freq, "signatures/s");
snprintSI(period_unit, 1/freq, "s/signature");
std::cout<<"Sign "<<int(runCount)<<" messages "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl;
LIME_LOGI<<"Sign "<<int(runCount)<<" messages "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl;
start = bctbx_get_cur_time_ms();
span=0;
......@@ -298,7 +293,7 @@ void signAndVerify_bench(uint64_t runTime_ms ) {
freq = 1000*runCount/static_cast<double>(span);
snprintSI(freq_unit, freq, "verifies/s");
snprintSI(period_unit, 1/freq, "s/verify");
std::cout<<"Verify "<<int(runCount)<<" messages "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl<<endl;
LIME_LOGI<<"Verify "<<int(runCount)<<" messages "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl<<endl;
BC_ASSERT_TRUE(Vera->verify(XpublicKey, aliceSignature));
}
......@@ -307,14 +302,14 @@ static void signAndVerify(void) {
#ifdef EC25519_ENABLED
signAndVerify_test<C255>();
if (bench) {
std::cout<<"Bench for Curve 25519:"<<endl;
LIME_LOGI<<"Bench for Curve 25519:"<<endl;
signAndVerify_bench<C255>(BENCH_TIMING_MS);
}
#endif
#ifdef EC448_ENABLED
signAndVerify_test<C448>();
if (bench) {
std::cout<<"Bench for Curve 448:"<<endl;
LIME_LOGI<<"Bench for Curve 448:"<<endl;
signAndVerify_bench<C448>(BENCH_TIMING_MS);
}
#endif
......@@ -349,7 +344,7 @@ static void hashMac_KDF_bench(uint64_t runTime_ms, size_t IKMsize) {
std::string freq_unit, period_unit;
snprintSI(freq_unit, freq, "derivations/s");
snprintSI(period_unit, 1/freq, "s/derivation");
std::cout<<"Derive "<<int(runCount)<<" key material in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl<<endl;
LIME_LOGI<<"Derive "<<int(runCount)<<" key material in "<<int(span)<<" ms : "<<period_unit<<" "<<freq_unit<<endl<<endl;
}
static void hashMac_KDF(void) {
......@@ -406,12 +401,12 @@ static void hashMac_KDF(void) {
size_t IKMsize = 0;
#ifdef EC25519_ENABLED
IKMsize = DSA<C255, lime::DSAtype::publicKey>::ssize()+4*X<C255, lime::Xtype::sharedSecret>::ssize();
std::cout<<"Bench for SHA512 on Curve 25519 X3DH sized IKM("<<IKMsize<<" bytes)"<<endl;
LIME_LOGI<<"Bench for SHA512 on Curve 25519 X3DH sized IKM("<<IKMsize<<" bytes)"<<endl;
hashMac_KDF_bench(BENCH_TIMING_MS, IKMsize);
#endif
#ifdef EC448_ENABLED
IKMsize = DSA<C448, lime::DSAtype::publicKey>::ssize()+4*X<C448, lime::Xtype::sharedSecret>::ssize();
std::cout<<"Bench for SHA512 on Curve 448 X3DH sized IKM("<<IKMsize<<" bytes)"<<endl;
LIME_LOGI<<"Bench for SHA512 on Curve 448 X3DH sized IKM("<<IKMsize<<" bytes)"<<endl;
hashMac_KDF_bench(BENCH_TIMING_MS, IKMsize);
#endif
}
......
......@@ -16,13 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define BCTBX_LOG_DOMAIN "lime-tester"
#include <bctoolbox/logging.h>
#include "lime_log.hpp"
#include "lime-tester.hpp"
#include "lime-tester-utils.hpp"
#include "lime_localStorage.hpp"
......
This diff is collapsed.
This diff is collapsed.
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