| 22 | constexpr size_t SignatureSize = 8; |
| 23 | |
| 24 | SHA1Context CodecInitKey(const char *pszPassword) |
| 25 | { |
| 26 | uint32_t pw[BlockSize]; // Repeat password until 64 char long |
| 27 | std::size_t j = 0; |
| 28 | for (uint32_t &value : pw) { |
| 29 | if (pszPassword[j] == '\0') |
| 30 | j = 0; |
| 31 | value = LoadLE32(&pszPassword[j]); |
| 32 | j += sizeof(uint32_t); |
| 33 | } |
| 34 | |
| 35 | uint32_t digest[SHA1HashSize]; |
| 36 | { |
| 37 | SHA1Context context; |
| 38 | SHA1Calculate(context, pw); |
| 39 | SHA1Result(context, digest); |
| 40 | } |
| 41 | |
| 42 | uint32_t key[BlockSize] { |
| 43 | 2908958655, 4146550480, 658981742, 1113311088, 3927878744, 679301322, 1760465731, 3305370375, |
| 44 | 2269115995, 3928541685, 580724401, 2607446661, 2233092279, 2416822349, 4106933702, 3046442503 |
| 45 | }; |
| 46 | |
| 47 | for (unsigned i = 0; i < BlockSize; ++i) { |
| 48 | key[i] ^= digest[(i + 3) % SHA1HashSize]; |
| 49 | } |
| 50 | |
| 51 | SHA1Context context; |
| 52 | SHA1Calculate(context, key); |
| 53 | return context; |
| 54 | } |
| 55 | |
| 56 | CodecSignature GetCodecSignature(byte *src) |
| 57 | { |
no test coverage detected