out should be appropriately sized */
| 212 | |
| 213 | /* out should be appropriately sized */ |
| 214 | void fromhex(uint8_t *out, const uint8_t *in, size_t len) |
| 215 | { |
| 216 | const uint8_t *end = in + len; |
| 217 | while (in != end) { |
| 218 | uint8_t i0 = tolower(*(in++)); |
| 219 | uint8_t i1 = tolower(*(in++)); |
| 220 | i0 -= isdigit(i0) ? '0' : ('a' - 0xa); |
| 221 | i1 -= isdigit(i1) ? '0' : ('a' - 0xa); |
| 222 | *(out++) = (i0 << 4) | i1; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | /* TODO: add all types supported */ |