|
| 1 | +// Non-cryptography snippets. Nothing in this file should be flagged by the query. |
| 2 | + |
| 3 | +typedef unsigned char uint8_t; |
| 4 | +typedef unsigned int uint32_t; |
| 5 | +typedef unsigned long size_t; |
| 6 | + |
| 7 | +// a very cut down stub for `std::cout` |
| 8 | +namespace std |
| 9 | +{ |
| 10 | + template<class charT> struct char_traits; |
| 11 | + |
| 12 | + template <class charT, class traits = char_traits<charT> > |
| 13 | + class basic_ostream { |
| 14 | + public: |
| 15 | + typedef charT char_type; |
| 16 | + }; |
| 17 | + template<class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*); |
| 18 | + |
| 19 | + typedef basic_ostream<char> ostream; |
| 20 | + |
| 21 | + extern ostream cout; |
| 22 | +} |
| 23 | + |
| 24 | +// --- |
| 25 | + |
| 26 | +uint32_t lookup[256]; |
| 27 | + |
| 28 | +uint8_t computeCRC32(const uint8_t *data, size_t dataLen) { |
| 29 | + // This function has "RC3" in its name, but is not an implementation of the (broken) RC3 encryption algorithm. |
| 30 | + uint32_t result = 0xFFFFFFFF; |
| 31 | + |
| 32 | + for (size_t i = 0; i < dataLen; i++) { |
| 33 | + result = (result >> 8) + lookup[(result ^ data[i]) & 0xFF]; |
| 34 | + result = (result >> 8) + lookup[(result ^ data[i]) & 0xFF]; // artificial extra compute |
| 35 | + result = (result >> 8) + lookup[(result ^ data[i]) & 0xFF]; // artificial extra compute |
| 36 | + result = (result >> 8) + lookup[(result ^ data[i]) & 0xFF]; // artificial extra compute |
| 37 | + } |
| 38 | + |
| 39 | + return result ^ 0xFFFFFFFF; |
| 40 | +} |
| 41 | + |
| 42 | +void convert_image_universal(uint32_t *img, int width, int height) { |
| 43 | + // This function has "rsa" in its name, but is nothing to do with the RSA encryption algorithm. |
| 44 | + uint32_t *pixel_ptr = img; |
| 45 | + uint32_t num_pixels = width * height; |
| 46 | + |
| 47 | + // convert pixels RGBA -> ARGB (with probably unhelpful loop unrolling) |
| 48 | + while (num_pixels >= 4) { |
| 49 | + pixel_ptr[0] = (pixel_ptr[0] >> 8) ^ (pixel_ptr[0] << 24); |
| 50 | + pixel_ptr[1] = (pixel_ptr[1] >> 8) ^ (pixel_ptr[1] << 24); |
| 51 | + pixel_ptr[2] = (pixel_ptr[2] >> 8) ^ (pixel_ptr[2] << 24); |
| 52 | + pixel_ptr[3] = (pixel_ptr[3] >> 8) ^ (pixel_ptr[3] << 24); |
| 53 | + num_pixels -= 4; |
| 54 | + } |
| 55 | + if (num_pixels >= 2) { |
| 56 | + pixel_ptr[0] = (pixel_ptr[0] >> 8) ^ (pixel_ptr[0] << 24); |
| 57 | + pixel_ptr[1] = (pixel_ptr[1] >> 8) ^ (pixel_ptr[1] << 24); |
| 58 | + num_pixels -= 2; |
| 59 | + } |
| 60 | + if (num_pixels >= 1) { |
| 61 | + pixel_ptr[2] = (pixel_ptr[2] >> 8) ^ (pixel_ptr[2] << 24); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +const char* yes_no_setting() { return "no"; } |
| 66 | + |
| 67 | +void output_encrypt_decrypt_algorithms() { |
| 68 | + // This function has "encrypt" and "decrypt" in its name, but no encryption is done. |
| 69 | + // This function uses `<<` heavily, but not as an integer shift left. |
| 70 | + const char *indent = " "; |
| 71 | + |
| 72 | + std::cout << "Supported algorithms:\n"; |
| 73 | + std::cout << indent << "DES (" << yes_no_setting() << ")\n"; |
| 74 | + std::cout << indent << "3DES (" << yes_no_setting() << ")\n"; |
| 75 | + std::cout << indent << "AES (" << yes_no_setting() << ")\n"; |
| 76 | + std::cout << indent << "RSA (" << yes_no_setting() << ")\n"; |
| 77 | + std::cout << indent << "Blowfish (" << yes_no_setting() << ")\n"; |
| 78 | + std::cout << indent << "Twofish (" << yes_no_setting() << ")\n"; |
| 79 | + std::cout << indent << "Chacha (" << yes_no_setting() << ")\n"; |
| 80 | +} |
| 81 | + |
| 82 | +// this macro expands to some compute operations that look a bit like cryptography |
| 83 | +#define COMPUTE(v) \ |
| 84 | + v[0] ^= v[1] ^ v[2] ^ v[3] ^ v[4]; \ |
| 85 | + v[1] ^= v[2] ^ v[3] ^ v[4] ^ v[5]; \ |
| 86 | + v[2] ^= v[3] ^ v[4] ^ v[5] ^ v[6]; \ |
| 87 | + v[3] ^= v[4] ^ v[5] ^ v[6] ^ v[7]; |
| 88 | + |
| 89 | +void wideStringCharsAt(int *v) { |
| 90 | + // This function has "des" and "rsa" in the name. |
| 91 | + COMPUTE(v) |
| 92 | +} |
| 93 | + |
| 94 | +void bitcastVariable(int *v) { |
| 95 | + // This function has "aria" and "cast" in the name. |
| 96 | + COMPUTE(v) |
| 97 | +} |
| 98 | + |
| 99 | +void dividesVariance(int *v) { |
| 100 | + // This function has "des" and "aria" in the name. |
| 101 | + COMPUTE(v) |
| 102 | +} |
| 103 | + |
| 104 | +void broadcastNodes(int *v) { |
| 105 | + // This function has "cast" and "des" in the name. |
| 106 | + COMPUTE(v) |
| 107 | +} |
0 commit comments