Skip to content

Commit df1e413

Browse files
author
Rafał Fabich
committed
Salsa20: Fix in the nonce and the counter handling to comply with the Salsa20 standard
1 parent d04dd31 commit df1e413

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/salsa20.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void cf_salsa20_init(cf_salsa20_ctx *ctx, const uint8_t *key, size_t nkey, const
139139
}
140140

141141
memset(ctx->nonce, 0, sizeof ctx->nonce);
142-
memcpy(ctx->nonce + 8, nonce, 8);
142+
memcpy(ctx->nonce, nonce, 8);
143143
ctx->nblock = 0;
144144
ctx->ncounter = 8;
145145
}
@@ -152,7 +152,7 @@ static void cf_salsa20_next_block(void *vctx, uint8_t *out)
152152
ctx->nonce,
153153
ctx->constant,
154154
out);
155-
incr_le(ctx->nonce, ctx->ncounter);
155+
incr_le(ctx->nonce + 8, ctx->ncounter);
156156
}
157157

158158
void cf_salsa20_cipher(cf_salsa20_ctx *ctx, const uint8_t *input, uint8_t *output, size_t bytes)

0 commit comments

Comments
 (0)