Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions barretenberg/cpp/src/barretenberg/crypto/aes128/aes128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

#include "aes128.hpp"

#include "barretenberg/crypto/hmac/hmac.hpp"
#include "memory.h"
#include <array>
#include <cstddef>
#include <cstdint>

#include <iostream>

namespace {

static constexpr uint8_t round_constants[11] = { 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
Expand Down Expand Up @@ -248,6 +247,7 @@ void aes128_encrypt_buffer_cbc(uint8_t* buffer, uint8_t* iv, const uint8_t* key,
memcpy((void*)(buffer + (i * 16)), (void*)block_state, 16);
memcpy((void*)iv, (void*)block_state, 16);
}
secure_erase_bytes(round_key, sizeof(round_key));
}

void aes128_decrypt_buffer_cbc(uint8_t* buffer, uint8_t* iv, const uint8_t* key, const size_t length)
Expand All @@ -266,6 +266,7 @@ void aes128_decrypt_buffer_cbc(uint8_t* buffer, uint8_t* iv, const uint8_t* key,
memcpy((void*)(buffer + (i * 16)), (void*)block_state, 16);
memcpy((void*)iv, (void*)next_iv, 16);
}
secure_erase_bytes(round_key, sizeof(round_key));
}

} // namespace bb::crypto
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ schnorr_signature schnorr_construct_signature(const std::string& message, const
// method is overloaded to utilise a suitable entropy source
// (see https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md)
//
// TODO(https://github.com/AztecProtocol/barretenberg/issues/895): securely erase `k`
Fr k = Fr::random_element();

typename G1::affine_element R(G1::one * k);
Expand All @@ -97,6 +96,7 @@ schnorr_signature schnorr_construct_signature(const std::string& message, const
// the conversion from e_raw results in a biased field element e
Fr e = Fr::serialize_from_buffer(&e_raw[0]);
Fr s = k - (private_key * e);
secure_erase_bytes(&k, sizeof(k));

// we serialize e_raw rather than e, so that no binary conversion needs to be
// performed during verification.
Expand Down
Loading