summaryrefslogtreecommitdiff
path: root/crypto_scrypt-hexconvert.c
blob: 3df12a0234221501d50f4297656cb44743f990c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>

/* The hexconvert function is only used to test reference vectors against
 * known answers. The contents of this file are therefore a component
 * to assist with test harnesses only
 */

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;
}