Skip to content

Commit 6babf40

Browse files
committed
Rename ChaCha20::Seek -> Seek64 to clarify multiple of 64
1 parent e37bcaa commit 6babf40

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

src/bench/chacha20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void CHACHA20(benchmark::Bench& bench, size_t buffersize)
1616
std::vector<uint8_t> key(32,0);
1717
ChaCha20 ctx(key.data(), key.size());
1818
ctx.SetIV(0);
19-
ctx.Seek(0);
19+
ctx.Seek64(0);
2020
std::vector<uint8_t> in(buffersize,0);
2121
std::vector<uint8_t> out(buffersize,0);
2222
bench.batch(in.size()).unit("byte").run([&] {

src/crypto/chacha20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void ChaCha20Aligned::SetIV(uint64_t iv)
6868
input[15] = iv >> 32;
6969
}
7070

71-
void ChaCha20Aligned::Seek(uint64_t pos)
71+
void ChaCha20Aligned::Seek64(uint64_t pos)
7272
{
7373
input[12] = pos;
7474
input[13] = pos >> 32;

src/crypto/chacha20.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ChaCha20Aligned
3030
void SetIV(uint64_t iv);
3131

3232
/** set the 64bit block counter (pos seeks to byte position 64*pos). */
33-
void Seek(uint64_t pos);
33+
void Seek64(uint64_t pos);
3434

3535
/** outputs the keystream of size <64*blocks> into <c> */
3636
void Keystream64(unsigned char* c, size_t blocks);
@@ -60,7 +60,7 @@ class ChaCha20
6060
void SetIV(uint64_t iv) { m_aligned.SetIV(iv); }
6161

6262
/** set the 64bit block counter (pos seeks to byte position 64*pos). */
63-
void Seek(uint64_t pos) { m_aligned.Seek(pos); }
63+
void Seek64(uint64_t pos) { m_aligned.Seek64(pos); }
6464

6565
/** outputs the keystream of size <bytes> into <c> */
6666
void Keystream(unsigned char* c, size_t bytes);

src/crypto/chacha_poly_aead.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool ChaCha20Poly1305AEAD::Crypt(uint64_t seqnr_payload, uint64_t seqnr_aad, int
6262
// block counter 0 for the poly1305 key
6363
// use lower 32bytes for the poly1305 key
6464
// (throws away 32 unused bytes (upper 32) from this ChaCha20 round)
65-
m_chacha_main.Seek(0);
65+
m_chacha_main.Seek64(0);
6666
m_chacha_main.Crypt(poly_key, poly_key, sizeof(poly_key));
6767

6868
// if decrypting, verify the tag prior to decryption
@@ -85,7 +85,7 @@ bool ChaCha20Poly1305AEAD::Crypt(uint64_t seqnr_payload, uint64_t seqnr_aad, int
8585
if (m_cached_aad_seqnr != seqnr_aad) {
8686
m_cached_aad_seqnr = seqnr_aad;
8787
m_chacha_header.SetIV(seqnr_aad);
88-
m_chacha_header.Seek(0);
88+
m_chacha_header.Seek64(0);
8989
m_chacha_header.Keystream(m_aad_keystream_buffer, CHACHA20_ROUND_OUTPUT);
9090
}
9191
// crypt the AAD (3 bytes message length) with given position in AAD cipher instance keystream
@@ -94,7 +94,7 @@ bool ChaCha20Poly1305AEAD::Crypt(uint64_t seqnr_payload, uint64_t seqnr_aad, int
9494
dest[2] = src[2] ^ m_aad_keystream_buffer[aad_pos + 2];
9595

9696
// Set the playload ChaCha instance block counter to 1 and crypt the payload
97-
m_chacha_main.Seek(1);
97+
m_chacha_main.Seek64(1);
9898
m_chacha_main.Crypt(src + CHACHA20_POLY1305_AEAD_AAD_LEN, dest + CHACHA20_POLY1305_AEAD_AAD_LEN, src_len - CHACHA20_POLY1305_AEAD_AAD_LEN);
9999

100100
// If encrypting, calculate and append tag
@@ -117,7 +117,7 @@ bool ChaCha20Poly1305AEAD::GetLength(uint32_t* len24_out, uint64_t seqnr_aad, in
117117
// we need to calculate the 64 keystream bytes since we reached a new aad sequence number
118118
m_cached_aad_seqnr = seqnr_aad;
119119
m_chacha_header.SetIV(seqnr_aad); // use LE for the nonce
120-
m_chacha_header.Seek(0); // block counter 0
120+
m_chacha_header.Seek64(0); // block counter 0
121121
m_chacha_header.Keystream(m_aad_keystream_buffer, CHACHA20_ROUND_OUTPUT); // write keystream to the cache
122122
}
123123

src/test/crypto_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void TestChaCha20(const std::string &hex_message, const std::string &hexk
136136
std::vector<unsigned char> m = ParseHex(hex_message);
137137
ChaCha20 rng(key.data(), key.size());
138138
rng.SetIV(nonce);
139-
rng.Seek(seek);
139+
rng.Seek64(seek);
140140
std::vector<unsigned char> out = ParseHex(hexout);
141141
std::vector<unsigned char> outres;
142142
outres.resize(out.size());
@@ -152,7 +152,7 @@ static void TestChaCha20(const std::string &hex_message, const std::string &hexk
152152
if (!hex_message.empty()) {
153153
// Manually XOR with the keystream and compare the output
154154
rng.SetIV(nonce);
155-
rng.Seek(seek);
155+
rng.Seek64(seek);
156156
std::vector<unsigned char> only_keystream(outres.size());
157157
rng.Keystream(only_keystream.data(), only_keystream.size());
158158
for (size_t i = 0; i != m.size(); i++) {
@@ -631,7 +631,7 @@ static void TestChaCha20Poly1305AEAD(bool must_succeed, unsigned int expected_aa
631631

632632
// manually construct the AAD keystream
633633
cmp_ctx.SetIV(seqnr_aad);
634-
cmp_ctx.Seek(0);
634+
cmp_ctx.Seek64(0);
635635
cmp_ctx.Keystream(cmp_ctx_buffer.data(), 64);
636636
BOOST_CHECK(memcmp(expected_aad_keystream.data(), cmp_ctx_buffer.data(), expected_aad_keystream.size()) == 0);
637637
// crypt the 3 length bytes and compare the length
@@ -659,7 +659,7 @@ static void TestChaCha20Poly1305AEAD(bool must_succeed, unsigned int expected_aa
659659
}
660660
// set nonce and block counter, output the keystream
661661
cmp_ctx.SetIV(seqnr_aad);
662-
cmp_ctx.Seek(0);
662+
cmp_ctx.Seek64(0);
663663
cmp_ctx.Keystream(cmp_ctx_buffer.data(), 64);
664664

665665
// crypt the 3 length bytes and compare the length

src/test/fuzz/crypto_chacha20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ FUZZ_TARGET(crypto_chacha20)
3030
chacha20.SetIV(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
3131
},
3232
[&] {
33-
chacha20.Seek(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
33+
chacha20.Seek64(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
3434
},
3535
[&] {
3636
std::vector<uint8_t> output(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));

src/test/fuzz/crypto_diff_fuzz_chacha20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ FUZZ_TARGET(crypto_diff_fuzz_chacha20)
304304
},
305305
[&] {
306306
uint64_t counter = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
307-
chacha20.Seek(counter);
307+
chacha20.Seek64(counter);
308308
ctx.input[12] = counter;
309309
ctx.input[13] = counter >> 32;
310310
},

0 commit comments

Comments
 (0)