> On Oct 7, 2016, at 12:18 PM, Ted Unangst <[email protected]> wrote:
> 
> Kinichiro Inoguchi wrote:
>> I think this 16 bytes string assignment has boundary issue.
>> 
>>    static const char sigma[16] = "expand 32-byte k";
>> 
>> I found this when I tried to build libressl-portable with MSVC on Windows.
> 
> another broken compiler? the above line is perfectly valid C.
> 

Technically, that's a 17-byte string being assigned to a 16-byte character 
array, including the NULL. I believe there is a way to get GCC to warn about 
this as well.

This is a simpler change:

diff --git a/src/lib/libc/crypt/chacha_private.h 
b/src/lib/libc/crypt/chacha_private.h
index b720d93..a08509c 100644
--- a/src/lib/libc/crypt/chacha_private.h
+++ b/src/lib/libc/crypt/chacha_private.h
@@ -48,8 +48,8 @@ typedef struct
   a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
   c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);

-static const char sigma[16] = "expand 32-byte k";
-static const char tau[16] = "expand 16-byte k";
+static const char sigma[] = "expand 32-byte k";
+static const char tau[] = "expand 16-byte k";

 static void
 chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)

Reply via email to