Since you seem to be using C++ I'd recommend to create a class,
let's call it 'Byte_Block'. In that class you have an array for
storing your 16 bytes of data. And beside that you implement all
kinds of operations you need to do on whole blocks of 16 bytes,
including e.g. an operator for XOR and whatever else you need.
One of te constructors may take three arguments, a flag,
the Nonce and l(m), from which you construct the block as
needed for point 1.
class Byte_Block
{
private:
uint8_t m_block[ 16 ];
size_t const m_L = 1; // set this to whatever L is supposed to be,
// just make sure it's not larger than 15
public:
// Constructor for empty block (initialized to all 0)
Byte_Block( )
{
std::fill_n( m_block, 16, 0 );
}
// Constructor from flags, Nonce and l(m)
Byte_Block( uint8_t flags,
uint8_t const * Nonce,
uint8_t const * lm )
{
m_block[ 0 ] = flags;
std::copy_n( Nonce, 15 - m_L, m_block + 1 );
std::copy_n( lm, m_L, m_block + 16 - m_L );
}
// XOR operator (may need some modification if the flags or l(m)
// parts of the blocks must be treated differently)
Byte_Block
operator ^ ( Byte_Block const & other ) const
{
Byte_Block result;
for ( size_t i = 0; i < 16, ++i )
result[ i ] = m_block[ i ] ^ other.m_block[ i ];
return result;
}
// Single byte read access operator
uint8_t
operator [ ] ( size_t pos ) const
{
assert( pos < 16 );
return m_block[ pos ];
}
// Single byte write access operator
uint8_t &
operator [ ] ( size_t pos )
{
assert( pos < 16 );
return m_nlock[ pos ];
}
};
Note: the code has not been testet - not even an attempt to
compile it has been made! So the mistakes all are your's
to find and correct;-)
With something like this you will have split up most problems
into nice little sub-problems, which will look a lot easier to
handle than when you try to solve them all at once. Of course,
you will need a couple of other building blocks in that class.
Now you can do
Byte_Block B1( flags, Nonce
Byte_Block B2( B1 );
std::cout << B1[ 5 ] << std::endl;
B1[ 7 ] = 0xab;
Byte_Block B3 = B1 ^ B2;
etc. So, keep the low level details hidden in the class
and otherwise concentrate on the bigger picture. You don't
need no pointers (to pointers), just, if you in- sist a
dynamic array of pointers to Byte_Block objects (but a
std::vector<Byte_Block> probably would be a simpler and
perhaps somewhat cleaner approach since it doesn't re-
quire that you keep track all of the time of how many
of such blocks you've got).
Regards, Jens
--
\ Jens Thoms Toerring ___
j...@toerring.de
\__________________________
http://toerring.de