Add crypto_stream_salsa20_xor_ic() to set the initial counter value.

This commit is contained in:
Frank Denis
2014-06-24 22:16:55 -07:00
parent e352e775e8
commit f08666b0c6
4 changed files with 33 additions and 13 deletions
@@ -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)
@@ -4,6 +4,8 @@ D. J. Bernstein
Public domain.
*/
#include <stdint.h>
#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);
@@ -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);
}
@@ -10,6 +10,7 @@
*/
#include <stddef.h>
#include <stdint.h>
#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