Skip to content

Commit

Permalink
fix CTR mode not allowing NULL as IV
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai committed Aug 5, 2010
1 parent fcad9e9 commit e32bbdb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion c5/cryptlib.cpp
Expand Up @@ -87,7 +87,7 @@ void SimpleKeyingInterface::ThrowIfResynchronizable()

void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv)
{
if (!iv && !(IVRequirement() == INTERNALLY_GENERATED_IV || IVRequirement() == UNIQUE_IV || !IsResynchronizable()))
if (!iv && IVRequirement() == UNPREDICTABLE_RANDOM_IV)
throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV");
}

Expand Down
4 changes: 3 additions & 1 deletion c5/modes.cpp
Expand Up @@ -56,7 +56,8 @@ void CFB_ModePolicy::TransformRegister()

void CFB_ModePolicy::CipherResynchronize(const byte *iv, size_t length)
{
memcpy_s(m_register, m_register.size(), iv, BlockSize());
assert(length == BlockSize());
CopyOrZero(m_register, iv, length);
TransformRegister();
}

Expand Down Expand Up @@ -85,6 +86,7 @@ void OFB_ModePolicy::WriteKeystream(byte *keystreamBuffer, size_t iterationCount

void OFB_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
{
assert(length == BlockSize());
CopyOrZero(m_register, iv, length);
}

Expand Down

0 comments on commit e32bbdb

Please sign in to comment.