diff options
Diffstat (limited to 'crypto_scrypt-hexconvert.c')
-rw-r--r-- | crypto_scrypt-hexconvert.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto_scrypt-hexconvert.c b/crypto_scrypt-hexconvert.c new file mode 100644 index 0000000..ececbd9 --- /dev/null +++ b/crypto_scrypt-hexconvert.c @@ -0,0 +1,30 @@ +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <stdint.h> + +int libscrypt_hexconvert(uint8_t *buf, size_t s, char *outbuf, size_t obs) +{ + + size_t i; + int len = 0; + + if (!buf || s < 1 || obs < (s * 2 + 1)) + return 0; + + memset(outbuf, 0, obs); + + + for(i=0; i<=(s-1); i++) + { + /* snprintf(outbuf, s,"%s...", outbuf....) has undefined results + * and can't be used. Using offests like this makes snprintf + * nontrivial. we therefore have use inescure sprintf() and + * lengths checked elsewhere (start of function) */ + /*@ -bufferoverflowhigh @*/ + len += sprintf(outbuf+len, "%02x", (unsigned int) buf[i]); + } + + return 1; +} + |