[Cryptech-Commits] [sw/libhal] 08/58: Typing "!" when one meant "~" has interesting effects when bit masking.
git at cryptech.is
git at cryptech.is
Tue Jul 7 18:24:52 UTC 2015
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch master
in repository sw/libhal.
commit b7956f3c5a660e6115cc67a593b38fbd8d8aba4f
Author: Rob Austein <sra at hactrn.net>
Date: Sun May 24 15:20:53 2015 -0400
Typing "!" when one meant "~" has interesting effects when bit masking.
---
aes_keywrap.c | 2 +-
tests/test-aes-key-wrap.c | 26 ++++++++++++++------------
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/aes_keywrap.c b/aes_keywrap.c
index 9ded0e1..a41a866 100644
--- a/aes_keywrap.c
+++ b/aes_keywrap.c
@@ -63,7 +63,7 @@ static hal_error_t load_kek(const uint8_t *K, const size_t K_len, const kek_acti
config[3] |= AES_CONFIG_ENCDEC;
break;
case KEK_decrypting:
- config[3] &= !AES_CONFIG_ENCDEC;
+ config[3] &= ~AES_CONFIG_ENCDEC;
break;
default:
return HAL_ERROR_BAD_ARGUMENTS;
diff --git a/tests/test-aes-key-wrap.c b/tests/test-aes-key-wrap.c
index 1af9a2f..2db1802 100644
--- a/tests/test-aes-key-wrap.c
+++ b/tests/test-aes-key-wrap.c
@@ -92,33 +92,41 @@ static int run_test(const uint8_t * const K, const size_t K_len,
* Wrap and compare results.
*/
+ printf("Wrapping with %lu-bit KEK...\n", (unsigned long) K_len * 8);
if ((err = hal_aes_keywrap(K, K_len, Q, Q_len, c, &c_len)) != HAL_OK) {
- printf("couldn't wrap with %lu-bit KEK: %s\n",
+ printf("Couldn't wrap with %lu-bit KEK: %s\n",
(unsigned long) K_len * 8, hal_error_string(err));
ok1 = 0;
}
else if (C_len != c_len || memcmp(C, c, C_len) != 0) {
- printf("ciphertext mismatch:\n Want: %s\n Got: %s\n",
+ printf("Ciphertext mismatch:\n Want: %s\n Got: %s\n",
format_hex(C, C_len, h1, sizeof(h1)),
format_hex(c, c_len, h2, sizeof(h2)));
ok1 = 0;
}
+ else {
+ printf("OK\n");
+ }
/*
* Unwrap and compare results.
*/
+ printf("Unwrapping with %lu-bit KEK...\n", (unsigned long) K_len * 8);
if ((err = hal_aes_keyunwrap(K, K_len, C, C_len, q, &q_len)) != HAL_OK) {
- printf("couldn't unwrap with %lu-bit KEK: %s\n",
+ printf("Couldn't unwrap with %lu-bit KEK: %s\n",
(unsigned long) K_len * 8, hal_error_string(err));
ok2 = 0;
}
else if (Q_len != q_len || memcmp(Q, q, Q_len) != 0) {
- printf("plaintext mismatch:\n Want: %s\n Got: %s\n",
+ printf("Plaintext mismatch:\n Want: %s\n Got: %s\n",
format_hex(Q, Q_len, h1, sizeof(h1)),
format_hex(q, q_len, h2, sizeof(h2)));
ok2 = 0;
}
+ else {
+ printf("OK\n");
+ }
return ok1 && ok2;
}
@@ -135,16 +143,10 @@ int main (int argc, char *argv[])
hal_io_set_debug(1);
- printf("Testing 128-bit KEK...");
- if (run_test(K_128, sizeof(K_128), C_128, sizeof(C_128)))
- printf("OK\n");
- else
+ if (!run_test(K_128, sizeof(K_128), C_128, sizeof(C_128)))
failures++;
- printf("Testing 256-bit KEK...");
- if (run_test(K_256, sizeof(K_256), C_256, sizeof(C_256)))
- printf("OK\n");
- else
+ if (!run_test(K_256, sizeof(K_256), C_256, sizeof(C_256)))
failures++;
return failures;
More information about the Commits
mailing list