Browse Source

arc4: Add unit test

master
Daniel Scharrer 1 year ago
parent
commit
cd0f3c78f1
  1. 1
      CMakeLists.txt
  2. 46
      src/crypto/arc4.cpp
  3. 1
      src/crypto/arc4.hpp

1
CMakeLists.txt

@ -466,6 +466,7 @@ set(INNOEXTRACT_SOURCES
set(UNITTEST_SOURCES
src/crypto/adler32.cpp
src/crypto/arc4.cpp if INNOEXTRACT_HAVE_ARC4
src/util/test.hpp
src/util/test.cpp

46
src/crypto/arc4.cpp

@ -23,6 +23,7 @@
#include <algorithm>
#include "util/endian.hpp"
#include "util/test.hpp"
namespace crypto {
@ -68,4 +69,49 @@ void arc4::crypt(const char * in, char * out, size_t length) {
}
INNOEXTRACT_TEST(arc4,
const boost::uint8_t key[] = {
0x7f, 0xe5, 0x54, 0xd3, 0x47, 0x1e, 0xc7, 0xba, 0xb3, 0x37,
0x4f, 0xfd, 0x46, 0xb3, 0x88, 0x85, 0x12, 0x2b, 0x13, 0x14
};
const boost::uint8_t ciphertext[] = {
0x06, 0x58, 0x8c, 0x39, 0xf8, 0xc7, 0xf3, 0xbd, 0x17, 0x74, 0x7c, 0x84, 0xd1, 0xaf, 0x6c, 0xcf,
0x51, 0x98, 0x8a, 0x32, 0xe5, 0x25, 0x4a, 0xae, 0x04, 0xda, 0x18, 0xa7, 0x02, 0xd7, 0xe5, 0x34,
0x0a, 0x34, 0x3a, 0x7c, 0xc1, 0x9c, 0x9c, 0xb4, 0x07, 0xf6, 0x52, 0x31, 0x49, 0x21, 0x7f, 0xc2,
0x9a, 0x18, 0x25, 0xa1, 0x86, 0x37, 0x9c, 0x47, 0x8b, 0x61, 0x72, 0x9c, 0x93, 0x8a, 0x72, 0xbd,
0x99, 0xc9, 0xc4, 0x5f, 0x44, 0x28, 0xcf, 0x28, 0xe6, 0x9a, 0x0b, 0x2d, 0xad, 0x33, 0xf1, 0x8c,
0x3b, 0x51, 0xa6, 0x72, 0x9c, 0x0a, 0x97, 0x73, 0xe6, 0x6d, 0xd1, 0xb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, 0x6d, 0x5b, 0xdb, 0x7a, 0xcf, 0x43, 0x19, 0x68, 0x7f, 0xdd, 0xb0, 0x15, 0x42,
0x50, 0xb3, 0x04, 0xc4, 0x6c, 0x11, 0x95, 0xed, 0xe8, 0x1c, 0xb6, 0xcd, 0x23, 0x3d, 0x5a, 0x0f
};
arc4 cipher;
cipher.init(reinterpret_cast<const char *>(key), sizeof(key));
char buffer0[sizeof(ciphertext)];
cipher.crypt(testdata, buffer0, sizeof(ciphertext));
test_equals("crypt", buffer0, ciphertext, sizeof(ciphertext));
cipher.init(reinterpret_cast<const char *>(key), sizeof(key));
cipher.crypt(testdata, buffer0, 3);
cipher.discard(129);
char buffer1[sizeof(ciphertext) - 132];
cipher.crypt(testdata + 132, buffer1, sizeof(ciphertext) - 132);
test_equals("discard", buffer1, ciphertext + 132, sizeof(ciphertext) - 132);
)
} // namespace crypto

1
src/crypto/arc4.hpp

@ -59,4 +59,3 @@ private:
#endif // INNOEXTRACT_HAVE_ARC4
#endif // INNOEXTRACT_CRYPTO_ARC4_HPP

Loading…
Cancel
Save