According to Is u_char a standard?, u_char is equivalent to uint8_t (C99), not unsigned char. Hence if you have an array of unsigned char that you receive from PHP, you will have to copy the chars into a new array of uint8_t (u_char), call your lib's C function, and if it mods the data (since it takes a u_char* not a const uchar*) you have to copy the result into the original array so PHP sees the change. If PHP uses immutable strings, you will have to return the string instead.
SWIG can help with some of the above tasks (like via %inline and %extend; I don't think you need type maps).
If u_char really is an unsigned char, and PHP is giving you a char*, then the principle is the same, but you don't need the copy parts, because the size type is the same as char*. You could use %inline:
%inline %{
int c_library_function(char* phpString, size_t stringSize) {
return c_library_function((u_char*) phpString, stringSize);
}
%}
If you don't want to have to do this for every function that expects u_char*, I think your only option is a typemap entry in the .i file, such as
%array_class(unsigned char, char);
or
%apply char* {unsigned char*};
but I have never used these.