1ced56a00Sopenharmony_ci// SPDX-License-Identifier: MIT 2ced56a00Sopenharmony_ci/* 3ced56a00Sopenharmony_ci * Test the hash algorithm-related libfsverity APIs. 4ced56a00Sopenharmony_ci * 5ced56a00Sopenharmony_ci * Copyright 2020 Google LLC 6ced56a00Sopenharmony_ci * 7ced56a00Sopenharmony_ci * Use of this source code is governed by an MIT-style 8ced56a00Sopenharmony_ci * license that can be found in the LICENSE file or at 9ced56a00Sopenharmony_ci * https://opensource.org/licenses/MIT. 10ced56a00Sopenharmony_ci */ 11ced56a00Sopenharmony_ci 12ced56a00Sopenharmony_ci#include "utils.h" 13ced56a00Sopenharmony_ci 14ced56a00Sopenharmony_ci#define SHA256_DIGEST_SIZE 32 15ced56a00Sopenharmony_ci#define SHA512_DIGEST_SIZE 64 16ced56a00Sopenharmony_ci 17ced56a00Sopenharmony_ciint main(void) 18ced56a00Sopenharmony_ci{ 19ced56a00Sopenharmony_ci install_libfsverity_error_handler(); 20ced56a00Sopenharmony_ci 21ced56a00Sopenharmony_ci ASSERT(libfsverity_get_digest_size(0) == -1); 22ced56a00Sopenharmony_ci ASSERT(libfsverity_get_hash_name(0) == NULL); 23ced56a00Sopenharmony_ci ASSERT(libfsverity_find_hash_alg_by_name("bad") == 0); 24ced56a00Sopenharmony_ci ASSERT(libfsverity_find_hash_alg_by_name(NULL) == 0); 25ced56a00Sopenharmony_ci 26ced56a00Sopenharmony_ci ASSERT(libfsverity_get_digest_size(100) == -1); 27ced56a00Sopenharmony_ci ASSERT(libfsverity_get_hash_name(100) == NULL); 28ced56a00Sopenharmony_ci 29ced56a00Sopenharmony_ci ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA256) == 30ced56a00Sopenharmony_ci SHA256_DIGEST_SIZE); 31ced56a00Sopenharmony_ci ASSERT(!strcmp("sha256", 32ced56a00Sopenharmony_ci libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA256))); 33ced56a00Sopenharmony_ci ASSERT(libfsverity_find_hash_alg_by_name("sha256") == 34ced56a00Sopenharmony_ci FS_VERITY_HASH_ALG_SHA256); 35ced56a00Sopenharmony_ci 36ced56a00Sopenharmony_ci ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA512) == 37ced56a00Sopenharmony_ci SHA512_DIGEST_SIZE); 38ced56a00Sopenharmony_ci ASSERT(!strcmp("sha512", 39ced56a00Sopenharmony_ci libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA512))); 40ced56a00Sopenharmony_ci ASSERT(libfsverity_find_hash_alg_by_name("sha512") == 41ced56a00Sopenharmony_ci FS_VERITY_HASH_ALG_SHA512); 42ced56a00Sopenharmony_ci 43ced56a00Sopenharmony_ci printf("test_hash_algs passed\n"); 44ced56a00Sopenharmony_ci return 0; 45ced56a00Sopenharmony_ci} 46