Skip to content

Comments

modes: starting to replace raw pointer arithmetic with std::span view.#5265

Open
devnexen wants to merge 1 commit intomasterfrom
symkey_upd
Open

modes: starting to replace raw pointer arithmetic with std::span view.#5265
devnexen wants to merge 1 commit intomasterfrom
symkey_upd

Conversation

@devnexen
Copy link
Collaborator

No description provided.

@coveralls
Copy link

Coverage Status

coverage: 90.071% (-0.004%) from 90.075%
when pulling c2d8f4c on symkey_upd
into 35bfb4c on master.

Copy link
Collaborator

@reneme reneme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general suggestions. Note that this clashes with #4880 which has been open for a while. Perhaps let's revisit this once 3.11.0 is out the door, @randombit?

Comment on lines 181 to 192
const secure_vector<uint8_t>& ad = ad_buf();
BOTAN_ARG_CHECK(ad.size() % CCM_BS == 0, "AD is block size multiple");

const BlockCipher& E = cipher();

secure_vector<uint8_t> T(CCM_BS);
E.encrypt(format_b0(sz), T);

for(size_t i = 0; i != ad.size(); i += CCM_BS) {
xor_buf(T.data(), &ad[i], CCM_BS);
xor_buf(std::span{T}.first(CCM_BS), std::span(&ad[i], CCM_BS));
E.encrypt(T);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: This could be simplified even further, along those lines:

Suggested change
}
BufferSlicer ad(ad_buf());
BOTAN_ARG_CHECK(ad.remaining() % CCM_BS == 0, "AD is block size multiple");
const BlockCipher& E = cipher();
secure_vector<uint8_t> T(CCM_BS);
E.encrypt(format_b0(sz), T);
while(!ad.empty()) {
xor_buf(T, ad.take<CCM_BS>());
E.encrypt(T);
}
BOTAN_DEBUG_ASSERT(ad.empty());

... no need for the .first for T because T is allocated with exactly CCM_BS bytes anyway. Also, you might have to include stl_util.h for the BufferSlicer.

Comment on lines +113 to 115
copy_mem(std::span{out}.first(k1.length()), k1.bits_of());
xor_buf(std::span{out}.first(k2.length()), k2.bits_of());
return OctetString(out);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're on it:

Suggested change
copy_mem(std::span{out}.first(k1.length()), k1.bits_of());
xor_buf(std::span{out}.first(k2.length()), k2.bits_of());
return OctetString(out);
copy_mem(std::span{out}.first(k1.length()), k1.bits_of());
xor_buf(std::span{out}.first(k2.length()), k2.bits_of());
return OctetString(std::move(out));

Comment on lines 234 to 245
const secure_vector<uint8_t>& ad = ad_buf();
BOTAN_ARG_CHECK(ad.size() % CCM_BS == 0, "AD is block size multiple");

const BlockCipher& E = cipher();

secure_vector<uint8_t> T(CCM_BS);
E.encrypt(format_b0(sz - tag_size()), T);

for(size_t i = 0; i != ad.size(); i += CCM_BS) {
xor_buf(T.data(), &ad[i], CCM_BS);
xor_buf(std::span{T}.first(CCM_BS), std::span(&ad[i], CCM_BS));
E.encrypt(T);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants