diff options
-rw-r--r-- | keyDerivation.cpp | 4 | ||||
-rw-r--r-- | mpi.cpp | 7 | ||||
-rw-r--r-- | 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 ); @@ -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<u_int32_t>(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; } @@ -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: |