From b6f796adf863d1800c03bc2519108a9ea6f532bf Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Tue, 11 Dec 2007 16:35:07 +0000 Subject: * added mpi operator * kd iv generation fix --- keyDerivation.cpp | 7 ++++++- mpi.cpp | 7 +++++++ mpi.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/keyDerivation.cpp b/keyDerivation.cpp index afe20f6..809a354 100644 --- a/keyDerivation.cpp +++ b/keyDerivation.cpp @@ -124,11 +124,16 @@ void KeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, Buffer& key, r = static_cast(seq_nr / ( 0x01 << ld_kdr_ )); r = r.mul2exp(8); - key_id = r + Mpi(static_cast(label)); + key_id = r + static_cast(label); Mpi salt = Mpi(salt_.getBuf(), salt_.getLength()); iv = key_id ^ salt; + std::cout << "KeyDerivation::generate: r_len: "<< r.getLen() << std::endl; + std::cout << "KeyDerivation::generate: key_id_len: "<< key_id.getLen() << std::endl; + std::cout << "KeyDerivation::generate: salt_len: "<< salt.getLen() << std::endl; + std::cout << "KeyDerivation::generate: iv_len: "<< iv.getLen() << std::endl; + err = gcry_cipher_reset( cipher_ ); if( err ) cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << gpg_strerror( err ); diff --git a/mpi.cpp b/mpi.cpp index 5e094ae..8d35bb8 100644 --- a/mpi.cpp +++ b/mpi.cpp @@ -74,6 +74,13 @@ Mpi Mpi::operator+(const Mpi &b) const return res; } +Mpi Mpi::operator+(const long unsigned int &b) const +{ + Mpi res; + gcry_mpi_add_ui(res.val_, val_, b); + return res; +} + Mpi Mpi::operator*(const unsigned long int n) const { Mpi res; diff --git a/mpi.h b/mpi.h index 1be758e..12079c5 100644 --- a/mpi.h +++ b/mpi.h @@ -48,6 +48,7 @@ public: void operator=(const Mpi &src); void operator=(long unsigned int); Mpi operator+(const Mpi &b) const; + Mpi operator+(const long unsigned int &b) const; Mpi operator^(const Mpi &b) const; Mpi operator*(const unsigned long int n) const; -- cgit v1.2.3