| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/cal/cal.h> |
| 6 |
#include <aws/common/common.h> |
| 7 |
#include <aws/common/error.h> |
| 8 |
|
| 9 |
#define AWS_DEFINE_ERROR_INFO_CAL(CODE, STR) [(CODE) - 0x1C00] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-cal") |
| 10 |
|
| 11 |
static struct aws_error_info s_errors[] = { |
| 12 |
AWS_DEFINE_ERROR_INFO_CAL(AWS_ERROR_CAL_SIGNATURE_VALIDATION_FAILED, "Verify on a cryptographic signature failed."), |
| 13 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 14 |
AWS_ERROR_CAL_MISSING_REQUIRED_KEY_COMPONENT, |
| 15 |
"An attempt was made to perform an " |
| 16 |
"Asymmetric cryptographic operation with the" |
| 17 |
"wrong key component. For example, attempt to" |
| 18 |
"verify a signature with a private key or " |
| 19 |
"sign a message with a public key."), |
| 20 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 21 |
AWS_ERROR_CAL_INVALID_KEY_LENGTH_FOR_ALGORITHM, |
| 22 |
"A key length was used for an algorithm that needs a different key length."), |
| 23 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 24 |
AWS_ERROR_CAL_UNKNOWN_OBJECT_IDENTIFIER, |
| 25 |
"An ASN.1 OID was encountered that wasn't expected or understood. Most likely, an unsupported algorithm was " |
| 26 |
"encountered."), |
| 27 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 28 |
AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED, |
| 29 |
"An ASN.1 DER decoding operation failed on malformed input."), |
| 30 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 31 |
AWS_ERROR_CAL_MISMATCHED_DER_TYPE, |
| 32 |
"An invalid DER type was requested during encoding/decoding."), |
| 33 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 34 |
AWS_ERROR_CAL_UNSUPPORTED_ALGORITHM, |
| 35 |
"The specified algorithm is unsupported on this platform."), |
| 36 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 37 |
AWS_ERROR_CAL_BUFFER_TOO_LARGE_FOR_ALGORITHM, |
| 38 |
"The input passed to a cipher algorithm was too large for that algorithm. Consider breaking the input into " |
| 39 |
"smaller chunks."), |
| 40 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 41 |
AWS_ERROR_CAL_INVALID_CIPHER_MATERIAL_SIZE_FOR_ALGORITHM, |
| 42 |
"A cipher material such as an initialization vector or tag was an incorrect size for the selected algorithm."), |
| 43 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 44 |
AWS_ERROR_CAL_DER_UNSUPPORTED_NEGATIVE_INT, |
| 45 |
"DER decoder does support negative integers."), |
| 46 |
AWS_DEFINE_ERROR_INFO_CAL(AWS_ERROR_CAL_UNSUPPORTED_KEY_FORMAT, "Key format is not supported."), |
| 47 |
AWS_DEFINE_ERROR_INFO_CAL( |
| 48 |
AWS_ERROR_CAL_CRYPTO_OPERATION_FAILED, |
| 49 |
"Unknown error when calling underlying Crypto library.")}; |
| 50 |
|
| 51 |
static struct aws_error_info_list s_list = { |
| 52 |
.error_list = s_errors, |
| 53 |
.count = AWS_ARRAY_SIZE(s_errors), |
| 54 |
}; |
| 55 |
|
| 56 |
static struct aws_log_subject_info s_cal_log_subject_infos[] = { |
| 57 |
DEFINE_LOG_SUBJECT_INFO( |
| 58 |
AWS_LS_CAL_GENERAL, |
| 59 |
"aws-c-cal", |
| 60 |
"Subject for Cal logging that doesn't belong to any particular category"), |
| 61 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_CAL_ECC, "ecc", "Subject for elliptic curve cryptography specific logging."), |
| 62 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_CAL_HASH, "hash", "Subject for hashing specific logging."), |
| 63 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_CAL_HMAC, "hmac", "Subject for hmac specific logging."), |
| 64 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_CAL_DER, "der", "Subject for der specific logging."), |
| 65 |
DEFINE_LOG_SUBJECT_INFO( |
| 66 |
AWS_LS_CAL_LIBCRYPTO_RESOLVE, |
| 67 |
"libcrypto_resolve", |
| 68 |
"Subject for libcrypto symbol resolution logging."), |
| 69 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_CAL_RSA, "rsa", "Subject for rsa cryptography specific logging."), |
| 70 |
DEFINE_LOG_SUBJECT_INFO(AWS_LS_CAL_ED25519, "ed25519", "Subject for ed25519 cryptography specific logging."), |
| 71 |
}; |
| 72 |
|
| 73 |
static struct aws_log_subject_info_list s_cal_log_subject_list = { |
| 74 |
.subject_list = s_cal_log_subject_infos, |
| 75 |
.count = AWS_ARRAY_SIZE(s_cal_log_subject_infos), |
| 76 |
}; |
| 77 |
|
| 78 |
#ifndef BYO_CRYPTO |
| 79 |
extern void aws_cal_platform_init(struct aws_allocator *allocator); |
| 80 |
extern void aws_cal_platform_clean_up(void); |
| 81 |
extern void aws_cal_platform_thread_clean_up(void); |
| 82 |
#endif |
| 83 |
|
| 84 |
static bool s_cal_library_initialized = false; |
| 85 |
|
| 86 |
void aws_cal_library_init(struct aws_allocator *allocator) { |
| 87 |
if (!s_cal_library_initialized) { |
| 88 |
aws_common_library_init(allocator); |
| 89 |
aws_register_error_info(&s_list); |
| 90 |
aws_register_log_subject_info_list(&s_cal_log_subject_list); |
| 91 |
#ifndef BYO_CRYPTO |
| 92 |
aws_cal_platform_init(allocator); |
| 93 |
#endif |
| 94 |
s_cal_library_initialized = true; |
| 95 |
} |
| 96 |
} |
| 97 |
void aws_cal_library_clean_up(void) { |
| 98 |
if (s_cal_library_initialized) { |
| 99 |
s_cal_library_initialized = false; |
| 100 |
#ifndef BYO_CRYPTO |
| 101 |
aws_cal_platform_clean_up(); |
| 102 |
#endif |
| 103 |
aws_unregister_log_subject_info_list(&s_cal_log_subject_list); |
| 104 |
aws_unregister_error_info(&s_list); |
| 105 |
aws_common_library_clean_up(); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
void aws_cal_thread_clean_up(void) { |
| 110 |
#ifndef BYO_CRYPTO |
| 111 |
aws_cal_platform_thread_clean_up(); |
| 112 |
#endif |
| 113 |
} |