Add BufferedTransformation GetWord64 and PutWord64 (GH #862)
parent
a76c6a203f
commit
6d69043403
37
cryptlib.cpp
37
cryptlib.cpp
|
|
@ -743,6 +743,12 @@ size_t BufferedTransformation::ChannelPutWord32(const std::string &channel, word
|
|||
return ChannelPut(channel, m_buf, 4, blocking);
|
||||
}
|
||||
|
||||
size_t BufferedTransformation::ChannelPutWord64(const std::string &channel, word64 value, ByteOrder order, bool blocking)
|
||||
{
|
||||
PutWord(false, order, m_buf, value);
|
||||
return ChannelPut(channel, m_buf, 8, blocking);
|
||||
}
|
||||
|
||||
size_t BufferedTransformation::PutWord16(word16 value, ByteOrder order, bool blocking)
|
||||
{
|
||||
return ChannelPutWord16(DEFAULT_CHANNEL, value, order, blocking);
|
||||
|
|
@ -753,6 +759,11 @@ size_t BufferedTransformation::PutWord32(word32 value, ByteOrder order, bool blo
|
|||
return ChannelPutWord32(DEFAULT_CHANNEL, value, order, blocking);
|
||||
}
|
||||
|
||||
size_t BufferedTransformation::PutWord64(word64 value, ByteOrder order, bool blocking)
|
||||
{
|
||||
return ChannelPutWord64(DEFAULT_CHANNEL, value, order, blocking);
|
||||
}
|
||||
|
||||
// Issue 340
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic push
|
||||
|
|
@ -765,7 +776,7 @@ size_t BufferedTransformation::PeekWord16(word16 &value, ByteOrder order) const
|
|||
byte buf[2] = {0, 0};
|
||||
size_t len = Peek(buf, 2);
|
||||
|
||||
if (order)
|
||||
if (order == BIG_ENDIAN_ORDER)
|
||||
value = (buf[0] << 8) | buf[1];
|
||||
else
|
||||
value = (buf[1] << 8) | buf[0];
|
||||
|
|
@ -778,7 +789,7 @@ size_t BufferedTransformation::PeekWord32(word32 &value, ByteOrder order) const
|
|||
byte buf[4] = {0, 0, 0, 0};
|
||||
size_t len = Peek(buf, 4);
|
||||
|
||||
if (order)
|
||||
if (order == BIG_ENDIAN_ORDER)
|
||||
value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf [3];
|
||||
else
|
||||
value = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf [0];
|
||||
|
|
@ -786,6 +797,23 @@ size_t BufferedTransformation::PeekWord32(word32 &value, ByteOrder order) const
|
|||
return len;
|
||||
}
|
||||
|
||||
size_t BufferedTransformation::PeekWord64(word64 &value, ByteOrder order) const
|
||||
{
|
||||
byte buf[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
size_t len = Peek(buf, 8);
|
||||
|
||||
if (order == BIG_ENDIAN_ORDER)
|
||||
value = ((word64)buf[0] << 56) | ((word64)buf[1] << 48) | ((word64)buf[2] << 40) |
|
||||
((word64)buf[3] << 32) | ((word64)buf[4] << 24) | ((word64)buf[5] << 16) |
|
||||
((word64)buf[6] << 8) | (word64)buf[7];
|
||||
else
|
||||
value = ((word64)buf[7] << 56) | ((word64)buf[6] << 48) | ((word64)buf[5] << 40) |
|
||||
((word64)buf[4] << 32) | ((word64)buf[3] << 24) | ((word64)buf[2] << 16) |
|
||||
((word64)buf[1] << 8) | (word64)buf[0];
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// Issue 340
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic pop
|
||||
|
|
@ -801,6 +829,11 @@ size_t BufferedTransformation::GetWord32(word32 &value, ByteOrder order)
|
|||
return (size_t)Skip(PeekWord32(value, order));
|
||||
}
|
||||
|
||||
size_t BufferedTransformation::GetWord64(word64 &value, ByteOrder order)
|
||||
{
|
||||
return (size_t)Skip(PeekWord64(value, order));
|
||||
}
|
||||
|
||||
void BufferedTransformation::Attach(BufferedTransformation *newAttachment)
|
||||
{
|
||||
if (AttachedTransformation() && AttachedTransformation()->Attachable())
|
||||
|
|
|
|||
58
cryptlib.h
58
cryptlib.h
|
|
@ -1614,8 +1614,8 @@ public:
|
|||
/// \brief Input a byte for processing
|
||||
/// \param inByte the 8-bit byte (octet) to be processed.
|
||||
/// \param blocking specifies whether the object should block when processing input.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed). 0 indicates all
|
||||
/// bytes were processed.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed).
|
||||
/// 0 indicates all bytes were processed.
|
||||
/// \details <tt>Put(byte)</tt> calls <tt>Put(byte*, size_t)</tt>.
|
||||
size_t Put(byte inByte, bool blocking=true)
|
||||
{return Put(&inByte, 1, blocking);}
|
||||
|
|
@ -1624,8 +1624,8 @@ public:
|
|||
/// \param inString the byte buffer to process
|
||||
/// \param length the size of the string, in bytes
|
||||
/// \param blocking specifies whether the object should block when processing input
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed). 0 indicates all
|
||||
/// bytes were processed.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed).
|
||||
/// 0 indicates all bytes were processed.
|
||||
/// \details Internally, Put() calls Put2().
|
||||
size_t Put(const byte *inString, size_t length, bool blocking=true)
|
||||
{return Put2(inString, length, 0, blocking);}
|
||||
|
|
@ -1634,18 +1634,26 @@ public:
|
|||
/// \param value the 16-bit value to be processed
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \param blocking specifies whether the object should block when processing input
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed). 0 indicates all
|
||||
/// bytes were processed.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed).
|
||||
/// 0 indicates all bytes were processed.
|
||||
size_t PutWord16(word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
|
||||
|
||||
/// Input a 32-bit word for processing.
|
||||
/// \param value the 32-bit value to be processed.
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \param blocking specifies whether the object should block when processing input.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed). 0 indicates all
|
||||
/// bytes were processed.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed).
|
||||
/// 0 indicates all bytes were processed.
|
||||
size_t PutWord32(word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
|
||||
|
||||
/// Input a 64-bit word for processing.
|
||||
/// \param value the 64-bit value to be processed.
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \param blocking specifies whether the object should block when processing input.
|
||||
/// \return the number of bytes that remain in the block (i.e., bytes not processed).
|
||||
/// 0 indicates all bytes were processed.
|
||||
size_t PutWord64(word64 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
|
||||
|
||||
/// \brief Request space which can be written into by the caller
|
||||
/// \param size the requested size of the buffer
|
||||
/// \return byte pointer to the space to input data
|
||||
|
|
@ -1856,7 +1864,7 @@ public:
|
|||
/// \param peekMax the number of bytes to Peek
|
||||
/// \return the number of bytes read during the call.
|
||||
/// \details Peek does not remove bytes from the object. Use the return value of
|
||||
/// Get() to detect short reads.
|
||||
/// Peek() to detect short reads.
|
||||
virtual size_t Peek(byte *outString, size_t peekMax) const;
|
||||
|
||||
/// \brief Retrieve a 16-bit word
|
||||
|
|
@ -1870,15 +1878,23 @@ public:
|
|||
/// \param value the 32-bit value to be retrieved
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \return the number of bytes consumed during the call.
|
||||
/// \details Use the return value of GetWord16() to detect short reads.
|
||||
/// \details Use the return value of GetWord32() to detect short reads.
|
||||
size_t GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER);
|
||||
|
||||
/// \brief Retrieve a 64-bit word
|
||||
/// \param value the 64-bit value to be retrieved
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \return the number of bytes consumed during the call.
|
||||
/// \details Use the return value of GetWord64() to detect short reads.
|
||||
/// \since Crypto++ 8.3
|
||||
size_t GetWord64(word64 &value, ByteOrder order=BIG_ENDIAN_ORDER);
|
||||
|
||||
/// \brief Peek a 16-bit word
|
||||
/// \param value the 16-bit value to be retrieved
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \return the number of bytes consumed during the call.
|
||||
/// \details Peek does not consume bytes in the stream. Use the return value
|
||||
/// of GetWord16() to detect short reads.
|
||||
/// of PeekWord16() to detect short reads.
|
||||
size_t PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const;
|
||||
|
||||
/// \brief Peek a 32-bit word
|
||||
|
|
@ -1886,9 +1902,18 @@ public:
|
|||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \return the number of bytes consumed during the call.
|
||||
/// \details Peek does not consume bytes in the stream. Use the return value
|
||||
/// of GetWord16() to detect short reads.
|
||||
/// of PeekWord32() to detect short reads.
|
||||
size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const;
|
||||
|
||||
/// \brief Peek a 64-bit word
|
||||
/// \param value the 64-bit value to be retrieved
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \return the number of bytes consumed during the call.
|
||||
/// \details Peek does not consume bytes in the stream. Use the return value
|
||||
/// of PeekWord64() to detect short reads.
|
||||
/// \since Crypto++ 8.3
|
||||
size_t PeekWord64(word64 &value, ByteOrder order=BIG_ENDIAN_ORDER) const;
|
||||
|
||||
/// move transferMax bytes of the buffered output to target as input
|
||||
|
||||
/// \brief Transfer bytes from this object to another BufferedTransformation
|
||||
|
|
@ -2144,6 +2169,15 @@ public:
|
|||
/// number of bytes that were not processed.
|
||||
size_t ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
|
||||
|
||||
/// \brief Input a 64-bit word for processing on a channel.
|
||||
/// \param channel the channel to process the data.
|
||||
/// \param value the 64-bit value to be processed.
|
||||
/// \param order the ByteOrder of the value to be processed.
|
||||
/// \param blocking specifies whether the object should block when processing input.
|
||||
/// \return 0 indicates all bytes were processed during the call. Non-0 indicates the
|
||||
/// number of bytes that were not processed.
|
||||
size_t ChannelPutWord64(const std::string &channel, word64 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
|
||||
|
||||
/// \brief Signal the end of a message
|
||||
/// \param channel the channel to process the data.
|
||||
/// \param propagation the number of attached transformations the ChannelMessageEnd() signal should be passed
|
||||
|
|
|
|||
Loading…
Reference in New Issue