Fabcoin Core  0.16.2
P2P Digital Currency
crypto_scrypt-hexconvert.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <stdint.h>
5 
6 /* The hexconvert function is only used to test reference vectors against
7  * known answers. The contents of this file are therefore a component
8  * to assist with test harnesses only
9  */
10 
11 int libscrypt_hexconvert(uint8_t *buf, size_t s, char *outbuf, size_t obs)
12 {
13 
14  size_t i;
15  int len = 0;
16 
17  if (!buf || s < 1 || obs < (s * 2 + 1))
18  return 0;
19 
20  memset(outbuf, 0, obs);
21 
22 
23  for(i=0; i<=(s-1); i++)
24  {
25  /* snprintf(outbuf, s,"%s...", outbuf....) has undefined results
26  * and can't be used. Using offests like this makes snprintf
27  * nontrivial. we therefore have use inescure sprintf() and
28  * lengths checked elsewhere (start of function) */
29  /*@ -bufferoverflowhigh @*/
30  len += sprintf(outbuf+len, "%02x", (unsigned int) buf[i]);
31  }
32 
33  return 1;
34 }
35 
int libscrypt_hexconvert(uint8_t *buf, size_t s, char *outbuf, size_t obs)