Use unsigned char and tmp ptrs.  Pointer dest was getting modified.