diff --git a/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S b/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S index 8e29a506..f2415685 100644 --- a/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S +++ b/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S @@ -33,19 +33,20 @@ mov $0,%rax mov %r9,%rcx rep stosb sub %r9,%rdi +movq $0,472(%rsp) jmp ._start .text .p2align 5 -.globl crypto_stream_salsa20_xor -.globl _crypto_stream_salsa20_xor +.globl crypto_stream_salsa20_xor_ic +.globl _crypto_stream_salsa20_xor_ic #ifdef __ELF__ -.type crypto_stream_salsa20_xor, @function -.type _crypto_stream_salsa20_xor, @function +.type crypto_stream_salsa20_xor_ic, @function +.type _crypto_stream_salsa20_xor_ic, @function #endif -crypto_stream_salsa20_xor: -_crypto_stream_salsa20_xor: +crypto_stream_salsa20_xor_ic: +_crypto_stream_salsa20_xor_ic: mov %rsp,%r11 and $31,%r11 @@ -60,9 +61,10 @@ movq %rbx,456(%rsp) movq %rbp,464(%rsp) mov %rdi,%rdi mov %rsi,%rsi +mov %r9,%r10 +movq %r8,472(%rsp) mov %rdx,%r9 mov %rcx,%rdx -mov %r8,%r10 cmp $0,%r9 jbe ._done @@ -75,17 +77,16 @@ movl %ecx,64(%rsp) movl %r8d,4+64(%rsp) movl %eax,8+64(%rsp) movl %r11d,12+64(%rsp) -mov $0,%rcx movl 24(%r10),%r8d movl 4(%r10),%eax movl 4(%rdx),%edx -movq %rcx,472(%rsp) +movq 472(%rsp),%rcx movl %ecx,80(%rsp) movl %r8d,4+80(%rsp) movl %eax,8+80(%rsp) movl %edx,12+80(%rsp) movl 12(%r10),%edx -mov $0,%rcx +shr $32,%rcx movl 28(%r10),%r8d movl 8(%r10),%eax movl %edx,96(%rsp) diff --git a/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c b/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c index 2b44c4a3..19cd79e7 100644 --- a/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +++ b/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c @@ -4,6 +4,8 @@ D. J. Bernstein Public domain. */ +#include + #include "api.h" #include "crypto_core_salsa20.h" #include "utils.h" @@ -16,10 +18,10 @@ static const unsigned char sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k' }; -int crypto_stream_xor( +int crypto_stream_salsa20_xor_ic( unsigned char *c, const unsigned char *m,unsigned long long mlen, - const unsigned char *n, + const unsigned char *n, uint64_t ic, const unsigned char *k ) { @@ -33,7 +35,10 @@ int crypto_stream_xor( for (i = 0;i < 32;++i) kcopy[i] = k[i]; for (i = 0;i < 8;++i) in[i] = n[i]; - for (i = 8;i < 16;++i) in[i] = 0; + for (i = 8;i < 16;++i) { + in[i] = (unsigned char) (ic & 0xff); + ic >>= 8; + } while (mlen >= 64) { crypto_core_salsa20(block,in,kcopy,sigma); diff --git a/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c b/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c index cd5aed50..3bc05801 100644 --- a/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c +++ b/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c @@ -9,3 +9,11 @@ size_t crypto_stream_salsa20_noncebytes(void) { return crypto_stream_salsa20_NONCEBYTES; } + +int +crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m, + unsigned long long mlen, const unsigned char *n, + const unsigned char *k) +{ + return crypto_stream_salsa20_xor_ic(c, m, mlen, n, 0U, k); +} diff --git a/src/libsodium/include/sodium/crypto_stream_salsa20.h b/src/libsodium/include/sodium/crypto_stream_salsa20.h index 4af870be..1c06512b 100644 --- a/src/libsodium/include/sodium/crypto_stream_salsa20.h +++ b/src/libsodium/include/sodium/crypto_stream_salsa20.h @@ -10,6 +10,7 @@ */ #include +#include #include "export.h" #ifdef __cplusplus @@ -36,6 +37,11 @@ int crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *k); +SODIUM_EXPORT +int crypto_stream_salsa20_xor_ic(unsigned char *c, const unsigned char *m, + unsigned long long mlen, + const unsigned char *n, uint64_t ic, + const unsigned char *k); #ifdef __cplusplus } #endif