Move hex_table definition outside the function
Fix static allocation in BER encoding
Fix thread safety issue in Bas64 encoding

This makes the static table not as clear as it was before, but the
static initialization prevents a race condition here over the
initialization over this structure.

If we would want to keep the old algorithm, it would be needed to add an
explicit pack initialization phase so we can solve this in a thread safe
way. Since this is a much more invasive change, I opted for this
solution.