From f7307935fb087f8c327c8d8f09f8837925e70c34 Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Tue, 11 Dec 2007 17:47:29 +0000 Subject: set iv to fixed length of 16byte in kd --- keyDerivation.cpp | 4 +--- mpi.cpp | 7 +++++-- mpi.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/keyDerivation.cpp b/keyDerivation.cpp index 406e877..5e5068a 100644 --- a/keyDerivation.cpp +++ b/keyDerivation.cpp @@ -133,9 +133,7 @@ void KeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, Buffer& key, if( err ) cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << gpg_strerror( err ); - iv.clearHighBit(129); - - err = gcry_cipher_setiv( cipher_ , iv.getBuf().getBuf(), iv.getBuf().getLength()); + err = gcry_cipher_setiv( cipher_ , iv.getBuf(16).getBuf(), iv.getBuf().getLength()); if( err ) cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to set IV: " << gpg_strerror( err ); diff --git a/mpi.cpp b/mpi.cpp index b8a4b6c..6a94f3e 100644 --- a/mpi.cpp +++ b/mpi.cpp @@ -127,14 +127,17 @@ void Mpi::clearHighBit(u_int32_t n) gcry_mpi_clear_highbit( val_, n ); } -Buffer Mpi::getBuf() const +Buffer Mpi::getBuf(u_int32_t min_len) const { u_int32_t len = 0, written = 0; len = gcry_mpi_get_nbits( val_ ); Buffer res(static_cast(len/8)+1); - gcry_mpi_print( GCRYMPI_FMT_STD, res, len, &written, val_ ); + if(res.getLength() < min_len) + res.resizeBack(min_len); + + gcry_mpi_print( GCRYMPI_FMT_STD, res, res.getLength(), &written, val_ ); return res; } diff --git a/mpi.h b/mpi.h index b423d7c..6121d9c 100644 --- a/mpi.h +++ b/mpi.h @@ -55,7 +55,7 @@ public: void rShift(u_int8_t n); // LSB on the right side! Mpi mul2exp(u_int32_t e) const; // value * 2^e void clearHighBit(u_int32_t n); - Buffer getBuf() const; + Buffer getBuf(u_int32_t min_len=0) const; u_int32_t getLen() const; protected: -- cgit v1.2.3