#include #include #include #include #include #include int main() { using TestVector = std::tuple, std::vector>; std::cout << "OpenSSL" << std::endl; std::cout << std::endl; for (const auto& [key_data, plaintext] : std::initializer_list{ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF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11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}}, {{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}}, {{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, {{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, {{0x4f, 0x8a, 0xfc, 0x23, 0xa1, 0xda, 0xac, 0x52, 0x25, 0x10, 0x98, 0x2b, 0x41, 0xc9, 0x18, 0x60, 0x81, 0xb2, 0xa0, 0x05, 0x37, 0xe1, 0x93, 0xd8, 0x5d, 0x00, 0x40, 0x13, 0xce, 0x52, 0x0c, 0xc7, 0x7a, 0xeb, 0x3c, 0x78, 0x22, 0x66, 0x8c, 0x42, 0x5a, 0xdf, 0x7a, 0x9a, 0xf9, 0x77, 0xad, 0x0c, 0x38, 0x0f, 0x47, 0x12, 0x29, 0xdc, 0xc7, 0x34, 0x78, 0xd6, 0xa5, 0x60, 0xce, 0x3b, 0xc7, 0x30, 0xdf, 0x05, 0xe9, 0x75, 0xa6, 0xd0, 0x6d, 0x4e}, {0x63, 0x03, 0x8f, 0x81, 0xaf, 0xf4, 0x3d, 0x3e}}, {{0x4f, 0x8a, 0xfc, 0x23, 0xa1, 0xda, 0xac, 0x52, 0x25, 0x10, 0x98, 0x2b, 0x41, 0xc9, 0x18, 0x60, 0x81, 0xb2, 0xa0, 0x05, 0x37, 0xe1, 0x93, 0xd8, 0x5d, 0x00, 0x40, 0x13, 0xce, 0x52, 0x0c, 0xc7, 0x7a, 0xeb, 0x3c, 0x78, 0x22, 0x66, 0x8c, 0x42, 0x5a, 0xdf, 0x7a, 0x9a, 0xf9, 0x77, 0xad, 0x0c, 0x38, 0x0f, 0x47, 0x12, 0x29, 0xdc, 0xc7, 0x34, 0x78, 0xd6, 0xa5, 0x60, 0xce, 0x3b, 0xc7, 0x30, 0xdf, 0x05, 0xe9, 0x75, 0xa6, 0xd0, 0x6d, 0x4e, 0x9b, 0xe8, 0xca, 0x0e}, {0x63, 0x03, 0x8f, 0x81, 0xaf, 0xf4, 0x3d, 0x3e}}, }) { BF_KEY key; unsigned char ciphertext[8] = {}; BF_set_key(&key, key_data.size(), key_data.data()); BF_ecb_encrypt(plaintext.data(), ciphertext, &key, 1); std::cout << '[' << std::dec << key_data.size() << ']' << ' '; for (const auto key_byte : key_data) std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)key_byte; std::cout << ' '; for (const auto plaintext_byte : plaintext) std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)plaintext_byte; std::cout << ' '; for (const auto ciphertext_byte : ciphertext) std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)ciphertext_byte; std::cout << std::endl; } std::cout << "Nettle" << std::endl; std::cout << std::endl; for (const auto& [key_data, plaintext] : std::initializer_list{ {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}, {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}, {{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}}, {{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}}, {{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, {{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, {{0x4f, 0x8a, 0xfc, 0x23, 0xa1, 0xda, 0xac, 0x52, 0x25, 0x10, 0x98, 0x2b, 0x41, 0xc9, 0x18, 0x60, 0x81, 0xb2, 0xa0, 0x05, 0x37, 0xe1, 0x93, 0xd8, 0x5d, 0x00, 0x40, 0x13, 0xce, 0x52, 0x0c, 0xc7, 0x7a, 0xeb, 0x3c, 0x78, 0x22, 0x66, 0x8c, 0x42, 0x5a, 0xdf, 0x7a, 0x9a, 0xf9, 0x77, 0xad, 0x0c, 0x38, 0x0f, 0x47, 0x12, 0x29, 0xdc, 0xc7, 0x34, 0x78, 0xd6, 0xa5, 0x60, 0xce, 0x3b, 0xc7, 0x30, 0xdf, 0x05, 0xe9, 0x75, 0xa6, 0xd0, 0x6d, 0x4e}, {0x63, 0x03, 0x8f, 0x81, 0xaf, 0xf4, 0x3d, 0x3e}}, {{0x4f, 0x8a, 0xfc, 0x23, 0xa1, 0xda, 0xac, 0x52, 0x25, 0x10, 0x98, 0x2b, 0x41, 0xc9, 0x18, 0x60, 0x81, 0xb2, 0xa0, 0x05, 0x37, 0xe1, 0x93, 0xd8, 0x5d, 0x00, 0x40, 0x13, 0xce, 0x52, 0x0c, 0xc7, 0x7a, 0xeb, 0x3c, 0x78, 0x22, 0x66, 0x8c, 0x42, 0x5a, 0xdf, 0x7a, 0x9a, 0xf9, 0x77, 0xad, 0x0c, 0x38, 0x0f, 0x47, 0x12, 0x29, 0xdc, 0xc7, 0x34, 0x78, 0xd6, 0xa5, 0x60, 0xce, 0x3b, 0xc7, 0x30, 0xdf, 0x05, 0xe9, 0x75, 0xa6, 0xd0, 0x6d, 0x4e, 0x9b, 0xe8, 0xca, 0x0e}, {0x63, 0x03, 0x8f, 0x81, 0xaf, 0xf4, 0x3d, 0x3e}}, }) { blowfish_ctx ctx; unsigned char ciphertext[8] = {}; blowfish_set_key(&ctx, key_data.size(), key_data.data()); blowfish_encrypt(&ctx, plaintext.size(), ciphertext, plaintext.data()); std::cout << '[' << std::dec << key_data.size() << ']' << ' '; for (const auto key_byte : key_data) std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)key_byte; std::cout << ' '; for (const auto plaintext_byte : plaintext) std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)plaintext_byte; std::cout << ' '; for (const auto ciphertext_byte : ciphertext) std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)ciphertext_byte; std::cout << std::endl; } }