Line 0
Link Here
|
|
|
1 |
--- cipher/salsa20.c.orig 2016-03-23 16:34:00 UTC |
2 |
+++ cipher/salsa20.c |
3 |
@@ -485,7 +485,8 @@ salsa20r12_encrypt_stream (void *context |
4 |
static const char* |
5 |
selftest (void) |
6 |
{ |
7 |
- SALSA20_context_t ctx; |
8 |
+ byte ctxbuf[sizeof(SALSA20_context_t) + 15]; |
9 |
+ SALSA20_context_t *ctx; |
10 |
byte scratch[8+1]; |
11 |
byte buf[256+64+4]; |
12 |
int i; |
13 |
@@ -502,32 +503,35 @@ selftest (void) |
14 |
static const byte ciphertext_1[] = |
15 |
{ 0xE3, 0xBE, 0x8F, 0xDD, 0x8B, 0xEC, 0xA2, 0xE3}; |
16 |
|
17 |
- salsa20_setkey (&ctx, key_1, sizeof key_1); |
18 |
- salsa20_setiv (&ctx, nonce_1, sizeof nonce_1); |
19 |
+ /* 16-byte alignment required for amd64 implementation. */ |
20 |
+ ctx = (SALSA20_context_t *)((uintptr_t)(ctxbuf + 15) & ~(uintptr_t)15); |
21 |
+ |
22 |
+ salsa20_setkey (ctx, key_1, sizeof key_1); |
23 |
+ salsa20_setiv (ctx, nonce_1, sizeof nonce_1); |
24 |
scratch[8] = 0; |
25 |
- salsa20_encrypt_stream (&ctx, scratch, plaintext_1, sizeof plaintext_1); |
26 |
+ salsa20_encrypt_stream (ctx, scratch, plaintext_1, sizeof plaintext_1); |
27 |
if (memcmp (scratch, ciphertext_1, sizeof ciphertext_1)) |
28 |
return "Salsa20 encryption test 1 failed."; |
29 |
if (scratch[8]) |
30 |
return "Salsa20 wrote too much."; |
31 |
- salsa20_setkey( &ctx, key_1, sizeof(key_1)); |
32 |
- salsa20_setiv (&ctx, nonce_1, sizeof nonce_1); |
33 |
- salsa20_encrypt_stream (&ctx, scratch, scratch, sizeof plaintext_1); |
34 |
+ salsa20_setkey( ctx, key_1, sizeof(key_1)); |
35 |
+ salsa20_setiv (ctx, nonce_1, sizeof nonce_1); |
36 |
+ salsa20_encrypt_stream (ctx, scratch, scratch, sizeof plaintext_1); |
37 |
if (memcmp (scratch, plaintext_1, sizeof plaintext_1)) |
38 |
return "Salsa20 decryption test 1 failed."; |
39 |
|
40 |
for (i = 0; i < sizeof buf; i++) |
41 |
buf[i] = i; |
42 |
- salsa20_setkey (&ctx, key_1, sizeof key_1); |
43 |
- salsa20_setiv (&ctx, nonce_1, sizeof nonce_1); |
44 |
+ salsa20_setkey (ctx, key_1, sizeof key_1); |
45 |
+ salsa20_setiv (ctx, nonce_1, sizeof nonce_1); |
46 |
/*encrypt*/ |
47 |
- salsa20_encrypt_stream (&ctx, buf, buf, sizeof buf); |
48 |
+ salsa20_encrypt_stream (ctx, buf, buf, sizeof buf); |
49 |
/*decrypt*/ |
50 |
- salsa20_setkey (&ctx, key_1, sizeof key_1); |
51 |
- salsa20_setiv (&ctx, nonce_1, sizeof nonce_1); |
52 |
- salsa20_encrypt_stream (&ctx, buf, buf, 1); |
53 |
- salsa20_encrypt_stream (&ctx, buf+1, buf+1, (sizeof buf)-1-1); |
54 |
- salsa20_encrypt_stream (&ctx, buf+(sizeof buf)-1, buf+(sizeof buf)-1, 1); |
55 |
+ salsa20_setkey (ctx, key_1, sizeof key_1); |
56 |
+ salsa20_setiv (ctx, nonce_1, sizeof nonce_1); |
57 |
+ salsa20_encrypt_stream (ctx, buf, buf, 1); |
58 |
+ salsa20_encrypt_stream (ctx, buf+1, buf+1, (sizeof buf)-1-1); |
59 |
+ salsa20_encrypt_stream (ctx, buf+(sizeof buf)-1, buf+(sizeof buf)-1, 1); |
60 |
for (i = 0; i < sizeof buf; i++) |
61 |
if (buf[i] != (byte)i) |
62 |
return "Salsa20 encryption test 2 failed."; |