Skip to content

Commit 19a5520

Browse files
committed
Allow base16_encode() to re-use the input buffer as output
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 72b353f commit 19a5520

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/misc/base16/base16_encode.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ int base16_encode(const unsigned char *in, unsigned long inlen,
5252
alphabet = alphabets[1];
5353
}
5454

55-
for (i = 0; i < x; i += 2) {
56-
out[i] = alphabet[(in[i/2] >> 4) & 0x0f];
57-
out[i+1] = alphabet[in[i/2] & 0x0f];
55+
for (i = x; i > 0; i -= 2) {
56+
out[i-2] = alphabet[(in[(i-1)/2] >> 4) & 0x0f];
57+
out[i-1] = alphabet[in[(i-1)/2] & 0x0f];
5858
}
59+
5960
out[x] = '\0';
6061

6162
return CRYPT_OK;

0 commit comments

Comments
 (0)