summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Nindl <nine@wirdorange.org>2007-12-12 14:14:58 +0000
committerErwin Nindl <nine@wirdorange.org>2007-12-12 14:14:58 +0000
commita83f590e0e89883e8362bb5c4a760f09856378f9 (patch)
treefd84c16aadc37ed1011e4cbb5a4d42dc18534085
parentset iv to fixed length of 16byte in kd (diff)
changed Mpi::getBuf, now returns u_int8_t *!
-rw-r--r--cypher.cpp2
-rw-r--r--keyDerivation.cpp2
-rw-r--r--mpi.cpp19
-rw-r--r--mpi.h2
4 files changed, 15 insertions, 10 deletions
diff --git a/cypher.cpp b/cypher.cpp
index 7bf0c3e..34a9a10 100644
--- a/cypher.cpp
+++ b/cypher.cpp
@@ -147,7 +147,7 @@ Buffer AesIcmCypher::getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t
iv = salt.mul2exp(16) ^ sid.mul2exp(64) ^ seq.mul2exp(16);
- err = gcry_cipher_setiv( cipher_, iv.getBuf().getBuf(), 16 );
+ err = gcry_cipher_setiv( cipher_, iv.getBuf(16), 16 );
if( err ) {
cLog.msg(Log::PRIO_ERR) << "AesIcmCypher: Failed to set cipher IV: " << gpg_strerror( err );
return Buffer(0);
diff --git a/keyDerivation.cpp b/keyDerivation.cpp
index 5e5068a..4ed87ad 100644
--- a/keyDerivation.cpp
+++ b/keyDerivation.cpp
@@ -133,7 +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 );
- err = gcry_cipher_setiv( cipher_ , iv.getBuf(16).getBuf(), iv.getBuf().getLength());
+ err = gcry_cipher_setiv( cipher_ , iv.getBuf(16), 16);
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 6a94f3e..afd1785 100644
--- a/mpi.cpp
+++ b/mpi.cpp
@@ -127,17 +127,22 @@ void Mpi::clearHighBit(u_int32_t n)
gcry_mpi_clear_highbit( val_, n );
}
-Buffer Mpi::getBuf(u_int32_t min_len) const
+u_int8_t* Mpi::getBuf(u_int32_t buf_len) const
{
- u_int32_t len = 0, written = 0;
- len = gcry_mpi_get_nbits( val_ );
+ // u_int32_t len = 0;
+ u_int32_t written = 0;
- Buffer res(static_cast<u_int32_t>(len/8)+1);
+ u_int8_t *res = NULL;
+ res = new u_int8_t[buf_len];
+ std::memset(res, 0, buf_len);
- if(res.getLength() < min_len)
- res.resizeBack(min_len);
+ // len = gcry_mpi_get_nbits( val_ );
+ // if( len%8 == 0 )
+ // len = len/8;
+ // else
+ // len = (len/8)+1;
- gcry_mpi_print( GCRYMPI_FMT_STD, res, res.getLength(), &written, val_ );
+ gcry_mpi_print( GCRYMPI_FMT_STD, res, buf_len, &written, val_ );
return res;
}
diff --git a/mpi.h b/mpi.h
index 6121d9c..de7aa98 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(u_int32_t min_len=0) const;
+ u_int8_t *getBuf(u_int32_t buf_len) const;
u_int32_t getLen() const;
protected: