diff --git a/xls/modules/aes/aes_ctr_test.cc b/xls/modules/aes/aes_ctr_test.cc index bac06447b1..917ea64ad5 100644 --- a/xls/modules/aes/aes_ctr_test.cc +++ b/xls/modules/aes/aes_ctr_test.cc @@ -77,9 +77,9 @@ static void IvToBuffer(const InitVector& iv, static void PrintTraceMessages(const InterpreterEvents& events) { if (absl::GetFlag(FLAGS_print_traces) && !events.trace_msgs.empty()) { - std::cout << "Trace messages:" << std::endl; + std::cout << "Trace messages:" << '\n'; for (const auto& tm : events.trace_msgs) { - std::cout << " - " << tm << std::endl; + std::cout << " - " << tm << '\n'; } } } @@ -213,7 +213,7 @@ static absl::StatusOr RunSample(JitData* jit_data, if (reference_ciphertext.size() != xls_ciphertext.size()) { std::cout << "Error: XLS and reference ciphertexts differ in num blocks: " << "XLS: " << xls_ciphertext.size() - << ", ref: " << reference_ciphertext.size() << std::endl; + << ", ref: " << reference_ciphertext.size() << '\n'; return false; } @@ -222,7 +222,7 @@ static absl::StatusOr RunSample(JitData* jit_data, for (int32_t byte_idx = 0; byte_idx < kBlockBytes; byte_idx++) { if (reference_ciphertext[block_idx][byte_idx] != xls_ciphertext[block_idx][byte_idx]) { - std::cout << "Error comparing block " << block_idx << ":" << std::endl; + std::cout << "Error comparing block " << block_idx << ":" << '\n'; PrintFailure(reference_ciphertext[block_idx], xls_ciphertext[block_idx], byte_idx, /*ciphertext=*/true); return false; @@ -246,7 +246,7 @@ static absl::StatusOr RunSample(JitData* jit_data, if (sample_data.input_blocks.size() != xls_plaintext.size()) { std::cout << "Error: XLS decrypted plaintext and input plaintext differ " << "in num blocks XLS: " << xls_ciphertext.size() - << ", ref: " << sample_data.input_blocks.size() << std::endl; + << ", ref: " << sample_data.input_blocks.size() << '\n'; return false; } @@ -255,7 +255,7 @@ static absl::StatusOr RunSample(JitData* jit_data, for (int32_t byte_idx = 0; byte_idx < kBlockBytes; byte_idx++) { if (sample_data.input_blocks[block_idx][byte_idx] != xls_plaintext[block_idx][byte_idx]) { - std::cout << "Error comparing block " << block_idx << ":" << std::endl; + std::cout << "Error comparing block " << block_idx << ":" << '\n'; PrintFailure(sample_data.input_blocks[block_idx], xls_plaintext[block_idx], byte_idx, /*ciphertext=*/false); @@ -319,21 +319,19 @@ static absl::Status RunTest(int32_t num_samples, int32_t key_bits) { XLS_ASSIGN_OR_RETURN(bool proceed, RunSample(&encrypt_jit_data, sample_data, &xls_encrypt_dur)); if (!proceed) { - std::cout << "Key : " << FormatKey(sample_data.key) << std::endl; - std::cout << "IV : " << FormatInitVector(sample_data.iv) - << std::endl; - std::cout << "Plaintext: " << std::endl - << FormatBlocks(sample_data.input_blocks, /*indent=*/4) - << std::endl; + std::cout << "Key : " << FormatKey(sample_data.key) << '\n'; + std::cout << "IV : " << FormatInitVector(sample_data.iv) << '\n'; + std::cout << "Plaintext: " << '\n' + << FormatBlocks(sample_data.input_blocks, /*indent=*/4) << '\n'; return absl::InternalError( absl::StrCat("Testing failed at sample ", i, ".")); } } std::cout << "AES-CTR: Successfully ran " << num_samples << " samples." - << std::endl; + << '\n'; std::cout << "AES-CTR: Avg. XLS encryption time: " - << xls_encrypt_dur / num_samples << std::endl; + << xls_encrypt_dur / num_samples << '\n'; return absl::OkStatus(); } diff --git a/xls/modules/aes/aes_gcm_test.cc b/xls/modules/aes/aes_gcm_test.cc index 7167cafce9..7ab6fb3f40 100644 --- a/xls/modules/aes/aes_gcm_test.cc +++ b/xls/modules/aes/aes_gcm_test.cc @@ -206,7 +206,7 @@ static bool CompareBlock(const Block& expected, const Block& actual, std::string_view failure_msg, bool is_ciphertext) { for (int byte_idx = 0; byte_idx < kBlockBytes; byte_idx++) { if (expected[byte_idx] != actual[byte_idx]) { - std::cout << failure_msg << std::endl; + std::cout << failure_msg << '\n'; PrintFailure(expected, actual, byte_idx, is_ciphertext); return false; } @@ -245,7 +245,7 @@ static absl::StatusOr RunSample(JitData* jit_data, xls_encrypted.output_data.size()) { std::cout << "Reference & XLS ciphertext differed in sizes: " << "reference: " << reference_encrypted.output_data.size() - << ", XLS: " << xls_encrypted.output_data.size() << std::endl; + << ", XLS: " << xls_encrypted.output_data.size() << '\n'; return false; } @@ -275,8 +275,7 @@ static absl::StatusOr RunSample(JitData* jit_data, if (xls_decrypted.output_data.size() != xls_encrypted.output_data.size()) { std::cout << "Input plaintext and XLS deciphered text differed in sizes: " << "input: " << sample_data.input_data.size() - << ", decrypted: " << xls_decrypted.output_data.size() - << std::endl; + << ", decrypted: " << xls_decrypted.output_data.size() << '\n'; return false; } @@ -365,21 +364,20 @@ static absl::Status RunTest(int num_samples, int key_bits) { XLS_ASSIGN_OR_RETURN(bool proceed, RunSample(&jit_data, sample_data)); if (!proceed) { - std::cout << "Key : " << FormatKey(sample_data.key) << std::endl; + std::cout << "Key : " << FormatKey(sample_data.key) << '\n'; std::cout << "IV : " << FormatInitVector(sample_data.init_vector) - << std::endl; - std::cout << "Plaintext: " << std::endl - << FormatBlocks(sample_data.input_data, /*indent=*/4) - << std::endl; - std::cout << "AAD: " << std::endl - << FormatBlocks(sample_data.aad, /*indent=*/4) << std::endl; + << '\n'; + std::cout << "Plaintext: " << '\n' + << FormatBlocks(sample_data.input_data, /*indent=*/4) << '\n'; + std::cout << "AAD: " << '\n' + << FormatBlocks(sample_data.aad, /*indent=*/4) << '\n'; return absl::InternalError( absl::StrCat("Testing failed at sample ", sample_idx, ".")); } } std::cout << "AES-GCM: Successfully ran " << num_samples << " " << key_bits - << "-bit samples." << std::endl; + << "-bit samples." << '\n'; return absl::OkStatus(); } diff --git a/xls/modules/aes/aes_test.cc b/xls/modules/aes/aes_test.cc index d40506c296..a5be16eba9 100644 --- a/xls/modules/aes/aes_test.cc +++ b/xls/modules/aes/aes_test.cc @@ -88,8 +88,8 @@ static absl::StatusOr RunSample(const Block& input, const Key& key, *xls_encrypt_dur += absl::Now() - start_time; XLS_VLOG(2) << "Reference ciphertext: " << FormatBlock(reference_ciphertext) - << std::endl; - XLS_VLOG(2) << "XLS ciphertext: " << FormatBlock(xls_ciphertext) << std::endl; + << '\n'; + XLS_VLOG(2) << "XLS ciphertext: " << FormatBlock(xls_ciphertext) << '\n'; // Verify the ciphertexts match, to ensure we're actually doing the encryption // properly. @@ -105,8 +105,7 @@ static absl::StatusOr RunSample(const Block& input, const Key& key, XLS_ASSIGN_OR_RETURN(Block xls_decrypted, XlsDecrypt(key, key_bytes, input)); *xls_decrypt_dur += absl::Now() - start_time; - XLS_VLOG(2) << "Decrypted plaintext: " << FormatBlock(xls_decrypted) - << std::endl; + XLS_VLOG(2) << "Decrypted plaintext: " << FormatBlock(xls_decrypted) << '\n'; // We can just compare the XLS result to the input to verify we're decrypting // right. @@ -140,19 +139,19 @@ static absl::Status RunTest(int32_t key_bits, int32_t num_samples) { bool proceed, RunSample(input, key, key_bytes, &xls_encrypt_dur, &xls_decrypt_dur)); if (!proceed) { - std::cout << "Plaintext: " << FormatBlock(input) << std::endl; - std::cout << "Key: " << FormatKey(key) << std::endl; + std::cout << "Plaintext: " << FormatBlock(input) << '\n'; + std::cout << "Key: " << FormatKey(key) << '\n'; return absl::InternalError( absl::StrCat(key_bits, "-bit validation failed.")); } } std::cout << "Successfully ran " << num_samples << " " << key_bits - << "-bit samples." << std::endl; + << "-bit samples." << '\n'; std::cout << "Avg. XLS encryption time: " << xls_encrypt_dur / num_samples - << std::endl; + << '\n'; std::cout << "Avg. XLS decryption time: " << xls_decrypt_dur / num_samples - << std::endl; + << '\n'; return absl::OkStatus(); } diff --git a/xls/modules/aes/aes_test_common.cc b/xls/modules/aes/aes_test_common.cc index e18b67f2c0..9a4fb489fb 100644 --- a/xls/modules/aes/aes_test_common.cc +++ b/xls/modules/aes/aes_test_common.cc @@ -63,10 +63,9 @@ void PrintFailure(const Block& expected_block, const Block& actual_block, std::cout << "Mismatch in " << type_str << " at byte " << index << ": " << std::hex << "expected: 0x" << static_cast(expected_block[index]) << "; actual: 0x" - << static_cast(actual_block[index]) << std::endl; - std::cout << " - Expected block: " << FormatBlock(expected_block) - << std::endl; - std::cout << " - Actual block : " << FormatBlock(actual_block) << std::endl; + << static_cast(actual_block[index]) << '\n'; + std::cout << " - Expected block: " << FormatBlock(expected_block) << '\n'; + std::cout << " - Actual block : " << FormatBlock(actual_block) << '\n'; } Value InitVectorToValue(const InitVector& iv) { diff --git a/xls/modules/aes/sample_generator.cc b/xls/modules/aes/sample_generator.cc index d8d7272152..af3193597f 100644 --- a/xls/modules/aes/sample_generator.cc +++ b/xls/modules/aes/sample_generator.cc @@ -231,7 +231,7 @@ static absl::Status RealMain(EncryptionMode mode, int key_bits, XLS_ASSIGN_OR_RETURN(Result result, RunGcm(sample)); - std::cout << DslxFormatOutput(sample, result) << std::endl; + std::cout << DslxFormatOutput(sample, result) << '\n'; return absl::OkStatus(); }