Intel HEXL
Intel Homomorphic Encryption Acceleration Library, accelerating the modular arithmetic operations used in homomorphic encryption.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <stdint.h>
7 
8 #include "hexl/util/types.hpp"
9 
10 // Create logging/debug macros with no run-time overhead unless HEXL_DEBUG is
11 // enabled
12 #ifdef HEXL_DEBUG
13 #include "hexl/logging/logging.hpp"
14 
19 #define HEXL_CHECK(cond, expr) \
20  if (!(cond)) { \
21  LOG(ERROR) << expr << " in function: " << __FUNCTION__ \
22  << " in file: " __FILE__ << ":" << __LINE__; \
23  throw std::runtime_error("Error. Check log output"); \
24  }
25 
32 #define HEXL_CHECK_BOUNDS(arg, n, bound, expr) \
33  for (size_t hexl_check_idx = 0; hexl_check_idx < n; ++hexl_check_idx) { \
34  HEXL_CHECK((arg)[hexl_check_idx] < bound, expr); \
35  }
36 
37 #else // HEXL_DEBUG=OFF
38 
39 #define HEXL_CHECK(cond, expr) \
40  {}
41 #define HEXL_CHECK_BOUNDS(...) \
42  {}
43 
44 #endif // HEXL_DEBUG