| 63 | } |
| 64 | |
| 65 | unsigned readHexKey(ThrowStatusWrapper* status, const char* hex, unsigned char* key, unsigned bufSize) |
| 66 | { |
| 67 | unsigned char* k = key; |
| 68 | const char* const end = hex + strlen(hex) - 1; |
| 69 | for (const char* s = hex; s < end; s += 2) |
| 70 | { |
| 71 | if (k - key >= bufSize) |
| 72 | break; |
| 73 | |
| 74 | // FF |
| 75 | char ss[3]; |
| 76 | ss[0] = s[0]; |
| 77 | ss[1] = s[1]; |
| 78 | ss[2] = 0; |
| 79 | unsigned c = strtoul(ss, NULL, 16); |
| 80 | if (c > 255) |
| 81 | error(status, "Key format error"); |
| 82 | *k++ = static_cast<unsigned char>(c); |
| 83 | } |
| 84 | return k - key; |
| 85 | } |
| 86 | |
| 87 | void PseudoRandom::init(ThrowStatusWrapper* status) |
| 88 | { |