From dca4161990a2f9286c9400d014645c2ae69a3369 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 25 Oct 2016 01:01:30 -0400 Subject: Uppercase HAL_DIGEST_ALGORITHM_ symbols for API consistency. --- hal.h | 16 ++++----- hash.c | 14 ++++---- libhal.py | 20 +++++------ rpc_hash.c | 12 +++---- tests/test-rpc_bighash.c | 2 +- tests/test-rpc_hash.c | 92 ++++++++++++++++++++++++------------------------ 6 files changed, 78 insertions(+), 78 deletions(-) diff --git a/hal.h b/hal.h index db4038d..10a78ed 100644 --- a/hal.h +++ b/hal.h @@ -253,14 +253,14 @@ typedef struct hal_hash_driver hal_hash_driver_t; */ typedef enum { - hal_digest_algorithm_none, - hal_digest_algorithm_sha1, - hal_digest_algorithm_sha224, - hal_digest_algorithm_sha256, - hal_digest_algorithm_sha512_224, - hal_digest_algorithm_sha512_256, - hal_digest_algorithm_sha384, - hal_digest_algorithm_sha512 + HAL_DIGEST_ALGORITHM_NONE, + HAL_DIGEST_ALGORITHM_SHA1, + HAL_DIGEST_ALGORITHM_SHA224, + HAL_DIGEST_ALGORITHM_SHA256, + HAL_DIGEST_ALGORITHM_SHA512_224, + HAL_DIGEST_ALGORITHM_SHA512_256, + HAL_DIGEST_ALGORITHM_SHA384, + HAL_DIGEST_ALGORITHM_SHA512 } hal_digest_algorithm_t; typedef struct { diff --git a/hash.c b/hash.c index 042eff9..8485f40 100644 --- a/hash.c +++ b/hash.c @@ -191,7 +191,7 @@ static const uint8_t */ const hal_hash_descriptor_t hal_hash_sha1[1] = {{ - hal_digest_algorithm_sha1, + HAL_DIGEST_ALGORITHM_SHA1, SHA1_BLOCK_LEN, SHA1_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha1, sizeof(dalgid_sha1), @@ -199,7 +199,7 @@ const hal_hash_descriptor_t hal_hash_sha1[1] = {{ }}; const hal_hash_descriptor_t hal_hash_sha224[1] = {{ - hal_digest_algorithm_sha256, + HAL_DIGEST_ALGORITHM_SHA256, SHA256_BLOCK_LEN, SHA224_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha224, sizeof(dalgid_sha224), @@ -207,7 +207,7 @@ const hal_hash_descriptor_t hal_hash_sha224[1] = {{ }}; const hal_hash_descriptor_t hal_hash_sha256[1] = {{ - hal_digest_algorithm_sha256, + HAL_DIGEST_ALGORITHM_SHA256, SHA256_BLOCK_LEN, SHA256_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha256, sizeof(dalgid_sha256), @@ -215,7 +215,7 @@ const hal_hash_descriptor_t hal_hash_sha256[1] = {{ }}; const hal_hash_descriptor_t hal_hash_sha512_224[1] = {{ - hal_digest_algorithm_sha512_224, + HAL_DIGEST_ALGORITHM_SHA512_224, SHA512_BLOCK_LEN, SHA512_224_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha512_224, sizeof(dalgid_sha512_224), @@ -223,7 +223,7 @@ const hal_hash_descriptor_t hal_hash_sha512_224[1] = {{ }}; const hal_hash_descriptor_t hal_hash_sha512_256[1] = {{ - hal_digest_algorithm_sha512_256, + HAL_DIGEST_ALGORITHM_SHA512_256, SHA512_BLOCK_LEN, SHA512_256_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha512_256, sizeof(dalgid_sha512_256), @@ -231,7 +231,7 @@ const hal_hash_descriptor_t hal_hash_sha512_256[1] = {{ }}; const hal_hash_descriptor_t hal_hash_sha384[1] = {{ - hal_digest_algorithm_sha384, + HAL_DIGEST_ALGORITHM_SHA384, SHA512_BLOCK_LEN, SHA384_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha384, sizeof(dalgid_sha384), @@ -239,7 +239,7 @@ const hal_hash_descriptor_t hal_hash_sha384[1] = {{ }}; const hal_hash_descriptor_t hal_hash_sha512[1] = {{ - hal_digest_algorithm_sha512, + HAL_DIGEST_ALGORITHM_SHA512, SHA512_BLOCK_LEN, SHA512_DIGEST_LEN, sizeof(hal_hash_state_t), sizeof(hal_hmac_state_t), dalgid_sha512, sizeof(dalgid_sha512), diff --git a/libhal.py b/libhal.py index c35a51a..03ef41a 100644 --- a/libhal.py +++ b/libhal.py @@ -182,14 +182,14 @@ RPCFunc.define(''' class HALDigestAlgorithm(Enum): pass HALDigestAlgorithm.define(''' - hal_digest_algorithm_none, - hal_digest_algorithm_sha1, - hal_digest_algorithm_sha224, - hal_digest_algorithm_sha256, - hal_digest_algorithm_sha512_224, - hal_digest_algorithm_sha512_256, - hal_digest_algorithm_sha384, - hal_digest_algorithm_sha512 + HAL_DIGEST_ALGORITHM_NONE, + HAL_DIGEST_ALGORITHM_SHA1, + HAL_DIGEST_ALGORITHM_SHA224, + HAL_DIGEST_ALGORITHM_SHA256, + HAL_DIGEST_ALGORITHM_SHA512_224, + HAL_DIGEST_ALGORITHM_SHA512_256, + HAL_DIGEST_ALGORITHM_SHA384, + HAL_DIGEST_ALGORITHM_SHA512 ''') class HALKeyType(Enum): pass @@ -606,11 +606,11 @@ if __name__ == "__main__": print "Random:", hexstr(hsm.get_random(16)) - h = hsm.hash_initialize(hal_digest_algorithm_sha256) + h = hsm.hash_initialize(HAL_DIGEST_ALGORITHM_SHA256) h.update("Hi, Mom") print "Hash:", hexstr(h.finalize()) - h = hsm.hash_initialize(hal_digest_algorithm_sha256, key = "secret") + h = hsm.hash_initialize(HAL_DIGEST_ALGORITHM_SHA256, key = "secret") h.update("Hi, Dad") print "HMAC:", hexstr(h.finalize()) diff --git a/rpc_hash.c b/rpc_hash.c index 7cae484..4b0f8c6 100644 --- a/rpc_hash.c +++ b/rpc_hash.c @@ -157,12 +157,12 @@ static inline void free_handle(handle_slot_t *slot) static inline const hal_hash_descriptor_t *alg_to_descriptor(const hal_digest_algorithm_t alg) { switch (alg) { - case hal_digest_algorithm_sha1: return hal_hash_sha1; - case hal_digest_algorithm_sha256: return hal_hash_sha256; - case hal_digest_algorithm_sha512_224: return hal_hash_sha512_224; - case hal_digest_algorithm_sha512_256: return hal_hash_sha512_256; - case hal_digest_algorithm_sha384: return hal_hash_sha384; - case hal_digest_algorithm_sha512: return hal_hash_sha512; + case HAL_DIGEST_ALGORITHM_SHA1: return hal_hash_sha1; + case HAL_DIGEST_ALGORITHM_SHA256: return hal_hash_sha256; + case HAL_DIGEST_ALGORITHM_SHA512_224: return hal_hash_sha512_224; + case HAL_DIGEST_ALGORITHM_SHA512_256: return hal_hash_sha512_256; + case HAL_DIGEST_ALGORITHM_SHA384: return hal_hash_sha384; + case HAL_DIGEST_ALGORITHM_SHA512: return hal_hash_sha512; default: return NULL; } } diff --git a/tests/test-rpc_bighash.c b/tests/test-rpc_bighash.c index e18d9b0..823baf6 100644 --- a/tests/test-rpc_bighash.c +++ b/tests/test-rpc_bighash.c @@ -108,7 +108,7 @@ int main (int argc, char *argv[]) expected = NULL; check(hal_rpc_client_init()); - check(hal_rpc_hash_initialize(client, session, &hash, hal_digest_algorithm_sha256, NULL, 0)); + check(hal_rpc_hash_initialize(client, session, &hash, HAL_DIGEST_ALGORITHM_SHA256, NULL, 0)); for (int i = 0; i < iterations; ++i) { check(hal_rpc_hash_update(hash, block, sizeof(block))); diff --git a/tests/test-rpc_hash.c b/tests/test-rpc_hash.c index a0c571c..24f8ede 100644 --- a/tests/test-rpc_hash.c +++ b/tests/test-rpc_hash.c @@ -656,52 +656,52 @@ int main (int argc, char *argv[]) ok &= hal_rpc_client_init(); - ok &= test_hash(hal_digest_algorithm_sha1, nist_512_single, sha1_single_digest, "SHA-1 single block"); - ok &= test_hash(hal_digest_algorithm_sha1, nist_512_double, sha1_double_digest, "SHA-1 double block"); - - ok &= test_hash(hal_digest_algorithm_sha256, nist_512_single, sha256_single_digest, "SHA-256 single block"); - ok &= test_hash(hal_digest_algorithm_sha256, nist_512_double, sha256_double_digest, "SHA-256 double block"); - - ok &= test_hash(hal_digest_algorithm_sha512_224, nist_1024_single, sha512_224_single_digest, "SHA-512/224 single block"); - ok &= test_hash(hal_digest_algorithm_sha512_224, nist_1024_double, sha512_224_double_digest, "SHA-512/224 double block"); - - ok &= test_hash(hal_digest_algorithm_sha512_256, nist_1024_single, sha512_256_single_digest, "SHA-512/256 single block"); - ok &= test_hash(hal_digest_algorithm_sha512_256, nist_1024_double, sha512_256_double_digest, "SHA-512/256 double block"); - - ok &= test_hash(hal_digest_algorithm_sha384, nist_1024_single, sha384_single_digest, "SHA-384 single block"); - ok &= test_hash(hal_digest_algorithm_sha384, nist_1024_double, sha384_double_digest, "SHA-384 double block"); - - ok &= test_hash(hal_digest_algorithm_sha512, nist_1024_single, sha512_single_digest, "SHA-512 single block"); - ok &= test_hash(hal_digest_algorithm_sha512, nist_1024_double, sha512_double_digest, "SHA-512 double block"); - - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_1_key, hmac_sha1_tc_1_data, hmac_sha1_tc_1_result_sha1, "HMAC-SHA-1 test case 1"); - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_2_key, hmac_sha1_tc_2_data, hmac_sha1_tc_2_result_sha1, "HMAC-SHA-1 test case 2"); - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_3_key, hmac_sha1_tc_3_data, hmac_sha1_tc_3_result_sha1, "HMAC-SHA-1 test case 3"); - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_4_key, hmac_sha1_tc_4_data, hmac_sha1_tc_4_result_sha1, "HMAC-SHA-1 test case 4"); - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_5_key, hmac_sha1_tc_5_data, hmac_sha1_tc_5_result_sha1, "HMAC-SHA-1 test case 5"); - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_6_key, hmac_sha1_tc_6_data, hmac_sha1_tc_6_result_sha1, "HMAC-SHA-1 test case 6"); - ok &= test_hmac(hal_digest_algorithm_sha1, hmac_sha1_tc_7_key, hmac_sha1_tc_7_data, hmac_sha1_tc_7_result_sha1, "HMAC-SHA-1 test case 7"); - - ok &= test_hmac(hal_digest_algorithm_sha256, hmac_sha2_tc_1_key, hmac_sha2_tc_1_data, hmac_sha2_tc_1_result_sha256, "HMAC-SHA-256 test case 1"); - ok &= test_hmac(hal_digest_algorithm_sha256, hmac_sha2_tc_2_key, hmac_sha2_tc_2_data, hmac_sha2_tc_2_result_sha256, "HMAC-SHA-256 test case 2"); - ok &= test_hmac(hal_digest_algorithm_sha256, hmac_sha2_tc_3_key, hmac_sha2_tc_3_data, hmac_sha2_tc_3_result_sha256, "HMAC-SHA-256 test case 3"); - ok &= test_hmac(hal_digest_algorithm_sha256, hmac_sha2_tc_4_key, hmac_sha2_tc_4_data, hmac_sha2_tc_4_result_sha256, "HMAC-SHA-256 test case 4"); - ok &= test_hmac(hal_digest_algorithm_sha256, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha256, "HMAC-SHA-256 test case 6"); - ok &= test_hmac(hal_digest_algorithm_sha256, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha256, "HMAC-SHA-256 test case 7"); - - ok &= test_hmac(hal_digest_algorithm_sha384, hmac_sha2_tc_1_key, hmac_sha2_tc_1_data, hmac_sha2_tc_1_result_sha384, "HMAC-SHA-384 test case 1"); - ok &= test_hmac(hal_digest_algorithm_sha384, hmac_sha2_tc_2_key, hmac_sha2_tc_2_data, hmac_sha2_tc_2_result_sha384, "HMAC-SHA-384 test case 2"); - ok &= test_hmac(hal_digest_algorithm_sha384, hmac_sha2_tc_3_key, hmac_sha2_tc_3_data, hmac_sha2_tc_3_result_sha384, "HMAC-SHA-384 test case 3"); - ok &= test_hmac(hal_digest_algorithm_sha384, hmac_sha2_tc_4_key, hmac_sha2_tc_4_data, hmac_sha2_tc_4_result_sha384, "HMAC-SHA-384 test case 4"); - ok &= test_hmac(hal_digest_algorithm_sha384, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha384, "HMAC-SHA-384 test case 6"); - ok &= test_hmac(hal_digest_algorithm_sha384, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha384, "HMAC-SHA-384 test case 7"); - - ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_1_key, hmac_sha2_tc_1_data, hmac_sha2_tc_1_result_sha512, "HMAC-SHA-512 test case 1"); - ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_2_key, hmac_sha2_tc_2_data, hmac_sha2_tc_2_result_sha512, "HMAC-SHA-512 test case 2"); - ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_3_key, hmac_sha2_tc_3_data, hmac_sha2_tc_3_result_sha512, "HMAC-SHA-512 test case 3"); - ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_4_key, hmac_sha2_tc_4_data, hmac_sha2_tc_4_result_sha512, "HMAC-SHA-512 test case 4"); - ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha512, "HMAC-SHA-512 test case 6"); - ok &= test_hmac(hal_digest_algorithm_sha512, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha512, "HMAC-SHA-512 test case 7"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA1, nist_512_single, sha1_single_digest, "SHA-1 single block"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA1, nist_512_double, sha1_double_digest, "SHA-1 double block"); + + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA256, nist_512_single, sha256_single_digest, "SHA-256 single block"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA256, nist_512_double, sha256_double_digest, "SHA-256 double block"); + + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512_224, nist_1024_single, sha512_224_single_digest, "SHA-512/224 single block"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512_224, nist_1024_double, sha512_224_double_digest, "SHA-512/224 double block"); + + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512_256, nist_1024_single, sha512_256_single_digest, "SHA-512/256 single block"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512_256, nist_1024_double, sha512_256_double_digest, "SHA-512/256 double block"); + + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA384, nist_1024_single, sha384_single_digest, "SHA-384 single block"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA384, nist_1024_double, sha384_double_digest, "SHA-384 double block"); + + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512, nist_1024_single, sha512_single_digest, "SHA-512 single block"); + ok &= test_hash(HAL_DIGEST_ALGORITHM_SHA512, nist_1024_double, sha512_double_digest, "SHA-512 double block"); + + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_1_key, hmac_sha1_tc_1_data, hmac_sha1_tc_1_result_sha1, "HMAC-SHA-1 test case 1"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_2_key, hmac_sha1_tc_2_data, hmac_sha1_tc_2_result_sha1, "HMAC-SHA-1 test case 2"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_3_key, hmac_sha1_tc_3_data, hmac_sha1_tc_3_result_sha1, "HMAC-SHA-1 test case 3"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_4_key, hmac_sha1_tc_4_data, hmac_sha1_tc_4_result_sha1, "HMAC-SHA-1 test case 4"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_5_key, hmac_sha1_tc_5_data, hmac_sha1_tc_5_result_sha1, "HMAC-SHA-1 test case 5"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_6_key, hmac_sha1_tc_6_data, hmac_sha1_tc_6_result_sha1, "HMAC-SHA-1 test case 6"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA1, hmac_sha1_tc_7_key, hmac_sha1_tc_7_data, hmac_sha1_tc_7_result_sha1, "HMAC-SHA-1 test case 7"); + + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA256, hmac_sha2_tc_1_key, hmac_sha2_tc_1_data, hmac_sha2_tc_1_result_sha256, "HMAC-SHA-256 test case 1"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA256, hmac_sha2_tc_2_key, hmac_sha2_tc_2_data, hmac_sha2_tc_2_result_sha256, "HMAC-SHA-256 test case 2"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA256, hmac_sha2_tc_3_key, hmac_sha2_tc_3_data, hmac_sha2_tc_3_result_sha256, "HMAC-SHA-256 test case 3"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA256, hmac_sha2_tc_4_key, hmac_sha2_tc_4_data, hmac_sha2_tc_4_result_sha256, "HMAC-SHA-256 test case 4"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA256, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha256, "HMAC-SHA-256 test case 6"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA256, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha256, "HMAC-SHA-256 test case 7"); + + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA384, hmac_sha2_tc_1_key, hmac_sha2_tc_1_data, hmac_sha2_tc_1_result_sha384, "HMAC-SHA-384 test case 1"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA384, hmac_sha2_tc_2_key, hmac_sha2_tc_2_data, hmac_sha2_tc_2_result_sha384, "HMAC-SHA-384 test case 2"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA384, hmac_sha2_tc_3_key, hmac_sha2_tc_3_data, hmac_sha2_tc_3_result_sha384, "HMAC-SHA-384 test case 3"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA384, hmac_sha2_tc_4_key, hmac_sha2_tc_4_data, hmac_sha2_tc_4_result_sha384, "HMAC-SHA-384 test case 4"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA384, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha384, "HMAC-SHA-384 test case 6"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA384, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha384, "HMAC-SHA-384 test case 7"); + + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA512, hmac_sha2_tc_1_key, hmac_sha2_tc_1_data, hmac_sha2_tc_1_result_sha512, "HMAC-SHA-512 test case 1"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA512, hmac_sha2_tc_2_key, hmac_sha2_tc_2_data, hmac_sha2_tc_2_result_sha512, "HMAC-SHA-512 test case 2"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA512, hmac_sha2_tc_3_key, hmac_sha2_tc_3_data, hmac_sha2_tc_3_result_sha512, "HMAC-SHA-512 test case 3"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA512, hmac_sha2_tc_4_key, hmac_sha2_tc_4_data, hmac_sha2_tc_4_result_sha512, "HMAC-SHA-512 test case 4"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA512, hmac_sha2_tc_6_key, hmac_sha2_tc_6_data, hmac_sha2_tc_6_result_sha512, "HMAC-SHA-512 test case 6"); + ok &= test_hmac(HAL_DIGEST_ALGORITHM_SHA512, hmac_sha2_tc_7_key, hmac_sha2_tc_7_data, hmac_sha2_tc_7_result_sha512, "HMAC-SHA-512 test case 7"); ok &= hal_rpc_client_close(); -- cgit v1.2.3